Преглед изворни кода

报表,材差,调整清单汇总相关

MaiXinRong пре 2 година
родитељ
комит
ab003e7978
2 измењених фајлова са 52 додато и 17 уклоњено
  1. 28 15
      app/lib/rm/material.js
  2. 24 2
      app/service/material_list.js

+ 28 - 15
app/lib/rm/material.js

@@ -150,17 +150,18 @@ class ReportMemoryMaterial {
             orders: [['order', 'desc']],
         });
         if (materials.length > 0) {
-            let result;
+            let result, material;
             if (materials[0].order === material_order) {
-                const material = materials[0];
+                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,' +
+                    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,' +
                         '    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` +
+                        '  LEFT JOIN ' + this.ctx.service.materialStage.tableName + ' ms ON msb.ms_id = ms.id ' +
                         `  WHERE msb.mid = ?` +
                         '  ORDER By msb.ms_id, mb.order';
                     result = await this.ctx.app.mysql.query(sql, [material.id]);
@@ -174,7 +175,7 @@ class ReportMemoryMaterial {
                 if (!material) return [];
 
                 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,' +
+                    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,' +
                         '    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, ' +
@@ -182,6 +183,7 @@ class ReportMemoryMaterial {
                         `  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 ' +
+                        '  LEFT JOIN ' + this.ctx.service.materialStage.tableName + ' ms ON msb.ms_id = ms.id ' +
                         '  WHERE msb.mid = ?'+
                         '  ORDER By msb.ms_id, mb.order';
                     result = await this.ctx.app.mysql.query(sql, [material.id]);
@@ -262,7 +264,7 @@ class ReportMemoryMaterial {
         }
     }
 
-    async _getMaterialStageGatherBills(tender_id, stage_id, stage_order) {
+    async _getMaterialStageGatherBills(tender_id, stage_id, stage_order, stageSelf) {
         const decimal = this.materialGatherBase.decimal;
         const billsData = this.ctx.helper.clone(this.materialGatherBase.billsData);
         const curStageBills = await this.ctx.service.stageBills.getStagesData(tender_id, stage_id);
@@ -285,7 +287,10 @@ class ReportMemoryMaterial {
         const gclGatherModel = require('../gcl_gather').gclGather;
         const gatherUtil = new gclGatherModel(this.ctx);
         gatherUtil.gatherObj(billsTree, pos);
-        const materialGl = this.materialGatherBase.materialGl;
+
+        const materialGl = stageSelf
+            ? this.materialGatherBase.materialGl.filter(x => { return x.sid === parseInt(stage_id); })
+            : this.materialGatherBase.materialGl;
         const materialNotJoin = this.materialGatherBase.materialNotJoin;
 
         const helper = this.ctx.helper;
@@ -302,8 +307,8 @@ class ReportMemoryMaterial {
                 });
                 x.is_join = !mnj;
                 if (mnj) continue;
-                const list = materialGl.filter(g => {
-                    return g.gcl_id === x.org_gcl_id && g.xmj_id === x.id && (x.mx_id && x.mx_id !== x.id ? x.mx_id === g.mx_id : true);
+                const list = materialGl.filter(gl => {
+                    return gl.gcl_id === x.org_gcl_id && gl.xmj_id === x.id && (x.mx_id && x.mx_id !== x.id ? x.mx_id === gl.mx_id : true);
                 });
                 for (const l of list) {
                     x.jiacha = helper.add(x.jiacha, helper.mul(helper.mul(x.gather_qty, l.quantity), l.m_spread));
@@ -329,26 +334,34 @@ class ReportMemoryMaterial {
             // 获取基础数据
             this.materialGatherBase.billsData = await this.ctx.service.ledger.getData(tender_id);
             this.materialGatherBase.posData = await this.ctx.service.pos.getPosData({ tid: tender_id });
-            this.materialGatherBase.materialGl = material_order === materials[0].order
-                ? await this.ctx.service.materialList.getMaterialData(tender_id, material.id)
-                : await this.ctx.service.materialList.getPreMaterialData(tender_id, material.id);
+            if (material.is_stage_self) {
+                this.materialGatherBase.materialGl = material_order === materials[0].order
+                    ? await this.ctx.service.materialList.getMaterialStageData(tender_id, material.id)
+                    : await this.ctx.service.materialList.getPreMaterialStageData(tender_id, material.id);
+            } else {
+                this.materialGatherBase.materialGl = material_order === materials[0].order
+                    ? await this.ctx.service.materialList.getMaterialData(tender_id, material.id)
+                    : await this.ctx.service.materialList.getPreMaterialData(tender_id, material.id);
+            }
             this.materialGatherBase.materialNotJoin = await this.ctx.service.materialListNotjoin.getAllDataByCondition({ where: { mid: material.id } });
 
-            const mem_material_gather_bills = [], mem_material_gather_xmj = [];
+            const mem_material_gather_bills = [], mem_material_gather_xmj = [], mem_material_gather_gl = [];
             if (material.is_stage_self) {
                 const stageIds = material.stage_id.split(',');
                 const stageOrders = material.s_order.split(',');
                 for (const [i, sid] of stageIds.entries()) {
-                    const [gclList, leafXmjs] = await this._getMaterialStageGatherBills(tender_id, sid, stageOrders[i]);
+                    const [gclList, leafXmjs] = await this._getMaterialStageGatherBills(tender_id, sid, stageOrders[i], true);
                     mem_material_gather_bills.push(...gclList);
                     mem_material_gather_xmj.push(...leafXmjs);
+                    mem_material_gather_gl.push(this.materialGatherBase.materialGl);
                 }
             } else {
-                const [gclList, leafXmjs] = await this._getMaterialStageGatherBills(tender_id, material.stage_id, material.stage_order);
+                const [gclList, leafXmjs] = await this._getMaterialStageGatherBills(tender_id, material.stage_id, material.stage_order, false);
                 mem_material_gather_bills.push(...gclList);
                 mem_material_gather_xmj.push(...leafXmjs);
+                mem_material_gather_gl.push(this.materialGatherBase.materialGl);
             }
-            return {mem_material_gather_bills, mem_material_gather_xmj, mem_material_gather_gl: this.materialGatherBase.materialGl};
+            return {mem_material_gather_bills, mem_material_gather_xmj, mem_material_gather_gl};
         } catch (err) {
             this.ctx.log(err);
             return {};

+ 24 - 2
app/service/material_list.js

@@ -300,7 +300,7 @@ module.exports = app => {
          * @return {void}
          */
         async getMaterialData(tid, mid) {
-            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`ms_id`, ml.`tid`, ml.`mid`, mb.m_spread' +
+            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`ms_id`, ml.`tid`, ml.`mid`, mb.m_spread, ml.ms_id' +
                 ' FROM ' + this.tableName + ' as ml' +
                 ' LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' as mb' +
                 ' ON ml.`mb_id` = mb.`id`' +
@@ -310,7 +310,7 @@ module.exports = app => {
         }
 
         async getPreMaterialData(tid, mid) {
-            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`ms_id`, ml.`tid`, ml.`mid`, mbh.m_spread' +
+            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`ms_id`, ml.`tid`, ml.`mid`, mbh.m_spread, ml.ms_id' +
                 ' FROM ' + this.tableName + ' as ml' +
                 ' LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' as mb ON ml.`mb_id` = mb.`id`' +
                 ' LEFT JOIN ' + this.ctx.service.materialBillsHistory.tableName + ' as mbh ON ml.`mb_id` = mbh.`mb_id` and mbh.mid = ?' +
@@ -319,6 +319,28 @@ module.exports = app => {
             return await this.db.query(sql, sqlParam);
         }
 
+        async getMaterialStageData(tid, mid) {
+            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`ms_id`, ml.`tid`, ml.`mid`, msb.m_spread, ml.ms_id, ms.sid, ms.order as s_order' +
+                ' FROM ' + this.tableName + ' as ml' +
+                ' LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' as mb ON ml.`mb_id` = mb.`id`' +
+                ' LEFT JOIN ' + this.ctx.service.materialStageBills.tableName + ' as msb ON ml.mb_id = msb.mb_id AND ml.ms_id = msb.ms_id' +
+                ' LEFT JOIN ' + this.ctx.service.materialStage.tableName + ' as ms ON ml.`ms_id` = ms.`id`' +
+                ' WHERE ml.`tid` = ? AND ml.`mid` = ?';
+            const sqlParam = [tid, mid];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        async getPreMaterialStageData(tid, mid) {
+            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`order`, ml.`quantity`, ml.`expr`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`ms_id`, ml.`tid`, ml.`mid`, msb.m_spread, ml.ms_id, ms.sid, ms.order as s_order' +
+                ' FROM ' + this.tableName + ' as ml' +
+                ' LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' as mb ON ml.`mb_id` = mb.`id`' +
+                ' LEFT JOIN ' + this.ctx.service.materialStageBills.tableName + ' as msb ON ml.`mb_id` = msb.mb_id AND ml.ms_id = msb.ms_id And ml.mid = msb.mid' +
+                ' LEFT JOIN ' + this.ctx.service.materialStage.tableName + ' as ms ON ml.`ms_id` = ms.`id`' +
+                ' WHERE ml.`tid` = ? AND ml.`mid` = ?';
+            const sqlParam = [mid, tid, mid];
+            return await this.db.query(sql, sqlParam);
+        }
+
         /**
          * 复制上一期并生成新一期清单工料关联,计算新一期小计值
          * @param transaction