Explorar o código

报表,材差报表调整

MaiXinRong %!s(int64=2) %!d(string=hai) anos
pai
achega
b8ee33ef9c
Modificáronse 3 ficheiros con 68 adicións e 15 borrados
  1. 53 12
      app/lib/rm/material.js
  2. 4 0
      app/service/report.js
  3. 11 3
      app/service/stage_change.js

+ 53 - 12
app/lib/rm/material.js

@@ -152,22 +152,51 @@ class ReportMemoryMaterial {
         if (materials.length > 0) {
             let result;
             if (materials[0].order === material_order) {
-                result = await this.ctx.service.materialBills.getAllDataByCondition({
-                    where: {tid: tender_id}
-                });
+                const material = materials[0];
+                if (material.is_stage_self) {
+                    const sql = 'SELECT msb.id, msb.tid, msb.mid, msb.ms_id, mb.order, mb.t_type, mb.code, mb.name, mb.unit, mb.spec, mb.m_type,' +
+                        '    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' +
+                        `  FROM ${this.ctx.service.materialStageBills.tableName} msb` +
+                        `  LEFT JOIN ${this.ctx.service.materialBills.tableName} mb ON msb.mb_id = mb.id` +
+                        `  WHERE msb.mid = ?` +
+                        '  ORDER By msb.ms_id, mb.order';
+                    result = await this.ctx.app.mysql.query(sql, [material.id]);
+                } else {
+                    result = await this.ctx.service.materialBills.getAllDataByCondition({
+                        where: {tid: tender_id}
+                    });
+                }
             } else {
                 const material = this.ctx.helper._.find(materials, {order: material_order});
                 if (!material) return [];
 
-                const sql = 'SELECT mb.id, mb.tid, mb.mid, mb.order, mb.order, mb.t_type, mb.code, mb.name, mb.unit, mb.spec, mb.m_type,' +
-                    '    mbh.quantity, mbh.expr,' +
-                    '    mb.basic_price, mb.basic_times, ' +
-                    '    mbh.msg_tp, mbh.msg_times, mbh.msg_spread, mbh.m_up_risk, mbh.m_down_risk, mbh.m_spread, mbh.m_tp, mbh.pre_tp, mbh.m_tax_tp, mbh.tax_pre_tp, mbh.origin, ' +
-                    '    mb.remark, mb.is_summary, mbh.m_tax, mb.in_time' +
-                    '  FROM ' + this.ctx.service.materialBillsHistory.tableName + ' mbh ' +
-                    '  LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' mb ON mbh.mb_id = mb.id ' +
-                    '  WHERE mbh.tid = ? And mbh.mid = ?';
-                result = await this.ctx.app.mysql.query(sql, [tender_id, material.id]);
+                if (material.is_stage_self) {
+                    const sql = 'SELECT msb.id, msb.tid, msb.mid, msb.ms_id, mb.order, mb.t_type, mb.code, mb.name, mb.unit, mb.spec, mb.m_type,' +
+                        '    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' +
+                        `  FROM ${this.ctx.service.materialStageBills.tableName} msb` +
+                        '  LEFT JOIN ' + this.ctx.service.materialBillsHistory.tableName + ' mbh ON msb.mb_id = mbh.mb_id' +
+                        '  LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' mb ON msb.mb_id = mb.id ' +
+                        '  WHERE msb.mid = ?'+
+                        '  ORDER By msb.ms_id, mb.order';
+                    result = await this.ctx.app.mysql.query(sql, [material.id]);
+                } else {
+                    const sql = 'SELECT mb.id, mb.tid, mb.mid, mb.order, mb.t_type, mb.code, mb.name, mb.unit, mb.spec, mb.m_type,' +
+                        '    mbh.quantity, mbh.expr,' +
+                        '    mb.basic_price, mb.basic_times, ' +
+                        '    mbh.msg_tp, mbh.msg_times, mbh.msg_spread, mbh.m_up_risk, mbh.m_down_risk, mbh.m_spread, mbh.m_tp, mbh.pre_tp, mbh.m_tax_tp, mbh.tax_pre_tp, mbh.origin, ' +
+                        '    mb.remark, mb.is_summary, mbh.m_tax, mb.in_time' +
+                        '  FROM ' + this.ctx.service.materialBillsHistory.tableName + ' mbh ' +
+                        '  LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' mb ON mbh.mb_id = mb.id ' +
+                        '  WHERE mbh.tid = ? And mbh.mid = ?'+
+                        '  ORDER By mb.order';
+                    result = await this.ctx.app.mysql.query(sql, [tender_id, material.id]);
+                }
             }
             this._completeMaterialGl(result);
             return result;
@@ -295,6 +324,18 @@ class ReportMemoryMaterial {
             return {};
         }
     }
+
+    async getMaterialStage(tender_id, material_order, fields) {
+        const material = await this.ctx.service.material.getDataByCondition({tid: tender_id, order: material_order});
+        if (material.is_stage_self) {
+            return await this.ctx.service.materialStage.getAllDataByCondition({ where: { mid: material.id } });
+        } else {
+            return [{
+                id: -1, tid: material.id, mid: material.id, sid: material.stage_id, order: material.stage_order,
+                m_tp: material.m_tp, m_tax_tp: material.m_tax_tp,
+            }];
+        }
+    }
 }
 
 module.exports = ReportMemoryMaterial;

