|
@@ -13,6 +13,9 @@ const parseInfo = infoConst.parseInfo;
|
|
const arrayInfo = infoConst.arrayInfo;
|
|
const arrayInfo = infoConst.arrayInfo;
|
|
const defaultInfo = infoConst.defaultInfo;
|
|
const defaultInfo = infoConst.defaultInfo;
|
|
const advanceConst = require('../const/audit').advance;
|
|
const advanceConst = require('../const/audit').advance;
|
|
|
|
+const auditConst = require('../const/audit');
|
|
|
|
+
|
|
|
|
+
|
|
module.exports = app => {
|
|
module.exports = app => {
|
|
|
|
|
|
class TenderInfo extends app.BaseService {
|
|
class TenderInfo extends app.BaseService {
|
|
@@ -143,12 +146,21 @@ module.exports = app => {
|
|
}
|
|
}
|
|
changeUnits = this._.flatten(changeUnits);
|
|
changeUnits = this._.flatten(changeUnits);
|
|
|
|
|
|
|
|
+ let billsService, posService;
|
|
|
|
+ if (this.ctx.tender.data.status === auditConst.ledger.status.checked) {
|
|
|
|
+ billsService = this.ctx.service.ledger;
|
|
|
|
+ posService = this.ctx.service.pos;
|
|
|
|
+ } else {
|
|
|
|
+ billsService = this.ctx.service.reviseBills;
|
|
|
|
+ posService = this.ctx.service.revisePos;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (changeUnits.length > 0) {
|
|
if (changeUnits.length > 0) {
|
|
- const bills = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
|
|
|
+ const bills = await billsService.getAllDataByCondition({
|
|
columns: ['id', 'unit', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty'],
|
|
columns: ['id', 'unit', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty'],
|
|
where: { tender_id: tenderId, unit: changeUnits, is_leaf: true },
|
|
where: { tender_id: tenderId, unit: changeUnits, is_leaf: true },
|
|
});
|
|
});
|
|
- const pos = changeUnits.length > 0 ? await this.ctx.service.pos.getPosDataByUnits(tenderId, changeUnits) : [];
|
|
|
|
|
|
+ const pos = changeUnits.length > 0 ? await posService.getPosDataByUnits(tenderId, changeUnits) : [];
|
|
|
|
|
|
for (const b of bills) {
|
|
for (const b of bills) {
|
|
const precision = this.ctx.helper.findPrecision(newPrecision, b.unit);
|
|
const precision = this.ctx.helper.findPrecision(newPrecision, b.unit);
|
|
@@ -185,8 +197,8 @@ module.exports = app => {
|
|
try {
|
|
try {
|
|
await transaction.update(this.tableName,
|
|
await transaction.update(this.tableName,
|
|
{ precision: JSON.stringify(newPrecision) }, { where: { tid: tenderId } });
|
|
{ precision: JSON.stringify(newPrecision) }, { where: { tid: tenderId } });
|
|
- if (bills.length > 0) await transaction.updateRows(this.ctx.service.ledger.tableName, bills);
|
|
|
|
- if (pos.length > 0) await transaction.updateRows(this.ctx.service.pos.tableName, pos);
|
|
|
|
|
|
+ if (bills.length > 0) await transaction.updateRows(billsService.tableName, bills);
|
|
|
|
+ if (pos.length > 0) await transaction.updateRows(posService.tableName, pos);
|
|
await transaction.commit();
|
|
await transaction.commit();
|
|
} catch (err) {
|
|
} catch (err) {
|
|
await transaction.rollback();
|
|
await transaction.rollback();
|
|
@@ -198,11 +210,11 @@ module.exports = app => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- async _reCalcLedger(tenderId, newDecimal, oldDecimal) {
|
|
|
|
|
|
+ async _reCalcLedger(tenderId, billsService, newDecimal, oldDecimal) {
|
|
const changeBills = [];
|
|
const changeBills = [];
|
|
const calcUp = newDecimal.up < oldDecimal.up, calcTp = newDecimal.tp !== oldDecimal.tp;
|
|
const calcUp = newDecimal.up < oldDecimal.up, calcTp = newDecimal.tp !== oldDecimal.tp;
|
|
if (calcUp || calcTp) {
|
|
if (calcUp || calcTp) {
|
|
- const bills = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
|
|
|
+ const bills = await billsService.getAllDataByCondition({
|
|
columns: ['id', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty', 'quantity'],
|
|
columns: ['id', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty', 'quantity'],
|
|
where: { tender_id: tenderId, is_leaf: true },
|
|
where: { tender_id: tenderId, is_leaf: true },
|
|
});
|
|
});
|
|
@@ -227,7 +239,6 @@ module.exports = app => {
|
|
const upDecimal = newDecimal.up, tpDecimal = newDecimal.extra ? newDecimal.extraTp : newDecimal.tp;
|
|
const upDecimal = newDecimal.up, tpDecimal = newDecimal.extra ? newDecimal.extraTp : newDecimal.tp;
|
|
const calcUp = upDecimal < oldDecimal.up,
|
|
const calcUp = upDecimal < oldDecimal.up,
|
|
calcTp = tpDecimal < (oldDecimal.extra ? oldDecimal.extraTp : oldDecimal.tp);
|
|
calcTp = tpDecimal < (oldDecimal.extra ? oldDecimal.extraTp : oldDecimal.tp);
|
|
- console.log(calcUp, calcTp);
|
|
|
|
|
|
|
|
if (calcUp || calcTp) {
|
|
if (calcUp || calcTp) {
|
|
const stageJgcl = await this.ctx.service.stageJgcl.getAllDataByCondition({
|
|
const stageJgcl = await this.ctx.service.stageJgcl.getAllDataByCondition({
|
|
@@ -281,7 +292,11 @@ module.exports = app => {
|
|
changeAdvanceBills.push(cb);
|
|
changeAdvanceBills.push(cb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- const changeBills = await this._reCalcLedger(tenderId, newDecimal, oldDecimal);
|
|
|
|
|
|
+
|
|
|
|
+ const billsService = this.ctx.tender.data.status === auditConst.ledger.status.checked
|
|
|
|
+ ? this.ctx.service.ledger
|
|
|
|
+ : this.ctx.service.reviseBills;
|
|
|
|
+ const changeBills = await this._reCalcLedger(tenderId, billsService, newDecimal, oldDecimal);
|
|
const [changeSj, changeSb, changeSo] = await this._reCalcStageExtra(tenderId, newDecimal, oldDecimal);
|
|
const [changeSj, changeSb, changeSo] = await this._reCalcStageExtra(tenderId, newDecimal, oldDecimal);
|
|
if (changeBills.length > 0 ||
|
|
if (changeBills.length > 0 ||
|
|
changeAdvanceBills.length > 0 ||
|
|
changeAdvanceBills.length > 0 ||
|
|
@@ -290,7 +305,7 @@ module.exports = app => {
|
|
try {
|
|
try {
|
|
await transaction.update(this.tableName,
|
|
await transaction.update(this.tableName,
|
|
{ decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
|
|
{ decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
|
|
- if (changeBills.length > 0) await transaction.updateRows(this.ctx.service.ledger.tableName, changeBills);
|
|
|
|
|
|
+ if (changeBills.length > 0) await transaction.updateRows(billsService.tableName, changeBills);
|
|
if (changeSj.length > 0) await transaction.updateRows(this.ctx.service.stageJgcl.tableName, changeSj);
|
|
if (changeSj.length > 0) await transaction.updateRows(this.ctx.service.stageJgcl.tableName, changeSj);
|
|
if (changeSb.length > 0) await transaction.updateRows(this.ctx.service.stageBonus.tableName, changeSb);
|
|
if (changeSb.length > 0) await transaction.updateRows(this.ctx.service.stageBonus.tableName, changeSb);
|
|
if (changeSo.length > 0) await transaction.updateRows(this.ctx.service.stageOther.tableName, changeSo);
|
|
if (changeSo.length > 0) await transaction.updateRows(this.ctx.service.stageOther.tableName, changeSo);
|