From 8469b2ac3f0fbf08cdd740c72392644eaa658a59 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 08:24:50 +0200 Subject: [PATCH 1/3] feat: refs #7683 productionControl --- .../vn/procedures/productionControl.sql | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index dad46393d..1b4a8e88a 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -174,27 +174,30 @@ proc: BEGIN WHERE NOT `lines`; -- Lineas por linea de encajado + CREATE OR REPLACE TEMPORARY TABLE tItemPackingType + (PRIMARY KEY(ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, + SUM(sub.H) H, + SUM(sub.V) V, + SUM(sub.N) N + FROM ( + SELECT t.ticketFk, + SUM(i.itemPackingTypeFk = 'H') H, + SUM(i.itemPackingTypeFk = 'V') V, + SUM(i.itemPackingTypeFk IS NULL) N + FROM tmp.productionTicket t + JOIN sale s ON s.ticketFk = t.ticketFk + JOIN item i ON i.id = s.itemFk + GROUP BY t.ticketFk, i.itemPackingTypeFk + ) sub + GROUP BY ticketFk; + UPDATE tmp.productionBuffer pb - JOIN ( - SELECT ticketFk, - SUM(sub.H) H, - SUM(sub.V) V, - SUM(sub.N) N - FROM ( - SELECT t.ticketFk, - SUM(i.itemPackingTypeFk = 'H') H, - SUM(i.itemPackingTypeFk = 'V') V, - SUM(i.itemPackingTypeFk IS NULL) N - FROM tmp.productionTicket t - JOIN sale s ON s.ticketFk = t.ticketFk - JOIN item i ON i.id = s.itemFk - GROUP BY t.ticketFk, i.itemPackingTypeFk - ) sub - GROUP BY ticketFk - ) sub2 ON sub2.ticketFk = pb.ticketFk - SET pb.H = sub2.H, - pb.V = sub2.V, - pb.N = sub2.N; + JOIN tItemPackingType ti ON ti.ticketFk = pb.ticketFk + SET pb.H = ti.H, + pb.V = ti.V, + pb.N = ti.N; -- Colecciones segun tipo de encajado UPDATE tmp.productionBuffer pb From c17214ce05e07f58562a0d4c3ac7e1bef8952e59 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 18 Jul 2024 11:50:01 +0200 Subject: [PATCH 2/3] feat: refs #7683 drop temporary table --- db/routines/vn/procedures/productionControl.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index 1b4a8e88a..ad1434189 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -199,6 +199,8 @@ proc: BEGIN pb.V = ti.V, pb.N = ti.N; + DROP TEMPORARY TABLE tItemPackingType; + -- Colecciones segun tipo de encajado UPDATE tmp.productionBuffer pb JOIN ticketCollection tc ON pb.ticketFk = tc.ticketFk From 15adc59ec5f006ae74a771bc0b8faa3036178f4f Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 18 Jul 2024 12:04:17 +0200 Subject: [PATCH 3/3] feat: refs #7683 drop temporary table --- db/routines/vn/procedures/productionControl.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index ad1434189..af6d929d7 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -199,8 +199,6 @@ proc: BEGIN pb.V = ti.V, pb.N = ti.N; - DROP TEMPORARY TABLE tItemPackingType; - -- Colecciones segun tipo de encajado UPDATE tmp.productionBuffer pb JOIN ticketCollection tc ON pb.ticketFk = tc.ticketFk @@ -278,6 +276,7 @@ proc: BEGIN tmp.risk, tmp.ticket_problems, tmp.ticketWithPrevia, - tItemShelvingStock; + tItemShelvingStock, + tItemPackingType; END$$ DELIMITER ;