Wednesday, 11 December 2024

Query to find list of all open invoice for the customer

 SELECT
    hp.party_id,
    hp.party_number,
    hp.party_name,
    hp.party_type,
    hca.account_number,
    hcp.send_statements,
    hcp.statement_cycle_id,
    hcp.dunning_letters,
    rcta.org_id,
    hou.name,
    rcta.trx_number                           invoice_number,
    ar.class,
    rcta.purchase_order                       purchase_order,
    rcta.trx_date                             transaction_date,
    to_char(ar.due_date, 'MM/DD/YYYY')        due_date,
    ar.amount_due_remaining                   amount_due_remaining,
    trunc(sysdate - ar.due_date)              day_late,
    hca.cust_account_id
FROM
    hz_parties                hp,
    hz_cust_accounts          hca,
    hz_customer_profiles      hcp,
    ra_customer_trx_all       rcta,
    hr_operating_units        hou,
    ar_payment_schedules_all  ar
WHERE
        1 = 1
    AND hp.party_id = hca.party_id
    AND hca.cust_account_id = hcp.cust_account_id
    AND hcp.site_use_id IS NULL
    AND rcta.org_id = hou.organization_id
    AND rcta.bill_to_customer_id = hcp.cust_account_id
    AND rcta.customer_trx_id = ar.customer_trx_id
    AND ar.class = 'INV'
    AND ar.status = 'OP'
    AND hp.status = 'A'
    AND hca.status = 'A'
    AND hcp.status = 'A'
    AND hp.party_type = 'ORGANIZATION'
    AND hca.account_number = '37382'
ORDER BY
    hp.party_name,
    hca.account_number;

No comments:

Post a Comment