|
@@ -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 {};
|