DBA Data[Home] [Help]

PACKAGE BODY: APPS.ISC_FS_TASK_PARTY_MERGE_PKG

Source


1 package body isc_fs_task_party_merge_pkg
2 /* $Header: iscfshzmgb.pls 120.0 2005/08/28 14:57:32 kreardon noship $ */
3 as
4 
5 procedure task_merge_party
6 ( p_entity_name        in varchar2
7 , p_from_id            in number
8 , x_to_id              out nocopy number
9 , p_from_fk_id         in number
10 , p_to_fk_id           in number
11 , p_parent_entity_name in varchar2
12 , p_batch_id           in number
13 , p_batch_party_id     in number
14 , x_return_status      out nocopy varchar2
15 ) is
16 
17 l_merge_reason_code  varchar2(30);
18 
19  cursor c_duplicate is
20    select merge_reason_code
21    from hz_merge_batch
22    where batch_id = p_batch_id;
23 
24 begin
25 
26   x_return_status := FND_API.G_RET_STS_SUCCESS;
27 
28   -- only bother with attempting merge if events are enabled (CSF-DBI implemented)
29   if isc_fs_event_log_etl_pkg.check_events_enabled <> 'Y' then
30     return;
31   end if;
32 
33   open c_duplicate;
34   fetch c_duplicate into l_merge_reason_code;
35   close c_duplicate;
36 
37   if l_merge_reason_code <> 'DUPLICATE' then
38 
39       -- if there are any validations to be done, include it in this section
40       -- if reason code is duplicate then allow the party merge to happen without
41       -- any validations.
42 
43       null;
44 
45   end if;
46 
47   -- perform the merge operation
48 
49   -- if the parent has NOT changed(i.e. parent  getting transferred)  then nothing
50   -- needs to be done. Set merged to id (x_to_id) the same as merged from id and return
51 
52   if p_from_fk_id = p_to_fk_id  then
53 
54       x_to_id := p_from_id;
55       return;
56 
57   end if;
58 
59 
60   -- If the parent has changed(ie. Parent is getting merged) then transfer the
61   -- dependent record to the new parent.
62   -- For ISC_FS_TASKS_F table, if party_id 1000 got merged to party_id 2000
63   -- then we have to insert an event row for each task.  When the incremental
64   -- load is next run it will capture the "current" (party_id 2000) data from JTF_TASKS_B
65 
66   insert into isc_fs_party_merge_events
67   ( send_date
68   , event_name
69   , source_object_type_code
70   , source_object_id
71   , task_id
72   , created_by
73   , creation_date
74   , last_updated_by
75   , last_update_date
76   , last_update_login
77   )
78   select
79     hz_utility_pub.last_update_date
80   , 'task_merge_party'
81   , 'SR'
82   , source_object_id
83   , task_id
84   , hz_utility_pub.user_id
85   , hz_utility_pub.last_update_date
86   , hz_utility_pub.user_id
87   , hz_utility_pub.last_update_date
88   , hz_utility_pub.last_update_login
89   from
90     isc_fs_tasks_f
91   where customer_id = p_from_fk_id;
92 
93 exception
94   when others then
95     fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
96     fnd_message.set_token('ERROR' ,SQLERRM);
97     fnd_msg_pub.add;
98     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
99 
100 end task_merge_party;
101 
102 procedure task_merge_address
103 ( p_entity_name        in varchar2
104 , p_from_id            in number
105 , x_to_id              out nocopy number
106 , p_from_fk_id         in number
107 , p_to_fk_id           in number
108 , p_parent_entity_name in varchar2
109 , p_batch_id           in number
110 , p_batch_party_id     in number
111 , x_return_status      out nocopy varchar2
112 ) is
113 
114   l_merge_reason_code  varchar2(30);
115 
116  cursor c_duplicate is
117    select merge_reason_code
118    from hz_merge_batch
119    where batch_id = p_batch_id;
120 
121 begin
122 
123   x_return_status := FND_API.G_RET_STS_SUCCESS;
124 
125   -- only bother with attempting merge if events are enabled (CSF-DBI implemented)
126   if isc_fs_event_log_etl_pkg.check_events_enabled <> 'Y' then
127     return;
128   end if;
129 
130   open    c_duplicate;
131   fetch   c_duplicate into l_merge_reason_code;
132   close   c_duplicate;
133 
134   if l_merge_reason_code <> 'DUPLICATE' then
135 
136       -- if there are any validations to be done, include it in this section
137       -- if reason code is duplicate then allow the party merge to happen without
138       -- any validations.
139 
140       null;
141 
142   end if;
143 
144   -- perform the merge operation
145 
146   -- if the parent has NOT changed(i.e. parent  getting transferred)  then nothing
147   -- needs to be done. Set merged to id (x_to_id) the same as merged from id and return
148   -- If the party_site has been transferred then nothing should be done.
149 
150   if p_from_fk_id = p_to_fk_id  then
151 
152     x_to_id := p_from_id;
153     return;
154 
155   end if;
156 
157 
158   -- If the parent has changed(ie. Parent is getting merged) then transfer the
159   -- dependent record to the new parent.
160   -- For ISC_FS_TASKS_F table, if party_site_id 1111 got merged to party_site_id 2222
161   -- then we have to insert an event row for each task.  When the incremental
162   -- load is next run it will capture the "current" (party_site_id 2222) data from JTF_TASKS_B
163 
164   insert into isc_fs_party_merge_events
165   ( send_date
166   , event_name
167   , source_object_type_code
168   , source_object_id
169   , task_id
170   , created_by
171   , creation_date
172   , last_updated_by
173   , last_update_date
174   , last_update_login
175   )
176   select
177     hz_utility_pub.last_update_date
178   , 'task_merge_address'
179   , 'SR'
180   , source_object_id
181   , task_id
182   , hz_utility_pub.user_id
183   , hz_utility_pub.last_update_date
184   , hz_utility_pub.user_id
185   , hz_utility_pub.last_update_date
186   , hz_utility_pub.last_update_login
187   from
188     isc_fs_tasks_f
189   where address_id = p_from_fk_id;
190 
191 exception
192   when others then
193     fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
194     fnd_message.set_token('ERROR' ,SQLERRM);
195     fnd_msg_pub.add;
196     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
197 
198 end task_merge_address;
199 
200 end isc_fs_task_party_merge_pkg;