diff --git a/back/methods/collection/spec/collectionFauls.spec.js b/back/methods/collection/spec/collectionFauls.spec.js index 0df234bfd..210dcdf63 100644 --- a/back/methods/collection/spec/collectionFauls.spec.js +++ b/back/methods/collection/spec/collectionFauls.spec.js @@ -1,8 +1,9 @@ - +const app = require('vn-loopback/server/server'); describe('collectionFaults()', () => { it('return shelving afected', async() => { - let val = 2; + let response = await app.models.Collection.collectionFaults('UXN', 0, 1); - expect(val).toBeGreaterThan(1); + expect(response.length).toBeGreaterThan(0); + expect(response[0][0].shelvingFk).toEqual('UXN'); }); }); diff --git a/back/methods/collection/spec/getCollection.spec.js b/back/methods/collection/spec/getCollection.spec.js index b8a92285f..44c7af62f 100644 --- a/back/methods/collection/spec/getCollection.spec.js +++ b/back/methods/collection/spec/getCollection.spec.js @@ -2,9 +2,10 @@ const app = require('vn-loopback/server/server'); describe('getCollection()', () => { it('return list of collection', async() => { - let ctx = {req: {accessToken: {userId: 1}}}; + let ctx = {req: {accessToken: {userId: 106}}}; let response = await app.models.Collection.getCollection(ctx); - expect(response.length).toEqual(0); + expect(response.length).toBeGreaterThan(0); + expect(response[0].collectionFk).toEqual(1); }); }); diff --git a/back/methods/collection/spec/getSectors.spec.js b/back/methods/collection/spec/getSectors.spec.js index 4ba288c01..d453220a0 100644 --- a/back/methods/collection/spec/getSectors.spec.js +++ b/back/methods/collection/spec/getSectors.spec.js @@ -5,5 +5,7 @@ describe('getSectors()', () => { let response = await app.models.Collection.getSectors(); expect(response.length).toBeGreaterThan(0); + expect(response[0].id).toEqual(1); + expect(response[0].description).toEqual('First sector'); }); }); diff --git a/back/methods/collection/spec/newCollection.spec.js b/back/methods/collection/spec/newCollection.spec.js index 4bf3f7945..bd574db0f 100644 --- a/back/methods/collection/spec/newCollection.spec.js +++ b/back/methods/collection/spec/newCollection.spec.js @@ -2,9 +2,10 @@ const app = require('vn-loopback/server/server'); describe('newCollection()', () => { it('return a new collection', async() => { - let ctx = {req: {accessToken: {userId: 1}}}; - let response = await app.models.Collection.newCollection(ctx, 500, 1, 1); + let ctx = {req: {accessToken: {userId: 106}}}; + let response = await app.models.Collection.newCollection(ctx, 1, 1, 1); expect(response.length).toBeGreaterThan(0); + expect(response[0].ticketFk).toEqual(1); }); }); diff --git a/back/methods/collection/spec/updateCollectionSale.spec.js b/back/methods/collection/spec/updateCollectionSale.spec.js index bd4d0fb78..4695f6eec 100644 --- a/back/methods/collection/spec/updateCollectionSale.spec.js +++ b/back/methods/collection/spec/updateCollectionSale.spec.js @@ -1,7 +1,12 @@ -describe('updateCollectionSale()', () => { - it('return a collection updated', async() => { - let val = 2; +const app = require('vn-loopback/server/server'); - expect(val).toBeGreaterThan(1); +describe('updateCollectionSale()', () => { + it('return a new collection', async() => { + let ctx = {req: {accessToken: {userId: 106}}}; + let response = await app.models.Collection.updateCollectionSale(ctx, 1, 5, 5, 5, 1, 4, false, 'UXN', 1, 1); + + expect(response.length).toBeGreaterThan(0); + expect(response[0][0].id).toEqual(1); + expect(response[0][0].quantity).toEqual(5); }); }); diff --git a/db/changes/10162-postValentineDay/00-collectionPlacement_get.sql b/db/changes/10162-postValentineDay/00-collectionPlacement_get.sql new file mode 100644 index 000000000..d89f6a801 --- /dev/null +++ b/db/changes/10162-postValentineDay/00-collectionPlacement_get.sql @@ -0,0 +1,108 @@ +DROP procedure IF EXISTS `vn`.`collectionPlacement_get`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`collectionPlacement_get`(vCollectionFk INT) +BEGIN + + DECLARE vCalcFk INT; + DECLARE vWarehouseFk INT; + DECLARE vWarehouseAliasFk INT; + + SELECT t.warehouseFk, w.aliasFk + INTO vWarehouseFk, vWarehouseAliasFk + FROM vn.ticket t + JOIN vn.ticketCollection tc ON tc.ticketFk = t.id + JOIN vn.warehouse w ON w.id = t.warehouseFk + WHERE tc.collectionFk = vCollectionFk + LIMIT 1; + + CALL cache.visible_refresh(vCalcFk,FALSE,vWarehouseFk); + + DROP TEMPORARY TABLE IF EXISTS tmp.parked; + CREATE TEMPORARY TABLE tmp.parked + ENGINE MEMORY + SELECT s.itemFk, 0 as quantity + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk; + + UPDATE tmp.parked pk + JOIN ( SELECT itemFk, sum(visible) as visible + FROM vn.itemShelvingStock iss + JOIN vn.warehouse w ON w.id = iss.warehouseFk + WHERE w.aliasFk = vWarehouseAliasFk + GROUP BY iss.itemFk ) iss ON iss.itemFk = pk.itemFk + SET pk.quantity = iss.visible; + + DROP TEMPORARY TABLE IF EXISTS tmp.`grouping`; + CREATE TEMPORARY TABLE tmp.`grouping` + ENGINE MEMORY + SELECT itemFk, `grouping` + FROM ( + SELECT itemFk, + CASE groupingMode + WHEN 0 THEN 1 + WHEN 2 THEN packing + ELSE `grouping` + END AS `grouping` + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.warehouseInFk = vWarehouseFk + AND landed BETWEEN (SELECT inventoried FROM vn.config LIMIT 1) AND CURDATE() + AND b.isIgnored = FALSE + ORDER BY tr.landed DESC + ) sub + GROUP BY sub.itemFk ; + + DROP TEMPORARY TABLE IF EXISTS tmp.grouping2; + CREATE TEMPORARY TABLE tmp.grouping2 + ENGINE MEMORY + SELECT * FROM tmp.`grouping`; + + + SELECT s.id as saleFk, s.itemFk, + p.code COLLATE utf8_general_ci as placement , + sh.code COLLATE utf8_general_ci as shelving, + ish.created, + ish.visible, + 0 as `order`, + IF(sc.isPreviousPreparedByPacking, ish.packing, g.`grouping`) as `grouping` + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + JOIN vn.warehouse w ON w.id = sc.warehouseFk + JOIN tmp.`grouping` g ON g.itemFk = s.itemFk + WHERE tc.collectionFk = vCollectionFk + AND w.aliasFk = vWarehouseAliasFk + AND ish.visible > 0 + UNION ALL + SELECT s.id as saleFk, s.itemFk, + ip.code COLLATE utf8_general_ci as placement, + '' COLLATE latin1_general_ci as shelving, + modificationDate as created, + v.visible - p.quantity as visible, + 0 as `order`, + g.`grouping` + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + JOIN vn.itemPlacement ip ON ip.itemFk = s.itemFk AND ip.warehouseFk = vWarehouseFk + JOIN tmp.parked p ON p.itemFk = s.itemFk + JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vCalcFk + LEFT JOIN tmp.grouping2 g ON g.itemFk = s.itemFk + WHERE tc.collectionFk = vCollectionFk + AND v.visible - p.quantity > 0; + + DROP TEMPORARY TABLE + tmp.parked, + tmp.`grouping`, + tmp.grouping2; +END + + +$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/changes/10162-postValentineDay/00-collection_faults.sql b/db/changes/10162-postValentineDay/00-collection_faults.sql new file mode 100644 index 000000000..5faa42ca4 --- /dev/null +++ b/db/changes/10162-postValentineDay/00-collection_faults.sql @@ -0,0 +1,39 @@ +DROP procedure IF EXISTS `vn`.`collection_faults`; + +DELIMITER $$ + +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`collection_faults`( + vShelvingFk VARCHAR(10), + vQuantity INT, + vItemFk INT) +BEGIN + DECLARE vQuantityTotal INT DEFAULT 0; + DECLARE vshelve VARCHAR(2); + DECLARE vdeep INT(11); + DECLARE vpriority INT(11); + DECLARE vgrouping SMALLINT(5); + DECLARE vpacking INT(11); + DECLARE vpackagingFk VARCHAR(10); + DECLARE vlevel VARCHAR(45); + DECLARE vuserFk INT(10); + + + SELECT SUM(quantity),shelve,deep,priority,`grouping`,packing,packagingFk,`level`,userFk + INTO vQuantityTotal,vshelve,vdeep,vpriority,vgrouping,vpacking,vpackagingFk,vlevel,vuserFk + FROM vn.itemShelving + WHERE shelvingFk = vShelvingFk COLLATE utf8mb4_unicode_ci AND itemFk = vItemFk + GROUP BY itemFk; + + SELECT vQuantityTotal - vQuantity INTO vQuantityTotal; + + DELETE FROM vn.itemShelving WHERE shelvingFk = vShelvingFk COLLATE utf8mb4_unicode_ci AND itemFk = vItemFk; + + INSERT INTO vn.itemShelving (itemFk, shelvingFk,shelve,deep,quantity,visible,available,priority,`grouping`,packing,packagingFk,`level`,userFk ) + VALUES (vItemFk,vShelvingFk,vshelve,vdeep,vQuantityTotal,vQuantityTotal,vQuantityTotal,vpriority,vgrouping,vpacking,vpackagingFk,vlevel,vuserFk ); + + SELECT * FROM vn.itemShelving + WHERE shelvingFk = vShelvingFk COLLATE utf8mb4_unicode_ci AND itemFk = vItemFk; + +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/changes/10162-postValentineDay/00-collection_updateSale.sql b/db/changes/10162-postValentineDay/00-collection_updateSale.sql new file mode 100644 index 000000000..cce8f4ff5 --- /dev/null +++ b/db/changes/10162-postValentineDay/00-collection_updateSale.sql @@ -0,0 +1,42 @@ +DROP procedure IF EXISTS `vn`.`collection_updateSale`; + + +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`collection_updateSale`( + vSaleFk INT, + vOriginalQuantity INT, + vWorkerFk INT, + vStateFk INT, + vTicketFk INT) +BEGIN + + DECLARE vNumPrepared INT; + DECLARE vNumTotal INT; + + REPLACE INTO vn.saleTracking(saleFk,isChecked, originalQuantity, workerFk, actionFk,stateFk) + VALUES(vSaleFk,1,vOriginalQuantity,vWorkerFk,vStateFk,vStateFk); + + UPDATE vn.sale SET isPicked = 1 + WHERE id = vSaleFk; + + SELECT COUNT(s.id) INTO vNumPrepared + FROM vn.sale s + WHERE s.ticketFk = vTicketFk AND s.isPicked = 1; + + SELECT COUNT(s.id) INTO vNumTotal + FROM vn.sale s + WHERE s.ticketFk = vTicketFk; + + IF vNumPrepared = vNumTotal THEN + + INSERT INTO vncontrol.inter + SET state_id = vStateFk, Id_Ticket = vTicketFk, Id_Trabajador = vWorkerFk; + + CALL vn.collection_update(vTicketFk); + + END IF; + + +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/changes/10162-postValentineDay/00-coolerPathDetail.sql b/db/changes/10162-postValentineDay/00-coolerPathDetail.sql new file mode 100644 index 000000000..7d3006544 --- /dev/null +++ b/db/changes/10162-postValentineDay/00-coolerPathDetail.sql @@ -0,0 +1,13 @@ +/*DROP view IF EXISTS `vn`.`coolerPathDetail`; + +CREATE + ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `vn`.`coolerPathDetail` AS + SELECT + `c`.`cooler_path_detail_id` AS `id`, + `c`.`cooler_path_id` AS `coolerPathFk`, + `c`.`pasillo` AS `hallway` + FROM + `vn2008`.`cooler_path_detail` `c`*/ \ No newline at end of file diff --git a/db/changes/10162-postValentineDay/00-sale_updateOriginalQuantity.sql b/db/changes/10162-postValentineDay/00-sale_updateOriginalQuantity.sql new file mode 100644 index 000000000..debdd3ac2 --- /dev/null +++ b/db/changes/10162-postValentineDay/00-sale_updateOriginalQuantity.sql @@ -0,0 +1,15 @@ +DROP procedure IF EXISTS `vn`.`sale_updateOriginalQuantity`; + +DELIMITER $$ + +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_updateOriginalQuantity`(vSale INT, vQuantity INT) +proc: BEGIN + +UPDATE vn.sale SET originalQuantity = vQuantity +WHERE id = vSale; + +SELECT * FROM vn.sale WHERE id = vSale; + +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/changes/10162-postValentineDay/00-sector_getWarehouse.sql b/db/changes/10162-postValentineDay/00-sector_getWarehouse.sql new file mode 100644 index 000000000..90611b559 --- /dev/null +++ b/db/changes/10162-postValentineDay/00-sector_getWarehouse.sql @@ -0,0 +1,14 @@ +DROP procedure IF EXISTS `vn`.`sector_getWarehouse`; + +DELIMITER $$ + +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sector_getWarehouse`(vSectorFk INT) +BEGIN + + SELECT s.warehouseFk + FROM vn.sector s + WHERE s.id = vSectorFk; + +END$$ + +DELIMITER ; \ No newline at end of file