浏览代码

超计判断调整

MaiXinRong 3 年之前
父节点
当前提交
d05d7d6745
共有 5 个文件被更改,包括 47 次插入23 次删除
  1. 4 1
      app/controller/stage_controller.js
  2. 5 5
      app/lib/bills_pos_convert.js
  3. 7 6
      app/public/js/global.js
  4. 24 11
      app/public/js/stage.js
  5. 7 0
      app/service/stage_change.js

+ 4 - 1
app/controller/stage_controller.js

@@ -527,13 +527,16 @@ module.exports = app => {
                 if (!data.target || (!data.target.bills && !data.target.pos) || !data.change) {
                     throw '调用变更令数据错误';
                 }
-                let result, minus;
+                let result, minus, posMinus;
                 if (data.target.pos) {
                     result = await ctx.service.stageChange.posChange(data.target.pos, data.change);
                     result.change = { target: { lid: data.target.pos.lid, pid: data.target.pos.id } };
                     result.change.data = await ctx.service.stageChange.getLastestStageData(ctx.tender.id,
                         ctx.stage.id, data.target.pos.lid, data.target.pos.id);
                     minus = await this.ctx.service.stageChange.getBillsMinusQty(ctx.stage, data.target.pos.lid);
+                    posMinus = await this.ctx.service.stageChange.getPosMinusQty(ctx.stage, data.target.pos.id);
+                    const pos = result.pos.curStageData.find(x => { return x.pid === posMinus.pid });
+                    if (pos) pos.minus_qc_qty = posMinus.qty;
                 } else {
                     result = await ctx.service.stageChange.billsChange(data.target.bills, data.change);
                     result.change = { target: { lid: data.target.bills.id, pid: '-1' } };

+ 5 - 5
app/lib/bills_pos_convert.js

@@ -244,9 +244,9 @@ class BillsPosConvert {
 
         // 1#台账相关
         child.end_minus_qc_qty = this.ctx.helper.add(child.pre_minus_qc_qty, child.minus_qc_qty); // 1#台账 台账+负变更
-        child.end_1_qty = this.ctx.helper.add(child.end_minus_qc_qty, child.quantity); // 1#台账 台账+负变更
-        child.end_1_tp = this.ctx.helper.mul(child.unit_price, child.end_1_qty, tpDecimal);
-        child.end_final_1_tp = this.ctx.helper.add(child.end_qc_tp, child.end_1_tp);
+        child.final_1_qty = this.ctx.helper.add(child.end_minus_qc_qty, child.quantity); // 1#台账 台账+负变更
+        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.end_qc_tp, child.final_1_tp);
         child.end_gather_1_percent = this.ctx.helper.mul(this.ctx.helper.div(child.end_gather_tp, child.end_final_1_tp, 4), 100);
     }
     _calculateNode(node, children) {
@@ -263,13 +263,13 @@ class BillsPosConvert {
             node.end_gather_tp = this.ctx.helper.add(node.end_gather_tp, child.end_gather_tp);
             node.real_tp = this.ctx.helper.add(node.real_tp, child.real_tp);
             node.estimate_tp = this.ctx.helper.add(node.estimate_tp, child.estimate_tp);
-            node.end_1_tp = this.ctx.helper.add(node.end_1_tp, child.end_1_tp);
+            node.final_1_tp = this.ctx.helper.add(node.final_1_tp, child.final_1_tp);
         }
         if (node.dgn_qty1)
             node.dgn_price = this.ctx.helper.div(node.total_price, node.dgn_qty1, this.ctx.tender.info.decimal.up);
         node.final_tp = this.ctx.helper.add(node.total_price, node.end_qc_tp);
         node.end_gather_percent = this.ctx.helper.mul(this.ctx.helper.div(node.end_gather_tp, node.final_tp, 4), 100);
-        node.end_final_1_tp = this.ctx.helper.add(node.end_qc_tp, node.end_1_tp);
+        node.end_final_1_tp = this.ctx.helper.add(node.end_qc_tp, node.final_1_tp);
         node.end_gather_1_percent = this.ctx.helper.mul(this.ctx.helper.div(node.end_gather_tp, node.end_final_1_tp, 4), 100);
     }
     _recursiveCalcUnitNodes(nodes) {

+ 7 - 6
app/public/js/global.js

@@ -1017,10 +1017,11 @@ $.fn.extend({
 const checkUtils = {
     posOver(data) {
         if (!data) return false;
+        console.log(data.name, data.final_1_qty, data.end_contract_qty);
         if (!data.quantity) return !!data.end_contract_qty;
         return data.quantity > 0
-            ? data.end_contract_qty > data.quantity
-            : data.end_contract_qty < data.quantity || data.end_contract_qty > 0;
+            ? data.end_contract_qty > data.final_1_qty
+            : data.end_contract_qty < data.final_1_qty || data.end_contract_qty > 0;
     },
     billsOver(data, isTz, relaPos) {
         if (!data) return false;
@@ -1039,8 +1040,8 @@ const checkUtils = {
             } else {
                 if (!data.quantity) return !!data.end_contract_qty;
                 return data.quantity > 0
-                    ? data.end_contract_qty > data.quantity
-                    : data.end_contract_qty < data.quantity || data.end_contract_qty > 0;
+                    ? data.end_contract_qty > data.final_1_qty
+                    : data.end_contract_qty < data.final_1_qty || data.end_contract_qty > 0;
             }
         } else {
             if (data.is_tp) {
@@ -1051,8 +1052,8 @@ const checkUtils = {
             } else {
                 if (!data.deal_qty) return !!data.end_contract_qty;
                 return data.deal_qty > 0
-                    ? data.end_contract_qty > data.deal_qty
-                    : data.end_contract_qty < data.deal_qty || data.end_contract_qty > 0;
+                    ? data.end_contract_qty > data.final_deal_1_qty
+                    : data.end_contract_qty < data.final_deal_1_qty || data.end_contract_qty > 0;
             }
         }
     }

+ 24 - 11
app/public/js/stage.js

@@ -269,7 +269,7 @@ $(document).ready(() => {
     // 台账树结构计算相关设置
     stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr', 'minus_qc_qty'];
     stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
-        'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'end_1_tp'];
+        'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'final_1_tp'];
     stageTreeSetting.calcFun = function (node) {
         if (!node.children || node.children.length === 0) {
             node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
@@ -278,8 +278,9 @@ $(document).ready(() => {
             node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
             node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
             node.end_minus_qc_qty = ZhCalc.add(node.pre_minus_qc_qty, node.minus_qc_qty);
-            node.end_1_qty = ZhCalc.add(node.end_minus_qc_qty, node.quantity); // 1#台账 台账+负变更
-            node.end_1_tp = ZhCalc.mul(node.unit_price, node.end_1_qty, tenderInfo.decimal.tp);
+            node.final_1_qty = ZhCalc.add(node.end_minus_qc_qty, node.quantity); // 1#台账 台账+负变更
+            node.final_1_tp = ZhCalc.mul(node.unit_price, node.final_1_qty, tenderInfo.decimal.tp);
+            node.final_deal_1_qty = ZhCalc.add(node.end_minus_qc_qty, node.deal_qty);
         }
         node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
         node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
@@ -287,7 +288,7 @@ $(document).ready(() => {
         node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
         node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
         node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
-        node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.end_1_tp);
+        node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
         if (!node.children || node.children.length === 0) {
             if (node.end_contract_qty) {
                 node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
@@ -305,7 +306,7 @@ $(document).ready(() => {
     // 初始化 计量单元 数据结构
     const stagePosSetting = {
         id: 'id', ledgerId: 'lid',
-        updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr'],
+        updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr', 'minus_qc_qty'],
     };
     stagePosSetting.calcFun = function (pos) {
         pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
@@ -318,6 +319,8 @@ $(document).ready(() => {
         pos.estimate_qty = !checkZero(pos.real_qty)
             ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
             : null;
+        pos.end_minus_qc_qty = ZhCalc.add(pos.minus_qc_qty, pos.pre_minus_qc_qty);
+        pos.final_1_qty = ZhCalc.add(pos.end_minus_qc_qty, pos.quantity);
     };
     const stagePos = new StagePosData(stagePosSetting);
 
@@ -2045,20 +2048,32 @@ $(document).ready(() => {
     postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;import_change;tag;cooperation;minus_change' }, function (result) {
         // 加载树结构
         stageTree.loadDatas(result.ledgerData);
+        // 加载部位明细
+        stagePos.loadDatas(result.posData);
         let mcIndex = {};
         if (result.minus_change && result.minus_change.length > 0) {
             for (const mc of result.minus_change) {
                 if (!mcIndex[mc.lid]) mcIndex[mc.lid] = stageTree.nodes.find(x => { return x.id === mc.lid; });
-                if (!mcIndex[mc.lid]) continue;
-                mcIndex[mc.lid].pre_minus_qc_qty = ZhCalc.add(mcIndex[mc.lid].pre_minus_qc_qty, mc.qty);
+                if (!mcIndex[mc.lid]) {
+                    mcIndex[mc.lid].pre_minus_qc_qty = ZhCalc.add(mcIndex[mc.lid].pre_minus_qc_qty, mc.qty);
+                }
+                const mcP = stagePos.getPos(mc.pid);
+                if (mcP) {
+                    mcP.pre_minus_qc_qty = ZhCalc.add(mcP.pre_minus_qc_qty, mc.qty);
+                }
             }
         }
         if (result.changeData && result.changeData.length > 0) {
             for (const mc of result.changeData) {
                 if (!mc.minus || !mc.qty) continue;
                 if (!mcIndex[mc.lid]) mcIndex[mc.lid] = stageTree.nodes.find(x => { return x.id === mc.lid; });
-                if (!mcIndex[mc.lid]) continue;
-                mcIndex[mc.lid].minus_qc_qty = ZhCalc.add(mcIndex[mc.lid].minus_qc_qty, mc.qty);
+                if (!mcIndex[mc.lid]) {
+                    mcIndex[mc.lid].minus_qc_qty = ZhCalc.add(mcIndex[mc.lid].minus_qc_qty, mc.qty);
+                }
+                const mcP = stagePos.getPos(mc.pid);
+                if (mcP) {
+                    mcP.pre_minus_qc_qty = ZhCalc.add(mcP.pre_minus_qc_qty, mc.qty);
+                }
             }
         }
         mcIndex = null;
@@ -2076,8 +2091,6 @@ $(document).ready(() => {
             t.node = stageTree.datas.find(x => {return x.id === t.lid});
         }
         billsTag.loadDatas(result.tags);
-        // 加载部位明细
-        stagePos.loadDatas(result.posData);
         stagePos.calculateAll();
         SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
         SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);

+ 7 - 0
app/service/stage_change.js

@@ -495,6 +495,13 @@ module.exports = app => {
             const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
             return { lid, qty: this.ctx.helper.sum(filter.map(x => { return x.qty; })) };
         };
+
+
+        async getPosMinusQty(stage, pid) {
+            const data = await this.getAllDataByCondition({ where: { sid: stage.id, pid, minus: 1 } });
+            const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
+            return { pid, qty: this.ctx.helper.sum(filter.map(x => { return x.qty; })) };
+        };
     }
 
     return StageChange;