Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-04-26 13:41:05 +02:00
commit 5ad0f15720
5 changed files with 84 additions and 73 deletions

View File

@ -1,24 +1,28 @@
drop procedure weekWaste;
DROP PROCEDURE IF EXISTS `bs`.`weekWaste`;
create definer = root@`%` procedure weekWaste__()
DELIMITER $$
$$
CREATE DEFINER = `root`@`%` PROCEDURE `bs`.`weekWaste__`()
BEGIN
DECLARE vWeek INT;
DECLARE vWeek INT;
DECLARE vYear INT;
SELECT week, year
INTO vWeek, vYear
FROM vn.time
WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK);
INTO vWeek, vYear
FROM vn.time
WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK);
SELECT *, 100 * dwindle / total AS percentage
FROM (
SELECT buyer,
sum(saleTotal) as total,
sum(saleWaste) as dwindle
FROM bs.waste
WHERE year = vYear and week = vWeek
GROUP BY buyer
) sub
ORDER BY percentage DESC;
END;
SELECT *, 100 * dwindle / total AS percentage
FROM (
SELECT buyer,
SUM(saleTotal) AS total,
SUM(saleWaste) AS dwindle
FROM bs.waste
WHERE year = vYear
AND week = vWeek
GROUP BY buyer
) sub
ORDER BY percentage DESC;
END;$$
DELIMITER ;

View File

@ -1,28 +1,32 @@
drop procedure weekWaste_byWorker;
DROP PROCEDURE IF EXISTS `bs`.`weekWaste_byWorker`;
create definer = root@`%` procedure weekWaste_byWorker__(IN vWorkerFk int)
DELIMITER $$
$$
CREATE
DEFINER = root@`%` PROCEDURE `bs`.`weekWaste_byWorker__`(IN vWorkerFk INT)
BEGIN
DECLARE vWeek INT;
DECLARE vWeek INT;
DECLARE vYear INT;
SELECT week, year
INTO vWeek, vYear
FROM vn.time
WHERE dated = TIMESTAMPADD(WEEK,-1,CURDATE());
INTO vWeek, vYear
FROM vn.time
WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE());
SELECT *, 100 * mermas / total as porcentaje
FROM (
SELECT ws.family,
sum(ws.saleTotal) as total,
sum(ws.saleWaste) as mermas
FROM bs.waste ws
SELECT *, 100 * mermas / total AS porcentaje
FROM (
SELECT ws.family,
SUM(ws.saleTotal) AS total,
SUM(ws.saleWaste) AS mermas
FROM bs.waste ws
JOIN vn.worker w ON w.user = ws.buyer
WHERE year = vYear AND week = vWeek
AND w.id = vWorkerFk
GROUP BY family
) sub
ORDER BY porcentaje DESC;
END;
WHERE year = vYear
AND week = vWeek
AND w.id = vWorkerFk
GROUP BY family
) sub
ORDER BY porcentaje DESC;
END;;$$
DELIMITER ;

View File

@ -1,25 +1,30 @@
drop procedure weekWaste_getDetail;
DROP PROCEDURE IF EXISTS `bs`.`weekWaste_getDetail`;
create definer = root@`%` procedure weekWaste_getDetail__()
DELIMITER $$
$$
CREATE
DEFINER = root@`%` PROCEDURE `bs`.`weekWaste_getDetail__`()
BEGIN
DECLARE vLastWeek DATE;
DECLARE vWeek INT;
DECLARE vLastWeek DATE;
DECLARE vWeek INT;
DECLARE vYear INT;
SET vLastWeek = TIMESTAMPADD(WEEK,-1,CURDATE());
SET vLastWeek = TIMESTAMPADD(WEEK, -1, CURDATE());
SET vYear = YEAR(vLastWeek);
SET vWeek = WEEK(vLastWeek, 1);
SELECT *, 100 * dwindle / total AS percentage
FROM (
SELECT buyer,
ws.family,
sum(ws.saleTotal) AS total,
sum(ws.saleWaste) AS dwindle
FROM bs.waste ws
WHERE year = vYear AND week = vWeek
GROUP BY buyer, family
) sub
ORDER BY percentage DESC;
END;
SELECT *, 100 * dwindle / total AS percentage
FROM (
SELECT buyer,
ws.family,
SUM(ws.saleTotal) AS total,
SUM(ws.saleWaste) AS dwindle
FROM bs.waste ws
WHERE year = vYear
AND week = vWeek
GROUP BY buyer, family
) sub
ORDER BY percentage DESC;
END;$$
DELIMITER ;

View File

@ -17,6 +17,5 @@ ALTER TABLE `bs`.`waste`
ALTER TABLE `bs`.`waste` DROP PRIMARY KEY;
ALTER TABLE `bs`.`waste`
AD PRIMARY KEY (buyer, year, week, family, itemFk);
ADD PRIMARY KEY (buyer, `year`, week, family, itemFk);

View File

@ -2,27 +2,28 @@ UPDATE `bs`.nightTask t SET t.`procedure` = 'waste_addSales' WHERE t.id = 54;
DROP PROCEDURE IF EXISTS `bs`.`waste_Add`;
DELIMITER $$
$$
CREATE
DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`()
DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`()
BEGIN
DECLARE vWeek INT;
DECLARE vYear INT;
SELECT week, year
DECLARE vYear INT;
SELECT week, year
INTO vWeek, vYear
FROM vn.time
WHERE dated = CURDATE();
FROM vn.time
WHERE dated = CURDATE();
REPLACE bs.waste
REPLACE bs.waste
SELECT *, 100 * mermas / total as porcentaje
FROM (
SELECT buyer,
year,
week,
week,
family,
itemFk,
itemTypeFk,
itemFk,
itemTypeFk,
floor(sum(value)) as total,
floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas
FROM vn.saleValue
@ -32,7 +33,5 @@ BEGIN
) sub
ORDER BY mermas DESC;
END;
END;$$
DELIMITER ;