| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 | 
<!--数据检查--><div class="modal fade" id="ledger-check-modal" data-backdrop="static">    <div class="modal-dialog" role="document">        <div class="modal-content">            <div class="modal-header">                <h5 class="modal-title">数据检查</h5>            </div>            <div class="modal-body">                <p>数据检查,将检查罗列台帐中以下内容:</p>                <div class="card mb-2 p-2 border-success" id="check-sibling">                    <div class="d-flex justify-content-between">                        项目节、清单同层                        <span class="text-muted" name="check-status">待检查</span>                    </div>                </div>                <div class="card mb-2 p-2 border-success" id="check-empty-code">                    <div class="d-flex justify-content-between">                        项目节、清单编号同时为空                        <!-- <span class="text-muted">待检查</span> -->                        <!-- <span class="text-muted" title="检查中"><i class="fa fa-spinner fa-spin"></i></span> -->                        <span class="text-success" title="完成" name="check-status"><i class="fa fa-check"></i></span>                    </div>                </div>                <div class="card mb-2 p-2 border-success" id="check-calc">                    <div class="d-flex justify-content-between">                        清单数量不等于计量单元之和                        <!-- <span class="text-muted">待检查</span> -->                        <!-- <span class="text-muted" title="检查中"><i class="fa fa-spinner fa-spin"></i></span> -->                        <span class="text-success" title="完成" name="check-status"><i class="fa fa-check"></i></span>                    </div>                </div>                <div class="card mb-2 p-2 border-success" id="check-zero">                    <div class="d-flex justify-content-between">                        清单数量或单价为0                        <!-- <span class="text-muted">待检查</span> -->                        <!-- <span class="text-muted" title="检查中"><i class="fa fa-spinner fa-spin"></i></span> -->                        <span class="text-success" title="完成" name="check-status"><i class="fa fa-check"></i></span>                    </div>                </div>                 <a href="javascript: void(0);" class="btn btn-sm btn-block btn-primary" id="ledger-check-begin">开始检查</a>                 <a href="#" class="btn btn-sm btn-block btn-primary disabled" id="ledger-check-waiting">检查中,请等待...</a>                <p class="text-center text-success" id="ledger-check-hint">检查完成,现在您可以查看结果。</p>            </div>            <div class="modal-footer">                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">关闭</button>                <!--检查完有结果显示按钮-->                <button type="button" class="btn btn-sm btn-primary" id="ledger-check-show">查看结果</button>            </div>        </div>    </div></div><script>    const ledgerCheckType = {        sibling: {value: 1, text: '项目节、清单同层'},        empty_code: {value: 2, text: '项目节、清单编号同时为空'},        calc: {value: 3, text: '清单数量不等于计量单元之和'},        zero: {value: 4, text: '清单数量或单价为0'},    };    const LedgerChecker = function (setting) {        const ledger = setting.ledgerTree, ledgerPos = setting.ledgerPos;        const initWaitingModal = function () {            $('.card', '#ledger-check-modal').removeClass('border-success');            $('[name=check-status]', '#ledger-check-modal').removeClass('text-success').addClass('text-muted').html('待检查');            $('#ledger-check-begin').show();            $('#ledger-check-waiting').hide();            $('#ledger-check-hint').removeClass('text-warning').addClass('text-success').html('检查完成,现在您可以查看结果。').hide();            $('#ledger-check-show').hide();        }        const doSomeCheck = function (selector, checkFun) {            const checkStatus = $('[name=check-status]', selector);            checkStatus.html('<i class="fa fa-spinner fa-spin"></i>');            const result = checkFun(ledger);            checkStatus.removeClass('text-muted').addClass('text-success').html('<i class="fa fa-check"></i>');            $(selector).addClass('border-success');            return result;        }        const ledgerCheckUtil = {            checkSibling: function (ledgerTree) {                const error = [];                for (const node of ledgerTree.nodes) {                    if (!node.children || node.children.length === 0) continue;                    let hasXmj, hasGcl;                    for (const child of node.children) {                        if (child.b_code) hasXmj = true;                        if (!child.b_code) hasGcl = true;                    }                    if (hasXmj && hasGcl) error.push(node);                }                return error;            },            checkCodeEmpty: function (ledgerTree) {                const error = [];                const checkNodeCode = function (node) {                    if ((!node.code || node.code === '') && (!node.b_code || node.b_code === '')) error.push(node);                    if (node.children && node.children.length > 0) {                        for (const child of node.children) {                            checkNodeCode(child);                        }                    }                }                for (const topLevel of ledgerTree.children) {                    if (topLevel.node_type !== 1) continue;                    checkNodeCode(topLevel);                }                return error;            },            checkCalc: function (ledgerTree) {                const error = [];                for (const node of ledgerTree.nodes) {                    if (node.children && node.children.length > 0) continue;                    const nodePos = ledgerPos.getLedgerPos(node.id);                    if (!nodePos || nodePos.length === 0) continue;                    const checkData = {                        sgfh_qty: node.sgfh_qty || 0, qtcl_qty: node.qtcl_qty || 0, sjcl_qty: node.sjcl_qty || 0,                        quantity: node.quantity || 0                    };                    const calcData = {                        sgfh_qty: 0, qtcl_qty: 0, sjcl_qty: 0,                        quantity: 0                    };                    for (const np of nodePos) {                        calcData.sgfh_qty = ZhCalc.add(calcData.sgfh_qty, np.sgfh_qty) || 0;                        calcData.qtcl_qty = ZhCalc.add(calcData.qtcl_qty, np.qtcl_qty) || 0;                        calcData.sjcl_qty = ZhCalc.add(calcData.sjcl_qty, np.sjcl_qty) || 0;                        calcData.quantity = ZhCalc.add(calcData.quantity, np.quantity) || 0;                    }                    if (!_.isMatch(checkData, calcData)) error.push(node);                }                return error;            },            checkZero: function (ledgerTree) {                const error = [];                for (const node of ledgerTree.nodes) {                    if ((!node.b_code || node.b_code === '')) continue;                    if (node.children && node.children.length > 0) continue;                    if ((checkZero(node.sgfh_qty) && checkZero(node.qtcl_qty) && checkZero(node.sjcl_qty)                        && checkZero(node.deal_qty) && checkZero(node.quantity))                        || checkZero(node.unit_price)) error.push(node);                }                return error;            },        };        const assignWarningData = function (nodes, checkType, warningData) {            for (const node of nodes) {                warningData.push({                    type: checkType,                    ledger_id: node.ledger_id,                    code: node.code,                    b_code: node.b_code,                    name: node.name,                })            }        }        const checkData = function () {            $('#ledger-check-begin').hide();            $('#ledger-check-waiting').show();            const checkData = {                check_time: new Date(),                warning_data: [],            }            const sibling = doSomeCheck('#check-sibling', ledgerCheckUtil.checkSibling) || [];            assignWarningData(sibling, ledgerCheckType.sibling.value, checkData.warning_data);            const empty_code = doSomeCheck('#check-empty-code', ledgerCheckUtil.checkCodeEmpty) || [];            assignWarningData(empty_code, ledgerCheckType.empty_code.value, checkData.warning_data);            const calc = doSomeCheck('#check-calc', ledgerCheckUtil.checkCalc) || [];            assignWarningData(calc, ledgerCheckType.calc.value, checkData.warning_data);            const zero = doSomeCheck('#check-zero', ledgerCheckUtil.checkZero) || [];            assignWarningData(zero, ledgerCheckType.zero.value, checkData.warning_data);            $('#ledger-check-waiting').hide();            setting.checkList.clearCheckData();            if (checkData.warning_data.length > 0) {                $('#ledger-check-hint').removeClass('text-success').addClass('text-warning').html('检查完成,发现问题,请查阅检查结果。').show();                $('#ledger-check-show').show();                setting.checkList.loadCheckData(checkData);            } else {                setting.checkList.hide();                $('#ledger-check-show').hide();                $('#ledger-check-hint').html('检查完成,没有任何问题。').show();            }        }        $('#ledger-check-begin').bind('click', checkData);        $('#ledger-check-modal').bind('show.bs.modal', initWaitingModal);        $('#ledger-check-show').bind('click', function () {            $('#ledger-check-modal').modal('hide');            setting.checkList.show();        });    }</script>
 |