Bläddra i källkod

汇总表,签约清单数据

MaiXinRong 5 år sedan
förälder
incheckning
dcd297b387

+ 5 - 0
app/service/report.js

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

+ 72 - 0
app/service/rpt_gather_memory.js

@@ -131,6 +131,7 @@ module.exports = app => {
             });
             this.resultTenderInfo = [];
             this.resultDealpPay = [];
+            this.resultDealBills = [];
         }
 
         _checkSpecialTender(tender, special) {
@@ -716,6 +717,77 @@ module.exports = app => {
             }
             return this.resultDealpPay;
         }
+
+        /**
+         * 签约清单
+         */
+        async _gatherDealBills(tender, fun) {
+            const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({
+                where: { tender_id: tender.id }
+            });
+            for (const db of dealBills) {
+                let rdb = this.ctx.helper._.find(this.resultDealBills, {
+                    code: db.code,
+                    name: db.name,
+                    unit: db.unit,
+                    unit_price: db.unit_price ? db.unit_price: 0,
+                });
+                if (!rdb) {
+                    rdb = {
+                        code: db.code,
+                        name: db.name,
+                        unit: db.unit,
+                        unit_price: db.unit_price ? db.unit_price: 0,
+                    };
+                    this.resultDealBills.push(rdb);
+                }
+                if (fun) fun(rdb, db);
+            }
+        }
+
+        async _gatherCommonDealBills(sTender, index) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            await this._gatherDealBills(tender, function (gatherData, sourceData) {
+                const prefix = 't_' + index + '_';
+                gatherData[prefix + 'id'] = tender.id;
+                gatherData[prefix + 'name'] = tender.name;
+
+                gatherData[prefix + 'qty'] = sourceData.quantity;
+                gatherData[prefix + 'tp'] = sourceData.total_price;
+
+                gatherData['s_' + 'qty'] = sourceData.quantity;
+                gatherData['s_' + 'tp'] = sourceData.total_price;
+            });
+        }
+
+        async _gatherSpecialDealBills(sTender, sKey) {
+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid);
+            await this._gatherDealBills(tender, function (gatherData, sourceData) {
+                const prefix = 'st_' + sKey + '_';
+
+                gatherData[prefix + 'qty'] = sourceData.quantity;
+                gatherData[prefix + 'tp'] = sourceData.total_price;
+            });
+        }
+
+        async getGatherDealBills(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 === '') {
+                    await this._gatherCommonDealBills(tender, commonIndex);
+                    commonIndex++;
+                } else {
+                    await this._gatherSpecialDealBills(tender, specialKey);
+                }
+            }
+            return this.resultDealBills;
+        }
     }
 
     return RptGatherMemory;

+ 28 - 4
builder_report_index_define.js

