|
@@ -794,6 +794,7 @@ module.exports = app => {
|
|
* @returns {Promise<*>} - 可用的变更令列表
|
|
* @returns {Promise<*>} - 可用的变更令列表
|
|
*/
|
|
*/
|
|
async getValidChanges(tid, bills, pos) {
|
|
async getValidChanges(tid, bills, pos) {
|
|
|
|
+ const timesLen = 100;
|
|
const filter = 'cb.`code` = ' + this.db.escape(bills.b_code) + (pos ? ' And cb.`bwmx` = ' + this.db.escape(pos.name) : '');
|
|
const filter = 'cb.`code` = ' + this.db.escape(bills.b_code) + (pos ? ' And cb.`bwmx` = ' + this.db.escape(pos.name) : '');
|
|
const sql = 'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
|
|
const sql = 'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
|
|
' c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
|
|
' c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
|
|
@@ -804,17 +805,18 @@ module.exports = app => {
|
|
' Left Join (' +
|
|
' Left Join (' +
|
|
' SELECT SUM(sc.qty) As used_amount, sc.cbid' +
|
|
' SELECT SUM(sc.qty) As used_amount, sc.cbid' +
|
|
' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
|
|
' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
|
|
- ' INNER JOIN (SELECT Max(stimes) As `stimes`, Max(sorder) As `sorder`, cbid ' +
|
|
|
|
|
|
+ ' INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
|
|
' FROM ' + this.ctx.service.stageChange.tableName +
|
|
' FROM ' + this.ctx.service.stageChange.tableName +
|
|
' WHERE tid = ?' +
|
|
' WHERE tid = ?' +
|
|
- ' GROUP BY cbid' +
|
|
|
|
|
|
+ ' GROUP BY cbid, sid' +
|
|
' ) As MF' +
|
|
' ) As MF' +
|
|
- ' ON sc.stimes = MF.stimes And sc.sorder = MF.sorder And sc.cbid = MF.cbid' +
|
|
|
|
|
|
+ ' ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
|
|
' GROUP BY sc.cbid' +
|
|
' GROUP BY sc.cbid' +
|
|
' ) As scb ON cb.id = scb.cbid' +
|
|
' ) As scb ON cb.id = scb.cbid' +
|
|
' WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
|
|
' WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
|
|
' ORDER BY c.in_time';
|
|
' ORDER BY c.in_time';
|
|
const sqlParam = [tid, tid, audit.flow.status.checked];
|
|
const sqlParam = [tid, tid, audit.flow.status.checked];
|
|
|
|
+ console.log(this.db.format(sql, sqlParam));
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
for (const c of changes) {
|
|
for (const c of changes) {
|
|
const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
|
|
const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
|