|
@@ -144,67 +144,84 @@ class ReportMemoryMaterial {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async _loadMaterialMonth(material, gl) {
|
|
|
+ const materialMonth = await this.ctx.service.materialMonth.getAllDataByCondition({
|
|
|
+ where: { mid: material.id },
|
|
|
+ orders: [['mb_id', 'asc'], ['yearmonth', 'asc']],
|
|
|
+ });
|
|
|
+
|
|
|
+ const month = this.ctx.helper._.uniq(materialMonth.map(x => { return x.yearmonth; }));
|
|
|
+ let g;
|
|
|
+ for (const mm of materialMonth) {
|
|
|
+ if (!g || g.id !== mm.mb_id) g = gl.find(x => { return mm.mb_id === x.id; });
|
|
|
+ if (!g.month_msg_tp) g.month_msg_tp = [];
|
|
|
+ if (!g.month) g.month = month.concat([]);
|
|
|
+ const index = month.indexOf(mm.yearmonth);
|
|
|
+ if (index >= 0) g.month_msg_tp[index] = mm.msg_tp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async getMaterialGl(tender_id, material_order, fields) {
|
|
|
const materials = await this.ctx.service.material.getAllDataByCondition({
|
|
|
where: {tid: tender_id},
|
|
|
orders: [['order', 'desc']],
|
|
|
});
|
|
|
- if (materials.length > 0) {
|
|
|
- let result, material;
|
|
|
- if (materials[0].order === material_order) {
|
|
|
- material = materials[0];
|
|
|
- if (material.is_stage_self) {
|
|
|
- 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]);
|
|
|
- } else {
|
|
|
- result = await this.ctx.service.materialBills.getAllDataByCondition({
|
|
|
- where: {tid: tender_id}
|
|
|
- });
|
|
|
- }
|
|
|
+ if (materials.length === 0) return [];
|
|
|
+
|
|
|
+ let result, material;
|
|
|
+ if (materials[0].order === material_order) {
|
|
|
+ material = materials[0];
|
|
|
+ if (material.is_stage_self) {
|
|
|
+ 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]);
|
|
|
} else {
|
|
|
- const material = this.ctx.helper._.find(materials, {order: material_order});
|
|
|
- if (!material) return [];
|
|
|
-
|
|
|
- if (material.is_stage_self) {
|
|
|
- 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, ' +
|
|
|
- ' 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 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';
|
|
|
- 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]);
|
|
|
- }
|
|
|
+ result = await this.ctx.service.materialBills.getAllDataByCondition({
|
|
|
+ where: {tid: tender_id}
|
|
|
+ });
|
|
|
}
|
|
|
- this._completeMaterialGl(result);
|
|
|
- return result;
|
|
|
} else {
|
|
|
- return [];
|
|
|
+ const material = this.ctx.helper._.find(materials, {order: material_order});
|
|
|
+ if (!material) return [];
|
|
|
+
|
|
|
+ if (material.is_stage_self) {
|
|
|
+ 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, ' +
|
|
|
+ ' 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 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';
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if (this._checkFieldsExist(fields, ['month_msg_tp', 'month'])) await this._loadMaterialMonth(material, result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
async getMaterialGlDetail(tender_id, material_order, fields) {
|