From 91fac11fa0ac19c03fb8cfde516c7a47c44e5d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 16 Sep 2024 18:21:12 +0200 Subject: [PATCH 1/8] fix: refs #7760 tmp.ticketIPT --- .../vn/procedures/prepareTicketList.sql | 8 +- .../vn/procedures/productionControl.sql | 43 ++-- .../vn/procedures/sale_getProblems.sql | 233 ----------------- .../procedures/sale_getProblemsByTicket.sql | 23 +- .../vn/procedures/ticket_getProblems.sql | 239 +++++++++++++++--- .../back/methods/sales-monitor/salesFilter.js | 11 +- modules/ticket/back/methods/ticket/filter.js | 10 +- .../back/methods/ticket/getTicketsFuture.js | 10 +- 8 files changed, 250 insertions(+), 327 deletions(-) delete mode 100644 db/routines/vn/procedures/sale_getProblems.sql diff --git a/db/routines/vn/procedures/prepareTicketList.sql b/db/routines/vn/procedures/prepareTicketList.sql index 7c44bb994..cfe9492ee 100644 --- a/db/routines/vn/procedures/prepareTicketList.sql +++ b/db/routines/vn/procedures/prepareTicketList.sql @@ -1,16 +1,18 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`prepareTicketList`(vStartingDate DATETIME, vEndingDate DATETIME) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`prepareTicketList`( + vStartingDate DATETIME, + vEndingDate DATETIME +) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket; CREATE TEMPORARY TABLE tmp.productionTicket (PRIMARY KEY (ticketFk)) ENGINE = MEMORY - SELECT t.id ticketFk, t.clientFk + SELECT t.id ticketFk FROM ticket t JOIN alertLevel al ON al.code = 'DELIVERED' LEFT JOIN ticketState ts ON ts.ticketFk = t.id JOIN client c ON c.id = t.clientFk - WHERE c.typeFk IN ('normal','handMaking','internalUse') AND ( t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index e5323e84e..88ed42e83 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -15,7 +15,7 @@ proc: BEGIN DECLARE vEndingDate DATETIME; DECLARE vIsTodayRelative BOOLEAN; - SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY + SELECT util.dayEnd(util.VN_CURDATE() + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY) INTO vEndingDate FROM productionConfig; @@ -26,16 +26,10 @@ proc: BEGIN CALL prepareTicketList(util.yesterday(), vEndingDate); CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT * FROM tmp.productionTicket; - - CALL prepareClientList(); - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems (INDEX (ticketFk)) ENGINE = MEMORY - SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped - FROM tmp.productionTicket tt - JOIN ticket t ON t.id = tt.ticketFk; + SELECT ticketFk + FROM tmp.productionTicket; CALL ticket_getProblems(vIsTodayRelative); @@ -43,7 +37,7 @@ proc: BEGIN (PRIMARY KEY(ticketFk), previaParking VARCHAR(255)) ENGINE = MEMORY SELECT tt.ticketFk, - tt.clientFk, + t.clientFk, t.warehouseFk, t.nickname, t.packages, @@ -61,7 +55,17 @@ proc: BEGIN 0 `lines`, CAST( 0 AS DECIMAL(5,2)) m3, CAST( 0 AS DECIMAL(5,2)) preparationRate, - "" problem, + TRIM(CAST(CONCAT( IFNULL(tpr.itemShortage, ''), + IFNULL(tpr.itemDelay, ''), + IFNULL(tpr.itemLost, ''), + IF(tpr.isFreezed, ' CONGELADO',''), + IF(tpr.hasHighRisk, ' RIESGO',''), + IF(tpr.hasTicketRequest, ' COD 100',''), + IF(tpr.isTaxDataChecked, '',' FICHA INCOMPLETA'), + IF(tpr.hasComponentLack, ' COMPONENTES', ''), + IF(HOUR(util.VN_NOW()) < IF(HOUR(t.shipped), HOUR(t.shipped), COALESCE(HOUR(zc.hour),HOUR(z.hour))) + AND tpr.isTooLittle, ' PEQUEÑO', '') + ) AS char(255))) problem, IFNULL(tls.state,2) state, w.code workerCode, DATE(t.shipped) shipped, @@ -101,6 +105,7 @@ proc: BEGIN AND DATE(t.shipped) = zc.dated LEFT JOIN ticketParking tp ON tp.ticketFk = t.id LEFT JOIN parking pk ON pk.id = tp.parkingFk + LEFT JOIN tmp.ticketProblem tpr ON tpr.ticketFk = tt.ticketFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); @@ -123,19 +128,6 @@ proc: BEGIN ADD COLUMN `collectionV` INT, ADD COLUMN `collectionN` INT; - UPDATE tmp.productionBuffer pb - JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk - SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage, ''), - IFNULL(tp.itemDelay, ''), - IFNULL(tp.itemLost, ''), - IF(tp.isFreezed, ' CONGELADO',''), - IF(tp.hasHighRisk, ' RIESGO',''), - IF(tp.hasTicketRequest, ' COD 100',''), - IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), - IF(tp.hasComponentLack, ' COMPONENTES', ''), - IF(HOUR(util.VN_NOW()) < pb.HH AND tp.isTooLittle, ' PEQUEÑO', '') - ) AS char(255))); - -- Clientes Nuevos o Recuperados UPDATE tmp.productionBuffer pb LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk @@ -267,8 +259,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.productionTicket, - tmp.ticket, - tmp.ticket_problems, + tmp.ticketProblems, tmp.ticketWithPrevia, tItemShelvingStock, tItemPackingType; diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql deleted file mode 100644 index 2bba8fbc3..000000000 --- a/db/routines/vn/procedures/sale_getProblems.sql +++ /dev/null @@ -1,233 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblems`( - vIsTodayRelative tinyint(1) -) -BEGIN -/** - * Calcula los problemas de cada venta para un conjunto de tickets. - * - * @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy - * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Tickets a calcular - * @return tmp.sale_problems - */ - DECLARE vWarehouseFk INT; - DECLARE vDate DATE; - DECLARE vAvailableCache INT; - DECLARE vVisibleCache INT; - DECLARE vDone BOOL; - DECLARE vCursor CURSOR FOR - SELECT DISTINCT warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(shipped)) - FROM tmp.sale_getProblems - WHERE shipped BETWEEN util.VN_CURDATE() - AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_problems ( - ticketFk INT(11), - saleFk INT(11), - isFreezed INTEGER(1) DEFAULT 0, - risk DECIMAL(10,1) DEFAULT 0, - hasRisk TINYINT(1) DEFAULT 0, - hasHighRisk TINYINT(1) DEFAULT 0, - hasTicketRequest INTEGER(1) DEFAULT 0, - itemShortage VARCHAR(255), - isTaxDataChecked INTEGER(1) DEFAULT 1, - itemDelay VARCHAR(255), - itemLost VARCHAR(255), - hasComponentLack INTEGER(1), - hasRounding VARCHAR(255), - isTooLittle BOOL DEFAULT FALSE, - isVip BOOL DEFAULT FALSE, - PRIMARY KEY (ticketFk, saleFk) - ) ENGINE = MEMORY; - - INSERT INTO tmp.sale_problems(ticketFk, - saleFk, - isFreezed, - risk, - hasRisk, - hasHighRisk, - hasTicketRequest, - isTaxDataChecked, - hasComponentLack, - isTooLittle) - SELECT sgp.ticketFk, - s.id, - IF(FIND_IN_SET('isFreezed', t.problem), TRUE, FALSE) isFreezed, - t.risk, - IF(FIND_IN_SET('hasRisk', t.problem), TRUE, FALSE) hasRisk, - IF(FIND_IN_SET('hasHighRisk', t.problem), TRUE, FALSE) hasHighRisk, - IF(FIND_IN_SET('hasTicketRequest', t.problem), TRUE, FALSE) hasTicketRequest, - IF(FIND_IN_SET('isTaxDataChecked', t.problem), FALSE, TRUE) isTaxDataChecked, - IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack, - IF(FIND_IN_SET('isTooLittle', t.problem) - AND util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE, - TRUE, FALSE) isTooLittle - FROM tmp.sale_getProblems sgp - JOIN ticket t ON t.id = sgp.ticketFk - LEFT JOIN sale s ON s.ticketFk = t.id - LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk - AND zc.dated = util.VN_CURDATE() - WHERE s.problem <> '' OR t.problem <> '' OR t.risk - GROUP BY t.id, s.id; - - INSERT INTO tmp.sale_problems(ticketFk, isVip) - SELECT sgp.ticketFk, TRUE - FROM tmp.sale_getProblems sgp - JOIN client c ON c.id = sgp.clientFk - WHERE c.businessTypeFk = 'VIP' - ON DUPLICATE KEY UPDATE isVIP = TRUE; - - CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse - (INDEX (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT ish.itemFk itemFk, - SUM(ish.visible) visible, - s.warehouseFk warehouseFk - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - GROUP BY ish.itemFk, s.warehouseFk; - - -- Disponible, faltas, inventario y retrasos - OPEN vCursor; - l: LOOP - SET vDone = FALSE; - FETCH vCursor INTO vWarehouseFk, vDate; - - IF vDone THEN - LEAVE l; - END IF; - - -- Disponible: no va a haber suficiente producto para preparar todos los pedidos - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); - - -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida - CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); - - INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk) - SELECT ticketFk, problem, saleFk - FROM ( - SELECT sgp.ticketFk, - LEFT(CONCAT('F: ', GROUP_CONCAT(i.id, ' ', i.longName, ' ')), 250) problem, - s.id saleFk - FROM tmp.sale_getProblems sgp - JOIN ticket t ON t.id = sgp.ticketFk - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = i.id - AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id - AND issw.warehouseFk = t.warehouseFk - WHERE IFNULL(v.visible, 0) < s.quantity - AND IFNULL(av.available, 0) < s.quantity - AND IFNULL(issw.visible, 0) < s.quantity - AND NOT s.isPicked - AND NOT s.reserved - AND ic.merchandise - AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouseFk - GROUP BY sgp.ticketFk) sub - ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk; - - -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida - INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk) - SELECT ticketFk, problem, saleFk - FROM ( - SELECT sgp.ticketFk, - LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem, - s.id saleFk - FROM tmp.sale_getProblems sgp - JOIN ticket t ON t.id = sgp.ticketFk - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk - AND v.calc_id = vVisibleCache - LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id - AND issw.warehouseFk = t.warehouseFk - WHERE IFNULL(v.visible, 0) >= s.quantity - AND IFNULL(issw.visible, 0) < s.quantity - AND s.quantity > 0 - AND NOT s.isPicked - AND NOT s.reserved - AND ic.merchandise - AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouseFk - GROUP BY sgp.ticketFk - ) sub - ON DUPLICATE KEY UPDATE itemLost = sub.problem, saleFk = sub.saleFk; - - -- Retraso: Disponible suficiente, pero no visible ni ubicado - INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk) - SELECT ticketFk, problem, saleFk - FROM ( - SELECT sgp.ticketFk, - LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem, - s.id saleFk - FROM tmp.sale_getProblems sgp - JOIN ticket t ON t.id = sgp.ticketFk - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk - AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id - AND issw.warehouseFk = t.warehouseFk - WHERE IFNULL(v.visible, 0) < s.quantity - AND IFNULL(av.available, 0) >= s.quantity - AND IFNULL(issw.visible, 0) < s.quantity - AND s.quantity > 0 - AND NOT s.isPicked - AND NOT s.reserved - AND ic.merchandise - AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouseFk - GROUP BY sgp.ticketFk - ) sub - ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; - - -- Redondeo: cantidad incorrecta con respecto al grouping - CALL buy_getUltimate(NULL, vWarehouseFk, vDate); - INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk) - SELECT ticketFk, problem, saleFk - FROM ( - SELECT sgp.ticketFk, - s.id saleFk, - LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,'') SEPARATOR ', '), 250) problem - FROM tmp.sale_getProblems sgp - JOIN ticket t ON t.id = sgp.ticketFk - AND t.warehouseFk = vWarehouseFk - JOIN sale s ON s.ticketFk = sgp.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - JOIN buy b ON b.id = bu.buyFk - WHERE MOD(s.quantity, b.`grouping`) - GROUP BY sgp.ticketFk - )sub - ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk; - - DROP TEMPORARY TABLE tmp.buyUltimate; - END LOOP; - CLOSE vCursor; - - DROP TEMPORARY TABLE tItemShelvingStock_byWarehouse; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/sale_getProblemsByTicket.sql b/db/routines/vn/procedures/sale_getProblemsByTicket.sql index ff419989d..af69e8430 100644 --- a/db/routines/vn/procedures/sale_getProblemsByTicket.sql +++ b/db/routines/vn/procedures/sale_getProblemsByTicket.sql @@ -1,5 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTicket`(IN vTicketFk INT, IN vIsTodayRelative TINYINT(1)) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTicket`( + IN vTicketFk INT, + IN vIsTodayRelative TINYINT(1) +) BEGIN /** * Calcula los problemas de cada venta @@ -7,19 +10,17 @@ BEGIN * * @return Problems result */ - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped - FROM ticket t - WHERE t.id = vTicketFk; + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT vTicketFk ticketFk; - CALL sale_getProblems(vIsTodayRelative); + CALL ticket_getProblems(vIsTodayRelative); - SELECT * FROM tmp.sale_problems; + SELECT * FROM tmp.saleProblems; DROP TEMPORARY TABLE - tmp.sale_getProblems, - tmp.sale_problems; + tmp.ticket, + tmp.ticketProblems; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index 1851bce47..00a8ee727 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -1,53 +1,216 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getProblems`( - vIsTodayRelative tinyint(1) + vIsTodayRelative TINYINT(1) ) BEGIN /** * Calcula los problemas para un conjunto de tickets. * Agrupados por ticket * - * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular - * @return tmp.ticket_problems + * @table tmp.tmp.ticket(ticketFk) Identificadores de los tickets a calcular + * @return tmp.ticketProblems */ - CALL sale_getProblems(vIsTodayRelative); + DECLARE vWarehouseFk INT; + DECLARE vDate DATE; + DECLARE vAvailableCache INT; + DECLARE vVisibleCache INT; + DECLARE vDone BOOL; + DECLARE vCursor CURSOR FOR + SELECT DISTINCT t.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(t.shipped)) + FROM tmp.ticket t + JOIN ticket t ON t.id = t.ticketFk + WHERE t.shipped BETWEEN util.VN_CURDATE() + AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY); - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems - (PRIMARY KEY (ticketFk)) + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tmp.saleProblems( + ticketFk INT(11), + saleFk INT(11), + hasItemShortage BOOL DEFAULT FALSE, + hasItemLost BOOL DEFAULT FALSE, + hasItemDelay BOOL DEFAULT FALSE, + hasRounding BOOL DEFAULT FALSE, + PRIMARY KEY (ticketFk, saleFk) + ) ENGINE = MEMORY; + + CREATE OR REPLACE TEMPORARY TABLE tItemShelving + (INDEX (itemFk, warehouseFk)) ENGINE = MEMORY - SELECT ticketFk, - MAX(isFreezed) isFreezed, - MAX(risk) risk, - MAX(hasRisk) hasRisk, - MAX(hasHighRisk) hasHighRisk, - MAX(hasTicketRequest) hasTicketRequest, - MAX(itemShortage) itemShortage, - MIN(isTaxDataChecked) isTaxDataChecked, - MAX(hasComponentLack) hasComponentLack, - MAX(isTooLittle) isTooLittle, - MAX(itemDelay) itemDelay, - MAX(hasRounding) hasRounding, - MAX(itemLost) itemLost, - MAX(isVip) isVip, - 0 totalProblems - FROM tmp.sale_problems - GROUP BY ticketFk; + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, s.warehouseFk; + + -- Disponible, faltas, inventario y retrasos + OPEN vCursor; + l: LOOP + SET vDone = FALSE; + FETCH vCursor INTO vWarehouseFk, vDate; - UPDATE tmp.ticket_problems - SET totalProblems = ( - (isFreezed) + - (hasHighRisk) + - (hasTicketRequest) + - (!isTaxDataChecked) + - (hasComponentLack) + - (itemDelay IS NOT NULL) + - (isTooLittle) + - (itemLost IS NOT NULL) + - (hasRounding IS NOT NULL) + - (itemShortage IS NOT NULL) + - (isVip) - ); + IF vDone THEN + LEAVE l; + END IF; + + -- Disponible: no va a haber suficiente producto para preparar todos los pedidos + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); + + -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida + CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); - DROP TEMPORARY TABLE tmp.sale_problems; + INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasItemShortage) + SELECT tt.ticketFk, s.id, TRUE + FROM tmp.ticket tt + JOIN ticket t ON t.id = tt.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelving tis ON tis.itemFk = i.id + AND tis.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) < s.quantity + AND IFNULL(av.available, 0) < s.quantity + AND IFNULL(tis.visible, 0) < s.quantity + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY s.id; + + -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida + INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasItemLost) + SELECT tt.ticketFk, s.id, TRUE + FROM tmp.ticket tt + JOIN ticket t ON t.id = tt.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelving tis ON tis.itemFk = i.id + AND tis.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) >= s.quantity + AND IFNULL(tis.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY s.id + ON DUPLICATE KEY UPDATE hasItemLost = TRUE; + + -- Retraso: Disponible suficiente, pero no visible ni ubicado + INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasItemDelay) + SELECT tt.ticketFk, s.id, TRUE + FROM tmp.ticket tt + JOIN ticket t ON t.id = tt.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelving tis ON tis.itemFk = i.id + AND tis.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) < s.quantity + AND IFNULL(av.available, 0) >= s.quantity + AND IFNULL(tis.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY s.id + ON DUPLICATE KEY UPDATE hasItemDelay = TRUE; + + -- Redondeo: cantidad incorrecta con respecto al grouping + CALL buy_getUltimate(NULL, vWarehouseFk, vDate); + + INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasRounding) + SELECT tt.ticketFk, s.id, TRUE + FROM tmp.ticket tt + JOIN ticket t ON t.id = tt.ticketFk + AND t.warehouseFk = vWarehouseFk + JOIN sale s ON s.ticketFk = tt.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + JOIN buy b ON b.id = bu.buyFk + WHERE MOD(s.quantity, b.`grouping`) + GROUP BY s.id + ON DUPLICATE KEY UPDATE hasRounding = TRUE; + + DROP TEMPORARY TABLE tmp.buyUltimate; + END LOOP; + CLOSE vCursor; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketProblem ( + ticketFk INT(11), + isFreezed BOOL DEFAULT FALSE, + risk DECIMAL(10,1) DEFAULT 0, + hasRisk BOOL DEFAULT FALSE, + hasHighRisk BOOL DEFAULT FALSE, + hasTicketRequest BOOL DEFAULT FALSE, + isTaxDataChecked BOOL DEFAULT FALSE, + isTooLittle BOOL DEFAULT FALSE, + isVip BOOL DEFAULT FALSE, + hasItemShortage BOOL DEFAULT FALSE, + hasItemDelay BOOL DEFAULT FALSE, + hasItemLost BOOL DEFAULT FALSE, + hasComponentLack BOOL DEFAULT FALSE, + hasRounding BOOL DEFAULT FALSE, + PRIMARY KEY (ticketFk) + ) ENGINE = MEMORY + SELECT tt.ticketFk, + IF(FIND_IN_SET('isFreezed', t.problem), TRUE, FALSE) isFreezed, + t.risk, + IF(FIND_IN_SET('hasRisk', t.problem), TRUE, FALSE) hasRisk, + IF(FIND_IN_SET('hasHighRisk', t.problem), TRUE, FALSE) hasHighRisk, + IF(FIND_IN_SET('hasTicketRequest', t.problem), TRUE, FALSE) hasTicketRequest, + IF(FIND_IN_SET('isTaxDataChecked', t.problem), FALSE, TRUE) isTaxDataChecked, + IF(FIND_IN_SET('isTooLittle', t.problem) + AND util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE, + TRUE, FALSE) isTooLittle, + IF(c.businessTypeFk = 'VIP', TRUE, FALSE) isVip, + SUM(IFNULL(ts.hasItemShortage,0)) hasItemShortage, + SUM(IFNULL(ts.hasItemDelay,0)) hasItemDelay, + SUM(IFNULL(ts.hasItemLost,0)) hasItemLost, + IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack, + SUM(IFNULL(ts.hasRounding,0)) hasRounding, + LEFT(CONCAT('F: ',GROUP_CONCAT(CONCAT(i.id, ' ', i.longName) SEPARATOR ', ')), 250) itemShortage, + LEFT(CONCAT('R: ',GROUP_CONCAT(CONCAT(i2.id, ' ', i2.longName) SEPARATOR ', ')), 250) itemDelay, + LEFT(CONCAT('I: ',GROUP_CONCAT(CONCAT(i3.id, ' ', i3.longName) SEPARATOR ', ')), 250) itemLost, + LEFT(CONCAT('RE: ',GROUP_CONCAT(CONCAT(i4.id, ' ', i4.longName) SEPARATOR ', ')), 250) componentLack, + LEFT(CONCAT('RE: ',GROUP_CONCAT(CONCAT(i5.id, ' ', i5.longName) SEPARATOR ', ')), 250) rounding + FROM tmp.ticket tt + JOIN ticket t ON t.id = tt.ticketFk + JOIN client c ON c.id = t.clientFk + LEFT JOIN sale s ON s.ticketFk = t.id + LEFT JOIN tmp.saleProblems ts ON ts.saleFk = s.id + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + AND zc.dated = util.VN_CURDATE() + WHERE s.problem <> '' OR t.problem <> '' OR t.risk + GROUP BY t.id; + + DROP TEMPORARY TABLE tItemShelving; END$$ DELIMITER ; diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 927f49999..9b22cb2d2 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -239,10 +239,10 @@ module.exports = Self => { stmts.push(`SET SESSION optimizer_search_depth = @_optimizer_search_depth`); stmt = new ParameterizedSQL(` - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX (ticketFk)) ENGINE = MEMORY - SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped + SELECT f.id ticketFk FROM tmp.filter f LEFT JOIN alertLevel al ON al.id = f.alertLevel WHERE (al.code = 'FREE' OR f.alertLevel IS NULL) @@ -263,7 +263,7 @@ module.exports = Self => { stmts.push('CALL ticket_getWarnings()'); stmt = new ParameterizedSQL(` - UPDATE tmp.ticket_problems + UPDATE tmp.ticketProblems SET risk = IF(hasRisk, risk, 0) `); stmts.push(stmt); @@ -271,7 +271,7 @@ module.exports = Self => { stmt = new ParameterizedSQL(` SELECT * FROM tmp.filter f - LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id + LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id LEFT JOIN tmp.ticket_warnings tw ON tw.ticketFk = f.id `); stmts.push(stmt); @@ -376,8 +376,7 @@ module.exports = Self => { stmts.push(` DROP TEMPORARY TABLE tmp.filter, - tmp.ticket_problems, - tmp.sale_getProblems, + tmp.ticketProblem, tmp.sale_getWarnings, tmp.ticket_warnings `); diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index c98ddaab6..9ac239be7 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -293,10 +293,10 @@ module.exports = Self => { stmts.push(stmt); stmt = new ParameterizedSQL(` - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX (ticketFk)) ENGINE = MEMORY - SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped + SELECT f.id ticketFk FROM tmp.filter f LEFT JOIN alertLevel al ON al.id = f.alertLevel WHERE (al.code = 'FREE' OR f.alertLevel IS NULL) @@ -307,7 +307,7 @@ module.exports = Self => { stmts.push('CALL ticket_getProblems(FALSE)'); stmt = new ParameterizedSQL(` - UPDATE tmp.ticket_problems + UPDATE tmp.ticketProblems SET risk = IF(hasRisk, risk, 0) `); stmts.push(stmt); @@ -315,7 +315,7 @@ module.exports = Self => { stmt = new ParameterizedSQL(` SELECT f.*, tp.* FROM tmp.filter f - LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id + LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id `); if (args.problems != undefined && (!args.from && !args.to)) @@ -371,7 +371,7 @@ module.exports = Self => { stmts.push( `DROP TEMPORARY TABLE tmp.filter, - tmp.ticket_problems`); + tmp.ticketProblems`); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); diff --git a/modules/ticket/back/methods/ticket/getTicketsFuture.js b/modules/ticket/back/methods/ticket/getTicketsFuture.js index 247924591..1c31da057 100644 --- a/modules/ticket/back/methods/ticket/getTicketsFuture.js +++ b/modules/ticket/back/methods/ticket/getTicketsFuture.js @@ -146,10 +146,10 @@ module.exports = Self => { stmts.push(stmt); stmt = new ParameterizedSQL(` - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX (ticketFk)) ENGINE = MEMORY - SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped, f.lines, f.liters + SELECT f.id ticketFk FROM tmp.filter f LEFT JOIN alertLevel al ON al.id = f.alertLevel WHERE (al.code = 'FREE' OR f.alertLevel IS NULL) @@ -159,7 +159,7 @@ module.exports = Self => { stmts.push('CALL ticket_getProblems(FALSE)'); stmt = new ParameterizedSQL(` - UPDATE tmp.ticket_problems + UPDATE tmp.ticketProblems SET risk = IF(hasRisk, risk, 0) `); stmts.push(stmt); @@ -167,7 +167,7 @@ module.exports = Self => { stmt = new ParameterizedSQL(` SELECT f.*, tp.* FROM tmp.filter f - LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id + LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id `); if (args.problems != undefined && (!args.originScopeDays && !args.futureScopeDays)) @@ -217,7 +217,7 @@ module.exports = Self => { stmts.push( `DROP TEMPORARY TABLE tmp.filter, - tmp.ticket_problems`); + tmp.ticketProblems`); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); -- 2.40.1 From 750b83bb45efd8be2f95d148567a511a9288417e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 16 Sep 2024 19:03:12 +0200 Subject: [PATCH 2/8] fix: refs #7760 tmp.ticketIPT --- db/routines/vn/procedures/productionControl.sql | 2 +- db/routines/vn/procedures/ticket_getProblems.sql | 11 ++++++++--- .../monitor/back/methods/sales-monitor/salesFilter.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index 88ed42e83..b33224e80 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -105,7 +105,7 @@ proc: BEGIN AND DATE(t.shipped) = zc.dated LEFT JOIN ticketParking tp ON tp.ticketFk = t.id LEFT JOIN parking pk ON pk.id = tp.parkingFk - LEFT JOIN tmp.ticketProblem tpr ON tpr.ticketFk = tt.ticketFk + LEFT JOIN tmp.ticketProblems tpr ON tpr.ticketFk = tt.ticketFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index 00a8ee727..f718893eb 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -7,7 +7,7 @@ BEGIN * Calcula los problemas para un conjunto de tickets. * Agrupados por ticket * - * @table tmp.tmp.ticket(ticketFk) Identificadores de los tickets a calcular + * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular * @return tmp.ticketProblems */ DECLARE vWarehouseFk INT; @@ -163,7 +163,7 @@ BEGIN END LOOP; CLOSE vCursor; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketProblem ( + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketProblems ( ticketFk INT(11), isFreezed BOOL DEFAULT FALSE, risk DECIMAL(10,1) DEFAULT 0, @@ -199,13 +199,18 @@ BEGIN LEFT(CONCAT('F: ',GROUP_CONCAT(CONCAT(i.id, ' ', i.longName) SEPARATOR ', ')), 250) itemShortage, LEFT(CONCAT('R: ',GROUP_CONCAT(CONCAT(i2.id, ' ', i2.longName) SEPARATOR ', ')), 250) itemDelay, LEFT(CONCAT('I: ',GROUP_CONCAT(CONCAT(i3.id, ' ', i3.longName) SEPARATOR ', ')), 250) itemLost, - LEFT(CONCAT('RE: ',GROUP_CONCAT(CONCAT(i4.id, ' ', i4.longName) SEPARATOR ', ')), 250) componentLack, + LEFT(CONCAT('C: ',GROUP_CONCAT(CONCAT(i4.id, ' ', i4.longName) SEPARATOR ', ')), 250) componentLack, LEFT(CONCAT('RE: ',GROUP_CONCAT(CONCAT(i5.id, ' ', i5.longName) SEPARATOR ', ')), 250) rounding FROM tmp.ticket tt JOIN ticket t ON t.id = tt.ticketFk JOIN client c ON c.id = t.clientFk LEFT JOIN sale s ON s.ticketFk = t.id LEFT JOIN tmp.saleProblems ts ON ts.saleFk = s.id + LEFT JOIN item i ON i.id = s.itemFk AND ts.hasItemShortage + LEFT JOIN item i2 ON i2.id = s.itemFk AND ts.hasItemDelay + LEFT JOIN item i3 ON i3.id = s.itemFk AND ts.hasItemLost + LEFT JOIN item i4 ON i4.id = s.itemFk AND FIND_IN_SET('hasComponentLack', s.problem) + LEFT JOIN item i5 ON i5.id = s.itemFk AND ts.hasRounding LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = util.VN_CURDATE() WHERE s.problem <> '' OR t.problem <> '' OR t.risk diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 9b22cb2d2..70c750ef5 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -376,7 +376,7 @@ module.exports = Self => { stmts.push(` DROP TEMPORARY TABLE tmp.filter, - tmp.ticketProblem, + tmp.ticketProblems, tmp.sale_getWarnings, tmp.ticket_warnings `); -- 2.40.1 From 712bfe73680a149bb6b292a18ef99a058db66616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 19 Sep 2024 20:15:38 +0200 Subject: [PATCH 3/8] fix: refs #7965 UnifyProblems --- .../vn/procedures/productionControl.sql | 61 +++--- .../vn/procedures/sale_getProblems.sql | 168 +++++++++++++++++ .../procedures/sale_getProblemsByTicket.sql | 19 +- .../vn/procedures/ticket_getProblems.sql | 177 ++---------------- 4 files changed, 226 insertions(+), 199 deletions(-) create mode 100644 db/routines/vn/procedures/sale_getProblems.sql diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index b33224e80..294ac3486 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -36,6 +36,19 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.productionBuffer (PRIMARY KEY(ticketFk), previaParking VARCHAR(255)) ENGINE = MEMORY + WITH saleProblemsDescription AS( + SELECT s.ticketFk, + LEFT(CONCAT('F: ', GROUP_CONCAT(CONCAT(i.id, ' ', i.longName) SEPARATOR ', ')), 250) itemShortage, + LEFT(CONCAT('R: ', GROUP_CONCAT(CONCAT(i2.id, ' ', i2.longName) SEPARATOR ', ')), 250) itemDelay, + LEFT(CONCAT('I: ', GROUP_CONCAT(CONCAT(i3.id, ' ', i3.longName) SEPARATOR ', ')), 250) itemLost + FROM tmp.saleProblems sp + JOIN vn.sale s ON s.id = sp.saleFk + LEFT JOIN vn.item i ON i.id = s.itemFk AND sp.hasItemShortage + LEFT JOIN vn.item i2 ON i2.id = s.itemFk AND sp.hasItemDelay + LEFT JOIN vn.item i3 ON i3.id = s.itemFk AND sp.hasItemLost + WHERE hasItemShortage OR hasItemDelay OR hasItemLost + GROUP BY s.ticketFk + ) SELECT tt.ticketFk, t.clientFk, t.warehouseFk, @@ -55,9 +68,9 @@ proc: BEGIN 0 `lines`, CAST( 0 AS DECIMAL(5,2)) m3, CAST( 0 AS DECIMAL(5,2)) preparationRate, - TRIM(CAST(CONCAT( IFNULL(tpr.itemShortage, ''), - IFNULL(tpr.itemDelay, ''), - IFNULL(tpr.itemLost, ''), + TRIM(CAST(CONCAT( IFNULL(sp.itemShortage, ''), + IFNULL(sp.itemDelay, ''), + IFNULL(sp.itemLost, ''), IF(tpr.isFreezed, ' CONGELADO',''), IF(tpr.hasHighRisk, ' RIESGO',''), IF(tpr.hasTicketRequest, ' COD 100',''), @@ -85,30 +98,31 @@ proc: BEGIN ag.isOwn, rm.bufferFk FROM tmp.productionTicket tt - JOIN ticket t ON tt.ticketFk = t.id - JOIN alertLevel al ON al.code = 'FREE' - LEFT JOIN ticketStateToday tst ON tst.ticketFk = t.id - LEFT JOIN `state` st ON st.id = tst.state - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker wk ON wk.id = c.salesPersonFk - JOIN address a ON a.id = t.addressFk - LEFT JOIN province p ON p.id = a.provinceFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - JOIN agency ag ON ag.id = am.agencyFk - LEFT JOIN ticketState tls ON tls.ticketFk = tt.ticketFk - LEFT JOIN ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk - LEFT JOIN worker w ON w.id = tls.userFk - LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN `zone` z ON z.id = t.zoneFk - LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + JOIN vn.ticket t ON tt.ticketFk = t.id + JOIN vn.alertLevel al ON al.code = 'FREE' + LEFT JOIN vn.ticketStateToday tst ON tst.ticketFk = t.id + LEFT JOIN vn.`state` st ON st.id = tst.state + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk + JOIN vn.address a ON a.id = t.addressFk + LEFT JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN vn.agency ag ON ag.id = am.agencyFk + LEFT JOIN vn.ticketState tls ON tls.ticketFk = tt.ticketFk + LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk + LEFT JOIN vn.worker w ON w.id = tls.userFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND DATE(t.shipped) = zc.dated - LEFT JOIN ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN parking pk ON pk.id = tp.parkingFk + LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id + LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk LEFT JOIN tmp.ticketProblems tpr ON tpr.ticketFk = tt.ticketFk + LEFT JOIN saleProblemsDescription sp ON sp.ticketFk = tt.ticketFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); - + UPDATE tmp.productionBuffer pb JOIN ( SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking @@ -260,6 +274,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.productionTicket, tmp.ticketProblems, + tmp.saleProblems, tmp.ticketWithPrevia, tItemShelvingStock, tItemPackingType; diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql new file mode 100644 index 000000000..a8388034f --- /dev/null +++ b/db/routines/vn/procedures/sale_getProblems.sql @@ -0,0 +1,168 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblems`( + vIsTodayRelative TINYINT(1) +) +BEGIN +/** + * Calcula los problemas para un conjunto de sale + * + * @table tmp.sale(saleFk) Identificadores de los sale a calcular + * @return tmp.saleProblems + */ + DECLARE vWarehouseFk INT; + DECLARE vDate DATE; + DECLARE vAvailableCache INT; + DECLARE vVisibleCache INT; + DECLARE vDone BOOL; + DECLARE vCursor CURSOR FOR + SELECT t.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(t.shipped)) dated + FROM tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + JOIN ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN util.VN_CURDATE() + AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY) + GROUP BY warehouseFk, dated; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tmp.saleProblems( + saleFk INT(11), + hasItemShortage BOOL DEFAULT FALSE, + hasItemLost BOOL DEFAULT FALSE, + hasItemDelay BOOL DEFAULT FALSE, + hasRounding BOOL DEFAULT FALSE, + PRIMARY KEY (saleFk) + ) ENGINE = MEMORY; + + CREATE OR REPLACE TEMPORARY TABLE tItemShelving + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, s.warehouseFk; + + -- Disponible, faltas, inventario y retrasos + OPEN vCursor; + l: LOOP + SET vDone = FALSE; + FETCH vCursor INTO vWarehouseFk, vDate; + + IF vDone THEN + LEAVE l; + END IF; + + -- Disponible: no va a haber suficiente producto para preparar todos los pedidos + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); + + -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida + CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); + + INSERT INTO tmp.saleProblems(saleFk, hasItemShortage) + SELECT s.id, TRUE + FROM tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelving tis ON tis.itemFk = i.id + AND tis.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) < s.quantity + AND IFNULL(av.available, 0) < s.quantity + AND IFNULL(tis.visible, 0) < s.quantity + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY s.id; + + -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida + INSERT INTO tmp.saleProblems(saleFk, hasItemLost) + SELECT s.id, TRUE + FROM tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelving tis ON tis.itemFk = i.id + AND tis.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) >= s.quantity + AND IFNULL(tis.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY s.id + ON DUPLICATE KEY UPDATE hasItemLost = TRUE; + + -- Retraso: Disponible suficiente, pero no visible ni ubicado + INSERT INTO tmp.saleProblems(saleFk, hasItemDelay) + SELECT s.id, TRUE + FROM tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelving tis ON tis.itemFk = i.id + AND tis.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) < s.quantity + AND IFNULL(av.available, 0) >= s.quantity + AND IFNULL(tis.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY s.id + ON DUPLICATE KEY UPDATE hasItemDelay = TRUE; + + -- Redondeo: cantidad incorrecta con respecto al grouping + CALL buy_getUltimate(NULL, vWarehouseFk, vDate); + + INSERT INTO tmp.saleProblems(saleFk, hasRounding) + SELECT s.id, TRUE + FROM tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + JOIN ticket t ON t.id = s.ticketFk + AND t.warehouseFk = vWarehouseFk + JOIN item i ON i.id = s.itemFk + JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + JOIN buy b ON b.id = bu.buyFk + WHERE MOD(s.quantity, b.`grouping`) + GROUP BY s.id + ON DUPLICATE KEY UPDATE hasRounding = TRUE; + + DROP TEMPORARY TABLE tmp.buyUltimate; + END LOOP; + CLOSE vCursor; + + DROP TEMPORARY TABLE tItemShelving, tmp.sale; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_getProblemsByTicket.sql b/db/routines/vn/procedures/sale_getProblemsByTicket.sql index af69e8430..708938cba 100644 --- a/db/routines/vn/procedures/sale_getProblemsByTicket.sql +++ b/db/routines/vn/procedures/sale_getProblemsByTicket.sql @@ -5,22 +5,19 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTic ) BEGIN /** - * Calcula los problemas de cada venta - * para un conjunto de tickets. + * Calcula los problemas de cada venta para un tickets. * * @return Problems result */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT vTicketFk ticketFk; + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX (saleFk)) + ENGINE = MEMORY + SELECT id saleFk FROM sale WHERE ticketFk = vTicketFk; - CALL ticket_getProblems(vIsTodayRelative); + CALL sale_getProblems(vIsTodayRelative); - SELECT * FROM tmp.saleProblems; + SELECT * FROM tmp.saleProblems; - DROP TEMPORARY TABLE - tmp.ticket, - tmp.ticketProblems; + DROP TEMPORARY TABLE tmp.saleProblems; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index f718893eb..c5a1532ff 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -5,163 +5,23 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getProblems`( BEGIN /** * Calcula los problemas para un conjunto de tickets. - * Agrupados por ticket * * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular - * @return tmp.ticketProblems + * @return tmp.ticketProblems, tmp.saleProblems */ - DECLARE vWarehouseFk INT; - DECLARE vDate DATE; - DECLARE vAvailableCache INT; - DECLARE vVisibleCache INT; - DECLARE vDone BOOL; - DECLARE vCursor CURSOR FOR - SELECT DISTINCT t.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(t.shipped)) - FROM tmp.ticket t - JOIN ticket t ON t.id = t.ticketFk - WHERE t.shipped BETWEEN util.VN_CURDATE() - AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - CREATE OR REPLACE TEMPORARY TABLE tmp.saleProblems( - ticketFk INT(11), + CREATE OR REPLACE TEMPORARY TABLE tmp.sale ( saleFk INT(11), - hasItemShortage BOOL DEFAULT FALSE, - hasItemLost BOOL DEFAULT FALSE, - hasItemDelay BOOL DEFAULT FALSE, - hasRounding BOOL DEFAULT FALSE, - PRIMARY KEY (ticketFk, saleFk) - ) ENGINE = MEMORY; - - CREATE OR REPLACE TEMPORARY TABLE tItemShelving - (INDEX (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT ish.itemFk itemFk, - SUM(ish.visible) visible, - s.warehouseFk warehouseFk - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - GROUP BY ish.itemFk, s.warehouseFk; - - -- Disponible, faltas, inventario y retrasos - OPEN vCursor; - l: LOOP - SET vDone = FALSE; - FETCH vCursor INTO vWarehouseFk, vDate; - - IF vDone THEN - LEAVE l; - END IF; - - -- Disponible: no va a haber suficiente producto para preparar todos los pedidos - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); - - -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida - CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); - - INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasItemShortage) - SELECT tt.ticketFk, s.id, TRUE - FROM tmp.ticket tt - JOIN ticket t ON t.id = tt.ticketFk - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = i.id - AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - LEFT JOIN tItemShelving tis ON tis.itemFk = i.id - AND tis.warehouseFk = t.warehouseFk - WHERE IFNULL(v.visible, 0) < s.quantity - AND IFNULL(av.available, 0) < s.quantity - AND IFNULL(tis.visible, 0) < s.quantity - AND NOT s.isPicked - AND NOT s.reserved - AND ic.merchandise - AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouseFk + PRIMARY KEY (saleFk) + ) ENGINE = MEMORY + SELECT DISTINCT s.id saleFk + FROM tmp.ticket tt + JOIN ticket t ON t.id = tt.ticketFk + JOIN sale s ON s.ticketFk = t.id + WHERE t.shipped BETWEEN util.VN_CURDATE() + AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY) GROUP BY s.id; - -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida - INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasItemLost) - SELECT tt.ticketFk, s.id, TRUE - FROM tmp.ticket tt - JOIN ticket t ON t.id = tt.ticketFk - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk - AND v.calc_id = vVisibleCache - LEFT JOIN tItemShelving tis ON tis.itemFk = i.id - AND tis.warehouseFk = t.warehouseFk - WHERE IFNULL(v.visible, 0) >= s.quantity - AND IFNULL(tis.visible, 0) < s.quantity - AND s.quantity > 0 - AND NOT s.isPicked - AND NOT s.reserved - AND ic.merchandise - AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouseFk - GROUP BY s.id - ON DUPLICATE KEY UPDATE hasItemLost = TRUE; - - -- Retraso: Disponible suficiente, pero no visible ni ubicado - INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasItemDelay) - SELECT tt.ticketFk, s.id, TRUE - FROM tmp.ticket tt - JOIN ticket t ON t.id = tt.ticketFk - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk - AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - LEFT JOIN tItemShelving tis ON tis.itemFk = i.id - AND tis.warehouseFk = t.warehouseFk - WHERE IFNULL(v.visible, 0) < s.quantity - AND IFNULL(av.available, 0) >= s.quantity - AND IFNULL(tis.visible, 0) < s.quantity - AND s.quantity > 0 - AND NOT s.isPicked - AND NOT s.reserved - AND ic.merchandise - AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouseFk - GROUP BY s.id - ON DUPLICATE KEY UPDATE hasItemDelay = TRUE; - - -- Redondeo: cantidad incorrecta con respecto al grouping - CALL buy_getUltimate(NULL, vWarehouseFk, vDate); - - INSERT INTO tmp.saleProblems(ticketFk, saleFk, hasRounding) - SELECT tt.ticketFk, s.id, TRUE - FROM tmp.ticket tt - JOIN ticket t ON t.id = tt.ticketFk - AND t.warehouseFk = vWarehouseFk - JOIN sale s ON s.ticketFk = tt.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - JOIN buy b ON b.id = bu.buyFk - WHERE MOD(s.quantity, b.`grouping`) - GROUP BY s.id - ON DUPLICATE KEY UPDATE hasRounding = TRUE; - - DROP TEMPORARY TABLE tmp.buyUltimate; - END LOOP; - CLOSE vCursor; + CALL sale_getProblems(vIsTodayRelative); CREATE OR REPLACE TEMPORARY TABLE tmp.ticketProblems ( ticketFk INT(11), @@ -195,27 +55,14 @@ BEGIN SUM(IFNULL(ts.hasItemDelay,0)) hasItemDelay, SUM(IFNULL(ts.hasItemLost,0)) hasItemLost, IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack, - SUM(IFNULL(ts.hasRounding,0)) hasRounding, - LEFT(CONCAT('F: ',GROUP_CONCAT(CONCAT(i.id, ' ', i.longName) SEPARATOR ', ')), 250) itemShortage, - LEFT(CONCAT('R: ',GROUP_CONCAT(CONCAT(i2.id, ' ', i2.longName) SEPARATOR ', ')), 250) itemDelay, - LEFT(CONCAT('I: ',GROUP_CONCAT(CONCAT(i3.id, ' ', i3.longName) SEPARATOR ', ')), 250) itemLost, - LEFT(CONCAT('C: ',GROUP_CONCAT(CONCAT(i4.id, ' ', i4.longName) SEPARATOR ', ')), 250) componentLack, - LEFT(CONCAT('RE: ',GROUP_CONCAT(CONCAT(i5.id, ' ', i5.longName) SEPARATOR ', ')), 250) rounding + SUM(IFNULL(ts.hasRounding,0)) hasRounding FROM tmp.ticket tt JOIN ticket t ON t.id = tt.ticketFk JOIN client c ON c.id = t.clientFk LEFT JOIN sale s ON s.ticketFk = t.id LEFT JOIN tmp.saleProblems ts ON ts.saleFk = s.id - LEFT JOIN item i ON i.id = s.itemFk AND ts.hasItemShortage - LEFT JOIN item i2 ON i2.id = s.itemFk AND ts.hasItemDelay - LEFT JOIN item i3 ON i3.id = s.itemFk AND ts.hasItemLost - LEFT JOIN item i4 ON i4.id = s.itemFk AND FIND_IN_SET('hasComponentLack', s.problem) - LEFT JOIN item i5 ON i5.id = s.itemFk AND ts.hasRounding LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = util.VN_CURDATE() - WHERE s.problem <> '' OR t.problem <> '' OR t.risk GROUP BY t.id; - - DROP TEMPORARY TABLE tItemShelving; END$$ DELIMITER ; -- 2.40.1 From 69cafd5a0457f7a6e5b50aa3b57e45132b49fa2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 30 Sep 2024 14:30:15 +0200 Subject: [PATCH 4/8] fix: refs #7965 UnifyProblems --- modules/monitor/back/methods/sales-monitor/salesFilter.js | 4 ++-- modules/ticket/back/methods/ticket/filter.js | 2 +- modules/ticket/back/methods/ticket/getTicketsFuture.js | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 70c750ef5..4f81f59b9 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -289,7 +289,7 @@ module.exports = Self => { {'tp.hasTicketRequest': true}, {'tp.hasComponentLack': true}, {'tp.isTaxDataChecked': false}, - {'tp.itemShortage': {neq: null}}, + {'tp.hasItemShortage': true}, {'tp.isTooLittle': true} ]}; } else if (hasProblems === false) { @@ -299,7 +299,7 @@ module.exports = Self => { {'tp.hasTicketRequest': false}, {'tp.hasComponentLack': false}, {'tp.isTaxDataChecked': true}, - {'tp.itemShortage': null}, + {'tp.hasItemShortage': false}, {'tp.isTooLittle': false} ]}; } diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 9ac239be7..77da770a2 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -345,7 +345,7 @@ module.exports = Self => { {'tp.isFreezed': hasProblem}, {'tp.hasRisk': hasProblem}, {'tp.hasTicketRequest': hasProblem}, - {'tp.itemShortage': range}, + {'tp.hasItemShortage': range}, {'tp.hasRounding': hasProblem} ]}; diff --git a/modules/ticket/back/methods/ticket/getTicketsFuture.js b/modules/ticket/back/methods/ticket/getTicketsFuture.js index 1c31da057..af3acff13 100644 --- a/modules/ticket/back/methods/ticket/getTicketsFuture.js +++ b/modules/ticket/back/methods/ticket/getTicketsFuture.js @@ -175,20 +175,17 @@ module.exports = Self => { let condition; let hasProblem; - let range; let hasWhere; switch (args.problems) { case true: condition = `or`; hasProblem = true; - range = {neq: null}; hasWhere = true; break; case false: condition = `and`; hasProblem = null; - range = null; hasWhere = true; break; } @@ -198,7 +195,7 @@ module.exports = Self => { {'tp.isFreezed': hasProblem}, {'tp.hasRisk': hasProblem}, {'tp.hasTicketRequest': hasProblem}, - {'tp.itemShortage': range}, + {'tp.hasItemShortage': hasProblem}, {'tp.hasComponentLack': hasProblem}, {'tp.isTooLittle': hasProblem}, {'tp.hasRounding': hasProblem} -- 2.40.1 From bb1695eac69b8449280bdc30a7108c2174c6dfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 30 Sep 2024 16:39:55 +0200 Subject: [PATCH 5/8] fix: refs #7965 UnifyProblems --- .../vn/procedures/ticket_getProblems.sql | 18 +++++++++++++++++- modules/ticket/back/methods/ticket/filter.js | 5 +---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index c5a1532ff..e58d49a5a 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -55,7 +55,8 @@ BEGIN SUM(IFNULL(ts.hasItemDelay,0)) hasItemDelay, SUM(IFNULL(ts.hasItemLost,0)) hasItemLost, IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack, - SUM(IFNULL(ts.hasRounding,0)) hasRounding + SUM(IFNULL(ts.hasRounding,0)) hasRounding, + 0 totalProblems FROM tmp.ticket tt JOIN ticket t ON t.id = tt.ticketFk JOIN client c ON c.id = t.clientFk @@ -64,5 +65,20 @@ BEGIN LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = util.VN_CURDATE() GROUP BY t.id; + + UPDATE tmp.ticketProblems + SET totalProblems = ( + (isFreezed) + + (hasHighRisk) + + (hasTicketRequest) + + (!isTaxDataChecked) + + (hasComponentLack) + + (hasItemDelay IS NOT NULL) + + (isTooLittle) + + (hasItemLost IS NOT NULL) + + (hasRounding IS NOT NULL) + + (hasItemShortage IS NOT NULL) + + (isVip) + ); END$$ DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index eccec735f..257121307 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -325,20 +325,17 @@ module.exports = Self => { let condition; let hasProblem; - let range; let hasWhere; switch (args.problems) { case true: condition = `or`; hasProblem = true; - range = {neq: null}; hasWhere = true; break; case false: condition = `and`; hasProblem = null; - range = null; hasWhere = true; break; } @@ -347,7 +344,7 @@ module.exports = Self => { {'tp.isFreezed': hasProblem}, {'tp.hasRisk': hasProblem}, {'tp.hasTicketRequest': hasProblem}, - {'tp.hasItemShortage': range}, + {'tp.hasItemShortage': hasProblem}, {'tp.hasRounding': hasProblem} ]}; -- 2.40.1 From 6a5cf1a57ff787e94032391c315b44f88c5aaa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 1 Oct 2024 15:46:51 +0200 Subject: [PATCH 6/8] fix: refs #7965 UnifyProblems --- db/dump/fixtures.before.sql | 34 +++--- .../vn/procedures/ticket_getProblems.sql | 101 +++++++++++------- .../sales-monitor/specs/salesFilter.spec.js | 2 +- .../back/methods/ticket/specs/filter.spec.js | 6 +- 4 files changed, 84 insertions(+), 59 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ffbc6a864..e8b89afa9 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1072,12 +1072,12 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (5, 1, 2, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 'hasComponentLack'), (6, 1, 3, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 'hasComponentLack'), (7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.74, 0, 0, 0, util.VN_CURDATE(), NULL), - (8, 4, 11, 'Melee weapon heavy shield 100cm', 10, 1.79, 0, 0, 0, util.VN_CURDATE(), NULL), + (8, 4, 11, 'Melee weapon heavy shield 100cm', 10, 1.79, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost,hasRounding'), (9, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), (10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, util.VN_CURDATE(), NULL), (11, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), - (12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE(), NULL), - (13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE(), NULL), + (12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost'), + (13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost'), (14, 1, 8, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), (15, 1, 19, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), (16, 2, 20, 'Melee weapon combat fist 15cm', 20, 7.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), @@ -1088,25 +1088,25 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (21, 1, 6, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 'hasComponentLack'), (22, 1, 7, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), (23, 1, 9, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (24, 1, 10, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (25, 4, 12, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (26, 4, 13, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (27, 4, 14, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (28, 4, 15, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (29, 4, 17, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (30, 4, 18, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE(), NULL), + (24, 1, 10, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack'), + (25, 4, 12, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), + (26, 4, 13, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), + (27, 4, 14, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack,hasItemLost'), + (28, 4, 15, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), + (29, 4, 17, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack'), + (30, 4, 18, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack'), + (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE(), 'hasRounding'), (32, 1, 24, 'Ranged weapon longbow 200cm', -1, 8.07, 0, 0, 0, util.VN_CURDATE(), NULL), (33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE(), NULL), - (34, 4, 28, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (35, 4, 29, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), + (34, 4, 28, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), + (35, 4, 29, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), (37, 4, 31, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), NULL), - (36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), + (36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), (38, 2, 32, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 'hasComponentLack'), (39, 1, 32, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (40, 2, 34, 'Melee weapon combat fist 15cm', 10.00, 3.91, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (41, 2, 35, 'Melee weapon combat fist 15cm', 8.00, 3.01, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'), - (42, 2, 36, 'Melee weapon combat fist 15cm', 6.00, 2.50, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'); + (40, 2, 34, 'Melee weapon combat fist 15cm', 10.00, 3.91, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'), + (41, 2, 35, 'Melee weapon combat fist 15cm', 8.00, 3.01, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasRounding,hasItemLost'), + (42, 2, 36, 'Melee weapon combat fist 15cm', 6.00, 2.50, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasRounding,hasItemLost'); INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) VALUES diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index e58d49a5a..3855c3a1d 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -40,45 +40,70 @@ BEGIN hasRounding BOOL DEFAULT FALSE, PRIMARY KEY (ticketFk) ) ENGINE = MEMORY - SELECT tt.ticketFk, - IF(FIND_IN_SET('isFreezed', t.problem), TRUE, FALSE) isFreezed, - t.risk, - IF(FIND_IN_SET('hasRisk', t.problem), TRUE, FALSE) hasRisk, - IF(FIND_IN_SET('hasHighRisk', t.problem), TRUE, FALSE) hasHighRisk, - IF(FIND_IN_SET('hasTicketRequest', t.problem), TRUE, FALSE) hasTicketRequest, - IF(FIND_IN_SET('isTaxDataChecked', t.problem), FALSE, TRUE) isTaxDataChecked, - IF(FIND_IN_SET('isTooLittle', t.problem) - AND util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE, - TRUE, FALSE) isTooLittle, - IF(c.businessTypeFk = 'VIP', TRUE, FALSE) isVip, - SUM(IFNULL(ts.hasItemShortage,0)) hasItemShortage, - SUM(IFNULL(ts.hasItemDelay,0)) hasItemDelay, - SUM(IFNULL(ts.hasItemLost,0)) hasItemLost, - IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack, - SUM(IFNULL(ts.hasRounding,0)) hasRounding, - 0 totalProblems - FROM tmp.ticket tt - JOIN ticket t ON t.id = tt.ticketFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN sale s ON s.ticketFk = t.id - LEFT JOIN tmp.saleProblems ts ON ts.saleFk = s.id - LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk - AND zc.dated = util.VN_CURDATE() - GROUP BY t.id; + WITH hasItemShortage AS( + SELECT s.ticketFk + FROM tmp.saleProblems sp + JOIN vn.sale s ON s.id = sp.saleFk + WHERE sp.hasItemShortage + GROUP BY s.ticketFk + ),hasItemLost AS( + SELECT s.ticketFk + FROM tmp.saleProblems sp + JOIN vn.sale s ON s.id = sp.saleFk + WHERE sp.hasItemLost + GROUP BY s.ticketFk + ),hasRounding AS( + SELECT s.ticketFk + FROM tmp.saleProblems sp + JOIN vn.sale s ON s.id = sp.saleFk + WHERE sp.hasRounding + GROUP BY s.ticketFk + ), hasItemDelay AS( + SELECT s.ticketFk + FROM tmp.saleProblems sp + JOIN vn.sale s ON s.id = sp.saleFk + WHERE sp.hasItemDelay + GROUP BY s.ticketFk + ), hasComponentLack AS( + SELECT s.ticketFk + FROM tmp.saleProblems sp + JOIN vn.sale s ON s.id = sp.saleFk + WHERE FIND_IN_SET('hasComponentLack', s.problem) + GROUP BY s.ticketFk + )SELECT tt.ticketFk, + IF(FIND_IN_SET('isFreezed', t.problem), TRUE, FALSE) isFreezed, + t.risk, + IF(FIND_IN_SET('hasRisk', t.problem), TRUE, FALSE) hasRisk, + IF(FIND_IN_SET('hasHighRisk', t.problem), TRUE, FALSE) hasHighRisk, + IF(FIND_IN_SET('hasTicketRequest', t.problem), TRUE, FALSE) hasTicketRequest, + IF(FIND_IN_SET('isTaxDataChecked', t.problem), TRUE, FALSE) isTaxDataChecked, + IF(FIND_IN_SET('isTooLittle', t.problem) + AND util.VN_NOW() < (util.VN_CURDATE() + + INTERVAL HOUR(zc.`hour`) HOUR) + + INTERVAL MINUTE(zc.`hour`) MINUTE, + TRUE, FALSE) isTooLittle, + IF(c.businessTypeFk = 'VIP', TRUE, FALSE) isVip, + IF(his.ticketFk IS NULL, FALSE, TRUE) hasItemShortage, + IF(hid.ticketFk IS NULL, FALSE, TRUE) hasItemDelay, + IF(hil.ticketFk IS NULL, FALSE, TRUE) hasItemLost, + IF(hcl.ticketFk IS NULL, FALSE, TRUE) hasComponentLack, + IF(hr.ticketFk IS NULL, FALSE, TRUE) hasRounding, + 0 totalProblems + FROM tmp.ticket tt + JOIN vn.ticket t ON t.id = tt.ticketFk + JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN hasItemShortage his ON his.ticketFk = t.id + LEFT JOIN hasItemLost hil ON hil.ticketFk = t.id + LEFT JOIN hasRounding hr ON hr.ticketFk = t.id + LEFT JOIN hasItemDelay hid ON hid.ticketFk = t.id + LEFT JOIN hasComponentLack hcl ON hcl.ticketFk = t.id + LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk + AND zc.dated = util.VN_CURDATE() + GROUP BY t.id; UPDATE tmp.ticketProblems - SET totalProblems = ( - (isFreezed) + - (hasHighRisk) + - (hasTicketRequest) + - (!isTaxDataChecked) + - (hasComponentLack) + - (hasItemDelay IS NOT NULL) + - (isTooLittle) + - (hasItemLost IS NOT NULL) + - (hasRounding IS NOT NULL) + - (hasItemShortage IS NOT NULL) + - (isVip) - ); + SET totalProblems = isFreezed + hasHighRisk + hasTicketRequest + + isTaxDataChecked + hasComponentLack + hasItemDelay + + isTooLittle + hasItemLost + hasRounding + hasItemShortage + isVip; END$$ DELIMITER ; diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index 738af5219..908c446a6 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -48,7 +48,7 @@ describe('SalesMonitor salesFilter()', () => { } }); - it('should now return the tickets matching the problems on false', async() => { + fit('should now return the tickets matching the problems on false', async() => { const tx = await models.SalesMonitor.beginTransaction({}); try { diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index d0edb24e3..44bfbb7e3 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -45,8 +45,8 @@ describe('ticket filter()', () => { ticket.isFreezed === true || ticket.hasRisk === true || ticket.hasTicketRequest === true || - (typeof ticket.hasRounding === 'string' && ticket.hasRounding.trim().length > 0) || - (typeof ticket.itemShortage === 'string' && ticket.itemShortage.trim().length > 0) + ticket.hasRounding === true || + ticket.hasItemShortage === true ); expect(hasProblemTicket).toBe(true); @@ -83,7 +83,7 @@ describe('ticket filter()', () => { expect(ticket.isFreezed).toEqual(null); expect(ticket.hasRisk).toEqual(null); expect(ticket.hasTicketRequest).toEqual(null); - expect(ticket.itemShortage).toEqual(null); + expect(ticket.hasItemShortage).toEqual(null); expect(ticket.hasRounding).toEqual(null); }); -- 2.40.1 From 99c70a533a3fed301ce3427d4b7e61558e0ee2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 2 Oct 2024 14:25:27 +0200 Subject: [PATCH 7/8] fix: test --- db/dump/fixtures.before.sql | 2 +- .../monitor/back/methods/sales-monitor/salesFilter.js | 4 ++-- .../methods/sales-monitor/specs/salesFilter.spec.js | 4 ++-- .../ticket/back/methods/ticket/specs/filter.spec.js | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 63d395e86..550a79015 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1076,7 +1076,7 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (9, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), (10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, util.VN_CURDATE(), NULL), (11, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), - (12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost'), + (12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE(), NULL), (13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost'), (14, 1, 8, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), (15, 1, 19, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL), diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 4f81f59b9..36e2c40aa 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -288,7 +288,7 @@ module.exports = Self => { {'tp.hasRisk': true}, {'tp.hasTicketRequest': true}, {'tp.hasComponentLack': true}, - {'tp.isTaxDataChecked': false}, + {'tp.isTaxDataChecked': true}, {'tp.hasItemShortage': true}, {'tp.isTooLittle': true} ]}; @@ -298,7 +298,7 @@ module.exports = Self => { {'tp.hasRisk': false}, {'tp.hasTicketRequest': false}, {'tp.hasComponentLack': false}, - {'tp.isTaxDataChecked': true}, + {'tp.isTaxDataChecked': false}, {'tp.hasItemShortage': false}, {'tp.isTooLittle': false} ]}; diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index 908c446a6..1b4616de7 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -48,7 +48,7 @@ describe('SalesMonitor salesFilter()', () => { } }); - fit('should now return the tickets matching the problems on false', async() => { + it('should now return the tickets matching the problems on false', async() => { const tx = await models.SalesMonitor.beginTransaction({}); try { @@ -68,7 +68,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toEqual(4); + expect(result.length).toEqual(5); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 44bfbb7e3..d06d02f23 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -42,11 +42,11 @@ describe('ticket filter()', () => { const result = await models.Ticket.filter(ctx, filter, options); const hasProblemTicket = result.some(ticket => - ticket.isFreezed === true || - ticket.hasRisk === true || - ticket.hasTicketRequest === true || - ticket.hasRounding === true || - ticket.hasItemShortage === true + ticket.isFreezed == true || + ticket.hasRisk == true || + ticket.hasTicketRequest == true || + ticket.hasRounding == true || + ticket.hasItemShortage == true ); expect(hasProblemTicket).toBe(true); -- 2.40.1 From 4e0a81464c6e0dc410d8c87091bbfe2f9aa06df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 2 Oct 2024 15:12:57 +0200 Subject: [PATCH 8/8] fix: test --- db/routines/vn/procedures/productionControl.sql | 1 + db/routines/vn/procedures/sale_getProblems.sql | 2 +- db/routines/vn/procedures/sale_getProblemsByTicket.sql | 4 +++- db/routines/vn/procedures/ticket_getProblems.sql | 2 ++ modules/monitor/back/methods/sales-monitor/salesFilter.js | 1 + modules/ticket/back/methods/ticket/filter.js | 1 + modules/ticket/back/methods/ticket/getTicketsFuture.js | 1 + 7 files changed, 10 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index 29abc8044..b9550d62c 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -283,6 +283,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.productionTicket, + tmp.ticket, tmp.ticketProblems, tmp.saleProblems, tmp.ticketWithPrevia, diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql index a8388034f..79b548c2c 100644 --- a/db/routines/vn/procedures/sale_getProblems.sql +++ b/db/routines/vn/procedures/sale_getProblems.sql @@ -163,6 +163,6 @@ BEGIN END LOOP; CLOSE vCursor; - DROP TEMPORARY TABLE tItemShelving, tmp.sale; + DROP TEMPORARY TABLE tItemShelving; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/sale_getProblemsByTicket.sql b/db/routines/vn/procedures/sale_getProblemsByTicket.sql index 708938cba..fdfd5c8bc 100644 --- a/db/routines/vn/procedures/sale_getProblemsByTicket.sql +++ b/db/routines/vn/procedures/sale_getProblemsByTicket.sql @@ -18,6 +18,8 @@ BEGIN SELECT * FROM tmp.saleProblems; - DROP TEMPORARY TABLE tmp.saleProblems; + DROP TEMPORARY TABLE + tmp.saleProblems, + tmp.sale; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index 3855c3a1d..fe77ed57b 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -105,5 +105,7 @@ BEGIN SET totalProblems = isFreezed + hasHighRisk + hasTicketRequest + isTaxDataChecked + hasComponentLack + hasItemDelay + isTooLittle + hasItemLost + hasRounding + hasItemShortage + isVip; + + DROP TEMPORARY TABLE tmp.sale; END$$ DELIMITER ; diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 36e2c40aa..27a308311 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -375,6 +375,7 @@ module.exports = Self => { stmts.push(` DROP TEMPORARY TABLE + tmp.ticket, tmp.filter, tmp.ticketProblems, tmp.sale_getWarnings, diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 257121307..3ca52337d 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -369,6 +369,7 @@ module.exports = Self => { stmts.push( `DROP TEMPORARY TABLE + tmp.ticket, tmp.filter, tmp.ticketProblems`); diff --git a/modules/ticket/back/methods/ticket/getTicketsFuture.js b/modules/ticket/back/methods/ticket/getTicketsFuture.js index af3acff13..88f40bc3e 100644 --- a/modules/ticket/back/methods/ticket/getTicketsFuture.js +++ b/modules/ticket/back/methods/ticket/getTicketsFuture.js @@ -213,6 +213,7 @@ module.exports = Self => { stmts.push( `DROP TEMPORARY TABLE + tmp.ticket, tmp.filter, tmp.ticketProblems`); -- 2.40.1