Kaynağa Gözat

结算台账,预结算数据加载显示

MaiXinRong 1 yıl önce
ebeveyn
işleme
2750717d70

+ 22 - 4
app/controller/settle_controller.js

@@ -221,6 +221,10 @@ module.exports = app => {
             }
         }
 
+        checkNeedPretreadData(ctx) {
+            return ctx.settle.audit_status === auditConst.settle.status.uncheck || (ctx.settle.audit_status === auditConst.settle.status.checkNo && !ctx.settle.readOnly);
+        }
+
         async _loadLatestStage(ctx) {
             if (ctx.settle.latestStage) return;
             ctx.settle.latestStage = ctx.settle.final_sid
@@ -248,6 +252,14 @@ module.exports = app => {
             ]);
             return posData;
         }
+        async _loadPretreatSettleData(ctx) {
+            if (this.checkNeedPretreadData(ctx)) {
+                this.pretreadSettle = {};
+                const Pretreat = require('../lib/settle');
+                const pretreadObj = new Pretreat(ctx);
+                [this.pretreadSettle.settleBills, this.pretreadSettle.settlePos] = await pretreadObj.doSettle(this.ctx.settle);
+            }
+        }
         async _loadSettleDataByKey(ctx, key, hpack) {
             switch (key) {
                 case 'stageBills':
@@ -263,10 +275,16 @@ module.exports = app => {
                     const settleChange = await ctx.service.stageChangeFinal.getUnSettleChangeData(ctx.settle.latestStage);
                     return hpack ? [ctx.helper.hpackArr(settleChange), key] : [settleChange, ''];
                 case 'settleBills':
-                    const settleBills = await ctx.service.settleBills.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
+                    await this._loadPretreatSettleData(ctx);
+                    const settleBills = this.checkNeedPretreadData(ctx)
+                        ? this.pretreadSettle.settleBills
+                        : await ctx.service.settleBills.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
                     return hpack ? [ctx.helper.hpackArr(settleBills), 'settleBills'] : [settleBills, ''];
                 case 'settlePos':
-                    const settlePos = await ctx.service.settlePos.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
+                    await this._loadPretreatSettleData(ctx);
+                    const settlePos = this.checkNeedPretreadData(ctx)
+                        ? this.pretreadSettle.settlePos
+                        : await ctx.service.settlePos.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
                     return hpack ? [ctx.helper.hpackArr(settlePos), 'settlePos'] : [settlePos, ''];
                 case 'settleSelect':
                     const settleSelect = await ctx.service.settleSelect.getAllDataByCondition({ where: { settle_id: ctx.settle.id } });
@@ -313,8 +331,8 @@ module.exports = app => {
         async loadGatherData(ctx) {
             try {
                 const settle = await this.ctx.service.settle.getLatestCompleteSettle(ctx.tender.id);
-                const bills = await this.ctx.service.settleBillsFinal.getDataByCondition({ where: { settle_id: settle.id }});
-                const pos = await this.ctx.service.settlePosFinal.getDataByCondition({ where: { settle_id: settle.id }});
+                const bills = await this.ctx.service.settleBills.getDataByCondition({ where: { settle_id: settle.id }});
+                const pos = await this.ctx.service.settlePos.getDataByCondition({ where: { settle_id: settle.id }});
                 ctx.body = { err: 0, msg: '', data: { bills, pos } };
             } catch(err) {
                 ctx.log(err);

+ 4 - 0
app/lib/ledger.js

@@ -618,6 +618,10 @@ class pos {
         }
     }
 
+    getPos(id) {
+        return this.items[itemsPre + id];
+    }
+
     getLedgerPosKey() {
         const result = [];
         for (const prop in this.ledgerPos) {

+ 0 - 1
app/lib/rpt_data_analysis.js

@@ -45,7 +45,6 @@ const valueCheck = {
                 return !ctx.helper._.isNil(value) ? value >= condition.value : false;
             case '<=':
                 return !ctx.helper._.isNil(value) ? value <= condition.value : false;
-            case '!=':
             default:
                 return true;
         }

+ 3 - 2
app/public/js/path_tree.bak.js

@@ -217,9 +217,10 @@ const createNewPathTree = function (setting) {
      * @returns {Array}
      */
     proto.getPosterity = function (node) {
-        const reg = new RegExp('^' + node.full_path + '.');
+        const field = this.setting.fullPath;
+        const reg = new RegExp('^' + node[field] + '.');
         return this.datas.filter(function (x) {
-            return reg.test(x.full_path);
+            return reg.test(x[field]);
         })
     };
     /**

+ 3 - 3
app/public/js/path_tree.js

@@ -460,8 +460,8 @@ const createNewPathTree = function (type, setting) {
             const parents = [];
             if (!node) return parents;
 
-            if (node.full_path && node.full_path !== '') {
-                const parentIds = node.full_path.split('-');
+            if (node[this.setting.fullPath] && node[this.setting.fullPath] !== '') {
+                const parentIds = node[this.setting.fullPath].split('-');
                 parentIds.length = parentIds.length - 1;
                 for (const id of parentIds) {
                     if (id !== node[this.setting.id]) {
@@ -556,7 +556,7 @@ const createNewPathTree = function (type, setting) {
         getPosterity(node) {
             const self = this;
             let posterity;
-            if (node.full_path !== '') {
+            if (node[self.setting.fullPath] !== '') {
                 const reg = new RegExp('^' + node[self.setting.fullPath] + '-');
                 posterity = this.datas.filter(function (x) {
                     return reg.test(x[self.setting.fullPath]);

+ 20 - 18
app/public/js/settle_ledger.js

@@ -18,38 +18,40 @@ $(document).ready(() => {
 
     let searchLedger;
     const settleTreeSetting = {
-        id: 'ledger_id',
-        pid: 'ledger_pid',
-        order: 'order',
-        level: 'level',
+        id: 'tree_id',
+        pid: 'tree_pid',
+        order: 'tree_order',
+        level: 'tree_level',
+        fullPath: 'tree_full_path',
+        isLeaf: 'tree_is_leaf',
         rootId: -1,
-        keys: ['id', 'tender_id', 'ledger_id'],
+        keys: ['id', 'tid', 'tree_id'],
         stageId: 'id',
         autoExpand: 3,
         markExpandKey: 'settle-select-expand',
         markExpandSubKey: window.location.pathname.split('/')[2],
-        calcFields: ['total_price', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'],
+        calcFields: ['total_price', 'cur_contract_tp', 'cur_qc_tp', 'cur_gather_tp', 'cur_correct_tp'],
         calcFun: function(node) {
             if (!node.children || node.children.length === 0) {
-                node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
-                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));
+                node.cur_gather_qty = ZhCalc.add(node.cur_contract_qty, node.cur_qc_qty);
+                if (node.cur_contract_qty) {
+                    node.cur_correct_tp = ZhCalc.add(node.cur_qc_tp, ZhCalc.mul(node.cur_contract_qty, node.unit_price, tenderInfo.decimal.tp));
                 } else {
-                    node.end_correct_tp = node.end_gather_tp;
+                    node.cur_correct_tp = node.cur_gather_tp;
                 }
             }
-            node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_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.cur_gather_tp = ZhCalc.add(node.cur_contract_tp, node.cur_qc_tp);
+            node.cur_gather_percent = ZhCalc.mul(ZhCalc.div(node.cur_gather_tp, node.cur_final_tp), 100, 2);
+            node.cur_correct_percent = ZhCalc.mul(ZhCalc.div(node.cur_correct_tp, node.cur_final_tp), 100, 2);
         }
     };
     const settleTree = createNewPathTree('stage', settleTreeSetting);
     const settlePosSetting = {
         id: 'id', ledgerId: 'lid',
         calcFun: function(pos) {
-            pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
+            pos.cur_gather_qty = ZhCalc.add(pos.cur_contract_qty, pos.cur_qc_qty);
             pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
-            pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
+            pos.cur_gather_percent = ZhCalc.mul(ZhCalc.div(pos.cur_gather_qty, pos.sum), 100, 2);
         }
     };
     const settlePos = new StagePosData(settlePosSetting);
@@ -58,8 +60,8 @@ $(document).ready(() => {
     const slSheet = slSpread.getActiveSheet();
     slSheet.frozenColumnCount(billsSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
     slSheet.options.frozenlineColor = '#93b5e4';
-    const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
-    if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
+    const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'cur_final_1_percent' || x.field === 'cur_correct_1_percent'});
+    if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'cur_correct_1_percent' : 'cur_final_1_percent';
     billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
         if (!data) return defaultColor;
         if (data.children && data.children.length > 0) return defaultColor;
@@ -131,7 +133,7 @@ $(document).ready(() => {
             const billsNode = SpreadJsObj.getSelectObject(slSheet);
             if (billsNode) {
                 spSheet.zh_setting.readOnly = readOnly;
-                const posRange = settlePos.getLedgerPos(billsNode.id) || [];
+                const posRange = settlePos.getLedgerPos(billsNode.lid) || [];
                 SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
             } else {
                 spSheet.zh_setting.readOnly = true;

+ 39 - 8
app/public/js/settle_select.js

@@ -110,7 +110,7 @@ $(document).ready(() => {
     // 0: 可结算,1: 合同未完成,2:
     const settleCheck = {
         _analysisPos(pos) {
-            pos.undoneDeal = pos.quantity ? !checkZero(ZhCalc.div(pos.end_contract_qty, pos.quantity)) : false;
+            pos.undoneDeal = pos.quantity ? !checkZero(ZhCalc.sub(pos.end_contract_qty, pos.quantity)) : false;
             pos.undone = pos.undoneDeal || pos.undoneChange;
         },
         _analysisNode(node) {
@@ -132,7 +132,9 @@ $(document).ready(() => {
                         if (pos.undoneChange) node.undoneChange = true;
                     }
                 } else {
-                    node.undoneDeal = node.end_contract_qty ? !checkZero(ZhCalc.div(node.end_contract_qty, node.quantity)) : false;
+                    node.undoneDeal = node.end_contract_qty
+                        ? !checkZero(ZhCalc.sub(node.end_contract_qty, node.quantity))
+                        : !checkZero(ZhCalc.sub(node.end_contract_tp, node.total_price));
                     node.undone = !!node.undoneDeal || !!node.undoneChange;
                 }
             }
@@ -195,10 +197,12 @@ $(document).ready(() => {
                     }
                     if (!p.children || p.children.length === 0) {
                         const posRange = settlePos.getLedgerPos(p.id);
-                        for (const p of posRange) {
-                            if (p.selected) {
-                                if (!update.del) update.del = [];
-                                update.del.push({ pid: p.id });
+                        if (posRange && posRange.length > 0) {
+                            for (const p of posRange) {
+                                if (p.selected) {
+                                    if (!update.del) update.del = [];
+                                    update.del.push({ pid: p.id });
+                                }
                             }
                         }
                     }
@@ -279,9 +283,9 @@ $(document).ready(() => {
 
             const update = {};
             if (!node.selected) {
-                update.add = [{ lid: node.id }];
+                update.add = [{ pid: node.id }];
             } else {
-                update.del = [{ lid: node.id }];
+                update.del = [{ pid: node.id }];
             }
             postData(window.location.pathname + '/update', update, result => {
                 node.selected = !node.selected;
@@ -409,4 +413,31 @@ $(document).ready(() => {
             window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
         }
     });
+
+    // 显示层次
+    (function (select, sheet) {
+        $(select).click(function () {
+            const tag = $(this).attr('tag');
+            const tree = sheet.zh_tree;
+            if (!tree) return;
+            setTimeout(() => {
+                showWaitingView();
+                switch (tag) {
+                    case "1":
+                    case "2":
+                    case "3":
+                    case "4":
+                    case "5":
+                        tree.expandByLevel(parseInt(tag));
+                        SpreadJsObj.refreshTreeRowVisible(sheet);
+                        break;
+                    case "last":
+                        tree.expandByCustom(() => { return true; });
+                        SpreadJsObj.refreshTreeRowVisible(sheet);
+                        break;
+                }
+                closeWaitingView();
+            }, 100);
+        });
+    })('a[name=showLevel]', slSheet);
 });

+ 6 - 4
app/public/js/shares/sjs_setting.js

@@ -6,17 +6,19 @@ const sjsSettingObj = (function () {
         setting.selectedBackColor = '#fffacd';
         setting.tree = {
             getFont: function (sheet, data, row, col, defaultFont) {
-                if (sheet.zh_tree && data.level === 1) {
-                    return 'bold ' + defaultFont;
+                if (sheet.zh_tree) {
+                    const levelField = sheet.zh_tree.setting.level;
+                    return data[levelField] === 1 ? 'bold ' + defaultFont : defaultFont;
                 } else {
                     return defaultFont;
                 }
             },
             getColor: function (sheet, data, row, col, defaultColor) {
                 if (sheet.zh_tree) {
-                    if (data.level === 2) {
+                    const levelField = sheet.zh_tree.setting.level;
+                    if (data[levelField] === 2) {
                         return '#C4CAFB';
-                    } else if ((!data.b_code || data.b_code === '') && data.level > 2) {
+                    } else if ((!data.b_code || data.b_code === '') && data[levelField] > 2) {
                         return '#DFE8F9';
                     } else {
                         return defaultColor;

+ 4 - 0
app/service/settle.js

@@ -317,6 +317,10 @@ module.exports = app => {
             // 可否撤回,是哪一种撤回
             await this._doCheckSettleCanCancel(settle);
         }
+
+        async doSettle(settle) {
+
+        }
     }
 
     return Settle;

+ 2 - 2
app/service/settle_select.js

@@ -31,8 +31,8 @@ module.exports = app => {
                         if (d.lid) lid.push(d.lid);
                         if (d.pid) pid.push(d.pid);
                     }
-                    const delLibData = await this.getAllDataByCondition({ settle_id: this.ctx.settle.id, lid });
-                    const delPidData = await this.getAllDataByCondition({ settle_id: this.ctx.settle.id, pid });
+                    const delLibData = lid.length > 0 ? await this.getAllDataByCondition({ where: { settle_id: this.ctx.settle.id, lid } }) : [];
+                    const delPidData = pid.length > 0 ? await this.getAllDataByCondition({ where: { settle_id: this.ctx.settle.id, pid } }) : [];
                     if (delLibData.length + delPidData.length !== data.del.length) throw '提交数据错误';
                     const deleteData = [...delLibData, ...delPidData];
                     await conn.delete(this.tableName, { id: deleteData.map(x => { return x.id }) });

+ 15 - 12
app/view/settle/index.ejs

@@ -30,7 +30,7 @@
         <div class="row w-100 sub-content">
             <div id="left-view" class="c-body" style="width: 100%">
                 <!--上部分-->
-                <div class="sjs-height-1" id="settle-ledger">
+                <div class="sjs-height-1" id="settle-bills">
                 </div>
                 <!--下部分-->
                 <div class="bcontent-wrap" id="main-bottom">
@@ -104,13 +104,13 @@
             {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '本期合同结算|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '本期完成结算|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_final_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
+            {title: '本期合同结算|数量', colSpan: '2|1', rowSpan: '1|1', field: 'cur_contract_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cur_contract_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'cur_qc_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cur_qc_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '本期完成结算|数量', colSpan: '3|1', rowSpan: '1|1', field: 'cur_gather_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cur_gather_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'cur_final_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
             {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: true},
             <% if (ctx.session.sessionProject.gxby) { %>
@@ -128,6 +128,7 @@
         font: '12px 微软雅黑',
         frozenColCount: 5,
         frozenLineColor: '#93b5e4',
+        readOnly,
     };
     const posSpreadSetting = {
         cols: [
@@ -135,9 +136,10 @@
             {title: '结算状态', colSpan: '1', rowSpan: '2', field: 'settle_status', hAlign: 1, width: 60, formatter: '@', readOnly: true},
             {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true},
             {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@', readOnly: true},
-            {title: '累计计量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
-            {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'end_qc_qty', hAlign: 2, width: 80, type: 'Number', readOnly: true},
-            {title: '|完成', colSpan: '|1', rowSpan: '|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
+            {title: '台账数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 60, formatter: '@', readOnly: true},
+            {title: '本期结算|合同', colSpan: '3|1', rowSpan: '1|1', field: 'cur_contract_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
+            {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'cur_qc_qty', hAlign: 2, width: 80, type: 'Number', readOnly: true},
+            {title: '|完成', colSpan: '|1', rowSpan: '|1', field: 'cur_gather_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
             {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
             <% if (ctx.session.sessionProject.gxby) { %>
             {title: '工序报验', colSpan: '1', rowSpan: '2', field: 'gxby', hAlign: 1, width: 80, formatter: '@', readOnly: true},
@@ -146,12 +148,13 @@
             {title: '档案管理', colSpan: '1', rowSpan: '2', field: 'dagl', hAlign: 1, width: 80, formatter: '@', readOnly: true},
             <% } %>
         ],
-        emptyRows: 20,
+        emptyRows: 0,
         headRows: 2,
         headRowHeight: [25, 25],
         headColWidth: [30],
         defaultRowHeight: 21,
         headerFont: '12px 微软雅黑',
         font: '12px 微软雅黑',
+        readOnly,
     };
 </script>

+ 1 - 0
app/view/settle/select.ejs

@@ -137,6 +137,7 @@
             {title: '结算状态', colSpan: '1', rowSpan: '2', field: 'settle_status', hAlign: 1, width: 60, formatter: '@', readOnly: true},
             {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true},
             {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@', readOnly: true},
+            {title: '台账数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 60, formatter: '@', readOnly: true},
             {title: '累计计量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'end_qc_qty', hAlign: 2, width: 80, type: 'Number', readOnly: true},
             {title: '|完成', colSpan: '|1', rowSpan: '|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},