Merge branch 'dev' into 2893-show-expedition.externalId
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-04-26 11:52:42 +00:00
commit e952e995cb
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 BEGIN
DECLARE vWeek INT; DECLARE vWeek INT;
DECLARE vYear INT; DECLARE vYear INT;
SELECT week, year SELECT week, year
INTO vWeek, vYear INTO vWeek, vYear
FROM vn.time FROM vn.time
WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK); WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK);
SELECT *, 100 * dwindle / total AS percentage SELECT *, 100 * dwindle / total AS percentage
FROM ( FROM (
SELECT buyer, SELECT buyer,
sum(saleTotal) as total, SUM(saleTotal) AS total,
sum(saleWaste) as dwindle SUM(saleWaste) AS dwindle
FROM bs.waste FROM bs.waste
WHERE year = vYear and week = vWeek WHERE year = vYear
GROUP BY buyer AND week = vWeek
) sub GROUP BY buyer
ORDER BY percentage DESC; ) sub
END; 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 BEGIN
DECLARE vWeek INT; DECLARE vWeek INT;
DECLARE vYear INT; DECLARE vYear INT;
SELECT week, year SELECT week, year
INTO vWeek, vYear INTO vWeek, vYear
FROM vn.time FROM vn.time
WHERE dated = TIMESTAMPADD(WEEK,-1,CURDATE()); WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE());
SELECT *, 100 * mermas / total as porcentaje SELECT *, 100 * mermas / total AS porcentaje
FROM ( FROM (
SELECT ws.family, SELECT ws.family,
sum(ws.saleTotal) as total, SUM(ws.saleTotal) AS total,
sum(ws.saleWaste) as mermas SUM(ws.saleWaste) AS mermas
FROM bs.waste ws FROM bs.waste ws
JOIN vn.worker w ON w.user = ws.buyer JOIN vn.worker w ON w.user = ws.buyer
WHERE year = vYear AND week = vWeek WHERE year = vYear
AND w.id = vWorkerFk AND week = vWeek
GROUP BY family AND w.id = vWorkerFk
GROUP BY family
) sub ) sub
ORDER BY porcentaje DESC; ORDER BY porcentaje DESC;
END; 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 BEGIN
DECLARE vLastWeek DATE; DECLARE vLastWeek DATE;
DECLARE vWeek INT; DECLARE vWeek INT;
DECLARE vYear INT; DECLARE vYear INT;
SET vLastWeek = TIMESTAMPADD(WEEK,-1,CURDATE()); SET vLastWeek = TIMESTAMPADD(WEEK, -1, CURDATE());
SET vYear = YEAR(vLastWeek); SET vYear = YEAR(vLastWeek);
SET vWeek = WEEK(vLastWeek, 1); SET vWeek = WEEK(vLastWeek, 1);
SELECT *, 100 * dwindle / total AS percentage SELECT *, 100 * dwindle / total AS percentage
FROM ( FROM (
SELECT buyer, SELECT buyer,
ws.family, ws.family,
sum(ws.saleTotal) AS total, SUM(ws.saleTotal) AS total,
sum(ws.saleWaste) AS dwindle SUM(ws.saleWaste) AS dwindle
FROM bs.waste ws FROM bs.waste ws
WHERE year = vYear AND week = vWeek WHERE year = vYear
GROUP BY buyer, family AND week = vWeek
) sub GROUP BY buyer, family
ORDER BY percentage DESC; ) sub
END; 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` DROP PRIMARY KEY;
ALTER TABLE `bs`.`waste` 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`; DROP PROCEDURE IF EXISTS `bs`.`waste_Add`;
DELIMITER $$
$$
CREATE CREATE
DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`() DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`()
BEGIN BEGIN
DECLARE vWeek INT; DECLARE vWeek INT;
DECLARE vYear INT; DECLARE vYear INT;
SELECT week, year SELECT week, year
INTO vWeek, vYear INTO vWeek, vYear
FROM vn.time FROM vn.time
WHERE dated = CURDATE(); WHERE dated = CURDATE();
REPLACE bs.waste REPLACE bs.waste
SELECT *, 100 * mermas / total as porcentaje SELECT *, 100 * mermas / total as porcentaje
FROM ( FROM (
SELECT buyer, SELECT buyer,
year, year,
week, week,
family, family,
itemFk, itemFk,
itemTypeFk, itemTypeFk,
floor(sum(value)) as total, floor(sum(value)) as total,
floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas
FROM vn.saleValue FROM vn.saleValue
@ -32,7 +33,5 @@ BEGIN
) sub ) sub
ORDER BY mermas DESC; ORDER BY mermas DESC;
END;$$
END; DELIMITER ;