|
@@ -122,6 +122,24 @@ module.exports = app => {
|
|
|
await this.db.update(this.tableName, data, { where: { tid: tenderId } });
|
|
|
}
|
|
|
|
|
|
+ async _getLedgerService() {
|
|
|
+ try {
|
|
|
+ if (this.ctx.tender.data.status === auditConst.ledger.status.checked) {
|
|
|
+ const stageCount = this.ctx.service.stage.count({tid: this.ctx.tender.id});
|
|
|
+ if (stageCount === 0) {
|
|
|
+ const revise = await ctx.service.ledgerRevise.getLastestRevise(this.ctx.tender.id);
|
|
|
+ if (revise.status === auditConst.revise.status.uncheck || revise.status === auditConst.revise.status.checkNo) {
|
|
|
+ return [this.ctx.service.reviseBills, this.ctx.service.revisePos];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return [this.ctx.service.ledger, this.ctx.service.pos];
|
|
|
+ }
|
|
|
+ } catch(err) {
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
async savePrecision(tenderId, newPrecision, oldPrecision, decimal) {
|
|
|
const changePrecision = [];
|
|
|
const units = await this.ctx.service.ledger.getTenderUsedUnits(tenderId);
|
|
@@ -146,16 +164,9 @@ module.exports = app => {
|
|
|
}
|
|
|
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;
|
|
|
- }
|
|
|
+ const [billsService, posService] = await this._getLedgerService();
|
|
|
|
|
|
- if (changeUnits.length > 0) {
|
|
|
+ if (changeUnits.length > 0 && billsService && posService) {
|
|
|
const bills = await billsService.getAllDataByCondition({
|
|
|
columns: ['id', 'unit', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty'],
|
|
|
where: { tender_id: tenderId, unit: changeUnits, is_leaf: true },
|
|
@@ -295,18 +306,8 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- let billsService = null;
|
|
|
- if (this.ctx.tender.data.ledger_status === auditConst.ledger.status.checked) {
|
|
|
- const stageCount = this.ctx.service.stage.count({tid: tenderId});
|
|
|
- if (stageCount === 0) {
|
|
|
- const revise = await ctx.service.ledgerRevise.getLastestRevise(tenderId);
|
|
|
- if (revise.status === auditConst.revise.status.uncheck || revise.status === auditConst.revise.status.checkNo) {
|
|
|
- billsService = this.ctx.service.reviseBills;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- billsService = this.ctx.service.ledger;
|
|
|
- }
|
|
|
+ const [billsService] = await this._getLedgerService();
|
|
|
+
|
|
|
const changeBills = await this._reCalcLedger(tenderId, billsService, newDecimal, oldDecimal);
|
|
|
const [changeSj, changeSb, changeSo] = await this._reCalcStageExtra(tenderId, newDecimal, oldDecimal);
|
|
|
if (changeBills.length > 0 ||
|