Tuesday, January 14, 2020

Oracle Supplier Custom Interface with API

create or replace package XX_SUP_DTL_CRT_PKG is

  procedure XX_SUPPLIER_CREATION(p_vendor_name      varchar2,
                                 p_type_lookup_code varchar2,
                                 p_vendor_name_alt  varchar2,
                                 x_vendor_id        out nocopy number);

  procedure XX_SUPPLIER_SITE_CREATION(p_vendor_site_code       varchar2,
                                      p_address_line1          varchar2,
                                      p_address_line2          varchar2,
                                      p_address_line3          varchar2,
                                      p_address_line4          varchar2,
                                      p_country                varchar2,
                                      p_org_id                 number,
                                      p_city                   varchar2,
                                      p_state                  varchar2,
                                      p_province               varchar2,
                                      p_zip                    varchar2,
                                      p_pay_site_flag          varchar2,
                                      p_purchasing_site_flag   varchar2,
                                      p_area_code              varchar2,
                                      p_site_phone             varchar2,
                                      p_fax_area_code          varchar2,
                                      p_fax                    varchar2,
                                      p_site_email_add         varchar2,
                                      p_allow_awt_flag         varchar2,
                                      p_vat_registration_num   number,
                                      p_vat_code               varchar2,
                                      p_hold_all_payments_flag varchar2,
                                      p_hold_unmatch_inv_flag  varchar2,
                                      p_hold_reason            varchar2,
                                      p_pay_group_lookup_code  varchar2,
                                      p_chque_type             varchar2,
                                      p_vendor_id              number,
                                      x_vendor_site_id         out nocopy number);

  Procedure XX_SUPPLIER_CONTACT_CREATION(p_org_id             number,
                                         p_prefix             varchar2,
                                         p_person_title       varchar2,
                                         p_person_first_name  varchar2,
                                         p_person_middle_name varchar2,
                                         p_person_last_name   varchar2,
                                         p_phone              varchar2,
                                         p_email_address      varchar2,
                                         p_department         varchar2,
                                         p_fax_phone          varchar2,
                                         p_alt_phone          varchar2,
                                         p_vendor_id          number,
                                         p_vendor_site_id     number,
                                         x_vendor_contact_id  out nocopy number);

  procedure UPLOAD_MAIN( -- header details
                        p_vendor_name      varchar2,
                        p_type_lookup_code varchar2,
                        p_vendor_name_alt  varchar2,
                        --site details
                        p_vendor_site_code       varchar2,
                        p_address_line1          varchar2,
                        p_address_line2          varchar2,
                        p_address_line3          varchar2,
                        p_address_line4          varchar2,
                        p_country                varchar2,
                        p_org_id                 number,
                        p_purchasing_site_flag   varchar2,
                        p_area_code              varchar2,
                        p_site_phone             varchar2,
                        p_fax_area_code          varchar2,
                        p_fax                    varchar2,
                        p_site_email_add         varchar2,
                        p_allow_awt_flag         varchar2,
                        p_vat_registration_num   number,
                        p_vat_code               varchar2,
                        p_hold_all_payments_flag varchar2,
                        p_hold_unmatch_inv_flag  varchar2,
                        p_hold_reason            varchar2,
                        p_pay_group_lookup_code  varchar2,
                        p_city                   varchar2,
                        p_state                  varchar2,
                        p_province               varchar2,
                        p_zip                    varchar2,
                        p_pay_site_flag          varchar2,
                        p_chque_type             varchar2,
                        -- contact details
                        p_prefix             varchar2,
                        p_person_title       varchar2,
                        p_person_first_name  varchar2,
                        p_person_middle_name varchar2,
                        p_person_last_name   varchar2,
                        p_phone              varchar2,
                        p_email_address      varchar2,
                        p_department         varchar2,
                        p_fax_phone          varchar2,
                        p_alt_phone          varchar2,
                        x_vendor_id          out nocopy number,
                        x_vendor_site_id     out nocopy number,
                        x_vendor_contact_id  out nocopy number);

end XX_SUP_DTL_CRT_PKG ;

        ========================== X X ================================

