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