Jelajahi Sumber

汇总表,标段信息数据

MaiXinRong 5 tahun lalu
induk
melakukan
f37423aa31
3 mengubah file dengan 229 tambahan dan 6 penghapusan
  1. 5 0
      app/service/report.js
  2. 191 4
      app/service/rpt_gather_memory.js
  3. 33 2
      builder_report_index_define.js

+ 5 - 0
app/service/report.js

@@ -125,6 +125,11 @@ module.exports = app => {
                                 customDefine.gather_select, customSelect ? customSelect.gather_select : null));
                             runnableKey.push(filter);
                             break;
+                        case 'mem_gather_tender_info':
+                            runnableRst.push(service.rptGatherMemory.getGatherTenderInfo(memFieldKeys[filter],
+                                customDefine.gather_select, customSelect ? customSelect.gather_select : null));
+                            runnableKey.push(filter);
+                            break;
                         default:
                             break;
                     }

+ 191 - 4
app/service/rpt_gather_memory.js

@@ -124,6 +124,7 @@ module.exports = app => {
                 level: 'level',
                 rootId: -1
             });
+            this.resultTenderInfo = [];
         }
 
         _checkSpecialTender(tender, special) {
@@ -135,6 +136,9 @@ module.exports = app => {
             return '';
         }
 
+        /**
+         * 台账数据
+         */
         async _gatherStageData(index, tender, stage, hasPre) {
             const helper = this.ctx.helper;
             const billsTree = new Ledger.billsTree(this.ctx, {
@@ -308,7 +312,7 @@ module.exports = app => {
             await this._gatherStageData(index, tender, stages[0], hasPre);
         }
 
-        async _gatherLegerData(sTender, index) {
+        async _gatherLedgerData(sTender, index) {
             const helper = this.ctx.helper;
             const billsTree = new Ledger.billsTree(this.ctx, {
                 id: 'ledger_id',
@@ -318,7 +322,7 @@ module.exports = app => {
                 rootId: -1,
                 keys: ['id', 'tender_id', 'ledger_id'],
                 stageId: 'id',
-                calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
+                calcFields: ['deal_tp', 'total_price'],
             });
             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
             const billsData = await this.ctx.service.ledger.getData(tender.id);
@@ -339,7 +343,7 @@ module.exports = app => {
                 rootId: -1,
                 keys: ['id', 'tender_id', 'ledger_id'],
                 stageId: 'id',
-                calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
+                calcFields: ['deal_tp', 'total_price'],
             });
             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
             const billsData = await this.ctx.service.ledger.getData(tender.id);
@@ -373,7 +377,7 @@ module.exports = app => {
                             await this._gatherCheckedFinalData(tender, commonIndex, gsSetting.hasPre);
                             break;
                         case 'ledger':
-                            await this._gatherLegerData(tender, commonIndex);
+                            await this._gatherLedgerData(tender, commonIndex);
                             break;
                     }
                     commonIndex++;
@@ -386,6 +390,189 @@ module.exports = app => {
             return this.resultTree.getDefaultDatas();
         }
 
+        /**
+         * 标段信息
+         */
+        async _getBaseTenderInfo(tender) {
+            const info = {
+                id: tender.id,
+                name: tender.name,
+
+                deal_tp: tender.deal_tp,
+                tp: tender.total_price
+            };
+            if (tender.ledger_status === auditConst.ledger.status.uncheck || tender.ledger_status === auditConst.ledger.status.checkNo) {
+                const sum = await this.ctx.service.ledger.addUp({tender_id: tender.id/*, is_leaf: true*/});
+                info.tp = sum.total_price;
+                info.deal_tp = sum.deal_tp;
+            }
+            return info;
+        }
+        async _getStageTenderInfo(stage, info) {
+            if (stage) {
+                const helper = this.ctx.helper;
+                await this.ctx.service.stage.doCheckStage(stage);
+                await this.ctx.service.stage.checkStageGatherData(stage);
+
+                info.pre_contract_tp = stage.pre_contract_tp;
+                info.pre_qc_tp = stage.pre_qc_tp;
+                info.pre_gather_tp = helper.add(info.pre_contract_tp, info.pre_qc_tp);
+
+                info.contract_tp = stage.contract_tp;
+                info.qc_tp = stage.qc_tp;
+                info.gather_tp = helper.add(info.contract_tp, info.qc_tp);
+
+                info.end_contract_tp = helper.add(info.pre_contract_tp, info.contract_tp);
+                info.end_qc_tp = helper.add(info.pre_qc_tp, info.qc_tp);
+                info.end_gather_tp = helper.add(info.pre_gather_tp, info.gather_tp);
+
+                info.yf = stage.yf;
+                info.pre_yf = stage.pre_yf;
+                info.end_yf = helper.add(stage.yf, stage.pre_yf);
+            }
+        }
+
+        async _gatherMonthTenderInfo(sTender, index, month, hasPre) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            const info = this._getBaseTenderInfo(tender);
+            const stage = await this.ctx.service.stage.getDataByCondition({tid: tender.id, s_time: month});
+            this._getStageTenderInfo(stage, info);
+            this.resultTenderInfo.push(info);
+        }
+
+        async _gatherZoneTenderInfo(sTender, index, zone) {
+            const helper = this.ctx.helper;
+            /**
+             * 汇总并合并 相关数据
+             * @param {Array} index - 主数据
+             * @param {Array[]}rela - 相关数据 {data, fields, prefix, relaId}
+             */
+            const sumAssignRelaData = function (index, rela) {
+                const loadFields = function (datas, fields, prefix, relaId) {
+                    for (const d of datas) {
+                        const key = indexPre + d[relaId];
+                        const m = index[key];
+                        if (m) {
+                            for (const f of fields) {
+                                if (d[f] !== undefined) {
+                                    m[prefix + f] = helper.add(m[prefix + f], d[f]);
+                                }
+                            }
+                        }
+                    }
+                };
+                for (const r of rela) {
+                    loadFields(r.data, r.fields, r.prefix, r.relaId);
+                }
+            };
+
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            const info = this._getBaseTenderInfo(tender);
+
+            const times = zone.split(' - ');
+            if (times.length !== 2) throw '选择的汇总周期无效';
+            const beginTime = moment(times[0], 'YYYY-MM').date();
+            const endTime = moment(times[1], 'YYYY-MM').date();
+
+            const stages = await this.ctx.service.stage.getAllDataByCondition({ where: { tid: tender.id } });
+            for (const stage of stages) {
+                const sTime = moment(stage.s_time, 'YYYY-MM').date();
+                if (sTime >= beginTime && sTime <= endTime) {
+                    await this.ctx.service.stage.doCheckStage(stage);
+                    await this.ctx.service.stage.checkStageGatherData(stage);
+
+                    info.contract_tp = helper.add(info.contract_tp, stage.contract_tp);
+                    info.qc_tp = helper.add(info.qc_tp, stage.qc_tp);
+
+                    info.yf = helper.add(info.yf, stage.yf);
+                }
+            }
+            info.gather_tp = helper.add(info.contract_tp, info.qc_tp);
+
+            this.resultTenderInfo.push(info);
+        }
+
+        async _gatherFinalTenderInfo(sTender, index, hasPre) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            const info = this._getBaseTenderInfo(tender);
+            const stages = await this.db.select(this.ctx.service.stage.tableName, {
+                where: { tid: tender.id },
+                orders: [['order', 'desc']],
+            });
+            if (stages.length !== 0) {
+                const lastStage = stages[0];
+                if (lastStage.status === auditConst.stage.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
+                    stages.splice(0, 1);
+                }
+            }
+            await this._getStageTenderInfo(stages[0], info);
+            this.resultTenderInfo.push(info);
+        }
+
+        async _gatherCheckedFinalTenderInfo(sTender, index, hasPre) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            const info = this._getBaseTenderInfo(tender);
+            const stages = await this.db.select(this.ctx.service.stage.tableName, {
+                where: { tid: tender.id },
+                orders: [['order', 'desc']],
+            });
+            if (stages.length !== 0) {
+                const lastStage = stages[0];
+                if (lastStage.status !== auditConst.stage.status.checked) {
+                    stages.splice(0, 1);
+                }
+            }
+            await this._getStageTenderInfo(stages[0], info);
+            this.resultTenderInfo.push(info);
+        }
+
+        async _gatherLedgerTenderInfo(sTender, index) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            const info = this._getBaseTenderInfo(tender);
+            this.resultTenderInfo.push(info);
+        }
+
+        async _gatherSpecialTenderInfo(sTender, sKey) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+
+            const info = this._getBaseTenderInfo(tender);
+            info.spec = sKey;
+            this.resultTenderInfo.push(info);
+        }
+
+        async getGatherTenderInfo(memFieldKeys, gsDefine, gsCustom) {
+            if (!gsDefine || !gsDefine.enable) return [];
+            if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
+
+            this.resultTenderInfo = [];
+            const gsSetting = JSON.parse(gsDefine.setting);
+            let commonIndex = 0;
+            for (const tender of gsCustom.tenders) {
+                const specialKey = this._checkSpecialTender(tender, gsSetting.special);
+                if (specialKey === '') {
+                    switch (gsSetting.type) {
+                        case 'month':
+                            await this._gatherMonthTenderInfo(tender, commonIndex, gsCustom.month, gsSetting.hasPre);
+                            break;
+                        case 'zone':
+                            await this._gatherZoneTenderInfo(tender, commonIndex, gsCustom.zone);
+                            break;
+                        case 'final':
+                            await this._gatherFinalTenderInfo(tender, commonIndex, gsSetting.hasPre);
+                            break;
+                        case 'checked-final':
+                            await this._gatherCheckedFinalTenderInfo(tender, commonIndex, gsSetting.hasPre);
+                            break;
+                        case 'ledger':
+                            await this._gatherLedgerTenderInfo(tender, commonIndex);
+                            break;
+                    }
+                    commonIndex++;
+                } else {
+                    await this._gatherSpecialTenderInfo(tender, specialKey);
+                }
+            }
+        }
     }
 
     return RptGatherMemory;

