瀏覽代碼

变更明细,记录调用时的单价

MaiXinRong 2 年之前
父節點
當前提交
b67a9245de
共有 4 個文件被更改,包括 33 次插入10 次删除
  1. 17 4
      app/lib/revise_price.js
  2. 6 4
      app/service/stage_change.js
  3. 1 1
      app/service/stage_change_final.js
  4. 9 1
      sql/update.sql

+ 17 - 4
app/lib/revise_price.js

@@ -108,8 +108,10 @@ class revisePriceCalc {
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
 
-        // 计算 insertBills billsPriceChange reCalcBillsCur/reCalcBillsPrice
-        const result = { ibData: [], bpcData: [] };
+        const stageChange = await this.ctx.service.stageChange.getFinalStageData(stage.tid, stage.id);
+
+        // 计算 insertBills billsPriceChange stageChange
+        const result = { ibData: [], bpcData: [], scData: [] };
         const helper = this.ctx.helper;
         const decimal = this.ctx.tender.info.decimal;
         const said = this.ctx.session.sessionUser.accountId;
@@ -140,10 +142,15 @@ class revisePriceCalc {
                     positive_qc_pc_tp: node.positive_qc_pc_tp, negative_qc_pc_tp: node.negative_qc_pc_tp,
                 });
             }
+            const scDetail = stageChange.filter(x => { return x.lid === node.id; });
+            for (const scd of scDetail) {
+                result.scData.push({ id: scd.id, unit_price: node.unit_price });
+            }
         });
         if (result.ibData.length > 0) await transaction.insert(this.ctx.service.stageBills.tableName, result.ibData);
         await transaction.delete(this.ctx.service.stageBillsPc.tableName, { sid: stage.id });
         if (result.bpcData.length > 0) await transaction.insert(this.ctx.service.stageBillsPc.tableName, result.bpcData);
+        if (result.scData.length > 0) await transaction.updateRows(this.ctx.service.stageChange.tableName, result.scData);
 
         let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0, positive_qc_pc_tp = 0, negative_qc_pc_tp = 0;
         for (const bpc of result.bpcData) {
@@ -212,9 +219,10 @@ class revisePriceCalc {
         ]);
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
+        const stageChange = await this.ctx.service.stageChange.getFinalStageData(stage.tid, stage.id);
 
-        // 计算 insertBills/updateBills billsPriceChange
-        const result = { ibData: [], ubData: [], bpcData: [] };
+        // 计算 insertBills/updateBills billsPriceChange StageChange
+        const result = { ibData: [], ubData: [], bpcData: [], scData: [] };
         const helper = this.ctx.helper;
         const decimal = this.ctx.tender.info.decimal;
         const said = this.ctx.session.sessionUser.accountId;
@@ -251,11 +259,16 @@ class revisePriceCalc {
                     positive_qc_pc_tp: node.positive_qc_pc_tp, negative_qc_pc_tp: node.negative_qc_pc_tp,
                 });
             }
+            const scDetail = stageChange.filter(x => { return x.lid === node.id; });
+            for (const scd of scDetail) {
+                result.scData.push({ id: scd.id, unit_price: node.unit_price });
+            }
         });
         if (result.ibData.length > 0) await transaction.insert(this.ctx.service.stageBills.tableName, result.ibData);
         if (result.ubData.length > 0) await transaction.updateRows(this.ctx.service.stageBills.tableName, result.ubData);
         await transaction.delete(this.ctx.service.stageBillsPc.tableName, { sid: stage.id });
         if (result.bpcData.length > 0) await transaction.insert(this.ctx.service.stageBillsPc.tableName, result.bpcData);