+ 4 - 0
app/service/report.js

@@ -217,6 +217,10 @@ module.exports = app => {
                             runnableRst.push(materialSource.getMaterialPos(params.tender_id, params.material_order, memFieldKeys[filter]));
                             runnableKey.push(filter);
                             break;
+                        case 'mem_material_stage':
+                            runnableRst.push(materialSource.getMaterialStage(params.tender_id, params.material_order, memFieldKeys[filter]));
+                            runnableKey.push(filter);
+                            break;
                         case 'mem_stage_sum_bills':
                             runnableRst.push(service.rptStageSumMemory.getStageSumBills(params.tender_id, memFieldKeys[filter],
                                 customDefine.stage_select, customSelect ? customSelect.stage_select : null));

+ 11 - 3
app/service/stage_change.js

@@ -81,7 +81,9 @@ class autoUseChange {
         const billsPos = this.findBillsPos(bills);
         if (!billsPos) return;
         this.insertChange.push({
-            tid: this.default.tid, sid: this.default.sid, lid: billsPos.lid, pid: billsPos.pid, cid: bills.cid, cbid: bills.id, qty: bills.valid_qty, stimes: 1, sorder: 0,
+            tid: this.default.tid, sid: this.default.sid,
+            lid: billsPos.lid, pid: billsPos.pid, cid: bills.cid, cbid: bills.id,
+            qty: bills.valid_qty, stimes: 1, sorder: 0,
         });
 
         if (billsPos.pid !== '-1') {
@@ -112,7 +114,10 @@ class autoUseChange {
             if (sp) {
                 this.updatePos.push({ id: sp.id, qc_qty });
             } else {
-                this.insertPos.push({ tid: this.default.tid, sid: this.default.sid, said: this.default.said, lid: cp.lid, pid, qc_qty, times: 1, order: 0 });
+                this.insertPos.push({
+                    tid: this.default.tid, sid: this.default.sid, said: this.default.said,
+                    lid: cp.lid, pid, qc_qty, times: 1, order: 0
+                });
             }
             const cb = this.changeBills[cp.lid];
             if (!cb) {
@@ -131,7 +136,10 @@ class autoUseChange {
             if (sb) {
                 this.updateBills.push({ id: sb.id, qc_qty, qc_tp });
             } else {
-                this.insertBills.push({ tid: this.default.tid, sid: this.default.sid, said: this.default.said, lid, qc_qty, qc_tp, times: 1, order: 0 });
+                this.insertBills.push({
+                    tid: this.default.tid, sid: this.default.sid, said: this.default.said,
+                    lid, qc_qty, qc_tp, times: 1, order: 0
+                });
             }
         }
     }