|
@@ -353,6 +353,46 @@ module.exports = app => {
|
|
|
return change;
|
|
|
}
|
|
|
|
|
|
+ async _getReCalcChangeData(ctx) {
|
|
|
+ const change = await ctx.service.change.getAllDataByCondition({
|
|
|
+ columns: [ 'cid', 'code', 'name', 'w_code', 'tp_decimal', 'up_decimal' ],
|
|
|
+ where: { tid: ctx.tender.id, valid: 1, status: changeAudit.status.checked },
|
|
|
+ orders: [['code', 'asc']],
|
|
|
+ });
|
|
|
+ const changeBills = await ctx.service.changeAuditList.getAllDataByCondition({
|
|
|
+ columns: [ 'id', 'cid', 'code', 'name', 'unit', 'unit_price', 'oamount2', 'checked_amount', 'checked_price', 'is_valuation', 'gcl_id', 'bwmx', 'mx_id'],
|
|
|
+ where: { tid: ctx.tender.id }
|
|
|
+ });
|
|
|
+ const changeIndex = {};
|
|
|
+ change.forEach(x => { changeIndex[x.cid] = x; x.bills = [] });
|
|
|
+ changeBills.forEach(cb => {
|
|
|
+ const c = changeIndex[cb.cid];
|
|
|
+ if (!c) return;
|
|
|
+ if (cb.gcl_id) {
|
|
|
+ let b = c.bills.find(x => { return x.gcl_id === cb.gcl_id; });
|
|
|
+ if (!b) {
|
|
|
+ b = { code: cb.code, name: cb.name, unit: cb.unit, unit_price: cb.unit_price, pos: [], gcl_id: cb.gcl_id };
|
|
|
+ c.bills.push(b);
|
|
|
+ }
|
|
|
+ b.checked_amount = this.ctx.helper.add(b.checked_amount, cb.checked_amount);
|
|
|
+ b.pos.push(cb);
|
|
|
+ } else {
|
|
|
+ c.bills.push({
|
|
|
+ code: cb.code, name: cb.name, unit: cb.unit, unit_price: cb.unit_price,
|
|
|
+ gcl_id: '', checked_amount: cb.checked_amount, checked_price: cb.checked_price,
|
|
|
+ pos: [cb],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const helper = ctx.helper;
|
|
|
+ change.forEach(x => {
|
|
|
+ const tpDecimal = x.tp_decimal || ctx.tender.info.decimal.tp;
|
|
|
+ x.bills.forEach(b => { b.checked_price = helper.mul(b.unit_price, b.checked_amount, tpDecimal); });
|
|
|
+ x.bills.sort((a, b) => { return helper.compareCode(a.code, b.code)});
|
|
|
+ });
|
|
|
+ return change;
|
|
|
+ }
|
|
|
+
|
|
|
async getStageData(ctx) {
|
|
|
try {
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
@@ -397,6 +437,9 @@ module.exports = app => {
|
|
|
case 'change':
|
|
|
responseData.data.change = await this._getChangeData(ctx);
|
|
|
break;
|
|
|
+ case 'reCalcChange':
|
|
|
+ responseData.data.reCalcChange = await this._getReCalcChangeData(ctx);
|
|
|
+ break;
|
|
|
case 'preStageChange':
|
|
|
responseData.data.preStageChange = ctx.stage.preCheckedStage
|
|
|
? await this.ctx.service.stageChangeFinal.getEndStageData(ctx.tender.id, ctx.stage.preCheckedStage.order)
|