|
@@ -334,22 +334,25 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getStageUsedData(sid, cid) {
|
|
|
- const sql = 'SELECT c.*, ' +
|
|
|
- ' l.ledger_id As `ledger_id`, l.b_code As `l_code`, l.name As `l_name`, l.unit As `l_unit`, l.unit_price As `l_up`,' +
|
|
|
- ' l.deal_qty As `l_deal_qty`, l.deal_tp As `l_deal_tp`, l.quantity As `l_qty`, l.total_price As `l_tp`, ' +
|
|
|
- ' l.drawing_code As `l_drawing_code`, ' +
|
|
|
- ' p.name As `p_name`, p.drawing_code As `p_drawing_code`, p.`quantity` As `p_qty`' +
|
|
|
- ' FROM ' + this.tableName + ' As c ' +
|
|
|
- ' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, `sid` From ' + this.tableName +
|
|
|
- ' WHERE sid = ? And cid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`, `cbid`, `no_value`' +
|
|
|
- ' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid And c.sid = m.sid' +
|
|
|
- ' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' As l ON c.lid = l.id' +
|
|
|
- ' LEFT JOIN ' + this.ctx.service.pos.tableName + ' As p ON c.pid = p.id';
|
|
|
- const sqlParam = [sid, cid];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
+ const data = await this.getAllDataByCondition({ where: { sid, cid } });
|
|
|
+ const _ = this.ctx.helper._;
|
|
|
+ const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
|
|
|
+ const bills = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
+ where: { id: _.uniq(_.map(filter, 'lid')) }
|
|
|
+ });
|
|
|
+ const pos = await this.ctx.service.pos.getAllDataByCondition({
|
|
|
+ where: { id: _.uniq(_.map(filter, 'pid')) }
|
|
|
+ });
|
|
|
+ return filter.map(x => {
|
|
|
+ const b = bills.find(y => { return y.id === x.lid });
|
|
|
+ const p = pos.find(y => { return y.id === x.pid });
|
|
|
+ return {
|
|
|
+ ...x,
|
|
|
+ ledger_id: b.ledger_id, l_code: b.b_code, l_name: b.name, l_unit: b.unit, l_up: b.unit_price,
|
|
|
+ l_deal_qty: b.deal_qty, l_deal_tp: b.deal_tp, l_qty: b.quantity, l_tp: b.total_price, l_drawing_code: b.drawing_code,
|
|
|
+ p_name: p.name, p_drawing_code: p.drawing_code, p_qty: p.quantity,
|
|
|
+ };
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|