nuevo enfoque recipe y manejo de errores en order_confirm #2523

Merged
pako merged 3 commits from 6021-floranet_beta into dev 2024-05-29 09:40:45 +00:00
3 changed files with 68 additions and 7 deletions
Showing only changes of commit e0d8a46cd6 - Show all commits

View File

@ -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

View File

@ -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 ;

View File

@ -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`;