Saturday, March 17, 2012

Relation between AR tables and Projects, Project invoices


Following is the project invoices query with customer_name,project_number,
bill-to address,project revenue, ar invoice ,invoice_amount,payment amount etc.:-

SELECT       trx.trx_number, reve.gl_date,
                  hl.address1 || hl.address2 address,
                  hl.city, hl.state, hl.postal_code, hca.account_name,
                  paysch.amount_due_remaining, reve.draft_revenue_num,
                  proj.project_id project_id, draftinv.draft_invoice_num,
                  proj.segment1 project_number, draftinv.system_reference
FROM    ar_payment_schedules_all paysch,
            ra_customer_trx_all trx,
            pa_draft_invoices draftinv,
            pa_draft_invoice_items dinvitms,
            pa_cust_rev_dist_lines revedist,
            pa_draft_revenues reve,
            pa_projects proj,
            hz_cust_accounts hca,
            hz_cust_acct_sites_all hcas,
            hz_cust_site_uses_all hcsu,
            hz_party_sites hps,
            hz_locations hl
WHERE paysch.customer_trx_id = trx.customer_trx_id
     AND paysch.CLASS = 'INV'
     AND paysch.status = 'OP'
     AND trx.bill_to_customer_id = hca.cust_account_id
     AND trx.bill_to_site_use_id = hcsu.site_use_id
     AND hca.cust_account_id = hcas.cust_account_id
     AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
     AND hps.party_site_id = hcas.party_site_id
     AND trx.interface_header_context = 'PROJECTS INVOICES'
     AND draftinv.system_reference = trx.customer_trx_id
     AND draftinv.draft_invoice_num = dinvitms.draft_invoice_num
     AND dinvitms.draft_invoice_num = revedist.draft_invoice_num
     AND dinvitms.line_num = revedist.draft_invoice_item_line_num
     AND revedist.draft_revenue_num = reve.draft_revenue_num
     AND hl.location_id = hps.location_id
     AND reve.transfer_status_code = 'A'
     AND draftinv.draft_invoice_num_credited IS NULL
     AND proj.project_id = reve.project_id
     AND proj.project_id = revedist.project_id
     AND proj.project_id = dinvitms.project_id
     AND proj.project_id = draftinv.project_id
     AND draftinv.project_id = dinvitms.project_id
     AND reve.project_id = draftinv.project_id
GROUP BY      trx.trx_number,
                     hca.account_name,
                     hl.address1 || hl.address2,
                     hl.city, hl.state,
                     hl.postal_code,
                     reve.gl_date,
                     paysch.amount_due_remaining,
                     reve.draft_revenue_num,
                     draftinv.draft_invoice_num,
                     proj.segment1,
                     draftinv.system_reference,
                     proj.project_id;

No comments:

Post a Comment