2023-06-20 06:58:22 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_updateComission`(vCurrency INT)
|
|
|
|
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
|
|
|
|
WHERE t.shipped >= util.VN_CURDATE()
|
|
|
|
AND e.currencyFk = vCurrency;
|
|
|
|
|
|
|
|
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
|
|
|
|
FROM currency
|
|
|
|
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 ;
|