feat: refs #8190 entry_getCommission #3207

Open
robert wants to merge 4 commits from 8190-entry_getCommission into dev
1 changed files with 36 additions and 31 deletions
Showing only changes of commit 69314171ea - Show all commits

View File

@ -11,18 +11,23 @@ BEGIN
DECLARE vCurrentCommission INT;
DECLARE vIsCurrencyUsd INT;
DECLARE vLastEntryFk INT;
DECLARE vTravelFkLanded INT;
Review

vLanded

vLanded
SELECT count(*) INTO vIsCurrencyUsd
FROM currency c
WHERE c.code = 'USD' AND id = vCurrencyFk;
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
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