فهرست منبع

1. 部位台账,计量单元-计量清单,增加排序
2. 部位台账, 金额计算方式调整

MaiXinRong 5 سال پیش
والد
کامیت
f80b6c7e05
4فایلهای تغییر یافته به همراه106 افزوده شده و 18 حذف شده
  1. 30 0
      app/public/js/path_tree.js
  2. 74 17
      app/public/js/shares/bills_pos_convert.js
  3. 1 1
      app/public/js/stage_bwtz.js
  4. 1 0
      app/view/stage/bwtz.ejs

+ 30 - 0
app/public/js/path_tree.js

@@ -1332,6 +1332,36 @@ const createNewPathTree = function (type, setting) {
             }
             return item;
         }
+
+        sortTreeNodeCustom(field, fun, isResort) {
+            const self = this;
+            const sortNodes = function (nodes) {
+                nodes.sort(function (a, b) {
+                    return fun(a[field], b[field]);
+                });
+                for (const [i, node] of nodes.entries()) {
+                    node.order = i+1;
+                }
+            };
+            const addSortNodes = function (nodes) {
+                if (!nodes) { return }
+                for (let i = 0; i < nodes.length; i++) {
+                    self.nodes.push(nodes[i]);
+                    nodes[i].index = self.nodes.length - 1;
+                    if (!isResort) {
+                        nodes[i].children = self.getChildren(nodes[i]);
+                    }
+                    sortNodes(nodes[i].children);
+                    addSortNodes(nodes[i].children);
+                }
+            };
+            this.nodes = [];
+            if (!isResort) {
+                this.children = this.getChildren();
+            }
+            sortNodes(this.children);
+            addSortNodes(this.children);
+        }
     }
 
     if (type === 'base') {

+ 74 - 17
app/public/js/shares/bills_pos_convert.js

@@ -10,8 +10,8 @@
 
 const billsPosConvertModel = (function () {
     // 需要汇总计算的字段
-    const tpFields = ['total_price', 'contract_tp', 'qc_tp',
-        'pre_contract_tp', 'pre_qc_tp', 'end_contract_tp', 'end_qc_tp'];
+    const tpFields = ['total_price', 'contract_tp', 'qc_tp', 'gather_tp',
+        'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp'];
     const baseCalcFields = ['quantity', 'contract_qty', 'qc_qty', 'gather_qty',
         'pre_contract_qty', 'pre_qc_qty', 'pre_gather_qty', 'end_contract_qty', 'end_qc_qty', 'end_gather_qty'];
     // 基础数据
@@ -31,7 +31,7 @@ const billsPosConvertModel = (function () {
         updateFields: ['contract_qty', 'qc_qty'],
     };
     const bpcPos = new StagePosData(bpcPosSetting);
-    let bpcChange;
+    let bpcChange, tpDecimal;
 
     // 结果
     const resultTreeSetting = {
@@ -52,21 +52,46 @@ const billsPosConvertModel = (function () {
     function loadPosData(pos) {
         bpcPos.loadDatas(pos);
     }
-    function loadData(ledger, pos, change) {
+    function loadData(ledger, pos, change, decimal) {
         loadLedgerData(ledger);
         loadPosData(pos);
         bpcChange = change;
+        tpDecimal = decimal;
     }
 
     function convertXmj(node) {
         return resultTree.addData(node, ['ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
             'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'drawing_code', 'postil', 'memo']);
     }
+    // v1
     function loadField(node, data, fields) {
         for (const prop in data) {
             if (fields.indexOf(prop) >= 0) node[prop] = data[prop];
         }
     }
+    // v2
+    function loadCalcFields(node, data) {
+        node.quantity = ZhCalc.add(node.quantity, data.quantity);
+        node.total_price = ZhCalc.add(node.total_price, ZhCalc.mul(node.unit_price, data.quantity, tpDecimal));
+
+        node.contract_qty = ZhCalc.add(node.contract_qty, data.contract_qty);
+        node.contract_tp = ZhCalc.add(node.contract_tp, ZhCalc.mul(node.unit_price, data.contract_qty, tpDecimal));
+        node.qc_qty = ZhCalc.add(node.qc_qty, data.qc_qty);
+        node.qc_tp = ZhCalc.add(node.qc_tp, ZhCalc.mul(node.unit_price, data.qc_qty, tpDecimal));
+        node.gather_qty = ZhCalc.add(node.gather_qty, data.gather_qty);
+
+        node.pre_contract_qty = ZhCalc.add(node.pre_contract_qty, data.pre_contract_qty);
+        node.pre_contract_tp = ZhCalc.add(node.pre_contract_tp, ZhCalc.mul(node.unit_price, data.pre_contract_qty, tpDecimal));
+        node.pre_qc_qty = ZhCalc.add(node.pre_qc_qty, data.pre_qc_qty);
+        node.pre_qc_tp = ZhCalc.add(node.pre_qc_tp, ZhCalc.mul(node.unit_price, data.pre_qc_qty, tpDecimal));
+        node.pre_gather_qty = ZhCalc.add(node.pre_gather_qty, data.pre_gather_qty);
+
+        node.end_contract_qty = ZhCalc.add(node.end_contract_qty, data.end_contract_qty);
+        node.end_contract_tp = ZhCalc.add(node.end_contract_tp, ZhCalc.mul(node.unit_price, data.end_contract_qty, tpDecimal));
+        node.end_qc_qty = ZhCalc.add(node.end_qc_qty, data.end_qc_qty);
+        node.end_qc_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.unit_price, data.end_qc_qty, tpDecimal));
+        node.end_gather_qty = ZhCalc.add(node.end_gather_qty, data.end_gather_qty);
+    }
     function convertGcl(node, xmj) {
         if (!xmj) return;
 
@@ -81,7 +106,8 @@ const billsPosConvertModel = (function () {
                 const gclUnit = xmj.unitTree.addNode({pos_name: null,
                     b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price
                 }, posUnit);
-                loadField(gclUnit, p, baseCalcFields);
+                //loadField(gclUnit, p, baseCalcFields);
+                loadCalcFields(gclUnit, p);
                 if (!gclUnit.changes) gclUnit.changes = [];
                 for (const c of bpcChange) {
                     if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
@@ -92,7 +118,8 @@ const billsPosConvertModel = (function () {
         } else {
             const unit = xmj.unitTree.addNode({pos_name: null,
                 b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price});
-            loadField(unit, node, baseCalcFields);
+            //loadField(unit, node, baseCalcFields);
+            loadCalcFields(unit, node);
             if (!unit.changes) unit.changes = [];
             for (const c of bpcChange) {
                 if (c.lid === node.id && c.pid == -1 && c.qty && c.qty !== 0) {
@@ -124,16 +151,22 @@ const billsPosConvertModel = (function () {
         node.end_qc_qty = ZhCalc.add(node.qc_qty, node.pre_qc_qty);
         node.end_gather_qty = ZhCalc.add(node.gather_qty, node.pre_gather_qty);
 
-        node.total_price = ZhCalc.mul(node.unit_price, node.quantity);
-        node.contract_tp = ZhCalc.mul(node.unit_price, node.contract_qty);
-        node.qc_tp = ZhCalc.mul(node.unit_price, node.qc_qty);
-        node.gather_tp = ZhCalc.mul(node.unit_price, node.gather_qty);
-        node.pre_contract_tp = ZhCalc.mul(node.unit_price, node.pre_contract_qty);
-        node.pre_qc_tp = ZhCalc.mul(node.unit_price, node.pre_qc_qty);
-        node.pre_gather_tp = ZhCalc.mul(node.unit_price, node.pre_gather_qty);
-        node.end_contract_tp = ZhCalc.mul(node.unit_price, node.end_contract_qty);
-        node.end_qc_tp = ZhCalc.mul(node.unit_price, node.end_qc_qty);
-        node.end_gather_tp = ZhCalc.mul(node.unit_price, node.end_gather_qty);
+        // v1
+        // node.total_price = ZhCalc.mul(node.unit_price, node.quantity, tpDecimal);
+        // node.contract_tp = ZhCalc.mul(node.unit_price, node.contract_qty, tpDecimal);
+        // node.qc_tp = ZhCalc.mul(node.unit_price, node.qc_qty, tpDecimal);
+        // node.gather_tp = ZhCalc.mul(node.unit_price, node.gather_qty, tpDecimal);
+        // node.pre_contract_tp = ZhCalc.mul(node.unit_price, node.pre_contract_qty, tpDecimal);
+        // node.pre_qc_tp = ZhCalc.mul(node.unit_price, node.pre_qc_qty, tpDecimal);
+        // node.pre_gather_tp = ZhCalc.mul(node.unit_price, node.pre_gather_qty, tpDecimal);
+        // node.end_contract_tp = ZhCalc.mul(node.unit_price, node.end_contract_qty, tpDecimal);
+        // node.end_qc_tp = ZhCalc.mul(node.unit_price, node.end_qc_qty, tpDecimal);
+        // node.end_gather_tp = ZhCalc.mul(node.unit_price, node.end_gather_qty, tpDecimal);
+
+        // v2
+        node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
+        node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
+        node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
 
         node.final_tp = ZhCalc.add(node.total_price, node.end_qc_tp);
         node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.final_tp, 4), 100);
@@ -174,7 +207,31 @@ const billsPosConvertModel = (function () {
         for (const node of nodes) {
             recursiveCalculateAndSort(node.children);
             if (node.unitTree) {
-                node.unitTree.sortTreeNode();
+                node.unitTree.sortTreeNodeCustom('b_code', function (a, b) {
+                    function compareCode(code1, code2) {
+                        if (numReg.test(code1)) {
+                            if (numReg.test(code2)) {
+                                return _.toNumber(code1) - _.toNumber(code2);
+                            } else {
+                                return -1
+                            }
+                        } else {
+                            if (numReg.test(code2)) {
+                                return 1;
+                            } else {
+                                return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1);
+                            }
+                        }
+                    }
+                    const numReg = /^[0-9]+$/;
+                    const aCodes = a ? a.split('-') : [], bCodes = b ? b.split('-') : [];
+                    for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {
+                        const iCompare = compareCode(aCodes[i], bCodes[i]);
+                        if (iCompare !== 0) {
+                            return iCompare;
+                        }
+                    }
+                }, false);
                 recursiveCalcUnitNodes(node.unitTree.children);
                 calculateNode(node, node.unitTree.children, tpFields);
             } else if (node.children && node.children.length > 0) {

+ 1 - 1
app/public/js/stage_bwtz.js

@@ -32,7 +32,7 @@ $(document).ready(() => {
     xmjSpread.bind(spreadNS.Events.SelectionChanged, unitTreeObj.loadCurUnitData);
 
     postData(preUrl + '/load', { filter: 'ledger;pos;change' }, function (result) {
-        billsPosConvertModel.loadData(result.ledgerData, result.posData, result.changeData);
+        billsPosConvertModel.loadData(result.ledgerData, result.posData, result.changeData, decimal);
         const xmjTree = billsPosConvertModel.convert();
         SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
         unitTreeObj.loadCurUnitData();

+ 1 - 0
app/view/stage/bwtz.ejs

@@ -98,4 +98,5 @@
         font: '12px 微软雅黑',
         readOnly: true,
     };
+    const decimal = <%- ctx.tender.info.decimal.tp %>;
 </script>