Annotation: transactions.get_sales_by_offices

CREATE OR REPLACE FUNCTION transactions.get_sales_by_offices(divide_by integer)
RETURNS TABLE(office text, jan numeric, feb numeric, mar numeric, apr numeric, may numeric, jun numeric, jul numeric, aug numeric, sep numeric, oct numeric, nov numeric, "dec" numeric)

Information: transactions.get_sales_by_offices

Schema transactions
Function Name get_sales_by_offices
Arguments divide_by integer
Owner postgres
Result Type TABLE(office text, jan numeric, feb numeric, mar numeric, apr numeric, may numeric, jun numeric, jul numeric, aug numeric, sep numeric, oct numeric, nov numeric, "dec" numeric)
Description

Implementation: transactions.get_sales_by_offices

CREATE OR REPLACE FUNCTION transactions.get_sales_by_offices(divide_by integer)
 RETURNS TABLE(office text, jan numeric, feb numeric, mar numeric, apr numeric, may numeric, jun numeric, jul numeric, aug numeric, sep numeric, oct numeric, nov numeric, "dec" numeric)
 LANGUAGE plpgsql
AS $function$
    DECLARE root_office_id integer = 0;
BEGIN
    SELECT office.offices.office_id INTO root_office_id
    FROM office.offices
    WHERE parent_office_id IS NULL
    LIMIT 1;

        IF divide_by <= 0 THEN
                divide_by := 1;
        END IF;
        
        RETURN QUERY
        SELECT * FROM transactions.get_sales_by_offices(root_office_id, divide_by);
END
$function$