DBA Data[Home] [Help]

APPS.IEX_DUNNING_PVT SQL Statements

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

Line: 39

            select par_site.location_id
            from
                HZ_CUST_SITE_USES_ALL site_use,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                hz_party_sites par_site
            where
                site_use.site_use_id = P_SITE_USE_ID and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                par_site.party_site_id = acct_site.party_site_id;
Line: 109

            select
                decode(P_REL_TYPE, rel.relationship_type,
                        decode(point.contact_point_purpose,
                          'DUNNING', decode(point.primary_by_purpose, 'Y', 1, decode(point.primary_flag, 'Y', 2, 3
                                                                              )
                                     ), 4
                        ),
                        decode(point.contact_point_purpose,
                          'DUNNING', decode(point.primary_by_purpose, 'Y', 5, decode(point.primary_flag, 'Y', 6, 7
                                                                              )
                                     ), 8
                        )
                ) Display_Order,
                rel.party_id,
                rel.subject_id,
                point.contact_point_id,
                rel.relationship_type
            from HZ_RELATIONSHIPS rel,
                hz_contact_points point
            where rel.object_id = P_PARTY_ID and
                rel.relationship_type in ('DUNNING', 'COLLECTIONS') and
                rel.status = 'A' and
                rel.party_id = point.owner_table_ID and
                point.owner_table_name = 'HZ_PARTIES' and
                upper(point.contact_point_type) = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'PHONE', 'FAX', 'PHONE') and
                nvl(point.phone_line_type, 'EMAIL') = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'GEN', 'FAX', 'FAX') and
                NVL(point.do_not_use_flag, 'N') = 'N' and
                (point.status = 'A' OR point.status <> 'I')
            order by Display_Order;
Line: 141

            select
                decode(P_REL_TYPE, rel.relationship_type, 1, 2) Display_Order,
                rel.party_id,
                rel.subject_id,
                rel.relationship_type
            from HZ_RELATIONSHIPS rel
            where rel.object_id = P_PARTY_ID and
                rel.relationship_type in ('DUNNING', 'COLLECTIONS') and
                rel.status = 'A'
            order by Display_Order;
Line: 154

            select location_id
            from hz_party_sites
            where party_id = P_REL_PARTY_ID and
                status in ('A', 'I');
Line: 161

            select location_id
        --Start for bug 8771065 gnramasa 6th-Aug-09
        --    from ast_locations_v where party_site_id =
            from ast_locations_v where party_site_id in
            	(select party_site_id
        --		from hz_cust_acct_sites_all where cust_acct_site_id =
    		from hz_cust_acct_sites_all where cust_acct_site_id in
                          (select address_id
                           from ar_contacts_v where contact_party_id = P_CONTACT_ID
    		       AND address_id is not null
    		       AND status = 'A'));
Line: 177

            select location_id
            from ast_locations_v
            where party_id = P_ORG_PARTY_ID and
                primary_flag = 'Y';
Line: 359

            select
                decode(role_resp.responsibility_type,
                    'DUN', decode(role_resp.primary_flag, 'Y', 1, 2),
                    'BILL_TO', decode(role_resp.primary_flag, 'Y', 3, 4),
                    'INV', decode(role_resp.primary_flag, 'Y', 5, 6),
                    'SHIP_TO', decode(role_resp.primary_flag, 'Y', 7, 8), 9
                ) Display_Order,
                role_resp.responsibility_type,
                party.party_id,
                sub_party.party_id
            from
                HZ_CUST_SITE_USES_ALL site_use,
                HZ_CUST_ACCOUNT_ROLES acct_role,
                HZ_ROLE_RESPONSIBILITY role_resp,
                HZ_RELATIONSHIPS rel,
                hz_parties party,
                hz_parties sub_party
            where
                site_use.site_use_id = P_SITE_USE_ID and
                acct_role.cust_acct_site_id = site_use.cust_acct_site_id and
                acct_role.status = 'A' and
                role_resp.cust_account_role_id = acct_role.cust_account_role_id and
                acct_role.party_id = party.party_id and
                party.status = 'A' and
                rel.party_id = party.party_id and
                rel.subject_type = 'PERSON' and
                rel.status = 'A' and
                decode(rel.object_type, 'PERSON', rel.directional_flag, 1) = decode(rel.object_type, 'PERSON', 'F', 1) and
                sub_party.party_id = rel.subject_id and
                sub_party.status = 'A'
            order by Display_Order, sub_party.party_name;
Line: 393

            select
                decode(cont_point.contact_point_purpose,
                    'DUNNING', decode(cont_point.primary_flag, 'Y', 1, decode(cont_point.primary_by_purpose, 'Y', 2, 3)),
                    'COLLECTIONS', decode(cont_point.primary_flag, 'Y', 4, decode(cont_point.primary_by_purpose, 'Y', 5, 6)),
                    'BUSINESS', decode(cont_point.primary_flag, 'Y', 7, decode(cont_point.primary_by_purpose, 'Y', 8, 9)),
                    null, decode(cont_point.primary_flag, 'Y', 10, decode(cont_point.primary_by_purpose, 'Y', 11, 12))
                ) Display_Order
                ,cont_point.CONTACT_POINT_ID
            from hz_contact_points cont_point
            where
                cont_point.owner_table_id = P_PARTY_ID and
                cont_point.owner_table_name = 'HZ_PARTIES' and
                cont_point.contact_point_type = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'PHONE', 'FAX', 'PHONE') and
                nvl(cont_point.phone_line_type, 'EMAIL') = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'GEN', 'FAX', 'FAX') and
                NVL(cont_point.do_not_use_flag, 'N') = 'N' and
                (cont_point.status = 'A' OR cont_point.status <> 'I')
            order by Display_Order;
Line: 413

            select
                decode(cont_point.contact_point_purpose,
                    'DUNNING', decode(cont_point.primary_flag, 'Y', 1, decode(cont_point.primary_by_purpose, 'Y', 2, 3)),
                    'COLLECTIONS', decode(cont_point.primary_flag, 'Y', 4, decode(cont_point.primary_by_purpose, 'Y', 5, 6)),
                    'BUSINESS', decode(cont_point.primary_flag, 'Y', 7, decode(cont_point.primary_by_purpose, 'Y', 8, 9)),
                    null, decode(cont_point.primary_flag, 'Y', 10, decode(cont_point.primary_by_purpose, 'Y', 11, 12))
                ) Display_Order
                ,cont_point.CONTACT_POINT_ID
            from
                HZ_CUST_SITE_USES_ALL site_use,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                hz_contact_points cont_point
            where
                site_use.site_use_id = P_SITE_USE_ID and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                cont_point.owner_table_id = acct_site.party_site_id and
                cont_point.owner_table_name = 'HZ_PARTY_SITES' and
                cont_point.contact_point_type = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'PHONE', 'FAX', 'PHONE') and
                nvl(cont_point.phone_line_type, 'EMAIL') = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'GEN', 'FAX', 'FAX') and
                NVL(cont_point.do_not_use_flag, 'N') = 'N' and
                (cont_point.status = 'A' OR cont_point.status <> 'I')
            order by Display_Order;
Line: 438

            select par_site.location_id
            from
                HZ_CUST_SITE_USES_ALL site_use,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                hz_party_sites par_site
            where
                site_use.site_use_id = P_SITE_USE_ID and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                par_site.party_site_id = acct_site.party_site_id;
Line: 455

        l_dun_contact_level := nvl(fnd_profile.value('IEX_DUNNING_CONTACT_SELECTION_METHOD'), 'ALL');  --Added for bug 6500750 gnramasa 13-Nov-07
Line: 678

            select
                decode(role_resp.responsibility_type,
                    'DUN', decode(role_resp.primary_flag, 'Y', 1, 2),
                    'BILL_TO', decode(role_resp.primary_flag, 'Y', 3, 4),
                    'INV', decode(role_resp.primary_flag, 'Y', 5, 6),
                    'SHIP_TO', decode(role_resp.primary_flag, 'Y', 7, 8), 9
                ) Display_Order,
                role_resp.responsibility_type,
                party.party_id,
                sub_party.party_id,
                rel.object_id
            from
                HZ_CUST_ACCOUNT_ROLES acct_role,
                HZ_ROLE_RESPONSIBILITY role_resp,
                HZ_RELATIONSHIPS rel,
                hz_parties party,
                hz_parties sub_party
            where
                acct_role.cust_account_id = P_CUST_ACCOUNT_ID and
                acct_role.cust_acct_site_id is null and
                acct_role.status = 'A' and
                acct_role.cust_account_role_id = role_resp.cust_account_role_id and
                acct_role.party_id = party.party_id and
                party.status = 'A' and
                rel.party_id = party.party_id and
                rel.subject_type = 'PERSON' and
                rel.status = 'A' and
                decode(rel.object_type, 'PERSON', rel.directional_flag, 1) = decode(rel.object_type, 'PERSON', 'F', 1) and
                sub_party.party_id = rel.subject_id and
                sub_party.status = 'A'
            order by Display_Order, sub_party.party_name;
Line: 712

            select
                decode(cont_point.contact_point_purpose,
                    'DUNNING', decode(cont_point.primary_flag, 'Y', 1, decode(cont_point.primary_by_purpose, 'Y', 2, 3)),
                    'COLLECTIONS', decode(cont_point.primary_flag, 'Y', 4, decode(cont_point.primary_by_purpose, 'Y', 5, 6)),
                    'BUSINESS', decode(cont_point.primary_flag, 'Y', 7, decode(cont_point.primary_by_purpose, 'Y', 8, 9)),
                    null, decode(cont_point.primary_flag, 'Y', 10, decode(cont_point.primary_by_purpose, 'Y', 11, 12))
                ) Display_Order
                ,cont_point.CONTACT_POINT_ID
            from hz_contact_points cont_point
            where
                cont_point.owner_table_id = P_PARTY_ID and
                cont_point.owner_table_name = 'HZ_PARTIES' and
                cont_point.contact_point_type = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'PHONE', 'FAX', 'PHONE') and
                nvl(cont_point.phone_line_type, 'EMAIL') = decode(P_CONTACT_POINT_TYPE, 'EMAIL', 'EMAIL', 'PHONE', 'GEN', 'FAX', 'FAX') and
                NVL(cont_point.do_not_use_flag, 'N') = 'N' and
                (cont_point.status = 'A' OR cont_point.status <> 'I')
            order by Display_Order;
Line: 732

            select party_id from hz_cust_accounts where cust_account_id = P_CUST_ACCOUNT_ID;
Line: 736

            select
                decode(site_use.site_use_code,
                    'DUN', 1,
                    'BILL_TO', decode(site_use.primary_flag, 'Y', 2, 3)) display_order,
                site_use.site_use_code,
                par_site.location_id
            from
                hz_party_sites par_site,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                HZ_CUST_SITE_USES_ALL site_use
            where
                acct_site.cust_account_id = P_CUST_ACCOUNT_ID and
                acct_site.status = 'A' and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                site_use.status = 'A' and
                par_site.party_site_id = acct_site.party_site_id and
                par_site.status in ('A', 'I')
            order by display_order;
Line: 757

            select count(1)
            from
                hz_party_sites par_site,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                HZ_CUST_SITE_USES_ALL site_use
            where
                acct_site.cust_account_id = P_CUST_ACCOUNT_ID and
                acct_site.status = 'A' and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                site_use.status = 'A' and
                par_site.party_site_id = acct_site.party_site_id and
                par_site.status in ('A', 'I') and
                site_use.site_use_code = 'BILL_TO' and
                site_use.primary_flag <> 'Y';
Line: 775

            select location_id
            from ast_locations_v
            where party_id = P_ORG_PARTY_ID and
                primary_flag = 'Y';
Line: 789

        l_dun_contact_level := nvl(fnd_profile.value('IEX_DUNNING_CONTACT_SELECTION_METHOD'), 'ALL');  --Added for bug 6500750 gnramasa 13-Nov-07
Line: 1116

            select
                decode(site_use.site_use_code,
                    'DUN', decode(par_site.identifying_address_flag, 'Y', 1, 'N', 4),
                    'BILL_TO', decode(par_site.identifying_address_flag,
                                  'Y', decode(site_use.primary_flag, 'Y', 2, 3),
                                  'N', decode(site_use.primary_flag, 'Y', 5, 6))) Display_Order ,
                acct_site.cust_account_id,
                site_use.site_use_code,
                par_site.identifying_address_flag,
                site_use.primary_flag
            from  HZ_CUST_SITE_USES_ALL site_use,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                hz_party_sites par_site
            where  par_site.party_id = P_PARTY_ID and
                par_site.status in ('A', 'I') and
                par_site.party_site_id = acct_site.party_site_id and
                acct_site.status = 'A' and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                site_use.status = 'A'
            order by Display_Order;
Line: 1142

            select count(1)
            from  HZ_CUST_SITE_USES_ALL site_use,
                HZ_CUST_ACCT_SITES_ALL acct_site,
                hz_party_sites par_site
            where  par_site.party_id = P_PARTY_ID and
                par_site.status in ('A', 'I') and
                par_site.party_site_id = acct_site.party_site_id and
                acct_site.status = 'A' and
                acct_site.cust_acct_site_id = site_use.cust_acct_site_id and
                site_use.status = 'A' and
                site_use.site_use_code = P_SITE_USE_CODE and
                par_site.identifying_address_flag = P_IDENT_FLAG and
                site_use.primary_flag = P_PRIMARY_FLAG;
Line: 1287

            select party_id
            from hz_cust_accounts
            where cust_account_id = p_cust_account_id;
Line: 1292

            select cust.party_id
            from hz_cust_accounts cust,
            hz_cust_acct_sites_all acc_site,
            hz_cust_site_uses_all site_use
            where site_use.site_use_id = p_site_use_id and
            site_use.cust_acct_site_id = acc_site.cust_acct_site_id and
            acc_site.cust_account_id = cust.cust_account_id;
Line: 1301

            select party_cust_id, customer_site_use_id
            from iex_delinquencies_all
            where delinquency_id = p_delinquency_id;
Line: 1509

            select party_cust_id, cust_account_id, customer_site_use_id
            from iex_delinquencies_all
            where delinquency_id = p_delinquency_id;
Line: 1514

            select party_id
            from hz_cust_accounts
            where cust_account_id = p_cust_account_id;
Line: 1519

            select cust.party_id, cust.cust_account_id
            from hz_cust_accounts cust,
            hz_cust_acct_sites_all acc_site,
            hz_cust_site_uses_all site_use
            where site_use.site_use_id = p_site_use_id and
            site_use.cust_acct_site_id = acc_site.cust_acct_site_id and
            acc_site.cust_account_id = cust.cust_account_id;
Line: 1528

            select dispute_id
            from IEX_DISPUTES
            where cm_request_id = p_cm_request_id;
Line: 1534

            select customer_id
            from ar_payment_schedules_all
            where customer_trx_id = p_cust_trx_id;
Line: 1733

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_party_index).key_name || ' value in bind table');
Line: 1764

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_cust_account_index).key_name || ' value in bind table');
Line: 1780

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_party_index).key_name || ' value in bind table');
Line: 1797

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_site_use_index).key_name || ' value in bind table');
Line: 1813

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_party_index).key_name || ' value in bind table');
Line: 1825

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_cust_account_index).key_name || ' value in bind table');
Line: 1843

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_del_index).key_name || ' value in bind table');
Line: 1859

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_party_index).key_name || ' value in bind table');
Line: 1871

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_cust_account_index).key_name || ' value in bind table');
Line: 1883

                WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_site_use_index).key_name || ' value in bind table');
Line: 1921

             WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_location_index).key_name || ' value in bind table');
Line: 1933

             WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_contact_index).key_name || ' value in bind table');
Line: 1945

             WriteLog(l_api_name || ': Updated ' || l_fulfillment_bind_tbl(l_contact_point_index).key_name || ' value in bind table');
Line: 1993

        SELECT delinquency_id
          FROM iex_delinquencies
         WHERE delinquency_ID = IN_del_ID;
Line: 2099

          WriteLog(l_api_name || G_PKG_NAME || ' ' || l_api_name || ' -CreateAgDn:InsertRow');
Line: 2102

          IEX_AG_DN_PKG.insert_row(
              px_rowid                         => l_rowid
            , px_AG_DN_XREF_id                 => x_AG_DN_XREF_id
            , p_last_update_date               => sysdate
            , p_last_updated_by                => FND_GLOBAL.USER_ID
            , p_creation_date                  => sysdate
            , p_created_by                     => FND_GLOBAL.USER_ID
            , p_last_update_login              => FND_GLOBAL.USER_ID
            , p_aging_bucket_id                => l_AG_DN_XREF_rec.aging_bucket_id
            , p_aging_bucket_line_id           => l_AG_DN_XREF_rec.aging_bucket_line_id
            , p_callback_flag                  => l_AG_DN_XREF_rec.callback_flag
            , p_callback_days                  => l_AG_DN_XREF_rec.callback_days
            , p_fm_method                      => l_AG_DN_XREF_rec.fm_method
            , p_dunning_level                  => l_AG_DN_XREF_rec.dunning_level
            , p_template_id                    => l_AG_DN_XREF_rec.template_id
            , p_xdo_template_id                => l_AG_DN_XREF_rec.xdo_template_id
            , p_score_range_low                => l_AG_DN_XREF_rec.score_range_low
            , p_score_range_high               => l_AG_DN_XREF_rec.score_range_high
            , p_object_version_number          => l_AG_DN_XREF_rec.object_version_number
         );
Line: 2167

    Procedure Update_AG_DN_XREF
               (p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                P_AG_DN_XREF_REC          IN IEX_DUNNING_PUB.AG_DN_XREF_REC_TYPE,
                p_AG_DN_XREF_ID           IN NUMBER,
                x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2)

    IS
        CURSOR C_get_AG_DN_XREF_Rec (IN_AG_DN_XREF_ID NUMBER) is
           select  ROWID,
                   AG_DN_XREF_ID,
                   AGING_BUCKET_ID,
                   AGING_BUCKET_LINE_ID,
                   CALLBACK_FLAG,
                   CALLBACK_DAYS,
                   FM_METHOD,
                   TEMPLATE_ID,
                   XDO_TEMPLATE_ID,
                   SCORE_RANGE_LOW,
                   SCORE_RANGE_HIGH,
                   DUNNING_LEVEL,
                   OBJECT_VERSION_NUMBER ,
                   LAST_UPDATE_DATE,
                   LAST_UPDATED_BY,
                   CREATION_DATE,
                   CREATED_BY ,
                   LAST_UPDATE_LOGIN
             from iex_AG_DN_XREF
            where AG_DN_XREF_id = in_AG_DN_XREF_id
            FOR UPDATE NOWAIT;
Line: 2201

        l_api_name                    CONSTANT VARCHAR2(30) := 'Update_AG_DN';
Line: 2215

          SAVEPOINT UPDATE_AG_DN_PVT;
Line: 2257

             l_AG_DN_XREF_ref_rec.LAST_UPDATE_DATE,
             l_AG_DN_XREF_ref_rec.LAST_UPDATED_BY,
             l_AG_DN_XREF_ref_rec.CREATION_DATE,
             l_AG_DN_XREF_ref_rec.CREATED_BY,
             l_AG_DN_XREF_ref_rec.LAST_UPDATE_LOGIN;
Line: 2266

                FND_MESSAGE.Set_Name('AS', 'API_MISSING_UPDATE_TARGET');
Line: 2276

          If (l_ag_Dn_xref_rec.last_update_date is NULL or
             l_ag_Dn_xref_rec.last_update_date = FND_API.G_MISS_Date )
          Then
              IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR)
              THEN
                  FND_MESSAGE.Set_Name('IEX', 'API_MISSING_ID');
Line: 2282

                  FND_MESSAGE.Set_Token('COLUMN', 'Last_Update_Date', FALSE);
Line: 2329

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateRow ');
Line: 2331

          IEX_AG_DN_PKG.update_row(
              p_rowid                          => l_rowid
            , p_AG_DN_XREF_id                  => p_AG_DN_XREF_id
            , p_last_update_date               => sysdate
            , p_last_updated_by                => FND_GLOBAL.USER_ID
            , p_creation_date                  => l_AG_DN_XREF_rec.creation_date
            , p_created_by                     => l_AG_DN_XREF_rec.created_by
            , p_last_update_login              => FND_GLOBAL.USER_ID
            , p_aging_bucket_id                => l_AG_DN_XREF_rec.aging_bucket_id
            , p_aging_bucket_line_id           => l_AG_DN_XREF_rec.aging_bucket_line_id
            , p_callback_flag                  => l_AG_DN_XREF_rec.callback_flag
            , p_callback_days                  => l_AG_DN_XREF_rec.callback_days
            , p_fm_method                      => l_AG_DN_XREF_rec.fm_method
            , p_template_id                    => l_AG_DN_XREF_rec.template_id
            , p_xdo_template_id                => l_AG_DN_XREF_rec.xdo_template_id
            , p_score_range_low                => l_AG_DN_XREF_rec.score_range_low
            , p_score_range_high               => l_AG_DN_XREF_rec.score_range_high
            , p_dunning_level                  => l_AG_DN_XREF_rec.dunning_level
            , p_object_version_number          => l_ag_dn_xref_rec.object_version_number
         );