+        if (result.scData.length > 0) await transaction.updateRows(this.ctx.service.stageChange.tableName, result.scData);
 
         let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0, positive_qc_pc_tp = 0, negative_qc_pc_tp = 0;
         for (const bpc of result.bpcData) {

+ 6 - 4
app/service/stage_change.js

@@ -301,6 +301,7 @@ module.exports = app => {
                 if (!nc || nc.qty !== oc.qty) {
                     const qty = nc ? this.round(nc.qty, precision.value) : null;
                     const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus, noValue);
+                    change.unit_price = ledgerBills.unit_price;
                     billsQty = this.ctx.helper.add(billsQty, change.qty);
                     if (change.minus) {
                         billsNegativeQty = this.ctx.helper.add(billsNegativeQty, change.qty);
@@ -326,6 +327,7 @@ module.exports = app => {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 if (!nc) {
                     const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus, noValue);
+                    change.unit_price = ledgerBills.unit_price;
                     billsQty = this.ctx.helper.add(billsQty, change.qty);
                     if (change.minus) {
                         billsNegativeQty = this.ctx.helper.add(billsNegativeQty, change.qty);
@@ -387,6 +389,7 @@ module.exports = app => {
                 if (!nc || nc.qty !== oc.qty) {
                     const qty = nc ? this.round(nc.qty, precision.value) : null;
                     const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus, noValue);
+                    change.unit_price = ledgerBills.unit_price;
                     posQty = this.ctx.helper.add(posQty, change.qty);
                     if (change.minus) {
                         posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);
@@ -412,6 +415,7 @@ module.exports = app => {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 if (!nc) {
                     const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus, noValue);
+                    change.unit_price;
                     posQty = this.ctx.helper.add(posQty, change.qty);
                     if (change.minus) {
                         posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);
@@ -570,12 +574,10 @@ module.exports = app => {
             data = helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
             const bqData = [];
             for (const d of data) {
-                if (!d.qty) continue;
+                if (!d.qty || d.no_value) continue;
                 let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
                 if (!bd) {
-                    const bills = await this.db.get(this.ctx.service.ledger.departTableName(tender.id), { id: d.lid });
-                    if (!bills) continue;
-                    bd = { lid: d.lid, quality: d.quality, unit_price: bills.unit_price };
+                    bd = { lid: d.lid, quality: d.quality, unit_price: d.unit_price };
                     bqData.push(bd);
                 }
                 const tp = this.ctx.helper.mul(d.qty, bd.unit_price, tender.info.decimal.tp);

+ 1 - 1
app/service/stage_change_final.js

@@ -64,7 +64,7 @@ module.exports = app => {
                 data.push({
                     tid: c.tid, sid: c.sid, sorder: stage.order,
                     lid: c.lid, pid: c.pid, cid: c.cid, cbid: c.cbid,
-                    qty: c.qty, minus: c.minus, no_value: c.no_value,
+                    qty: c.qty, minus: c.minus, no_value: c.no_value, unit_price: c.unit_price,
                 });
             }
             await transaction.delete(this.tableName, { tid: tender.id, sid: stage.id });

+ 9 - 1
sql/update.sql

@@ -484,4 +484,12 @@ ADD COLUMN `pre_positive_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '截止上
 ADD COLUMN `positive_qc_pc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-正-变更金额' AFTER `pre_positive_qc_tp`,
 ADD COLUMN `negative_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-负-变更金额' AFTER `pre_positive_qc_tp`,
 ADD COLUMN `pre_negative_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '截止上期-负-变更金额' AFTER `negative_qc_tp`,
-ADD COLUMN `negative_qc_pc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-负-变更金额' AFTER `pre_negative_qc_tp`;
+ADD COLUMN `negative_qc_pc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-负-变更金额' AFTER `pre_negative_qc_tp`;
+
+ALTER TABLE `zh_stage_change`
+ADD COLUMN `unit_price`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '清单单价' AFTER `no_value`;
+ALTER TABLE `zh_stage_change_final`
+ADD COLUMN `unit_price`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '清单单价' AFTER `no_value`;
+
+Update `zh_stage_change` sc LEFT JOIN zh_change_audit_list cal ON sc.cbid = cal.id Set sc.unit_price = IFNULL(cal.unit_price, 0);
+Update `zh_stage_change_final` sc LEFT JOIN zh_change_audit_list cal ON sc.cbid = cal.id Set sc.unit_price = IFNULL(cal.unit_price, 0);