From 20b4f6ec745f1a9c8f1e22a01a8343c05cb643e6 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 21 Jan 2020 09:33:26 +0100 Subject: [PATCH] updated tests --- .../10140-kings/00-weekWaste_getDetail.sql | 29 +++++++++++++++++++ db/dump/fixtures.sql | 20 ++++++------- 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 db/changes/10140-kings/00-weekWaste_getDetail.sql diff --git a/db/changes/10140-kings/00-weekWaste_getDetail.sql b/db/changes/10140-kings/00-weekWaste_getDetail.sql new file mode 100644 index 000000000..a7e099f58 --- /dev/null +++ b/db/changes/10140-kings/00-weekWaste_getDetail.sql @@ -0,0 +1,29 @@ +USE `bs`; +DROP procedure IF EXISTS `weekWaste_getDetail`; + +DELIMITER $$ +USE `bs`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `weekWaste_getDetail`() +BEGIN + DECLARE vLastWeek DATE; + DECLARE vWeek INT; + DECLARE vYear INT; + + 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$$ + +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index d72b579db..d315933fa 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1136,16 +1136,16 @@ INSERT INTO `bi`.`claims_ratio`(`id_Cliente`, `Consumo`, `Reclamaciones`, `Ratio INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `saleTotal`, `saleWaste`, `rate`) VALUES - ('CharlesXavier', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Carnation', '1062', '51', '4.8'), - ('CharlesXavier', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Carnation Colombia', '35074', '687', '2.0'), - ('CharlesXavier', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Carnation Mini', '1777', '13', '0.7'), - ('CharlesXavier', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Carnation Short', '9182', '59', '0.6'), - ('DavidCharlesHaller', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Containers', '-74', '0', '0.0'), - ('DavidCharlesHaller', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Packagings', '-7', '0', '0.0'), - ('DavidCharlesHaller', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Freight', '1100', '0', '0.0'), - ('HankPym', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Funeral Accessories', '848', '-187', '-22.1'), - ('HankPym', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Miscellaneous Accessories', '186', '0', '0.0'), - ('HankPym', YEAR(CURDATE()), WEEK(CURDATE(), 1), 'Adhesives', '277', '0', '0.0'); + ('CharlesXavier', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation', '1062', '51', '4.8'), + ('CharlesXavier', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Colombia', '35074', '687', '2.0'), + ('CharlesXavier', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Mini', '1777', '13', '0.7'), + ('CharlesXavier', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Short', '9182', '59', '0.6'), + ('DavidCharlesHaller', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Containers', '-74', '0', '0.0'), + ('DavidCharlesHaller', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Packagings', '-7', '0', '0.0'), + ('DavidCharlesHaller', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Freight', '1100', '0', '0.0'), + ('HankPym', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Funeral Accessories', '848', '-187', '-22.1'), + ('HankPym', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Miscellaneous Accessories', '186', '0', '0.0'), + ('HankPym', YEAR(DATE_ADD(CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(CURDATE(), INTERVAL -1 WEEK), 1), 'Adhesives', '277', '0', '0.0'); INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packageFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`,`minPrice`,`producer`,`printedStickers`,`isChecked`,`isIgnored`, `created`) VALUES