From d53f19b47dc765b478e559683bcf6a546a15b26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Apr 2024 17:01:14 +0200 Subject: [PATCH 01/13] feat: Turn problems into calculated columns --- .../vn/functions/sale_hasComponentLack.sql | 26 ++++++ .../vn/functions/ticket_isTooLittle.sql | 24 ++++++ .../vn/procedures/buy_getRoundingProblem.sql | 33 ++++++++ .../sale_getComponentLackProblem.sql | 21 +++++ .../sale_getComponentLackProblemComponent.sql | 25 ++++++ .../vn/procedures/sale_getRoundingProblem.sql | 34 ++++++++ db/routines/vn/procedures/sale_setProblem.sql | 17 ++++ .../vn/procedures/ticket_getFreezeProblem.sql | 25 ++++++ .../procedures/ticket_getRequestProblem.sql | 26 ++++++ .../vn/procedures/ticket_getRiskProblem.sql | 33 ++++++++ .../procedures/ticket_getRoundingProblem.sql | 33 ++++++++ .../ticket_getTaxDataCheckedProblem.sql | 26 ++++++ .../procedures/ticket_getTooLittleProblem.sql | 20 +++++ .../ticket_getTooLittleProblemConfig.sql | 21 +++++ .../ticket_getTooLittleProblemItemCost.sql | 26 ++++++ db/routines/vn/procedures/ticket_risk.sql | 82 +++++++++++++++++++ .../vn/procedures/ticket_setProblem.sql | 17 ++++ .../11000-grayAsparagus/00-firstScript.sql | 8 ++ 18 files changed, 497 insertions(+) create mode 100644 db/routines/vn/functions/sale_hasComponentLack.sql create mode 100644 db/routines/vn/functions/ticket_isTooLittle.sql create mode 100644 db/routines/vn/procedures/buy_getRoundingProblem.sql create mode 100644 db/routines/vn/procedures/sale_getComponentLackProblem.sql create mode 100644 db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql create mode 100644 db/routines/vn/procedures/sale_getRoundingProblem.sql create mode 100644 db/routines/vn/procedures/sale_setProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getFreezeProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getRequestProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getRiskProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getRoundingProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getTooLittleProblem.sql create mode 100644 db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql create mode 100644 db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql create mode 100644 db/routines/vn/procedures/ticket_risk.sql create mode 100644 db/routines/vn/procedures/ticket_setProblem.sql create mode 100644 db/versions/11000-grayAsparagus/00-firstScript.sql diff --git a/db/routines/vn/functions/sale_hasComponentLack.sql b/db/routines/vn/functions/sale_hasComponentLack.sql new file mode 100644 index 000000000..e066daca4 --- /dev/null +++ b/db/routines/vn/functions/sale_hasComponentLack.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE FUNCTION vn.sale_hasComponentLack(vSelf INT) + RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Comprueba si la línea de sale tiene todos lo componentes obligatorios + * + * @return BOOL + */ + DECLARE vHasComponentLack TINYINT(1); + + WITH componentRequired AS( + SELECT COUNT(*)total + FROM component + WHERE isRequired + )SELECT SUM(IF(c.isRequired, TRUE, FALSE)) <> cr.total INTO vHasComponentLack + FROM vn.sale s + JOIN componentRequired cr + LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id + LEFT JOIN vn.component c ON c.id = sc.componentFk + WHERE s.id = vSelf; + + RETURN vHasComponentLack; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/functions/ticket_isTooLittle.sql b/db/routines/vn/functions/ticket_isTooLittle.sql new file mode 100644 index 000000000..cd14d6bed --- /dev/null +++ b/db/routines/vn/functions/ticket_isTooLittle.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(vSelf INT) + RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Comprueba si el ticket es pequeño en función de los parámtros de configuración + * teniendo en cuenta el volumen y el importe + * + * @return BOOL + */ + DECLARE vIsTooLittle TINYINT(1); + + SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume + OR IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle + FROM ticket t + LEFT JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleVolume sv ON sv.ticketFk = t.id + JOIN volumeConfig vc + WHERE t.id = vSelf; + + RETURN vIsTooLittle; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/buy_getRoundingProblem.sql b/db/routines/vn/procedures/buy_getRoundingProblem.sql new file mode 100644 index 000000000..9a658d169 --- /dev/null +++ b/db/routines/vn/procedures/buy_getRoundingProblem.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getRoundingProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas de redondeo para las líneas de venta relacionadas con un buy + * + * @param vSelf Id de ticket + */ + DECLARE vWarehouseFk INT; + DECLARE vDated DATE; + + SELECT warehouseFk, DATE(shipped) + INTO vWarehouseFk, vDated + FROM ticket + WHERE id = vSelf; + + CALL buyUltimate(vWarehouseFk, vDated); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem + FROM ticket t + JOIN sale s ON s.ticketFk = tl.ticketFk + JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + JOIN buy b ON b.id = bu.buyFk + WHERE t.id = vSelf; + + CALL sale_setProblem('hasRounding'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getComponentLackProblem.sql b/db/routines/vn/procedures/sale_getComponentLackProblem.sql new file mode 100644 index 000000000..0f8b6b690 --- /dev/null +++ b/db/routines/vn/procedures/sale_getComponentLackProblem.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas + * con los componentes, verifica que esten o no todos los componenetes obligatorios + * + * @param vSelf Id del sale + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem; + + CALL sale_setProblem('hasComponentLack'); + + DROP TEMPORARY TABLE tmp.sale; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql b/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql new file mode 100644 index 000000000..e02f2a802 --- /dev/null +++ b/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblemComponent`( + vComponentFk INT +) +BEGIN +/** + * Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas + * con los componentes que derivan de cambios en la tabla vn.component + * + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT s.id saleFk, sale_hasComponentLack(s.id) hasProblem + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE t.shipped >= util.midnight() + AND sc.componentFk = vComponentFk; + + CALL sale_setProblem('hasComponentLack'); + + DROP TEMPORARY TABLE tmp.sale; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getRoundingProblem.sql b/db/routines/vn/procedures/sale_getRoundingProblem.sql new file mode 100644 index 000000000..7f8d29d87 --- /dev/null +++ b/db/routines/vn/procedures/sale_getRoundingProblem.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getRoundingProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas de redondeo para las líneas de venta + * + * @param vSelf Id de sale + */ + DECLARE vItemFk INT; + DECLARE vWarehouseFk INT; + DECLARE vDated DATE; + DECLARE vQuantity INT; + + SELECT s.itemFk, t.warehouseFk, DATE(t.shipped), s.quantity + INTO vItemFk, vWarehouseFk, vDated, vQuantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE s.id = vSelf; + + CALL buyUltimate(vWarehouseFk, vDated); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem + FROM tmp.buyUltimate bu + JOIN buy b ON b.id = bu.buyFk + WHERE bu.itemFk = vItemFk; + + CALL sale_setProblem('hasRounding'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql new file mode 100644 index 000000000..723d97a34 --- /dev/null +++ b/db/routines/vn/procedures/sale_setProblem.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`( + vProblemCode VARCHAR(25) +) +BEGIN +/** + * Actualiza en la tabla sale la columna problema + * @table tmp.sale(saleFk, hasProblem) Identificadores de los sales a actualizar + */ + UPDATE sale s + JOIN tmp.sale ts ON ts.saleFk = s.id + SET s.problem = CONCAT( + IF(ts.hasProblem, + CONCAT(s.problem, ',', vProblemCode), + REPLACE(s.problem, vProblemCode , ''))); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getFreezeProblem.sql b/db/routines/vn/procedures/ticket_getFreezeProblem.sql new file mode 100644 index 000000000..5e8422640 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getFreezeProblem.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`( + vClientFk INT +) +proc: BEGIN +/** + * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente + * se encuentra congelado o deja de estarlo + * + * @param vClientFk Id del cliente + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, NOT c.isFreezed hasProblem + FROM ticket t + JOIN client c ON c.id = t.clientFk + WHERE t.shipped >= util.midnight() + AND c.id = vClientFk; + + CALL ticket_setProblem('isFreezed'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRequestProblem.sql b/db/routines/vn/procedures/ticket_getRequestProblem.sql new file mode 100644 index 000000000..f866f0ad8 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getRequestProblem.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas cuando el ticket tiene una petición de compra pendiente o + * deja de tenerla + * @param vSelf Id del ticket de la petición de compra + */ + DECLARE vHasProblem BOOL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, COUNT(tr.id) hasProblem + FROM ticket t + LEFT JOIN ticketRequest tr ON tr.ticketFk = t.id + WHERE t.id = vSelf + AND isOK IS NULL; + + CALL ticket_setProblem('hasTicketRequest'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRiskProblem.sql b/db/routines/vn/procedures/ticket_getRiskProblem.sql new file mode 100644 index 000000000..73b5386cd --- /dev/null +++ b/db/routines/vn/procedures/ticket_getRiskProblem.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas para los tickets con riesgo + * + * @param vSelf Id del ticket + */ + DECLARE vHasRisk BOOL; + DECLARE vHasHighRisk BOOL; + + SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10)) + INTO vHasRisk, vHasHighRisk + FROM client c + JOIN ticket t ON t.clientFk = c.id + JOIN clientConfig cc + WHERE t.id = vSelf; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + SELECT vSelf ticketFk, vRisk hasProblem; + + CALL ticket_setProblem('hasRisk'); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + SELECT vSelf ticketFk, vHasHighRisk hasProblem; + + CALL ticket_setProblem('hasHighRisk'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRoundingProblem.sql b/db/routines/vn/procedures/ticket_getRoundingProblem.sql new file mode 100644 index 000000000..ca58aff20 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getRoundingProblem.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRoundingProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas de redondeo para las líneas de venta de un ticket + * + * @param vSelf Id de ticket + */ + DECLARE vWarehouseFk INT; + DECLARE vDated DATE; + + SELECT warehouseFk, DATE(shipped) + INTO vWarehouseFk, vDated + FROM ticket + WHERE id = vSelf; + + CALL buyUltimate(vWarehouseFk, vDated); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem + FROM ticket t + JOIN sale s ON s.ticketFk = tl.ticketFk + JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + JOIN buy b ON b.id = bu.buyFk + WHERE t.id = vSelf; + + CALL sale_setProblem('hasRounding'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql new file mode 100644 index 000000000..e82932035 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`( + vClientFk INT +) +proc: BEGIN +/** + * Actualiza los problemas de los ticket de hoy y a fututo + * cuyo cliente tenga o no los datos comprobados + * + * @param vClientFk Id del cliente + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, NOT c.isTaxDataChecked hasProblem + FROM ticket t + JOIN client c ON c.id = t.clientFk + WHERE t.shipped >= util.midnight() + AND c.id = vClientFk; + + CALL ticket_setProblem('isTaxDataChecked'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql b/db/routines/vn/procedures/ticket_getTooLittleProblem.sql new file mode 100644 index 000000000..ae08fefa7 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTooLittleProblem.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblem`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas cuando el ticket es demasiado pequeño o deja de serlo + * + * @param vSelf Id del ticket + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT vSelf ticketFk, ticket_isTooLittle(vSelf); + + CALL ticket_setProblem('isTooLittle'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql new file mode 100644 index 000000000..2a509c9cd --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemConfig`() +BEGIN +/** + * Actualiza los problemas cuando el ticket es demasiado pequeño o deja de serlo, que derivan + * del cambio en la tabla vn.volumeConfig + * + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem + FROM ticket t + WHERE t.shipped >= util.midnight() + GROUP BY t.id; + + CALL ticket_setProblem('isTooLittle'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql new file mode 100644 index 000000000..2e068bfb2 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemItemCost`( + vItemFk INT +) +BEGIN +/** + * Actualiza los problemas cuando el ticket es demasiado pequeño o deja de serlo, que derivan + * del cambio en la tabla vn.itemCost + * + * @param vItemFk Id del item + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + WHERE s.itemFk = vItemFk + AND t.shipped >= util.midnight() + GROUP BY t.id; + + CALL ticket_setProblem('isTooLittle'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_risk.sql b/db/routines/vn/procedures/ticket_risk.sql new file mode 100644 index 000000000..59f6888fa --- /dev/null +++ b/db/routines/vn/procedures/ticket_risk.sql @@ -0,0 +1,82 @@ +DELIMITER $$ +$$ +CREATE OR REPLACE PROCEDURE vn.ticket_risk(vClientFk INT) +BEGIN +/** + * Actualiza el riesgo de los tickets pendientes de un cliente + * + * @param vClientFk Id del cliente + */ + DECLARE vHasDebt BOOL; + + SELECT COUNT(*) INTO vHasDebt + FROM `client` + WHERE id = vClientFk + AND typeFk = 'normal'; + + IF vHasDebt THEN + + CREATE OR REPLACE TEMPORARY TABLE tTicketRisk + (KEY (ticketFk)) + ENGINE = MEMORY + WITH ticket AS( + SELECT id ticketFk, DATE(shipped) dated + FROM vn.ticket t + WHERE clientFk = vClientFk + AND refFk IS NULL + AND NOT isDeleted + AND totalWithoutVat <> 0 + ), dated AS( + SELECT MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started, + MAX(DATE(t.dated)) ended + FROM ticket t + JOIN vn.clientConfig cc + ), balance AS( + SELECT SUM(amount)amount + FROM ( + SELECT SUM(amount) amount + FROM vn.clientRisk + WHERE clientFk = vClientFk + UNION ALL + SELECT -(SUM(amount) / 100) amount + FROM hedera.tpvTransaction t + WHERE clientFk = vClientFk + AND receiptFk IS NULL + AND status = 'ok' + ) sub + ), uninvoiced AS( + SELECT DATE(t.shipped) dated, SUM(t.totalWithVat)amount + FROM vn.ticket t + JOIN dated d + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND t.shipped BETWEEN d.started AND d.ended + GROUP BY DATE(t.shipped) + ), receipt AS( + SELECT DATE(payed) dated, SUM(amountPaid) amount + FROM vn.receipt + WHERE clientFk = vClientFk + AND payed > util.VN_CURDATE() + GROUP BY DATE(payed) + ), risk AS( + SELECT ui.dated, + SUM(ui.amount) OVER (ORDER BY ui.dated) + + b.amount + + SUM(IFNULL(r.amount, 0)) amount + FROM balance b + JOIN uninvoiced ui + LEFT JOIN receipt r ON r.dated > ui.dated + GROUP BY ui.dated + ) + SELECT ti.ticketFk, r.amount + FROM ticket ti + JOIN risk r ON r.dated = ti.dated; + + UPDATE ticket t + JOIN tTicketRisk tr ON tr.ticketFk = t.id + SET t.risk = tr.amount; + + DROP TEMPORARY TABLE IF EXISTS tTicketRisk; + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql new file mode 100644 index 000000000..24bb97258 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setProblem.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( + vProblemCode VARCHAR(25) +) +BEGIN +/** + * Actualiza en la tabla ticket la columna problema + * @table tmp.ticket(ticketFk, hasProblem) Identificadores de los tickets a actualizar + */ + UPDATE ticket t + JOIN tmp.ticket tt ON tt.ticketFk = t.id + SET t.problem = CONCAT( + IF(tt.hasProblem, + CONCAT(problem, ',', vProblemCode), + REPLACE(problem, vProblemCode , ''))); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11000-grayAsparagus/00-firstScript.sql b/db/versions/11000-grayAsparagus/00-firstScript.sql new file mode 100644 index 000000000..38d6817bb --- /dev/null +++ b/db/versions/11000-grayAsparagus/00-firstScript.sql @@ -0,0 +1,8 @@ +ALTER TABLE vn.ticket DROP COLUMN IF EXISTS problem; +ALTER TABLE vn.sale DROP COLUMN IF EXISTS problem; +ALTER TABLE vn.ticket DROP COLUMN IF EXISTS risk; + +ALTER TABLE vn.ticket ADD IF NOT EXISTS problem SET('hasTicketRequest', 'isFreezed', 'hasRisk', 'hasHighRisk', 'isTaxDataChecked', 'isTooLittle')NOT NULL DEFAULT ''; +ALTER TABLE vn.sale ADD IF NOT EXISTS problem SET('hasItemShortage', 'hasComponentLack', 'hasItemDelay', 'hasRounding', 'hasItemLost')NOT NULL DEFAULT ''; +ALTER TABLE vn.ticket ADD IF NOT EXISTS risk DECIMAL(10,2) DEFAULT NULL NULL COMMENT 'cache calculada con el riesgo del cliente'; + From 7bbf113ffaaa8adef81e299914d159f84bb38203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Apr 2024 18:26:57 +0200 Subject: [PATCH 02/13] feat: Turn issues into calculated columns refs#7213 --- db/routines/vn/functions/sale_hasComponentLack.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/functions/sale_hasComponentLack.sql b/db/routines/vn/functions/sale_hasComponentLack.sql index e066daca4..6d1b4ad01 100644 --- a/db/routines/vn/functions/sale_hasComponentLack.sql +++ b/db/routines/vn/functions/sale_hasComponentLack.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE FUNCTION vn.sale_hasComponentLack(vSelf INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`sale_hasComponentLack`(vSelf INT) RETURNS tinyint(1) READS SQL DATA BEGIN @@ -12,7 +12,7 @@ BEGIN WITH componentRequired AS( SELECT COUNT(*)total - FROM component + FROM vn.component WHERE isRequired )SELECT SUM(IF(c.isRequired, TRUE, FALSE)) <> cr.total INTO vHasComponentLack FROM vn.sale s From c262805d337fc1f74dc785185e6aab5498a72ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Apr 2024 18:29:14 +0200 Subject: [PATCH 03/13] feat: Turn issues into calculated columns refs#7213 --- db/routines/vn/procedures/ticket_risk.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_risk.sql b/db/routines/vn/procedures/ticket_risk.sql index 59f6888fa..7dfe81211 100644 --- a/db/routines/vn/procedures/ticket_risk.sql +++ b/db/routines/vn/procedures/ticket_risk.sql @@ -1,6 +1,6 @@ DELIMITER $$ $$ -CREATE OR REPLACE PROCEDURE vn.ticket_risk(vClientFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_risk`(vClientFk INT) BEGIN /** * Actualiza el riesgo de los tickets pendientes de un cliente From 9ca1b9f104a5c37295b933d184f54e91a61c3d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 17 Apr 2024 15:02:58 +0200 Subject: [PATCH 04/13] feat: Turn issues into calculated columns refs#7213 --- db/routines/vn/procedures/ticket_risk.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticket_risk.sql b/db/routines/vn/procedures/ticket_risk.sql index 7dfe81211..af40bff63 100644 --- a/db/routines/vn/procedures/ticket_risk.sql +++ b/db/routines/vn/procedures/ticket_risk.sql @@ -1,6 +1,5 @@ DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_risk`(vClientFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_risk`(vClientFk INT) BEGIN /** * Actualiza el riesgo de los tickets pendientes de un cliente From 27e3ae897a010ea34b2d4a14cb119e6ce6cc94c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 2 May 2024 17:05:10 +0200 Subject: [PATCH 05/13] feat: Turn issues into calculated columns refs#7213 --- .../{ticket_risk.sql => client_risk.sql} | 17 ++++---- db/routines/vn/procedures/client_riskAll.sql | 27 +++++++++++++ .../sale_getComponentLackProblemAll.sql | 22 ++++++++++ .../vn/procedures/sale_getRoundingProblem.sql | 9 +++-- .../vn/procedures/ticket_getFreezeProblem.sql | 25 +++++------- .../procedures/ticket_getFreezeProblemAll.sql | 19 +++++++++ .../ticket_getFreezeProblemByClient.sql | 22 ++++++++++ .../procedures/ticket_getRequestProblem.sql | 24 ++++------- .../ticket_getRequestProblemAll.sql | 21 ++++++++++ .../ticket_getRequestProblemByTicket.sql | 24 +++++++++++ .../vn/procedures/ticket_getRiskProblem.sql | 2 +- .../procedures/ticket_getRiskProblemAll.sql | 40 +++++++++++++++++++ .../procedures/ticket_getRoundingProblem.sql | 1 + .../ticket_getTaxDataCheckedProblem.sql | 20 +++------- .../ticket_getTaxDataCheckedProblemAll.sql | 21 ++++++++++ ...icket_getTaxDataCheckedProblemByClient.sql | 26 ++++++++++++ .../procedures/ticket_getTooLittleProblem.sql | 2 +- .../ticket_getTooLittleProblemAll.sql | 19 +++++++++ .../ticket_getTooLittleProblemConfig.sql | 3 +- .../ticket_getTooLittleProblemItemCost.sql | 15 ++++--- .../vn/procedures/worker_updateBalance.sql | 4 +- 21 files changed, 292 insertions(+), 71 deletions(-) rename db/routines/vn/procedures/{ticket_risk.sql => client_risk.sql} (84%) create mode 100644 db/routines/vn/procedures/client_riskAll.sql create mode 100644 db/routines/vn/procedures/sale_getComponentLackProblemAll.sql create mode 100644 db/routines/vn/procedures/ticket_getFreezeProblemAll.sql create mode 100644 db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql create mode 100644 db/routines/vn/procedures/ticket_getRequestProblemAll.sql create mode 100644 db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql create mode 100644 db/routines/vn/procedures/ticket_getRiskProblemAll.sql create mode 100644 db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql create mode 100644 db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql create mode 100644 db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql diff --git a/db/routines/vn/procedures/ticket_risk.sql b/db/routines/vn/procedures/client_risk.sql similarity index 84% rename from db/routines/vn/procedures/ticket_risk.sql rename to db/routines/vn/procedures/client_risk.sql index af40bff63..6f170222e 100644 --- a/db/routines/vn/procedures/ticket_risk.sql +++ b/db/routines/vn/procedures/client_risk.sql @@ -1,16 +1,17 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_risk`(vClientFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_risk`( + vSelf INT) BEGIN /** * Actualiza el riesgo de los tickets pendientes de un cliente * - * @param vClientFk Id del cliente + * @param vSelf Id del cliente */ DECLARE vHasDebt BOOL; SELECT COUNT(*) INTO vHasDebt FROM `client` - WHERE id = vClientFk + WHERE id = vSelf AND typeFk = 'normal'; IF vHasDebt THEN @@ -21,7 +22,7 @@ BEGIN WITH ticket AS( SELECT id ticketFk, DATE(shipped) dated FROM vn.ticket t - WHERE clientFk = vClientFk + WHERE clientFk = vSelf AND refFk IS NULL AND NOT isDeleted AND totalWithoutVat <> 0 @@ -35,11 +36,11 @@ BEGIN FROM ( SELECT SUM(amount) amount FROM vn.clientRisk - WHERE clientFk = vClientFk + WHERE clientFk = vSelf UNION ALL SELECT -(SUM(amount) / 100) amount FROM hedera.tpvTransaction t - WHERE clientFk = vClientFk + WHERE clientFk = vSelf AND receiptFk IS NULL AND status = 'ok' ) sub @@ -47,14 +48,14 @@ BEGIN SELECT DATE(t.shipped) dated, SUM(t.totalWithVat)amount FROM vn.ticket t JOIN dated d - WHERE t.clientFk = vClientFk + WHERE t.clientFk = vSelf AND t.refFk IS NULL AND t.shipped BETWEEN d.started AND d.ended GROUP BY DATE(t.shipped) ), receipt AS( SELECT DATE(payed) dated, SUM(amountPaid) amount FROM vn.receipt - WHERE clientFk = vClientFk + WHERE clientFk = vSelf AND payed > util.VN_CURDATE() GROUP BY DATE(payed) ), risk AS( diff --git a/db/routines/vn/procedures/client_riskAll.sql b/db/routines/vn/procedures/client_riskAll.sql new file mode 100644 index 000000000..0941d2ad5 --- /dev/null +++ b/db/routines/vn/procedures/client_riskAll.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_riskAll`() +BEGIN +/** + * Actualiza el riesgo todos los clientes + * + */ + DECLARE vDone BOOL; + DECLARE vClientFk INT; + + DECLARE cClients CURSOR FOR + SELECT id + FROM vn.client; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + OPEN cClients; + myLoop: LOOP + SET vDone = FALSE; + FETCH cClients INTO vClientFk; + IF vDone THEN LEAVE myLoop; END IF; + CALL vn.client_risk(vClientFk); + END LOOP; + CLOSE cClients; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql b/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql new file mode 100644 index 000000000..d9e8c5e07 --- /dev/null +++ b/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblemAll`() +BEGIN +/** + * Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas + * con los componentes, verifica que esten o no todos los componenetes obligatorios + * + * @param vSelf Id del sale + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT s.id saleFk, sale_hasComponentLack(s.id) hasProblem + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.shipped >= util.midnight(); + + CALL sale_setProblem('hasComponentLack'); + + DROP TEMPORARY TABLE tmp.sale; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getRoundingProblem.sql b/db/routines/vn/procedures/sale_getRoundingProblem.sql index 7f8d29d87..ab01dfdb8 100644 --- a/db/routines/vn/procedures/sale_getRoundingProblem.sql +++ b/db/routines/vn/procedures/sale_getRoundingProblem.sql @@ -22,13 +22,14 @@ BEGIN CALL buyUltimate(vWarehouseFk, vDated); CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem - FROM tmp.buyUltimate bu - JOIN buy b ON b.id = bu.buyFk - WHERE bu.itemFk = vItemFk; + SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem + FROM tmp.buyUltimate bu + JOIN buy b ON b.id = bu.buyFk + WHERE bu.itemFk = vItemFk; CALL sale_setProblem('hasRounding'); DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getFreezeProblem.sql b/db/routines/vn/procedures/ticket_getFreezeProblem.sql index 5e8422640..c3c35b9b8 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblem.sql +++ b/db/routines/vn/procedures/ticket_getFreezeProblem.sql @@ -1,25 +1,18 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`( - vClientFk INT -) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`() proc: BEGIN /** * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente * se encuentra congelado o deja de estarlo * - * @param vClientFk Id del cliente + * @table tmp.ticket(ticketFk, hasProblem) */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, NOT c.isFreezed hasProblem - FROM ticket t - JOIN client c ON c.id = t.clientFk - WHERE t.shipped >= util.midnight() - AND c.id = vClientFk; - - CALL ticket_setProblem('isFreezed'); - - DROP TEMPORARY TABLE tmp.ticket; + UPDATE tmp.ticket t + JOIN ticket ti ON ti.id = t.ticketFk + JOIN client c ON c.id = ti.clientFk + SET t.hasProblem = TRUE + WHERE c.isFreezed; + + CALL ticket_setProblem('hasTicketRequest'); END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql b/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql new file mode 100644 index 000000000..f91436964 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemAll`() +proc: BEGIN +/** + * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente + * se encuentra congelado o deja de estarlo + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + WHERE t.shipped >= util.midnight(); + + CALL ticket_getFreezeProblem(); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql b/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql new file mode 100644 index 000000000..58f574368 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemByClient`( + vClientFk INT +) +proc: BEGIN +/** + * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente + * se encuentra congelado o deja de estarlo + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + WHERE t.clientFk = vClientFk + AND t.shipped >= util.midnight(); + + CALL ticket_getFreezeProblem(); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRequestProblem.sql b/db/routines/vn/procedures/ticket_getRequestProblem.sql index f866f0ad8..82695b8d6 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblem.sql +++ b/db/routines/vn/procedures/ticket_getRequestProblem.sql @@ -1,26 +1,16 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`( - vSelf INT -) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`() BEGIN /** - * Actualiza los problemas cuando el ticket tiene una petición de compra pendiente o + * Actualiza los problemas de tickets que tienen una petición de compra pendiente o * deja de tenerla - * @param vSelf Id del ticket de la petición de compra + * @table tmp.ticket(ticketFk, hasProblem) */ - DECLARE vHasProblem BOOL; + UPDATE tmp.ticket t + JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk + SET t.hasProblem = TRUE + WHERE tr.isOK IS NULL; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, COUNT(tr.id) hasProblem - FROM ticket t - LEFT JOIN ticketRequest tr ON tr.ticketFk = t.id - WHERE t.id = vSelf - AND isOK IS NULL; - CALL ticket_setProblem('hasTicketRequest'); - - DROP TEMPORARY TABLE tmp.ticket; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql b/db/routines/vn/procedures/ticket_getRequestProblemAll.sql new file mode 100644 index 000000000..18a373ecd --- /dev/null +++ b/db/routines/vn/procedures/ticket_getRequestProblemAll.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemAll`() +BEGIN +/** + * Actualiza los problemas de tickets pendientes de preparar que tiene una petición + * de compra pendiente o deja de tenerla + */ + DECLARE vHasProblem BOOL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + WHERE t.shipped >= util.midnight(); + + CALL ticket_getRequestProblem(); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql b/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql new file mode 100644 index 000000000..6a3aa8006 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemByTicket`( + vSelf INT +) +BEGIN +/** + * Actualiza los problemas de un ticket que tiene una petición de compra pendiente o + * deja de tenerla + * @param vSelf Id del ticket de la petición de compra + */ + DECLARE vHasProblem BOOL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + WHERE t.id = vSelf; + + CALL ticket_getRequestProblem(); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRiskProblem.sql b/db/routines/vn/procedures/ticket_getRiskProblem.sql index 73b5386cd..458b0aff9 100644 --- a/db/routines/vn/procedures/ticket_getRiskProblem.sql +++ b/db/routines/vn/procedures/ticket_getRiskProblem.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProbl ) BEGIN /** - * Actualiza los problemas para los tickets con riesgo + * Actualiza los problema de riesgo para un ticket en concreto * * @param vSelf Id del ticket */ diff --git a/db/routines/vn/procedures/ticket_getRiskProblemAll.sql b/db/routines/vn/procedures/ticket_getRiskProblemAll.sql new file mode 100644 index 000000000..1a3776c16 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getRiskProblemAll.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblemAll`() +BEGIN +/** + * Actualiza los problema de riesgo para un ticket en concreto + * + * @param vSelf Id del ticket + */ + CREATE OR REPLACE TEMPORARY TABLE tRisk + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, + t.risk > (c.credit + 10) hasRisk, + ((t.risk - cc.riskTolerance) > (c.credit + 10)) hasHighRisk + FROM client c + JOIN ticket t ON t.clientFk = c.id + JOIN clientConfig cc + WHERE t.shipped >= util.midnight(); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, hasRisk hasProblem + FROM tRisk; + + CALL ticket_setProblem('hasRisk'); + DROP TEMPORARY TABLE tmp.ticket; + + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, hasHighRisk hasProblem + FROM tRisk; + + CALL ticket_setProblem('hasHighRisk'); + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tRisk; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getRoundingProblem.sql b/db/routines/vn/procedures/ticket_getRoundingProblem.sql index ca58aff20..ca88fdf0a 100644 --- a/db/routines/vn/procedures/ticket_getRoundingProblem.sql +++ b/db/routines/vn/procedures/ticket_getRoundingProblem.sql @@ -29,5 +29,6 @@ BEGIN CALL sale_setProblem('hasRounding'); DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql index e82932035..95678e35e 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql @@ -1,26 +1,18 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`( - vClientFk INT -) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`() proc: BEGIN /** * Actualiza los problemas de los ticket de hoy y a fututo * cuyo cliente tenga o no los datos comprobados * - * @param vClientFk Id del cliente */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, NOT c.isTaxDataChecked hasProblem - FROM ticket t - JOIN client c ON c.id = t.clientFk - WHERE t.shipped >= util.midnight() - AND c.id = vClientFk; + UPDATE tmp.ticket t + JOIN ticket ti ON ti.id = t.ticketFk + JOIN client c ON c.id = ti.clientFk + SET t.hasproblem = TRUE + WHERE c.isTaxDataChecked; CALL ticket_setProblem('isTaxDataChecked'); - - DROP TEMPORARY TABLE tmp.ticket; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql new file mode 100644 index 000000000..64ce44fe5 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemAll`() +proc: BEGIN +/** + * Actualiza los problemas de los tickets de hoy y a futuro + * cuyos clientes tengan o no los datos comprobados + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + JOIN client c ON c.id = t.clientFk + WHERE t.shipped >= util.midnight(); + + CALL ticket_getTaxDataCheckedProblem(); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql new file mode 100644 index 000000000..8f9e171c5 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemByClient`( + vClientFk INT +) +proc: BEGIN +/** + * Actualiza los problemas de los ticket de hoy y a futuro + * cuyo cliente tenga o no los datos comprobados + * + * @param vClientFk Id del cliente + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + JOIN client c ON c.id = t.clientFk + WHERE t.shipped >= util.midnight() + AND c.id = vClientFk; + + CALL ticket_getTaxDataCheckedProblem(); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql b/db/routines/vn/procedures/ticket_getTooLittleProblem.sql index ae08fefa7..b75f795e3 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblem.sql @@ -11,7 +11,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) ENGINE = MEMORY - SELECT vSelf ticketFk, ticket_isTooLittle(vSelf); + SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem; CALL ticket_setProblem('isTooLittle'); diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql new file mode 100644 index 000000000..beed67810 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemAll`() +BEGIN +/** + * Actualiza los problemas cuando un ticket es demasiado pequeño o deja de serlo + * + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk, ticket_isTooLittle(id) hasProblem + FROM ticket + WHERE shipped >= util.midnight(); + + CALL ticket_setProblem('isTooLittle'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql index 2a509c9cd..96883a0ae 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql @@ -11,8 +11,7 @@ BEGIN ENGINE = MEMORY SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem FROM ticket t - WHERE t.shipped >= util.midnight() - GROUP BY t.id; + WHERE t.shipped >= util.midnight(); CALL ticket_setProblem('isTooLittle'); diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql index 2e068bfb2..1f75a8a45 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql @@ -12,12 +12,15 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) ENGINE = MEMORY - SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - WHERE s.itemFk = vItemFk - AND t.shipped >= util.midnight() - GROUP BY t.id; + WITH tickets AS( + SELECT t.id ticketFk + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + WHERE s.itemFk = vItemFk + AND t.shipped >= util.midnight() + GROUP BY t.id + )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem + FROM tickets; CALL ticket_setProblem('isTooLittle'); diff --git a/db/routines/vn/procedures/worker_updateBalance.sql b/db/routines/vn/procedures/worker_updateBalance.sql index c1fd0adf7..17c2fbbe1 100644 --- a/db/routines/vn/procedures/worker_updateBalance.sql +++ b/db/routines/vn/procedures/worker_updateBalance.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelfFk INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2)) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelf INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2)) BEGIN /** * Actualiza la columna balance de worker. @@ -8,6 +8,6 @@ BEGIN */ UPDATE worker SET balance = IFNULL(balance, 0) + IFNULL(vCredit, 0) - IFNULL(vDebit, 0) - WHERE id = vSelfFk; + WHERE id = vSelf; END$$ DELIMITER ; From e28a5eb4782d23f00a42f8f02c7a01fc4b1c8e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 2 May 2024 18:13:12 +0200 Subject: [PATCH 06/13] feat: Turn issues into calculated columns refs#7213 --- .../vn/functions/sale_hasComponentLack.sql | 12 +++++++----- db/routines/vn/functions/ticket_isTooLittle.sql | 7 ++++--- .../vn/procedures/buy_getRoundingProblem.sql | 4 ++-- db/routines/vn/procedures/client_risk.sql | 16 ++++++++-------- db/routines/vn/procedures/client_riskAll.sql | 6 +++--- .../procedures/sale_getComponentLackProblem.sql | 6 +++--- .../sale_getComponentLackProblemAll.sql | 7 +++---- .../sale_getComponentLackProblemComponent.sql | 6 +++--- .../vn/procedures/sale_getRoundingProblem.sql | 5 ++--- db/routines/vn/procedures/sale_setProblem.sql | 4 ++-- .../vn/procedures/ticket_getFreezeProblem.sql | 5 ++--- .../vn/procedures/ticket_getFreezeProblemAll.sql | 6 +++--- .../ticket_getFreezeProblemByClient.sql | 4 ++-- .../vn/procedures/ticket_getRequestProblem.sql | 4 ++-- .../procedures/ticket_getRequestProblemAll.sql | 3 +-- .../vn/procedures/ticket_getRiskProblem.sql | 4 ++-- .../vn/procedures/ticket_getRiskProblemAll.sql | 3 +-- .../vn/procedures/ticket_getRoundingProblem.sql | 2 +- .../ticket_getTaxDataCheckedProblem.sql | 10 +++++----- .../ticket_getTaxDataCheckedProblemAll.sql | 7 ++++--- .../ticket_getTaxDataCheckedProblemByClient.sql | 7 +++---- .../vn/procedures/ticket_getTooLittleProblem.sql | 2 +- .../procedures/ticket_getTooLittleProblemAll.sql | 2 +- .../ticket_getTooLittleProblemConfig.sql | 4 ++-- .../ticket_getTooLittleProblemItemCost.sql | 4 ++-- db/routines/vn/procedures/ticket_setProblem.sql | 4 ++-- 26 files changed, 71 insertions(+), 73 deletions(-) diff --git a/db/routines/vn/functions/sale_hasComponentLack.sql b/db/routines/vn/functions/sale_hasComponentLack.sql index 6d1b4ad01..912d5f107 100644 --- a/db/routines/vn/functions/sale_hasComponentLack.sql +++ b/db/routines/vn/functions/sale_hasComponentLack.sql @@ -1,18 +1,20 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`sale_hasComponentLack`(vSelf INT) - RETURNS tinyint(1) +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`sale_hasComponentLack`( + vSelf INT +)RETURNS tinyint(1) READS SQL DATA BEGIN /** - * Comprueba si la línea de sale tiene todos lo componentes obligatorios + * Check if a sales line has all the required components. * + * @param vSelf Id de sale * @return BOOL */ DECLARE vHasComponentLack TINYINT(1); WITH componentRequired AS( - SELECT COUNT(*)total - FROM vn.component + SELECT COUNT(*) total + FROM vn.component WHERE isRequired )SELECT SUM(IF(c.isRequired, TRUE, FALSE)) <> cr.total INTO vHasComponentLack FROM vn.sale s diff --git a/db/routines/vn/functions/ticket_isTooLittle.sql b/db/routines/vn/functions/ticket_isTooLittle.sql index cd14d6bed..01b3d9fbb 100644 --- a/db/routines/vn/functions/ticket_isTooLittle.sql +++ b/db/routines/vn/functions/ticket_isTooLittle.sql @@ -1,11 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(vSelf INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`( + vSelf INT +) RETURNS tinyint(1) READS SQL DATA BEGIN /** - * Comprueba si el ticket es pequeño en función de los parámtros de configuración - * teniendo en cuenta el volumen y el importe + * Check if the ticket is small based on the volume and amount parameters. * * @return BOOL */ diff --git a/db/routines/vn/procedures/buy_getRoundingProblem.sql b/db/routines/vn/procedures/buy_getRoundingProblem.sql index 9a658d169..870275f70 100644 --- a/db/routines/vn/procedures/buy_getRoundingProblem.sql +++ b/db/routines/vn/procedures/buy_getRoundingProblem.sql @@ -4,9 +4,9 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getRoundingProb ) BEGIN /** - * Actualiza los problemas de redondeo para las líneas de venta relacionadas con un buy + * Update the rounding problems for sales lines related to a buy. * - * @param vSelf Id de ticket + * @param vSelf Id ticket */ DECLARE vWarehouseFk INT; DECLARE vDated DATE; diff --git a/db/routines/vn/procedures/client_risk.sql b/db/routines/vn/procedures/client_risk.sql index 6f170222e..a655a7c97 100644 --- a/db/routines/vn/procedures/client_risk.sql +++ b/db/routines/vn/procedures/client_risk.sql @@ -3,19 +3,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_risk`( vSelf INT) BEGIN /** - * Actualiza el riesgo de los tickets pendientes de un cliente + * Update the risk for a client with pending tickets * - * @param vSelf Id del cliente + * @param vSelf Id cliente */ DECLARE vHasDebt BOOL; - + SELECT COUNT(*) INTO vHasDebt FROM `client` WHERE id = vSelf AND typeFk = 'normal'; - + IF vHasDebt THEN - + CREATE OR REPLACE TEMPORARY TABLE tTicketRisk (KEY (ticketFk)) ENGINE = MEMORY @@ -45,7 +45,7 @@ BEGIN AND status = 'ok' ) sub ), uninvoiced AS( - SELECT DATE(t.shipped) dated, SUM(t.totalWithVat)amount + SELECT DATE(t.shipped) dated, SUM(t.totalWithVat) amount FROM vn.ticket t JOIN dated d WHERE t.clientFk = vSelf @@ -71,11 +71,11 @@ BEGIN SELECT ti.ticketFk, r.amount FROM ticket ti JOIN risk r ON r.dated = ti.dated; - + UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id SET t.risk = tr.amount; - + DROP TEMPORARY TABLE IF EXISTS tTicketRisk; END IF; END$$ diff --git a/db/routines/vn/procedures/client_riskAll.sql b/db/routines/vn/procedures/client_riskAll.sql index 0941d2ad5..a3c2f8a86 100644 --- a/db/routines/vn/procedures/client_riskAll.sql +++ b/db/routines/vn/procedures/client_riskAll.sql @@ -2,7 +2,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_riskAll`() BEGIN /** - * Actualiza el riesgo todos los clientes + * Update the risk for all clients with pending tickets * */ DECLARE vDone BOOL; @@ -10,7 +10,7 @@ BEGIN DECLARE cClients CURSOR FOR SELECT id - FROM vn.client; + FROM client; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -20,7 +20,7 @@ BEGIN SET vDone = FALSE; FETCH cClients INTO vClientFk; IF vDone THEN LEAVE myLoop; END IF; - CALL vn.client_risk(vClientFk); + CALL client_risk(vClientFk); END LOOP; CLOSE cClients; END$$ diff --git a/db/routines/vn/procedures/sale_getComponentLackProblem.sql b/db/routines/vn/procedures/sale_getComponentLackProblem.sql index 0f8b6b690..35bf963a0 100644 --- a/db/routines/vn/procedures/sale_getComponentLackProblem.sql +++ b/db/routines/vn/procedures/sale_getComponentLackProblem.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLa ) BEGIN /** - * Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas - * con los componentes, verifica que esten o no todos los componenetes obligatorios + * Update the problems for sales lines that have or no longer have problems with components, + * verify whether all mandatory components are present or not * * @param vSelf Id del sale */ @@ -13,7 +13,7 @@ BEGIN (INDEX(saleFk)) ENGINE = MEMORY SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem; - + CALL sale_setProblem('hasComponentLack'); DROP TEMPORARY TABLE tmp.sale; diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql b/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql index d9e8c5e07..f8b4560bc 100644 --- a/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql +++ b/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql @@ -2,10 +2,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblemAll`() BEGIN /** - * Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas - * con los componentes, verifica que esten o no todos los componenetes obligatorios - * - * @param vSelf Id del sale + * Update the problems for all pending sales lines that have or no longer have problems + * with components, verify whether all mandatory components are present or not + * */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk)) diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql b/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql index e02f2a802..06958d5f8 100644 --- a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql +++ b/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLa ) BEGIN /** - * Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas - * con los componentes que derivan de cambios en la tabla vn.component + * Update the issues for sales lines that have or no longer have problems with components, verify + * whether all mandatory components are present or not resulting from changes in the table vn.component * */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale @@ -17,7 +17,7 @@ BEGIN LEFT JOIN saleComponent sc ON sc.saleFk = s.id WHERE t.shipped >= util.midnight() AND sc.componentFk = vComponentFk; - + CALL sale_setProblem('hasComponentLack'); DROP TEMPORARY TABLE tmp.sale; diff --git a/db/routines/vn/procedures/sale_getRoundingProblem.sql b/db/routines/vn/procedures/sale_getRoundingProblem.sql index ab01dfdb8..01afc9d72 100644 --- a/db/routines/vn/procedures/sale_getRoundingProblem.sql +++ b/db/routines/vn/procedures/sale_getRoundingProblem.sql @@ -4,9 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getRoundingPro ) BEGIN /** - * Actualiza los problemas de redondeo para las líneas de venta - * - * @param vSelf Id de sale + * Update the rounding problem for a sales line + * @param vSelf Id sale */ DECLARE vItemFk INT; DECLARE vWarehouseFk INT; diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql index 723d97a34..b0b1b8c6f 100644 --- a/db/routines/vn/procedures/sale_setProblem.sql +++ b/db/routines/vn/procedures/sale_setProblem.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`( ) BEGIN /** - * Actualiza en la tabla sale la columna problema - * @table tmp.sale(saleFk, hasProblem) Identificadores de los sales a actualizar + * Update column sale.problem with a problem code + * @table tmp.sale(saleFk, hasProblem) */ UPDATE sale s JOIN tmp.sale ts ON ts.saleFk = s.id diff --git a/db/routines/vn/procedures/ticket_getFreezeProblem.sql b/db/routines/vn/procedures/ticket_getFreezeProblem.sql index c3c35b9b8..b830ac853 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblem.sql +++ b/db/routines/vn/procedures/ticket_getFreezeProblem.sql @@ -1,9 +1,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`() -proc: BEGIN +BEGIN /** - * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente - * se encuentra congelado o deja de estarlo + * Update the problem of tickets whose client is frozen or unfrozen * * @table tmp.ticket(ticketFk, hasProblem) */ diff --git a/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql b/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql index f91436964..94c8c8525 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql +++ b/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql @@ -2,8 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemAll`() proc: BEGIN /** - * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente - * se encuentra congelado o deja de estarlo + * Update the problem of all tickets whose client is frozen or unfrozen + * */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) @@ -11,7 +11,7 @@ proc: BEGIN SELECT t.id ticketFk, FALSE hasProblem FROM ticket t WHERE t.shipped >= util.midnight(); - + CALL ticket_getFreezeProblem(); DROP TEMPORARY TABLE tmp.ticket; diff --git a/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql b/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql index 58f574368..a5f8ce6bf 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql +++ b/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezePro ) proc: BEGIN /** - * Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente - * se encuentra congelado o deja de estarlo + * Update the problem of all client tickets whose client is frozen or unfrozen + * @param vClientFk Id client */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) diff --git a/db/routines/vn/procedures/ticket_getRequestProblem.sql b/db/routines/vn/procedures/ticket_getRequestProblem.sql index 82695b8d6..9b94c72b5 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblem.sql +++ b/db/routines/vn/procedures/ticket_getRequestProblem.sql @@ -2,8 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`() BEGIN /** - * Actualiza los problemas de tickets que tienen una petición de compra pendiente o - * deja de tenerla + * Update the problems of tickets that have a pending ticketRequest or no longer have it + * * @table tmp.ticket(ticketFk, hasProblem) */ UPDATE tmp.ticket t diff --git a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql b/db/routines/vn/procedures/ticket_getRequestProblemAll.sql index 18a373ecd..3cd726aac 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql +++ b/db/routines/vn/procedures/ticket_getRequestProblemAll.sql @@ -2,8 +2,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemAll`() BEGIN /** - * Actualiza los problemas de tickets pendientes de preparar que tiene una petición - * de compra pendiente o deja de tenerla + * Update the problems of all tickets that have a pending ticketRequest or no longer have it */ DECLARE vHasProblem BOOL; diff --git a/db/routines/vn/procedures/ticket_getRiskProblem.sql b/db/routines/vn/procedures/ticket_getRiskProblem.sql index 458b0aff9..cd8a5931f 100644 --- a/db/routines/vn/procedures/ticket_getRiskProblem.sql +++ b/db/routines/vn/procedures/ticket_getRiskProblem.sql @@ -4,9 +4,9 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProbl ) BEGIN /** - * Actualiza los problema de riesgo para un ticket en concreto + * Update the risk problem for a specific ticket * - * @param vSelf Id del ticket + * @param vSelf Id ticket */ DECLARE vHasRisk BOOL; DECLARE vHasHighRisk BOOL; diff --git a/db/routines/vn/procedures/ticket_getRiskProblemAll.sql b/db/routines/vn/procedures/ticket_getRiskProblemAll.sql index 1a3776c16..b9a0bc617 100644 --- a/db/routines/vn/procedures/ticket_getRiskProblemAll.sql +++ b/db/routines/vn/procedures/ticket_getRiskProblemAll.sql @@ -2,9 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblemAll`() BEGIN /** - * Actualiza los problema de riesgo para un ticket en concreto + * Update the risk problem for all tickets * - * @param vSelf Id del ticket */ CREATE OR REPLACE TEMPORARY TABLE tRisk (KEY (ticketFk)) diff --git a/db/routines/vn/procedures/ticket_getRoundingProblem.sql b/db/routines/vn/procedures/ticket_getRoundingProblem.sql index ca88fdf0a..230065a88 100644 --- a/db/routines/vn/procedures/ticket_getRoundingProblem.sql +++ b/db/routines/vn/procedures/ticket_getRoundingProblem.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRoundingP ) BEGIN /** - * Actualiza los problemas de redondeo para las líneas de venta de un ticket + * Update the rounding problem for the sales lines of a ticket * * @param vSelf Id de ticket */ diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql index 95678e35e..56dd29048 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql @@ -1,12 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`() -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` + PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`() +BEGIN /** - * Actualiza los problemas de los ticket de hoy y a fututo - * cuyo cliente tenga o no los datos comprobados + * Update the problem of tickets, depending on whether + * the client taxDataCheched is verified or not * */ - UPDATE tmp.ticket t JOIN ticket ti ON ti.id = t.ticketFk JOIN client c ON c.id = ti.clientFk diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql index 64ce44fe5..d5b011ebd 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql @@ -1,9 +1,10 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemAll`() +CREATE OR REPLACE DEFINER=`root`@`localhost` + PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemAll`() proc: BEGIN /** - * Actualiza los problemas de los tickets de hoy y a futuro - * cuyos clientes tengan o no los datos comprobados + * Update the problem of all tickets, depending on whether + * the client taxDataCheched is verified or not */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql index 8f9e171c5..3e641c96f 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql @@ -4,12 +4,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCh ) proc: BEGIN /** - * Actualiza los problemas de los ticket de hoy y a futuro - * cuyo cliente tenga o no los datos comprobados + * Update the problem of tickets for a specific client, depending on whether + * the client taxDataCheched is verified or not * - * @param vClientFk Id del cliente + * @param vClientFk Id cliente */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) ENGINE = MEMORY diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql b/db/routines/vn/procedures/ticket_getTooLittleProblem.sql index b75f795e3..39f2302b4 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblem.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittle ) BEGIN /** - * Actualiza los problemas cuando el ticket es demasiado pequeño o deja de serlo + * Update the problems when the ticket is too small or is no longer so * * @param vSelf Id del ticket */ diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql index beed67810..ab14d0804 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql @@ -2,7 +2,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemAll`() BEGIN /** - * Actualiza los problemas cuando un ticket es demasiado pequeño o deja de serlo + * Update the problems for all tickets when the ticket is too small or is no longer so * */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql index 96883a0ae..6a9f41e24 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql @@ -2,8 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemConfig`() BEGIN /** - * Actualiza los problemas cuando el ticket es demasiado pequeño o deja de serlo, que derivan - * del cambio en la tabla vn.volumeConfig + * Update the problems when the ticket is too small or is no longer so, + * derived from changes in the volumeConfig table * */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql index 1f75a8a45..abcbb307c 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql +++ b/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittle ) BEGIN /** - * Actualiza los problemas cuando el ticket es demasiado pequeño o deja de serlo, que derivan - * del cambio en la tabla vn.itemCost + * Update the problems when the ticket is too small or is no longer so, + * derived from changes in the itemCost table * * @param vItemFk Id del item */ diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql index 24bb97258..4566d3b79 100644 --- a/db/routines/vn/procedures/ticket_setProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblem.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( ) BEGIN /** - * Actualiza en la tabla ticket la columna problema - * @table tmp.ticket(ticketFk, hasProblem) Identificadores de los tickets a actualizar + * Update column ticket.problem with a problem code + * @table tmp.ticket(ticketFk, hasProblem) */ UPDATE ticket t JOIN tmp.ticket tt ON tt.ticketFk = t.id From 7659a39b42800f886b43cdbf53869a417a9ba15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 3 May 2024 10:19:05 +0200 Subject: [PATCH 07/13] feat: Turn issues into calculated columns refs#7213 --- .../vn/functions/ticket_isTooLittle.sql | 3 +- .../vn/procedures/buy_getRoundingProblem.sql | 33 ------------------- db/routines/vn/procedures/client_risk.sql | 2 +- .../sale_getComponentLackProblemAll.sql | 21 ------------ .../sale_getComponentLackProblemComponent.sql | 3 +- .../vn/procedures/sale_getRoundingProblem.sql | 8 ++--- .../ticket_getRequestProblemAll.sql | 2 -- .../ticket_getRequestProblemByTicket.sql | 2 -- .../ticket_getTaxDataCheckedProblem.sql | 4 +-- .../ticket_getTooLittleProblemAll.sql | 19 ----------- 10 files changed, 10 insertions(+), 87 deletions(-) delete mode 100644 db/routines/vn/procedures/buy_getRoundingProblem.sql delete mode 100644 db/routines/vn/procedures/sale_getComponentLackProblemAll.sql delete mode 100644 db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql diff --git a/db/routines/vn/functions/ticket_isTooLittle.sql b/db/routines/vn/functions/ticket_isTooLittle.sql index 01b3d9fbb..1af421a47 100644 --- a/db/routines/vn/functions/ticket_isTooLittle.sql +++ b/db/routines/vn/functions/ticket_isTooLittle.sql @@ -14,8 +14,7 @@ BEGIN SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume OR IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle - FROM ticket t - LEFT JOIN sale s ON s.ticketFk = t.id + FROM ticket t LEFT JOIN saleVolume sv ON sv.ticketFk = t.id JOIN volumeConfig vc WHERE t.id = vSelf; diff --git a/db/routines/vn/procedures/buy_getRoundingProblem.sql b/db/routines/vn/procedures/buy_getRoundingProblem.sql deleted file mode 100644 index 870275f70..000000000 --- a/db/routines/vn/procedures/buy_getRoundingProblem.sql +++ /dev/null @@ -1,33 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getRoundingProblem`( - vSelf INT -) -BEGIN -/** - * Update the rounding problems for sales lines related to a buy. - * - * @param vSelf Id ticket - */ - DECLARE vWarehouseFk INT; - DECLARE vDated DATE; - - SELECT warehouseFk, DATE(shipped) - INTO vWarehouseFk, vDated - FROM ticket - WHERE id = vSelf; - - CALL buyUltimate(vWarehouseFk, vDated); - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem - FROM ticket t - JOIN sale s ON s.ticketFk = tl.ticketFk - JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - JOIN buy b ON b.id = bu.buyFk - WHERE t.id = vSelf; - - CALL sale_setProblem('hasRounding'); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/client_risk.sql b/db/routines/vn/procedures/client_risk.sql index a655a7c97..163326300 100644 --- a/db/routines/vn/procedures/client_risk.sql +++ b/db/routines/vn/procedures/client_risk.sql @@ -76,7 +76,7 @@ BEGIN JOIN tTicketRisk tr ON tr.ticketFk = t.id SET t.risk = tr.amount; - DROP TEMPORARY TABLE IF EXISTS tTicketRisk; + DROP TEMPORARY TABLE tTicketRisk; END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql b/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql deleted file mode 100644 index f8b4560bc..000000000 --- a/db/routines/vn/procedures/sale_getComponentLackProblemAll.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblemAll`() -BEGIN -/** - * Update the problems for all pending sales lines that have or no longer have problems - * with components, verify whether all mandatory components are present or not - * - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) - ENGINE = MEMORY - SELECT s.id saleFk, sale_hasComponentLack(s.id) hasProblem - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - WHERE t.shipped >= util.midnight(); - - CALL sale_setProblem('hasComponentLack'); - - DROP TEMPORARY TABLE tmp.sale; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql b/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql index 06958d5f8..366281aa2 100644 --- a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql +++ b/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql @@ -7,6 +7,7 @@ BEGIN * Update the issues for sales lines that have or no longer have problems with components, verify * whether all mandatory components are present or not resulting from changes in the table vn.component * + * @param vComponentFk Id component */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk)) @@ -16,7 +17,7 @@ BEGIN JOIN sale s ON s.ticketFk = t.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id WHERE t.shipped >= util.midnight() - AND sc.componentFk = vComponentFk; + AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk); CALL sale_setProblem('hasComponentLack'); diff --git a/db/routines/vn/procedures/sale_getRoundingProblem.sql b/db/routines/vn/procedures/sale_getRoundingProblem.sql index 01afc9d72..4328b2fe0 100644 --- a/db/routines/vn/procedures/sale_getRoundingProblem.sql +++ b/db/routines/vn/procedures/sale_getRoundingProblem.sql @@ -9,16 +9,16 @@ BEGIN */ DECLARE vItemFk INT; DECLARE vWarehouseFk INT; - DECLARE vDated DATE; + DECLARE vShipped DATE; DECLARE vQuantity INT; - SELECT s.itemFk, t.warehouseFk, DATE(t.shipped), s.quantity - INTO vItemFk, vWarehouseFk, vDated, vQuantity + SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity + INTO vItemFk, vWarehouseFk, vShipped, vQuantity FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE s.id = vSelf; - CALL buyUltimate(vWarehouseFk, vDated); + CALL buyUltimate(vWarehouseFk, vShipped); CREATE OR REPLACE TEMPORARY TABLE tmp.ticket SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem diff --git a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql b/db/routines/vn/procedures/ticket_getRequestProblemAll.sql index 3cd726aac..85e2e0863 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql +++ b/db/routines/vn/procedures/ticket_getRequestProblemAll.sql @@ -4,8 +4,6 @@ BEGIN /** * Update the problems of all tickets that have a pending ticketRequest or no longer have it */ - DECLARE vHasProblem BOOL; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) ENGINE = MEMORY diff --git a/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql b/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql index 6a3aa8006..e304e4aa2 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql +++ b/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql @@ -8,8 +8,6 @@ BEGIN * deja de tenerla * @param vSelf Id del ticket de la petición de compra */ - DECLARE vHasProblem BOOL; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) ENGINE = MEMORY diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql index 56dd29048..71c48d60f 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql +++ b/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql @@ -10,8 +10,8 @@ BEGIN UPDATE tmp.ticket t JOIN ticket ti ON ti.id = t.ticketFk JOIN client c ON c.id = ti.clientFk - SET t.hasproblem = TRUE - WHERE c.isTaxDataChecked; + SET ti.hasproblem = TRUE + WHERE NOT c.isTaxDataChecked; CALL ticket_setProblem('isTaxDataChecked'); END$$ diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql b/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql deleted file mode 100644 index ab14d0804..000000000 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemAll.sql +++ /dev/null @@ -1,19 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemAll`() -BEGIN -/** - * Update the problems for all tickets when the ticket is too small or is no longer so - * - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk, ticket_isTooLittle(id) hasProblem - FROM ticket - WHERE shipped >= util.midnight(); - - CALL ticket_setProblem('isTooLittle'); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file From 2659e3b2596749dbe518672a593df116e906b481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 3 May 2024 14:03:26 +0200 Subject: [PATCH 08/13] feat: Turn issues into calculated columns refs#7213 --- .../vn/procedures/{client_risk.sql => client_setRisk.sql} | 2 +- .../procedures/{client_riskAll.sql => client_setRiskAll.sql} | 4 ++-- ...ponentLackProblem.sql => sale_setComponentLackProblem.sql} | 2 +- ...omponent.sql => sale_setComponentLackProblemComponent.sql} | 2 +- ...ale_getRoundingProblem.sql => sale_setRoundingProblem.sql} | 2 +- ...icket_getFreezeProblem.sql => ticket_setFreezeProblem.sql} | 2 +- ...getFreezeProblemAll.sql => ticket_setFreezeProblemAll.sql} | 2 +- ...roblemByClient.sql => ticket_setFreezeProblemByClient.sql} | 2 +- ...ket_getRequestProblem.sql => ticket_setRequestProblem.sql} | 2 +- ...tRequestProblemAll.sql => ticket_setRequestProblemAll.sql} | 2 +- ...oblemByTicket.sql => ticket_setRequestProblemByTicket.sql} | 2 +- .../{ticket_getRiskProblem.sql => ticket_setRiskProblem.sql} | 2 +- ...ket_getRiskProblemAll.sql => ticket_setRiskProblemAll.sql} | 2 +- ...t_getRoundingProblem.sql => ticket_setRoundingProblem.sql} | 4 ++-- ...CheckedProblem.sql => ticket_setTaxDataCheckedProblem.sql} | 2 +- ...dProblemAll.sql => ticket_setTaxDataCheckedProblemAll.sql} | 2 +- ...Client.sql => ticket_setTaxDataCheckedProblemByClient.sql} | 2 +- ...getTooLittleProblem.sql => ticket_setTooLittleProblem.sql} | 2 +- ...ProblemConfig.sql => ticket_setTooLittleProblemConfig.sql} | 2 +- ...lemItemCost.sql => ticket_setTooLittleProblemItemCost.sql} | 2 +- 20 files changed, 22 insertions(+), 22 deletions(-) rename db/routines/vn/procedures/{client_risk.sql => client_setRisk.sql} (98%) rename db/routines/vn/procedures/{client_riskAll.sql => client_setRiskAll.sql} (88%) rename db/routines/vn/procedures/{sale_getComponentLackProblem.sql => sale_setComponentLackProblem.sql} (93%) rename db/routines/vn/procedures/{sale_getComponentLackProblemComponent.sql => sale_setComponentLackProblemComponent.sql} (94%) rename db/routines/vn/procedures/{sale_getRoundingProblem.sql => sale_setRoundingProblem.sql} (96%) rename db/routines/vn/procedures/{ticket_getFreezeProblem.sql => ticket_setFreezeProblem.sql} (92%) rename db/routines/vn/procedures/{ticket_getFreezeProblemAll.sql => ticket_setFreezeProblemAll.sql} (91%) rename db/routines/vn/procedures/{ticket_getFreezeProblemByClient.sql => ticket_setFreezeProblemByClient.sql} (92%) rename db/routines/vn/procedures/{ticket_getRequestProblem.sql => ticket_setRequestProblem.sql} (91%) rename db/routines/vn/procedures/{ticket_getRequestProblemAll.sql => ticket_setRequestProblemAll.sql} (91%) rename db/routines/vn/procedures/{ticket_getRequestProblemByTicket.sql => ticket_setRequestProblemByTicket.sql} (92%) rename db/routines/vn/procedures/{ticket_getRiskProblem.sql => ticket_setRiskProblem.sql} (95%) rename db/routines/vn/procedures/{ticket_getRiskProblemAll.sql => ticket_setRiskProblemAll.sql} (96%) rename db/routines/vn/procedures/{ticket_getRoundingProblem.sql => ticket_setRoundingProblem.sql} (91%) rename db/routines/vn/procedures/{ticket_getTaxDataCheckedProblem.sql => ticket_setTaxDataCheckedProblem.sql} (86%) rename db/routines/vn/procedures/{ticket_getTaxDataCheckedProblemAll.sql => ticket_setTaxDataCheckedProblemAll.sql} (88%) rename db/routines/vn/procedures/{ticket_getTaxDataCheckedProblemByClient.sql => ticket_setTaxDataCheckedProblemByClient.sql} (92%) rename db/routines/vn/procedures/{ticket_getTooLittleProblem.sql => ticket_setTooLittleProblem.sql} (92%) rename db/routines/vn/procedures/{ticket_getTooLittleProblemConfig.sql => ticket_setTooLittleProblemConfig.sql} (91%) rename db/routines/vn/procedures/{ticket_getTooLittleProblemItemCost.sql => ticket_setTooLittleProblemItemCost.sql} (93%) diff --git a/db/routines/vn/procedures/client_risk.sql b/db/routines/vn/procedures/client_setRisk.sql similarity index 98% rename from db/routines/vn/procedures/client_risk.sql rename to db/routines/vn/procedures/client_setRisk.sql index 163326300..020f554bf 100644 --- a/db/routines/vn/procedures/client_risk.sql +++ b/db/routines/vn/procedures/client_setRisk.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_risk`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_setRisk`( vSelf INT) BEGIN /** diff --git a/db/routines/vn/procedures/client_riskAll.sql b/db/routines/vn/procedures/client_setRiskAll.sql similarity index 88% rename from db/routines/vn/procedures/client_riskAll.sql rename to db/routines/vn/procedures/client_setRiskAll.sql index a3c2f8a86..6fe867e22 100644 --- a/db/routines/vn/procedures/client_riskAll.sql +++ b/db/routines/vn/procedures/client_setRiskAll.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_riskAll`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_setRiskAll`() BEGIN /** * Update the risk for all clients with pending tickets @@ -20,7 +20,7 @@ BEGIN SET vDone = FALSE; FETCH cClients INTO vClientFk; IF vDone THEN LEAVE myLoop; END IF; - CALL client_risk(vClientFk); + CALL client_setRisk(vClientFk); END LOOP; CLOSE cClients; END$$ diff --git a/db/routines/vn/procedures/sale_getComponentLackProblem.sql b/db/routines/vn/procedures/sale_setComponentLackProblem.sql similarity index 93% rename from db/routines/vn/procedures/sale_getComponentLackProblem.sql rename to db/routines/vn/procedures/sale_setComponentLackProblem.sql index 35bf963a0..ede4e86b2 100644 --- a/db/routines/vn/procedures/sale_getComponentLackProblem.sql +++ b/db/routines/vn/procedures/sale_setComponentLackProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setComponentLackProblem`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql b/db/routines/vn/procedures/sale_setComponentLackProblemComponent.sql similarity index 94% rename from db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql rename to db/routines/vn/procedures/sale_setComponentLackProblemComponent.sql index 366281aa2..96e17f8ca 100644 --- a/db/routines/vn/procedures/sale_getComponentLackProblemComponent.sql +++ b/db/routines/vn/procedures/sale_setComponentLackProblemComponent.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblemComponent`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setComponentLackProblemComponent`( vComponentFk INT ) BEGIN diff --git a/db/routines/vn/procedures/sale_getRoundingProblem.sql b/db/routines/vn/procedures/sale_setRoundingProblem.sql similarity index 96% rename from db/routines/vn/procedures/sale_getRoundingProblem.sql rename to db/routines/vn/procedures/sale_setRoundingProblem.sql index 4328b2fe0..0f4bb2c0c 100644 --- a/db/routines/vn/procedures/sale_getRoundingProblem.sql +++ b/db/routines/vn/procedures/sale_setRoundingProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getRoundingProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setRoundingProblem`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_getFreezeProblem.sql b/db/routines/vn/procedures/ticket_setFreezeProblem.sql similarity index 92% rename from db/routines/vn/procedures/ticket_getFreezeProblem.sql rename to db/routines/vn/procedures/ticket_setFreezeProblem.sql index b830ac853..fb9a50b58 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblem.sql +++ b/db/routines/vn/procedures/ticket_setFreezeProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setFreezeProblem`() BEGIN /** * Update the problem of tickets whose client is frozen or unfrozen diff --git a/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql b/db/routines/vn/procedures/ticket_setFreezeProblemAll.sql similarity index 91% rename from db/routines/vn/procedures/ticket_getFreezeProblemAll.sql rename to db/routines/vn/procedures/ticket_setFreezeProblemAll.sql index 94c8c8525..17d0c4545 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblemAll.sql +++ b/db/routines/vn/procedures/ticket_setFreezeProblemAll.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemAll`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setFreezeProblemAll`() proc: BEGIN /** * Update the problem of all tickets whose client is frozen or unfrozen diff --git a/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql b/db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql similarity index 92% rename from db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql rename to db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql index a5f8ce6bf..4dd167781 100644 --- a/db/routines/vn/procedures/ticket_getFreezeProblemByClient.sql +++ b/db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemByClient`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setFreezeProblemByClient`( vClientFk INT ) proc: BEGIN diff --git a/db/routines/vn/procedures/ticket_getRequestProblem.sql b/db/routines/vn/procedures/ticket_setRequestProblem.sql similarity index 91% rename from db/routines/vn/procedures/ticket_getRequestProblem.sql rename to db/routines/vn/procedures/ticket_setRequestProblem.sql index 9b94c72b5..cf05c7255 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblem.sql +++ b/db/routines/vn/procedures/ticket_setRequestProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRequestProblem`() BEGIN /** * Update the problems of tickets that have a pending ticketRequest or no longer have it diff --git a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql b/db/routines/vn/procedures/ticket_setRequestProblemAll.sql similarity index 91% rename from db/routines/vn/procedures/ticket_getRequestProblemAll.sql rename to db/routines/vn/procedures/ticket_setRequestProblemAll.sql index 85e2e0863..5cf26efa6 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblemAll.sql +++ b/db/routines/vn/procedures/ticket_setRequestProblemAll.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemAll`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRequestProblemAll`() BEGIN /** * Update the problems of all tickets that have a pending ticketRequest or no longer have it diff --git a/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql b/db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql similarity index 92% rename from db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql rename to db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql index e304e4aa2..323692142 100644 --- a/db/routines/vn/procedures/ticket_getRequestProblemByTicket.sql +++ b/db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemByTicket`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRequestProblemByTicket`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_getRiskProblem.sql b/db/routines/vn/procedures/ticket_setRiskProblem.sql similarity index 95% rename from db/routines/vn/procedures/ticket_getRiskProblem.sql rename to db/routines/vn/procedures/ticket_setRiskProblem.sql index cd8a5931f..1e014578f 100644 --- a/db/routines/vn/procedures/ticket_getRiskProblem.sql +++ b/db/routines/vn/procedures/ticket_setRiskProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRiskProblem`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_getRiskProblemAll.sql b/db/routines/vn/procedures/ticket_setRiskProblemAll.sql similarity index 96% rename from db/routines/vn/procedures/ticket_getRiskProblemAll.sql rename to db/routines/vn/procedures/ticket_setRiskProblemAll.sql index b9a0bc617..2cdbe2ae6 100644 --- a/db/routines/vn/procedures/ticket_getRiskProblemAll.sql +++ b/db/routines/vn/procedures/ticket_setRiskProblemAll.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblemAll`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRiskProblemAll`() BEGIN /** * Update the risk problem for all tickets diff --git a/db/routines/vn/procedures/ticket_getRoundingProblem.sql b/db/routines/vn/procedures/ticket_setRoundingProblem.sql similarity index 91% rename from db/routines/vn/procedures/ticket_getRoundingProblem.sql rename to db/routines/vn/procedures/ticket_setRoundingProblem.sql index 230065a88..92cda37cd 100644 --- a/db/routines/vn/procedures/ticket_getRoundingProblem.sql +++ b/db/routines/vn/procedures/ticket_setRoundingProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRoundingProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRoundingProblem`( vSelf INT ) BEGIN @@ -11,7 +11,7 @@ BEGIN DECLARE vWarehouseFk INT; DECLARE vDated DATE; - SELECT warehouseFk, DATE(shipped) + SELECT warehouseFk, shipped INTO vWarehouseFk, vDated FROM ticket WHERE id = vSelf; diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql similarity index 86% rename from db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql rename to db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql index 71c48d60f..84f0cdcaa 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblem.sql +++ b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` - PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`() + PROCEDURE `vn`.`ticket_setTaxDataCheckedProblem`() BEGIN /** * Update the problem of tickets, depending on whether diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql similarity index 88% rename from db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql rename to db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql index d5b011ebd..42f1bf42e 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemAll.sql +++ b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` - PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemAll`() + PROCEDURE `vn`.`ticket_setTaxDataCheckedProblemAll`() proc: BEGIN /** * Update the problem of all tickets, depending on whether diff --git a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemByClient.sql similarity index 92% rename from db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql rename to db/routines/vn/procedures/ticket_setTaxDataCheckedProblemByClient.sql index 3e641c96f..0bb73f691 100644 --- a/db/routines/vn/procedures/ticket_getTaxDataCheckedProblemByClient.sql +++ b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemByClient.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemByClient`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTaxDataCheckedProblemByClient`( vClientFk INT ) proc: BEGIN diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql b/db/routines/vn/procedures/ticket_setTooLittleProblem.sql similarity index 92% rename from db/routines/vn/procedures/ticket_getTooLittleProblem.sql rename to db/routines/vn/procedures/ticket_setTooLittleProblem.sql index 39f2302b4..08f566f86 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblem.sql +++ b/db/routines/vn/procedures/ticket_setTooLittleProblem.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTooLittleProblem`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql b/db/routines/vn/procedures/ticket_setTooLittleProblemConfig.sql similarity index 91% rename from db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql rename to db/routines/vn/procedures/ticket_setTooLittleProblemConfig.sql index 6a9f41e24..48643d27c 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemConfig.sql +++ b/db/routines/vn/procedures/ticket_setTooLittleProblemConfig.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemConfig`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTooLittleProblemConfig`() BEGIN /** * Update the problems when the ticket is too small or is no longer so, diff --git a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql b/db/routines/vn/procedures/ticket_setTooLittleProblemItemCost.sql similarity index 93% rename from db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql rename to db/routines/vn/procedures/ticket_setTooLittleProblemItemCost.sql index abcbb307c..89c6d08ed 100644 --- a/db/routines/vn/procedures/ticket_getTooLittleProblemItemCost.sql +++ b/db/routines/vn/procedures/ticket_setTooLittleProblemItemCost.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemItemCost`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTooLittleProblemItemCost`( vItemFk INT ) BEGIN From 6d3f00ec951c5af22a4d608ecdb790707258c2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 13 May 2024 09:54:27 +0200 Subject: [PATCH 09/13] feat: Turn issues into calculated columns refs#7213 --- .../vn/procedures/client_setRiskAll.sql | 27 ------------- .../vn/procedures/ticket_setFreezeProblem.sql | 17 -------- .../procedures/ticket_setFreezeProblemAll.sql | 19 --------- .../ticket_setFreezeProblemByClient.sql | 22 ----------- .../vn/procedures/ticket_setProblemFreeze.sql | 29 ++++++++++++++ .../procedures/ticket_setProblemRequest.sql | 30 ++++++++++++++ ...kProblem.sql => ticket_setProblemRisk.sql} | 2 +- ...blem.sql => ticket_setProblemRounding.sql} | 2 +- .../ticket_setProblemTaxDataChecked.sql | 24 ++++++++++++ ...lem.sql => ticket_setProblemTooLittle.sql} | 2 +- ...l => ticket_setProblemTooLittleConfig.sql} | 2 +- ...=> ticket_setProblemTooLittleItemCost.sql} | 2 +- .../procedures/ticket_setRequestProblem.sql | 16 -------- .../ticket_setRequestProblemAll.sql | 18 --------- .../ticket_setRequestProblemByTicket.sql | 22 ----------- ...{client_setRisk.sql => ticket_setRisk.sql} | 2 +- .../procedures/ticket_setRiskProblemAll.sql | 39 ------------------- .../ticket_setTaxDataCheckedProblem.sql | 18 --------- .../ticket_setTaxDataCheckedProblemAll.sql | 22 ----------- 19 files changed, 89 insertions(+), 226 deletions(-) delete mode 100644 db/routines/vn/procedures/client_setRiskAll.sql delete mode 100644 db/routines/vn/procedures/ticket_setFreezeProblem.sql delete mode 100644 db/routines/vn/procedures/ticket_setFreezeProblemAll.sql delete mode 100644 db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql create mode 100644 db/routines/vn/procedures/ticket_setProblemFreeze.sql create mode 100644 db/routines/vn/procedures/ticket_setProblemRequest.sql rename db/routines/vn/procedures/{ticket_setRiskProblem.sql => ticket_setProblemRisk.sql} (95%) rename db/routines/vn/procedures/{ticket_setRoundingProblem.sql => ticket_setProblemRounding.sql} (95%) create mode 100644 db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql rename db/routines/vn/procedures/{ticket_setTooLittleProblem.sql => ticket_setProblemTooLittle.sql} (92%) rename db/routines/vn/procedures/{ticket_setTooLittleProblemConfig.sql => ticket_setProblemTooLittleConfig.sql} (91%) rename db/routines/vn/procedures/{ticket_setTooLittleProblemItemCost.sql => ticket_setProblemTooLittleItemCost.sql} (93%) delete mode 100644 db/routines/vn/procedures/ticket_setRequestProblem.sql delete mode 100644 db/routines/vn/procedures/ticket_setRequestProblemAll.sql delete mode 100644 db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql rename db/routines/vn/procedures/{client_setRisk.sql => ticket_setRisk.sql} (95%) delete mode 100644 db/routines/vn/procedures/ticket_setRiskProblemAll.sql delete mode 100644 db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql delete mode 100644 db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql diff --git a/db/routines/vn/procedures/client_setRiskAll.sql b/db/routines/vn/procedures/client_setRiskAll.sql deleted file mode 100644 index 6fe867e22..000000000 --- a/db/routines/vn/procedures/client_setRiskAll.sql +++ /dev/null @@ -1,27 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_setRiskAll`() -BEGIN -/** - * Update the risk for all clients with pending tickets - * - */ - DECLARE vDone BOOL; - DECLARE vClientFk INT; - - DECLARE cClients CURSOR FOR - SELECT id - FROM client; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - OPEN cClients; - myLoop: LOOP - SET vDone = FALSE; - FETCH cClients INTO vClientFk; - IF vDone THEN LEAVE myLoop; END IF; - CALL client_setRisk(vClientFk); - END LOOP; - CLOSE cClients; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setFreezeProblem.sql b/db/routines/vn/procedures/ticket_setFreezeProblem.sql deleted file mode 100644 index fb9a50b58..000000000 --- a/db/routines/vn/procedures/ticket_setFreezeProblem.sql +++ /dev/null @@ -1,17 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setFreezeProblem`() -BEGIN -/** - * Update the problem of tickets whose client is frozen or unfrozen - * - * @table tmp.ticket(ticketFk, hasProblem) - */ - UPDATE tmp.ticket t - JOIN ticket ti ON ti.id = t.ticketFk - JOIN client c ON c.id = ti.clientFk - SET t.hasProblem = TRUE - WHERE c.isFreezed; - - CALL ticket_setProblem('hasTicketRequest'); -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setFreezeProblemAll.sql b/db/routines/vn/procedures/ticket_setFreezeProblemAll.sql deleted file mode 100644 index 17d0c4545..000000000 --- a/db/routines/vn/procedures/ticket_setFreezeProblemAll.sql +++ /dev/null @@ -1,19 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setFreezeProblemAll`() -proc: BEGIN -/** - * Update the problem of all tickets whose client is frozen or unfrozen - * - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem - FROM ticket t - WHERE t.shipped >= util.midnight(); - - CALL ticket_getFreezeProblem(); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql b/db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql deleted file mode 100644 index 4dd167781..000000000 --- a/db/routines/vn/procedures/ticket_setFreezeProblemByClient.sql +++ /dev/null @@ -1,22 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setFreezeProblemByClient`( - vClientFk INT -) -proc: BEGIN -/** - * Update the problem of all client tickets whose client is frozen or unfrozen - * @param vClientFk Id client - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem - FROM ticket t - WHERE t.clientFk = vClientFk - AND t.shipped >= util.midnight(); - - CALL ticket_getFreezeProblem(); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblemFreeze.sql b/db/routines/vn/procedures/ticket_setProblemFreeze.sql new file mode 100644 index 000000000..bdb32b3fe --- /dev/null +++ b/db/routines/vn/procedures/ticket_setProblemFreeze.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemFreeze`( + vClientFk INT +) +BEGIN +/** + * Update the problem of tickets whose client is frozen or unfrozen + * + * @param vClientFk Id Cliente, if NULL all clients + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + WHERE t.shipped >= util.midnight() + AND (vClientFk IS NULL OR t.clientFk = vClientFk); + + UPDATE tmp.ticket t + JOIN ticket ti ON ti.id = t.ticketFk + JOIN client c ON c.id = ti.clientFk + SET t.hasProblem = TRUE + WHERE c.isFreezed; + + CALL ticket_setProblem('hasTicketRequest'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblemRequest.sql b/db/routines/vn/procedures/ticket_setProblemRequest.sql new file mode 100644 index 000000000..13d918ab9 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setProblemRequest.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRequest`( + vSelf INT +) +BEGIN +/** + * Update the problems of tickets that have a pending ticketRequest or no longer have it + * + * @param vSelf Id ticket, if NULL ALL tickets + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, FALSE hasProblem + FROM ticket t + WHERE t.shipped >= util.midnight() + AND (vSelf IS NULL OR t.id = vSelf); + + + UPDATE tmp.ticket t + JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk + SET t.hasProblem = TRUE + WHERE tr.isOK IS NULL; + + CALL ticket_setProblem('hasTicketRequest'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setRiskProblem.sql b/db/routines/vn/procedures/ticket_setProblemRisk.sql similarity index 95% rename from db/routines/vn/procedures/ticket_setRiskProblem.sql rename to db/routines/vn/procedures/ticket_setProblemRisk.sql index 1e014578f..7c499f5ba 100644 --- a/db/routines/vn/procedures/ticket_setRiskProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblemRisk.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRiskProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRisk`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_setRoundingProblem.sql b/db/routines/vn/procedures/ticket_setProblemRounding.sql similarity index 95% rename from db/routines/vn/procedures/ticket_setRoundingProblem.sql rename to db/routines/vn/procedures/ticket_setProblemRounding.sql index 92cda37cd..272a48151 100644 --- a/db/routines/vn/procedures/ticket_setRoundingProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblemRounding.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRoundingProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRounding`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql new file mode 100644 index 000000000..18d81c037 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` + PROCEDURE `vn`.`ticket_setProblemTaxDataChecked`(vSelf INT) +BEGIN +/** + * Update the problem of tickets, depending on whether + * the client taxDataCheched is verified or not + * + * @param vSelf Id ticket, if NULL ALL tickets + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (INDEX(ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem + FROM ticket t + JOIN client c ON c.id = t.clientFk + WHERE t.shipped >= util.midnight() + AND (c.id = vClientFk OR vClientFk IS NULL); + + CALL ticket_setProblem('isTaxDataChecked'); + + DROP TEMPORARY TABLE tmp.ticket; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setTooLittleProblem.sql b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql similarity index 92% rename from db/routines/vn/procedures/ticket_setTooLittleProblem.sql rename to db/routines/vn/procedures/ticket_setProblemTooLittle.sql index 08f566f86..98a0787af 100644 --- a/db/routines/vn/procedures/ticket_setTooLittleProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTooLittleProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittle`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_setTooLittleProblemConfig.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql similarity index 91% rename from db/routines/vn/procedures/ticket_setTooLittleProblemConfig.sql rename to db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql index 48643d27c..3df0752e5 100644 --- a/db/routines/vn/procedures/ticket_setTooLittleProblemConfig.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTooLittleProblemConfig`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittleConfig`() BEGIN /** * Update the problems when the ticket is too small or is no longer so, diff --git a/db/routines/vn/procedures/ticket_setTooLittleProblemItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql similarity index 93% rename from db/routines/vn/procedures/ticket_setTooLittleProblemItemCost.sql rename to db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index 89c6d08ed..215b4d7db 100644 --- a/db/routines/vn/procedures/ticket_setTooLittleProblemItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTooLittleProblemItemCost`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittleItemCost`( vItemFk INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_setRequestProblem.sql b/db/routines/vn/procedures/ticket_setRequestProblem.sql deleted file mode 100644 index cf05c7255..000000000 --- a/db/routines/vn/procedures/ticket_setRequestProblem.sql +++ /dev/null @@ -1,16 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRequestProblem`() -BEGIN -/** - * Update the problems of tickets that have a pending ticketRequest or no longer have it - * - * @table tmp.ticket(ticketFk, hasProblem) - */ - UPDATE tmp.ticket t - JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk - SET t.hasProblem = TRUE - WHERE tr.isOK IS NULL; - - CALL ticket_setProblem('hasTicketRequest'); -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setRequestProblemAll.sql b/db/routines/vn/procedures/ticket_setRequestProblemAll.sql deleted file mode 100644 index 5cf26efa6..000000000 --- a/db/routines/vn/procedures/ticket_setRequestProblemAll.sql +++ /dev/null @@ -1,18 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRequestProblemAll`() -BEGIN -/** - * Update the problems of all tickets that have a pending ticketRequest or no longer have it - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem - FROM ticket t - WHERE t.shipped >= util.midnight(); - - CALL ticket_getRequestProblem(); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql b/db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql deleted file mode 100644 index 323692142..000000000 --- a/db/routines/vn/procedures/ticket_setRequestProblemByTicket.sql +++ /dev/null @@ -1,22 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRequestProblemByTicket`( - vSelf INT -) -BEGIN -/** - * Actualiza los problemas de un ticket que tiene una petición de compra pendiente o - * deja de tenerla - * @param vSelf Id del ticket de la petición de compra - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem - FROM ticket t - WHERE t.id = vSelf; - - CALL ticket_getRequestProblem(); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/client_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql similarity index 95% rename from db/routines/vn/procedures/client_setRisk.sql rename to db/routines/vn/procedures/ticket_setRisk.sql index 020f554bf..a17df5ffc 100644 --- a/db/routines/vn/procedures/client_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_setRisk`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRisk`( vSelf INT) BEGIN /** diff --git a/db/routines/vn/procedures/ticket_setRiskProblemAll.sql b/db/routines/vn/procedures/ticket_setRiskProblemAll.sql deleted file mode 100644 index 2cdbe2ae6..000000000 --- a/db/routines/vn/procedures/ticket_setRiskProblemAll.sql +++ /dev/null @@ -1,39 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRiskProblemAll`() -BEGIN -/** - * Update the risk problem for all tickets - * - */ - CREATE OR REPLACE TEMPORARY TABLE tRisk - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, - t.risk > (c.credit + 10) hasRisk, - ((t.risk - cc.riskTolerance) > (c.credit + 10)) hasHighRisk - FROM client c - JOIN ticket t ON t.clientFk = c.id - JOIN clientConfig cc - WHERE t.shipped >= util.midnight(); - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT ticketFk, hasRisk hasProblem - FROM tRisk; - - CALL ticket_setProblem('hasRisk'); - DROP TEMPORARY TABLE tmp.ticket; - - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT ticketFk, hasHighRisk hasProblem - FROM tRisk; - - CALL ticket_setProblem('hasHighRisk'); - - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tRisk; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql deleted file mode 100644 index 84f0cdcaa..000000000 --- a/db/routines/vn/procedures/ticket_setTaxDataCheckedProblem.sql +++ /dev/null @@ -1,18 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` - PROCEDURE `vn`.`ticket_setTaxDataCheckedProblem`() -BEGIN -/** - * Update the problem of tickets, depending on whether - * the client taxDataCheched is verified or not - * - */ - UPDATE tmp.ticket t - JOIN ticket ti ON ti.id = t.ticketFk - JOIN client c ON c.id = ti.clientFk - SET ti.hasproblem = TRUE - WHERE NOT c.isTaxDataChecked; - - CALL ticket_setProblem('isTaxDataChecked'); -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql b/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql deleted file mode 100644 index 42f1bf42e..000000000 --- a/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemAll.sql +++ /dev/null @@ -1,22 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` - PROCEDURE `vn`.`ticket_setTaxDataCheckedProblemAll`() -proc: BEGIN -/** - * Update the problem of all tickets, depending on whether - * the client taxDataCheched is verified or not - */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem - FROM ticket t - JOIN client c ON c.id = t.clientFk - WHERE t.shipped >= util.midnight(); - - CALL ticket_getTaxDataCheckedProblem(); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file From 057121582e0bac0b50c629aa2ab1460e37456d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 13 May 2024 10:06:00 +0200 Subject: [PATCH 10/13] feat: Turn issues into calculated columns refs#7213 --- ...m.sql => sale_setProblemComponentLack.sql} | 2 +- ...le_setProblemComponentLackByComponent.sql} | 2 +- ...roblem.sql => sale_setProblemRounding.sql} | 2 +- ...cket_setProblemTaxDataCheckedByClient.sql} | 2 +- .../ticket_setProblemTooLittleConfig.sql | 20 ------------------- .../ticket_setProblemTooLittleItemCost.sql | 6 +++--- 6 files changed, 7 insertions(+), 27 deletions(-) rename db/routines/vn/procedures/{sale_setComponentLackProblem.sql => sale_setProblemComponentLack.sql} (93%) rename db/routines/vn/procedures/{sale_setComponentLackProblemComponent.sql => sale_setProblemComponentLackByComponent.sql} (94%) rename db/routines/vn/procedures/{sale_setRoundingProblem.sql => sale_setProblemRounding.sql} (96%) rename db/routines/vn/procedures/{ticket_setTaxDataCheckedProblemByClient.sql => ticket_setProblemTaxDataCheckedByClient.sql} (82%) delete mode 100644 db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql diff --git a/db/routines/vn/procedures/sale_setComponentLackProblem.sql b/db/routines/vn/procedures/sale_setProblemComponentLack.sql similarity index 93% rename from db/routines/vn/procedures/sale_setComponentLackProblem.sql rename to db/routines/vn/procedures/sale_setProblemComponentLack.sql index ede4e86b2..363663a00 100644 --- a/db/routines/vn/procedures/sale_setComponentLackProblem.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLack.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setComponentLackProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLack`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/sale_setComponentLackProblemComponent.sql b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql similarity index 94% rename from db/routines/vn/procedures/sale_setComponentLackProblemComponent.sql rename to db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql index 96e17f8ca..895598e84 100644 --- a/db/routines/vn/procedures/sale_setComponentLackProblemComponent.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setComponentLackProblemComponent`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLackByComponent`( vComponentFk INT ) BEGIN diff --git a/db/routines/vn/procedures/sale_setRoundingProblem.sql b/db/routines/vn/procedures/sale_setProblemRounding.sql similarity index 96% rename from db/routines/vn/procedures/sale_setRoundingProblem.sql rename to db/routines/vn/procedures/sale_setProblemRounding.sql index 0f4bb2c0c..366fbf8fd 100644 --- a/db/routines/vn/procedures/sale_setRoundingProblem.sql +++ b/db/routines/vn/procedures/sale_setProblemRounding.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setRoundingProblem`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRounding`( vSelf INT ) BEGIN diff --git a/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemByClient.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql similarity index 82% rename from db/routines/vn/procedures/ticket_setTaxDataCheckedProblemByClient.sql rename to db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql index 0bb73f691..fc2b32551 100644 --- a/db/routines/vn/procedures/ticket_setTaxDataCheckedProblemByClient.sql +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setTaxDataCheckedProblemByClient`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`tticket_setProblemTaxDataCheckedByClient`( vClientFk INT ) proc: BEGIN diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql deleted file mode 100644 index 3df0752e5..000000000 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleConfig.sql +++ /dev/null @@ -1,20 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittleConfig`() -BEGIN -/** - * Update the problems when the ticket is too small or is no longer so, - * derived from changes in the volumeConfig table - * - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem - FROM ticket t - WHERE t.shipped >= util.midnight(); - - CALL ticket_setProblem('isTooLittle'); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index 215b4d7db..178972d94 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -7,7 +7,7 @@ BEGIN * Update the problems when the ticket is too small or is no longer so, * derived from changes in the itemCost table * - * @param vItemFk Id del item + * @param vItemFk Id del item, NULL ALL items */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) @@ -16,8 +16,8 @@ BEGIN SELECT t.id ticketFk FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id - WHERE s.itemFk = vItemFk - AND t.shipped >= util.midnight() + WHERE t.shipped >= util.midnight() + AND (s.itemFk = vItemFk OR vItemFk IS NULL) GROUP BY t.id )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem FROM tickets; From b1af6259375c0eefadf1df414521b5a99d2a39f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 13 May 2024 12:32:46 +0200 Subject: [PATCH 11/13] feat: Turn issues into calculated columns refs#7213 --- db/routines/vn/procedures/ticket_setRisk.sql | 37 +++++++++++--------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index a17df5ffc..6985543ca 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -20,57 +20,62 @@ BEGIN (KEY (ticketFk)) ENGINE = MEMORY WITH ticket AS( - SELECT id ticketFk, DATE(shipped) dated + SELECT id ticketFk, companyFk, DATE(shipped) dated FROM vn.ticket t WHERE clientFk = vSelf AND refFk IS NULL AND NOT isDeleted AND totalWithoutVat <> 0 ), dated AS( - SELECT MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started, + SELECT t.companyFk, MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started, MAX(DATE(t.dated)) ended FROM ticket t JOIN vn.clientConfig cc + GROUP BY t.companyFk ), balance AS( - SELECT SUM(amount)amount + SELECT SUM(amount)amount, companyFk FROM ( - SELECT SUM(amount) amount + SELECT amount, companyFk FROM vn.clientRisk WHERE clientFk = vSelf UNION ALL - SELECT -(SUM(amount) / 100) amount + SELECT -(SUM(amount) / 100) amount, tm.companyFk FROM hedera.tpvTransaction t + JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk WHERE clientFk = vSelf AND receiptFk IS NULL AND status = 'ok' ) sub + WHERE companyFk + GROUP BY companyFk ), uninvoiced AS( - SELECT DATE(t.shipped) dated, SUM(t.totalWithVat) amount + SELECT t.companyFk, DATE(t.shipped) dated, SUM(IFNULL(t.totalWithVat, 0)) amount FROM vn.ticket t JOIN dated d WHERE t.clientFk = vSelf AND t.refFk IS NULL AND t.shipped BETWEEN d.started AND d.ended - GROUP BY DATE(t.shipped) + GROUP BY t.companyFk, DATE(t.shipped) ), receipt AS( - SELECT DATE(payed) dated, SUM(amountPaid) amount + SELECT companyFk,DATE(payed) dated, SUM(amountPaid) amount FROM vn.receipt WHERE clientFk = vSelf AND payed > util.VN_CURDATE() - GROUP BY DATE(payed) + GROUP BY companyFk, DATE(payed) ), risk AS( - SELECT ui.dated, - SUM(ui.amount) OVER (ORDER BY ui.dated) + + 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 - LEFT JOIN receipt r ON r.dated > ui.dated - GROUP BY ui.dated + 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 + SELECT ti.ticketFk, r.amount FROM ticket ti - JOIN risk r ON r.dated = ti.dated; + 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 f89ca786dfd5f42a18bef1d7cd4e4ff0c3736493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 13 May 2024 13:31:58 +0200 Subject: [PATCH 12/13] eat: Turn issues into calculated columns refs#7213 --- .../vn/functions/ticket_isTooLittle.sql | 1 + db/routines/vn/procedures/sale_setProblem.sql | 1 + .../vn/procedures/ticket_setProblem.sql | 2 ++ .../ticket_setProblemTaxDataChecked.sql | 2 +- ...icket_setProblemTaxDataCheckedByClient.sql | 25 ------------------- db/routines/vn/procedures/ticket_setRisk.sql | 16 ++++++------ 6 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql diff --git a/db/routines/vn/functions/ticket_isTooLittle.sql b/db/routines/vn/functions/ticket_isTooLittle.sql index 1af421a47..2ce24f0fa 100644 --- a/db/routines/vn/functions/ticket_isTooLittle.sql +++ b/db/routines/vn/functions/ticket_isTooLittle.sql @@ -8,6 +8,7 @@ BEGIN /** * Check if the ticket is small based on the volume and amount parameters. * + * @param vSelf Id ticket * @return BOOL */ DECLARE vIsTooLittle TINYINT(1); diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql index b0b1b8c6f..20319cc3f 100644 --- a/db/routines/vn/procedures/sale_setProblem.sql +++ b/db/routines/vn/procedures/sale_setProblem.sql @@ -5,6 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`( BEGIN /** * Update column sale.problem with a problem code + * @param vProblemCode Code to set or unset * @table tmp.sale(saleFk, hasProblem) */ UPDATE sale s diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql index 4566d3b79..bab8f1f52 100644 --- a/db/routines/vn/procedures/ticket_setProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblem.sql @@ -5,6 +5,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( BEGIN /** * Update column ticket.problem with a problem code + * + * @param vProblemCode Code to set or unset * @table tmp.ticket(ticketFk, hasProblem) */ UPDATE ticket t diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql index 18d81c037..bf946a0ee 100644 --- a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql @@ -6,7 +6,7 @@ BEGIN * Update the problem of tickets, depending on whether * the client taxDataCheched is verified or not * - * @param vSelf Id ticket, if NULL ALL tickets + * @param vSelf Id ticket, if NULL all tickets */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql deleted file mode 100644 index fc2b32551..000000000 --- a/db/routines/vn/procedures/ticket_setProblemTaxDataCheckedByClient.sql +++ /dev/null @@ -1,25 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`tticket_setProblemTaxDataCheckedByClient`( - vClientFk INT -) -proc: BEGIN -/** - * Update the problem of tickets for a specific client, depending on whether - * the client taxDataCheched is verified or not - * - * @param vClientFk Id cliente - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem - FROM ticket t - JOIN client c ON c.id = t.clientFk - WHERE t.shipped >= util.midnight() - AND c.id = vClientFk; - - CALL ticket_getTaxDataCheckedProblem(); - - DROP TEMPORARY TABLE tmp.ticket; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index 6985543ca..f5e6cb5a0 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -1,17 +1,17 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRisk`( - vSelf INT) + vClientFk INT) BEGIN /** * Update the risk for a client with pending tickets * - * @param vSelf Id cliente + * @param vClientFk Id cliente */ DECLARE vHasDebt BOOL; SELECT COUNT(*) INTO vHasDebt FROM `client` - WHERE id = vSelf + WHERE id = vClientFk AND typeFk = 'normal'; IF vHasDebt THEN @@ -22,7 +22,7 @@ BEGIN WITH ticket AS( SELECT id ticketFk, companyFk, DATE(shipped) dated FROM vn.ticket t - WHERE clientFk = vSelf + WHERE clientFk = vClientFk AND refFk IS NULL AND NOT isDeleted AND totalWithoutVat <> 0 @@ -37,12 +37,12 @@ BEGIN FROM ( SELECT amount, companyFk FROM vn.clientRisk - WHERE clientFk = vSelf + 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 = vSelf + WHERE clientFk = vClientFk AND receiptFk IS NULL AND status = 'ok' ) sub @@ -52,14 +52,14 @@ BEGIN SELECT t.companyFk, DATE(t.shipped) dated, SUM(IFNULL(t.totalWithVat, 0)) amount FROM vn.ticket t JOIN dated d - WHERE t.clientFk = vSelf + WHERE t.clientFk = vClientFk AND t.refFk IS NULL AND t.shipped BETWEEN d.started AND d.ended GROUP BY t.companyFk, DATE(t.shipped) ), receipt AS( SELECT companyFk,DATE(payed) dated, SUM(amountPaid) amount FROM vn.receipt - WHERE clientFk = vSelf + WHERE clientFk = vClientFk AND payed > util.VN_CURDATE() GROUP BY companyFk, DATE(payed) ), risk AS( From 3ce43909e27bb4b4ba9911aaa484d09d596c3d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 13 May 2024 14:21:01 +0200 Subject: [PATCH 13/13] feat: Turn issues into calculated columns refs#7213 --- db/routines/vn/procedures/ticket_setProblemRequest.sql | 2 -- db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql | 4 ++-- .../vn/procedures/ticket_setProblemTooLittleItemCost.sql | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setProblemRequest.sql b/db/routines/vn/procedures/ticket_setProblemRequest.sql index 13d918ab9..a5dc31472 100644 --- a/db/routines/vn/procedures/ticket_setProblemRequest.sql +++ b/db/routines/vn/procedures/ticket_setProblemRequest.sql @@ -8,7 +8,6 @@ BEGIN * * @param vSelf Id ticket, if NULL ALL tickets */ - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) ENGINE = MEMORY @@ -17,7 +16,6 @@ BEGIN WHERE t.shipped >= util.midnight() AND (vSelf IS NULL OR t.id = vSelf); - UPDATE tmp.ticket t JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk SET t.hasProblem = TRUE diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql index bf946a0ee..b6c2d8533 100644 --- a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql @@ -1,12 +1,12 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` - PROCEDURE `vn`.`ticket_setProblemTaxDataChecked`(vSelf INT) + PROCEDURE `vn`.`ticket_setProblemTaxDataChecked`(vClientFk INT) BEGIN /** * Update the problem of tickets, depending on whether * the client taxDataCheched is verified or not * - * @param vSelf Id ticket, if NULL all tickets + * @param vClientFk Id cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk)) diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index 178972d94..9a7852ac5 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -17,7 +17,7 @@ BEGIN FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id WHERE t.shipped >= util.midnight() - AND (s.itemFk = vItemFk OR vItemFk IS NULL) + AND (s.itemFk = vItemFk OR vItemFk IS NULL) GROUP BY t.id )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem FROM tickets;