2024-02-15 12:13:22 +00:00
|
|
|
DELIMITER $$
|
|
|
|
$$
|
|
|
|
|
2024-05-14 12:01:13 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT)
|
2024-02-15 12:13:22 +00:00
|
|
|
READS SQL DATA
|
|
|
|
|
|
|
|
BEGIN
|
2024-05-14 12:01:13 +00:00
|
|
|
/** Update order.isPaid field, and makes the ticket
|
2024-02-15 12:13:22 +00:00
|
|
|
*
|
|
|
|
* @param vCatalogueFk floranet.catalogue.id
|
|
|
|
*
|
|
|
|
* @returns floranet.order.isPaid
|
|
|
|
*/
|
2024-05-14 12:01:13 +00:00
|
|
|
DECLARE vNewTicketFk INT;
|
|
|
|
DECLARE vZoneFk INT;
|
|
|
|
|
2024-02-15 12:13:22 +00:00
|
|
|
UPDATE `order`
|
|
|
|
SET isPaid = TRUE,
|
|
|
|
payed = NOW()
|
|
|
|
WHERE catalogueFk = vCatalogueFk;
|
|
|
|
|
2024-05-14 12:01:13 +00:00
|
|
|
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;
|
|
|
|
|
2024-02-15 12:13:22 +00:00
|
|
|
SELECT isPaid
|
|
|
|
FROM `order`
|
|
|
|
WHERE catalogueFk = vCatalogueFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|