2019-05-30 06:41:08 +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('getLanded', {
|
2019-01-25 10:58:50 +00:00
|
|
|
description: 'Returns the first shipped and landed possible for params',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
2019-05-30 06:41:08 +00:00
|
|
|
arg: 'shipped',
|
|
|
|
type: 'date',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'addressFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'agencyModeFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'warehouseFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
2020-06-05 08:01:21 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'showExpiredZones',
|
|
|
|
type: 'boolean',
|
|
|
|
required: true
|
2019-01-25 10:58:50 +00:00
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getLanded`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-05 08:01:21 +00:00
|
|
|
Self.getLanded = async(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones) => {
|
2019-05-30 06:41:08 +00:00
|
|
|
let stmts = [];
|
|
|
|
stmts.push(new ParameterizedSQL(
|
2020-06-05 08:01:21 +00:00
|
|
|
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
|
2019-07-26 09:48:01 +00:00
|
|
|
shipped,
|
|
|
|
addressFk,
|
|
|
|
agencyModeFk,
|
2020-06-05 08:01:21 +00:00
|
|
|
warehouseFk,
|
|
|
|
showExpiredZones
|
2019-05-30 06:41:08 +00:00
|
|
|
]
|
|
|
|
));
|
|
|
|
|
|
|
|
let rsIndex = stmts.push(
|
|
|
|
`SELECT * FROM tmp.zoneGetLanded`) - 1;
|
2019-11-15 14:42:00 +00:00
|
|
|
stmts.push(`DROP TEMPORARY TABLE tmp.zoneGetLanded`);
|
2019-05-30 06:41:08 +00:00
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let landed = await Self.rawStmt(sql);
|
2019-01-25 10:58:50 +00:00
|
|
|
|
2019-05-30 06:41:08 +00:00
|
|
|
return landed[rsIndex][0];
|
2019-01-25 10:58:50 +00:00
|
|
|
};
|
|
|
|
};
|