Annotation: transactions.get_top_selling_products_by_office

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)

Information: transactions.get_top_selling_products_by_office

Schema transactions
Function Name get_top_selling_products_by_office
Arguments
Owner postgres
Result Type TABLE(id integer, office_id integer, office_code text, office_name text, item_id integer, item_code text, item_name text, total_sales numeric)
Description

Implementation: transactions.get_top_selling_products_by_office

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$