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 => {
|
2020-09-23 09:21:25 +00:00
|
|
|
Self.remoteMethodCtx('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
|
2019-01-25 10:58:50 +00:00
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getLanded`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk, options) => {
|
2021-09-21 16:48:59 +00:00
|
|
|
const myOptions = {};
|
2021-06-18 13:05:03 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2020-09-23 09:21:25 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
|
|
|
const models = Self.app.models;
|
2023-01-23 14:24:00 +00:00
|
|
|
const roles = await models.VnUser.getRoles(userId);
|
2020-10-20 08:19:12 +00:00
|
|
|
const canSeeExpired = roles.filter(role =>
|
|
|
|
role == 'productionBoss' || role == 'administrative'
|
|
|
|
);
|
2020-09-23 09:21:25 +00:00
|
|
|
let showExpired = false;
|
2020-10-20 08:19:12 +00:00
|
|
|
if (canSeeExpired.length) showExpired = true;
|
2020-09-23 09:21:25 +00:00
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
const stmts = [];
|
2019-05-30 06:41:08 +00:00
|
|
|
stmts.push(new ParameterizedSQL(
|
2021-06-18 13:05:03 +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,
|
2020-09-23 09:21:25 +00:00
|
|
|
showExpired
|
2021-09-21 16:48:59 +00:00
|
|
|
]
|
2019-05-30 06:41:08 +00:00
|
|
|
));
|
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
const rsIndex = stmts.push('SELECT * FROM tmp.zoneGetLanded') - 1;
|
|
|
|
|
|
|
|
stmts.push('DROP TEMPORARY TABLE tmp.zoneGetLanded');
|
2019-05-30 06:41:08 +00:00
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
const sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
const landed = await Self.rawStmt(sql, myOptions);
|
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
|
|
|
};
|
|
|
|
};
|