Q2
Q2
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_am ount, NVL (aip.discount_taken, 0) discount_amount, aip.amount amount_paid, ai.payment_method_code payment_method, TO_CHAR(ac.check_date , 'DD-MON-YYYY') 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 (ac.check_date - 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_d ate, 'DD-MON-YYYY') discount_date --QC 48928 FROM ap_invoices ai, ap_suppliers pv, ap_supplier_sites pvs, ap_checks ac, ap_payment_schedules aps , ap_invoice_payments aip 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 = ac.org_id AND ai.org_id = aps.org_id AND aip.org_id = ai.org_id AND ai.org_id = mo_global.get_current_org_id AND aip.payment_num = aps.payment_num AND ai.payment_status_flag = aps.payment_status_flag AND aip.invoice_id = ai.invoice_id AND aip.check_id = ac.check_id AND NVL(aip.reversal_flag,'N') = 'N' --Added for fix of defect#19960 AND aip.posted_flag in ('N' , 'Y') AND ai.created_by = NVL(:P_IN_NUM_USER_ID , ai.created_by) AND EXISTS ( SELECT 1 FROM DUAL
: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)) --ORDER BY pvs.vendor_site_code , ai.invoice_date , ai.invoice_num , ai.invoi ce_type_lookup_code ORDER BY 6,8,3,9
WHERE (