From e1c16a498ea5fb60dc05227d5e99237a8dc597da Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 12 Nov 2024 14:06:10 +0100 Subject: [PATCH 1/3] feat: refs #8007 Added country salesByWeek --- db/routines/bs/procedures/indicatorsUpdate.sql | 11 +++++------ db/versions/11340-maroonHydrangea/00-firstScript.sql | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 db/versions/11340-maroonHydrangea/00-firstScript.sql diff --git a/db/routines/bs/procedures/indicatorsUpdate.sql b/db/routines/bs/procedures/indicatorsUpdate.sql index d66e52a61..7b5cd090d 100644 --- a/db/routines/bs/procedures/indicatorsUpdate.sql +++ b/db/routines/bs/procedures/indicatorsUpdate.sql @@ -125,12 +125,11 @@ BEGIN TRUNCATE salesByWeek; - INSERT INTO salesByWeek (week, year, sales) - SELECT t.week, t.year, SUM(v.importe + v.recargo) sales - FROM ventas v - LEFT JOIN vn.time t ON t.dated = fecha - GROUP BY t.week, t.year - ORDER BY t.week, t.year; + INSERT INTO salesByWeek (`year`, `week`, countryFk, sales) + SELECT YEAR(s.dated), WEEK(s.dated, 4), c.countryFk, SUM(s.amount) + FROM sale s + JOIN client c ON c.id = s.clientFk + GROUP BY YEAR(s.dated), WEEK(s.dated, 4), c.countryFk -- Indicador Ventas semana actual UPDATE indicators i diff --git a/db/versions/11340-maroonHydrangea/00-firstScript.sql b/db/versions/11340-maroonHydrangea/00-firstScript.sql new file mode 100644 index 000000000..b3eaea992 --- /dev/null +++ b/db/versions/11340-maroonHydrangea/00-firstScript.sql @@ -0,0 +1,8 @@ +ALTER TABLE bs.salesByWeek + ADD countryFk mediumint(8) unsigned NOT NULL, + CHANGE `year` `year` int(11) NOT NULL FIRST, + CHANGE countryFk countryFk mediumint(8) unsigned NOT NULL AFTER week, + CHANGE sales total double DEFAULT NULL NULL, + ADD CONSTRAINT salesByWeek_country_FK FOREIGN KEY (countryFk) REFERENCES vn.country(id) + ON DELETE RESTRICT + ON UPDATE CASCADE; -- 2.40.1 From 8308bad100fa98566c5c441164878814dbe9ae15 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 12 Nov 2024 14:06:34 +0100 Subject: [PATCH 2/3] feat: refs #8007 Added country salesByWeek --- db/routines/bs/procedures/indicatorsUpdate.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/bs/procedures/indicatorsUpdate.sql b/db/routines/bs/procedures/indicatorsUpdate.sql index 7b5cd090d..35c9a822f 100644 --- a/db/routines/bs/procedures/indicatorsUpdate.sql +++ b/db/routines/bs/procedures/indicatorsUpdate.sql @@ -129,7 +129,7 @@ BEGIN SELECT YEAR(s.dated), WEEK(s.dated, 4), c.countryFk, SUM(s.amount) FROM sale s JOIN client c ON c.id = s.clientFk - GROUP BY YEAR(s.dated), WEEK(s.dated, 4), c.countryFk + GROUP BY YEAR(s.dated), WEEK(s.dated, 4), c.countryFk; -- Indicador Ventas semana actual UPDATE indicators i -- 2.40.1 From 4d3884f5c1ebfd26476eeb5423199ad484d4ca7b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 12 Nov 2024 14:08:29 +0100 Subject: [PATCH 3/3] feat: refs #8007 Added country salesByWeek --- db/routines/bs/procedures/indicatorsUpdate.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/bs/procedures/indicatorsUpdate.sql b/db/routines/bs/procedures/indicatorsUpdate.sql index 35c9a822f..5dbf5f8f6 100644 --- a/db/routines/bs/procedures/indicatorsUpdate.sql +++ b/db/routines/bs/procedures/indicatorsUpdate.sql @@ -125,7 +125,7 @@ BEGIN TRUNCATE salesByWeek; - INSERT INTO salesByWeek (`year`, `week`, countryFk, sales) + INSERT INTO salesByWeek (`year`, `week`, countryFk, total) SELECT YEAR(s.dated), WEEK(s.dated, 4), c.countryFk, SUM(s.amount) FROM sale s JOIN client c ON c.id = s.clientFk -- 2.40.1