+ 33 - 2
builder_report_index_define.js

@@ -429,7 +429,7 @@ const stage_im_tz_bills = {
 const gather_stage_bills = {
     name: '汇总-清单数据表(mem_gather_stage_bills)',
     remark: '',
-    id: 33,
+    id: 36,
     key: 'mem_gather_stage_bills',
     prefix: '汇总-清单数据',
     cols: [
@@ -500,6 +500,37 @@ const gather_stage_bills = {
         { name: '(特殊3-需替换key3)台账-金额', field: 'ts_key3_tp', type: dataType.currency },
     ],
 };
+const gather_tender_info = {
+    name: '汇总-标段信息(mem_gather_tender_info)',
+    remark: '',
+    id: 37,
+    key: 'mem_gather_tender_info',
+    prefix: '汇总-标段信息',
+    cols: [
+        { name: 'id', field: 'id', type: dataType.int},
+        { name: '名称', field: 'name', type: dataType.str },
+        { name: '是否特殊标', field: 'spec', type: dataType.str },
+
+        { name: '台账-金额', field: 'tp', type: dataType.currency },
+        { name: '签约-金额', field: 'deal_tp', type: dataType.currency },
+
+        { name: '本期-合同-金额', field: 'contract_tp', type: dataType.currency },
+        { name: '本期-变更-金额', field: 'qc_tp', type: dataType.currency },
+        { name: '本期-完成-金额', field: 'gather_tp', type: dataType.currency },
+
+        { name: '截止上期-合同-金额', field: 'pre_contract_tp', type: dataType.currency },
+        { name: '截止上期-变更-金额', field: 'pre_qc_tp', type: dataType.currency },
+        { name: '截止上期-完成-金额', field: 'pre_gather_tp', type: dataType.currency },
+
+        { name: '截止本期-合同-金额', field: 'end_contract_tp', type: dataType.currency },
+        { name: '截止本期-变更-金额', field: 'end_qc_tp', type: dataType.currency },
+        { name: '截止本期-完成-金额', field: 'end_gather_tp', type: dataType.currency },
+
+        { name: '截止上期-应付', field: 'pre_yf', type: dataType.currency },
+        { name: '本期-应付', field: 'yf', type: dataType.currency },
+        { name: '截止本期-应付', field: 'end_yf', type: dataType.currency },
+    ],
+};
 
 const recursiveMkdirSync = async function(pathName) {
     if (!fs.existsSync(pathName)) {
@@ -596,7 +627,7 @@ const defines = [stage_jgcl, stage_bonus, stage_other,
     stage_pos, stage_pos_compare,
     stage_pay,
     stage_im_zl, stage_im_tz, stage_im_tz_bills,
-    gather_stage_bills,
+    gather_stage_bills, gather_tender_info,
 ];
 for (const d of defines) {
     exportTableDefine(d);