Line: 2362

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateAgDn:End ');
Line: 2374

                  ROLLBACK TO UPDATE_AG_DN_PVT;
Line: 2383

                  ROLLBACK TO UPDATE_AG_DN_PVT;
Line: 2391

                  ROLLBACK TO UPDATE_AG_DN_PVT;
Line: 2394

    END Update_AG_DN_XREF;
Line: 2396

    Procedure Delete_AG_DN_XREF
               (p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                P_AG_DN_XREF_ID           IN NUMBER,
                x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2)

    IS
        CURSOR C_GET_AG_DN_XREF (IN_AG_DN_XREF_ID NUMBER) IS
          SELECT AG_DN_XREF_ID
            FROM IEX_AG_DN_XREF
           WHERE AG_DN_XREF_ID = IN_AG_DN_XREF_ID;
Line: 2412

        l_api_name              CONSTANT VARCHAR2(30) := 'Delete_AG_DN';
Line: 2422

          SAVEPOINT DELETE_AG_DN_PVT;
Line: 2455

                FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 2464

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Delete Row');
Line: 2468

          IEX_AG_DN_PKG.Delete_Row(
                 p_AG_DN_XREF_ID  => l_AG_DN_XREF_ID);
Line: 2499

                  ROLLBACK TO DELETE_AG_DN_PVT;
Line: 2500

                  WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - DeleteAgDn:error='||SQLERRM);
Line: 2507

                  ROLLBACK TO DELETE_AG_DN_PVT;
Line: 2508

                  WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - DeleteAgDn:error='||SQLERRM);
Line: 2515

                  ROLLBACK TO DELETE_AG_DN_PVT;
Line: 2516

                  WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - DeleteAgDn:error='||SQLERRM);
Line: 2518

    END Delete_AG_DN_XREF;
Line: 2565

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 2571

          IEX_Dunnings_PKG.insert_row(
              px_rowid                         => l_rowid
            , px_dunning_id                    => x_dunning_id
            , p_last_update_date               => sysdate
            , p_last_updated_by                => FND_GLOBAL.USER_ID
            , p_creation_date                  => sysdate
            , p_created_by                     => FND_GLOBAL.USER_ID
            , p_last_update_login              => FND_GLOBAL.USER_ID
    	--			, p_request_id                     => FND_GLOBAL.CONC_REQUEST_ID
    	, p_request_id                     => l_dunning_rec.request_id
            , p_template_id                    => l_dunning_rec.template_id
            , p_callback_yn                    => l_dunning_rec.callback_yn
            , p_callback_date                  => l_dunning_rec.callback_date
            , p_campaign_sched_id              => l_dunning_rec.campaign_sched_id
            , p_status                         => l_dunning_rec.status
            , p_delinquency_id                 => l_dunning_rec.delinquency_id
            , p_ffm_request_id                 => l_dunning_rec.ffm_request_id
            , p_xml_request_id                 => l_dunning_rec.xml_request_id
            , p_xml_template_id                => l_dunning_rec.xml_template_id
            , p_object_id                      => l_dunning_rec.object_id
            , p_object_type                    => l_dunning_rec.object_type
            , p_dunning_object_id              => l_dunning_rec.dunning_object_id
            , p_dunning_level                  => l_dunning_rec.dunning_level
            , p_dunning_method                 => l_dunning_rec.dunning_method
            , p_amount_due_remaining           => l_dunning_rec.amount_due_remaining
            , p_currency_code                  => l_dunning_rec.currency_code
            , p_delivery_status                => l_dunning_rec.delivery_status
            , p_parent_dunning_id              => l_dunning_rec.PARENT_DUNNING_ID
            , p_dunning_plan_id                => l_dunning_rec.dunning_plan_id
            , p_contact_destination            => l_dunning_rec.contact_destination
            , p_contact_party_id               => l_dunning_rec.contact_party_id
    	, p_dunning_mode		   => l_dunning_rec.dunning_mode
    	, p_confirmation_mode              => l_dunning_rec.confirmation_mode
    	, p_org_id                         => l_dunning_rec.org_id
    	, p_ag_dn_xref_id                  => l_dunning_rec.ag_dn_xref_id
    	, p_correspondence_date            => nvl(l_dunning_rec.correspondence_date,trunc(sysdate))
    	, p_addt_xml_template_id           => l_dunning_rec.addt_xml_template_id	--added for bug 9970624 gnramasa 4th Aug 10
    	, p_addt_delivery_status           => l_dunning_rec.addt_delivery_status	--added for bug 9970624 gnramasa 4th Aug 10
    	, p_as_of_date                     => nvl(l_dunning_rec.as_of_date,trunc(sysdate))
          );
Line: 2689

        select ag_dn_xref_id,
               range_of_dunning_level_from,
    	   range_of_dunning_level_to,
    	   min_days_between_dunning
        from iex_ag_dn_xref
        where AG_DN_XREF_ID = p_ag_dn_xref_id
        order by AG_DN_XREF_ID;
Line: 2714

        select nvl(dunn.include_current ,'N'),
               nvl(dunn.include_unused_payments_flag,'N')
        from iex_ag_dn_xref xref,
             iex_dunning_plans_b dunn
        where AG_DN_XREF_ID = p_ag_dn_xref_id
        and xref.dunning_plan_id = dunn.dunning_plan_id;
Line: 2786

               select site_use_code into t_code from hz_cust_site_uses_all where site_use_id = l_object_id;
Line: 2805

    				     vPLSQL := 'select  del.delinquency_id, ' ||
    				        '          del.transaction_id, ' ||
    					'	   del.payment_schedule_id ' ||
    					'    from iex_delinquencies del, ' ||
    					'	 ar_payment_schedules arp ' ||
    					'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    					'    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    					'    and del.staged_dunning_level is NULL ' ||
    					'    and arp.invoice_currency_code = :p_inv_curr ' ||
    					'    and (trunc(arp.due_date) + :p_min_days_bw_dun) <= :p_corr_date ' ||
    					'    and (trunc(arp.due_date) + :p_gra_days) <= :p_corr_date ' ||
    					'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';
Line: 2827

    							   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    							   '	FROM hz_cust_profile_amts '||
    							   '	WHERE site_use_id  IS NULL '||
    							   '	AND cust_account_id = arp.customer_id '||
    							   '	AND currency_code   = arp.invoice_currency_code),0) '||
    				                           '    order by del.payment_schedule_id';
Line: 2838

    				         '  and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    							   '	from hz_cust_profile_amts '||
    							   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    							   '	and currency_code = arp.invoice_currency_code),0) '||
    				                           '    order by del.payment_schedule_id';
Line: 2865

    				      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 2870

    				      IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => p_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    					, p_stage_number                    => i
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 2896

    					      update iex_delinquencies_all
    					      set staged_dunning_level = i
    					      where delinquency_id = l_delinquency_id;
Line: 2902

    				      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    				      x_dunning_trx_id	:= null;
Line: 2909

    				vPLSQL1 := 'select del.delinquency_id, ' ||
    					   ' del.transaction_id, ' ||
    					   ' del.payment_schedule_id  ' ||
    				'    from iex_delinquencies del, ' ||
    				'	 ar_payment_schedules arp ' ||
    				'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    				'    and del.status = ''CURRENT'' ' ||
    				'    and del.staged_dunning_level is NULL ' ||
    				'    and arp.status = ''OP'' ' ||
    				'    and (arp.class = ''INV'' or arp.class = ''BR'') ' ||  -- Bills Receivables change
    				'    and arp.invoice_currency_code = :p_inv_curr ' ||
    				'    and (trunc(arp.due_date) + :p_min_days_bw_dun) <= :p_corr_date ' ||
    				'    and (trunc(arp.due_date) + :p_gra_days) <= :p_corr_date ' ||
    				'    and arp.amount_in_dispute >= decode(:p_include_dis_items, ''Y'', arp.amount_due_remaining, (arp.amount_due_original + 1)) ';
Line: 2937

    				      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 2942

    				      IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => p_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    					, p_stage_number                    => i
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 2968

    					      update iex_delinquencies_all
    					      set staged_dunning_level = i
    					      where delinquency_id = l_delinquency_id;
Line: 2974

    				      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    				      x_dunning_trx_id	:= null;
Line: 2985

    				vPLSQL := 'select del.delinquency_id, ' ||
    				'	   del.transaction_id, ' ||
    				'	   del.payment_schedule_id ' ||
    				'    from iex_delinquencies del ' ||
    				'	 ,ar_payment_schedules arp ' ||
    				'    where ' ||
    				'    del.payment_schedule_id = arp.payment_schedule_id and ' ||
    				'    del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    				'    and del.staged_dunning_level = :p_stage_no ' ||
    				'    and arp.invoice_currency_code = :p_inv_curr ' ||
    				'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'    and nvl( ' ||
    				'	( ' ||
    				'	 (select trunc(correspondence_date) from iex_dunnings  ' ||
    				'	  where dunning_id = ' ||
    				'	   (select max(iet.DUNNING_ID) from iex_dunning_transactions iet, ' ||
    				'                                               iex_dunnings dunn ' ||
    				'	    where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id ' ||
    				'                    and dunn.dunning_id = iet.dunning_id ' ||
    				'                    and ((dunn.dunning_mode = ''DRAFT'' and dunn.confirmation_mode = ''CONFIRMED'') ' ||
    				'                            OR (dunn.dunning_mode = ''FINAL'')) ' ||
    				'	    and iet.STAGE_NUMBER = :p_stage_no and dunn.delivery_status is null)) ' ||
    				'	    + :p_min_days_bw_dun ) ' ||
    				'	    , :p_corr_date ) ' ||
    				'	    <= :p_corr_date ';
Line: 3018

    							   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    							   '	FROM hz_cust_profile_amts '||
    							   '	WHERE site_use_id  IS NULL '||
    							   '	AND cust_account_id = arp.customer_id '||
    							   '	AND currency_code   = arp.invoice_currency_code),0) '||
    				                           '    order by del.payment_schedule_id';
Line: 3029

    				                           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    							   '	from hz_cust_profile_amts '||
    							   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    							   '	and currency_code = arp.invoice_currency_code),0) '||
    				                           '    order by del.payment_schedule_id';
Line: 3050

    				      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 3055

    				      IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => p_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    					, p_stage_number                    => i
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 3081

    					      update iex_delinquencies_all
    					      set staged_dunning_level = i
    					      where delinquency_id = l_delinquency_id;
Line: 3087

    				      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    				      x_dunning_trx_id	:= null;
Line: 3095

    				vPLSQL1 := 'select del.delinquency_id, ' ||
    					'	   del.transaction_id, ' ||
    					'	   del.payment_schedule_id ' ||
    					'    from iex_delinquencies del ' ||
    					'	 ,ar_payment_schedules arp ' ||
    					'    where  ' ||
    					'    del.payment_schedule_id = arp.payment_schedule_id and ' ||
    					'    del.status = ''CURRENT'' ' ||
    					'    and del.staged_dunning_level = :p_stage_no ' ||
    					'    and arp.status = ''OP'' ' ||
    					'    and (arp.class = ''INV'' or arp.class = ''BR'') ' ||    -- Bills Receivables change
    					'    and arp.invoice_currency_code = :p_inv_curr ' ||
    					'    and arp.amount_in_dispute >= decode(:p_include_dis_items, ''Y'', arp.amount_due_remaining, (arp.amount_due_original + 1)) ' ||
    					'    and nvl( ' ||
    					'	( ' ||
    					'	 (select trunc(correspondence_date) from iex_dunnings  ' ||
    					'	  where dunning_id = ' ||
    					'	   (select max(iet.DUNNING_ID) from iex_dunning_transactions iet, ' ||
    					'                                           iex_dunnings dunn ' ||
    					'	    where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id ' ||
    					'                    and dunn.dunning_id = iet.dunning_id ' ||
    					'                    and ((dunn.dunning_mode = ''DRAFT'' and dunn.confirmation_mode = ''CONFIRMED'') ' ||
    					'                            OR (dunn.dunning_mode = ''FINAL'')) ' ||
    					'	    and iet.STAGE_NUMBER = :p_stage_no and dunn.delivery_status is null)) ' ||
    					'	    + :p_min_days_bw_dun ) ' ||
    					'	    , :p_corr_date ) ' ||
    					'	    <= :p_corr_date';
Line: 3137

    				      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 3142

    				      IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => p_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    					, p_stage_number                    => i
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 3168

    					      update iex_delinquencies_all
    					      set staged_dunning_level = i
    					      where delinquency_id = l_delinquency_id;
Line: 3174

    				      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    				      x_dunning_trx_id	:= null;
Line: 3186

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert current invoices');
Line: 3192

    	    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Start insert current invoices');
Line: 3195

    			vPLSQL2 := 'select arp.customer_trx_id, ' ||
    				'	   arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp, ' ||
    				'         hz_cust_accounts hca ' ||
    				'    where arp.customer_id = hca.cust_account_id ' ||
    				'    and hca.party_id = :p_party_id ' ||
    				'    and trunc(arp.due_date) > trunc(:p_corr_date) ' ||
    				'    and arp.status = ''OP'' ' ||
    				'    and arp.amount_due_remaining <> 0 ' ||--'    and arp.amount_due_remaining > 0 ' || Changed to fix 12552027 by snuthala 5/19/2011
    				'    and (arp.class = ''INV'' or arp.class = ''BR'') ' ||    -- Bills Receivables change
    				'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'    and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ||
    				'    order by arp.payment_schedule_id';
Line: 3209

    		      vPLSQL2 := 'select arp.customer_trx_id, ' ||
    				'	   arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp ' ||
    				'    where arp.customer_id = :p_cust_acct_id ' ||
    				'    and trunc(arp.due_date) > trunc(:p_corr_date) ' ||
    				'    and arp.status = ''OP'' ' ||
    				'    and arp.amount_due_remaining <> 0 ' ||--'    and arp.amount_due_remaining > 0 ' || Changed to fix 12552027 by snuthala 5/19/2011
    				'    and (arp.class = ''INV'' or arp.class = ''BR'') ' ||    -- Bills Receivables change
    				'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'    and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'') ' ||
    				'    order by arp.payment_schedule_id';
Line: 3221

    		      vPLSQL2 := 'select arp.customer_trx_id, ' ||
    				'	   arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp ' ||
    				-- '    where arp.customer_site_use_id = :p_site_use_id ' ||   -- Bills Receivables
            '    where arp.customer_site_use_id IN ( :p_site_use_id, '||t_id||')' || -- Bills Receivables
    				'    and trunc(arp.due_date) > trunc(:p_corr_date) ' ||
    				'    and arp.status = ''OP'' ' ||
    				'    and arp.amount_due_remaining <> 0 ' ||--'    and arp.amount_due_remaining > 0 ' || Changed to fix 12552027 by snuthala 5/19/2011
    				'    and (arp.class = ''INV'' or arp.class = ''BR'') ' ||   -- Bills Receivables change
    				'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'    and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'') ' ||
    				'    order by arp.payment_schedule_id';
Line: 3248

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    			  px_rowid                          => l_rowid
    			, px_dunning_trx_id                 => x_dunning_trx_id
    			, p_dunning_id                      => p_dunning_id
    			, p_cust_trx_id                     => l_customer_trx_id
    			, p_payment_schedule_id             => l_payment_schedule_id
    			, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    			, p_stage_number                    => null
    			, p_created_by                      => FND_GLOBAL.USER_ID
    			, p_creation_date                   => sysdate
    			, p_last_updated_by                 => FND_GLOBAL.USER_ID
    			, p_last_update_date                => sysdate
    			, p_last_update_login               => FND_GLOBAL.USER_ID
    			, p_object_version_number	    => 1.0
    		      );
Line: 3272

    		      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    		      x_dunning_trx_id	:= null;
Line: 3284

    				vPLSQL := 'select  del.delinquency_id, ' ||
    				        '          del.transaction_id, ' ||
    					'	   del.payment_schedule_id ' ||
    					'    from iex_delinquencies del, ' ||
    					'	 ar_payment_schedules arp ' ||
    					'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    					'    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    					'    and del.staged_dunning_level is NULL ' ||
    					'    and (trunc(arp.due_date) + :p_min_days_bw_dun) > :p_corr_date ' ||
    				  '    and (trunc(arp.due_date) + :p_gra_days) > :p_corr_date ' ||
    					'    and (trunc(arp.due_date) + 0) < :p_corr_date ' ||
            --'    and (trunc(arp.due_date) + 0) <= :p_corr_date ' ||
    					'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';
Line: 3299

							   '    and del.payment_schedule_id not in (select payment_schedule_id from  iex_dunning_transactions where dunning_id = :p_dunning_id and PAYMENT_SCHEDULE_ID =  del.payment_schedule_id ) ' ||
    							   '    order by del.payment_schedule_id';
Line: 3305

    							   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    							   '	FROM hz_cust_profile_amts '||
    							   '	WHERE site_use_id  IS NULL '||
    							   '	AND cust_account_id = arp.customer_id '||
    							   '	AND currency_code   = arp.invoice_currency_code),0) '||
							   '    and del.payment_schedule_id not in (select payment_schedule_id from  iex_dunning_transactions where dunning_id = :p_dunning_id and PAYMENT_SCHEDULE_ID =  del.payment_schedule_id ) ' ||
    				                           '    order by del.payment_schedule_id';
Line: 3317

    				                           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    							   '	from hz_cust_profile_amts '||
    							   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    							   '	and currency_code = arp.invoice_currency_code),0) '||
							   '    and del.payment_schedule_id not in (select payment_schedule_id from  iex_dunning_transactions where dunning_id = :p_dunning_id and PAYMENT_SCHEDULE_ID =  del.payment_schedule_id ) ' ||
    				                           '    order by del.payment_schedule_id';
Line: 3339

    				      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 3344

                                          select count(*) into iex_dunn_trx_counter from iex_dunning_transactions where dunning_id = p_dunning_id and PAYMENT_SCHEDULE_ID = l_payment_schedule_id;
Line: 3348

    					      IEX_Dunnings_PKG.insert_staged_dunning_row(
    						  px_rowid                          => l_rowid
    						, px_dunning_trx_id                 => x_dunning_trx_id
    						, p_dunning_id                      => p_dunning_id
    						, p_cust_trx_id                     => l_transaction_id
    						, p_payment_schedule_id             => l_payment_schedule_id
    						, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    						, p_stage_number                    => null
    						, p_created_by                      => FND_GLOBAL.USER_ID
    						, p_creation_date                   => sysdate
    						, p_last_updated_by                 => FND_GLOBAL.USER_ID
    						, p_last_update_date                => sysdate
    						, p_last_update_login               => FND_GLOBAL.USER_ID
    						, p_object_version_number	    => 1.0
    					      );
Line: 3372

    					      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    					      x_dunning_trx_id	:= null;
Line: 3382

    	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - End insert current invoices');
Line: 3385

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert unapplied receipts and On Account Credit memos');
Line: 3390

    	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Start insert unapplied receipts');
Line: 3393

    			vPLSQL2 := 'select arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp, ' ||
    				'         hz_cust_accounts hca ' ||
    				'    where arp.customer_id = hca.cust_account_id ' ||
    				'    and hca.party_id = :p_party_id ' ||
    				'    and arp.status = ''OP'' ' ||
    			        '    and arp.amount_due_remaining <> 0 ' ||
    			        '    and arp.class = ''PMT'' ' ||
    			        '    order by arp.payment_schedule_id';
Line: 3403

    		      vPLSQL2 := 'select arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    ' where arp.customer_id = :p_cust_acct_id ' ||
    				    ' and arp.status = ''OP'' ' ||
    				    ' and arp.amount_due_remaining <> 0 ' ||
    				    ' and arp.class = ''PMT'' ' ||
    				    ' order by arp.payment_schedule_id';
Line: 3411

    		      vPLSQL2 := 'select arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    -- ' where arp.customer_site_use_id IN ( :p_site_use_id,24388) ' ||
                ' where arp.customer_site_use_id  IN ( :p_site_use_id, '||t_id||')' ||   -- Bills Receivables
    				    ' and arp.status = ''OP'' ' ||
    				    ' and arp.amount_due_remaining <> 0 ' ||
    				    ' and arp.class = ''PMT'' ' ||
    				    ' order by arp.payment_schedule_id';
Line: 3428

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    			  px_rowid                          => l_rowid
    			, px_dunning_trx_id                 => x_dunning_trx_id
    			, p_dunning_id                      => p_dunning_id
    			--, p_cust_trx_id                     => l_customer_trx_id
    			, p_payment_schedule_id             => l_payment_schedule_id
    			, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    			, p_stage_number                    => null
    			, p_created_by                      => FND_GLOBAL.USER_ID
    			, p_creation_date                   => sysdate
    			, p_last_updated_by                 => FND_GLOBAL.USER_ID
    			, p_last_update_date                => sysdate
    			, p_last_update_login               => FND_GLOBAL.USER_ID
    			, p_object_version_number	    => 1.0
    		      );
Line: 3452

    		      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    		      x_dunning_trx_id	:= null;
Line: 3458

    	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - End insert unapplied receipts');
Line: 3460

    	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Start insert On Account Credit memos');
Line: 3463

    			vPLSQL2 := 'select arp.customer_trx_id customer_trx_id, ' ||
    			        '          arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp, ' ||
    				'         hz_cust_accounts hca ' ||
    				'    where arp.customer_id = hca.cust_account_id ' ||
    				'    and hca.party_id = :p_party_id ' ||
    				'    and arp.amount_due_remaining <> 0 ' ||
    				'    and arp.class =''CM'' ' ||
    				'    and arp.status=''OP'' ';
Line: 3473

    		      vPLSQL2 := 'select arp.customer_trx_id customer_trx_id, ' ||
    			            '    arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    ' where arp.customer_id = :p_cust_acct_id ' ||
    				    '    and arp.amount_due_remaining <> 0 ' ||
    				    '    and arp.class =''CM'' ' ||
    				    '    and arp.status=''OP'' ';
Line: 3481

    		      vPLSQL2 := 'select arp.customer_trx_id customer_trx_id, ' ||
    			            '    arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    -- ' where arp.customer_site_use_id IN ( :p_site_use_id,24388) ' ||
                ' where arp.customer_site_use_id  IN ( :p_site_use_id, '||t_id||')' ||   -- Bills Receivabless
    				    '    and arp.amount_due_remaining <> 0 ' ||
    				    '    and arp.class =''CM'' ' ||
    				    '    and arp.status=''OP'' ';
Line: 3499

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    			  px_rowid                          => l_rowid
    			, px_dunning_trx_id                 => x_dunning_trx_id
    			, p_dunning_id                      => p_dunning_id
    			, p_cust_trx_id                     => l_customer_trx_id
    			, p_payment_schedule_id             => l_payment_schedule_id
    			, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    			, p_stage_number                    => null
    			, p_created_by                      => FND_GLOBAL.USER_ID
    			, p_creation_date                   => sysdate
    			, p_last_updated_by                 => FND_GLOBAL.USER_ID
    			, p_last_update_date                => sysdate
    			, p_last_update_login               => FND_GLOBAL.USER_ID
    			, p_object_version_number	    => 1.0
    		      );
Line: 3523

    		      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    		      x_dunning_trx_id	:= null;
Line: 3531

    	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - End insert On Account Credit memos');
Line: 3577

    Procedure Update_Dunning
               (p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                P_Dunning_REC             IN IEX_DUNNING_PUB.DUNNING_REC_TYPE,
                x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2)

    IS
        --Start adding for bug 8489610 by gnramasa 14-May-09
        --Start adding for bug 9970624 gnramasa 4th Aug 10
        CURSOR C_get_DUNNING_Rec (IN_DUNNING_ID NUMBER) is
           select  ROWID,
                   DUNNING_ID,
                   TEMPLATE_ID,
                   CALLBACK_YN,
                   CALLBACK_DATE,
                   CAMPAIGN_SCHED_ID,
                   STATUS,
                   DELINQUENCY_ID,
                   FFM_REQUEST_ID,
                   XML_REQUEST_ID,
                   XML_TEMPLATE_ID,
                   OBJECT_ID,
                   OBJECT_TYPE,
                   DUNNING_OBJECT_ID,
                   DUNNING_LEVEL,
                   DUNNING_METHOD,
                   AMOUNT_DUE_REMAINING,
                   CURRENCY_CODE,
                   LAST_UPDATE_DATE,
                   LAST_UPDATED_BY,
                   CREATION_DATE,
                   CREATED_BY ,
                   LAST_UPDATE_LOGIN,
                   delivery_status,
                   PARENT_DUNNING_ID,
                   financial_charge,   -- bug 3955222
                   letter_name,   -- bug 3955222
                   interest_amt,   -- bug 3955222
                   dunning_plan_id,   -- bug 3955222
                   contact_destination,   -- bug 3955222
                   contact_party_id,   -- bug 3955222
    	       dunning_mode,
    	       confirmation_mode,
    	       request_id,
    	       ag_dn_xref_id,
    	       correspondence_date,
    	       addt_xml_template_id,
    	       addt_delivery_status
             from iex_DUNNINGS
            where dunning_id = in_dunning_id
            FOR UPDATE NOWAIT;
Line: 3632

        l_api_name                    CONSTANT VARCHAR2(30) := 'Update_DUNNING';
Line: 3646

          SAVEPOINT UPDATE_dunning_PVT;
Line: 3694

             l_DUNNING_REF_REC.LAST_UPDATE_DATE,
             l_DUNNING_REF_REC.LAST_UPDATED_BY,
             l_DUNNING_REF_REC.CREATION_DATE,
             l_DUNNING_REF_REC.CREATED_BY,
             l_DUNNING_REF_REC.LAST_UPDATE_LOGIN,
             l_DUNNING_REF_REC.delivery_status,
             l_DUNNING_REF_REC.parent_dunning_id,
             l_DUNNING_REF_REC.financial_charge,  -- bug 3955222
             l_DUNNING_REF_REC.letter_name,  -- bug 3955222
             l_DUNNING_REF_REC.interest_amt,  -- bug 3955222
             l_DUNNING_REF_REC.dunning_plan_id,  -- bug 3955222
             l_DUNNING_REF_REC.contact_destination,  -- bug 3955222
             l_DUNNING_REF_REC.contact_party_id,  -- bug 3955222
    	 l_DUNNING_REF_REC.dunning_mode,
    	 l_DUNNING_REF_REC.confirmation_mode,
    	 l_DUNNING_REF_REC.request_id,
    	 l_DUNNING_REF_REC.ag_dn_xref_id,
    	 l_DUNNING_REF_REC.correspondence_date,
    	 l_DUNNING_REF_REC.addt_xml_template_id,
    	 l_DUNNING_REF_REC.addt_delivery_status;
Line: 3718

                FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 3729

          If (l_dunning_rec.last_update_date is NULL or
             l_dunning_rec.last_update_date = FND_API.G_MISS_Date )
          Then
              IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR)
              THEN
                  FND_MESSAGE.Set_Name('IEX', 'API_MISSING_ID');
Line: 3735

                  FND_MESSAGE.Set_Token('COLUMN', 'Last_Update_Date', FALSE);
Line: 3867

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Update Row');
Line: 3876

              IEX_DUNNINGS_PKG.Update_Row(
                 p_rowid                          => l_rowid
               , p_dunning_id                     => l_dunning_rec.dunning_id
               , p_last_update_date               => sysdate
               , p_last_updated_by                => FND_GLOBAL.USER_ID
               , p_creation_date                  => l_dunning_rec.creation_date
               , p_created_by                     => l_dunning_rec.created_by
               , p_last_update_login              => FND_GLOBAL.USER_ID
    					 --, p_request_id                     => FND_GLOBAL.CONC_REQUEST_ID
    	   , p_request_id                     => l_dunning_rec.request_id
               , p_template_id                    => l_dunning_rec.template_id
               , p_callback_yn                    => l_dunning_rec.callback_yn
               , p_callback_date                  => l_dunning_rec.callback_date
               , p_campaign_sched_id              => l_dunning_rec.campaign_sched_id
               , p_status                         => l_dunning_rec.status
               , p_delinquency_id                 => l_dunning_rec.delinquency_id
               , p_ffm_request_id                 => l_dunning_rec.ffm_request_id
               , p_xml_request_id                 => l_dunning_rec.xml_request_id
               , p_xml_template_id                => l_dunning_rec.xml_template_id
               , p_object_id                      => l_dunning_rec.object_id
               , p_object_type                    => l_dunning_rec.object_type
               , p_dunning_object_id              => l_dunning_rec.dunning_object_id
               , p_dunning_level                  => l_dunning_rec.dunning_level
               , p_dunning_method                 => l_dunning_rec.dunning_method
               , p_amount_due_remaining           => l_dunning_rec.amount_due_remaining
               , p_currency_code                  => l_dunning_rec.currency_code
               , p_delivery_status                => l_dunning_rec.delivery_status
               , p_parent_dunning_id              => l_dunning_rec.PARENT_DUNNING_ID
               , p_financial_charge               => l_dunning_rec.financial_charge   -- bug 3955222
               , p_letter_name                    => l_dunning_rec.letter_name   -- bug 3955222
               , p_interest_amt                   => l_dunning_rec.interest_amt   -- bug 3955222
               , p_dunning_plan_id                => l_dunning_rec.dunning_plan_id   -- bug 3955222
               , p_contact_destination            => l_dunning_rec.contact_destination   -- bug 3955222
               , p_contact_party_id               => l_dunning_rec.contact_party_id   -- bug 3955222
    	   , p_dunning_mode		      => l_dunning_rec.dunning_mode
    	   , p_confirmation_mode              => l_dunning_rec.confirmation_mode
    	   , p_ag_dn_xref_id                  => l_dunning_rec.ag_dn_xref_id
    	   , p_correspondence_date            => l_dunning_rec.correspondence_date
    	   , p_addt_xml_template_id           => l_dunning_rec.addt_xml_template_id
    	   , p_addt_delivery_status           => l_dunning_rec.addt_delivery_status

              );
Line: 3949

                  ROLLBACK TO UPDATE_DUNNING_PVT;
Line: 3957

                  ROLLBACK TO UPDATE_DUNNING_PVT;
Line: 3965

                  ROLLBACK TO UPDATE_DUNNING_PVT;
Line: 3968

    END Update_DUNNING;
Line: 3971

       clchang update 10/16/2002 -
        Send Dunning can be in Customer, Account and Delinquency levels in 11.5.9;
Line: 3975

       clchang update 04/21/2003 -
        new level 'BILL_TO' in 11.5.10.
    *=========================================================================*/
    Procedure Send_Level_Dunning
               (p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                p_running_level           IN VARCHAR2,
                p_dunning_plan_id         in number,
                p_resend_flag             IN VARCHAR2,
                p_delinquencies_tbl       IN IEX_DELINQUENCY_PUB.DELINQUENCY_TBL_TYPE,
                p_parent_request_id       IN NUMBER,
    	    	p_dunning_mode	      IN VARCHAR2,     -- added by gnramasa for bug 8489610 14-May-09
    	    	p_confirmation_mode	      IN   VARCHAR2,   -- added by gnramasa for bug 8489610 14-May-09
    	    	p_correspondence_date     IN DATE,
                x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2)

    IS
        CURSOR C_GET_DEL (IN_del_ID NUMBER) IS
          SELECT delinquency_ID
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 4002

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
                 , IEX_DUNNING_PLANS_VL c  -- bug 4914799 ctlee 12/30/2005
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = IN_CODE
             and c.score_id = a.score_id   -- bug 4914799 ctlee 12/30/2005
             and c.dunning_plan_id = p_dunning_plan_id -- bug 4914799 ctlee 12/30/2005
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = IN_CODE
    				   AND b.score_id = a.score_id );
Line: 4018

          SELECT x.ag_dn_xref_id,
                 x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = IN_LEVEL ;
Line: 4036

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 4043

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 4053

         select sum(a.amount_in_dispute) - sum(a.amount_due_remaining)
          from iex_delinquencies d
              ,ar_payment_schedules a
         where a.payment_schedule_id  = d.payment_schedule_id
           and d.party_cust_id        = nvl(p_party_id, d.party_cust_id)
           and d.cust_account_id      = nvl(P_CUST_ACCOUNT_ID, d.cust_account_id )
           and d.customer_site_use_id = nvl(p_site_use_id, d.customer_site_use_id )
           and d.status IN ('DELINQUENT', 'PREDELINQUENT');
Line: 4063

         select sum(a.amount_in_dispute) - sum(a.amount_due_remaining)
          from iex_delinquencies d
              ,ar_payment_schedules a
         where a.payment_schedule_id  = d.payment_schedule_id
           and d.party_cust_id        = p_party_id
           and d.status IN ('DELINQUENT', 'PREDELINQUENT');
Line: 4071

         select sum(a.amount_in_dispute) - sum(a.amount_due_remaining)
          from iex_delinquencies d
              ,ar_payment_schedules a
         where a.payment_schedule_id  = d.payment_schedule_id
           and d.cust_account_id      = P_CUST_ACCOUNT_ID
           and d.status IN ('DELINQUENT', 'PREDELINQUENT');
Line: 4079

         select sum(a.amount_in_dispute) - sum(a.amount_due_remaining)
          from iex_delinquencies d
              ,ar_payment_schedules a
         where a.payment_schedule_id  = d.payment_schedule_id
           and d.customer_site_use_id = p_site_use_id
           and d.status IN ('DELINQUENT', 'PREDELINQUENT');
Line: 4090

        SELECT count(1)
    		FROM ar_payment_schedules_all ps, iex_delinquencies_all del
    		WHERE del.party_cust_id=p_party_id
    	        AND ps.payment_schedule_id = del.payment_schedule_id
    	        AND ps.status = 'OP'
    	        AND del.status IN ('DELINQUENT', 'PREDELINQUENT')
    		and not exists(select 1
    	        from iex_promise_details pd where pd.delinquency_id=del.delinquency_id
    		and pd.status='COLLECTABLE'
    		and pd.state='PROMISE'
    	        group by pd.delinquency_id
    		having sum(nvl(pd.promise_amount,0))>=ps.amount_due_remaining);
Line: 4103

       SELECT count(1)
    		FROM ar_payment_schedules_all ps, iex_delinquencies_all del
    		WHERE del.cust_account_id=p_cust_account_id
    	        AND ps.payment_schedule_id = del.payment_schedule_id
    	        AND ps.status = 'OP'
    	        AND del.status IN ('DELINQUENT', 'PREDELINQUENT')
    		and not exists(select 1
    	        from iex_promise_details pd where pd.delinquency_id=del.delinquency_id
    		and pd.status='COLLECTABLE'
    		and pd.state='PROMISE'
    	        group by pd.delinquency_id
    		having sum(nvl(pd.promise_amount,0))>=ps.amount_due_remaining);
Line: 4116

       SELECT count(1)
    		FROM ar_payment_schedules_all ps, iex_delinquencies_all del
    		WHERE del.customer_site_use_id= p_site_use_id
    	        AND ps.payment_schedule_id = del.payment_schedule_id
    	        AND ps.status = 'OP'
    	        AND del.status IN ('DELINQUENT', 'PREDELINQUENT')
    		and not exists(select 1
    	        from iex_promise_details pd where pd.delinquency_id=del.delinquency_id
    		and pd.status='COLLECTABLE'
    		and pd.state='PROMISE'
    	        group by pd.delinquency_id
    		having sum(nvl(pd.promise_amount,0))>=ps.amount_due_remaining);
Line: 4201

        select nvl(count(*),0)
        from iex_bankruptcies
        where party_id = p_par_id
        and (disposition_code in ('GRANTED','NEGOTIATION')
             OR (disposition_code is NULL));
Line: 4235

        select nvl(dunn.INCLUDE_CURRENT,'N'),
               nvl(dunn.grace_days ,'N'),
               nvl(dunn.dun_disputed_items, 'N')
        from iex_dunning_plans_b dunn
        where dunning_plan_id = p_dunn_plan_id;
Line: 4242

        select nvl(sum(aps.acctd_amount_due_remaining),0)
           from ar_payment_schedules_all aps,iex_delinquencies_all dd,hz_cust_accounts hzca
           where dd.payment_schedule_id = aps.payment_schedule_id
           and aps.class IN ('INV', 'GUAR', 'CB', 'DM', 'DEP', 'BR')    -- Bills Receivables change
           and aps.status='OP'
           and (trunc(aps.due_date) + p_grace_days) <= p_corr_date
           and nvl(aps.amount_in_dispute,0) = decode(p_include_dis_items, 'Y', nvl(aps.amount_in_dispute,0), 0)
           and aps.amount_due_remaining > 0
           and aps.customer_id=hzca.cust_account_id
           and aps.org_id=p_org_id
           and hzca.party_id = p_party_id;
Line: 4255

           select nvl(sum(acctd_amount_due_remaining),0)
           from  ar_payment_schedules_all aps,hz_cust_accounts hzca
           where aps.class IN ('CM','PMT')
           and   aps.status = 'OP'
           and   aps.customer_id = hzca.cust_account_id
           and   aps.org_id= p_org_id
           and   hzca.party_id = p_party_id;
Line: 4390

          select fnd_profile.value(nvl('IEX_ALLOW_DUN_FULL_PROMISE','N')) into l_allow_send from dual; -- Added for bug#8408162
Line: 4685

             vPLSQL1 := 'select count(*) from ( ' ||
    							'    select del.delinquency_id, ' ||
    							'	   del.transaction_id, ' ||
    							'	   del.payment_schedule_id  ' ||
    							'    from iex_delinquencies del, ' ||
    							'	 ar_payment_schedules arp ' ||
    							'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    							'    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    							'    and (trunc(arp.due_date) + :p_grace_days) <= :p_corr_date ' ||
    							'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';
Line: 4699

    						   'select null, arp.customer_trx_id, ' ||
    						   'arp.payment_schedule_id ' ||
    				                   'from ar_payment_schedules arp ' ||
    					           ', hz_cust_accounts hca ' ||    -- Bills Receivables
    				                   'where arp.customer_id = hca.cust_account_id ' ||   -- Bills Receivables
    				                   'and arp.status = ''OP'' ' || -- Bills Receivables
                                --                   'where arp.status = ''OP'' ' || -- Bills Receivables
    				                   'and arp.amount_due_remaining <> 0 ' ||
    						   'and (arp.class = ''INV'' or arp.class = ''BR'') ' ||  -- Bills Receivables change
    				                   'and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
                                     		    --'and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' )  and  hca.party_id = :p_party_id ' ;  -- Bills Receivables
Line: 4710

                                            'and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ; -- Bills Receivables
Line: 4728

    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0) ';
Line: 4737

    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0)';
Line: 4745

    					                           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0)' ;
Line: 4752

    								   '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0)';
Line: 4851

                 * clchang updated 02/13/2003
                 * callback_days could be null if callback_yn = 'N';
Line: 4947

    		  INSERT_DUNNING_TRANSACTION(
    				p_api_version              => p_api_version
    			      , p_init_msg_list            => p_init_msg_list
    			      , p_commit                   => p_commit
    			      , p_delinquencies_tbl        => l_del_tbl
    			      , p_ag_dn_xref_id	           => l_ag_dn_xref_id
    			      , p_dunning_id               => l_dunning_id
    			      , p_correspondence_date      => p_correspondence_date
    			      , p_running_level            => p_running_level
    			      , p_grace_days               => l_grace_days
    			      , p_include_dispute_items    => l_dun_disputed_items
    			      , x_return_status            => x_return_status
    			      , x_msg_count                => x_msg_count
    			      , x_msg_data                 => x_msg_data
                              ,p_workitem_id               => null);   -- bug 14772139
Line: 5144

                IEX_DUNNING_PVT.Update_DUNNING(
                    p_api_version              => 1.0
                    , p_init_msg_list            => FND_API.G_FALSE
                    , p_commit                   => FND_API.G_TRUE
                    , p_dunning_rec              => l_dunning_rec_upd
                    , x_return_status            => l_return_status
                    , x_msg_count                => l_msg_count
                    , x_msg_data                 => l_msg_data
                );
Line: 5263

          SELECT delinquency_ID
            FROM IEX_DELINQUENCIES_ALL
           WHERE delinquency_ID = in_del_ID;
Line: 5269

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
                 , IEX_DUNNING_PLANS_VL c  -- bug 4914799 ctlee 12/30/2005
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = IN_CODE
             and c.score_id = a.score_id   -- bug 4914799 ctlee 12/30/2005
             and c.dunning_plan_id = p_dunning_plan_id -- bug 4914799 ctlee 12/30/2005
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = IN_CODE
    				   AND b.score_id = a.score_id );
Line: 5285

          SELECT x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = IN_LEVEL ;
Line: 5302

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 5311

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 5318

        select ag_dn_xref_id,
               dunning_level,
               template_id,
               xdo_template_id,
               fm_method,
               upper(callback_flag) callback_flag,
               callback_days,
    	   range_of_dunning_level_from,
    	   range_of_dunning_level_to,
    	   min_days_between_dunning,
    	   invoice_copies
        from iex_ag_dn_xref
        where dunning_plan_id = p_dunn_plan_id
        order by AG_DN_XREF_ID ;
Line: 5346

        select nvl(dunn.INCLUDE_CURRENT,'N'),
               nvl(dunn.grace_days ,'N'),
               nvl(dunn.dun_disputed_items, 'N')
        from iex_dunning_plans_b dunn
        where dunning_plan_id = p_dunn_plan_id;
Line: 5438

        select nvl(count(*),0)
        from iex_bankruptcies
        where party_id = p_par_id
        and (disposition_code in ('GRANTED','NEGOTIATION')
             OR (disposition_code is NULL));
Line: 5446

        select min_days_between_dunning
        from iex_ag_dn_xref
        where dunning_plan_id = p_dunn_plan_id
        and p_stage_no between range_of_dunning_level_from and range_of_dunning_level_to
        and p_score_val between score_range_low and score_range_high;
Line: 5555

                 select site_use_code into t_code from hz_cust_site_uses_all where site_use_id = l_object_id;
Line: 5742

    		        update iex_delinquencies del
    			set staged_dunning_level = 98
    			where del.party_cust_id = l_object_id
    			and staged_dunning_level = 99
    			and status in ('DELINQUENT','PREDELINQUENT')
    			and nvl(
    				 (
    				    (select trunc(correspondence_date) from iex_dunnings
    				     where dunning_id =
    					(select max(iet.DUNNING_ID)
    					from iex_dunning_transactions iet,
    					     iex_dunnings dunn
    					 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    						    and dunn.dunning_id = iet.dunning_id
    						    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    							    OR (dunn.dunning_mode = 'FINAL'))
    					 and iet.STAGE_NUMBER = 99
    					 and dunn.delivery_status is null
    					)
    				     )
    				   + l_min_days_between_dunn_99
    				  )
    				     , p_correspondence_date
    			      )
    			      <= p_correspondence_date ;
Line: 5769

    		        update iex_delinquencies del
    			set staged_dunning_level = 98
    			where del.cust_account_id = l_object_id
    			and staged_dunning_level = 99
    			and status in ('DELINQUENT','PREDELINQUENT')
    			and nvl(
    				 (
    				    (select trunc(correspondence_date) from iex_dunnings
    				     where dunning_id =
    					(select max(iet.DUNNING_ID)
    					from iex_dunning_transactions iet,
    					     iex_dunnings dunn
    					 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    						    and dunn.dunning_id = iet.dunning_id
    						    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    							    OR (dunn.dunning_mode = 'FINAL'))
    					 and iet.STAGE_NUMBER = 99
    					 and dunn.delivery_status is null
    					)
    				     )
    				   + l_min_days_between_dunn_99
    				  )
    				     , p_correspondence_date
    			      )
    			      <= p_correspondence_date ;
Line: 5796

    			update iex_delinquencies del
    			set staged_dunning_level = 98
    			where del.customer_site_use_id = l_object_id
    			and staged_dunning_level = 99
    			and status in ('DELINQUENT','PREDELINQUENT')
    			and nvl(
    				 (
    				    (select trunc(correspondence_date) from iex_dunnings
    				     where dunning_id =
    					(select max(iet.DUNNING_ID)
    					from iex_dunning_transactions iet,
    					     iex_dunnings dunn
    					 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    						    and dunn.dunning_id = iet.dunning_id
    						    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    							    OR (dunn.dunning_mode = 'FINAL'))
    					 and iet.STAGE_NUMBER = 99
    					 and dunn.delivery_status is null
    					)
    				     )
    				   + l_min_days_between_dunn_99
    				  )
    				     , p_correspondence_date
    			      )
    			      <= p_correspondence_date ;
Line: 5823

    	    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' Updated : ' || SQL%ROWCOUNT || ' number of row''s staged_dunning_level from 99 to 98');
Line: 5866

    	 vPLSQL := '  select ag_dn_xref_id, ' ||
    		' dunning_level, ' ||
    	        ' template_id, ' ||
    		' xdo_template_id, ' ||
    		' fm_method, ' ||
    		' upper(callback_flag) callback_flag, ' ||
    		' callback_days, ' ||
    		' range_of_dunning_level_from, ' ||
    		' range_of_dunning_level_to, ' ||
    		' min_days_between_dunning, ' ||
    		' invoice_copies ' ||
    		' from iex_ag_dn_xref ' ||
    		' where dunning_plan_id = :p_dunning_plan_id ' ||
    		' AND :p_score between score_range_low and score_range_high ' ||
    		' order by range_of_dunning_level_from ' || l_orderby;
Line: 6004

    					 vPLSQL1 := 'select count(*) from ( ' ||
    							'    select del.delinquency_id, ' ||
    							'	   del.transaction_id, ' ||
    							'	   del.payment_schedule_id  ' ||
    							'    from iex_delinquencies del, ' ||
    							'	 ar_payment_schedules arp ' ||
    							'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    							'    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    							'    and del.staged_dunning_level is NULL ' ||
    							'    and (trunc(arp.due_date) + :p_min_days_bw_dun) <= :p_corr_date ' ||
    							'    and (trunc(arp.due_date) + :p_grace_days) <= :p_corr_date ' ||
    							'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';
Line: 6020

    						   'select null, arp.customer_trx_id, ' ||
    						   'arp.payment_schedule_id ' ||
    				                   'from ar_payment_schedules arp, ' ||
    					           'hz_cust_accounts hca ' ||
    				                   'where arp.customer_id = hca.cust_account_id ' ||
    				                   'and arp.status = ''OP'' ' ||
    				                   'and arp.amount_due_remaining <> 0 ' ||--'    and arp.amount_due_remaining > 0 ' || Changed to fix 12552027 by snuthala 5/19/2011
    						   'and arp.class = ''INV'' ' ||
    				                   'and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
                                     		   'and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ;*/
Line: 6041

    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0))';
Line: 6049

    					                           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0))';
Line: 6093

    				      vPLSQL1 := 'select count(*) from ( ' ||
    							'    select del.delinquency_id, ' ||
    							'	   del.transaction_id, ' ||
    							'	   del.payment_schedule_id ' ||
    							'   from iex_delinquencies del ' ||
    							'	 ,ar_payment_schedules arp ' ||
    							'    where ' ||
    							'    del.payment_schedule_id = arp.payment_schedule_id and ' ||
    							'    del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    							'    and del.staged_dunning_level = :p_stage_no ' ||
    							'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    							'    and nvl( ' ||
    							'	     ( ' ||
    							'		(select trunc(correspondence_date) from iex_dunnings ' ||
    							'		 where dunning_id = ' ||
    							'		    (select max(iet.DUNNING_ID) from iex_dunning_transactions iet, ' ||
    							'                                                    iex_dunnings dunn ' ||
    							'		     where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id ' ||
    							'                    and dunn.dunning_id = iet.dunning_id ' ||
    							'                    and ((dunn.dunning_mode = ''DRAFT'' and dunn.confirmation_mode = ''CONFIRMED'') ' ||
    							'                            OR (dunn.dunning_mode = ''FINAL'')) ' ||
    							'		     and iet.STAGE_NUMBER = :p_stage_no ' ||
    							'                    and dunn.delivery_status is null' ||
    							'		    ) ' ||
    							'		 ) ' ||
    							'	       + :p_min_days_bw_dun ' ||
    							'	      ) ' ||
    							'	     , :p_corr_date ' ||
    							'	    ) ' ||
    							'	    <= :p_corr_date ';
Line: 6130

    						   'select null, arp.customer_trx_id, ' ||
    						   'arp.payment_schedule_id ' ||
    				                   'from ar_payment_schedules arp, ' ||
    					           'hz_cust_accounts hca ' ||
    				                   'where arp.customer_id = hca.cust_account_id ' ||
    				                   'and arp.status = ''OP'' ' ||
    				                   'and arp.amount_due_remaining <> 0 ' ||--'    and arp.amount_due_remaining > 0 ' || Changed to fix 12552027 by snuthala 5/19/2011
    						   'and arp.class = ''INV'' ' ||
    				                   'and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
                                     		   'and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ;
Line: 6141

    							'    select del.delinquency_id, ' ||
    							'	   del.transaction_id, ' ||
    							'	   del.payment_schedule_id ' ||
    							'    from iex_delinquencies del ' ||
    							'	 ,ar_payment_schedules arp ' ||
    							'    where ' ||
    							'    del.payment_schedule_id = arp.payment_schedule_id and ' ||
    							'    del.status = ''CURRENT'' ' ||
    							'    and del.staged_dunning_level = :p_stage_no ' ||
    							'    and arp.status = ''OP'' ' ||
    							'    and arp.class = ''INV'' ' ||
    							'    and arp.amount_in_dispute >= decode(:p_include_dis_items, ''Y'', arp.amount_due_remaining, (arp.amount_due_original + 1)) ' ||
    							'    and nvl( ' ||
    							'	( ' ||
    							'	 (select trunc(correspondence_date) from iex_dunnings ' ||
    							'	  where dunning_id = ' ||
    							'	   (select max(iet.DUNNING_ID) from iex_dunning_transactions iet, ' ||
    							'                                           iex_dunnings dunn ' ||
    							'	    where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id ' ||
    							'                    and dunn.dunning_id = iet.dunning_id ' ||
    							'                    and ((dunn.dunning_mode = ''DRAFT'' and dunn.confirmation_mode = ''CONFIRMED'') ' ||
    							'                            OR (dunn.dunning_mode = ''FINAL'')) ' ||
    							'	    and iet.STAGE_NUMBER = :p_stage_no and dunn.delivery_status is null)) ' ||
    							'	    + :p_min_days_bw_dun ) ' ||
    							'	    , :p_corr_date ) ' ||
    							'	    <= :p_corr_date ' ;*/
Line: 6179

    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0)) ';
Line: 6188

    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0))';*/
Line: 6196

    					                           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0))';/* ||
Line: 6202

    								   '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0))';*/
Line: 6303

    			     * clchang updated 02/13/2003
    			     * callback_days could be null if callback_yn = 'N';
Line: 6583

    			    IEX_DUNNING_PVT.Update_DUNNING(
    				p_api_version              => 1.0
    				, p_init_msg_list            => FND_API.G_FALSE
    				, p_commit                   => FND_API.G_TRUE
    				, p_dunning_rec              => l_dunning_rec_upd
    				, x_return_status            => l_return_status
    				, x_msg_count                => l_msg_count
    				, x_msg_data                 => l_msg_data
    			    );
Line: 6610

    			 select template_id
    			 into l_xdo_template_id
    			 from iex_dunnings
    			 where dunning_id = l_dunning_id;
Line: 6615

    			select xml_template_id
    			 into l_xdo_template_id
    			 from iex_dunnings
    			 where dunning_id = l_dunning_id;
Line: 6726

    		    IEX_DUNNING_PVT.Update_DUNNING(
    			p_api_version              => 1.0
    			, p_init_msg_list            => FND_API.G_FALSE
    			, p_commit                   => FND_API.G_TRUE
    			, p_dunning_rec              => l_dunning_rec_upd
    			, x_return_status            => l_return_status
    			, x_msg_count                => l_msg_count
    			, x_msg_data                 => l_msg_data
    		    );
Line: 6742

    				update iex_delinquencies del
    				set staged_dunning_level = 99
    				where del.party_cust_id = l_object_id
    				and staged_dunning_level = 98
    				and status in ('DELINQUENT','PREDELINQUENT')
    				and exists (select count(iet.DUNNING_ID)
    						from iex_dunning_transactions iet,
    						     iex_dunnings dunn
    						 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    							    and dunn.dunning_id = iet.dunning_id
    							    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    								    OR (dunn.dunning_mode = 'FINAL'))
    						 and iet.STAGE_NUMBER = 99
    						 and dunn.delivery_status is null
    					    );
Line: 6759

    				update iex_delinquencies del
    				set staged_dunning_level = 99
    				where del.cust_account_id = l_object_id
    				and staged_dunning_level = 98
    				and status in ('DELINQUENT','PREDELINQUENT')
    				and exists (select count(iet.DUNNING_ID)
    						from iex_dunning_transactions iet,
    						     iex_dunnings dunn
    						 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    							    and dunn.dunning_id = iet.dunning_id
    							    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    								    OR (dunn.dunning_mode = 'FINAL'))
    						 and iet.STAGE_NUMBER = 99
    						 and dunn.delivery_status is null
    					    );
Line: 6776

    				update iex_delinquencies del
    				set staged_dunning_level = 99
    				where del.customer_site_use_id = l_object_id
    				and staged_dunning_level = 98
    				and status in ('DELINQUENT','PREDELINQUENT')
    				and exists (select count(iet.DUNNING_ID)
    						from iex_dunning_transactions iet,
    						     iex_dunnings dunn
    						 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    							    and dunn.dunning_id = iet.dunning_id
    							    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    								    OR (dunn.dunning_mode = 'FINAL'))
    						 and iet.STAGE_NUMBER = 99
    						 and dunn.delivery_status is null
    					    );
Line: 6793

    		    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' Updated : ' || SQL%ROWCOUNT || ' number of row''s staged_dunning_level from 98 to 99');
Line: 6877

     * clchang updated 09/19/2002 -
     *     insert ffm_request_id into iex_dunnings after CALL_FFM successfully;
Line: 6879

     *     Create_Dunning and Update_Dunning also updated;
Line: 6898

          SELECT delinquency_ID,
                 party_cust_id,
                 cust_account_id,
                 customer_site_use_id,
                 score_value
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 6907

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = 'IEX_DELINQUENCY'
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = 'IEX_DELINQUENCY');
Line: 6918

             select score_value
                    from iex_score_histories
                    where score_object_id = p_object_id
                    and score_object_code = p_object_type
                    order by creation_date desc;
Line: 6925

          select isc.jtf_object_code
    	from iex_dunning_plans_vl ipd, IEX_SCORES isc
    	where ipd.dunning_plan_id = p_dunn_plan_id
    	and ipd.score_id=isc.score_id;
Line: 6938

          SELECT x.ag_dn_xref_id,
    	     	 x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days,
                 ar.bucket_name
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = 'DELINQUENCY' ;
Line: 6957

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 6966

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 6973

         select nvl(ps.amount_due_remaining,0),
                nvl(ps.invoice_currency_code,'USD')
           from ar_payment_schedules_all ps,
                --iex_delinquencies_all del
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.delinquency_id = in_id;
Line: 6982

        select nvl(dunn.grace_days ,'N'),
               nvl(dunn.dun_disputed_items, 'N')
        from iex_dunning_plans_b dunn
        where dunning_plan_id = p_dunn_plan_id;
Line: 6988

          select currency_code,  nvl(min_dunning_invoice_amount,0) from hz_cust_profile_amts
            where site_use_id = p_customer_site_use_id and currency_code = (
              SELECT  sob.currency_code FROM ar_system_parameters_all sp, gl_sets_of_books sob
              WHERE   sob.set_of_books_id = sp.set_of_books_id
    	  and sp.org_id = p_org_id);
Line: 6996

    	select nvl(min_dunning_amount,0), nvl(min_dunning_invoice_amount,0)
    	from hz_cust_profile_amts
    	where site_use_id = p_site_use_id
    	and currency_code = p_currency_code;
Line: 7078

        select nvl(count(*),0)
        from iex_bankruptcies
        where party_id = p_par_id
        and (disposition_code in ('GRANTED','NEGOTIATION')
             OR (disposition_code is NULL));
Line: 7153

    		select payment_schedule_id into l_del_object_id
    		from iex_delinquencies_all
    		where delinquency_id = l_delinquency_id;
Line: 7190

         SELECT count(1) into l_fully_promised
    	           FROM ar_payment_schedules_all ps, iex_delinquencies_all del
    		   WHERE del.delinquency_id= l_delinquency_id
    	             AND ps.payment_schedule_id = del.payment_schedule_id
    	             AND ps.status = 'OP'
    	             AND del.status IN ('DELINQUENT', 'PREDELINQUENT')
    		     and not exists(select 1 from iex_promise_details pd where pd.delinquency_id=del.delinquency_id
    		                                                       and pd.status='COLLECTABLE'
    	                                    	                       and pd.state='PROMISE'
    	                                                               group by pd.delinquency_id
    		                                                       having sum(nvl(pd.promise_amount,0))>=ps.amount_due_remaining);
Line: 7201

    	  select fnd_profile.value(nvl('IEX_ALLOW_DUN_FULL_PROMISE','N')) into l_allow_send from dual;
Line: 7219

    		 select sum(a.amount_in_dispute) - sum(a.amount_due_remaining) into l_dispute_amount
    		 from iex_delinquencies d
    		 ,ar_payment_schedules a
    		 where a.payment_schedule_id  = d.payment_schedule_id
    	         and d.delinquency_id = l_delinquency_id;
Line: 7447

                   FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 7590

                * clchang updated 02/13/2003
                * callback_days could be null if callback_yn = 'N';
Line: 7624

                   FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 7676

                WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 7694

                   INSERT_DUNNING_TRANSACTION(
    				p_api_version              => p_api_version
    			      , p_init_msg_list            => p_init_msg_list
    			      , p_commit                   => p_commit
    			      , p_delinquencies_tbl        => l_del_tbl
    			      , p_ag_dn_xref_id	           => l_ag_dn_xref_id
    			      , p_dunning_id               => l_dunning_id
    			      , p_correspondence_date      => p_correspondence_date
    			      , p_running_level            => l_running_level
    			      , p_grace_days               => l_grace_days
    			      , p_include_dispute_items    => l_dun_disputed_items
    			      , x_return_status            => x_return_status
    			      , x_msg_count                => x_msg_count
    			      , x_msg_data                 => x_msg_data
                              ,p_workitem_id               => null);  -- bug 14772139
Line: 7849

                IEX_DUNNING_PVT.Update_DUNNING(p_api_version              => 1.0
    													                , p_init_msg_list            => FND_API.G_TRUE
    													                , p_commit                   => FND_API.G_TRUE
    													                , p_dunning_rec              => l_dunning_rec_upd
    													                , x_return_status            => l_return_status
    													                , x_msg_count                => l_msg_count
    													                , x_msg_data                 => l_msg_data);
Line: 7860

                * Update Delinquency
                * Set DUNN_YN = 'N'
                *===========================================*/
                  WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateDel');
Line: 7944

          SELECT delinquency_ID,
                 party_cust_id,
                 cust_account_id,
                 customer_site_use_id,
                 score_value
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 7953

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = 'IEX_DELINQUENCY'
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = 'IEX_DELINQUENCY');
Line: 7964

             select score_value
                    from iex_score_histories
                    where score_object_id = p_object_id
                    and score_object_code = p_object_type
                    order by creation_date desc;
Line: 7971

          select isc.jtf_object_code
    	from iex_dunning_plans_vl ipd, IEX_SCORES isc
    	where ipd.dunning_plan_id = p_dunn_plan_id
    	and ipd.score_id=isc.score_id;
Line: 7984

          SELECT
                 x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days,
                 ar.bucket_name
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = 'DELINQUENCY' ;
Line: 8003

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 8012

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 8019

         select ps.amount_due_remaining,
                ps.invoice_currency_code
           from ar_payment_schedules_all ps,
                --iex_delinquencies_all del
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.delinquency_id = in_id;
Line: 8117

        select nvl(dunn.grace_days ,'N'),
               nvl(dunn.dun_disputed_items, 'N')
        from iex_dunning_plans_b dunn
        where dunning_plan_id = p_dunn_plan_id;
Line: 8123

    	select nvl(min_dunning_amount,0), nvl(min_dunning_invoice_amount,0)
    	from hz_cust_profile_amts
    	where site_use_id = p_site_use_id
    	and currency_code = p_currency_code;
Line: 8129

            select arp.invoice_currency_code,
    	       arp.amount_due_remaining,
    	       del.staged_dunning_level,
    	       del.transaction_id,
    	       del.payment_schedule_id
    	from iex_delinquencies del,
    	     ar_payment_schedules arp
    	where del.delinquency_id = p_delinquency_id
    	and del.payment_schedule_id = arp.payment_schedule_id;
Line: 8140

    	select ag_dn_xref_id,
    	 dunning_level,
    	 template_id,
    	 xdo_template_id,
    	 fm_method,
    	 upper(callback_flag) callback_flag,
    	 callback_days,
    	 range_of_dunning_level_from,
    	 range_of_dunning_level_to,
    	 min_days_between_dunning ,
    	 invoice_copies
    	 from iex_ag_dn_xref
    	 where dunning_plan_id = p_dunning_plan_id
    	 --and range_of_dunning_level_from >= p_stage
    	 --and range_of_dunning_level_to <= p_stage
    	 and p_stage between range_of_dunning_level_from and range_of_dunning_level_to
    	 and p_score between score_range_low and score_range_high;
Line: 8160

        select count(*) from (
        select del.delinquency_id,
               del.transaction_id,
               del.payment_schedule_id
        from iex_delinquencies del,
             ar_payment_schedules arp
        where del.payment_schedule_id = arp.payment_schedule_id
        and del.status in ('DELINQUENT','PREDELINQUENT')
        and del.delinquency_id = p_del_id
        and del.staged_dunning_level is NULL
        and (trunc(arp.due_date) + p_min_days_bw_dun) <= p_corr_date
        and (trunc(arp.due_date) + p_grace_days) <= p_corr_date
        and nvl(arp.amount_in_dispute,0) = decode(p_include_dis_items, 'Y', nvl(arp.amount_in_dispute,0), 0)
        /*
        union
        select del.delinquency_id,
               del.transaction_id,
               del.payment_schedule_id
        from iex_delinquencies del,
             ar_payment_schedules arp
        where del.payment_schedule_id = arp.payment_schedule_id
        and del.status = 'CURRENT'
        and del.delinquency_id = p_del_id
        and del.staged_dunning_level is NULL
        and arp.status = 'OP'
        and arp.class = 'INV'
        and (trunc(arp.due_date) + p_min_days_bw_dun) <= p_corr_date
        and (trunc(arp.due_date) + p_grace_days) <= p_corr_date
        and arp.amount_in_dispute >= decode(p_include_dis_items, 'Y', arp.amount_due_remaining, (arp.amount_due_original + 1))
        */
        );
Line: 8194

        select count(*) from (
        select del.delinquency_id,
               del.transaction_id,
               del.payment_schedule_id
        from iex_delinquencies del
             ,ar_payment_schedules arp
        where
        del.payment_schedule_id = arp.payment_schedule_id and
        del.status in ('DELINQUENT','PREDELINQUENT')
        and del.delinquency_id = p_del_id
        and del.staged_dunning_level = p_stage_no
        and nvl(arp.amount_in_dispute,0) = decode(p_include_dis_items, 'Y', nvl(arp.amount_in_dispute,0), 0)
        and nvl(
                 (
    	        (select trunc(correspondence_date) from iex_dunnings
                     where dunning_id =
                        (select max(iet.DUNNING_ID) from iex_dunning_transactions iet,
    		                                     iex_dunnings dunn
                         where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
                         and dunn.dunning_id = iet.dunning_id
    		     and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    					OR (dunn.dunning_mode = 'FINAL'))
    		     and iet.STAGE_NUMBER = p_stage_no
    		     and dunn.delivery_status is null
    		     --group by iet.dunning_id
    		    )
    		 )
    	       + p_min_days_bw_dun
    	      )
    	     , p_corr_date
    	    )
    	    <= p_corr_date
        /*
        union
        select del.delinquency_id,
               del.transaction_id,
               del.payment_schedule_id
        from iex_delinquencies del
             ,ar_payment_schedules arp
        where
        del.payment_schedule_id = arp.payment_schedule_id and
        del.status = 'CURRENT'
        and del.party_cust_id = p_party_id
        and del.cust_account_id = p_cust_acct_id
        and del.staged_dunning_level = p_stage_no
        and arp.status = 'OP'
        and arp.class = 'INV'
        and arp.amount_in_dispute >= decode(p_include_dis_items, 'Y', arp.amount_due_remaining, (arp.amount_due_original + 1))
        and nvl(
            (
    	 (select trunc(correspondence_date) from iex_dunnings
              where dunning_id =
               (select distinct DUNNING_ID from iex_dunning_transactions
                where PAYMENT_SCHEDULE_ID = del.payment_schedule_id
                and STAGE_NUMBER = p_stage_no))
    	    + p_min_days_bw_dun )
    	    , p_corr_date )
    	    <= p_corr_date
         */
         );
Line: 8268

        select nvl(count(*),0)
        from iex_bankruptcies
        where party_id = p_par_id
        and (disposition_code in ('GRANTED','NEGOTIATION')
             OR (disposition_code is NULL));
Line: 8276

        select min_days_between_dunning
        from iex_ag_dn_xref
        where dunning_plan_id = p_dunn_plan_id
        and p_stage_no between range_of_dunning_level_from and range_of_dunning_level_to
        and p_score_val between score_range_low and score_range_high;
Line: 8363

    			select payment_schedule_id into l_del_object_id
    			from iex_delinquencies_all
    			where delinquency_id = l_delinquency_id;
Line: 8449

    		 update iex_delinquencies del
    		 set staged_dunning_level = 98
    		 where delinquency_id = l_delinquency_id
    		 and staged_dunning_level = 99
    		 and status in ('DELINQUENT','PREDELINQUENT')
    		 and nvl(
    			 (
    			    (select trunc(correspondence_date) from iex_dunnings
    			     where dunning_id =
    				(select max(iet.DUNNING_ID)
    				from iex_dunning_transactions iet,
    				     iex_dunnings dunn
    				 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    					    and dunn.dunning_id = iet.dunning_id
    					    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    						    OR (dunn.dunning_mode = 'FINAL'))
    				 and iet.STAGE_NUMBER = 99
    				 and dunn.delivery_status is null
    				)
    			     )
    			   + l_min_days_between_dunn_99
    			  )
    			     , p_correspondence_date
    		      )
    		      <= p_correspondence_date ;
Line: 8475

    		WriteLog(G_PKG_NAME || ' ' || l_api_name || ' Updated : ' || SQL%ROWCOUNT || ' number of row''s staged_dunning_level from 99 to 98');
Line: 8618

    			--FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 8689

    		    * clchang updated 02/13/2003
    		    * callback_days could be null if callback_yn = 'N';
Line: 8724

    		       FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 8809

    		    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 8832

    			      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 8837

    			      IEX_Dunnings_PKG.insert_staged_dunning_row(
    				  px_rowid                          => l_rowid
    				, px_dunning_trx_id                 => x_dunning_trx_id
    				, p_dunning_id                      => l_dunning_id
    				, p_cust_trx_id                     => l_transaction_id
    				, p_payment_schedule_id             => l_payment_schedule_id
    				, p_ag_dn_xref_id                   => l_ag_dn_xref_id
    				, p_stage_number                    => l_stage
    				, p_created_by                      => FND_GLOBAL.USER_ID
    				, p_creation_date                   => sysdate
    				, p_last_updated_by                 => FND_GLOBAL.USER_ID
    				, p_last_update_date                => sysdate
    				, p_last_update_login               => FND_GLOBAL.USER_ID
    				, p_object_version_number	    => 1.0
    			      );
Line: 8863

    				      update iex_delinquencies_all
    				      set staged_dunning_level = l_stage
    				      where delinquency_id = l_delinquency_id;
Line: 8869

    			      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    			      x_dunning_trx_id	:= null;
Line: 9007

    		    IEX_DUNNING_PVT.Update_DUNNING(p_api_version              => 1.0
    						, p_init_msg_list            => FND_API.G_TRUE
    						, p_commit                   => FND_API.G_TRUE
    						, p_dunning_rec              => l_dunning_rec_upd
    						, x_return_status            => l_return_status
    						, x_msg_count                => l_msg_count
    						, x_msg_data                 => l_msg_data);
Line: 9018

    		    * Update Delinquency
    		    * Set DUNN_YN = 'N'
    		    *===========================================*/
    		      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateDel');
Line: 9044

    		update iex_delinquencies del
    		set staged_dunning_level = 99
    		where delinquency_id = l_delinquency_id
    		and staged_dunning_level = 98
    		and status in ('DELINQUENT','PREDELINQUENT')
    		and exists (select count(iet.DUNNING_ID)
    				from iex_dunning_transactions iet,
    				     iex_dunnings dunn
    				 where iet.PAYMENT_SCHEDULE_ID = del.payment_schedule_id
    					    and dunn.dunning_id = iet.dunning_id
    					    and ((dunn.dunning_mode = 'DRAFT' and dunn.confirmation_mode = 'CONFIRMED')
    						    OR (dunn.dunning_mode = 'FINAL'))
    				 and iet.STAGE_NUMBER = 99
    				 and dunn.delivery_status is null
    			    );
Line: 9060

    	    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' Updated : ' || SQL%ROWCOUNT || ' number of row''s staged_dunning_level from 98 to 99');
Line: 9120

       clchang updated 04/21/2003 -
         added one new level 'BILL_TO' in 11.5.10.
    *=========================================================================*/
    Procedure Resend_Level_Dunning
               (p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                p_dunning_plan_id         in number,
                p_running_level           IN VARCHAR2,
                p_delinquencies_tbl       IN IEX_DELINQUENCY_PUB.DELINQUENCY_TBL_TYPE,
                p_org_id                  in number,
    	    	p_dunning_id              in Number,
    	    	x_request_id              OUT NOCOPY NUMBER,
                x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2)

    IS
        CURSOR C_GET_DEL (IN_del_ID NUMBER) IS
          SELECT delinquency_ID
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 9145

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
                 , IEX_DUNNING_PLANS_VL c  -- bug 4914799 ctlee 12/30/2005
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = IN_CODE
             and c.score_id = a.score_id   -- bug 4914799 ctlee 12/30/2005
             and c.dunning_plan_id = p_dunning_plan_id -- bug 4914799 ctlee 12/30/2005
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = IN_CODE);
Line: 9160

          SELECT x.ag_dn_xref_id,
                 x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = IN_LEVEL ;
Line: 9178

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 9187

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 9192

        select nvl(dunn.grace_days ,'N'),
               nvl(dunn.dun_disputed_items, 'N')
        from iex_dunning_plans_b dunn
        where dunning_plan_id = p_dunn_plan_id;
Line: 9198

        select  nvl(dunn.as_of_date,sysdate)
        from iex_dunnings dunn
        where dunning_id = p_dunning_id;
Line: 9203

        select nvl(sum(aps.acctd_amount_due_remaining),0)
           from ar_payment_schedules_all aps,iex_delinquencies_all dd,hz_cust_accounts hzca
           where dd.payment_schedule_id = aps.payment_schedule_id
           and aps.class IN ('INV', 'GUAR', 'CB', 'DM', 'DEP')
           and aps.status='OP'
           and (trunc(aps.due_date) + p_grace_days) <= p_corr_date
           and nvl(aps.amount_in_dispute,0) = decode(p_include_dis_items, 'Y', nvl(aps.amount_in_dispute,0), 0)
           and aps.amount_due_remaining > 0
           and aps.customer_id=hzca.cust_account_id
           and aps.org_id=p_org_id
           and hzca.party_id = p_party_id;
Line: 9216

           select nvl(sum(acctd_amount_due_remaining),0)
           from  ar_payment_schedules_all aps,hz_cust_accounts hzca
           where aps.class IN ('CM','PMT')
           and   aps.status = 'OP'
           and   aps.customer_id = hzca.cust_account_id
           and   aps.org_id= p_org_id
           and   hzca.party_id = p_party_id;
Line: 9428

               del_tbl(nIdx) := l_delinquency_id; --in order to update del)
Line: 9700

             vPLSQL1 := 'select count(*) from ( ' ||
    							'    select del.delinquency_id, ' ||
    							'	   del.transaction_id, ' ||
    							'	   del.payment_schedule_id  ' ||
    							'    from iex_delinquencies del, ' ||
    							'	 ar_payment_schedules arp ' ||
    							'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    							'    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    							'    and (trunc(arp.due_date) + :p_grace_days) <= :p_corr_date ' ||
    							'    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';
Line: 9713

    						   'select null, arp.customer_trx_id, ' ||
    						   'arp.payment_schedule_id ' ||
    				                   'from ar_payment_schedules arp, ' ||
    					           'hz_cust_accounts hca ' ||
    				                   'where arp.customer_id = hca.cust_account_id ' ||
    				                   'and hca.party_id = :p_party_id ' ||
    				                   'and arp.status = ''OP'' ' ||
    				                   'and arp.amount_due_remaining <> 0 ' ||--'    and arp.amount_due_remaining > 0 ' || Changed to fix 12552027 by snuthala 5/19/2011
    						   'and arp.class = ''INV'' ' ||
    				                   'and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
                                     		   'and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ;
Line: 9734

    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0) '||
    								   vPLSQL2 ||
    								   '    and del.cust_account_id = :p_cust_acct_id '||
    								   '    and arp.amount_due_remaining >= NVL ( '||
    								   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    								   '	FROM hz_cust_profile_amts '||
    								   '	WHERE site_use_id  IS NULL '||
    								   '	AND cust_account_id = arp.customer_id '||
    								   '	AND currency_code   = arp.invoice_currency_code),0))';
Line: 9749

    					                           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0) ' ||
    								   vPLSQL2 ||
    								   '    and del.customer_site_use_id = :p_site_use_id ' ||
    								   '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    								   '	from hz_cust_profile_amts '||
    								   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    								   '	and currency_code = arp.invoice_currency_code),0))';
Line: 10014

                 * clchang updated 02/13/2003
                 * callback_days could be null if callback_yn = 'N';
Line: 10072

    	     WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert Row', l_write);
Line: 10092

    		 INSERT_DUNNING_TRANSACTION(
    				p_api_version              => p_api_version
    			      , p_init_msg_list            => p_init_msg_list
    			      , p_commit                   => p_commit
    			      , p_delinquencies_tbl        => l_del_tbl
    			      , p_ag_dn_xref_id	           => l_ag_dn_xref_id
    			      , p_dunning_id               => l_dunning_id
    			      , p_correspondence_date      => l_as_of_date
    			      , p_running_level            => p_running_level
    			      , p_grace_days               => l_grace_days
    			      , p_include_dispute_items    => l_dun_disputed_items
    			      , x_return_status            => x_return_status
    			      , x_msg_count                => x_msg_count
    			      , x_msg_data                 => x_msg_data
                              ,p_workitem_id               => null);  -- bug 14772139
Line: 10113

               * Update Delinquency
               * Set DUNN_YN = 'N'
               *===========================================*/

                 WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - ==========Summary===========');
Line: 10220

          SELECT delinquency_ID
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 10226

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
                 , IEX_DUNNING_PLANS_VL c  -- bug 4914799 ctlee 12/30/2005
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = IN_CODE
             and c.score_id = a.score_id   -- bug 4914799 ctlee 12/30/2005
             and c.dunning_plan_id = p_dunning_plan_id -- bug 4914799 ctlee 12/30/2005
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = IN_CODE);
Line: 10241

          SELECT x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = IN_LEVEL ;
Line: 10258

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 10267

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 10327

        SELECT dunning_object_id,
              delinquency_id,
              dunning_level,
    	  xml_template_id,
    	  ag_dn_xref_id,
    	  xml_request_id,
    	  addt_xml_template_id,
    	  dunning_method,
    	  amount_due_remaining,
    	  currency_code,
    	  nvl(as_of_date,sysdate)
         FROM iex_dunnings
        WHERE dunning_id = in_dunning_id;
Line: 10342

          SELECT
                 --x.fm_method,
    	     upper(x.callback_flag),
                 x.callback_days
            FROM IEX_AG_DN_XREF x
           WHERE x.ag_dn_xref_id = p_ag_dn_xref_id;
Line: 10363

          SELECT resource_id
          FROM iex_xml_request_histories
          WHERE xml_request_id = p_xml_req_id;
Line: 10368

        select  nvl(dunn.as_of_date,sysdate)
        from iex_dunnings dunn
        where dunning_id = p_dunning_id;
Line: 10563

               del_tbl(nIdx) := l_delinquency_id; --in order to update del)
Line: 10975

                 * clchang updated 02/13/2003
                 * callback_days could be null if callback_yn = 'N';
Line: 11035

           select parent_dunning_id into temp_dunning_id
           from iex_dunnings
           where dunning_id =  p_dunning_id;
Line: 11049

                 WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert Row', l_write);
Line: 11073

               * Update Delinquency
               * Set DUNN_YN = 'N'
               *===========================================*/

                 WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - ==========Summary===========');
Line: 11171

          SELECT delinquency_ID,
                 party_cust_id,
                 cust_account_id,
                 customer_site_use_id,
                 score_value
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 11180

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = 'IEX_DELINQUENCY'
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = 'IEX_DELINQUENCY');
Line: 11192

          SELECT x.ag_dn_xref_id,x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days,
                 ar.bucket_name
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = 'DELINQUENCY' ;
Line: 11210

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 11219

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 11226

         select ps.amount_due_remaining,
                ps.invoice_currency_code
           from ar_payment_schedules_all ps,
                --iex_delinquencies_all del
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.delinquency_id = in_id;
Line: 11235

        select nvl(dunn.grace_days ,'N'),
               nvl(dunn.dun_disputed_items, 'N')
        from iex_dunning_plans_b dunn
        where dunning_plan_id = p_dunn_plan_id;
Line: 11298

        select  nvl(dunn.as_of_date,sysdate)
        from iex_dunnings dunn
        where dunning_id = p_dunning_id;
Line: 11745

           * clchang updated 02/13/2003
           * callback_days could be null if callback_yn = 'N';
Line: 11779

              FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 11821

           WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 11840

    	 INSERT_DUNNING_TRANSACTION(
    				p_api_version              => p_api_version
    			      , p_init_msg_list            => p_init_msg_list
    			      , p_commit                   => p_commit
    			      , p_delinquencies_tbl        => l_del_tbl
    			      , p_ag_dn_xref_id	           => l_ag_dn_xref_id
    			      , p_dunning_id               => l_dunning_id
    			      , p_correspondence_date      => l_as_of_date
    			      , p_running_level            => l_running_level
    			      , p_grace_days               => l_grace_days
    			      , p_include_dispute_items    => l_dun_disputed_items
    			      , x_return_status            => x_return_status
    			      , x_msg_count                => x_msg_count
    			      , x_msg_data                 => x_msg_data
                              ,p_workitem_id               => null);  -- bug 14772139
Line: 11863

            * Update Delinquency
            * Set DUNN_YN = 'N'
            *===========================================*/

             WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateDel');
Line: 11962

          SELECT delinquency_ID,
                 party_cust_id,
                 cust_account_id,
                 customer_site_use_id,
                 score_value
            FROM IEX_DELINQUENCIES
           WHERE delinquency_ID = in_del_ID;
Line: 11972

          SELECT a.score_value
            FROM IEX_SCORE_HISTORIES a
           WHERE a.score_object_ID = in_ID
             AND a.score_object_code = 'IEX_DELINQUENCY'
             AND a.creation_date = (select max(b.creation_date)
                                      from iex_score_histories b
                                     where b.score_object_id = in_id
                                       AND b.score_object_code = 'IEX_DELINQUENCY');
Line: 11984

          SELECT x.template_id,
                 x.xdo_template_id,
                 x.fm_method,
                 upper(x.callback_flag),
                 x.callback_days,
                 ar.bucket_name
            FROM IEX_AG_DN_XREF x,
                 ar_aging_buckets ar,
                 iex_dunning_plans_vl d
           WHERE x.aging_bucket_line_ID = l_line_ID
             and x.dunning_plan_id = p_dunning_plan_id
             AND l_score between x.score_range_low and x.score_range_high
             AND x.aging_bucket_id = ar.aging_bucket_id
             and ar.aging_bucket_id = d.aging_bucket_id
             AND ar.status = 'A'
             AND x.dunning_level = 'DELINQUENCY' ;
Line: 12002

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 12011

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 12019

         select ps.amount_due_remaining,
                ps.invoice_currency_code
           from ar_payment_schedules_all ps,
                --iex_delinquencies_all del
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.delinquency_id = in_id;
Line: 12075

        SELECT dunning_object_id,
              delinquency_id,
              dunning_level,
    	  xml_template_id,
    	  ag_dn_xref_id,
    	  xml_request_id,
    	  addt_xml_template_id
         FROM iex_dunnings
        WHERE dunning_id = in_dunning_id;
Line: 12086

          SELECT x.fm_method,
    	     upper(x.callback_flag),
                 x.callback_days
            FROM IEX_AG_DN_XREF x
           WHERE x.ag_dn_xref_id = p_ag_dn_xref_id;
Line: 12107

        select  nvl(dunn.as_of_date,sysdate)
        from iex_dunnings dunn
        where dunning_id = p_dunning_id;
Line: 12556

           * clchang updated 02/13/2003
           * callback_days could be null if callback_yn = 'N';
Line: 12590

              FND_MESSAGE.Set_Name('IEX', 'API_MISSING_UPDATE_TARGET');
Line: 12635

           select parent_dunning_id into temp_dunning_id
           from iex_dunnings
           where dunning_id =  p_dunning_id;
Line: 12648

           WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 12671

            * Update Delinquency
            * Set DUNN_YN = 'N'
            *===========================================*/

             WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateDel');
Line: 12760

       updated for 11.5.11  - 11/22/04
       dunning support aging in 11.5.11 at all levels.
       added 2 more parameters: p_object_code, and p_object_id.
       so this procedure can age not just del level, but all levels.
     */
    Procedure AGING_DEL(
                p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                p_delinquency_id          IN NUMBER,
                p_dunning_plan_id         in number,
                p_bucket                  IN VARCHAR2,
                p_object_code             IN VARCHAR2,
                p_object_id               IN NUMBER,
                x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2,
                x_AGING_Bucket_line_ID    OUT NOCOPY NUMBER)

    IS
    -- begin bug 4914799, add max function and check del status
    -- begin bug 9393778 gnramasa 19th Feb 10, add trunc function
        CURSOR C_GET_PARTY_DAYS (in_party_id number) IS
          --SELECT max(sysdate - ar.due_date) days
          SELECT max(trunc(sysdate) - trunc(ar.due_date)) days
            FROM iex_delinquencies del,
                 ar_payment_schedules ar
           WHERE del.party_cust_id = in_party_id
             AND del.payment_schedule_id = ar.payment_schedule_id
             and del.status in ('DELINQUENT', 'PREDELINQUENT');
Line: 12793

          SELECT max(trunc(sysdate) - trunc(ar.due_date)) days
            FROM iex_delinquencies del,
                 ar_payment_schedules ar
           WHERE del.cust_account_id = in_acct_id
             AND del.payment_schedule_id = ar.payment_schedule_id
             and del.status in ('DELINQUENT', 'PREDELINQUENT');
Line: 12802

          SELECT max(trunc(sysdate) - trunc(ar.due_date)) days
            FROM iex_delinquencies del,
                 ar_payment_schedules ar
           WHERE del.customer_site_use_id = in_site_id
             AND del.payment_schedule_id = ar.payment_schedule_id
             and del.status in ('DELINQUENT', 'PREDELINQUENT');
Line: 12811

          SELECT (trunc(sysdate) - trunc(ar.due_date)) days
            FROM iex_delinquencies del,
                 ar_payment_schedules ar
           WHERE delinquency_ID = in_DEL_ID
             AND del.payment_schedule_id = ar.payment_schedule_id
             and del.status in ('DELINQUENT', 'PREDELINQUENT');
Line: 12821

           SELECT l.aging_bucket_line_id
             FROM ar_aging_bucket_lines l,
                  ar_aging_buckets b,
                  iex_dunning_plans_vl d
             WHERE d.dunning_plan_id = p_dunning_plan_id
                and  d.aging_bucket_id = b.aging_bucket_id
                and  b.aging_bucket_id = l.aging_bucket_id
                --AND round(IN_DAYS) between l.days_start and l.days_to
    	    AND IN_DAYS between l.days_start and l.days_to
                and exists (select 1 from iex_ag_dn_xref x
                             where d.dunning_plan_id = x.dunning_plan_id
                             and d.aging_bucket_id = x.aging_bucket_id
                             and x.aging_bucket_line_id = l.aging_bucket_line_id);
Line: 13016

          SELECT  --content_NUMBER,
                 upper(substr(content_name,instr(content_name,'.')+1,length(content_name)-instr(content_name,'.'))) DocType,
                 mes_doc_ID
            FROM JTF_FM_TEMPLATE_CONTENTS
           WHERE template_ID = in_template_ID
             AND nvl(upper(f_deletedflag),'0') <>'D'
           --bug 3090268
           --ORDER BY content_number;
Line: 13027

          SELECT email_address
            FROM HZ_PARTIES
           WHERE party_ID = in_party_ID;
Line: 13032

          SELECT email_address
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND Contact_point_type = 'EMAIL'
             AND primary_flag = 'Y';
Line: 13039

          SELECT mes.query_id
            FROM jtf_FM_query_mes mes,
                 jtf_FM_query q
           WHERE mes.MES_DOC_ID = in_mes_doc_id
             AND mes.query_id = q.query_id;
Line: 13200

                      FND_MESSAGE.Set_Token ('INFO', 'No Contents for selected template ');
Line: 13361

       vstr1          := 'SELECT  to_date('' ';
Line: 13367

       vstr4          := 'SELECT to_date('' ' ;
Line: 13390

      v_create_string := 'SELECT SYSDATE + ' || l_callback_days ||
                         ', TO_NUMBER(TO_CHAR(SYSDATE + ' || l_callback_days || ',' || '''D''' || ')) FROM DUAL ';
Line: 13508

          SELECT  --content_NUMBER,
             upper(substr(content_name,instr(content_name,'.')+1,length(content_name)-instr(content_name,'.'))) DocType,
                 mes_doc_ID
            FROM JTF_FM_TEMPLATE_CONTENTS
           WHERE template_ID = in_template_ID
             AND nvl(upper(f_deletedflag),'0') <>'D'
           --bug 3090268
           --ORDER BY content_number;
Line: 13519

          SELECT email_address
            FROM HZ_PARTIES
           WHERE party_ID = in_party_ID;
Line: 13524

          SELECT email_address
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND Contact_point_type = 'EMAIL'
             AND primary_flag = 'Y';
Line: 13531

          SELECT mes.query_id
            FROM jtf_FM_query_mes mes,
                 jtf_FM_query q
           WHERE mes.MES_DOC_ID = in_mes_doc_id
             AND mes.query_id = q.query_id;
Line: 13751

                      *    if no rows selected based on the bind data,
                      *    skip IEXFmAcctDel.htm content;
Line: 13754

                      *    if no rows selected based on the bind data,
                      *    skip IEXFmPart2.htm and IEXFmAcctPreDel.htm contents;
Line: 13757

                      *    FFM engine set status FAILURE if no rows selected for one content.
                      *    then our template will be FAILURE
                      *    just because one content has no table data;
Line: 13920

            WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 14028

          SELECT q.query_id
            FROM iex_query_temp_xref xref,
                 iex_xml_queries q
           WHERE xref.template_id = IN_TEMPLATE_ID
             AND xref.query_id = q.query_id
             AND q.query_level = IN_LEVEL;
Line: 14037

          SELECT j.resource_id
            FROM jtf_rs_resource_extns j
           WHERE j.user_id = in_user_id;
Line: 14042

          SELECT email_address
            FROM HZ_PARTIES
           WHERE party_ID = in_party_ID;
Line: 14047

          SELECT email_address
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND Contact_point_type = 'EMAIL'
             AND primary_flag = 'Y';
Line: 14054

        select decode(p_contact_type , 'EMAIL', c.email_address,
                                       'PHONE', c.phone_country_code || c.phone_area_code || c.phone_number,
                                         'FAX', c.phone_country_code || c.phone_area_code || c.phone_number, null)
         from hz_contact_points c
        where contact_point_id = p_contact_point_id;
Line: 14062

            select QUERY_TEMP_ID, ADDT_QUERY_TEMP_ID, DESTINATION
            from IEX_XML_REQUEST_HISTORIES
            where XML_REQUEST_ID = p_request_id;
Line: 14068

          SELECT j.user_id
            FROM jtf_rs_resource_extns j
           WHERE j.resource_id = p_resource_id;
Line: 14075

              select query_id from IEX_QUERY_TEMP_XREF
    	  where query_temp_id = p_query_temp_id;
Line: 14145

        select user_id
        from jtf_rs_resource_extns
        where resource_id = p_resource_id;
Line: 14160

         select 'Active'
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id
         and trunc(sysdate) >= TRUNC (NVL(xdo.start_date, sysdate))
         and trunc(sysdate) < TRUNC(NVL(xdo.end_date, sysdate + 1));
Line: 14169

         select template_name
         from xdo_templates_vl xdo
         where xdo.template_id = l_template_id;
Line: 14343

    	select nvl(plan.dunning_type,'DAYS_OVERDUE')
    	into l_dunning_type
    	from IEX_DUNNING_PLANS_B plan, iex_dunnings dunn
    	where dunn.xml_request_id = p_request_id
    	and plan.dunning_plan_id = dunn.dunning_plan_id;
Line: 14381

    		WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 14403

    				select customer_trx_id, payment_schedule_id
    				into l_transaction_id, l_payment_schedule_id
    				from ar_payment_schedules_all
    				where customer_trx_id = p_object_id;
Line: 14414

    			    --insert invoice list in to iex_dunning_transactions table for all correspondence.
    			    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Calling IEX_Dunnings_PKG.insert_staged_dunning_row');
Line: 14416

    			    IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => l_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => null
    					, p_stage_number                    => null
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 14432

    				WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Cannot insert record in to iex_dunning_transactions table');
Line: 14434

    				WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert record in to iex_dunning_transactions table is success. x_dunning_trx_id ' || x_dunning_trx_id);
Line: 14500

    		ELSE --xml creation is success, so update the dunning_id rec with xml_request_id
    			--For staged dunning, dunning record will be created with request_id from resend procedure.
    			if l_dunning_type <> 'STAGED_DUNNING' then
    				 if l_request_id is not null then
    					--l_dunning_upd_rec.DUNNING_ID := l_dunning_id;
Line: 14516

    					    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Update dunning Row with xml request id');
Line: 14518

    					    IEX_DUNNING_PVT.Update_DUNNING(
    						   p_api_version              => 1.0
    						 , p_init_msg_list            => FND_API.G_FALSE
    						 , p_commit                   => FND_API.G_TRUE
    						 , p_dunning_rec              => l_dunning_upd_rec
    						 , x_return_status            => l_return_status1
    						 , x_msg_count                => l_msg_count1
    						 , x_msg_data                 => l_msg_data1);
Line: 14527

    					    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Update Dunning status='|| l_return_status1);
Line: 14761

    		    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 14783

    				select customer_trx_id, payment_schedule_id
    				into l_transaction_id, l_payment_schedule_id
    				from ar_payment_schedules_all
    				where customer_trx_id = p_object_id;
Line: 14794

    			    --insert invoice list in to iex_dunning_transactions table for all correspondence.
    			    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Calling IEX_Dunnings_PKG.insert_staged_dunning_row');
Line: 14796

    			    IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => l_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => null
    					, p_stage_number                    => null
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 14812

    				WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Cannot insert record in to iex_dunning_transactions table');
Line: 14814

    				WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert record in to iex_dunning_transactions table is success. x_dunning_trx_id ' || x_dunning_trx_id);
Line: 14862

    	       ELSE --xml creation is success, so update the dunning_id rec with xml_request_id
    		 if l_request_id is not null then
    			--l_dunning_upd_rec.DUNNING_ID := l_dunning_id;
Line: 14876

    			    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Update dunning Row with xml request id');
Line: 14878

    			    IEX_DUNNING_PVT.Update_DUNNING(
    				   p_api_version              => 1.0
    				 , p_init_msg_list            => FND_API.G_FALSE
    				 , p_commit                   => FND_API.G_TRUE
    				 , p_dunning_rec              => l_dunning_upd_rec
    				 , x_return_status            => l_return_status1
    				 , x_msg_count                => l_msg_count1
    				 , x_msg_data                 => l_msg_data1);
Line: 14887

    			    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Update Dunning status='|| l_return_status1);
Line: 14922

            /* We need to update the delivary status for all correspondence.
    	   So commenting the if condition */
    	/*
    	IF(p_object_code = 'PARTY' or
               p_object_code = 'IEX_ACCOUNT' or
               p_object_code = 'IEX_BILLTO' or
               p_object_code = 'IEX_DELINQUENCY' or
               p_object_code = 'IEX_STRATEGY') THEN
    	*/

    	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' -  Update dunning with delivery status: ' || l_dunning_rec.DELIVERY_STATUS);
Line: 14945

    		    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateRow');
Line: 14947

    		    IEX_DUNNING_PVT.Update_DUNNING(
    			   p_api_version              => 1.0
    			 , p_init_msg_list            => FND_API.G_FALSE
    			 , p_commit                   => FND_API.G_TRUE
    			 , p_dunning_rec              => l_dunning_rec
    			 , x_return_status            => l_return_status1
    			 , x_msg_count                => l_msg_count1
    			 , x_msg_data                 => l_msg_data1);
Line: 14956

    		    WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - UpdateDunning status='|| l_return_status1);
Line: 15000

                WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 15052

    		WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 15132

     * clchang updated 07/08/2003
     *                 for the new design of using 'Contact Purpose'.
     *                 - contact point is based on purpose, primary,
     *                   type, status;
Line: 15144

     * clchang updated 01/17/2004
     *                 - the party_id could be rel_party_id, person_party_id, or
     *                   org_party_id.
     *                   1. chk the party_type by chk_party_type;
Line: 15180

          SELECT email_address
            FROM HZ_PARTIES
           WHERE party_ID = in_party_ID;
Line: 15185

          SELECT party_id
            FROM HZ_RELATIONSHIPS
           WHERE object_id = in_party_ID
             AND relationship_type = 'DUNNING'
             AND status = 'A';
Line: 15192

          SELECT r.object_id --org party id
            FROM HZ_PARTIES p, HZ_RELATIONSHIPS r
           WHERE r.party_id = in_rel_party_ID
             AND p.party_id = r.object_id
             AND p.party_type = 'ORGANIZATION';
Line: 15199

          SELECT p.party_type
            FROM HZ_PARTIES p
           WHERE p.party_id = in_party_ID;
Line: 15225

         x_contact_party_id := p_party_id; -- default to origal party_id until updated #3955222
Line: 15342

              x_contact_party_id := l_party_id; -- default to org party_id until updated #3955222
Line: 15377

                  x_contact_party_id := l_dunning_party_id; -- default to dunning party_id until updated #3955222
Line: 15414

                 x_contact_party_id := l_party_id; -- default to origal party_id until updated #3955222
Line: 15491

          SELECT email_address,
                 decode(primary_by_purpose, 'Y',1,2) purpose,
                 decode(primary_flag, 'Y',1,2) primary
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND owner_table_name = 'HZ_PARTIES'
             --AND Contact_point_type = 'EMAIL'
             AND upper(Contact_point_type) = IN_TYPE
             AND Contact_point_purpose = 'DUNNING'
             AND NVL(do_not_use_flag, 'N') = 'N'
             AND (status = 'A' OR status <> 'I')
           order by purpose, primary;
Line: 15505

          SELECT email_address,
                 decode(primary_flag, 'Y',1,2) primary
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND owner_table_name = 'HZ_PARTIES'
             --AND Contact_point_type = 'EMAIL'
             AND upper(Contact_point_type) = IN_TYPE
             AND NVL(do_not_use_flag, 'N') = 'N'
             AND (status = 'A' OR status <> 'I')
           order by primary;
Line: 15517

          SELECT phone_country_code || phone_area_code||phone_number faxnum,
                 decode(primary_by_purpose, 'Y',1,2) purpose,
                 decode(primary_flag, 'Y', 1, 2) primary
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND owner_table_name = 'HZ_PARTIES'
             AND upper(Contact_point_type) = 'PHONE'
             AND upper(phone_line_type) = 'FAX'
             AND Contact_point_purpose = 'DUNNING'
             AND NVL(do_not_use_flag, 'N') = 'N'
             AND (status = 'A' OR status <> 'I')
           order by purpose, primary;
Line: 15531

          SELECT phone_country_code || phone_area_code||phone_number faxnum,
                 decode(primary_flag, 'Y', 1, 2) primary
            FROM HZ_CONTACT_POINTS
           WHERE owner_table_ID = in_party_ID
             AND owner_table_name = 'HZ_PARTIES'
             AND upper(Contact_point_type) = 'PHONE'
             AND upper(phone_line_type) = 'FAX'
             AND NVL(do_not_use_flag, 'N') = 'N'
             AND (status = 'A' OR status <> 'I')
           order by primary;
Line: 15764

          SELECT upper(query_string)
            FROM jtf_fm_queries_all
           WHERE query_id = IN_ID
             AND nvl(upper(f_deletedflag),'0') <>'D';
Line: 15789

    		-- clchang updated for sql bind var 05/07/2003
    		vstr1               VARCHAR2(100) ;
Line: 15797

      vstr1           := 'SELECT COUNT(*) ';
Line: 15911

          SELECT dunning_ID
            FROM IEX_DUNNINGS
           WHERE
             STATUS = 'OPEN'
             AND dunning_level = IN_TYPE
             AND dunning_object_id = IN_ID;
Line: 16017

    				  UPDATE IEX_DUNNINGS
    				     SET CALLBACK_YN = 'N',
    	                STATUS = 'CLOSE',
    	                LAST_UPDATE_DATE = sysdate
                WHERE Dunning_id = dunning_tbl(i);
Line: 16090

          SELECT dunning_ID
            FROM IEX_DUNNINGS
           WHERE
             STATUS = 'OPEN'
             AND dunning_level = IN_TYPE
             AND dunning_object_id = IN_ID
    	 AND (ag_dn_xref_id = IN_DUNN_PLAN_LINE_ID OR
    	      ag_dn_xref_id IS NULL);
Line: 16197

    				  UPDATE IEX_DUNNINGS
    				     SET CALLBACK_YN = 'N',
    	                STATUS = 'CLOSE',
    	                LAST_UPDATE_DATE = sysdate
                WHERE Dunning_id = dunning_tbl(i);
Line: 16265

          SELECT dunning_ID,
                 delinquency_id,
                 dunning_object_id,
                 to_char(callback_date, 'YYYYMMDD')
            FROM IEX_DUNNINGS
           WHERE STATUS = 'OPEN'
            AND CALLBACK_YN = 'Y'
            AND dunning_level = IN_LEVEL
            AND to_char(callback_date, 'YYYYMMDD') <= to_char(sysdate,'YYYYMMDD');
Line: 16278

          SELECT 1
            FROM IEX_DELINQUENCIES d
           WHERE d.delinquency_ID = in_del_ID
             AND STATUS in ('DELINQUENT', 'PREDELINQUENT');
Line: 16284

          SELECT 1
            FROM IEX_DELINQUENCIES d
           WHERE d.cust_account_ID = in_ACCT_ID
             AND STATUS in ('DELINQUENT', 'PREDELINQUENT');
Line: 16290

          SELECT 1
            FROM IEX_DELINQUENCIES d
           WHERE d.party_cust_id = in_party_id
             AND STATUS in ('DELINQUENT', 'PREDELINQUENT');
Line: 16296

          SELECT 1
            FROM IEX_DELINQUENCIES d
           WHERE d.customer_site_use_id = in_SITE_ID
             AND STATUS in ('DELINQUENT', 'PREDELINQUENT');
Line: 16509

                  * Update Dunning
                  *=====================*/
                   IF (l_skip = 0) THEN
                       nCnt := nCnt + 1;
Line: 16528

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - update_dunnings cnt='||nCnt);
Line: 16533

    			   UPDATE IEX_DUNNINGS
                SET CALLBACK_YN = 'N',
                    LAST_UPDATE_DATE = sysdate
              WHERE Dunning_id = dunning_tbl(i);