create or replace package body XX_SUP_DTL_CRT_PKG is

  procedure XX_SUPPLIER_CREATION(p_vendor_name      varchar2,
                                 p_type_lookup_code varchar2,
                                 p_vendor_name_alt  varchar2,
                                 x_vendor_id        out nocopy number) as

    p_api_version      NUMBER;
    p_init_msg_list    VARCHAR2(200);
    p_commit           VARCHAR2(200);
    p_validation_level NUMBER;
    x_return_status    VARCHAR2(200);
    x_msg_count        NUMBER;
    x_msg_data         VARCHAR2(200);
    l_vendor_rec       apps.ap_vendor_pub_pkg.r_vendor_rec_type;
    x_party_id         NUMBER;
    v_msg_index_out    NUMBER;

  BEGIN
    p_api_version                        := 1.0;
    p_init_msg_list                      := fnd_api.g_true;
    p_commit                             := fnd_api.g_true;
    p_validation_level                   := fnd_api.g_valid_level_full;
    x_return_status                      := NULL;
    x_msg_count                          := NULL;
    x_msg_data                           := NULL;
    l_vendor_rec.vendor_name             := p_vendor_name;
    l_vendor_rec.vendor_type_lookup_code := p_type_lookup_code;
    l_vendor_rec.vendor_name_alt         := p_vendor_name_alt;
    l_vendor_rec.women_owned_flag        := 'N';
    l_vendor_rec.small_business_flag     := 'Y';
    x_vendor_id                          := NULL;
    x_party_id                           := NULL;

    -- Attribute Details
    /*l_vendor_rec.attribute_category             := p_attribute_category;
    l_vendor_rec.attribute1                     := p_attribute1;
    l_vendor_rec.attribute2                     := p_attribute2;
    l_vendor_rec.attribute3                     := p_attribute3;
    l_vendor_rec.attribute4                     := p_attribute4;
    l_vendor_rec.attribute5                     := p_attribute5;
    l_vendor_rec.attribute6                     := p_attribute6;
    l_vendor_rec.attribute7                     := p_attribute7;
    l_vendor_rec.attribute8                     := p_attribute8;
    l_vendor_rec.attribute9                     := p_attribute9;
    l_vendor_rec.attribute10                    := p_attribute10;
    l_vendor_rec.attribute11                    := p_attribute11;
    l_vendor_rec.attribute12                    := p_attribute12;
    l_vendor_rec.attribute13                    := p_attribute13;
    l_vendor_rec.attribute14                    := p_attribute14;
    l_vendor_rec.attribute15                    := p_attribute15;*/

    -- Other values

    ap_vendor_pub_pkg.create_vendor(p_api_version   => p_api_version,
                                    p_init_msg_list => p_init_msg_list,
                                    -- p_commit           => p_commit,
                                    p_validation_level => p_validation_level,
                                    x_return_status    => x_return_status,
                                    x_msg_count        => x_msg_count,
                                    x_msg_data         => x_msg_data,
                                    p_vendor_rec       => l_vendor_rec,
                                    x_vendor_id        => x_vendor_id,
                                    x_party_id         => x_party_id);
    --commit;
    dbms_output.put_line('X_RETURN_STATUS = ' || x_return_status);
    dbms_output.put_line('X_MSG_COUNT = ' || to_char(x_msg_count));
    dbms_output.put_line('X_MSG_DATA = ' || x_msg_data);
    dbms_output.put_line('X_VENDOR_ID = ' || to_char(x_vendor_id));
    dbms_output.put_line('X_PARTY_ID = ' || to_char(x_party_id));
    dbms_output.put_line('');

    IF x_msg_count > 0 THEN
      FOR v_index IN 1 .. x_msg_count LOOP
        fnd_msg_pub.get(p_msg_index     => v_index,
                        p_encoded       => 'F',
                        p_data          => x_msg_data,
                        p_msg_index_out => v_msg_index_out);
        x_msg_data := SUBSTR(x_msg_data, 1, 200);
        dbms_output.put_line(x_msg_data);
      END LOOP;
    END IF;

  END XX_SUPPLIER_CREATION;

  Procedure XX_SUPPLIER_SITE_CREATION(p_vendor_site_code       varchar2,
                                      p_address_line1          varchar2,
                                      p_address_line2          varchar2,
                                      p_address_line3          varchar2,
                                      p_address_line4          varchar2,
                                      p_country                varchar2,
                                      p_org_id                 number,
                                      p_city                   varchar2,
                                      p_state                  varchar2,
                                      p_province               varchar2,
                                      p_zip                    varchar2,
                                      p_pay_site_flag          varchar2,
                                      p_purchasing_site_flag   varchar2,
                                      p_area_code              varchar2,
                                      p_site_phone             varchar2,
                                      p_fax_area_code          varchar2,
                                      p_fax                    varchar2,
                                      p_site_email_add         varchar2,
                                      p_allow_awt_flag         varchar2,
                                      p_vat_registration_num   number,
                                      p_vat_code               varchar2,
                                      p_hold_all_payments_flag varchar2,
                                      p_hold_unmatch_inv_flag  varchar2,
                                      p_hold_reason            varchar2,
                                      p_pay_group_lookup_code  varchar2,
                                      p_chque_type             varchar2,
                                      p_vendor_id              number,
                                      x_vendor_site_id         out nocopy number) as

    l_vendor_site_rec  ap_vendor_pub_pkg.r_vendor_site_rec_type;
    l_return_status    VARCHAR2(100);
    l_msg_count        NUMBER;
    l_msg_data         VARCHAR2(1000);
    l_party_site_id    NUMBER;
    l_location_id      NUMBER;
    l_msg_index_out    NUMBER;
    p_api_version      NUMBER;
    p_init_msg_list    VARCHAR2(200);
    p_commit           VARCHAR2(200);
    p_validation_level NUMBER;

  BEGIN

    --Required
    p_api_version                      := 1.0;
    p_init_msg_list                    := fnd_api.g_true;
    p_commit                           := fnd_api.g_true;
    p_validation_level                 := fnd_api.g_valid_level_full;
    x_vendor_site_id                   := null;
    l_vendor_site_rec.vendor_id        := p_vendor_id; -- '10013890';
    l_vendor_site_rec.vendor_site_code := p_vendor_site_code;
    l_vendor_site_rec.address_line1    := p_address_line1;

    --Optional
    l_vendor_site_rec.address_line2                := p_address_line2;
    l_vendor_site_rec.address_line3                := p_address_line3;
    l_vendor_site_rec.address_line4                := p_address_line4;
    l_vendor_site_rec.country                      := p_country;
    l_vendor_site_rec.org_id                       := p_org_id;
    l_vendor_site_rec.city                         := p_city;
    l_vendor_site_rec.state                        := p_state;
    l_vendor_site_rec.province                     := p_province;
    l_vendor_site_rec.zip                          := p_zip;
    l_vendor_site_rec.purchasing_site_flag         := p_purchasing_site_flag; --'Y';
    l_vendor_site_rec.pay_site_flag                := p_pay_site_flag; --'Y';
    l_vendor_site_rec.rfq_only_site_flag           := 'N';
    l_vendor_site_rec.area_code                    := p_area_code;
    l_vendor_site_rec.phone                        := p_site_phone; --'0567072954';
    l_vendor_site_rec.fax_area_code                := p_fax_area_code;
    l_vendor_site_rec.fax                          := p_fax;
    l_vendor_site_rec.email_address                := p_site_email_add;
    l_vendor_site_rec.allow_awt_flag               := p_allow_awt_flag;
    l_vendor_site_rec.vat_registration_num         := p_vat_registration_num;
    l_vendor_site_rec.vat_code                     := p_vat_code;
    l_vendor_site_rec.hold_all_payments_flag       := p_hold_all_payments_flag; --
    l_vendor_site_rec.hold_unmatched_invoices_flag := p_hold_unmatch_inv_flag;
    l_vendor_site_rec.hold_reason                  := p_hold_reason;
    l_vendor_site_rec.pay_group_lookup_code        := p_pay_group_lookup_code;
    l_vendor_site_rec.attribute2                   := p_chque_type;

    ap_vendor_pub_pkg.create_vendor_site(p_api_version   => p_api_version,
                                         p_init_msg_list => p_init_msg_list,
                                         -- p_commit           => p_commit,
                                         p_validation_level => p_validation_level,
                                         x_return_status    => l_return_status,
                                         x_msg_count        => l_msg_count,
                                         x_msg_data         => l_msg_data,
                                         p_vendor_site_rec  => l_vendor_site_rec,
                                         x_vendor_site_id   => x_vendor_site_id,
                                         x_party_site_id    => l_party_site_id,
                                         x_location_id      => l_location_id);
    --commit;                                       
    dbms_output.put_line('return_status: ' || l_return_status);
    dbms_output.put_line('msg_data: ' || l_msg_data);
    dbms_output.put_line('msg_count = ' || TO_CHAR(l_msg_count));
    dbms_output.put_line('vendor_site_id: ' || x_vendor_site_id);
    dbms_output.put_line('party_site_id: ' || l_party_site_id);
    dbms_output.put_line('location_id: ' || l_location_id);
    dbms_output.put_line('');

    IF l_msg_count > 0 THEN
      FOR v_index IN 1 .. l_msg_count LOOP
        fnd_msg_pub.get(p_msg_index     => v_index,
                        p_encoded       => 'F',
                        p_data          => l_msg_data,
                        p_msg_index_out => l_msg_index_out);
        l_msg_data := SUBSTR(l_msg_data, 1, 200);
        DBMS_OUTPUT.put_line(l_msg_data);
      END LOOP;
    END IF;

  END XX_SUPPLIER_SITE_CREATION;

  Procedure XX_SUPPLIER_CONTACT_CREATION(p_org_id             number,
                                         p_prefix             varchar2,
                                         p_person_title       varchar2,
                                         p_person_first_name  varchar2,
                                         p_person_middle_name varchar2,
                                         p_person_last_name   varchar2,
                                         p_phone              varchar2,
                                         p_email_address      varchar2,
                                         p_department         varchar2,
                                         p_fax_phone          varchar2,
                                         p_alt_phone          varchar2,
                                         p_vendor_id          number,
                                         p_vendor_site_id     number,
                                         x_vendor_contact_id  out nocopy number) as

    l_vendor_contact_rec ap_vendor_pub_pkg.r_vendor_contact_rec_type;
    l_return_status      VARCHAR2(10);
    l_msg_count          NUMBER;
    l_msg_data           VARCHAR2(1000);
    l_per_party_id       NUMBER;
    l_rel_party_id       NUMBER;
    l_rel_id             NUMBER;
    l_org_contact_id     NUMBER;
    l_party_site_id      NUMBER;
    l_msg_index_out      NUMBER;
    p_api_version        NUMBER;
    p_init_msg_list      VARCHAR2(200);
    p_commit             VARCHAR2(200);
    p_validation_level   NUMBER;

  BEGIN

    -- Required

    p_api_version                          := 1.0;
    p_init_msg_list                        := fnd_api.g_true;
    p_commit                               := fnd_api.g_true;
    p_validation_level                     := fnd_api.g_valid_level_full;
    x_vendor_contact_id                    := null;
    l_vendor_contact_rec.vendor_site_id    := p_vendor_site_id;
    l_vendor_contact_rec.vendor_id         := p_vendor_id;
    l_vendor_contact_rec.org_id            := p_org_id;
    l_vendor_contact_rec.person_first_name := p_person_first_name;
    l_vendor_contact_rec.person_last_name  := p_person_last_name;

    -- Optional
    l_vendor_contact_rec.prefix             := p_prefix;
    l_vendor_contact_rec.person_title       := p_person_title;
    l_vendor_contact_rec.person_middle_name := p_person_middle_name;
    l_vendor_contact_rec.email_address      := p_email_address;
    l_vendor_contact_rec.department         := p_department;
    l_vendor_contact_rec.fax_phone          := p_fax_phone;
    l_vendor_contact_rec.phone              := p_phone;
    l_vendor_contact_rec.alt_phone          := p_alt_phone;

    ap_vendor_pub_pkg.create_vendor_contact(p_api_version   => p_api_version,
                                            p_init_msg_list => p_init_msg_list,
                                            -- p_commit             => p_commit,
                                            p_validation_level   => p_validation_level,
                                            x_return_status      => l_return_status,
                                            x_msg_count          => l_msg_count,
                                            x_msg_data           => l_msg_data,
                                            p_vendor_contact_rec => l_vendor_contact_rec,
                                            x_vendor_contact_id  => x_vendor_contact_id,
                                            x_per_party_id       => l_per_party_id,
                                            x_rel_party_id       => l_rel_party_id,
                                            x_rel_id             => l_rel_id,
                                            x_org_contact_id     => l_org_contact_id,
                                            x_party_site_id      => l_party_site_id);

    --commit;

    dbms_output.put_line('return_status: ' || l_return_status);
    dbms_output.put_line('msg_data: ' || l_msg_data);
    dbms_output.put_line('vendor_contact_id: ' || x_vendor_contact_id);
    dbms_output.put_line('party_site_id: ' || l_party_site_id);
    dbms_output.put_line('per_party_id: ' || l_per_party_id);
    dbms_output.put_line('rel_party_id: ' || l_rel_party_id);
    dbms_output.put_line('rel_id: ' || l_rel_id);
    dbms_output.put_line('org_contact_id: ' || l_org_contact_id);
    dbms_output.put_line('p_vendor_site_id: ' || p_vendor_site_id);

    IF l_msg_count > 0 THEN
      FOR v_index IN 1 .. l_msg_count LOOP
        fnd_msg_pub.get(p_msg_index     => v_index,
                        p_encoded       => 'F',
                        p_data          => l_msg_data,
                        p_msg_index_out => l_msg_index_out);
        l_msg_data := SUBSTR(l_msg_data, 1, 200);
        DBMS_OUTPUT.put_line(l_msg_data);
      END LOOP;
    END IF;

  END XX_SUPPLIER_CONTACT_CREATION;

  procedure UPLOAD_MAIN( -- header details
                        p_vendor_name      varchar2,
                        p_type_lookup_code varchar2,
                        p_vendor_name_alt  varchar2,
                        --site details
                        p_vendor_site_code       varchar2,
                        p_address_line1          varchar2,
                        p_address_line2          varchar2,
                        p_address_line3          varchar2,
                        p_address_line4          varchar2,
                        p_country                varchar2,
                        p_org_id                 number,
                        p_purchasing_site_flag   varchar2,
                        p_area_code              varchar2,
                        p_site_phone             varchar2,
                        p_fax_area_code          varchar2,
                        p_fax                    varchar2,
                        p_site_email_add         varchar2,
                        p_allow_awt_flag         varchar2,
                        p_vat_registration_num   number,
                        p_vat_code               varchar2,
                        p_hold_all_payments_flag varchar2,
                        p_hold_unmatch_inv_flag  varchar2,
                        p_hold_reason            varchar2,
                        p_pay_group_lookup_code  varchar2,
                        p_city                   varchar2,
                        p_state                  varchar2,
                        p_province               varchar2,
                        p_zip                    varchar2,
                        p_pay_site_flag          varchar2,
                        p_chque_type             varchar2,
                        -- contact details
                        p_prefix             varchar2,
                        p_person_title       varchar2,
                        p_person_first_name  varchar2,
                        p_person_middle_name varchar2,
                        p_person_last_name   varchar2,
                        p_phone              varchar2,
                        p_email_address      varchar2,
                        p_department         varchar2,
                        p_fax_phone          varchar2,
                        p_alt_phone          varchar2,
                        x_vendor_id          out nocopy number,
                        x_vendor_site_id     out nocopy number,
                        x_vendor_contact_id  out nocopy number) as

  BEGIN

    XX_SUP_DTL_CRT_PKG.XX_SUPPLIER_CREATION(p_vendor_name,
                                                p_type_lookup_code,
                                                p_vendor_name_alt,
                                                x_vendor_id);

    XX_SUP_DTL_CRT_PKG.XX_SUPPLIER_SITE_CREATION(p_vendor_site_code,
                                                     p_address_line1,
                                                     p_address_line2,
                                                     p_address_line3,
                                                     p_address_line4,
                                                     p_country,
                                                     p_org_id,
                                                     p_city,
                                                     p_state,
                                                     p_province,
                                                     p_zip,
                                                     p_pay_site_flag,
                                                     p_purchasing_site_flag,
                                                     p_area_code,
                                                     p_site_phone,
                                                     p_fax_area_code,
                                                     p_fax,
                                                     p_site_email_add,
                                                     p_allow_awt_flag,
                                                     p_vat_registration_num,
                                                     p_vat_code,
                                                     p_hold_all_payments_flag,
                                                     p_hold_unmatch_inv_flag,
                                                     p_hold_reason,
                                                     p_pay_group_lookup_code,
                                                     p_chque_type,
                                                     x_vendor_id,
                                                     x_vendor_site_id);

    XX_SUP_DTL_CRT_PKG.XX_SUPPLIER_CONTACT_CREATION(p_org_id,
                                                        p_prefix,
                                                        p_person_title,
                                                        p_person_first_name,
                                                        p_person_middle_name,
                                                        p_person_last_name,
                                                        p_phone,
                                                        p_email_address,
                                                        p_department,
                                                        p_fax_phone,
                                                        p_alt_phone,
                                                        x_vendor_id,
                                                        x_vendor_site_id,
                                                        x_vendor_contact_id);
                                                     

  END UPLOAD_MAIN;

