2024-06-07 14:29:51 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getListItemNewer', {
|
|
|
|
description:
|
|
|
|
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'shelvingFk',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
description: 'Shelving code'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'parking',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
description: 'Parking code'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
returns: {
|
2024-06-18 06:24:15 +00:00
|
|
|
type: 'Array',
|
2024-06-07 14:29:51 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getListItemNewer`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getListItemNewer = async(shelvingFk, parking, options) => {
|
|
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2024-06-18 06:24:15 +00:00
|
|
|
const [isParkingToReview] = await Self.rawSql(`
|
2024-06-07 14:29:51 +00:00
|
|
|
SELECT COUNT(p.id) parkingToReview
|
|
|
|
FROM vn.parking p
|
|
|
|
JOIN vn.sector s ON s.id = p.sectorFk
|
2024-06-17 17:50:51 +00:00
|
|
|
JOIN vn.productionConfig pc
|
|
|
|
WHERE p.code = ? AND s.code = pc.sectorToCode;`,
|
2024-06-07 14:29:51 +00:00
|
|
|
[parking], myOptions);
|
|
|
|
|
2024-06-18 06:24:15 +00:00
|
|
|
if (isParkingToReview['parkingToReview'] < 1) return [];
|
|
|
|
|
|
|
|
const result = await Self.rawSql(`
|
2024-06-07 14:29:51 +00:00
|
|
|
WITH tItemShelving AS(
|
|
|
|
SELECT is2.itemFk, is2.created, p.sectorFK, is2.id
|
|
|
|
FROM vn.itemShelving is2
|
|
|
|
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
|
|
|
|
JOIN vn.parking p ON p.id = sh.parkingFk
|
|
|
|
JOIN vn.sector s ON s.id = p.sectorFk
|
2024-06-17 17:50:51 +00:00
|
|
|
JOIN vn.productionConfig pc
|
2024-06-18 08:08:40 +00:00
|
|
|
WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode
|
2024-06-07 14:29:51 +00:00
|
|
|
), tItemInSector AS (
|
|
|
|
SELECT is2.itemFk, is2.created, is2.shelvingFk
|
|
|
|
FROM vn.itemShelving is2
|
|
|
|
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
|
|
|
|
JOIN vn.parking p ON p.id = sh.parkingFk
|
|
|
|
JOIN vn.sector s ON s.id = p.sectorFk
|
2024-06-17 17:50:51 +00:00
|
|
|
JOIN vn.productionConfig pc
|
2024-06-07 14:29:51 +00:00
|
|
|
WHERE is2.shelvingFk <> ?
|
2024-06-18 08:08:40 +00:00
|
|
|
AND s.code = pc.sectorFromCode)
|
2024-06-07 14:29:51 +00:00
|
|
|
SELECT ti.itemFK, tis.shelvingFk
|
|
|
|
FROM tItemShelving ti
|
|
|
|
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
|
|
|
|
JOIN vn.productionConfig pc
|
2024-07-05 06:43:45 +00:00
|
|
|
WHERE ti.created + INTERVAL pc.itemOlderReviewHours HOUR < tis.created ;`,
|
2024-06-18 06:24:15 +00:00
|
|
|
[shelvingFk, shelvingFk], myOptions);
|
|
|
|
return result;
|
2024-06-07 14:29:51 +00:00
|
|
|
};
|
|
|
|
};
|