|
@@ -220,6 +220,7 @@ const gatherUtils = {
|
|
|
gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
|
|
|
},
|
|
|
};
|
|
|
+const rmUtils = require('../lib/rm/rm_utils');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class RptGatherMemory extends app.BaseService {
|
|
@@ -1182,7 +1183,7 @@ module.exports = app => {
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
- async _gatherChange(tender) {
|
|
|
+ async _gatherChange(tender, hasUsed) {
|
|
|
const self = this;
|
|
|
try {
|
|
|
const info = await this.ctx.service.tenderInfo.getTenderInfo(tender.id);
|
|
@@ -1205,7 +1206,9 @@ module.exports = app => {
|
|
|
});
|
|
|
c.attNames = names.join('\n');
|
|
|
}
|
|
|
- const changeBills = await this.ctx.service.changeAuditList.getChangeAuditBills(tender.id, this.ctx.session.sessionProject.page_show.isOnlyChecked);
|
|
|
+ const changeBills = hasUsed
|
|
|
+ ? await this.ctx.service.stageChangeFinal.getChangeBillsWithUsedQty(tender.id, this.ctx.session.sessionProject.page_show.isOnlyChecked)
|
|
|
+ : await this.ctx.service.changeAuditList.getChangeAuditBills(tender.id, this.ctx.session.sessionProject.page_show.isOnlyChecked);
|
|
|
for (const d of changeBills) {
|
|
|
d.tender_name = tender.name;
|
|
|
d.o_qty = d.oamount;
|
|
@@ -1217,8 +1220,16 @@ module.exports = app => {
|
|
|
d.sp_qty = d.spamount;
|
|
|
d.sp_tp = this.ctx.helper.mul(d.sp_qty, d.unit_price, decimal.tp);
|
|
|
|
|
|
+ d.used_tp = this.ctx.helper.mul(d.used_qty, d.unit_price, decimal.tp);
|
|
|
+ d.is_used = !!d.used_qty;
|
|
|
+
|
|
|
const auditAmount = d.audit_amount ? d.audit_amount.split(',') : [];
|
|
|
const relaChange = ctx.helper._.find(change, {cid: d.cid});
|
|
|
+ d.relaChange = relaChange;
|
|
|
+ if (relaChange) {
|
|
|
+ if (d.is_used) relaChange.is_used = true;
|
|
|
+ relaChange.used_tp = ctx.helper.add(relaChange.used_tp, d.used_tp);
|
|
|
+ }
|
|
|
for (const [i, aa] of auditAmount.entries()) {
|
|
|
const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
|
|
|
d[amountField] = aa ? parseFloat(aa) : 0;
|
|
@@ -1228,6 +1239,14 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ for (const c of change) {
|
|
|
+ c.is_used = !!c.is_used;
|
|
|
+ c.used_ratio = c.total_price ? ctx.helper.mul(ctx.helper.div(c.used_tp, c.total_price), 100) : 0;
|
|
|
+ }
|
|
|
+ for (const cb of changeBills) {
|
|
|
+ cb.is_used_bgl = cb.relaChange ? cb.relaChange.is_used : cb.is_used;
|
|
|
+ delete cb.relaChange;
|
|
|
+ }
|
|
|
|
|
|
change.sort(function (a, b) {
|
|
|
return a.code.localeCompare(b.code);
|
|
@@ -1255,9 +1274,10 @@ module.exports = app => {
|
|
|
if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
|
|
|
|
|
|
const result = { mem_gather_change: [], mem_gather_change_bills: [] };
|
|
|
+ const hasUsed = rmUtils.checkFieldsExist(memFieldKeys, ['used_qty', 'is_used_bgl', 'is_used', 'used_ratio']);
|
|
|
for (const t of gsCustom.tenders) {
|
|
|
const tender = await this.ctx.service.tender.getCheckTender(t.tid);
|
|
|
- const [change, changeBills] = await this._gatherChange(tender);
|
|
|
+ const [change, changeBills] = await this._gatherChange(tender, hasUsed);
|
|
|
result.mem_gather_change.push(...change);
|
|
|
result.mem_gather_change_bills.push(...changeBills);
|
|
|
}
|