2019-10-31 11:54:16 +00:00
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
|
2019-01-25 10:58:50 +00:00
|
|
|
module.exports = Self => {
|
2019-07-26 09:48:01 +00:00
|
|
|
Self.remoteMethod('getShipped', {
|
2019-01-25 10:58:50 +00:00
|
|
|
description: 'Returns the first shipped possible for params',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
2019-05-30 06:41:08 +00:00
|
|
|
arg: 'landed',
|
|
|
|
type: 'date',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'addressFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'agencyModeFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'warehouseFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
2019-01-25 10:58:50 +00:00
|
|
|
}],
|
|
|
|
returns: {
|
2019-05-30 06:41:08 +00:00
|
|
|
type: 'date',
|
2019-01-25 10:58:50 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getShipped`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
Self.getShipped = async(landed, addressFk, agencyModeFk, warehouseFk)=> {
|
2019-10-31 11:54:16 +00:00
|
|
|
let stmts = [];
|
|
|
|
stmts.push(new ParameterizedSQL(
|
|
|
|
`CALL vn.zone_getShippedWarehouse(?, ?, ?)`, [
|
|
|
|
landed,
|
|
|
|
addressFk,
|
|
|
|
agencyModeFk
|
|
|
|
]
|
|
|
|
));
|
|
|
|
|
|
|
|
let rsIndex = stmts.push(new ParameterizedSQL(
|
|
|
|
`SELECT * FROM tmp.zoneGetShipped WHERE warehouseFk = ?`, [
|
|
|
|
warehouseFk
|
|
|
|
]
|
|
|
|
)) - 1;
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let shipped = await Self.rawStmt(sql);
|
|
|
|
|
|
|
|
return shipped[rsIndex][0];
|
2019-01-25 10:58:50 +00:00
|
|
|
};
|
|
|
|
};
|