Sfoglia il codice sorgente

计量期总金额重算

laiguoran 4 anni fa
parent
commit
9f5045e7f8

+ 42 - 1
app/controller/schedule_controller.js

@@ -81,6 +81,7 @@ module.exports = app => {
             const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
             const scheduleLedgerList = await this._getSelectedLedgerList(ctx);
             const allSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
+            const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
             const hadDataLidList = [];
             for (const sl of scheduleLedgerList) {
                 const info = _.find(allSlmList, function(item) {
@@ -100,6 +101,7 @@ module.exports = app => {
                 measureType,
                 scheduleLedgerList,
                 hadDataLidList,
+                scheduleStage,
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.ledger),
                 revising: await this._getLastReviseStatus(ctx),
             };
@@ -194,6 +196,44 @@ module.exports = app => {
             }
         }
 
+        /**
+         * 获取所有期下台账数据(Ajax)
+         *
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async _getAllStageLedgerData(ctx) {
+            const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+            const stageList = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
+            if (stageList.length > 0) {
+                const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
+                for (const d of dgnData) {
+                    const l = ctx.app._.find(ledgerData, { id: d.id });
+                    ctx.app._.assignIn(l, d);
+                }
+                for (const s of stageList) {
+                    const stageInfo = await ctx.service.stage.getDataByCondition({
+                        tid: ctx.tender.id,
+                        order: s.order,
+                    });
+                    // let preStageData;
+                    // 当前操作人查看最新数据,其他人查看历史数据
+                    const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
+                    // // 查询截止上期数据
+                    // if (stageInfo.order > 1) {
+                    //     preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
+                    // } else {
+                    //     preStageData = [];
+                    // }
+                    this.ctx.helper.assignRelaData(ledgerData, [
+                        { data: curStageData, fields: ['contract_tp', 'qc_tp'], prefix: s.order + '_', relaId: 'lid' },
+                        // { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: s.order + '_pre_', relaId: 'lid' },
+                    ]);
+                }
+            }
+            return ledgerData;
+        }
+
         async _getStageLedgerData(ctx, stageOrder) {
             const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
             const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
@@ -279,7 +319,8 @@ module.exports = app => {
          */
         async loadLedgerData(ctx) {
             try {
-                const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+                // const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+                const ledgerData = await this._getAllStageLedgerData(ctx);
                 // const posData = ctx.tender.data.measure_type === measureType.tz.value
                 //     ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
                 // const convert = new billsPosConvert(ctx);

+ 55 - 11
app/public/js/schedule_ledger.js

@@ -21,10 +21,7 @@ $(function () {
         level: 'level',
         rootId: -1,
         fullPath: 'full_path',
-        calcFields: ['can_select'],
-        //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
-        // markFoldKey: 'bills-fold',
-        // markFoldSubKey: window.location.pathname.split('/')[2],
+        // calcFields: ['can_select'],
     };
     const ledgerTree = createNewPathTree('filter', treeSetting);
 
@@ -66,6 +63,23 @@ $(function () {
     SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
 
     postData(window.location.pathname + '/load', {}, function (data) {
+        const showList = ['is_select', 'can_select', 'ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
+            'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', 'total_price'];
+        const calcList = ['total_price'];
+        const fileds = [];
+        if (scheduleStage.length > 0) {
+            for (const ss of scheduleStage) {
+                // const pushTp = [ss.order + '_gather_tp', ss.order + '_contract_tp', ss.order + '_qc_tp'];
+                showList.push(ss.order + '_gather_tp');
+                showList.push(ss.order + '_contract_tp');
+                showList.push(ss.order + '_qc_tp');
+                calcList.push(ss.order + '_gather_tp');
+                calcList.push(ss.order + '_contract_tp');
+                calcList.push(ss.order + '_qc_tp');
+                fileds.push(ss.order + '_contract_tp');
+                fileds.push(ss.order + '_qc_tp');
+            }
+        }
         const baseLedgerTree = createNewPathTree('base', {
             id: 'ledger_id',
             pid: 'ledger_pid',
@@ -73,22 +87,27 @@ $(function () {
             level: 'level',
             rootId: -1,
             fullPath: 'full_path',
-            calcFields: ['total_price'],
+            updateFields: fileds,
+            calcFields: calcList,
             calcFun: function (node) {
                 node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
+                if (scheduleStage.length > 0) {
+                    for (const ss of scheduleStage) {
+                        node[ss.order + '_gather_tp'] = ZhCalc.add(node[ss.order + '_contract_tp'], node[ss.order + '_qc_tp']);
+                    }
+                }
             }
         });
-        // slh = _.map(data.slh, 'ledger_id');
         slh = data.slh;
         const datas = addIsSelect(data.bills);
         baseLedgerTree.loadDatas(datas);
         treeCalc.calculateAll(baseLedgerTree);
         for (const d of baseLedgerTree.nodes) {
             if (!d.b_code)
-                ledgerTree.addData(d, ['is_select', 'can_select', 'ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
-                    'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', 'total_price']);
+                ledgerTree.addData(d, showList);
         }
         ledgerTree.sortTreeNode(true);
+        // treeCalc.calculateAll(ledgerTree);
         console.log(ledgerTree);
 
         SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
@@ -201,7 +220,9 @@ $(function () {
         }
         $(this).attr('disabled', true);
         const [under_ledger, parent_ledger] = getPAndULedger(select_ledger);
-        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger, type: 'sz' } , function (result) {
+        // 重新计算每一期计量进度金额并提交
+        const stageTpList = calcStageTp(under_ledger);
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger, stageTpList, type: 'sz' } , function (result) {
             toastr.success('设置成功');
             setTimeout(function () {
                 window.location.reload();
@@ -231,7 +252,9 @@ $(function () {
         }
         $(this).attr('disabled', true);
         const [under_ledger, parent_ledger] = getPAndULedger(select_ledger);
-        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger, type: 'xz' } , function (result) {
+        // 重新计算每一期计量进度金额并提交
+        const stageTpList = calcStageTp(under_ledger);
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger, stageTpList, type: 'xz' } , function (result) {
             toastr.success('进度台账数据修正成功');
             setTimeout(function () {
                 window.location.reload();
@@ -245,7 +268,13 @@ $(function () {
         for (const sl of select_ledger) {
             const hadChild = _.find(select_ledger, { ledger_pid: sl.ledger_id });
             if (!hadChild) {
-                under_ledger.push({ ledger_id: sl.ledger_id, ledger_pid: sl.ledger_pid, gcl: sl.dgn_qty1, tp: sl.total_price });
+                const pushArray = { ledger_id: sl.ledger_id, ledger_pid: sl.ledger_pid, gcl: sl.dgn_qty1, tp: sl.total_price };
+                if (scheduleStage.length > 0) {
+                    for (const ss of scheduleStage) {
+                        pushArray[ss.order + '_gather_tp'] = sl[ss.order + '_gather_tp'];
+                    }
+                }
+                under_ledger.push(pushArray);
             }
         }
         // 从最底层找出之前的所有父节点,删除他们可能存在已填的值
@@ -313,6 +342,21 @@ $(function () {
     //     });
     // })('a[name=showLevel]', ledgerSpread.getActiveSheet());
 });
+
+function calcStageTp(list) {
+    if (scheduleStage.length > 0) {
+        const stageTp = [];
+        for (const ss of scheduleStage) {
+            let stage_price = 0;
+            for (const l of list) {
+                stage_price = ZhCalc.add(stage_price, l[ss.order + '_gather_tp']);
+            }
+            stageTp.push({ id: ss.id, tp: stage_price });
+        }
+        return stageTp;
+    }
+    return false;
+}
 function addIsSelect(datas) {
     // const newDatas = [];
     for (const d of datas) {

+ 1 - 0
app/public/js/schedule_stage_tp.js

@@ -122,6 +122,7 @@ $(function () {
             const newLedgerList = setMonthToLedger(data.ledgerData, slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData);
             baseLedgerTree.loadDatas(newLedgerList);
             treeCalc.calculateAll(baseLedgerTree);
+            console.log(baseLedgerTree);
             for (const d of baseLedgerTree.nodes) {
                 if (!d.b_code) {
                     const one = _.find(selectedLedgerList, function (item) {

+ 5 - 0
app/service/schedule_ledger.js

@@ -118,6 +118,11 @@ module.exports = app => {
                     await this.ctx.service.scheduleMonth.calcPlan(transaction, this.ctx.tender.id);
                     await this.ctx.service.scheduleMonth.calcSj(transaction, this.ctx.tender.id);
                 }
+                // 判断是否已存在计量进度,并更新计量统计数据,再更新总的统计数据
+                if (datas.stageTpList) {
+                    await transaction.updateRows(this.ctx.service.scheduleStage.tableName, datas.stageTpList);
+                    await this.ctx.service.scheduleStage.calcStageSjTp(transaction, this.ctx.tender.id);
+                }
                 await transaction.commit();
                 return true;
             } catch (err) {

+ 1 - 0
app/view/schedule/ledger.ejs

@@ -52,4 +52,5 @@
     const thousandth = <%- ctx.tender.info.display.thousandth %>;
     const measureType = JSON.parse('<%- JSON.stringify(measureType) %>');
     const hadDataLidList = JSON.parse('<%- JSON.stringify(hadDataLidList) %>');
+    const scheduleStage = JSON.parse('<%- JSON.stringify(scheduleStage) %>');
 </script>