상세 컨텐츠

본문 제목

중간 코드 확인

python

by bumychoi 2024. 5. 20. 04:15

본문

{% extends "main.html" %}
{% block contents %}

<style>
    html,
    body,
    h1,
    h2,
    h3,
    div,
    span,
    a,
    button,
    table,
    tbody,
    thead,
    input {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    header {
        background-color: hsl(57, 95%, 60%);
    }

    body {
        min-height: 110%;
        background-color: hsl(186, 77%, 74%);
    }

    .clicked {
        background-color: rgb(59, 62, 147);
        /* border-radius: 20%; */
        color: rgb(232, 132, 37);
        display: flex;
        text-align: start;
        flex-direction: column;
        width: 150px;
    }

    .clicked>ul>span {
        text-align: center;
    }

    .btn btn-warning {
        margin: 0;
        padding: 0;
    }

    ol,
    ul {
        padding: 4px 4px 4px 4px;
        /* margin: auto; */
    }

    /* .btn btn-secondary btn-lg {
        zoom: 0.5;
        margin: 0;
        padding: 0;
    } */
    .wrap {
        /* background-color: chartreuse; */
        width: 1600px;
        height: 300px;
        margin: auto;
        border: 1px;
    }

    td>input {
        border: none;
    }

    th>input {
        border: none;
    }

    tr {
        cursor: pointer;
    }

    td>button {
        zoom: 0.65;
    }

    .total {

        height: 800px;

    }

    table {
        width: 1200px;
        table-layout: fixed;
    }

    .flex-row {
        display: flex;
        flex-direction: row;
        align-items: flex-start
            /* justify-content: center; */
    }

    .flex-col {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .list-group {
        background-color: rgb(13, 170, 233);
        color: white;
        width: 200px;
    }

    .list-group>ul {
        height: 650px;
    }

    .list-group>ul>li {
        height: 30px;
    }

    tr {
        width: 1000px;
    }

    .add-form>td {
        background-color: rgb(173, 214, 243);
    }

    .clicked {
        background-color: azure;
        color: blue;
        width: 200px;
        height: 30px;
    }

    .sum {
        margin-right: 10px;
        margin-left: auto;
        background-color: rgb(212, 250, 130);
        font-size: 20px;
        font-weight: 500;
        padding: auto;
        border: 1.5px solid rgb(13, 59, 132);
    }

    .sum>span {
        /* border: 1.5px solid rgb(13, 59, 132); */
        margin-left: 2px;
    }

    .input {
        width: 1600px;
        background-color: rgb(222, 240, 164);
        height: 350px;
        /* display: none; */
    }

    .btn>button {
        margin-left: auto;
        margin-right: 10px;
        width: 100px;
        height: 50px;
    }

    tr {
        cursor: pointer;
        border-right: 1px dashed blanchedalmond;
    }

    td {
        width: auto;
        border-right: 1px dashed blanchedalmond;
    }

    .listclick {
        border-color: rgb(241, 7, 7);
        font-weight: 3000;
        font-style: initial;
        border-style: dashed;
        box-shadow: 5px -5px teal
    }

    .form_in {
        width: 1800px;
    }

    h4 {
        background-color: rgb(239, 161, 43);
        width: 400px;
        margin-left: auto;
        margin-right: auto;
        text-align: center;
        font-weight: 600;
        font-style: italic;
    }

    .sum {
        margin-right: auto;
        margin-left: 10px;
        /* background-color: rgb(212, 250, 130); */
        font-size: 15px;
        font-weight: 350;
        padding: auto;
        /* border: 1.5px solid rgb(13, 59, 132); */
    }

    .sum>span {
        /* border: 1.5px solid rgb(13, 59, 132); */
        margin-left: 2px;
    }
</style>
<script>
    let id
    let idx
    let clicked_id
    let mv_id
    $(document).ready(() => {
        d_list(id)

    })
    function input_list(idx) {
        // console.log(idx)
        let url = `/freight/d_list_input_list?list=${idx}`
        fetch(url).then(res => res.json()).then(data => {
            let rows = data['result1'];
            let sum_bundle = 0
            let sum_bd =0
            $("#list_1").empty();
            rows.forEach((row) => {
                let id = row['_id']
                let list_id = row['list_id']
                let number = row['number']
                let tc_no = row['tc_no']
                let bundle = row['bundle']
                let offer = row['offer']
                let gangjung = row['gangjung']
                let size = row['size']
                let mt = row['bundle_mt']
                let hauju = row['hauju']
                let temp_html2 = `<tr class=id_list id="${id}" >
                                    <td><input readonly type="text" name="number" id="number" value=${number}></td>
                                    <td><input readonly type="text" name="tc_no" id="tc_no" value=${tc_no}></td>
                                    <td><input readonly type="text" name="bundle" id="bundle" value=${bundle}></td>
                                    <td><input readonly type="text" name="huju" id="huju" value=${hauju}></td>
                                    <td><input readonly type="text" name="mt" id="mt" value=${mt}></td>
                                    <td><input readonly type="text" name="gangjung" id="gangjung" value=${gangjung}></td>
                                    <td><input readonly type="text" name="offer" id="offer" value=${offer}></td>
                                    <td><input readonly type="text" name="size" id="size" value=${size}></td>
                                    <td>
                                        <div class="btn-group">
                                            <button onclick="show('${id}')" class="btn btn-success" aria-current="page">수정</button>
                                        </div>
                                    </td>
                                </tr>
                                <tr class=id_mody id="${id}_mody" style="display:none;">
                                    <td><input type="text" name="number" id="number" value=${number}></td>
                                    <td><input type="text" name="tc_no" id="tc_no" value=${tc_no}></td>
                                    <td><input type="text" name="bundle" id="tc_no" value=${bundle}></td>
                                    <td><input readonly type="text" name="hauju" id="hauju" value=${hauju}></td>
                                    <td><input readonly readonly type="text" name="mt" id="mt" value=${mt}></td>
                                    <td><input readonly type="text" name="gangjung" id="gangjung" value=${gangjung}></td>
                                    <td><input readonly type="text" name="offer" id="offer" value=${offer}></td>
                                    <td><input readonly type="text" name="size" id="size" value=${size}></td>
                                    <td>
                                        <div class="btn-group btn-group-sm">
                                            <button onclick="mody('${id}')" class="btn btn-success" aria-current="page">수정</button>
                                            <button onclick="hide('${id}')" class="btn btn-warning" aria-current="page">취소</button>
                                            <button onclick="del('${id}')" class="btn btn-danger">삭제</button>
                                        </div>
                                    </td>
                                </tr>
                `
                $('#list_1').append(temp_html2)
                sum_bundle += (Number(bundle))
            })
            $(`#${idx}input_sum`).text(sum_bundle)
            sun_bd = $(`#${idx}bd`).text()
           
            r_bund = sun_bd - sum_bundle
            console.log(r_bund)
            $(`#${idx}remain`).text(r_bund)
        })
       
    }
    function d_list(id) {
        if (id == undefined) {
            fetch(`/freight/d_bar_lists`).then(res => res.json()).then(data => {
                let rows = data['result'];
                $("#list").empty();
                rows.forEach((row) => {
                    let id = row['_id']
                    let msn = row['msn']
                    let hauju = row['hauju']
                    let p_name = row['p_name']
                    let offer = row['offer']
                    let gangjung = row['gangjung']
                    let size = row['size']
                    let bundle = row['bundle']

                    let mt = row['mt']
                    let storage = row['storage']
                    let mv_id = row['mv_id']
                    let temp_html = ` <tr id='${id}_add' onclick="list_click('${id}')">
                                        <td name="msn">${msn}</td>
                                        <td name="hauju">${hauju}</td>
                                        <td name="P_name">${p_name}</td>
                                        <td name="offer">${offer}</td>
                                        <td name="ganfjung">${gangjung}</td>
                                        <td name="size">${size}</td>
                                        <td name="bundle" id='${idx}bundle'>${bundle}</td>
                                        <td name="mt">${mt}</td>
                                        <td name="input_sum" id='${idx}input_sum'></td>
                                        <td name"remain" id='${idx}remain'>잔량</td>
                                    </tr>`

                    $("#list").append(temp_html)
                })

            })
        }
        else {
            let url = `/freight/d_bar_lists?data=${id}`
            fetch(url).then(res => res.json()).then(data => {
                // let name = data["mv_name"]
                // console.log(name)
                let rows = data['result'];
                $("#list").empty();
                let total_bd = 0
                let total_mt = 0
                rows.forEach((row) => {
                    let id = row['_id']
                    let msn = row['msn']
                    let hauju = row['hauju']
                    let p_name = row['p_name']
                    let offer = row['offer']
                    let gangjung = row['gangjung']
                    let size = row['size']
                    let bundle = row['bundle']
                    total_bd +=Number(bundle)
                    let mt = row['mt']
                    total_mt += Number(mt)
                    let storage = row['storage']
                    let mv_id = row['mv_id']
                    let temp_html = ` <tr id='${id}_add' onclick="list_click('${id}')">
                                        <td name="msn">${msn}</td>
                                        <td name="hauju">${hauju}</td>
                                        <td name="P_name">${p_name}</td>
                                        <td name="offer">${offer}</td>
                                        <td name="gangjung">${gangjung}</td>
                                        <td name="size">${size}</td>
                                        <td name="bundle"style="text-align:right" id='${id}bd'}>${bundle}</td>
                                        <td name="mt" style="text-align:right">${mt}</td>
                                        <td name="input_sum" id='${id}input_sum'></td>
                                        <td name"remain" id='${id}remain'></td>
                                    </tr>`
                    $("#list").append(temp_html)
                   
                })
                result = total_mt.toFixed(3).replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
                result2 =total_bd.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
                $(`#total_bd`).text(result2)
                $(`#total_mt`).text(result)
            })
        }
    }

    function mv_click(id) {
        mv_id = id
        $(`#mv_mv`).text(`${id}`)
        $(`.list-group`).addClass('clicked')
        $(`#${id}`).removeClass('clicked')
        d_list(id)
        $(`.input`).hide();
    }
    function d_input(idx) {
        let list_id = $('input[name=list_id]').val()
        let number = $('input[name=number]').val()
        let tc_no = $('input[name=tc_no]').val()
        let bundle = $('input[name =bundle]').val()
        let offer = $('input[name =offer]').val()
        let gangjung = $('input[name=gangjung]').val()
        let size = $('input[name=size]').val()
        let hauju = $('input[name=hauju]').val()
        let bundle_mt = $('input[name=mt]').val()
        let formData = new FormData()
        formData.append("list_id_give", list_id)
        formData.append("number_give", number)
        formData.append("tc_no_give", tc_no)
        formData.append("bundle_give", bundle)
        formData.append("offer_give", offer)
        formData.append("gangjung_give", gangjung)
        formData.append("size_give", size)
        formData.append("hauju_give", hauju)
        formData.append("bundle_mt_give", bundle_mt)
        clicked_id = list_id

        fetch('/freight/d_bar_input', { method: "POST", body: formData }).then(res => res.json()).then(data => {
            alert(data["msg"])
            list_click(clicked_id)
        })

    }
    function list_click(idx) {
        let msn = $(`#${idx}_add>td[name=msn]`).text()
        let hauju = $(`#${idx}_add>td[name=hauju]`).text()
        let p_name = $(`#${idx}_add>td[name=p_name]`).text()
        let offer = $(`#${idx}_add>td[name=offer]`).text()
        let bundle = $(`#${idx}_add>td[name=bundle]`).text()
        let gangjung = $(`#${idx}_add>td[name=gangjung]`).text()
        let size = $(`#${idx}_add>td[name=size]`).text()
        let mt = $(`#${idx}_add>td[name=mt]`).text()
        mt = Math.round(mt / bundle * 1000) / 1000
        $('#mt').val(mt)
        $('#hauju').val(hauju)
        $('#gangjung').val(gangjung)
        $('#offer').val(offer)
        $('#size').val(size)
        $(`#list_id`).val(idx)
        $(`#number`).val('')
        $(`#tc_no`).val(``)
        $(`#bundle`).val('')

        $(`.listclick`).removeClass('listclick')
        $(`#${idx}_add`).addClass('listclick')
        input_list(idx)
    }
    function show(id) {
        $(`#${id}`).hide();
        $(`#${id}_mody`).show();
    }
    function hide(id) {
        $(`#${id}`).show();
        $(`#${id}_mody`).hide();
    }
    function mody(id) {
        let number = $(`#${id}_mody>td>input[name=number]`).val()
        let tc_no = $(`#${id}_mody>td>input[name=tc_no]`).val()
        let bundle = $(`#${id}_mody>td>input[name=bundle]`).val()
        let hauju = $(`#${id}_mody>td>input[name=hauju]`).val()
        let mt = $(`#${id}_mody>td>input[name=mt]`).val()
        let gangjung = $(`#${id}_mody>td>input[name=gangjung]`).val()
        let offer = $(`#${id}_mody>td>input[name=offer]`).val()
        let size = $(`#${id}_mody>td>input[name=size]`).val()
        let bundle_mt = $(`#${id}_mody>td>input[name=mt]`).val()
        let formData = new FormData()
        formData.append("id_give", id)
        formData.append("number_give", number)
        formData.append("tc_no_give", tc_no)
        formData.append("bundle_give", bundle)
        formData.append("hauju_give", hauju)
        formData.append("mt_give", mt)
        formData.append("gangjung_give", gangjung)
        formData.append("offer_give", offer)
        formData.append("size_give", size)
        formData.append("bundle_mt_give",bundle_mt)
        clicked_id = id
        fetch('/freight/d_bar_modify', { method: "POST", body: formData }).then(res => res.json()).then(data => {
            alert(data["msg"])
            hide(id)
        })
        // list_click(clicked_id)
    }
    function del(id) {
        clicked_id = id
        if (confirm("정말삭제하나요?")) {
            let formData = new FormData()
            formData.append("id_give", id)
            fetch('/freight/d_bar_delete', { method: "POST", body: formData }).then(res => res.json()).then(data => {
                alert(data["msg"])
                list_click(clicked_id)
            })

        }

    }
    function mv_sum(id){
        if (id == undefined){
            alert('본선을 선택하세요')
        }
        else{
            let url = `/freight/d_bar_sum?data=${id}`
            window.open(`/freight/d_bar_sum?data=${id}`)
            fetch(url).then(res => res.json()).then(data => {
                let rows = data['msg'];
                rows.forEach((row) => {
                console.log(rows)
                })
            })  
        }
       
    }
</script>
<header>
    <div class="flex-row">
        <div>
            {% for d_list in d_lists %}
            <a id="{{d_list._id}}" class="list-group" onclick="mv_click(`${id}`)" name="mv_name">{{d_list.date}}
                {{d_list.mv_name}}</a>
            {% endfor %}
        </div>
        <div class="flex-col">
            <div class=form_in>
                <tr class=id_list id="id_list">
                    <td><input type="text" placeholder="전표번호" name="number" id="number"></td>
                    <td><input type="text" placeholder="차량번호" name="tc_no" id="tc_no"></td>
                    <td><input type="text" placeholder="수량" name="bundle" id="bundle"></td>
                    <td><input readonly type="text" placeholder="사이즈" name="size" id="size"></td>
                    <td><input readonly type="text" placeholder="강종" name="gangjung" id="gangjung"></td>
                    <td><input readonly type="text" placeholder="제강사" name="offer" id="offer"></td>
                    <td><input readonly type="text" placeholder="화주명" name="hauju" id="hauju"></td>
                    <td><input readonly type="text" placeholder="중량" name="mt" id="mt"></td>
                    <input type="hidden" name="list_id" id="list_id">`
                    <div class="btn">
                        <button type="button" class="btn btn-success" onclick="d_input(id)">입고</button>
                        <button type="button" class="btn btn-warning" onclick="mv_sum(mv_id)">집계</button>
                    </div>
                   
                </tr>
            </div>
            <div class="flex-row">
                <div class="flex-row">
                    <table class="table" style="border: 8px blue;">
                        <tr>
                            <td>총수량</td>
                            <td>총중량</td>
                            <td>작업수량</td>
                            <td>작업중량</td>
                            <td>남은수량</td>
                            <td>남은중량</td>
                        </tr>
                        <tr>
                            <td><span id="total_bd">00</span> B/D</td>
                            <td><span id="total_mt">00</span> M/T</td>
                            <td><span id="in_bd">00</span> B/D</td>
                            <td><span id="in_mt">00</span> M/T</td>
                            <td><span id="remain_bd">00</span> B/D</td>
                            <td><span id="remain_mt">00</span>  M/T</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

</header>

<body>
    <div class="flex-col">
        <div class="wrap  bd-sidbar">
            <table class="table" style="border: 8px blue;">
                <thead class="table-primary">
                    <tr>
                        <th scope="col">MSN</th>
                        <th scope="col">화주명</th>
                        <th scope="col">품명</th>
                        <th scope="col">제강사</th>
                        <th scope="col">강종</th>
                        <th scope="col">싸이즈</th>
                        <th scope="col">총수량(B/D)</th>
                        <th scope="col">총중량(M/T)</th>
                        <th scope="col">입고수량</th>
                        <th scope="col">잔량</th>
                    </tr>
                </thead>
                <tbody class="table table-striped table" id=list class="add-form">
                    <!-- <tr class="add-form_1" id="add-form_1" style="background-color: aqua;">
                        <td><input type="text" placeholder="MSN" name="msn"></td>
                        <td><input type="text" placeholder="화주명" name="hauju"></td>
                        <td><input type="text" placeholder="세부품명" value="d_bar" name="p_name"></td>
                        <td><input type="text" placeholder="제강사" name="offer"></td>
                        <td><input type="text" placeholder="강 종" name="gangjung"></td>
                        <td><input type="text" placeholder="싸이즈" name="size"></td>
                        <td><input type="text" placeholder="수 량" name="bundle"></td>
                        <td><input type="text" placeholder="톤수" name="mt"></td>
                        <td><input type="text" placeholder="창고코드" name="storage"></td>
                        </td>
                    </tr> -->
                </tbody>
            </table>
            <table e class="table" style="border: 8px blue;">
                <tbody class="table table-striped table">
                    <div>
                    </div>
                </tbody>
            </table>
        </div>
    </div>
    <hr>
    <h4><sub style="font-size: 14px; color: rgb(222, 240, 164);">전번,차번,수량 만 <strong
                style="font-family: 900;">수정가능</strong></sub>
    </h4>
    <div class="wrap  bd-sidbar" style="height: 300px; width:1550px; overflow-y: auto">
        <table class="table" style="border: 8px blue;">
            <thead class="table-primary">
                <tr>
                    <th scope="col">전표번호</th>
                    <th scope="col">차량번호</th>
                    <th scope="col">B/D</th>
                    <th scope="col">화주명</th>
                    <th scope="col">중량</th>
                    <th scope="col">제강사</th>
                    <th scope="col">강종</th>
                    <th scope="col">싸이즈</th>
                    <th scope="col">수정삭재</th>
                </tr>
            </thead>
            <tbody class="table table-striped table" id=list_1 class="add-form">
                <!-- <tr class=id_list id="id_list">
                    <td><input type="text" placeholder="전표번호" name="number" id="number"></td>
                    <td><input type="text" placeholder="차량번호" name="tc_no" id="tc_no"></td>
                    <td><input type="text" placeholder="수량" name="huju" id="huju"></td>
                    <td><input type="text" placeholder="중량" name="mt" id="mt"></td>
                    <td><input type="text" placeholder="강종" name="gangjung" id="gangjung"></td>
                    <td><input type="text" placeholder="제강사" name="offer" id="offer"></td>
                    <td><input type="text" placeholder="사이즈" name="size" id="size"></td>
                    <td>
                        <div class="btn-group">
                            <a href="#" class="btn btn-warning" aria-current="page">수정</a>
                            <a href="#" class="btn btn-danger">삭제</a>
                        </div>
                    </td>
                </tr> -->
            </tbody>
        </table>
    </div>
    </tr>
    </div>
</body>
{% endblock %}

 

 

from main import *
from flask import Blueprint
from bson.objectid import ObjectId

bp = Blueprint("freight", __name__, url_prefix='/freight')

@bp.route("/")
def freight():
    d_lists = list(db.mv.find({"cago_name": "철근"}))
    return render_template("freight.html",d_lists=d_lists,title="철근상세")

@bp.route('/d_bar_lists',methods=['GET'])
def d_bar_lists():
    data = request.args.get('data')
    d_details = list(db.d_list.find({'mv_id':data}).sort({"number": -1}))
    for d_detail in d_details:
        d_detail["_id"] = str(d_detail['_id'])
    return jsonify({"result": d_details})

@bp.route('/d_bar_input',methods=['POST'])
def d_bar_input():
    list_id_receive = request.form["list_id_give"]
    number_receive = int(request.form["number_give"])
    tc_no_receive = request.form["tc_no_give"]
    bundle_receive = int(request.form["bundle_give"])
    offer_receive = request.form["offer_give"]
    gangjung_receive = request.form["gangjung_give"]
    size_receive = request.form["size_give"]
    hauju_receive = request.form["hauju_give"]
    bundle_mt_recevive =float(request.form['bundle_mt_give'])
    doc ={
        "list_id":list_id_receive,
        "number":number_receive,
        "tc_no":tc_no_receive,
        "bundle":bundle_receive,
        "offer":offer_receive,
        "gangjung":gangjung_receive,
        "size":size_receive,
        "hauju":hauju_receive,
        "bundle_mt":bundle_mt_recevive
    }
    db.d_input.insert_one(doc)

    return jsonify({"msg":"저장완료"})

@bp.route('/d_list_input_list')
def d_list_input_list():
    data = request.args.get('list')
    input_lists = list(db.d_input.find({'list_id':data}))
    for input_list in input_lists:
        input_list["_id"] = str(input_list['_id'])
    return jsonify({"result1":input_lists})

@bp.route('/d_bar_modify',methods=['POST'])
def d_bar_modify():
    id_receive = request.form["id_give"]
    number_receive = int(request.form["number_give"])
    tc_no_receive = request.form["tc_no_give"]
    bundle_receive = int(request.form["bundle_give"])
    hauju_receive = request.form["hauju_give"]
    mt_receive = request.form["mt_give"]
    gangjung_receive = request.form["gangjung_give"]
    offer_receive = request.form["offer_give"]
    size_receive = request.form["size_give"]
    bundle_mt_receive=request.form["bundle_mt_give"]
    id_receive = ObjectId(id_receive)
    # print(hauju_receive)
    db.d_input.update_one({'_id':id_receive},{'$set':{
                            "number":number_receive,
                            "to_no":tc_no_receive,
                            "bundle":bundle_receive,
                            "hauju":hauju_receive,
                            "mt":mt_receive,
                            "gangjung":gangjung_receive,
                            "offer":offer_receive,
                            "size":size_receive,
                            "bundle_mt":bundle_mt_receive
                            }})

    return jsonify({"msg":"수정완료"})

@bp.route("/d_bar_delete",methods=["POST"])
def d_bar_delete():
    id_receive = request.form["id_give"]
    id_receive = ObjectId(id_receive)
    db.d_input.delete_one({'_id':id_receive})

    return jsonify({"msg":"삭제완료"})

@bp.route('/d_bar_sum',methods=['GET'])
def d_bar_sum():
    data = request.args.get('data')
    mv_lists = list(db.d_list.aggregate([
        {'$match':{'mv_id':data}},
        {'$group':{'_id':{"size":{"_id":"$size"},
                         "hauju":{"_id":"$hauju"},
                         "offer":{"_id":"$offer"},
                         "gangjung":{"_id":"$gangjung"}},

                         "total":{"$sum":"$bundle"}}},
]))

    for mv_list in mv_lists:
        mv_list["_id"] = str(mv_list['_id'])
        # mv_list['bundle'] = int(mv_list['bundle'])
        # mv_list['mt']=float(mv_list['mt'])

    return jsonify({"msg":mv_lists})


관련글 더보기