CREATE OR REPLACE FUNCTION transactions.get_top_selling_products_by_office()
RETURNS TABLE(id integer, office_id integer, office_code text, office_name text, item_id integer, item_code text, item_name text, total_sales 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;
RETURN QUERY
SELECT * FROM transactions.get_top_selling_products_by_office(root_office_id, 5);
END
$function$