From d276c7b6116ac2638f31e4f3848354c8358cc4f7 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 22 Mar 2023 10:57:18 +0100 Subject: [PATCH] refs #5342 unificados proc x_getWarnings --- db/changes/231201/00-itemType_isFragile.sql | 5 +++ db/changes/231201/00-sale_getWarnings.sql | 35 ------------------- db/changes/231201/00-ticket_getWarnings.sql | 30 +++++++++++----- .../back/methods/sales-monitor/salesFilter.js | 3 ++ 4 files changed, 29 insertions(+), 44 deletions(-) create mode 100644 db/changes/231201/00-itemType_isFragile.sql delete mode 100644 db/changes/231201/00-sale_getWarnings.sql diff --git a/db/changes/231201/00-itemType_isFragile.sql b/db/changes/231201/00-itemType_isFragile.sql new file mode 100644 index 000000000..00a74b8b6 --- /dev/null +++ b/db/changes/231201/00-itemType_isFragile.sql @@ -0,0 +1,5 @@ +ALTER TABLE `vn`.`itemType` ADD isFragile tinyint(1) NULL; +ALTER TABLE `vn`.`itemType` MODIFY COLUMN isFragile tinyint(1) DEFAULT 0 NOT NULL; +UPDATE `vn`.`itemType` + SET isFragile = 1 + WHERE code IN ('ZKA', 'ZKE'); diff --git a/db/changes/231201/00-sale_getWarnings.sql b/db/changes/231201/00-sale_getWarnings.sql deleted file mode 100644 index ee2c7b8f2..000000000 --- a/db/changes/231201/00-sale_getWarnings.sql +++ /dev/null @@ -1,35 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`sale_getWarnings`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_getWarnings`() -BEGIN -/** - * Calcula las advertencias de cada venta para un conjunto de tickets. - * - * @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular - * @return tmp.sale_warnings - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings; - CREATE TEMPORARY TABLE tmp.sale_warnings ( - ticketFk INT(11), - saleFk INT(11), - isFragile INTEGER(1) DEFAULT 0, - PRIMARY KEY (ticketFk, saleFk) - ) ENGINE = MEMORY; - - -- Frágil - INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile) - SELECT tt.ticketFk, s.id, TRUE - FROM tmp.sale_getWarnings tt - LEFT JOIN sale s ON s.ticketFk = tt.ticketFk - LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN agencyMode am ON am.id = tt.agencyModeFk - LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE dm.code IN ('AGENCY', 'DELIVERY') - AND (ic.code = 'plant' OR it.code IN ('ZKA', 'ZKE')); -END$$ -DELIMITER ; diff --git a/db/changes/231201/00-ticket_getWarnings.sql b/db/changes/231201/00-ticket_getWarnings.sql index 0cd420bd3..605fe6ad0 100644 --- a/db/changes/231201/00-ticket_getWarnings.sql +++ b/db/changes/231201/00-ticket_getWarnings.sql @@ -11,7 +11,26 @@ BEGIN * @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular * @return tmp.ticket_warnings */ - CALL sale_getWarnings(); + DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings; + CREATE TEMPORARY TABLE tmp.sale_warnings ( + ticketFk INT(11), + saleFk INT(11), + isFragile INTEGER(1) DEFAULT 0, + PRIMARY KEY (ticketFk, saleFk) + ) ENGINE = MEMORY; + + -- Frágil + INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile) + SELECT tt.ticketFk, s.id, TRUE + FROM tmp.sale_getWarnings tt + LEFT JOIN sale s ON s.ticketFk = tt.ticketFk + LEFT JOIN item i ON i.id = s.itemFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN agencyMode am ON am.id = tt.agencyModeFk + LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.code IN ('AGENCY') + AND (ic.code = 'plant' OR it.isFragile); DROP TEMPORARY TABLE IF EXISTS tmp.ticket_warnings; CREATE TEMPORARY TABLE tmp.ticket_warnings @@ -19,17 +38,10 @@ BEGIN ENGINE = MEMORY SELECT sw.ticketFk, - MAX(sw.isFragile) AS isFragile, - 0 AS totalWarnings + MAX(sw.isFragile) AS isFragile FROM tmp.sale_warnings sw GROUP BY sw.ticketFk; - UPDATE tmp.ticket_warnings tw - SET tw.totalWarnings = - ( - (tw.isFragile) - ); - DROP TEMPORARY TABLE tmp.sale_warnings; END$$ diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index c9a25b1a1..b6ebcc5a2 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -402,6 +402,9 @@ module.exports = Self => { tmp.filter, tmp.ticket_problems, tmp.sale_getProblems, + tmp.sale_warnings, + tmp.sale_getWarnings, + tmp.ticket_warnings, tmp.risk`); const sql = ParameterizedSQL.join(stmts, ';');