end XX_SUP_DTL_CRT_PKG;

Tuesday, January 7, 2020

SQL Query to get User Names of the Responsibility Attached

SELECT UNIQUE
    papf.full_name,
    fu.user_name,
    frt.responsibility_id,
    frt.responsibility_name,
    frv.responsibility_key,
    frv.application_id,
    furg.end_date,
    frv.end_date,
    fu.end_date
FROM
    apps.fnd_user                fu,
    apps.fnd_user_resp_groups    furg,
    apps.fnd_responsibility_tl   frt,
    apps.fnd_responsibility_vl   frv,
    apps.per_all_people_f        papf
WHERE
    fu.user_id = furg.user_id
    AND furg.responsibility_id = frt.responsibility_id
    AND frt.responsibility_id = frv.responsibility_id
    AND papf.person_id = fu.employee_id
    AND frt.responsibility_name = 'RESPONSIBILITY_NAME'
    AND fu.user_name = 'USER_NAME';

Sunday, December 29, 2019

SQL Query to find Security profiles attached to an User

SELECT
    fa.application_short_name,
    fpo.profile_option_name,
    fpo.user_profile_option_name,
    fu.user_name,
    fpov.profile_option_value
FROM
    fnd_profile_options_vl      fpo,
    fnd_application             fa,
    fnd_profile_option_values   fpov,
    fnd_user                    fu
