Browse Source

材差报表相关

MaiXinRong 1 year ago
parent
commit
8bf36b2d72

+ 26 - 8
app/lib/rpt_data_analysis.js

@@ -1459,17 +1459,35 @@ const materialSumSelectConverse = {
         for (const s of materials) {
         for (const s of materials) {
             const curReg = new RegExp('^m_' + s + '_');
             const curReg = new RegExp('^m_' + s + '_');
             for (const [i, d] of data.entries()) {
             for (const [i, d] of data.entries()) {
-                const nd = { cross_index: i + 1, s_order: s };
-                for (const prop in d) {
-                    if (reg.test(prop)) {
-                        if (curReg.test(prop)) {
-                            nd[prop.replace(curReg, 'm_')] = d[prop];
+                const stageId = `m_${s}_stageId`;
+                if (d[stageId]) {
+                    for (const sid of d[stageId]) {
+                        const curStageReg = new RegExp(`^m_${s}_s${sid}_`);
+                        const nd = { cross_index: i + 1, s_order: `${s}_${sid}` };
+                        for (const prop in d) {
+                            if (reg.test(prop)) {
+                                if (curStageReg.test(prop)) {
+                                    nd[prop.replace(curStageReg, 'm_')] = d[prop];
+                                }
+                            } else {
+                                nd[prop] = d[prop];
+                            }
                         }
                         }
-                    } else {
-                        nd[prop] = d[prop];
+                        result.push(nd);
                     }
                     }
+                } else {
+                    const nd = { cross_index: i + 1, s_order: s };
+                    for (const prop in d) {
+                        if (reg.test(prop)) {
+                            if (curReg.test(prop)) {
+                                nd[prop.replace(curReg, 'm_')] = d[prop];
+                            }
+                        } else {
+                            nd[prop] = d[prop];
+                        }
+                    }
+                    result.push(nd);
                 }
                 }
-                result.push(nd);
             }
             }
         }
         }
         return result;
         return result;

+ 1 - 0
app/service/budget_final_list.js

@@ -13,6 +13,7 @@ const status = {
     wait: 1,
     wait: 1,
     ext: 2,
     ext: 2,
     done: 3,
     done: 3,
+    error: 4,
 };
 };
 
 
 module.exports = app => {
 module.exports = app => {

+ 54 - 13
app/service/rpt_stage_sum_memory.js

@@ -177,19 +177,60 @@ module.exports = app => {
                 const material = await this.db.get(this.ctx.service.material.tableName, { tid: this.ctx.tender.id, order: m });
                 const material = await this.db.get(this.ctx.service.material.tableName, { tid: this.ctx.tender.id, order: m });
                 if (!material) continue;
                 if (!material) continue;
 
 
-                const prefix = 'm_' + material.order + '_';
-                calcPrefix.push(prefix);
-                const defaultData = {};
-                defaultData[prefix + 'order'] = material.order;
-
-                const curMaterial = material.status === auditConst.material.status.checked
-                    ? await this.ctx.service.materialBillsHistory.getAllDataByCondition({ where: { mid: material.id } })
-                    : await this.ctx.service.materialBills.getAllDataByCondition({ where: { tid }});
-                const relaId = material.status === auditConst.material.status.checked ? 'mb_id' : 'id';
-
-                this.ctx.helper.assignRelaData(materialData, [
-                    {data: curMaterial, fields, prefix: prefix, relaId, defaultData: defaultData}
-                ]);
+                if (material.is_stage_self) {
+                    let curMaterial = [];
+                    if (material.status !== auditConst.material.status.checked) {
+                        const sql = 'SELECT msb.id, msb.tid, msb.mid, msb.ms_id, ms.sid, ms.`order` as s_order, mb.order, mb.t_type, mb.code, mb.name, mb.unit, mb.spec, mb.m_type, mb.in_time, msb.mb_id, ' +
+                            '    msb.quantity, mb.expr,' +
+                            '    mb.basic_price, mb.basic_times, ' +
+                            '    msb.msg_tp, msb.msg_times, msb.msg_spread, mb.m_up_risk, mb.m_down_risk, msb.m_spread, msb.m_tp, mb.pre_tp, msb.m_tax_tp, mb.tax_pre_tp, mb.origin, ' +
+                            '    msb.remark, msb.is_summary, mb.m_tax, mb.in_time, mb.origin' +
+                            `  FROM ${this.ctx.service.materialStageBills.tableName} msb` +
+                            `  LEFT JOIN ${this.ctx.service.materialBills.tableName} mb ON msb.mb_id = mb.id` +
+                            '  LEFT JOIN ' + this.ctx.service.materialStage.tableName + ' ms ON msb.ms_id = ms.id ' +
+                            `  WHERE msb.mid = ?` +
+                            '  ORDER By msb.ms_id, mb.order';
+                        curMaterial = await this.ctx.app.mysql.query(sql, [material.id]);
+                    } else {
+                        const sql = 'SELECT msb.id, msb.tid, msb.mid, msb.ms_id, ms.sid, ms.`order` as s_order, mb.order, mb.t_type, mb.code, mb.name, mb.unit, mb.spec, mb.m_type, mb.in_time, msb.mb_id,' +
+                            '    msb.quantity, mbh.expr,' +
+                            '    mb.basic_price, mb.basic_times, ' +
+                            '    msb.msg_tp, msb.msg_times, msb.msg_spread, mbh.m_up_risk, mbh.m_down_risk, msb.m_spread, msb.m_tp, mbh.pre_tp, msb.m_tax_tp, mbh.tax_pre_tp, mbh.origin, ' +
+                            '    msb.remark, msb.is_summary, mbh.m_tax, mb.in_time, mbh.origin' +
+                            `  FROM ${this.ctx.service.materialStageBills.tableName} msb` +
+                            '  LEFT JOIN ' + this.ctx.service.materialBillsHistory.tableName + ' mbh ON msb.mb_id = mbh.mb_id AND msb.mid = mbh.mid' +
+                            '  LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' mb ON msb.mb_id = mb.id ' +
+                            '  LEFT JOIN ' + this.ctx.service.materialStage.tableName + ' ms ON msb.ms_id = ms.id ' +
+                            '  WHERE msb.mid = ?'+
+                            '  ORDER By msb.ms_id, mb.order';
+                        curMaterial = await this.ctx.app.mysql.query(sql, [material.id]);
+                    }
+                    const stageId = material.stage_id.split(',');
+                    materialData.forEach(x => { return x['m_' + material.order + '_' + 'stageId'] = stageId });
+                    for (const sid of stageId) {
+                        const prefix = 'm_' + material.order + '_' + `s${sid}_`;
+                        calcPrefix.push(prefix);
+                        const defaultData = {};
+                        defaultData[prefix + 'order'] = material.order;
+                        const sidInt = parseInt(sid);
+                        const curStageMaterial = curMaterial.filter(x => { return x.sid === sidInt; });
+                        this.ctx.helper.assignRelaData(materialData, [
+                            {data: curStageMaterial, fields, prefix: prefix, relaId: 'mb_id', defaultData: defaultData}
+                        ]);
+                    }
+                } else {
+                    const prefix = 'm_' + material.order + '_';
+                    calcPrefix.push(prefix);
+                    const defaultData = {};
+                    defaultData[prefix + 'order'] = material.order;
+                    const curMaterial = material.status === auditConst.material.status.checked
+                        ? await this.ctx.service.materialBillsHistory.getAllDataByCondition({ where: { mid: material.id } })
+                        : await this.ctx.service.materialBills.getAllDataByCondition({ where: { tid }});
+                    const relaId = material.status === auditConst.material.status.checked ? 'mb_id' : 'id';
+                    this.ctx.helper.assignRelaData(materialData, [
+                        {data: curMaterial, fields, prefix: prefix, relaId, defaultData: defaultData}
+                    ]);
+                }
             }
             }
 
 
             return materialData;
             return materialData;