Browse Source

金额模式-done

laiguoran 4 years ago
parent
commit
cc2d82bd9f

+ 10 - 2
app/controller/schedule_controller.js

@@ -84,6 +84,7 @@ module.exports = app => {
             let nextSlmList = [];
             let endSlmList = [];
             let yearSlmList = [];
+            let curYearStageData = [];
             if (ctx.params.order && scheduleStage.length > 0) {
                 curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
             }
@@ -103,9 +104,15 @@ module.exports = app => {
                     return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
                 }), 'yearmonth');
                 yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
+                // 获取本年完成计量数据
+                const stageList = _.filter(stageOrderList, function(item) {
+                    return item.s_time.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
+                });
+                const stageIdList = _.map(_.filter(stageList, function(item) {
+                    return _.find(newSS, { order: item.order });
+                }), 'id');
+                curYearStageData = await ctx.service.stageBills.getStagesData(ctx.tender.id, stageIdList.join(','));
             }
-            // 获取本年完成计量数据
-
             const renderData = {
                 tender: tender.data,
                 tenderInfo: tender.info,
@@ -119,6 +126,7 @@ module.exports = app => {
                 nextSlmList,
                 endSlmList,
                 yearSlmList,
+                curYearStageData,
                 scheduleLedgerList: await this._getSelectedLedgerList(ctx),
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageTp),
             };

+ 19 - 10
app/public/js/schedule_stage_tp.js

@@ -22,6 +22,7 @@ $(function () {
         level: 'level',
         rootId: -1,
         fullPath: 'full_path',
+        calcFields: ['plan_gcl', 'plan_tp', 'next_plan_gcl', 'next_plan_tp', 'end_plan_gcl', 'end_plan_tp', 'year_plan_gcl', 'year_plan_tp'],
     };
     const ledgerTree = createNewPathTree('filter', treeSetting);
 
@@ -38,8 +39,8 @@ $(function () {
         {title: '|金额(万元)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 70, type: 'Number', readOnly: true},
         {title: '本年计划完成|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'year_plan_gcl', hAlign: 2, width: 70, type: 'Number', readOnly: true},
         {title: '|金额(万元)', colSpan: '|1', rowSpan: '|1', field: 'year_plan_tp', hAlign: 2, width: 70, type: 'Number', readOnly: true},
-        {title: '本年累计完成|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'dgn_qty1', hAlign: 2, width: 70, type: 'Number', readOnly: true},
-        {title: '|金额(万元)', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 70, type: 'Number', readOnly: true},
+        {title: '本年累计完成|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'year_contract_qty', hAlign: 2, width: 70, type: 'Number', readOnly: true},
+        {title: '|金额(万元)', colSpan: '|1', rowSpan: '|1', field: 'year_gather_tp', hAlign: 2, width: 70, type: 'Number', readOnly: true},
         {title: '本月计划完成|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'plan_gcl', hAlign: 2, width: 70, type: 'Number', readOnly: true},
         {title: '|金额(万元)', colSpan: '|1', rowSpan: '|1', field: 'plan_tp', hAlign: 2, width: 70, type: 'Number', readOnly: true},
         {title: '本期完成计量|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 70, type: 'Number', readOnly: true},
@@ -70,9 +71,11 @@ $(function () {
 
     if (curScheduleStage && curScheduleStage.order) {
         postData('/tender/' + getTenderId() + '/measure/stage/' + curScheduleStage.order + '/load', { filter: 'ledger' }, function (data) {
-            const calcList = ['contract_qty', 'end_gather_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
+            const calcList = ['year_contract_qty', 'year_gather_tp',
+                'contract_qty', 'end_gather_qty', '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'];
             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'];
@@ -85,7 +88,7 @@ $(function () {
                 fullPath: 'full_path',
                 calcFields: calcList,
             };
-            baseLedgerTreeSetting.updateFields = ['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', '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);
@@ -113,11 +116,9 @@ $(function () {
                 node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
             };
             const baseLedgerTree = createNewPathTree('base', baseLedgerTreeSetting);
-            const newLedgerList = setMonthToLedger(data.ledgerData, slmList, nextSlmList, endSlmList, yearSlmList);
-            console.log(newLedgerList);
+            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) {
@@ -128,9 +129,8 @@ $(function () {
                     }
                 }
             }
-            console.log(ledgerTree);
             ledgerTree.sortTreeNode(true);
-            // console.log(ledgerTree);
+            treeCalc.calculateAll(ledgerTree);
             SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
         }, null, true);
     }
@@ -267,7 +267,7 @@ function setLeafData(tree) {
     return newtree;
 }
 
-function setMonthToLedger(ledgerList, slm, nextSlm, endSlm, yearSlm) {
+function setMonthToLedger(ledgerList, slm, nextSlm, endSlm, yearSlm, yearLedgerData) {
     if (slm.length > 0) {
         for(const s of slm) {
             const index = _.findIndex(ledgerList, { 'ledger_id': s.lid });
@@ -304,6 +304,15 @@ function setMonthToLedger(ledgerList, slm, nextSlm, endSlm, yearSlm) {
             }
         }
     }
+    if (yearLedgerData.length > 0) {
+        for (const yl of yearLedgerData) {
+            const index = _.findIndex(ledgerList, {'id': yl.lid});
+            if (index && index !== -1) {
+                ledgerList[index].year_contract_qty = ZhCalc.add(yl.contract_qty, yl.qc_qty);
+                ledgerList[index].year_gather_tp = ZhCalc.add(yl.contract_tp, yl.qc_tp);
+            }
+        }
+    }
     return ledgerList;
 }
 const is_numeric = (value) => {

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

@@ -62,4 +62,5 @@
     const nextSlmList = JSON.parse('<%- JSON.stringify(nextSlmList) %>');
     const endSlmList = JSON.parse('<%- JSON.stringify(endSlmList) %>');
     const yearSlmList = JSON.parse('<%- JSON.stringify(yearSlmList) %>');
+    const curYearStageData = JSON.parse('<%- JSON.stringify(curYearStageData) %>');
 </script>