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)
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$