Tuesday, 11 September 2018

Query to get Prepay apply and Standard Invoice information

--Query to get Prepay apply and Standard Invoice information
SELECT pv.vendor_name
      ,aia.invoice_num
      ,aia.invoice_id
      ,aia.invoice_amount
      ,ail.line_number Invoice_Line_Num
      ,prepay.invoice_id Prepay_Invoice_Id
      ,prepay.invoice_num Prepay_Invoice_Num
      ,ail.prepay_line_number Prepay_Invoice_Line_Num
      ,(-1)*(ail.amount - NVL(ail.included_tax_amount,0)) Prepay_Amt_Applied
      ,NULLIF((-1)*(NVL(ail.total_rec_tax_amount, 0) +     
       NVL(ail.total_nrec_tax_amount, 0)), 0) Prepay_Tax_amount_Applied
  FROM AP_INVOICES_ALL aia
      ,AP_INVOICES_ALL prepay
      ,AP_INVOICE_LINES_ALL ail
      ,AP_SUPPLIERS pv
WHERE aia.invoice_id = ail.invoice_id
  AND prepay.invoice_id = ail.prepay_invoice_id
  AND ail.amount < 0
  AND NVL(ail.discarded_flag,'N') <> 'Y'
  AND ail.line_type_lookup_code = 'PREPAY'
  AND aia.vendor_id = pv.vendor_id
  AND aia.invoice_type_lookup_code NOT IN ('PREPAYMENT', 'CREDIT','DEBIT')
  AND aia.invoice_id = 641876;

No comments:

Post a Comment