You are on page 1of 2

SELECT NVL(TO_CHAR(ai.doc_sequence_value), -- QC41524 ai.voucher_num) document_sequence, ai.pay_group_lookup_code pay_group, ai.invoice_num invoice_number, ai.invoice_id ai_invoice_id, pv.vendor_name supplier_name, pv.

segment1 supplier_number, pvs.vendor_site_code supplier_site_name, pv.vendor_type_lookup_code supplier_type, TO_CHAR(ai.invoice_date , 'DD-MON-YYYY') invoice_date, ai.invoice_type_lookup_code invoice_type, ai.SOURCE source_of_invoice, TO_CHAR(ai.gl_date , 'DD-MON-YYYY') gl_date, ai.invoice_amount invoice_amount, 0 discount_amount, 0 amount_paid, ai.payment_method_code payment_method, null payment_date, TO_CHAR(aps.due_date , 'DD-MON-YYYY') due_date, aps.amount_remaining amount_remaining, ai.invoice_currency_code currency, NVL(ai.exchange_rate , 1) exchange_rate, -- ai.created_by created_by, -- QC # 49223 (SELECT fu.user_name FROM fnd_user fu WHERE fu.user_id = ai.created_by ) created_by, -- QC # 49223 (SELECT COUNT (ail.invoice_id) FROM ap_invoice_lines ail WHERE ail.invoice_id = ai.invoice_id AND ai.org_id = ail.org_id GROUP BY ail.invoice_id) line_count, TRUNC(sysdate - aps.due_date) early_late_date, xxfin_gbl_invoices_status_pkg.xxfin_gbl_get_invoice_sts_func ( ai.invoice_id, ai.invoice_amount, ai.payment_status_flag, ai.invoice_type_lookup_code ) invoice_status, TO_CHAR(aps.discount_ date, 'DD-MON-YYYY') discount_date --QC 48928 FROM ap_invoices ai, ap_suppliers pv, ap_supplier_sites pvs, ap_payment_schedules aps WHERE aps.invoice_id = ai.invoice_id AND pv.vendor_id = ai.vendor_id AND pv.party_id = ai.party_id AND pvs.vendor_id = pv.vendor_id AND ai.vendor_site_id = pvs.vendor_site_id AND ai.org_id = aps.org_id AND ai.org_id = mo_global.get_current_org_id AND ai.payment_status_flag = aps.payment_status_flag AND ai.created_by = NVL(:P_IN_NUM_USER_ID , ai.created_by) AND EXISTS ( SELECT 1 FROM DUAL WHERE ( :P_IN_CHR_SUPPLIER_TYPE is NULL AND pv.vendor_type_lookup_code IN ('NON TRADE', 'TRADE MANUFACTURER', 'TRADE SERVICE PROVIDER', 'TRADE SUPPLIER','INTERCOMPA NY') -- CA 294997 'INTERCOMPANY' added

) OR (pv.vendor_type_lookup_code = :P_IN_CHR_SUPPLIER_TYPE)) AND pv.vendor_id = NVL (:p_in_num_supplier_id, pv.vendor_id) --add for QC41524 AND TRUNC(ai.gl_date) >= :P_IN_DTE_FROM_GL_DATE AND TRUNC(ai.gl_date) <= :P_IN_DTE_TO_GL_DATE --end add for QC41524 AND ai.invoice_currency_code = NVL (:P_IN_CHR_CUR_CODE, ai.invoice_currency_code) -- MQ fix for QC#31058 AND invoice_status = NVL(:P_IN_CHR_STATUS,invoice_status) -- End of MQ fix for QC#31058 AND EXISTS ( SELECT 1 FROM DUAL WHERE ( NVL(:P_IN_CHR_CANCEL_FLAG,'N') = 'N' --Added NVL condition for defect fix #19690 AND NVL(:P_IN_CHR_VALIDATED,'N') = 'N' --Added NVL condition f or defect fix #19690 AND invoice_status NOT IN ('Cancelled') ) OR ( NVL(:P_IN_CHR_CANCEL_FLAG,'N') = 'N' --Added NVL condition for defect fix #19690 AND NVL(:P_IN_CHR_VALIDATED,'N') = 'Y' --Added NVL condition f or defect fix #19690 AND invoice_status IN ('Validated') ) OR ( NVL(:P_IN_CHR_CANCEL_FLAG,'N') = 'Y' --Added NVL conditio n for defect fix #19690 AND NVL(:P_IN_CHR_VALIDATED,'N') = 'N' --Added NVL condition f or defect fix #19690 ) OR ( NVL(:P_IN_CHR_CANCEL_FLAG,'N') = 'Y' --Added NVL conditio n for defect fix #19690 AND NVL(:P_IN_CHR_VALIDATED,'N') = 'Y' --Added NVL condition f or defect fix #19690 AND invoice_status IN ('Validated') ) ) AND ai.invoice_type_lookup_code = NVL (:P_IN_CHR_INV_TYPE, ai.invoice_type_lookup_code) AND UPPER(ai.source) = UPPER(NVL (:P_IN_CHR_SOURCE, ai.source)) AND NOT EXISTS (SELECT 1 FROM ap_invoice_payments WHERE invoice_id=ai.invoice _id GROUP BY NVL(reversal_flag,'N') HAVING COUNT(1)=1)

You might also like