Jelajahi Sumber

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 4 tahun lalu
induk
melakukan
35b9fe138f

+ 20 - 4
app/controller/schedule_controller.js

@@ -158,7 +158,7 @@ module.exports = app => {
             const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
             const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
             // const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
-            const gclScheduleMonth = _.filter(scheduleMonth, { stage_gcl_used: 1 });
+            const gclScheduleMonth = _.orderBy(_.filter(scheduleMonth, { stage_gcl_used: 1 }), ['yearmonth'], ['desc']);
             const curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(gclScheduleMonth, 'yearmonth') : null;
             const renderData = {
                 tender: tender.data,
@@ -184,7 +184,8 @@ module.exports = app => {
          */
         async loadTpLedgerData(ctx) {
             try {
-                const ledgerData = await this._getStageLedgerData(ctx, ctx.params.order);
+                const highOrder = await ctx.service.scheduleStage.count({ tid: ctx.tender.id });
+                const ledgerData = await this._getStageLedgerData(ctx, ctx.params.order, highOrder);
                 const postData = { ledgerData };
                 const data = JSON.parse(ctx.request.body.data);
                 if (data.filter && data.filter === 'gcl') {
@@ -255,7 +256,7 @@ module.exports = app => {
             return ledgerData;
         }
 
-        async _getStageLedgerData(ctx, stageOrder) {
+        async _getStageLedgerData(ctx, stageOrder, highOrder) {
             const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
             const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
             for (const d of dgnData) {
@@ -266,7 +267,7 @@ module.exports = app => {
                 tid: ctx.tender.id,
                 order: stageOrder,
             });
-            let preStageData;
+            let preStageData, prefinalStageData;
             // 当前操作人查看最新数据,其他人查看历史数据
             const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
             // 查询截止上期数据
@@ -279,6 +280,21 @@ module.exports = app => {
                 { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
                 { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid' },
             ]);
+            // 获取进度最新期的数据
+            const finalStageInfo = await ctx.service.stage.getDataByCondition({
+                tid: ctx.tender.id,
+                order: highOrder,
+            });
+            const finalStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, finalStageInfo.id);
+            if (finalStageInfo.order > 1) {
+                prefinalStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, finalStageInfo.order - 1);
+            } else {
+                prefinalStageData = [];
+            }
+            this.ctx.helper.assignRelaData(ledgerData, [
+                { data: finalStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: 'final_', relaId: 'lid' },
+                { data: prefinalStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_final_', relaId: 'lid' },
+            ]);
             return ledgerData;
         }
 

+ 16 - 6
app/public/js/schedule_stage_tp.js

@@ -34,7 +34,7 @@ $(function () {
             node.year_contract_qty = ZhCalc.round(ZhCalc.div(node.year_gather_tp, node.dgn_price), 3);
             node.contract_qty = ZhCalc.round(ZhCalc.div(node.gather_tp, node.dgn_price), 3);
         },
-        calcFields: ['plan_tp', 'next_plan_tp', 'end_plan_tp', 'year_plan_tp', 'total_price', 'end_gather_tp', 'year_gather_tp', 'gather_tp'],
+        calcFields: ['plan_tp', 'next_plan_tp', 'end_plan_tp', 'year_plan_tp', 'total_price', 'end_gather_tp', 'year_gather_tp', 'gather_tp', 'end_final_gather_tp'],
     };
     const ledgerTree = createNewPathTree('filter', treeSetting);
 
@@ -87,12 +87,14 @@ $(function () {
         postData('/tender/' + getTenderId() + '/schedule/stage/' + curScheduleStage.order + '/load', {}, function (data) {
             const calcList = ['year_gather_tp',
                 'contract_tp', 'qc_qty', 'qc_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'];
+                'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp',
+                'final_contract_tp', 'final_qc_tp', 'pre_final_contract_tp', 'pre_final_qc_tp', 'pre_final_gather_tp', 'final_gather_tp', 'end_final_gather_tp'];
             const showList = ['plan_gcl', 'plan_tp', 'next_plan_gcl', 'next_plan_tp', 'end_plan_gcl', 'end_plan_tp', 'year_plan_gcl', 'year_plan_tp',
                 'year_contract_qty', 'year_gather_tp',
                 'contract_qty', 'end_gather_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
                 'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', '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'];
+                'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp',
+                'final_contract_tp', 'final_qc_tp', 'pre_final_contract_tp', 'pre_final_qc_tp', 'pre_final_gather_tp', 'final_gather_tp', 'end_final_gather_tp'];
             const baseLedgerTreeSetting = {
                 id: 'ledger_id',
                 pid: 'ledger_pid',
@@ -102,7 +104,7 @@ $(function () {
                 fullPath: 'full_path',
                 calcFields: calcList,
             };
-            baseLedgerTreeSetting.updateFields = ['year_contract_qty', 'year_gather_tp', 'contract_qty', 'end_gather_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
+            baseLedgerTreeSetting.updateFields = ['year_contract_qty', 'year_gather_tp', 'contract_qty', 'end_gather_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'final_contract_tp', 'final_qc_tp', 'postil', 'used', 'contract_expr'];
             baseLedgerTreeSetting.calcFun = function (node) {
                 if (!node.children || node.children.length === 0) {
                     node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
@@ -128,6 +130,10 @@ $(function () {
                 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);
                 node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
+
+                node.pre_final_gather_tp = ZhCalc.add(node.pre_final_contract_tp, node.pre_final_qc_tp);
+                node.final_gather_tp = ZhCalc.add(node.final_contract_tp, node.final_qc_tp);
+                node.end_final_gather_tp = ZhCalc.add(node.pre_final_gather_tp, node.final_gather_tp);
             };
             const baseLedgerTree = createNewPathTree('base', baseLedgerTreeSetting);
             const newLedgerList = setMonthToLedger(data.ledgerData, slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData);
@@ -146,6 +152,7 @@ $(function () {
             ledgerTree.sortTreeNode(true);
             treeCalc.calculateAll(ledgerTree);
             calcGatherTpAndUpdate(ledgerTree.nodes);
+            console.log(ledgerTree);
             SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
         }, null, true);
     }
@@ -222,15 +229,18 @@ $(function () {
 function calcGatherTpAndUpdate(tree) {
     if (tree.length > 0) {
         let total_tp = 0;
+        let final_total_tp = 0;
         for (const t of tree) {
             if (t.is_leaf && t.gather_tp) {
                 total_tp = ZhCalc.add(total_tp, t.gather_tp);
+                final_total_tp = ZhCalc.add(final_total_tp, t.end_final_gather_tp);
             }
         }
         console.log(curScheduleStage.tp, total_tp);
-        if (curScheduleStage.tp !== total_tp) {
+        console.log(schedule.stage_sj_tp, final_total_tp);
+        if (curScheduleStage.tp !== total_tp || schedule.stage_sj_tp !== final_total_tp) {
             // 更新计量总金额并更新金额模式总金额
-            postData('/tender/' + getTenderId() + '/schedule/stage/save', { type: 'update_tp', postData: { tp: total_tp, order: curScheduleStage.order } }, function (data) {
+            postData('/tender/' + getTenderId() + '/schedule/stage/save', { type: 'update_tp', postData: { tp: total_tp, stage_sj_tpL: final_total_tp, order: curScheduleStage.order } }, function (data) {
                 console.log('总金额已更新');
             })
         }

+ 11 - 2
app/service/schedule_stage.js

@@ -96,8 +96,17 @@ module.exports = app => {
                     },
                 };
                 await transaction.update(this.tableName, updateData, option);
-                // 重算计量总金额
-                await this.calcStageSjTp(transaction, this.ctx.tender.id);
+                // 更新计量总金额
+                const stageData = {
+                    stage_sj_tp: data.stage_sj_tp,
+                };
+                const stageOption = {
+                    where: {
+                        tid: this.ctx.tender.id,
+                    },
+                };
+                await transaction.update(this.ctx.service.schedule.tableName, stageData, stageOption);
+                // await this.calcStageSjTp(transaction, this.ctx.tender.id);
                 await transaction.commit();
                 return true;
             } catch (err) {