salix/db/changes/10300-newFacility/02-waste_addSales.sql

39 lines
753 B
MySQL
Raw Normal View History

2021-03-30 08:28:44 +00:00
UPDATE `bs`.nightTask t SET t.`procedure` = 'waste_addSales' WHERE t.id = 54;
2021-04-01 11:12:02 +00:00
DROP PROCEDURE IF EXISTS `bs`.`waste_Add`;
2021-03-30 08:28:44 +00:00
CREATE
DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`()
BEGIN
DECLARE vWeek INT;
DECLARE vYear INT;
SELECT week, year
INTO vWeek, vYear
FROM vn.time
WHERE dated = CURDATE();
REPLACE bs.waste
SELECT *, 100 * mermas / total as porcentaje
FROM (
SELECT buyer,
year,
week,
family,
itemFk,
itemTypeFk,
floor(sum(value)) as total,
floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas
FROM vn.saleValue
where year = vYear and week = vWeek
GROUP BY family
) sub
ORDER BY mermas DESC;
END;