2023-06-20 06:58:22 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_updateComission`(vCurrency INT)
|
2023-06-20 06:58:22 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Actualiza la comision de las entradas de hoy a futuro y las recalcula
|
|
|
|
*
|
|
|
|
* @param vCurrency id del tipo de moneda(SAR,EUR,USD,GBP,JPY)
|
|
|
|
*/
|
|
|
|
DECLARE vCurrencyName VARCHAR(25);
|
|
|
|
DECLARE vComission INT;
|
|
|
|
|
2024-04-23 09:50:48 +00:00
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
|
|
|
ROLLBACK;
|
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
|
|
|
START TRANSACTION;
|
|
|
|
|
2023-06-20 06:58:22 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.recalcEntryCommision
|
|
|
|
SELECT e.id
|
|
|
|
FROM vn.entry e
|
|
|
|
JOIN vn.travel t ON t.id = e.travelFk
|
|
|
|
JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
2024-10-18 06:21:09 +00:00
|
|
|
WHERE t.landed >= util.VN_CURDATE()
|
2024-06-05 09:13:40 +00:00
|
|
|
AND e.currencyFk = vCurrency
|
|
|
|
AND NOT e.isBooked;
|
2023-06-20 06:58:22 +00:00
|
|
|
|
|
|
|
SET vComission = currency_getCommission(vCurrency);
|
|
|
|
|
|
|
|
UPDATE vn.entry e
|
|
|
|
JOIN tmp.recalcEntryCommision tmp ON tmp.id = e.id
|
|
|
|
SET e.commission = vComission;
|
|
|
|
|
|
|
|
SELECT `name` INTO vCurrencyName
|
2024-10-18 06:21:09 +00:00
|
|
|
FROM currency
|
2023-06-20 06:58:22 +00:00
|
|
|
WHERE id = vCurrency;
|
|
|
|
|
|
|
|
CALL entry_recalc();
|
2024-04-23 09:50:48 +00:00
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
|
2023-06-20 06:58:22 +00:00
|
|
|
SELECT util.notification_send(
|
|
|
|
'entry-update-comission',
|
|
|
|
JSON_OBJECT('currencyName', vCurrencyName, 'referenceCurrent', vComission),
|
2024-01-15 11:31:03 +00:00
|
|
|
NULL
|
2023-06-20 06:58:22 +00:00
|
|
|
);
|
|
|
|
|
2024-04-23 09:50:48 +00:00
|
|
|
DROP TEMPORARY TABLE tmp.recalcEntryCommision;
|
2023-06-20 06:58:22 +00:00
|
|
|
END$$
|
2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER ;
|