diff --git a/db/changes/233001/00-itemShelving_inventory.sql b/db/changes/233001/00-itemShelving_inventory.sql new file mode 100644 index 000000000..b0b080ef3 --- /dev/null +++ b/db/changes/233001/00-itemShelving_inventory.sql @@ -0,0 +1,64 @@ + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_inventory`(vParkingFromFk VARCHAR(8), vParkingToFk VARCHAR(8)) +BEGIN +/** + * Devuelve un listado de ubicaciones a revisar + * + * @param vParkingFromFk Parking de partida, identificador de parking + * @param vParkingToFk Parking de llegada, identificador de parking +*/ + + DECLARE vSectorFk INT; + DECLARE vPickingOrderFrom INT; + DECLARE vPickingOrderTo INT; + + SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom + FROM parking p + WHERE p.code = vParkingFromFk COLLATE 'utf8mb3_general_ci'; + + SELECT p.pickingOrder INTO vPickingOrderTo + FROM parking p + WHERE p.code = vParkingToFk COLLATE 'utf8mb3_general_ci'; + + CALL visible_getMisfit(vSectorFk); + + 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 priority + FROM itemShelving ish + JOIN item i ON i.id = ish.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN (SELECT s.itemFk, sum(s.quantity) notPrepared + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN config c ON c.mainWarehouseFk = w.id + WHERE t.shipped BETWEEN util.VN_CURDATE() + AND util.dayEnd(util.VN_CURDATE()) + AND s.isPicked = FALSE + GROUP BY s.itemFk) s ON s.itemFk = i.id + JOIN hedera.imageConfig ic + WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo + AND p.sectorFk = vSectorFk + ORDER BY p.pickingOrder; + +END$$ +DELIMITER ; + diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index fe11d5b64..eaa00a3de 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -37,7 +37,7 @@ ALTER TABLE `vn`.`ticket` AUTO_INCREMENT = 1; INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`) VALUES - ('DEFAULT_TOKEN', '1209600', util.VN_CURDATE(), 66); + ('DEFAULT_TOKEN', '1209600', CURDATE(), 66); INSERT INTO `salix`.`printConfig` (`id`, `itRecipient`, `incidencesEmail`) VALUES @@ -2953,3 +2953,8 @@ INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `t ('E', 'Midgard', 1, 'CEE'), ('R', 'Jotunheim', 1, 'NATIONAL'), ('W', 'Vanaheim', 1, 'WORLD'); + + +INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) + VALUES + (1, 0, 0, 'marvel.com'); 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..6a8c9804c --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/getInventory.spec.js @@ -0,0 +1,24 @@ +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}; + await models.ItemShelving.rawSql(` + UPDATE vn.config + SET mainWarehouseFk=1 + WHERE id=1 + `, null, options); + response = await models.ItemShelving.getInventory('100-01', 'LR-02-3', 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); }; diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 49bebcb6b..be379adca 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -23,6 +23,9 @@ }, "isChecked": { "type": "boolean" + }, + "visible": { + "type": "number" } }, "relations": {