feat: refs #8127 entry_getCommission #3128

Merged
robert merged 5 commits from 8127-entry_updateComission into dev 2024-11-18 08:48:51 +00:00
2 changed files with 39 additions and 43 deletions
Showing only changes of commit 7e0f19b368 - Show all commits

View File

@ -1,48 +1,22 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getCommission`(vTravelFk INT,
vCurrencyFk INT,
vSupplierFk INT
vCurrencyFk INT,
vSupplierFk INT
)
RETURNS int(11)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE vCommission INT;
DECLARE vCurrentCommission INT;
DECLARE vIsCurrencyUsd INT;
DECLARE vLastEntryFk INT;
DECLARE vCommission INT;
DECLARE vCurrentCommission INT;
DECLARE vIsNotEUR INT;
DECLARE vLastEntryFk INT;
SELECT count(*) INTO vIsCurrencyUsd
FROM currency c
WHERE c.code = 'USD' AND id = vCurrencyFk;
IF NOT vIsCurrencyUsd THEN
SELECT e.id INTO vLastEntryFk
FROM vn.entry e
JOIN vn.travel tr ON tr.id = e.travelFk
WHERE e.supplierFk = vSupplierFk
ORDER BY tr.landed DESC
LIMIT 1;
IF vLastEntryFk THEN
SELECT commission INTO vCurrentCommission
FROM vn.entry
WHERE id = vLastEntryFk;
ELSE
SELECT commission INTO vCurrentCommission
FROM supplier s
WHERE s.id = vSupplierFk;
END IF;
RETURN vCurrentCommission;
ELSE
SELECT count(*) INTO vIsNotEUR
FROM currency c
WHERE c.code <> 'EUR' AND id = vCurrencyFk;
IF vIsNotEUR THEN
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
FROM travel t
LEFT JOIN referenceCurrent r ON r.currencyFk = vCurrencyFk AND r.`dated` <= t.shipped
@ -52,7 +26,29 @@ BEGIN
RETURN IFNULL(vCommission, 0);
END IF;
ELSE
SELECT e.id INTO vLastEntryFk
FROM vn.entry e
JOIN vn.travel tr ON tr.id = e.travelFk
WHERE e.supplierFk = vSupplierFk
ORDER BY tr.landed DESC
LIMIT 1;
IF vLastEntryFk THEN
SELECT commission INTO vCurrentCommission
FROM vn.entry
WHERE id = vLastEntryFk;
ELSE
SELECT commission INTO vCurrentCommission
FROM supplier s
WHERE s.id = vSupplierFk;
END IF;
RETURN vCurrentCommission;
END IF;
END$$
DELIMITER ;

View File

@ -22,7 +22,7 @@ BEGIN
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()
WHERE t.landed >= util.VN_CURDATE()
AND e.currencyFk = vCurrency
AND NOT e.isBooked;