feat: refs #8007 Added country salesByWeek

This commit is contained in:
Guillermo Bonet 2024-11-12 14:06:10 +01:00
parent 4891e98109
commit e1c16a498e
2 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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;