8282-testToMaster #3284
|
@ -46,34 +46,44 @@ module.exports = Self => {
|
|||
const pickingOrderToCompare = parkingItem['pickingOrder'];
|
||||
|
||||
const result = await Self.rawSql(`
|
||||
WITH currentItemShelving AS(
|
||||
SELECT is2.created + INTERVAL ? HOUR created, is2.itemFk, sh.code
|
||||
FROM vn.itemShelving is2
|
||||
JOIN vn.shelving sh ON sh.id = is2.shelvingFk
|
||||
LEFT JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
LEFT JOIN vn.sector s ON s.id = p.sectorFk
|
||||
WHERE sh.code = ? AND (? IS NULL OR is2.itemFk = ?)
|
||||
)
|
||||
,itemShelvings AS (
|
||||
SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder,p.code parkingFk
|
||||
FROM vn.itemShelving is2
|
||||
JOIN currentItemShelving ai ON is2.itemfk = ai.itemFk
|
||||
JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
JOIN vn.sector s ON s.id = p.sectorFk)
|
||||
,parkingDestiny AS (
|
||||
SELECT ? pickingOrder)
|
||||
SELECT ish.*,
|
||||
CASE
|
||||
WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created THEN "new"
|
||||
WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created THEN "old"
|
||||
END AS itemCreated
|
||||
FROM itemShelvings ish
|
||||
JOIN parkingDestiny d
|
||||
JOIN currentItemShelving aish
|
||||
WHERE ish.pickingOrder < d.pickingOrder AND aish.created < ish.created OR
|
||||
ish.pickingOrder > d.pickingOrder AND aish.created > ish.created;`,
|
||||
[hoursToCompare, shelving, itemFk, itemFk, pickingOrderToCompare], myOptions);
|
||||
WITH currentItemShelving AS (
|
||||
SELECT is2.created, is2.itemFk, sh.code
|
||||
FROM vn.itemShelving is2
|
||||
JOIN vn.shelving sh ON sh.id = is2.shelvingFk
|
||||
LEFT JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
LEFT JOIN vn.sector s ON s.id = p.sectorFk
|
||||
WHERE sh.code = ? AND (? IS NULL OR is2.itemFk = ?)
|
||||
),
|
||||
itemShelvings AS (
|
||||
SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder, p.code AS parkingFk
|
||||
FROM vn.itemShelving is2
|
||||
JOIN currentItemShelving ai ON is2.itemFk = ai.itemFk
|
||||
JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
JOIN vn.sector s ON s.id = p.sectorFk
|
||||
),
|
||||
parkingDestiny AS (
|
||||
SELECT ? AS pickingOrder
|
||||
)
|
||||
SELECT ish.*,
|
||||
CASE
|
||||
WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created
|
||||
AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "old"
|
||||
WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created
|
||||
AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "new"
|
||||
END AS itemCreated
|
||||
FROM itemShelvings ish
|
||||
JOIN parkingDestiny d ON d.pickingOrder IS NOT NULL
|
||||
JOIN currentItemShelving aish ON ish.itemFk = aish.itemFk
|
||||
WHERE ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ?
|
||||
AND (
|
||||
(ish.pickingOrder < d.pickingOrder AND aish.created < ish.created)
|
||||
OR
|
||||
(ish.pickingOrder > d.pickingOrder AND aish.created > ish.created)
|
||||
);
|
||||
`,
|
||||
[shelving, itemFk, itemFk, pickingOrderToCompare,
|
||||
hoursToCompare, hoursToCompare, hoursToCompare, hoursToCompare], myOptions);
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue