Thursday, 19 December 2013

Script for All Purchase Order Details with Invoice and Payment Information in Details



Script for All Purchase Order Details with Invoice and Payment Information in Details


  SELECT aia.invoice_date,
--#############################################################################
--All Purchase Order Details with Invoice and Payment Information in Details
--#############################################################################      
         aia.invoice_num,
         apca.check_date,
         apca.check_number,
         pha.segment1 po_number,
         pha.creation_date po_date,                                         --
         aia.invoice_currency_code "Currency",
         --aia.invoice_amount,
         --       aia.description,
         --       aila.line_number,
         --       aila.description "LineDescription",
         --       aila.quantity_invoiced,
         --       aila.amount "LineAmount",
         --       aila.unit_price,
         --       aila.original_amount,
         --pha.po_header_id,
         --pha.vendor_id,
         pha.comments,
         pv.vendor_name,
         pv.segment1 vendor_num,
         /*       pha.vendor_site_id,
                pvsa.address_line1||' '||
                pvsa.address_line2||' '||
                pvsa.address_line3||' '||
                pvsa.city||' '||
                ftt.territory_short_name ADDRESS,
                pvsa.address_line1,
                pvsa.address_line2,
                pvsa.address_line3,
                pvsa.city,
                ftt.territory_short_name,
                            pvsa.fax,
                pha.terms_id,*/
         apt.Description pay_terms,
         pha.currency_code,
         --pha.rate,
         --pla.po_line_id,
         pla.line_num,
         pla.item_description,
         pla.UNIT_MEAS_LOOKUP_CODE,
         pla.unit_price,
         LTRIM (pla.quantity) Quantity,
         pla.quantity * pla.unit_price * NVL (pha.rate, 1) amount,
         MTL_CATEGORIES_B.segment1 catdesc,
         (SELECT CONCATENATED_SEGMENTS
            FROM apps.gl_code_combinations_kfv
           WHERE code_combination_id = pod.code_combination_id)
            dist_account        
    FROM apps.po_headers_all pha,
         apps.po_lines_all pla,
         apps.ap_terms apt,
         apps.po_vendors pv,
         apps.po_vendor_sites_all pvsa,
         apps.fnd_territories_tl ftt,
         apps.MTL_CATEGORIES_B,
         apps.po_line_locations_all poll,
         apps.po_distributions_all pod,
         apps.ap_invoice_distributions_all apid,
         ap.ap_invoice_lines_all aila,
         ap.ap_invoices_all aia,
         ap.ap_invoice_payments_all aipa,
         ap.ap_checks_all apca
   WHERE     pha.org_id = 81
         --AND PHA.segment1 = '151900005'
         AND pha.PO_HEADER_ID = pla.PO_HEADER_ID
         AND pha.terms_id = apt.term_id
         AND pha.vendor_id = pv.vendor_id
         AND pha.vendor_site_id = pvsa.vendor_site_id
         AND pvsa.country = ftt.territory_code(+)
         AND ftt.language(+) = 'AR'
         AND MTL_CATEGORIES_B.CATEGORY_ID = pla.CATEGORY_ID
         AND pla.PO_LINE_ID = poll.PO_LINE_ID
         AND poll.LINE_LOCATION_ID = pod.LINE_LOCATION_ID
         AND pod.po_distribution_id = apid.po_distribution_id(+)
         AND aila.invoice_id = apid.invoice_id
         AND aila.line_number = apid.INVOICE_LINE_NUMBER
         AND aia.invoice_id = aila.invoice_id
         AND aipa.check_id = apca.check_id
         AND aipa.invoice_id = aia.invoice_id
         AND pha.creation_date BETWEEN :P_FROM AND :P_TO
ORDER BY pha.segment1, pla.line_num

Tuesday, 19 November 2013

Script for All Purchase Order Details with Line , Distribution Level Information in Details




Script for All Purchase Order Details with Line , Distribution Level Information in Details

  SELECT ph.segment1 po_number,
         --####################################################################
--All Purchase Order Details with Line , Distribution Level Information in Details
         --####################################################################
         TO_CHAR (ph.creation_date, 'DD-MON-YYYY') po_date,
         --ph.vendor_id,
         --pl.po_header_id,
         ph.comments,
         pv.vendor_name,
         pv.segment1 vendor_num,
         ph.AUTHORIZATION_STATUS PO_STATUS,
         pl.line_num,
         pl.item_description,
         pl.quantity,
         pl.unit_price,
         pl.amount,
         pl.quantity * pl.unit_price * NVL (ph.rate, 1) line_amount,
         (SELECT CONCATENATED_SEGMENTS
            FROM apps.gl_code_combinations_kfv
           WHERE code_combination_id = pd.code_combination_id)
            dist_account
    FROM apps.po_distributions_all pd,
         apps.po_line_locations_all pll,
         apps.po_lines_all pl,
         apps.po_headers_all ph,
         apps.po_vendors pv
   WHERE     pd.line_location_id = pll.line_location_id(+)
         AND pd.org_id = pll.org_id(+)
         AND pll.po_line_id = pl.po_line_id(+)
         AND pll.org_id = pl.org_id(+)
         AND pl.po_header_id = ph.po_header_id(+)
         AND pl.org_id = ph.org_id(+)
         AND ph.vendor_id = pv.vendor_id
         --AND ph.segment1 LIKE '151900004%'
         AND ph.creation_date BETWEEN :P_FROM AND :P_TO
ORDER BY ph.segment1, pl.line_num;