|
@@ -958,51 +958,87 @@ module.exports = app => {
|
|
|
async getValidChanges(tid, bills, pos) {
|
|
|
const timesLen = 100;
|
|
|
const filter =
|
|
|
- 'cb.`code` = ' +
|
|
|
- this.db.escape(bills.b_code) +
|
|
|
- ' And cb.`name` = ' +
|
|
|
- this.db.escape(bills.name) +
|
|
|
- ' And cb.`unit` = ' +
|
|
|
- this.db.escape(bills.unit) +
|
|
|
- ' And cb.`unit_price` = ' +
|
|
|
- this.db.escape(bills.unit_price) +
|
|
|
+ 'cb.`code` = ' + this.db.escape(bills.b_code) +
|
|
|
+ ' And cb.`name` = ' + this.db.escape(bills.name) +
|
|
|
+ ' And cb.`unit` = ' + this.db.escape(bills.unit) +
|
|
|
+ ' And cb.`unit_price` = ' + this.db.escape(bills.unit_price) +
|
|
|
(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,' +
|
|
|
' c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
|
|
|
' cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, cb.bwmx As b_bwmx, ' +
|
|
|
' scb.used_amount' +
|
|
|
- ' FROM ' +
|
|
|
- this.tableName +
|
|
|
- ' As c ' +
|
|
|
- ' Left Join ' +
|
|
|
- this.ctx.service.changeAuditList.tableName +
|
|
|
- ' As cb On c.cid = cb.cid ' +
|
|
|
+ ' FROM ' + this.tableName + ' As c ' +
|
|
|
+ ' Left Join ' + this.ctx.service.changeAuditList.tableName + ' As cb On c.cid = cb.cid ' +
|
|
|
' Left Join (' +
|
|
|
' SELECT SUM(sc.qty) As used_amount, sc.cbid' +
|
|
|
- ' FROM ' +
|
|
|
- this.ctx.service.stageChange.tableName +
|
|
|
- ' As sc' +
|
|
|
- ' INNER JOIN (SELECT MAX(`stimes` * ' +
|
|
|
- timesLen +
|
|
|
- ' + `sorder`) As `flow`, cbid, sid ' +
|
|
|
- ' FROM ' +
|
|
|
- this.ctx.service.stageChange.tableName +
|
|
|
+ ' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
|
|
|
+ ' INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
|
|
|
+ ' FROM ' + this.ctx.service.stageChange.tableName +
|
|
|
' WHERE tid = ?' +
|
|
|
' GROUP BY cbid, sid' +
|
|
|
' ) As MF' +
|
|
|
- ' ON (sc.stimes * ' +
|
|
|
- timesLen +
|
|
|
- ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
|
|
|
+ ' ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
|
|
|
' GROUP BY sc.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';
|
|
|
const sqlParam = [tid, tid, audit.flow.status.checked];
|
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
|
for (const c of changes) {
|
|
|
- const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' + ' FROM ?? As ca ' + ' Left Join ?? As pa ' + ' On ca.uid = pa.id ' + ' Where ca.cid = ?';
|
|
|
+ const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
|
|
|
+ ' FROM ?? As ca ' +
|
|
|
+ ' Left Join ?? As pa ' +
|
|
|
+ ' On ca.uid = pa.id ' +
|
|
|
+ ' Where ca.cid = ?';
|
|
|
+ const aSqlParam = [this.ctx.service.changeAtt.tableName, this.ctx.service.projectAccount.tableName, c.cid];
|
|
|
+ c.attachments = await this.db.query(aSql, aSqlParam);
|
|
|
+ }
|
|
|
+ return changes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询审批人可用的变更令
|
|
|
+ * @param bills - 查询的清单
|
|
|
+ * @param pos - 查询的部位
|
|
|
+ * @return {Promise<*>} - 可用的变更令列表
|
|
|
+ */
|
|
|
+ async getAuditValidChanges(tid, bills, pos, times, order) {
|
|
|
+ const timesLen = 100;
|
|
|
+ const filter =
|
|
|
+ 'cb.`code` = ' + this.db.escape(bills.b_code) +
|
|
|
+ ' And cb.`name` = ' + this.db.escape(bills.name) +
|
|
|
+ ' And cb.`unit` = ' + this.db.escape(bills.unit) +
|
|
|
+ ' And cb.`unit_price` = ' + this.db.escape(bills.unit_price) +
|
|
|
+ (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,' +
|
|
|
+ ' c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
|
|
|
+ ' cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, cb.bwmx As b_bwmx, ' +
|
|
|
+ ' scb.used_amount' +
|
|
|
+ ' FROM ' + this.tableName + ' As c ' +
|
|
|
+ ' Left Join ' + this.ctx.service.changeAuditList.tableName + ' As cb On c.cid = cb.cid ' +
|
|
|
+ ' Left Join (' +
|
|
|
+ ' SELECT SUM(sc.qty) As used_amount, sc.cbid' +
|
|
|
+ ' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
|
|
|
+ ' INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
|
|
|
+ ' FROM ' + this.ctx.service.stageChange.tableName +
|
|
|
+ ' WHERE tid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) ' +
|
|
|
+ ' GROUP BY cbid, sid' +
|
|
|
+ ' ) As MF' +
|
|
|
+ ' ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
|
|
|
+ ' GROUP BY sc.cbid' +
|
|
|
+ ' ) As scb ON cb.id = scb.cbid' +
|
|
|
+ ' WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
|
|
|
+ ' ORDER BY c.in_time';
|
|
|
+ const sqlParam = [tid, times, times, order, tid, audit.flow.status.checked];
|
|
|
+ const changes = await this.db.query(sql, sqlParam);
|
|
|
+ for (const c of changes) {
|
|
|
+ const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
|
|
|
+ ' FROM ?? As ca ' +
|
|
|
+ ' Left Join ?? As pa ' +
|
|
|
+ ' On ca.uid = pa.id ' +
|
|
|
+ ' Where ca.cid = ?';
|
|
|
const aSqlParam = [this.ctx.service.changeAtt.tableName, this.ctx.service.projectAccount.tableName, c.cid];
|
|
|
c.attachments = await this.db.query(aSql, aSqlParam);
|
|
|
}
|