Modified by www.SourceFiles.app
This commit is contained in:
@@ -450,12 +450,14 @@ BEGIN
|
|||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
-- Step 9: outstanding credits, oldest first, never below zero.
|
-- Step 9: outstanding credits, oldest first, never below zero.
|
||||||
|
-- Every column is alias-qualified: this function's RETURNS TABLE declares an
|
||||||
|
-- `amount_cents` output, which would otherwise shadow the table's column.
|
||||||
FOR cred IN
|
FOR cred IN
|
||||||
SELECT * FROM public.student_credits
|
SELECT sc.* FROM public.student_credits sc
|
||||||
WHERE student_id = _student AND NOT is_void
|
WHERE sc.student_id = _student AND NOT sc.is_void
|
||||||
AND amount_applied_cents < amount_cents
|
AND sc.amount_applied_cents < sc.amount_cents
|
||||||
AND (expires_on IS NULL OR expires_on >= _from)
|
AND (sc.expires_on IS NULL OR sc.expires_on >= _from)
|
||||||
ORDER BY issued_at
|
ORDER BY sc.issued_at
|
||||||
LOOP
|
LOOP
|
||||||
EXIT WHEN running_total <= 0;
|
EXIT WHEN running_total <= 0;
|
||||||
remaining := cred.amount_cents - cred.amount_applied_cents;
|
remaining := cred.amount_cents - cred.amount_applied_cents;
|
||||||
|
|||||||
Reference in New Issue
Block a user