WHERE
    fpo.application_id = fa.application_id
    AND fpo.profile_option_id = fpov.profile_option_id
    AND fpo.application_id = fpov.application_id
    AND fpov.level_value = fu.user_id
    AND fu.user_name = '&1'

Wednesday, December 11, 2019

Standard PO's for last 12 months

SELECT
    pha.segment1                po_no,
    trunc(pha.creation_date) po_date,
    pha.currency_code           po_currency,
    nvl(pha.rate, 1) po_rate,
    nvl2(pla.item_id, msib.segment1, NULL) item,
    nvl2(pla.item_id, msib.description, pla.item_description) item_desc,
    msib.primary_uom_code       item_uom,
    mck.concatenated_segments   item_category,
    pll.price_override          item_po_price,
    aps.vendor_name             supplier_name,
    nvl((nvl(pll.quantity, 0) - nvl(pll.quantity_cancelled, 0)), 0) ordered_qty,
    ( nvl((nvl(pll.quantity, 0) - nvl(pll.quantity_cancelled, 0)), 0) * pll.price_override ) ordered_value_po_curr,
    (
        CASE pha.currency_code
            WHEN 'AED' THEN
                ( nvl((nvl(pll.quantity, 0) - nvl(pll.quantity_cancelled, 0)), 0) * pll.price_override )
            ELSE
                ( ( nvl((nvl(pll.quantity, 0) - nvl(pll.quantity_cancelled, 0)), 0) * pll.price_override ) * nvl(pha.rate, 1) )
        END
    ) ordered_value_aed
FROM
    apps.po_headers_all              pha,
    apps.po_lines_all                pla,
    apps.po_distributions_all        pda,
    apps.gl_code_combinations        gcc,
    apps.po_line_locations_all       pll,
    apps.hr_all_organization_units   hao,
    apps.mtl_system_items_b          msib,
    apps.mtl_categories_kfv          mck,
    apps.po_agents_v                 pov,
    apps.ap_suppliers                aps,
    apps.ap_supplier_sites_all       ass