@@ -440,7 +440,7 @@ const gather_stage_bills = {
         { name: '单价', field: 'unit_price', type: dataType.currency },
 
         { name: '标段id', field: 't_id', type: dataType.int },
-        { name: '标段-名称', field: 't_name', type: dataType.int },
+        { name: '标段-名称', field: 't_name', type: dataType.str },
 
         { name: '(标段)台账-数量', field: 't_qty', type: dataType.currency },
         { name: '(标段)台账-金额', field: 't_tp', type: dataType.currency },
@@ -544,7 +544,7 @@ const gather_stage_pay = {
         { name: '是否参与本期应付计算', field: 'minus', type: dataType.int },
 
         { name: '标段id', field: 't_id', type: dataType.int },
-        { name: '标段-名称', field: 't_name', type: dataType.int },
+        { name: '标段-名称', field: 't_name', type: dataType.str },
 
         { name: '(标段)本期-金额', field: 't_tp', type: dataType.currency },
         { name: '(标段)截止上期-金额', field: 't_pre_tp', type: dataType.currency },
@@ -555,6 +555,30 @@ const gather_stage_pay = {
         { name: '(合计)截止本期-金额', field: 's_end_tp', type: dataType.currency },
     ],
 };
+const gather_deal_bills = {
+    name: '汇总-签约清单 数据表(mem_gather_deal_bills)',
+    remark: '',
+    id: 39,
+    key: 'mem_gather_deal_bills',
+    prefix: '汇总-期-合同支付',
+    cols: [
+        { name: '编号', field: 'code', type: dataType.str },
+        { name: '名称', field: 'name', type: dataType.str },
+        { name: '单位', field: 'unit', type: dataType.str },
+        { name: '单价', field: 'unit_price', type: dataType.currency },
+
+        { name: '标段id', field: 't_id', type: dataType.int },
+        { name: '标段-名称', field: 't_name', type: dataType.str },
+
+        { name: '(标段)本期-金额', field: 't_tp', type: dataType.currency },
+
+        { name: '(合计)本期-金额', field: 's_tp', type: dataType.currency },
+
+        { name: '(特殊1)本期-金额', field: 'ts_key1_tp', type: dataType.currency },
+        { name: '(特殊2)本期-金额', field: 'ts_key2_tp', type: dataType.currency },
+        { name: '(特殊3)本期-金额', field: 'ts_key3_tp', type: dataType.currency },
+    ],
+};
 
 const recursiveMkdirSync = async function(pathName) {
     if (!fs.existsSync(pathName)) {
@@ -576,7 +600,7 @@ const saveBufferFile = async function(buffer, fileName) {
 const addFields = function(table, col) {
     const data = {};
     data.ID = table.ID * 100 + (col.id ? Math.max(table.items.length + 1, col.id) : table.items.length + 1);
-    data.Name = col.name + (col.field ? '(' + col.field + ')' : '');
+    data.Name = col.name + (col.field ? '(' + col.field + ')' : '') + (data.ID ? '(id: ' + data.ID + ')' : '');
     if (table.prefix && table.prefix !== '') data.Name = table.prefix + '-' + data.Name;
     data.DataType = col.type;
     data.TableName = table.key;
@@ -651,7 +675,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_tender_info, gather_stage_pay
+    gather_stage_bills, gather_tender_info, gather_stage_pay, gather_deal_bills,
 ];
 for (const d of defines) {
     exportTableDefine(d);

+ 42 - 0
test/app/service/rpt_gather_memory.test.js

@@ -156,4 +156,46 @@ describe('test/app/service/rpt_gather_memory.test.js', () => {
         // yield ctx.helper.saveBufferFile(JSON.stringify(reportData, "", "\t"), path.join(savePath, 'mem_gather_stage_bills_coverse.json'));
         // assert(reportData.mem_gather_stage_bills.length === mem_gather_stage_bills.length * 2);
     });
+    it('test getGatherDealBills - final', function* () {
+        const ctx = app.mockContext(mockData);
+
+        // const select = {
+        //     tenders: [{tid: 2256}, {tid: 2257}, {tid: 2258, gs: true}],
+        //     type: 'month',
+        //     month: '2020-01',
+        // };
+        const select = {
+            tenders: [{tid: 2256}, {tid: 2257}],
+            type: 'final',
+        };
+        // const define = {
+        //     enable: true,
+        //     setting: JSON.stringify({
+        //         title: '请选择汇总的标段',
+        //         type: 'month',
+        //         special: [
+        //             {"title": "批复概算", "key": "gs"}
+        //         ]
+        //     })
+        // };
+        const define = {
+            enable: true,
+            setting: JSON.stringify({
+                title: '请选择汇总的标段',
+                type: 'final',
+            })
+        };
+
+        const mem_gather_stage_bills = yield ctx.service.rptGatherMemory.getGatherDealBills([], define, select);
+        yield ctx.helper.saveBufferFile(JSON.stringify(mem_gather_stage_bills, "", "\t"), path.join(savePath, 'mem_gather_deal_pay.json'));
+
+        // const reportDataAnalysis = require('../../../app/lib/rpt_data_analysis');
+        // const reportData = {mem_gather_stage_bills: mem_gather_stage_bills};
+        // reportDataAnalysis.analysisObj.gatherSelectConverse.fun(ctx, reportData, [], {table: ["mem_gather_stage_bills"]}, {
+        //     cDefine: { gather_select: select },
+        //     tplDefine: {gather_select: define },
+        // });
+        // yield ctx.helper.saveBufferFile(JSON.stringify(reportData, "", "\t"), path.join(savePath, 'mem_gather_stage_bills_coverse.json'));
+        // assert(reportData.mem_gather_stage_bills.length === mem_gather_stage_bills.length * 2);
+    });
 });