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

60 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_newWithAddress`(
OUT vSelf INT,
vLandingDate DATE,
vAddressFk INT)
BEGIN
/**
* Crea una nueva orden para el usuario actual especificando
* una fecha de entrega.
*
* @param vSelf Id de la nueva orden
* @param vLandingDate Fecha de entrega
*/
DECLARE vCompany INT;
DECLARE vDeliveryMethodId INT;
DECLARE vAgencyMode INT;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
DECLARE EXIT HANDLER FOR SQLSTATE '45000'
BEGIN
ROLLBACK;
SET vSelf = NULL;
RESIGNAL;
END;
START TRANSACTION;
SELECT a.agencyModeFk, a.id
INTO vAgencyMode, vAddressFk
FROM vn.address a
WHERE a.id = vAddressFk;
SELECT deliveryMethodFk INTO vDeliveryMethodId
FROM vn.agencyMode am
WHERE am.id = vAgencyMode;
IF vCompany IS NULL
THEN
SELECT defaultCompanyFk INTO vCompany
FROM orderConfig;
END IF;
INSERT INTO `order`
SET
customer_id = account.myUser_getId(),
date_send = vLandingDate,
delivery_method_id = vDeliveryMethodId,
agency_id = vAgencyMode,
address_id = vAddressFk,
source_app = 'WEB',
company_id = vCompany;
SET vSelf = LAST_INSERT_ID();
CALL order_checkConfig(vSelf);
COMMIT;
END$$
DELIMITER ;