salix/modules/item/back/methods/item-shelving/getListItemNewer.js

71 lines
2.7 KiB
JavaScript
Raw Normal View History

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
2024-09-18 21:41:01 +00:00
FROM vn.parking p
2024-06-07 14:29:51 +00:00
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
2024-11-13 10:15:31 +00:00
JOIN vn.shelving sh ON sh.id = is2.shelvingFk
2024-06-07 14:29:51 +00:00
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-11-13 10:15:31 +00:00
WHERE sh.code = ? AND s.code = pc.sectorFromCode
2024-06-07 14:29:51 +00:00
), tItemInSector AS (
SELECT is2.itemFk, is2.created, sh.code
2024-06-07 14:29:51 +00:00
FROM vn.itemShelving is2
2024-11-13 10:15:31 +00:00
JOIN vn.shelving sh ON sh.id = is2.shelvingFk
2024-06-07 14:29:51 +00:00
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-11-13 10:15:31 +00:00
WHERE sh.code <> ?
2024-06-18 08:08:40 +00:00
AND s.code = pc.sectorFromCode)
SELECT ti.itemFK, tis.code shelvingFk
2024-06-07 14:29:51 +00:00
FROM tItemShelving ti
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
JOIN vn.productionConfig pc
2024-09-23 06:09:24 +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
};
};