浏览代码

计量台账,变更后台账

MaiXinRong 1 月之前
父节点
当前提交
d6403414bb
共有 3 个文件被更改,包括 84 次插入9 次删除
  1. 18 0
      app/const/spread.js
  2. 60 3
      app/public/js/stage.js
  3. 6 6
      app/service/change_audit_list.js

+ 18 - 0
app/const/spread.js

@@ -144,6 +144,7 @@ const BaseSetCol = {
         { key: 'unit_price', name: '单价', fixed: ['alias'], bills: 1, pos: 0 },
         { key: 'deal_calc', name: '签约', fixed: [], bills: 1, pos: 0 },
         { key: 'tz_calc', name: '台账', fixed: [], bills: 1, pos: 1},
+        { key: 'tz2_calc', name: '变更后台账', fixed: [], bills: 1, pos: 1},
         { key: 'real_qty', name: '现场实际数量', fixed: ['valid', 'alias'], bills: 0, pos: 1},
         { key: 'estimate_qty', name: '预计变更数量', fixed: ['valid', 'alias'], bills: 0, pos: 1},
         { key: 'cur_calc', name: '本期计量', fixed: ['alias'], bills: 1, pos: 1, },
@@ -194,6 +195,7 @@ const BaseSetCol = {
         { key: 'unit_price', name: '单价', fixed: ['alias'], bills: 1, pos: 0 },
         { key: 'deal_calc', name: '签约', fixed: [], bills: 1, pos: 0 },
         { key: 'tz_calc', name: '台账', fixed: [], bills: 1, pos: 1},
+        { key: 'tz2_calc', name: '变更后台账', fixed: [], bills: 1, pos: 1},
         { key: 'real_qty', name: '现场实际数量', fixed: ['valid', 'alias'], bills: 0, pos: 1},
         { key: 'estimate_qty', name: '预计变更数量', fixed: ['valid', 'alias'], bills: 0, pos: 1},
         { key: 'cur_calc', name: '本期计量', fixed: ['alias'], bills: 1, pos: 1, },
@@ -248,6 +250,7 @@ const glSpreadTemplate = {
         { key: 'unit_price', valid: 1 },
         { key: 'deal_calc', valid: 0, },
         { key: 'tz_calc', valid: 1 },
+        { key: 'tz2_calc', valid: 0 },
         { key: 'real_qty', valid: 1 },
         { key: 'estimate_qty', valid: 1 },
         { key: 'cur_calc', valid: 1 },
@@ -298,6 +301,7 @@ const glSpreadTemplate = {
         { key: 'unit_price', valid: 1 },
         { key: 'deal_calc', valid: 1, },
         { key: 'tz_calc', valid: 1, pos_valid: 0 },
+        { key: 'tz2_calc', valid: 0 },
         { key: 'real_qty', valid: 1 },
         { key: 'estimate_qty', valid: 1 },
         { key: 'cur_calc', valid: 1 },
@@ -351,6 +355,7 @@ const szSpreadTemplate = {
         { key: 'unit_price', valid: 1 },
         { key: 'deal_calc', valid: 0, },
         { key: 'tz_calc', valid: 1 },
+        { key: 'tz2_calc', valid: 1 },
         { key: 'real_qty', valid: 1 },
         { key: 'estimate_qty', valid: 1 },
         { key: 'cur_calc', valid: 1 },
@@ -401,6 +406,7 @@ const szSpreadTemplate = {
         { key: 'unit_price', valid: 1 },
         { key: 'deal_calc', valid: 0, },
         { key: 'tz_calc', valid: 1 },
+        { key: 'tz2_calc', valid: 1 },
         { key: 'real_qty', valid: 1 },
         { key: 'estimate_qty', valid: 1 },
         { key: 'cur_calc', valid: 1 },
@@ -454,6 +460,7 @@ const fjSpreadTemplate = {
         { key: 'unit_price', valid: 1 },
         { key: 'deal_calc', valid: 0, },
         { key: 'tz_calc', valid: 1 },
+        { key: 'tz2_calc', valid: 1 },
         { key: 'real_qty', valid: 1 },
         { key: 'estimate_qty', valid: 1 },
         { key: 'cur_calc', valid: 1 },
@@ -504,6 +511,7 @@ const fjSpreadTemplate = {
         { key: 'unit_price', valid: 1 },
         { key: 'deal_calc', valid: 0, },
         { key: 'tz_calc', valid: 1 },
+        { key: 'tz2_calc', valid: 1 },
         { key: 'real_qty', valid: 1 },
         { key: 'estimate_qty', valid: 1 },
         { key: 'cur_calc', valid: 1 },
@@ -601,6 +609,10 @@ const BaseSpreadColSetting = {
                 {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, readOnly: true, type: 'Number', aliasFormat: '{%s}|数量'},
                 {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             ],
+            tz2_calc: [
+                {title: '变更后台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'tz2_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number', aliasFormat: '{%s}|数量'},
+                {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'tz2_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            ],
             deal_calc: [
                 {title: '签约|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number', aliasFormat: '{%s}|数量'},
                 {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
@@ -662,6 +674,7 @@ const BaseSpreadColSetting = {
             name: [{title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true}],
             position: [{title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@', readOnly: true}],
             tz_calc: [{title: '台账数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 60, formatter: '@', readOnly: true, aliasFormat: '{%s}数量'}],
+            tz2_calc: [{title: '变更后台账数量', colSpan: '1', rowSpan: '2', field: 'tz2_qty', hAlign: 2, width: 60, formatter: '@', readOnly: true, aliasFormat: '{%s}数量'}],
             real_qty: [{title: '现场实际数量', colSpan: '1', rowSpan: '2', field: 'real_qty', hAlign: 2, width: 60, type: 'Number'}],
             estimate_qty: [{title: '预计变更数量', colSpan: '1', rowSpan: '2', field: 'estimate_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true}],
             cur_calc: [
@@ -760,6 +773,10 @@ const BaseSpreadColSetting = {
                 {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, readOnly: true, type: 'Number', aliasFormat: '{%s}|数量'},
                 {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             ],
+            tz2_calc: [
+                {title: '变更后台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'tz2_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number', aliasFormat: '{%s}|数量'},
+                {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'tz2_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            ],
             deal_calc: [
                 {title: '签约|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number', aliasFormat: '{%s}|数量'},
                 {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
@@ -823,6 +840,7 @@ const BaseSpreadColSetting = {
             real_qty: [{title: '现场实际数量', colSpan: '1', rowSpan: '2', field: 'real_qty', hAlign: 2, width: 60, type: 'Number'}],
             estimate_qty: [{title: '预计变更数量', colSpan: '1', rowSpan: '2', field: 'estimate_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true}],
             tz_calc: [{title: '台账数量', colSpan: '1', rowSpan: '2', field: 'sgfh_qty', hAlign: 2, width: 60, type: 'Number', aliasFormat: '{%s}数量'}],
+            tz2_calc: [{title: '变更后台账数量', colSpan: '1', rowSpan: '2', field: 'tz2_qty', hAlign: 2, width: 60, formatter: '@', readOnly: true, aliasFormat: '{%s}数量'}],
             cur_calc: [
                 {title: '本期计量|合同', colSpan: '5|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
                 {title: '|合同公式', colSpan: '|1', rowSpan: '|1', field: 'contract_expr', hAlign: 0, width: 100},

+ 60 - 3
app/public/js/stage.js

@@ -306,7 +306,7 @@ $(document).ready(() => {
     stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr', 'ex_stage_qty1', 'ex_stage_tp1'];
     stageTreeSetting.calcFields = ['deal_tp', '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', 'end_gather_tp', 'end_correct_tp',
-        'final_1_tp', 'end_final_1_tp', 'due_qc_tp', 'due_final_tp', 'ex_tp1', 'ex_stage_tp1', 'end_ex_stage_tp1'];
+        'final_1_tp', 'end_final_1_tp', 'due_qc_tp', 'due_final_tp', 'ex_tp1', 'ex_stage_tp1', 'end_ex_stage_tp1', 'tz2_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);
@@ -321,6 +321,7 @@ $(document).ready(() => {
             node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
             node.due_final_qty = ZhCalc.add(node.quantity, node.due_qc_qty);
             node.end_ex_stage_qty1 = ZhCalc.add(node.ex_stage_qty1, node.pre_ex_stage_qty1);
+            node.tz2_qty = ZhCalc.add(node.quantity, node.tz2_qc_qty);
         }
         node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
         node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
@@ -329,7 +330,7 @@ $(document).ready(() => {
         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.final_1_tp);
-        node.due_final_tp = ZhCalc.add(node.quantity, node.due_qc_tp);
+        node.due_final_tp = ZhCalc.add(node.total_price, node.due_qc_tp);
         node.end_ex_stage_tp1 = ZhCalc.add(node.ex_stage_tp1, node.pre_ex_stage_tp1);
         if (!node.children || node.children.length === 0) {
             if (node.end_contract_qty) {
@@ -338,6 +339,7 @@ $(document).ready(() => {
                 node.end_correct_tp = node.end_gather_tp;
             }
         }
+        node.tz2_tp = ZhCalc.add(node.total_price, node.tz2_qc_tp);
         node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
         node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
         node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
@@ -367,6 +369,8 @@ $(document).ready(() => {
         pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
         pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
         pos.end_ex_stage_qty1 = ZhCalc.add(pos.pre_ex_stage_qty1, pos.ex_stage_qty1);
+        pos.due_final_qty = ZhCalc.add(pos.quantity, pos.due_qc_qty);
+        pos.tz2_qty = ZhCalc.add(pos.quantity, pos.tz2_qc_qty);
     };
     const stagePos = new StagePosData(stagePosSetting);
 
@@ -1525,6 +1529,58 @@ $(document).ready(() => {
             const data = [], groupData = [];
             exportNodesData(data, nodes ? nodes : stageTree.children, groupData);
             SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename, groupData);
+        },
+        loadChangeData: function(tree, pos, changes) {
+            const findEmptyBills = function(tree, change, changeBills) {
+                const cb = {
+                    b_code: changeBills.code || '',
+                    name: changeBills.name || '',
+                    unit: changeBills.unit || '',
+                    unit_price: changeBills.unit_price || 0,
+                };
+                for (const node of tree.nodes) {
+                    if (node.children && node.children.length > 0) continue;
+
+                    const b = {
+                        b_code: node.b_code || '',
+                        name: node.name || '',
+                        unit: node.unit || '',
+                        unit_price: node.unit_price || 0,
+                    };
+                    if (_.isMatch(cb, b)) return node;
+                }
+                return null;
+            };
+            for (const change of changes) {
+                for (const changeBills of change.bills) {
+                    const node = changeBills.gcl_id
+                        ? tree.nodes.find(x => {return x.id === changeBills.gcl_id})
+                        : findEmptyBills(tree, change, changeBills);
+
+                    if (!node) continue;
+                    if (changeBills.is_valuation) {
+                        node.tz2_qc_qty = ZhCalc.add(node.tz2_qc_qty, changeBills.checked_amount);
+                        node.tz2_qc_tp = ZhCalc.add(node.tz2_qc_tp, changeBills.checked_price);
+                    } else {
+                        node.tz2_qc_qty = ZhCalc.sub(node.tz2_qc_qty, changeBills.checked_amount);
+                        node.tz2_qc_tp = ZhCalc.sub(node.tz2_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.tz2_qc_qty = ZhCalc.add(pos.tz2_qc_qty, changeBills.checked_amount);
+                            } else {
+                                pos.tz2_qc_qty = ZhCalc.sub(pos.tz2_qc_qty, changeBills.checked_amount);
+                            }
+                        }
+                    }
+                }
+            }
         }
     };
     slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
@@ -2521,7 +2577,7 @@ $(document).ready(() => {
     });
 
     // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
-    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag' }, function (result) {
+    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;change' }, function (result) {
         // 加载树结构
         stageTree.loadDatas(result.ledgerData, result.locked);
         if (stage.assist) {
@@ -2531,6 +2587,7 @@ $(document).ready(() => {
         }
         // 加载部位明细
         stagePos.loadDatas(result.posData);
+        stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.change);
         checkShowLast(result.ledgerData.length);
         treeCalc.calculateAll(stageTree);
         for (const t of result.tags) {

+ 6 - 6
app/service/change_audit_list.js

@@ -1192,14 +1192,14 @@ module.exports = app => {
         }
 
         async getBillsSum(tid) {
-            const sql = 'SELECT gcl_id, Sum(qc_qty) AS qc_qty, Sum(qc_tp) AS qc_tp, Sum(qc_minus_qty) AS qc_minus_qty' +
+            const sql = 'SELECT gcl_id, Sum(qc_qty) AS qc_qty, Sum(qc_tp) AS qc_tp, Sum(qc_minus_qty) AS qc_minus_qty, Sum(qc_minus_tp) AS qc_minus_tp' +
                 '  FROM(' +
-                '    SELECT cal.gcl_id, Sum(cal.checked_amount) AS qc_qty, Sum(cal.checked_price) AS qc_tp, 0 As qc_minus_qty' +
+                '    SELECT cal.gcl_id, Sum(cal.checked_amount) AS qc_qty, Sum(cal.checked_price) AS qc_tp, 0 As qc_minus_qty, 0 As qc_minus_tp' +
                 `      FROM ${this.tableName} cal LEFT JOIN ${this.ctx.service.change.tableName} c ON cal.cid = c.cid` +
                 '      WHERE c.tid = ? AND c.valid AND c.status = ? AND cal.is_valuation' +
                 '      GROUP BY cal.gcl_id' +
                 '    UNION ALL ' +
-                '    SELECT cal.gcl_id, 0 As qc_qty, 0 As qc_tp, Sum(cal.checked_amount) AS qc_minus_qty' +
+                '    SELECT cal.gcl_id, 0 As qc_qty, 0 As qc_tp, Sum(cal.checked_amount) AS qc_minus_qty, Sum(cal.checked_price) AS qc_minus_tp' +
                 `      FROM ${this.tableName} cal LEFT JOIN ${this.ctx.service.change.tableName} c ON cal.cid = c.cid` +
                 '      WHERE c.tid = ? AND c.valid AND c.status = ? AND not cal.is_valuation' +
                 '      GROUP BY cal.gcl_id) As TEMP' +
@@ -1208,14 +1208,14 @@ module.exports = app => {
         }
 
         async getPosSum(tid) {
-            const sql = 'SELECT mx_id, Sum(qc_qty) AS qc_qty, Sum(qc_tp) AS qc_tp, Sum(qc_minus_qty) AS qc_minus_qty' +
+            const sql = 'SELECT mx_id, Sum(qc_qty) AS qc_qty, Sum(qc_minus_qty) AS qc_minus_qty' +
                 '  FROM(' +
-                '    SELECT cal.mx_id, Sum(cal.checked_amount) AS qc_qty, Sum(cal.checked_price) AS qc_tp, 0 As qc_minus_qty' +
+                '    SELECT cal.mx_id, Sum(cal.checked_amount) AS qc_qty, 0 As qc_minus_qty' +
                 `      FROM ${this.tableName} cal LEFT JOIN ${this.ctx.service.change.tableName} c ON cal.cid = c.cid` +
                 '      WHERE c.tid = ? AND c.valid AND c.status = ? AND cal.is_valuation' +
                 '      GROUP BY cal.mx_id' +
                 '    UNION ALL ' +
-                '    SELECT cal.mx_id, 0 As qc_qty, 0 As qc_tp, Sum(cal.checked_amount) AS qc_minus_qty' +
+                '    SELECT cal.mx_id, 0 As qc_qty, Sum(cal.checked_amount) AS qc_minus_qty' +
                 `      FROM ${this.tableName} cal LEFT JOIN ${this.ctx.service.change.tableName} c ON cal.cid = c.cid` +
                 '      WHERE c.tid = ? AND c.valid AND c.status = ? AND not cal.is_valuation' +
                 '      GROUP BY cal.mx_id) As TEMP' +