nuevo enfoque recipe y manejo de errores en order_confirm #2523
|
@ -44,8 +44,8 @@ proc:BEGIN
|
||||||
addressFk
|
addressFk
|
||||||
)
|
)
|
||||||
SELECT CONCAT(i.name, ' by ',a.nickname),
|
SELECT CONCAT(i.name, ' by ',a.nickname),
|
||||||
i.minPrice + apc.deliveryCost,
|
r.price + apc.deliveryCost,
|
||||||
i.id,
|
r.itemFk,
|
||||||
vLanded,
|
vLanded,
|
||||||
vPostalCode,
|
vPostalCode,
|
||||||
it.name,
|
it.name,
|
||||||
|
@ -53,13 +53,15 @@ proc:BEGIN
|
||||||
i.description,
|
i.description,
|
||||||
apc.addressFk
|
apc.addressFk
|
||||||
FROM vn.item i
|
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 vn.itemType it ON it.id = i.typeFk
|
||||||
JOIN addressPostCode apc
|
JOIN addressPostCode apc
|
||||||
ON apc.dayOfWeek = dayOfWeek(vLanded)
|
ON apc.dayOfWeek = dayOfWeek(vLanded)
|
||||||
AND NOW() < vLanded - INTERVAL apc.hoursInAdvance HOUR
|
AND NOW() < vLanded - INTERVAL apc.hoursInAdvance HOUR
|
||||||
AND apc.postCode = vPostalCode
|
AND apc.postCode = vPostalCode
|
||||||
JOIN vn.address a ON a.id = apc.addressFk
|
JOIN vn.address a ON a.id = apc.addressFk;
|
||||||
WHERE it.code IN ('FNR','FNP');
|
|
||||||
|
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM catalogue
|
FROM catalogue
|
||||||
|
|
|
@ -18,10 +18,29 @@ proc:BEGIN
|
||||||
DECLARE vBodyEmail TEXT;
|
DECLARE vBodyEmail TEXT;
|
||||||
DECLARE vZoneFk INT;
|
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
|
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;
|
END IF;
|
||||||
|
|
||||||
|
START TRANSACTION;
|
||||||
|
|
||||||
UPDATE `order`
|
UPDATE `order`
|
||||||
SET isPaid = TRUE,
|
SET isPaid = TRUE,
|
||||||
payed = NOW()
|
payed = NOW()
|
||||||
|
@ -90,6 +109,23 @@ proc:BEGIN
|
||||||
AND apc.dayOfWeek = dayOfWeek(c.dated)
|
AND apc.dayOfWeek = dayOfWeek(c.dated)
|
||||||
WHERE c.id = vCatalogueFk;
|
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,
|
SELECT cl.email,
|
||||||
cf.email,
|
cf.email,
|
||||||
CONCAT('Nuevo pedido FLORANET para entrega el ',c.dated),
|
CONCAT('Nuevo pedido FLORANET para entrega el ',c.dated),
|
||||||
|
@ -124,5 +160,8 @@ proc:BEGIN
|
||||||
SELECT isPaid, vNewTicketFk
|
SELECT isPaid, vNewTicketFk
|
||||||
FROM `order`
|
FROM `order`
|
||||||
WHERE catalogueFk = vCatalogueFk;
|
WHERE catalogueFk = vCatalogueFk;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -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`;
|
Loading…
Reference in New Issue