|
@@ -1114,37 +1114,29 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
const sql =
|
|
|
- 'SELECT C.*, Sum(U.utp) As used_tp, Round(Sum(U.utp) / C.total_price * 100, 2) As used_pt' +
|
|
|
- ' FROM ' +
|
|
|
- this.tableName +
|
|
|
- ' As C' +
|
|
|
- ' LEFT JOIN (SELECT sc.tid, sc.cid, sc.cbid, Round(SUM(sc.qty) * cb.unit_price, ?) As utp' +
|
|
|
- ' FROM ' +
|
|
|
- this.ctx.service.stageChange.tableName +
|
|
|
- ' As sc' +
|
|
|
+ 'SELECT C.*, Sum(U.utp) As used_tp, TRUNCATE(Sum(U.utp) / C.total_price * 100 + 0.005, 2) As used_pt' +
|
|
|
+ ' FROM ' + this.tableName + ' As C' +
|
|
|
+ ' LEFT JOIN (SELECT sc.tid, sc.cid, sc.cbid, IF(SUM(sc.qty) > 0, TRUNCATE(SUM(sc.qty) * cb.unit_price + ?, 0), TRUNCATE(SUM(sc.qty) * cb.unit_price - ?, ?)) As utp' +
|
|
|
+ ' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
|
|
|
' INNER JOIN (' +
|
|
|
' SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `cbid`, sChange.`sid` ' +
|
|
|
- ' FROM ' +
|
|
|
- this.ctx.service.stageChange.tableName +
|
|
|
- ' As sChange ' +
|
|
|
- ' LEFT JOIN ' +
|
|
|
- this.ctx.service.stage.tableName +
|
|
|
- ' As s' +
|
|
|
+ ' FROM ' + this.ctx.service.stageChange.tableName + ' As sChange ' +
|
|
|
+ ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' As s' +
|
|
|
' ON sChange.sid = s.id' +
|
|
|
- ' WHERE sChange.tid = ?' +
|
|
|
- filter +
|
|
|
+ ' WHERE sChange.tid = ?' + filter +
|
|
|
' GROUP By `lid`, `pid`, `cbid`, `sid`' +
|
|
|
' ) As m' +
|
|
|
' ON sc.stimes = m.stimes And sc.sorder = m.sorder And sc.`cbid` = m.`cbid` AND sc.`sid` = m.`sid` And sc.`lid` = m.`lid` And sc.`pid` = m.`pid`' +
|
|
|
- ' LEFT JOIN ' +
|
|
|
- this.ctx.service.changeAuditList.tableName +
|
|
|
+ ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName +
|
|
|
' As cb ON sc.cbid = cb.id' +
|
|
|
' GROUP By sc.`cbid`' +
|
|
|
' ) As U ON C.cid = U.cid' +
|
|
|
' WHERE C.tid = ? And C.status = ? And C.valid' +
|
|
|
' GROUP By C.cid' +
|
|
|
' ORDER By in_time';
|
|
|
- const sqlParam = [this.ctx.tender.info.decimal.tp, tid, tid, audit.flow.status.checked];
|
|
|
+ // 舍入步长
|
|
|
+ const step = parseFloat('0.' + '0000000'.substr(0, this.ctx.tender.info.decimal.tp) + '5');
|
|
|
+ const sqlParam = [step, step, this.ctx.tender.info.decimal.tp, tid, tid, audit.flow.status.checked];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|