DBA Data[Home] [Help]

APPS.HZ_CUSTOMER_INT SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 7

g_last_update_login                NUMBER;
Line: 8

g_last_updated_by                  NUMBER;
Line: 21

      SELECT cust_account_id
      FROM   hz_cust_accounts
      WHERE  orig_system_reference = p_orig_system_customer_ref;
Line: 41

      SELECT cust_acct_site_id
      FROM   hz_cust_acct_sites_all  -- bug 4454799
      WHERE  orig_system_reference = p_orig_system_address_ref
	AND  org_id = p_org_id; -- bug 4454799
Line: 61

      SELECT cust_account_role_id
      FROM   hz_cust_account_roles
      WHERE  orig_system_reference = p_orig_system_contact_ref;
Line: 80

      SELECT party_id
      FROM   hz_cust_account_roles
      WHERE  orig_system_reference = p_orig_system_contact_ref;
Line: 106

 SELECT party_number
 FROM hz_parties
 WHERE orig_system_reference = 'PREL-'||p_orig_system_contact_ref;
Line: 111

 SELECT party_name
 FROM hz_parties
 WHERE orig_system_reference = p_orig_system_contact_ref;
Line: 116

 SELECT party_name
 FROM hz_parties
 WHERE party_id = (select party_id
                   from hz_cust_accounts
                   where orig_system_reference = p_orig_system_customer_ref);
Line: 148

 PROCEDURE update_party_prel_name(p_party_id IN NUMBER )
 IS

   l_party_name VARCHAR2(360);
Line: 154

      SELECT r.party_id, r.object_id, o.party_name, r.subject_id, s.party_name,
             rel.party_number, rel.party_name
      FROM hz_relationships r, hz_parties s, hz_parties o, hz_parties rel
      WHERE (r.subject_id = p_party_id OR r.object_id = p_party_id)
      AND r.party_id IS NOT NULL
      AND r.subject_table_name = 'HZ_PARTIES'
      AND r.object_table_name = 'HZ_PARTIES'
      AND r.directional_flag = 'F'
      AND r.subject_id = s.party_id
      AND r.object_id = o.party_id
      AND r.party_id = rel.party_id;
Line: 194

        UPDATE hz_parties
        SET party_name = l_party_name
        WHERE party_id = i_party_id(i);
Line: 203

      update_party_prel_name(i_party_id(i));
Line: 207

  end update_party_prel_name;
Line: 214

      SELECT party_site_id
      FROM hz_cust_acct_sites_all -- bug 4454799
      WHERE orig_system_reference = p_orig_system_address_ref
      AND org_id = p_org_id; -- bug 4454799
Line: 234

      SELECT party_id
      FROM   hz_cust_accounts
      WHERE  orig_system_reference = p_orig_system_customer_ref;
Line: 256

      SELECT party_id
      FROM   hz_parties
      WHERE  orig_system_reference = p_orig_system_contact_ref;
Line: 261

      SELECT orig_system_customer_ref
      FROM   ra_customers_interface;
Line: 296

      SELECT language_code
      FROM   fnd_languages
      WHERE  nls_language = p_language;
Line: 313

      SELECT  site_use_code, i.gl_id_rec, i.gl_id_rev, i.gl_id_tax,
              i.gl_id_freight, i.gl_id_clearing, i.gl_id_unbilled,
              i.gl_id_unearned, i.interface_status
      FROM    ra_customers_interface i
      WHERE   i.request_id = p_request_id
              AND nvl(i.validated_flag,'N') <> 'Y'
              AND (gl_id_rec IS NOT NULL
                   OR gl_id_rev IS NOT NULL
                   OR gl_id_tax IS NOT NULL
                   OR gl_id_freight IS NOT NULL
                   OR gl_id_clearing IS NOT NULL
                   OR gl_id_unbilled IS NOT NULL
                   OR gl_id_unearned IS NOT NULL)
      FOR UPDATE;
Line: 329

      SELECT  i.site_use_code, i.gl_id_unpaid_rec, i.gl_id_remittance,
              i.gl_id_factor, i.interface_status
      FROM    ra_customers_interface i
      WHERE   i.request_id = p_request_id
              AND nvl(i.validated_flag,'N') <> 'Y'
              AND (gl_id_unpaid_rec IS NOT NULL
                   OR gl_id_remittance IS NOT NULL
                   OR gl_id_factor IS NOT NULL)
      FOR UPDATE;
Line: 450

      UPDATE ra_customers_interface_all
      SET    interface_status = p_interface_status
      WHERE  CURRENT OF auto_acc;
Line: 505

      UPDATE ra_customers_interface_all
      SET    interface_status = p_interface_status
      WHERE  CURRENT OF boe;
Line: 513

                               p_insert_update_flag IN VARCHAR2)
    RETURN VARCHAR2 IS
    l_return_code VARCHAR2(5) := 'A3,';
Line: 518

      SELECT party_id
      FROM   hz_parties
      WHERE  orig_system_reference = p_orig_system_customer_ref;
Line: 522

    IF p_insert_update_flag = 'I' THEN
      OPEN c7;
Line: 548

      SELECT party_id
      FROM   hz_parties
      WHERE  orig_system_reference = p_orig_system_customer_ref
      AND    party_id              = p_request_id /* Bug Fix : 5214454 */
         --  AND request_id        = p_request_id;  /* Bug Fix : 1891773 */
Line: 575

      SELECT party_id
      FROM   hz_parties party
      WHERE  party.orig_system_reference = p_orig_system_customer_ref
      AND    party.PARTY_TYPE = decode(p_person_flag, 'Y', 'PERSON','ORGANIZATION')
      AND	 exists (select 'X' from hz_cust_accounts where  party_id = party.party_id)
      AND    rownum  = 1;
Line: 583

      SELECT party_id
      FROM   hz_cust_accounts
      WHERE  orig_system_reference = p_orig_system_customer_ref;
Line: 588

      SELECT party_id
      FROM   hz_parties
      WHERE  orig_system_reference = p_orig_system_customer_ref
      AND    PARTY_TYPE = decode(p_person_flag, 'Y', 'PERSON','ORGANIZATION')
      AND    status  in ('A','I')
      AND    rownum  = 1;
Line: 627

      SELECT c.party_id
      FROM   hz_parties c
      WHERE  c.orig_system_reference = p_orig_system_contact_ref
             AND c.request_id        = p_request_id
             AND NOT EXISTS
               (SELECT 'X'
                FROM   hz_cust_accounts y
                WHERE  y.orig_system_reference = p_orig_system_contact_ref
                       AND y.party_id = c.party_id);
Line: 654

      SELECT rel.party_id
      FROM   hz_relationships rel,
             hz_org_contacts  cont
      WHERE  cont.request_id    = p_request_id
             AND cont.orig_system_reference = p_orig_system_contact_ref
             AND cont.party_relationship_id = rel.relationship_id
             AND rel.subject_table_name = 'HZ_PARTIES'
             AND rel.object_table_name = 'HZ_PARTIES';
Line: 679

      SELECT rel.relationship_id
      FROM   hz_relationships  rel,
             hz_org_contacts         cont
      WHERE  cont.request_id = p_request_id
             AND cont.orig_system_reference = p_orig_system_contact_ref
             AND cont.party_relationship_id = rel.relationship_id
             AND rel.subject_table_name = 'HZ_PARTIES'
             AND rel.object_table_name = 'HZ_PARTIES';
Line: 720

                select  'X'
                into    l_count
                from    hz_cust_accounts cust
                        ,hz_cust_acct_sites site
                        ,hz_cust_site_uses su
                where   site.orig_system_reference = p_bill_to_orig_address_ref
                and     site.cust_acct_site_id = su.cust_acct_site_id
                and     site.cust_account_id = cust.cust_account_id
                and     cust.orig_system_reference = p_orig_system_customer_ref
                and     su.site_use_code = 'BILL_TO'
                and     su.status = 'A'
                and     site.status = 'A';
Line: 736

                  select  'X'
                  into l_count
                  from ra_customers_interface i,
                        ra_customers_interface i1
                  where
                        i.request_id                = req_id
                  and   i.bill_to_orig_address_ref is not  NULL
                  and   i1.site_use_code = 'BILL_TO'
                  and   i.bill_to_orig_address_ref = i1.orig_system_address_ref
                  and   i.orig_system_address_ref = p_orig_system_address_ref
                  and   i.orig_system_customer_ref = p_orig_system_customer_ref
                  and   i.rowid                    <> i1.rowid
                  and   i.interface_status is null
                  and   rownum = 1;
