|
@@ -1092,16 +1092,21 @@ module.exports = app => {
|
|
|
if (!this.changeInfo) await this.getChangeInfo(tid, sid);
|
|
|
this.changeInfoBills = [];
|
|
|
for (const c of this.changeInfo) {
|
|
|
- const cb = await this.ctx.service.stageChange.getUsedData(tid, c.cid);
|
|
|
+ const cb = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: c.cid } });
|
|
|
+ const cbu = await this.ctx.service.stageChange.getUsedData(tid, c.cid);
|
|
|
const curUsedBills = await this.ctx.service.stageChange.getStageUsedData(sid, c.cid);
|
|
|
for (const b of cb) {
|
|
|
b.qty = this.ctx.helper._.toNumber(b.samount);
|
|
|
- b.valid_qty = this.ctx.helper.sub(b.qty, b.used_qty);
|
|
|
b.tp = this.ctx.helper.round(this.ctx.helper.mul(b.qty, b.unit_price), this.ctx.tender.info.decimal.tp);
|
|
|
- const pos = this.ctx.helper._.filter(curUsedBills, { cbid: b.id });
|
|
|
+
|
|
|
+ const u = cbu.find(x => { return x.id === b.id; });
|
|
|
+ b.used_qty = u ? u.used_qty : 0;
|
|
|
+
|
|
|
+ b.valid_qty = this.ctx.helper.sub(b.qty, b.used_qty);
|
|
|
+ const cur = this.ctx.helper._.filter(curUsedBills, { cbid: b.id });
|
|
|
b.cur_qty = 0;
|
|
|
- for (const p of pos) {
|
|
|
- b.cur_qty = this.ctx.helper.add(b.cur_qty, p.qty);
|
|
|
+ for (const cc of cur) {
|
|
|
+ b.cur_qty = this.ctx.helper.add(b.cur_qty, cc.qty);
|
|
|
}
|
|
|
b.cur_used = !!b.cur_qty;
|
|
|
this.changeInfoBills.push(b);
|