diff --git a/db/routines/floranet/procedures/catalogue_get.sql b/db/routines/floranet/procedures/catalogue_get.sql index 523026a41..7ce32cfac 100644 --- a/db/routines/floranet/procedures/catalogue_get.sql +++ b/db/routines/floranet/procedures/catalogue_get.sql @@ -44,8 +44,8 @@ proc:BEGIN addressFk ) SELECT CONCAT(i.name, ' by ',a.nickname), - i.minPrice + apc.deliveryCost, - i.id, + r.price + apc.deliveryCost, + r.itemFk, vLanded, vPostalCode, it.name, @@ -53,13 +53,15 @@ proc:BEGIN i.description, apc.addressFk FROM vn.item i + JOIN (SELECT itemFk, SUM(quantity * cost) price + FROM recipe + GROUP BY itemFk) r ON r.itemFk = i.id 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'); + JOIN vn.address a ON a.id = apc.addressFk; SELECT * FROM catalogue diff --git a/db/routines/floranet/procedures/order_confirm.sql b/db/routines/floranet/procedures/order_confirm.sql index 903d348a2..3b9413da9 100644 --- a/db/routines/floranet/procedures/order_confirm.sql +++ b/db/routines/floranet/procedures/order_confirm.sql @@ -18,10 +18,29 @@ proc:BEGIN DECLARE vBodyEmail TEXT; DECLARE vZoneFk INT; + DECLARE exit handler FOR SQLEXCEPTION + BEGIN + ROLLBACK; + + GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; + + SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')) AS `SQLEXCEPTION`; + + CALL vn.mail_insert( + 'floranet@verdnatura.es,pako@verdnatura.es', + 'noreply@verdnatura.es', + 'Floranet.order_confirm failure', + CONCAT('CatalogueFk: ', vCatalogueFk, '\n','ERROR ', IFNULL(@errno, 0), ': ', ifnull(@text, 'texto')) + ); + END; + IF (SELECT isPaid FROM `order` WHERE catalogueFk = vCatalogueFk) THEN - CALL util.throw('Esta orden ya está confirmada'); + SELECT CONCAT('CatalogueFk: ', vCatalogueFk, ' Esta orden ya está confirmada') AS `ERROR`; + LEAVE proc; END IF; + START TRANSACTION; + UPDATE `order` SET isPaid = TRUE, payed = NOW() @@ -89,7 +108,24 @@ proc:BEGIN ON apc.addressFk = c.addressFk AND apc.dayOfWeek = dayOfWeek(c.dated) WHERE c.id = vCatalogueFk; - + + INSERT INTO vn.sale( + ticketFk, + itemFk, + concept, + price, + quantity) + SELECT + vNewTicketFk, + r.elementFk, + i.longName, + r.cost, + r.quantity + FROM catalogue c + JOIN recipe r ON r.itemFk = c.itemFk + JOIN vn.item i ON i.id = r.elementFk + WHERE c.id = vCatalogueFk; + SELECT cl.email, cf.email, CONCAT('Nuevo pedido FLORANET para entrega el ',c.dated), @@ -114,7 +150,7 @@ proc:BEGIN JOIN `order` o ON o.catalogueFk = c.id JOIN config cf WHERE c.id = vCatalogueFk; - + CALL vn.mail_insert( vCustomerEmail, vFloranetEmail, @@ -124,5 +160,8 @@ proc:BEGIN SELECT isPaid, vNewTicketFk FROM `order` WHERE catalogueFk = vCatalogueFk; + + COMMIT; + END$$ DELIMITER ; \ No newline at end of file diff --git a/db/versions/11074-brownRuscus/00-firstScript.sql b/db/versions/11074-brownRuscus/00-firstScript.sql new file mode 100644 index 000000000..f78ba98ae --- /dev/null +++ b/db/versions/11074-brownRuscus/00-firstScript.sql @@ -0,0 +1,20 @@ +-- Place your SQL code here + + +-- floranet.recipe definition + +CREATE OR REPLACE TABLE floranet.`recipe` + ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFk` int(11) NOT NULL COMMENT 'Bouquet or plant name', + `elementFk` int(11) NOT NULL COMMENT 'Item detail for bouquet''s composition', + `quantity` int(10) unsigned NOT NULL DEFAULT 1, + `cost` decimal(10,2) NOT NULL DEFAULT 1.00, + PRIMARY KEY (`id`), + KEY `recipe_FK` (`itemFk`), + KEY `recipe_FK_1` (`elementFk`), + CONSTRAINT `recipe_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON UPDATE CASCADE, + CONSTRAINT `recipe_item_FK` FOREIGN KEY (`elementFk`) REFERENCES `vn`.`item` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Links handmade products with their elements'; + +DROP TABLE IF EXISTS floranet.`element`; \ No newline at end of file