This commit is contained in:
parent
0a11997250
commit
69314171ea
|
@ -7,31 +7,36 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getCommission`(v
|
|||
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 vIsCurrencyUsd INT;
|
||||
DECLARE vLastEntryFk INT;
|
||||
DECLARE vTravelFkLanded INT;
|
||||
|
||||
SELECT count(*) INTO vIsCurrencyUsd
|
||||
FROM currency c
|
||||
WHERE c.code = 'USD' AND id = vCurrencyFk;
|
||||
SELECT count(*) INTO vIsCurrencyUsd
|
||||
FROM currency c
|
||||
WHERE c.code = 'USD' AND id = vCurrencyFk;
|
||||
|
||||
IF NOT vIsCurrencyUsd THEN
|
||||
IF NOT vIsCurrencyUsd THEN
|
||||
SELECT landed INTO vTravelFkLanded
|
||||
FROM travel
|
||||
WHERE id = vTravelFk;
|
||||
|
||||
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;
|
||||
FROM entry e
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
WHERE tr.landed < vTravelFkLanded
|
||||
AND e.supplierFk = vSupplierFk
|
||||
ORDER BY (vTravelFkLanded - tr.landed) ASC, tr.landed DESC
|
||||
LIMIT 1;
|
||||
|
||||
IF vLastEntryFk THEN
|
||||
IF vLastEntryFk THEN
|
||||
|
||||
SELECT commission INTO vCurrentCommission
|
||||
FROM vn.entry
|
||||
WHERE id = vLastEntryFk;
|
||||
WHERE id = vLastEntryFk;
|
||||
|
||||
ELSE
|
||||
ELSE
|
||||
|
||||
SELECT commission INTO vCurrentCommission
|
||||
FROM supplier s
|
||||
|
@ -39,9 +44,9 @@ BEGIN
|
|||
|
||||
END IF;
|
||||
|
||||
RETURN vCurrentCommission;
|
||||
RETURN vCurrentCommission;
|
||||
|
||||
ELSE
|
||||
ELSE
|
||||
|
||||
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
|
||||
FROM travel t
|
||||
|
|
Loading…
Reference in New Issue