Monday, October 23, 2017

Purchase Order(PO) Change History Query

SELECT   *
    FROM (SELECT po.segment1 AS po_number, po.revision_num AS revision,
                 DECODE (po.type_lookup_code,
                         'BLANKET', fnd_message.get_string ('POS',
                                                            'POS_POTYPE_BLKT'
                                                           ),
                         'CONTRACT', fnd_message.get_string ('POS',
                                                             'POS_POTYPE_CNTR'
                                                            ),
                         'STANDARD', fnd_message.get_string ('POS',
                                                             'POS_POTYPE_STD'
                                                            ),
                         'PLANNED', fnd_message.get_string ('POS',
                                                            'POS_POTYPE_PLND'
                                                           )
                        ) TYPE,
                 po.currency_code AS currency,
                 hr1.location_code AS ship_to_location,
                 po.ship_via_lookup_code AS ship_via,
                 po.fob_lookup_code AS fob,
                 TO_CHAR
                    (pos_totals_po_sv.get_po_archive_total
                                                          (po.po_header_id,
                                                           po.revision_num,
                                                           po.type_lookup_code
                                                          ),
                     fnd_currency.safe_get_format_mask (po.currency_code, 30)
                    ) AS total,
                 hr2.location_code AS bill_to_location,
                 terms.NAME AS payment_terms,
                 po.freight_terms_lookup_code AS feight,
                 he.full_name AS buyer, po.po_header_id AS po_header_id,
                 po.ship_to_location_id AS ship_to_location_id,
                 po.bill_to_location_id AS bill_to_location_id,
                 po.agent_id AS agent_id, TO_NUMBER (NULL) AS po_release_id,
                 po.type_lookup_code, NVL (global_agreement_flag, 'N'),
                 po.org_id
            FROM po_headers_archive_all po,
                 ap_terms_val_v terms,
                 hr_locations_all_tl hr1,
                 hr_locations_all_tl hr2,
                 per_all_people_f he
           WHERE po.terms_id = terms.term_id(+)
             AND po.ship_to_location_id = hr1.location_id(+)
             AND po.bill_to_location_id = hr2.location_id(+)
             AND he.person_id(+) = po.agent_id
             AND TRUNC (SYSDATE) BETWEEN he.effective_start_date(+) AND he.effective_end_date(+)
             AND latest_external_flag = 'Y'
             AND hr1.LANGUAGE(+) = USERENV ('LANG')
             AND hr2.LANGUAGE(+) = USERENV ('LANG')
          UNION ALL
          SELECT po.segment1 || '-' || por.release_num AS po_number,
                 por.revision_num,
                 DECODE (por.release_type,
                         'BLANKET', fnd_message.get_string ('POS',
                                                            'POS_POTYPE_BLKTR'
                                                           ),
                         'SCHEDULED', fnd_message.get_string
                                                           ('POS',
                                                            'POS_POTYPE_PLNDR'
                                                           )
                        ) TYPE,
                 po.currency_code AS currency,
                 hr1.location_code AS ship_to_location,
                 po.ship_via_lookup_code AS ship_via,
                 po.fob_lookup_code AS fob,
                 TO_CHAR
                    (pos_totals_po_sv.get_release_archive_total
                                                           (por.po_release_id,
                                                            por.revision_num
                                                           ),
                     fnd_currency.safe_get_format_mask (po.currency_code, 30)
                    ) AS total,
                 hr2.location_code AS bill_to_location,
                 terms.NAME AS payment_terms,
                 po.freight_terms_lookup_code AS feight,
                 he.full_name AS buyer, po.po_header_id AS po_header_id,
                 po.ship_to_location_id AS ship_to_location_id,
                 po.bill_to_location_id AS bill_to_location_id,
                 po.agent_id AS agent_id, por.po_release_id AS po_release_id,
                 po.type_lookup_code, NVL (global_agreement_flag, 'N'),
                 por.org_id
            FROM po_headers_archive_all po,
                 po_releases_archive_all por,
                 ap_terms_val_v terms,
                 hr_locations_all_tl hr1,
                 hr_locations_all_tl hr2,
                 per_all_people_f he
           WHERE po.po_header_id = por.po_header_id
             AND po.terms_id = terms.term_id(+)
             AND po.ship_to_location_id = hr1.location_id(+)
             AND po.bill_to_location_id = hr2.location_id(+)
             AND he.person_id(+) = po.agent_id
             AND TRUNC (SYSDATE) BETWEEN he.effective_start_date(+) AND he.effective_end_date(+)
             AND por.latest_external_flag = 'Y'
             AND po.latest_external_flag = 'Y'
             AND hr1.LANGUAGE(+) = USERENV ('LANG')
             AND hr2.LANGUAGE(+) = USERENV ('LANG')) qrslt
   WHERE (po_header_id = :1 AND po_release_id IS NULL)
ORDER BY revision DESC

3 comments:

SupplierAddressImportTemplate.xlsm South Africa Suburb Field mapping in POZ_SUPPLIER_ADDRESSES_INT

Suburb mpping in Supplier Address Import Template will be mapped to Address Element Attribute2 (HZ_LOCATIONS. ADDR_ELEMENT_ATTRIBUTE2)