From 599f22a25de9e25e26a405a223770be432468134 Mon Sep 17 00:00:00 2001 From: Pako Date: Tue, 14 May 2024 09:03:49 +0200 Subject: [PATCH 1/4] 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 2/4] 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 49a2e6fc84c677c62d58fc708367020624c0d8e3 Mon Sep 17 00:00:00 2001 From: Pako Date: Fri, 24 May 2024 11:44:58 +0200 Subject: [PATCH 3/4] 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 4/4] 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';