From 460723bd7aaf4c6503c90126b01187adefeb6f5d Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 10:08:04 +0200 Subject: [PATCH 01/32] refactor: refs #6453 order_confirmWithUser --- .../procedures/order_confirmWithUser.sql | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 9c932aaa1..d85eb7f71 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -28,11 +28,8 @@ BEGIN DECLARE vClientId INT; DECLARE vCompanyId INT; DECLARE vAgencyModeId INT; - DECLARE TICKET_FREE INT DEFAULT 2; DECLARE vCalc INT; DECLARE vIsLogifloraItem BOOL; - DECLARE vOldQuantity INT; - DECLARE vNewQuantity INT; DECLARE vIsTaxDataChecked BOOL; DECLARE cDates CURSOR FOR @@ -40,14 +37,15 @@ BEGIN FROM `order` o JOIN order_row r ON r.order_id = o.id LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id - WHERE o.id = vSelf AND r.amount != 0 + WHERE o.id = vSelf + AND r.amount GROUP BY r.warehouse_id; DECLARE cRows CURSOR FOR SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo FROM order_row r JOIN vn.item i ON i.id = r.item_id - WHERE r.amount != 0 + WHERE r.amount AND r.warehouse_id = vWarehouse AND r.order_id = vSelf ORDER BY r.rate DESC; @@ -62,10 +60,20 @@ BEGIN END; -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, - o.company_id, o.agency_id, c.isTaxDataChecked - INTO vDelivery, vAddress, vNotes, vClientId, - vCompanyId, vAgencyModeId, vIsTaxDataChecked + SELECT o.date_send, + o.address_id, + o.note, + a.clientFk, + o.company_id, + o.agency_id, + c.isTaxDataChecked + INTO vDelivery, + vAddress, + vNotes, + vClientId, + vCompanyId, + vAgencyModeId, + vIsTaxDataChecked FROM hedera.`order` o JOIN vn.address a ON a.id = o.address_id JOIN vn.client c ON c.id = a.clientFk @@ -73,11 +81,11 @@ BEGIN -- Verifica si el cliente tiene los datos comprobados IF NOT vIsTaxDataChecked THEN - CALL util.throw ('clientNotVerified'); + CALL util.throw('clientNotVerified'); END IF; -- Carga las fechas de salida de cada almacen - CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE); + CALL vn.zone_getShipped(vDelivery, vAddress, vAgencyModeId, FALSE); -- Trabajador que realiza la accion IF vUserId IS NULL THEN @@ -94,7 +102,7 @@ BEGIN FROM order_row WHERE order_id = vSelf AND amount > 0; IF NOT vOk THEN - CALL util.throw ('ORDER_EMPTY'); + CALL util.throw('ORDER_EMPTY'); END IF; -- Crea los tickets del pedido @@ -112,23 +120,22 @@ BEGIN END IF; -- Busca un ticket existente que coincida con los parametros - WITH tPrevia AS - (SELECT DISTINCT s.ticketFk + WITH tPrevia AS ( + SELECT DISTINCT s.ticketFk FROM vn.sale s JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ) + ) SELECT t.id INTO vTicket FROM vn.ticket t JOIN vn.alertLevel al ON al.code = 'FREE' LEFT JOIN tPrevia tp ON tp.ticketFk = t.id LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id - JOIN hedera.`order` o - ON o.address_id = t.addressFk - AND vWarehouse = t.warehouseFk - AND o.date_send = t.landed - AND DATE(t.shipped) = vShipment + JOIN hedera.`order` o ON o.address_id = t.addressFk + AND vWarehouse = t.warehouseFk + AND o.date_send = t.landed + AND DATE(t.shipped) = vShipment WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL @@ -136,11 +143,8 @@ BEGIN LIMIT 1; -- Crea el ticket en el caso de no existir uno adecuado - IF vTicket IS NULL - THEN - + IF vTicket IS NULL THEN SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); - CALL vn.ticket_add( vClientId, vShipment, @@ -158,7 +162,7 @@ BEGIN INSERT INTO vn.ticketTracking SET ticketFk = vTicket, userFk = vUserId, - stateFk = TICKET_FREE; + stateFk = (SELECT id FROM vn.state WHERE code = 'FREE'); END IF; INSERT IGNORE INTO vn.orderTicket @@ -166,21 +170,17 @@ BEGIN ticketFk = vTicket; -- Añade las notas - - IF vNotes IS NOT NULL AND vNotes != '' - THEN + IF vNotes IS NOT NULL AND vNotes <> '' THEN INSERT INTO vn.ticketObservation SET ticketFk = vTicket, - observationTypeFk = 4 /* salesperson */ , + observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), `description` = vNotes ON DUPLICATE KEY UPDATE `description` = CONCAT(VALUES(`description`),'. ', `description`); END IF; -- Añade los movimientos y sus componentes - OPEN cRows; - lRows: LOOP SET vDone = FALSE; FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; @@ -191,7 +191,7 @@ BEGIN SET vSale = NULL; - SELECT s.id, s.quantity INTO vSale, vOldQuantity + SELECT s.id INTO vSale FROM vn.sale s WHERE ticketFk = vTicket AND price = vPrice @@ -204,10 +204,6 @@ BEGIN SET quantity = quantity + vAmount, originalQuantity = quantity WHERE id = vSale; - - SELECT s.quantity INTO vNewQuantity - FROM vn.sale s - WHERE id = vSale; ELSE -- Obtiene el coste SELECT SUM(rc.`price`) valueSum INTO vPriceFixed @@ -236,7 +232,8 @@ BEGIN GROUP BY vSale, rc.componentFk; END IF; - UPDATE order_row SET Id_Movimiento = vSale + UPDATE order_row + SET Id_Movimiento = vSale WHERE id = vRowId; -- Inserta en putOrder si la compra es de Floramondo @@ -245,13 +242,13 @@ BEGIN SET @available := 0; - SELECT GREATEST(0,available) INTO @available + SELECT GREATEST(0, available) INTO @available FROM cache.availableNoRaids WHERE calc_id = vCalc AND item_id = vItem; UPDATE cache.availableNoRaids - SET available = GREATEST(0,available - vAmount) + SET available = GREATEST(0, available - vAmount) WHERE item_id = vItem AND calc_id = vCalc; @@ -283,13 +280,13 @@ BEGIN LIMIT 1; END IF; END LOOP; - CLOSE cRows; END LOOP; - CLOSE cDates; - UPDATE `order` SET confirmed = TRUE, confirm_date = util.VN_NOW() + UPDATE `order` + SET confirmed = TRUE, + confirm_date = util.VN_NOW() WHERE id = vSelf; COMMIT; From b06832735260c32f1388512e15c00a02a7050fe5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 10:49:39 +0200 Subject: [PATCH 02/32] refactor: refs #6453 order_confirmWithUser --- db/routines/hedera/procedures/order_confirmWithUser.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index d85eb7f71..3801e935b 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -97,18 +97,17 @@ BEGIN CALL order_checkEditable(vSelf); -- Check order is not empty - SELECT COUNT(*) > 0 INTO vOk - FROM order_row WHERE order_id = vSelf AND amount > 0; + FROM order_row + WHERE order_id = vSelf + AND amount > 0; IF NOT vOk THEN CALL util.throw('ORDER_EMPTY'); END IF; -- Crea los tickets del pedido - OPEN cDates; - lDates: LOOP SET vTicket = NULL; From b75bdc07c29f78b248357f3c445277bdfd0009d0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 08:10:34 +0200 Subject: [PATCH 03/32] refactor: refs #6453 order_confirmWithUser --- .../procedures/order_confirmWithUser.sql | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 3801e935b..76ff4e723 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -1,36 +1,40 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirmWithUser`(vSelf INT, vUserId INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirmWithUser`( + vSelf INT, + vUserFk INT +) BEGIN /** - * Confirms an order, creating each of its tickets on the corresponding - * date, store and user. + * Confirms an order, creating each of its tickets on + * the corresponding date, store and user. * * @param vSelf The order identifier * @param vUser The user identifier */ - DECLARE vOk BOOL; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vWarehouse INT; + DECLARE vIsOk BOOL; + DECLARE vDone BOOL; + DECLARE vWarehouseFk INT; DECLARE vShipment DATE; - DECLARE vTicket INT; + DECLARE vTicketFk INT; DECLARE vNotes VARCHAR(255); DECLARE vItem INT; DECLARE vConcept VARCHAR(30); DECLARE vAmount INT; DECLARE vPrice DECIMAL(10,2); - DECLARE vSale INT; + DECLARE vSaleFk INT; DECLARE vRate INT; - DECLARE vRowId INT; + DECLARE vRowFk INT; DECLARE vPriceFixed DECIMAL(10,2); DECLARE vDelivery DATE; - DECLARE vAddress INT; + DECLARE vAddressFk INT; DECLARE vIsConfirmed BOOL; - DECLARE vClientId INT; - DECLARE vCompanyId INT; - DECLARE vAgencyModeId INT; - DECLARE vCalc INT; + DECLARE vClientFk INT; + DECLARE vCompanyFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vCalcFk INT; DECLARE vIsLogifloraItem BOOL; DECLARE vIsTaxDataChecked BOOL; + DECLARE vAvailable INT; DECLARE cDates CURSOR FOR SELECT zgs.shipped, r.warehouse_id @@ -46,12 +50,11 @@ BEGIN FROM order_row r JOIN vn.item i ON i.id = r.item_id WHERE r.amount - AND r.warehouse_id = vWarehouse + AND r.warehouse_id = vWarehouseFk AND r.order_id = vSelf ORDER BY r.rate DESC; - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -68,13 +71,13 @@ BEGIN o.agency_id, c.isTaxDataChecked INTO vDelivery, - vAddress, + vAddressFk, vNotes, - vClientId, - vCompanyId, - vAgencyModeId, + vClientFk, + vCompanyFk, + vAgencyModeFk, vIsTaxDataChecked - FROM hedera.`order` o + FROM `order` o JOIN vn.address a ON a.id = o.address_id JOIN vn.client c ON c.id = a.clientFk WHERE o.id = vSelf; @@ -85,11 +88,11 @@ BEGIN END IF; -- Carga las fechas de salida de cada almacen - CALL vn.zone_getShipped(vDelivery, vAddress, vAgencyModeId, FALSE); + CALL vn.zone_getShipped(vDelivery, vAddressFk, vAgencyModeFk, FALSE); -- Trabajador que realiza la accion - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; + IF vUserFk IS NULL THEN + SELECT employeeFk INTO vUserFk FROM orderConfig; END IF; START TRANSACTION; @@ -97,12 +100,12 @@ BEGIN CALL order_checkEditable(vSelf); -- Check order is not empty - SELECT COUNT(*) > 0 INTO vOk + SELECT COUNT(*) > 0 INTO vIsOk FROM order_row WHERE order_id = vSelf AND amount > 0; - IF NOT vOk THEN + IF NOT vIsOk THEN CALL util.throw('ORDER_EMPTY'); END IF; @@ -110,9 +113,9 @@ BEGIN OPEN cDates; lDates: LOOP - SET vTicket = NULL; + SET vTicketFk = NULL; SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouse; + FETCH cDates INTO vShipment, vWarehouseFk; IF vDone THEN LEAVE lDates; @@ -126,13 +129,13 @@ BEGIN JOIN vn.ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) ) - SELECT t.id INTO vTicket + SELECT t.id INTO vTicketFk FROM vn.ticket t JOIN vn.alertLevel al ON al.code = 'FREE' LEFT JOIN tPrevia tp ON tp.ticketFk = t.id LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id JOIN hedera.`order` o ON o.address_id = t.addressFk - AND vWarehouse = t.warehouseFk + AND vWarehouseFk = t.warehouseFk AND o.date_send = t.landed AND DATE(t.shipped) = vShipment WHERE o.id = vSelf @@ -142,36 +145,36 @@ BEGIN LIMIT 1; -- Crea el ticket en el caso de no existir uno adecuado - IF vTicket IS NULL THEN + IF vTicketFk IS NULL THEN SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); CALL vn.ticket_add( - vClientId, + vClientFk, vShipment, - vWarehouse, - vCompanyId, - vAddress, - vAgencyModeId, + vWarehouseFk, + vCompanyFk, + vAddressFk, + vAgencyModeFk, NULL, vDelivery, - vUserId, + vUserFk, TRUE, - vTicket + vTicketFk ); ELSE INSERT INTO vn.ticketTracking - SET ticketFk = vTicket, - userFk = vUserId, + SET ticketFk = vTicketFk, + userFk = vUserFk, stateFk = (SELECT id FROM vn.state WHERE code = 'FREE'); END IF; INSERT IGNORE INTO vn.orderTicket SET orderFk = vSelf, - ticketFk = vTicket; + ticketFk = vTicketFk; -- Añade las notas IF vNotes IS NOT NULL AND vNotes <> '' THEN INSERT INTO vn.ticketObservation SET - ticketFk = vTicket, + ticketFk = vTicketFk, observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), `description` = vNotes ON DUPLICATE KEY UPDATE @@ -182,74 +185,71 @@ BEGIN OPEN cRows; lRows: LOOP SET vDone = FALSE; - FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; + FETCH cRows INTO vRowFk, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; IF vDone THEN LEAVE lRows; END IF; - SET vSale = NULL; + SET vSaleFk = NULL; - SELECT s.id INTO vSale + SELECT s.id INTO vSaleFk FROM vn.sale s - WHERE ticketFk = vTicket + WHERE ticketFk = vTicketFk AND price = vPrice AND itemFk = vItem AND discount = 0 LIMIT 1; - IF vSale THEN + IF vSaleFk THEN UPDATE vn.sale SET quantity = quantity + vAmount, originalQuantity = quantity - WHERE id = vSale; + WHERE id = vSaleFk; ELSE -- Obtiene el coste SELECT SUM(rc.`price`) valueSum INTO vPriceFixed FROM orderRowComponent rc JOIN vn.component c ON c.id = rc.componentFk JOIN vn.componentType ct ON ct.id = c.typeFk AND ct.isBase - WHERE rc.rowFk = vRowId; + WHERE rc.rowFk = vRowFk; INSERT INTO vn.sale SET itemFk = vItem, - ticketFk = vTicket, + ticketFk = vTicketFk, concept = vConcept, quantity = vAmount, price = vPrice, priceFixed = vPriceFixed, isPriceFixed = TRUE; - SET vSale = LAST_INSERT_ID(); + SET vSaleFk = LAST_INSERT_ID(); - INSERT INTO vn.saleComponent - (saleFk, componentFk, `value`) - SELECT vSale, rc.componentFk, rc.price + INSERT INTO vn.saleComponent (saleFk, componentFk, `value`) + SELECT vSaleFk, rc.componentFk, rc.price FROM orderRowComponent rc JOIN vn.component c ON c.id = rc.componentFk - WHERE rc.rowFk = vRowId - GROUP BY vSale, rc.componentFk; + WHERE rc.rowFk = vRowFk + GROUP BY vSaleFk, rc.componentFk; END IF; UPDATE order_row - SET Id_Movimiento = vSale - WHERE id = vRowId; + SET Id_Movimiento = vSaleFk + WHERE id = vRowFk; -- Inserta en putOrder si la compra es de Floramondo IF vIsLogifloraItem THEN - CALL cache.availableNoRaids_refresh(vCalc,FALSE,vWarehouse,vShipment); + CALL cache.availableNoRaids_refresh(vCalcFk, FALSE,vWarehouseFk, vShipment); - SET @available := 0; - - SELECT GREATEST(0, available) INTO @available + SELECT GREATEST(0, available) INTO vAvailable FROM cache.availableNoRaids - WHERE calc_id = vCalc + WHERE calc_id = vCalcFk AND item_id = vItem; UPDATE cache.availableNoRaids SET available = GREATEST(0, available - vAmount) WHERE item_id = vItem - AND calc_id = vCalc; + AND calc_id = vCalcFk; INSERT INTO edi.putOrder ( deliveryInformationID, @@ -262,20 +262,20 @@ BEGIN ) SELECT di.ID, i.supplyResponseFk, - CEIL((vAmount - @available)/ sr.NumberOfItemsPerCask), + CEIL((vAmount - vAvailable)/ sr.NumberOfItemsPerCask), o.address_id , - vClientId, + vClientFk, IFNULL(ca.fhAdminNumber, fhc.defaultAdminNumber), - vSale + vSaleFk FROM edi.deliveryInformation di JOIN vn.item i ON i.supplyResponseFk = di.supplyResponseID JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientId + LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientFk JOIN edi.floraHollandConfig fhc - JOIN hedera.`order` o ON o.id = vSelf + JOIN `order` o ON o.id = vSelf WHERE i.id = vItem AND di.LatestOrderDateTime > util.VN_NOW() - AND vAmount > @available + AND vAmount > vAvailable LIMIT 1; END IF; END LOOP; From a8d03450732bd24292696ca17ba73c5efe703586 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 08:18:33 +0200 Subject: [PATCH 04/32] refactor: refs #6453 order_confirmWithUser --- .../procedures/order_confirmWithUser.sql | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 76ff4e723..61a7421cf 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -17,7 +17,7 @@ BEGIN DECLARE vShipment DATE; DECLARE vTicketFk INT; DECLARE vNotes VARCHAR(255); - DECLARE vItem INT; + DECLARE vItemFk INT; DECLARE vConcept VARCHAR(30); DECLARE vAmount INT; DECLARE vPrice DECIMAL(10,2); @@ -46,12 +46,12 @@ BEGIN GROUP BY r.warehouse_id; DECLARE cRows CURSOR FOR - SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo - FROM order_row r - JOIN vn.item i ON i.id = r.item_id + SELECT r.id, r.itemFk, i.name, r.amount, r.price, r.rate, i.isFloramondo + FROM orderRow r + JOIN vn.item i ON i.id = r.itemFk WHERE r.amount - AND r.warehouse_id = vWarehouseFk - AND r.order_id = vSelf + AND r.warehouseFk = vWarehouseFk + AND r.orderFk = vSelf ORDER BY r.rate DESC; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -185,7 +185,7 @@ BEGIN OPEN cRows; lRows: LOOP SET vDone = FALSE; - FETCH cRows INTO vRowFk, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; + FETCH cRows INTO vRowFk, vItemFk, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; IF vDone THEN LEAVE lRows; @@ -197,7 +197,7 @@ BEGIN FROM vn.sale s WHERE ticketFk = vTicketFk AND price = vPrice - AND itemFk = vItem + AND itemFk = vItemFk AND discount = 0 LIMIT 1; @@ -215,7 +215,7 @@ BEGIN WHERE rc.rowFk = vRowFk; INSERT INTO vn.sale - SET itemFk = vItem, + SET itemFk = vItemFk, ticketFk = vTicketFk, concept = vConcept, quantity = vAmount, @@ -244,11 +244,11 @@ BEGIN SELECT GREATEST(0, available) INTO vAvailable FROM cache.availableNoRaids WHERE calc_id = vCalcFk - AND item_id = vItem; + AND item_id = vItemFk; UPDATE cache.availableNoRaids SET available = GREATEST(0, available - vAmount) - WHERE item_id = vItem + WHERE item_id = vItemFk AND calc_id = vCalcFk; INSERT INTO edi.putOrder ( @@ -273,7 +273,7 @@ BEGIN LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientFk JOIN edi.floraHollandConfig fhc JOIN `order` o ON o.id = vSelf - WHERE i.id = vItem + WHERE i.id = vItemFk AND di.LatestOrderDateTime > util.VN_NOW() AND vAmount > vAvailable LIMIT 1; From 0e760ba5057b97b55e97c9d1c3bd6a5481eed5dd Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 08:23:43 +0200 Subject: [PATCH 05/32] refactor: refs #6453 order_confirmWithUser --- .../hedera/procedures/order_confirmWithUser.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 61a7421cf..b5962ec88 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -37,13 +37,13 @@ BEGIN DECLARE vAvailable INT; DECLARE cDates CURSOR FOR - SELECT zgs.shipped, r.warehouse_id + SELECT zgs.shipped, r.warehouseFk FROM `order` o - JOIN order_row r ON r.order_id = o.id - LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id + JOIN orderRow r ON r.orderFk = o.id + LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouseFk WHERE o.id = vSelf AND r.amount - GROUP BY r.warehouse_id; + GROUP BY r.warehouseFk; DECLARE cRows CURSOR FOR SELECT r.id, r.itemFk, i.name, r.amount, r.price, r.rate, i.isFloramondo @@ -101,8 +101,8 @@ BEGIN -- Check order is not empty SELECT COUNT(*) > 0 INTO vIsOk - FROM order_row - WHERE order_id = vSelf + FROM orderRow + WHERE orderFk = vSelf AND amount > 0; IF NOT vIsOk THEN @@ -233,8 +233,8 @@ BEGIN GROUP BY vSaleFk, rc.componentFk; END IF; - UPDATE order_row - SET Id_Movimiento = vSaleFk + UPDATE orderRow + SET saleFk = vSaleFk WHERE id = vRowFk; -- Inserta en putOrder si la compra es de Floramondo From a1d3d2f2f8ea12ef313e705cf372bf4ceae82674 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 10:30:24 +0200 Subject: [PATCH 06/32] refactor: refs #6453 Major changes --- .../procedures/order_confirmWithUser.sql | 214 ++++++++++++------ 1 file changed, 141 insertions(+), 73 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index b5962ec88..bf4408fbc 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -5,8 +5,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirmWi ) BEGIN /** - * Confirms an order, creating each of its tickets on - * the corresponding date, store and user. + * Confirms an order, creating each of its tickets + * on the corresponding date, store and user. * * @param vSelf The order identifier * @param vUser The user identifier @@ -25,7 +25,7 @@ BEGIN DECLARE vRate INT; DECLARE vRowFk INT; DECLARE vPriceFixed DECIMAL(10,2); - DECLARE vDelivery DATE; + DECLARE vLanded DATE; DECLARE vAddressFk INT; DECLARE vIsConfirmed BOOL; DECLARE vClientFk INT; @@ -35,8 +35,9 @@ BEGIN DECLARE vIsLogifloraItem BOOL; DECLARE vIsTaxDataChecked BOOL; DECLARE vAvailable INT; + DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE cDates CURSOR FOR + DECLARE vDates CURSOR FOR SELECT zgs.shipped, r.warehouseFk FROM `order` o JOIN orderRow r ON r.orderFk = o.id @@ -45,8 +46,25 @@ BEGIN AND r.amount GROUP BY r.warehouseFk; - DECLARE cRows CURSOR FOR - SELECT r.id, r.itemFk, i.name, r.amount, r.price, r.rate, i.isFloramondo + DECLARE vDistinctItemPackingType CURSOR FOR + SELECT DISTINCT i.itemPackingTypeFk + FROM `order` o + JOIN orderRow r ON r.orderFk = o.id + JOIN vn.item i ON i.id = r.itemFk + WHERE o.id = vSelf + AND r.warehouseFk = vWarehouseFk + AND r.amount + ORDER BY i.itemPackingTypeFk DESC; + + DECLARE vRows CURSOR FOR + SELECT r.id, + r.itemFk, + i.name, + r.amount, + r.price, + r.rate, + i.itemPackingTypeFk, + i.isFloramondo FROM orderRow r JOIN vn.item i ON i.id = r.itemFk WHERE r.amount @@ -70,7 +88,7 @@ BEGIN o.company_id, o.agency_id, c.isTaxDataChecked - INTO vDelivery, + INTO vLanded, vAddressFk, vNotes, vClientFk, @@ -88,7 +106,7 @@ BEGIN END IF; -- Carga las fechas de salida de cada almacen - CALL vn.zone_getShipped(vDelivery, vAddressFk, vAgencyModeFk, FALSE); + CALL vn.zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, FALSE); -- Trabajador que realiza la accion IF vUserFk IS NULL THEN @@ -110,88 +128,135 @@ BEGIN END IF; -- Crea los tickets del pedido - OPEN cDates; - lDates: - LOOP + OPEN vDates; + lDates: LOOP SET vTicketFk = NULL; SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouseFk; + FETCH vDates INTO vShipment, vWarehouseFk; IF vDone THEN LEAVE lDates; END IF; + CREATE OR REPLACE TEMPORARY TABLE tTicketByItemPackingType( + itemPackingTypeFk VARCHAR(1), + ticketFk INT, + PRIMARY KEY(itemPackingTypeFk, ticketFk) + ) ENGINE = MEMORY; + -- Busca un ticket existente que coincida con los parametros - WITH tPrevia AS ( - SELECT DISTINCT s.ticketFk - FROM vn.sale s - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ) - SELECT t.id INTO vTicketFk - FROM vn.ticket t - JOIN vn.alertLevel al ON al.code = 'FREE' - LEFT JOIN tPrevia tp ON tp.ticketFk = t.id - LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id - JOIN hedera.`order` o ON o.address_id = t.addressFk - AND vWarehouseFk = t.warehouseFk - AND o.date_send = t.landed - AND DATE(t.shipped) = vShipment - WHERE o.id = vSelf - AND t.refFk IS NULL - AND tp.ticketFk IS NULL - AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) - LIMIT 1; + OPEN vDistinctItemPackingType; + lDistinctItemPackingType: LOOP + SET vItemPackingTypeFk = NULL; + SET vDone = FALSE; + FETCH vDistinctItemPackingType INTO vItemPackingTypeFk; - -- Crea el ticket en el caso de no existir uno adecuado - IF vTicketFk IS NULL THEN - SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); - CALL vn.ticket_add( - vClientFk, - vShipment, - vWarehouseFk, - vCompanyFk, - vAddressFk, - vAgencyModeFk, - NULL, - vDelivery, - vUserFk, - TRUE, - vTicketFk - ); - ELSE - INSERT INTO vn.ticketTracking - SET ticketFk = vTicketFk, - userFk = vUserFk, - stateFk = (SELECT id FROM vn.state WHERE code = 'FREE'); - END IF; + IF vDone THEN + LEAVE lDistinctItemPackingType; + END IF; - INSERT IGNORE INTO vn.orderTicket - SET orderFk = vSelf, - ticketFk = vTicketFk; + WITH tPrevia AS ( + SELECT DISTINCT s.ticketFk + FROM vn.sale s + JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) + ), + tTicketSameItemPackingType AS ( + SELECT t.id, COUNT(*) = SUM(IF( + vItemPackingTypeFk IS NOT NULL, + i.itemPackingTypeFk = vItemPackingTypeFk, + i.itemPackingTypeFk IS NULL + )) hasSameItemPackingType + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.shipped = vShipment + GROUP BY t.id + HAVING hasSameItemPackingType + ) + SELECT t.id INTO vTicketFk + FROM vn.ticket t + JOIN vn.alertLevel al ON al.code = 'FREE' + LEFT JOIN tPrevia tp ON tp.ticketFk = t.id + LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id + JOIN hedera.`order` o ON o.address_id = t.addressFk + AND t.warehouseFk = vWarehouseFk + AND o.date_send = t.landed + AND DATE(t.shipped) = vShipment + JOIN tTicketSameItemPackingType tt ON tt.id = t.id + WHERE o.id = vSelf + AND t.refFk IS NULL + AND tp.ticketFk IS NULL + AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) + LIMIT 1; - -- Añade las notas - IF vNotes IS NOT NULL AND vNotes <> '' THEN - INSERT INTO vn.ticketObservation SET - ticketFk = vTicketFk, - observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), - `description` = vNotes - ON DUPLICATE KEY UPDATE - `description` = CONCAT(VALUES(`description`),'. ', `description`); - END IF; + -- Crea el ticket en el caso de no existir uno adecuado + IF vTicketFk IS NULL THEN + SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); + CALL vn.ticket_add( + vClientFk, + vShipment, + vWarehouseFk, + vCompanyFk, + vAddressFk, + vAgencyModeFk, + NULL, + vLanded, + vUserFk, + TRUE, + vTicketFk + ); + ELSE + INSERT INTO vn.ticketTracking + SET ticketFk = vTicketFk, + userFk = vUserFk, + stateFk = (SELECT id FROM vn.state WHERE code = 'FREE'); + END IF; + + INSERT IGNORE INTO vn.orderTicket + SET orderFk = vSelf, + ticketFk = vTicketFk; + + -- Añade las notas + IF vNotes IS NOT NULL AND vNotes <> '' THEN + INSERT INTO vn.ticketObservation SET + ticketFk = vTicketFk, + observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), + `description` = vNotes + ON DUPLICATE KEY UPDATE + `description` = CONCAT(VALUES(`description`),'. ', `description`); + END IF; + + INSERT INTO tTicketByItemPackingType + SET itemPackingTypeFk = vItemPackingTypeFk, + ticketFk = vTicketFk; + END LOOP; + CLOSE vDistinctItemPackingType; -- Añade los movimientos y sus componentes - OPEN cRows; + OPEN vRows; lRows: LOOP + SET vSaleFk = NULL; SET vDone = FALSE; - FETCH cRows INTO vRowFk, vItemFk, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; + FETCH vRows INTO vRowFk, + vItemFk, + vConcept, + vAmount, + vPrice, + vRate, + vItemPackingTypeFk, + vIsLogifloraItem; IF vDone THEN LEAVE lRows; END IF; - SET vSaleFk = NULL; + SELECT ticketFk INTO vTicketFk + FROM tTicketByItemPackingType + WHERE IF(vItemPackingTypeFk IS NOT NULL, + itemPackingTypeFk = vItemPackingTypeFk, + itemPackingTypeFk IS NULL) SELECT s.id INTO vSaleFk FROM vn.sale s @@ -211,7 +276,8 @@ BEGIN SELECT SUM(rc.`price`) valueSum INTO vPriceFixed FROM orderRowComponent rc JOIN vn.component c ON c.id = rc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk AND ct.isBase + JOIN vn.componentType ct ON ct.id = c.typeFk + AND ct.isBase WHERE rc.rowFk = vRowFk; INSERT INTO vn.sale @@ -279,9 +345,9 @@ BEGIN LIMIT 1; END IF; END LOOP; - CLOSE cRows; + CLOSE vRows; END LOOP; - CLOSE cDates; + CLOSE vDates; UPDATE `order` SET confirmed = TRUE, @@ -289,5 +355,7 @@ BEGIN WHERE id = vSelf; COMMIT; + + DROP TEMPORARY TABLE tTicketByItemPackingType; END$$ DELIMITER ; From 7e415181c2afb40421ca3bf109533ea674c9606b Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:26:45 +0200 Subject: [PATCH 07/32] refactor: refs #6453 Major changes --- .../procedures/order_confirmWithUser.sql | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index bf4408fbc..246648e18 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -36,6 +36,7 @@ BEGIN DECLARE vIsTaxDataChecked BOOL; DECLARE vAvailable INT; DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE vCountDistinctItemPackingTypeFk INT; DECLARE vDates CURSOR FOR SELECT zgs.shipped, r.warehouseFk @@ -54,7 +55,7 @@ BEGIN WHERE o.id = vSelf AND r.warehouseFk = vWarehouseFk AND r.amount - ORDER BY i.itemPackingTypeFk DESC; + ORDER BY i.itemPackingTypeFk DESC; -- El último siempre NULL!! DECLARE vRows CURSOR FOR SELECT r.id, @@ -155,6 +156,28 @@ BEGIN LEAVE lDistinctItemPackingType; END IF; + IF vItemPackingTypeFk IS NULL THEN + SELECT COUNT(*) INTO vCountDistinctItemPackingTypeFk + FROM tTicketByItemPackingType; + + CASE + WHEN vCountDistinctItemPackingTypeFk = 1 THEN + INSERT INTO tTicketByItemPackingType + SET itemPackingTypeFk = vItemPackingTypeFk, + ticketFk = (SELECT ticketFk FROM tTicketByItemPackingType); + LEAVE lDistinctItemPackingType; + WHEN vCountDistinctItemPackingTypeFk > 1 THEN + INSERT INTO tTicketByItemPackingType + SET itemPackingTypeFk = vItemPackingTypeFk, + ticketFk = ( + SELECT ticketFk + FROM tTicketByItemPackingType + WHERE itemPackingTypeFk = 'H' + ); + LEAVE lDistinctItemPackingType; + END CASE; + END IF; + WITH tPrevia AS ( SELECT DISTINCT s.ticketFk FROM vn.sale s From 15f580508bf3e4cfcb32bd63b49847c8e8e6ba98 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:29:14 +0200 Subject: [PATCH 08/32] refactor: refs #6453 Minor changes --- db/routines/hedera/procedures/order_confirmWithUser.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 246648e18..fe0f33b3f 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -55,7 +55,8 @@ BEGIN WHERE o.id = vSelf AND r.warehouseFk = vWarehouseFk AND r.amount - ORDER BY i.itemPackingTypeFk DESC; -- El último siempre NULL!! + ORDER BY i.itemPackingTypeFk DESC; + -- El último siempre NULL, es imprescindible para la lógica !!! DECLARE vRows CURSOR FOR SELECT r.id, From 6dc464d26b15de4f83815ff01a44bce620f74233 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 11 Jul 2024 07:14:02 +0200 Subject: [PATCH 09/32] refactor: refs #6453 Minor changes --- db/routines/hedera/procedures/order_confirmWithUser.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index fe0f33b3f..c48b74dd7 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -162,6 +162,8 @@ BEGIN FROM tTicketByItemPackingType; CASE + WHEN NOT vCountDistinctItemPackingTypeFk THEN + -- Code WHEN vCountDistinctItemPackingTypeFk = 1 THEN INSERT INTO tTicketByItemPackingType SET itemPackingTypeFk = vItemPackingTypeFk, @@ -196,6 +198,7 @@ BEGIN JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk WHERE t.shipped = vShipment + AND t.warehouseFk= vWarehouseFk GROUP BY t.id HAVING hasSameItemPackingType ) From 5f29384389c741e2e0d79cde820eb992a026a75d Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 19 Jul 2024 10:49:45 +0200 Subject: [PATCH 10/32] feat: #6453 Rollback always split by itemPackingType --- .../procedures/order_confirmWithUser.sql | 190 +++++------------- 1 file changed, 55 insertions(+), 135 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index c48b74dd7..86489b080 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -47,17 +47,6 @@ BEGIN AND r.amount GROUP BY r.warehouseFk; - DECLARE vDistinctItemPackingType CURSOR FOR - SELECT DISTINCT i.itemPackingTypeFk - FROM `order` o - JOIN orderRow r ON r.orderFk = o.id - JOIN vn.item i ON i.id = r.itemFk - WHERE o.id = vSelf - AND r.warehouseFk = vWarehouseFk - AND r.amount - ORDER BY i.itemPackingTypeFk DESC; - -- El último siempre NULL, es imprescindible para la lógica !!! - DECLARE vRows CURSOR FOR SELECT r.id, r.itemFk, @@ -140,126 +129,65 @@ BEGIN LEAVE lDates; END IF; - CREATE OR REPLACE TEMPORARY TABLE tTicketByItemPackingType( - itemPackingTypeFk VARCHAR(1), - ticketFk INT, - PRIMARY KEY(itemPackingTypeFk, ticketFk) - ) ENGINE = MEMORY; - -- Busca un ticket existente que coincida con los parametros - OPEN vDistinctItemPackingType; - lDistinctItemPackingType: LOOP - SET vItemPackingTypeFk = NULL; - SET vDone = FALSE; - FETCH vDistinctItemPackingType INTO vItemPackingTypeFk; + WITH tPrevia AS ( + SELECT DISTINCT s.ticketFk + FROM vn.sale s + JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) + ) + SELECT t.id INTO vTicketFk + FROM vn.ticket t + JOIN vn.alertLevel al ON al.code = 'FREE' + LEFT JOIN tPrevia tp ON tp.ticketFk = t.id + LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id + JOIN hedera.`order` o ON o.address_id = t.addressFk + AND t.warehouseFk = vWarehouseFk + AND o.date_send = t.landed + AND DATE(t.shipped) = vShipment + WHERE o.id = vSelf + AND t.refFk IS NULL + AND tp.ticketFk IS NULL + AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) + LIMIT 1; - IF vDone THEN - LEAVE lDistinctItemPackingType; - END IF; + -- Crea el ticket en el caso de no existir uno adecuado + IF vTicketFk IS NULL THEN + SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); + CALL vn.ticket_add( + vClientFk, + vShipment, + vWarehouseFk, + vCompanyFk, + vAddressFk, + vAgencyModeFk, + NULL, + vLanded, + vUserFk, + TRUE, + vTicketFk + ); + ELSE + INSERT INTO vn.ticketTracking + SET ticketFk = vTicketFk, + userFk = vUserFk, + stateFk = (SELECT id FROM vn.state WHERE code = 'FREE'); + END IF; - IF vItemPackingTypeFk IS NULL THEN - SELECT COUNT(*) INTO vCountDistinctItemPackingTypeFk - FROM tTicketByItemPackingType; + INSERT IGNORE INTO vn.orderTicket + SET orderFk = vSelf, + ticketFk = vTicketFk; - CASE - WHEN NOT vCountDistinctItemPackingTypeFk THEN - -- Code - WHEN vCountDistinctItemPackingTypeFk = 1 THEN - INSERT INTO tTicketByItemPackingType - SET itemPackingTypeFk = vItemPackingTypeFk, - ticketFk = (SELECT ticketFk FROM tTicketByItemPackingType); - LEAVE lDistinctItemPackingType; - WHEN vCountDistinctItemPackingTypeFk > 1 THEN - INSERT INTO tTicketByItemPackingType - SET itemPackingTypeFk = vItemPackingTypeFk, - ticketFk = ( - SELECT ticketFk - FROM tTicketByItemPackingType - WHERE itemPackingTypeFk = 'H' - ); - LEAVE lDistinctItemPackingType; - END CASE; - END IF; - - WITH tPrevia AS ( - SELECT DISTINCT s.ticketFk - FROM vn.sale s - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ), - tTicketSameItemPackingType AS ( - SELECT t.id, COUNT(*) = SUM(IF( - vItemPackingTypeFk IS NOT NULL, - i.itemPackingTypeFk = vItemPackingTypeFk, - i.itemPackingTypeFk IS NULL - )) hasSameItemPackingType - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.shipped = vShipment - AND t.warehouseFk= vWarehouseFk - GROUP BY t.id - HAVING hasSameItemPackingType - ) - SELECT t.id INTO vTicketFk - FROM vn.ticket t - JOIN vn.alertLevel al ON al.code = 'FREE' - LEFT JOIN tPrevia tp ON tp.ticketFk = t.id - LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id - JOIN hedera.`order` o ON o.address_id = t.addressFk - AND t.warehouseFk = vWarehouseFk - AND o.date_send = t.landed - AND DATE(t.shipped) = vShipment - JOIN tTicketSameItemPackingType tt ON tt.id = t.id - WHERE o.id = vSelf - AND t.refFk IS NULL - AND tp.ticketFk IS NULL - AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) - LIMIT 1; - - -- Crea el ticket en el caso de no existir uno adecuado - IF vTicketFk IS NULL THEN - SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); - CALL vn.ticket_add( - vClientFk, - vShipment, - vWarehouseFk, - vCompanyFk, - vAddressFk, - vAgencyModeFk, - NULL, - vLanded, - vUserFk, - TRUE, - vTicketFk - ); - ELSE - INSERT INTO vn.ticketTracking - SET ticketFk = vTicketFk, - userFk = vUserFk, - stateFk = (SELECT id FROM vn.state WHERE code = 'FREE'); - END IF; - - INSERT IGNORE INTO vn.orderTicket - SET orderFk = vSelf, - ticketFk = vTicketFk; - - -- Añade las notas - IF vNotes IS NOT NULL AND vNotes <> '' THEN - INSERT INTO vn.ticketObservation SET - ticketFk = vTicketFk, - observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), - `description` = vNotes - ON DUPLICATE KEY UPDATE - `description` = CONCAT(VALUES(`description`),'. ', `description`); - END IF; - - INSERT INTO tTicketByItemPackingType - SET itemPackingTypeFk = vItemPackingTypeFk, - ticketFk = vTicketFk; - END LOOP; - CLOSE vDistinctItemPackingType; + -- Añade las notas + IF vNotes IS NOT NULL AND vNotes <> '' THEN + INSERT INTO vn.ticketObservation SET + ticketFk = vTicketFk, + observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), + `description` = vNotes + ON DUPLICATE KEY UPDATE + `description` = CONCAT(VALUES(`description`),'. ', `description`); + END IF; -- Añade los movimientos y sus componentes OPEN vRows; @@ -279,12 +207,6 @@ BEGIN LEAVE lRows; END IF; - SELECT ticketFk INTO vTicketFk - FROM tTicketByItemPackingType - WHERE IF(vItemPackingTypeFk IS NOT NULL, - itemPackingTypeFk = vItemPackingTypeFk, - itemPackingTypeFk IS NULL) - SELECT s.id INTO vSaleFk FROM vn.sale s WHERE ticketFk = vTicketFk @@ -382,7 +304,5 @@ BEGIN WHERE id = vSelf; COMMIT; - - DROP TEMPORARY TABLE tTicketByItemPackingType; END$$ DELIMITER ; From 578de51f7e689b7ddc9ab03d5bf8015eb2c181f5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 19 Jul 2024 10:54:40 +0200 Subject: [PATCH 11/32] feat: #6453 Refactor --- db/routines/hedera/procedures/order_confirmWithUser.sql | 7 ------- 1 file changed, 7 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 86489b080..841a69390 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -22,21 +22,16 @@ BEGIN DECLARE vAmount INT; DECLARE vPrice DECIMAL(10,2); DECLARE vSaleFk INT; - DECLARE vRate INT; DECLARE vRowFk INT; DECLARE vPriceFixed DECIMAL(10,2); DECLARE vLanded DATE; DECLARE vAddressFk INT; - DECLARE vIsConfirmed BOOL; DECLARE vClientFk INT; DECLARE vCompanyFk INT; DECLARE vAgencyModeFk INT; DECLARE vCalcFk INT; DECLARE vIsLogifloraItem BOOL; DECLARE vIsTaxDataChecked BOOL; - DECLARE vAvailable INT; - DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE vCountDistinctItemPackingTypeFk INT; DECLARE vDates CURSOR FOR SELECT zgs.shipped, r.warehouseFk @@ -53,7 +48,6 @@ BEGIN i.name, r.amount, r.price, - r.rate, i.itemPackingTypeFk, i.isFloramondo FROM orderRow r @@ -199,7 +193,6 @@ BEGIN vConcept, vAmount, vPrice, - vRate, vItemPackingTypeFk, vIsLogifloraItem; From 4c602800ea9183a72ef358e29a5141286711bb5c Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 29 Jul 2024 11:46:59 +0200 Subject: [PATCH 12/32] feat: refs #6453 Added new ticket search --- .../procedures/order_confirmWithUser.sql | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 841a69390..48f97c9b6 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -123,14 +123,14 @@ BEGIN LEAVE lDates; END IF; - -- Busca un ticket existente que coincida con los parametros + -- Busca un ticket libre disponible WITH tPrevia AS ( SELECT DISTINCT s.ticketFk FROM vn.sale s JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ) + ), SELECT t.id INTO vTicketFk FROM vn.ticket t JOIN vn.alertLevel al ON al.code = 'FREE' @@ -146,6 +146,37 @@ BEGIN AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) LIMIT 1; + -- Comprobamos si hay un ticket de previa disponible + IF vTicketFk IS NULL THEN + WITH tItemPackingTypeOrder AS ( + SELECT GROUP_CONCAT(DISTINCT i.itemPackingTypeFk) distinctItemPackingTypes, + o.address_id + FROM vn.item i + JOIN orderRow oro ON oro.itemFk = i.id + JOIN `order` o ON o.id = oro.orderFk + WHERE oro.orderFk = vSelf + ), + tItemPackingTypeTicket AS ( + SELECT t.id, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk) distinctItemPackingTypes + FROM vn.ticket t + JOIN vn.alertLevel al ON al.code = 'ON_PREVIOUS' + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN tItemPackingTypeOrder ipto + WHERE t.refFk IS NULL + AND DATE(t.shipped) = vShipment + AND t.warehouseFk = vWarehouseFk + AND t.addressFk = ipto.address_id + GROUP BY t.id + ) + SELECT iptt.id INTO vTicketFk + FROM tItemPackingTypeTicket iptt + JOIN tItemPackingTypeOrder ipto + WHERE INSTR(iptt.distinctItemPackingTypes, ipto.distinctItemPackingTypes) + LIMIT 1 + END IF; + -- Crea el ticket en el caso de no existir uno adecuado IF vTicketFk IS NULL THEN SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); From e53b12d51bc220990d3e90ea0f20a2985adec303 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 29 Jul 2024 12:31:44 +0200 Subject: [PATCH 13/32] feat: refs #6453 Fixes --- db/routines/hedera/procedures/order_confirmWithUser.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 48f97c9b6..cf0f9aead 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -20,6 +20,7 @@ BEGIN DECLARE vItemFk INT; DECLARE vConcept VARCHAR(30); DECLARE vAmount INT; + DECLARE vAvailable INT; DECLARE vPrice DECIMAL(10,2); DECLARE vSaleFk INT; DECLARE vRowFk INT; @@ -48,7 +49,6 @@ BEGIN i.name, r.amount, r.price, - i.itemPackingTypeFk, i.isFloramondo FROM orderRow r JOIN vn.item i ON i.id = r.itemFk @@ -130,7 +130,7 @@ BEGIN JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ), + ) SELECT t.id INTO vTicketFk FROM vn.ticket t JOIN vn.alertLevel al ON al.code = 'FREE' @@ -174,7 +174,7 @@ BEGIN FROM tItemPackingTypeTicket iptt JOIN tItemPackingTypeOrder ipto WHERE INSTR(iptt.distinctItemPackingTypes, ipto.distinctItemPackingTypes) - LIMIT 1 + LIMIT 1; END IF; -- Crea el ticket en el caso de no existir uno adecuado @@ -224,7 +224,6 @@ BEGIN vConcept, vAmount, vPrice, - vItemPackingTypeFk, vIsLogifloraItem; IF vDone THEN From 6ad3d5a5ebdc37873d5c6dc3791e6529fe1308bb Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 29 Jul 2024 12:36:08 +0200 Subject: [PATCH 14/32] feat: refs #6453 Minor changes --- db/routines/hedera/procedures/order_confirmWithUser.sql | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index cf0f9aead..4fcee91f7 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -15,6 +15,7 @@ BEGIN DECLARE vDone BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; + DECLARE vShipmentDayEnd DATE; DECLARE vTicketFk INT; DECLARE vNotes VARCHAR(255); DECLARE vItemFk INT; @@ -123,13 +124,15 @@ BEGIN LEAVE lDates; END IF; + SET vShipmentDayEnd = util.dayEnd(vShipment); + -- Busca un ticket libre disponible WITH tPrevia AS ( SELECT DISTINCT s.ticketFk FROM vn.sale s JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) + WHERE t.shipped BETWEEN vShipment AND vShipmentDayEnd ) SELECT t.id INTO vTicketFk FROM vn.ticket t @@ -139,7 +142,7 @@ BEGIN JOIN hedera.`order` o ON o.address_id = t.addressFk AND t.warehouseFk = vWarehouseFk AND o.date_send = t.landed - AND DATE(t.shipped) = vShipment + AND t.shipped BETWEEN vShipment AND vShipmentDayEnd WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL @@ -165,7 +168,7 @@ BEGIN JOIN vn.item i ON i.id = s.itemFk JOIN tItemPackingTypeOrder ipto WHERE t.refFk IS NULL - AND DATE(t.shipped) = vShipment + AND t.shipped BETWEEN vShipment AND vShipmentDayEnd AND t.warehouseFk = vWarehouseFk AND t.addressFk = ipto.address_id GROUP BY t.id From b6abcbe0907eb78e28feab73800ac5abebb064e0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jul 2024 10:14:20 +0200 Subject: [PATCH 15/32] feat: refs #6453 Requested changes --- .../procedures/order_confirmWithUser.sql | 65 +++---------------- 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 4fcee91f7..17798caf8 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -11,11 +11,11 @@ BEGIN * @param vSelf The order identifier * @param vUser The user identifier */ - DECLARE vIsOk BOOL; + DECLARE vHasRows BOOL; DECLARE vDone BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; - DECLARE vShipmentDayEnd DATE; + DECLARE vShipmentDayEnd DATETIME; DECLARE vTicketFk INT; DECLARE vNotes VARCHAR(255); DECLARE vItemFk INT; @@ -32,7 +32,6 @@ BEGIN DECLARE vCompanyFk INT; DECLARE vAgencyModeFk INT; DECLARE vCalcFk INT; - DECLARE vIsLogifloraItem BOOL; DECLARE vIsTaxDataChecked BOOL; DECLARE vDates CURSOR FOR @@ -49,8 +48,7 @@ BEGIN r.itemFk, i.name, r.amount, - r.price, - i.isFloramondo + r.price FROM orderRow r JOIN vn.item i ON i.id = r.itemFk WHERE r.amount @@ -104,12 +102,12 @@ BEGIN CALL order_checkEditable(vSelf); -- Check order is not empty - SELECT COUNT(*) > 0 INTO vIsOk + SELECT COUNT(*) > 0 INTO vHasRows FROM orderRow WHERE orderFk = vSelf AND amount > 0; - IF NOT vIsOk THEN + IF NOT vHasRows THEN CALL util.throw('ORDER_EMPTY'); END IF; @@ -209,8 +207,8 @@ BEGIN -- Añade las notas IF vNotes IS NOT NULL AND vNotes <> '' THEN - INSERT INTO vn.ticketObservation SET - ticketFk = vTicketFk, + INSERT INTO vn.ticketObservation + SET ticketFk = vTicketFk, observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'), `description` = vNotes ON DUPLICATE KEY UPDATE @@ -222,12 +220,7 @@ BEGIN lRows: LOOP SET vSaleFk = NULL; SET vDone = FALSE; - FETCH vRows INTO vRowFk, - vItemFk, - vConcept, - vAmount, - vPrice, - vIsLogifloraItem; + FETCH vRows INTO vRowFk, vItemFk, vConcept, vAmount, vPrice; IF vDone THEN LEAVE lRows; @@ -277,48 +270,6 @@ BEGIN UPDATE orderRow SET saleFk = vSaleFk WHERE id = vRowFk; - - -- Inserta en putOrder si la compra es de Floramondo - IF vIsLogifloraItem THEN - CALL cache.availableNoRaids_refresh(vCalcFk, FALSE,vWarehouseFk, vShipment); - - SELECT GREATEST(0, available) INTO vAvailable - FROM cache.availableNoRaids - WHERE calc_id = vCalcFk - AND item_id = vItemFk; - - UPDATE cache.availableNoRaids - SET available = GREATEST(0, available - vAmount) - WHERE item_id = vItemFk - AND calc_id = vCalcFk; - - INSERT INTO edi.putOrder ( - deliveryInformationID, - supplyResponseId, - quantity , - EndUserPartyId, - EndUserPartyGLN, - FHAdminNumber, - saleFk - ) - SELECT di.ID, - i.supplyResponseFk, - CEIL((vAmount - vAvailable)/ sr.NumberOfItemsPerCask), - o.address_id , - vClientFk, - IFNULL(ca.fhAdminNumber, fhc.defaultAdminNumber), - vSaleFk - FROM edi.deliveryInformation di - JOIN vn.item i ON i.supplyResponseFk = di.supplyResponseID - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientFk - JOIN edi.floraHollandConfig fhc - JOIN `order` o ON o.id = vSelf - WHERE i.id = vItemFk - AND di.LatestOrderDateTime > util.VN_NOW() - AND vAmount > vAvailable - LIMIT 1; - END IF; END LOOP; CLOSE vRows; END LOOP; From 4ef57e68692bc81008343a01a9840358d1a43d9c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jul 2024 14:17:41 +0200 Subject: [PATCH 16/32] fix: refs #7821 Added orders in item_getMinacum --- db/routines/vn/procedures/item_getMinacum.sql | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql index a3ebedb12..c0bdb7e7d 100644 --- a/db/routines/vn/procedures/item_getMinacum.sql +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -1,35 +1,38 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinacum`(IN vWarehouseFk TINYINT, IN vDatedFrom DATETIME, IN vRange INT, IN vItemFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinacum`( + vWarehouseFk TINYINT, + vDated DATE, + vRange INT, + vItemFk INT +) BEGIN /** - * Cálculo del mínimo acumulado, para un item/almacén especificado, en caso de - * NULL para todo. + * Cálculo del mínimo acumulado, para un item/almacén + * especificado, en caso de NULL para todo. * - * @param vWarehouseFk -> warehouseFk - * @param vDatedFrom -> fecha inicio - * @param vRange -> número de días a considerar - * @param vItemFk -> Identificador de item + * @param vWarehouseFk Id warehouse + * @param vDated Fecha inicio + * @param vRange Número de días a considerar + * @param vItemFk Id de artículo * @return tmp.itemMinacum */ - DECLARE vDatedTo DATETIME; + DECLARE vDatedTo DATETIME DEFAULT util.dayEnd(vDated + INTERVAL vRange DAY); - SET vDatedFrom = TIMESTAMP(DATE(vDatedFrom), '00:00:00'); - SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, vRange, vDatedFrom), '23:59:59'); - - DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc; - CREATE TEMPORARY TABLE tmp.itemCalc + CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY SELECT sub.itemFk, sub.dated, CAST(SUM(sub.quantity) AS SIGNED) quantity, sub.warehouseFk - FROM (SELECT s.itemFk, + FROM ( + SELECT s.itemFk, DATE(t.shipped) dated, -s.quantity quantity, t.warehouseFk FROM sale s JOIN ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + WHERE t.shipped BETWEEN vDated AND vDatedTo AND t.warehouseFk AND s.quantity != 0 AND (vItemFk IS NULL OR s.itemFk = vItemFk) @@ -42,10 +45,10 @@ BEGIN FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vDatedFrom AND vDatedTo + WHERE t.landed BETWEEN vDated AND vDatedTo AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) AND !e.isExcludedFromAvailable - AND b.quantity != 0 + AND b.quantity <> 0 AND (vItemFk IS NULL OR b.itemFk = vItemFk) UNION ALL SELECT b.itemFk, @@ -55,20 +58,35 @@ BEGIN FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + WHERE t.shipped BETWEEN vDated AND vDatedTo AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk) AND !e.isExcludedFromAvailable - AND b.quantity != 0 + AND b.quantity <> 0 AND (vItemFk IS NULL OR b.itemFk = vItemFk) AND !e.isRaid + UNION ALL + SELECT r.itemFk, + r.shipment, + -r.amount, + r.warehouseFk + FROM hedera.orderRow r + JOIN hedera.`order` o ON o.id = r.orderFk + JOIN vn.client c ON c.id = o.customer_id + WHERE r.shipment BETWEEN vDated AND vDatedTo + AND (vWarehouseFk IS NULL OR r.warehouseFk = vWarehouseFk) + AND r.created >= ( + SELECT SUBTIME(util.VN_NOW(), reserveTime) + FROM hedera.orderConfig + ) + AND NOT o.confirmed + AND (vItemFk IS NULL OR r.itemFk = vItemFk) + AND r.amount <> 0 ) sub GROUP BY sub.itemFk, sub.warehouseFk, sub.dated; - CALL item_getAtp(vDatedFrom); - DROP TEMPORARY TABLE tmp.itemCalc; + CALL item_getAtp(vDated); - DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; - CREATE TEMPORARY TABLE tmp.itemMinacum + CREATE OR REPLACE TEMPORARY TABLE tmp.itemMinacum (INDEX(itemFk)) ENGINE = MEMORY SELECT i.itemFk, @@ -77,6 +95,8 @@ BEGIN FROM tmp.itemAtp i HAVING amount != 0; - DROP TEMPORARY TABLE tmp.itemAtp; + DROP TEMPORARY TABLE + tmp.itemAtp, + tmp.itemCalc; END$$ DELIMITER ; From 961d05ab354944977308c5db39dc4398fce6442a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jul 2024 14:19:04 +0200 Subject: [PATCH 17/32] fix: refs #7821 Added orders in item_getMinacum --- db/routines/vn/procedures/item_getMinacum.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql index c0bdb7e7d..2b51355d5 100644 --- a/db/routines/vn/procedures/item_getMinacum.sql +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -34,7 +34,7 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN vDated AND vDatedTo AND t.warehouseFk - AND s.quantity != 0 + AND s.quantity <> 0 AND (vItemFk IS NULL OR s.itemFk = vItemFk) AND (vWarehouseFk IS NULL OR t.warehouseFk = vWarehouseFk) UNION ALL @@ -93,7 +93,7 @@ BEGIN i.warehouseFk, i.quantity amount FROM tmp.itemAtp i - HAVING amount != 0; + HAVING amount <> 0; DROP TEMPORARY TABLE tmp.itemAtp, From 952b7a5054efff1b7ce6b34a33cbb87c3f13cda3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jul 2024 07:10:38 +0200 Subject: [PATCH 18/32] hotFix model itemShelving refs #7805 --- modules/item/back/models/item-shelving.json | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 893a1f81d..40f2a2852 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -1,9 +1,9 @@ { "name": "ItemShelving", "base": "VnModel", - "mixins": { - "Loggable": true - }, + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemShelving" @@ -17,27 +17,27 @@ }, "shelvingFk": { "type": "string" - }, + }, "itemFk": { "type": "number" - }, + }, "created": { "type": "date" - }, + }, "grouping": { "type": "number" - }, - "isChecked": { - "type": "boolean" + }, + "isChecked": { + "type": "number" }, "packing": { "type": "number" - }, - "visible": { - "type": "number" }, - "userFk": { - "type": "number" + "visible": { + "type": "number" + }, + "userFk": { + "type": "number" } }, "relations": { @@ -56,6 +56,6 @@ "model": "Shelving", "foreignKey": "shelvingFk", "primaryKey": "code" - } + } } -} +} \ No newline at end of file From 07b6d2aca9ae9f3f7536ecc127afcb955866c935 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 31 Jul 2024 08:59:33 +0200 Subject: [PATCH 19/32] feat: refs #7644 Added comment if has itemOriginalFk --- print/templates/reports/buy-label/buy-label.js | 3 +-- print/templates/reports/buy-label/sql/buys.sql | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/print/templates/reports/buy-label/buy-label.js b/print/templates/reports/buy-label/buy-label.js index 7d626c052..48ffe336c 100755 --- a/print/templates/reports/buy-label/buy-label.js +++ b/print/templates/reports/buy-label/buy-label.js @@ -15,7 +15,6 @@ module.exports = { }, methods: { getBarcode(id) { - const xmlSerializer = new XMLSerializer(); const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null); const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); @@ -26,7 +25,7 @@ module.exports = { width: 3.8, height: 115, }); - return xmlSerializer.serializeToString(svgNode); + return new XMLSerializer().serializeToString(svgNode); } }, props: { diff --git a/print/templates/reports/buy-label/sql/buys.sql b/print/templates/reports/buy-label/sql/buys.sql index 015a74797..44b1b4bad 100644 --- a/print/templates/reports/buy-label/sql/buys.sql +++ b/print/templates/reports/buy-label/sql/buys.sql @@ -21,12 +21,13 @@ SELECT ROW_NUMBER() OVER(ORDER BY b.id, num.n) labelNum, b.id, b.itemFk, p.name producer, - i.comment + IF(i2.id, i2.comment, i.comment) comment FROM buy b JOIN item i ON i.id = b.itemFk LEFT JOIN producer p ON p.id = i.producerFk LEFT JOIN ink ON ink.id = i.inkFk LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN item i2 ON i2.id = b.itemOriginalFk JOIN numbers num WHERE b.entryFk = ? AND num.n <= b.stickers From cc78355aad92cdd9c446637abe17e29f43061f92 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 31 Jul 2024 09:26:55 +0200 Subject: [PATCH 20/32] fix: refs #7821 Requested changes --- db/routines/vn/procedures/item_getMinacum.sql | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql index 2b51355d5..1decf881d 100644 --- a/db/routines/vn/procedures/item_getMinacum.sql +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -8,7 +8,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinacum`( BEGIN /** * Cálculo del mínimo acumulado, para un item/almacén - * especificado, en caso de NULL para todo. + * especificado, en caso de NULL para todos. * * @param vWarehouseFk Id warehouse * @param vDated Fecha inicio @@ -47,7 +47,7 @@ BEGIN JOIN travel t ON t.id = e.travelFk WHERE t.landed BETWEEN vDated AND vDatedTo AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND !e.isExcludedFromAvailable + AND NOT e.isExcludedFromAvailable AND b.quantity <> 0 AND (vItemFk IS NULL OR b.itemFk = vItemFk) UNION ALL @@ -60,10 +60,10 @@ BEGIN JOIN travel t ON t.id = e.travelFk WHERE t.shipped BETWEEN vDated AND vDatedTo AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk) - AND !e.isExcludedFromAvailable + AND NOT e.isExcludedFromAvailable AND b.quantity <> 0 AND (vItemFk IS NULL OR b.itemFk = vItemFk) - AND !e.isRaid + AND NOT e.isRaid UNION ALL SELECT r.itemFk, r.shipment, @@ -71,11 +71,11 @@ BEGIN r.warehouseFk FROM hedera.orderRow r JOIN hedera.`order` o ON o.id = r.orderFk - JOIN vn.client c ON c.id = o.customer_id + JOIN client c ON c.id = o.customer_id WHERE r.shipment BETWEEN vDated AND vDatedTo AND (vWarehouseFk IS NULL OR r.warehouseFk = vWarehouseFk) AND r.created >= ( - SELECT SUBTIME(util.VN_NOW(), reserveTime) + SELECT util.VN_NOW() - INTERVAL TIME_TO_SEC(reserveTime) SECOND FROM hedera.orderConfig ) AND NOT o.confirmed @@ -89,11 +89,11 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemMinacum (INDEX(itemFk)) ENGINE = MEMORY - SELECT i.itemFk, - i.warehouseFk, - i.quantity amount - FROM tmp.itemAtp i - HAVING amount <> 0; + SELECT itemFk, + warehouseFk, + quantity amount + FROM tmp.itemAtp + WHERE quantity <> 0; DROP TEMPORARY TABLE tmp.itemAtp, From dca7900ab231cbb52944a77e4264b2a35adbc270 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 31 Jul 2024 11:31:02 +0200 Subject: [PATCH 21/32] fix: refs #7818 entry_splitByShelving --- db/routines/vn/procedures/entry_splitByShelving.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index eb07c12b7..f46278e5a 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -110,7 +110,7 @@ BEGIN UPDATE itemShelving SET isSplit = TRUE - WHERE shelvingFk = vShelvingFk; + WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci; END LOOP; CLOSE cur; END$$ From 77fa4dd4979d1148cec6cb02cdeb87020685a436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 14:38:12 +0200 Subject: [PATCH 22/32] fix: refs #7213 componentLack y setRisk --- db/routines/vn/procedures/sale_setProblemComponentLack.sql | 2 +- .../vn/procedures/sale_setProblemComponentLackByComponent.sql | 4 ++-- db/routines/vn/procedures/ticket_setRisk.sql | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/sale_setProblemComponentLack.sql b/db/routines/vn/procedures/sale_setProblemComponentLack.sql index aa5f5f1be..23eb77c2e 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLack.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLack.sql @@ -14,7 +14,7 @@ BEGIN ENGINE = MEMORY SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem, - ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + (ticket_isProblemCalcNeeded(ticketFk) AND quantity > 0) isProblemCalcNeeded FROM sale WHERE id = vSelf; diff --git a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql index 2ee49b656..cdf28ac09 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql @@ -14,9 +14,9 @@ BEGIN ENGINE = MEMORY SELECT saleFk, sale_hasComponentLack(saleFk) hasProblem, - ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + (ticket_isProblemCalcNeeded(ticketFk) AND quantity > 0) isProblemCalcNeeded FROM ( - SELECT s.id saleFk, s.ticketFk + SELECT s.id saleFk, s.ticketFk, s.quantity FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index bd5d1e9f9..b88e60a37 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -85,7 +85,7 @@ BEGIN UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id SET t.risk = NULL - WHERE tr.isProblemCalcNeeded + WHERE NOT tr.isProblemCalcNeeded ORDER BY t.id; DROP TEMPORARY TABLE tTicketRisk; From 6c0aae04c004d97d6fe31d4faa739ae5faf2be04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 14:59:12 +0200 Subject: [PATCH 23/32] fix: refs #7213 componentLack y setRisk --- db/routines/vn/procedures/ticket_setRisk.sql | 140 ++++++++----------- 1 file changed, 62 insertions(+), 78 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index b88e60a37..535cd0787 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -1,94 +1,78 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRisk`( - vClientFk INT) + vClientFk INT +) BEGIN /** - * Update the risk for a client with pending tickets + * Update the risk for a client with pending tickets. * * @param vClientFk Id cliente */ - DECLARE vHasDebt BOOL; - DECLARE vStarted DATETIME; - - SELECT COUNT(*) INTO vHasDebt - FROM `client` - WHERE id = vClientFk - AND typeFk = 'normal'; - - IF vHasDebt THEN - - SELECT util.VN_CURDATE() - INTERVAL riskScope MONTH INTO vStarted - FROM clientConfig; - + IF (SELECT COUNT(*) FROM client WHERE id = vClientFk AND typeFk = 'normal') THEN CREATE OR REPLACE TEMPORARY TABLE tTicketRisk - (KEY (ticketFk)) + (PRIMARY KEY (ticketFk)) ENGINE = MEMORY - WITH ticket AS( - SELECT id ticketFk, - companyFk, - DATE(shipped) dated, - totalWithVat, - ticket_isProblemCalcNeeded(id) isProblemCalcNeeded - FROM vn.ticket - WHERE clientFk = vClientFk - AND refFk IS NULL - AND NOT isDeleted - AND IFNULL(totalWithVat, 0) <> 0 - AND shipped > vStarted - ), balance AS( - SELECT SUM(amount)amount, companyFk - FROM ( - SELECT amount, companyFk - FROM vn.clientRisk - WHERE clientFk = vClientFk - UNION ALL - SELECT -(SUM(amount) / 100) amount, tm.companyFk - FROM hedera.tpvTransaction t - JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk - WHERE clientFk = vClientFk - AND receiptFk IS NULL - AND status = 'ok' - ) sub - WHERE companyFk - GROUP BY companyFk - ), uninvoiced AS( - SELECT companyFk, dated, SUM(totalWithVat) amount - FROM ticket - GROUP BY companyFk, dated - ), receipt AS( - SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount - FROM vn.receipt - WHERE clientFk = vClientFk - AND payed > util.VN_CURDATE() - GROUP BY companyFk, DATE(payed) - ), risk AS( - SELECT b.companyFk, - ui.dated, - SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated ) + - b.amount + - SUM(IFNULL(r.amount, 0)) amount - FROM balance b - JOIN uninvoiced ui ON ui.companyFk = b.companyFk - LEFT JOIN receipt r ON r.dated > ui.dated AND r.companyFk = ui.companyFk - GROUP BY b.companyFk, ui.dated - ) - SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded - FROM ticket ti - JOIN risk r ON r.dated = ti.dated AND r.companyFk = ti.companyFk; + WITH ticket AS ( + SELECT t.id ticketFk, + t.companyFk, + DATE(t.shipped) dated, + t.totalWithVat, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded + FROM vn.ticket t + JOIN vn.clientConfig cc + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND NOT t.isDeleted + AND IFNULL(t.totalWithVat, 0) <> 0 + AND t.shipped > (util.VN_CURDATE() - INTERVAL cc.riskScope MONTH) + ), balance AS ( + SELECT SUM(amount)amount, companyFk + FROM ( + SELECT amount, companyFk + FROM vn.clientRisk + WHERE clientFk = vClientFk + UNION ALL + SELECT -(SUM(amount) / 100) amount, tm.companyFk + FROM hedera.tpvTransaction t + JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk + WHERE clientFk = vClientFk + AND receiptFk IS NULL + AND `status` = 'ok' + ) sub + WHERE companyFk + GROUP BY companyFk + ), uninvoiced AS ( + SELECT companyFk, dated, SUM(totalWithVat) amount + FROM ticket + GROUP BY companyFk, dated + ), receipt AS ( + SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount + FROM vn.receipt + WHERE clientFk = vClientFk + AND payed > util.VN_CURDATE() + GROUP BY companyFk, DATE(payed) + ), risk AS ( + SELECT b.companyFk, + ui.dated, + SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated) + + b.amount + + SUM(IFNULL(r.amount, 0)) amount + FROM balance b + JOIN uninvoiced ui ON ui.companyFk = b.companyFk + LEFT JOIN receipt r ON r.dated > ui.dated + AND r.companyFk = ui.companyFk + GROUP BY b.companyFk, ui.dated + ) + SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded + FROM ticket ti + JOIN risk r ON r.dated = ti.dated + AND r.companyFk = ti.companyFk; UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id - SET t.risk = tr.amount - WHERE tr.isProblemCalcNeeded - ORDER BY t.id; - - UPDATE ticket t - JOIN tTicketRisk tr ON tr.ticketFk = t.id - SET t.risk = NULL - WHERE NOT tr.isProblemCalcNeeded - ORDER BY t.id; + SET t.risk = IF(tr.isProblemCalcNeeded, tr.amount, NULL); DROP TEMPORARY TABLE tTicketRisk; - END IF; + END IF; END$$ DELIMITER ; \ No newline at end of file From 65e9ed301ff370f6f0e019c44ecfda47adf526f3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jul 2024 18:11:03 +0200 Subject: [PATCH 24/32] hotFix itemShelving refs #6861 --- .../itemShelvingSale_addBySaleGroup.sql | 46 +++++++++++++++++++ .../vn/procedures/itemShelving_get.sql | 3 +- .../vn/triggers/itemShelving_beforeUpdate.sql | 4 -- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql b/db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql new file mode 100644 index 000000000..285b9f93f --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySaleGroup`( + vSaleGroupFk INT(11) +) +BEGIN +/** + * Reserva cantidades con ubicaciones para el contenido de una preparación previa + * a través del saleGroup + * + * @param vSaleGroupFk Identificador de saleGroup + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vSaleFk INT; + DECLARE vSectorFk INT; + DECLARE vSales CURSOR FOR + SELECT s.id + FROM saleGroupDetail sgd + JOIN sale s ON sgd.saleFk = s.id + JOIN saleTracking str ON str.saleFk = s.id + JOIN `state` st ON st.id = str.stateFk + AND st.code = 'PREVIOUS_PREPARATION' + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + WHERE sgd.saleGroupFk = vSaleGroupFk + AND str.workerFk = account.myUser_getId() + AND iss.id IS NULL; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT sectorFk INTO vSectorFk + FROM operator + WHERE workerFk = account.myUser_getId(); + + OPEN vSales; + l: LOOP + SET vDone = FALSE; + FETCH vSales INTO vSaleFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); + END LOOP; + CLOSE vSales; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelving_get.sql b/db/routines/vn/procedures/itemShelving_get.sql index 1be762f09..d42446b06 100644 --- a/db/routines/vn/procedures/itemShelving_get.sql +++ b/db/routines/vn/procedures/itemShelving_get.sql @@ -16,7 +16,8 @@ BEGIN ish.id, s.priority, ish.isChecked, - ic.url + ic.url, + ish.available FROM itemShelving ish JOIN item i ON i.id = ish.itemFk JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index 214c64b45..961d89f65 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -9,9 +9,5 @@ BEGIN SET NEW.userFk = account.myUser_getId(); END IF; - IF (NEW.visible <> OLD.visible) THEN - SET NEW.available = GREATEST(NEW.available + NEW.visible - OLD.visible, 0); - END IF; - END$$ DELIMITER ; From 70b931553bf91c2bda7509b01023b96a34f4178f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jul 2024 18:14:09 +0200 Subject: [PATCH 25/32] hotFix itemShelving refs #6861 --- modules/item/back/models/item-shelving.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 40f2a2852..5df3b0703 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -38,6 +38,9 @@ }, "userFk": { "type": "number" + }, + "available": { + "type": "number" } }, "relations": { From 5b0dcee62d5be611423328fe6583b11237953071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 18:41:18 +0200 Subject: [PATCH 26/32] hotfix: getBuys add field comment Ticket 207748 --- modules/entry/back/methods/entry/getBuys.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index bd9c5db7a..245dada09 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -101,7 +101,8 @@ module.exports = Self => { 'groupingMode', 'inkFk', 'originFk', - 'producerFk' + 'producerFk', + 'comment' ], include: [ { From 77f6e80066b37174020dfd76446dbbd97cf5212b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 17:38:50 +0000 Subject: [PATCH 27/32] Actualizar db/routines/vn/procedures/ticket_setRisk.sql --- db/routines/vn/procedures/ticket_setRisk.sql | 113 ++++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index 535cd0787..e3cbaf231 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -13,60 +13,65 @@ BEGIN (PRIMARY KEY (ticketFk)) ENGINE = MEMORY WITH ticket AS ( - SELECT t.id ticketFk, - t.companyFk, - DATE(t.shipped) dated, - t.totalWithVat, - ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded - FROM vn.ticket t - JOIN vn.clientConfig cc - WHERE t.clientFk = vClientFk - AND t.refFk IS NULL - AND NOT t.isDeleted - AND IFNULL(t.totalWithVat, 0) <> 0 - AND t.shipped > (util.VN_CURDATE() - INTERVAL cc.riskScope MONTH) - ), balance AS ( - SELECT SUM(amount)amount, companyFk - FROM ( - SELECT amount, companyFk - FROM vn.clientRisk - WHERE clientFk = vClientFk - UNION ALL - SELECT -(SUM(amount) / 100) amount, tm.companyFk - FROM hedera.tpvTransaction t - JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk - WHERE clientFk = vClientFk - AND receiptFk IS NULL - AND `status` = 'ok' - ) sub - WHERE companyFk - GROUP BY companyFk - ), uninvoiced AS ( - SELECT companyFk, dated, SUM(totalWithVat) amount - FROM ticket - GROUP BY companyFk, dated - ), receipt AS ( - SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount - FROM vn.receipt - WHERE clientFk = vClientFk - AND payed > util.VN_CURDATE() - GROUP BY companyFk, DATE(payed) - ), risk AS ( - SELECT b.companyFk, - ui.dated, - SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated) + - b.amount + - SUM(IFNULL(r.amount, 0)) amount - FROM balance b - JOIN uninvoiced ui ON ui.companyFk = b.companyFk - LEFT JOIN receipt r ON r.dated > ui.dated - AND r.companyFk = ui.companyFk - GROUP BY b.companyFk, ui.dated - ) - SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded - FROM ticket ti - JOIN risk r ON r.dated = ti.dated - AND r.companyFk = ti.companyFk; + SELECT t.id ticketFk, + t.companyFk, + DATE(t.shipped) dated, + t.totalWithVat, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded + FROM vn.ticket t + JOIN vn.clientConfig cc + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND NOT t.isDeleted + AND IFNULL(t.totalWithVat, 0) <> 0 + AND t.shipped > (util.VN_CURDATE() - INTERVAL cc.riskScope MONTH) + ), uninvoiced AS ( + SELECT companyFk, dated, SUM(totalWithVat) amount + FROM ticket + GROUP BY companyFk, dated + ), companies AS ( + SELECT DISTINCT companyFk FROM uninvoiced + ), balance AS ( + SELECT SUM(IFNULL(amount, 0))amount, companyFk + FROM ( + SELECT cr.amount, c.companyFk + FROM companies c + LEFT JOIN vn.clientRisk cr ON cr.companyFk = c.companyFk + AND cr.clientFk = vClientFk + UNION ALL + SELECT -(SUM(t.amount) / 100) amount, c.companyFk + FROM companies c + LEFT JOIN hedera.tpvMerchant tm ON tm.companyFk = c.companyFk + LEFT JOIN hedera.tpvTransaction t ON t.merchantFk = tm.id + AND t.clientFk = vClientFk + AND t.receiptFk IS NULL + AND t.`status` = 'ok' + ) sub + WHERE companyFk + GROUP BY companyFk + ), receipt AS ( + SELECT r.companyFk, DATE(r.payed) dated, SUM(r.amountPaid) amount + FROM vn.receipt r + JOIN companies c ON c.companyFk = r.companyFk + WHERE r.clientFk = vClientFk + AND r.payed > util.VN_CURDATE() + GROUP BY r.companyFk, DATE(r.payed) + ), risk AS ( + SELECT b.companyFk, + ui.dated, + SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated) + + b.amount + + SUM(IFNULL(r.amount, 0)) amount + FROM balance b + JOIN uninvoiced ui ON ui.companyFk = b.companyFk + LEFT JOIN receipt r ON r.dated > ui.dated + AND r.companyFk = ui.companyFk + GROUP BY b.companyFk, ui.dated + ) + SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded + FROM ticket ti + JOIN risk r ON r.dated = ti.dated + AND r.companyFk = ti.companyFk; UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id From b56260af365a0a2097b6068a80340ec56c27b202 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 2 Aug 2024 07:58:45 +0200 Subject: [PATCH 28/32] feat: refs #6453 Requested changes --- .../procedures/order_confirmWithUser.sql | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 17798caf8..3acdaed5a 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -136,11 +136,11 @@ BEGIN FROM vn.ticket t JOIN vn.alertLevel al ON al.code = 'FREE' LEFT JOIN tPrevia tp ON tp.ticketFk = t.id - LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id + LEFT JOIN vn.ticketState tls ON tls.ticketFk = t.id JOIN hedera.`order` o ON o.address_id = t.addressFk + AND t.shipped BETWEEN vShipment AND vShipmentDayEnd AND t.warehouseFk = vWarehouseFk AND o.date_send = t.landed - AND t.shipped BETWEEN vShipment AND vShipmentDayEnd WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL @@ -150,7 +150,9 @@ BEGIN -- Comprobamos si hay un ticket de previa disponible IF vTicketFk IS NULL THEN WITH tItemPackingTypeOrder AS ( - SELECT GROUP_CONCAT(DISTINCT i.itemPackingTypeFk) distinctItemPackingTypes, + SELECT GROUP_CONCAT( + DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk + ) distinctItemPackingTypes, o.address_id FROM vn.item i JOIN orderRow oro ON oro.itemFk = i.id @@ -159,16 +161,20 @@ BEGIN ), tItemPackingTypeTicket AS ( SELECT t.id, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk) distinctItemPackingTypes + GROUP_CONCAT( + DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk + ) distinctItemPackingTypes FROM vn.ticket t - JOIN vn.alertLevel al ON al.code = 'ON_PREVIOUS' + JOIN vn.ticketState tls ON tls.ticketFk = t.id + JOIN vn.alertLevel al ON al.id = tls.alertLevel JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN tItemPackingTypeOrder ipto - WHERE t.refFk IS NULL - AND t.shipped BETWEEN vShipment AND vShipmentDayEnd + WHERE t.shipped BETWEEN vShipment AND vShipmentDayEnd + AND t.refFk IS NULL AND t.warehouseFk = vWarehouseFk AND t.addressFk = ipto.address_id + AND al.code = 'ON_PREVIOUS' GROUP BY t.id ) SELECT iptt.id INTO vTicketFk From d852d16ae4d19e97aafa562a8c9686b0e78c8742 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 2 Aug 2024 08:11:38 +0200 Subject: [PATCH 29/32] feat: refs #7382 Changes --- db/routines/vn/procedures/invoiceIn_booking.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql index c728085b8..a5dd3a5f1 100644 --- a/db/routines/vn/procedures/invoiceIn_booking.sql +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -16,9 +16,11 @@ BEGIN DECLARE vHasRepeatedTransactions BOOL; SELECT TRUE INTO vHasRepeatedTransactions - FROM invoiceInTax - WHERE invoiceInFk = vSelf - HAVING COUNT(DISTINCT transactionTypeSageFk) > 1 + FROM invoiceInTax iit + JOIN invoiceIn ii ON ii.id = iit.invoiceInFk + WHERE ii.id = vSelf + AND ii.serial = 'E' + HAVING COUNT(DISTINCT iit.transactionTypeSageFk) > 1 LIMIT 1; IF vHasRepeatedTransactions THEN From ddd5e4ffa491ce3b98a025659475e4d16b7b8d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 2 Aug 2024 10:28:50 +0200 Subject: [PATCH 30/32] fix: refs #7829 Error al calcular problemas de componentes --- .../vn/procedures/sale_getProblems.sql | 29 +++++++-------- .../ticket_setProblemRiskByClient.sql | 35 +++++++++++++++++++ 2 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 db/routines/vn/procedures/ticket_setProblemRiskByClient.sql diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql index ba4ff5857..730d84f38 100644 --- a/db/routines/vn/procedures/sale_getProblems.sql +++ b/db/routines/vn/procedures/sale_getProblems.sql @@ -13,7 +13,7 @@ BEGIN DECLARE vAvailableCache INT; DECLARE vVisibleCache INT; DECLARE vDone BOOL; - DECLARE vComponentCount INT; + DECLARE vRequiredComponent INT; DECLARE vCursor CURSOR FOR SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(tt.shipped)) @@ -54,7 +54,7 @@ BEGIN SELECT ticketFk, clientFk FROM tmp.sale_getProblems; - SELECT COUNT(*) INTO vComponentCount + SELECT COUNT(*) INTO vRequiredComponent FROM component WHERE isRequired; @@ -96,20 +96,17 @@ BEGIN -- Faltan componentes INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk) - SELECT ticketFk, (vComponentCount > nComp) hasComponentLack, saleFk - FROM ( - SELECT COUNT(s.id) nComp, tl.ticketFk, s.id saleFk - FROM tmp.ticket_list tl - JOIN sale s ON s.ticketFk = tl.ticketFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - LEFT JOIN component c ON c.id = sc.componentFk AND c.isRequired - JOIN ticket t ON t.id = tl.ticketFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP') - AND s.quantity > 0 - GROUP BY s.id - ) sub + SELECT t.id, COUNT(c.id) < vRequiredComponent hasComponentLack, s.id + FROM tmp.ticket_list tl + JOIN ticket t ON t.id = tl.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN component c ON c.id = sc.componentFk AND c.isRequired + WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP') + AND s.quantity > 0 + GROUP BY s.id HAVING hasComponentLack; -- Cliente congelado diff --git a/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql b/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql new file mode 100644 index 000000000..d652f5269 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRiskByClient`( + vClientFk INT +) +BEGIN +/** + * Updates future ticket risk for a client + * + * @param vClientFk Id client + */ + DECLARE vDone INT DEFAULT FALSE; + DECLARE vTicketFk INT; + DECLARE vTickets CURSOR FOR + SELECT id + FROM ticket + WHERE clientFk = vClientFk + AND shipped >= util.VN_CURDATE(); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vTickets; + l: LOOP + SET vDone = FALSE; + FETCH vTickets INTO vTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL vn.ticket_setProblemRisk(vTicketFk); + END LOOP; + + CLOSE vTickets; +END$$ +DELIMITER ; \ No newline at end of file From 29a50caaca99ec6024f13fa9780c67130ad72e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 2 Aug 2024 11:43:30 +0200 Subject: [PATCH 31/32] fix: refs #7829 Error al calcular problemas de componentes --- db/routines/vn/procedures/sale_getProblems.sql | 3 ++- db/routines/vn/procedures/ticket_setProblemRiskByClient.sql | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql index 730d84f38..979978f4a 100644 --- a/db/routines/vn/procedures/sale_getProblems.sql +++ b/db/routines/vn/procedures/sale_getProblems.sql @@ -103,7 +103,8 @@ BEGIN JOIN agencyMode am ON am.id = t.agencyModeFk JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk LEFT JOIN saleComponent sc ON sc.saleFk = s.id - LEFT JOIN component c ON c.id = sc.componentFk AND c.isRequired + LEFT JOIN component c ON c.id = sc.componentFk + AND c.isRequired WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP') AND s.quantity > 0 GROUP BY s.id diff --git a/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql b/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql index d652f5269..8479550de 100644 --- a/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql +++ b/db/routines/vn/procedures/ticket_setProblemRiskByClient.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRi ) BEGIN /** - * Updates future ticket risk for a client + * Updates future ticket risk for a client. * * @param vClientFk Id client */ @@ -14,7 +14,8 @@ BEGIN SELECT id FROM ticket WHERE clientFk = vClientFk - AND shipped >= util.VN_CURDATE(); + AND shipped >= util.VN_CURDATE() + AND refFk IS NULL; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -29,7 +30,6 @@ BEGIN CALL vn.ticket_setProblemRisk(vTicketFk); END LOOP; - CLOSE vTickets; END$$ DELIMITER ; \ No newline at end of file From abd8bc96390eca32823c33e5d8e20574ca1b0d70 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 2 Aug 2024 12:20:50 +0200 Subject: [PATCH 32/32] fix: refs #6453 order_confirmWithUser --- db/routines/hedera/procedures/order_confirmWithUser.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 3acdaed5a..2b033b704 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -155,8 +155,8 @@ BEGIN ) distinctItemPackingTypes, o.address_id FROM vn.item i - JOIN orderRow oro ON oro.itemFk = i.id - JOIN `order` o ON o.id = oro.orderFk + JOIN hedera.orderRow oro ON oro.itemFk = i.id + JOIN hedera.`order` o ON o.id = oro.orderFk WHERE oro.orderFk = vSelf ), tItemPackingTypeTicket AS (