DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_TRANSFER_PUB

Source


1 PACKAGE BODY FA_TRANSFER_PUB AS
2 /* $Header: FAPTFRB.pls 120.9.12010000.2 2008/07/31 07:28:34 sbhaskar ship $   */
3 
4 G_PKG_NAME CONSTANT VARCHAR2(30) := 'FA_TRANSFER_PUB';
5 g_log_level_rec fa_api_types.log_level_rec_type;
6 
7 FUNCTION valid_input(px_trans_rec     IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
8                      p_asset_hdr_rec  IN     FA_API_TYPES.asset_hdr_rec_type,
9                      p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null)
10                 RETURN BOOLEAN;
11 
12 PROCEDURE do_transfer(p_api_version         IN     NUMBER,
13      		      p_init_msg_list       IN     VARCHAR2 := FND_API.G_FALSE,
14     		      p_commit              IN     VARCHAR2 := FND_API.G_FALSE,
15      		      p_validation_level    IN     NUMBER   := FND_API.G_VALID_LEVEL_FULL,
16                       p_calling_fn          IN     VARCHAR2,
17                       x_return_status       OUT NOCOPY    VARCHAR2,
18                       x_msg_count           OUT NOCOPY    NUMBER,
19                       x_msg_data            OUT NOCOPY    VARCHAR2,
20 		      px_trans_rec          IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
21                       px_asset_hdr_rec      IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
22 		      px_asset_dist_tbl     IN OUT NOCOPY FA_API_TYPES.asset_dist_tbl_type)
23 
24 IS
25 
26    l_api_version   CONSTANT NUMBER := 1.0;
27    l_api_name      CONSTANT VARCHAR2(30) := 'TRANSFER API';
28 
29    -- Bug 5475276 Cursor to get the book_type_code
30    CURSOR c_corp_book( p_asset_id number ) IS
31         SELECT bc.book_type_code
32           FROM fa_books bks,
33                fa_book_controls bc
34          WHERE bks.book_type_code = bc.distribution_source_book
35            AND bks.book_type_code = bc.book_type_code
36            AND bks.asset_id       = p_asset_id
37            AND bks.transaction_header_id_out is null;
38 
39    l_period_addition varchar2(1);
40    l_asset_cat_rec FA_API_TYPES.asset_cat_rec_type;
41 
42 BEGIN
43 
44      SAVEPOINT transfer_pub;
45 
46    if (not g_log_level_rec.initialized) then
47       if (NOT fa_util_pub.get_log_level_rec (
48                 x_log_level_rec =>  g_log_level_rec
49       )) then
50          raise FND_API.G_EXC_ERROR;
51       end if;
52    end if;
53 
54 
55      IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version,
56                                         l_api_name, G_PKG_NAME) then
57                 RAISE   FND_API.G_EXC_ERROR;
58      END IF;
59 
60      if (p_init_msg_list = FND_API.G_TRUE) then
61          fa_srvr_msg.Init_Server_Message;
62          fa_debug_pkg.Initialize;
63      end if;
64 
65      if (px_asset_hdr_rec.asset_id is null) then
66             fa_srvr_msg.add_message(
67                         calling_fn => 'FA_TRANSFER_PUB.do_transfer',
68                         name       => 'FA_SHARED_ITEM_NULL',
69                         token1     => 'ITEM',
70                         value1     => 'Asset Id'
71                         ,p_log_level_rec => g_log_level_rec);
72 	    raise FND_API.G_EXC_ERROR;
73      end if;
74 
75      -- Bug 5475276 Get the book_type_code if it is not supplied.
76      if (px_asset_hdr_rec.book_type_code is null) then
77 
78         open c_corp_book( px_asset_hdr_rec.asset_id );
79         fetch c_corp_book into px_asset_hdr_rec.book_type_code;
80         close c_corp_book;
81 
82         if px_asset_hdr_rec.book_type_code is null then
83          fa_srvr_msg.add_message
84              (calling_fn => 'FA_TRANSFER_PUB.do_transfer',
85               name       => 'FA_EXP_GET_ASSET_INFO'
86               ,p_log_level_rec => g_log_level_rec);
87            raise FND_API.G_EXC_ERROR;
88         end if;
89      end if;
90 
91      -- call the cache for the primary transaction book
92      if NOT fa_cache_pkg.fazcbc(X_book => px_asset_hdr_rec.book_type_code
93   ,p_log_level_rec => g_log_level_rec) then
94          RAISE FND_API.G_EXC_ERROR;
95      end if;
96 
97      -- validate book is corporate and enabled and asset exists in book
98 
99      if not fa_asset_val_pvt.validate_asset_book
100             (p_transaction_type_code  => 'TRANSFER',
101              p_book_type_code         => px_asset_hdr_rec.book_type_code,
102              p_asset_id               => px_asset_hdr_rec.asset_id,
103              p_calling_fn             => 'FA_TRANSFER_PUB.do_transfer',
104              p_log_level_rec          => g_log_level_rec) then
105         raise FND_API.G_EXC_ERROR;
106      end if;
107 
108      px_trans_rec.transaction_type_code := 'TRANSFER';
109      IF NOT FA_TRX_APPROVAL_PKG.faxcat(
110                         X_book          =>px_asset_hdr_rec.book_type_code,
111                         X_asset_id      =>px_asset_hdr_rec.asset_id,
112                         X_trx_type      =>px_trans_rec.transaction_type_code,
113                         X_trx_date      =>px_trans_rec.transaction_date_entered,
114                         X_init_message_flag=> 'NO',
115                         p_log_level_rec          => g_log_level_rec) then
116         raise FND_API.G_EXC_ERROR;
117      end if;
118 
119      if not fa_asset_val_pvt.validate_period_of_addition
120                                 (px_asset_hdr_rec.asset_id,
121                                  px_asset_hdr_rec.book_type_code,
122                                  'ABSOLUTE',
123                                  l_period_addition,
124                                  p_log_level_rec          => g_log_level_rec) then
125          RAISE   FND_API.G_EXC_ERROR;
126      end if;
127      px_asset_hdr_rec.period_of_addition := l_period_addition;
128 
129      -- validate input
130      if not valid_input(px_trans_rec,
131                         px_asset_hdr_rec,
132                         p_log_level_rec          => g_log_level_rec) then
133         raise FND_API.G_EXC_ERROR;
134      end if;
135 
136      -- BUG# 3325400
137      -- forcing selection of the thid here rather
138      -- then relying on table handler
139      select fa_transaction_headers_s.nextval
140        into px_trans_rec.transaction_header_id
141        from dual;
142 
143      if not FA_DISTRIBUTION_PVT.do_distribution(
144                         px_trans_rec          => px_trans_rec,
145                         px_asset_hdr_rec      => px_asset_hdr_rec,
146                         px_asset_cat_rec_new  => l_asset_cat_rec,
147                         px_asset_dist_tbl     => px_asset_dist_tbl,
148                         p_validation_level    => p_validation_level,
149                         p_log_level_rec          => g_log_level_rec) then
150         raise FND_API.G_EXC_ERROR;
151      end if;
152 
153      /*
154       * Code hook for IAC
155       */
156      if (FA_IGI_EXT_PKG.IAC_Enabled) then
157         if not FA_IGI_EXT_PKG.Do_Transfer(
158                         p_trans_rec         => px_trans_rec,
159                         p_asset_hdr_rec     => px_asset_hdr_rec,
160                         p_asset_cat_rec     => l_asset_cat_rec,
161                         p_calling_function  =>'FA_TRANSFER_PUB.Do_Transfer') then
162            raise FND_API.G_EXC_ERROR;
163         end if;
164      end if; -- (FA_IGI_EXT_PKG.IAC_Enabled)
165 
166      -- call to workflow business event
167 
168      fa_business_events.raise(
169 		 p_event_name => 'oracle.apps.fa.transfer.asset.transfer',
170                  p_event_key => px_asset_hdr_rec.asset_id || to_char(sysdate,'RRDDDSSSSS'),
171                  p_parameter_name1 => 'ASSET_ID',
172                  p_parameter_value1 => px_asset_hdr_rec.asset_id,
173                  p_parameter_name2 => 'BOOK_TYPE_CODE',
174                  p_parameter_value2 => px_asset_hdr_rec.book_type_code);
175 
176      if cse_fa_integration_grp.is_oat_enabled then
177         if not cse_fa_integration_grp.transfer(
178                              p_trans_rec      =>  px_trans_rec,
179                              p_asset_hdr_rec  =>  px_asset_hdr_rec,
180                              p_asset_dist_tbl =>  px_asset_dist_tbl) then
181            raise FND_API.G_EXC_ERROR;
182         end if;
183      end if;
184 
185 
186      if (p_commit = FND_API.G_TRUE) then
187           COMMIT WORK;
188      end if;
189 /*
190         -- Return the status.
191      FA_SRVR_MSG.Add_Message(
192              calling_fn => 'FA_TRANSFER_PUB.do_transfer',
193              name       => 'FA_SHARED_END_SUCCESS',
194              token1     => 'PROGRAM',
195              value1     => 'FA_TRANSFER_PUB.do_transfer'
196              ,p_log_level_rec => g_log_level_rec); */
197 
198      FND_MSG_PUB.Count_And_Get(
199                        p_count => x_msg_count,
200                        p_data => x_msg_data
201                        );
202 
203      x_return_status := FND_API.G_RET_STS_SUCCESS;
204 
205 
206 EXCEPTION
207      WHEN FND_API.G_EXC_ERROR THEN
208         FA_SRVR_MSG.Add_Message(
209 		calling_fn => 'FA_TRANSFER_PUB.do_transfer'
210 		,p_log_level_rec => g_log_level_rec);
211 
212         FND_MSG_PUB.Count_And_Get(
213                 p_count => x_msg_count,
214                 p_data => x_msg_data
215                 );
216         ROLLBACK TO transfer_pub;
217         x_return_status := FND_API.G_RET_STS_ERROR;
218 
219      WHEN OTHERS THEN
220         FA_SRVR_MSG.add_sql_error(
221                 calling_fn => 'FA_TRANSFER_PUB.do_transfer'
222                 ,p_log_level_rec => g_log_level_rec);
223 
224         FND_MSG_PUB.Count_And_Get(
225                 p_count => x_msg_count,
226                 p_data => x_msg_data
227                 );
228         ROLLBACK TO transfer_pub;
229         x_return_status := FND_API.G_RET_STS_ERROR;
230 
231 END;
232 
233 FUNCTION valid_input(px_trans_rec     IN OUT NOCOPY fa_api_types.trans_rec_type,
234                      p_asset_hdr_rec  IN     fa_api_types.asset_hdr_rec_type,
235                      p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null)
236 RETURN BOOLEAN IS
237 
238    l_fiscal_year_name varchar2(30);
239    l_fiscal_year     number;
240    l_fy_start_date   date;
241    l_fy_end_date     date;
242    l_count           number;
243    l_max_transaction_date   date;
244    l_period_rec      FA_API_TYPES.period_rec_type;
245    l_override_flag   varchar2(1);
246    l_transaction_date date;
247 
248 BEGIN
249 
250      -- check if asset is attached to hierarchy and see if it can
251      -- be override to proceed with normal transfer
252      if (nvl(fnd_profile.value('CRL-FA ENABLED'), 'N') = 'Y') then
253         if (not fa_cua_asset_APIS.check_override_allowed(
254                       p_attribute_name => 'DISTRIBUTION',
255                       p_book_type_code => p_asset_hdr_rec.book_type_code,
256                       p_asset_id => p_asset_hdr_rec.asset_id,
257                       x_override_flag => l_override_flag)) then
258            fa_srvr_msg.add_message(
259                       calling_fn => 'FA_TRANSFER_PUB.valid_input'
260                       ,p_log_level_rec => p_log_level_rec);
261            return FALSE;
262         end if;
263         -- if override flag is set to No, do not allow the transfer
264         if (l_override_flag = 'N') then
265            fa_srvr_msg.add_message(
266                       calling_fn => 'FA_TRANSFER_PUB.valid_input',
267                       name => 'CUA_NO_DIST_CHANGE_ALLOWED',
268                       p_log_level_rec          => p_log_level_rec);
269            return FALSE;
270         end if;
271      end if;
272 
273      -- check if asset is fully retired
274      if FA_ASSET_VAL_PVT.validate_fully_retired(p_asset_hdr_rec.asset_id,
275 			       p_asset_hdr_rec.book_type_code,
276                                p_log_level_rec          => p_log_level_rec) then
277          fa_srvr_msg.add_message(
278              calling_fn      => 'FA_TRANSFER_PUB.valid_input',
279              Name            => 'FA_REC_RETIRED',
280              p_log_level_rec          => p_log_level_rec);
281              return FALSE;
282      end if;
283 
284      if not FA_UTIL_PVT.get_period_rec
285               (p_book       => p_asset_hdr_rec.book_type_code,
286                x_period_rec => l_period_rec,
287                p_log_level_rec          => p_log_level_rec) then
288         return FALSE;
289      end if;
290 
291      if (px_trans_rec.transaction_date_entered is null or
292          p_asset_hdr_rec.period_of_addition = 'Y') then
293          l_transaction_date :=
294                           greatest(l_period_rec.calendar_period_open_date,
295                           least(sysdate,l_period_rec.calendar_period_close_date));
296          px_trans_rec.transaction_date_entered :=
297                to_date(to_char(l_transaction_date,'DD/MM/YYYY'),'DD/MM/YYYY');
298      else
299         if not fa_cache_pkg.fazcbc (X_book => p_asset_hdr_rec.book_type_code,
300                                     p_log_level_rec          => p_log_level_rec) then
301            fa_srvr_msg.add_message( calling_fn => 'FA_TRANSFER_PUB.valid_input',
302                                     p_log_level_rec          => p_log_level_rec);
303            return FALSE;
304         else
305            l_fiscal_year_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
306            l_fiscal_year      := fa_cache_pkg.fazcbc_record.current_fiscal_year;
307         end if;
308 
309         select start_date, end_date
310         into l_fy_start_Date, l_fy_end_date
311         from fa_fiscal_year
312         where fiscal_year = l_fiscal_year
313         and fiscal_year_name = l_fiscal_year_name;
314 
315         if not FA_UTIL_PVT.get_latest_trans_date('FA_TRANSFER_PUB.valid_input',
316 						  p_asset_hdr_rec.asset_id,
317 						  p_asset_hdr_rec.book_type_code,
318 						  l_max_transaction_date,
319                                                   p_log_level_rec          => p_log_level_rec) then
320            return FALSE;
321         end if;
322 
323         if (px_trans_rec.transaction_date_entered <l_fy_start_date or
324             px_trans_rec.transaction_date_entered > l_fy_end_date) then
325             fa_srvr_msg.add_message(
326 			calling_fn => 'FA_TRANSFER_PUB.valid_input',
327 			name       => 'FA_RET_DATE_MUSTBE_IN_CUR_FY',
328                         p_log_level_rec          => p_log_level_rec);
329             return FALSE;
330         end if;
331 
332         if (px_trans_rec.transaction_date_entered > l_period_rec.calendar_period_close_date) then
333            fa_srvr_msg.add_message(
334                         calling_fn => 'FA_TRANSFER_PUB.valid_input',
335                         name       => 'FA_SHARED_CANNOT_FUTURE',
336                         p_log_level_rec          => p_log_level_rec);
337            return FALSE;
338         end if;
339 
340         if (px_trans_rec.transaction_date_entered < l_max_transaction_date) then
341            fa_srvr_msg.add_message(
342                         calling_fn => 'FA_TRANSFER_PUB.valid_input',
343                         name       => 'FA_SHARED_OTHER_TRX_FOLLOW',
344                         p_log_level_rec          => p_log_level_rec);
345            return FALSE;
346         end if;
347 
348         if (px_trans_rec.transaction_date_entered <to_date('1000/01/01', 'YYYY/MM/DD')) then
349            fa_srvr_msg.add_message(
350                         calling_fn => 'FA_TRANSFER_PUB.valid_input',
351                         name       => 'FA_YEAR_GREATER_THAN',
352                         p_log_level_rec          => p_log_level_rec);
353            return FALSE;
354         end if;
355 
356      -- check that only one prior period transfer is allowed in the same period
357 
358         SELECT count(1)
359         INTO   l_count
360         FROM   FA_TRANSACTION_HEADERS th,
361                FA_DEPRN_PERIODS dp
362         WHERE  th.asset_id = nvl(p_asset_hdr_rec.asset_id, -1)
363         AND    th.book_type_code = nvl(p_asset_hdr_rec.book_type_code,'XX')
364         AND    th.transaction_type_code||'' = 'TRANSFER'
365         AND    th.transaction_date_entered < dp.calendar_period_open_date
366         AND    th.date_effective > dp.period_open_date
367         AND    px_trans_rec.transaction_date_entered <
368                 		dp.calendar_period_open_date
369         AND    dp.book_type_code = nvl(p_asset_hdr_rec.book_type_code, 'XX')
370         AND    dp.period_close_date IS NULL;
371 
372         IF (l_count > 0) THEN
373            fa_srvr_msg.add_message(
374                         calling_fn => 'FA_TRANSFER_PUB.valid_input',
375                         name       => 'FA_SHARED_ONE_PRIOR_PERIOD_TRX'
376                         ,p_log_level_rec => p_log_level_rec);
377            return FALSE;
378         end if;
379 
380         -- prior period tfr is not allowed after assets' normal life complete
381 
382         SELECT count(1)
383         INTO   l_count
384         FROM   FA_BOOKS bk, FA_DEPRN_PERIODS dp
385         WHERE  bk.asset_id = p_asset_hdr_rec.asset_id
386         AND    bk.book_type_code = p_asset_hdr_rec.book_type_code
387         AND    nvl(period_counter_fully_reserved, 99) <>
388                           nvl(period_counter_life_complete, 99)
389         AND    bk.date_ineffective IS NULL
390         AND    dp.book_type_code = bk.book_type_code
391         AND    px_trans_rec.transaction_date_entered <
392                                    dp.calendar_period_open_date
393         AND    dp.period_close_date IS NULL;
394 
395         if (l_count > 0) THEN
396            fa_srvr_msg.add_message(
397                         calling_fn => 'FA_TRANSFER_PUB.valid_input',
398                         name       => 'FA_NO_TRX_WHEN_LIFE_COMPLETE'
399                         ,p_log_level_rec => p_log_level_rec);
400            return FALSE;
401         end if;
402      end if;
403 
404      return TRUE;
405 
406 EXCEPTION
407     when others then
408 	fa_srvr_msg.add_sql_error(
409                     calling_fn => 'FA_TRANSFER_PUB.valid_input'
410                     ,p_log_level_rec => p_log_level_rec);
411         return FALSE;
412 
413 END;
414 
415 
416 
417 END FA_TRANSFER_PUB;