|
@@ -276,7 +276,7 @@ module.exports = app => {
|
|
|
async getUsedData(tid, cid) {
|
|
|
const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
|
|
|
let filter;
|
|
|
- if (lastStage.id === this.ctx.stage.id) {
|
|
|
+ if (this.ctx.stage && lastStage.id === this.ctx.stage.id) {
|
|
|
filter = this.db.format(' And (s.`order` < ? || (s.`order` = ? And sChange.`stimes` <= ? And sChange.`sorder` <= ?))',
|
|
|
[lastStage.order, lastStage.order, this.ctx.stage.curTimes, this.ctx.stage.curOrder]);
|
|
|
} else {
|
|
@@ -312,6 +312,25 @@ module.exports = app => {
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
|
+ async getFinalUsedData(tid, cid) {
|
|
|
+ const sql = 'SELECT c.lid, c.pid, SUM(c.qty) as used_qty,' +
|
|
|
+ ' cb.tid, cb.cid, cb.id, cb.code, cb.name, cb.unit, cb.unit_price, cb.detail, cb.samount' +
|
|
|
+ ' FROM ' + this.ctx.service.changeAuditList.tableName + ' As cb' +
|
|
|
+ ' LEFT JOIN ' + this.tableName + ' As c ON cb.id = c.cbid ' +
|
|
|
+ ' INNER JOIN (' +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, sChange.`sid`, `cid` ' +
|
|
|
+ ' FROM ' + this.tableName + ' As sChange' +
|
|
|
+ ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' As s ON sChange.sid = s.id' +
|
|
|
+ ' WHERE sChange.tid = ? AND cid = ?' +
|
|
|
+ ' GROUP By `lid`, `pid`, `cbid`, sChange.`sid`' +
|
|
|
+ ' ) As m' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.`cbid` = m.`cbid` AND c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`lid` = m.`lid` And c.`pid` = m.`pid`' +
|
|
|
+ ' WHERE cb.cid = ?' +
|
|
|
+ ' GROUP By c.`cbid`';
|
|
|
+ const sqlParam = [tid, cid, cid];
|
|
|
+ return await this.db.query(sql, sqlParam);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取 变更令 - 变更清单 当期使用情况
|
|
|
* @param {Number} sid - 查询期id
|