Annotation: transactions.get_party_transaction_summary

CREATE OR REPLACE FUNCTION transactions.get_party_transaction_summary(office_id integer, party_id bigint, OUT currency_code text, OUT currency_symbol text, OUT total_due_amount numeric, OUT office_due_amount numeric, OUT accrued_interest numeric, OUT last_receipt_date date, OUT transaction_value numeric)
RETURNS record

Information: transactions.get_party_transaction_summary

Schema transactions
Function Name get_party_transaction_summary
Arguments office_id integer, party_id bigint, OUT currency_code text, OUT currency_symbol text, OUT total_due_amount numeric, OUT office_due_amount numeric, OUT accrued_interest numeric, OUT last_receipt_date date, OUT transaction_value numeric
Owner postgres
Result Type record
Description

Implementation: transactions.get_party_transaction_summary

CREATE OR REPLACE FUNCTION transactions.get_party_transaction_summary(office_id integer, party_id bigint, OUT currency_code text, OUT currency_symbol text, OUT total_due_amount numeric, OUT office_due_amount numeric, OUT accrued_interest numeric, OUT last_receipt_date date, OUT transaction_value numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
    DECLARE root_office_id integer = 0;
BEGIN
    currency_code := core.get_currency_code_by_party_id(party_id);

    SELECT core.currencies.currency_symbol into $4
    FROM core.currencies
    WHERE core.currencies.currency_code = $3;

    SELECT office.offices.office_id INTO root_office_id
    FROM office.offices
    WHERE parent_office_id IS NULL;

    total_due_amount := transactions.get_total_due(root_office_id, party_id);

    office_due_amount := transactions.get_total_due(office_id, party_id);


    accrued_interest := transactions.get_accrued_interest(office_id, party_id);

    last_receipt_date := transactions.get_last_receipt_date(office_id, party_id);

    transaction_value := transactions.get_average_party_transaction(party_id, office_id);


    RETURN;
END
$function$