Browse Source

部位台账,计算补差

MaiXinRong 2 years ago
parent
commit
d455ab43a3
2 changed files with 27 additions and 7 deletions
  1. 21 6
      app/lib/bills_pos_convert.js
  2. 6 1
      app/view/stage/bwtz.ejs

+ 21 - 6
app/lib/bills_pos_convert.js

@@ -19,7 +19,7 @@ class BillsPosConvert {
         this.ctx = ctx;
         this._ = this.ctx.helper._;
 
-        this.tpFields = ['total_price', 'contract_tp', 'qc_tp', 'gather_tp',
+        this.tpFields = ['total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp',
             'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp'];
         this.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'];
@@ -85,6 +85,8 @@ class BillsPosConvert {
         node.quantity = this.ctx.helper.add(node.quantity, data.quantity);
         node.total_price = this.ctx.helper.add(node.total_price, this.ctx.helper.mul(node.unit_price, data.quantity, tpDecimal));
 
+        const org_price = node.org_price || node.unit_price;
+
         node.contract_qty = this.ctx.helper.add(node.contract_qty, data.contract_qty);
         node.contract_tp = this.ctx.helper.add(node.contract_tp, this.ctx.helper.mul(node.unit_price, data.contract_qty, tpDecimal));
         node.qc_qty = this.ctx.helper.add(node.qc_qty, data.qc_qty);
@@ -92,9 +94,9 @@ class BillsPosConvert {
         node.gather_qty = this.ctx.helper.add(node.gather_qty, data.gather_qty);
 
         node.pre_contract_qty = this.ctx.helper.add(node.pre_contract_qty, data.pre_contract_qty);
-        node.pre_contract_tp = this.ctx.helper.add(node.pre_contract_tp, this.ctx.helper.mul(node.unit_price, data.pre_contract_qty, tpDecimal));
+        node.pre_contract_tp = this.ctx.helper.add(node.pre_contract_tp, this.ctx.helper.mul(org_price, data.pre_contract_qty, tpDecimal));
         node.pre_qc_qty = this.ctx.helper.add(node.pre_qc_qty, data.pre_qc_qty);
-        node.pre_qc_tp = this.ctx.helper.add(node.pre_qc_tp, this.ctx.helper.mul(node.unit_price, data.pre_qc_qty, tpDecimal));
+        node.pre_qc_tp = this.ctx.helper.add(node.pre_qc_tp, this.ctx.helper.mul(org_price, data.pre_qc_qty, tpDecimal));
         node.pre_gather_qty = this.ctx.helper.add(node.pre_gather_qty, data.pre_gather_qty);
 
         node.real_qty = this.ctx.helper.add(node.real_qty, data.real_qty);
@@ -111,6 +113,7 @@ class BillsPosConvert {
         node.qc_qty = this.ctx.helper.add(node.qc_qty, data.qc_qty);
         node.qc_tp = this.ctx.helper.add(node.qc_tp, data.qc_tp);
         node.gather_qty = this.ctx.helper.add(node.gather_qty, data.gather_qty);
+        node.gather_tp = this.ctx.helper.add(node.gather_tp, data.gather_tp);
 
         node.pre_contract_qty = this.ctx.helper.add(node.pre_contract_qty, data.pre_contract_qty);
         node.pre_contract_tp = this.ctx.helper.add(node.pre_contract_tp, data.pre_contract_tp);
@@ -142,7 +145,7 @@ class BillsPosConvert {
                 if (p.ex_memo3) posUnit.ex_memo3.push(p.ex_memo3);
 
                 const gclUnit = xmj.unitTree.addNode({pos_name: '',
-                    b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price
+                    b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price, org_price: node.org_price,
                 }, posUnit);
                 if (node.drawing_code && gclUnit.drawing_code.indexOf(node.drawing_code) < 0)
                     gclUnit.drawing_code.push(node.drawing_code);
@@ -164,7 +167,7 @@ class BillsPosConvert {
         } else {
             const unit = xmj.unitTree.addNode({
                 pos_name: '',
-                b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price,
+                b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price, org_price: node.org_price,
             });
             if (node.drawing_code && unit.drawing_code.indexOf(node.drawing_code) < 0)
                 unit.drawing_code.push(node.drawing_code);
@@ -248,12 +251,24 @@ class BillsPosConvert {
         child.final_1_tp = this.ctx.helper.mul(child.unit_price, child.final_1_qty, tpDecimal);
         child.end_final_1_tp = this.ctx.helper.add(child.final_1_tp, child.end_qc_tp);
         child.end_final_1_percent = this.ctx.helper.mul(this.ctx.helper.div(child.end_gather_tp, child.end_final_1_tp, 4), 100);
+
+        const priceDiff = child.org_price ? this.ctx.helper.sub(child.unit_price, child.org_price) : 0;
+        if (priceDiff && (child.pre_contract_qty || child.pre_qc_qty)) {
+            child.contract_pc_tp = this.ctx.helper.sub(this.ctx.helper.mul(child.unit_price, child.pre_contract_qty, this.ctx.tender.info.decimal.tp), child.pre_contract_tp);
+            child.qc_pc_tp = this.ctx.helper.sub(this.ctx.helper.mul(child.unit_price, child.pre_qc_qty, this.ctx.tender.info.decimal.tp), child.pre_qc_tp);
+            child.pc_tp = this.ctx.helper.add(child.contract_pc_tp, child.qc_pc_tp);
+            child.gather_tp = this.ctx.helper.add(child.gather_tp, child.pc_tp);
+            child.end_contract_tp = this.ctx.helper.add(child.end_contract_tp, child.contract_pc_tp);
+            child.end_qc_tp = this.ctx.helper.add(child.end_qc_tp, child.qc_pc_tp);
+            child.end_gather_tp = this.ctx.helper.add(child.end_contract_tp, child.end_qc_tp);
+        }
     }
     _calculateNode(node, children) {
         for (const child of children) {
             node.total_price = this.ctx.helper.add(node.total_price, child.total_price);
             node.contract_tp = this.ctx.helper.add(node.contract_tp, child.contract_tp);
             node.qc_tp = this.ctx.helper.add(node.qc_tp, child.qc_tp);
+            node.pc_tp = this.ctx.helper.add(node.pc_tp, child.pc_tp);
             node.gather_tp = this.ctx.helper.add(node.gather_tp, child.gather_tp);
             node.pre_contract_tp = this.ctx.helper.add(node.pre_contract_tp, child.pre_contract_tp);
             node.pre_qc_tp = this.ctx.helper.add(node.pre_qc_tp, child.pre_qc_tp);
@@ -372,7 +387,7 @@ class BillsPosConvert {
         switch (filter) {
             case 'cur':
                 return this._getResultData(function (node) {
-                    for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
+                    for (const field of ['contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp']) {
                         if (node[field]) {
                             return false;
                         }

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

@@ -163,8 +163,9 @@
             {title: '现场实际金额', colSpan: '1', rowSpan: '2', field: 'real_tp', hAlign: 2, width: 60, type: 'Number'},
             {title: '预计变更金额', colSpan: '1', rowSpan: '2', field: 'estimate_tp', hAlign: 2, width: 60, type: 'Number'},
             <% } %>
-            {title: '本期计量金额|合同计量', colSpan: '3|1', rowSpan: '1|1', field: 'contract_tp', hAlign: 2, width: 70, type: 'Number'},
+            {title: '本期计量金额|合同计量', colSpan: '4|1', rowSpan: '1|1', field: 'contract_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 70, type: 'Number'},
+            {title: '|补差', colSpan: '|1', rowSpan: '|1', field: 'pc_tp', hAlign: 2, width: 70, type: 'Number', visible: <%- ctx.tender.info.display.stage.priceDiff %> },
             {title: '|完成计量', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '截止本期计量金额|合同计量', colSpan: '4|1', rowSpan: '1|1', field: 'end_contract_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 70, type: 'Number'},
@@ -236,6 +237,10 @@
             {title: '本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
             {title: '|变更令', colSpan: '|1', rowSpan: '|1', field: 'bgl_code', hAlign: 2, width: 60, formatter: '@', cellType: 'ellipsisAutoTip'},
+            <% if ( ctx.tender.info.display.stage.priceDiff ) { %>
+            { title: '本期补差|原单价', colSpan: '2|1', rowSpan: '1|1', field: 'org_price', hAlign: 2, width: 60, type: 'Number', /*getValue(data) { return data.pc_tp ? data.org_price : null},*/  },
+            { title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'pc_tp', hAlign: 2, width: 60, type: 'Number' },
+            <% } %>
             {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
             {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},