From 5517ac265da2dac8e581b3d2f1e64418c51953f8 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 4 Jun 2019 09:14:42 +0200 Subject: [PATCH] SQL webZone fixes --- .../10032-webZone/00-catalog_calcFromItem.sql | 5 + .../00-catalog_calcFromMyAddress.sql | 41 +++++++ db/changes/10032-webZone/00-deprecate.sql | 102 ++++++++++++++++++ .../00-myBasket_calcCatalogFromItem.sql | 1 + .../00-myBasket_calcCatalogFull.sql | 2 + db/changes/10032-webZone/00-order_addItem.sql | 10 +- .../00-order_calcCatalogFromItem.sql | 1 + .../00-order_calcCatalogFull.sql | 2 + db/changes/10032-webZone/00-order_update.sql | 2 +- db/changes/10032-webZone/98-rename.sql | 1 + db/changes/10032-webZone/99-privs.sql | 1 + 11 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql create mode 100644 db/changes/10032-webZone/98-rename.sql diff --git a/db/changes/10032-webZone/00-catalog_calcFromItem.sql b/db/changes/10032-webZone/00-catalog_calcFromItem.sql index 151f0c65c..03823d65c 100644 --- a/db/changes/10032-webZone/00-catalog_calcFromItem.sql +++ b/db/changes/10032-webZone/00-catalog_calcFromItem.sql @@ -11,6 +11,11 @@ BEGIN * Calculates available and price for a single item. * * @param vItemFk The item id + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped */ DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item diff --git a/db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql b/db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql new file mode 100644 index 000000000..ee2996bd6 --- /dev/null +++ b/db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql @@ -0,0 +1,41 @@ + +DROP procedure IF EXISTS `hedera`.`catalog_calcFromMyAddress`; +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`catalog_calcFromMyAddress`(vDelivery DATE, vAddress INT) +BEGIN +/** + * Gets the available items list. + * + * @param vDelivery Delivery date + * @param vAddress Address id + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + DECLARE vAgencyMode INT; + + SELECT a.agencyModeFk + INTO vAgencyMode + FROM myClient c + JOIN vn.address a ON a.clientFk = c.id + WHERE a.id = vAddress; + + CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT c.item_id itemFk + FROM `cache`.available c + JOIN tmp.availableCalc a ON a.calcFk = c.calc_id + WHERE c.available > 0 + GROUP BY c.item_id; + + CALL vn.ticketCalculate(vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/changes/10032-webZone/00-deprecate.sql b/db/changes/10032-webZone/00-deprecate.sql index a81628d32..5889c5a65 100644 --- a/db/changes/10032-webZone/00-deprecate.sql +++ b/db/changes/10032-webZone/00-deprecate.sql @@ -238,3 +238,105 @@ END$$ DELIMITER ; ; + + +USE `hedera`; +DROP procedure IF EXISTS `hedera`.`myItemGetAvailableFromDate`; + +DELIMITER $$ +USE `hedera`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `__myItemGetAvailableFromDate`(vDelivery DATE) +BEGIN +/** + * Gets the available items list. + * + * @deprecated Use item_calcCatalogFromMyAddress() + * @param vDelivery Delivery date + */ + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + + SELECT a.agencyModeFk, a.id + INTO vAgencyMode, vAddress + FROM myClient c + JOIN vn.address a ON a.id = c.defaultAddressFk; + + CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT c.item_id itemFk + FROM cache.available c + JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id + WHERE c.available > 0 + GROUP BY c.item_id; + + CALL vn.ticketCalculate(vDelivery, vAddress, vAgencyMode); +-- ------------------- + /*SELECT b.itemFk, b.item, b.available, b.price + FROM tmp.ticketCalculateItem b + JOIN vn.item i ON i.id = b.itemFk + WHERE b.available > 0 + ORDER BY i.relevancy DESC, i.name, i.size; + + select * from tmp.ticketComponentPrice;*/ +-- ------------------- + DROP TEMPORARY TABLE vn2008.t_bionic_available; +END$$ + +DELIMITER ; +; + + +USE `hedera`; +DROP procedure IF EXISTS `hedera`.`myItemGetAvailable`; + +DELIMITER $$ +USE `hedera`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `__myItemGetAvailable`(vDelivery DATE, vAddress INT) +BEGIN +/** + * Gets the available items list. + * + * @deprecated Use item_calcCatalogFromMyAddress() + * @param vDelivery Delivery date + * @param vAddress Id Address + */ + DECLARE vAgencyMode INT; + + SELECT a.agencyModeFk + INTO vAgencyMode + FROM myClient c + JOIN vn.address a ON a.clientFk = c.id + WHERE a.id = vAddress; + + CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT c.item_id itemFk + FROM cache.available c + JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id + WHERE c.available > 0 + GROUP BY c.item_id; + + CALL vn.ticketCalculate(vDelivery, vAddress, vAgencyMode); +-- ------------------- + /*SELECT b.itemFk, b.item, b.available, b.price + FROM tmp.ticketCalculateItem b + JOIN vn.item i ON i.id = b.itemFk + WHERE b.available > 0 + ORDER BY i.relevancy DESC, i.name, i.size; + + select * from tmp.ticketComponentPrice;*/ +-- ------------------- + DROP TEMPORARY TABLE vn2008.t_bionic_available; +END$$ + +DELIMITER ; +; + diff --git a/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql b/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql index ad673b38c..edde8f389 100644 --- a/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql +++ b/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql @@ -12,6 +12,7 @@ BEGIN * @return tmp.ticketComponentPrice * @return tmp.ticketComponent * @return tmp.ticketLot + * @return tmp.zoneGetShipped */ CALL order_calcCatalogFromItem(myBasket_getId(), vItem); END$$ diff --git a/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql b/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql index 96e06fa3b..8e182faa9 100644 --- a/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql +++ b/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql @@ -10,7 +10,9 @@ BEGIN * @table tmp.item(itemFk) * @return tmp.ticketCalculateItem * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent * @return tmp.ticketLot + * @return tmp.zoneGetShipped */ CALL order_calcCatalogFull(myBasket_getId()); END$$ diff --git a/db/changes/10032-webZone/00-order_addItem.sql b/db/changes/10032-webZone/00-order_addItem.sql index a56679f3e..90a4efaad 100644 --- a/db/changes/10032-webZone/00-order_addItem.sql +++ b/db/changes/10032-webZone/00-order_addItem.sql @@ -6,7 +6,15 @@ CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_addItem`( vWarehouse INT, vItem INT, vAmount INT) -BEGIN +BEGIN +/** + * Adds an item to the order, checking availability and grouping. + * + * @param vSelf The order id + * @param vWarehouse The warehouse id + * @param vItem The item id + * @param vAmount The amount to add + */ DECLARE vRow INT; DECLARE vAdd INT; DECLARE vAvailable INT; diff --git a/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql b/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql index ba2533a24..8f4ca6012 100644 --- a/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql +++ b/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql @@ -13,6 +13,7 @@ BEGIN * @return tmp.ticketComponentPrice * @return tmp.ticketComponent * @return tmp.ticketLot + * @return tmp.zoneGetShipped */ DECLARE vDate DATE; DECLARE vAddress INT; diff --git a/db/changes/10032-webZone/00-order_calcCatalogFull.sql b/db/changes/10032-webZone/00-order_calcCatalogFull.sql index 221f0ac99..7d57be472 100644 --- a/db/changes/10032-webZone/00-order_calcCatalogFull.sql +++ b/db/changes/10032-webZone/00-order_calcCatalogFull.sql @@ -11,7 +11,9 @@ BEGIN * @table tmp.item(itemFk) * @return tmp.ticketCalculateItem * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent * @return tmp.ticketLot + * @return tmp.zoneGetShipped */ DECLARE vDate DATE; DECLARE vAddress INT; diff --git a/db/changes/10032-webZone/00-order_update.sql b/db/changes/10032-webZone/00-order_update.sql index 29d6a98fc..23e4045e5 100644 --- a/db/changes/10032-webZone/00-order_update.sql +++ b/db/changes/10032-webZone/00-order_update.sql @@ -4,7 +4,7 @@ DELIMITER $$ CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_update`(vSelf INT) proc: BEGIN /** - * Actualiza la líneas de un pedido. + * Actualiza las líneas de un pedido. * * @param vSelf Id del pedido */ diff --git a/db/changes/10032-webZone/98-rename.sql b/db/changes/10032-webZone/98-rename.sql new file mode 100644 index 000000000..d0799b6e6 --- /dev/null +++ b/db/changes/10032-webZone/98-rename.sql @@ -0,0 +1 @@ +RENAME TABLE hedera.myOrderMyTicket TO hedera.myOrderTicket; \ No newline at end of file diff --git a/db/changes/10032-webZone/99-privs.sql b/db/changes/10032-webZone/99-privs.sql index 2f92e7c14..b14c5ae2f 100644 --- a/db/changes/10032-webZone/99-privs.sql +++ b/db/changes/10032-webZone/99-privs.sql @@ -3,4 +3,5 @@ GRANT EXECUTE ON PROCEDURE hedera.myBasket_calcCatalogFromItem TO `guest`@`%`; GRANT EXECUTE ON PROCEDURE hedera.myBasket_calcCatalogFull TO `guest`@`%`; GRANT EXECUTE ON PROCEDURE hedera.myBasket_getAvailable TO `guest`@`%`; GRANT EXECUTE ON PROCEDURE hedera.myOrder_getAvailable TO `guest`@`%`; +GRANT EXECUTE ON PROCEDURE hedera.catalog_calcFromMyAddress TO account@'%'; CALL account.privSync;