WHERE
    pha.po_header_id = pla.po_header_id
    AND pla.po_line_id = pll.po_line_id
    AND pll.ship_to_organization_id = hao.organization_id
    AND pll.po_release_id IS NULL
    AND pla.item_id = msib.inventory_item_id (+)
    AND pha.po_header_id = pda.po_header_id
    AND pla.po_line_id = pda.po_line_id
    AND pda.code_combination_id = gcc.code_combination_id
    AND msib.organization_id (+) = 63
    AND pla.category_id = mck.category_id
    AND pha.agent_id = pov.agent_id
    AND pha.vendor_id = aps.vendor_id
    AND pha.vendor_site_id = ass.vendor_site_id
    AND aps.vendor_id = ass.vendor_id
    AND pha.type_lookup_code = 'STANDARD'
    AND trunc(pha.creation_date) BETWEEN trunc(add_months(sysdate, - 12), 'MONTH') AND trunc(sysdate, 'MONTH')
ORDER BY
    trunc(pha.creation_date) ASC

Sunday, November 24, 2019

FND_PROFILE & FND_GLOBAL values

Following are the FND_PROFILE values that can be used in the PL/SQL code:

   fnd_profile.value('PROFILEOPTION');
   fnd_profile.value('MFG_ORGANIZATION_ID');
   fnd_profile.value('ORG_ID');
   fnd_profile.value('LOGIN_ID');
   fnd_profile.value('USER_ID');
   fnd_profile.value('USERNAME');
   fnd_profile.value('CONCURRENT_REQUEST_ID');
   fnd_profile.value('GL_SET_OF_BKS_ID');
   fnd_profile.value('SO_ORGANIZATION_ID');
   fnd_profile.value('APPL_SHRT_NAME');
   fnd_profile.value('RESP_NAME');
   fnd_profile.value('RESP_ID');

Following are the FND_GLOBAL values that can be used in the PL/SQL code:

   FND_GLOBAL.USER_ID;
   FND_GLOBAL.APPS_INTIALIZE;
   FND_GLOBAL.LOGIN_ID;
   FND_GLOBAL.CONC_LOGIN_ID;
   FND_GLOBAL.PROG_APPL_ID;
   FND_GLOBAL.CONC_PROGRAM_ID;
   FND_GLOBAL.CONC_REQUEST_ID;

For example, I almost always use the following global variable assignments in my package specification to use throughout the entire package body:

   g_user_id      PLS_INTEGER  :=  fnd_global.user_id;
   g_login_id     PLS_INTEGER  :=  fnd_global.login_id;
   g_conc_req_id  PLS_INTEGER  :=  fnd_global.conc_request_id;
   g_org_id       PLS_INTEGER  :=  fnd_profile.value('ORG_ID');
   g_sob_id       PLS_INTEGER  :=  fnd_profile.value('GL_SET_OF_BKS_ID');

And initialize the application environment as follows:

   v_resp_appl_id  := fnd_global.resp_appl_id;
   v_resp_id       := fnd_global.resp_id;
   v_user_id       := fnd_global.user_id;
   
   FND_GLOBAL.APPS_INITIALIZE(v_user_id,v_resp_id, v_resp_appl_id);

Thursday, November 21, 2019

Query to find all responsibilities of a user

SELECT fu.user_name                "User Name",
       frt.responsibility_name     "Responsibility Name",
       furg.start_date             "Start Date",
       furg.end_date               "End Date",     
       fr.responsibility_key       "Responsibility Key",
       fa.application_short_name   "Application Short Name"
  FROM fnd_user_resp_groups_direct        furg,
       applsys.fnd_user                   fu,
       applsys.fnd_responsibility_tl      frt,
       applsys.fnd_responsibility         fr,
       applsys.fnd_application_tl         fat,
       applsys.fnd_application            fa
 WHERE furg.user_id             =  fu.user_id
   AND furg.responsibility_id   =  frt.responsibility_id
   AND fr.responsibility_id     =  frt.responsibility_id
   AND fa.application_id        =  fat.application_id
   AND fr.application_id        =  fat.application_id
   AND frt.language             =  USERENV('LANG')
   AND UPPER(fu.user_name)      =  UPPER('xxuser')
 ORDER BY frt.responsibility_name;

Saturday, November 16, 2019

Supplier Conversion in Oracle Apps R12

In My scenario it is a conversion. Just one time loading Suppliers in Oracle Apps.
In short I will explain and attached the code below:

This is only one file having Supplier Headers, Sites and Supplier Contacts.
Based on the file developed one Stage table to store till Import into Interface Tables:

/* Stage Table */
create table XX_SUPP_INT_STG
(
  vendor_name                VARCHAR2(240),
  vendor_name_alt            VARCHAR2(320),
  legacy_vendor_num          VARCHAR2(30),
  vendor_type                VARCHAR2(30),
  organization_name          VARCHAR2(240),
  country                    VARCHAR2(25),
  address_line1              VARCHAR2(240),
  address_line2              VARCHAR2(240),
  address_line3              VARCHAR2(240),
  address_line4              VARCHAR2(240),
  city                       VARCHAR2(60),
  state                      VARCHAR2(60),
  province                   VARCHAR2(60),
  postal_code                VARCHAR2(20),
  vendor_site_code           VARCHAR2(15),
  purchasing_site            VARCHAR2(1),
  pay_site                   VARCHAR2(1),
  phone_area_code            VARCHAR2(10),
  phone_number               VARCHAR2(15),
  fax_area_code              VARCHAR2(10),
  fax                        VARCHAR2(15),
  site_email                 VARCHAR2(2000),
  allow_wht_tax_header_level VARCHAR2(1),
  invoice_wht_tax_group_hdr  NUMBER(15),
  allow_wht_tax_site_level   VARCHAR2(1),
  invoice_wht_tax_group_site NUMBER(15),
  calc_tax_site_level        VARCHAR2(1),
  vat_reg_number             VARCHAR2(20),
  vat_code                   VARCHAR2(30),
  hold_all_pay_hdr           VARCHAR2(1),
  hold_unmatch_inv_hdr       VARCHAR2(1),
  hold_unvali_inv_hdr        VARCHAR2(1),
  hold_reason_hdr            VARCHAR2(240),
  hold_all_pay_site          VARCHAR2(1),
  hold_unmatch_inv_site      VARCHAR2(1),
  hold_unvali_inv_site       VARCHAR2(1),
  hold_reason_site           VARCHAR2(240),
  pay_group                  VARCHAR2(25),
  prefix                     VARCHAR2(60),
  title                      VARCHAR2(30),
  first_name                 VARCHAR2(15),
  middle_name                VARCHAR2(15),
  last_name                  VARCHAR2(15),
  contact_email              VARCHAR2(2000),
  department                 VARCHAR2(60),
  contact_fax                VARCHAR2(40),
  contact_phone              VARCHAR2(40),
  contact_alt_phone          VARCHAR2(40)
) ;

