Annotation: core.calculate_interest

CREATE OR REPLACE FUNCTION core.calculate_interest(principal numeric, rate numeric, days integer, round_up integer, num_of_days_in_year integer)
RETURNS numeric

Information: core.calculate_interest

Schema core
Function Name calculate_interest
Arguments principal numeric, rate numeric, days integer, round_up integer, num_of_days_in_year integer
Owner postgres
Result Type numeric
Description

Implementation: core.calculate_interest

CREATE OR REPLACE FUNCTION core.calculate_interest(principal numeric, rate numeric, days integer, round_up integer, num_of_days_in_year integer)
 RETURNS numeric
 LANGUAGE plpgsql
 IMMUTABLE STRICT
AS $function$
    DECLARE interest numeric;
BEGIN
    IF num_of_days_in_year = 0 OR num_of_days_in_year IS NULL THEN
        RAISE EXCEPTION 'Cannot calculate interest. The number of days in a year was not provided.';
    END IF;
    
    interest := ROUND(principal * rate * days / (num_of_days_in_year * 100), round_up);

    RETURN interest;
END
$function$