|
@@ -12,7 +12,7 @@ const infoConst = require('../const/tender_info');
|
|
|
const parseInfo = infoConst.parseInfo;
|
|
|
const arrayInfo = infoConst.arrayInfo;
|
|
|
const defaultInfo = infoConst.defaultInfo;
|
|
|
-
|
|
|
+const advanceConst = require('../const/audit').advance;
|
|
|
module.exports = app => {
|
|
|
|
|
|
class TenderInfo extends app.BaseService {
|
|
@@ -202,8 +202,10 @@ module.exports = app => {
|
|
|
|
|
|
async saveDecimal(tenderId, newDecimal, oldDecimal) {
|
|
|
const changeBills = [],
|
|
|
+ changeAdvanceBills = [],
|
|
|
calcUp = newDecimal.up < oldDecimal.up,
|
|
|
- calcTp = newDecimal.tp !== oldDecimal.tp;
|
|
|
+ calcTp = newDecimal.tp !== oldDecimal.tp,
|
|
|
+ caclPayTp = (newDecimal.pay ? newDecimal.payTp : newDecimal.tp) < (oldDecimal.pay ? oldDecimal.payTp : oldDecimal.tp);
|
|
|
if (calcUp || calcTp) {
|
|
|
const bills = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
columns: ['id', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty', 'quantity'],
|
|
@@ -220,12 +222,29 @@ module.exports = app => {
|
|
|
changeBills.push(cb);
|
|
|
}
|
|
|
}
|
|
|
+ if (caclPayTp) {
|
|
|
+ // 获取预付款需要修改的相关记录
|
|
|
+ const ad_bills = await this.ctx.service.advance.getAllDataByCondition({
|
|
|
+ columns: ['id', 'cur_amount', 'prev_amount', 'prev_total_amount'],
|
|
|
+ where: { status: [advanceConst.status.uncheck, advanceConst.status.checkNo], tid: tenderId },
|
|
|
+ });
|
|
|
+ const decimal = newDecimal.pay ? newDecimal.payTp : newDecimal.tp;
|
|
|
+ // 根据精度重新计算相关金额
|
|
|
+ for (const ad of ad_bills) {
|
|
|
+ const cb = { id: ad.id };
|
|
|
+ cb.cur_amount = this.ctx.helper.round(ad.cur_amount, decimal);
|
|
|
+ cb.prev_total_amount = this.ctx.helper.round(this.ctx.helper.add(ad.cur_amount, ad.prev_amount), decimal);
|
|
|
+ changeAdvanceBills.push(cb);
|
|
|
+ }
|
|
|
+ }
|
|
|
if (changeBills.length > 0) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
await transaction.update(this.tableName,
|
|
|
{ decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
|
|
|
await transaction.updateRows(this.ctx.service.ledger.tableName, changeBills);
|
|
|
+
|
|
|
+ // await transaction.updateRows(this.ctx.service.advance.tableName, changeAdvanceBills);
|
|
|
await transaction.commit();
|
|
|
} catch (error) {
|
|
|
await transaction.rollback();
|
|
@@ -235,6 +254,10 @@ module.exports = app => {
|
|
|
await this.db.update(this.tableName,
|
|
|
{ decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
|
|
|
}
|
|
|
+ // 更新预付款记录
|
|
|
+ if (changeAdvanceBills.length) {
|
|
|
+ await this.db.updateRows(this.ctx.service.advance.tableName, changeAdvanceBills);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|