We have interface tables for Supplier Headers, Sites and Contacts:

AP_SUPPLIERS_INT
AP_SUPPLIER_SITES_INT
AP_SUPPLIER_SITES_INT

Base Tables:

AP_SUPPLIERS / PO_VENDORS
AP_SUPPLIER_SITES / PO_VENDOR_SITES_ALL
AP_SUPPLIER_CONTACTS / PO_VENDOR_CONTANCTS

I have above stage table columns in my excel data file, it is in .xls ( we can have in .csv also. if not in these two types, we need to format the file as per our process.

Dump the excel file Data into Stage table directly ( I have done this step using PL/SQL Developer).

After I have data in my stage table: I run the below code. Because of I have done this conversion one time only, it will never use in future, but if it is multi time process (Interface), just you can create the package or procedure, register in application as per your requirement you can go ahead and you can add more validations before importing into interface table and stage table with respect your business need.

======================================================================
DECLARE

  CURSOR C_SUPP_DATA is(
    SELECT distinct VENDOR_NAME,
                  VENDOR_NAME_ALT,
          LEGACY_VENDOR_NUM,
          VENDOR_TYPE,
          PAY_GROUP,
          ALLOW_WHT_TAX_HEADER_LEVEL,
          INVOICE_WHT_TAX_GROUP_HDR,
          HOLD_ALL_PAY_HDR,
          HOLD_UNMATCH_INV_HDR,
          HOLD_UNVALI_INV_HDR,
          HOLD_REASON_HDR
      FROM XX_SUPP_INT_STG);

  CURSOR C_SITE_DATA(P_VENDOR_NAME varchar2) is(
    SELECT distinct COUNTRY,
                    ADDRESS_LINE1,
                    ADDRESS_LINE2,
                    ADDRESS_LINE3,
                    ADDRESS_LINE4,
                    CITY,
                    STATE,
                    PROVINCE,
                    POSTAL_CODE,
                    VENDOR_SITE_CODE,
                    PURCHASING_SITE,
                    PAY_SITE,
                    PHONE_AREA_CODE,
                    PHONE_NUMBER,
                    FAX_AREA_CODE,
                    FAX,
                    SITE_EMAIL,
                    ALLOW_WHT_TAX_HEADER_LEVEL,
                    INVOICE_WHT_TAX_GROUP_HDR,
                    ALLOW_WHT_TAX_SITE_LEVEL,
                    INVOICE_WHT_TAX_GROUP_SITE,
                    CALC_TAX_SITE_LEVEL,
                    VAT_REG_NUMBER,
                    VAT_CODE,
                    HOLD_ALL_PAY_HDR,
                    HOLD_UNMATCH_INV_HDR,
                    HOLD_UNVALI_INV_HDR,
                    HOLD_REASON_HDR,
                    HOLD_ALL_PAY_SITE,
                    HOLD_UNMATCH_INV_SITE,
                    HOLD_UNVALI_INV_SITE,
                    HOLD_REASON_SITE,
                    PAY_GROUP,
ORGANIZATION_NAME
      FROM XX_SUPP_INT_STG
     where VENDOR_NAME = P_VENDOR_NAME);

  CURSOR C_CONTACT_DATA(P_VENDOR_NAME varchar2, P_VENDOR_SITE varchar2) is(
    select distinct PREFIX,
                    TITLE,
                    FIRST_NAME,
                    MIDDLE_NAME,
                    LAST_NAME,
                    CONTACT_EMAIL,
                    DEPARTMENT,
                    CONTACT_FAX,
                    CONTACT_PHONE,
                    CONTACT_ALT_PHONE
      from XX_SUPP_INT_STG
     where VENDOR_NAME = P_VENDOR_NAME
       and VENDOR_SITE_CODE = P_VENDOR_SITE);

  lc_site_org_id                 po_vendor_sites_all.org_id%type; -- := 50168; /* this need to remove*/
  lc_vendor_interface_id         ap_suppliers_int.vendor_interface_id%type;
  lc_vendor_site_interface_id    ap_supplier_sites_int.vendor_site_interface_id%type;
  lc_vendor_contact_interface_id ap_sup_site_contact_int.vendor_contact_interface_id%type;
  lc_vendor_cnt                  NUMBER := 0;
  lc_user_id                     NUMBER;

BEGIN

  FOR i IN C_SUPP_DATA LOOP
    /* Main Loop */

    lc_vendor_interface_id := ap_suppliers_int_s.nextval;
 
    begin
      INSERT INTO ap.ap_suppliers_int
        (vendor_interface_id,
         vendor_name,
         vendor_name_alt,
         vendor_type_lookup_code,
         allow_awt_flag,
         awt_group_id,
         hold_all_payments_flag,
         hold_unmatched_invoices_flag,
         hold_future_payments_flag,
         hold_reason,
         pay_group_lookup_code,
         attribute10)
      VALUES
        (lc_vendor_interface_id,
         i.vendor_name,
         i.vendor_name_alt,
         i.vendor_type,
         i.allow_wht_tax_header_level,
         i.invoice_wht_tax_group_hdr,
         i.hold_all_pay_hdr,
         i.hold_unmatch_inv_hdr,
         i.hold_unvali_inv_hdr,
         i.hold_reason_hdr,
         i.pay_group,
         i.legacy_vendor_num );
 
    EXCEPTION
      WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE(i.vendor_name ||
                             ' Error occured occured at Supplier Header ' ||
                             SQLCODE || ' - ' || SQLERRM);
   
    end;

    FOR j IN C_SITE_DATA(i.vendor_name) LOOP
 
BEGIN
       SELECT organization_id
       INTO lc_site_org_id
       FROM hr_operating_units
       WHERE NAME = j.organization_name ;
     
     EXCEPTION
       WHEN OTHERS
       THEN
       DBMS_OUTPUT.PUT_LINE(j.organization_name, 'invalid Organization');
    END;

      begin
        lc_vendor_site_interface_id := ap_supplier_sites_int_s.nextval;
   
        INSERT INTO ap.ap_supplier_sites_int
          (vendor_site_interface_id,
           vendor_interface_id,
           vendor_site_code,
           address_line1,
           address_line2,
           address_line3,
           address_line4,
           city,
           state,
           country,
           zip,
           phone,
           org_id,
           province,
           purchasing_site_flag,
           pay_site_flag,
           area_code,
           fax_area_code,
           fax,
           email_address,
           allow_awt_flag,
           awt_group_id,
           auto_tax_calc_flag,
           vat_registration_num,
           vat_code,
           hold_all_payments_flag,
           hold_future_payments_flag,
           HOLD_REASON)
        VALUES
          (lc_vendor_site_interface_id,
           lc_vendor_interface_id,
           j.vendor_site_code,
           j.address_line1,
           j.address_line2,
           j.address_line3,
           j.address_line4,
           j.city,
           j.state,
           j.country,
           j.postal_code,
           j.phone_number,
           lc_site_org_id,
           j.province,
           j.purchasing_site,
           j.pay_site,
           j.phone_area_code,
           j.fax_area_code,
           j.fax,
           j.site_email,
           j.allow_wht_tax_site_level,
           j.invoice_wht_tax_group_site,
           j.calc_tax_site_level,
           j.vat_reg_number,
           j.vat_code,
           j.hold_all_pay_site,
           j.hold_unvali_inv_site,
           j.HOLD_REASON_SITE);
   
      EXCEPTION
        WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE(i.vendor_name || ' ' || j.vendor_site_code ||
                               ' Error occured occured at Supplier Site ' ||
                               SQLCODE || ' - ' || SQLERRM);
     
      end;
 
      for k in C_CONTACT_DATA(i.vendor_name, j.vendor_site_code) LOOP
     
IF k.last_name IS NULL THEN --last name condition
   DBMS_OUTPUT.PUT_LINE(i.vendor_name||''||j.vendor_site_code||''||'Contact not created because LAST NAME is null ');
        ELSE
        begin
        lc_vendor_contact_interface_id :=ap_sup_site_contact_int_s.nextval ;
   
          INSERT INTO ap.ap_sup_site_contact_int ss
            (vendor_interface_id,
             vendor_contact_interface_id,
             vendor_site_code,
             first_name,
             middle_name,
             last_name,
             area_code,
             phone,
             first_name_alt,
             last_name_alt,
             email_address,
             fax,
             prefix,
             title,
             department,
             alt_phone,
             org_id)
          VALUES
            (lc_vendor_interface_id,
             lc_vendor_contact_interface_id,
             j.vendor_site_code,
             k.first_name,
             k.middle_name,
             k.last_name,
'',--area_code
             k.contact_phone,
             NULL,
             NULL,
             k.contact_email,
             k.contact_fax,
             k.prefix,
             k.title,
             k.department,
             NVL(k.contact_alt_phone,k.contact_phone),
             lc_site_org_id);
     
        EXCEPTION
          WHEN OTHERS THEN
            DBMS_OUTPUT.PUT_LINE(i.vendor_name || ' ' ||
                                 j.vendor_site_code || ' ' || k.first_name ||
                                 ' Error occured at Supplier Contact ' ||
                                 SQLCODE || ' - ' || SQLERRM);
       
        END;

        END IF; --last name condition
      END LOOP; -- Contact Loop
 
    END LOOP; -- Site Loop

  END LOOP; -- Main Loop
  COMMIT;
  DBMS_OUTPUT.PUT_LINE('Interface ID: '||lc_vendor_interface_id);

EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Unhandled Exception occured at Supplier Header ' ||
                         SQLCODE || ' - ' || SQLERRM);
