2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`()
|
|
|
|
BEGIN
|
|
|
|
DECLARE vWeek INT;
|
|
|
|
DECLARE vYear INT;
|
|
|
|
|
|
|
|
SELECT week, year
|
|
|
|
INTO vWeek, vYear
|
|
|
|
FROM vn.time
|
|
|
|
WHERE dated = util.VN_CURDATE();
|
|
|
|
|
|
|
|
REPLACE bs.waste
|
|
|
|
SELECT *, 100 * mermas / total as porcentaje
|
|
|
|
FROM (
|
|
|
|
SELECT buyer,
|
|
|
|
year,
|
|
|
|
week,
|
|
|
|
family,
|
|
|
|
itemFk,
|
|
|
|
itemTypeFk,
|
|
|
|
floor(sum(value)) as total,
|
2024-02-20 12:10:03 +00:00
|
|
|
floor(sum(IF(typeFk = 'loses', value, 0))) as mermas
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM vn.saleValue
|
|
|
|
where year = vYear and week = vWeek
|
|
|
|
|
|
|
|
GROUP BY family, itemFk
|
|
|
|
|
|
|
|
) sub
|
|
|
|
ORDER BY mermas DESC;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|