瀏覽代碼

中间计量问题

MaiXinRong 5 年之前
父節點
當前提交
83a5703674
共有 1 個文件被更改,包括 37 次插入15 次删除
  1. 37 15
      app/public/js/stage_im.js

+ 37 - 15
app/public/js/stage_im.js

@@ -445,6 +445,31 @@ const stageIm = (function () {
         }
     }
 
+    function addBwBillsGclBills(im, bills) {
+        if (!im.gclBills) im.gclBills = [];
+        let gcl = im.gclBills.find(function (x) {
+            return (!bills.b_code || bills.b_code === x.b_code) &&
+                (!bills.name || bills.name === x.name) &&
+                (!bills.unit || bills.unit === x.unit) &&
+                checkZero(ZhCalc.sub(bills.unit_price, x.unit_price));
+        });
+        if (!gcl) {
+            gcl = {b_code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.unit_price};
+            im.gclBills.push(gcl);
+        }
+        gcl.contract_jl = ZhCalc.add(gcl.contract_jl, bills.contract_jl);
+        gcl.qc_jl = ZhCalc.add(gcl.qc_jl, bills.qc_jl);
+        gcl.jl = ZhCalc.add(gcl.jl, bills.jl);
+    }
+    function calculateBwBillsIm(im) {
+        im.contract_jl = 0;
+        im.qc_jl = 0;
+        for (const b of im.gclBills) {
+            im.contract_jl = ZhCalc.add(im.contract_jl, ZhCalc.mul(b.contract_jl, b.unit_price, decimal.tp));
+            im.qc_jl = ZhCalc.add(im.qc_jl, ZhCalc.mul(b.qc_jl, b.unit_price, decimal.tp));
+        }
+        im.jl = ZhCalc.add(im.contract_jl, im.qc_jl);
+    }
     function generateBwBillsImData (node) {
         if (node.gather_tp) {
             const nodeIndex = gsTree.getNodeIndex(node);
@@ -491,18 +516,13 @@ const stageIm = (function () {
                                 im.changes.push(c);
                             }
                         }
+                        addBwBillsGclBills(im, {
+                            b_code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price,
+                            jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty
+                        });
 
-                        im.jl = ZhCalc.add(im.jl, ZhCalc.mul(pp.gather_qty, p.unit_price, decimal.tp));
-                        im.contract_jl = ZhCalc.add(im.contract_jl, ZhCalc.mul(pp.contract_qty, p.unit_price, decimal.tp));
-                        im.qc_jl = ZhCalc.add(im.qc_jl, ZhCalc.mul(pp.qc_qty, p.unit_price, decimal.tp));
                         if (pp.drawing_code) im.drawing_code.push(pp.drawing_code);
                         if (pp.position) im.position.push(pp.position);
-
-                        im.gclBills.push({
-                            bid: p.id,
-                            b_code: p.b_code, name: p.name, unit: p.unit,
-                            jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty
-                        });
                     }
                 } else {
                     for (const c of changes) {
@@ -511,21 +531,23 @@ const stageIm = (function () {
                         }
                     }
 
-                    imDefault.jl = ZhCalc.add(imDefault.jl, p.gather_qty);
                     imDefault.contract_jl = ZhCalc.add(imDefault.contract_jl, p.contract_qty);
                     imDefault.qc_jl = ZhCalc.add(imDefault.qc_jl, p.qc_qty);
 
-                    imDefault.gclBills.push({
-                        bid: p.id,
-                        b_code: p.b_code, name: p.name, unit: p.unit,
-                        jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty
+                    addBwBillsGclBills(imDefault, {
+                        b_code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price,
+                        jl: p.gather_qty ? p.gather_qty : p.gather_tp,
+                        contract_jl: p.contract_qty ? p.contract_qty : p.contract_tp,
+                        qc_jl: p.qc_qty ? p.qc_qty : p.tp,
                     });
                 }
             }
-            if (imDefault.jl) {
+            if (imDefault.contract_jl || imDefault.qc_jl) {
+                imDefault.jl = ZhCalc.add(imDefault.contract_jl, imDefault.qc_jl);
                 ImData.push(imDefault);
             }
             for (const im of nodeImData) {
+                calculateBwBillsIm(im);
                 im.drawing_code = im.drawing_code.join(mergeChar);
                 im.position = im.position.join(mergeChar);
                 ImData.push(im);