END;
======================================================================

After data inserted into Interface tables, we need to run the concurrent programs one after another to get the data into base tables, as I said above one time process so, I did not created one package and call everything there, but you can do that, if required.

Supplier Open Interface Import
Supplier Sites Open Interface Import
Supplier Contacts Open Interface Import

Once above programs completed Normal, you can see your migrated data in below base tables based on my legacy_vendor_number i.e

AP_SUPPLIERS / PO_VENDORS (attribute10 in this table )
AP_SUPPLIER_SITES / PO_VENDOR_SITES_ALL
AP_SUPPLIER_CONTACTS / PO_VENDOR_CONTANCTS






Monday, November 4, 2019

SQL Query to Get Vendor (Supplier) details with Supplier Header and Site Payment Methods in Oracle Apps

/* Supplier Detail Query */
SELECT
   pov.vendor_name
   ,pov.vendor_name_alt
   ,pov.segment1 vendor_number
   ,pov.vendor_type_lookup_code "VENDOR TYPE"
   ,pov.creation_date "VENDOR CREATION DATE"
   ,( SELECT
         paym.payment_method_code
      FROM
          ap_suppliers supp,
          iby_external_payees_all payee,
          iby_ext_party_pmt_mthds paym
      WHERE  1 = 1
      AND   supp.party_id = payee.payee_party_id
      AND   payee.ext_payee_id = paym.ext_pmt_party_id
      AND   supplier_site_id IS NULL
      AND   paym.primary_flag = 'Y'
      AND   pov.vendor_id = supp.vendor_id
    ) VENDOR_HDR_PAY_METHOD
   ,pov.end_date_active "VENDOR_END_DATE_ACTIVE"
   ,pov.vat_registration_num "VENDOR REGISTRATION NUMBER"
   ,pvs.vendor_site_code
   ,paym.payment_method_code VENDOR_SITE_PAY_METHOD
   ,pvs.end_date_active "VENDOR_SITE_END_DATE_ACTIVE"
   ,pvs.inactive_date "SITE INACTIVE DATE"
   ,hou.name "ORGANIZATION NAME"
   ,pvs.invoice_currency_code "INVOICE CURRENCY"
   ,pvs.payment_currency_code "PAYMENT CURRENCY"
   ,pvs.address_line1||' '||pvs.address_line2||' '||pvs.address_line1||' '||pvs.city||' '||pvs.state||' '||pvs.zip||' '||pvs.province||' '||pvs.country "VENDOR SITE ADDRESS"
   ,pvs.status "SITE STATUS"
   ,pvs.remittance_email "SITE REMITTANCE EMAIL"
   ,pvs.email_address "SITE EMAIL"
   ,pvs.fax_area_code||' '||pvs.fax "SITE FAX"
   ,pvc.prefix
   ,pvc.title
   ,pvc.first_name
   ,pvc.middle_name
   ,pvc.last_name
   ,pvc.email_address "CONTACT EMAIL"
   ,pvc.DEPARTMENT
   ,pvc.fax_area_code||' '||pvc.fax "CONTACT FAX"
   ,pvc.area_code||' '||pvc.phone "CONTACT PHONE"
   ,pvc.alt_area_code||' '||pvc.alt_phone "CONTACT ALT PHONE"
   ,pvc.inactive_date "CONTACT INACTIVE DATE"
