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