Browse Source

计量台账,变更后计算调整

MaiXinRong 2 months ago
parent
commit
6dbba64b51

+ 43 - 0
app/controller/stage_controller.js

@@ -353,6 +353,46 @@ module.exports = app => {
             return change;
         }
 
+        async _getReCalcChangeData(ctx) {
+            const change = await ctx.service.change.getAllDataByCondition({
+                columns: [ 'cid', 'code', 'name', 'w_code', 'tp_decimal', 'up_decimal' ],
+                where: { tid: ctx.tender.id, valid: 1, status: changeAudit.status.checked },
+                orders: [['code', 'asc']],
+            });
+            const changeBills = await ctx.service.changeAuditList.getAllDataByCondition({
+                columns: [ 'id', 'cid', 'code', 'name', 'unit', 'unit_price', 'oamount2', 'checked_amount', 'checked_price', 'is_valuation', 'gcl_id', 'bwmx', 'mx_id'],
+                where: { tid: ctx.tender.id }
+            });
+            const changeIndex = {};
+            change.forEach(x => { changeIndex[x.cid] = x; x.bills = [] });
+            changeBills.forEach(cb => {
+                const c = changeIndex[cb.cid];
+                if (!c) return;
+                if (cb.gcl_id) {
+                    let b = c.bills.find(x => { return x.gcl_id === cb.gcl_id; });
+                    if (!b) {
+                        b = { code: cb.code, name: cb.name, unit: cb.unit, unit_price: cb.unit_price, pos: [], gcl_id: cb.gcl_id };
+                        c.bills.push(b);
+                    }
+                    b.checked_amount = this.ctx.helper.add(b.checked_amount, cb.checked_amount);
+                    b.pos.push(cb);
+                } else {
+                    c.bills.push({
+                        code: cb.code, name: cb.name, unit: cb.unit, unit_price: cb.unit_price,
+                        gcl_id: '', checked_amount: cb.checked_amount, checked_price: cb.checked_price,
+                        pos: [cb],
+                    });
+                }
+            });
+            const helper = ctx.helper;
+            change.forEach(x => {
+                const tpDecimal = x.tp_decimal || ctx.tender.info.decimal.tp;
+                x.bills.forEach(b => { b.checked_price = helper.mul(b.unit_price, b.checked_amount, tpDecimal); });
+                x.bills.sort((a, b) => { return helper.compareCode(a.code, b.code)});
+            });
+            return change;
+        }
+
         async getStageData(ctx) {
             try {
                 const data = JSON.parse(ctx.request.body.data);
@@ -397,6 +437,9 @@ module.exports = app => {
                         case 'change':
                             responseData.data.change = await this._getChangeData(ctx);
                             break;
+                        case 'reCalcChange':
+                            responseData.data.reCalcChange = await this._getReCalcChangeData(ctx);
+                            break;
                         case 'preStageChange':
                             responseData.data.preStageChange = ctx.stage.preCheckedStage
                                 ? await this.ctx.service.stageChangeFinal.getEndStageData(ctx.tender.id, ctx.stage.preCheckedStage.order)

+ 9 - 3
app/lib/revise_price.js

@@ -231,9 +231,15 @@ class revisePriceCalc {
             } else {
                 bills_tp = this.ctx.helper.mul(b.unit_price, b.spamount, change.tp_decimal || decimal.tp);
             }
-            let sb = sumBills.find(x => { return x.gcl_id === b.gcl_id });
-            if (!sb) {
-                sb = {gcl_id: b.gcl_id, unit_price: b.unit_price, v_qty: 0, uv_qty: 0, p_qty: 0, n_qty: 0 };
+            let sb;
+            if (b.gcl_id) {
+                sb = sumBills.find(x => { return x.gcl_id === b.gcl_id });
+                if (!sb) {
+                    sb = {gcl_id: b.gcl_id, unit_price: b.unit_price, v_qty: 0, uv_qty: 0, p_qty: 0, n_qty: 0 };
+                    sumBills.push(sb);
+                }
+            } else {
+                sb = { gcl_id: b.gcl_id, unit_price: b.unit_price, v_qty: 0, uv_qty: 0, p_qty: 0, n_qty: 0 };
                 sumBills.push(sb);
             }
             if (b.spamount >= 0) {

+ 7 - 18
app/public/js/stage.js

@@ -1558,25 +1558,14 @@ $(document).ready(() => {
                         : findEmptyBills(tree, change, changeBills);
 
                     if (!node) continue;
-                    if (changeBills.is_valuation) {
-                        node.tz_qc_qty = ZhCalc.add(node.tz_qc_qty, changeBills.checked_amount);
-                        node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.checked_price);
-                    } else {
-                        node.tz_qc_minus_qty = ZhCalc.add(node.tz_qc_minus_qty, changeBills.checked_amount);
-                        node.tz_qc_minus_tp = ZhCalc.add(node.tz_qc_minus_tp, changeBills.checked_price);
-                    }
+                    node.tz_qc_qty = ZhCalc.add(node.tz_qc_qty, changeBills.checked_amount);
+                    node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.checked_price);
 
                     const posData = pos.getLedgerPos(node.id);
                     if (posData && posData.length > 0) {
-                        const changePos = changeBills.is_valuation
-                            ? posData.find(x => { return x.name === changeBills.bwmx; })
-                            : posData[0];
-                        if (changePos) {
-                            if (changeBills.is_valuation) {
-                                pos.tz_qc_qty = ZhCalc.add(pos.tz_qc_qty, changeBills.checked_amount);
-                            } else {
-                                pos.tz_qc_minus_qty = ZhCalc.add(pos.tz_qc_minus_qty, changeBills.checked_amount);
-                            }
+                        for (const p of changeBills.pos) {
+                            const changePos = changeBills.bwmx ? posData.find(x => { return x.name === changeBills.bwmx; }) : posData[0];
+                            changePos.tz_qc_qty = ZhCalc.add(pos.tz_qc_qty, p.checked_amount);
                         }
                     }
                 }
@@ -2577,7 +2566,7 @@ $(document).ready(() => {
     });
 
     // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
-    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;change' }, function (result) {
+    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;reCalcChange' }, function (result) {
         // 加载树结构
         stageTree.loadDatas(result.ledgerData, result.locked);
         if (stage.assist) {
@@ -2587,7 +2576,7 @@ $(document).ready(() => {
         }
         // 加载部位明细
         stagePos.loadDatas(result.posData);
-        stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.change);
+        stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.reCalcChange);
         checkShowLast(result.ledgerData.length);
         treeCalc.calculateAll(stageTree);
         for (const t of result.tags) {

+ 1 - 1
app/service/change_audit_list.js

@@ -518,7 +518,7 @@ module.exports = app => {
                             }
                         }
                     }
-                    const price = this.ctx.helper.mul(spamount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal);
+                    const price = this.ctx.helper.mul(zheli , this.ctx.helper.round(unitPrice, up_decimal), tp_decimal);
                     const valuation_price = this.ctx.helper.mul(valuation_amount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal) || 0;
                     const unvaluation_price = this.ctx.helper.mul(unvaluation_amount, this.ctx.helper.round(unitPrice, up_decimal), tp_decimal) || 0;
                     valuation_tp = this.ctx.helper.accAdd(valuation_tp, valuation_price);