|
@@ -11,6 +11,7 @@
|
|
|
const defaultPid = -1; // 非pid
|
|
|
const audit = require('../const/audit');
|
|
|
const timesLen = audit.stage.timesLen;
|
|
|
+const changeConst = require('../const/change');
|
|
|
|
|
|
module.exports = app => {
|
|
|
|
|
@@ -393,6 +394,32 @@ module.exports = app => {
|
|
|
const data = await this.getAllDataByCondition({ where: { tid, sid } });
|
|
|
return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid']);
|
|
|
}
|
|
|
+
|
|
|
+ async getQualityTotalPrice(sid) {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +
|
|
|
+ ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON sc.cid = c.cid' +
|
|
|
+ ' WHERE sid = ?';
|
|
|
+ const data = await this.db.query(sql, [sid]);
|
|
|
+ const bqData = [];
|
|
|
+ for (const d of data) {
|
|
|
+ if (!d.qty) continue;
|
|
|
+ let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
|
|
|
+ if (!bd) {
|
|
|
+ const bills = await this.ctx.service.ledger.getDataById(d.lid);
|
|
|
+ if (!bills) continue;
|
|
|
+ bd = { lid: d.lid, quality: d.quality, unit_price: bills.unit_price };
|
|
|
+ bqData.push(bd);
|
|
|
+ }
|
|
|
+ const tp = this.ctx.helper.mul(d.qty, bd.unit_price, this.ctx.tender.info.decimal.tp);
|
|
|
+ bd.tp = this.ctx.helper.add(bd.tp, tp);
|
|
|
+ }
|
|
|
+ const result = {};
|
|
|
+ result.common = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.common.value; }), 'tp'));
|
|
|
+ result.more = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.more.value; }), 'tp'));
|
|
|
+ result.great = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.great.value; }), 'tp'));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return StageChange;
|