Line: 760

      SELECT 'x'
      FROM   hz_cust_accounts cust,
             hz_cust_acct_sites_all site, -- bug 4454799
             hz_cust_site_uses_all su  -- bug 4454799
      WHERE  cust.orig_system_reference = p_orig_system_customer_ref
             AND site.orig_system_reference = p_bill_to_orig_address_ref
             AND site.org_id = p_org_id  -- bug 4454799
             AND site.cust_account_id = cust.cust_account_id
             AND site.cust_acct_site_id = su.cust_acct_site_id
             AND site.org_id = su.org_id -- bug 4454799
             AND su.site_use_code = 'BILL_TO'
             AND su.status = 'A'
             AND site.status = 'A'
      UNION ALL
      SELECT 'x'
      FROM   hz_cust_accounts cust,
             hz_cust_acct_sites_all site, -- bug 4454799
             hz_cust_site_uses_all su  -- bug 4454799
      WHERE  cust.orig_system_reference = p_orig_system_parent_ref
             AND site.orig_system_reference = p_bill_to_orig_address_ref
             AND site.org_id = p_org_id  -- bug 4454799
             AND site.cust_account_id = cust.cust_account_id
             AND site.cust_acct_site_id = su.cust_acct_site_id
             AND site.org_id = su.org_id  -- bug 4454799
             AND su.site_use_code = 'BILL_TO'
             AND su.status = 'A'
             AND site.status = 'A';
Line: 789

      SELECT 'x'
      FROM   hz_cust_accounts cust,
             hz_cust_acct_relate_all rel, -- bug 4454799
             hz_cust_acct_sites_all site, -- bug 4454799
             hz_cust_site_uses_all su  -- bug 4454799
      WHERE  cust.orig_system_reference = p_orig_system_customer_ref
             AND  rel.related_cust_account_id = cust.cust_account_id
             AND  rel.bill_to_flag   = 'Y'
             AND  site.cust_account_id = rel.cust_account_id
             AND  site.orig_system_reference = p_bill_to_orig_address_ref
             AND  site.org_id = p_org_id -- bug 4454799
	     AND  site.org_id = su.org_id -- bug 4454799
	     AND  site.org_id = rel.org_id -- bug 4454799
             AND site.cust_acct_site_id = su.cust_acct_site_id
             AND su.site_use_code = 'BILL_TO'
             AND su.status = 'A'
             AND site.status = 'A';
Line: 808

      SELECT 'x'
      FROM   ra_customers_interface      i,
             ra_customers_interface_all i1 -- bug 4454799
      WHERE  i.request_id = req_id
             AND   i.bill_to_orig_address_ref is not NULL
             AND   i.orig_system_customer_ref = p_orig_system_customer_ref
             AND   i.orig_system_address_ref = p_orig_system_address_ref
             AND   i.bill_to_orig_address_ref = i1.orig_system_address_ref
             AND   i.org_id = p_org_id  -- bug 4454799
             AND   i.org_id = i1.org_id -- bug 4454799
             AND   i1.site_use_code = 'BILL_TO'
             AND   i.rowid  <> i1.rowid
             AND   i1.interface_status is null
             AND   rownum = 1
      UNION ALL
      SELECT 'x'
      FROM   ra_customers_interface i,
             ra_customers_interface_all i1 -- bug 4454799
      WHERE  i.request_id = req_id
             AND   i.bill_to_orig_address_ref is not NULL
             AND   i.orig_system_customer_ref = p_orig_system_customer_ref
             AND   i1.orig_system_customer_ref = i.orig_system_parent_ref
             AND   i.orig_system_address_ref = p_orig_system_address_ref
             AND   i.org_id = p_org_id  -- bug 4454799
	     AND   i.org_id = i1.org_id -- bug 4454799
             AND   i.bill_to_orig_address_ref = i1.orig_system_address_ref
             AND   i1.site_use_code = 'BILL_TO'
             AND   i.rowid  <> i1.rowid
             AND   i1.interface_status is null
             AND   rownum = 1;
Line: 913

      SELECT orig_system_parent_ref, orig_system_party_ref
      FROM   ra_customers_interface
      WHERE  orig_system_customer_ref = p_orig_system_customer_ref
             AND ROWNUM = 1;
Line: 1287

  FUNCTION validate_profile(v_insert_update_flag IN VARCHAR,
                            v_orig_system_customer_ref IN VARCHAR,
                            v_orig_system_address_ref IN VARCHAR,
                            v_org_id IN NUMBER,
                            v_request_id IN NUMBER)
    RETURN VARCHAR2 AS

    l_dummy VARCHAR(1);
Line: 1296

    CURSOR c1 IS -- Check if Cust record exists for ninsertion
      SELECT 'x'
      FROM   ra_customers_interface
      WHERE  orig_system_customer_ref = v_orig_system_customer_ref
             AND interface_status is null
             AND request_id = v_request_id;
Line: 1304

      SELECT 'x'
      FROM   hz_customer_profiles p ,hz_cust_accounts c
      WHERE  c.orig_system_reference = v_orig_system_customer_ref
             AND p.cust_account_id = c.cust_account_id
             AND p.site_use_id is null;
Line: 1311

      SELECT 'x' -- The address ref should exist as Bill To and defined for the customer
      FROM   hz_cust_acct_sites_all ra, hz_cust_site_uses_all rsu, hz_cust_accounts rc -- bug 4454799
      WHERE  ra.orig_system_reference = v_orig_system_address_ref
             AND ra.org_id = v_org_id  -- bug 4454799
             AND rc.orig_system_reference = v_orig_system_customer_ref
             AND rc.cust_account_id = ra.cust_account_id
             AND ra.cust_acct_site_id = rsu.cust_acct_site_id
             AND ra.org_id = rsu.org_id  -- bug 4454799
             AND rsu.status = 'A'
             AND rsu.site_use_code in ('BILL_TO','DUN','STMTS')
      UNION ALL
      SELECT 'x' -- If not already defined, THEN address rec should
                 -- exist in  interface table with Bill To
      FROM   ra_customers_interface
      WHERE  orig_system_customer_ref = v_orig_system_customer_ref
             AND interface_status is null
             AND orig_system_address_ref = v_orig_system_address_ref
             AND org_id = v_org_id  -- bug 4454799
             AND request_id = v_request_id
--Bug fix 2473275
             AND site_use_code in ('BILL_TO','DUN','STMTS');
Line: 1334

      SELECT 'x'
      FROM   hz_customer_profiles p,
             hz_cust_acct_sites_all ra, -- bug 4454799
             hz_cust_site_uses_all rsu  -- but 4454799
      WHERE  ra.orig_system_reference = v_orig_system_address_ref
             AND ra.org_id = v_org_id  -- bug 4454799
	     AND ra.org_id = rsu.org_id -- bug 4454799
             AND ra.cust_acct_site_id = rsu.cust_acct_site_id
             AND rsu.status = 'A'
--Bug fix 2473275
             AND rsu.site_use_code in ('BILL_TO','DUN','STMTS')
             AND rsu.site_use_id = p.site_use_id;
Line: 1349

    IF v_insert_update_flag NOT IN ('I','U') THEN
      RETURN 'J8,';
Line: 1357

      IF v_insert_update_flag = 'I' THEN  -- Insert New Profile
        -- check if the customer ref is valid.  if not, reject with status = S1
        OPEN c1;
Line: 1376

      IF v_insert_update_flag = 'U' THEN -- Updating existing profile
        -- This customer should have a profile defined already.
        -- if not defined  reject with status = 'a4'
        OPEN c2;
Line: 1391

      IF v_insert_update_flag = 'I' THEN -- Insert New Profile

        -- First check if the address  has been already created
        -- as a Bill_TO,DUNNING or STATEMENTS or if not created THEN should be in the
        -- interface table with no error AND should be BILL_TO,DUNNING or STATEMENTS.
        OPEN c3;
Line: 1413

      IF v_insert_update_flag = 'U' THEN -- Updating Existing Profile
        -- This Site should have a profile defined already.
        -- if not defined  reject with status = 'a4'
        OPEN c4;
Line: 1449

      SELECT 'X'
      FROM   ar_location_values v,
             ar_location_values pv,
             ar_location_values gv,
             ar_location_values ggv,
             ar_location_rates  r
      WHERE  v.location_structure_id      = p_location_structure_id
             AND v.location_segment_id    = r.location_segment_id
             AND v.location_segment_value = UPPER(p_postal_code)
             AND v.location_segment_qualifier = 'POSTAL_CODE'
             AND TRUNC(p_creation_date)
               BETWEEN TRUNC(r.start_date)
                       AND NVL(TRUNC(r.end_date), TRUNC(p_creation_date))
             AND p_postal_code BETWEEN r.from_postal_code AND r.to_postal_code
             AND v.parent_segment_id  = pv.location_segment_id(+)
             AND pv.parent_segment_id = gv.location_segment_id(+)
             AND gv.parent_segment_id = ggv.location_segment_id(+)
             AND (pv.location_segment_value = UPPER(p_city)
                  OR p_city IS NULL)
             AND (gv.location_segment_value = UPPER(p_county)
                  OR p_county IS NULL)
             AND (ggv.location_segment_value = UPPER(p_state)
                  OR p_state IS NULL );
Line: 1475

      SELECT 'X'
      FROM   ar_location_values v,
             ar_location_values pv,
             ar_location_values gv,
             ar_location_rates  r
      WHERE  v.location_structure_id      = p_location_structure_id
             AND v.location_segment_id    = r.location_segment_id
             AND v.location_segment_value = UPPER(p_city)
             AND v.location_segment_qualifier = 'CITY'
             AND TRUNC(p_creation_date)
               BETWEEN TRUNC(r.start_date)
                       AND NVL(TRUNC(r.end_date), TRUNC(p_creation_date))
             AND p_postal_code BETWEEN r.from_postal_code AND r.to_postal_code
             AND v.parent_segment_id  = pv.location_segment_id(+)
             AND pv.parent_segment_id = gv.location_segment_id(+)
             AND (pv.location_segment_value = UPPER(p_county)
                  OR p_county IS NULL)
             AND (gv.location_segment_value = UPPER(p_state)
                  OR p_state IS NULL);
Line: 1498

      SELECT 'X'
      FROM   ar_location_values v,
             ar_location_values gv,
             ar_location_rates  r
      WHERE  v.location_structure_id      = p_location_structure_id
             AND v.location_segment_id    = r.location_segment_id
             AND v.location_segment_value = UPPER(p_child_value)
             AND v.location_segment_qualifier = p_child
             AND TRUNC(p_creation_date)
               BETWEEN TRUNC(r.start_date)
                       AND nvl(TRUNC(r.end_date), TRUNC(p_creation_date))
             AND p_postal_code BETWEEN r.from_postal_code AND r.to_postal_code
             AND v.parent_segment_id  = gv.location_segment_id(+)
             AND (gv.location_segment_value = UPPER(p_parent_value)
                  OR p_state IS NULL);
Line: 1517

      SELECT 'X'
      FROM   ar_location_values v, ar_location_rates  r
      WHERE  v.location_structure_id      = p_location_structure_id
             AND v.location_segment_id    = r.location_segment_id
             AND v.location_segment_value = UPPER(p_value)
             AND v.location_segment_qualifier = p_segment
             AND TRUNC(p_creation_date)
               BETWEEN TRUNC(r.start_date)
                       AND nvl(TRUNC(r.end_date), TRUNC(p_creation_date))
             AND p_postal_code BETWEEN r.from_postal_code AND r.to_postal_code
             ;
Line: 1555

        select
        rtrim(substr(l_struct,1,instr(l_struct,'.')),'.'),ltrim(substr(l_struct,instr(l_struct,'.')),'.') into l_child,l_parent
        from dual;
Line: 1650

      SELECT decode(party.orig_system_reference,p_orig_system_party_ref,'','Y3,')
      FROM   hz_parties party
      WHERE  party.party_number = p_party_number;
Line: 1655

      SELECT decode(party.orig_system_reference,p_orig_system_customer_ref,'','Y3,')
      FROM   hz_parties party
      WHERE  party.party_number = p_party_number;
Line: 1660

      SELECT decode(NVL(i.orig_system_party_ref,i.orig_system_customer_ref),p_orig_system_party_ref,'','Y3,')
      FROM   ra_customers_interface_all i
      WHERE  i.party_number = p_party_number
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1667

      SELECT decode(NVL(i.orig_system_party_ref,i.orig_system_customer_ref),p_orig_system_customer_ref,'','Y3,')
      FROM   ra_customers_interface_all i
      WHERE  i.party_number = p_party_number
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1773

      SELECT decode(i.party_number,p_party_number,'','Y4,')
      FROM   ra_customers_interface_all i
      WHERE  i.orig_system_party_ref = p_orig_system_party_ref
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1780

      SELECT decode(i.party_number,p_party_number,'','Y4,')
      FROM   ra_customers_interface_all i
      WHERE  i.orig_system_customer_ref = p_orig_system_party_ref
      AND    i.orig_system_party_ref is null
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1788

      SELECT decode(i.party_number,p_party_number,'','Y4,')
      FROM   ra_customers_interface_all i
      WHERE  i.orig_system_party_ref = p_orig_system_customer_ref
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1795

      SELECT decode(i.party_number,p_party_number,'','Y4,')
      FROM   ra_customers_interface_all i
      WHERE  i.orig_system_customer_ref = p_orig_system_customer_ref
      AND    i.orig_system_party_ref is null
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1900

      SELECT decode(cust.orig_system_reference,p_orig_system_customer_ref,'','A5,')
      FROM   hz_cust_accounts cust
      WHERE  cust.account_number = p_customer_number;
Line: 1905

      SELECT decode(i.orig_system_customer_ref,p_orig_system_customer_ref,'','A5,')
      FROM   ra_customers_interface_all i
      WHERE  i.customer_number = p_customer_number
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 1981

      SELECT decode(cust_site.orig_system_reference,p_orig_system_address_ref,'','Y6,')
      FROM   hz_party_sites site, hz_cust_acct_sites_all cust_site -- bug 4454799
      WHERE  site.party_site_number = p_party_site_number
      AND    cust_site.org_id = p_org_id  -- bug 4454799
      AND    site.party_site_id = cust_site.party_site_id;
Line: 1988

      SELECT decode(i.orig_system_address_ref,p_orig_system_address_ref,'','Y6,')
      FROM   ra_customers_interface_all i
      WHERE  i.party_site_number = p_party_site_number
      AND    i.org_id = p_org_id  -- bug 4454799
      AND    i.request_id = req_id
      AND    i.rowid <> p_rowid ;
Line: 2084

      SELECT  loc.location_id,loc.country,loc.city, loc.state,
              loc.county, loc.province, loc.postal_code
      FROM    hz_cust_acct_sites_all cs, -- bug 4454799
              hz_party_sites         ps,
              hz_locations           loc
      WHERE   cs.orig_system_reference   =  p_orig_system_address_ref
      AND     cs.org_id			 =  p_org_id  -- bug 4454799
      AND     ps.party_site_id           =  cs.party_site_id
      AND     ps.location_id             =  loc.location_id;
Line: 2105

              SELECT  'Y'
              INTO    l_loc_assignment_exist
              FROM    DUAL
              WHERE   EXISTS (SELECT  1
                               FROM    hz_loc_assignments la
                               WHERE   la.location_id = l_location_id
                            );
Line: 2112

              SELECT  'Y'
              INTO    l_is_remit_to_location
              FROM    DUAL
              WHERE   EXISTS (SELECT  1
                               FROM    hz_party_sites ps
                               WHERE   ps.location_id = l_location_id
                               AND     ps.party_id = -1
                            );
Line: 2175

  g_last_update_login := hz_utility_v2pub.last_update_login;
Line: 2176

  g_last_updated_by := hz_utility_v2pub.last_updated_by;
Line: 2184

 |    update_exception_table
 |
 | DESCRIPTION
 |    Update win source exception table when mix-n-match is seted up.
 |
 | SCOPE - PRIVATE
 |
 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED
 |
 | ARGUMENTS  : IN:
 |                   p_i_party_id
 |                   p_entity_attr_id
 |                   p_value
 |                   p_ue_ranking
 |                   p_sst_is_null
 |              OUT:
 |          IN/ OUT:
 | NOTES
 |
 | MODIFICATION HISTORY
 |
 |    Jianying Huang     07/12/2002        Bug No : 2460837. Created.
 |
 +===========================================================================*/

PROCEDURE update_exception_table (
  p_i_party_id                       IN     t_id,
  p_entity_attr_id                   IN     NUMBER,
  p_value                            IN     t_varchar500,
  p_ue_ranking                       IN     NUMBER,
  p_sst_is_null                      IN     t_flag
) IS
  i_party_id                         t_id := t_id();
Line: 2234

        DELETE hz_win_source_exceps
        WHERE party_id = i_party_id(i)
        AND entity_attr_id = p_entity_attr_id;
Line: 2239

        UPDATE hz_win_source_exceps exp
        SET content_source_type = 'USER_ENTERED',
            exception_type = (
              SELECT DECODE(sign(s.ranking-p_ue_ranking), 0, exp.exception_type,
                            1, 'Migration', -1, 'Exception')
              FROM hz_select_data_sources s
              WHERE entity_attr_id = p_entity_attr_id
              AND content_source_type = exp.content_source_type),
            last_updated_by = g_last_updated_by,
            last_update_login = g_last_update_login,
            last_update_date = SYSDATE,
            request_id = g_request_id,
            program_application_id = g_program_application_id,
            program_id = g_program_id,
            program_update_date = SYSDATE
        WHERE party_id = i_party_id(i)
        AND entity_attr_id = p_entity_attr_id;
Line: 2258

        INSERT INTO hz_win_source_exceps (
            party_id,
            entity_attr_id,
            content_source_type,
            exception_type,
            created_by,
            creation_date,
            last_update_login,
            last_update_date,
            last_updated_by,
            request_id,
            program_application_id,
            program_id,
            program_update_date
        ) SELECT
            i_party_id(i),
            p_entity_attr_id,
            'USER_ENTERED',
            decode(i_flag(i), '', 'Migration', 'Exception'),
            g_created_by,
            SYSDATE,
            g_last_update_login,
            SYSDATE,
            g_last_updated_by,
            g_request_id,
            g_program_application_id,
            g_program_id,
            SYSDATE
          FROM dual
          WHERE NOT EXISTS (
            SELECT 'Y'
            FROM hz_win_source_exceps
            WHERE party_id = i_party_id(i)
            AND entity_attr_id = p_entity_attr_id );
Line: 2293

END update_exception_table;
Line: 2297

 |    update_org_ue_profile
 |
 | DESCRIPTION
 |    The procedure will be called in racudc.lpc to sync. user-entered profile
 |    and sst profile when mix-n-match is seted up.
 |
 | SCOPE - PUBLIC
 |
 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED
 |
 | ARGUMENTS  : IN:
 |                   p_request_id
 |              OUT:
 |          IN/ OUT:
 | NOTES
 |
 | MODIFICATION HISTORY
 |
 |    Jianying Huang     07/12/2002        Bug No : 2460837. Created.
 |    Sisir		 05/07/2003	   Bug No : 2970763;Before create/update
Line: 2319

 |					   insert/update clause.
 +===========================================================================*/

PROCEDURE update_org_ue_profile (
    p_request_id                    IN     NUMBER
) IS

    -- The cursor is used to select interface related value for user-entered
    -- profile.
    CURSOR c_entity IS
      SELECT /* decode(trunc(org.effective_start_date),trunc(sysdate),'U','C') create_update_flag,*/
      	     decode(fnd_profile.value ('HZ_PROFILE_VERSION'),'NEW_VERSION','C','NO_VERSION','U',
	     	decode(trunc(org.effective_start_date),trunc(sysdate),'U','C')) create_update_flag,
             org.organization_profile_id,
             org.party_id,
             -- User NVL for bug 1404725. We do not need NVL on
             -- customer name because it is a not-null column.
             -- However, for some reason we did not do NVL on
             -- customer name phonetic. Please see racudc.lpc.
             -- If we decide to do NVL on phoneic also, we need
             -- to modify both racudc.lpc and this procedure.
             -- By selecting non-NVL value here is to differentiate
             -- when customer is updating the column by passing
             -- value and when he/she does not want to update the
             -- column by setting the column to null. This information
             -- will be used when update data source exception table.
             nvl(i.jgzz_fiscal_code, org.jgzz_fiscal_code),
             i.jgzz_fiscal_code,
             decode(sst.jgzz_fiscal_code, '', 'Y', 'N'),
             i.customer_name,
             decode(sst.organization_name, '', 'Y', 'N'),
             i.customer_name_phonetic,
             decode(sst.organization_name_phonetic, '', 'Y', 'N'),
             nvl(i.cust_tax_reference, org.tax_reference),
             i.cust_tax_reference,
             decode(sst.tax_reference, '', 'Y', 'N'),nvl(org.version_number,1)+1
      FROM hz_organization_profiles org,
           hz_organization_profiles sst,
           ra_customers_interface_all i, -- Bug 4956131
           hz_cust_accounts cust,
           (SELECT min(i1.rowid) myrowid
            FROM ra_customers_interface_all i1 -- Bug 4956131
            WHERE i1.request_id = p_request_id
            AND i1.interface_status IS NULL
            AND i1.insert_update_flag='U'
            AND NVL(i1.person_flag,'N') = 'N'
            GROUP BY i1.orig_system_customer_ref) temp
      WHERE i.rowid = temp.myrowid
      AND i.request_id = p_request_id
      AND i.orig_system_customer_ref = cust.orig_system_reference
      AND cust.party_id = org.party_id
      AND org.effective_end_date is null
      AND org.actual_content_source = 'USER_ENTERED'
      AND sst.party_id = org.party_id
      AND sst.effective_end_date is null
      AND sst.actual_content_source = 'SST'
      ORDER BY create_update_flag;
Line: 2377

    i_create_update_flag               t_flag;
Line: 2406

      SELECT s.entity_attr_id, s.ranking
      FROM hz_entity_attributes e,
           hz_select_data_sources s
      WHERE e.attribute_name = UPPER(p_attribute_name)
      AND e.entity_attr_id = s.entity_attr_id
      AND s.content_source_type = 'USER_ENTERED';
Line: 2418

    update_start                       NUMBER := 0;
Line: 2419

    update_end                         NUMBER := 0;
Line: 2445

        i_create_update_flag,
        i_ue_profile_id,
        i_party_id,
        i_jgzz_fiscal_code,
        i1_jgzz_fiscal_code,
        ss_jgzz_fiscal_code,
        i_organization_name,
        ss_organization_name,
        i_organization_name_phonetic,
        ss_organization_name_phonetic,
        i_tax_reference,
        i1_tax_reference,
        ss_tax_reference,
	i_version_number LIMIT rows;
Line: 2476

      update_start := 0;  update_end := -1;
Line: 2479

        IF i_create_update_flag(i) = 'C' THEN
          IF create_start = 0 THEN create_start := i; END IF;
Line: 2482

          IF update_start = 0 THEN
            update_start := i;
Line: 2490

      IF update_start > 0 AND update_end = -1 THEN update_end := subtotal; END IF;
Line: 2495

        UPDATE hz_organization_profiles
        SET effective_end_date = decode(trunc(effective_start_date),trunc(sysdate),trunc(sysdate),TRUNC(SYSDATE-1))
        WHERE organization_profile_id = i_ue_profile_id(i);
Line: 2502

        INSERT INTO hz_organization_profiles (
          created_by,
          creation_date,
          last_update_login,
          last_update_date,
          last_updated_by,
          request_id,
          program_application_id,
          program_id,
          program_update_date,
          content_source_type,
          actual_content_source,
          created_by_module,
          application_id,
          organization_profile_id,
          party_id,
          effective_start_date,
          object_version_number,
          jgzz_fiscal_code,
          organization_name,
          organization_name_phonetic,
          tax_reference,
	  version_number
        ) VALUES (
          g_created_by,
          SYSDATE,
          g_last_update_login,
          SYSDATE,
          g_last_updated_by,
          g_request_id,
          g_program_application_id,
          g_program_id,
          SYSDATE,
          'USER_ENTERED',
          'USER_ENTERED',
          'TCA-CUSTOMER-INTERFACE',
          222,
          hz_organization_profiles_s.nextval,
          i_party_id(i),
          SYSDATE,
          1,
          i_jgzz_fiscal_code(i),
          i_organization_name(i),
          i_organization_name_phonetic(i),
          i_tax_reference(i),
	  i_version_number(i)
      );
Line: 2552

      FORALL i IN update_start..update_end
        UPDATE hz_organization_profiles
        SET
          last_updated_by = g_last_updated_by,
          last_update_login = g_last_update_login,
          last_update_date = SYSDATE,
          request_id = g_request_id,
          program_application_id = g_program_application_id,
          program_id = g_program_id,
          program_update_date = SYSDATE,
          jgzz_fiscal_code = i_jgzz_fiscal_code(i),
          organization_name = i_organization_name(i),
          organization_name_phonetic = i_organization_name_phonetic(i),
          tax_reference = i_tax_reference(i),
	  version_number = nvl(version_number,1)+1
      WHERE organization_profile_id = i_ue_profile_id(i);
Line: 2573

        update_exception_table(i_party_id,id_jgzz_fiscal_code,i1_jgzz_fiscal_code,rk_jgzz_fiscal_code,ss_jgzz_fiscal_code);
Line: 2581

        update_exception_table(i_party_id,id_organization_name,i_organization_name,rk_organization_name,ss_organization_name);
Line: 2589

        update_exception_table(i_party_id,id_organization_name_phonetic,i_organization_name_phonetic,rk_organization_name_phonetic,ss_organization_name_phonetic);
Line: 2597

        update_exception_table(i_party_id,id_tax_reference,i1_tax_reference,rk_tax_reference,ss_tax_reference);
Line: 2610

END update_org_ue_profile;
Line: 2614

 |    update_per_ue_profile
 |
 | DESCRIPTION
 |    The procedure will be called in racudc.lpc to sync. user-entered profile
 |    and sst profile when mix-n-match is seted up.
 |
 | SCOPE - PUBLIC
 |
 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED
 |
 | ARGUMENTS  : IN:
 |                   p_request_id
 |              OUT:
 |          IN/ OUT:
 | NOTES
 |
 | MODIFICATION HISTORY
 |
 |    Jianying Huang     07/12/2002        Bug No : 2460837. Created.
 |    Sisir		 06/09/2003	   Bug No : 2970763 Added additional
 |					   clause of hz_profile_version in decode
 |					   stmt and also added version_number
 |					   column in the select clause.
 +===========================================================================*/

PROCEDURE update_per_ue_profile (
    p_request_id                    IN     NUMBER
) IS

    -- The cursor is used to select interface related value for user-entered
    -- profile.
    CURSOR c_entity IS
      SELECT /* decode(trunc(per.effective_start_date),trunc(sysdate),'U','C') create_update_flag, */
      	     decode(fnd_profile.value ('HZ_PROFILE_VERSION'),'NEW_VERSION','C','NO_VERSION','U',
	     	decode(trunc(per.effective_start_date),trunc(sysdate),'U','C')) create_update_flag,
             per.person_profile_id,
             per.party_id,
             -- User NVL for bug 1404725 when we have to take
             -- value from hz_person_profiles. By selecting
             -- non-NVL value here is to differentiate when
             -- customer is updating the column by passing value
             -- and when he/she does not want to update the column
             -- by setting the column to null. This information
             -- will be used when update data source exception table.
             nvl(i.jgzz_fiscal_code, per.jgzz_fiscal_code),
             i.jgzz_fiscal_code,
             decode(sst.jgzz_fiscal_code, '', 'Y', 'N'),
             i.customer_name,
             decode(sst.person_name, '', 'Y', 'N'),
             decode(i.person_first_name,'',decode(i.person_last_name,'',substrb(i.customer_name,1,150),''),i.person_first_name),
             decode(sst.person_first_name, '', 'Y', 'N'),
             nvl(i.person_last_name, per.person_last_name),
             i.person_last_name,
             decode(sst.person_last_name, '', 'Y', 'N'),
             nvl(i.customer_name_phonetic, per.person_name_phonetic),
             i.customer_name_phonetic,
             decode(sst.person_name_phonetic, '', 'Y', 'N'),
             decode(nvl(i.person_flag,'N'),'Y',i.customer_name_phonetic,''),
             decode(sst.person_first_name_phonetic, '', 'Y', 'N'),
             decode(nvl(i.person_flag,'N'),'Y',i.customer_name_phonetic,''),
             decode(sst.person_last_name_phonetic, '', 'Y', 'N'),
             nvl(i.cust_tax_reference, per.tax_reference),
             i.cust_tax_reference,
             decode(sst.tax_reference, '', 'Y', 'N'),nvl(per.version_number,1)+1
      FROM hz_person_profiles per,
           hz_person_profiles sst,
           ra_customers_interface_all i, -- Bug 4956131
           hz_cust_accounts cust,
           (SELECT min(i1.rowid) myrowid
            FROM ra_customers_interface_all i1 -- Bug 4956131
            WHERE i1.request_id = p_request_id
            AND i1.interface_status IS NULL
            AND i1.insert_update_flag='U'
            AND i1.person_flag = 'Y'
            GROUP BY i1.orig_system_customer_ref) temp
      WHERE i.rowid = temp.myrowid
      AND i.request_id = p_request_id
      AND i.orig_system_customer_ref = cust.orig_system_reference
      AND cust.party_id = per.party_id
      AND per.effective_end_date is null
      AND per.actual_content_source = 'USER_ENTERED'
      AND sst.party_id = per.party_id
      AND sst.effective_end_date is null
      AND sst.actual_content_source = 'SST'
      ORDER BY create_update_flag;
Line: 2700

    i_create_update_flag               t_flag;
Line: 2747

      SELECT s.entity_attr_id, s.ranking
      FROM hz_entity_attributes e,
           hz_select_data_sources s
      WHERE e.attribute_name = UPPER(p_attribute_name)
      AND e.entity_attr_id = s.entity_attr_id
      AND s.content_source_type = 'USER_ENTERED';
Line: 2759

    update_start                       NUMBER := 0;
Line: 2760

    update_end                         NUMBER := 0;
Line: 2786

        i_create_update_flag,
        i_ue_profile_id,
        i_party_id,
        i_jgzz_fiscal_code,
        i1_jgzz_fiscal_code,
        ss_jgzz_fiscal_code,
        i_person_name,
        ss_person_name,
        i_person_first_name,
        ss_person_first_name,
        i_person_last_name,
        i1_person_last_name,
        ss_person_last_name,
        i_person_name_phonetic,
        i1_person_name_phonetic,
        ss_person_name_phonetic,
        i_person_first_name_phonetic,
        ss_person_first_name_phonetic,
        i_person_last_name_phonetic,
        ss_person_last_name_phonetic,
        i_tax_reference,
        i1_tax_reference,
        ss_tax_reference,
	i_version_number LIMIT rows;
Line: 2827

      update_start := 0;  update_end := -1;
Line: 2830

        IF i_create_update_flag(i) = 'C' THEN
          IF create_start = 0 THEN create_start := i; END IF;
Line: 2833

          IF update_start = 0 THEN
            update_start := i;
Line: 2841

      IF update_start > 0 AND update_end = -1 THEN update_end := subtotal; END IF;
Line: 2846

        UPDATE hz_person_profiles
        SET effective_end_date = decode(trunc(effective_start_date),trunc(sysdate),trunc(sysdate),TRUNC(SYSDATE-1))
        WHERE person_profile_id = i_ue_profile_id(i);
Line: 2853

        INSERT INTO hz_person_profiles (
          created_by,
          creation_date,
          last_update_login,
          last_update_date,
          last_updated_by,
          request_id,
          program_application_id,
          program_id,
          program_update_date,
          content_source_type,
          actual_content_source,
          created_by_module,
          application_id,
          person_profile_id,
          party_id,
          effective_start_date,
          object_version_number,
          jgzz_fiscal_code,
          person_name,
          person_first_name,
          person_last_name,
          person_name_phonetic,
          person_first_name_phonetic,
          person_last_name_phonetic,
          tax_reference,
	  version_number
        ) VALUES (
          g_created_by,
          SYSDATE,
          g_last_update_login,
          SYSDATE,
          g_last_updated_by,
          g_request_id,
          g_program_application_id,
          g_program_id,
          SYSDATE,
          'USER_ENTERED',
          'USER_ENTERED',
          'TCA-CUSTOMER-INTERFACE',
          222,
          hz_person_profiles_s.nextval,
          i_party_id(i),
          SYSDATE,
          1,
          i_jgzz_fiscal_code(i),
          i_person_name(i),
          i_person_first_name(i),
          i_person_last_name(i),
          i_person_name_phonetic(i),
          i_person_first_name_phonetic(i),
          i_person_last_name_phonetic(i),
          i_tax_reference(i),
	  i_version_number(i)
      );
Line: 2911

      FORALL i IN update_start..update_end
        UPDATE hz_person_profiles
        SET
          last_updated_by = g_last_updated_by,
          last_update_login = g_last_update_login,
          last_update_date = SYSDATE,
          request_id = g_request_id,
          program_application_id = g_program_application_id,
          program_id = g_program_id,
          program_update_date = SYSDATE,
          jgzz_fiscal_code = i_jgzz_fiscal_code(i),
          person_name = i_person_name(i),
          person_first_name = i_person_first_name(i),
          person_last_name = i_person_last_name(i),
          person_name_phonetic = i_person_name_phonetic(i),
          person_first_name_phonetic = i_person_first_name_phonetic(i),
          person_last_name_phonetic = i_person_last_name_phonetic(i),
          tax_reference = i_tax_reference(i),
	  version_number = nvl(version_number,1)+1
      WHERE person_profile_id = i_ue_profile_id(i);
Line: 2936

        update_exception_table(i_party_id,id_jgzz_fiscal_code,i1_jgzz_fiscal_code,rk_jgzz_fiscal_code,ss_jgzz_fiscal_code);
Line: 2944

        update_exception_table(i_party_id,id_person_name,i_person_name,rk_person_name,ss_person_name);
Line: 2952

        update_exception_table(i_party_id,id_person_first_name,i_person_first_name,rk_person_first_name,ss_person_first_name);
Line: 2960

        update_exception_table(i_party_id,id_person_last_name,i1_person_last_name,rk_person_last_name,ss_person_last_name);
Line: 2968

        update_exception_table(i_party_id,id_person_name_phonetic,i1_person_name_phonetic,rk_person_name_phonetic,ss_person_name_phonetic);
Line: 2976

        update_exception_table(i_party_id,id_person_first_name_phonetic,i_person_first_name_phonetic,rk_person_first_name_phonetic,ss_person_first_name_phonetic);
Line: 2984

        update_exception_table(i_party_id,id_person_last_name_phonetic,i_person_last_name_phonetic,rk_person_last_name_phonetic,ss_person_last_name_phonetic);
Line: 2992

        update_exception_table(i_party_id,id_tax_reference,i1_tax_reference,rk_tax_reference,ss_tax_reference);
Line: 3005

END update_per_ue_profile;
Line: 3043

SELECT su.primary_flag
FROM hz_cust_accounts cust,
     hz_cust_acct_sites_all site, -- bug 4454799
     hz_cust_site_uses_all su  -- bug 4454799
WHERE cust.orig_system_reference = p_orig_system_customer_ref
and  cust.cust_account_id = site.cust_account_id
and  site.cust_acct_site_id = su.cust_acct_site_id
and  site.org_id = p_org_id  -- bug 4454799
and  site.org_id = su.org_id -- bug 4454799
and  su.site_use_code in ('STMTS','DUN','LEGAL')
and  su.site_use_code = p_site_use_code
and  su.status = 'A'
and  rownum = 1;
Line: 3100

SELECT site.cust_acct_site_id,suse.site_use_id
FROM   hz_cust_accounts       cust,
       hz_cust_acct_sites_all site,
       hz_cust_site_uses_all  suse
WHERE  cust.orig_system_reference = p_orig_system_customer_ref
and    cust.cust_account_id   = site.cust_account_id
and    site.cust_acct_site_id = suse.cust_acct_site_id
and    site.org_id = p_org_id  -- bug 4454799
and    site.org_id = suse.org_id -- bug 4454799
and    suse.site_use_code = p_site_use_code
and    suse.status = 'A'
and    suse.primary_flag = 'Y'
and    rownum = 1;
Line: 3118

      update hz_cust_site_uses_all
      set    primary_flag           = 'N',
             last_update_login      = hz_utility_v2pub.last_update_login,
             last_update_date       = SYSDATE,
             last_updated_by        = hz_utility_v2pub.last_updated_by,
             request_id             = hz_utility_v2pub.request_id,
             program_application_id = hz_utility_v2pub.program_application_id,
             program_id             = hz_utility_v2pub.program_id
      where  site_use_id = l_site_use_id;
Line: 3128

      update hz_cust_acct_sites_all
      set    BILL_TO_FLAG = decode(p_site_use_code,'BILL_TO','Y',BILL_TO_FLAG),
             SHIP_TO_FLAG = decode(p_site_use_code,'SHIP_TO','Y',SHIP_TO_FLAG),
             MARKET_FLAG  = decode(p_site_use_code,'MARKET','Y',MARKET_FLAG),
             last_update_login      = hz_utility_v2pub.last_update_login,
             last_update_date       = SYSDATE,
             last_updated_by        = hz_utility_v2pub.last_updated_by,
             request_id             = hz_utility_v2pub.request_id,
             program_application_id = hz_utility_v2pub.program_application_id,
             program_id             = hz_utility_v2pub.program_id
      where  cust_acct_site_id = l_acct_site_id;
Line: 3159

       (SELECT  'THIRD_PARTY' PARTY_TYPE_CODE,
                party.party_id PARTY_ID,
                party.country COUNTRY_CODE, --4742586
                FND_GLOBAL.Login_ID PROGRAM_LOGIN_ID ,
                party.tax_reference TAX_REFERENCE,
                SYSDATE CREATION_DATE,
                FND_GLOBAL.User_ID CREATED_BY,
                SYSDATE LAST_UPDATE_DATE,
                FND_GLOBAL.User_ID LAST_UPDATED_BY,
                FND_GLOBAL.Login_ID LAST_UPDATE_LOGIN
        FROM	HZ_PARTIES party, ra_customers_interface_all rci -- Bug 4956131
        WHERE   party.orig_system_reference = nvl(rci.orig_system_party_ref, rci.orig_system_customer_ref)
      	AND     party.request_id =  p_request_id
      	AND     rci.interface_status is null
        AND     rci.request_id = p_request_id
        AND     rci.insert_update_flag  = 'I'
	AND 	(rci.rowid = (  SELECT min(i2.rowid)
                                FROM   ra_customers_interface_all i2 -- Bug 4956131
                                WHERE  i2.orig_system_customer_ref = rci.orig_system_customer_ref
	                        AND    rci.orig_system_party_ref is null
                                AND    i2.interface_status is null
                                AND    i2.request_id = p_request_id
                                AND    i2.insert_update_flag = 'I') OR
                 rci.rowid = (  SELECT min(i2.rowid)
                                FROM   ra_customers_interface_all i2 -- Bug 4956131
                                WHERE  i2.orig_system_party_ref = rci.orig_system_party_ref
                                AND    i2.interface_status is null
                                AND    i2.request_id = p_request_id
                                AND    i2.insert_update_flag = 'I'))
        AND      (party.party_type ='ORGANIZATION' OR party.party_type ='PERSON')) PTY
   ON  (PTY.PARTY_ID = PTP.PARTY_ID AND PTP.PARTY_TYPE_CODE = 'THIRD_PARTY')
   WHEN MATCHED THEN
        UPDATE SET
        PTP.REP_REGISTRATION_NUMBER = PTY.TAX_REFERENCE,
        PTP.LAST_UPDATE_DATE=PTY.LAST_UPDATE_DATE,
        PTP.LAST_UPDATED_BY=PTY.LAST_UPDATED_BY,
        PTP.LAST_UPDATE_LOGIN=PTY.LAST_UPDATE_LOGIN,
        PTP.PROGRAM_ID = hz_utility_v2pub.program_id,
        PTP.PROGRAM_APPLICATION_ID = hz_utility_v2pub.program_application_id,
        PTP.REQUEST_ID = p_request_id,
        PTP.OBJECT_VERSION_NUMBER = PTP.OBJECT_VERSION_NUMBER +1
   WHEN NOT MATCHED THEN
        INSERT (PARTY_TYPE_CODE,
                PARTY_TAX_PROFILE_ID,
                PARTY_ID,
                PROGRAM_LOGIN_ID,
                REP_REGISTRATION_NUMBER,
                CREATION_DATE,
                CREATED_BY,
                LAST_UPDATE_DATE,
                LAST_UPDATED_BY,
                LAST_UPDATE_LOGIN,
                PROGRAM_ID,
                PROGRAM_APPLICATION_ID,
                REQUEST_ID,
                OBJECT_VERSION_NUMBER,
                COUNTRY_CODE)--4742586
        VALUES (PTY.PARTY_TYPE_CODE,
                ZX_PARTY_TAX_PROFILE_S.NEXTVAL,
                PTY.PARTY_ID,
                PTY.PROGRAM_LOGIN_ID,
                PTY.TAX_REFERENCE,
                PTY.CREATION_DATE,
                PTY.CREATED_BY,
                PTY.LAST_UPDATE_DATE,
                PTY.LAST_UPDATED_BY,
                PTY.LAST_UPDATE_LOGIN,
                hz_utility_v2pub.program_id,
                hz_utility_v2pub.program_application_id,
                p_request_id,
                1,
                PTY.COUNTRY_CODE );--4742586
Line: 3236

       (SELECT  'THIRD_PARTY' PARTY_TYPE_CODE,
                party.party_id PARTY_ID,
                party.country COUNTRY_CODE,
                FND_GLOBAL.Login_ID PROGRAM_LOGIN_ID ,
                party.tax_reference TAX_REFERENCE,
                SYSDATE CREATION_DATE,
                FND_GLOBAL.User_ID CREATED_BY,
                SYSDATE LAST_UPDATE_DATE,
                FND_GLOBAL.User_ID LAST_UPDATED_BY,
                FND_GLOBAL.Login_ID LAST_UPDATE_LOGIN
        FROM    HZ_PARTIES party, RA_CONTACT_PHONES_INT_ALL rcpi
        WHERE   party.orig_system_reference =  rcpi.orig_system_contact_ref
        AND     party.request_id =  p_request_id
        AND     rcpi.interface_status is null
        AND     rcpi.request_id = p_request_id
        AND     rcpi.insert_update_flag  = 'I'
        AND     rcpi.rowid = (  SELECT min(i2.rowid)
                                FROM   RA_CONTACT_PHONES_INT_ALL i2
                                WHERE  i2.orig_system_contact_ref = rcpi.orig_system_contact_ref
                                AND    i2.interface_status is null
                                AND    i2.request_id = p_request_id
                                AND    i2.insert_update_flag = 'I')
        AND      party.party_type ='PERSON') PTY
   ON  (PTY.PARTY_ID = PTP.PARTY_ID AND PTP.PARTY_TYPE_CODE = 'THIRD_PARTY')
   WHEN MATCHED THEN
        UPDATE SET
        PTP.REP_REGISTRATION_NUMBER = PTY.TAX_REFERENCE,
        PTP.LAST_UPDATE_DATE=PTY.LAST_UPDATE_DATE,
        PTP.LAST_UPDATED_BY=PTY.LAST_UPDATED_BY,
        PTP.LAST_UPDATE_LOGIN=PTY.LAST_UPDATE_LOGIN,
        PTP.PROGRAM_ID = hz_utility_v2pub.program_id,
        PTP.PROGRAM_APPLICATION_ID = hz_utility_v2pub.program_application_id,
        PTP.REQUEST_ID = p_request_id,
        PTP.OBJECT_VERSION_NUMBER = PTP.OBJECT_VERSION_NUMBER +1
   WHEN NOT MATCHED THEN
        INSERT (PARTY_TYPE_CODE,
                PARTY_TAX_PROFILE_ID,
                PARTY_ID,
                PROGRAM_LOGIN_ID,
                REP_REGISTRATION_NUMBER,
                CREATION_DATE,
                CREATED_BY,
                LAST_UPDATE_DATE,
                LAST_UPDATED_BY,
                LAST_UPDATE_LOGIN,
                PROGRAM_ID,
          	PROGRAM_APPLICATION_ID,
                REQUEST_ID,
                OBJECT_VERSION_NUMBER,
                COUNTRY_CODE)
        VALUES (PTY.PARTY_TYPE_CODE,
                ZX_PARTY_TAX_PROFILE_S.NEXTVAL,
                PTY.PARTY_ID,
                PTY.PROGRAM_LOGIN_ID,
                PTY.TAX_REFERENCE,
                PTY.CREATION_DATE,
                PTY.CREATED_BY,
                PTY.LAST_UPDATE_DATE,
                PTY.LAST_UPDATED_BY,
                PTY.LAST_UPDATE_LOGIN,
                hz_utility_v2pub.program_id,
         	hz_utility_v2pub.program_application_id,
                p_request_id,
                1,
                PTY.COUNTRY_CODE );
Line: 3307

       (SELECT  'THIRD_PARTY_SITE' PARTY_TYPE_CODE,
                ps.party_site_id PARTY_ID,
                loc.country COUNTRY_CODE,--4742586
                FND_GLOBAL.Login_ID PROGRAM_LOGIN_ID ,
                NULL TAX_REFERENCE,
                SYSDATE CREATION_DATE,
                FND_GLOBAL.User_ID CREATED_BY,
                SYSDATE LAST_UPDATE_DATE,
                FND_GLOBAL.User_ID LAST_UPDATED_BY,
                FND_GLOBAL.Login_ID LAST_UPDATE_LOGIN
        FROM    HZ_PARTY_SITES ps, ra_customers_interface_all rci, -- Bug 4956131
                HZ_LOCATIONS loc --4742586
        WHERE   ps.orig_system_reference = rci.orig_system_address_ref
        AND     loc.location_id = ps.location_id --4742586
      	AND     ps.request_id =  p_request_id
      	AND     rci.interface_status is null
        AND     rci.request_id = p_request_id
        AND     rci.insert_update_flag  = 'I'
	AND 	(rci.rowid = (  SELECT min(i2.rowid)
                                FROM   ra_customers_interface_all i2 -- Bug 4956131
                                WHERE  i2.orig_system_address_ref = rci.orig_system_address_ref
                                AND    i2.interface_status is null
                                AND    i2.request_id = p_request_id
                                AND    i2.insert_update_flag = 'I'))) PTY
  ON  (PTY.PARTY_ID = PTP.PARTY_ID AND PTP.PARTY_TYPE_CODE = 'THIRD_PARTY_SITE')
  WHEN MATCHED THEN
       UPDATE SET
        PTP.LAST_UPDATE_DATE=PTY.LAST_UPDATE_DATE,
        PTP.LAST_UPDATED_BY=PTY.LAST_UPDATED_BY,
        PTP.LAST_UPDATE_LOGIN=PTY.LAST_UPDATE_LOGIN,
        PTP.PROGRAM_ID = hz_utility_v2pub.program_id,
        PTP.PROGRAM_APPLICATION_ID = hz_utility_v2pub.program_application_id,
        PTP.REQUEST_ID = p_request_id,
        PTP.OBJECT_VERSION_NUMBER = PTP.OBJECT_VERSION_NUMBER +1
  WHEN NOT MATCHED THEN
       INSERT (
        PARTY_TYPE_CODE,
        PARTY_TAX_PROFILE_ID,
        PARTY_ID,
        PROGRAM_LOGIN_ID,
        REP_REGISTRATION_NUMBER,
        CREATION_DATE,
        CREATED_BY,
        LAST_UPDATE_DATE,
        LAST_UPDATED_BY,
        LAST_UPDATE_LOGIN,
        PROGRAM_ID,
      	PROGRAM_APPLICATION_ID,
        REQUEST_ID,
        OBJECT_VERSION_NUMBER,
        COUNTRY_CODE)--4742586
       VALUES (
        PTY.PARTY_TYPE_CODE,
        ZX_PARTY_TAX_PROFILE_S.NEXTVAL,
        PTY.PARTY_ID,
        PTY.PROGRAM_LOGIN_ID,
        PTY.TAX_REFERENCE,
        PTY.CREATION_DATE,
        PTY.CREATED_BY,
        PTY.LAST_UPDATE_DATE,
        PTY.LAST_UPDATED_BY,
        PTY.LAST_UPDATE_LOGIN,
	hz_utility_v2pub.program_id,
	hz_utility_v2pub.program_application_id,
	p_request_id,
        1,
        PTY.COUNTRY_CODE);--4742586
Line: 3378

PROCEDURE insert_ci_party_usages
(
  p_request_id                    IN NUMBER
)
IS

