From 93da12923959e0b829871d30e08b1e157f3b6e7c Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jul 2023 08:54:45 +0200 Subject: [PATCH] refs #5983 feat(itemShelving): add getInventory --- .../233001/00-itemShelving_inventory.sql | 52 +++++++++++++++++++ .../methods/item-shelving/getInventory.js | 37 +++++++++++++ .../item-shelving/specs/getInventory.spec.js | 19 +++++++ modules/item/back/models/item-shelving.js | 1 + 4 files changed, 109 insertions(+) create mode 100644 db/changes/233001/00-itemShelving_inventory.sql create mode 100644 modules/item/back/methods/item-shelving/getInventory.js create mode 100644 modules/item/back/methods/item-shelving/specs/getInventory.spec.js diff --git a/db/changes/233001/00-itemShelving_inventory.sql b/db/changes/233001/00-itemShelving_inventory.sql new file mode 100644 index 000000000..b2a2ff321 --- /dev/null +++ b/db/changes/233001/00-itemShelving_inventory.sql @@ -0,0 +1,52 @@ + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_inventory`(vParkingFromFk INT, vParkingToFk INT) +/** + * Devuelve un listado de ubicaciones a revisar + * + * @param vParkingFromFk Parking de partida, identificador de vn.parking + * @param vParkingToFk Parking de llegada, identificador de vn.parking +*/ + + DECLARE vSectorFk INT; + DECLARE vPickingOrderFrom INT; + DECLARE vPickingOrderTo INT; + + SELECT ish.id, + p.pickingOrder, + p.code parking, + ish.shelvingFk, + ish.itemFk, + i.longName, + ish.visible, + p.sectorFk, + it.workerFk buyer, + CONCAT('http:',ic.url, '/catalog/1600x900/',i.image) urlImage, + ish.isChecked, + CASE + WHEN s.notPrepared > sm.parked THEN 0 + WHEN sm.visible > sm.parked THEN 1 + ELSE 2 + END + FROM vn.itemShelving ish + JOIN vn.item i ON i.id = ish.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN (SELECT s.itemFk, sum(s.quantity) notPrepared + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN CURDATE() + AND CURDATE() + INTERVAL 23 HOUR + AND s.isPicked = FALSE + AND w.name = 'Algemesi' + GROUP BY s.itemFk) s ON s.itemFk = i.id + JOIN hedera.imageConfig ic + WHERE p.pickingOrder BETWEEN vParkingFrom AND vPickingOrderTo + AND p.sectorFk = vSectorFk + ORDER BY p.pickingOrder; + +END ;; +DELIMITER ; diff --git a/modules/item/back/methods/item-shelving/getInventory.js b/modules/item/back/methods/item-shelving/getInventory.js new file mode 100644 index 000000000..144bd83e7 --- /dev/null +++ b/modules/item/back/methods/item-shelving/getInventory.js @@ -0,0 +1,37 @@ +module.exports = Self => { + Self.remoteMethod('getInventory', { + description: 'Get list of itemShelving to review between two parking code', + accessType: 'WRITE', + accepts: [{ + arg: 'parkingFrom', + type: 'string', + required: true, + description: 'Parking code from' + }, + { + arg: 'parkingTo', + type: 'string', + required: true, + description: 'Parking code to' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getInventory`, + verb: 'POST' + } + }); + + Self.getInventory = async(parkingFrom, parkingTo, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const [result] = await Self.rawSql(`CALL vn.itemShelving_inventory(?, ?)`, [parkingFrom, parkingTo], myOptions); + + return result; + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/getInventory.spec.js b/modules/item/back/methods/item-shelving/specs/getInventory.spec.js new file mode 100644 index 000000000..76cc39073 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/getInventory.spec.js @@ -0,0 +1,19 @@ +const models = require('vn-loopback/server/server').models; + +describe('itemShelving getInventory()', () => { + it('should return a list of itemShelvings', async() => { + const tx = await models.ItemShelving.beginTransaction({}); + + let response; + try { + const options = {transaction: tx}; + response = await models.ItemShelving.getInventory(1, 2, options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(response.length).toEqual(2); + }); +}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index 5f372a3be..98ff18931 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/item-shelving/deleteItemShelvings')(Self); + require('../methods/item-shelving/getInventory')(Self); };