This commit is contained in:
parent
0a11997250
commit
69314171ea
|
@ -11,18 +11,23 @@ BEGIN
|
||||||
DECLARE vCurrentCommission INT;
|
DECLARE vCurrentCommission INT;
|
||||||
DECLARE vIsCurrencyUsd INT;
|
DECLARE vIsCurrencyUsd INT;
|
||||||
DECLARE vLastEntryFk INT;
|
DECLARE vLastEntryFk INT;
|
||||||
|
DECLARE vTravelFkLanded INT;
|
||||||
|
|
||||||
SELECT count(*) INTO vIsCurrencyUsd
|
SELECT count(*) INTO vIsCurrencyUsd
|
||||||
FROM currency c
|
FROM currency c
|
||||||
WHERE c.code = 'USD' AND id = vCurrencyFk;
|
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
|
SELECT e.id INTO vLastEntryFk
|
||||||
FROM vn.entry e
|
FROM entry e
|
||||||
JOIN vn.travel tr ON tr.id = e.travelFk
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
WHERE e.supplierFk = vSupplierFk
|
WHERE tr.landed < vTravelFkLanded
|
||||||
ORDER BY tr.landed DESC
|
AND e.supplierFk = vSupplierFk
|
||||||
|
ORDER BY (vTravelFkLanded - tr.landed) ASC, tr.landed DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
IF vLastEntryFk THEN
|
IF vLastEntryFk THEN
|
||||||
|
|
Loading…
Reference in New Issue