Forráskód Böngészése

单价调整,本期合同计量,总价计算相关

MaiXinRong 3 hete
szülő
commit
d346b5e905
1 módosított fájl, 29 hozzáadás és 10 törlés
  1. 29 10
      app/lib/revise_price.js

+ 29 - 10
app/lib/revise_price.js

@@ -61,6 +61,15 @@ class revisePriceCalc {
         return p;
     }
 
+    _calcContractTpByTp(bills, decimal) {
+        let activeQty = this.ctx.helper.add(bills.quantity, bills.qc_minus_qty);
+        let end_contract_qty = bills.cur_contract_qty;
+        activeQty = this.ctx.helper.add(activeQty, bills.pre_qc_minus_qty);
+        end_contract_qty = this.ctx.helper.add(end_contract_qty, bills.pre_contract_qty);
+        const end_contract_tp = this.ctx.helper.mul(this.ctx.helper.div(end_contract_qty, activeQty), bills.total_price, decimal.tp);
+        return this.ctx.helper.sub(end_contract_tp, bills.pre_contract_tp);
+    }
+
     /**
      * 新增一期计量,检查单价调整
      * @param {Object} newStage - 新计量期
@@ -79,7 +88,7 @@ class revisePriceCalc {
         // 加载树结构
         const bills = await this.ctx.service.ledger.getData(newStage.tid);
         this.ctx.helper.assignRelaData(bills, [
-            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty', 'positive_qc_tp', 'negative_qc_tp'], prefix: 'pre_', relaId: 'lid' },
+            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty', 'positive_qc_tp', 'negative_qc_tp', 'qc_minus_qty'], prefix: 'pre_', relaId: 'lid' },
         ]);
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
@@ -95,7 +104,9 @@ class revisePriceCalc {
             if (node.children && node.children.length > 0) return;
             const priceDiff = helper.sub(node.unit_price, node.pre_unit_price);
             if (!priceDiff) return;
-            node.contract_pc_tp = calcType === 'up' ? helper.sub(helper.mul(node.pre_contract_qty, node.unit_price, decimal.tp), node.pre_contract_tp) : 0;
+            node.contract_pc_tp = calcType === 'up'
+                ? helper.sub(helper.mul(node.pre_contract_qty, node.unit_price, decimal.tp), node.pre_contract_tp)
+                : 0;
             node.qc_pc_tp = helper.sub(helper.mul(node.pre_qc_qty, node.unit_price, decimal.tp), node.pre_qc_tp);
             node.pc_tp = helper.add(node.contract_pc_tp, node.qc_pc_tp);
             node.positive_qc_pc_tp = helper.sub(helper.mul(node.pre_positive_qc_qty, node.unit_price, decimal.tp), node.pre_positive_qc_tp);
@@ -138,8 +149,8 @@ class revisePriceCalc {
         // 加载树结构
         const bills = await this.ctx.service.ledger.getData(stage.tid);
         this.ctx.helper.assignRelaData(bills, [
-            { data: curBillsData, fields: ['id', 'contract_qty', 'qc_qty', 'positive_qc_qty', 'negative_qc_qty', 'postil', 'times', 'order', 'ex_stage_qty1'], prefix: 'cur_', relaId: 'lid' },
-            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty', 'positive_qc_tp', 'negative_qc_tp'], prefix: 'pre_', relaId: 'lid' },
+            { data: curBillsData, fields: ['id', 'contract_qty', 'qc_qty', 'positive_qc_qty', 'negative_qc_qty', 'postil', 'times', 'order', 'ex_stage_qty1', 'qc_minus_qty'], prefix: 'cur_', relaId: 'lid' },
+            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty', 'positive_qc_tp', 'negative_qc_tp', 'qc_minus_qty'], prefix: 'pre_', relaId: 'lid' },
         ]);
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
@@ -152,12 +163,15 @@ class revisePriceCalc {
         const decimal = this.ctx.tender.info.decimal;
         const said = this.ctx.session.sessionUser.accountId;
         const calcType = this.ctx.tender.info.calc_type;
+        const self = this;
         billsTree.calculateAll(node => {
             if (node.children && node.children.length > 0) return;
             // const priceDiff = helper.sub(node.unit_price, node.pre_unit_price);
             // if (!priceDiff) return;
             if (node.cur_id && (node.cur_contract_qty || node.cur_qc_qty || node.cur_ex_stage_qty1)) {
-                const cur_contract_tp = calcType === 'up' ? helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp) : node.cur_contract_tp;
+                const cur_contract_tp = calcType === 'up'
+                    ? helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp)
+                    : self._calcContractTpByTp(node, decimal);
                 const cur_qc_tp = helper.mul(node.cur_qc_qty, node.unit_price, decimal.tp);
                 const cur_positive_qc_tp = helper.mul(node.cur_positive_qc_qty, node.unit_price, decimal.tp);
                 const cur_negative_qc_tp = helper.mul(node.cur_negative_qc_qty, node.unit_price, decimal.tp);
@@ -369,8 +383,8 @@ class revisePriceCalc {
 
         // 加载树结构
         this.ctx.helper.assignRelaData(bills, [
-            { data: curBillsData, fields: ['id', 'contract_qty', 'qc_qty', 'positive_qc_qty', 'negative_qc_qty', 'times', 'order', 'postil', 'ex_stage_qty1', 'ex_stage_tp1'], prefix: 'cur_', relaId: 'lid' },
-            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty', 'positive_qc_tp', 'negative_qc_tp'], prefix: 'pre_', relaId: 'lid' },
+            { data: curBillsData, fields: ['id', 'contract_qty', 'qc_qty', 'positive_qc_qty', 'negative_qc_qty', 'times', 'order', 'postil', 'ex_stage_qty1', 'ex_stage_tp1', 'qc_minus_qty'], prefix: 'cur_', relaId: 'lid' },
+            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty', 'positive_qc_tp', 'negative_qc_tp', 'qc_minus_qty'], prefix: 'pre_', relaId: 'lid' },
         ], 'id', true);
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
@@ -385,7 +399,9 @@ class revisePriceCalc {
         billsTree.calculateAll(node => {
             if (node.children && node.children.length > 0) return;
             if (node.cur_id && (node.cur_contract_qty || node.cur_qc_qty || node.cur_ex_stage_qty1)) {
-                const cur_contract_tp = calcType === 'up' ? helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp) : node.cur_contract_tp;
+                const cur_contract_tp = calcType === 'up'
+                    ? helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp)
+                    : self._calcContractTpByTp(node, decimal);
                 const cur_qc_tp = helper.mul(node.cur_qc_qty, node.unit_price, decimal.tp);
                 const cur_positive_qc_tp = helper.mul(node.cur_positive_qc_qty, node.unit_price, decimal.tp);
                 const cur_negative_qc_tp = helper.mul(node.cur_negative_qc_qty, node.unit_price, decimal.tp);
@@ -456,7 +472,7 @@ class revisePriceCalc {
 
         // 加载树结构
         this.ctx.helper.assignRelaData(bills, [
-            { data: curBillsData, fields: ['id', 'contract_qty', 'qc_qty', 'positive_qc_qty', 'negative_qc_qty', 'times', 'order', 'postil'], prefix: 'cur_', relaId: 'lid' },
+            { data: curBillsData, fields: ['id', 'contract_qty', 'qc_qty', 'positive_qc_qty', 'negative_qc_qty', 'times', 'order', 'postil', 'qc_minus_qty'], prefix: 'cur_', relaId: 'lid' },
         ], 'id', true);
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
@@ -468,10 +484,13 @@ class revisePriceCalc {
         const decimal = this.ctx.tender.info.decimal;
         const said = this.ctx.session.sessionUser.accountId;
         const calcType = this.ctx.tender.info.calc_type;
+        const self = this;
         billsTree.calculateAll(node => {
             if (node.children && node.children.length > 0) return;
             if (node.cur_id && (node.cur_contract_qty || node.cur_qc_qty)) {
-                const cur_contract_tp = calcType === 'up' ? helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp) : node.cur_contract_tp;
+                const cur_contract_tp = calcType === 'up'
+                    ? helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp)
+                    : self._calcContractTpByTp(node, decimal);
                 const cur_qc_tp = helper.mul(node.cur_qc_qty, node.unit_price, decimal.tp);
                 const cur_positive_qc_tp = helper.mul(node.cur_positive_qc_qty, node.unit_price, decimal.tp);
                 const cur_negative_qc_tp = helper.mul(node.cur_negative_qc_qty, node.unit_price, decimal.tp);