Compare commits
6 Commits
7d5928bc3d
...
5e21e4e368
Author | SHA1 | Date |
---|---|---|
Robert Ferrús | 5e21e4e368 | |
Robert Ferrús | 329488d700 | |
Robert Ferrús | 923296e85e | |
Robert Ferrús | c5f1b05671 | |
Robert Ferrús | f7a5fc7e31 | |
Robert Ferrús | 7e0f19b368 |
|
@ -1,48 +1,22 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getCommission`(vTravelFk INT,
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getCommission`(vTravelFk INT,
|
||||||
vCurrencyFk INT,
|
vCurrencyFk INT,
|
||||||
vSupplierFk INT
|
vSupplierFk INT
|
||||||
)
|
)
|
||||||
RETURNS int(11)
|
RETURNS int(11)
|
||||||
NOT DETERMINISTIC
|
NOT DETERMINISTIC
|
||||||
READS SQL DATA
|
READS SQL DATA
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vCommission INT;
|
DECLARE vCommission INT;
|
||||||
DECLARE vCurrentCommission INT;
|
DECLARE vCurrentCommission INT;
|
||||||
DECLARE vIsCurrencyUsd INT;
|
DECLARE vIsNotEUR INT;
|
||||||
DECLARE vLastEntryFk INT;
|
DECLARE vLastEntryFk INT;
|
||||||
|
|
||||||
SELECT count(*) INTO vIsCurrencyUsd
|
SELECT count(*) INTO vIsNotEUR
|
||||||
FROM currency c
|
FROM currency c
|
||||||
WHERE c.code = 'USD' AND id = vCurrencyFk;
|
WHERE c.code <> 'EUR' 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
|
|
||||||
|
|
||||||
|
IF vIsNotEUR THEN
|
||||||
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
|
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
|
||||||
FROM travel t
|
FROM travel t
|
||||||
LEFT JOIN referenceCurrent r ON r.currencyFk = vCurrencyFk AND r.`dated` <= t.shipped
|
LEFT JOIN referenceCurrent r ON r.currencyFk = vCurrencyFk AND r.`dated` <= t.shipped
|
||||||
|
@ -51,8 +25,27 @@ BEGIN
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
RETURN IFNULL(vCommission, 0);
|
RETURN IFNULL(vCommission, 0);
|
||||||
|
ELSE
|
||||||
|
SELECT e.id INTO vLastEntryFk
|
||||||
|
FROM `entry` e
|
||||||
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
|
WHERE e.supplierFk = vSupplierFk
|
||||||
|
ORDER BY tr.landed DESC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
END IF;
|
IF vLastEntryFk THEN
|
||||||
|
SELECT commission INTO vCurrentCommission
|
||||||
|
FROM `entry`
|
||||||
|
WHERE id = vLastEntryFk;
|
||||||
|
|
||||||
|
ELSE
|
||||||
|
SELECT commission INTO vCurrentCommission
|
||||||
|
FROM supplier s
|
||||||
|
WHERE s.id = vSupplierFk;
|
||||||
|
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN vCurrentCommission;
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -22,7 +22,7 @@ BEGIN
|
||||||
FROM vn.entry e
|
FROM vn.entry e
|
||||||
JOIN vn.travel t ON t.id = e.travelFk
|
JOIN vn.travel t ON t.id = e.travelFk
|
||||||
JOIN vn.warehouse w ON w.id = t.warehouseInFk
|
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 e.currencyFk = vCurrency
|
||||||
AND NOT e.isBooked;
|
AND NOT e.isBooked;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue