1 PACKAGE BODY OKL_AM_AMORTIZE_PVT AS
2 /* $Header: OKLRTATB.pls 120.22 2008/02/05 22:19:43 rmunjulu noship $ */
3
4 -- SECHAWLA 06-MAY-04 3578894 : Added a new type declaration
5 TYPE book_rec_type IS RECORD
6 ( parent_line_id NUMBER,
7 dnz_chr_id NUMBER,
8 depreciation_category fa_additions_b.asset_category_id%TYPE,
9 book_type_code FA_BOOKS.book_type_code%TYPE,
10 book_class FA_BOOK_CONTROLS.book_class%TYPE,
11 salvage_value FA_BOOKS.salvage_value%TYPE,
12 DEPRN_METHOD_CODE FA_BOOKS.DEPRN_METHOD_CODE%TYPE ,
13 LIFE_IN_MONTHS FA_BOOKS.LIFE_IN_MONTHS%TYPE,
14 -- SECHAWLA 28-MAY-04 3645574 : Added deprn_rate
15 DEPRN_RATE NUMBER,
16 asset_number fa_additions_b.asset_number%TYPE,
17 item_description okc_k_lines_tl.item_description%TYPE,
18 asset_id fa_books.asset_id%TYPE,
19 original_cost fa_books.original_cost%TYPE,
20 current_units fa_additions_b.current_units%TYPE,
21 in_service_date fa_books.DATE_PLACED_IN_SERVICE%TYPE);
22
23
24
25 -- Start of comments
26 --
27 -- Procedure Name : get_reporting_product
28 -- Description : This procedure checks if there is a reporting product attached to the contract and returns
29 -- the deal type of the reporting product and MG reporting book
30 -- Business Rules :
31 -- Parameters : p_contract_id - Contract ID
32 -- Version : 1.0
33 -- History : SECHAWLA 06-MAY-04 3578894- Created
34 -- End of comments
35
36 PROCEDURE get_reporting_product(p_api_version IN NUMBER,
37 p_init_msg_list IN VARCHAR2,
38 x_return_status OUT NOCOPY VARCHAR2,
39 x_msg_count OUT NOCOPY NUMBER,
40 x_msg_data OUT NOCOPY VARCHAR2,
41 p_contract_id IN NUMBER,
42 x_rep_product OUT NOCOPY VARCHAR2,
43 x_mg_rep_book OUT NOCOPY VARCHAR2,
44 x_rep_deal_type OUT NOCOPY VARCHAR2) IS
45 --,x_rep_tax_owner OUT VARCHAR2) IS
46
47 -- Get the financial product of the contract
48 CURSOR l_get_fin_product(cp_khr_id IN NUMBER) IS
49 SELECT a.start_date, a.contract_number, b.pdt_id
50 FROM okc_k_headers_b a, okl_k_headers b
51 WHERE a.id = b.id
52 AND a.id = cp_khr_id;
53
54 SUBTYPE pdtv_rec_type IS OKL_SETUPPRODUCTS_PUB.pdtv_rec_type;
55 SUBTYPE pdt_parameters_rec_type IS OKL_SETUPPRODUCTS_PUB.pdt_parameters_rec_type;
56
57 l_fin_product_id NUMBER;
58 l_start_date DATE;
59 lp_pdtv_rec pdtv_rec_type;
60 lp_empty_pdtv_rec pdtv_rec_type;
61 lx_no_data_found BOOLEAN;
62 lx_pdt_parameter_rec pdt_parameters_rec_type ;
63 l_contract_number VARCHAR2(120);
64 l_mg_rep_book fa_book_controls.book_type_code%TYPE;
65 mg_error EXCEPTION;
66 l_reporting_product OKL_PRODUCTS_V.NAME%TYPE;
67 l_reporting_product_id NUMBER;
68 l_rep_deal_type okl_product_parameters_v.deal_type%TYPE;
69 -- l_rep_tax_owner okl_product_parameters_v.tax_owner%TYPE;
70
71
72 BEGIN
73 -- get the financial product of the contract
74 OPEN l_get_fin_product(p_contract_id);
75 FETCH l_get_fin_product INTO l_start_date, l_contract_number, l_fin_product_id;
76 CLOSE l_get_fin_product;
77
78 lp_pdtv_rec.id := l_fin_product_id;
79
80 -- check if the fin product has a reporting product
81 OKL_SETUPPRODUCTS_PUB.Getpdt_parameters( p_api_version => p_api_version,
82 p_init_msg_list => OKC_API.G_FALSE,
83 x_return_status => x_return_status,
84 x_no_data_found => lx_no_data_found,
85 x_msg_count => x_msg_count,
86 x_msg_data => x_msg_data,
87 p_pdtv_rec => lp_pdtv_rec,
88 p_product_date => l_start_date,
89 p_pdt_parameter_rec => lx_pdt_parameter_rec);
90
91 IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
92 -- Error getting financial product parameters for contract CONTRACT_NUMBER.
93 OKC_API.set_message( p_app_name => 'OKL',
94 p_msg_name => 'OKL_AM_FIN_PROD_PARAM_ERR',
95 p_token1 => 'CONTRACT_NUMBER',
96 p_token1_value => l_contract_number);
97
98
99
100 ELSE
101
102 l_reporting_product := lx_pdt_parameter_rec.reporting_product;
103 l_reporting_product_id := lx_pdt_parameter_rec.reporting_pdt_id;
104
105 IF l_reporting_product IS NOT NULL AND l_reporting_product <> OKC_API.G_MISS_CHAR THEN
106 -- Contract has a reporting product
107 x_rep_product := l_reporting_product;
108
109 lp_pdtv_rec := lp_empty_pdtv_rec;
110 lp_pdtv_rec.id := l_reporting_product_id;
111
112 -- get the deal type of the reporting product
113 OKL_SETUPPRODUCTS_PUB.Getpdt_parameters( p_api_version => p_api_version,
114 p_init_msg_list => OKC_API.G_FALSE,
115 x_return_status => x_return_status,
116 x_no_data_found => lx_no_data_found,
117 x_msg_count => x_msg_count,
118 x_msg_data => x_msg_data,
119 p_pdtv_rec => lp_pdtv_rec,
120 p_product_date => l_start_date,
121 p_pdt_parameter_rec => lx_pdt_parameter_rec);
122
123 IF x_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
124 -- Error getting reporting product parameters for contract CONTRACT_NUMBER.
125 OKC_API.set_message( p_app_name => 'OKL',
126 p_msg_name => 'OKL_AM_REP_PROD_PARAM_ERR',
127 p_token1 => 'CONTRACT_NUMBER',
128 p_token1_value => l_contract_number);
129
130
131 ELSE
132
133 l_rep_deal_type := lx_pdt_parameter_rec.Deal_Type;
134 IF l_rep_deal_type IS NULL OR l_rep_deal_type = OKC_API.G_MISS_CHAR THEN
135 --Deal Type not defined for Reporting product REP_PROD.
136 OKC_API.set_message( p_app_name => 'OKL',
137 p_msg_name => 'OKL_AM_NO_MG_DEAL_TYPE',
138 p_token1 => 'REP_PROD',
139 p_token1_value => l_reporting_product);
140
141 RAISE mg_error;
142 ELSE
143 x_rep_deal_type := l_rep_deal_type ;
144 END IF;
145
146 /*
147 l_rep_tax_owner := lx_pdt_parameter_rec.Tax_Owner;
148 IF l_rep_tax_owner IS NULL OR l_rep_tax_owner = OKC_API.G_MISS_CHAR THEN
149 -- Tax Owner not defined for Reporting product REP_PROD.
150 OKC_API.set_message( p_app_name => 'OKL',
151 p_msg_name => 'OKL_AM_NO_MG_TAX_OWNER',
152 p_token1 => 'REP_PROD',
153 p_token1_value => l_reporting_product);
154
155 RAISE mg_error;
156 ELSE
157 x_rep_tax_owner := l_rep_tax_owner;
158 END IF;
159 */
160
161 -- SECHAWLA 06-MAY-04 3578894 : Reporting book can be updated only if the reporting product is Op LEASE
162 -- This resriction is added because Authoring does not assign the asset to reporting book is other than
163 -- OP LEASE Bug 3574232 has been raised on Authoring to allow asset entry in Rep book for other deal types
164 --IF l_rep_deal_type = 'LEASEOP' THEN -- SECHAWLA 29-JUL-05 4384784
165 -- get the MG reporting book
166 l_mg_rep_book := OKL_SYSTEM_PARAMS_ALL_PUB.get_system_param_value(OKL_SYSTEM_PARAMS_ALL_PUB.G_RPT_PROD_BOOK_TYPE_CODE);
167 IF l_mg_rep_book IS NULL THEN
168 --Multi GAAP Reporting Book is not defined.
169 OKC_API.set_message( p_app_name => 'OKL',
170 p_msg_name => 'OKL_AM_NO_MG_REP_BOOK');
171
172 RAISE mg_error;
173 ELSE
174 x_mg_rep_book := l_mg_rep_book;
175 END IF;
176 -- END IF;
177
178 END IF;
179
180 END IF;
181
182 END IF;
183
184 EXCEPTION
185 WHEN mg_error THEN
186 IF l_get_fin_product%ISOPEN THEN
187 CLOSE l_get_fin_product;
188 END IF;
189 x_return_status := OKL_API.G_RET_STS_ERROR;
190 WHEN OTHERS THEN
191 IF l_get_fin_product%ISOPEN THEN
192 CLOSE l_get_fin_product;
193 END IF;
194 OKL_API.set_message(p_app_name => 'OKC',
195 p_msg_name => g_unexpected_error,
196 p_token1 => g_sqlcode_token,
197 p_token1_value => sqlcode,
198 p_token2 => g_sqlerrm_token,
199 p_token2_value => sqlerrm);
200 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
201 END get_reporting_product;
202
203
204
205 -- Start of comments
206 --
207 -- Procedure Name : process_oplease
208 -- Description : This procedure creates off lease transactions for an asset in Operating Lease
209 -- Business Rules :
210 -- Parameters : p_book_rec : record type parameter with corporate book information
211 -- p_corporate_book : corporate book
212 -- p_kle_id : asset line id
213 -- p_try_id : transaction type id
214 -- p_sysdate : today's date
215 -- p_func_curr_code : functional currency code
216 -- Version : 1.0
217 -- History : SECHAWLA 06-APR-04 - Created
218 -- SECHAWLA 28-MAY-04 3645574 - Addded depreciation rate processing logic for diminishing dep methods
219 -- SECHAWLA 15-DEC-04 4028371 : set FA trx date on trx line
220 -- End of comments
221
222 PROCEDURE process_oplease( p_api_version IN NUMBER,
223 p_init_msg_list IN VARCHAR2 ,
224 x_return_status OUT NOCOPY VARCHAR2,
225 x_msg_count OUT NOCOPY NUMBER,
226 x_msg_data OUT NOCOPY VARCHAR2,
227 p_book_rec IN book_rec_type,
228 p_corporate_book IN VARCHAR2,
229 p_kle_id IN NUMBER,
230 p_try_id IN NUMBER,
231 p_sysdate IN DATE,
232 p_func_curr_code IN VARCHAR2,
233 p_legal_entity_id IN NUMBER) IS -- RRAVIKIR Legal Entity Changes
234
235 process_error EXCEPTION;
236 process_unexp_error EXCEPTION;
237
238
239
240 --SECHAWLA 19-FEB-04 3439647 : added life_in_months to the select clause
241 -- This cursor will return a method_code corresponding to a unique method_id
242 CURSOR l_methodcode_csr(p_method_id fa_methods.method_id%TYPE) IS
243 SELECT method_code, life_in_months
244 FROM fa_methods
245 WHERE method_id = p_method_id;
246
247
248
249 -- This cursor will return the hold period days and the default depreciation method from a hold period setup table
250 -- using category_id and book_type_code.
251 CURSOR l_amthld_csr(p_category_id okl_amort_hold_setups.category_id%TYPE,
252 p_book_type_code okl_amort_hold_setups.book_type_code%TYPE) IS
253 -- SECHAWLA 28-MAY-04 3645574 : Added deprn_rate
254 SELECT hold_period_days, method_id, deprn_rate
255 FROM okl_amort_hold_setups
256 WHERE category_id = p_category_id
257 AND book_type_code = p_book_type_code;
258
259 /*
260 -- This cursor will return current cost of an asset
261 CURSOR l_astbksv_csr(p_id okx_ast_bks_v.asset_id%TYPE, p_btc okx_ast_bks_v.book_type_code%TYPE) IS
262 SELECT cost
263 FROM okx_ast_bks_v
264 WHERE asset_id = p_id
265 AND book_type_code = p_btc;
266 */
267
268 l_hold_period_days okl_amort_hold_setups.hold_period_days%TYPE;
269 l_setup_method_id okl_amort_hold_setups.method_id%TYPE;
270 l_fa_method_code fa_methods.method_code%TYPE;
271 l_fa_life_in_months fa_methods.life_in_months%TYPE;
272 lp_thpv_rec thpv_rec_type;
273 lx_thpv_rec thpv_rec_type;
274 lp_tlpv_rec tlpv_rec_type;
275 lx_tlpv_rec tlpv_rec_type;
276 lp_empty_thpv_rec thpv_rec_type;
277 lp_empty_tlpv_rec tlpv_rec_type;
278
279 SUBTYPE adpv_rec_type IS OKL_TXD_ASSETS_PUB.adpv_rec_type;
280 lp_adpv_rec adpv_rec_type;
281 lx_adpv_rec adpv_rec_type;
282 lp_empty_adpv_rec adpv_rec_type;
283
284 -- SECHAWLA 28-MAY-04 3645574 : new declaration
285 l_setup_deprn_rate NUMBER;
286
287 -- SECHAWLA 15-DEC-04 4028371 : new declartions
288 l_fa_trx_date DATE;
289 BEGIN
290
291 -- get the hold period and dep method from setup, for each book/category
292 OPEN l_amthld_csr(p_book_rec.depreciation_category, p_book_rec.book_type_code);
293 -- SECHAWLA 28-MAY-04 3645574 : Added l_setup_deprn_rate
294 FETCH l_amthld_csr INTO l_hold_period_days,l_setup_method_id, l_setup_deprn_rate; --l_setup_deprn_rate could be null
295 CLOSE l_amthld_csr;
296
297
298 -- If there is a method_id in okl_amort_hold_setups then use it to get deprn method from fa_methods.
299
300 IF l_setup_method_id IS NOT NULL THEN -- either life or rate is defined in the setup. Life is not stored in teh setup table but rate is stores
301 OPEN l_methodcode_csr(l_setup_method_id);
302 -- SECHAWLA 19-FEB-04 3439647 : Added l_fa_life_in_months
303 FETCH l_methodcode_csr INTO l_fa_method_code, l_fa_life_in_months; -- life_in_months will be null for diminishing dep methods
304 IF l_methodcode_csr%NOTFOUND THEN
305 -- The depreciation method defined for category DEPRN_CAT and book BOOK is invalid.
306 OKL_API.set_message( p_app_name => 'OKL',
307 p_msg_name => 'OKL_AM_INVALID_DEPRN_MTHD',
308 p_token1 => 'DEPRN_CAT',
309 p_token1_value => p_book_rec.depreciation_category,
310 p_token2 => 'BOOK',
311 p_token2_value => p_book_rec.book_type_code);
312 RAISE process_error;
313 END IF;
314 CLOSE l_methodcode_csr;
315 END IF;
316
317 -- SECHAWLA 28-MAY-04 3645574 : Removing this validation, as life is null for diminishing dep methods
318 /*IF p_book_rec.life_in_months IS NULL THEN
319 -- Life in Months not defined for asset ASSET_NUMBER and book BOOK
320 OKL_API.set_message( p_app_name => 'OKL',
321 p_msg_name => 'OKL_AM_NO_LIFE_IN_MONTHS',
322 p_token1 => 'ASSET_NUMBER',
323 p_token1_value => p_book_rec.asset_number,
324 p_token2 => 'BOOK',
325 p_token2_value => p_book_rec.book_type_code);
326 RAISE process_error;
327 END IF;
328 */
329 -- SECHAWLA 28-MAY-04 3645574 : new validation, eithr life or rate should be defined
330 IF p_book_rec.life_in_months IS NULL AND p_book_rec.deprn_rate IS NULL THEN
331 -- Life in Months or Depreciation Rate should be defined for asset ASSET_NUMBER and book BOOK.
332 OKL_API.set_message( p_app_name => 'OKL',
333 p_msg_name => 'OKL_AM_NO_LIFE_NO_RATE',
334 p_token1 => 'ASSET_NUMBER',
335 p_token1_value => p_book_rec.asset_number,
336 p_token2 => 'BOOK',
337 p_token2_value => p_book_rec.book_type_code);
338 RAISE process_error;
339 END IF;
340 -- SECHAWLA 28-MAY-04 3645574 : end new validation
341
342 --SECHAWLA 15-DEC-04 4028371 : get the FA trx date
343 OKL_ACCOUNTING_UTIL.get_fa_trx_date(p_book_type_code => p_book_rec.book_type_code,
344 x_return_status => x_return_status,
345 x_fa_trx_date => l_fa_trx_date);
346
347 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
348 RAISE process_unexp_error;
349 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
350 RAISE process_error;
351 END IF;
352
353
354 IF l_hold_period_days IS NOT NULL AND l_hold_period_days <> 0 THEN -- SECHAWLA 03-JUN-04 Added check for 0 hold period days
355 -- create 1st transaction header
356 -- SECHAWLA 06-MAY-04 3578894 : Changed tas_type to a new tas_type
357 -- lp_thpv_rec.tas_type := 'AMT';
358 lp_thpv_rec.tas_type := 'AUD'; -- depreciation flag adjustment trx
359
360 lp_thpv_rec.tsu_code := 'ENTERED';
361
362 lp_thpv_rec.try_id := p_try_id;
363 lp_thpv_rec.date_trans_occurred := p_sysdate;
364
365 -- RRAVIKIR Legal Entity Changes
366 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
367 -- Legal Entity Changes End
368
369 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
370 p_init_msg_list => OKL_API.G_FALSE,
371 x_return_status => x_return_status,
372 x_msg_count => x_msg_count,
373 x_msg_data => x_msg_data,
374 p_thpv_rec => lp_thpv_rec,
375 x_thpv_rec => lx_thpv_rec);
376
377 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
378 RAISE process_unexp_error;
379 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
380 RAISE process_error;
381 END IF;
382
383
384 -- create 1st transaction line
385
386 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
387 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
388 lp_tlpv_rec.kle_id := p_kle_id;
389 lp_tlpv_rec.line_number := 1;
390
391 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
392 --lp_tlpv_rec.tal_type := 'AML';
393 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
394 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
395 lp_tlpv_rec.description := p_book_rec.item_description;
396
397 -- SECHAWLA 06-MAY-04 3578894 : Dep method and life are populated for display on off lease trx details screen
398 -- When this trx is processed, dep method and life will not be updated in FA
399
400 -- SECHAWLA 28-MAY-04 3645574 : Store either life or rate
401 IF p_book_rec.life_in_months IS NOT NULL THEN
402 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
403 ELSE
404 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
405 END IF;
406
407
408 -- FA Adjustmets API expects a depreciation method and life in months, not the depreciation Id
409
410 -- SECHAWLA 19-FEB-04 3439647 : when we stop the depreciation, there is no need to update the
411 -- dep method with the one on setup
412
413
414 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
415
416
417 -- SECHAWLA 06-MAY-04 3578894 : need to populate sv for display on the off lse upd screen
418 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
419
420 --In case of Operating lease, asset is already assigned to a corporate book
421
422 lp_tlpv_rec.corporate_book := p_corporate_book;
423 lp_tlpv_rec.original_cost := p_book_rec.original_cost;
424 lp_tlpv_rec.current_units := p_book_rec.current_units;
425 lp_tlpv_rec.hold_period_days := l_hold_period_days;
426 lp_tlpv_rec.depreciate_yn := 'N';
427 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
428 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
429 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
430
431 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
432 lp_tlpv_rec.currency_code := p_func_curr_code;
433
434 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
435 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
436
437 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
438 p_init_msg_list => OKL_API.G_FALSE,
439 x_return_status => x_return_status,
440 x_msg_count => x_msg_count,
441 x_msg_data => x_msg_data,
442 p_tlpv_rec => lp_tlpv_rec,
443 x_tlpv_rec => lx_tlpv_rec);
444
445 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
446 RAISE process_unexp_error;
447 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
448 RAISE process_error;
449 END IF;
450
451 -- When process_oplease procedure is called with mg rep book (tax book), then
452 -- we need to create tax book trx also.
453 IF p_book_rec.book_type_code <> p_corporate_book THEN
454 IF p_book_rec.book_class = 'TAX' THEN
455 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
456 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
457 lp_adpv_rec.asset_number := p_book_rec.asset_number;
458 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
459 p_api_version => p_api_version,
460 p_init_msg_list => OKL_API.G_FALSE,
461 x_return_status => x_return_status,
462 x_msg_count => x_msg_count,
463 x_msg_data => x_msg_data,
464 p_adpv_rec => lp_adpv_rec,
465 x_adpv_rec => lx_adpv_rec );
466 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
467 RAISE process_unexp_error;
468 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
469 RAISE process_error;
470 END IF;
471 END IF;
472
473 END IF;
474
475 -- Validations for the 2nd trx (if any) should go here
476
477 /* SECHAWLA 06-MAY-04 3578894 : Do not populate cost in case of OP Lease
478 -- validations specific to the 2nd transaction line
479 OPEN l_astbksv_csr(l_asset_id, l_corporate_book);
480 FETCH l_astbksv_csr INTO l_cost;
481 IF l_astbksv_csr%NOTFOUND THEN
482 -- Cost not defined for this asset and book type code
483 OKL_API.set_message( p_app_name => 'OKL',
484 p_msg_name => 'OKL_AM_COST_NOT_FOUND',
485 p_token1 => 'ASSET_NUMBER',
486 p_token1_value => l_asset_number,
487 p_token2 => 'BOOK_TYPE_CODE',
488 p_token2_value => l_corporate_book);
489 l_line_status := 'ERROR';
490 END IF;
491 CLOSE l_astbksv_csr;
492 -- end validation
493 */
494
495 -- SECHAWLA 06-MAY-04 3578894 : Split the 2nd trx into 2 transactions. First update the deprn method and
496 -- flag and then start the depreciation. This is required because FA does not allow updating depreciation
497 -- flag with any other attribute. Details in bug 3501172
498
499 -- SECHAWLA 06-MAY-04 3578894 : Initialize the trx hdr and line for each trx
500 lp_thpv_rec := lp_empty_thpv_rec;
501 lp_tlpv_rec := lp_empty_tlpv_rec;
502 lp_adpv_rec := lp_empty_adpv_rec;
503 -- SECHAWLA 06-MAY-04 3578894 : end initialization
504
505
506 -- Create 2nd Transaction Header
507 lp_thpv_rec.tas_type := 'AMT';
508
509 lp_thpv_rec.tsu_code := 'ENTERED';
510
511 lp_thpv_rec.try_id := p_try_id;
512 lp_thpv_rec.date_trans_occurred := p_sysdate + l_hold_period_days;
513
514 -- RRAVIKIR Legal Entity Changes
515 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
516 -- Legal Entity Changes End
517
518 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
519 p_init_msg_list => OKL_API.G_FALSE,
520 x_return_status => x_return_status,
521 x_msg_count => x_msg_count,
522 x_msg_data => x_msg_data,
523 p_thpv_rec => lp_thpv_rec,
524 x_thpv_rec => lx_thpv_rec);
525
526 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
527 RAISE process_unexp_error;
528 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
529 RAISE process_error;
530 END IF;
531
532 -- create 2nd transaction line.
533 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
534 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
535 lp_tlpv_rec.kle_id := p_kle_id;
536 lp_tlpv_rec.line_number := 1;
537 lp_tlpv_rec.tal_type := 'AML';
538 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
539 lp_tlpv_rec.description := p_book_rec.item_description;
540
541 -- SECHAWLA 19-FEB-04 3439647
542 --lp_tlpv_rec.life_in_months := l_life_in_months;
543
544 -- If there is a method_id in okl_amort_hold_setups then use it. Otherwise get method id
545 -- from fa_methods
546
547
548 IF l_setup_method_id IS NOT NULL THEN
549 lp_tlpv_rec.deprn_method := l_fa_method_code;
550
551 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
552 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
553 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
554 ELSE
555 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
556 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
557 END IF;
558
559 ELSE
560 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
561
562 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
563 IF p_book_rec.life_in_months IS NOT NULL THEN
564 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
565 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
566 ELSE
567 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
568 END IF;
569 END IF;
570
571
572 --In case of Operating lease, asset is already assigned to a corporate book
573
574 lp_tlpv_rec.corporate_book := p_corporate_book;
575
576 -- SECHAWLA 06-MAY-04 3578894 : Do not update cost in case of OP Lease
577 --lp_tlpv_rec.depreciation_cost := l_cost ;
578
579 --SECHAWLA 06-MAY-04 3578894 : Populate sv for display on off lse upd screen
580 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
581
582
583 lp_tlpv_rec.original_cost := p_book_rec.original_cost;
584 lp_tlpv_rec.current_units := p_book_rec.current_units;
585 lp_tlpv_rec.hold_period_days := l_hold_period_days;
586
587 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 3rd trx,so the process
588 -- asset trx program can identify that these are split transactions. When 2nd trx is processed, the flag
589 -- is not updated in FA. Only Dep method and life will be updated
590 lp_tlpv_rec.depreciate_yn := 'Y';
591
592 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
593 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
594 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
595
596 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
597 lp_tlpv_rec.currency_code := p_func_curr_code;
598
599 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
600 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
601
602 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
603 p_init_msg_list => OKL_API.G_FALSE,
604 x_return_status => x_return_status,
605 x_msg_count => x_msg_count,
606 x_msg_data => x_msg_data,
607 p_tlpv_rec => lp_tlpv_rec,
608 x_tlpv_rec => lx_tlpv_rec);
609
610
611 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
612 RAISE process_unexp_error;
613 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
614 RAISE process_error;
615 END IF;
616
617
618 -- When process_oplease procedure is called with mg rep book (tax book), then
619 -- we need to create tax book trx also.
620 IF p_book_rec.book_type_code <> p_corporate_book THEN
621 IF p_book_rec.book_class = 'TAX' THEN
622 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
623 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
624 lp_adpv_rec.asset_number := p_book_rec.asset_number;
625 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
626 p_api_version => p_api_version,
627 p_init_msg_list => OKL_API.G_FALSE,
628 x_return_status => x_return_status,
629 x_msg_count => x_msg_count,
630 x_msg_data => x_msg_data,
631 p_adpv_rec => lp_adpv_rec,
632 x_adpv_rec => lx_adpv_rec );
633 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
634 RAISE process_unexp_error;
635 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
636 RAISE process_error;
637 END IF;
638 END IF;
639 END IF;
640
641
642 -- Validations for 3rd trx (if any) shold go here
643 -- SECHAWLA 06-MAY-04 3578894 : create 3rd trx hdr and line, to start the depreciation
644
645 -- Initialize the trx hdr and line for each trx
646 lp_thpv_rec := lp_empty_thpv_rec;
647 lp_tlpv_rec := lp_empty_tlpv_rec;
648 lp_adpv_rec := lp_empty_adpv_rec;
649
650 -- Create a 3rd trx header and line with dep_yn = 'Y' and dep_method = null, life = null
651
652 -- Create 3rd Transaction Header
653 lp_thpv_rec.tas_type := 'AUD'; -- depreciate flag update trx
654
655 lp_thpv_rec.tsu_code := 'ENTERED';
656
657 lp_thpv_rec.try_id := p_try_id;
658 lp_thpv_rec.date_trans_occurred := p_sysdate + l_hold_period_days;
659
660 -- RRAVIKIR Legal Entity Changes
661 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
662 -- Legal Entity Changes End
663
664 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
665 p_init_msg_list => OKL_API.G_FALSE,
666 x_return_status => x_return_status,
667 x_msg_count => x_msg_count,
668 x_msg_data => x_msg_data,
669 p_thpv_rec => lp_thpv_rec,
670 x_thpv_rec => lx_thpv_rec);
671
672 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
673 RAISE process_unexp_error;
674 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
675 RAISE process_error;
676 END IF;
677
678 -- create 3rd transaction line.
679 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
680 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
681 lp_tlpv_rec.kle_id := p_kle_id;
682 lp_tlpv_rec.line_number := 1;
683
684 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
685 --lp_tlpv_rec.tal_type := 'AML';
686 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
687
688 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
689 lp_tlpv_rec.description := p_book_rec.item_description;
690
691 --In case of Operating lease, asset is already assigned to a corporate book
692
693 lp_tlpv_rec.corporate_book := p_corporate_book;
694
695 lp_tlpv_rec.original_cost := p_book_rec.original_cost;
696 lp_tlpv_rec.current_units := p_book_rec.current_units;
697 lp_tlpv_rec.hold_period_days := l_hold_period_days;
698 -- SECHAWLA 06-MAY-04 3578894 : When 3rd trx is processed, the flag will be updated in FA. No other
699 -- financial attributes will be updated along with the flag
700 lp_tlpv_rec.depreciate_yn := 'Y';
701
702 --SECHAWLA 06-MAY-04 3578894 : Populate dep method, life and sv for display on off lse upd screen
703 IF l_setup_method_id IS NOT NULL THEN
704 lp_tlpv_rec.deprn_method := l_fa_method_code;
705
706 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
707 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
708 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
709 ELSE
710 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
711 END IF;
712 ELSE
713 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
714
715 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
716 IF p_book_rec.life_in_months IS NOT NULL THEN
717 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
718 ELSE
719 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
720 END IF;
721 END IF;
722
723 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
724
725 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
726 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
727 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
728
729 lp_tlpv_rec.currency_code := p_func_curr_code;
730
731 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
732 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
733
734 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
735 p_init_msg_list => OKL_API.G_FALSE,
736 x_return_status => x_return_status,
737 x_msg_count => x_msg_count,
738 x_msg_data => x_msg_data,
739 p_tlpv_rec => lp_tlpv_rec,
740 x_tlpv_rec => lx_tlpv_rec);
741
742
743 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
744 RAISE process_unexp_error;
745 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
746 RAISE process_error;
747 END IF;
748 -- SECHAWLA 06-MAY-04 3578894 : end create 3rd trx hdr and line
749
750 -- When process_oplease procedure is called with mg rep book (tax book), then
751 -- we need to create tax book trx also.
752 IF p_book_rec.book_type_code <> p_corporate_book THEN
753 IF p_book_rec.book_class = 'TAX' THEN
754 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
755 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
756 lp_adpv_rec.asset_number := p_book_rec.asset_number;
757 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
758 p_api_version => p_api_version,
759 p_init_msg_list => OKL_API.G_FALSE,
760 x_return_status => x_return_status,
761 x_msg_count => x_msg_count,
762 x_msg_data => x_msg_data,
763 p_adpv_rec => lp_adpv_rec,
764 x_adpv_rec => lx_adpv_rec );
765 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
766 RAISE process_unexp_error;
767 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
768 RAISE process_error;
769 END IF;
770 END IF;
771
772 END IF;
773
774
775 ELSE -- LEASEOP, Hold period is null or 0
776 -- do nothing --
777 --NULL;
778
779 -- Create 1st Transaction Header
780 lp_thpv_rec.tas_type := 'AMT';
781
782 lp_thpv_rec.tsu_code := 'ENTERED';
783
784 lp_thpv_rec.try_id := p_try_id;
785 lp_thpv_rec.date_trans_occurred := p_sysdate ;
786 -- RRAVIKIR Legal Entity Changes
787 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
788 -- Legal Entity Changes End
789
790 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
791 p_init_msg_list => OKL_API.G_FALSE,
792 x_return_status => x_return_status,
793 x_msg_count => x_msg_count,
794 x_msg_data => x_msg_data,
795 p_thpv_rec => lp_thpv_rec,
796 x_thpv_rec => lx_thpv_rec);
797
798 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
799 RAISE process_unexp_error;
800 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
801 RAISE process_error;
802 END IF;
803
804 -- create 1st transaction line.
805 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
806 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
807 lp_tlpv_rec.kle_id := p_kle_id;
808 lp_tlpv_rec.line_number := 1;
809 lp_tlpv_rec.tal_type := 'AML';
810 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
811 lp_tlpv_rec.description := p_book_rec.item_description;
812
813
814 -- If there is a method_id in okl_amort_hold_setups then use it. Otherwise get method id
815 -- from fa_methods
816
817 IF l_setup_method_id IS NOT NULL THEN
818 lp_tlpv_rec.deprn_method := l_fa_method_code;
819
820 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
821 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
822 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
823 ELSE
824 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
825 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
826 END IF;
827
828 ELSE
829 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
830
831 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
832 IF p_book_rec.life_in_months IS NOT NULL THEN
833 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
834 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
835 ELSE
836 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
837 END IF;
838 END IF;
839
840
841 --In case of Operating lease, asset is already assigned to a corporate book
842
843 lp_tlpv_rec.corporate_book := p_corporate_book;
844
845 -- SECHAWLA 06-MAY-04 3578894 : Do not update cost in case of OP Lease
846 --lp_tlpv_rec.depreciation_cost := l_cost ;
847
848 --SECHAWLA 06-MAY-04 3578894 : Populate sv for display on off lse upd screen
849 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
850
851
852 lp_tlpv_rec.original_cost := p_book_rec.original_cost;
853 lp_tlpv_rec.current_units := p_book_rec.current_units;
854 -- lp_tlpv_rec.hold_period_days := l_hold_period_days;
855
856 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 2nd trx,so the process
857 -- asset trx program can identify that these are split transactions. When 1st trx is processed, the flag
858 -- is not updated in FA. Only Dep method and life will be updated
859 lp_tlpv_rec.depreciate_yn := 'Y';
860
861 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
862 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
863 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
864
865 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
866 lp_tlpv_rec.currency_code := p_func_curr_code;
867
868 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
869 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
870
871 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
872 p_init_msg_list => OKL_API.G_FALSE,
873 x_return_status => x_return_status,
874 x_msg_count => x_msg_count,
875 x_msg_data => x_msg_data,
876 p_tlpv_rec => lp_tlpv_rec,
877 x_tlpv_rec => lx_tlpv_rec);
878
879
880 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
881 RAISE process_unexp_error;
882 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
883 RAISE process_error;
884 END IF;
885
886
887 -- When process_oplease procedure is called with mg rep book (tax book), then
888 -- we need to create tax book trx also.
889 IF p_book_rec.book_type_code <> p_corporate_book THEN
890 IF p_book_rec.book_class = 'TAX' THEN
891 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
892 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
893 lp_adpv_rec.asset_number := p_book_rec.asset_number;
894 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
895 p_api_version => p_api_version,
896 p_init_msg_list => OKL_API.G_FALSE,
897 x_return_status => x_return_status,
898 x_msg_count => x_msg_count,
899 x_msg_data => x_msg_data,
900 p_adpv_rec => lp_adpv_rec,
901 x_adpv_rec => lx_adpv_rec );
902 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
903 RAISE process_unexp_error;
904 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
905 RAISE process_error;
906 END IF;
907 END IF;
908
909 END IF;
910
911
912 -- Validations for 2nd trx (if any) shold go here
913 -- SECHAWLA 06-MAY-04 3578894 : create 2nd trx hdr and line, to start the depreciation
914
915 -- Initialize the trx hdr and line for each trx
916 lp_thpv_rec := lp_empty_thpv_rec;
917 lp_tlpv_rec := lp_empty_tlpv_rec;
918 lp_adpv_rec := lp_empty_adpv_rec;
919
920 -- Create a 2nd trx header and line with dep_yn = 'Y' and dep_method = null, life = null
921
922 -- Create 2nd Transaction Header
923 lp_thpv_rec.tas_type := 'AUD'; -- depreciate flag update trx
924
925 lp_thpv_rec.tsu_code := 'ENTERED';
926
927 lp_thpv_rec.try_id := p_try_id;
928 lp_thpv_rec.date_trans_occurred := p_sysdate;
929 -- RRAVIKIR Legal Entity Changes
930 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
931 -- Legal Entity Changes End
932
933 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
934 p_init_msg_list => OKL_API.G_FALSE,
935 x_return_status => x_return_status,
936 x_msg_count => x_msg_count,
937 x_msg_data => x_msg_data,
938 p_thpv_rec => lp_thpv_rec,
939 x_thpv_rec => lx_thpv_rec);
940
941 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
942 RAISE process_unexp_error;
943 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
944 RAISE process_error;
945 END IF;
946
947 -- create 2nd transaction line.
948 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
949 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
950 lp_tlpv_rec.kle_id := p_kle_id;
951 lp_tlpv_rec.line_number := 1;
952
953 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
954 --lp_tlpv_rec.tal_type := 'AML';
955 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
956
957 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
958 lp_tlpv_rec.description := p_book_rec.item_description;
959
960 --In case of Operating lease, asset is already assigned to a corporate book
961
962 lp_tlpv_rec.corporate_book := p_corporate_book;
963
964 lp_tlpv_rec.original_cost := p_book_rec.original_cost;
965 lp_tlpv_rec.current_units := p_book_rec.current_units;
966 -- lp_tlpv_rec.hold_period_days := l_hold_period_days;
967 -- SECHAWLA 06-MAY-04 3578894 : When 2nd trx is processed, the flag will be updated in FA. No other
968 -- financial attributes will be updated along with the flag
969 lp_tlpv_rec.depreciate_yn := 'Y';
970
971 --SECHAWLA 06-MAY-04 3578894 : Populate dep method, life and sv for display on off lse upd screen
972 IF l_setup_method_id IS NOT NULL THEN
973 lp_tlpv_rec.deprn_method := l_fa_method_code;
974
975 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
976 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
977 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
978 ELSE
979 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
980 END IF;
981
982 ELSE
983 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
984
985 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
986 IF p_book_rec.life_in_months IS NOT NULL THEN
987 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
988 ELSE
989 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
990 END IF;
991 END IF;
992 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
993
994 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
995 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
996 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
997
998 lp_tlpv_rec.currency_code := p_func_curr_code;
999
1000 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
1001 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
1002
1003 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
1004 p_init_msg_list => OKL_API.G_FALSE,
1005 x_return_status => x_return_status,
1006 x_msg_count => x_msg_count,
1007 x_msg_data => x_msg_data,
1008 p_tlpv_rec => lp_tlpv_rec,
1009 x_tlpv_rec => lx_tlpv_rec);
1010
1011
1012 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1013 RAISE process_unexp_error;
1014 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1015 RAISE process_error;
1016 END IF;
1017 -- SECHAWLA 06-MAY-04 3578894 : end create 2nd trx hdr and line
1018
1019 -- When process_oplease procedure is called with mg rep book (tax book), then
1020 -- we need to create tax book trx also.
1021 IF p_book_rec.book_type_code <> p_corporate_book THEN
1022 IF p_book_rec.book_class = 'TAX' THEN
1023 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
1024 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
1025 lp_adpv_rec.asset_number := p_book_rec.asset_number;
1026 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
1027 p_api_version => p_api_version,
1028 p_init_msg_list => OKL_API.G_FALSE,
1029 x_return_status => x_return_status,
1030 x_msg_count => x_msg_count,
1031 x_msg_data => x_msg_data,
1032 p_adpv_rec => lp_adpv_rec,
1033 x_adpv_rec => lx_adpv_rec );
1034 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1035 RAISE process_unexp_error;
1036 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1037 RAISE process_error;
1038 END IF;
1039 END IF;
1040
1041 END IF;
1042 END IF; -- IF l_hold_period_days IS NOT NULL THEN
1043 EXCEPTION
1044 WHEN process_error THEN
1045 --IF l_astbksv_csr%ISOPEN THEN
1046 -- CLOSE l_astbksv_csr;
1047 --END IF;
1048
1049 IF l_methodcode_csr%ISOPEN THEN
1050 CLOSE l_methodcode_csr;
1051 END IF;
1052
1053 IF l_amthld_csr%ISOPEN THEN
1054 CLOSE l_amthld_csr;
1055 END IF;
1056
1057 x_return_status := OKL_API.G_RET_STS_ERROR;
1058 WHEN process_unexp_error THEN
1059 --IF l_astbksv_csr%ISOPEN THEN
1060 -- CLOSE l_astbksv_csr;
1061 --END IF;
1062
1063 IF l_methodcode_csr%ISOPEN THEN
1064 CLOSE l_methodcode_csr;
1065 END IF;
1066
1067 IF l_amthld_csr%ISOPEN THEN
1068 CLOSE l_amthld_csr;
1069 END IF;
1070 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1071 WHEN OTHERS THEN
1072 --IF l_astbksv_csr%ISOPEN THEN
1073 -- CLOSE l_astbksv_csr;
1074 --END IF;
1075
1076 IF l_methodcode_csr%ISOPEN THEN
1077 CLOSE l_methodcode_csr;
1078 END IF;
1079
1080 IF l_amthld_csr%ISOPEN THEN
1081 CLOSE l_amthld_csr;
1082 END IF;
1083 -- unexpected error
1084 OKL_API.set_message(p_app_name => 'OKC',
1085 p_msg_name => g_unexpected_error,
1086 p_token1 => g_sqlcode_token,
1087 p_token1_value => sqlcode,
1088 p_token2 => g_sqlerrm_token,
1089 p_token2_value => sqlerrm);
1090 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1091
1092 END process_oplease;
1093
1094
1095 -- Start of comments
1096 --
1097 -- Procedure Name : process_dfstlease_lessor
1098 -- Description : This procedure creates off lease transactions for an asset in DF/Sales lease,
1099 -- when tax owner is lessor
1100 -- Business Rules :
1101 -- Parameters : p_book_rec : record type parameter with corporate book information
1102 -- p_corporate_book : corporate book
1103 -- p_kle_id : asset line id
1104 -- p_df_original_cost : original cost
1105 -- p_oec : original equipment cost
1106 -- p_net_investment_value : net investment
1107 -- p_try_id : transaction type id
1108 -- p_sysdate : today's date
1109 -- p_func_curr_code : functional currency code
1110 -- Version : 1.0
1111 -- History : SECHAWLA 06-APR-04 - Created
1112 -- SECHAWLA 28-MAY-04 3645574 - Added deprn rate processing logic for diminishing dep methods
1113 -- SECHAWLA 15-DEC-04 4028371 : set FA trx date on trx line
1114 -- End of comments
1115
1116 PROCEDURE process_dfstlease_lessor( p_api_version IN NUMBER,
1117 p_init_msg_list IN VARCHAR2 ,
1118 x_return_status OUT NOCOPY VARCHAR2,
1119 x_msg_count OUT NOCOPY NUMBER,
1120 x_msg_data OUT NOCOPY VARCHAR2,
1121 p_book_rec IN book_rec_type,
1122 p_corporate_book IN VARCHAR2,
1123 p_kle_id IN NUMBER,
1124 p_df_original_cost IN NUMBER,
1125 p_oec IN NUMBER,
1126 p_net_investment_value IN NUMBER,
1127 p_try_id IN NUMBER,
1128 p_sysdate IN DATE,
1129 p_func_curr_code IN VARCHAR2,
1130 p_legal_entity_id IN NUMBER) IS -- RRAVIKIR Legal Entity Changes
1131
1132 process_error EXCEPTION;
1133 process_unexp_error EXCEPTION;
1134
1135
1136 --SECHAWLA 19-FEB-04 3439647 : added life_in_months to the select clause
1137 -- This cursor will return a method_code corresponding to a unique method_id
1138 CURSOR l_methodcode_csr(p_method_id fa_methods.method_id%TYPE) IS
1139 SELECT method_code, life_in_months
1140 FROM fa_methods
1141 WHERE method_id = p_method_id;
1142
1143
1144 -- This cursor will return the hold period days and the default depreciation method from a hold period setup table
1145 -- using category_id and book_type_code.
1146 CURSOR l_amthld_csr(p_category_id okl_amort_hold_setups.category_id%TYPE,
1147 p_book_type_code okl_amort_hold_setups.book_type_code%TYPE) IS
1148 -- SECHAWLA 28-MAY-04 3645574 : Added deprn_rate
1149 SELECT hold_period_days, method_id, deprn_rate
1150 FROM okl_amort_hold_setups
1151 WHERE category_id = p_category_id
1152 AND book_type_code = p_book_type_code;
1153
1154 l_hold_period_days okl_amort_hold_setups.hold_period_days%TYPE;
1155 l_setup_method_id okl_amort_hold_setups.method_id%TYPE;
1156 l_fa_method_code fa_methods.method_code%TYPE;
1157 l_fa_life_in_months fa_methods.life_in_months%TYPE;
1158 lp_thpv_rec thpv_rec_type;
1159 lx_thpv_rec thpv_rec_type;
1160 lp_tlpv_rec tlpv_rec_type;
1161 lx_tlpv_rec tlpv_rec_type;
1162 lp_empty_thpv_rec thpv_rec_type;
1163 lp_empty_tlpv_rec tlpv_rec_type;
1164
1165 SUBTYPE adpv_rec_type IS OKL_TXD_ASSETS_PUB.adpv_rec_type;
1166 lp_adpv_rec adpv_rec_type;
1167 lx_adpv_rec adpv_rec_type;
1168 lp_empty_adpv_rec adpv_rec_type;
1169
1170 -- SECHAWLA 28-MAY-04 3645574 : new declaration
1171 l_setup_deprn_rate NUMBER;
1172
1173 -- SECHAWLA 15-DEC-04 4028371 : new declartions
1174 l_fa_trx_date DATE;
1175
1176 -- SGORANTL 22-MAR-06 5097643 : new declartions
1177 l_contract_currency_code VARCHAR2(15);
1178 l_currency_conversion_type VARCHAR2(30);
1179 l_currency_conversion_rate NUMBER;
1180 l_currency_conversion_date DATE;
1181 l_converted_amount NUMBER;
1182 l_orig_cost_contr_currcy NUMBER; -- orginal cost in contract currency
1183 l_orig_cost_in_func NUMBER; -- orginal cost converted to functional currency before the hold period
1184 l_nest_invest_val_in_func NUMBER; -- net investment value converted to functional currency before the hold period
1185 -- end of XILI 22-Feb-06 5029064
1186
1187
1188
1189 BEGIN
1190
1191
1192 -- get the hold period and dep method from setup, for each book/category
1193 -- SECHAWLA 28-MAY-04 3645574 : Added l_setup_deprn_rate
1194
1195 OPEN l_amthld_csr(p_book_rec.depreciation_category, p_book_rec.book_type_code);
1196 FETCH l_amthld_csr INTO l_hold_period_days,l_setup_method_id, l_setup_deprn_rate; --l_setup_deprn_rate could be null;
1197 CLOSE l_amthld_csr;
1198
1199 -- If there is a method_id in okl_amort_hold_setups then use it to get deprn method from fa_methods.
1200
1201 IF l_setup_method_id IS NOT NULL THEN
1202 OPEN l_methodcode_csr(l_setup_method_id);
1203 -- SECHAWLA 19-FEB-04 3439647 : Added l_fa_life_in_months
1204 FETCH l_methodcode_csr INTO l_fa_method_code, l_fa_life_in_months;
1205 IF l_methodcode_csr%NOTFOUND THEN
1206 -- The depreciation method defined for category DEPRN_CAT and book BOOK is invalid.
1207 OKL_API.set_message( p_app_name => 'OKL',
1208 p_msg_name => 'OKL_AM_INVALID_DEPRN_MTHD',
1209 p_token1 => 'DEPRN_CAT',
1210 p_token1_value => p_book_rec.depreciation_category,
1211 p_token2 => 'BOOK',
1212 p_token2_value => p_book_rec.book_type_code);
1213 RAISE process_error;
1214
1215 END IF;
1216 CLOSE l_methodcode_csr;
1217 END IF;
1218
1219 -- SECHAWLA 28-MAY-04 3645574 : Removing this validation, as life is null for diminishing dep methods
1220 /*
1221 IF p_book_rec.life_in_months IS NULL THEN
1222 -- Life in Months not defined for asset ASSET_NUMBER and book BOOK
1223 OKL_API.set_message( p_app_name => 'OKL',
1224 p_msg_name => 'OKL_AM_NO_LIFE_IN_MONTHS',
1225 p_token1 => 'ASSET_NUMBER',
1226 p_token1_value => p_book_rec.asset_number,
1227 p_token2 => 'BOOK',
1228 p_token2_value => p_book_rec.book_type_code);
1229
1230 RAISE process_error;
1231 END IF;
1232 */
1233 -- SECHAWLA 28-MAY-04 3645574 : new validation, either life or rate should be defined
1234 IF p_book_rec.life_in_months IS NULL AND p_book_rec.deprn_rate IS NULL THEN
1235 -- Either Life in Months or Depreciation Rate should be defined for asset ASSET_NUMBER and book BOOK.
1236 OKL_API.set_message( p_app_name => 'OKL',
1237 p_msg_name => 'OKL_AM_NO_LIFE_NO_RATE',
1238 p_token1 => 'ASSET_NUMBER',
1239 p_token1_value => p_book_rec.asset_number,
1240 p_token2 => 'BOOK',
1241 p_token2_value => p_book_rec.book_type_code);
1242 RAISE process_error;
1243 END IF;
1244 -- SECHAWLA 28-MAY-04 3645574 : end new validation
1245 -------------------
1246
1247 --SECHAWLA 15-DEC-04 4028371 : get FA trx date
1248 OKL_ACCOUNTING_UTIL.get_fa_trx_date(p_book_type_code => p_book_rec.book_type_code,
1249 x_return_status => x_return_status,
1250 x_fa_trx_date => l_fa_trx_date);
1251
1252 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1253 RAISE process_unexp_error;
1254 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1255 RAISE process_error;
1256 END IF;
1257
1258 -- SGORANTL 22-MAR-06 5097643 : convert original_cost and depreciation_cost to functional currency
1259 IF p_df_original_cost IS NOT NULL THEN
1260 l_orig_cost_contr_currcy := p_df_original_cost;
1261 ELSE
1262 l_orig_cost_contr_currcy := p_oec;
1263 END IF;
1264
1265 -- convert orginal cost to functional currency, XILI 22-Feb-06 5029064
1266 OKL_ACCOUNTING_UTIL.convert_to_functional_currency(
1267 p_khr_id => p_book_rec.dnz_chr_id,
1268 p_to_currency => p_func_curr_code,
1269 p_transaction_date => p_sysdate,
1270 p_amount => l_orig_cost_contr_currcy,
1271 x_return_status => x_return_status,
1272 x_contract_currency => l_contract_currency_code,
1273 x_currency_conversion_type => l_currency_conversion_type,
1274 x_currency_conversion_rate => l_currency_conversion_rate,
1275 x_currency_conversion_date => l_currency_conversion_date,
1276 x_converted_amount => l_converted_amount);
1277
1278 IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
1279 RAISE process_unexp_error;
1280 END IF;
1281
1282 l_orig_cost_in_func := l_converted_amount;
1283
1284 -- convert net investment cost to functional currency, XILI 22-Feb-06 5029064
1285 OKL_ACCOUNTING_UTIL.convert_to_functional_currency(
1286 p_khr_id => p_book_rec.dnz_chr_id,
1287 p_to_currency => p_func_curr_code,
1288 p_transaction_date => p_sysdate,
1289 p_amount => p_net_investment_value,
1290 x_return_status => x_return_status,
1291 x_contract_currency => l_contract_currency_code,
1292 x_currency_conversion_type => l_currency_conversion_type,
1293 x_currency_conversion_rate => l_currency_conversion_rate,
1294 x_currency_conversion_date => l_currency_conversion_date,
1295 x_converted_amount => l_converted_amount);
1296
1297 IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
1298 RAISE process_unexp_error;
1299 END IF;
1300
1301 l_nest_invest_val_in_func := l_converted_amount;
1302 -- end of SGORANTL 22-MAR-06 5097643 : convert original_cost and depreciation_cost to functional currency
1303
1304 OKL_API.set_message('OKL', 'orig_cost=');
1305
1306
1307
1308 IF l_hold_period_days IS NOT NULL AND l_hold_period_days <> 0 THEN -- SECHAWLA 03-JUN-04 Added check for 0 hold period days
1309
1310
1311 -- SECHAWLA 06-MAY-04 3578894 : Split the 1st trx into 2 trasnactions : First Stop the depreciation
1312 -- and then update the cost. Split 2nd trx into 2 trasnactions : first update the dep method, life,
1313 -- cost, sv and then start the depreciation. This is required because FA does not allow updating depreciation
1314 -- flag with any other attributes. Details in bug 3501172
1315
1316 -- SECHAWLA 19-FEB-04 3439647 : Write asset cost up to the net investment and stop the dpreciation
1317 -- Start the depreciation when hold period expires
1318
1319 -- Create 1st transaction header
1320
1321 -- SECHAWLA 06-MAY-04 3578894 : Use a diff tas_type for dep flag only updates
1322 --lp_thpv_rec.tas_type := 'AMT';
1323 lp_thpv_rec.tas_type := 'AUD'; -- new tas_type
1324
1325
1326 lp_thpv_rec.tsu_code := 'ENTERED';
1327
1328 lp_thpv_rec.try_id := p_try_id;
1329 lp_thpv_rec.date_trans_occurred := p_sysdate;
1330 -- RRAVIKIR Legal Entity Changes
1331 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
1332 -- Legal Entity Changes End
1333
1334 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
1335 p_init_msg_list => OKL_API.G_FALSE,
1336 x_return_status => x_return_status,
1337 x_msg_count => x_msg_count,
1338 x_msg_data => x_msg_data,
1339 p_thpv_rec => lp_thpv_rec,
1340 x_thpv_rec => lx_thpv_rec);
1341
1342 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1343 RAISE process_unexp_error;
1344 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1345 RAISE process_error;
1346 END IF;
1347
1348 -- Create 1st transaction line to update asset cost and stop depreciation
1349 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
1350 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
1351 lp_tlpv_rec.kle_id := p_kle_id;
1352 lp_tlpv_rec.line_number := 1;
1353
1354 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
1355 --lp_tlpv_rec.tal_type := 'AML';
1356 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
1357
1358 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
1359 lp_tlpv_rec.description := p_book_rec.item_description;
1360
1361 -- SECHAWLA 06-MAY-04 3578894 : deprn method and life are populated in the 1st trx for display on
1362 -- off lease details screen. These will not be processed in FA when 1st trx is processed
1363 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code; -- original dep method
1364
1365 -- SECHAWLA 28-MAY-04 3645574 : Store either life or rate
1366 IF p_book_rec.life_in_months IS NOT NULL THEN
1367 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
1368 ELSE
1369 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
1370 END IF;
1371
1372
1373 lp_tlpv_rec.corporate_book := p_corporate_book;
1374
1375 -- SECHAWLA 06-MAY-04 3578894 : Do not update cost in 1st trx. Only update the depreciate_yn flag
1376 -- lp_tlpv_rec.depreciation_cost := l_net_investment_value;
1377
1378 -- populate sv for display on off lse upd screen
1379 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
1380
1381 /* -- SGORANTL 22-Feb-06 5097643
1382
1383 IF p_df_original_cost IS NOT NULL THEN
1384 lp_tlpv_rec.original_cost := p_df_original_cost;
1385 ELSE
1386 lp_tlpv_rec.original_cost := p_oec;
1387 END IF;
1388 */
1389
1390 lp_tlpv_rec.original_cost := l_orig_cost_in_func; --rmunjulu bug 6766343 - Added to pass asset orginal cost
1391
1392 lp_tlpv_rec.current_units := p_book_rec.current_units;
1393 lp_tlpv_rec.hold_period_days := l_hold_period_days;
1394 lp_tlpv_rec.depreciate_yn := 'N';
1395 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
1396 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
1397 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
1398
1399 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
1400 lp_tlpv_rec.currency_code := p_func_curr_code;
1401
1402 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
1403 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
1404
1405 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
1406 p_init_msg_list => OKL_API.G_FALSE,
1407 x_return_status => x_return_status,
1408 x_msg_count => x_msg_count,
1409 x_msg_data => x_msg_data,
1410 p_tlpv_rec => lp_tlpv_rec,
1411 x_tlpv_rec => lx_tlpv_rec);
1412
1413 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1414 RAISE process_unexp_error;
1415 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1416 RAISE process_error;
1417 END IF;
1418
1419
1420 -- When process_dfstlease_lessor procedure is called with mg rep book (tax book), then
1421 -- we need to create tax book trx also.
1422 IF p_book_rec.book_type_code <> p_corporate_book THEN
1423 IF p_book_rec.book_class = 'TAX' THEN
1424 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
1425 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
1426 lp_adpv_rec.asset_number := p_book_rec.asset_number;
1427 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
1428 p_api_version => p_api_version,
1429 p_init_msg_list => OKL_API.G_FALSE,
1430 x_return_status => x_return_status,
1431 x_msg_count => x_msg_count,
1432 x_msg_data => x_msg_data,
1433 p_adpv_rec => lp_adpv_rec,
1434 x_adpv_rec => lx_adpv_rec );
1435 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1436 RAISE process_unexp_error;
1437 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1438 RAISE process_error;
1439 END IF;
1440 END IF;
1441
1442 END IF;
1443 ----------------------------------
1444
1445 -- Validations for 2nd trx (if any) shold go here
1446
1447
1448 -- SECHAWLA 06-MAY-04 3578894 : Create 2nd trx (split from 1st) to update asset cost
1449
1450 -- Initialize the trx hdr and line for each trx
1451 lp_thpv_rec := lp_empty_thpv_rec;
1452 lp_tlpv_rec := lp_empty_tlpv_rec;
1453 lp_adpv_rec := lp_empty_adpv_rec;
1454
1455 -- SECHAWLA 22-MAR-04 : use a diff tas_type for cost only updates
1456 --lp_thpv_rec.tas_type := 'AMT';
1457 lp_thpv_rec.tas_type := 'AUS'; -- new tas_type
1458
1459
1460 lp_thpv_rec.tsu_code := 'ENTERED';
1461
1462 lp_thpv_rec.try_id := p_try_id;
1463 lp_thpv_rec.date_trans_occurred := p_sysdate;
1464 -- RRAVIKIR Legal Entity Changes
1465 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
1466 -- Legal Entity Changes End
1467
1468 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
1469 p_init_msg_list => OKL_API.G_FALSE,
1470 x_return_status => x_return_status,
1471 x_msg_count => x_msg_count,
1472 x_msg_data => x_msg_data,
1473 p_thpv_rec => lp_thpv_rec,
1474 x_thpv_rec => lx_thpv_rec);
1475
1476 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1477 RAISE process_unexp_error;
1478 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1479 RAISE process_error;
1480 END IF;
1481
1482 -- Create 2nd transaction line to update asset cost
1483 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
1484 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
1485 lp_tlpv_rec.kle_id := p_kle_id;
1486 lp_tlpv_rec.line_number := 1;
1487
1488 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for cost only updates
1489 --lp_tlpv_rec.tal_type := 'AML';
1490 lp_tlpv_rec.tal_type := 'AUT'; -- new tal_type
1491
1492 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
1493 lp_tlpv_rec.description := p_book_rec.item_description;
1494
1495 -- SECHAWLA 06-MAY-04 3578894 : deprn method and life are populated in the 2nd trx for display on
1496 -- off lease details screen. These will not be processed in FA when 2nd trx is processed
1497 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code; -- original dep method
1498
1499 -- SECHAWLA 28-MAY-04 3645574 : Store either life or rate
1500 IF p_book_rec.life_in_months IS NOT NULL THEN
1501 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
1502 ELSE
1503 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
1504 END IF;
1505
1506 lp_tlpv_rec.corporate_book := p_corporate_book;
1507
1508 --SECHAWLA 06-MAY-04 3578894 : Update cost
1509 /* -- SGORANTL 22-MAR-06 5097643
1510
1511 lp_tlpv_rec.depreciation_cost := p_net_investment_value; -- This would be reporting NIV if this
1512 -- procedure is called for reporting book
1513 -- Otherwise it would have base NIV value
1514
1515 IF p_df_original_cost IS NOT NULL THEN
1516 lp_tlpv_rec.original_cost := p_df_original_cost;
1517 ELSE
1518 lp_tlpv_rec.original_cost := p_oec;
1519 END IF;
1520 */
1521 -- rmunjulu bug 6766343 - Pass depreciation cost and original cost
1522 lp_tlpv_rec.depreciation_cost := l_nest_invest_val_in_func;
1523 lp_tlpv_rec.original_cost := l_orig_cost_in_func;
1524
1525 lp_tlpv_rec.current_units := p_book_rec.current_units;
1526 lp_tlpv_rec.hold_period_days := l_hold_period_days;
1527
1528 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 1st trx,so the process
1529 -- asset trx program can identify that these are split transactions. When this trx is processed, the flag
1530 -- is not updated in FA. Only cost will be updated
1531 lp_tlpv_rec.depreciate_yn := 'N';
1532
1533 -- populate sv for display on off lse upd screen
1534 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
1535
1536 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
1537 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
1538 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
1539
1540 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
1541 lp_tlpv_rec.currency_code := p_func_curr_code;
1542
1543 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx line
1544 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
1545
1546 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
1547 p_init_msg_list => OKL_API.G_FALSE,
1548 x_return_status => x_return_status,
1549 x_msg_count => x_msg_count,
1550 x_msg_data => x_msg_data,
1551 p_tlpv_rec => lp_tlpv_rec,
1552 x_tlpv_rec => lx_tlpv_rec);
1553
1554 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1555 RAISE process_unexp_error;
1556 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1557 RAISE process_error;
1558 END IF;
1559
1560 -- When process_dfstlease_lessor procedure is called with mg rep book (tax book), then
1561 -- we need to create tax book trx also.
1562 IF p_book_rec.book_type_code <> p_corporate_book THEN
1563 IF p_book_rec.book_class = 'TAX' THEN
1564 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
1565 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
1566 lp_adpv_rec.asset_number := p_book_rec.asset_number;
1567 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
1568 p_api_version => p_api_version,
1569 p_init_msg_list => OKL_API.G_FALSE,
1570 x_return_status => x_return_status,
1571 x_msg_count => x_msg_count,
1572 x_msg_data => x_msg_data,
1573 p_adpv_rec => lp_adpv_rec,
1574 x_adpv_rec => lx_adpv_rec );
1575 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1576 RAISE process_unexp_error;
1577 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1578 RAISE process_error;
1579 END IF;
1580 END IF;
1581
1582 END IF;
1583
1584 -- SECHAWLA 06-MAY-04 3578894 : end 2nd trx
1585 -----------------------------------
1586
1587 -- Validations for 3rd trx (if any) should go here
1588
1589
1590 -- SECHAWLA 06-MAY-04 3578894 : Split the 2nd trx into 2 transactions : first update dep method, life,
1591 -- cost, sv and then start the depreciation
1592
1593 -- Initialize the trx hdr and line for each trx
1594 lp_thpv_rec := lp_empty_thpv_rec;
1595 lp_tlpv_rec := lp_empty_tlpv_rec;
1596 lp_adpv_rec := lp_empty_adpv_rec;
1597
1598 -- Create 3rd Transaction Header
1599 lp_thpv_rec.tas_type := 'AMT';
1600
1601 lp_thpv_rec.tsu_code := 'ENTERED';
1602
1603
1604 lp_thpv_rec.try_id := p_try_id;
1605 lp_thpv_rec.date_trans_occurred := p_sysdate + l_hold_period_days;
1606 -- RRAVIKIR Legal Entity Changes
1607 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
1608 -- Legal Entity Changes End
1609
1610 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
1611 p_init_msg_list => OKL_API.G_FALSE,
1612 x_return_status => x_return_status,
1613 x_msg_count => x_msg_count,
1614 x_msg_data => x_msg_data,
1615 p_thpv_rec => lp_thpv_rec,
1616 x_thpv_rec => lx_thpv_rec);
1617
1618 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1619 RAISE process_unexp_error;
1620 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1621 RAISE process_error;
1622 END IF;
1623
1624 -- create 3rd transaction line
1625 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
1626 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
1627 lp_tlpv_rec.kle_id := p_kle_id;
1628 lp_tlpv_rec.line_number := 1;
1629 lp_tlpv_rec.tal_type := 'AML';
1630 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
1631 lp_tlpv_rec.description := p_book_rec.item_description;
1632
1633 -- SECHAWLA 19-FEB-04 3439647
1634 --lp_tlpv_rec.life_in_months := l_life_in_months;
1635
1636 -- If there is a method_id in okl_amort_hold_setups then use it. Otherwise get method id
1637 -- from fa_methods
1638
1639 IF l_setup_method_id IS NOT NULL THEN
1640 lp_tlpv_rec.deprn_method := l_fa_method_code;
1641
1642 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
1643 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
1644 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
1645 ELSE
1646 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
1647 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
1648 END IF;
1649 ELSE
1650 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
1651
1652 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
1653 IF p_book_rec.life_in_months IS NOT NULL THEN
1654 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
1655 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
1656 ELSE
1657 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
1658 END IF;
1659 END IF;
1660
1661 lp_tlpv_rec.corporate_book := p_corporate_book;
1662
1663
1664 --In case of direct finance/sales type of lease,Asset will exist in the corporate book, but with the Cost
1665 --and Original cost set to zero. Get Original cost from original creation line in Txl_assets, if it is
1666 --not found, then use OEC from OKL_K_LINES.OEC of the top financial asset line.
1667
1668 -- SECHAWLA 19-FEB-04 3439647 : Always update cost with net investment. At the end of the term, net investment = rv
1669 --IF p_early_termination_yn = 'N' THEN
1670 --lp_tlpv_rec.depreciation_cost := l_residual_value;
1671 --ELSE
1672
1673 -- SECHAWLA 19-FEB-04 3439647 : Moved this piece of code to the beginning
1674 --- /*okl_am_util_pvt.get_formula_value(
1675 -- p_formula_name => G_NET_INVESTMENT_FORMULA,
1676 -- p_chr_id => l_dnz_chr_id,
1677 -- p_cle_id => p_kle_id,
1678 -- x_formula_value => l_net_investment_value,
1679 -- x_return_status => x_return_status);
1680
1681 -- IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1682 -- RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1683 -- ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1684 -- RAISE OKL_API.G_EXCEPTION_ERROR;
1685 -- END IF;
1686 -- */
1687 /* -- SGORANTL 22-MAR-06 5097643
1688
1689 lp_tlpv_rec.depreciation_cost := p_net_investment_value;
1690
1691 -- END IF;
1692
1693
1694 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
1695 IF p_df_original_cost IS NOT NULL THEN
1696 lp_tlpv_rec.original_cost := p_df_original_cost;
1697 ELSE
1698 lp_tlpv_rec.original_cost := p_oec;
1699 END IF;
1700 */
1701
1702 lp_tlpv_rec.depreciation_cost := l_nest_invest_val_in_func; -- XILI 22-Feb-06 5029064
1703 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- XILI 22-Feb-06 5029064
1704 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
1705 lp_tlpv_rec.current_units := p_book_rec.current_units;
1706 lp_tlpv_rec.hold_period_days := l_hold_period_days;
1707
1708
1709 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 4th trx,so the process
1710 -- asset trx program can identify that these are split transactions. When this trx is processed, the flag
1711 -- is not updated in FA. Only dep method, life, cost and sv will be updated
1712 lp_tlpv_rec.depreciate_yn := 'Y';
1713
1714 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
1715 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
1716 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
1717
1718 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
1719 lp_tlpv_rec.currency_code := p_func_curr_code;
1720
1721 -- SECHAWLA 15-NOV-04 : set FA date on trx line
1722 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
1723
1724 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
1725 p_init_msg_list => OKL_API.G_FALSE,
1726 x_return_status => x_return_status,
1727 x_msg_count => x_msg_count,
1728 x_msg_data => x_msg_data,
1729 p_tlpv_rec => lp_tlpv_rec,
1730 x_tlpv_rec => lx_tlpv_rec);
1731
1732 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1733 RAISE process_unexp_error;
1734 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1735 RAISE process_error;
1736 END IF;
1737
1738
1739 -- When process_dfstlease_lessor procedure is called with mg rep book (tax book), then
1740 -- we need to create tax book trx also.
1741 IF p_book_rec.book_type_code <> p_corporate_book THEN
1742 IF p_book_rec.book_class = 'TAX' THEN
1743 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
1744 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
1745 lp_adpv_rec.asset_number := p_book_rec.asset_number;
1746 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
1747 p_api_version => p_api_version,
1748 p_init_msg_list => OKL_API.G_FALSE,
1749 x_return_status => x_return_status,
1750 x_msg_count => x_msg_count,
1751 x_msg_data => x_msg_data,
1752 p_adpv_rec => lp_adpv_rec,
1753 x_adpv_rec => lx_adpv_rec );
1754 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1755 RAISE process_unexp_error;
1756 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1757 RAISE process_error;
1758 END IF;
1759 END IF;
1760
1761 END IF;
1762 -----------------------------------------------------
1763
1764 -- Validations for 4th trx (if any) shold go here
1765
1766
1767 -- SECHAWLA 06-MAY-04 3578894 : Create 4th trx (split from 3rd)
1768
1769 -- Initialize the trx hdr and line for each trx
1770 lp_thpv_rec := lp_empty_thpv_rec;
1771 lp_tlpv_rec := lp_empty_tlpv_rec;
1772 lp_adpv_rec := lp_empty_adpv_rec;
1773
1774 -- Create 4th Transaction Header
1775
1776 --SECHAWLA 06-MAY-04 3578894 : Use a diff tas_type for dep flag only updates
1777
1778 lp_thpv_rec.tas_type := 'AUD'; -- new tas_type
1779
1780
1781 lp_thpv_rec.tsu_code := 'ENTERED';
1782
1783 lp_thpv_rec.try_id := p_try_id;
1784 lp_thpv_rec.date_trans_occurred := p_sysdate + l_hold_period_days;
1785 -- RRAVIKIR Legal Entity Changes
1786 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
1787 -- Legal Entity Changes End
1788
1789 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
1790 p_init_msg_list => OKL_API.G_FALSE,
1791 x_return_status => x_return_status,
1792 x_msg_count => x_msg_count,
1793 x_msg_data => x_msg_data,
1794 p_thpv_rec => lp_thpv_rec,
1795 x_thpv_rec => lx_thpv_rec);
1796
1797 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1798 RAISE process_unexp_error;
1799 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1800 RAISE process_error;
1801 END IF;
1802
1803 -- create 4th transaction line
1804 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
1805 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
1806 lp_tlpv_rec.kle_id := p_kle_id;
1807 lp_tlpv_rec.line_number := 1;
1808
1809 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
1810 --lp_tlpv_rec.tal_type := 'AML';
1811 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
1812
1813 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
1814 lp_tlpv_rec.description := p_book_rec.item_description;
1815
1816
1817 lp_tlpv_rec.corporate_book := p_corporate_book;
1818 /* -- SGORANTL 22-MAR-06 5097643
1819
1820 IF p_df_original_cost IS NOT NULL THEN
1821 lp_tlpv_rec.original_cost := p_df_original_cost;
1822 ELSE
1823 lp_tlpv_rec.original_cost := p_oec;
1824 END IF;
1825 */
1826
1827 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- XILI 22-Feb-06 5029064
1828 lp_tlpv_rec.current_units := p_book_rec.current_units;
1829 lp_tlpv_rec.hold_period_days := l_hold_period_days;
1830
1831 -- SECHAWLA 06-MAY-04 3578894 : Start the depreciation. Dep method, life, cost and sv are null
1832 -- when 4th trx is processed, only the dep flag will get updated
1833 lp_tlpv_rec.depreciate_yn := 'Y';
1834
1835 -- SECHAWLA 06-MAY-04 3578894 : populate dep method, life and sv for display on off lse trx upd screen
1836 IF l_setup_method_id IS NOT NULL THEN
1837 lp_tlpv_rec.deprn_method := l_fa_method_code;
1838
1839 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
1840 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
1841 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
1842 ELSE
1843 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
1844 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
1845 END IF;
1846 ELSE
1847 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
1848
1849 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
1850 IF p_book_rec.life_in_months IS NOT NULL THEN
1851 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
1852 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
1853 ELSE
1854 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
1855 END IF;
1856 END IF;
1857 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
1858
1859 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
1860 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
1861 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
1862
1863 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
1864 lp_tlpv_rec.currency_code := p_func_curr_code;
1865
1866 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
1867 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
1868
1869 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
1870 p_init_msg_list => OKL_API.G_FALSE,
1871 x_return_status => x_return_status,
1872 x_msg_count => x_msg_count,
1873 x_msg_data => x_msg_data,
1874 p_tlpv_rec => lp_tlpv_rec,
1875 x_tlpv_rec => lx_tlpv_rec);
1876
1877 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1878 RAISE process_unexp_error;
1879 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1880 RAISE process_error;
1881 END IF;
1882
1883 -- When process_dfstlease_lessor procedure is called with mg rep book (tax book), then
1884 -- we need to create tax book trx also.
1885 IF p_book_rec.book_type_code <> p_corporate_book THEN
1886 IF p_book_rec.book_class = 'TAX' THEN
1887 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
1888 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
1889 lp_adpv_rec.asset_number := p_book_rec.asset_number;
1890 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
1891 p_api_version => p_api_version,
1892 p_init_msg_list => OKL_API.G_FALSE,
1893 x_return_status => x_return_status,
1894 x_msg_count => x_msg_count,
1895 x_msg_data => x_msg_data,
1896 p_adpv_rec => lp_adpv_rec,
1897 x_adpv_rec => lx_adpv_rec );
1898 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1899 RAISE process_unexp_error;
1900 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1901 RAISE process_error;
1902 END IF;
1903 END IF;
1904
1905 END IF;
1906
1907 ELSE -- Hold period is null or 0
1908
1909 -- Split this trx into 2 trasnactions : first update dep method, life, cost, sv and then start depreciation
1910
1911
1912 -- Create 1st Transaction Header
1913
1914 lp_thpv_rec.tas_type := 'AMT';
1915
1916 lp_thpv_rec.tsu_code := 'ENTERED';
1917
1918 lp_thpv_rec.try_id := p_try_id;
1919 lp_thpv_rec.date_trans_occurred := p_sysdate;
1920 -- RRAVIKIR Legal Entity Changes
1921 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
1922 -- Legal Entity Changes End
1923
1924 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
1925 p_init_msg_list => OKL_API.G_FALSE,
1926 x_return_status => x_return_status,
1927 x_msg_count => x_msg_count,
1928 x_msg_data => x_msg_data,
1929 p_thpv_rec => lp_thpv_rec,
1930 x_thpv_rec => lx_thpv_rec);
1931
1932 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1933 RAISE process_unexp_error;
1934 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1935 RAISE process_error;
1936 END IF;
1937
1938 -- create transaction line
1939 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
1940 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
1941 lp_tlpv_rec.kle_id := p_kle_id;
1942 lp_tlpv_rec.line_number := 1;
1943 lp_tlpv_rec.tal_type := 'AML';
1944 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
1945 lp_tlpv_rec.description := p_book_rec.item_description;
1946
1947 -- SECHAWLA 19-FEB-04 3439647
1948 --lp_tlpv_rec.life_in_months := l_life_in_months;
1949
1950 -- If there is a method_id in okl_amort_hold_setups then use it. Otherwise get method id
1951 -- from fa_methods
1952
1953 IF l_setup_method_id IS NOT NULL THEN
1954 lp_tlpv_rec.deprn_method := l_fa_method_code;
1955
1956 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
1957 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
1958 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
1959 ELSE
1960 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
1961 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
1962 END IF;
1963 ELSE
1964 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
1965
1966 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
1967 IF p_book_rec.life_in_months IS NOT NULL THEN
1968 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
1969 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
1970 ELSE
1971 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
1972 END IF;
1973 END IF;
1974
1975 lp_tlpv_rec.corporate_book := p_corporate_book;
1976 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
1977
1978 --In case of direct finance/sales type of lease,Asset will exist in the corporate book, but with the Cost
1979 --and Original cost set to zero. Get Original cost from original creation line in Txl_assets, if it is
1980 --not found, then use OEC from OKL_K_LINES.OEC of the top financial asset line.
1981
1982 -- SECHAWLA 19-FEB-04 3439647 : Always update cost with net investment. At the end of the term, net investment = rv
1983 --IF p_early_termination_yn = 'N' THEN
1984 -- lp_tlpv_rec.depreciation_cost := l_residual_value;
1985 -- ELSE
1986
1987 -- SECHAWLA 19-FEB-04 3439647 : Moved this piece of code to the beginning
1988 -- /*
1989 -- okl_am_util_pvt.get_formula_value(
1990 -- p_formula_name => G_NET_INVESTMENT_FORMULA,
1991 -- p_chr_id => l_dnz_chr_id,
1992 -- p_cle_id => p_kle_id,
1993 -- x_formula_value => l_net_investment_value,
1994 -- x_return_status => x_return_status);
1995
1996 -- IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1997 -- RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1998 -- ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1999 -- RAISE OKL_API.G_EXCEPTION_ERROR;
2000 -- END IF;
2001 -- */
2002 lp_tlpv_rec.depreciation_cost := p_net_investment_value;
2003
2004 -- END IF;
2005 /* -- SGORANTL 22-MAR-06 5097643
2006
2007 IF p_df_original_cost IS NOT NULL THEN
2008 lp_tlpv_rec.original_cost := p_df_original_cost;
2009 ELSE
2010 lp_tlpv_rec.original_cost := p_oec;
2011 END IF;
2012 */
2013
2014 lp_tlpv_rec.depreciation_cost := l_nest_invest_val_in_func; -- SGORANTL 22-MAR-06 5097643
2015 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
2016 lp_tlpv_rec.current_units := p_book_rec.current_units;
2017 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 2nd trx,so the process
2018 -- asset trx program can identify that these are split transactions. When this trx is processed, the flag
2019 -- is not updated in FA. Only dep method, life, cost and sv will be updated
2020 lp_tlpv_rec.depreciate_yn := 'Y';
2021
2022 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
2023 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
2024 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
2025
2026 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
2027
2028 lp_tlpv_rec.currency_code := p_func_curr_code;
2029
2030 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
2031 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
2032
2033 OKL_TXL_ASSETS_PUB.create_txl_asset_def( p_api_version => p_api_version,
2034 p_init_msg_list => OKL_API.G_FALSE,
2035 x_return_status => x_return_status,
2036 x_msg_count => x_msg_count,
2037 x_msg_data => x_msg_data,
2038 p_tlpv_rec => lp_tlpv_rec,
2039 x_tlpv_rec => lx_tlpv_rec);
2040
2041 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2042 RAISE process_unexp_error;
2043 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2044 RAISE process_error;
2045 END IF;
2046
2047
2048 -- When process_dfstlease_lessor procedure is called with mg rep book (tax book), then
2049 -- we need to create tax book trx also.
2050 IF p_book_rec.book_type_code <> p_corporate_book THEN
2051 IF p_book_rec.book_class = 'TAX' THEN
2052 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
2053 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
2054 lp_adpv_rec.asset_number := p_book_rec.asset_number;
2055 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
2056 p_api_version => p_api_version,
2057 p_init_msg_list => OKL_API.G_FALSE,
2058 x_return_status => x_return_status,
2059 x_msg_count => x_msg_count,
2060 x_msg_data => x_msg_data,
2061 p_adpv_rec => lp_adpv_rec,
2062 x_adpv_rec => lx_adpv_rec );
2063 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2064 RAISE process_unexp_error;
2065 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2066 RAISE process_error;
2067 END IF;
2068 END IF;
2069
2070 END IF;
2071 -------------------------------------------------
2072
2073 -- Validations for 2nd trx (if any) should go here
2074
2075
2076 --SECHAWLA 06-MAY-04 3578894 : Create 2nd trx to start the depreciation
2077
2078 -- Initialize the trx hdr and line for each trx
2079 lp_thpv_rec := lp_empty_thpv_rec;
2080 lp_tlpv_rec := lp_empty_tlpv_rec;
2081 lp_adpv_rec := lp_empty_adpv_rec;
2082
2083 -- Create 2nd Transaction Header
2084
2085 -- SECHAWLA 06-MAY-04 3578894 : use a diff tas_type from dep flag only updates
2086 --lp_thpv_rec.tas_type := 'AMT';
2087 lp_thpv_rec.tas_type := 'AUD'; -- new tas_type
2088
2089 lp_thpv_rec.tsu_code := 'ENTERED';
2090 lp_thpv_rec.try_id := p_try_id;
2091 lp_thpv_rec.date_trans_occurred := p_sysdate;
2092 -- RRAVIKIR Legal Entity Changes
2093 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
2094 -- Legal Entity Changes End
2095
2096 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
2097 p_init_msg_list => OKL_API.G_FALSE,
2098 x_return_status => x_return_status,
2099 x_msg_count => x_msg_count,
2100 x_msg_data => x_msg_data,
2101 p_thpv_rec => lp_thpv_rec,
2102 x_thpv_rec => lx_thpv_rec);
2103
2104 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2105 RAISE process_unexp_error;
2106 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2107 RAISE process_error;
2108 END IF;
2109
2110 -- create 2nd transaction line
2111 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
2112 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
2113 lp_tlpv_rec.kle_id := p_kle_id;
2114 lp_tlpv_rec.line_number := 1;
2115
2116 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
2117 --lp_tlpv_rec.tal_type := 'AML';
2118 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
2119
2120 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
2121 lp_tlpv_rec.description := p_book_rec.item_description;
2122
2123 lp_tlpv_rec.corporate_book := p_corporate_book;
2124
2125 /* -- SGORANTL 22-MAR-06 5097643
2126
2127 IF p_df_original_cost IS NOT NULL THEN
2128 lp_tlpv_rec.original_cost := p_df_original_cost;
2129 ELSE
2130 lp_tlpv_rec.original_cost := p_oec;
2131 END IF;
2132 */
2133
2134 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
2135 lp_tlpv_rec.current_units := p_book_rec.current_units;
2136
2137 -- SECHAWLA 06-MAY-04 3578894 : start the depreciation. dep method, life, cost and sv are null. When
2138 -- this trx is processed in FA, only dep flag will be updated.
2139 lp_tlpv_rec.depreciate_yn := 'Y';
2140
2141 -- SECHAWLA 06-MAY-04 3578894 : populate dep method, life and sv for display on off lse trx upd screen
2142 IF l_setup_method_id IS NOT NULL THEN
2143 lp_tlpv_rec.deprn_method := l_fa_method_code;
2144
2145 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
2146 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
2147 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
2148 ELSE
2149 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
2150 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
2151 END IF;
2152 ELSE
2153 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
2154
2155 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
2156 IF p_book_rec.life_in_months IS NOT NULL THEN
2157 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
2158 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
2159 ELSE
2160 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
2161 END IF;
2162 END IF;
2163 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
2164
2165 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
2166 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
2167 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
2168
2169 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
2170 lp_tlpv_rec.currency_code := p_func_curr_code;
2171
2172 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
2173 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
2174
2175 OKL_TXL_ASSETS_PUB.create_txl_asset_def( p_api_version => p_api_version,
2176 p_init_msg_list => OKL_API.G_FALSE,
2177 x_return_status => x_return_status,
2178 x_msg_count => x_msg_count,
2179 x_msg_data => x_msg_data,
2180 p_tlpv_rec => lp_tlpv_rec,
2181 x_tlpv_rec => lx_tlpv_rec);
2182
2183 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2184 RAISE process_unexp_error;
2185 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2186 RAISE process_error;
2187 END IF;
2188
2189 -- When process_dfstlease_lessor procedure is called with mg rep book (tax book), then
2190 -- we need to create tax book trx also.
2191 IF p_book_rec.book_type_code <> p_corporate_book THEN
2192 IF p_book_rec.book_class = 'TAX' THEN
2193 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
2194 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
2195 lp_adpv_rec.asset_number := p_book_rec.asset_number;
2196 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
2197 p_api_version => p_api_version,
2198 p_init_msg_list => OKL_API.G_FALSE,
2199 x_return_status => x_return_status,
2200 x_msg_count => x_msg_count,
2201 x_msg_data => x_msg_data,
2202 p_adpv_rec => lp_adpv_rec,
2203 x_adpv_rec => lx_adpv_rec );
2204 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2205 RAISE process_unexp_error;
2206 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2207 RAISE process_error;
2208 END IF;
2209 END IF;
2210
2211 END IF;
2212
2213 END IF; -- hold period days is null
2214
2215
2216 EXCEPTION
2217 WHEN process_error THEN
2218 IF l_methodcode_csr%ISOPEN THEN
2219 CLOSE l_methodcode_csr;
2220 END IF;
2221
2222 IF l_amthld_csr%ISOPEN THEN
2223 CLOSE l_amthld_csr;
2224 END IF;
2225
2226
2227 x_return_status := OKL_API.G_RET_STS_ERROR;
2228 WHEN process_unexp_error THEN
2229
2230 IF l_methodcode_csr%ISOPEN THEN
2231 CLOSE l_methodcode_csr;
2232 END IF;
2233
2234 IF l_amthld_csr%ISOPEN THEN
2235 CLOSE l_amthld_csr;
2236 END IF;
2237
2238 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2239 WHEN OTHERS THEN
2240
2241 IF l_methodcode_csr%ISOPEN THEN
2242 CLOSE l_methodcode_csr;
2243 END IF;
2244
2245 IF l_amthld_csr%ISOPEN THEN
2246 CLOSE l_amthld_csr;
2247 END IF;
2248 -- unexpected error
2249 OKL_API.set_message(p_app_name => 'OKC',
2250 p_msg_name => g_unexpected_error,
2251 p_token1 => g_sqlcode_token,
2252 p_token1_value => sqlcode,
2253 p_token2 => g_sqlerrm_token,
2254 p_token2_value => sqlerrm);
2255 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2256
2257 END process_dfstlease_lessor;
2258
2259
2260 -- Start of comments
2261 --
2262 -- Procedure Name : process_dfstlease_lessee
2263 -- Description : This procedure creates off lease transactions for an asset in DF/Sales lease,
2264 -- when tax owner is lessee
2265 -- Business Rules :
2266 -- Parameters : p_book_rec : record type parameter with corporate/tax book information
2267 -- p_corporate_book : corporate book
2268 -- p_kle_id : asset line id
2269 -- p_df_original_cost : original cost
2270 -- p_oec : original equipment cost
2271 -- p_net_investment_value : net investment
2272 -- p_try_id : transaction type id
2273 -- p_sysdate : today's date
2274 -- p_func_curr_code : functional currency code
2275 -- Version : 1.0
2276 -- History : SECHAWLA 06-APR-04 - Created
2277 -- SECHAWLA 28-MAY-04 3645574 : Added processing logic for deprn rate for diminishing dep methods
2278 -- SECHAWLA 15-DEC-04 4028371 : set FA trx date on trx line
2279 -- End of comments
2280
2281 PROCEDURE process_dfstlease_lessee( p_api_version IN NUMBER,
2282 p_init_msg_list IN VARCHAR2 ,
2283 x_return_status OUT NOCOPY VARCHAR2,
2284 x_msg_count OUT NOCOPY NUMBER,
2285 x_msg_data OUT NOCOPY VARCHAR2,
2286 p_book_rec IN book_rec_type,
2287 p_corporate_book IN VARCHAR2,
2288 p_kle_id IN NUMBER,
2289 p_df_original_cost IN NUMBER,
2290 p_oec IN NUMBER,
2291 p_net_investment_value IN NUMBER,
2292 p_try_id IN NUMBER,
2293 p_sysdate IN DATE,
2294 p_func_curr_code IN VARCHAR2,
2295 p_legal_entity_id IN NUMBER) IS -- RRAVIKIR Legal Entity Changes
2296
2297 process_error EXCEPTION;
2298 process_unexp_error EXCEPTION;
2299
2300
2301
2302 --SECHAWLA 19-FEB-04 3439647 : added life_in_months to the select clause
2303 -- This cursor will return a method_code corresponding to a unique method_id
2304 CURSOR l_methodcode_csr(p_method_id fa_methods.method_id%TYPE) IS
2305 SELECT method_code, life_in_months
2306 FROM fa_methods
2307 WHERE method_id = p_method_id;
2308
2309
2310
2311 -- This cursor will return the hold period days and the default depreciation method from a hold period setup table
2312 -- using category_id and book_type_code.
2313 CURSOR l_amthld_csr(p_category_id okl_amort_hold_setups.category_id%TYPE,
2314 p_book_type_code okl_amort_hold_setups.book_type_code%TYPE) IS
2315 -- SECHAWLA 28-MAY-04 3645574 : Added deprn_rate
2316 SELECT hold_period_days, method_id, deprn_rate
2317 FROM okl_amort_hold_setups
2318 WHERE category_id = p_category_id
2319 AND book_type_code = p_book_type_code;
2320
2321 l_hold_period_days okl_amort_hold_setups.hold_period_days%TYPE;
2322 l_setup_method_id okl_amort_hold_setups.method_id%TYPE;
2323 l_fa_method_code fa_methods.method_code%TYPE;
2324 l_fa_life_in_months fa_methods.life_in_months%TYPE;
2325 lp_thpv_rec thpv_rec_type;
2326 lx_thpv_rec thpv_rec_type;
2327 lp_tlpv_rec tlpv_rec_type;
2328 lx_tlpv_rec tlpv_rec_type;
2329 lp_empty_thpv_rec thpv_rec_type;
2330 lp_empty_tlpv_rec tlpv_rec_type;
2331 SUBTYPE adpv_rec_type IS OKL_TXD_ASSETS_PUB.adpv_rec_type;
2332 lp_adpv_rec adpv_rec_type;
2333 lx_adpv_rec adpv_rec_type;
2334 lp_empty_adpv_rec adpv_rec_type;
2335
2336 -- SECHAWLA 28-MAY-04 3645574 : new declaration
2337 l_setup_deprn_rate NUMBER;
2338
2339 -- SECHAWLA 15-DEC-04 4028371 : new declartions
2340 l_fa_trx_date DATE;
2341
2342 -- SGORANTL 22-MAR-06 5097643 : new declartions
2343 l_contract_currency_code VARCHAR2(15);
2344 l_currency_conversion_type VARCHAR2(30);
2345 l_currency_conversion_rate NUMBER;
2346 l_currency_conversion_date DATE;
2347 l_converted_amount NUMBER;
2348 l_orig_cost_contr_currcy NUMBER; -- orginal cost in contract currency
2349 l_orig_cost_in_func NUMBER; -- orginal cost converted to functional currency before the hold period
2350 l_nest_invest_val_in_func NUMBER; -- net investment value converted to functional currency before the hold period
2351 -- end of SGORANTL 22-MAR-06 5097643
2352
2353
2354
2355 BEGIN
2356 -- get the hold period and dep method from setup, for each book/category
2357 OPEN l_amthld_csr(p_book_rec.depreciation_category, p_book_rec.book_type_code);
2358 -- SECHAWLA 28-MAY-04 3645574 : Added l_setup_deprn_rate
2359 FETCH l_amthld_csr INTO l_hold_period_days,l_setup_method_id, l_setup_deprn_rate; --l_setup_deprn_rate could be null;
2360 CLOSE l_amthld_csr;
2361
2362
2363
2364 -- If there is a method_id in okl_amort_hold_setups then use it to get deprn method from fa_methods.
2365
2366 IF l_setup_method_id IS NOT NULL THEN
2367 OPEN l_methodcode_csr(l_setup_method_id);
2368 -- SECHAWLA 19-FEB-04 3439647 : Added l_fa_life_in_months
2369 FETCH l_methodcode_csr INTO l_fa_method_code, l_fa_life_in_months;
2370 IF l_methodcode_csr%NOTFOUND THEN
2371 -- The depreciation method defined for category DEPRN_CAT and book BOOK is invalid.
2372 OKL_API.set_message( p_app_name => 'OKL',
2373 p_msg_name => 'OKL_AM_INVALID_DEPRN_MTHD',
2374 p_token1 => 'DEPRN_CAT',
2375 p_token1_value => p_book_rec.depreciation_category,
2376 p_token2 => 'BOOK',
2377 p_token2_value => p_book_rec.book_type_code);
2378 RAISE process_error;
2379
2380 END IF;
2381 CLOSE l_methodcode_csr;
2382 END IF;
2383
2384 -- SECHAWLA 28-MAY-04 3645574 : Removing this validation, as life is null for diminishing dep methods
2385 /*
2386 IF p_book_rec.life_in_months IS NULL THEN
2387 -- Life in Months not defined for asset
2388 OKL_API.set_message( p_app_name => 'OKL',
2389 p_msg_name => 'OKL_AM_NO_LIFE_IN_MONTHS',
2390 p_token1 => 'ASSET_NUMBER',
2391 p_token1_value => p_book_rec.asset_number,
2392 p_token2 => 'BOOK',
2393 p_token2_value => p_book_rec.book_type_code);
2394 RAISE process_error;
2395 END IF;
2396 */
2397
2398 -- SECHAWLA 28-MAY-04 3645574 : new validation, eithr life or rate should be defined
2399 IF p_book_rec.life_in_months IS NULL AND p_book_rec.deprn_rate IS NULL THEN
2400 -- Either Life in Months or Depreciation Rate should be defined for asset ASSET_NUMBER and book BOOK.
2401 OKL_API.set_message( p_app_name => 'OKL',
2402 p_msg_name => 'OKL_AM_NO_LIFE_NO_RATE',
2403 p_token1 => 'ASSET_NUMBER',
2404 p_token1_value => p_book_rec.asset_number,
2405 p_token2 => 'BOOK',
2406 p_token2_value => p_book_rec.book_type_code);
2407 RAISE process_error;
2408 END IF;
2409 -- SECHAWLA 28-MAY-04 3645574 : end new validation
2410 -------------------
2411 --SECHAWLA 15-DEC-04 4028371 : get FA trx date
2412 OKL_ACCOUNTING_UTIL.get_fa_trx_date(p_book_type_code => p_book_rec.book_type_code,
2413 x_return_status => x_return_status,
2414 x_fa_trx_date => l_fa_trx_date);
2415
2416 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2417 RAISE process_unexp_error;
2418 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2419 RAISE process_error;
2420 END IF;
2421
2422 -- SGORANTL 22-MAR-06 5097643 : convert original_cost and depreciation_cost to functional currency
2423 IF p_df_original_cost IS NOT NULL THEN
2424 l_orig_cost_contr_currcy := p_df_original_cost;
2425 ELSE
2426 l_orig_cost_contr_currcy := p_oec;
2427 END IF;
2428
2429 -- convert orginal cost to functional currency, XILI 22-Feb-06 5029064
2430 OKL_ACCOUNTING_UTIL.convert_to_functional_currency(
2431 p_khr_id => p_book_rec.dnz_chr_id,
2432 p_to_currency => p_func_curr_code,
2433 p_transaction_date => p_sysdate,
2434 p_amount => l_orig_cost_contr_currcy,
2435 x_return_status => x_return_status,
2436 x_contract_currency => l_contract_currency_code,
2437 x_currency_conversion_type => l_currency_conversion_type,
2438 x_currency_conversion_rate => l_currency_conversion_rate,
2439 x_currency_conversion_date => l_currency_conversion_date,
2440 x_converted_amount => l_converted_amount);
2441
2442 IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
2443 RAISE process_unexp_error;
2444 END IF;
2445
2446 l_orig_cost_in_func := l_converted_amount;
2447
2448 -- convert net investment cost to functional currency, XILI 22-Feb-06 5029064
2449 OKL_ACCOUNTING_UTIL.convert_to_functional_currency(
2450 p_khr_id => p_book_rec.dnz_chr_id,
2451 p_to_currency => p_func_curr_code,
2452 p_transaction_date => p_sysdate,
2453 p_amount => p_net_investment_value,
2454 x_return_status => x_return_status,
2455 x_contract_currency => l_contract_currency_code,
2456 x_currency_conversion_type => l_currency_conversion_type,
2457 x_currency_conversion_rate => l_currency_conversion_rate,
2458 x_currency_conversion_date => l_currency_conversion_date,
2459 x_converted_amount => l_converted_amount);
2460
2461 IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
2462 RAISE process_unexp_error;
2463 END IF;
2464
2465 l_nest_invest_val_in_func := l_converted_amount;
2466 -- end of SGORANTL 22-MAR-06 5097643 : convert original_cost and depreciation_cost to functional currency
2467
2468
2469
2470 IF l_hold_period_days IS NOT NULL AND l_hold_period_days <> 0 THEN -- SECHAWLA 03-JUN-04 Added check for 0 hold period days
2471
2472
2473 -- SECHAWLA 06-MAY-04 3578894 : Split the 1st trx into 2 trasnactions : First Stop the depreciation
2474 -- and then update the cost. Split 2nd trx into 2 trasnactions : first update the dep method, life,
2475 -- cost, sv and then start the depreciation. This is required because FA does not allow updating depreciation
2476 -- flag with any other attributes. Details in bug 3501172
2477
2478 -- SECHAWLA 19-FEB-04 3439647 : Write asset cost up to the net investment and stop the dpreciation
2479 -- Start the depreciation when hold period expires
2480
2481 -- Create 1st transaction header
2482
2483 -- SECHAWLA 06-MAY-04 3578894 : Use a diff tas_type for dep flag only updates
2484 --lp_thpv_rec.tas_type := 'AMT';
2485 lp_thpv_rec.tas_type := 'AUD'; -- new tas_type
2486
2487 lp_thpv_rec.tsu_code := 'ENTERED';
2488
2489 lp_thpv_rec.try_id := p_try_id;
2490 lp_thpv_rec.date_trans_occurred := p_sysdate;
2491 -- RRAVIKIR Legal Entity Changes
2492 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
2493 -- Legal Entity Changes End
2494
2495 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
2496 p_init_msg_list => OKL_API.G_FALSE,
2497 x_return_status => x_return_status,
2498 x_msg_count => x_msg_count,
2499 x_msg_data => x_msg_data,
2500 p_thpv_rec => lp_thpv_rec,
2501 x_thpv_rec => lx_thpv_rec);
2502
2503 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2504 RAISE process_unexp_error;
2505 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2506 RAISE process_error;
2507 END IF;
2508
2509 -- Create 1st transaction line to update asset cost and stop depreciation
2510 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
2511 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
2512 lp_tlpv_rec.kle_id := p_kle_id;
2513 lp_tlpv_rec.line_number := 1;
2514
2515 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
2516 --lp_tlpv_rec.tal_type := 'AML';
2517 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
2518
2519 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
2520 lp_tlpv_rec.description := p_book_rec.item_description;
2521
2522 -- SECHAWLA 06-MAY-04 3578894 : deprn method and life are populated in the 1st trx for display on
2523 -- off lease details screen. These will not be processed in FA when 1st trx is processed
2524 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code; -- original dep method
2525
2526 -- SECHAWLA 28-MAY-04 3645574 : Store either life or rate
2527 IF p_book_rec.life_in_months IS NOT NULL THEN
2528 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
2529 ELSE
2530 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
2531 END IF;
2532
2533
2534 lp_tlpv_rec.corporate_book := p_corporate_book;
2535
2536 -- SECHAWLA 06-MAY-04 3578894 : Do not update cost in 1st trx. Only update the depreciate_yn flag
2537 -- lp_tlpv_rec.depreciation_cost := l_net_investment_value;
2538
2539 -- populate sv for display on off lse upd screen
2540 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
2541
2542 /* -- SGORANTL 22-MAR-06 5097643
2543
2544 IF p_df_original_cost IS NOT NULL THEN
2545 lp_tlpv_rec.original_cost := p_df_original_cost;
2546 ELSE
2547 lp_tlpv_rec.original_cost := p_oec;
2548 END IF;
2549 */
2550 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
2551 lp_tlpv_rec.current_units := p_book_rec.current_units;
2552 lp_tlpv_rec.hold_period_days := l_hold_period_days;
2553 lp_tlpv_rec.depreciate_yn := 'N';
2554 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
2555 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
2556 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
2557
2558 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
2559 lp_tlpv_rec.currency_code := p_func_curr_code;
2560
2561 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
2562 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
2563
2564 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
2565 p_init_msg_list => OKL_API.G_FALSE,
2566 x_return_status => x_return_status,
2567 x_msg_count => x_msg_count,
2568 x_msg_data => x_msg_data,
2569 p_tlpv_rec => lp_tlpv_rec,
2570 x_tlpv_rec => lx_tlpv_rec);
2571
2572 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2573 RAISE process_unexp_error;
2574 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2575 RAISE process_error;
2576 END IF;
2577
2578 -- SECHAWLA 06-MAY-04 3578894 : If this book is a tax book, also create a row in okl_txd_assets_b
2579 IF p_book_rec.book_class = 'TAX' THEN
2580 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
2581 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
2582 lp_adpv_rec.asset_number := p_book_rec.asset_number;
2583 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
2584 p_api_version => p_api_version,
2585 p_init_msg_list => OKL_API.G_FALSE,
2586 x_return_status => x_return_status,
2587 x_msg_count => x_msg_count,
2588 x_msg_data => x_msg_data,
2589 p_adpv_rec => lp_adpv_rec,
2590 x_adpv_rec => lx_adpv_rec );
2591 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2592 RAISE process_unexp_error;
2593 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2594 RAISE process_error;
2595 END IF;
2596 END IF;
2597
2598 ----------------------------------
2599
2600
2601
2602 -- Validations for 2nd trx (if any) shold go here
2603
2604
2605 -- SECHAWLA 06-MAY-04 3578894 : Create 2nd trx (split from 1st) to update asset cost
2606
2607 -- Initialize the trx hdr and line for each trx
2608 lp_thpv_rec := lp_empty_thpv_rec;
2609 lp_tlpv_rec := lp_empty_tlpv_rec;
2610 lp_adpv_rec := lp_empty_adpv_rec;
2611
2612 -- SECHAWLA 22-MAR-04 : use a diff tas_type for cost only updates
2613 --lp_thpv_rec.tas_type := 'AMT';
2614 lp_thpv_rec.tas_type := 'AUS'; -- new tas_type
2615
2616 lp_thpv_rec.tsu_code := 'ENTERED';
2617 lp_thpv_rec.try_id := p_try_id;
2618 lp_thpv_rec.date_trans_occurred := p_sysdate;
2619 -- RRAVIKIR Legal Entity Changes
2620 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
2621 -- Legal Entity Changes End
2622
2623 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
2624 p_init_msg_list => OKL_API.G_FALSE,
2625 x_return_status => x_return_status,
2626 x_msg_count => x_msg_count,
2627 x_msg_data => x_msg_data,
2628 p_thpv_rec => lp_thpv_rec,
2629 x_thpv_rec => lx_thpv_rec);
2630
2631 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2632 RAISE process_unexp_error;
2633 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2634 RAISE process_error;
2635 END IF;
2636
2637 -- Create 2nd transaction line to update asset cost
2638 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
2639 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
2640 lp_tlpv_rec.kle_id := p_kle_id;
2641 lp_tlpv_rec.line_number := 1;
2642
2643 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for cost only updates
2644 --lp_tlpv_rec.tal_type := 'AML';
2645 lp_tlpv_rec.tal_type := 'AUT'; -- new tal_type
2646
2647 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
2648 lp_tlpv_rec.description := p_book_rec.item_description;
2649
2650 -- SECHAWLA 06-MAY-04 3578894 : deprn method and life are populated in the 2nd trx for display on
2651 -- off lease details screen. These will not be processed in FA when 2nd trx is processed
2652 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code; -- original dep method
2653
2654 -- SECHAWLA 28-MAY-04 3645574 : Store either life or rate
2655 IF p_book_rec.life_in_months IS NOT NULL THEN
2656 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
2657 ELSE
2658 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
2659 END IF;
2660
2661 lp_tlpv_rec.corporate_book := p_corporate_book;
2662
2663 --SECHAWLA 06-MAY-04 3578894 : Update cost
2664 lp_tlpv_rec.depreciation_cost := p_net_investment_value;
2665 /* -- SGORANTL 22-MAR-06 5097643
2666
2667 IF p_df_original_cost IS NOT NULL THEN
2668 lp_tlpv_rec.original_cost := p_df_original_cost;
2669 ELSE
2670 lp_tlpv_rec.original_cost := p_oec;
2671 END IF;
2672 */
2673 lp_tlpv_rec.depreciation_cost := l_nest_invest_val_in_func; -- SGORANTL 22-MAR-06 5097643
2674 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
2675 lp_tlpv_rec.current_units := p_book_rec.current_units;
2676 lp_tlpv_rec.hold_period_days := l_hold_period_days;
2677
2678 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 1st trx,so the process
2679 -- asset trx program can identify that these are split transactions. When this trx is processed, the flag
2680 -- is not updated in FA. Only cost will be updated
2681 lp_tlpv_rec.depreciate_yn := 'N';
2682
2683 -- populate sv for display on off lse upd screen
2684 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
2685
2686 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
2687 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
2688 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
2689
2690 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
2691 lp_tlpv_rec.currency_code := p_func_curr_code;
2692
2693 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
2694 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
2695
2696 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
2697 p_init_msg_list => OKL_API.G_FALSE,
2698 x_return_status => x_return_status,
2699 x_msg_count => x_msg_count,
2700 x_msg_data => x_msg_data,
2701 p_tlpv_rec => lp_tlpv_rec,
2702 x_tlpv_rec => lx_tlpv_rec);
2703
2704 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2705 RAISE process_unexp_error;
2706 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2707 RAISE process_error;
2708 END IF;
2709
2710 -- SECHAWLA 06-MAY-04 3578894 : If this book is a tax book, also create a row in okl_txd_assets_b
2711 IF p_book_rec.book_class = 'TAX' THEN
2712 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
2713 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
2714 lp_adpv_rec.asset_number := p_book_rec.asset_number;
2715 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
2716 p_api_version => p_api_version,
2717 p_init_msg_list => OKL_API.G_FALSE,
2718 x_return_status => x_return_status,
2719 x_msg_count => x_msg_count,
2720 x_msg_data => x_msg_data,
2721 p_adpv_rec => lp_adpv_rec,
2722 x_adpv_rec => lx_adpv_rec );
2723 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2724 RAISE process_unexp_error;
2725 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2726 RAISE process_error;
2727 END IF;
2728
2729 END IF;
2730
2731 -- SECHAWLA 06-MAY-04 3578894 : end 2nd trx
2732 -----------------------------------
2733
2734 -- Validations for 3rd trx (if any) shold go here
2735
2736
2737 -- SECHAWLA 06-MAY-04 3578894 : Split the 2nd trx into 2 transactions : first update dep method, life,
2738 -- cost, sv and then start the depreciation
2739
2740 -- Initialize the trx hdr and line for each trx
2741 lp_thpv_rec := lp_empty_thpv_rec;
2742 lp_tlpv_rec := lp_empty_tlpv_rec;
2743 lp_adpv_rec := lp_empty_adpv_rec;
2744
2745 -- Create 3rd Transaction Header
2746 lp_thpv_rec.tas_type := 'AMT';
2747 lp_thpv_rec.tsu_code := 'ENTERED';
2748
2749 lp_thpv_rec.try_id := p_try_id;
2750 lp_thpv_rec.date_trans_occurred := p_sysdate + l_hold_period_days;
2751 -- RRAVIKIR Legal Entity Changes
2752 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
2753 -- Legal Entity Changes End
2754
2755 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
2756 p_init_msg_list => OKL_API.G_FALSE,
2757 x_return_status => x_return_status,
2758 x_msg_count => x_msg_count,
2759 x_msg_data => x_msg_data,
2760 p_thpv_rec => lp_thpv_rec,
2761 x_thpv_rec => lx_thpv_rec);
2762
2763 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2764 RAISE process_unexp_error;
2765 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2766 RAISE process_error;
2767 END IF;
2768
2769 -- create 3rd transaction line
2770 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
2771 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
2772 lp_tlpv_rec.kle_id := p_kle_id;
2773 lp_tlpv_rec.line_number := 1;
2774 lp_tlpv_rec.tal_type := 'AML';
2775 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
2776 lp_tlpv_rec.description := p_book_rec.item_description;
2777
2778 -- SECHAWLA 19-FEB-04 3439647
2779 --lp_tlpv_rec.life_in_months := l_life_in_months;
2780
2781 -- If there is a method_id in okl_amort_hold_setups then use it. Otherwise get method id
2782 -- from fa_methods
2783
2784 IF l_setup_method_id IS NOT NULL THEN
2785 lp_tlpv_rec.deprn_method := l_fa_method_code;
2786
2787 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
2788 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
2789 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
2790 ELSE
2791 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
2792 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
2793 END IF;
2794
2795 ELSE
2796 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
2797
2798 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
2799 IF p_book_rec.life_in_months IS NOT NULL THEN
2800 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
2801 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
2802 ELSE
2803 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
2804 END IF;
2805 END IF;
2806
2807 lp_tlpv_rec.corporate_book := p_corporate_book;
2808
2809
2810 --In case of direct finance/sales type of lease,Asset will exist in the corporate book, but with the Cost
2811 --and Original cost set to zero. Get Original cost from original creation line in Txl_assets, if it is
2812 --not found, then use OEC from OKL_K_LINES.OEC of the top financial asset line.
2813
2814 -- SECHAWLA 19-FEB-04 3439647 : Always update cost with net investment. At the end of the term, net investment = rv
2815 --IF p_early_termination_yn = 'N' THEN
2816 --lp_tlpv_rec.depreciation_cost := l_residual_value;
2817 --ELSE
2818
2819 -- SECHAWLA 19-FEB-04 3439647 : Moved this piece of code to the beginning
2820 -- /*okl_am_util_pvt.get_formula_value(
2821 -- p_formula_name => G_NET_INVESTMENT_FORMULA,
2822 -- p_chr_id => l_dnz_chr_id,
2823 -- p_cle_id => p_kle_id,
2824 -- x_formula_value => l_net_investment_value,
2825 -- x_return_status => x_return_status);
2826
2827 -- IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2828 -- RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2829 -- ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2830 -- RAISE OKL_API.G_EXCEPTION_ERROR;
2831 -- END IF;
2832 -- */
2833
2834 /* -- SGORANTL 22-MAR-06 5097643
2835
2836 lp_tlpv_rec.depreciation_cost := p_net_investment_value;
2837
2838 -- END IF;
2839
2840
2841 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
2842 IF p_df_original_cost IS NOT NULL THEN
2843 lp_tlpv_rec.original_cost := p_df_original_cost;
2844 ELSE
2845 lp_tlpv_rec.original_cost := p_oec;
2846 END IF;
2847 */
2848
2849 lp_tlpv_rec.depreciation_cost := l_nest_invest_val_in_func; -- SGORANTL 22-MAR-06 5097643
2850 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
2851 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
2852 lp_tlpv_rec.current_units := p_book_rec.current_units;
2853 lp_tlpv_rec.hold_period_days := l_hold_period_days;
2854
2855
2856 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 4th trx,so the process
2857 -- asset trx program can identify that these are split transactions. When this trx is processed, the flag
2858 -- is not updated in FA. Only dep method, life, cost and sv will be updated
2859 lp_tlpv_rec.depreciate_yn := 'Y';
2860
2861 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
2862 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
2863 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
2864
2865 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
2866 lp_tlpv_rec.currency_code := p_func_curr_code;
2867
2868 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
2869 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
2870
2871 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
2872 p_init_msg_list => OKL_API.G_FALSE,
2873 x_return_status => x_return_status,
2874 x_msg_count => x_msg_count,
2875 x_msg_data => x_msg_data,
2876 p_tlpv_rec => lp_tlpv_rec,
2877 x_tlpv_rec => lx_tlpv_rec);
2878
2879 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2880 RAISE process_unexp_error;
2881 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2882 RAISE process_error;
2883 END IF;
2884
2885 -- SECHAWLA 06-MAY-04 3578894 : If this book is a tax book, also create a row in okl_txd_assets_b
2886 IF p_book_rec.book_class = 'TAX' THEN
2887 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
2888 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
2889 lp_adpv_rec.asset_number := p_book_rec.asset_number;
2890 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
2891 p_api_version => p_api_version,
2892 p_init_msg_list => OKL_API.G_FALSE,
2893 x_return_status => x_return_status,
2894 x_msg_count => x_msg_count,
2895 x_msg_data => x_msg_data,
2896 p_adpv_rec => lp_adpv_rec,
2897 x_adpv_rec => lx_adpv_rec );
2898 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2899 RAISE process_unexp_error;
2900 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2901 RAISE process_error;
2902 END IF;
2903
2904 END IF;
2905
2906 -----------------------------------------------------
2907
2908 -- Validations for 4th trx (if any) shold go here
2909
2910
2911 -- SECHAWLA 06-MAY-04 3578894 : Create 4th trx (split from 3rd)
2912
2913 -- Initialize the trx hdr and line for each trx
2914 lp_thpv_rec := lp_empty_thpv_rec;
2915 lp_tlpv_rec := lp_empty_tlpv_rec;
2916 lp_adpv_rec := lp_empty_adpv_rec;
2917
2918 -- Create 4th Transaction Header
2919
2920 --SECHAWLA 06-MAY-04 3578894 : Use a diff tas_type for dep flag only updates
2921 --lp_thpv_rec.tas_type := 'AMT';
2922 lp_thpv_rec.tas_type := 'AUD'; -- new tas_type
2923
2924 lp_thpv_rec.tsu_code := 'ENTERED';
2925
2926 lp_thpv_rec.try_id := p_try_id;
2927 lp_thpv_rec.date_trans_occurred := p_sysdate + l_hold_period_days;
2928 -- RRAVIKIR Legal Entity Changes
2929 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
2930 -- Legal Entity Changes End
2931
2932 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
2933 p_init_msg_list => OKL_API.G_FALSE,
2934 x_return_status => x_return_status,
2935 x_msg_count => x_msg_count,
2936 x_msg_data => x_msg_data,
2937 p_thpv_rec => lp_thpv_rec,
2938 x_thpv_rec => lx_thpv_rec);
2939
2940 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2941 RAISE process_unexp_error;
2942 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
2943 RAISE process_error;
2944 END IF;
2945
2946 -- create 4th transaction line
2947 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
2948 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
2949 lp_tlpv_rec.kle_id := p_kle_id;
2950 lp_tlpv_rec.line_number := 1;
2951
2952 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
2953 --lp_tlpv_rec.tal_type := 'AML';
2954 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
2955
2956 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
2957 lp_tlpv_rec.description := p_book_rec.item_description;
2958
2959
2960 lp_tlpv_rec.corporate_book := p_corporate_book;
2961 /* -- SGORANTL 22-MAR-06 5097643
2962
2963 IF p_df_original_cost IS NOT NULL THEN
2964 lp_tlpv_rec.original_cost := p_df_original_cost;
2965 ELSE
2966 lp_tlpv_rec.original_cost := p_oec;
2967 END IF;
2968 */
2969 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
2970 lp_tlpv_rec.current_units := p_book_rec.current_units;
2971 lp_tlpv_rec.hold_period_days := l_hold_period_days;
2972
2973 -- SECHAWLA 06-MAY-04 3578894 : Start the depreciation. Dep method, life, cost and sv are null
2974 -- when 4th trx is processed, only the dep flag will get updated
2975 lp_tlpv_rec.depreciate_yn := 'Y';
2976
2977 -- SECHAWLA 06-MAY-04 3578894 : populate dep method, life and sv for display on off lse trx upd screen
2978 IF l_setup_method_id IS NOT NULL THEN
2979 lp_tlpv_rec.deprn_method := l_fa_method_code;
2980 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
2981 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
2982 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
2983 ELSE
2984 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
2985 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
2986 END IF;
2987 ELSE
2988 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
2989
2990 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
2991 IF p_book_rec.life_in_months IS NOT NULL THEN
2992 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
2993 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
2994 ELSE
2995 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
2996 END IF;
2997 END IF;
2998 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
2999
3000 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
3001 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
3002 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
3003
3004 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
3005 lp_tlpv_rec.currency_code := p_func_curr_code;
3006
3007 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
3008 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
3009
3010 OKL_TXL_ASSETS_PUB.create_txl_asset_def(p_api_version => p_api_version,
3011 p_init_msg_list => OKL_API.G_FALSE,
3012 x_return_status => x_return_status,
3013 x_msg_count => x_msg_count,
3014 x_msg_data => x_msg_data,
3015 p_tlpv_rec => lp_tlpv_rec,
3016 x_tlpv_rec => lx_tlpv_rec);
3017
3018 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3019 RAISE process_unexp_error;
3020 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3021 RAISE process_error;
3022 END IF;
3023
3024 -- SECHAWLA 06-MAY-04 3578894 : If this book is a tax book, also create a row in okl_txd_assets_b
3025 IF p_book_rec.book_class = 'TAX' THEN
3026 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
3027 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
3028 lp_adpv_rec.asset_number := p_book_rec.asset_number;
3029 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
3030 p_api_version => p_api_version,
3031 p_init_msg_list => OKL_API.G_FALSE,
3032 x_return_status => x_return_status,
3033 x_msg_count => x_msg_count,
3034 x_msg_data => x_msg_data,
3035 p_adpv_rec => lp_adpv_rec,
3036 x_adpv_rec => lx_adpv_rec );
3037 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3038 RAISE process_unexp_error;
3039 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3040 RAISE process_error;
3041 END IF;
3042
3043 END IF;
3044
3045 ELSE -- Hold period is null or 0
3046
3047 -- Split this trx into 2 trasnactions : first update dep method, life, cost, sv and then start depreciation
3048
3049
3050 -- Create 1st Transaction Header
3051
3052 lp_thpv_rec.tas_type := 'AMT';
3053 lp_thpv_rec.tsu_code := 'ENTERED';
3054
3055 lp_thpv_rec.try_id := p_try_id;
3056 lp_thpv_rec.date_trans_occurred := p_sysdate;
3057 -- RRAVIKIR Legal Entity Changes
3058 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
3059 -- Legal Entity Changes End
3060
3061 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
3062 p_init_msg_list => OKL_API.G_FALSE,
3063 x_return_status => x_return_status,
3064 x_msg_count => x_msg_count,
3065 x_msg_data => x_msg_data,
3066 p_thpv_rec => lp_thpv_rec,
3067 x_thpv_rec => lx_thpv_rec);
3068
3069 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3070 RAISE process_unexp_error;
3071 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3072 RAISE process_error;
3073 END IF;
3074
3075 -- create transaction line
3076 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
3077 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
3078 lp_tlpv_rec.kle_id := p_kle_id;
3079 lp_tlpv_rec.line_number := 1;
3080 lp_tlpv_rec.tal_type := 'AML';
3081 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
3082 lp_tlpv_rec.description := p_book_rec.item_description;
3083
3084 -- SECHAWLA 19-FEB-04 3439647
3085 --lp_tlpv_rec.life_in_months := l_life_in_months;
3086
3087 -- If there is a method_id in okl_amort_hold_setups then use it. Otherwise get method id
3088 -- from fa_methods
3089
3090 IF l_setup_method_id IS NOT NULL THEN
3091 lp_tlpv_rec.deprn_method := l_fa_method_code;
3092
3093 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
3094 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
3095 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
3096 ELSE
3097 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
3098 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
3099 END IF;
3100
3101 ELSE
3102 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
3103
3104 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
3105 IF p_book_rec.life_in_months IS NOT NULL THEN
3106 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
3107 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
3108 ELSE
3109 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
3110 END IF;
3111 END IF;
3112
3113 lp_tlpv_rec.corporate_book := p_corporate_book;
3114 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
3115
3116 --In case of direct finance/sales type of lease,Asset will exist in the corporate book, but with the Cost
3117 --and Original cost set to zero. Get Original cost from original creation line in Txl_assets, if it is
3118 --not found, then use OEC from OKL_K_LINES.OEC of the top financial asset line.
3119
3120 -- SECHAWLA 19-FEB-04 3439647 : Always update cost with net investment. At the end of the term, net investment = rv
3121 --IF p_early_termination_yn = 'N' THEN
3122 -- lp_tlpv_rec.depreciation_cost := l_residual_value;
3123 -- ELSE
3124
3125 -- SECHAWLA 19-FEB-04 3439647 : Moved this piece of code to the beginning
3126 -- /*
3127 -- okl_am_util_pvt.get_formula_value(
3128 -- p_formula_name => G_NET_INVESTMENT_FORMULA,
3129 -- p_chr_id => l_dnz_chr_id,
3130 -- p_cle_id => p_kle_id,
3131 -- x_formula_value => l_net_investment_value,
3132 -- x_return_status => x_return_status);
3133
3134 -- IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3135 -- RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3136 -- ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3137 -- RAISE OKL_API.G_EXCEPTION_ERROR;
3138 -- END IF;
3139 -- */
3140 /* -- SGORANTL 22-MAR-06 5097643
3141
3142 lp_tlpv_rec.depreciation_cost := p_net_investment_value;
3143
3144 -- END IF;
3145
3146 IF p_df_original_cost IS NOT NULL THEN
3147 lp_tlpv_rec.original_cost := p_df_original_cost;
3148 ELSE
3149 lp_tlpv_rec.original_cost := p_oec;
3150 END IF;
3151 */
3152
3153 lp_tlpv_rec.depreciation_cost := l_nest_invest_val_in_func; -- SGORANTL 22-MAR-06 5097643
3154 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
3155 lp_tlpv_rec.current_units := p_book_rec.current_units;
3156
3157 -- SECHAWLA 06-MAY-04 3578894 : Depreciate_yn flag is set here and also in the 2nd trx,so the process
3158 -- asset trx program can identify that these are split transactions. When this trx is processed, the flag
3159 -- is not updated in FA. Only dep method, life, cost and sv will be updated
3160 lp_tlpv_rec.depreciate_yn := 'Y';
3161
3162 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
3163 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
3164 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
3165
3166 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
3167 lp_tlpv_rec.currency_code := p_func_curr_code;
3168
3169 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
3170 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
3171
3172 OKL_TXL_ASSETS_PUB.create_txl_asset_def( p_api_version => p_api_version,
3173 p_init_msg_list => OKL_API.G_FALSE,
3174 x_return_status => x_return_status,
3175 x_msg_count => x_msg_count,
3176 x_msg_data => x_msg_data,
3177 p_tlpv_rec => lp_tlpv_rec,
3178 x_tlpv_rec => lx_tlpv_rec);
3179
3180 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3181 RAISE process_unexp_error;
3182 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3183 RAISE process_error;
3184 END IF;
3185
3186 -- SECHAWLA 06-MAY-04 3578894 : If this book is a tax book, also create a row in okl_txd_assets_b
3187 IF p_book_rec.book_class = 'TAX' THEN
3188 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
3189 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
3190 lp_adpv_rec.asset_number := p_book_rec.asset_number;
3191 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
3192 p_api_version => p_api_version,
3193 p_init_msg_list => OKL_API.G_FALSE,
3194 x_return_status => x_return_status,
3195 x_msg_count => x_msg_count,
3196 x_msg_data => x_msg_data,
3197 p_adpv_rec => lp_adpv_rec,
3198 x_adpv_rec => lx_adpv_rec );
3199 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3200 RAISE process_unexp_error;
3201 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3202 RAISE process_error;
3203 END IF;
3204
3205 END IF;
3206
3207 -------------------------------------------------
3208
3209 -- Validations for 2nd trx (if any) should go here
3210
3211
3212 --SECHAWLA 06-MAY-04 3578894 : Create 2nd trx to start the depreciation
3213
3214 -- Initialize the trx hdr and line for each trx
3215 lp_thpv_rec := lp_empty_thpv_rec;
3216 lp_tlpv_rec := lp_empty_tlpv_rec;
3217 lp_adpv_rec := lp_empty_adpv_rec;
3218
3219 -- Create 2nd Transaction Header
3220
3221 -- SECHAWLA 06-MAY-04 3578894 : use a diff tas_type from dep flag only updates
3222 --lp_thpv_rec.tas_type := 'AMT';
3223 lp_thpv_rec.tas_type := 'AUD'; -- new tas_type
3224 lp_thpv_rec.tsu_code := 'ENTERED';
3225
3226 lp_thpv_rec.try_id := p_try_id;
3227 lp_thpv_rec.date_trans_occurred := p_sysdate;
3228 -- RRAVIKIR Legal Entity Changes
3229 lp_thpv_rec.legal_entity_id := p_legal_entity_id;
3230 -- Legal Entity Changes End
3231
3232 OKL_TRX_ASSETS_PUB.create_trx_ass_h_def( p_api_version => p_api_version,
3233 p_init_msg_list => OKL_API.G_FALSE,
3234 x_return_status => x_return_status,
3235 x_msg_count => x_msg_count,
3236 x_msg_data => x_msg_data,
3237 p_thpv_rec => lp_thpv_rec,
3238 x_thpv_rec => lx_thpv_rec);
3239
3240 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3241 RAISE process_unexp_error;
3242 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3243 RAISE process_error;
3244 END IF;
3245
3246 -- create 2nd transaction line
3247 lp_tlpv_rec.tas_id := lx_thpv_rec.id; -- FK
3248 lp_tlpv_rec.iay_id := p_book_rec.depreciation_category;
3249 lp_tlpv_rec.kle_id := p_kle_id;
3250 lp_tlpv_rec.line_number := 1;
3251
3252 --SECHAWLA 06-MAY-04 3578894 : use a diff tal_type for dep flag only updates
3253 --lp_tlpv_rec.tal_type := 'AML';
3254 lp_tlpv_rec.tal_type := 'AUF'; -- new tal_type
3255
3256 lp_tlpv_rec.asset_number := p_book_rec.asset_number;
3257 lp_tlpv_rec.description := p_book_rec.item_description;
3258
3259 lp_tlpv_rec.corporate_book := p_corporate_book;
3260
3261 /* -- SGORANTL 22-MAR-06 5097643
3262
3263 IF p_df_original_cost IS NOT NULL THEN
3264 lp_tlpv_rec.original_cost := p_df_original_cost;
3265 ELSE
3266 lp_tlpv_rec.original_cost := p_oec;
3267 END IF;
3268 */
3269 lp_tlpv_rec.original_cost := l_orig_cost_in_func; -- SGORANTL 22-MAR-06 5097643
3270 lp_tlpv_rec.current_units := p_book_rec.current_units;
3271
3272 -- SECHAWLA 06-MAY-04 3578894 : start the depreciation. dep method, life, cost and sv are null. When
3273 -- this trx is processed in FA, only dep flag will be updated.
3274 lp_tlpv_rec.depreciate_yn := 'Y';
3275
3276 -- SECHAWLA 06-MAY-04 3578894 : populate dep method, life and sv for display on off lse trx upd screen
3277 IF l_setup_method_id IS NOT NULL THEN
3278 lp_tlpv_rec.deprn_method := l_fa_method_code;
3279
3280 -- SECHAWLA 28-MAY-04 3645574 : check if l_setup_deprn_rate has a value. Is so, store rate otherwise store life
3281 IF l_setup_deprn_rate IS NOT NULL THEN -- setup has diminishing dep method
3282 lp_tlpv_rec.deprn_rate := l_setup_deprn_rate;
3283 ELSE
3284 -- SECHAWLA 19-FEB-04 3439647 : use life in months from the hold period setup
3285 lp_tlpv_rec.life_in_months := l_fa_life_in_months;
3286 END IF;
3287 ELSE
3288 lp_tlpv_rec.deprn_method := p_book_rec.deprn_method_code;
3289
3290 -- SECHAWLA 28-MAY-04 3645574: store either life or rate
3291 IF p_book_rec.life_in_months IS NOT NULL THEN
3292 -- SECHAWLA 19-FEB-04 3439647 : use original life in months
3293 lp_tlpv_rec.life_in_months := p_book_rec.life_in_months;
3294 ELSE
3295 lp_tlpv_rec.deprn_rate := p_book_rec.deprn_rate;
3296 END IF;
3297 END IF;
3298 lp_tlpv_rec.salvage_value := p_book_rec.salvage_value;
3299
3300
3301 lp_tlpv_rec.dnz_asset_id := to_number(p_book_rec.asset_id);
3302 lp_tlpv_rec.dnz_khr_id := p_book_rec.dnz_chr_id;
3303 lp_tlpv_rec.in_service_date := p_book_rec.in_service_date;
3304 --SECHAWLA 03-JAN-03 2683876 Pass the currency code if creating/updating amounts in txl assets
3305 lp_tlpv_rec.currency_code := p_func_curr_code;
3306
3307 -- SECHAWLA 15-DEC-04 4028371 : set FA date on trx header
3308 lp_tlpv_rec.FA_TRX_DATE := l_fa_trx_date;
3309
3310 OKL_TXL_ASSETS_PUB.create_txl_asset_def( p_api_version => p_api_version,
3311 p_init_msg_list => OKL_API.G_FALSE,
3312 x_return_status => x_return_status,
3313 x_msg_count => x_msg_count,
3314 x_msg_data => x_msg_data,
3315 p_tlpv_rec => lp_tlpv_rec,
3316 x_tlpv_rec => lx_tlpv_rec);
3317 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3318 RAISE process_unexp_error;
3319 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3320 RAISE process_error;
3321 END IF;
3322
3323 -- SECHAWLA 06-MAY-04 3578894 : If this book is a tax book, also create a row in okl_txd_assets_b
3324 IF p_book_rec.book_class = 'TAX' THEN
3325 lp_adpv_rec.tal_id := lx_tlpv_rec.id;
3326 lp_adpv_rec.tax_book := p_book_rec.book_type_code;
3327 lp_adpv_rec.asset_number := p_book_rec.asset_number;
3328 OKL_TXD_ASSETS_PUB.create_txd_asset_def(
3329 p_api_version => p_api_version,
3330 p_init_msg_list => OKL_API.G_FALSE,
3331 x_return_status => x_return_status,
3332 x_msg_count => x_msg_count,
3333 x_msg_data => x_msg_data,
3334 p_adpv_rec => lp_adpv_rec,
3335 x_adpv_rec => lx_adpv_rec );
3336 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3337 RAISE process_unexp_error;
3338 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3339 RAISE process_unexp_error;
3340 END IF;
3341
3342 END IF;
3343 END IF; -- hold period days is null
3344
3345 EXCEPTION
3346 WHEN process_error THEN
3347
3348 IF l_methodcode_csr%ISOPEN THEN
3349 CLOSE l_methodcode_csr;
3350 END IF;
3351
3352 IF l_amthld_csr%ISOPEN THEN
3353 CLOSE l_amthld_csr;
3354 END IF;
3355
3356 x_return_status := OKL_API.G_RET_STS_ERROR;
3357 WHEN process_unexp_error THEN
3358 IF l_methodcode_csr%ISOPEN THEN
3359 CLOSE l_methodcode_csr;
3360 END IF;
3361
3362 IF l_amthld_csr%ISOPEN THEN
3363 CLOSE l_amthld_csr;
3364 END IF;
3365
3366 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
3367 WHEN OTHERS THEN
3368 IF l_methodcode_csr%ISOPEN THEN
3369 CLOSE l_methodcode_csr;
3370 END IF;
3371
3372 IF l_amthld_csr%ISOPEN THEN
3373 CLOSE l_amthld_csr;
3374 END IF;
3375
3376 -- unexpected error
3377 OKL_API.set_message(p_app_name => 'OKC',
3378 p_msg_name => g_unexpected_error,
3379 p_token1 => g_sqlcode_token,
3380 p_token1_value => sqlcode,
3381 p_token2 => g_sqlerrm_token,
3382 p_token2_value => sqlerrm);
3383 x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
3384 END process_dfstlease_lessee;
3385
3386 ----------SECHAWLA 06-MAY-04 3578894 end new procedures --------------------
3387
3388
3389 -- Start of comments
3390 --
3391 -- Procedure Name : create_offlease_asset_trx
3392 -- Description : This procedure populates the transaction
3393 -- header- okl_trx_assets_v and transaction lines- okl_txl_assets_v with amortization transactions
3394 -- for off-lease assets for a particular financial asset
3395 -- Business Rules :
3396 -- Parameters : p_kle_id - Finacial Asset id
3397 -- p_early_termination_yn - early termination / end of term flag
3398 -- Version : 1.0
3399 -- History : SECHAWLA 03-JAN-03 2683876 Added logic to populate currency_code in txl assets
3400 -- SECHAWLA 05-JUN-03 2993071 Check for both Direct Finance and Sales type of lease while
3401 -- deriving the original cost / oec / residual value
3402 -- SECHAWLA 11-Oct-2003 3167323 Create amortization transaction for operating lease, w/o hold period
3403 -- SECHAWLA 03-MAY-04 3521126
3404 -- Always update asset cost with NIV for DF/Sales lease, in corp book
3405 -- Update asset cost with NIV for DF/Sales lease, in tax books, when tax owner = LESSEE
3406 --
3407 -- For DF/Sales lease, if hold period exists, then first update the cost with NIV and stop the
3408 -- depreciation. and then start the depreciation with the new dep method (if defined in setup)
3409 -- after the hold period expires
3410 --
3411 -- If hold period setup has a depreciation method defined, then also use the corresponding
3412 -- life in months from the setup
3413 -- SECJAWLA 07-MAY-04 3578894
3414 -- Split the off lease transactions so that the dep flag
3415 -- is updated independent of other updates(dep method,
3416 -- life, cost, sv)
3417 -- Create separate transactions for corporate, tax and
3418 -- Milti GAAP reporting book
3419 -- rmunjulu EDAT Added two additional parameters for effective dated processing
3420 -- Also made following changes
3421 -- 1. Set 'OFF_LSE_TRX_DATE' and pass as additional param to calculate net investment
3422 -- 2. Get the corporate books that the asset belongs to using quote eff date
3423 -- 3. Get the tax books that the asset belongs to using quote eff date
3424 -- 4. To process_oplease pass quote eff date
3425 -- 5. Get the reporting books that the asset belongs to using quote eff date
3426 -- 6. To process_dfstlease_lessee pass quote eff date
3427 -- 7. To process_dfstlease_lessor pass quote eff date
3428 -- rmunjulu EDAT 29-Dec-04 did to_char to convert to right format
3429 -- PAGARG 10-Feb-2005 3730369: Pass correct variable as out parameter
3430 -- for return status in call to get_reporting_product get_rule_record
3431 -- sechawla 20-Nov-07 Split Asset Enhancements - create off lease transactions
3432 -- when reporting product is DF/ST lease
3433 -- End of comments
3434
3435 PROCEDURE create_offlease_asset_trx(
3436 p_api_version IN NUMBER,
3437 p_init_msg_list IN VARCHAR2 ,
3438 x_return_status OUT NOCOPY VARCHAR2,
3439 x_msg_count OUT NOCOPY NUMBER,
3440 x_msg_data OUT NOCOPY VARCHAR2,
3441 p_kle_id IN NUMBER ,
3442 p_early_termination_yn IN VARCHAR2,
3443 p_quote_eff_date IN DATE DEFAULT NULL, -- rmunjulu EDAT Added parameter
3444 p_quote_accpt_date IN DATE DEFAULT NULL) -- rmunjulu EDAT Added parameter
3445 IS
3446
3447
3448
3449 l_df_original_cost NUMBER;
3450 l_oec NUMBER;
3451 l_residual_value NUMBER;
3452
3453 l_cost NUMBER;
3454 l_accumulated_deprn NUMBER;
3455 l_try_id okl_trx_types_v.id%TYPE;
3456
3457 l_return_status VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
3458 l_api_name CONSTANT VARCHAR2(30) := 'create_offlease_asset_trx';
3459 l_tax_owner VARCHAR2(10);
3460 l_rulv_rec okl_rule_pub.rulv_rec_type;
3461
3462 l_api_version CONSTANT NUMBER := 1;
3463 l_sysdate DATE;
3464
3465
3466
3467
3468 l_corporate_book okx_asset_lines_v.corporate_book%TYPE;
3469
3470 l_deal_type OKL_K_HEADERS_FULL_V.deal_type%TYPE;
3471
3472 --SECHAWLA 03-JAN-03 Bug # 2683876 : new declaration
3473 l_func_curr_code GL_LEDGERS_PUBLIC_V.CURRENCY_CODE%TYPE;
3474
3475
3476 --SECHAWLA 06-MAY-04 3578894
3477 l_base_NIV NUMBER;
3478 l_reporting_NIV NUMBER;
3479 l_name VARCHAR2(150);
3480 l_contract_id NUMBER;
3481 l_contract_number VARCHAR2(120);
3482
3483 lx_rep_product OKL_PRODUCTS_V.NAME%TYPE;
3484 lx_mg_rep_book fa_book_controls.book_type_code%TYPE;
3485 lx_rep_deal_type okl_product_parameters_v.deal_type%TYPE;
3486
3487 l_rep_book_found VARCHAR2(1) := 'N';
3488
3489 l_legal_entity_id NUMBER;
3490
3491 -- SECHAWLA 06-MAY-04 3578894 : added cp_sysdate parameter
3492 -- get all the tax books and validate that mg rep book (set in profile) is one of the asset tax books
3493 CURSOR l_fataxbooks_csr(cp_asset_number IN VARCHAR2, cp_sysdate IN DATE) IS
3494 SELECT fb.book_type_code
3495 FROM fa_books fb, fa_additions_b fab, fa_book_controls fbc
3496 WHERE fb.asset_id = fab.asset_id
3497 AND fb.book_type_code = fbc.book_type_code
3498 AND nvl(fbc.date_ineffective,cp_sysdate+1) > cp_sysdate
3499 AND fb.transaction_header_id_out IS NULL
3500 AND fab.asset_number = cp_asset_number
3501 AND fbc.book_class = 'TAX';
3502
3503 -- SECHAWLA 06-MAY-04 3578894 : added cp_sysdate parameter
3504 --Get the asset corporate book
3505 CURSOR l_facorpbook_csr(cp_asset_number IN VARCHAR2, cp_sysdate IN DATE) IS
3506 SELECT fb.book_type_code
3507 FROM fa_books fb, fa_additions_b fab, fa_book_controls fbc
3508 WHERE fb.asset_id = fab.asset_id
3509 AND fb.book_type_code = fbc.book_type_code
3510 AND nvl(fbc.date_ineffective,cp_sysdate+1) > cp_sysdate
3511 AND fb.transaction_header_id_out IS NULL
3512 AND fab.asset_number = cp_asset_number
3513 AND fbc.book_class = 'CORPORATE';
3514
3515
3516 /* SECHAWLA 06-MAY-04 3578894 : This cursor cann't be used as it does not return tax book info
3517 -- This cursor will return all the Fixed Asset Lines for a particular contract.
3518 CURSOR l_linesv_csr IS
3519 SELECT dnz_chr_id, depreciation_category, corporate_book, salvage_value, deprn_method_code, life_in_months,
3520 asset_number, item_description, asset_id,original_cost, current_units, in_service_date, deal_type
3521 FROM okx_asset_lines_v lines, OKL_K_HEADERS_FULL_V hdr
3522 WHERE lines.dnz_chr_id = hdr.id
3523 AND lines.parent_line_id = p_kle_id;
3524 */
3525
3526 -- SECHAWLA 06-MAY-04 3578894 : added cp_sysdate parameter
3527 -- SECHAWLA 06-MAY-04 3578894 : Use the following cursor to get corp book info
3528 -- This cursor will return 1 record for corp book
3529 CURSOR l_assetcorpbook_csr(cp_kle_id IN NUMBER, cp_sysdate IN DATE) IS
3530 SELECT cleb_fin.id parent_line_id,
3531 cleb_fin.dnz_chr_id,
3532 fab.asset_category_id depreciation_category,
3533 fb.book_type_code,
3534 fbc.book_class,
3535 fb.salvage_value,
3536 fb.DEPRN_METHOD_CODE,
3537 fb.LIFE_IN_MONTHS,
3538 -- SECHAWLA 28-MAY-04 : 3645574 :added adjusted_rate
3539 fb.adjusted_rate deprn_rate,
3540 fab.asset_number asset_number,
3541 clet_fin.item_description,
3542 fb.asset_id,
3543 fb.original_cost,
3544 fab.current_units,
3545 fb.DATE_PLACED_IN_SERVICE in_service_date
3546 FROM fa_books fb,
3547 fa_additions_b fab,
3548 fa_book_controls fbc,
3549 okc_k_items cim_fa,
3550 okc_k_lines_b cleb_fa,
3551 okc_line_styles_b lseb_fa,
3552 okc_k_lines_tl clet_fin,
3553 okc_k_lines_b cleb_fin,
3554 okc_line_styles_b lseb_fin
3555 WHERE fb.asset_id = fab.asset_id
3556 AND fb.transaction_header_id_out IS NULL
3557 AND fb.book_type_code = fbc.book_type_code
3558 AND nvl(fbc.date_ineffective,cp_sysdate+1) > cp_sysdate
3559 AND fab.asset_id = to_number(cim_fa.object1_id1)
3560 AND cim_fa.object1_id2 = '#'
3561 AND cim_fa.cle_id = cleb_fa.id
3562 AND cim_fa.dnz_chr_id = cleb_fa.dnz_chr_id
3563 AND cleb_fa.cle_id = cleb_fin.id
3564 AND cleb_fa.dnz_chr_id = cleb_fin.dnz_chr_id
3565 AND cleb_fa.lse_id = lseb_fa.id
3566 AND lseb_fa.lty_code = 'FIXED_ASSET'
3567 AND clet_fin.id = cleb_fin.id
3568 AND clet_fin.language = userenv('LANG')
3569 AND cleb_fin.lse_id = lseb_fin.id
3570 AND lseb_fin.lty_code = 'FREE_FORM1'
3571 AND cleb_fin.sts_code <> 'ABANDONED'
3572 AND cleb_fin.id = cp_kle_id
3573 AND fbc.book_class = 'CORPORATE';
3574
3575 -- SECHAWLA 06-MAY-04 3578894 : added cp_sysdate parameter
3576 -- Cursor to get both corp and tax books
3577 -- This cursor will return 1 record for corp book and may return one or more records for tax books
3578 CURSOR l_corptaxbooks_csr(cp_kle_id IN NUMBER, cp_sysdate IN DATE) IS
3579 SELECT cleb_fin.id parent_line_id,
3580 cleb_fin.dnz_chr_id,
3581 fab.asset_category_id depreciation_category,
3582 fb.book_type_code,
3583 fbc.book_class,
3584 fb.salvage_value,
3585 fb.DEPRN_METHOD_CODE,
3586 fb.LIFE_IN_MONTHS,
3587 -- SECHAWLA 28-MAY-04 : 3645574 :added adjusted_rate
3588 fb.adjusted_rate deprn_rate,
3589 fab.asset_number asset_number,
3590 clet_fin.item_description,
3591 fb.asset_id,
3592 fb.original_cost,
3593 fab.current_units,
3594 fb.DATE_PLACED_IN_SERVICE in_service_date
3595 FROM fa_books fb,
3596 fa_additions_b fab,
3597 fa_book_controls fbc,
3598 okc_k_items cim_fa,
3599 okc_k_lines_b cleb_fa,
3600 okc_line_styles_b lseb_fa,
3601 okc_k_lines_tl clet_fin,
3602 okc_k_lines_b cleb_fin,
3603 okc_line_styles_b lseb_fin
3604 WHERE fb.asset_id = fab.asset_id
3605 AND fb.transaction_header_id_out is null
3606 AND fb.book_type_code = fbc.book_type_code
3607 AND nvl(fbc.date_ineffective,cp_sysdate+1) > cp_sysdate
3608 AND fab.asset_id = to_number(cim_fa.object1_id1)
3609 AND cim_fa.object1_id2 = '#'
3610 AND cim_fa.cle_id = cleb_fa.id
3611 AND cim_fa.dnz_chr_id = cleb_fa.dnz_chr_id
3612 AND cleb_fa.cle_id = cleb_fin.id
3613 AND cleb_fa.dnz_chr_id = cleb_fin.dnz_chr_id
3614 AND cleb_fa.lse_id = lseb_fa.id
3615 AND lseb_fa.lty_code = 'FIXED_ASSET'
3616 AND clet_fin.id = cleb_fin.id
3617 AND clet_fin.language = userenv('LANG')
3618 AND cleb_fin.lse_id = lseb_fin.id
3619 AND lseb_fin.lty_code = 'FREE_FORM1'
3620 AND cleb_fin.sts_code <> 'ABANDONED'
3621 AND cleb_fin.id = cp_kle_id
3622 AND fbc.book_class IN ('CORPORATE','TAX')
3623 ORDER BY fbc.book_class;
3624
3625 -- SECHAWLA 06-MAY-04 3578894 : added cp_sysdate parameter
3626 -- Cursir to get both corp and tax books (excluding mg rep book)
3627 -- This cursor will return 1 record for corp book and may return one or more records for tax books
3628 CURSOR l_corptax_norep_books_csr(cp_kle_id IN NUMBER, cp_rep_book IN VARCHAR2, cp_sysdate IN DATE) IS
3629 SELECT cleb_fin.id parent_line_id,
3630 cleb_fin.dnz_chr_id,
3631 fab.asset_category_id depreciation_category,
3632 fb.book_type_code,
3633 fbc.book_class,
3634 fb.salvage_value,
3635 fb.DEPRN_METHOD_CODE,
3636 fb.LIFE_IN_MONTHS,
3637 -- SECHAWLA 28-MAY-04 : 3645574 :added adjusted_rate
3638 fb.adjusted_rate deprn_rate,
3639 fab.asset_number asset_number,
3640 clet_fin.item_description,
3641 fb.asset_id,
3642 fb.original_cost,
3643 fab.current_units,
3644 fb.DATE_PLACED_IN_SERVICE in_service_date
3645 FROM fa_books fb,
3646 fa_additions_b fab,
3647 fa_book_controls fbc,
3648 okc_k_items cim_fa,
3649 okc_k_lines_b cleb_fa,
3650 okc_line_styles_b lseb_fa,
3651 okc_k_lines_tl clet_fin,
3652 okc_k_lines_b cleb_fin,
3653 okc_line_styles_b lseb_fin
3654 WHERE fb.asset_id = fab.asset_id
3655 AND fb.transaction_header_id_out is null
3656 AND fb.book_type_code = fbc.book_type_code
3657 AND nvl(fbc.date_ineffective,cp_sysdate+1) > cp_sysdate
3658 AND fab.asset_id = to_number(cim_fa.object1_id1)
3659 AND cim_fa.object1_id2 = '#'
3660 AND cim_fa.cle_id = cleb_fa.id
3661 AND cim_fa.dnz_chr_id = cleb_fa.dnz_chr_id
3662 AND cleb_fa.cle_id = cleb_fin.id
3663 AND cleb_fa.dnz_chr_id = cleb_fin.dnz_chr_id
3664 AND cleb_fa.lse_id = lseb_fa.id
3665 AND lseb_fa.lty_code = 'FIXED_ASSET'
3666 AND clet_fin.id = cleb_fin.id
3667 AND clet_fin.language = userenv('LANG')
3668 AND cleb_fin.lse_id = lseb_fin.id
3669 AND lseb_fin.lty_code = 'FREE_FORM1'
3670 AND cleb_fin.sts_code <> 'ABANDONED'
3671 AND cleb_fin.id = cp_kle_id
3672 AND fbc.book_class IN ('CORPORATE','TAX')
3673 AND fb.book_type_code <> cp_rep_book
3674 ORDER BY fbc.book_class;
3675
3676 -- SECHAWLA 06-MAY-04 3578894 : added cp_sysdate parameter
3677 -- This cursor will return 1 record for mg reporting book
3678 CURSOR l_assetrepbook_csr(cp_kle_id IN NUMBER, cp_rep_book IN VARCHAR2, cp_sysdate IN DATE) IS
3679 SELECT cleb_fin.id parent_line_id,
3680 cleb_fin.dnz_chr_id,
3681 fab.asset_category_id depreciation_category,
3682 fb.book_type_code,
3683 fbc.book_class,
3684 fb.salvage_value,
3685 fb.DEPRN_METHOD_CODE,
3686 fb.LIFE_IN_MONTHS,
3687 -- SECHAWLA 28-MAY-04 : 3645574 :added adjusted_rate
3688 fb.adjusted_rate deprn_rate,
3689 fab.asset_number asset_number,
3690 clet_fin.item_description,
3691 fb.asset_id,
3692 fb.original_cost,
3693 fab.current_units,
3694 fb.DATE_PLACED_IN_SERVICE in_service_date
3695 FROM fa_books fb,
3696 fa_additions_b fab,
3697 fa_book_controls fbc,
3698 okc_k_items cim_fa,
3699 okc_k_lines_b cleb_fa,
3700 okc_line_styles_b lseb_fa,
3701 okc_k_lines_tl clet_fin,
3702 okc_k_lines_b cleb_fin,
3703 okc_line_styles_b lseb_fin
3704 WHERE fb.asset_id = fab.asset_id
3705 AND fb.transaction_header_id_out is null
3706 AND fb.book_type_code = fbc.book_type_code
3707 AND nvl(fbc.date_ineffective,cp_sysdate+1) > cp_sysdate
3708 AND fab.asset_id = to_number(cim_fa.object1_id1)
3709 AND cim_fa.object1_id2 = '#'
3710 AND cim_fa.cle_id = cleb_fa.id
3711 AND cim_fa.dnz_chr_id = cleb_fa.dnz_chr_id
3712 AND cleb_fa.cle_id = cleb_fin.id
3713 AND cleb_fa.dnz_chr_id = cleb_fin.dnz_chr_id
3714 AND cleb_fa.lse_id = lseb_fa.id
3715 AND lseb_fa.lty_code = 'FIXED_ASSET'
3716 AND clet_fin.id = cleb_fin.id
3717 AND clet_fin.language = userenv('LANG')
3718 AND cleb_fin.lse_id = lseb_fin.id
3719 AND lseb_fin.lty_code = 'FREE_FORM1'
3720 AND cleb_fin.sts_code <> 'ABANDONED'
3721 AND cleb_fin.id = cp_kle_id
3722 AND fbc.book_class = 'TAX'
3723 AND fb.book_type_code = cp_rep_book;
3724
3725
3726 -- SECHAWLA 06-MAY-04 3578894 : Added this cursor
3727 -- get the deal type for the asset
3728 CURSOR l_oklhdr_csr(cp_kle_id IN NUMBER) IS
3729 SELECT a.id, a.deal_type, a.legal_entity_id
3730 FROM okl_k_headers a, okc_k_lines_b b
3731 WHERE a.id = b.dnz_chr_id
3732 AND b.id = cp_kle_id;
3733
3734 -- SECHAWLA 06-MAY-04 3578894 : Added this cursor to validate the kle id
3735 CURSOR l_okllines_csr(cp_kle_id IN NUMBER) IS
3736 SELECT name
3737 FROM okl_k_lines_full_v
3738 WHERE id = cp_kle_id;
3739
3740 -- This cursor is used to get the cost, residual value of an asset from the Financial Asset (TOP LINE)
3741 CURSOR l_linesfullv_csr(p_id NUMBER) IS
3742 SELECT oec, residual_value
3743 FROM okl_k_lines_full_v
3744 WHERE id = p_id;
3745
3746 -- This cursor returns the original cost from the original asset creation line
3747 CURSOR l_txlassetsv_csr(p_asset_number okl_txl_assets_v.asset_number%type) IS
3748 SELECT original_cost
3749 FROM okl_txl_assets_v
3750 WHERE tal_type = 'CFA'
3751 AND asset_number = p_asset_number
3752 AND ROWNUM < 2;
3753
3754 --SECHAWLA 06-MAY-04 3578894 : passing additonal parameter for calling G_NET_INVESTMENT_FORMULA
3755 --if original product is op lease and reporting product is DF/ST lease. In this case net investment
3756 l_add_params okl_execute_formula_pub.ctxt_val_tbl_type;
3757
3758 -- rmunjulu EDAT
3759 l_quote_eff_date DATE;
3760 l_quote_accpt_date DATE;
3761 l_additional_params okl_execute_formula_pub.ctxt_val_tbl_type;
3762
3763 BEGIN
3764
3765 l_return_status := OKL_API.START_ACTIVITY(l_api_name,
3766 G_PKG_NAME,
3767 p_init_msg_list,
3768 l_api_version,
3769 p_api_version,
3770 '_PVT',
3771 x_return_status);
3772 IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3773 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3774 ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
3775 RAISE OKL_API.G_EXCEPTION_ERROR;
3776 END IF;
3777
3778 IF p_kle_id IS NULL OR p_kle_id = OKL_API.G_MISS_NUM THEN
3779 x_return_status := OKL_API.G_RET_STS_ERROR;
3780 -- kle id parameter is null
3781 OKC_API.set_message( p_app_name => 'OKC',
3782 p_msg_name => G_REQUIRED_VALUE,
3783 p_token1 => G_COL_NAME_TOKEN,
3784 p_token1_value => 'KLE_ID');
3785 RAISE OKL_API.G_EXCEPTION_ERROR;
3786 END IF;
3787
3788 -- SECHAWLA 06-MAY-04 3578894 : Validate p_kle_id
3789 OPEN l_okllines_csr(p_kle_id);
3790 FETCH l_okllines_csr INTO l_name;
3791 IF l_okllines_csr%NOTFOUND THEN
3792 x_return_status := OKL_API.G_RET_STS_ERROR;
3793 -- kle id is invalid
3794 OKC_API.set_message( p_app_name => 'OKC',
3795 p_msg_name => G_INVALID_VALUE,
3796 p_token1 => G_COL_NAME_TOKEN,
3797 p_token1_value => 'KLE_ID');
3798 RAISE OKL_API.G_EXCEPTION_ERROR;
3799 END IF;
3800 CLOSE l_okllines_csr;
3801
3802 --SECHAWLA 06-MAY-04 3578894 : These validations are not required as p_early_termination_yn parameter
3803 --will not be used any more in this API. This parameter was used to populate depreciation cost with RV if it
3804 --is EOT and with NIV if early termination. As part of bug fix 3578894, depreciation cost should always be
3805 --NIV . Still keeping the parameter in the API call for possibility of future use
3806 /*
3807 IF p_early_termination_yn IS NULL OR p_early_termination_yn = OKL_API.G_MISS_CHAR THEN
3808 x_return_status := OKL_API.G_RET_STS_ERROR;
3809 -- early_termination_yn parameter is null
3810 OKC_API.set_message( p_app_name => 'OKC',
3811 p_msg_name => G_REQUIRED_VALUE,
3812 p_token1 => G_COL_NAME_TOKEN,
3813 p_token1_value => 'EARLY_TERMINATION_YN');
3814
3815
3816 RAISE OKL_API.G_EXCEPTION_ERROR;
3817 END IF;
3818
3819 IF p_early_termination_yn <> 'Y' AND p_early_termination_yn <> 'N' THEN
3820 x_return_status := OKL_API.G_RET_STS_ERROR;
3821 -- early_termination_yn parameter is invalid
3822 OKC_API.set_message( p_app_name => 'OKC',
3823 p_msg_name => G_INVALID_VALUE,
3824 p_token1 => G_COL_NAME_TOKEN,
3825 p_token1_value => 'EARLY_TERMINATION_YN');
3826
3827
3828 RAISE OKL_API.G_EXCEPTION_ERROR;
3829 END IF;
3830 */
3831
3832 SELECT SYSDATE INTO l_sysdate FROM DUAL;
3833
3834 -- rmunjulu EDAT Added condition to default
3835 IF p_quote_eff_date IS NOT NULL
3836 AND p_quote_eff_date <> OKL_API.G_MISS_DATE THEN
3837
3838 l_quote_eff_date := p_quote_eff_date;
3839
3840 ELSE
3841
3842 l_quote_eff_date := l_sysdate;
3843
3844 END IF;
3845
3846 -- rmunjulu EDAT Added condition to default
3847 IF p_quote_accpt_date IS NOT NULL
3848 AND p_quote_accpt_date <> OKL_API.G_MISS_DATE THEN
3849
3850 l_quote_accpt_date := p_quote_accpt_date;
3851
3852 ELSE
3853
3854 l_quote_accpt_date := l_sysdate;
3855
3856 END IF;
3857
3858 okl_am_util_pvt.get_transaction_id(p_try_name => 'Off Lease Amortization',
3859 x_return_status => x_return_status,
3860 x_try_id => l_try_id);
3861
3862
3863 IF x_return_status <> OKL_API.G_RET_STS_SUCCESS THEN
3864 --Unable to find a transaction type for this transaction .
3865 OKL_API.set_message(p_app_name => 'OKL',
3866 p_msg_name => 'OKL_AM_NO_TRX_TYPE_FOUND',
3867 p_token1 => 'TRY_NAME',
3868 p_token1_value => 'Off Lease Amortization');
3869 RAISE OKC_API.G_EXCEPTION_ERROR;
3870 END IF;
3871
3872 --SECHAWLA 03-JAN-03 2683876 get the functional currency code
3873 l_func_curr_code := okl_am_util_pvt.get_functional_currency;
3874
3875 -- SECHAWLA 06-MAY-04 3578894 : Get the deal type
3876 OPEN l_oklhdr_csr(p_kle_id);
3877 FETCH l_oklhdr_csr INTO l_contract_id, l_deal_type, l_legal_entity_id;
3878 CLOSE l_oklhdr_csr;
3879
3880 -- SECHAWLA 06-MAY-04 3578894 : Off lease trx not craeted for loans
3881 IF l_deal_type IN ('LEASEDF','LEASEOP','LEASEST') THEN
3882
3883
3884 -- get the original cost from the original asset creation line
3885 OPEN l_txlassetsv_csr(l_name);
3886 FETCH l_txlassetsv_csr INTO l_df_original_cost;
3887 CLOSE l_txlassetsv_csr;
3888
3889 -- get the oec and rv
3890 OPEN l_linesfullv_csr(p_kle_id);
3891 FETCH l_linesfullv_csr INTO l_oec, l_residual_value;
3892 CLOSE l_linesfullv_csr;
3893
3894
3895 IF l_df_original_cost IS NULL THEN
3896 IF l_oec IS NULL THEN
3897 x_return_status := OKL_API.G_RET_STS_ERROR;
3898 -- OEC not defined for the asset
3899 OKL_API.set_message( p_app_name => 'OKL',
3900 p_msg_name => 'OKL_AM_NO_OEC',
3901 p_token1 => 'ASSET_NUMBER',
3902 p_token1_value => l_name);
3903
3904 RAISE OKL_API.G_EXCEPTION_ERROR;
3905 END IF;
3906 END IF;
3907
3908
3909
3910 IF l_deal_type IN ('LEASEDF','LEASEST') THEN
3911 -- SECHAWLA 19-FEB-04 3439647 : Moved this piece of code here from the following sections
3912 --SECHAWLA 06-MAY-04 3578894 : By default, NIV is calculated based upon base product's streams.
3913 -- No additional parameters are passed in this case
3914
3915 -- rmunjulu EDAT Pass additional parameters to set quote eff date as transaction date
3916 l_additional_params(1).name := 'quote_effective_from_date'; -- rmunjulu EDAT Pass quote eff from date
3917 l_additional_params(1).value := to_char(l_quote_eff_date,'MM/DD/YYYY'); -- rmunjulu EDAT 29-Dec-04 did to_char to convert to right format
3918
3919 okl_am_util_pvt.get_formula_value(
3920 p_formula_name => G_NET_INVESTMENT_FORMULA,
3921 p_chr_id => l_contract_id,
3922 p_cle_id => p_kle_id,
3923 -- rmunjulu EDAT
3924 p_additional_parameters => l_additional_params,
3925
3926 x_formula_value => l_base_NIV,
3927 x_return_status => x_return_status);
3928
3929 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3930 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3931 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3932 RAISE OKL_API.G_EXCEPTION_ERROR;
3933 END IF;
3934 -- SECHAWLA 19-FEB-04 3439647 : end moved code
3935
3936 END IF;
3937 -- end direct finance data validation
3938
3939 ----------------------
3940 -- get the tax owner (LESSOR/LESSEE) for the contract
3941 -- In case of OP Lease, tax owner is always LESSOR. In case of DF/Sales Lease, it can be LESSOR or LESSEE
3942 -- PAGARG 10-Feb-2005 3730369: Pass correct variable as out parameter for return status
3943 okl_am_util_pvt.get_rule_record(
3944 p_rgd_code => 'LATOWN'
3945 ,p_rdf_code =>'LATOWN'
3946 ,p_chr_id => l_contract_id
3947 ,p_cle_id => NULL
3948 ,x_rulv_rec => l_rulv_rec
3949 ,x_return_status => x_return_status
3950 ,x_msg_count => x_msg_count
3951 ,x_msg_data => x_msg_data);
3952
3953 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3954 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3955 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3956 RAISE OKL_API.G_EXCEPTION_ERROR;
3957 END IF;
3958
3959
3960
3961 IF l_rulv_rec.rule_information1 IS NULL OR l_rulv_rec.rule_information1 = OKL_API.G_MISS_CHAR THEN
3962 x_return_status := OKL_API.G_RET_STS_ERROR;
3963 -- tax owner is not defined for contract CONTRACT_NUMBER.
3964 OKL_API.set_message( p_app_name => 'OKL',
3965 p_msg_name => 'OKL_AM_NO_TAX_OWNER',
3966 p_token1 => 'CONTRACT_NUMBER',
3967 p_token1_value => l_contract_number);
3968
3969 RAISE OKL_API.G_EXCEPTION_ERROR;
3970 END IF;
3971
3972 -- l_rulv_rec.RULE_INFORMATION1 will contain the value 'LESSEE' or 'LESSOR'
3973 l_tax_owner := l_rulv_rec.RULE_INFORMATION1;
3974
3975 -- get the corporate book that the asset belongs to
3976 OPEN l_facorpbook_csr(l_name, l_quote_accpt_date); -- rmunjulu EDAT pass quote accpt date
3977 FETCH l_facorpbook_csr INTO l_corporate_book;
3978 CLOSE l_facorpbook_csr;
3979
3980 -- SECHAWLA 06-MAY-04 3578894 :Check if the contract has a reporting product attached
3981 -- PAGARG 10-Feb-2005 3730369: Pass correct variable as out parameter for return status
3982 get_reporting_product(
3983 p_api_version => p_api_version,
3984 p_init_msg_list => OKC_API.G_FALSE,
3985 x_return_status => x_return_status,
3986 x_msg_count => x_msg_count,
3987 x_msg_data => x_msg_data,
3988 p_contract_id => l_contract_id,
3989 x_rep_product => lx_rep_product,
3990 x_mg_rep_book => lx_mg_rep_book,
3991 x_rep_deal_type => lx_rep_deal_type);
3992 -- x_rep_tax_owner => lx_rep_tax_owner);
3993
3994 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3995 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3996 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
3997 RAISE OKL_API.G_EXCEPTION_ERROR;
3998 END IF;
3999
4000 -- If lx_rep_product is not null then lx_rep_deal_type and lx_mg_rep_book will also be populated
4001
4002 -- If a reporting product is attached to the contract and reporting deal type is OP LEASE
4003 -- then mg rep book (set in the profile) should be one of the asset books
4004
4005 -- SECHAWLA 06-MAY-04 3578894 : Added a deal type check to the folloiwng condition because of Authoring bug 3574232
4006 -- asset is being assigned to the reporting book only if rep product is OP lEASE, as of now
4007 IF lx_rep_product IS NOT NULL THEN --AND lx_rep_deal_type = 'LEASEOP' THEN -- SECHAWLA 29-JUL-05 4384784 : removed dela type check
4008 FOR l_fataxbooks_rec IN l_fataxbooks_csr(l_name, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date LOOP
4009 IF l_fataxbooks_rec.book_type_code = lx_mg_rep_book THEN
4010 l_rep_book_found := 'Y';
4011 EXIT;
4012 END IF;
4013 END LOOP;
4014 IF l_rep_book_found = 'N' THEN
4015 x_return_status := OKL_API.G_RET_STS_ERROR;
4016 -- Multi GAAP asset book is invalid
4017 OKL_API.set_message( p_app_name => 'OKL',
4018 p_msg_name => 'OKL_AM_INVALID_MG_BOOK');
4019
4020 RAISE OKL_API.G_EXCEPTION_ERROR;
4021 END IF;
4022 END IF;
4023
4024 -- At this point we know that if K has OP LEASE rep product attached, then mg rep book in profile is one of the
4025 -- asset books
4026
4027 IF l_deal_type = 'LEASEOP' THEN
4028
4029 -- Get the corporate book info. This cursor will return only 1 row for corp book
4030 FOR l_assetcorpbook_rec IN l_assetcorpbook_csr(p_kle_id, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date
4031
4032 process_oplease(p_api_version => p_api_version,
4033 p_init_msg_list => OKL_API.G_FALSE,
4034 x_return_status => x_return_status,
4035 x_msg_count => x_msg_count,
4036 x_msg_data => x_msg_data,
4037 p_book_rec => l_assetcorpbook_rec,
4038 p_corporate_book => l_corporate_book,
4039 p_kle_id => p_kle_id,
4040 p_try_id => l_try_id,
4041 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4042 p_func_curr_code => l_func_curr_code,
4043 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4044
4045 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4046 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4047 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4048 RAISE OKL_API.G_EXCEPTION_ERROR;
4049 END IF;
4050
4051
4052
4053 END LOOP;
4054
4055 -- Process reporting book if rep product is attached
4056 IF lx_rep_product IS NOT NULL THEN
4057 IF lx_rep_deal_type = 'LEASEOP' THEN
4058 -- This cursor will return 1 row for the reporting book
4059 FOR l_assetrepbook_rec IN l_assetrepbook_csr(p_kle_id, lx_mg_rep_book, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date
4060 process_oplease(
4061 p_api_version => p_api_version,
4062 p_init_msg_list => OKL_API.G_FALSE,
4063 x_return_status => x_return_status,
4064 x_msg_count => x_msg_count,
4065 x_msg_data => x_msg_data,
4066 p_book_rec => l_assetrepbook_rec,
4067 p_corporate_book => l_corporate_book,
4068 p_kle_id => p_kle_id,
4069 p_try_id => l_try_id,
4070 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4071 p_func_curr_code => l_func_curr_code,
4072 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4073
4074 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4075 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4076 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4077 RAISE OKL_API.G_EXCEPTION_ERROR;
4078 END IF;
4079 END LOOP;
4080 ELSIF lx_rep_deal_type IN ('LEASEDF','LEASEST') THEN
4081
4082 /* -- SECHAWLA 06-MAY-04 3578894 : Do nothing till Authoring bug 3574232 is fixed */
4083 -- 20-Nov-07 sechawla - Split Asset ER - create off lease transactions when reporting dela type IN ('LEASEDF','LEASEST')
4084 FOR l_assetrepbook_rec IN l_assetrepbook_csr(p_kle_id, lx_mg_rep_book, l_quote_accpt_date) LOOP
4085
4086 --SECHAWLA 06-MAY-04 3578894 : calculate NIV of the reporting product
4087 l_add_params(1).name := 'REP_PRODUCT_STRMS_YN';
4088 l_add_params(1).value := 'Y';
4089
4090 l_add_params(2).name := 'OFF_LSE_TRX_DATE';
4091 l_add_params(2).value := to_char(l_quote_eff_date,'MM/DD/YYYY');
4092
4093 l_add_params(3).name := 'quote_effective_from_date';
4094 l_add_params(3).value := to_char(l_quote_eff_date,'MM/DD/YYYY');
4095
4096 okl_am_util_pvt.get_formula_value(
4097 p_formula_name => G_NET_INVESTMENT_FORMULA,
4098 p_chr_id => l_contract_id,
4099 p_cle_id => p_kle_id,
4100 p_additional_parameters => l_add_params,
4101 x_formula_value => l_reporting_NIV,
4102 x_return_status => x_return_status);
4103
4104 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4105 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4106 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4107 RAISE OKL_API.G_EXCEPTION_ERROR;
4108 END IF;
4109
4110 process_dfstlease_lessor( p_api_version => p_api_version,
4111 p_init_msg_list => OKL_API.G_FALSE,
4112 x_return_status => x_return_status,
4113 x_msg_count => x_msg_count,
4114 x_msg_data => x_msg_data ,
4115 p_book_rec => l_assetrepbook_rec,
4116 p_corporate_book => l_corporate_book,
4117 p_kle_id => p_kle_id,
4118 p_df_original_cost => l_df_original_cost,
4119 p_oec => l_oec,
4120 p_net_investment_value => l_reporting_NIV,
4121 p_try_id => l_try_id,
4122 p_sysdate => l_quote_eff_date, --l_sysdate,
4123 p_func_curr_code => l_func_curr_code,
4124 p_legal_entity_id => l_legal_entity_id);
4125
4126 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4127 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4128 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4129 RAISE OKL_API.G_EXCEPTION_ERROR;
4130 END IF;
4131
4132
4133 END LOOP;
4134
4135 END IF;
4136 END IF;
4137
4138 ELSIF (l_deal_type = 'LEASEDF' OR l_deal_type = 'LEASEST') AND l_tax_owner = 'LESSEE' THEN
4139
4140
4141 -- Process reporting book differently if rep product is attached
4142 IF lx_rep_product IS NOT NULL THEN
4143
4144 -- process corp and tax book (excuding mg rep book)
4145 FOR l_corptax_norep_books_rec IN l_corptax_norep_books_csr(p_kle_id, lx_mg_rep_book, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date
4146
4147
4148 process_dfstlease_lessee(p_api_version => p_api_version,
4149 p_init_msg_list => OKL_API.G_FALSE,
4150 x_return_status => x_return_status,
4151 x_msg_count => x_msg_count,
4152 x_msg_data => x_msg_data,
4153 p_book_rec => l_corptax_norep_books_rec,
4154 p_corporate_book => l_corporate_book,
4155 p_kle_id => p_kle_id,
4156 p_df_original_cost => l_df_original_cost,
4157 p_oec => l_oec,
4158 p_net_investment_value => l_base_NIV,
4159 p_try_id => l_try_id,
4160 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4161 p_func_curr_code => l_func_curr_code,
4162 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4163
4164 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4165 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4166 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4167 RAISE OKL_API.G_EXCEPTION_ERROR;
4168 END IF;
4169
4170 END LOOP;
4171
4172 IF lx_rep_deal_type = 'LEASEOP' THEN
4173 FOR l_assetrepbook_rec IN l_assetrepbook_csr(p_kle_id, lx_mg_rep_book, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date
4174 process_oplease(
4175 p_api_version => p_api_version,
4176 p_init_msg_list => OKL_API.G_FALSE,
4177 x_return_status => x_return_status,
4178 x_msg_count => x_msg_count,
4179 x_msg_data => x_msg_data,
4180 p_book_rec => l_assetrepbook_rec,
4181 p_corporate_book => l_corporate_book,
4182 p_kle_id => p_kle_id,
4183 p_try_id => l_try_id,
4184 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4185 p_func_curr_code => l_func_curr_code,
4186 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4187
4188 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4189 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4190 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4191 RAISE OKL_API.G_EXCEPTION_ERROR;
4192 END IF;
4193 END LOOP;
4194 ELSIF lx_rep_deal_type IN ('LEASEDF','LEASEST') THEN
4195 -- -- SECHAWLA 06-MAY-04 3578894 : Do nothing till Authoring bug 3574232 is fixed
4196 --sechawla 20-Nov-07 Split Asset ER - create off lease transactions when reporting deal type IN ('LEASEDF','LEASEST')
4197
4198 FOR l_assetrepbook_rec IN l_assetrepbook_csr(p_kle_id, lx_mg_rep_book, l_quote_eff_date) LOOP
4199
4200 --SECHAWLA 06-MAY-04 3578894 : calculate NIV of the reporting product
4201 l_add_params(1).name := 'REP_PRODUCT_STRMS_YN';
4202 l_add_params(1).value := 'Y';
4203
4204 l_add_params(2).name := 'OFF_LSE_TRX_DATE';
4205 l_add_params(2).value := to_char(l_quote_eff_date,'MM/DD/YYYY');
4206
4207 l_add_params(3).name := 'quote_effective_from_date';
4208 l_add_params(3).value := to_char(l_quote_eff_date,'MM/DD/YYYY');
4209
4210 okl_am_util_pvt.get_formula_value(
4211 p_formula_name => G_NET_INVESTMENT_FORMULA,
4212 p_chr_id => l_contract_id,
4213 p_cle_id => p_kle_id,
4214 p_additional_parameters => l_add_params,
4215 x_formula_value => l_reporting_NIV,
4216 x_return_status => x_return_status);
4217
4218 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4219 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4220 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4221 RAISE OKL_API.G_EXCEPTION_ERROR;
4222 END IF;
4223
4224 process_dfstlease_lessor(p_api_version => p_api_version,
4225 p_init_msg_list => OKL_API.G_FALSE,
4226 x_return_status => x_return_status,
4227 x_msg_count => x_msg_count,
4228 x_msg_data => x_msg_data,
4229 p_book_rec => l_assetrepbook_rec,
4230 p_corporate_book => l_corporate_book,
4231 p_kle_id => p_kle_id,
4232 p_df_original_cost => l_df_original_cost,
4233 p_oec => l_oec,
4234 p_net_investment_value => l_reporting_NIV,
4235 p_try_id => l_try_id,
4236 p_sysdate => l_quote_eff_date, --l_sysdate,
4237 p_func_curr_code => l_func_curr_code,
4238 p_legal_entity_id => l_legal_entity_id);
4239
4240 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4241 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4242 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4243 RAISE OKL_API.G_EXCEPTION_ERROR;
4244 END IF;
4245 END LOOP;
4246
4247 END IF;
4248 ELSE -- no rep product attached. Process all tax books the same way
4249 -- Get the corporate and tax book info. This cursor will return all the books
4250 FOR l_corptaxbooks_rec IN l_corptaxbooks_csr(p_kle_id, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date
4251
4252
4253 process_dfstlease_lessee(p_api_version => p_api_version,
4254 p_init_msg_list => OKL_API.G_FALSE,
4255 x_return_status => x_return_status,
4256 x_msg_count => x_msg_count,
4257 x_msg_data => x_msg_data,
4258 p_book_rec => l_corptaxbooks_rec,
4259 p_corporate_book => l_corporate_book,
4260 p_kle_id => p_kle_id,
4261 p_df_original_cost => l_df_original_cost,
4262 p_oec => l_oec,
4263 p_net_investment_value => l_base_NIV,
4264 p_try_id => l_try_id,
4265 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4266 p_func_curr_code => l_func_curr_code,
4267 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4268
4269 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4270 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4271 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4272 RAISE OKL_API.G_EXCEPTION_ERROR;
4273 END IF;
4274
4275 END LOOP;
4276 END IF;
4277 -------------------------------------------------
4278 ELSIF (l_deal_type = 'LEASEDF' OR l_deal_type = 'LEASEST') AND l_tax_owner = 'LESSOR' THEN
4279
4280 -- Get the corporate and tax book info. This cursor will return all the books
4281 FOR l_assetcorpbook_rec IN l_assetcorpbook_csr(p_kle_id, l_quote_accpt_date) LOOP -- rmunjulu EDAT pass quote accpt date
4282
4283 process_dfstlease_lessor(p_api_version => p_api_version,
4284 p_init_msg_list => OKL_API.G_FALSE,
4285 x_return_status => x_return_status,
4286 x_msg_count => x_msg_count,
4287 x_msg_data => x_msg_data,
4288 p_book_rec => l_assetcorpbook_rec,
4289 p_corporate_book => l_corporate_book,
4290 p_kle_id => p_kle_id,
4291 p_df_original_cost => l_df_original_cost,
4292 p_oec => l_oec,
4293 p_net_investment_value => l_base_NIV,
4294 p_try_id => l_try_id,
4295 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4296 p_func_curr_code => l_func_curr_code,
4297 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4298
4299 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4300 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4301 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4302 RAISE OKL_API.G_EXCEPTION_ERROR;
4303 END IF;
4304
4305 END LOOP;
4306
4307 -- Process reporting book if rep product is attached
4308 IF lx_rep_product IS NOT NULL THEN
4309 IF lx_rep_deal_type = 'LEASEOP' THEN
4310 FOR l_assetrepbook_rec IN l_assetrepbook_csr(p_kle_id, lx_mg_rep_book, l_quote_eff_date) LOOP -- rmunjulu EDAT pass quote eff date
4311 process_oplease(
4312 p_api_version => p_api_version,
4313 p_init_msg_list => OKL_API.G_FALSE,
4314 x_return_status => x_return_status,
4315 x_msg_count => x_msg_count,
4316 x_msg_data => x_msg_data,
4317 p_book_rec => l_assetrepbook_rec,
4318 p_corporate_book => l_corporate_book,
4319 p_kle_id => p_kle_id,
4320 p_try_id => l_try_id,
4321 p_sysdate => l_quote_eff_date, -- rmunjulu EDAT
4322 p_func_curr_code => l_func_curr_code,
4323 p_legal_entity_id => l_legal_entity_id); -- RRAVIKIR Legal Entity changes
4324
4325 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4326 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4327 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4328 RAISE OKL_API.G_EXCEPTION_ERROR;
4329 END IF;
4330 END LOOP;
4331 ELSIF lx_rep_deal_type IN ('LEASEDF','LEASEST') THEN
4332
4333 -- SECHAWLA 06-MAY-04 3578894 : Do nothing till Authoring bug 3574232 is fixed
4334 --sechawla 20-Nov-07 Splot Asset ER - create off lease transactions when reporting deal type IN ('LEASEDF','LEASEST')
4335 FOR l_assetrepbook_rec IN l_assetrepbook_csr(p_kle_id, lx_mg_rep_book, l_quote_eff_date) LOOP
4336
4337 --SECHAWLA 06-MAY-04 3578894 : calculate NIV of the reporting product
4338 l_add_params(1).name := 'REP_PRODUCT_STRMS_YN';
4339 l_add_params(1).value := 'Y';
4340
4341 l_add_params(2).name := 'OFF_LSE_TRX_DATE';
4342 l_add_params(2).value := to_char(l_quote_eff_date,'MM/DD/YYYY');
4343
4344 l_add_params(3).name := 'quote_effective_from_date';
4345 l_add_params(3).value := to_char(l_quote_eff_date,'MM/DD/YYYY');
4346
4347 okl_am_util_pvt.get_formula_value(
4348 p_formula_name => G_NET_INVESTMENT_FORMULA,
4349 p_chr_id => l_contract_id,
4350 p_cle_id => p_kle_id,
4351 p_additional_parameters => l_add_params,
4352 x_formula_value => l_reporting_NIV,
4353 x_return_status => x_return_status);
4354
4355 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4356 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4357 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4358 RAISE OKL_API.G_EXCEPTION_ERROR;
4359 END IF;
4360
4361 process_dfstlease_lessor(p_api_version => p_api_version,
4362 p_init_msg_list => OKL_API.G_FALSE,
4363 x_return_status => x_return_status,
4364 x_msg_count => x_msg_count,
4365 x_msg_data => x_msg_data,
4366 p_book_rec => l_assetrepbook_rec,
4367 p_corporate_book => l_corporate_book,
4368 p_kle_id => p_kle_id,
4369 p_df_original_cost => l_df_original_cost,
4370 p_oec => l_oec,
4371 p_net_investment_value => l_reporting_NIV,
4372 p_try_id => l_try_id,
4373 p_sysdate => l_quote_eff_date,
4374 p_func_curr_code => l_func_curr_code,
4375 p_legal_entity_id => l_legal_entity_id);
4376
4377 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4378 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4379 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4380 RAISE OKL_API.G_EXCEPTION_ERROR;
4381 END IF;
4382 END LOOP;
4383
4384 END IF;
4385 END IF;
4386
4387
4388 END IF;
4389 END IF; --IF l_deal_type IN ('LEASEDF','LEASEOP','LEASEST') THEN
4390
4391
4392
4393
4394
4395
4396
4397
4398 OKL_API.END_ACTIVITY(x_msg_count, x_msg_data);
4399 EXCEPTION
4400 WHEN OKL_API.G_EXCEPTION_ERROR THEN
4401 -- SECHAWLA 06-MAY-04 3578894 : Changed cursor name l_linesv_csr to l_assetbooks_csr
4402 IF l_assetcorpbook_csr%ISOPEN THEN
4403 CLOSE l_assetcorpbook_csr;
4404 END IF;
4405
4406 IF l_corptaxbooks_csr%ISOPEN THEN
4407 CLOSE l_corptaxbooks_csr;
4408 END IF;
4409
4410
4411 IF l_corptax_norep_books_csr%ISOPEN THEN
4412 CLOSE l_corptax_norep_books_csr;
4413 END IF;
4414
4415 IF l_assetrepbook_csr%ISOPEN THEN
4416 CLOSE l_assetrepbook_csr;
4417 END IF;
4418
4419
4420 -- SECHAWLA 06-MAY-04 3578894 : Close new cursors
4421
4422 IF l_oklhdr_csr%ISOPEN THEN
4423 CLOSE l_oklhdr_csr;
4424 END IF;
4425
4426 IF l_okllines_csr%ISOPEN THEN
4427 CLOSE l_okllines_csr;
4428 END IF;
4429
4430 IF l_txlassetsv_csr%ISOPEN THEN
4431 CLOSE l_txlassetsv_csr;
4432 END IF;
4433 IF l_linesfullv_csr%ISOPEN THEN
4434 CLOSE l_linesfullv_csr;
4435 END IF;
4436
4437 IF l_fataxbooks_csr%ISOPEN THEN
4438 CLOSE l_fataxbooks_csr;
4439 END IF;
4440
4441 IF l_facorpbook_csr%ISOPEN THEN
4442 CLOSE l_facorpbook_csr;
4443 END IF;
4444
4445
4446 x_return_status := OKL_API.HANDLE_EXCEPTIONS
4447 (
4448 l_api_name,
4449 G_PKG_NAME,
4450 'OKL_API.G_RET_STS_ERROR',
4451 x_msg_count,
4452 x_msg_data,
4453 '_PVT'
4454 );
4455 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
4456 -- SECHAWLA 06-MAY-04 3578894 : Changed cursor name l_linesv_csr to l_assetbooks_csr
4457 IF l_assetcorpbook_csr%ISOPEN THEN
4458 CLOSE l_assetcorpbook_csr;
4459 END IF;
4460
4461 IF l_corptaxbooks_csr%ISOPEN THEN
4462 CLOSE l_corptaxbooks_csr;
4463 END IF;
4464
4465 IF l_corptax_norep_books_csr%ISOPEN THEN
4466 CLOSE l_corptax_norep_books_csr;
4467 END IF;
4468
4469 IF l_assetrepbook_csr%ISOPEN THEN
4470 CLOSE l_assetrepbook_csr;
4471 END IF;
4472
4473 -- SECHAWLA 06-MAY-04 3578894 : Close new cursors
4474
4475 IF l_oklhdr_csr%ISOPEN THEN
4476 CLOSE l_oklhdr_csr;
4477 END IF;
4478
4479 IF l_okllines_csr%ISOPEN THEN
4480 CLOSE l_okllines_csr;
4481 END IF;
4482
4483 IF l_txlassetsv_csr%ISOPEN THEN
4484 CLOSE l_txlassetsv_csr;
4485 END IF;
4486 IF l_linesfullv_csr%ISOPEN THEN
4487 CLOSE l_linesfullv_csr;
4488 END IF;
4489
4490 IF l_fataxbooks_csr%ISOPEN THEN
4491 CLOSE l_fataxbooks_csr;
4492 END IF;
4493
4494 IF l_facorpbook_csr%ISOPEN THEN
4495 CLOSE l_facorpbook_csr;
4496 END IF;
4497
4498 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
4499 (
4500 l_api_name,
4501 G_PKG_NAME,
4502 'OKL_API.G_RET_STS_UNEXP_ERROR',
4503 x_msg_count,
4504 x_msg_data,
4505 '_PVT'
4506 );
4507 WHEN OTHERS THEN
4508 -- SECHAWLA 06-MAY-04 3578894 : Changed cursor name l_linesv_csr to l_assetbooks_csr
4509 IF l_assetcorpbook_csr%ISOPEN THEN
4510 CLOSE l_assetcorpbook_csr;
4511 END IF;
4512
4513 IF l_corptaxbooks_csr%ISOPEN THEN
4514 CLOSE l_corptaxbooks_csr;
4515 END IF;
4516
4517 IF l_corptax_norep_books_csr%ISOPEN THEN
4518 CLOSE l_corptax_norep_books_csr;
4519 END IF;
4520
4521 IF l_assetrepbook_csr%ISOPEN THEN
4522 CLOSE l_assetrepbook_csr;
4523 END IF;
4524
4525 -- SECHAWLA 06-MAY-04 3578894 : Close new cursors
4526
4527 IF l_oklhdr_csr%ISOPEN THEN
4528 CLOSE l_oklhdr_csr;
4529 END IF;
4530
4531 IF l_okllines_csr%ISOPEN THEN
4532 CLOSE l_okllines_csr;
4533 END IF;
4534
4535 IF l_txlassetsv_csr%ISOPEN THEN
4536 CLOSE l_txlassetsv_csr;
4537 END IF;
4538 IF l_linesfullv_csr%ISOPEN THEN
4539 CLOSE l_linesfullv_csr;
4540 END IF;
4541
4542 IF l_fataxbooks_csr%ISOPEN THEN
4543 CLOSE l_fataxbooks_csr;
4544 END IF;
4545
4546 IF l_facorpbook_csr%ISOPEN THEN
4547 CLOSE l_facorpbook_csr;
4548 END IF;
4549 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
4550 (
4551 l_api_name,
4552 G_PKG_NAME,
4553 'OTHERS',
4554 x_msg_count,
4555 x_msg_data,
4556 '_PVT'
4557 );
4558 END create_offlease_asset_trx;
4559
4560
4561 -- Start of comments
4562 --
4563 -- Procedure Name : create_offlease_asset_trx
4564 -- Description : This procedure gets all Fixed Asset Lines (off-lease assets)
4565 -- for a particular contract using okx_asset_lines_v view and then calls the line level procedure
4566 -- to create amortization transactions.
4567 -- Business Rules :
4568 -- Parameters : p_contract_id - Contract id
4569 -- p_early_termination_yn - early termination / end of term flag
4570 -- Version : 1.0
4571 -- History : rmunjulu EDAT Added 2 new parameters p_quote_eff_date and p_quote_accpt_date
4572 -- : SECHAWLA 19-NOV-2004 4022466 : amortize active contract lines
4573 -- End of comments
4574
4575 PROCEDURE create_offlease_asset_trx( p_api_version IN NUMBER,
4576 p_init_msg_list IN VARCHAR2 ,
4577 x_return_status OUT NOCOPY VARCHAR2,
4578 x_msg_count OUT NOCOPY NUMBER,
4579 x_msg_data OUT NOCOPY VARCHAR2,
4580 p_contract_id IN NUMBER ,
4581 p_early_termination_yn IN VARCHAR2,
4582 p_quote_eff_date IN DATE DEFAULT NULL, -- rmunjulu EDAT Added parameter
4583 p_quote_accpt_date IN DATE DEFAULT NULL) -- rmunjulu EDAT Added parameter
4584 IS
4585
4586 /* -- SECHAWLA 19-NOV-2004 4022466
4587 -- This cursor is used to get all the line items for a given contract
4588 CURSOR l_linesv_csr IS
4589 SELECT parent_line_id
4590 FROM okx_asset_lines_v
4591 WHERE dnz_chr_id = p_contract_id;
4592 */
4593
4594 -- SECHAWLA 19-NOV-2004 4022466 :added
4595 -- get the contract status
4596 CURSOR l_okckhdr_csr(cp_khr_id IN NUMBER) IS
4597 SELECT sts_code
4598 FROM okc_k_headers_b
4599 WHERE id = cp_khr_id;
4600
4601 -- SECHAWLA 19-NOV-2004 4022466 :added
4602 -- get the active financial asset lines for the contract
4603 CURSOR l_okcklines_csr(cp_khr_id IN NUMBER, cp_sts_code IN VARCHAR2) IS
4604 SELECT a.id
4605 FROM okc_k_lines_b a , okc_line_styles_b b
4606 WHERE a.chr_id = cp_khr_id
4607 AND a.lse_id = b.id
4608 AND b.lty_code = 'FREE_FORM1'
4609 AND a.sts_code = cp_sts_code;
4610
4611 l_sts_code VARCHAR2(30);
4612
4613 l_api_name CONSTANT VARCHAR2(30) := 'create_offlease_asset_trx';
4614 l_api_version CONSTANT NUMBER := 1;
4615 l_return_status VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
4616
4617 BEGIN
4618 l_return_status := OKL_API.START_ACTIVITY(l_api_name,
4619 G_PKG_NAME,
4620 p_init_msg_list,
4621 l_api_version,
4622 p_api_version,
4623 '_PVT',
4624 x_return_status);
4625 IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4626 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4627 ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4628 RAISE OKL_API.G_EXCEPTION_ERROR;
4629 END IF;
4630
4631 -- SECHAWLA 19-NOV-2004 4022466 : added validations
4632 IF p_contract_id IS NULL OR p_contract_id = OKL_API.G_MISS_NUM THEN
4633 x_return_status := OKL_API.G_RET_STS_ERROR;
4634 -- chr id is required
4635 OKC_API.set_message( p_app_name => 'OKC',
4636 p_msg_name => G_REQUIRED_VALUE,
4637 p_token1 => G_COL_NAME_TOKEN,
4638 p_token1_value => 'CONTRACT_ID');
4639 RAISE OKL_API.G_EXCEPTION_ERROR;
4640 END IF;
4641
4642 OPEN l_okckhdr_csr(p_contract_id);
4643 FETCH l_okckhdr_csr INTO l_sts_code;
4644 IF l_okckhdr_csr%NOTFOUND THEN
4645 x_return_status := OKL_API.G_RET_STS_ERROR;
4646 -- chr id is invalid
4647 OKC_API.set_message( p_app_name => 'OKC',
4648 p_msg_name => G_INVALID_VALUE,
4649 p_token1 => G_COL_NAME_TOKEN,
4650 p_token1_value => 'CONTRACT_ID');
4651 RAISE OKL_API.G_EXCEPTION_ERROR;
4652 END IF;
4653 CLOSE l_okckhdr_csr;
4654 -- SECHAWLA 19-NOV-2004 4022466 : end
4655
4656 --FOR l_linesv_rec IN l_linesv_csr LOOP -- SECHAWLA 19-NOV-2004 4022466
4657 FOR l_okcklines_rec IN l_okcklines_csr(p_contract_id, l_sts_code) LOOP
4658 create_offlease_asset_trx( p_api_version => p_api_version,
4659 p_init_msg_list => p_init_msg_list,
4660 x_return_status => x_return_status,
4661 x_msg_count => x_msg_count,
4662 x_msg_data => x_msg_data,
4663 p_kle_id => l_okcklines_rec.id, -- SECHAWLA 19-NOV-2004 4022466
4664 p_early_termination_yn => p_early_termination_yn,
4665 p_quote_eff_date => p_quote_eff_date, -- rmunjulu EDAT
4666 p_quote_accpt_date => p_quote_accpt_date); -- rmunjulu EDAT
4667
4668 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4669 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4670 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
4671 RAISE OKL_API.G_EXCEPTION_ERROR;
4672 END IF;
4673
4674 END LOOP;
4675
4676 OKL_API.END_ACTIVITY(x_msg_count, x_msg_data);
4677
4678 EXCEPTION
4679 WHEN OKL_API.G_EXCEPTION_ERROR THEN
4680 IF l_okcklines_csr%ISOPEN THEN
4681 CLOSE l_okcklines_csr;
4682 END IF;
4683 -- SECHAWLA 19-NOV-2004 4022466
4684 IF l_okckhdr_csr%ISOPEN THEN
4685 CLOSE l_okckhdr_csr;
4686 END IF;
4687
4688 x_return_status := OKL_API.HANDLE_EXCEPTIONS
4689 (
4690 l_api_name,
4691 G_PKG_NAME,
4692 'OKL_API.G_RET_STS_ERROR',
4693 x_msg_count,
4694 x_msg_data,
4695 '_PVT'
4696 );
4697 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
4698 IF l_okcklines_csr%ISOPEN THEN
4699 CLOSE l_okcklines_csr;
4700 END IF;
4701 -- SECHAWLA 19-NOV-2004 4022466
4702 IF l_okckhdr_csr%ISOPEN THEN
4703 CLOSE l_okckhdr_csr;
4704 END IF;
4705
4706 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
4707 (
4708 l_api_name,
4709 G_PKG_NAME,
4710 'OKL_API.G_RET_STS_UNEXP_ERROR',
4711 x_msg_count,
4712 x_msg_data,
4713 '_PVT'
4714 );
4715 WHEN OTHERS THEN
4716 IF l_okcklines_csr%ISOPEN THEN
4717 CLOSE l_okcklines_csr;
4718 END IF;
4719
4720 -- SECHAWLA 19-NOV-2004 4022466
4721 IF l_okckhdr_csr%ISOPEN THEN
4722 CLOSE l_okckhdr_csr;
4723 END IF;
4724 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
4725 (
4726 l_api_name,
4727 G_PKG_NAME,
4728 'OTHERS',
4729 x_msg_count,
4730 x_msg_data,
4731 '_PVT'
4732 );
4733 END;
4734
4735 -- Start of comments
4736 --
4737 -- Procedure Name : update_offlease_asset_trx
4738 -- Description : This procedure is used to update a single off-lease transaction header and line
4739 -- Business Rules :
4740 -- Parameters : p_header_rec (transaction header)
4741 -- p_lines_rec (transaction line)
4742 -- Version : 1.0
4743 -- History : SECHAWLA 07-FEB-03 Bug # 2789656
4744 -- Added a validation to prevent negative salvage value
4745 -- SECHAWLA 03-JUN-04 Bug # 3657624
4746 -- Divide Depreciation rate by 100 before updating in okl_txl_assets_b. Rate passed from the
4747 -- screen is a percentage
4748 -- SECHAWLA 24-FEB-05 Bug # 4147143
4749 -- sync up other transactions for an asset when a particular transaction is updated for an asset
4750 -- SECHAWLA 27-FEB-05 Bug # 4147143
4751 -- Always update trx date on Asset Dep trx that stops dep, with date on Asset Amortization trx. |
4752 -- Restrict the transaction updates to appropriate book
4753 -- End of comments
4754
4755 PROCEDURE update_offlease_asset_trx(
4756 p_api_version IN NUMBER,
4757 p_init_msg_list IN VARCHAR2 ,
4758 x_return_status OUT NOCOPY VARCHAR2,
4759 x_msg_count OUT NOCOPY NUMBER,
4760 x_msg_data OUT NOCOPY VARCHAR2,
4761 p_header_rec IN thpv_rec_type,
4762 p_lines_rec IN tlpv_rec_type
4763 ) IS
4764
4765 l_return_status VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
4766 l_api_name CONSTANT VARCHAR2(30) := 'update_offlease_asset_trx';
4767 lx_header_rec thpv_rec_type;
4768 lx_lines_rec tlpv_rec_type;
4769
4770 l_old_trans_date DATE;
4771 l_old_hold_days NUMBER;
4772 l_asset_number VARCHAR2(15);
4773 l_depreciate_yn VARCHAR2(1);
4774 l_new_trans_date DATE;
4775 l_hold_diff NUMBER;
4776 lp_header_temp_rec thpv_rec_type;
4777 lp_lines_temp_rec tlpv_rec_type;
4778 l_api_version CONSTANT NUMBER := 1;
4779 l_sysdate DATE;
4780
4781 -- This cursor returns the transaction date from okl_trx_assets_v
4782 CURSOR l_hdrtransdate_csr(p_id number) IS
4783 SELECT DATE_TRANS_OCCURRED
4784 FROM okl_trx_assets -- SECHAWLA 24-FEB-05 4147143 : changed view to base table
4785 WHERE id = p_id;
4786
4787 -- SECHAWLA 24-FEB-05 4147143 : added kle_id, tal_type
4788 -- SECHAWLA 27-FEB-05 4147143 : added asset book
4789 -- This cursor returns the transaction line information from okl_txl_assets_v
4790 CURSOR l_lines_csr(p_id number) IS
4791 SELECT l.asset_number, l.hold_period_days, l.depreciate_yn, l.kle_id, l.tal_type,
4792 decode(d.tax_book,NULL,l.CORPORATE_BOOK,d.tax_book ) ASSET_BOOK
4793 FROM okl_txl_assets_b l, -- SECHAWLA 24-FEB-05 4147143 : changed view to base table
4794 OKL_TXD_ASSETS_B d -- SECHAWLA 27-FEB-05 4147143 : added
4795 WHERE l.id = p_id
4796 AND l.id = d.tal_id(+); -- SECHAWLA 27-FEB-05 4147143 : added
4797
4798 -- SECHAWLA 24-FEB-05 4147143 : new declarations
4799 -- get the first 2 transaction lines
4800 -- SECHAWLA 27-FEB-05 4147143 : added check for book and status
4801 CURSOR l_nodeplines_csr(cp_kle_id IN NUMBER, cp_book_type_code IN VARCHAR2) IS
4802 SELECT l.id, l.tas_id
4803 FROM okl_trx_assets h, okl_txl_assets_b l, OKL_TXD_ASSETS_B d
4804 WHERE l.kle_id = cp_kle_id
4805 AND l.tas_id = h.id
4806 AND h.tsu_code IN ( 'ENTERED','ERROR')
4807 AND l.tal_type IN ('AUF','AUT')
4808 AND l.depreciate_yn = 'N'
4809 AND l.id = d.tal_id(+)
4810 AND decode(d.tax_book,NULL,l.CORPORATE_BOOK,d.tax_book ) = cp_book_type_code;
4811
4812 -- Get the 4th transaction
4813 -- SECHAWLA 27-FEB-05 4147143 : added check for book and status
4814 CURSOR l_depstartline_csr(cp_kle_id IN NUMBER, cp_book_type_code IN VARCHAR2) IS
4815 SELECT hdr.id hdr_id ,line.id line_id
4816 FROM okl_trx_assets hdr, okl_txl_assets_b line, OKL_TXD_ASSETS_B txd
4817 WHERE line.kle_id = cp_kle_id
4818 AND line.tas_id = hdr.id
4819 AND hdr.tsu_code IN ( 'ENTERED','ERROR')
4820 AND tal_type = 'AUF'
4821 AND depreciate_yn = 'Y'
4822 AND line.tas_id = hdr.id
4823 AND line.id = txd.tal_id(+)
4824 AND decode(txd.tax_book,NULL,line.CORPORATE_BOOK,txd.tax_book ) = cp_book_type_code;
4825
4826 -- get the 3rd transaction header
4827 -- SECHAWLA 27-FEB-05 4147143 : added check for book and status
4828 CURSOR l_amortline_csr(cp_kle_id IN NUMBER, cp_book_type_code IN VARCHAR2) IS
4829 SELECT h.DATE_TRANS_OCCURRED
4830 FROM okl_trx_assets h, okl_txl_assets_b l, OKL_TXD_ASSETS_B d
4831 WHERE l.kle_id = cp_kle_id
4832 AND l.tas_id = h.id
4833 AND h.tsu_code IN ( 'ENTERED','ERROR')
4834 AND l.tal_type = 'AML'
4835 AND l.tas_id = h.id
4836 AND l.id = d.tal_id(+)
4837 AND decode(d.tax_book,NULL,l.CORPORATE_BOOK,d.tax_book ) = cp_book_type_code;
4838
4839
4840 lp_header_rec thpv_rec_type;
4841 lp_header_empty_rec thpv_rec_type;
4842 lp_lines_rec tlpv_rec_type;
4843 l_kle_id NUMBER;
4844 l_tal_type VARCHAR2(10);
4845 l_DATE_TRANS_OCCURRED DATE;
4846 l_hold_zero VARCHAR2(1) := 'N';
4847 l_booktype_code VARCHAR2(15);
4848 -- SECHAWLA 24-FEB-05 4147143 : end new declarations
4849
4850 BEGIN
4851
4852
4853 l_return_status := OKL_API.START_ACTIVITY(l_api_name,
4854 G_PKG_NAME,
4855 p_init_msg_list,
4856 l_api_version,
4857 p_api_version,
4858 '_PVT',
4859 x_return_status);
4860 IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4861 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4862 ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4863 RAISE OKL_API.G_EXCEPTION_ERROR;
4864 END IF;
4865
4866 SELECT SYSDATE INTO l_sysdate FROM DUAL;
4867
4868 lp_lines_temp_rec := p_lines_rec;
4869
4870 IF p_header_rec.id IS NULL OR p_header_rec.id = OKL_API.G_MISS_NUM OR
4871 p_lines_rec.id IS NULL OR p_lines_rec.id = OKL_API.G_MISS_NUM THEN
4872 x_return_status := OKL_API.G_RET_STS_ERROR;
4873 -- transaction id is requierd
4874 OKC_API.set_message( p_app_name => 'OKC',
4875 p_msg_name => G_REQUIRED_VALUE,
4876 p_token1 => G_COL_NAME_TOKEN,
4877 p_token1_value => 'TRANSACTION_ID');
4878 RAISE OKL_API.G_EXCEPTION_ERROR;
4879 END IF;
4880
4881
4882
4883 OPEN l_lines_csr(p_lines_rec.id);
4884 -- SECHAWLA 24-FEB-05 4147143 : added kle_id, tal_type
4885 -- SECHAWLA 27-FEB-05 4147143 : added booktype_code
4886 FETCH l_lines_csr INTO l_asset_number, l_old_hold_days, l_depreciate_yn, l_kle_id, l_tal_type, l_booktype_code ;
4887 IF l_lines_csr%NOTFOUND THEN
4888 x_return_status := OKL_API.G_RET_STS_ERROR;
4889 -- Line ID in the input line record is invalid
4890 OKC_API.set_message( p_app_name => 'OKC',
4891 p_msg_name => G_INVALID_VALUE,
4892 p_token1 => G_COL_NAME_TOKEN,
4893 p_token1_value => 'LINE_ID');
4894 RAISE OKL_API.G_EXCEPTION_ERROR;
4895 END IF;
4896 CLOSE l_lines_csr;
4897
4898 -- SECHAWLA 28-MAY-04 3645574 : Depreciation method can not be null
4899 IF p_lines_rec.deprn_method IS NULL OR p_lines_rec.deprn_method = OKL_API.G_MISS_CHAR THEN
4900 x_return_status := OKL_API.G_RET_STS_ERROR;
4901 -- Depreciation method can not be null
4902 OKL_API.set_message( p_app_name => 'OKC',
4903 p_msg_name => G_REQUIRED_VALUE,
4904 p_token1 => G_COL_NAME_TOKEN,
4905 p_token1_value => 'Depreciation Method');
4906 RAISE OKL_API.G_EXCEPTION_ERROR;
4907
4908 END IF;
4909
4910 -- SECHAWLA 03-JUN-04 3657624 : depreciation rate needs to be divided by 100 before storing
4911 -- in okl_txl_assets_b
4912 IF lp_lines_temp_rec.deprn_rate IS NOT NULL AND lp_lines_temp_rec.deprn_rate <> OKL_API.G_MISS_NUM THEN
4913 lp_lines_temp_rec.deprn_rate := lp_lines_temp_rec.deprn_rate / 100;
4914 END IF;
4915
4916
4917 -- SECHAWLA 07-FEB-03 Bug # 2789656 : Added the following validation to prevent negative salvage value
4918 IF p_lines_rec.salvage_value < 0 THEN
4919 x_return_status := OKL_API.G_RET_STS_ERROR;
4920 -- Asset failed because the new Salvage Value is negative
4921 OKL_API.set_message( p_app_name => 'OKL',
4922 p_msg_name => 'OKL_AM_NEGATIVE_SALVAGE_VALUE',
4923 p_token1 => 'ASSET_NUMBER',
4924 p_token1_value => l_asset_number);
4925 RAISE OKL_API.G_EXCEPTION_ERROR;
4926 END IF;
4927
4928 -- SECHAWLA 03-JUN-04 Added check for 0 hold period days
4929 IF l_old_hold_days IS NOT NULL
4930 --AND l_old_hold_days <> 0 -- SECHAWLA 24-FEB-05 4147143
4931 AND l_depreciate_yn = 'Y' THEN
4932 -- Incase of following scenarios update the hold_period_days when there is a change in the transcation date
4933 -- scenario 1 - Operating lease with hold period, where depreciate_yn = 'Y'
4934 -- scenario 2 - Direct Finance Lease with hold period.
4935 IF p_header_rec.date_trans_occurred IS NOT NULL AND p_header_rec.date_trans_occurred <> OKL_API.G_MISS_DATE THEN
4936
4937 OPEN l_hdrtransdate_csr(p_header_rec.id);
4938 FETCH l_hdrtransdate_csr INTO l_old_trans_date;
4939 IF l_hdrtransdate_csr%NOTFOUND THEN
4940 x_return_status := OKL_API.G_RET_STS_ERROR;
4941 -- Header ID in the input header record is invalid
4942 OKC_API.set_message( p_app_name => 'OKC',
4943 p_msg_name => G_INVALID_VALUE,
4944 p_token1 => G_COL_NAME_TOKEN,
4945 p_token1_value => 'HEADER_ID');
4946 RAISE OKL_API.G_EXCEPTION_ERROR;
4947 END IF;
4948
4949
4950
4951 CLOSE l_hdrtransdate_csr;
4952
4953 l_new_trans_date := p_header_rec.date_trans_occurred;
4954 -- hold period days is not updateable thru the screen
4955
4956 -- SECHAWLA 24-FEB-05 4147143 : begin
4957 IF l_tal_type = 'AUF' AND l_depreciate_yn = 'Y' THEN -- 4th trx is being updated
4958
4959 -- get the trx date of 3rd trx
4960 OPEN l_amortline_csr(l_kle_id, l_booktype_code); -- SECHAWLA 27-FEB-05 4147143 ; added book type code
4961 FETCH l_amortline_csr INTO l_date_trans_occurred;
4962 CLOSE l_amortline_csr;
4963
4964 IF l_new_trans_date < l_date_trans_occurred THEN
4965 x_return_status := OKL_API.G_RET_STS_ERROR;
4966 -- Asset failed because the new Transaction Date is invalid
4967 OKL_API.set_message( p_app_name => 'OKL',
4968 p_msg_name => 'OKL_AM_INVALID_DEP_DT');
4969 RAISE OKL_API.G_EXCEPTION_ERROR;
4970 END IF;
4971 END IF;
4972 -- SECHAWLA 24-FEB-05 4147143 : end
4973
4974 IF trunc(l_new_trans_date) <> trunc(l_old_trans_date) THEN
4975 IF trunc(l_old_trans_date) > trunc(l_new_trans_date) THEN
4976 IF trunc(l_new_trans_date) >= trunc(l_sysdate) THEN
4977 l_hold_diff := trunc(l_old_trans_date) - trunc(l_new_trans_date);
4978 lp_lines_temp_rec.hold_period_days := l_old_hold_days - l_hold_diff;
4979
4980 ELSE
4981 x_return_status := OKL_API.G_RET_STS_ERROR;
4982 -- Asset failed because the new Transaction Date is invalid
4983 OKL_API.set_message( p_app_name => 'OKL',
4984 p_msg_name => 'OKL_AM_INVALID_TRANS_DATE',
4985 p_token1 => 'ASSET_NUMBER',
4986 p_token1_value => l_asset_number);
4987 RAISE OKL_API.G_EXCEPTION_ERROR;
4988 END IF;
4989 ELSE
4990
4991 l_hold_diff := trunc(l_new_trans_date) - trunc(l_old_trans_date) ;
4992 lp_lines_temp_rec.hold_period_days := l_old_hold_days + l_hold_diff;
4993 END IF;
4994 -- SECHAWLA 24-FEB-05 4147143 : added else section
4995 ELSE
4996 lp_lines_temp_rec.hold_period_days := l_old_hold_days;
4997 END IF;
4998
4999
5000 END IF;
5001 END IF;
5002
5003 -- SECHAWLA 24-FEB-05 4147143 : begin
5004 IF lp_lines_temp_rec.hold_period_days = 0 THEN
5005 l_hold_zero := 'Y';
5006 lp_lines_temp_rec.hold_period_days := NULL;
5007 END IF;
5008 -- SECHAWLA 24-FEB-05 4147143 : end
5009
5010 OKL_TRX_ASSETS_PUB.update_trx_ass_h_def(
5011 p_api_version => p_api_version,
5012 p_init_msg_list => OKL_API.G_FALSE,
5013 x_return_status => x_return_status,
5014 x_msg_count => x_msg_count,
5015 x_msg_data => x_msg_data,
5016 p_thpv_rec => p_header_rec,
5017 x_thpv_rec => lx_header_rec);
5018
5019 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5020 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5021 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5022 RAISE OKL_API.G_EXCEPTION_ERROR;
5023 END IF;
5024
5025
5026
5027 OKL_TXL_ASSETS_PUB.update_txl_asset_def(
5028 p_api_version => p_api_version,
5029 p_init_msg_list => OKL_API.G_FALSE,
5030 x_return_status => x_return_status,
5031 x_msg_count => x_msg_count,
5032 x_msg_data => x_msg_data,
5033 p_tlpv_rec => lp_lines_temp_rec,
5034 x_tlpv_rec => lx_lines_rec);
5035
5036 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5037 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5038 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5039 RAISE OKL_API.G_EXCEPTION_ERROR;
5040 END IF;
5041
5042
5043 -- SECHAWLA 24-FEB-05 4147143 :
5044 IF l_tal_type = 'AML' THEN -- 3rd trx is updated
5045 IF trunc(l_new_trans_date) <> trunc(l_old_trans_date) THEN -- date changed during 3rd trx updte
5046 --If trx date = termination date then cancel 1st 2 transcations
5047 IF l_hold_zero = 'Y' THEN
5048 -- cancel 1st 2 transactions
5049 FOR l_nodeplines_rec IN l_nodeplines_csr(l_kle_id, l_booktype_code) LOOP -- SECHAWLA 27-FEB-05 4147143 : added booktype_code
5050 lp_header_rec.id := l_nodeplines_rec.tas_id;
5051 lp_header_rec.tsu_code := 'CANCELED';
5052
5053 OKL_TRX_ASSETS_PUB.update_trx_ass_h_def(
5054 p_api_version => p_api_version,
5055 p_init_msg_list => OKL_API.G_FALSE,
5056 x_return_status => x_return_status,
5057 x_msg_count => x_msg_count,
5058 x_msg_data => x_msg_data,
5059 p_thpv_rec => lp_header_rec,
5060 x_thpv_rec => lx_header_rec);
5061
5062 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5063 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5064 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5065 RAISE OKL_API.G_EXCEPTION_ERROR;
5066 END IF;
5067
5068 END LOOP;
5069 ELSE
5070 -- update only hold period days of 1st 2 transactions
5071 FOR l_nodeplines_rec IN l_nodeplines_csr(l_kle_id,l_booktype_code) LOOP -- SECHAWLA 27-FEB-05 4147143 : added booktype_code
5072 lp_lines_rec.id := l_nodeplines_rec.id;
5073 lp_lines_rec.hold_period_days := lp_lines_temp_rec.hold_period_days;
5074
5075 OKL_TXL_ASSETS_PUB.update_txl_asset_def(
5076 p_api_version => p_api_version,
5077 p_init_msg_list => OKL_API.G_FALSE,
5078 x_return_status => x_return_status,
5079 x_msg_count => x_msg_count,
5080 x_msg_data => x_msg_data,
5081 p_tlpv_rec => lp_lines_rec,
5082 x_tlpv_rec => lx_lines_rec);
5083
5084 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5085 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5086 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5087 RAISE OKL_API.G_EXCEPTION_ERROR;
5088 END IF;
5089
5090 END LOOP;
5091 END IF;
5092 END IF;
5093
5094 -- update 4th transaction hdr and line
5095 lp_header_rec := lp_header_empty_rec;
5096 FOR l_depstartline_rec IN l_depstartline_csr(l_kle_id, l_booktype_code) LOOP -- SECHAWLA 27-FEB-05 4147143 : added book type code
5097 -- IF trunc(l_new_trans_date) <> trunc(l_old_trans_date) THEN -- date changed during 3rd trx updte
5098 -- update header
5099 lp_header_rec.id := l_depstartline_rec.hdr_id;
5100 lp_header_rec.date_trans_occurred := trunc(p_header_rec.date_trans_occurred);
5101
5102 OKL_TRX_ASSETS_PUB.update_trx_ass_h_def(
5103 p_api_version => p_api_version,
5104 p_init_msg_list => OKL_API.G_FALSE,
5105 x_return_status => x_return_status,
5106 x_msg_count => x_msg_count,
5107 x_msg_data => x_msg_data,
5108 p_thpv_rec => lp_header_rec,
5109 x_thpv_rec => lx_header_rec);
5110
5111 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5112 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5113 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5114 RAISE OKL_API.G_EXCEPTION_ERROR;
5115 END IF;
5116 --END IF;
5117 -- Update line
5118 lp_lines_temp_rec.id := l_depstartline_rec.line_id;
5119 -- change id on the lines record with id of 4th trx and keep all other attributes same as that of 3rd trx
5120 OKL_TXL_ASSETS_PUB.update_txl_asset_def(
5121 p_api_version => p_api_version,
5122 p_init_msg_list => OKL_API.G_FALSE,
5123 x_return_status => x_return_status,
5124 x_msg_count => x_msg_count,
5125 x_msg_data => x_msg_data,
5126 p_tlpv_rec => lp_lines_temp_rec,
5127 x_tlpv_rec => lx_lines_rec);
5128
5129 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5130 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5131 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5132 RAISE OKL_API.G_EXCEPTION_ERROR;
5133 END IF;
5134 END LOOP;
5135 END IF; -- IF l_tal_type = 'AML' THEN
5136
5137
5138 OKL_API.END_ACTIVITY(x_msg_count, x_msg_data);
5139 EXCEPTION
5140 WHEN OKL_API.G_EXCEPTION_ERROR THEN
5141 IF l_lines_csr%ISOPEN THEN
5142 CLOSE l_lines_csr;
5143 END IF;
5144 IF l_hdrtransdate_csr%ISOPEN THEN
5145 CLOSE l_hdrtransdate_csr;
5146 END IF;
5147
5148 -- SECHAWLA 24-FEB-05 4147143 : close new cursors
5149 IF l_nodeplines_csr%ISOPEN THEN
5150 CLOSE l_nodeplines_csr;
5151 END IF;
5152
5153 IF l_depstartline_csr%ISOPEN THEN
5154 CLOSE l_depstartline_csr;
5155 END IF;
5156
5157 IF l_amortline_csr%ISOPEN THEN
5158 CLOSE l_amortline_csr;
5159 END IF;
5160
5161
5162 x_return_status := OKL_API.HANDLE_EXCEPTIONS
5163 (
5164 l_api_name,
5165 G_PKG_NAME,
5166 'OKL_API.G_RET_STS_ERROR',
5167 x_msg_count,
5168 x_msg_data,
5169 '_PVT'
5170 );
5171 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
5172 IF l_lines_csr%ISOPEN THEN
5173 CLOSE l_lines_csr;
5174 END IF;
5175 IF l_hdrtransdate_csr%ISOPEN THEN
5176 CLOSE l_hdrtransdate_csr;
5177 END IF;
5178
5179 -- SECHAWLA 24-FEB-05 4147143 : close new cursors
5180 IF l_nodeplines_csr%ISOPEN THEN
5181 CLOSE l_nodeplines_csr;
5182 END IF;
5183
5184 IF l_depstartline_csr%ISOPEN THEN
5185 CLOSE l_depstartline_csr;
5186 END IF;
5187
5188 IF l_amortline_csr%ISOPEN THEN
5189 CLOSE l_amortline_csr;
5190 END IF;
5191
5192 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
5193 (
5194 l_api_name,
5195 G_PKG_NAME,
5196 'OKL_API.G_RET_STS_UNEXP_ERROR',
5197 x_msg_count,
5198 x_msg_data,
5199 '_PVT'
5200 );
5201 WHEN OTHERS THEN
5202 IF l_lines_csr%ISOPEN THEN
5203 CLOSE l_lines_csr;
5204 END IF;
5205 IF l_hdrtransdate_csr%ISOPEN THEN
5206 CLOSE l_hdrtransdate_csr;
5207 END IF;
5208
5209 -- SECHAWLA 24-FEB-05 4147143 : close new cursors
5210 IF l_nodeplines_csr%ISOPEN THEN
5211 CLOSE l_nodeplines_csr;
5212 END IF;
5213
5214 IF l_depstartline_csr%ISOPEN THEN
5215 CLOSE l_depstartline_csr;
5216 END IF;
5217
5218 IF l_amortline_csr%ISOPEN THEN
5219 CLOSE l_amortline_csr;
5220 END IF;
5221 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
5222 (
5223 l_api_name,
5224 G_PKG_NAME,
5225 'OTHERS',
5226 x_msg_count,
5227 x_msg_data,
5228 '_PVT'
5229 );
5230
5231 END update_offlease_asset_trx;
5232
5233
5234
5235 -- Start of comments
5236 --
5237 -- Procedure Name : update_offlease_asset_trx
5238 -- Description : This procedure is used to update more than one off-lease transaction headers and lines
5239 -- Business Rules :
5240 -- Parameters : p_header_tbl (table of transaction header records)
5241 -- p_lines_tbl (table of transaction line records)
5242 -- x_record_status (this flag is set to 'S' if all records in the input tables got processed
5243 -- successfully. Otherwise it is set to 'E' or 'U'
5244 -- Version : 1.0
5245 -- History : SECHAWLA 07-FEB-03 Bug # 2789656 : Added a validation to prevent negative salvage value
5246 -- End of comments
5247
5248 PROCEDURE update_offlease_asset_trx(
5249 p_api_version IN NUMBER,
5250 p_init_msg_list IN VARCHAR2 ,
5251 x_return_status OUT NOCOPY VARCHAR2,
5252 x_msg_count OUT NOCOPY NUMBER,
5253 x_msg_data OUT NOCOPY VARCHAR2,
5254 p_header_tbl IN thpv_tbl_type,
5255 p_lines_tbl IN tlpv_tbl_type,
5256 x_record_status OUT NOCOPY VARCHAR2 ) IS
5257
5258 l_return_status VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
5259 l_api_name CONSTANT VARCHAR2(30) := 'update_offlease_asset_trx';
5260 lx_header_rec thpv_rec_type;
5261 lx_lines_rec tlpv_rec_type;
5262
5263 l_old_trans_date DATE;
5264 l_old_hold_days NUMBER;
5265 l_asset_number VARCHAR2(15);
5266 l_depreciate_yn VARCHAR2(1);
5267 l_new_trans_date DATE;
5268 l_api_version CONSTANT NUMBER := 1;
5269 l_sysdate DATE;
5270 i NUMBER;
5271 -- This cursor returns the transaction date from okl_trx_assets_v
5272 CURSOR l_hdrtransdate_csr(p_id NUMBER) IS
5273 SELECT DATE_TRANS_OCCURRED
5274 FROM OKL_TRX_ASSETS
5275 WHERE id = p_id;
5276
5277 -- This cursor returns the transaction line information from okl_txl_assets_v
5278 CURSOR l_lines_csr(p_id number) IS
5279 SELECT asset_number, hold_period_days, depreciate_yn
5280 FROM okl_txl_assets_v
5281 WHERE id = p_id;
5282
5283 lp_header_temp_rec thpv_rec_type;
5284 lp_lines_temp_rec tlpv_rec_type;
5285 l_hold_diff NUMBER;
5286 l_date_valid_yn VARCHAR2(1);
5287
5288 BEGIN
5289
5290 x_record_status := OKL_API.G_RET_STS_SUCCESS;
5291
5292 l_return_status := OKL_API.START_ACTIVITY(l_api_name,
5293 G_PKG_NAME,
5294 p_init_msg_list,
5295 l_api_version,
5296 p_api_version,
5297 '_PVT',
5298 x_return_status);
5299 IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5300 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5301 ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5302 RAISE OKL_API.G_EXCEPTION_ERROR;
5303 END IF;
5304
5305 /* -- SECHAWLA 24-FEB-05 4147143 : commented out as this procedure is not being used.
5306 With new logic of updating off-lease transctions, update to one transaction results in updat to other
5307 transactions for an asset. This procedure needs to be modified to uptake the new logic, if required
5308 IF p_header_tbl.count <> p_lines_tbl.count THEN
5309 x_return_status := OKL_API.G_RET_STS_ERROR;
5310 -- Number of records in the input header and lines table should be same.
5311 OKL_API.set_message( p_app_name => 'OKL',
5312 p_msg_name => 'OKL_AM_INVALID_RECORD_COUNT');
5313
5314 RAISE OKL_API.G_EXCEPTION_ERROR;
5315 END IF;
5316
5317 SELECT SYSDATE INTO l_sysdate FROM DUAL;
5318
5319 IF p_header_tbl.count > 0 THEN
5320 i := p_header_tbl.FIRST;
5321
5322 -- loop thru all the records in the input table, validate data an then update okl_trx_assets_v and
5323 -- okl_txl_assets_v
5324 LOOP
5325
5326 l_date_valid_yn := 'Y';
5327
5328 lp_lines_temp_rec := p_lines_tbl(i);
5329
5330 -- << LABEL 1 >>
5331 IF p_header_tbl(i).id IS NULL OR p_header_tbl(i).id = OKL_API.G_MISS_NUM OR
5332 p_lines_tbl(i).id IS NULL OR p_lines_tbl(i).id = OKL_API.G_MISS_NUM THEN
5333 x_record_status := OKL_API.G_RET_STS_ERROR;
5334 -- transaction Id is required
5335 OKC_API.set_message( p_app_name => 'OKC',
5336 p_msg_name => G_REQUIRED_VALUE,
5337 p_token1 => G_COL_NAME_TOKEN,
5338 p_token1_value => 'TRANSACTION_ID');
5339
5340 ELSE
5341
5342
5343 OPEN l_hdrtransdate_csr(p_header_tbl(i).id);
5344 FETCH l_hdrtransdate_csr INTO l_old_trans_date;
5345 -- << LABEL 4 >>
5346 IF l_hdrtransdate_csr%NOTFOUND THEN
5347 x_record_status := OKL_API.G_RET_STS_ERROR;
5348 -- Header Id for the current record in the input table is invalid
5349 OKC_API.set_message( p_app_name => 'OKC',
5350 p_msg_name => G_INVALID_VALUE,
5351 p_token1 => G_COL_NAME_TOKEN,
5352 p_token1_value => 'HEADER_ID');
5353
5354
5355 ELSE
5356
5357
5358 OPEN l_lines_csr(p_lines_tbl(i).id);
5359 FETCH l_lines_csr INTO l_asset_number, l_old_hold_days, l_depreciate_yn ;
5360 -- << LABEL 2 >>
5361 IF l_lines_csr%NOTFOUND THEN
5362 x_record_status := OKL_API.G_RET_STS_ERROR;
5363 -- Line Id for the current record in the input table is invalid
5364 OKC_API.set_message( p_app_name => 'OKC',
5365 p_msg_name => G_INVALID_VALUE,
5366 p_token1 => G_COL_NAME_TOKEN,
5367 p_token1_value => 'LINE_ID');
5368
5369 -- SECHAWLA 07-FEB-03 Bug # 2789656 : Added the following validation to prevent negative salvage value
5370 ELSIF p_lines_tbl(i).salvage_value < 0 THEN
5371 x_record_status := OKL_API.G_RET_STS_ERROR;
5372 -- Asset failed because the new Salvage Value is negative
5373 OKL_API.set_message( p_app_name => 'OKL',
5374 p_msg_name => 'OKL_AM_NEGATIVE_SALVAGE_VALUE',
5375 p_token1 => 'ASSET_NUMBER',
5376 p_token1_value => l_asset_number);
5377
5378 ELSE
5379 --SECHAWLA 03-JUN-04 Added a check for 0 hold period days
5380 -- << LABEL 3 >>
5381 IF l_old_hold_days IS NOT NULL AND l_old_hold_days <> 0 AND l_depreciate_yn = 'Y' THEN
5382 -- Incase of following scenarios update the hold_period_days when there is a change in the transcation date
5383 -- scenario 1 - Operating lease with hold period, where depreciate_yn = 'Y'
5384 -- scenario 2 - Direct Finance Lease with hold period.
5385
5386 IF p_header_tbl(i).date_trans_occurred IS NOT NULL AND
5387 p_header_tbl(i).date_trans_occurred <> OKL_API.G_MISS_DATE THEN
5388
5389
5390 l_new_trans_date := p_header_tbl(i).date_trans_occurred;
5391 -- hold period days is not updateable thru the screen
5392
5393 -- << LABEL 5 >>
5394 IF trunc(l_new_trans_date) <> trunc(l_old_trans_date) THEN
5395 IF trunc(l_old_trans_date) > trunc(l_new_trans_date) THEN
5396 IF trunc(l_new_trans_date) >= trunc(l_sysdate) THEN
5397 l_hold_diff := trunc(l_old_trans_date) - trunc(l_new_trans_date);
5398 lp_lines_temp_rec.hold_period_days := l_old_hold_days - l_hold_diff;
5399 ELSE
5400 x_record_status := OKL_API.G_RET_STS_ERROR;
5401 -- Asset failed because the new Transaction Date is invalid
5402 OKL_API.set_message( p_app_name => 'OKL',
5403 p_msg_name => 'OKL_AM_INVALID_TRANS_DATE',
5404 p_token1 => 'ASSET_NUMBER',
5405 p_token1_value => l_asset_number);
5406
5407 l_date_valid_yn := 'N';
5408 END IF;
5409 ELSE
5410 l_hold_diff := trunc(l_new_trans_date) - trunc(l_old_trans_date) ;
5411 lp_lines_temp_rec.hold_period_days := l_old_hold_days + l_hold_diff;
5412 END IF;
5413 END IF; -- << LABEL 5 >>
5414
5415 END IF;
5416
5417 END IF; -- << LABEL 3 >>
5418
5419
5420 IF l_date_valid_yn = 'Y' THEN
5421 OKL_TRX_ASSETS_PUB.update_trx_ass_h_def(
5422 p_api_version => p_api_version,
5423 p_init_msg_list => OKL_API.G_FALSE,
5424 x_return_status => x_return_status,
5425 x_msg_count => x_msg_count,
5426 x_msg_data => x_msg_data,
5427 p_thpv_rec => p_header_tbl(i),
5428 x_thpv_rec => lx_header_rec);
5429
5430 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5431 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5432 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5433 RAISE OKL_API.G_EXCEPTION_ERROR;
5434 END IF;
5435
5436 OKL_TXL_ASSETS_PUB.update_txl_asset_def(
5437 p_api_version => p_api_version,
5438 p_init_msg_list => OKL_API.G_FALSE,
5439 x_return_status => x_return_status,
5440 x_msg_count => x_msg_count,
5441 x_msg_data => x_msg_data,
5442 p_tlpv_rec => lp_lines_temp_rec,
5443 x_tlpv_rec => lx_lines_rec);
5444
5445 IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5446 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5447 ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
5448 RAISE OKL_API.G_EXCEPTION_ERROR;
5449 END IF;
5450 END IF;
5451
5452
5453 END IF; -- << LABEL 2 >>
5454 CLOSE l_lines_csr;
5455
5456 END IF; -- << LABEL 4 >>
5457 CLOSE l_hdrtransdate_csr;
5458
5459 END IF; -- << LABEL 1 >>
5460
5461 EXIT WHEN (i = p_header_tbl.LAST);
5462 i := p_header_tbl.NEXT(i);
5463
5464 END LOOP;
5465 END IF; -- p_header_tbl.count > 0
5466 */
5467 OKL_API.END_ACTIVITY(x_msg_count, x_msg_data);
5468 EXCEPTION
5469 WHEN OKL_API.G_EXCEPTION_ERROR THEN
5470 IF l_lines_csr%ISOPEN THEN
5471 CLOSE l_lines_csr;
5472 END IF;
5473 IF l_hdrtransdate_csr%ISOPEN THEN
5474 CLOSE l_hdrtransdate_csr;
5475 END IF;
5476 x_return_status := OKL_API.HANDLE_EXCEPTIONS
5477 (
5478 l_api_name,
5479 G_PKG_NAME,
5480 'OKL_API.G_RET_STS_ERROR',
5481 x_msg_count,
5482 x_msg_data,
5483 '_PVT'
5484 );
5485 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
5486 IF l_lines_csr%ISOPEN THEN
5487 CLOSE l_lines_csr;
5488 END IF;
5489 IF l_hdrtransdate_csr%ISOPEN THEN
5490 CLOSE l_hdrtransdate_csr;
5491 END IF;
5492 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
5493 (
5494 l_api_name,
5495 G_PKG_NAME,
5496 'OKL_API.G_RET_STS_UNEXP_ERROR',
5497 x_msg_count,
5498 x_msg_data,
5499 '_PVT'
5500 );
5501 WHEN OTHERS THEN
5502 IF l_lines_csr%ISOPEN THEN
5503 CLOSE l_lines_csr;
5504 END IF;
5505 IF l_hdrtransdate_csr%ISOPEN THEN
5506 CLOSE l_hdrtransdate_csr;
5507 END IF;
5508 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
5509 (
5510 l_api_name,
5511 G_PKG_NAME,
5512 'OTHERS',
5513 x_msg_count,
5514 x_msg_data,
5515 '_PVT'
5516 );
5517
5518 END update_offlease_asset_trx;
5519
5520
5521 -- Start of comments
5522 --
5523 -- Procedure Name : update_depreciation
5524 -- Description : Published API for update of Depreciation method and Salvage value
5525 -- Business Rules : This API will do validations which are done from screen and then call the
5526 -- screen level api for additional validations and updates
5527 -- Parameters :
5528 -- Version : 1.0
5529 -- History : RMUNJULU 3608615 Added
5530 -- RMUNJULU 3600565 Added IF conditions for checking both deprn_method
5531 -- and life_in_months passed if passed
5532 -- SECHAWLA 28-MAY-04 3645574 Added deprn rate processing logic for diminishing dep methods
5533 -- End of comments
5534 PROCEDURE update_depreciation(
5535 p_api_version IN NUMBER,
5536 p_init_msg_list IN VARCHAR2 DEFAULT OKC_API.G_FALSE,
5537 x_return_status OUT NOCOPY VARCHAR2,
5538 x_msg_count OUT NOCOPY NUMBER,
5539 x_msg_data OUT NOCOPY VARCHAR2,
5540 p_deprn_rec IN deprn_rec_type) IS
5541
5542 -- Get the Trn details
5543 CURSOR trns_csr (p_id IN NUMBER) IS
5544 SELECT TAS.id,
5545 TAS.tsu_code,
5546 TAS.tas_type,
5547 TAS.date_trans_occurred
5548 FROM OKL_TRX_ASSETS TAS
5549 WHERE TAS.id = p_id;
5550
5551 -- Check the Dep Method and Life In months
5552 CURSOR dep_csr (p_dep_method IN VARCHAR2, p_life_in_months IN NUMBER) IS
5553 SELECT FAM.method_code
5554 FROM FA_METHODS FAM
5555 WHERE FAM.method_code = p_dep_method
5556 AND FAM.life_in_months = p_life_in_months;
5557
5558 -- Get the Line details
5559 CURSOR line_csr (p_header_id IN NUMBER) IS
5560 SELECT TXL.id
5561 FROM OKL_TXL_ASSETS_V TXL
5562 WHERE TXL.tas_id = p_header_id;
5563
5564 -- Get the lookup meaning for OKL_TRANS_HEADER_TYPE
5565 CURSOR amt_csr (p_code IN VARCHAR2) IS
5566 SELECT fnd.meaning
5567 FROM fnd_lookups fnd
5568 WHERE fnd.lookup_type = 'OKL_TRANS_HEADER_TYPE'
5569 AND fnd.lookup_code = p_code;
5570
5571 -- Get the lookup meaning for ENTERED status
5572 CURSOR status_csr (p_code IN VARCHAR2) IS
5573 SELECT fnd.meaning
5574 FROM fnd_lookups fnd
5575 WHERE fnd.lookup_type = 'OKL_TRANSACTION_STATUS'
5576 AND fnd.lookup_code = p_code;
5577
5578
5579 -- SECHAWLA 28-MAY-04 3645574 : new cursor for validating deprn rate
5580 CURSOR l_flatrates_csr(cp_deprn_method IN VARCHAR2,cp_deprn_rate_percent IN NUMBER) IS
5581 SELECT 'x'
5582 FROM fa_methods famet, fa_flat_rates fart
5583 WHERE famet.method_code = cp_deprn_method
5584 AND famet.method_id = fart.method_id
5585 AND fart.adjusted_rate = cp_deprn_rate_percent / 100 -- sechawla 03-jun-04 3657624 : divide by 100
5586 AND nvl(fart.adjusting_rate,0) = 0 ;
5587
5588 l_return_status VARCHAR2(3);
5589 l_api_name VARCHAR2(30);
5590 l_api_version NUMBER;
5591
5592 l_id NUMBER;
5593 l_tsu_code OKL_TRX_ASSETS.tsu_code%TYPE;
5594 l_tas_type OKL_TRX_ASSETS.tas_type%TYPE;
5595 l_date_trn OKL_TRX_ASSETS.date_trans_occurred%TYPE;
5596 l_val FA_METHODS.method_code%TYPE;
5597 l_line_id NUMBER;
5598
5599 lp_header_rec thpv_rec_type;
5600 lp_lines_rec tlpv_rec_type;
5601
5602 l_trns_type fnd_lookups.meaning%TYPE;
5603 l_status fnd_lookups.meaning%TYPE;
5604
5605 -- SECHAWLA 28-MAY-04 3645574 : new declaration
5606 l_dummy VARCHAR2(1);
5607
5608 BEGIN
5609
5610 -- Initialize variables
5611 l_api_name := 'update_depreciation';
5612 l_api_version := 1;
5613 l_id := -999;
5614 l_line_id := -999;
5615 l_val := NULL;
5616
5617 -- Start activity
5618 l_return_status := OKL_API.START_ACTIVITY( l_api_name,
5619 G_PKG_NAME,
5620 p_init_msg_list,
5621 l_api_version,
5622 p_api_version,
5623 '_PVT',
5624 x_return_status);
5625
5626 IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5627 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5628 ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5629 RAISE OKL_API.G_EXCEPTION_ERROR;
5630 END IF;
5631
5632 -- Get trn details
5633 FOR trns_rec IN trns_csr(p_deprn_rec.p_tas_id) LOOP
5634
5635 l_id := trns_rec.id;
5636 l_tsu_code := trns_rec.tsu_code;
5637 l_tas_type := trns_rec.tas_type;
5638 l_date_trn := trns_rec.date_trans_occurred;
5639
5640 END LOOP;
5641
5642 -- Check trx_id
5643 IF l_id IS NULL
5644 OR l_id = -999 THEN
5645
5646 OKL_API.set_message(
5647 p_app_name => 'OKC',
5648 p_msg_name => G_INVALID_VALUE,
5649 p_token1 => G_COL_NAME_TOKEN,
5650 p_token1_value => 'p_tas_id');
5651
5652 RAISE OKL_API.G_EXCEPTION_ERROR;
5653
5654 END IF;
5655
5656 -- Check trn type
5657 IF l_tas_type <> 'AMT' THEN
5658
5659 -- get the trn type OKL_TRANS_HEADER_TYPE
5660 FOR amt_rec IN amt_csr (l_tas_type) LOOP
5661
5662 l_trns_type := amt_rec.meaning;
5663
5664 END LOOP;
5665
5666 -- Transaction type TRANSACTION_TYPE is not updateable.
5667 OKL_API.set_message(
5668 p_app_name => 'OKL',
5669 p_msg_name => 'OKL_AM_DEPRN_TYPE_ERR',
5670 p_token1 => 'TRANSACTION_TYPE',
5671 p_token1_value => l_trns_type);
5672
5673 RAISE OKL_API.G_EXCEPTION_ERROR;
5674
5675 END IF;
5676
5677 -- Check trn status
5678 IF l_tsu_code NOT IN ('ENTERED') THEN
5679
5680 -- get the trn status
5681 FOR status_rec IN status_csr (l_tsu_code) LOOP
5682
5683 l_status := status_rec.meaning;
5684
5685 END LOOP;
5686
5687 -- Transaction with status STATUS is not updateable.
5688 OKL_API.set_message(
5689 p_app_name => 'OKL',
5690 p_msg_name => 'OKL_AM_DEPRN_STATUS_ERR',
5691 p_token1 => 'STATUS',
5692 p_token1_value => l_status);
5693
5694 RAISE OKL_API.G_EXCEPTION_ERROR;
5695
5696 END IF;
5697
5698
5699
5700 -- RMUNJULU 06-May-2004
5701 -- Check if deprn_method passed but not life_in_months/rate
5702 IF (p_deprn_rec.p_dep_method IS NOT NULL AND p_deprn_rec.p_dep_method <> OKL_API.G_MISS_CHAR )
5703 AND (p_deprn_rec.p_life_in_months IS NULL OR p_deprn_rec.p_life_in_months = OKL_API.G_MISS_NUM)
5704 -- SECHAWLA 28-MAY-04 3645574 : Added check for deprn rate
5705 AND (p_deprn_rec.p_deprn_rate_percent IS NULL OR p_deprn_rec.p_deprn_rate_percent = OKL_API.G_MISS_NUM) THEN
5706
5707 -- SECHAWLA 28-MAY-04 3645574
5708 /*OKL_API.set_message(
5709 p_app_name => 'OKC',
5710 p_msg_name => G_INVALID_VALUE,
5711 p_token1 => G_COL_NAME_TOKEN,
5712 p_token1_value => 'p_life_in_months');
5713 */
5714
5715 -- SECHAWLA 28-MAY-04 3645574
5716 --Please provide Life In Months or Depreciation Rate.
5717 OKL_API.set_message( p_app_name => 'OKL',
5718 p_msg_name => 'OKL_AM_PROV_LIFE_OR_RATE');
5719
5720 RAISE OKL_API.G_EXCEPTION_ERROR;
5721
5722 END IF;
5723
5724 -- RMUNJULU 06-May-2004
5725 -- Check if life_in_months/rate is passed but not deprn_method
5726 IF ( (p_deprn_rec.p_life_in_months IS NOT NULL AND p_deprn_rec.p_life_in_months <> OKL_API.G_MISS_NUM )
5727 OR -- SECHAWLA 28-MAY-04 3645574 : added check for deprn rate
5728 (p_deprn_rec.p_deprn_rate_percent IS NOT NULL AND p_deprn_rec.p_deprn_rate_percent <> OKL_API.G_MISS_NUM )
5729 )
5730 AND (p_deprn_rec.p_dep_method IS NULL OR p_deprn_rec.p_dep_method = OKL_API.G_MISS_CHAR) THEN
5731
5732 OKL_API.set_message(
5733 p_app_name => 'OKC',
5734 --p_msg_name => G_INVALID_VALUE, -- SECHAWLA 28-MAY-04 3645574
5735 p_msg_name => G_REQUIRED_VALUE, -- SECHAWLA 28-MAY-04 3645574
5736 p_token1 => G_COL_NAME_TOKEN,
5737 p_token1_value => 'p_dep_method');
5738
5739 RAISE OKL_API.G_EXCEPTION_ERROR;
5740
5741 END IF;
5742
5743 -- SECHAWLA 26-MAY-04 3645574 : all 3 should not be populated
5744 IF (p_deprn_rec.p_dep_method IS NOT NULL AND p_deprn_rec.p_dep_method <> OKL_API.G_MISS_CHAR ) AND
5745 (p_deprn_rec.p_life_in_months IS NOT NULL AND p_deprn_rec.p_life_in_months <> OKL_API.G_MISS_NUM ) AND
5746 (p_deprn_rec.p_deprn_rate_percent IS NOT NULL AND p_deprn_rec.p_deprn_rate_percent <> OKL_API.G_MISS_NUM ) THEN
5747 --A depreciation method can not have both Life In Months and Depreciation Rate. Please provide only one of these values.
5748 OKL_API.set_message(
5749 p_app_name => 'OKL',
5750 p_msg_name => 'OKL_AM_BOTH_LIFE_AND_RATE');
5751 RAISE OKL_API.G_EXCEPTION_ERROR;
5752 END IF;
5753
5754
5755 -- RMUNJULU 06-May-2004
5756 -- when both deprn_method and life_in_months/rate passed
5757 IF (p_deprn_rec.p_dep_method IS NOT NULL AND p_deprn_rec.p_dep_method <> OKL_API.G_MISS_CHAR )
5758 AND ( (p_deprn_rec.p_life_in_months IS NOT NULL AND p_deprn_rec.p_life_in_months <> OKL_API.G_MISS_NUM)
5759 OR -- SECHAWLA 28-MAY-04 3645574 : added check for deprn rate
5760 (p_deprn_rec.p_deprn_rate_percent IS NOT NULL AND p_deprn_rec.p_deprn_rate_percent <> OKL_API.G_MISS_NUM )
5761 ) THEN
5762
5763 IF p_deprn_rec.p_life_in_months IS NOT NULL THEN -- SECHAWLA 28-MAY-04 3645574 : added this IF condition
5764 -- Check dep method and life in months
5765 FOR dep_rec IN dep_csr(p_deprn_rec.p_dep_method, p_deprn_rec.p_life_in_months) LOOP
5766
5767 l_val := dep_rec.method_code;
5768
5769 END LOOP;
5770
5771 IF l_val IS NULL THEN
5772
5773 -- Depreciation method DEPRECIATION_METHOD and life in months LIFE_IN_MONTHS is an invalid combination.
5774 OKL_API.set_message(
5775 p_app_name => 'OKL',
5776 p_msg_name => 'OKL_AM_DEPRN_INVALID_COMB',
5777 p_token1 => 'DEPRECIATION_METHOD',
5778 p_token1_value => p_deprn_rec.p_dep_method,
5779 p_token2 => 'LIFE_IN_MONTHS',
5780 p_token2_value => p_deprn_rec.p_life_in_months);
5781
5782 RAISE OKL_API.G_EXCEPTION_ERROR;
5783
5784 END IF;
5785 ELSE -- SECHAWLA 28-MAY-04 3645574 : deprn rate is provided
5786
5787 OPEN l_flatrates_csr(p_deprn_rec.p_dep_method, p_deprn_rec.p_deprn_rate_percent);
5788 FETCH l_flatrates_csr INTO l_dummy;
5789 IF l_flatrates_csr%NOTFOUND THEN
5790 -- This combination of Depreciation Method DEP_METHOD and Depreciation Rate DEP_RATE is invalid.
5791 OKL_API.set_message(
5792 p_app_name => 'OKL',
5793 p_msg_name => 'OKL_AM_INVALID_MTHD_RATE',
5794 p_token1 => 'DEP_METHOD',
5795 p_token1_value => p_deprn_rec.p_dep_method,
5796 p_token2 => 'DEP_RATE',
5797 p_token2_value => p_deprn_rec.p_deprn_rate_percent);
5798
5799 RAISE OKL_API.G_EXCEPTION_ERROR;
5800 END IF;
5801 CLOSE l_flatrates_csr;
5802
5803 END IF;
5804 END IF;
5805
5806 -- if line_id is supplied
5807 IF p_deprn_rec.p_tal_id IS NOT NULL
5808 AND p_deprn_rec.p_tal_id <> OKL_API.G_MISS_NUM THEN
5809
5810 l_line_id := p_deprn_rec.p_tal_id;
5811
5812 ELSE -- line id not supplied -- get from database
5813 -- Get line details
5814 FOR line_rec IN line_csr(p_deprn_rec.p_tas_id) LOOP
5815
5816 l_line_id := line_rec.id;
5817
5818 END LOOP;
5819 END IF;
5820
5821 -- Set the Header rec
5822 lp_header_rec.id := p_deprn_rec.p_tas_id;
5823
5824 -- if date trn occurred supplied
5825 IF p_deprn_rec.p_date_trns_occured IS NOT NULL
5826 AND p_deprn_rec.p_date_trns_occured <> OKL_API.G_MISS_DATE THEN
5827 lp_header_rec.date_trans_occurred := p_deprn_rec.p_date_trns_occured;
5828 ELSE -- date not supplied-- get from database
5829 lp_header_rec.date_trans_occurred := l_date_trn;
5830 END IF;
5831
5832 -- Set the line rec
5833 lp_lines_rec.id := l_line_id;
5834
5835 -- RMUNJULU 06-May-2004
5836 -- when both deprn_method and life_in_months/rate are supplied then set for update
5837 IF (p_deprn_rec.p_dep_method IS NOT NULL AND p_deprn_rec.p_dep_method <> OKL_API.G_MISS_CHAR)
5838 AND ( (p_deprn_rec.p_life_in_months IS NOT NULL AND p_deprn_rec.p_life_in_months <> OKL_API.G_MISS_NUM)
5839 OR -- SECHAWLA 28-MAY-04 3645574 : added deprn rate check
5840 (p_deprn_rec.p_deprn_rate_percent IS NOT NULL AND p_deprn_rec.p_deprn_rate_percent <> OKL_API.G_MISS_NUM)
5841 ) THEN
5842
5843 lp_lines_rec.deprn_method := p_deprn_rec.p_dep_method;
5844
5845 --SECHAWLA 28-MAY-04 3645574 : populate life or rate
5846 IF p_deprn_rec.p_life_in_months IS NOT NULL THEN
5847 lp_lines_rec.life_in_months := p_deprn_rec.p_life_in_months;
5848 lp_lines_rec.deprn_rate := NULL;
5849 ELSE
5850 lp_lines_rec.deprn_rate := p_deprn_rec.p_deprn_rate_percent;
5851 lp_lines_rec.life_in_months := NULL;
5852 END IF;
5853
5854 END IF;
5855
5856 -- if salvage value supplied
5857 IF p_deprn_rec.p_salvage_value IS NOT NULL
5858 AND p_deprn_rec.p_salvage_value <> OKL_API.G_MISS_NUM THEN
5859 lp_lines_rec.salvage_value := p_deprn_rec.p_salvage_value;
5860 END IF;
5861
5862 -- Update header and line trns
5863 update_offlease_asset_trx(
5864 p_api_version => p_api_version,
5865 p_init_msg_list => OKL_API.G_FALSE,
5866 x_return_status => l_return_status,
5867 x_msg_count => x_msg_count,
5868 x_msg_data => x_msg_data,
5869 p_header_rec => lp_header_rec,
5870 p_lines_rec => lp_lines_rec);
5871
5872 IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5873 RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5874 ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5875 RAISE OKL_API.G_EXCEPTION_ERROR;
5876 END IF;
5877
5878 x_return_status := l_return_status;
5879
5880 OKL_API.END_ACTIVITY(x_msg_count, x_msg_data);
5881 EXCEPTION
5882 WHEN OKL_API.G_EXCEPTION_ERROR THEN
5883 -- SECHAWLA 28-MAY-04 3645574 : close the new cursor
5884 IF l_flatrates_csr%ISOPEN THEN
5885 CLOSE l_flatrates_csr;
5886 END IF;
5887 x_return_status := OKL_API.HANDLE_EXCEPTIONS
5888 (
5889 l_api_name,
5890 G_PKG_NAME,
5891 'OKL_API.G_RET_STS_ERROR',
5892 x_msg_count,
5893 x_msg_data,
5894 '_PVT'
5895 );
5896 WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
5897
5898 -- SECHAWLA 28-MAY-04 3645574 : close the new cursor
5899 IF l_flatrates_csr%ISOPEN THEN
5900 CLOSE l_flatrates_csr;
5901 END IF;
5902
5903 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
5904 (
5905 l_api_name,
5906 G_PKG_NAME,
5907 'OKL_API.G_RET_STS_UNEXP_ERROR',
5908 x_msg_count,
5909 x_msg_data,
5910 '_PVT'
5911 );
5912 WHEN OTHERS THEN
5913
5914 -- SECHAWLA 28-MAY-04 3645574 : close the new cursor
5915 IF l_flatrates_csr%ISOPEN THEN
5916 CLOSE l_flatrates_csr;
5917 END IF;
5918
5919 x_return_status :=OKL_API.HANDLE_EXCEPTIONS
5920 (
5921 l_api_name,
5922 G_PKG_NAME,
5923 'OTHERS',
5924 x_msg_count,
5925 x_msg_data,
5926 '_PVT'
5927 );
5928 END update_depreciation;
5929
5930 END OKL_AM_AMORTIZE_PVT;