FROM
   po_vendors pov
   ,po_vendor_sites_all pvs
   ,po_vendor_contacts pvc
   ,hr_operating_units hou
   ,ap_suppliers supp
   ,ap_supplier_sites_all sites
   ,iby_external_payees_all payee
   ,iby_ext_party_pmt_mthds paym
WHERE 1 = 1
AND   pov.vendor_id = pvs.vendor_id
AND   pvs.vendor_site_id = pvc.vendor_site_id
AND   pov.vendor_id = pvc.vendor_id
AND   pvs.org_id = hou.organization_id
AND   pvs.status = 'A'
AND   pov.vendor_type_lookup_code !='EMPLOYEE'
AND   ((TO_CHAR(pov.end_date_active,'DD-MM-YYYY') <= TO_CHAR(SYSDATE,'DD-MM-YYYY') ) OR pov.end_date_active IS NULL OR TO_CHAR(pov.end_date_active,'DD-MM-YYYY') = '31-12-4712' )
AND   ((TO_CHAR(pvs.end_date_active,'DD-MM-YYYY') <= TO_CHAR(SYSDATE,'DD-MM-YYYY') ) OR pvs.end_date_active IS NULL OR TO_CHAR(pvs.end_date_active,'DD-MM-YYYY') = '31-12-4712' )
AND   ((TO_CHAR(pvs.inactive_date,'DD-MM-YYYY') <= TO_CHAR(SYSDATE,'DD-MM-YYYY') ) OR pvs.inactive_date IS NULL OR TO_CHAR(pvs.inactive_date,'DD-MM-YYYY') = '31-12-4712' )
AND   ((TO_CHAR(pvc.inactive_date,'DD-MM-YYYY') <= TO_CHAR(SYSDATE,'DD-MM-YYYY') ) OR pvc.inactive_date IS NULL OR TO_CHAR(pvc.inactive_date,'DD-MM-YYYY') = '31-12-4712' )
AND   supp.party_id = payee.payee_party_id
AND   payee.ext_payee_id = paym.ext_pmt_party_id
AND   supp.vendor_id = sites.vendor_id
AND   sites.vendor_site_id = payee.supplier_site_id
AND   paym.primary_flag = 'Y'
AND   pov.vendor_id = supp.vendor_id
AND   pvs.vendor_site_id = sites.vendor_site_id
ORDER BY pov.segment1 ASC

SQL Query to get Open, Approved Blanket Agreement Purchase Orders in Oracle Apps

/* Open Blanket Agreement Query*/
SELECT
   pha.segment1 "BLANKET AGREEMENT NUMBER"
   ,pha.revision_num
   ,pha.creation_date "AGREEMENT CREATION DATE"
   ,plc.displayed_field "AGREEMENT TYPE"
   ,pha.authorization_status "APPROVAL STATUS"
   ,pha.blanket_total_amount "AMOUNT"
   ,pha.approved_date
   ,NVL(INITCAP(pha.closed_code),'Open') "AGREEMENT STATUS"
   ,pla.line_num "PO LINE NUMBER"
   ,pla.creation_date "LINE CREATION DATE"
   ,NVL(pla.closed_code,'Open') "LINE STATUS"
   ,hou.name "ORGANIZATION NAME"
   ,pov.segment1 "VENDOR NUMBER"
   ,pov.VENDOR_NAME
   ,pov.VENDOR_TYPE_LOOKUP_CODE "VENDOR TYPE"
   ,pvs.VENDOR_SITE_CODE
   ,pha.currency_code
   ,ppf.full_name "BUYER NAME"
   ,pha.attribute_category "CATEGORY"
   ,pha.attribute1
   ,msi.segment1 "LINE ITEM"
   ,msi.description "ITEM DESCRIPTION"
   ,mcb.segment1||'.'||mcb.segment2||'.'||mcb.segment3||'.'||mcb.segment1 "ITEM CATEGORY"
   ,pla.quantity "BA QUANTITY"
   ,pla.unit_meas_lookup_code "UOM"
   ,pla.unit_price
FROM
   apps.po_headers_all pha
   ,apps.po_lines_all pla
   ,apps.po_lookup_codes plc
   ,apps.po_vendors pov
   ,apps.po_vendor_sites_all pvs
   ,apps.per_all_people_f ppf
   ,apps.hr_operating_units hou
   ,apps.mtl_system_items_b msi 
   ,apps.mtl_categories_b mcb
WHERE 1 = 1
AND   pha.po_header_id = pla.po_header_id
AND   pha.type_lookup_code = plc.lookup_code
AND   pha.vendor_id = pov.vendor_id
AND   pov.vendor_id = pvs.vendor_id
AND   pha.vendor_site_id =pvs.VENDOR_SITE_ID
AND   pha.agent_id = ppf.person_id
AND   (SYSDATE BETWEEN ppf.effective_start_date AND ppf.effective_end_date  )
AND   pha.org_id = hou.organization_id
AND   pla.item_id = msi.inventory_item_id
AND   msi.organization_id = 63
AND   pla.category_id = mcb.category_id
AND   plc.lookup_type = 'AGREEMENT_TYPE'
AND   pha.type_lookup_code = 'BLANKET'
AND   NVL(pha.closed_code,'OPEN') = 'OPEN'
AND   pha.authorization_status = 'APPROVED'
ORDER BY pha.segment1

SQL Query to find Customer, Customer Account and Customer Sites Information

/****************************************************************************** *PURPOSE: Query to Customer, Customer Account and Customer...