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

38 lines
725 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
2021-04-26 11:40:52 +00:00
DELIMITER $$
$$
2021-03-30 08:28:44 +00:00
CREATE
2021-04-26 11:40:52 +00:00
DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`()
2021-03-30 08:28:44 +00:00
BEGIN
DECLARE vWeek INT;
2021-04-26 11:40:52 +00:00
DECLARE vYear INT;
SELECT week, year
2021-03-30 08:28:44 +00:00
INTO vWeek, vYear
2021-04-26 11:40:52 +00:00
FROM vn.time
WHERE dated = CURDATE();
2021-03-30 08:28:44 +00:00
2021-04-26 11:40:52 +00:00
REPLACE bs.waste
2021-03-30 08:28:44 +00:00
SELECT *, 100 * mermas / total as porcentaje
FROM (
SELECT buyer,
year,
2021-04-26 11:40:52 +00:00
week,
2021-03-30 08:28:44 +00:00
family,
2021-04-26 11:40:52 +00:00
itemFk,
itemTypeFk,
2021-03-30 08:28:44 +00:00
floor(sum(value)) as total,
floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas
FROM vn.saleValue
where year = vYear and week = vWeek
2021-04-06 11:46:38 +00:00
GROUP BY family, itemFk
2021-03-30 08:28:44 +00:00
) sub
ORDER BY mermas DESC;
2021-04-26 11:40:52 +00:00
END;$$
DELIMITER ;