From 49fed4e51e45f1d203ca43f13ed3c4cb02cd5cb2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 22 May 2024 12:23:33 +0200 Subject: [PATCH] refs #6964 feat: hasItemOlder --- db/versions/11064-grayMedeola/00-firstScript.sql | 6 ++++++ .../back/methods/item-shelving/hasItemOlder.js | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 db/versions/11064-grayMedeola/00-firstScript.sql diff --git a/db/versions/11064-grayMedeola/00-firstScript.sql b/db/versions/11064-grayMedeola/00-firstScript.sql new file mode 100644 index 000000000..301c0fef1 --- /dev/null +++ b/db/versions/11064-grayMedeola/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.sector ADD hasItemOlderReview BIGINT DEFAULT false NULL COMMENT 'Indica si el sector se revisa para comprobar si tiene ítems más viejos'; +ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js index ee4cdc829..02cd14bb8 100644 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ b/modules/item/back/methods/item-shelving/hasItemOlder.js @@ -46,17 +46,22 @@ module.exports = Self => { SELECT COUNT(ish.id) countItemOlder FROM vn.itemShelving ish JOIN ( - SELECT ish.itemFk, created,shelvingFk + SELECT ish.itemFk, created, shelvingFk FROM vn.itemShelving ish JOIN vn.shelving s ON ish.shelvingFk = s.code + LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk WHERE ish.shelvingFk = ? )sub ON sub.itemFK = ish.itemFk JOIN vn.shelving s ON s.code = ish.shelvingFk JOIN vn.parking p ON p.id = s.parkingFk - WHERE sub.created > ish.created - AND (p.code <> ? OR ? IS NULL) - AND (ish.shelvingFk <> ? OR ? IS NULL) - AND (ish.itemFk <> ? OR ? IS NULL)`, + JOIN vn.sector s2 ON s2.id = p.sectorFk + JOIN vn.productionConfig pc ON pc.itemOlderReviewHours + WHERE ish.created + INTERVAL pc.itemOlderReviewHours HOUR < sub.created + AND (p.code <> ? OR ? IS NULL) + AND (ish.shelvingFk <> ? OR ? IS NULL) + AND (ish.itemFk = ? OR ? IS NULL) + AND (p.pickingOrder < sub.pickingOrder OR sub.pickingOrder IS NULL) + AND (s2.hasItemOlderReview)`, [shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions); return result[0]['countItemOlder'] > 0; };