From 889982dd82e09e038ae3a89766b50481742b4a56 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 12:00:54 +0200 Subject: [PATCH] refactor: refs #7126 Requested changes --- db/routines/bs/procedures/waste_addSales.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index 234719582..3e189d2e6 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -1,7 +1,10 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`() BEGIN - CALL cache.last_buy_refresh (FALSE); + DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL WEEKDAY(CURDATE()) DAY; + DECLARE vDateTo DATE DEFAULT vDateFrom + INTERVAL 6 DAY; + + CALL cache.last_buy_refresh(FALSE); REPLACE bs.waste SELECT YEAR(t.shipped), @@ -40,9 +43,8 @@ BEGIN JOIN vn.buy b ON b.id = lb.buy_id LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id LEFT JOIN vn.component c ON c.id = sc.componentFk - WHERE w.isManaged - AND YEAR(t.shipped) = YEAR(util.VN_CURDATE()) - AND WEEK(t.shipped, 4) = WEEK(util.VN_CURDATE(), 4) + WHERE t.shipped BETWEEN vDateFrom AND vDateTo + AND w.isManaged GROUP BY it.id, i.id; END$$ DELIMITER ;