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 => {
|
2023-05-11 06:00:49 +00:00
|
|
|
Self.remoteMethodCtx('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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-11 06:00:49 +00:00
|
|
|
Self.getShipped = async(ctx, landed, addressFk, agencyModeFk, warehouseFk, options) => {
|
2021-08-13 14:46:44 +00:00
|
|
|
const myOptions = {};
|
2021-05-14 17:21:04 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
const stmts = [];
|
2023-05-11 06:00:49 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
|
|
|
const models = Self.app.models;
|
|
|
|
const isProductionAssistant = await models.VnUser.hasRole(userId, 'productionAssi', myOptions);
|
2019-10-31 11:54:16 +00:00
|
|
|
stmts.push(new ParameterizedSQL(
|
2023-05-11 06:00:49 +00:00
|
|
|
`CALL vn.zone_getShipped(?, ?, ?, ?)`, [
|
2019-10-31 11:54:16 +00:00
|
|
|
landed,
|
|
|
|
addressFk,
|
2023-05-11 06:00:49 +00:00
|
|
|
agencyModeFk,
|
|
|
|
isProductionAssistant
|
2019-10-31 11:54:16 +00:00
|
|
|
]
|
|
|
|
));
|
|
|
|
|
2021-05-14 17:21:04 +00:00
|
|
|
const rsIndex = stmts.push(new ParameterizedSQL(
|
2019-10-31 11:54:16 +00:00
|
|
|
`SELECT * FROM tmp.zoneGetShipped WHERE warehouseFk = ?`, [
|
|
|
|
warehouseFk
|
|
|
|
]
|
|
|
|
)) - 1;
|
|
|
|
|
2021-05-14 17:21:04 +00:00
|
|
|
const sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
const shipped = await Self.rawStmt(sql, myOptions);
|
2019-10-31 11:54:16 +00:00
|
|
|
|
|
|
|
return shipped[rsIndex][0];
|
2019-01-25 10:58:50 +00:00
|
|
|
};
|
|
|
|
};
|