Line: 16550

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - DunnUpdatedNum='||nCnt);
Line: 16551

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - DunnUpdatedNum='||dunning_tbl.count);
Line: 16562

          l_task_query := 'select tsk.task_id,'
                   ||'tsk.object_version_number'
                   ||' from jtf_tasks_b tsk,'
                   ||' jtf_task_types_tl typ,'
                   ||' jtf_task_statuses_b st,'
                   ||' jtf_task_references_b ref,'
                   ||' iex_dunnings dun'
                   ||' where tsk.task_type_id=typ.task_type_id'
                   ||' and typ.name=''Callback'''
                   ||' and tsk.task_status_id=st.task_status_id'
                   ||' and  nvl(st.closed_flag,   ''N'') <>''Y'''
                   ||' and  nvl(st.cancelled_flag,   ''N'')<>''Y'''
                   ||' and  nvl(st.completed_flag,   ''N'')<>''Y'''
                   ||' and tsk.task_id=ref.task_id'
                   ||' and ref.object_type_code=''IEX_DUNNING'''
                   ||' and ref.object_id=dun.dunning_id'
                   ||' and dun.dunning_level='''||p_running_level||'''';
Line: 16581

          l_task_query:=l_task_query||' and not exists(select 1 from iex_delinquencies_all del '
                      ||' where  del.status in (''DELINQUENT'',''PREDELINQUENT'') '
                      ||' and dun.dunning_object_id=del.party_cust_id)';
Line: 16585

          l_task_query:=l_task_query||' and not exists(select 1 from iex_delinquencies_all del '
                      ||' where  del.status in (''DELINQUENT'',''PREDELINQUENT'') '
                      ||' and dun.dunning_object_id=del.cust_account_id)';
Line: 16589

          l_task_query:=l_task_query||' and not exists(select 1 from iex_delinquencies_all del '
                      ||' where  del.status in (''DELINQUENT'',''PREDELINQUENT'') '
                      ||' and dun.dunning_object_id=del.customer_site_use_id)';
Line: 16593

          l_task_query:=l_task_query||' and not exists(select 1 from iex_delinquencies_all del '
                      ||' where  del.status in (''DELINQUENT'',''PREDELINQUENT'') '
                      ||' and dun.dunning_object_id=del.delinquency_id)';
Line: 16605

    			JTF_TASKS_PUB.UPDATE_TASK(
    			P_API_VERSION           	=> p_api_version,
    		        P_INIT_MSG_LIST         	=> p_init_msg_list,
    		        P_COMMIT                	=> p_commit,
    			P_OBJECT_VERSION_NUMBER	=> l_object_version_number,
    			P_TASK_ID 			=> l_inv_task_id,
    			P_TASK_STATUS_NAME		=> 'Cancelled',
    			x_return_status		        => x_return_status,
    			x_msg_count			=> x_msg_count,
    			x_msg_data			=> x_msg_data);
Line: 16687

          SELECT d.delinquency_ID,
                 d.party_cust_id,
                 d.cust_account_id,
                 a.account_number,
                 d.customer_site_use_id,
                 ar.trx_number,
                 ar.payment_schedule_id,
                 h.party_name
            FROM IEX_DELINQUENCIES d,
                 HZ_PARTIES h,
                 HZ_CUST_ACCOUNTS a,
                 AR_PAYMENT_SCHEDULES ar
           WHERE d.delinquency_ID = in_del_ID
             AND h.party_id = d.party_cust_id
             AND d.cust_account_id = a.cust_account_id
             AND ar.payment_schedule_id = d.payment_schedule_id
             AND ar.class = 'INV';
Line: 16706

          SELECT d.party_cust_id,
                 d.cust_account_id,
                 a.account_number,
                 d.customer_site_use_id,
                 h.party_name,
                 u.location    -- added for bug 14738490
            FROM IEX_DELINQUENCIES d,
                 HZ_PARTIES h,
                 HZ_CUST_ACCOUNTS a,
                 HZ_CUST_SITE_USES u -- -- added for bug 14738490
           WHERE d.customer_site_use_id = in_SITE_ID
           AND   u.site_use_id  = d.customer_site_use_id
           AND   h.party_id = d.party_cust_id
           AND   d.cust_account_id = a.cust_account_id;
Line: 16722

          SELECT d.party_cust_id,
                 d.cust_account_id,
                 a.account_number,
                 h.party_name
            FROM IEX_DELINQUENCIES d,
                 HZ_PARTIES h,
                 HZ_CUST_ACCOUNTS a
           WHERE d.cust_account_ID = in_ACCT_ID
    	 AND h.party_id = d.party_cust_id
             AND d.cust_account_id = a.cust_account_id;
Line: 16734

          SELECT d.party_cust_id,
                 h.party_name
            FROM IEX_DELINQUENCIES d,
                 HZ_PARTIES h
           WHERE d.party_cust_id = in_party_id
             AND h.party_id = d.party_cust_id;
Line: 16980

           FND_FILE.PUT_LINE(FND_FILE.LOG, 'No default collector available to assign to callback.  Please update default collector.');
Line: 16990

                SELECT jvl.name  into l_taskname
		FROM  jtf_task_types_vl jvl , jtf_task_types_tl jtl
		WHERE jvl.task_type_id= jtl.task_type_id
		AND   jtl.language='US'
		AND   jtl.name = 'Callback'
		AND trunc(NVL (jvl.end_date_active, SYSDATE)) >= trunc(SYSDATE)
		AND trunc(NVL (jvl.start_date_active, SYSDATE)) <= trunc(SYSDATE);
Line: 16998

		SELECT jvl.name into l_statusname
		FROM  jtf_task_statuses_vl jvl , jtf_task_statuses_tl jtl
		WHERE jvl.task_status_id= jtl.task_status_id
		AND   jtl.language='US'
	        AND   jtl.name = 'Open'
	        AND trunc(NVL (jvl.end_date_active, SYSDATE)) >= trunc(SYSDATE)
                AND trunc(NVL (jvl.start_date_active, SYSDATE)) <= trunc(SYSDATE);
Line: 17181

     * Clchang updated 09/19/2002 for Bug 2242346
     *   to create a callback,
     *      we got resource_id from iex_delinquencyies before;
Line: 17225

          SELECT customer_id
            FROM jtf_tasks_vl
           WHERE customer_id = p_party_id;*/
Line: 17235

        SELECT DISTINCT person_id, salesforce_id
        FROM  as_accesses acc, jtf_rs_resource_extns rs
        WHERE acc.customer_id = p_party_id and rs.resource_id = acc.salesforce_id
          and rs.user_id is not null;
Line: 17245

          SELECT DISTINCT rs.resource_id, 0
            FROM as_rpt_managers_v m, as_accesses acc, jtf_rs_resource_extns rs
           WHERE m.person_id = acc.person_id
             AND m.manager_person_id = rs.source_id
             AND acc.customer_id = p_party_id
             AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate);
Line: 17253

          SELECT t.owner_id, count(t.owner_id)
            FROM jtf_tasks_vl t, jtf_task_statuses_vl s
           WHERE t.customer_id = p_party_id
             AND upper(t.owner_type_code) = 'RS_EMPLOYEE'
             AND t.task_name = 'Dunning Callback'
             AND t.task_status_id = s.task_status_id
             AND upper(s.name) = 'OPEN'
             AND t.owner_id in ( select DISTINCT rs.resource_id
                                 from as_rpt_managers_v m, as_accesses acc,
                                      jtf_rs_resource_extns rs
                                where m.person_id = acc.person_id
                                  and m.manager_person_id = rs.source_id
                                  and acc.customer_id = p_party_id
                                  AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate) )
           GROUP BY t.owner_id;
Line: 17270

          SELECT DISTINCT rs.resource_id, 0
            FROM as_rpt_managers_v m, as_accesses acc, jtf_rs_resource_extns rs
           WHERE m.person_id = acc.person_id
             AND m.manager_person_id = rs.source_id
             AND acc.customer_id = p_party_id
             AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate)
             AND rs.resource_id not in ( select distinct t2.owner_id
                                           from jtf_tasks_vl t2,
                                                jtf_task_statuses_vl s2
                                          where t2.customer_id = p_party_id
                                           and upper(t2.owner_type_code) = 'RS_EMPLOYEE'
                                           AND t2.task_status_id = s2.task_status_id
                                           AND upper(s2.name) = 'OPEN'
                                           and t2.task_name = 'Dunning Callback');
Line: 17286

          SELECT t.owner_id  --, count(t.owner_id)
            FROM jtf_tasks_vl t, jtf_task_statuses_vl s
           WHERE t.customer_id = p_party_id
             AND upper(t.owner_type_code) = 'RS_EMPLOYEE'
             AND t.task_name = 'Dunning Callback'
             AND t.task_status_id = s.task_status_id
             AND upper(s.name) = 'OPEN'
           GROUP BY t.owner_id
          HAVING COUNT(t.owner_id) = (select min(count(t2.owner_id))
                                      from jtf_tasks_vl t2, jtf_task_statuses_vl s2
                                     WHERE t2.customer_id = p_party_id
                                       AND upper(t2.owner_type_code) = 'RS_EMPLOYEE'
                                       AND t2.task_name = 'Dunning Callback'
                                       AND t2.task_status_id = s2.task_status_id
                                       AND upper(s2.name) = 'OPEN'
                                     group by t2.owner_id );
Line: 17305

          SELECT t.owner_id  --, count(t.owner_id)
            FROM jtf_tasks_vl t, jtf_task_statuses_vl s
           WHERE t.customer_id = p_party_id
             AND upper(t.owner_type_code) = 'RS_EMPLOYEE'
             AND t.task_name = 'Dunning Callback'
             AND t.task_status_id = s.task_status_id
             AND upper(s.name) = 'OPEN'
             AND t.owner_id in ( select DISTINCT rs.resource_id
                                 from as_accesses acc,
                                      jtf_rs_resource_extns rs
                                where acc.customer_id = p_party_id
                                  and rs.resource_id = acc.salesforce_id
                                  and rs.category = 'EMPLOYEE'
                                  and rs.user_id is not null
                                  AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate) )
           GROUP BY t.owner_id
          HAVING COUNT(t.owner_id) = (select min(count(t2.owner_id))
                                      from jtf_tasks_vl t2, jtf_task_statuses_vl s2
                                     WHERE t2.customer_id = p_party_id
                                       AND upper(t2.owner_type_code) = 'RS_EMPLOYEE'
                                       AND t2.task_name = 'Dunning Callback'
                                       AND t2.task_status_id = s2.task_status_id
                                       AND upper(s2.name) = 'OPEN'
                                       AND t2.owner_id in ( select DISTINCT rs.resource_id
                                           from as_accesses acc,
                                                jtf_rs_resource_extns rs
                                          where acc.customer_id = p_party_id
                                            and rs.resource_id = acc.salesforce_id
                                            and rs.category = 'EMPLOYEE'
                                            and rs.user_id is not null
                                            AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate) )
                                     group by t2.owner_id );
Line: 17340

          SELECT t.owner_id,  count(t.owner_id)
            FROM jtf_tasks_vl t, jtf_task_statuses_vl s
           WHERE t.customer_id = p_party_id
             AND upper(t.owner_type_code) = 'RS_EMPLOYEE'
             AND t.task_name = 'Dunning Callback'
             AND t.task_status_id = s.task_status_id
             AND upper(s.name) = 'OPEN'
             AND t.owner_id in ( select DISTINCT rs.resource_id
                                 from as_accesses acc,
                                      jtf_rs_resource_extns rs
                                where acc.customer_id = p_party_id
                                  and rs.resource_id = acc.salesforce_id
                                  and rs.category = 'EMPLOYEE'
                                  and rs.user_id is not null
                                  AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate) )
           GROUP BY t.owner_id;
Line: 17358

          SELECT DISTINCT rs.resource_id, 0
            FROM as_accesses acc, jtf_rs_resource_extns rs
           WHERE acc.customer_id = p_party_id
             AND nvl(rs.end_date_active,sysdate) >= trunc(sysdate)
             AND rs.resource_id = acc.salesforce_id
             and rs.category = 'EMPLOYEE'
             AND rs.user_id is not null
             AND rs.resource_id not in ( select distinct t2.owner_id
                                           from jtf_tasks_vl t2,
                                                jtf_task_statuses_vl s2
                                          where t2.customer_id = p_party_id
                                           and upper(t2.owner_type_code) = 'RS_EMPLOYEE'
                                           AND t2.task_status_id = s2.task_status_id
                                           AND upper(s2.name) = 'OPEN'
                                           and t2.task_name = 'Dunning Callback');
Line: 17538

         select ps.invoice_currency_code
           from ar_payment_schedules_all ps,
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.party_cust_id = in_id;
Line: 17564

         select ps.invoice_currency_code
           from ar_payment_schedules_all ps,
                --iex_delinquencies_all del
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.cust_account_id = in_id;
Line: 17591

         select ps.invoice_currency_code
           from ar_payment_schedules_all ps,
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.customer_site_use_id = in_id;
Line: 17619

         select sum(ps.acctd_amount_due_remaining)
           from ar_payment_schedules_all ps,
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.party_cust_id = in_id;
Line: 17645

         select sum(ps.acctd_amount_due_remaining)
           from ar_payment_schedules_all ps,
                --iex_delinquencies_all del
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.cust_account_id = in_id;
Line: 17672

         select sum(ps.acctd_amount_due_remaining)
           from ar_payment_schedules_all ps,
                iex_delinquencies del
          where ps.payment_schedule_id (+)= del.payment_schedule_id
            and del.customer_site_use_id = in_id;
Line: 17702

         select sum(ps.acctd_amount_due_remaining)
           from ar_payment_schedules_all ps,
                iex_dunning_transactions dtrx
          where ps.payment_schedule_id = dtrx.payment_schedule_id
            and dtrx.dunning_id = dunn_id;
Line: 17729

         select del.party_cust_id
           from iex_delinquencies del
          where del.cust_account_id = in_id;
Line: 17845

       SELECT
    	count(*) no_of_rec_processed,
    	sum(decode(delivery_status,NULL,1,0)) no_of_success_records,
    	sum(decode(delivery_status,NULL,0,1)) no_of_failure_records
       FROM iex_dunnings id
       WHERE id.request_id = p_req_id
            AND id.object_type <> 'IEX_INVOICES'
    	AND id.dunning_id =  (SELECT MAX(dunning_id)
    			      FROM iex_dunnings d
    			      WHERE d.dunning_object_id = id.dunning_object_id
    				   AND d.dunning_level = id.dunning_level
    				   AND d.request_id = id.request_id
    				   AND d.object_type <> 'IEX_INVOICES');
Line: 17860

    'select ' ||
    'id.dunning_object_id PARTY_ID, ' ||
    'p.party_name PARTY_NAME, ' ||
    'id.dunning_object_id DUNNING_OBJECT_ID, ' ||
    'id.xml_template_id TEMPLATE_ID,  ' ||
    'xtvl.template_name TEMPLATE_NAME, ' ||
    'id.delivery_status ERROR, ' ||
    'fnd_message.get_string(''IEX'',id.delivery_status) ERROR_DESC, ' ||
    'iex_utilities.get_lookup_meaning(''IEX_FULFILLMENT_SEND_METHOD'',id.dunning_method) DUNNING_METHOD, '||
    'ixr.destination DESTINATION, ' ||
    'decode(id.DUNNING_MODE, ''DRAFT'', iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'', nvl(id.CONFIRMATION_MODE,''DRAFT'')),iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'',''CONFIRMED'')) CONFIRMATION_STATUS '||
    --'ixr.xml_request_id REQUEST_ID ' ||
    --' ''http://techcm.us.oracle.com:8000/OA_HTML/IEXDUNCPRRedirect.jsp?RequestId=''  || ixr.xml_request_id DOWNLOAD_URL ' ||
    'from iex_xml_request_histories ixr, ' ||
    'hz_parties p, ' ||
    'iex_dunnings id, ' ||
    'XDO_TEMPLATES_B xtb, ' ||
    'XDO_TEMPLATES_TL xtvl ' ||
    'where id.dunning_object_id = p.party_id ' ||
    'and ixr.xml_request_id (+) = id.xml_request_id ' ||
    'and id.request_id = :l_request_id ' ||
    'and xtb.template_code=xtvl.template_code ' ||
    'and xtb.template_id = id.xml_template_id ' ||
    'and xtvl.language=userenv(''LANG'') ' ||
    'AND id.object_type <> ''IEX_INVOICES'' ' ||
    'and id.dunning_id = (select max(dunning_id) from iex_dunnings d ' ||
                         ' where d.dunning_object_id = id.dunning_object_id and d.dunning_level=id.dunning_level and d.request_id = id.request_id ' ||
    		     ' AND d.object_type <> ''IEX_INVOICES'' ) ' ||
    --'order by lower(p.party_name)' ;
Line: 17891

    'select ' ||
    'p.party_id PARTY_ID, ' ||
    'p.party_name PARTY_NAME, ' ||
    'hcu.account_number ACCOUNT_NUMBER, ' ||
    'id.dunning_object_id DUNNING_OBJECT_ID, ' ||
    'id.xml_template_id TEMPLATE_ID,  ' ||
    'xtvl.template_name TEMPLATE_NAME,  ' ||
    'id.delivery_status ERROR, ' ||
    'fnd_message.get_string(''IEX'',id.delivery_status) ERROR_DESC, ' ||
    'iex_utilities.get_lookup_meaning(''IEX_FULFILLMENT_SEND_METHOD'',id.dunning_method) DUNNING_METHOD, '||
    'ixr.destination DESTINATION, ' ||
    'decode(id.DUNNING_MODE, ''DRAFT'', iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'', nvl(id.CONFIRMATION_MODE,''DRAFT'')),iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'',''CONFIRMED'')) CONFIRMATION_STATUS '||
    --'ixr.xml_request_id REQUEST_ID ' ||
    --' ''http://techcm.us.oracle.com:8000/OA_HTML/IEXDUNCPRRedirect.jsp?RequestId=''  || ixr.xml_request_id DOWNLOAD_URL ' ||
    'from iex_xml_request_histories ixr, ' ||
    'hz_parties p, ' ||
    'hz_cust_accounts hcu, ' ||
    'iex_dunnings id, ' ||
    'XDO_TEMPLATES_B xtb, ' ||
    'XDO_TEMPLATES_TL xtvl ' ||
    'where id.dunning_object_id = hcu.cust_account_id ' ||
    'and hcu.party_id = p.party_id ' ||
    'and ixr.xml_request_id (+) = id.xml_request_id  ' ||
    'and id.request_id = :l_request_id ' ||
    'and xtb.template_code=xtvl.template_code ' ||
    'and xtb.template_id = id.xml_template_id ' ||
    'and xtvl.language=userenv(''LANG'') ' ||
    'AND id.object_type <> ''IEX_INVOICES'' ' ||
    'and id.dunning_id = (select max(dunning_id) from iex_dunnings d ' ||
                         ' where d.dunning_object_id = id.dunning_object_id and d.dunning_level=id.dunning_level and d.request_id = id.request_id ' ||
    		     ' AND d.object_type <> ''IEX_INVOICES'' ) ' ||
    --'order by lower(p.party_name)' ;
Line: 17925

    'select ' ||
    'p.party_id PARTY_ID, ' ||
    'p.party_name PARTY_NAME, ' ||
    'hcu.account_number ACCOUNT_NUMBER, ' ||
    'site_uses.location LOCATION, ' ||
    'id.dunning_object_id DUNNING_OBJECT_ID, ' ||
    'id.xml_template_id TEMPLATE_ID,  ' ||
    'xtvl.template_name TEMPLATE_NAME,  ' ||
    'id.delivery_status ERROR, ' ||
    'fnd_message.get_string(''IEX'',id.delivery_status) ERROR_DESC, ' ||
    'iex_utilities.get_lookup_meaning(''IEX_FULFILLMENT_SEND_METHOD'',id.dunning_method) DUNNING_METHOD, '||
    'ixr.destination DESTINATION, ' ||
    'decode(id.DUNNING_MODE, ''DRAFT'', iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'', nvl(id.CONFIRMATION_MODE,''DRAFT'')),iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'',''CONFIRMED'')) CONFIRMATION_STATUS '||
    --'ixr.xml_request_id REQUEST_ID ' ||
    --' ''http://techcm.us.oracle.com:8000/OA_HTML/IEXDUNCPRRedirect.jsp?RequestId=''  || ixr.xml_request_id DOWNLOAD_URL ' ||
    'from iex_xml_request_histories ixr, ' ||
    'hz_parties p, ' ||
    'hz_cust_accounts hcu,' ||
    'hz_cust_acct_sites_all acct_sites, ' ||
    'hz_cust_site_uses_all site_uses, ' ||
    'iex_dunnings id, ' ||
    'XDO_TEMPLATES_B xtb, ' ||
    'XDO_TEMPLATES_TL xtvl ' ||
    'where id.dunning_object_id = site_uses.site_use_id ' ||
    'and acct_sites.cust_acct_site_id = site_uses.cust_acct_site_id ' ||
    'and hcu.cust_account_id = acct_sites.cust_account_id ' ||
    'and p.party_id = hcu.party_id ' ||
    'and ixr.xml_request_id (+) = id.xml_request_id ' ||
    'and id.request_id = :l_request_id ' ||
    'and xtb.template_code=xtvl.template_code ' ||
    'and xtb.template_id = id.xml_template_id ' ||
    'and xtvl.language=userenv(''LANG'') ' ||
    'AND id.object_type <> ''IEX_INVOICES'' ' ||
    --'and nvl(id.confirmation_mode,''CONFIRMED'') <> ''REJECTED'' ' ||
    'and id.dunning_id = (select max(dunning_id) from iex_dunnings d ' ||
                         ' where d.dunning_object_id = id.dunning_object_id and d.dunning_level=id.dunning_level and d.request_id = id.request_id ' ||
    		     ' AND d.object_type <> ''IEX_INVOICES'' ) ' ||
   -- 'order by lower(p.party_name)' ;
Line: 17965

    'select ' ||
    'id.dunning_object_id PARTY_ID, ' ||
    'p.party_name PARTY_NAME, ' ||
    'aps.trx_number TRANSACTION_NUMBER, ' ||
    'id.dunning_object_id DUNNING_OBJECT_ID, ' ||
    'id.xml_template_id TEMPLATE_ID,  ' ||
    'xtvl.template_name TEMPLATE_NAME,  ' ||
    'id.delivery_status ERROR, ' ||
    'fnd_message.get_string(''IEX'',id.delivery_status) ERROR_DESC, ' ||
    'iex_utilities.get_lookup_meaning(''IEX_FULFILLMENT_SEND_METHOD'',id.dunning_method) DUNNING_METHOD, '||
    'ixr.destination DESTINATION, ' ||
    'decode(id.DUNNING_MODE, ''DRAFT'', iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'', nvl(id.CONFIRMATION_MODE,''DRAFT'')),iex_utilities.get_lookup_meaning(''IEX_CONFIRMATION_MODE'',''CONFIRMED'')) CONFIRMATION_STATUS '||
    --'ixr.xml_request_id REQUEST_ID ' ||
    --' ''http://techcm.us.oracle.com:8000/OA_HTML/IEXDUNCPRRedirect.jsp?RequestId=''  || ixr.xml_request_id DOWNLOAD_URL ' ||
    'from iex_xml_request_histories ixr, ' ||
    'hz_parties p, ' ||
    'iex_dunnings id, ' ||
    'XDO_TEMPLATES_B xtb, ' ||
    'XDO_TEMPLATES_TL xtvl, ' ||
    'iex_delinquencies_all del, ' ||
    'ar_payment_schedules_all aps ' ||
    'where id.dunning_object_id = del.delinquency_id ' ||
    'and del.payment_Schedule_id = aps.payment_Schedule_id ' ||
    'and del.party_cust_id = p.party_id ' ||
    'and ixr.xml_request_id (+) = id.xml_request_id  ' ||
    'and id.request_id = :l_request_id ' ||
    'and xtb.template_code=xtvl.template_code ' ||
    'and xtb.template_id = id.xml_template_id ' ||
    'and xtvl.language=userenv(''LANG'') ' ||
    'AND id.object_type <> ''IEX_INVOICES'' ' ||
    'and id.dunning_id = (select max(dunning_id) from iex_dunnings d ' ||
                         ' where d.dunning_object_id = id.dunning_object_id and d.dunning_level=id.dunning_level and d.request_id = id.request_id ' ||
    		     ' AND d.object_type <> ''IEX_INVOICES'' ) ' ||
   -- 'order by lower(p.party_name)' ;
Line: 18009

    select to_char(sysdate,  'YYYY-MM-DD')
    into l_report_date
    from dual;
Line: 18013

    select name
    into l_dunning_plan
    from iex_dunning_plans_vl
    where dunning_plan_id= p_dunning_plan_id;
Line: 18172

          select idt.cust_trx_id,
                 dunn.object_id,
                 dunn.object_type
          from iex_dunning_transactions idt,
               iex_dunnings dunn,
    	   iex_ag_dn_xref xref
          where idt.dunning_id = dunn.dunning_id
          and dunn.request_id = p_conc_req_id
          and dunn.ag_dn_xref_id = xref.ag_dn_xref_id
          and xref.invoice_copies = 'Y'
          and idt.cust_trx_id is not null;
Line: 18194

    vPLSQL1 := 'select idt.cust_trx_id, ' ||
        '         dunn.object_id, ' ||
        '         dunn.object_type, ' ||
        '         dunn.dunning_method ' ||
        '  from iex_dunning_transactions idt,  ' ||
        '       iex_dunnings dunn, ' ||
        '	   iex_ag_dn_xref xref,  ' ||
        '      ra_customer_trx trx ' ||
        '  where idt.dunning_id = dunn.dunning_id ' ||
        '  and dunn.request_id = :p_conc_req_id  ' ||
        '  and dunn.ag_dn_xref_id = xref.ag_dn_xref_id  ' ||
        '  and xref.invoice_copies = ''Y''  ' ||
        '  and idt.cust_trx_id is not null ' ||
        '  and trx.customer_trx_id = idt.cust_trx_id ' ||
        '  and trx.printing_option = ''PRI'' ' ;
Line: 18237

    			SELECT  ca.party_id into l_party_id
    			FROM hz_cust_site_uses site_uses,
    			     hz_cust_acct_sites acct_sites,
    			     hz_cust_accounts ca
    			WHERE site_uses.site_use_id = l_object_id
    			AND acct_sites.cust_acct_site_id = site_uses.cust_acct_site_id
    			AND ca.cust_account_id = acct_sites.cust_account_id;
Line: 18247

    			SELECT  ca.PARTY_CUST_ID into l_party_id
    			FROM IEX_DELINQUENCIES ca
    			WHERE ca.DELINQUENCY_ID = l_object_id;
Line: 18253

    			SELECT ca.party_id into l_party_id
    			FROM hz_cust_accounts ca
    			WHERE ca.cust_account_id = l_object_id;
Line: 18283

    			select location_id into l_location_id
    			from ast_locations_v
    			where party_id = l_party_id
    			AND primary_flag = 'Y';
Line: 18379

    Procedure INSERT_DUNNING_TRANSACTION
               (p_api_version             IN NUMBER := 1.0,
                p_init_msg_list           IN VARCHAR2 ,
                p_commit                  IN VARCHAR2 ,
                p_delinquencies_tbl       IN IEX_DELINQUENCY_PUB.DELINQUENCY_TBL_TYPE,
    	        p_dunning_id	          IN NUMBER,
    	        p_correspondence_date     IN DATE,
    	        p_ag_dn_xref_id           IN NUMBER ,
                p_running_level           IN VARCHAR2,
    	        p_grace_days              IN NUMBER,
    	        p_include_dispute_items   IN VARCHAR2 ,
    	        x_return_status           OUT NOCOPY VARCHAR2,
                x_msg_count               OUT NOCOPY NUMBER,
                x_msg_data                OUT NOCOPY VARCHAR2
                ,p_workitem_id            IN  NUMBER)  -- bug 14772139
    IS
        l_api_name                    CONSTANT VARCHAR2(30) := 'Inser_dunning_transaction';
Line: 18421

        select nvl(dunn.include_current ,'N'),
               nvl(dunn.include_unused_payments_flag,'N')
        from iex_ag_dn_xref xref,
             iex_dunning_plans_b dunn
        where AG_DN_XREF_ID = p_ag_dn_xref_id
        and xref.dunning_plan_id = dunn.dunning_plan_id;
Line: 18437

          SAVEPOINT INSERT_DUNNING_TRANSACTION_PVT;
Line: 18471

                select nvl(b.INCLUDE_CURRENT,'N') ,nvl(INCLUDE_UNUSED_PAYMENTS_FLAG,'N')
                       into l_include_curr_inv, l_include_unapp_rec
                  from iex_strategy_work_items a, IEX_STRY_TEMP_WORK_ITEMS_VL b
                  where a.work_item_template_id = b.work_item_temp_id
                    and a.work_item_id = p_workitem_id -- p_grace_days -- indicating workitem Id when p_ag_dn_xref_id is 0 from iexpstmb.pls
                    and b.work_type in ('AUTOMATIC','WORKFLOW');  -- bug 14772139
Line: 18511

    	  vPLSQL := 'select  del.delinquency_id, ' ||
    	            '        del.transaction_id, ' ||
    	            '        del.payment_schedule_id ' ||
    		    '    from iex_delinquencies del, ' ||
    		    '	      ar_payment_schedules arp ' ||
    		    '    where del.payment_schedule_id = arp.payment_schedule_id ' ||
     		    '    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    		    -- '    and del.staged_dunning_level is NULL ' || commented to fix 12621875 snuthala 6/6/2011
    		    '    and (trunc(arp.due_date) + :p_gra_days) <= :p_corr_date ' ||
    		    '    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';  -- bug 14772139
Line: 18530

    					   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    					   '	FROM hz_cust_profile_amts '||
    					   '	WHERE site_use_id  IS NULL '||
    					   '	AND cust_account_id = arp.customer_id '||
    					   '	AND currency_code   = arp.invoice_currency_code),0) '||
    				           '    order by del.payment_schedule_id';
Line: 18540

    				           '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    					   '	from hz_cust_profile_amts '||
    					   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    					   '	and currency_code = arp.invoice_currency_code),0) '||
    				           '    order by del.payment_schedule_id';
Line: 18562

    	      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 18567

    	      IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => p_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    					, p_stage_number                    => -1
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0);
Line: 18590

    	      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    	      x_dunning_trx_id	:= null;
Line: 18598

    		       vPLSQL := 'select  del.delinquency_id, ' ||
   	                         '        del.transaction_id, ' ||
    				 '        del.payment_schedule_id ' ||
    				 '    from iex_delinquencies del, ' ||
    				 '	 ar_payment_schedules arp ' ||
    				 '    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    				 '    and del.status in (''DELINQUENT'',''PREDELINQUENT'') ' ||
    			       --'    and del.staged_dunning_level is NULL ' || commented to fix 12621875 snuthala 6/6/2011
    			         '    and (trunc(arp.due_date) + 0) <= :p_corr_date ' ||
    				 '    and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ';
Line: 18616

    						   '	(SELECT NVL(min(min_dunning_invoice_amount),0) '||
    						   '	FROM hz_cust_profile_amts '||
    						   '	WHERE site_use_id  IS NULL '||
    						   '	AND cust_account_id = arp.customer_id '||
    						   '	AND currency_code   = arp.invoice_currency_code),0) ';
Line: 18626

    						   '    and arp.amount_due_remaining >= nvl ((select nvl(min(min_dunning_invoice_amount),0) '||
    						   '	from hz_cust_profile_amts '||
    						   '	where site_use_id =  arp.CUSTOMER_SITE_USE_ID '||
    						   '	and currency_code = arp.invoice_currency_code),0) ';
Line: 18636

	                --    start  added  12/23/2011 fix 13519242 to stop inserting duplicate rows
			vPLSQL3 := vPLSQL3 ||  '   and not exists (select 1 from iex_dunning_transactions dun_trx '||
			                        '   where dun_trx.payment_schedule_id = del.payment_schedule_id '||
					        '   and dun_trx.dunning_id = :p_dunning_id ) ' ||
    					        '    order by del.payment_schedule_id';
Line: 18653

    			   WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 18658

    			   IEX_Dunnings_PKG.insert_staged_dunning_row(
    						  px_rowid                          => l_rowid
    						, px_dunning_trx_id                 => x_dunning_trx_id
    						, p_dunning_id                      => p_dunning_id
    						, p_cust_trx_id                     => l_transaction_id
    						, p_payment_schedule_id             => l_payment_schedule_id
    						, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    						, p_stage_number                    => 0
    						, p_created_by                      => FND_GLOBAL.USER_ID
    						, p_creation_date                   => sysdate
    						, p_last_updated_by                 => FND_GLOBAL.USER_ID
    						, p_last_update_date                => sysdate
    						, p_last_update_login               => FND_GLOBAL.USER_ID
    						, p_object_version_number	    => 1.0
    					      );
Line: 18682

    		            --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    			    x_dunning_trx_id	:= null;
Line: 18692

                                'select del.delinquency_id, ' ||
    			        '       del.transaction_id, ' ||
    			        '       del.payment_schedule_id  ' ||
    				'    from iex_delinquencies del,  ar_payment_schedules arp ' ||
    				'    where del.payment_schedule_id = arp.payment_schedule_id ' ||
    				'      and del.status = ''CURRENT'' ' ||
    		--		'      and del.staged_dunning_level is NULL ' ||  -- commented for bug#15932721 schekuri 30-Nov-12
    				'      and arp.status = ''OP'' ' ||
    				-- '   and arp.class = ''INV'' ' ||  -- Bills Receivables
                                '      and (arp.class = ''INV'' or arp.class = ''BR'') ' ||   -- Bills Receivables
    			        '      and (trunc(arp.due_date) + :p_gra_days) <= :p_corr_date ' ||   -- Bills Receivables
    				'      and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ;
Line: 18727

    		      WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - InsertRow');
Line: 18732

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    					  px_rowid                          => l_rowid
    					, px_dunning_trx_id                 => x_dunning_trx_id
    					, p_dunning_id                      => p_dunning_id
    					, p_cust_trx_id                     => l_transaction_id
    					, p_payment_schedule_id             => l_payment_schedule_id
    					, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    					, p_stage_number                    => -1  --changed by schekuri bug#15932721
    					, p_created_by                      => FND_GLOBAL.USER_ID
    					, p_creation_date                   => sysdate
    					, p_last_updated_by                 => FND_GLOBAL.USER_ID
    					, p_last_update_date                => sysdate
    					, p_last_update_login               => FND_GLOBAL.USER_ID
    					, p_object_version_number	    => 1.0
    				      );
Line: 18756

    				      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    				      x_dunning_trx_id	:= null;
Line: 18766

          WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert current invoices');
Line: 18772

    	        WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Start insert current invoices');
Line: 18775

    			vPLSQL2 := 'select arp.customer_trx_id, ' ||
    				'	   arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp, hz_cust_accounts hca ' ||
    				'    where arp.customer_id = hca.cust_account_id ' ||
    				'      and hca.party_id = :p_party_id ' ||
    			--	'      and trunc(arp.due_date) > trunc(:p_corr_date) ' ||
    				'      and arp.status = ''OP'' ' ||
    				'      and arp.amount_due_remaining <> 0 ' ||
    				--'    and arp.class = ''INV'' ' ||     -- Bills Receivables
                                '      and (arp.class = ''INV'' or arp.class = ''BR'') ' ||   -- Bills Receivables
    				'      and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'      and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ||
                                '      and not exists (select 1 from iex_dunning_transactions dun_trx  where dun_trx.payment_schedule_id = arp.payment_schedule_id and dun_trx.dunning_id = :p_dunning_id ) ' || -- added by a bug 15932721
    				'    order by arp.payment_schedule_id';
Line: 18790

    		      vPLSQL2 := 'select arp.customer_trx_id, ' ||
    				'        arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp ' ||
    				'    where arp.customer_id = :p_cust_acct_id ' ||
    				--'    and trunc(arp.due_date) > trunc(:p_corr_date) ' ||
    				'      and arp.status = ''OP'' ' ||
    				'      and arp.amount_due_remaining <> 0 ' ||
    				--'    and arp.class = ''INV'' ' ||     -- Bills Receivables
                                '      and (arp.class = ''INV'' or arp.class = ''BR'') ' ||   -- Bills Receivables
    				'      and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'      and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ||
                                '      and not exists (select 1 from iex_dunning_transactions dun_trx  where dun_trx.payment_schedule_id = arp.payment_schedule_id and dun_trx.dunning_id = :p_dunning_id ) ' ||  -- added by a bug 15932721
    				'    order by arp.payment_schedule_id';
Line: 18804

    		      vPLSQL2 := 'select arp.customer_trx_id, ' ||
    				'	 arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp ' ||
    				'    where arp.customer_site_use_id = :p_site_use_id ' ||
    				--'    and trunc(arp.due_date) > trunc(:p_corr_date) ' ||
    				'      and arp.status = ''OP'' ' ||
    				'      and arp.amount_due_remaining <> 0 ' ||
    				--'    and arp.class = ''INV'' ' ||     -- Bills Receivables
                                '      and (arp.class = ''INV'' or arp.class = ''BR'') ' ||   -- Bills Receivables
    				'      and nvl(arp.amount_in_dispute,0) = decode(:p_include_dis_items, ''Y'', nvl(arp.amount_in_dispute,0), 0) ' ||
    				'      and not exists (select 1 from iex_delinquencies del where del.payment_schedule_id = arp.payment_schedule_id and del.status <> ''CURRENT'' ) ' ||
                                '      and not exists (select 1 from iex_dunning_transactions dun_trx  where dun_trx.payment_schedule_id = arp.payment_schedule_id and dun_trx.dunning_id = :p_dunning_id ) ' ||  -- added by a bug 15932721
    				'    order by arp.payment_schedule_id';
Line: 18832

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    			  px_rowid                          => l_rowid
    			, px_dunning_trx_id                 => x_dunning_trx_id
    			, p_dunning_id                      => p_dunning_id
    			, p_cust_trx_id                     => l_customer_trx_id
    			, p_payment_schedule_id             => l_payment_schedule_id
    			, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    			, p_stage_number                    => 0
    			, p_created_by                      => FND_GLOBAL.USER_ID
    			, p_creation_date                   => sysdate
    			, p_last_updated_by                 => FND_GLOBAL.USER_ID
    			, p_last_update_date                => sysdate
    			, p_last_update_login               => FND_GLOBAL.USER_ID
    			, p_object_version_number	    => 1.0
    		      );
Line: 18856

    		      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    		      x_dunning_trx_id	:= null;
Line: 18864

    	           WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - End insert current invoices');
Line: 18868

       WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Insert unapplied receipts and On Account Credit memos');
Line: 18873

          	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Start insert unapplied receipts');
Line: 18876

    			vPLSQL2 := 'select arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp, ' ||
    				'         hz_cust_accounts hca ' ||
    				'    where arp.customer_id = hca.cust_account_id ' ||
    				'    and hca.party_id = :p_party_id ' ||
    				'    and arp.status = ''OP'' ' ||
    			        '    and arp.amount_due_remaining <> 0 ' ||
    			        '    and arp.class = ''PMT'' ' ||
    			        '    order by arp.payment_schedule_id';
Line: 18886

    		      vPLSQL2 := 'select arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    ' where arp.customer_id = :p_cust_acct_id ' ||
    				    ' and arp.status = ''OP'' ' ||
    				    ' and arp.amount_due_remaining <> 0 ' ||
    				    ' and arp.class = ''PMT'' ' ||
    				    ' order by arp.payment_schedule_id';
Line: 18894

    		      vPLSQL2 := 'select arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    ' where arp.customer_site_use_id = :p_site_use_id ' ||
    				    ' and arp.status = ''OP'' ' ||
    				    ' and arp.amount_due_remaining <> 0 ' ||
    				    ' and arp.class = ''PMT'' ' ||
    				    ' order by arp.payment_schedule_id';
Line: 18912

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    			  px_rowid                          => l_rowid
    			, px_dunning_trx_id                 => x_dunning_trx_id
    			, p_dunning_id                      => p_dunning_id
    			--, p_cust_trx_id                     => l_customer_trx_id
    			, p_payment_schedule_id             => l_payment_schedule_id
    			, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    			, p_stage_number                    => null
    			, p_created_by                      => FND_GLOBAL.USER_ID
    			, p_creation_date                   => sysdate
    			, p_last_updated_by                 => FND_GLOBAL.USER_ID
    			, p_last_update_date                => sysdate
    			, p_last_update_login               => FND_GLOBAL.USER_ID
    			, p_object_version_number	    => 1.0
    		      );
Line: 18936

    		      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    		      x_dunning_trx_id	:= null;
Line: 18942

    	           WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - End insert unapplied receipts');
Line: 18944

        	WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - Start insert On Account Credit memos');
Line: 18947

    			vPLSQL2 := 'select arp.customer_trx_id customer_trx_id, ' ||
    			        '          arp.payment_schedule_id ' ||
    				'    from ar_payment_schedules arp, ' ||
    				'         hz_cust_accounts hca ' ||
    				'    where arp.customer_id = hca.cust_account_id ' ||
    				'    and hca.party_id = :p_party_id ' ||
    				'    and arp.amount_due_remaining <> 0 ' ||
    				'    and arp.class =''CM'' ' ||
    				'    and arp.status=''OP'' ';
Line: 18957

    		      vPLSQL2 := 'select arp.customer_trx_id customer_trx_id, ' ||
    			            '    arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    ' where arp.customer_id = :p_cust_acct_id ' ||
    				    '    and arp.amount_due_remaining <> 0 ' ||
    				    '    and arp.class =''CM'' ' ||
    				    '    and arp.status=''OP'' ';
Line: 18965

    		      vPLSQL2 := 'select arp.customer_trx_id customer_trx_id, ' ||
    			            '    arp.payment_schedule_id ' ||
    				    ' from ar_payment_schedules arp ' ||
    				    ' where arp.customer_site_use_id = :p_site_use_id ' ||
    				    '    and arp.amount_due_remaining <> 0 ' ||
    				    '    and arp.class =''CM'' ' ||
    				    '    and arp.status=''OP'' ';
Line: 18984

    		      IEX_Dunnings_PKG.insert_staged_dunning_row(
    			  px_rowid                          => l_rowid
    			, px_dunning_trx_id                 => x_dunning_trx_id
    			, p_dunning_id                      => p_dunning_id
    			, p_cust_trx_id                     => l_customer_trx_id
    			, p_payment_schedule_id             => l_payment_schedule_id
    			, p_ag_dn_xref_id                   => p_ag_dn_xref_id
    			, p_stage_number                    => null
    			, p_created_by                      => FND_GLOBAL.USER_ID
    			, p_creation_date                   => sysdate
    			, p_last_updated_by                 => FND_GLOBAL.USER_ID
    			, p_last_update_date                => sysdate
    			, p_last_update_login               => FND_GLOBAL.USER_ID
    			, p_object_version_number	    => 1.0
    		      );
Line: 19008

    		      --reset the x_dunning_trx_id, so that will get new no when inserting 2nd record.
    		      x_dunning_trx_id	:= null;
Line: 19017

    	        WriteLog(G_PKG_NAME || ' ' || l_api_name || ' - End insert On Account Credit memos');
Line: 19042

                  ROLLBACK TO INSERT_DUNNING_TRANSACTION_PVT;
Line: 19050

                  ROLLBACK TO INSERT_DUNNING_TRANSACTION_PVT;
Line: 19058

                  ROLLBACK TO INSERT_DUNNING_TRANSACTION_PVT;
Line: 19061

    END INSERT_DUNNING_TRANSACTION;