|
@@ -89,23 +89,29 @@ module.exports = app => {
|
|
|
const p = this.ctx.helper._.find(pre, function (x) {
|
|
|
return x.lid === c.lid;
|
|
|
});
|
|
|
- if (!p) continue;
|
|
|
- c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
|
|
|
- c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
|
|
|
- c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
|
|
|
- c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
|
|
|
- pre.splice(pre.indexOf(p), 1);
|
|
|
+ if (p) {
|
|
|
+ c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
|
|
|
+ c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
|
|
|
+ c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
|
|
|
+ c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
|
|
|
+ c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
|
|
|
+ pre.splice(pre.indexOf(p), 1);
|
|
|
+ } else {
|
|
|
+ c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//await transaction.insert(this.tableName, cur);
|
|
|
for (const p of pre) {
|
|
|
p.sid = stage.id;
|
|
|
p.sorder = stage.order;
|
|
|
+ p.used = p.used || !this.ctx.helper.checkZero(p.contract_qty) || !this.ctx.helper.checkZero(p.qc_qty);
|
|
|
}
|
|
|
await transaction.insert(this.tableName, cur.concat(pre));
|
|
|
} else {
|
|
|
- const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp)' +
|
|
|
- ' SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp' +
|
|
|
+ const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp, used)' +
|
|
|
+ ' SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp,' +
|
|
|
+ ' IFNULL((b.contract_qty <> 0 or b.contract_tp <> 0 or b.qc_qty <> 0 or b.qc_tp <> 0), 0) As used' +
|
|
|
' FROM ' + this.ctx.service.stageBills.tableName + ' AS b' +
|
|
|
' INNER JOIN(' +
|
|
|
' SELECT Max(`times` * ' + timesLen + ' + `order`) As `flow`, `lid` FROM ' + this.ctx.service.stageBills.tableName +
|