diff --git a/db/routines/util/procedures/connection_kill.sql b/db/routines/util/procedures/connection_kill.sql new file mode 100644 index 000000000..b38509d1b --- /dev/null +++ b/db/routines/util/procedures/connection_kill.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`connection_kill`( + vConnectionId BIGINT +) +BEGIN +/** + * Kill a connection + * + * @param vConnectionId + */ + KILL vConnectionId; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index 1d656a0ed..196764c42 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -30,12 +30,9 @@ BEGIN -- Si hay colecciones sin terminar, sale del proceso CALL collection_get(vUserFk); - SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0, - pc.collection_assign_lockname - INTO vHasTooMuchCollections, - vLockName - FROM tCollection - JOIN productionConfig pc; + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 INTO vHasTooMuchCollections + FROM productionConfig pc + LEFT JOIN tCollection ON TRUE; DROP TEMPORARY TABLE tCollection; diff --git a/db/routines/vn/procedures/sale_replaceItem.sql b/db/routines/vn/procedures/sale_replaceItem.sql index 056397274..a4aefc088 100644 --- a/db/routines/vn/procedures/sale_replaceItem.sql +++ b/db/routines/vn/procedures/sale_replaceItem.sql @@ -79,6 +79,10 @@ BEGIN ORDER BY (vQuantity % `grouping`) ASC LIMIT 1; + IF vNewPrice IS NULL THEN + CALL util.throw('price retrieval failed'); + END IF; + IF vNewPrice > vOldPrice THEN SET vFinalPrice = vOldPrice; SET vOption = 'substitution'; @@ -90,7 +94,8 @@ BEGIN START TRANSACTION; UPDATE sale - SET quantity = quantity - vQuantity + SET originalQuantity = quantity - vQuantity, + quantity = quantity - vQuantity WHERE id = vSaleFk; INSERT INTO vn.sale(ticketFk, @@ -100,7 +105,8 @@ BEGIN price) SELECT vTicketFk, vNewItemFk, - CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ', i.name), + CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, + CONCAT('+ ', i.name), vFinalPrice FROM vn.item i WHERE id = vNewItemFk; diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 8852a3010..d1ca7b5e2 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -8,38 +8,14 @@ BEGIN * @param vDateToAdvance Fecha a cuando se quiere adelantar. * @param vWarehouseFk Almacén */ - DECLARE vDateInventory DATE; - SELECT inventoried INTO vDateInventory FROM config; - - CREATE OR REPLACE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE landed >= vDateInventory - AND landed <= vDateToAdvance - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; + CALL item_getStock(vWarehouseFk, vDateToAdvance, NULL); + CALL item_getMinacum( + vWarehouseFk, + vDateToAdvance, + DATEDIFF(DATE_SUB(vDateFuture, INTERVAL 1 DAY), vDateToAdvance), + NULL + ); CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) @@ -87,7 +63,7 @@ BEGIN count(s.id) futureLines, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, + SUM(s.quantity <= (IFNULL(il.stock,0) + IFNULL(im.amount, 0))) hasStock, z.id futureZoneFk, z.name futureZoneName, st.classColor, @@ -107,7 +83,9 @@ BEGIN JOIN agencyMode am ON t.agencyModeFk = am.id JOIN zone z ON t.zoneFk = z.id LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id + LEFT JOIN tmp.itemMinacum im ON im.itemFk = i.id + AND im.warehouseFk = vWarehouseFk + LEFT JOIN tmp.itemList il ON il.itemFk = i.id WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) AND t.warehouseFk = vWarehouseFk GROUP BY t.id @@ -146,6 +124,8 @@ BEGIN ) dest ON dest.addressFk = origin.addressFk WHERE origin.hasStock; - DROP TEMPORARY TABLE tmp.stock; + DROP TEMPORARY TABLE IF EXISTS + tmp.itemList, + tmp.itemMinacum; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 91e0979cd..47d748ddf 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -63,7 +63,7 @@ BEGIN INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) (SELECT vCurTicketFk, p.id, COUNT(*) FROM expedition e - JOIN packaging p ON p.itemFk = e.freightItemFk + JOIN packaging p ON p.id = e.packagingFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage GROUP BY p.itemFk); diff --git a/db/routines/vn/procedures/ticket_getMovable.sql b/db/routines/vn/procedures/ticket_getMovable.sql index eee165538..512151bd4 100644 --- a/db/routines/vn/procedures/ticket_getMovable.sql +++ b/db/routines/vn/procedures/ticket_getMovable.sql @@ -21,7 +21,7 @@ BEGIN WHERE t.id = vTicketFk; -- Añadimos un dia más para calcular el stock hasta vNewShipped inclusive - CALL item_getStock(vWarehouseFk, DATE_ADD(vNewShipped, INTERVAL 1 DAY), NULL); + CALL item_getStock(vWarehouseFk, vNewShipped, NULL); CALL item_getMinacum( vWarehouseFk, vNewShipped, @@ -38,7 +38,7 @@ BEGIN s.discount, i.image, i.subName, - il.stock + IFNULL(im.amount, 0) AS movable + IFNULL(il.stock,0) + IFNULL(im.amount, 0) AS movable FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk @@ -48,8 +48,8 @@ BEGIN WHERE t.id = vTicketFk; DROP TEMPORARY TABLE IF EXISTS - tmp.itemList, - tmp.itemMinacum; + tmp.itemList, + tmp.itemMinacum; END$$ DELIMITER ; diff --git a/db/versions/11016-pinkAralia/00-firstScript.sql b/db/versions/11016-pinkAralia/00-firstScript.sql new file mode 100644 index 000000000..de090013d --- /dev/null +++ b/db/versions/11016-pinkAralia/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig ADD collectionNewLockname varchar(100) + DEFAULT 'collection_new' NOT NULL COMMENT 'Lockname value for proc vn.collection_new'; +ALTER TABLE vn.productionConfig ADD collectionAssignLockname varchar(100) + DEFAULT 'collection_assign' NULL COMMENT 'Lockname value for proc vn.collection_new'; diff --git a/db/versions/11021-bronzeErica/00-firstScript.sql b/db/versions/11021-bronzeErica/00-firstScript.sql new file mode 100644 index 000000000..6f6b68d49 --- /dev/null +++ b/db/versions/11021-bronzeErica/00-firstScript.sql @@ -0,0 +1,13 @@ + + ALTER TABLE vn.productionConfig + DROP COLUMN IF EXISTS collectionNewLockname, + DROP COLUMN IF EXISTS collectionAssignLockname; + + DELIMITER $$ + CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`connection_kill`() + BEGIN + + END$$ + DELIMITER ; + + GRANT EXECUTE ON PROCEDURE util.connection_kill TO 'developer'; \ No newline at end of file diff --git a/modules/route/back/methods/route/getExpeditionSummary.js b/modules/route/back/methods/route/getExpeditionSummary.js index ee89401a8..2bd2ca43a 100644 --- a/modules/route/back/methods/route/getExpeditionSummary.js +++ b/modules/route/back/methods/route/getExpeditionSummary.js @@ -49,8 +49,7 @@ module.exports = Self => { JOIN vn.agencyMode am ON am.id = r.agencyModeFk JOIN vn.agency ag ON ag.id = am.agencyFk LEFT JOIN vn.userConfig uc ON uc.userFk = account.myUser_getId() - WHERE (r.created = util.VN_CURDATE() OR r.created = util.yesterday()) - AND t.routeFk = ? + WHERE t.routeFk = ? GROUP BY t.addressFk, e.itemPackingTypeFk ) sub GROUP BY addressFk diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 0786b72c8..8bea731b7 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -150,7 +150,7 @@ module.exports = Self => { const salesNewTicket = salesMovable.filter(sale => (sale.movable ? sale.movable : 0) >= sale.quantity); const salesNewTicketLength = salesNewTicket.length; - if (salesNewTicketLength && sales.length != salesNewTicketLength) { + if (salesNewTicketLength && (args.newTicket || sales.length != salesNewTicketLength)) { const newTicket = await models.Ticket.transferSales( ctx, args.id, diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 7dc85bd3d..7db03e268 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -118,7 +118,7 @@ module.exports = Self => { const [salesMovable] = await Self.rawSql(query, params, myOptions); const itemMovable = new Map(); - for (sale of salesMovable) { + for (let sale of salesMovable) { const saleMovable = sale.movable ? sale.movable : 0; itemMovable.set(sale.id, saleMovable); } @@ -129,7 +129,7 @@ module.exports = Self => { const [difComponents] = await Self.rawSql(query, params, myOptions); const map = new Map(); - for (difComponent of difComponents) + for (let difComponent of difComponents) map.set(difComponent.saleFk, difComponent); for (sale of salesObj.items) { diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index d01f0c1bb..e5c06b6dd 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const UserError = require('vn-loopback/util/user-error'); const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('sale priceDifference()', () => { @@ -83,12 +82,10 @@ describe('sale priceDifference()', () => { warehouseId: 1 }; - const result = await models.Ticket.priceDifference(ctx, options); - const firstItem = result.items[0]; - const secondtItem = result.items[1]; + const {items} = await models.Ticket.priceDifference(ctx, options); - expect(firstItem.movable).toEqual(380); - expect(secondtItem.movable).toEqual(1790); + expect(items[0].movable).toEqual(410); + expect(items[1].movable).toEqual(1810); await tx.rollback(); } catch (e) {