Browse Source

修复清单明细本期价差计算bug

ellisran 1 year ago
parent
commit
85e4515580
2 changed files with 38 additions and 22 deletions
  1. 37 21
      app/public/js/material_list.js
  2. 1 1
      app/view/material/list.ejs

+ 37 - 21
app/public/js/material_list.js

@@ -68,20 +68,34 @@ function calcOneBQJC(xmj) {
     const notx = findNotJoinLeafXmj(xmj);
     if (notx === undefined) {
         const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
-        const notx2 = findNotChangeLeafXmj(xmj);
-        if (notx2 !== undefined) {
-            for (const l of list) {
-                jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.contract_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
-            }
-        } else {
-            for (const l of list) {
-                jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
-            }
+        // const notx2 = findNotChangeLeafXmj(xmj);
+        // if (notx2 !== undefined) {
+        //     for (const l of list) {
+        //         jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.contract_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
+        //     }
+        // } else {
+        for (const l of list) {
+            jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(calcQty(xmj, l.is_join), l.quantity), getMpSpreadByMBData(l.mb_id)));
         }
+        // }
     }
     return ZhCalc.round(jiacha, materialDecimal.tp);
 }
 
+function calcQty(info, is_join) {
+    let qty = '';
+    switch (qtySource) {
+        case qtySourceValueConst.gather_qty: qty = info.gather_qty; break;
+        case qtySourceValueConst.contract_qty: qty = info.contract_qty; break;
+        case qtySourceValueConst.gather_minus_qty: qty = ZhCalc.add(info.gather_qty, info.qc_minus_qty); break;
+        default: throw '未配置计量来源出错';
+    }
+    if (qtySource !== qtySourceValueConst.contract_qty && is_join === 2) {
+        qty = ZhCalc.sub(qty, info.qc_qty);
+    }
+    return qty;
+}
+
 function getPasteHint (str, row = '') {
     let returnObj = str;
     if (row) {
@@ -173,13 +187,13 @@ $(document).ready(() => {
         {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
         {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
     ];
-    if (materialQtySource === 1) {
+    if (qtySource === qtySourceValueConst.gather_qty) {
         ledgerCols.push({title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
         ledgerCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'});
         ledgerCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'});
-    } else if (materialQtySource === 2) {
+    } else if (qtySource === qtySourceValueConst.contract_qty) {
         ledgerCols.push({title: '本期计量数量|合同', colSpan: '1|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
-    } else if (materialQtySource === 3) {
+    } else if (qtySource === qtySourceValueConst.gather_minus_qty) {
         ledgerCols.push({title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
         ledgerCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'});
         ledgerCols.push({title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 110, type: 'Number'});
@@ -211,12 +225,12 @@ $(document).ready(() => {
     const ledgerCol = {
         getValue: {
             gather_qty: function (data) {
-                if (materialQtySource === qtySourceValueConst.gather_minus_qty) {
+                if (qtySource === qtySourceValueConst.gather_minus_qty) {
                     return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
                 }
             },
             gather_tp: function (data) {
-                if (materialQtySource === qtySourceValueConst.contract_qty) {
+                if (qtySource === qtySourceValueConst.contract_qty) {
                     return data.contract_tp;
                 } else {
                     return data.gather_tp;
@@ -262,13 +276,13 @@ $(document).ready(() => {
         {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
         {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
     ];
-    if (materialQtySource === 1) {
+    if (qtySource === qtySourceValueConst.gather_qty) {
         leafXmjCols.push({title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'});
         leafXmjCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'});
         leafXmjCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'});
-    } else if (materialQtySource === 2) {
+    } else if (qtySource === qtySourceValueConst.contract_qty) {
         leafXmjCols.push({title: '本期计量数量|合同', colSpan: '1|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 100, type: 'Number'});
-    } else if (materialQtySource === 3) {
+    } else if (qtySource === qtySourceValueConst.gather_minus_qty) {
         leafXmjCols.push({title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'});
         leafXmjCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'});
         leafXmjCols.push({title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 60, type: 'Number'});
@@ -317,7 +331,7 @@ $(document).ready(() => {
     const leafXmjCol = {
         getValue: {
             gather_qty: function (data) {
-                if (materialQtySource === 3) {
+                if (qtySource === qtySourceValueConst.gather_minus_qty) {
                     return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
                 }
             },
@@ -361,11 +375,13 @@ $(document).ready(() => {
                     updateBillsData(ms_id);
                     const newGclGatherListData = [];
                     for (const [index, s] of result.ledgerListData.entries()) {
+                        // gclGatherModel.clearGatherData();
                         gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
                         gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
                         const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
                             return item.qc_qty || item.contract_qty || item.qc_minus_qty
                         });
+                        console.log(oneGclGatherData);
                         newGclGatherListData.push(oneGclGatherData);
                     }
                     gclGatherListData = newGclGatherListData;
@@ -842,7 +858,7 @@ $(document).ready(() => {
                 const color = notx === undefined ? '' : '#d6d8db';
                 // leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
                 const notx2 = findNotChangeLeafXmj(x);
-                const color2 = notx2 === undefined || materialQtySource === qtySourceValueConst.contract_qty ? color : '#FFE699';
+                const color2 = notx2 === undefined || qtySource === qtySourceValueConst.contract_qty ? color : '#FFE699';
                 leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color2);
             }
         }
@@ -1187,7 +1203,7 @@ $(document).ready(() => {
                             if (!select || sel.rowCount !== 1) {
                                 return false;
                             }
-                            if (materialQtySource === qtySourceValueConst.contract_qty) {
+                            if (qtySource === qtySourceValueConst.contract_qty) {
                                 return false;
                             }
                             const notx = findNotJoinLeafXmj(select);
@@ -1215,7 +1231,7 @@ $(document).ready(() => {
                             if (!select || sel.rowCount !== 1) {
                                 return false;
                             }
-                            if (materialQtySource === qtySourceValueConst.contract_qty) {
+                            if (qtySource === qtySourceValueConst.contract_qty) {
                                 return false;
                             }
                             const notx = findNotJoinLeafXmj(select);

+ 1 - 1
app/view/material/list.ejs

@@ -109,7 +109,7 @@
     const stage_order = <%- material.order %>;
     const materialID = <%- material.id %>;
     const tenderID = <%- tender.id %>;
-    const materialQtySource = <%- material.qty_source %>;
+    const qtySource = <%- material.qty_source %>;
     const qtySourceValueConst = JSON.parse(unescape('<%- escape(JSON.stringify(qtySourceValueConst)) %>'));
     const materialIsNewQty = parseInt('<%- material.is_new_qty %>');
     const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));