Pārlūkot izejas kodu

部位台账,1#完成率

MaiXinRong 3 gadi atpakaļ
vecāks
revīzija
c15d502be6

+ 10 - 1
app/controller/stage_controller.js

@@ -1416,6 +1416,16 @@ module.exports = app => {
                 const ledgerData = await this._getStageLedgerData(ctx);
                 const posData = await this._getStagePosData(ctx);
                 const changeData = await this._getStageChangeData(ctx);
+                const preMinusChange = await this.ctx.service.stageChangeFinal.getPreMinusChange(ctx.stage.tid, ctx.stage.order);
+                const minusChange = changeData.filter(x => { return x.minus });
+                this.ctx.helper.assignSumRelaData(ledgerData, 'id', [
+                    {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'lid'},
+                    {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'lid'},
+                ]);
+                this.ctx.helper.assignSumRelaData(posData, 'id', [
+                    {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'pid'},
+                    {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'pid'},
+                ]);
                 const convert = new billsPosConvert(ctx);
                 convert.loadData(ledgerData, posData, changeData);
                 const result = convert.convert(data.filter);
@@ -1492,7 +1502,6 @@ module.exports = app => {
                     const filepath = `app/public/upload/${this.ctx.tender.id}/stage/fujian_${create_time + index.toString() + fileInfo.ext}`;
                     // await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, filepath));
                     await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
-                    // console.log(await fs.existsSync(path.resolve(this.app.baseDir, 'app', filepath)));
                     // const fileInfo = path.parse(stream.filename);
                     // const fileName = 'stage' + create_time + '_' + index + fileInfo.ext;
                     // 保存文件

+ 28 - 3
app/extend/helper.js

@@ -847,6 +847,34 @@ module.exports = {
             loadFields(r.data, r.fields, r.prefix, r.relaId);
         }
     },
+    /**
+     * 合并(并汇总) 相关数据
+     * @param {Array} main - 主数据
+     * @param {Array[]}rela - 相关数据 {data, fields, relaField}
+     *
+     * { data, fields}
+     */
+    assignSumRelaData(main, keyField, rela) {
+        const index = {},
+            indexPre = 'id_';
+        const addFun = this.add;
+        const loadFields = function(datas, fields, relaId) {
+            for (const d of datas) {
+                const key = indexPre + d[relaId];
+                const m = index[key];
+                if (!m) continue;
+                for (const f of fields) {
+                    if (d[f.source]) m[f.target] = addFun(m[f.target], d[f.source]);
+                }
+            }
+        };
+        for (const m of main) {
+            index[indexPre + m[keyField]] = m;
+        }
+        for (const r of rela) {
+            loadFields(r.data, r.fields, r.relaField);
+        }
+    },
 
     whereSql(where, as) {
         if (!where) {
@@ -1460,9 +1488,6 @@ module.exports = {
     },
 
     getStartEndMonth(month) {
-        // month = new Date('2021-10-03');
-        // const startMonth = new Date(month.getFullYear(), month.getMonth(), 1);
-        // const endMonth = new Date(month.getFullYear(), month.getMonth() + 1, 1);
         const startMonth = moment(month).startOf('month').format('YYYY-MM-DD HH:mm:ss');
         const endMonth = moment(month).endOf('month').format('YYYY-MM-DD HH:mm:ss');
         return [startMonth, endMonth];

+ 16 - 0
app/lib/bills_pos_convert.js

@@ -98,6 +98,9 @@ class BillsPosConvert {
         node.pre_gather_qty = this.ctx.helper.add(node.pre_gather_qty, data.pre_gather_qty);
 
         node.real_qty = this.ctx.helper.add(node.real_qty, data.real_qty);
+
+        node.minus_qc_qty = this.ctx.helper.add(node.minus_qc_qty, data.minus_qc_qty);
+        node.pre_minus_qc_qty = this.ctx.helper.add(node.pre_minus_qc_qty, data.pre_minus_qc_qty);
     }
     _loadBillsCalcFields(node, data) {
         node.quantity = this.ctx.helper.add(node.quantity, data.quantity);
@@ -114,6 +117,9 @@ class BillsPosConvert {
         node.pre_qc_qty = this.ctx.helper.add(node.pre_qc_qty, data.pre_qc_qty);
         node.pre_qc_tp = this.ctx.helper.add(node.pre_qc_tp, data.pre_qc_tp);
         node.pre_gather_qty = this.ctx.helper.add(node.pre_gather_qty, data.pre_gather_qty);
+
+        node.minus_qc_qty = this.ctx.helper.add(node.minus_qc_qty, data.minus_qc_qty);
+        node.pre_minus_qc_qty = this.ctx.helper.add(node.pre_minus_qc_qty, data.pre_minus_qc_qty);
     }
     _convertGcl(node, xmj) {
         if (!xmj) return;
@@ -235,6 +241,13 @@ class BillsPosConvert {
         child.estimate_tp = this.ctx.helper.mul(child.estimate_qty, child.unit_price, tpDecimal);
 
         child.bgl_code = this.ctx.helper._.uniq(this.ctx.helper._.map(child.changes, 'c_code')).join(';');
+
+        // 1#台账相关
+        child.end_minus_qc_qty = this.ctx.helper.add(child.pre_minus_qc_qty, child.minus_qc_qty); // 1#台账 台账+负变更
+        child.end_1_qty = this.ctx.helper.add(child.end_minus_qc_qty, child.quantity); // 1#台账 台账+负变更
+        child.end_1_tp = this.ctx.helper.mul(child.unit_price, child.end_1_qty, tpDecimal);
+        child.end_final_1_tp = this.ctx.helper.add(child.end_qc_tp, child.end_1_tp);
+        child.end_gather_1_percent = this.ctx.helper.mul(this.ctx.helper.div(child.end_gather_tp, child.end_final_1_tp, 4), 100);
     }
     _calculateNode(node, children) {
         for (const child of children) {
@@ -250,11 +263,14 @@ class BillsPosConvert {
             node.end_gather_tp = this.ctx.helper.add(node.end_gather_tp, child.end_gather_tp);
             node.real_tp = this.ctx.helper.add(node.real_tp, child.real_tp);
             node.estimate_tp = this.ctx.helper.add(node.estimate_tp, child.estimate_tp);
+            node.end_1_tp = this.ctx.helper.add(node.end_1_tp, child.end_1_tp);
         }
         if (node.dgn_qty1)
             node.dgn_price = this.ctx.helper.div(node.total_price, node.dgn_qty1, this.ctx.tender.info.decimal.up);
         node.final_tp = this.ctx.helper.add(node.total_price, node.end_qc_tp);
         node.end_gather_percent = this.ctx.helper.mul(this.ctx.helper.div(node.end_gather_tp, node.final_tp, 4), 100);
+        node.end_final_1_tp = this.ctx.helper.add(node.end_qc_tp, node.end_1_tp);
+        node.end_gather_1_percent = this.ctx.helper.mul(this.ctx.helper.div(node.end_gather_tp, node.end_final_1_tp, 4), 100);
     }
     _recursiveCalcUnitNodes(nodes) {
         if (!nodes || !nodes instanceof Array || nodes.length === 0) return;

+ 3 - 0
app/public/js/stage_bwtz.js

@@ -90,6 +90,9 @@ $(document).ready(() => {
     xmjSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
         unitTreeObj.loadCurUnitData();
     });
+    unitSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
+        console.log(SpreadJsObj.getSelectObject(info.sheet));
+    });
     const loadData = function (dataType) {
         postData(window.location.pathname + '/load', {filter: dataType}, function (result) {
             const setting = {

+ 4 - 2
app/view/stage/bwtz.ejs

@@ -166,10 +166,11 @@
             {title: '本期计量金额|合同计量', colSpan: '3|1', rowSpan: '1|1', field: 'contract_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|完成计量', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 70, type: 'Number'},
-            {title: '截止本期计量金额|合同计量', colSpan: '4|1', rowSpan: '1|1', field: 'end_contract_tp', hAlign: 2, width: 70, type: 'Number'},
+            {title: '截止本期计量金额|合同计量', colSpan: '5|1', rowSpan: '1|1', field: 'end_contract_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|完成计量', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 70, type: 'Number'},
+            {title: '|1#完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
             {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
             {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
@@ -242,9 +243,10 @@
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
             {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
-            {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
+            {title: '截止本期完成计量|数量', colSpan: '4|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
             {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
+            {title: '|1#完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code_merge', hAlign: 0, width: 80, formatter: '@'},
             {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil_merge', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
             {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo_merge', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},