salix/db/routines/hedera/procedures/myOrder_configureForGuest.sql

46 lines
858 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_configureForGuest`(OUT vSelf INT)
BEGIN
DECLARE vMethod VARCHAR(255);
DECLARE vAgency INT;
DECLARE vAddress INT;
DECLARE vDate DATE;
SELECT cf.guestMethod, cf.guestAgencyFk, cl.defaultAddressFk
INTO vMethod, vAgency, vAddress
FROM orderConfig cf
JOIN myClient cl
LIMIT 1;
SET vDate = TIMESTAMPADD(DAY, 1, util.VN_CURDATE());
IF WEEKDAY(vDate) BETWEEN 5 AND 6 THEN
SET vDate = TIMESTAMPADD(DAY, 7 - WEEKDAY(vDate), vDate);
END IF;
SELECT id INTO vSelf
FROM myOrder
WHERE NOT isConfirmed
ORDER BY id DESC
LIMIT 1;
IF vSelf IS NULL THEN
CALL myOrder_create(
vSelf,
vDate,
vMethod,
vAgency,
vAddress
);
ELSE
CALL myOrder_configure(
vSelf,
vDate,
vMethod,
vAgency,
vAddress
);
END IF;
END$$
DELIMITER ;