From 8af2cabaea916122286dc2e0e4ab6c79608ea28e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 6 Feb 2024 13:31:58 +0100 Subject: [PATCH 01/10] refs #6281 feat:buyFk in itemShelving --- .../vn/procedures/itemShelvingTransfer.sql | 1 + .../vn/procedures/itemShelving_add.sql | 70 +++++++++++-------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingTransfer.sql b/db/routines/vn/procedures/itemShelvingTransfer.sql index 326f8108b..b75cef627 100644 --- a/db/routines/vn/procedures/itemShelvingTransfer.sql +++ b/db/routines/vn/procedures/itemShelvingTransfer.sql @@ -24,6 +24,7 @@ BEGIN ON ish2.itemFk = ish.itemFk AND ish2.packing = ish.packing AND date(ish2.created) = date(ish.created) + AND ish2.buyFk = ish.buyFk WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci; IF vNewItemShelvingFk THEN diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 02762fa0b..cc6e9bb49 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -1,8 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN - - /** * Añade registro o lo actualiza si ya existe. * @@ -15,12 +13,24 @@ BEGIN * @param vWarehouseFk indica el sector * **/ - DECLARE vItemFk INT; + DECLARE vBuyFk INT; - SELECT barcodeToItem(vBarcode) INTO vItemFk; + SELECT id INTO vBuyFk + FROM buy WHERE id = vBarcode; + + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + IF vBuyFk IS NULL THEN + CALL cache.last_buy_refresh(FALSE); + + SELECT buy_id INTO vBuyFk + FROM cache.last_buy + WHERE item_id = vItemFk + AND warehouse_id = vWarehouseFk; + END IF; - IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN + IF NOT (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) THEN INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); INSERT INTO shelving(code, parkingFk) @@ -31,33 +41,37 @@ BEGIN END IF; IF (SELECT COUNT(*) FROM itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk + AND packing = vPacking + AND buyFk = vBuyFk) THEN UPDATE itemShelving - SET visible = visible+vQuantity - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; + SET visible = visible + vQuantity + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk + AND packing = vPacking + AND buyFk = vBuyFk; ELSE - CALL cache.last_buy_refresh(FALSE); - INSERT INTO itemShelving( itemFk, - shelvingFk, - visible, - grouping, - packing, - packagingFk) - SELECT vItemFk, - vShelvingFk, - vQuantity, - IFNULL(vGrouping, b.grouping), - IFNULL(vPacking, b.packing), - IFNULL(vPackagingFk, b.packagingFk) - FROM item i - LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id - WHERE i.id = vItemFk; + INSERT INTO itemShelving( + itemFk, + shelvingFk, + visible, + grouping, + packing, + packagingFk, + buyFk) + SELECT vItemFk, + vShelvingFk, + vQuantity, + IFNULL(vGrouping, b.grouping), + IFNULL(vPacking, b.packing), + IFNULL(vPackagingFk, b.packagingFk), + id + FROM buy b + WHERE id = vBuyFk; END IF; END$$ DELIMITER ; From 599f22a25de9e25e26a405a223770be432468134 Mon Sep 17 00:00:00 2001 From: Pako Date: Tue, 14 May 2024 09:03:49 +0200 Subject: [PATCH 02/10] catalogue tiene en cuenta apc --- db/routines/floranet/procedures/catalogue_get.sql | 9 +++++++-- db/routines/floranet/procedures/contact_request.sql | 13 +++++++++++-- .../floranet/procedures/deliveryDate_get.sql | 2 +- db/routines/floranet/procedures/order_put.sql | 12 ++++++------ db/routines/floranet/procedures/sliders_get.sql | 13 ++++++------- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/db/routines/floranet/procedures/catalogue_get.sql b/db/routines/floranet/procedures/catalogue_get.sql index 32624f383..d67f7555e 100644 --- a/db/routines/floranet/procedures/catalogue_get.sql +++ b/db/routines/floranet/procedures/catalogue_get.sql @@ -42,8 +42,8 @@ proc:BEGIN image, description ) - SELECT i.name, - i.`size`, + SELECT CONCAT(i.name, ' by ',a.nickname), + i.`size` + apc.deliveryCost, i.id, vLanded, vPostalCode, @@ -52,6 +52,11 @@ proc:BEGIN i.description FROM vn.item i JOIN vn.itemType it ON it.id = i.typeFk + JOIN addressPostCode apc + ON apc.dayOfWeek = dayOfWeek(vLanded) + AND NOW() < vLanded - INTERVAL apc.hoursInAdvance HOUR + AND apc.postCode = vPostalCode + JOIN vn.address a ON a.id = apc.addressFk WHERE it.code IN ('FNR','FNP'); SELECT * diff --git a/db/routines/floranet/procedures/contact_request.sql b/db/routines/floranet/procedures/contact_request.sql index 2ca25b87d..c479945cc 100644 --- a/db/routines/floranet/procedures/contact_request.sql +++ b/db/routines/floranet/procedures/contact_request.sql @@ -13,8 +13,17 @@ BEGIN /** * Set actions for contact request * - * @param vPostalCode Delivery address postal code + * @param vName Name + * @param vPhone Phone number + * @param vEmail e-mail + * @param vMessage text of the message */ - + + CALL vn.mail_insert( + 'pako@verdnatura.es', + vEmail, + 'Contact request', + CONCAT('Phone: ',vPhone, ' Message: ', vMessage) + ); END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/floranet/procedures/deliveryDate_get.sql b/db/routines/floranet/procedures/deliveryDate_get.sql index 75e9d6257..a235e8c31 100644 --- a/db/routines/floranet/procedures/deliveryDate_get.sql +++ b/db/routines/floranet/procedures/deliveryDate_get.sql @@ -21,7 +21,7 @@ BEGIN apc.dayOfWeek - vCurrentDayOfWeek, 7 - apc.dayOfWeek ) DAY nextDay, - NOW() + INTERVAL apc.hoursInAdvance - 12 HOUR minDeliveryTime + NOW() + INTERVAL apc.hoursInAdvance HOUR minDeliveryTime FROM addressPostCode apc WHERE apc.postCode = vPostalCode HAVING nextDay > minDeliveryTime) sub; diff --git a/db/routines/floranet/procedures/order_put.sql b/db/routines/floranet/procedures/order_put.sql index 979588f8f..ec0295ca7 100644 --- a/db/routines/floranet/procedures/order_put.sql +++ b/db/routines/floranet/procedures/order_put.sql @@ -10,12 +10,12 @@ BEGIN INSERT INTO `order` SET catalogueFk = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.products[0].id')), customerName = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.customerName')), - email = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.email')), - customerPhone = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.customerPhone')), - message= JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.message')), - deliveryName = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryName')), - address = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.address')), - deliveryPhone = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryPhone')); + email = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.email')), + customerPhone = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.customerPhone')), + message= JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.message')), + deliveryName = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryName')), + address = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.address')), + deliveryPhone = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryPhone')); SELECT LAST_INSERT_ID() orderFk; END$$ diff --git a/db/routines/floranet/procedures/sliders_get.sql b/db/routines/floranet/procedures/sliders_get.sql index 0e4aa297a..bafda4732 100644 --- a/db/routines/floranet/procedures/sliders_get.sql +++ b/db/routines/floranet/procedures/sliders_get.sql @@ -9,12 +9,11 @@ BEGIN * Returns list of url for sliders. */ SELECT - CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url, - i.longName - FROM vn.item i - JOIN vn.itemType it ON it.id = i.typeFk - WHERE it.code IN ('FNR','FNP') - LIMIT 3; - + CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url, + i.longName + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + WHERE it.code IN ('FNR','FNP') + LIMIT 3; END$$ DELIMITER ; \ No newline at end of file From bb4f78961f411a0469218606e224524e5197c30d Mon Sep 17 00:00:00 2001 From: Pako Date: Tue, 14 May 2024 14:01:13 +0200 Subject: [PATCH 03/10] element table --- .../floranet/procedures/contact_request.sql | 2 +- .../floranet/procedures/order_confirm.sql | 72 +++++++++++++++++-- .../11050-wheatAnthurium/00-firstScript.sql | 4 ++ .../11050-wheatAnthurium/01-elementFilter.sql | 6 ++ 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 db/versions/11050-wheatAnthurium/00-firstScript.sql create mode 100644 db/versions/11050-wheatAnthurium/01-elementFilter.sql diff --git a/db/routines/floranet/procedures/contact_request.sql b/db/routines/floranet/procedures/contact_request.sql index c479945cc..2132a86fc 100644 --- a/db/routines/floranet/procedures/contact_request.sql +++ b/db/routines/floranet/procedures/contact_request.sql @@ -20,7 +20,7 @@ BEGIN */ CALL vn.mail_insert( - 'pako@verdnatura.es', + 'floranet@verdnatura.es', vEmail, 'Contact request', CONCAT('Phone: ',vPhone, ' Message: ', vMessage) diff --git a/db/routines/floranet/procedures/order_confirm.sql b/db/routines/floranet/procedures/order_confirm.sql index b6aec033d..c5d61bf48 100644 --- a/db/routines/floranet/procedures/order_confirm.sql +++ b/db/routines/floranet/procedures/order_confirm.sql @@ -1,23 +1,87 @@ -DROP PROCEDURE IF EXISTS floranet.order_confirm; - DELIMITER $$ $$ -CREATE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT) READS SQL DATA BEGIN -/** Update order.isPaid field. +/** Update order.isPaid field, and makes the ticket * * @param vCatalogueFk floranet.catalogue.id * * @returns floranet.order.isPaid */ + DECLARE vNewTicketFk INT; + DECLARE vZoneFk INT; + UPDATE `order` SET isPaid = TRUE, payed = NOW() WHERE catalogueFk = vCatalogueFk; + SELECT zoneFk + INTO vZoneFk + FROM ( + SELECT zoneFk, COUNT(*) totalCount + FROM vn.ticket t + JOIN catalogue c ON c.id = vCatalogueFk + WHERE t.shipped > util.VN_CURDATE() - INTERVAL 1 YEAR + AND t.addressFk = c.addressFk + GROUP BY zoneFk + ORDER BY totalCount DESC + LIMIT 10000000000000000000 + ) sub + LIMIT 1; + + INSERT INTO ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + routeFk, + companyFk, + landed, + zoneFk + ) + SELECT a.clientFk, + c.dated - INTERVAL 1 DAY, + c.addressFk, + a.agencyModeFk, + a.nickname, + ag.warehouseFk, + NULL, + co.id, + c.dated, + vZoneFk + FROM vn.address a + JOIN vn.agencyMode am ON am.id = a.agencyModeFk + JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN catalogue c ON c.addressFk = a.id + JOIN vn.company co ON co.code = 'VNL' + WHERE c.id = vCatalogueFk; + + SET vNewTicketFk = LAST_INSERT_ID(); + + INSERT INTO vn.sale( + ticketFk, + itemFk, + concept, + price, + quantity) + SELECT + vNewTicketFk, + c.itemFk, + CONCAT('Entrega: ',c.name), + - c.price, + 1 + FROM catalogue c + JOIN addressPostCode apc + ON apc.addressFk = c.addressFk + AND apc.dayOfWeek = dayOfWeek(vDated) + WHERE c.id = vCatalogueFk; + SELECT isPaid FROM `order` WHERE catalogueFk = vCatalogueFk; diff --git a/db/versions/11050-wheatAnthurium/00-firstScript.sql b/db/versions/11050-wheatAnthurium/00-firstScript.sql new file mode 100644 index 000000000..cb8034ff5 --- /dev/null +++ b/db/versions/11050-wheatAnthurium/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here + +ALTER TABLE floranet.catalogue ADD addressFk int(11) NOT NULL; +ALTER TABLE floranet.catalogue ADD CONSTRAINT catalogue_address_FK FOREIGN KEY (addressFk) REFERENCES vn.address(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/11050-wheatAnthurium/01-elementFilter.sql b/db/versions/11050-wheatAnthurium/01-elementFilter.sql new file mode 100644 index 000000000..3f2bb78ac --- /dev/null +++ b/db/versions/11050-wheatAnthurium/01-elementFilter.sql @@ -0,0 +1,6 @@ +ALTER TABLE floranet.builder DROP FOREIGN KEY builder_FK_1; +ALTER TABLE floranet.`element` DROP PRIMARY KEY; +ALTER TABLE floranet.`element` ADD id INT NOT NULL; +ALTER TABLE floranet.`element` ADD CONSTRAINT element_pk PRIMARY KEY (id); +ALTER TABLE floranet.builder ADD CONSTRAINT builder_element_FK FOREIGN KEY (elementFk) REFERENCES floranet.`element`(id) ON DELETE CASCADE ON UPDATE CASCADE; + From dd76168bc3779f110049871cfbfd06d89a8b1b8a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 May 2024 09:15:24 +0200 Subject: [PATCH 04/10] 6281 feat:buyFk in itemShekving --- db/routines/vn/procedures/itemShelving_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 005a9f8cb..f991c3c63 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN From 20bf2b73b6a46f5050b4bace3dcefe9fdc2ce080 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 May 2024 09:27:20 +0200 Subject: [PATCH 05/10] 6281 feat:buyFk in itemShelving --- .../vn/procedures/itemShelving_add.sql | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index f991c3c63..d05c5aac1 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN - +ç /** * Añade registro o lo actualiza si ya existe. @@ -18,8 +18,20 @@ BEGIN DECLARE vItemFk INT; DECLARE vBuyFk INT; + SELECT id INTO vBuyFk + FROM buy WHERE id = vBarcode; + SELECT barcodeToItem(vBarcode) INTO vItemFk; + IF vBuyFk IS NULL THEN + CALL cache.last_buy_refresh(FALSE); + + SELECT buy_id INTO vBuyFk + FROM cache.last_buy + WHERE item_id = vItemFk + AND warehouse_id = vWarehouseFk; + END IF; + IF vPacking IS NULL THEN SET vPacking = itemPacking(vBarcode, vWarehouseFk); @@ -29,10 +41,11 @@ BEGIN IF (SELECT COUNT(*) FROM itemShelving WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN + AND packing = vPacking + AND buyFk = vBuyFk) THEN UPDATE itemShelving - SET visible = visible+vQuantity + SET visible = visible + vQuantity WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; ELSE From 2b2406ae5248305dd70a9a96857dde5ffb960b45 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 May 2024 09:32:12 +0200 Subject: [PATCH 06/10] 6281 feat:buyFk in itemShelving --- db/routines/vn/procedures/itemShelving_add.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index d05c5aac1..9395f5d80 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -1,7 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN -ç /** * Añade registro o lo actualiza si ya existe. From 598a7eefbcab27f6518f56215f7796d4f1c872e9 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 May 2024 09:39:23 +0200 Subject: [PATCH 07/10] 6281 feat:buyFk in itemShelving --- db/routines/vn/procedures/itemShelvingTransfer.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelvingTransfer.sql b/db/routines/vn/procedures/itemShelvingTransfer.sql index b75cef627..ae82bfe9d 100644 --- a/db/routines/vn/procedures/itemShelvingTransfer.sql +++ b/db/routines/vn/procedures/itemShelvingTransfer.sql @@ -17,7 +17,8 @@ BEGIN SELECT itemFk, packing, - created + created, + buyFk FROM itemShelving WHERE id = vItemShelvingFk ) ish2 From 7065cf0b38ec8558b0f0651992c5eccbc398273d Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 May 2024 09:58:03 +0200 Subject: [PATCH 08/10] feat: refs #6281 change fixtures --- db/dump/fixtures.before.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 3e6edf07d..8a86e2786 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1205,11 +1205,11 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) (32, 36, -92.324), (32, 39, 0.994); -INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`, `userFk`) +INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`,`buyFk`, `userFk`) VALUES - (2, 'GVC', 1, 1, 1, 1106), - (4, 'HEJ', 1, 1, 1, 1106), - (1, 'UXN', 2, 12, 12, 1106); + (2, 'GVC', 1, 1, 1, 2,1106), + (4, 'HEJ', 1, 1, 1, NULL,1106), + (1, 'UXN', 2, 12, 12, NULL,1106); INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) VALUES From 49a2e6fc84c677c62d58fc708367020624c0d8e3 Mon Sep 17 00:00:00 2001 From: Pako Date: Fri, 24 May 2024 11:44:58 +0200 Subject: [PATCH 09/10] tickets y email --- .../floranet/procedures/catalogue_get.sql | 8 +-- .../floranet/procedures/order_confirm.sql | 49 +++++++++++++++++-- .../11068-blueGerbera/00-firstScript.sql | 9 ++++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 db/versions/11068-blueGerbera/00-firstScript.sql diff --git a/db/routines/floranet/procedures/catalogue_get.sql b/db/routines/floranet/procedures/catalogue_get.sql index d67f7555e..523026a41 100644 --- a/db/routines/floranet/procedures/catalogue_get.sql +++ b/db/routines/floranet/procedures/catalogue_get.sql @@ -40,16 +40,18 @@ proc:BEGIN postalCode, `type`, image, - description + description, + addressFk ) SELECT CONCAT(i.name, ' by ',a.nickname), - i.`size` + apc.deliveryCost, + i.minPrice + apc.deliveryCost, i.id, vLanded, vPostalCode, it.name, CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image), - i.description + i.description, + apc.addressFk FROM vn.item i JOIN vn.itemType it ON it.id = i.typeFk JOIN addressPostCode apc diff --git a/db/routines/floranet/procedures/order_confirm.sql b/db/routines/floranet/procedures/order_confirm.sql index c5d61bf48..903d348a2 100644 --- a/db/routines/floranet/procedures/order_confirm.sql +++ b/db/routines/floranet/procedures/order_confirm.sql @@ -4,7 +4,7 @@ $$ CREATE OR REPLACE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT) READS SQL DATA -BEGIN +proc:BEGIN /** Update order.isPaid field, and makes the ticket * * @param vCatalogueFk floranet.catalogue.id @@ -12,8 +12,16 @@ BEGIN * @returns floranet.order.isPaid */ DECLARE vNewTicketFk INT; + DECLARE vCustomerEmail VARCHAR(255); + DECLARE vFloranetEmail VARCHAR(255); + DECLARE vSubjectEmail VARCHAR(100); + DECLARE vBodyEmail TEXT; DECLARE vZoneFk INT; + IF (SELECT isPaid FROM `order` WHERE catalogueFk = vCatalogueFk) THEN + CALL util.throw('Esta orden ya está confirmada'); + END IF; + UPDATE `order` SET isPaid = TRUE, payed = NOW() @@ -33,7 +41,7 @@ BEGIN ) sub LIMIT 1; - INSERT INTO ticket ( + INSERT INTO vn.ticket ( clientFk, shipped, addressFk, @@ -57,7 +65,7 @@ BEGIN vZoneFk FROM vn.address a JOIN vn.agencyMode am ON am.id = a.agencyModeFk - JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN vn.agency ag ON ag.id = am.agencyFk JOIN catalogue c ON c.addressFk = a.id JOIN vn.company co ON co.code = 'VNL' WHERE c.id = vCatalogueFk; @@ -79,10 +87,41 @@ BEGIN FROM catalogue c JOIN addressPostCode apc ON apc.addressFk = c.addressFk - AND apc.dayOfWeek = dayOfWeek(vDated) + AND apc.dayOfWeek = dayOfWeek(c.dated) WHERE c.id = vCatalogueFk; + + SELECT cl.email, + cf.email, + CONCAT('Nuevo pedido FLORANET para entrega el ',c.dated), + CONCAT_WS('\n', + CONCAT('Producto: ', c.name), + CONCAT('Fecha de entrega: ',c.dated), + CONCAT('Destinatario: ', o.deliveryName), + CONCAT('Dirección: ', o.address), + CONCAT('CP: ', c.postalCode), + CONCAT('Foto: ', c.image), + CONCAT('Mensaje: ', IFNULL(o.message,"Ninguno.")), + CONCAT('Teléfono: ',IFNULL(o.deliveryPhone,"--")), + CONCAT('Observaciones: ', IFNULL(o.observations,"No hay.")) + ) + INTO vCustomerEmail, + vFloranetEmail, + vSubjectEmail, + vBodyEmail + FROM vn.client cl + JOIN vn.address a ON a.clientFk = cl.id + JOIN catalogue c ON c.addressFk = a.id + JOIN `order` o ON o.catalogueFk = c.id + JOIN config cf + WHERE c.id = vCatalogueFk; + + CALL vn.mail_insert( + vCustomerEmail, + vFloranetEmail, + vSubjectEmail, + vBodyEmail); - SELECT isPaid + SELECT isPaid, vNewTicketFk FROM `order` WHERE catalogueFk = vCatalogueFk; END$$ diff --git a/db/versions/11068-blueGerbera/00-firstScript.sql b/db/versions/11068-blueGerbera/00-firstScript.sql new file mode 100644 index 000000000..6342981a7 --- /dev/null +++ b/db/versions/11068-blueGerbera/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +CREATE OR REPLACE TABLE floranet.config ( + email varchar(255) DEFAULT 'floranet@verdnatura.es' NOT NULL +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + + From ab3b58ec3c4342e94cf251661e98fa068696eeab Mon Sep 17 00:00:00 2001 From: Pako Date: Fri, 24 May 2024 13:41:02 +0200 Subject: [PATCH 10/10] modificacion recipe y element --- .../00-firstScript.sql | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 db/versions/11069-brownChrysanthemum/00-firstScript.sql diff --git a/db/versions/11069-brownChrysanthemum/00-firstScript.sql b/db/versions/11069-brownChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..3220d1257 --- /dev/null +++ b/db/versions/11069-brownChrysanthemum/00-firstScript.sql @@ -0,0 +1,35 @@ +-- Place your SQL code here +DROP TABLE IF EXISTS floranet.builder; + +CREATE OR REPLACE TABLE floranet.`element` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL, + `itemFk` int(11) DEFAULT NULL, + `longNameFilter` varchar(30) DEFAULT NULL, + `typeFk` smallint(5) unsigned DEFAULT NULL, + `minSize` int(10) unsigned DEFAULT NULL, + `maxSize` int(10) unsigned DEFAULT NULL, + `inkFk` char(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `originFk` tinyint(2) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `element_FK` (`itemFk`), + KEY `element_FK_1` (`typeFk`), + KEY `element_FK_2` (`inkFk`), + KEY `element_FK_3` (`originFk`), + CONSTRAINT `element_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `element_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `vn`.`itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `element_FK_2` FOREIGN KEY (`inkFk`) REFERENCES `vn`.`ink` (`id`) ON UPDATE CASCADE, + CONSTRAINT `element_FK_3` FOREIGN KEY (`originFk`) REFERENCES `vn`.`origin` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Filtro para localizar posibles items que coincidan con la descripción'; + +CREATE OR REPLACE TABLE floranet.`recipe` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFk` int(11) NOT NULL, + `elementFk` int(11) NOT NULL, + `quantity` int(10) unsigned NOT NULL DEFAULT 1, + PRIMARY KEY (`id`), + KEY `recipe_FK` (`itemFk`), + KEY `recipe_FK_1` (`elementFk`), + CONSTRAINT `recipe_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `recipe_element_FK` FOREIGN KEY (`elementFk`) REFERENCES `element` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Links handmade products with their elements';