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

@ -7,41 +7,46 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getCommission`(v
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 vIsCurrencyUsd INT;
DECLARE vLastEntryFk INT; DECLARE vLastEntryFk INT;
DECLARE vTravelFkLanded INT;
Review

vLanded

vLanded
SELECT count(*) INTO vIsCurrencyUsd
FROM currency c SELECT count(*) INTO vIsCurrencyUsd
WHERE c.code = 'USD' AND id = vCurrencyFk; 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 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
LIMIT 1; ORDER BY (vTravelFkLanded - tr.landed) ASC, tr.landed DESC
LIMIT 1;
IF vLastEntryFk THEN
IF vLastEntryFk THEN
SELECT commission INTO vCurrentCommission SELECT commission INTO vCurrentCommission
FROM vn.entry FROM vn.entry
WHERE id = vLastEntryFk; WHERE id = vLastEntryFk;
Review

per defecte ja es ASC

per defecte ja es ASC
ELSE ELSE
SELECT commission INTO vCurrentCommission SELECT commission INTO vCurrentCommission
FROM supplier s FROM supplier s
WHERE s.id = vSupplierFk; WHERE s.id = vSupplierFk;
END IF; END IF;
RETURN vCurrentCommission; RETURN vCurrentCommission;
ELSE ELSE
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
FROM travel t FROM travel t
@ -49,10 +54,10 @@ BEGIN
WHERE t.id = vTravelFk WHERE t.id = vTravelFk
ORDER BY r.`dated` DESC ORDER BY r.`dated` DESC
LIMIT 1; LIMIT 1;
RETURN IFNULL(vCommission, 0); RETURN IFNULL(vCommission, 0);
END IF; END IF;
END$$ END$$
DELIMITER ; DELIMITER ;