|
@@ -520,12 +520,36 @@ class fjHelper {
|
|
|
constructor (ctx) {
|
|
|
this.ctx = ctx;
|
|
|
}
|
|
|
- async _getStageImportData(tid, sid) {
|
|
|
- const sql = 'SELECT sic.*, l.b_code, l.name. l.unit, l.unit_price, l.quantity, l.total_price' +
|
|
|
- ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
|
|
|
+ async _getStageBillsData(tid, sid) {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const billsData = await this.ctx.app.mysql.select(this.ctx.service.ledger.tableName, {
|
|
|
+ where: { tender_id: tid, is_leaf: 1 }
|
|
|
+ });
|
|
|
+
|
|
|
+ const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
+ const curStage = this.ctx.stage.readOnly
|
|
|
+ ? await this.ctx.service.stageBills.getAuditorStageData2(tid, this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder)
|
|
|
+ : await this.ctx.service.stageBills.getLastestStageData2(tid, this.ctx.stage.id);
|
|
|
+ const bpcStage = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: this.ctx.stage.id } });
|
|
|
+
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ { data: curStage, fields: ['qc_qty', 'qc_tp', 'qc_minus_qty'], prefix: '', relaId: 'lid' },
|
|
|
+ { data: preStage, fields: ['qc_qty', 'qc_tp', 'qc_minus_qty'], prefix: 'pre_', relaId: 'lid' },
|
|
|
+ { data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp'], prefix: '', relaId: 'lid' },
|
|
|
+ ]);
|
|
|
+ billsData.forEach(node => {
|
|
|
+ node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
|
|
|
+ node.end_qc_tp = helper.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
|
|
|
+ node.final_qty = helper.add(node.quantity, node.end_qc_qty);
|
|
|
+ node.final_tp = helper.add(node.total_price, node.end_qc_tp);
|
|
|
+ });
|
|
|
+ return billsData;
|
|
|
+ }
|
|
|
+ async _getStageImportChangeData(tid, sid) {
|
|
|
+ const sql = 'SELECT sic.*, l.b_code, l.name, l.unit, l.unit_price, l.quantity, l.total_price' +
|
|
|
' FROM ' + this.ctx.service.stageImportChange.tableName + ' sic ' +
|
|
|
' LEFT JOIN (SELECT * FROM ' + this.ctx.service.ledger.tableName + ' WHERE tender_id = ? AND is_leaf) AS l ON sic.lid = l.id' +
|
|
|
- ' WHERE sic.tid = ? AND sic.sid < ?';
|
|
|
+ ' WHERE sic.tid = ? AND sic.sid <= ?';
|
|
|
return await this.ctx.app.mysql.query(sql, [tid, tid, sid]);
|
|
|
}
|
|
|
convertChangeProgress(data, sid) {
|
|
@@ -541,8 +565,8 @@ class fjHelper {
|
|
|
}
|
|
|
const ls = b.ledgerSource.find(x => { return x.lid === d.lid; });
|
|
|
if (!ls) b.ledgerSource.push({lid: d.lid, quantity: d.quantity, total_price: d.total_price });
|
|
|
- const field = (d.sid < sid ? 'pre_' : '') + (d.qty > 0 ? 'positive_' : 'negative_') + 'qc_qty';
|
|
|
- b[field] = this.ctx.helper.add(b[field], d.qty);
|
|
|
+ const field = (d.sid < sid ? 'pre_' : '') + (d.rela_qty > 0 ? 'positive_' : 'negative_') + 'qc_qty';
|
|
|
+ b[field] = this.ctx.helper.add(b[field], d.rela_qty);
|
|
|
}
|
|
|
bills.sort((a, b) => { return helper.compareCode(a.b_code, b.b_code); });
|
|
|
|
|
@@ -579,9 +603,78 @@ class fjHelper {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ convertChangeProgress1(stageBills, stageImportChange, sid) {
|
|
|
+ const helper = this.ctx.helper, tpDecimal = this.ctx.tender.info.decimal.tp;
|
|
|
+ const bills = [];
|
|
|
+ for (const sb of stageBills) {
|
|
|
+ if (!sb.b_code) continue;
|
|
|
+ let b = bills.find(x => { return x.b_code === sb.b_code && x.name === sb.name && x.unit === sb.unit && x.unit_price === sb.unit_price; });
|
|
|
+ if (!b) {
|
|
|
+ b = { b_code: sb.b_code, name: sb.name, unit: sb.unit, unit_price: sb.unit_price, ledgerSource: [] };
|
|
|
+ bills.push(b);
|
|
|
+ }
|
|
|
+ const ls = b.ledgerSource.find(x => { return x.lid === sb.lid; });
|
|
|
+ if (!ls) b.ledgerSource.push({
|
|
|
+ lid: sb.id,
|
|
|
+ quantity: sb.quantity, total_price: sb.total_price,
|
|
|
+ final_qty: sb.final_qty, final_tp: sb.final_tp,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ bills.sort((a, b) => { return helper.compareCode(a.b_code, b.b_code); });
|
|
|
+
|
|
|
+ for (const d of stageImportChange) {
|
|
|
+ const b = bills.find(x => { return x.ledgerSource.findIndex(y => { return y.lid === d.lid; }) >= 0; });
|
|
|
+ if (!b) continue;
|
|
|
+
|
|
|
+ const field = (d.sid < sid ? 'pre_' : '') + (d.rela_qty > 0 ? 'positive_' : 'negative_') + 'qc_qty';
|
|
|
+ b[field] = this.ctx.helper.add(b[field], d.rela_qty);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const b of bills) {
|
|
|
+ b.quantity = helper.sum(b.ledgerSource.map(x => { return x.quantity; }));
|
|
|
+ b.total_price = helper.sum(b.ledgerSource.map(x => { return x.total_price; }));
|
|
|
+ b.final_qty = helper.sum(b.ledgerSource.map(x => { return x.final_qty; }));
|
|
|
+ b.final_tp = helper.sum(b.ledgerSource.map(x => { return x.final_tp; }));
|
|
|
+ b.pre_positive_qc_tp = helper.mul(b.unit_price, b.pre_positive_qc_qty, tpDecimal);
|
|
|
+ b.pre_negative_qc_tp = helper.mul(b.unit_price, b.pre_negative_qc_qty, tpDecimal);
|
|
|
+ b.positive_qc_tp = helper.mul(b.unit_price, b.positive_qc_qty, tpDecimal);
|
|
|
+ b.negative_qc_tp = helper.mul(b.unit_price, b.negative_qc_qty, tpDecimal);
|
|
|
+ b.end_positive_qc_qty = helper.add(b.pre_positive_qc_qty, b.positive_qc_qty);
|
|
|
+ b.end_positive_qc_tp = helper.add(b.pre_positive_qc_tp, b.positive_qc_tp);
|
|
|
+ b.end_negative_qc_qty = helper.add(b.pre_negative_qc_qty, b.negative_qc_qty);
|
|
|
+ b.end_negative_qc_tp = helper.add(b.pre_negative_qc_tp, b.negative_qc_tp);
|
|
|
+ }
|
|
|
+
|
|
|
+ const result = [];
|
|
|
+ for (const b of bills) {
|
|
|
+ result.push({
|
|
|
+ b_code: b.b_code, name: b.name, unit: b.unit, unit_price: b.unit_price,
|
|
|
+ quantity: b.quantity, total_price: b.total_price,
|
|
|
+ pre_qc_qty: b.pre_positive_qc_qty, pre_qc_tp: b.pre_positive_qc_tp,
|
|
|
+ qc_qty: b.positive_qc_qty, qc_tp: b.positive_qc_tp,
|
|
|
+ end_qc_qty: b.end_positive_qc_qty, end_qc_tp: b.end_positive_qc_tp,
|
|
|
+ final_qty: b.final_qty, final_tp: b.final_tp,
|
|
|
+ minus: 0,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ for (const b of bills) {
|
|
|
+ result.push({
|
|
|
+ b_code: b.b_code, name: b.name, unit: b.unit, unit_price: b.unit_price,
|
|
|
+ quantity: b.quantity, total_price: b.total_price,
|
|
|
+ pre_qc_qty: b.pre_negative_qc_tp, pre_qc_tp: b.pre_negative_qc_tp,
|
|
|
+ qc_qty: b.negative_qc_qty, qc_tp: b.negative_qc_tp,
|
|
|
+ end_qc_qty: b.end_negative_qc_qty, end_qc_tp: b.end_negative_qc_tp,
|
|
|
+ final_qty: b.final_qty, final_tp: b.final_tp,
|
|
|
+ minus: 1,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
async getChangeProgressData(tid, sid) {
|
|
|
- const data = await this._getStageImportData(tid, sid);
|
|
|
- return this.convertChangeProgress(data, sid);
|
|
|
+ await this.ctx.service.stage.checkStage(sid);
|
|
|
+ const stageBills = await this._getStageBillsData(tid, sid);
|
|
|
+ const stageImportChange = await this._getStageImportChangeData(tid, sid);
|
|
|
+ return this.convertChangeProgress1(stageBills, stageImportChange, sid);
|
|
|
}
|
|
|
}
|
|
|
|