BEGIN
INSERT INTO hz_party_usg_assignments(
              PARTY_USG_ASSIGNMENT_ID
             ,PARTY_ID
             ,PARTY_USAGE_CODE
             ,EFFECTIVE_START_DATE
             ,EFFECTIVE_END_DATE
             ,STATUS_FLAG
             ,COMMENTS
             ,OWNER_TABLE_NAME
             ,OWNER_TABLE_ID
             ,OBJECT_VERSION_NUMBER
             ,CREATED_BY_MODULE
             ,APPLICATION_ID
             ,CREATED_BY
             ,CREATION_DATE
             ,LAST_UPDATE_LOGIN
             ,LAST_UPDATE_DATE
             ,LAST_UPDATED_BY
             ,REQUEST_ID
             ,PROGRAM_APPLICATION_ID
             ,PROGRAM_ID )
    SELECT    hz_party_usg_assignments_s.nextval      -- PARTY_USG_ASSIGNMENT_ID
             ,hzp.party_id                            -- PARTY_ID
             ,'CUSTOMER'                              -- PARTY_USAGE_CODE
             ,trunc(SYSDATE)                          -- EFFECTIVE_START_DATE
             ,decode((select min(status)
                      from   hz_cust_accounts
                      where  party_id = hzp.party_id),
                      'A',to_date('31-12-4712','DD-MM-YYYY')
                          ,trunc(SYSDATE))            -- EFFECTIVE_END_DATE
             ,(select min(status)
                      from   hz_cust_accounts
                      where  party_id = hzp.party_id) -- STATUS_FLAG
             ,''                                      -- COMMENTS
             ,''                                      -- OWNER_TABLE_NAME
             ,''                                      -- OWNER_TABLE_ID
             ,1                                       -- OBJECT_VERSION_NUMBER
             ,'CUST_INTERFACE'                        -- CREATED_BY_MODULE
             ,''                                      -- APPLICATION_ID
             ,hz_utility_v2pub.created_by             -- CREATED_BY
             , SYSDATE                                -- CREATION_DATE
             ,hz_utility_v2pub.last_update_login      -- LAST_UPDATE_LOGIN
             , SYSDATE                                -- LAST_UPDATE_DATE
             ,hz_utility_v2pub.last_updated_by        -- LAST_UPDATED_BY
             ,p_request_id                            -- REQUEST_ID
             ,hz_utility_v2pub.program_application_id -- PROGRAM_APPLICATION_ID
             ,hz_utility_v2pub.program_id             -- PROGRAM_ID
    from     ra_customers_interface  rci,
             hz_parties              hzp
    WHERE    hzp.orig_system_reference    = nvl(rci.orig_system_party_ref, rci.orig_system_customer_ref)
    and      hzp.request_id               = p_request_id
    AND      rci.interface_status        is null
    AND      rci.insert_update_flag       = 'I'
    AND      ( rci.rowid = (SELECT   min(i2.rowid)
                              FROM   ra_customers_interface i2
                              WHERE  i2.orig_system_customer_ref =
                                     rci.orig_system_customer_ref
                              and    rci.orig_system_party_ref is null
                              AND    i2.interface_status is null
                              AND    i2.insert_update_flag = 'I') OR
               rci.rowid = (SELECT   min(i2.rowid)
                             FROM    ra_customers_interface i2
                             WHERE   i2.orig_system_party_ref = rci.orig_system_party_ref
                             AND     i2.interface_status is null
                             AND     i2.insert_update_flag = 'I')
             );
Line: 3452

END insert_ci_party_usages;
Line: 3454

PROCEDURE insert_nci_party_usages
(
  p_request_id                    IN NUMBER
)
IS

BEGIN
INSERT INTO hz_party_usg_assignments(
              PARTY_USG_ASSIGNMENT_ID
             ,PARTY_ID
             ,PARTY_USAGE_CODE
             ,EFFECTIVE_START_DATE
             ,EFFECTIVE_END_DATE
             ,STATUS_FLAG
             ,COMMENTS
             ,OWNER_TABLE_NAME
             ,OWNER_TABLE_ID
             ,OBJECT_VERSION_NUMBER
             ,CREATED_BY_MODULE
             ,APPLICATION_ID
             ,CREATED_BY
             ,CREATION_DATE
             ,LAST_UPDATE_LOGIN
             ,LAST_UPDATE_DATE
             ,LAST_UPDATED_BY
             ,REQUEST_ID
             ,PROGRAM_APPLICATION_ID
             ,PROGRAM_ID )
    SELECT    hz_party_usg_assignments_s.nextval     -- PARTY_USG_ASSIGNMENT_ID
             ,hzp.party_id                           -- PARTY_ID
             ,'CUSTOMER'                             -- PARTY_USAGE_CODE
             ,trunc(SYSDATE)                         -- EFFECTIVE_START_DATE
             ,decode((select min(status)
                      from   hz_cust_accounts
                      where  party_id = hzp.party_id),
                      'A',to_date('31-12-4712','DD-MM-YYYY')
                          ,trunc(SYSDATE))           -- EFFECTIVE_END_DATE
             ,(select min(status)
                      from   hz_cust_accounts
                      where  party_id = hzp.party_id)-- STATUS_FLAG
             ,''                                     -- COMMENTS
             ,''                                     -- OWNER_TABLE_NAME
             ,''                                     -- OWNER_TABLE_ID
             ,1                                      -- OBJECT_VERSION_NUMBER
             ,'CUST_INTERFACE'                       -- CREATED_BY_MODULE
             ,''                                     -- APPLICATION_ID
             ,hz_utility_v2pub.created_by            -- CREATED_BY
             , SYSDATE                               -- CREATION_DATE
             ,hz_utility_v2pub.last_update_login     -- LAST_UPDATE_LOGIN
             , SYSDATE                               -- LAST_UPDATE_DATE
             ,hz_utility_v2pub.last_updated_by       -- LAST_UPDATED_BY
             ,p_request_id                           -- REQUEST_ID
             ,hz_utility_v2pub.program_application_id-- PROGRAM_APPLICATION_ID
             ,hz_utility_v2pub.program_id            -- PROGRAM_ID
    from     ra_customers_interface_all  rci, -- Bug 4956131
             hz_parties              hzp
    WHERE    hzp.party_id            = HZ_CUSTOMER_INT.get_account_party_id(rci.orig_system_party_ref,rci.person_flag,'P')
    AND      rci.request_id          = p_request_id
    AND      rci.interface_status    is null
    AND      rci.insert_update_flag  = 'I'
    AND      ( rci.rowid = (SELECT  min(i2.rowid)
                              FROM  ra_customers_interface_all i2 -- Bug 4956131
                              WHERE i2.orig_system_customer_ref =
                                    rci.orig_system_customer_ref
                              and   rci.orig_system_party_ref is null
                              AND   i2.interface_status is null
                              AND    i2.request_id = p_request_id
                              AND   i2.insert_update_flag = 'I') OR
               rci.rowid = (SELECT  min(i2.rowid)
                             FROM   ra_customers_interface_all i2 -- Bug 4956131
                             WHERE  i2.orig_system_party_ref = rci.orig_system_party_ref
                             AND    i2.request_id = p_request_id
                             AND    i2.interface_status is null
                             AND    i2.insert_update_flag = 'I')
             )
    and     not exists(     SELECT  '1'
                            FROM    hz_parties
                            WHERE   party_id = hzp.party_id
                            AND     request_id = p_request_id )
    and     not exists(
            select '1'
            from    hz_party_usg_assignments pua
            where   pua.party_id = hzp.party_id
            and     party_usage_code = 'CUSTOMER'
            and     pua.status_flag = ( select min(status)
                                        from   hz_cust_accounts
                                        where  party_id = hzp.party_id)
            and     pua.effective_start_date <= decode((select min(status)
                                                        from   hz_cust_accounts
                                                        where  party_id = hzp.party_id),
                                                               'A',trunc(SYSDATE)
                                                               ,pua.effective_start_date)
            and     nvl(pua.effective_end_date,to_date('31-12-4712','DD-MM-YYYY')) >= decode((select min(status)
                                                        from   hz_cust_accounts
                                                        where  party_id = hzp.party_id),
                                                               'A',trunc(SYSDATE)
                                                               ,nvl(pua.effective_start_date,
                                                               to_date('31-12-4712','DD-MM-YYYY')
                                                                    )));
Line: 3553

END insert_nci_party_usages;