DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKL_ACTIVATE_CONTRACT_PUB

Source


1 Package body OKL_ACTIVATE_CONTRACT_PUB AS
2 /* $Header: OKLPACOB.pls 120.32.12020000.5 2013/03/28 10:31:25 bkatraga ship $ */
3 
4 PROCEDURE get_stream_id
5 (
6  p_khr_id  		   	IN okl_k_headers_full_v.id%TYPE,
7  p_stream_type_purpose          IN okl_strm_type_b.STREAM_TYPE_PURPOSE%TYPE,
8  x_return_status		OUT NOCOPY VARCHAR2,
9  x_sty_id 		        OUT NOCOPY okl_strm_type_b.ID%TYPE
10 )
11 IS
12 
13 CURSOR pry_sty_csr IS
14 SELECT ID
15 FROM   OKL_Strm_type_b
16 WHERE stream_type_purpose = p_stream_type_purpose;
17 
18 l_sty_id 			  	NUMBER;
19 
20 BEGIN
21 
22   x_return_status         := Okl_Api.G_RET_STS_SUCCESS;
23 
24     OPEN pry_sty_csr;
25     FETCH pry_sty_csr INTO l_sty_id;
26     IF  pry_sty_csr%NOTFOUND THEN
27             OKL_API.SET_MESSAGE(p_app_name      => g_app_name,
28                                 p_msg_name      => 'OKL_NO_PRY_STY_FOUND',
29                                 p_token1        => 'PURPOSE',
30                                 p_token1_value  => p_stream_type_purpose);
31             RAISE Okl_Api.G_EXCEPTION_ERROR;
32      END IF;
33      CLOSE pry_sty_csr;
34 
35   x_sty_id := l_sty_id;
36 
37   EXCEPTION
38   WHEN Okl_Api.G_EXCEPTION_ERROR THEN
39      IF pry_sty_csr%ISOPEN THEN
40 	    CLOSE pry_sty_csr;
41 	 END IF;
42      x_return_status := Okl_Api.G_RET_STS_ERROR ;
43 
44   WHEN Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR THEN
45      IF pry_sty_csr%ISOPEN THEN
46 	    CLOSE pry_sty_csr;
47 	 END IF;
48      x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
49 
50   WHEN OTHERS THEN
51      IF pry_sty_csr%ISOPEN THEN
52 	    CLOSE pry_sty_csr;
53 	 END IF;
54      x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
55       --DBMS_OUTPUT.PUT_LINE(SQLERRM);
56 
57 END get_stream_id;
58 
59 --------------------------------------------------------------------------------
60 --Bug # 3310972
61 --Api Name     : Is_Rebook_Supported
62 --Description  : Local procedure will determine whether there is a change
63 --               in asset add-ons or adjustments during rebook. These changes
64 --               are not supported.
65 --Notes        :
66 --               IN Parameters -
67 --      IN Parameters -
68 --                     p_rbk_chr_id    - contract id of rebook copy contract
69 --                     p_orig_chr_id   - contract id of original contract
70 --      OUT Parameter  x_return_status - will return OKL_API.G_RET_STS_SUCCESS or
71 --                                       OKL_API.G_RET_STS_ERROR
72 --
73 --      03-Jul-2009 rpillay   Bug# 8652738: Modified API to only validate
74 --                            if an add-on has been deleted during rebook.
75 --                            Addition and Update of Add-on and Update of
76 --                            Trade-in and Down Payments are now supported by
77 --                            rebook
78 --End of Comments
79 --------------------------------------------------------------------------------
80   Procedure Is_Rebook_Supported (p_rbk_chr_id    IN NUMBER,
81                                  p_orig_chr_id   IN NUMBER,
82                                  x_return_status OUT NOCOPY VARCHAR2) is
83 
84   l_return_status   varchar2(1) default OKL_API.G_RET_STS_SUCCESS;
85 
86   l_asset_number okc_k_lines_tl.name%TYPE default NULL;
87 
88   ------------------------------------------------------
89   --Cursor to determine if an addon has been deleted
90   --during rebook
91   ------------------------------------------------------
92   Cursor l_deleted_addon_csr (p_rbk_chr_id in NUMBER,
93                               p_orig_chr_id in NUMBER) is
94   select clet.name
95   from   okc_line_styles_b   addon_lseb,
96          okc_k_lines_b       addon_cleb,
97          okc_line_styles_b   model_lseb,
98          okc_k_lines_b       model_cleb,
99          okc_k_lines_tl      clet,
100          okc_line_styles_b   lseb,
101          okc_k_lines_b       cleb
102   where
103   addon_cleb.cle_id            = model_cleb.id
104   and    addon_cleb.dnz_chr_id = model_cleb.dnz_chr_id
105   and    addon_lseb.id         = addon_cleb.lse_id
106   and    addon_lseb.lty_code   = 'ADD_ITEM'
107   --
108   and    model_cleb.cle_id     = cleb.id
109   and    model_cleb.dnz_chr_id = cleb.dnz_chr_id
110   and    model_lseb.id         = model_cleb.lse_id
111   and    model_lseb.lty_code   = 'ITEM'
112   --
113   and    clet.id               = cleb.id
114   and    clet.language         = userenv('LANG')
115   and    cleb.chr_id           = p_orig_chr_id --orig contract
116   and    cleb.dnz_chr_id       = p_orig_chr_id --orig contract
117   and    lseb.id               = cleb.lse_id
118   and    lseb.lty_code         = 'FREE_FORM1'
119   and    not exists (select '1'
120                  from   okc_k_lines_b addon_cleb2,
121                         okc_k_lines_b model_cleb2,
122                         okc_k_lines_b cleb2
123                  where  nvl(addon_cleb2.orig_system_id1,-999)       = addon_cleb.id
124                  and    nvl(model_cleb2.orig_system_id1,-999)       = model_cleb.id
125                  --and    nvl(cleb2.orig_system_id1,-999)             = cleb2.id
126                  and    nvl(cleb2.orig_system_id1,-999)             = cleb.id
127                  and    addon_cleb2.cle_id                          = model_cleb2.id
128                  and    addon_cleb2.dnz_chr_id                      = model_cleb2.dnz_chr_id
129                  and    model_cleb2.cle_id                          = cleb2.id
130                  and    model_cleb2.dnz_chr_id                      = cleb2.dnz_chr_id
131                  and    cleb2.chr_id                                = p_rbk_chr_id --rebook copy
132                  and    cleb2.dnz_chr_id                            = p_rbk_chr_id --rebook copy
133                  --to avoid picking up new asset added during rebook
134                  and    cleb2.orig_system_id1 is not null);
135 
136   l_unsupported_rebook_modfn EXCEPTION;
137 
138   begin
139       x_return_status := OKL_API.G_RET_STS_SUCCESS;
140 
141       l_asset_number  := NULL;
142 
143       --4.0 check if new addon has been deleted
144       open l_deleted_Addon_csr(p_rbk_chr_id => p_rbk_chr_id,
145                              p_orig_chr_id => p_orig_chr_id);
146       Fetch l_deleted_Addon_csr into l_asset_number;
147       If l_deleted_addon_csr%NOTFOUND then
148           NULL;
149       End If;
150       Close l_deleted_Addon_csr;
151 
152       If nvl(l_asset_number,OKL_API.G_MISS_CHAR) <> OKL_API.G_MISS_CHAR then
153          OKL_API.set_message(
154                            p_app_name     => G_APP_NAME,
155                            p_msg_name     => 'OKL_REBOOK_UNSUPPORTED_MODFN'
156                           );
157          raise l_unsupported_rebook_modfn;
158       End If;
159 
160       EXCEPTION
161       When l_unsupported_rebook_modfn then
162          If l_deleted_addon_csr%ISOPEN then
163               close l_deleted_addon_csr;
164           End If;
165           x_return_status := OKL_API.G_RET_STS_ERROR;
166       When OTHERS then
167          If l_deleted_addon_csr%ISOPEN then
168               close l_deleted_addon_csr;
169           End If;
170           x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
171 
172   End Is_Rebook_Supported;
173 --Bug# 3310972
174 --------------------------------------------------------------------------------
175 --Bug # 2953906
176 --Api Name     : Validate_Bill_To
177 --Description  : Local procedure to validate bill to addresses on the contract
178 --               Will be called for normal booking.Will not be called for
179 --               rebooks and releases
180 --Notes        :
181 --               IN Parameters -
182 --      IN Parameters -
183 --                     p_chr_id    - contract id
184 --      OUT Parameter  x_return_status - return status
185 --End of Comments
186 --------------------------------------------------------------------------------
187 Procedure Validate_bill_To(p_chr_id IN Number,
188                            x_return_status OUT NOCOPY  VARCHAR2) is
189 l_return_status varchar2(1) default OKL_API.G_RET_STS_SUCCESS;
190 
191 --cursor to fetch rule values for customer account and bill to at
192 --contract level and contract line level
193 
194 --Bug# 3124577 :new cursors for rule migration
195 --cursor to fetch contract header level BTO and CAN
196 cursor l_chrb_csr(chrId IN NUMBER) is
197 Select chrb.bill_to_site_use_id,
198        chrb.cust_acct_id
199 from   okc_k_headers_b chrb
200 where  id = ChrId;
201 
202 --cursor to fetch contract line level BTO and CAN
203 cursor l_cleb_csr (chrId In Number) is
204 Select cleb.bill_to_site_use_id
205 from   okc_k_lines_b cleb
206 where  cleb.dnz_chr_id = ChrId
207 and    cleb.sts_code <> 'ABANDONED'
208 and    cleb.bill_to_site_use_id is not null;
209 
210 --cursor to fetch vendor billing setup BTO and CAN
211 cursor l_cplb_csr (ChrId In Number) is
212 Select cplb.bill_to_site_use_id,
213        cplb.cust_acct_id
214 from   okc_k_party_roles_b cplb
215 where  cplb.chr_id = ChrId
216 and    cplb.dnz_chr_id = ChrId
217 and    (cplb.bill_to_site_use_id is NOT NULL
218         OR
219         cplb.cust_acct_id is NOT NULL);
220 
221 l_bto_id      okc_rules_b.object1_id1%TYPE;
222 l_custacct_id okc_rules_b.object1_id1%TYPE;
223 
224 
225 --Local function to determine whether BTO is active
226 Function is_bto_active(p_bto_id      IN Varchar2,
227                        p_custacct_id IN Varchar2) return Varchar2 is
228 l_return_status varchar2(1) default OKL_API.G_RET_STS_SUCCESS;
229 
230 --cursor to find BTO status
231 Cursor l_bto_sts_csr(btoid      IN NUMBER,
232                      custacctid IN NUMBER) is
233 select 'A'
234 from   okx_cust_site_uses_v site_use,
235        hz_cust_acct_sites_all site
236 where  site_use.id1                   = btoid
237 and    site_use.site_use_code         = 'BILL_TO'
238 and    site_use.b_status              = 'A'
239 --and    site_use.cust_acct_site_status = 'A'
240 and    site.cust_acct_site_id = site_use.cust_acct_site_id
241 and    site.status = 'A'
242 and    site_use.cust_account_id       = custacctid;
243 
244 l_bto_id         NUMBER;
245 l_custacct_id    NUMBER;
246 l_bto_status     VARCHAR2(1) default 'I';
247 
248 
249 Begin
250 ----
251     l_return_status := OKL_API.G_RET_STS_SUCCESS;
252     l_bto_status    := 'I'; -- inactive
253 
254     l_bto_id      := to_number(p_bto_id);
255     l_custacct_id := to_number(p_custacct_id);
256 
257     open l_bto_sts_csr(btoid      => l_bto_id,
258                        custacctid => l_custacct_id);
259     fetch l_bto_sts_csr into l_bto_status;
260     If l_bto_sts_csr%NOTFOUND then
261         null;
262     End If;
263     close l_bto_sts_csr;
264 
265     if l_bto_status = 'I' then
266        l_return_status := OKL_API.G_RET_STS_ERROR;
267     end if;
268     Return(l_return_status);
269 
270     exception
271     when others then
272         if l_bto_sts_csr%ISOPEN then
273             close l_bto_sts_csr;
274         end if;
275         l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
276         return(l_return_status);
277 end is_bto_active;
278 
279 Begin
280 -----
281     l_return_status := OKL_API.G_RET_STS_SUCCESS;
282 
283     --fetch contract customer account at contract header level
284     open l_chrb_csr(ChrId => p_chr_id);
285     Fetch l_chrb_csr into l_bto_id,l_custacct_id;
286     If l_chrb_csr%NOTFOUND then
287         Null;
288     End If;
289     Close l_chrb_csr;
290 
291     --check if bto is active at contract header level
292     l_return_status := is_bto_active(p_bto_id => l_bto_id,
293                                      p_custacct_id => l_custacct_id);
294     If l_return_status = OKL_API.G_RET_STS_ERROR then
295        --set error message
296         OKL_API.set_message(
297                            p_app_name     => G_APP_NAME,
298                            p_msg_name     => 'OKL_QA_INVALID_BILLTO'
299                           );
300     Elsif l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR then
301         Null;
302     End If;
303 
304 
305     If l_return_status = OKL_API.G_RET_STS_SUCCESS then
306         --fetch bill to at contract line level
307         open l_cleb_csr(ChrId => p_chr_id);
308         Loop
309             Fetch l_cleb_csr into l_bto_id;
310             Exit when l_cleb_csr%NOTFOUND;
311             --check if bto is active at contract line level
312             l_return_status := is_bto_active(p_bto_id => l_bto_id,
313                                              p_custacct_id => l_custacct_id);
314             If l_return_status = OKL_API.G_RET_STS_ERROR then
315                 --set error message
316                 OKL_API.set_message(
317                                    p_app_name     => G_APP_NAME,
318                                    p_msg_name     => 'OKL_QA_INVALID_BILLTO'
319                                   );
320                 Exit;
321             Elsif l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR then
322                 Exit;
323             End If;
324          End Loop;
325          Close l_cleb_csr;
326     End If;
327 
328 
329     If l_return_status = OKL_API.G_RET_STS_SUCCESS then
330         --fetch bill to  and cust account at vendor billing setup level
331         open l_cplb_csr(ChrId => p_chr_id);
332         Loop
333             Fetch l_cplb_csr into l_bto_id,l_custacct_id;
334             Exit when l_cplb_csr%NOTFOUND;
335             --check if bto is active at vendor billing setup level
336             If l_bto_id is not null and l_custacct_id is not null then
337                 l_return_status := is_bto_active(p_bto_id => l_bto_id,
338                                                  p_custacct_id => l_custacct_id);
339                 If l_return_status = OKL_API.G_RET_STS_ERROR then
340                     --set error message
341                     OKL_API.set_message(
342                                        p_app_name     => G_APP_NAME,
343                                        p_msg_name     => 'OKL_QA_INVALID_BILLTO'
344                                        );
345                     Exit;
346                 Elsif l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR then
347                     Exit;
348                 End If;
349              End If;
350          End Loop;
351          Close l_cplb_csr;
352     End If;
353 
354 
355     x_return_status := l_return_Status;
356     Exception
357     When others then
358          If l_chrb_csr%ISOPEN then
359             close l_chrb_csr;
360          End If;
361          If l_cleb_csr%ISOPEN then
362             close l_cleb_csr;
363          End If;
364          If l_cplb_csr%ISOPEN then
365             close l_cplb_csr;
366          End If;
367 
368          x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
369 ----
370 End Validate_Bill_To;
371 --Bug# 2953906 end
372 
373 --Bug # 3783518
374 --Api Name     : Validate_Rebook_Date
375 --Description  : Local procedure to check that if there is a change
376 --               in Unit Cost during Rebook, then the Revision Date
377 --               should be the same as Contract Start Date.
378 --Notes        :
379 --
380 --      IN Parameters -
381 --                     p_rbk_chr_id    - contract id of rebook copy contract
382 --                     p_orig_chr_id   - contract id of original contract
383 --      OUT Parameter  x_return_status - will return OKL_API.G_RET_STS_SUCCESS or
384 --                                       OKL_API.G_RET_STS_ERROR
385 --End of Comments
386 --------------------------------------------------------------------------------
387   PROCEDURE  Validate_Rebook_Date
388                  (p_api_version   IN  NUMBER,
389                   p_init_msg_list IN  VARCHAR2,
390                   x_return_status OUT NOCOPY VARCHAR2,
391                   x_msg_count     OUT NOCOPY NUMBER,
392                   x_msg_data      OUT NOCOPY VARCHAR2,
393                   p_rbk_chr_id    IN  NUMBER,
394                   p_orig_chr_id   IN  NUMBER,
395                   p_rebook_date   IN  DATE) IS
396 
397   l_return_status     VARCHAR2(1) := OKL_API.G_RET_STS_SUCCESS;
398   l_api_name          CONSTANT VARCHAR2(30) := 'Validate_Rebook_Date';
399   l_api_version	    CONSTANT NUMBER	:= 1.0;
400 
401   CURSOR chr_csr(p_chr_id NUMBER) IS
402   select start_date
403   from okc_k_headers_b
404   where id = p_chr_id;
405 
406   CURSOR cle_csr(p_rbk_chr_id    NUMBER,
407                  p_orig_chr_id   NUMBER,
408                  p_item_lty_code VARCHAR2) IS
409   select rbk_cle.price_unit    rbk_price_unit,
410          orig_cle.price_unit   orig_price_unit
411   from   okc_k_lines_b      rbk_cle,
412          okc_line_styles_b  rbk_lse,
413          okc_k_lines_b      orig_cle
414   where  rbk_cle.dnz_chr_id  = p_rbk_chr_id
415   and    rbk_lse.lty_code    = p_item_lty_code
416   and    rbk_cle.lse_id      = rbk_lse.id
417   and    orig_cle.id         = rbk_cle.orig_system_id1
418   and    orig_cle.dnz_chr_id = p_orig_chr_id;
419 
420   l_cle_rec               cle_csr%rowtype;
421   l_chr_rec               chr_csr%rowtype;
422   l_item_lty_code         okc_line_styles_b.lty_code%type := 'ITEM';
423 BEGIN
424 
425    open chr_csr(p_rbk_chr_id);
426    fetch chr_csr into l_chr_rec;
427    close chr_csr;
428 
429    -- Revision Date should be the same as Contract Start Date inorder to make an
430    -- Unit Cost change
431    if (l_chr_rec.start_date <> p_rebook_date) then
432 
433      open cle_csr(p_rbk_chr_id, p_orig_chr_id,l_item_lty_code);
434      loop
435        fetch cle_csr into l_cle_rec;
436        exit when cle_csr%NOTFOUND;
437 
438        if l_cle_rec.rbk_price_unit <> l_cle_rec.orig_price_unit then
439          close cle_csr;
440          OKL_API.SET_MESSAGE(p_app_name     => g_app_name,
441                              p_msg_name     => 'OKL_LLA_VALIDATE_UNIT_COST_CHG'
442 		   		     );
443          RAISE OKL_API.G_EXCEPTION_ERROR;
444        end if;
445      end loop;
446      close cle_csr;
447    end if;
448 
449 EXCEPTION
450   WHEN Okl_Api.G_EXCEPTION_ERROR THEN
451     x_return_status := OKL_API.G_RET_STS_ERROR;
452   WHEN Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR THEN
453     x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
454   WHEN OTHERS THEN
455     x_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
456 END Validate_Rebook_Date;
457 --Bug# 3783518: end
458 
459 --------------------------------------------------------------------------------
460 --Api Name     : Activate Contract
461 --Description  : Will call the FA Activation and IB Activation public apis
462 --               Will be called from the activate button on the booking screen
463 --Notes        :
464 --               IN Parameters -
465 --      IN Parameters -
466 --                     p_chr_id    - contract id to be activated
467 --                     p_call_mode - 'BOOK' for booking
468 --                                   'REBOOK' for rebooking
469 --                                   'RELEASE' for release
470 --End of Comments
471 --------------------------------------------------------------------------------
472 PROCEDURE ACTIVATE_CONTRACT(p_api_version   IN  NUMBER,
473                             p_init_msg_list IN  VARCHAR2,
474                             x_return_status OUT NOCOPY VARCHAR2,
475                             x_msg_count     OUT NOCOPY NUMBER,
476                             x_msg_data      OUT NOCOPY VARCHAR2,
477                             p_chrv_id       IN  NUMBER,
478                             p_call_mode     IN  VARCHAR2) IS
479 
480 l_return_status        VARCHAR2(1)  DEFAULT Okl_Api.G_RET_STS_SUCCESS;
481 l_api_name             CONSTANT VARCHAR2(30) := 'ACTIVATE_CONTRACT';
482 l_api_version          CONSTANT NUMBER := 1.0;
483 
484 l_cimv_tbl_fa          Okl_Activate_Asset_Pub.cimv_tbl_type;
485 l_cimv_tbl_ib          Okl_Activate_Ib_Pub.cimv_tbl_type;
486 l_tcnv_rec             Okl_Trx_Contracts_Pvt.tcnv_rec_type;
487 l_service_chr_id        Number;
488 
489 l_commit             VARCHAR2(1)   := Okl_Api.G_FALSE;
490 l_transaction_type   VARCHAR2(256) default 'Booking';
491 l_draft_yn           VARCHAR2(1)   := Okl_Api.G_FALSE;
492 
493 --Bug#2835070
494 --cursor to check if the contract is rebooked contract
495 cursor l_chk_rbk_csr(p_chr_id IN NUMBER) is
496 SELECT '!',chr.orig_system_id1, ktrx.date_transaction_occurred,ktrx.id
497 FROM   okc_k_headers_b CHR,
498        okl_trx_contracts ktrx
499 WHERE  ktrx.khr_id_new = chr.id
500 AND    ktrx.tsu_code = 'ENTERED'
501 AND    ktrx.rbr_code is NOT NULL
502 AND    ktrx.tcn_type = 'TRBK'
503 AND    CHR.id = p_chr_id
504 AND    CHR.ORIG_SYSTEM_SOURCE_CODE = 'OKL_REBOOK'
505 AND    ktrx.representation_type = 'PRIMARY'; -- MGAAP 7263041
506 
507 l_rbk_khr      VARCHAR2(1) DEFAULT '?';
508 l_orig_khr_id  okc_k_headers_b.orig_system_id1%Type;
509 l_rebook_date  OKL_TRX_CONTRACTS.date_transaction_occurred%TYPE;
510 l_transaction_id okl_trx_contracts.id%TYPE;
511 --4542290 start
512 l_trx_date  OKL_TRX_CONTRACTS.date_transaction_occurred%TYPE;
513 l_pdt_parameter_rec OKL_SETUPPRODUCTS_PUB.pdt_parameters_rec_type;
514 l_max_bill_date DATE;
515 l_sty_id NUMBER;
516 l_accrual_date  OKL_TRX_CONTRACTS.date_transaction_occurred%TYPE;
517 l_stream_name VARCHAR2(30);
518 --4542290 end
519 
520 --Bug#3156924 : Cursor modified to fetch transaction date
521 --cursor to check if the contract is selected for Mass Rebook
522 CURSOR  l_chk_mass_rbk_csr (p_chr_id IN NUMBER) IS
523 SELECT '!', ktrx.date_transaction_occurred,
524        --Bug# 4212626
525        ktrx.id,
526        source_trx_id -- 4542290
527 FROM   okc_k_headers_b CHR,
528        okl_trx_contracts ktrx
529 where  CHR.ID          = p_chr_id
530 AND    ktrx.KHR_ID     =  chr.id
531 AND    ktrx.tsu_code   = 'ENTERED'
532 AND    ktrx.rbr_code   IS NOT NULL
533 AND    ktrx.tcn_type   = 'TRBK'
534 AND    ktrx.representation_type = 'PRIMARY'  -- MGAAP 7263041
535 /*------------------------------------------------
536 --AND    EXISTS (SELECT '1'
537 --               FROM   okl_trx_contracts ktrx
538 --               WHERE  ktrx.KHR_ID     = chr.id
539 --               AND    ktrx.tsu_code   = 'ENTERED'
540 --               AND    ktrx.rbr_code IS NOT NULL
541 --               AND    ktrx.tcn_type = 'TRBK')
542 ------------------------------------------------*/
543 AND   EXISTS (SELECT '1'
544               FROM   okl_rbk_selected_contract rbk_khr
545               WHERE  rbk_khr.KHR_ID = chr.id
546               AND    rbk_khr.STATUS <> 'PROCESSED'); --check with debdip
547 
548 l_mass_rbk_khr  VARCHAR2(1) DEFAULT '?';
549 --Bug# 3156924
550 l_mass_rbk_date OKL_TRX_CONTRACTS.date_transaction_occurred%TYPE;
551 --Bug# 4212626
552 l_mass_rbk_trx_id OKL_TRX_CONTRACTS.id%TYPE;
553 --4542290
554 l_source_trx_id   OKL_TRX_CONTRACTS.ID%TYPE;
555 
556 CURSOR l_source_trx_type_csr(p_trx_id NUMBER) IS
557 SELECT TCN_TYPE
558 FROM   OKL_TRX_CONTRACTS
559 WHERE  ID = p_trx_id;
560 
561 l_source_trx_type OKL_TRX_CONTRACTS.TCN_TYPE%TYPE;
562 --4542290
563 --cursor to check if usage line exists on the contract
564 CURSOR l_chk_usage_csr (p_chr_id IN Number) IS
565 SELECT '!'
566 FROM   okc_k_headers_b CHR
567 WHERE  chr.ID = p_chr_id
568 AND    exists (SELECT '1'
569               FROM
570                      OKC_LINE_STYLES_B lse,
571                      OKC_K_LINES_B     cle
572               WHERE  cle.sts_code = 'APPROVED'
573               AND    lse.id = cle.lse_id
574               AND    lse.lty_code = 'USAGE'
575               AND    cle.dnz_chr_id = chr.id);
576 
577 l_usage_khr   VARCHAR2(1) DEFAULT '?';
578 
579 --cursor to check if contract is a re-lease contract
580 CURSOR l_chk_rel_khr_csr (p_chr_id IN Number) IS
581 SELECT '!'
582 FROM   okc_k_headers_b CHR
583 where  chr.ID = p_chr_id
584 AND    nvl(chr.orig_system_source_code,'XXXX') = 'OKL_RELEASE';
585 
586 l_rel_khr    VARCHAR2(1) DEFAULT '?';
587 
588 --cursor to check if contract has re-lease assets
589 CURSOR l_chk_rel_ast_csr (p_chr_id IN Number) IS
590 SELECT '!'
591 FROM   okc_k_headers_b CHR
592 WHERE   nvl(chr.orig_system_source_code,'XXXX') <> 'OKL_RELEASE'
593 and     chr.ID = p_chr_id
594 /*AND     exists (SELECT '1'
595                FROM   OKC_RULES_B rul
596                WHERE  rul.dnz_chr_id = chr.id
597                AND    rul.rule_information_category = 'LARLES'
598                AND    nvl(rule_information1,'N') = 'Y');*/
599 -- Bug# 15992711 Start of Modifications
600 AND  not   exists ( SELECT '1'
601                 FROM okl_k_lines kle
602                ,okc_k_lines_b cleb
603                 WHERE cleb.dnz_chr_id = chr.id
604                 AND cleb.chr_id = chr.id
605                 AND cleb.id = kle.id
606                 AND cleb.lse_id = 33
607                 AND cleb.sts_code <> 'ABANDONED'
608                 AND nvl(kle.re_lease_yn,'N') = 'N');
609 -- Bug# 15992711 End of Modifications
610 l_rel_ast     VARCHAR2(1) DEFAULT '?';
611 
612 -- Bug# 15992711 Start of Modifications
613 --cursor to check if contract is a mixed contract
614 CURSOR l_chk_mxd_ast_csr (p_chr_id IN Number) IS
615 SELECT '!'
616 FROM   okc_k_headers_b CHR
617 WHERE   nvl(chr.orig_system_source_code,'XXXX') <> 'OKL_RELEASE'
618 and     chr.ID = p_chr_id
619 AND     exists ( SELECT '1'
620                 FROM okl_k_lines kle
621                ,okc_k_lines_b cleb
622                 WHERE cleb.dnz_chr_id = chr.id
623                 AND cleb.chr_id = chr.id
624                 AND cleb.id = kle.id
625                 AND cleb.lse_id = 33
626                 AND cleb.sts_code <> 'ABANDONED'
627                 AND nvl(kle.re_lease_yn,'N') = 'Y')
628 AND    exists  ( SELECT '1'
629                 FROM okl_k_lines kle
630                ,okc_k_lines_b cleb
631                 WHERE cleb.dnz_chr_id = chr.id
632                 AND cleb.chr_id = chr.id
633                 AND cleb.id = kle.id
634                 AND cleb.lse_id = 33
635                 AND cleb.sts_code <> 'ABANDONED'
636                 AND nvl(kle.re_lease_yn,'N') = 'N');
637 l_mxd_ast     VARCHAR2(1) DEFAULT '?';
638 
639 l_rulv_rec   OKL_RULE_PUB.rulv_rec_type;
640 lx_rulv_rec  OKL_RULE_PUB.rulv_rec_type;
641 
642 --Cursor to check for the rule group LARLES
643 CURSOR l_rule_info_csr ( p_chr_id IN NUMBER) IS
644 SELECT rul.id
645       ,rul.rule_information1
646                FROM   OKC_RULES_B rul
647                WHERE  rul.dnz_chr_id = p_chr_id
648                AND    rul.rule_information_category = 'LARLES';
649 l_rul_info    NUMBER;
650 l_rul_info1   VARCHAR2(30);
651 -- Bug# 15992711 End of Modifications
652 
653 
654 --Bug#2522439 Start
655 --Cursorr to find out asset return record for re-lease
656 Cursor l_asr_csr(p_rel_chr_id IN NUMBER) IS
657 SELECT cle.cle_id        finasst_id,
658        cim.object1_id1   asset_id,
659        cle_orig.cle_id   orig_finasst_id,
660        asr.id            asset_return_id
661 FROM   OKL_ASSET_RETURNS_B asr,
662        OKC_K_LINES_B     cle_orig,
663        OKC_LINE_STYLES_B lse_orig,
664        OKC_K_ITEMS       cim_orig,
665        OKC_K_ITEMS       cim,
666        OKC_K_LINES_B     cle,
667        OKC_LINE_STYLES_B lse,
668        OKC_STATUSES_B    sts,
669        OKL_TXL_ASSETS_B  txl
670 WHERE  asr.kle_id            = cle_orig.cle_id
671 AND    asr.ars_code          = 'RE_LEASE'
672 AND    cim.object1_id1       = cim_orig.object1_id1
673 AND    cim.object1_id2       = cim_orig.object1_id2
674 AND    cim.jtot_object1_code = cim_orig.jtot_object1_code
675 AND    cim.id                <> cim_orig.id
676 AND    cle_orig.id           = cim_orig.cle_id
677 AND    cle_orig.dnz_chr_id   = cim_orig.dnz_chr_id
678 AND    cle_orig.lse_id       = lse_orig.id
679 AND    lse_orig.lty_code     = 'FIXED_ASSET'
680 AND    cim.cle_id            = cle.id
681 AND    cim.dnz_chr_id        = cle.dnz_chr_id
682 AND    cle.id                = txl.kle_id
683 AND    cle.dnz_chr_id        = p_rel_chr_id
684 AND    cle.lse_id            = lse.id
685 AND    lse.lty_code          = 'FIXED_ASSET'
686 AND    cle.sts_code          = sts.code
687 AND    sts.ste_code not in ('HOLD','EXPIRED','TERMINATED','CANCELLED');
688 /*
689 -- smereddy,04/13/2006,Bug#4291242
690 -- Commented as part of bug fix
691 AND    exists
692                   (select  trx.tas_type,
693                            ttyp.name
694                   from    OKL_TRX_ASSETS    trx,
695                           OKL_TRX_TYPES_TL  ttyp
696                   where   trx.id        = txl.tas_id
697                   and     trx.try_id    = ttyp.id
698                   and     ttyp.name     = 'Internal Asset Creation'
699                   and     ttyp.language = 'US'
700                   and     trx.tsu_code  <>  'PROCESSED'
701                   --Bug# 3533936
702                   and     trx.tas_type   = 'CRL')
703 AND    txl.tal_type = 'CRL';
704 -- end,smereddy,04/13/2006,Bug#4291242
705 */
706 l_asr_rec l_asr_csr%ROWTYPE;
707 
708 
709 l_artv_rec    okl_asset_returns_pub.artv_rec_type;
710 lx_artv_rec   okl_asset_returns_pub.artv_rec_type;
711 --Bug#2522439 End
712 
713 --Bug#3143522 : Subsidies enhancement
714 
715 l_subsidy_exists varchar2(1) default OKL_API.G_FALSE;
716 
717 -- cursor to find subsidies which have expired (if any)
718 -- sjalasut. modified cursor to remove " and    nvl(subb.effective_to_date,sysdate)+nvl(subb.expire_after_days,0) < sysdate "
719 -- from the cursor to make the cursor re-usable for subsidy pools enhancement, also added subsidy_id column
720 -- the check for expiried subsidy would be done in the code, the else part will fork to the common pool transaction api
721 -- also changed the name of the cursor from l_expired_subsidy_csr as now it retrieves all subsidies
722 
723 cursor l_subsidy_csr(p_chr_id in number) is
724 select nvl(subb.effective_to_date,sysdate) effective_to_date,
725        nvl(subb.expire_after_days,0)       expire_after_days,
726        clet_sub.name                       subsidy_name,
727        clet_asst.name                      asset_number,
728        subb.id                             subsidy_id,               -- added for subsidy pools enhancement
729        kle_sub.amount                      subsidy_amount,           -- added for subsidy pools enhancement
730        kle_sub.subsidy_override_amount     subsidy_override_amount,  -- added for subsidy pools enhancement
731        cleb_asst.start_date                asset_start_date,         -- added for subsidy pools enhancement
732        cleb_asst.id                        asset_id                  -- added for subsidy pools enhancement
733        ,subb.effective_from_date           effective_from_date       -- added : Bug 6050165 : prasjain
734 from   okl_subsidies_b   subb,
735        okl_k_lines       kle_sub,
736        okc_k_lines_tl    clet_sub,
737        okc_k_lines_b     cleb_sub,
738        okc_line_styles_b lseb_sub,
739        okc_k_lines_tl    clet_asst,
740        okc_k_lines_b     cleb_asst,
741        okc_line_styles_b lseb_asst
742 where  subb.id              = kle_sub.subsidy_id
743 --and    nvl(subb.effective_to_date,sysdate)+nvl(subb.expire_after_days,0) < sysdate
744 and    kle_sub.id           = cleb_sub.id
745 and    clet_sub.id          = cleb_sub.id
746 and    clet_sub.language    = userenv('LANG')
747 and    cleb_sub.cle_id      = cleb_asst.id
748 and    cleb_sub.dnz_chr_id  = cleb_asst.dnz_chr_id
749 and    cleb_sub.sts_code   <> 'ABANDONED'
750 and    lseb_sub.id          = cleb_sub.lse_id
751 and    lseb_sub.lty_code    = 'SUBSIDY'
752 and    clet_asst.id         = cleb_asst.id
753 and    clet_asst.language   = userenv('LANG')
754 and    cleb_asst.chr_id     = p_chr_id
755 and    cleb_asst.dnz_chr_id = p_chr_id
756 and    lseb_asst.id         = cleb_asst.lse_id
757 and    lseb_asst.lty_code   = 'FREE_FORM1'
758 and    cleb_asst.sts_code   <> 'ABANDONED';
759 
760 l_subsidy_rec    l_subsidy_csr%ROWTYPE;
761 l_subsidy_valid_status   varchar2(1) default OKL_API.G_RET_STS_SUCCESS;
762 
763     -- Start : Bug 6050165 : prasjain
764     --cursor to check subsidy applicability at line dates
765       cursor l_cle_csr (p_subsidy_id in number,
766                         p_asset_cle_id in number) is
767       Select 'Y'
768       from   okl_subsidies_b sub,
769              okc_k_lines_b   cleb
770       where  sub.id                = p_subsidy_id
771       and    cleb.id               = p_asset_cle_id
772       and    TRUNC(cleb.start_date) between TRUNC(sub.effective_from_date)
773                              and TRUNC(nvl(sub.effective_to_date,cleb.start_date));
774       l_applicable     varchar2(1);
775     -- End : Bug 6050165 : prasjain
776 
777 --Bug#3143522 : 11.5.10 Subsidy enhancement
778 
779 --BUG# 3397688 : get valid GL date for Accrual reversals during rebooks
780 l_gl_date    date;
781 
782 -- Bug# 3541098
783 -- cursor to get capitalize interest flag
784 Cursor cap_interest_rul_csr (pchrid number) is
785 Select rul.rule_information1 capitalize_interest_flag
786 From   okc_rules_b rul
787 where  rul.dnz_chr_id = pchrid
788 and    rul.rule_information_category = 'LACPLN';
789 
790 Cursor chr_csr (pchrid number) is
791 Select contract_number
792       ,start_date
793 From   okc_k_headers_b chr
794 where  chr.id = pchrid;
795 
796 --4542290
797 CURSOR max_bill_date_csr(p_stm_id IN NUMBER) IS
798 SELECT MAX(sel.stream_element_date) stream_element_date
799 FROM okl_strm_elements sel
800 WHERE sel.stm_id = p_stm_id
801 AND   sel.date_billed IS NOT NULL;
802 
803 l_capitalize_interest_flag  okc_rules_b.rule_information1%TYPE;
804 l_amount          number;
805 l_source_id       number;
806 l_contract_number okc_k_headers_b.contract_number%type;
807 l_start_date      okc_k_headers_b.start_date%type;
808 -- Bug# 3541098 end
809 
810 l_ignore_flag     VARCHAR2(1);
811 
812 -- sjalasut: added local variables for subsidy pools enhancement. START
813 lx_sub_pool_id okl_subsidy_pools_b.id%TYPE;
814 lx_sub_pool_curr_code okl_subsidy_pools_b.currency_code%TYPE;
815 l_sub_pool_applicable VARCHAR2(10);
816 lv_subsidy_amount okl_k_lines.amount%TYPE;
817 l_debug_enabled VARCHAR2(10);
818 l_module CONSTANT fnd_log_messages.module%TYPE := 'okl.plsql.OKL_ACTIVATE_CONTRACT_PUB.ACTIVATE_CONTRACT';
819 is_debug_statement_on BOOLEAN;
820 -- sjalasut: added local variables for subsidy pools enhancement. END
821 
822   -- dedey, Bug#4264314
823   lx_trx_number OKL_TRX_CONTRACTS.trx_number%TYPE := null; -- MGAAP 7263041
824   l_accrual_rec OKL_GENERATE_ACCRUALS_PVT.adjust_accrual_rec_type;
825   l_stream_tbl  OKL_GENERATE_ACCRUALS_PVT.stream_tbl_type;
826   -- dedey, Bug#4264314
827 
828   -- racheruv: added update of okl_stream_trx_date.last_trx_state flag.
829   l_contract_id     number;
830 
831   --Bug# 9191475
832   lx_trxnum_tbl OKL_GENERATE_ACCRUALS_PVT.trxnum_tbl_type;
833 
834 
835   --ndani - 14-Mar-2013, Start - Rebook accounting fix
836   --Bug# 16511024 : Accounting Booking : Booking to make two accounting calls
837   --                'Booking' and 'Release' while booking a contract
838 
839   --    cursor : to check whether Contract is having mixed asset or not
840   CURSOR l_chk_con_csr (chrid NUMBER) IS
841   SELECT COUNT (*)
842   FROM  (SELECT COUNT(*)
843          FROM  okc_k_lines_b   cleb,
844                okl_k_lines     kle
845          WHERE kle.id           = cleb.id
846          AND   cleb.chr_id      = chrid
847          --ndani - 27-Mar-2013 - Bug# 16552978 - Start
848          AND   cleb.dnz_chr_id  = chrid
849          AND   cleb.lse_id      = 33
850          AND   cleb.sts_code    <> 'ABANDONED'
851          --ndani - 27-Mar-2013 - Bug# 16552978 - End
852          GROUP BY NVL(kle.re_lease_yn,'N')
853         );
854 
855   --    cursor : to check whether Contract is having re-lease assets
856   CURSOR l_con_rel_csr (chrid NUMBER) IS
857   SELECT DISTINCT NVL(kle.re_lease_yn,'N')
858   FROM   okc_k_lines_b   cleb,
859          okl_k_lines     kle
860   WHERE kle.id           = cleb.id
861   AND   cleb.chr_id      = chrid
862   --ndani - 27-Mar-2013 - Bug# 16552978 - Start
863   AND   cleb.dnz_chr_id  = chrid
864   AND   cleb.lse_id      = 33
865   AND   cleb.sts_code    <> 'ABANDONED';
866   --ndani - 27-Mar-2013 - Bug# 16552978 - End
867 
868   l_chk_contract_count     NUMBER := 0;
869   l_con_rel_flag           okl_k_lines.re_lease_yn%TYPE;
870   l_acct_trans_type        VARCHAR2 (256);
871   l_acc_call_rel_flag      VARCHAR2 (1) := 'N';
872 
873   --Bug# 16511024 , End
874   --ndani - 14-Mar-2013, End - Rebook accounting fix
875 
876 BEGIN
877      x_return_status := Okl_Api.G_RET_STS_SUCCESS;
878     -- Call start_activity to create savepoint, check compatibility
879     -- and initialize message list
880     l_return_status := Okl_Api.START_ACTIVITY(
881 			p_api_name      => l_api_name,
882 			p_pkg_name      => g_pkg_name,
883 			p_init_msg_list => p_init_msg_list,
884 			l_api_version   => l_api_version,
885 			p_api_version   => p_api_version,
886 			p_api_type      => '_PUB',
887 			x_return_status => x_return_status);
888     -- Check if activity started successfully
889     IF (x_return_status = Okc_Api.G_RET_STS_UNEXP_ERROR) THEN
890        RAISE Okc_Api.G_EXCEPTION_UNEXPECTED_ERROR;
891     ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
892        RAISE Okc_Api.G_EXCEPTION_ERROR;
893     END IF;
894 
895     okl_debug_pub.logmessage('In Activate_contract: p_chrv_id =' || p_chrv_id);
896     okl_debug_pub.logmessage('p_call_mode =' || p_call_mode);
897     -- check if debug is enabled
898     l_debug_enabled := okl_debug_pub.check_log_enabled;
899     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
900 
901     --check for mass rebook contract
902     l_mass_rbk_khr := '?';
903     OPEN l_chk_mass_rbk_csr (p_chr_id => p_chrv_id);
904     --bug# 3156924
905     --FETCH l_chk_mass_rbk_csr INTO l_mass_rbk_khr;
906     --Bug# 4212626
907     FETCH l_chk_mass_rbk_csr INTO
908           l_mass_rbk_khr, l_mass_rbk_date, l_mass_rbk_trx_id, l_source_trx_id;
909           -- 4542290
910     IF l_chk_mass_rbk_csr%NOTFOUND THEN
911        NULL;
912     END IF;
913     CLOSE l_chk_mass_rbk_csr;
914 
915     --check for rebook contract
916     l_rbk_khr := '?';
917     l_orig_khr_id := null;
918     l_transaction_id := null;
919     OPEN l_chk_rbk_csr (p_chr_id => p_chrv_id);
920     FETCH l_chk_rbk_csr INTO l_rbk_khr,l_orig_khr_id,l_rebook_date,l_transaction_id;
921     IF l_chk_rbk_csr%NOTFOUND THEN
922        NULL;
923     END IF;
924     CLOSE l_chk_rbk_csr;
925 
926     l_rel_khr := '?';
927     --check for relese contract
928     OPEN l_chk_rel_khr_csr (p_chr_id => p_chrv_id);
929     FETCH l_chk_rel_khr_csr INTO l_rel_khr;
930     IF l_chk_rel_khr_csr%NOTFOUND THEN
931        NULL;
932     END IF;
933     CLOSE l_chk_rel_khr_csr;
934 
935     l_rel_ast := '?';
936     --check for relese assets in a contract
937     OPEN l_chk_rel_ast_csr (p_chr_id => p_chrv_id);
938     FETCH l_chk_rel_ast_csr INTO l_rel_ast;
939     IF l_chk_rel_ast_csr%NOTFOUND THEN
940        NULL;
941     END IF;
942     CLOSE l_chk_rel_ast_csr;
943 
944     --Bug# 15992711 Start of Modifications
945     --check for rule group LARLES
946     OPEN l_rule_info_csr (p_chr_id => p_chrv_id);
947     FETCH l_rule_info_csr INTO l_rul_info,l_rul_info1;
948     IF l_rule_info_csr%NOTFOUND THEN
949        NULL;
950     END IF;
951     CLOSE l_rule_info_csr;
952 
953     l_mxd_ast := '?';
954     --check for a mixed contract
955     OPEN l_chk_mxd_ast_csr (p_chr_id => p_chrv_id);
956     FETCH l_chk_mxd_ast_csr INTO l_mxd_ast;
957     IF l_chk_mxd_ast_csr%NOTFOUND THEN
958        NULL;
959     END IF;
960     CLOSE l_chk_mxd_ast_csr;
961     --Bug# 15992711 End of Modifications
962 
963     IF l_mass_rbk_khr = '!' THEN
964         --do mass rebook processing
965         --bug# 3156924 :
966         IF nvl(l_mass_rbk_date,OKL_API.G_MISS_DATE) = OKL_API.G_MISS_DATE then
967             l_mass_rbk_date := sysdate;
968         End IF;
969         --Bug# 3156924
970 
971          -- Start : Bug 6050165 : prasjain
972           l_subsidy_exists := OKL_API.G_FALSE;
973           okl_subsidy_process_pvt.is_contract_subsidized
974                             (p_api_version   => p_api_version,
975                             p_init_msg_list => p_init_msg_list,
976                             x_return_status => x_return_status,
977                             x_msg_count     => x_msg_count,
978                             x_msg_data      => x_msg_data,
979                             p_chr_id        => p_chrv_id,
980                             x_subsidized    => l_subsidy_exists);
981           IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
982                   RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
983           ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
984                   RAISE Okl_Api.G_EXCEPTION_ERROR;
985           END IF;
986 
987          IF l_subsidy_exists = OKL_API.G_TRUE THEN
988             l_subsidy_valid_status  := OKL_API.G_RET_STS_SUCCESS;
989             OPEN l_subsidy_csr (p_chr_id => p_chrv_id);
990             LOOP
991                 FETCH l_subsidy_csr INTO l_subsidy_rec;
992                 EXIT WHEN l_subsidy_csr%NOTFOUND;
993                 l_applicable := 'N';
994                   open l_cle_csr(p_subsidy_id   => l_subsidy_rec.subsidy_id,
995                                p_asset_cle_id => l_subsidy_rec.asset_id);
996                   Fetch l_cle_csr into l_applicable;
997                   If l_cle_csr%NOTFOUND then
998                       Null;
999                   End If;
1000                   close l_cle_csr;
1001 
1002                   If (l_applicable = 'N') then
1003                       Okl_Api.set_message(
1004                               p_app_name     => G_APP_NAME,
1005                               p_msg_name     => 'OKL_SUBSIDY_CRITERIA_MATCH',
1006                               p_token1       => 'SUBSIDY_NAME',
1007                               p_token1_value => l_subsidy_rec.subsidy_name,
1008                               p_token2       => 'ASSET_NUMBER',
1009                               p_token2_value => l_subsidy_rec.asset_number);
1010                       l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
1011                  end if;
1012                end loop;
1013                IF (l_subsidy_valid_status = Okl_Api.G_RET_STS_ERROR) THEN
1014                  RAISE Okl_Api.G_EXCEPTION_ERROR;
1015                end if;
1016            end if;
1017      -- End : Bug 6050165 : prasjain
1018 
1019         -- 4542290
1020         OPEN l_source_trx_type_csr(l_source_trx_id);
1021         FETCH l_source_trx_type_csr
1022         INTO  l_source_trx_type;
1023         CLOSE l_source_trx_type_csr;
1024 
1025         --dbms_output.put_line('Gone in for rebook.');
1026         Okl_Activate_Asset_Pvt.MASS_REBOOK_ASSET(p_api_version      => p_api_version,
1027                                                  p_init_msg_list    => p_init_msg_list,
1028                                                  x_return_status    => x_return_status,
1029                                                  x_msg_count        => x_msg_count,
1030                                                  x_msg_data         => x_msg_data,
1031                                                  p_rbk_chr_id       => p_chrv_id);
1032                 --dbms_output.put_line('Gone in for rebook. '||x_return_status);
1033         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1034             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1035         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1036             RAISE Okl_Api.G_EXCEPTION_ERROR;
1037         END IF;
1038 
1039 	 -- dedey, Bug#4264314
1040 	 OKL_CONTRACT_REBOOK_PVT.create_billing_adjustment(
1041 	   p_api_version     => p_api_version,
1042 	   p_init_msg_list   => p_init_msg_list,
1043 	   x_return_status   => x_return_status,
1044 	   x_msg_count       => x_msg_count,
1045 	   x_msg_data        => x_msg_data,
1046 	   p_rbk_khr_id      => p_chrv_id,
1047 	   p_orig_khr_id     => p_chrv_id,
1048 	   p_trx_id          => l_mass_rbk_trx_id,
1049 	   p_trx_date        => sysdate); -- 4583578 passing sysdate instead of rebook date
1050 
1051 	 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1052 	   RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1053 	 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1054 	   RAISE Okl_Api.G_EXCEPTION_ERROR;
1055 	 END IF;
1056 	 -- dedey, Bug#4264314
1057 
1058         -- 4542290
1059         -- 4752350 (added NVL as l_source_trx_type is NULL)
1060         IF (nvl(l_source_trx_type,'X') NOT IN ('ALT', 'PPD')) THEN
1061           --generate final booking JE for rebooked contract
1062           --bug# 28355070
1063 
1064           --ndani - 20-Mar-2013, Start - Mass Rebook accounting fix
1065           --Bug# 16526329 : Accounting Booking : Booking to make two accounting calls
1066 
1067           -- Cursor called to check whether contract is mixed contract or not
1068           OPEN l_chk_con_csr (p_chrv_id);
1069           FETCH l_chk_con_csr
1070            INTO l_chk_contract_count;
1071           CLOSE l_chk_con_csr;
1072 
1073           l_acct_trans_type := l_transaction_type;
1074 
1075           -- if mixed contract call okl_la_je_pvt.generate_journal_entries for 'Release' seperately
1076           IF (l_chk_contract_count = 2) THEN
1077             l_acc_call_rel_flag := 'Y';
1078 
1079           ELSE
1080              -- Cursor to check re-leased asset, if released then assign l_acct_trans_type with 'Release'
1081              OPEN l_con_rel_csr (p_chrv_id);
1082              FETCH l_con_rel_csr
1083               INTO l_con_rel_flag;
1084              CLOSE l_con_rel_csr;
1085 
1086              IF (NVL (l_con_rel_flag,'N') = 'Y') THEN
1087                 l_acct_trans_type := 'Release';
1088 
1089              END IF;
1090           END IF;
1091 
1092           --Bug# 16526329 , End
1093           --ndani - 20-Mar-2013, End - Mass Rebook accounting fix
1094 
1095           okl_la_je_pvt.generate_journal_entries(
1096                         p_api_version      => p_api_version,
1097                         p_init_msg_list    => p_init_msg_list,
1098                         p_commit           => l_commit,
1099                         p_contract_id      => p_chrv_id,
1100                         p_transaction_type => l_acct_trans_type, --l_transaction_type,--ndani - 20-Mar-2013, Bug# 16526329- Mass Rebook accounting fix
1101                         --Bug# 3156924
1102                         --p_transaction_date => sysdate,
1103                         p_transaction_date => l_mass_rbk_date,
1104                         p_draft_yn         => l_draft_yn,
1105                         p_memo_yn          => okl_api.g_true,
1106                         x_return_status    => x_return_status,
1107                         x_msg_count        => x_msg_count,
1108                         x_msg_data         => x_msg_data);
1109 
1110           IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1111               RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1112           ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1113               RAISE Okl_Api.G_EXCEPTION_ERROR;
1114           END IF;
1115 
1116           --ndani - 20-Mar-2013, Start - Mass Rebook accounting fix
1117           --Bug# 16526329 : Accounting Booking : Booking to make two accounting calls for reversal of
1118           --                'Booking' and 'Release'
1119           --                Calling okl_la_je_pvt.generate_journal_entries() when Contract
1120           --                is created as mixed contract
1121 
1122           IF l_acc_call_rel_flag = 'Y' THEN
1123 
1124               okl_la_je_pvt.generate_journal_entries(
1125                         p_api_version      => p_api_version,
1126                         p_init_msg_list    => p_init_msg_list,
1127                         p_commit           => l_commit,
1128                         p_contract_id      => p_chrv_id,
1129                         p_transaction_type => 'Release', --l_transaction_type,
1130                         --Bug# 3156924
1131                         --p_transaction_date => sysdate,
1132                         p_transaction_date => l_mass_rbk_date,
1133                         p_draft_yn         => l_draft_yn,
1134                         p_memo_yn          => okl_api.g_true,
1135                         x_return_status    => x_return_status,
1136                         x_msg_count        => x_msg_count,
1137                         x_msg_data         => x_msg_data);
1138 
1139               IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1140                   RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1141               ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1142                   RAISE Okl_Api.G_EXCEPTION_ERROR;
1143               END IF;
1144 
1145           END IF;
1146           --Bug# 16526329 , End
1147           --ndani - 20-Mar-2013, End - Mass Rebook accounting fix
1148         END IF;
1149 
1150          --bug# 2842342
1151          --call reverse accruals API
1152 
1153          --Bug# 3156924
1154          l_gl_date := OKL_ACCOUNTING_UTIL.get_valid_gl_date(p_gl_date => l_mass_rbk_date);
1155 
1156         -- Sales Tax Project changes Bug: 4622963 - START
1157 
1158         -- Important Note: 'Mass-Rebook' is not a seeded trx type
1159         -- it is a placeholder to distinguish regular 'Rebook'
1160         -- from 'Mass Rebook' process for sales tax, because tax processing
1161         -- is different between the processes. Inside the sales tax process
1162         -- it will be replaced by trx type 'Rebook' before calling tax engine,
1163         -- as both the processes use 'Rebook' as the trx type
1164 --ebtax rebook impacts akrangan start
1165 --remove upfront tax call for rebook
1166 /*
1167         okl_la_sales_tax_pvt.process_sales_tax(
1168                       p_api_version      => p_api_version,
1169                       p_init_msg_list    => Okl_Api.G_FALSE,
1170                       p_commit           => Okl_Api.G_FALSE,
1171                       p_contract_id      => l_orig_khr_id,
1172                       p_transaction_type => 'Mass-Rebook',
1173                       p_transaction_id   => l_mass_rbk_trx_id,
1174                       p_transaction_date => l_mass_rbk_date,
1175                       p_rbk_contract_id  => l_orig_khr_id,
1176                       x_return_status    => x_return_status,
1177                       x_msg_count        => x_msg_count,
1178                       x_msg_data         => x_msg_data);
1179 
1180         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1181             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1182         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1183             RAISE Okl_Api.G_EXCEPTION_ERROR;
1184         END IF;
1185         -- Sales Tax Project changes Bug: 4622963 - END
1186 */
1187 --akrangan end
1188  	       -- dedey,Bug#4264314
1189          -- This call moved up before JE call
1190 	 /*
1191 
1192          --Bug# 4212626
1193          OKL_CONTRACT_REBOOK_PVT.create_billing_adjustment(
1194            p_api_version     => p_api_version,
1195            p_init_msg_list   => p_init_msg_list,
1196            x_return_status   => x_return_status,
1197            x_msg_count       => x_msg_count,
1198            x_msg_data        => x_msg_data,
1199            p_rbk_khr_id      => p_chrv_id,
1200            p_orig_khr_id     => p_chrv_id,
1201            p_trx_id          => l_mass_rbk_trx_id,
1202            p_trx_date        => sysdate); -- 4583578 passing sysdate instead of rebook date
1203 
1204          IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1205            RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1206          ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1207            RAISE Okl_Api.G_EXCEPTION_ERROR;
1208          END IF;
1209 	 */
1210 	 -- dedey,Bug#4264314
1211 
1212          --Bug# 4212626
1213          -- This call is moved to Okl_Mass_Rebook_Pvt(OKLRMRPB.pls)
1214          -- as the accrual adjustment api requires the Contract
1215          -- status to be 'BOOKED' before accrual adjustments can be
1216          -- generated.
1217          /*
1218          OKL_CONTRACT_REBOOK_PVT.create_accrual_adjustment(
1219            p_api_version     => p_api_version,
1220            p_init_msg_list   => p_init_msg_list,
1221            x_return_status   => x_return_status,
1222            x_msg_count       => x_msg_count,
1223            x_msg_data        => x_msg_data,
1224            p_rbk_khr_id      => p_chrv_id,
1225            p_orig_khr_id     => p_chrv_id,
1226            p_trx_id          => l_mass_rbk_trx_id,
1227            p_trx_date        => l_mass_rbk_date);
1228 
1229          IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1230            RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1231          ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1232            RAISE Okl_Api.G_EXCEPTION_ERROR;
1233          END IF;
1234          */
1235 
1236         --Bug# 4212626
1237         /*
1238         okl_generate_accruals_pub.REVERSE_ALL_ACCRUALS (
1239             p_api_version   => p_api_version,
1240             p_init_msg_list => p_init_msg_list,
1241             p_khr_id        => p_chrv_id,
1242             --Bug# 3156924
1243             --p_reverse_date  => SYSDATE,
1244             p_reverse_date  => l_gl_date,
1245             p_description   => 'Call from Rebook API',
1246             x_return_status => x_return_status,
1247             x_msg_count     => x_msg_count,
1248             x_msg_data      => x_msg_data);
1249 
1250         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1251             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1252         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1253             RAISE Okl_Api.G_EXCEPTION_ERROR;
1254         END IF;
1255         */
1256 
1257     ELSIF l_rbk_khr = '!' THEN
1258 
1259         --Bug# : check if rebook changes are supported
1260         --       check that no changes to add-ons and adjustments
1261         Is_Rebook_Supported(p_rbk_chr_id    => p_chrv_id,
1262                             p_orig_chr_id   => l_orig_khr_id,
1263                             x_return_status => x_return_status);
1264 
1265          IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1266             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1267          ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1268             RAISE Okl_Api.G_EXCEPTION_ERROR;
1269          END IF;
1270          --Bug#:  End.
1271 
1272         -- 02-Mar-09  sechawla  bug 8370324 : removed the following validation
1273         /*
1274         --Bug# 3783518 : Allow update of unit cost only if the
1275         --               revision date is the same as contract start date
1276          Validate_Rebook_Date
1277                  (p_api_version     => p_api_version,
1278                   p_init_msg_list   => p_init_msg_list,
1279                   x_return_status   => x_return_status,
1280                   x_msg_count       => x_msg_count,
1281                   x_msg_data        => x_msg_data,
1282                   p_rbk_chr_id      => p_chrv_id,
1283                   p_orig_chr_id     => l_orig_khr_id,
1284                   p_rebook_date     => l_rebook_date);
1285           IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1286             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1287           ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1288             RAISE Okl_Api.G_EXCEPTION_ERROR;
1289           END IF;
1290         --Bug# 3783518: End
1291          */
1292 
1293         --Bug# 8756653
1294         -- Check if contract has been upgraded for effective dated rebook
1295         OKL_LLA_UTIL_PVT.check_rebook_upgrade
1296           (p_api_version     => p_api_version,
1297            p_init_msg_list   => p_init_msg_list,
1298            x_return_status   => x_return_status,
1299            x_msg_count       => x_msg_count,
1300            x_msg_data        => x_msg_data,
1301            p_chr_id          => l_orig_khr_id,
1302            p_rbk_chr_id      => p_chrv_id);
1303 
1304         IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1305           RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1306         ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
1307           RAISE OKL_API.G_EXCEPTION_ERROR;
1308         END IF;
1309 
1310       --Start : Bug 6050165 : prasjain
1311           l_subsidy_exists := OKL_API.G_FALSE;
1312           okl_subsidy_process_pvt.is_contract_subsidized
1313                             (p_api_version   => p_api_version,
1314                             p_init_msg_list => p_init_msg_list,
1315                             x_return_status => x_return_status,
1316                             x_msg_count     => x_msg_count,
1317                             x_msg_data      => x_msg_data,
1318                             p_chr_id        => p_chrv_id,
1319                             x_subsidized    => l_subsidy_exists);
1320           IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1321                   RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1322           ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1323                   RAISE Okl_Api.G_EXCEPTION_ERROR;
1324           END IF;
1325 
1326          IF l_subsidy_exists = OKL_API.G_TRUE THEN
1327             l_subsidy_valid_status  := OKL_API.G_RET_STS_SUCCESS;
1328             OPEN l_subsidy_csr (p_chr_id => p_chrv_id);
1329             LOOP
1330                 FETCH l_subsidy_csr INTO l_subsidy_rec;
1331                 EXIT WHEN l_subsidy_csr%NOTFOUND;
1332                 l_applicable := 'N';
1333                   open l_cle_csr(p_subsidy_id   => l_subsidy_rec.subsidy_id,
1334                                p_asset_cle_id => l_subsidy_rec.asset_id);
1335                   Fetch l_cle_csr into l_applicable;
1336                   If l_cle_csr%NOTFOUND then
1337                       Null;
1338                   End If;
1339                   close l_cle_csr;
1340 
1341                   If (l_applicable = 'N') then
1342                       Okl_Api.set_message(
1343                               p_app_name     => G_APP_NAME,
1344                               p_msg_name     => 'OKL_SUBSIDY_CRITERIA_MATCH',
1345                               p_token1       => 'SUBSIDY_NAME',
1346                               p_token1_value => l_subsidy_rec.subsidy_name,
1347                               p_token2       => 'ASSET_NUMBER',
1348                               p_token2_value => l_subsidy_rec.asset_number);
1349                       l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
1350                  end if;
1351                end loop;
1352                IF (l_subsidy_valid_status = Okl_Api.G_RET_STS_ERROR) THEN
1353                  RAISE Okl_Api.G_EXCEPTION_ERROR;
1354                end if;
1355            end if;
1356      --End : Bug 6050165 : prasjain
1357 
1358         --4542290
1359         l_trx_date := l_rebook_date;
1360         l_accrual_date := l_rebook_date;
1361 
1362         okl_k_rate_params_pvt.get_product(
1363           p_api_version   => p_api_version,
1364           p_init_msg_list => p_init_msg_list,
1365           x_return_status => x_return_status,
1366           x_msg_count     => x_msg_count,
1367           x_msg_data      => x_msg_data,
1368           p_khr_id        => p_chrv_id,
1369           x_pdt_parameter_rec => l_pdt_parameter_rec);
1370 
1371         IF (l_pdt_parameter_rec.interest_calculation_basis = 'REAMORT' AND
1372             l_pdt_parameter_rec.revenue_recognition_method = 'STREAMS' ) THEN
1373           -- Change l_trx_date accordingly
1374           get_stream_id
1375           (
1376             p_khr_id => p_chrv_id,
1377             p_stream_type_purpose => 'RENT',
1378             x_return_status => x_return_status,
1379             x_sty_id => l_sty_id
1380           );
1381 	  IF x_return_status <> 'S' THEN
1382             okl_api.set_message(p_app_name     => g_app_name,
1383                                 p_msg_name     => 'OKL_AGN_STRM_TYPE_ERROR',
1384                                 p_token1       => 'STREAM_NAME',
1385                                 p_token1_value => 'RENT');
1386             RAISE okl_api.g_exception_error;
1387 	  END IF;
1388 
1389           l_max_bill_date := NULL;
1390           OPEN max_bill_date_csr(p_stm_id => l_sty_id );
1391           FETCH max_bill_date_csr INTO l_max_bill_date;
1392           CLOSE max_bill_date_csr;
1393           IF (l_max_bill_date IS NOT NULL) THEN
1394             l_trx_date := l_max_bill_date;
1395           END IF;
1396 
1397           IF (l_pdt_parameter_rec.deal_type = 'LEASEOP') THEN
1398             l_stream_name := 'RENT_ACCRUAL';
1399           ELSIF (l_pdt_parameter_rec.deal_type IN ('LEASEDF','LEASEST')) THEN
1400             l_stream_name := 'LEASE_INCOME'; -- AKP: Check 'LEASE_INCOME'?
1401           ELSIF (l_pdt_parameter_rec.deal_type = 'LOAN') THEN
1402             l_stream_name := 'INTEREST_INCOME'; -- AKP: Check
1403           END IF;
1404           get_stream_id
1405             (
1406               p_khr_id => p_chrv_id,
1407               p_stream_type_purpose => l_stream_name,
1408               x_return_status => x_return_status,
1409               x_sty_id => l_sty_id
1410             );
1411 	  IF x_return_status <> 'S' THEN
1412             okl_api.set_message(p_app_name     => g_app_name,
1413                                 p_msg_name     => 'OKL_AGN_STRM_TYPE_ERROR',
1414                                 p_token1       => 'STREAM_NAME',
1415                                 p_token1_value => l_stream_name);
1416             RAISE okl_api.g_exception_error;
1417 	  END IF;
1418 
1419           l_max_bill_date := NULL;
1420           OPEN max_bill_date_csr(p_stm_id => l_sty_id );
1421           FETCH max_bill_date_csr INTO l_max_bill_date;
1422           CLOSE max_bill_date_csr;
1423           IF (l_max_bill_date IS NOT NULL) THEN
1424             l_accrual_date := l_max_bill_date;
1425           END IF;
1426 
1427         END IF;
1428         --4542290
1429 
1430         --Bug# 4212626
1431         OKL_CONTRACT_REBOOK_PVT.create_billing_adjustment(
1432            p_api_version     => p_api_version,
1433            p_init_msg_list   => p_init_msg_list,
1434            x_return_status   => x_return_status,
1435            x_msg_count       => x_msg_count,
1436            x_msg_data        => x_msg_data,
1437            p_rbk_khr_id      => p_chrv_id,
1438            p_orig_khr_id     => l_orig_khr_id,
1439            p_trx_id          => l_transaction_id,
1440            p_trx_date        => sysdate); -- 4583578 passing sysdate instead of rebook date
1441            --4542290 p_trx_date        => l_rebook_date);
1442 
1443         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1444           RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1445         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1446           RAISE Okl_Api.G_EXCEPTION_ERROR;
1447         END IF;
1448 
1449 	-- dedey,Bug#4264314
1450         /*
1451         --Bug# 4212626
1452         OKL_CONTRACT_REBOOK_PVT.create_accrual_adjustment(
1453            p_api_version     => p_api_version,
1454            p_init_msg_list   => p_init_msg_list,
1455            x_return_status   => x_return_status,
1456            x_msg_count       => x_msg_count,
1457            x_msg_data        => x_msg_data,
1458            p_rbk_khr_id      => p_chrv_id,
1459            p_orig_khr_id     => l_orig_khr_id,
1460            p_trx_id          => l_transaction_id,
1461            p_trx_date        => l_rebook_date);
1462 
1463 	*/
1464       OKL_STREAMS_SEC_PVT.RESET_REPO_STREAMS; -- MGAAP 7263041
1465       OKL_CONTRACT_REBOOK_PVT.calc_accrual_adjustment(
1466        p_api_version     => p_api_version,
1467        p_init_msg_list   => p_init_msg_list,
1468        x_return_status   => x_return_status,
1469        x_msg_count       => x_msg_count,
1470        x_msg_data        => x_msg_data,
1471        p_rbk_khr_id      => p_chrv_id,
1472        p_orig_khr_id     => l_orig_khr_id,
1473        p_trx_id          => l_transaction_id,
1474        --4542290 p_trx_date        => l_rebook_date,
1475        p_trx_date        => sysdate,    -- 4583578 passing sysdate instead of rebook_date
1476        x_accrual_rec     => l_accrual_rec,
1477        x_stream_tbl      => l_stream_tbl);
1478 
1479      IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1480        RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1481      ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1482        RAISE Okl_Api.G_EXCEPTION_ERROR;
1483      END IF;
1484 
1485      IF (l_stream_tbl.COUNT > 0) THEN -- Call adjustment when required, dedey
1486         OKL_GENERATE_ACCRUALS_PVT.ADJUST_ACCRUALS (
1487           p_api_version    => p_api_version,
1488           p_init_msg_list  => p_init_msg_list,
1489           x_return_status  => x_return_status,
1490           x_msg_count      => x_msg_count,
1491           x_msg_data       => x_msg_data ,
1492           --Bug# 9191475
1493           --x_trx_number     => lx_trx_number,
1494           x_trx_tbl        => lx_trxnum_tbl,
1495           p_accrual_rec    => l_accrual_rec,
1496           p_stream_tbl     => l_stream_tbl);
1497 
1498         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1499           RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1500         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1501           RAISE Okl_Api.G_EXCEPTION_ERROR;
1502         END IF;
1503 
1504       END IF; -- l_stream_tbl.COUNT > 0
1505 
1506       -- Start MGAAP 7263041
1507       OKL_STREAMS_SEC_PVT.SET_REPO_STREAMS;
1508       OKL_CONTRACT_REBOOK_PVT.calc_accrual_adjustment(
1509        p_api_version     => p_api_version,
1510        p_init_msg_list   => p_init_msg_list,
1511        x_return_status   => x_return_status,
1512        x_msg_count       => x_msg_count,
1513        x_msg_data        => x_msg_data,
1514        p_rbk_khr_id      => p_chrv_id,
1515        p_orig_khr_id     => l_orig_khr_id,
1516        p_trx_id          => l_transaction_id,
1517        --4542290 p_trx_date        => l_rebook_date,
1518        p_trx_date        => sysdate,    -- 4583578 passing sysdate instead of rebook_date
1519        x_accrual_rec     => l_accrual_rec,
1520        x_stream_tbl      => l_stream_tbl);
1521 
1522      OKL_STREAMS_SEC_PVT.RESET_REPO_STREAMS;
1523      IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1524        OKL_STREAMS_SEC_PVT.RESET_REPO_STREAMS;
1525        RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1526      ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1527        OKL_STREAMS_SEC_PVT.RESET_REPO_STREAMS;
1528        RAISE Okl_Api.G_EXCEPTION_ERROR;
1529      END IF;
1530 
1531      IF (l_stream_tbl.COUNT > 0) THEN -- Call adjustment when required, dedey
1532         --l_accrual_rec.trx_number := lx_trx_number;
1533         OKL_GENERATE_ACCRUALS_PVT.ADJUST_ACCRUALS (
1534           p_api_version    => p_api_version,
1535           p_init_msg_list  => p_init_msg_list,
1536           x_return_status  => x_return_status,
1537           x_msg_count      => x_msg_count,
1538           x_msg_data       => x_msg_data ,
1539           --Bug# 9191475
1540           --x_trx_number     => lx_trx_number,
1541           x_trx_tbl        => lx_trxnum_tbl,
1542           p_accrual_rec    => l_accrual_rec,
1543           p_stream_tbl     => l_stream_tbl,
1544           p_representation_type     => 'SECONDARY');
1545 
1546         OKL_STREAMS_SEC_PVT.RESET_REPO_STREAMS;
1547 
1548         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1549           RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1550         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1551           RAISE Okl_Api.G_EXCEPTION_ERROR;
1552         END IF;
1553 
1554       END IF; -- l_stream_tbl.COUNT > 0
1555       OKL_STREAMS_SEC_PVT.RESET_REPO_STREAMS;
1556       -- End MGAAP 7263041
1557 
1558 	-- dedey,Bug#4264314
1559 
1560         -- call synchronize
1561         --dbms_output.put_line('Into processing for rebooking.');
1562 		Okl_Contract_Rebook_Pvt.sync_rebook_orig_contract(
1563                                       p_api_version        => p_api_version,
1564                                       p_init_msg_list      => p_init_msg_list,
1565                                       x_return_status      => x_return_status,
1566                                       x_msg_count          => x_msg_count,
1567                                       x_msg_data           => x_msg_data,
1568                                       p_rebook_chr_id      => p_chrv_id
1569                                      );
1570          --dbms_output.put_line('Hey 1 first call: '||x_return_status);
1571          IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1572             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1573          ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1574             RAISE Okl_Api.G_EXCEPTION_ERROR;
1575          END IF;
1576 
1577 
1578         --dbms_output.put_line('Status1 BEFORE call: '||x_return_status);
1579          -- call synchronize Streams
1580 
1581          Okl_Contract_Rebook_Pvt.sync_rebook_stream (
1582                                p_api_version        => p_api_version,
1583                                p_init_msg_list      => p_init_msg_list,
1584                                x_return_status      => x_return_status,
1585                                x_msg_count          => x_msg_count,
1586                                x_msg_data           => x_msg_data,
1587                                p_chr_id             => p_chrv_id,
1588                                p_stream_status      =>  NULL
1589                               );
1590         --dbms_output.put_line('Status1: '||x_return_status);
1591 
1592         IF (x_return_status = Okc_Api.G_RET_STS_UNEXP_ERROR) THEN
1593         --dbms_output.put_line('Status2: '||x_return_status);
1594             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1595          ELSIF (x_return_status = Okc_Api.G_RET_STS_ERROR) THEN
1596         --dbms_output.put_line('Status3: '||x_return_status);
1597             RAISE Okl_Api.G_EXCEPTION_ERROR;
1598          END IF;
1599         --dbms_output.put_line('Status4: '||x_return_status);
1600 
1601         --call rebook api
1602 
1603         Okl_Activate_Asset_Pub.REBOOK_ASSET(p_api_version      => p_api_version,
1604                                             p_init_msg_list    => p_init_msg_list,
1605                                             x_return_status    => x_return_status,
1606                                             x_msg_count        => x_msg_count,
1607                                             x_msg_data         => x_msg_data,
1608                                             p_rbk_chr_id       => p_chrv_id);
1609         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1610             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1611         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1612             RAISE Okl_Api.G_EXCEPTION_ERROR;
1613         END IF;
1614 
1615         ---------------------------------------------------------------------------------------
1616         --Bug# 3143522: Subsidies enhancement : Create billing transaction for 'BILL' subsidies
1617         ---------------------------------------------------------------------------------------
1618         l_subsidy_exists := OKL_API.G_FALSE;
1619         okl_subsidy_process_pvt.is_contract_subsidized
1620                           (p_api_version   => p_api_version,
1621                           p_init_msg_list => p_init_msg_list,
1622                           x_return_status => x_return_status,
1623                           x_msg_count     => x_msg_count,
1624                           x_msg_data      => x_msg_data,
1625                           p_chr_id        => p_chrv_id,
1626                           x_subsidized    => l_subsidy_exists);
1627         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1628                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1629         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1630                 RAISE Okl_Api.G_EXCEPTION_ERROR;
1631         END IF;
1632 
1633         If l_subsidy_exists = OKL_API.G_FALSE Then
1634             okl_subsidy_process_pvt.is_contract_subsidized
1635                           (p_api_version   => p_api_version,
1636                           p_init_msg_list => p_init_msg_list,
1637                           x_return_status => x_return_status,
1638                           x_msg_count     => x_msg_count,
1639                           x_msg_data      => x_msg_data,
1640                           p_chr_id        => l_orig_khr_id,
1641                           x_subsidized    => l_subsidy_exists);
1642             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1643                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1644             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1645                 RAISE Okl_Api.G_EXCEPTION_ERROR;
1646             END IF;
1647         Elsif l_subsidy_exists = OKL_API.G_TRUE then
1648             Null;
1649         End If;
1650 
1651         If l_subsidy_exists = OKL_API.G_TRUE then
1652             -- varangan - Bug#5474059 - Modified - Start
1653             -- Subsidy billing during rebook done before actual
1654             -- synchronization with main contract. This is to ensure that
1655             -- the subsidy amount differences can be used to generate invoices/
1656             -- credit memo as is the case
1657             --call process API to create Billing transactions for Subsidies ;
1658            --call process API to create Billing transactions for Subsidies ;
1659             OKL_SUBSIDY_PROCESS_PVT.CREATE_BILLING_TRX(
1660                           p_api_version   => p_api_version,
1661                           p_init_msg_list => p_init_msg_list,
1662                           x_return_status => x_return_status,
1663                           x_msg_count     => x_msg_count,
1664                           x_msg_data      => x_msg_data,
1665                           p_chr_id        => p_chrv_id);
1666 
1667             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1668                     RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1669             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1670                     RAISE Okl_Api.G_EXCEPTION_ERROR;
1671             END IF;
1672             -- varangan - Bug#5474059 - Modified - End
1673 
1674             --do rebook synchronize for subsidies
1675             OKL_SUBSIDY_PROCESS_PVT.rebook_synchronize
1676                           (p_api_version   => p_api_version,
1677                           p_init_msg_list => p_init_msg_list,
1678                           x_return_status => x_return_status,
1679                           x_msg_count     => x_msg_count,
1680                           x_msg_data      => x_msg_data,
1681                           p_rbk_chr_id    => p_chrv_id,
1682                           p_orig_chr_id   => l_orig_khr_id);
1683 
1684             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1685                     RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1686             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1687                     RAISE Okl_Api.G_EXCEPTION_ERROR;
1688             END IF;
1689 
1690 
1691         End If;
1692         -------------------------------------------------------------------------------------------
1693         --Bug# 3143522: End Subsidies enhancement : Create billing transaction for 'BILL' subsidies
1694         --------------------------------------------------------------------------------------------
1695 
1696         --bug# 28355070
1697         --generate final booking JE for synced original contract
1698 
1699         --ndani - 14-Mar-2013, Start - Rebook accounting fix
1700         --Bug# 16511024 : Accounting Booking : Booking to make two accounting calls
1701          --                'Booking' and 'Release' for Booking
1702 
1703          -- Cursor called to check whether contract is mixed contract or not
1704          OPEN l_chk_con_csr (l_orig_khr_id);
1705          FETCH l_chk_con_csr
1706           INTO l_chk_contract_count;
1707          CLOSE l_chk_con_csr;
1708 
1709          l_acct_trans_type := l_transaction_type;
1710 
1711          -- if mixed contract call okl_la_je_pvt.generate_journal_entries for 'Release' seperately
1712          IF (l_chk_contract_count = 2) THEN
1713             l_acc_call_rel_flag := 'Y';
1714 
1715          ELSE
1716             -- Cursor to check re-leased asset, if released then assign l_acct_trans_type with 'Release'
1717             OPEN l_con_rel_csr (l_orig_khr_id);
1718             FETCH l_con_rel_csr
1719              INTO l_con_rel_flag;
1720             CLOSE l_con_rel_csr;
1721 
1722             IF (NVL (l_con_rel_flag,'N') = 'Y') THEN
1723                l_acct_trans_type := 'Release';
1724 
1725             END IF;
1726          END IF;
1727 
1728          --Bug# 16511024 , End
1729          --ndani - 14-Mar-2013, End - Rebook accounting fix
1730 
1731         okl_la_je_pvt.generate_journal_entries(
1732                       p_api_version      => p_api_version,
1733                       p_init_msg_list    => p_init_msg_list,
1734                       p_commit           => l_commit,
1735                       p_contract_id      => l_orig_khr_id,
1736                       p_transaction_type => l_acct_trans_type,
1737                       p_transaction_date => l_rebook_date,
1738                       p_draft_yn         => l_draft_yn,
1739                       p_memo_yn          => okl_api.g_true,
1740                       x_return_status    => x_return_status,
1741                       x_msg_count        => x_msg_count,
1742                       x_msg_data         => x_msg_data);
1743 
1744         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1745             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1746         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1747             RAISE Okl_Api.G_EXCEPTION_ERROR;
1748         END IF;
1749 
1750         --ndani - 14-Mar-2013, Start - Rebook accounting fix
1751         --Bug# 16511024 : Accounting Booking : Booking to make two accounting calls
1752         --                'Booking' and 'Release' for Booking
1753         --                Calling okl_la_je_pvt.generate_journal_entries() when Contract
1754         --                is created as mixed contract
1755 
1756         IF l_acc_call_rel_flag = 'Y' THEN
1757 
1758             okl_la_je_pvt.generate_journal_entries(
1759                       p_api_version      => p_api_version,
1760                       p_init_msg_list    => p_init_msg_list,
1761                       p_commit           => l_commit,
1762                       p_contract_id      => l_orig_khr_id,
1763                       p_transaction_type => 'Release', -- l_transaction_type
1764                       p_transaction_date => l_rebook_date,
1765                       p_draft_yn         => l_draft_yn,
1766                       p_memo_yn          => okl_api.g_true,
1767                       x_return_status    => x_return_status,
1768                       x_msg_count        => x_msg_count,
1769                       x_msg_data         => x_msg_data);
1770 
1771             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1772                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1773             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1774                 RAISE Okl_Api.G_EXCEPTION_ERROR;
1775             END IF;
1776 
1777         END IF;
1778         --Bug# 16511024 , End
1779         --ndani - 14-Mar-2013, End - Rebook accounting fix
1780 
1781 
1782         --Bug# 3397688 : Call function to get valid open period date
1783         l_gl_date := OKL_ACCOUNTING_UTIL.get_valid_gl_date(p_gl_date => l_rebook_date);
1784 
1785         -- Sales Tax Project changes Bug: 4622963 - START
1786         okl_la_sales_tax_pvt.process_sales_tax(
1787                       p_api_version      => p_api_version,
1788                       p_init_msg_list    => Okl_Api.G_FALSE,
1789                       p_commit           => Okl_Api.G_FALSE,
1790                       p_contract_id      => l_orig_khr_id,
1791                       p_transaction_type => 'Rebook',
1792                       p_transaction_id   => l_transaction_id,
1793                       p_transaction_date => l_rebook_date,
1794                       p_rbk_contract_id  => p_chrv_id,
1795                       x_return_status    => x_return_status,
1796                       x_msg_count        => x_msg_count,
1797                       x_msg_data         => x_msg_data);
1798 
1799         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1800             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1801         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1802             RAISE Okl_Api.G_EXCEPTION_ERROR;
1803         END IF;
1804         -- Sales Tax Project changes Bug: 4622963 - END
1805 
1806         --Bug# 4212626
1807         /*
1808          --bug# 2842342
1809          --call reverse accruals API
1810         okl_generate_accruals_pub.REVERSE_ALL_ACCRUALS (
1811             p_api_version   => p_api_version,
1812             p_init_msg_list => p_init_msg_list,
1813             p_khr_id        => l_orig_khr_id,
1814             --Bug# 3397688 :
1815             p_reverse_date  => l_gl_date,
1816             --p_reverse_date  => l_rebook_date,
1817             p_description   => 'Call from Rebook API',
1818             x_return_status => x_return_status,
1819             x_msg_count     => x_msg_count,
1820             x_msg_data      => x_msg_data);
1821 
1822         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1823             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1824         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1825             RAISE Okl_Api.G_EXCEPTION_ERROR;
1826         END IF;
1827         */
1828 
1829 --Bug#5955320
1830         --call insurance API
1831         OKL_INSURANCE_POLICIES_PUB.cancel_create_policies(
1832               p_api_version       => p_api_version,
1833               p_init_msg_list     => OKL_API.G_FALSE,
1834               x_return_status     => x_return_status,
1835               x_msg_count         => x_msg_count,
1836               x_msg_data          => x_msg_data,
1837               p_khr_id            => l_orig_khr_id,
1838               p_cancellation_date => l_rebook_date,
1839               p_transaction_id    => l_transaction_id,
1840               x_ignore_flag       => l_ignore_flag);
1841 
1842         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1843             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1844         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1845             If (l_ignore_flag = OKL_API.G_FALSE) then
1846                 RAISE Okl_Api.G_EXCEPTION_ERROR;
1847             End If;
1848         END IF;
1849 
1850         --Bug#3278666 : 11.5.10 call Asset management API to invalidate all valid quotes
1851         OKL_AM_INTEGRATION_PVT.cancel_termination_quotes(
1852                               p_api_version        => p_api_version,
1853                               p_init_msg_list      => p_init_msg_list,
1854                               x_return_status      => x_return_status,
1855                               x_msg_count          => x_msg_count,
1856                               x_msg_data           => x_msg_data,
1857                               p_khr_id             => l_orig_khr_id,
1858                               p_source_trx_id      => NULL
1859                               );
1860         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1861             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1862         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1863             RAISE Okl_Api.G_EXCEPTION_ERROR;
1864         END IF;
1865         --Bug# 3278666 : 11.5.10 call Asset management API to invalidate all valid quotes
1866 
1867         -- PPD
1868         -- Cancel un-accepted PPD transaction during rebook of a contract
1869         --
1870         OKL_CS_PRINCIPAL_PAYDOWN_PUB.CANCEL_PPD(
1871                 p_api_version           => p_api_version
1872                 ,p_init_msg_list        => p_init_msg_list
1873                 ,x_return_status        => x_return_status
1874                 ,x_msg_count            => x_msg_count
1875                 ,x_msg_data             => x_msg_data
1876                 ,p_khr_id               => l_orig_khr_id
1877                );
1878 
1879         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1880             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1881         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1882             RAISE Okl_Api.G_EXCEPTION_ERROR;
1883         END IF;
1884         -- End PPD Cancel
1885 
1886         --update transaction status
1887         Okl_Transaction_Pub.update_trx_status(
1888                               p_api_version        => p_api_version,
1889                               p_init_msg_list      => p_init_msg_list,
1890                               x_return_status      => x_return_status,
1891                               x_msg_count          => x_msg_count,
1892                               x_msg_data           => x_msg_data,
1893                               p_chr_id             => p_chrv_id,
1894                               p_status             => 'PROCESSED',
1895                               x_tcnv_rec           => l_tcnv_rec
1896                              );
1897         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1898             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1899         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1900             RAISE Okl_Api.G_EXCEPTION_ERROR;
1901         END IF;
1902 
1903         -- snarasip
1904         -- before the status is abandoned
1905 	-- check if the contract has mixed asset
1906 	-- if yes then check if rule_information1 = 'Y' then
1907 	-- update the rule to null
1908 	IF l_mxd_ast = '!' THEN
1909 	    --Bug# 15992711 Start of Modifications
1910 	    --check for rule group LARLES
1911 	    OPEN l_rule_info_csr (p_chr_id => l_orig_khr_id);
1912 	    FETCH l_rule_info_csr INTO l_rul_info,l_rul_info1;
1913 	    IF l_rule_info_csr%NOTFOUND THEN
1914 	       NULL;
1915 	    END IF;
1916 	    CLOSE l_rule_info_csr;
1917 
1918 	    IF l_rul_info1 = 'Y' THEN
1919                   l_rulv_rec.id := l_rul_info;
1920                   l_rulv_rec.rule_information1 := NULL;
1921                   OKL_RULE_PUB.update_rule
1922                      (p_api_version   => p_api_version,
1923                       p_init_msg_list => p_init_msg_list,
1924                       x_return_status => x_return_status,
1925                       x_msg_count     => x_msg_count,
1926                       x_msg_data      => x_msg_data,
1927                       p_rulv_rec      => l_rulv_rec,
1928                       p_edit_mode     => 'N',       -- snarasip Bug# 15992711 7-Mar-2013 ,added edit mode as 'N' to retain contract status
1929                       x_rulv_rec      => lx_rulv_rec);
1930 
1931 
1932                 IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1933                     RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1934                 ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1935                     RAISE Okl_Api.G_EXCEPTION_ERROR;
1936                 END IF;
1937             END IF;
1938         END IF;
1939         l_mxd_ast := '?';
1940         l_rul_info := NULL;
1941         l_rul_info1 := NULL;
1942         -- snarasip
1943         --change the rebook copy contract status to 'ABANDONED'
1944         okl_contract_status_pub.update_contract_status(
1945                                 p_api_version      => p_api_version,
1946                                 p_init_msg_list    => p_init_msg_list,
1947                                 x_return_status    => x_return_status,
1948                                 x_msg_count        => x_msg_count,
1949                                 x_msg_data         => x_msg_data,
1950                                 p_khr_status       => 'ABANDONED',
1951                                 p_chr_id           => p_chrv_id);
1952         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1953             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1954         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1955             RAISE Okl_Api.G_EXCEPTION_ERROR;
1956         END IF;
1957 
1958         --cascade status to lines
1959         okl_contract_status_pub.cascade_lease_status(
1960                                 p_api_version      => p_api_version,
1961                                 p_init_msg_list    => p_init_msg_list,
1962                                 x_return_status    => x_return_status,
1963                                 x_msg_count        => x_msg_count,
1964                                 x_msg_data         => x_msg_data,
1965                                 p_chr_id           => p_chrv_id);
1966 
1967         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1968             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1969         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1970             RAISE Okl_Api.G_EXCEPTION_ERROR;
1971         END IF;
1972 
1973         -- Bug# 6071566 - Added Start
1974         -- Re-assess the earliest stream bill date on contract after rebook to
1975         -- take into account any changes in payment structure.
1976         OKL_BILLING_CONTROLLER_PVT.track_next_bill_date(l_orig_khr_id);
1977         -- Bug# 6071566 - Added End
1978 
1979 
1980     ELSIF l_rel_khr = '!' Then
1981         -- call contract release api
1982         okl_release_pub.activate_release_contract(
1983             p_api_version        => p_api_version,
1984             p_init_msg_list      => p_init_msg_list,
1985             x_return_status      => x_return_status,
1986             x_msg_count          => x_msg_count,
1987             x_msg_data           => x_msg_data,
1988             p_chr_id             => p_chrv_id);
1989 
1990        IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1991             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1992         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
1993             RAISE Okl_Api.G_EXCEPTION_ERROR;
1994         END IF;
1995 
1996     ELSIF l_rel_ast = '!' Then
1997    /*
1998           dcshanmu 21-Jan-2008 start bug#6688570
1999           Subsidy enhancement added as part of the bug#6688570. As per the update
2000           given by the PM *** SRAWLING  11/20/07 10:16 am ***, the subsidy needs
2001           to be billed even if the contract is for re-leased assets and the amount
2002           needs to be tracked to a subsidy pool.
2003        */
2004     ---------------------------------------------------------------------------------------
2005     --Bug# 3143522: Subsidies enhancement : Check for expired subsidies and stop activation
2006     --                               Create billing transaction for 'BILL' subsidies
2007     ---------------------------------------------------------------------------------------
2008 
2009            l_subsidy_exists := OKL_API.G_FALSE;
2010            okl_subsidy_process_pvt.is_contract_subsidized
2011                              (p_api_version   => p_api_version,
2012                              p_init_msg_list => p_init_msg_list,
2013                              x_return_status => x_return_status,
2014                              x_msg_count     => x_msg_count,
2015                              x_msg_data      => x_msg_data,
2016                              p_chr_id        => p_chrv_id,
2017                              x_subsidized    => l_subsidy_exists);
2018            IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2019                    RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2020            ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2021                    RAISE Okl_Api.G_EXCEPTION_ERROR;
2022            END IF;
2023 
2024            IF l_subsidy_exists = OKL_API.G_TRUE THEN
2025              ---------------------------------------------------
2026              --check if expired subsidies exist for the contract
2027              ---------------------------------------------------
2028              l_subsidy_valid_status  := OKL_API.G_RET_STS_SUCCESS;
2029              OPEN l_subsidy_csr (p_chr_id => p_chrv_id);
2030              LOOP
2031                  FETCH l_subsidy_csr INTO l_subsidy_rec;
2032                  EXIT WHEN l_subsidy_csr%NOTFOUND;
2033                  --shagarg bug 6032336 start
2034                  l_applicable := 'N';
2035                    open l_cle_csr(p_subsidy_id   => l_subsidy_rec.subsidy_id,
2036                                 p_asset_cle_id => l_subsidy_rec.asset_id);
2037                    Fetch l_cle_csr into l_applicable;
2038                    If l_cle_csr%NOTFOUND then
2039                        Null;
2040                    End If;
2041                    close l_cle_csr;
2042 
2043                    If (l_applicable = 'N') then
2044                        Okl_Api.set_message(
2045                                p_app_name     => G_APP_NAME,
2046                                p_msg_name     => 'OKL_SUBSIDY_CRITERIA_MATCH',
2047                                p_token1       => 'SUBSIDY_NAME',
2048                                p_token1_value => l_subsidy_rec.subsidy_name,
2049                                p_token2       => 'ASSET_NUMBER',
2050                                p_token2_value => l_subsidy_rec.asset_number);
2051                        l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
2052                    end if;
2053 
2054                  --IF((l_subsidy_rec.effective_to_date + l_subsidy_rec.expire_after_days) < TRUNC(SYSDATE))THEN
2055                   if( TRUNC(sysdate) not between TRUNC(l_subsidy_rec.effective_from_date) and
2056                      TRUNC(nvl(l_subsidy_rec.EFFECTIVE_TO_DATE,sysdate) + nvl(l_subsidy_rec.EXPIRE_AFTER_DAYS,0)))then
2057                 --shagarg bug 6032336 end
2058                      OKL_API.Set_Message(p_app_name     => G_APP_NAME,
2059                                        p_msg_name     => 'OKL_SUBSIDY_EXPIRED',
2060                                        p_token1       => 'SUBSIDY',
2061                                        p_token1_value => l_subsidy_rec.subsidy_name,
2062                                        p_token2       => 'ASSET_NUMBER',
2063                                        p_token2_value => l_subsidy_rec.asset_number);
2064                    l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
2065 
2066 
2067 
2068                  ELSE
2069                    /*
2070                     * sjalasut added code for subsidy pools enhancement, the subsidy is checked for association
2071                     * with the subsidy pool, if associated, the authoring transaction api is invoked for
2072                     * validation and then create transaction. code logic being merged with subsidy expiration
2073                     * because only when subsidy is not expired and is associated with a pool, will the pool transaction occur.
2074                     * Further, it is not correct to indicate a validation failure on a subsidy pool transaction while the
2075                     * subsidy is actually exipred. START
2076                     */
2077                    IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2078                      okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'verifying subsidy applicability over pool subsidy id '||l_subsidy_rec.subsidy_id);
2079                    END IF;
2080 
2081                    l_sub_pool_applicable := okl_asset_subsidy_pvt.is_sub_assoc_with_pool(p_subsidy_id => l_subsidy_rec.subsidy_id
2082                                                                                         ,x_subsidy_pool_id => lx_sub_pool_id
2083                                                                                         ,x_sub_pool_curr_code => lx_sub_pool_curr_code
2084                                                                                         );
2085 
2086                    IF(l_sub_pool_applicable = 'Y')THEN
2087                      -- initialize for every iteration of the loop
2088                      lv_subsidy_amount := 0;
2089                      -- the amount for transaction is either the override amount if present or the calculated subsidy amount
2090                      lv_subsidy_amount := NVL(l_subsidy_rec.subsidy_override_amount,NVL(l_subsidy_rec.subsidy_amount,0));
2091                      -- write to debug log
2092                      IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2093                        okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'pool applicable sub_pool_id '||lx_sub_pool_id||' amount '||lv_subsidy_amount);
2094                      END IF;
2095                      okl_subsidy_pool_auth_trx_pvt.create_pool_trx_khr_book(p_api_version   => p_api_version
2096                                                                            ,p_init_msg_list => p_init_msg_list
2097                                                                            ,x_return_status => x_return_status
2098                                                                            ,x_msg_count     => x_msg_count
2099                                                                            ,x_msg_data      => x_msg_data
2100                                                                            ,p_chr_id        => p_chrv_id
2101                                                                            ,p_asset_id      => l_subsidy_rec.asset_id
2102                                                                            ,p_subsidy_id    => l_subsidy_rec.subsidy_id
2103                                                                            ,p_subsidy_pool_id => lx_sub_pool_id
2104                                                                            ,p_trx_amount    => lv_subsidy_amount
2105                                                                            );
2106                      l_subsidy_valid_status := x_return_status;
2107                      IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2108                        okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'x_return_status being copied into l_subsidy_valid_status '||l_subsidy_valid_status
2109                                                 ||' x_msg_data '||x_msg_data
2110                                                );
2111                      END IF; -- end of write to debug log
2112                    END IF; -- end of l_sub_pool_applicable = 'Y'
2113                  END IF; -- end of (l_subsidy_rec.effective_to_date + l_subsidy_rec.expire_after_days) < TRUNC(SYSDATE)
2114                    /*
2115                     * sjalasut added code for subsidy pools enhancement, the subsidy is checked for association
2116                     * with the subsidy pool, if associated, the authoring transaction api is invoked for
2117                     * validation and then create transaction. END
2118                     */
2119              END LOOP;
2120              CLOSE l_subsidy_csr;
2121 
2122              x_return_status := l_subsidy_valid_status;
2123 
2124                IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2125                        RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2126                ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2127                        RAISE Okl_Api.G_EXCEPTION_ERROR;
2128                END IF;
2129 
2130 
2131                --call process API to create Billing transactions for Subsidies ;
2132                OKL_SUBSIDY_PROCESS_PVT.CREATE_BILLING_TRX(
2133                              p_api_version   => p_api_version,
2134                              p_init_msg_list => p_init_msg_list,
2135                              x_return_status => x_return_status,
2136                              x_msg_count     => x_msg_count,
2137                              x_msg_data      => x_msg_data,
2138                              p_chr_id        => p_chrv_id);
2139 
2140                IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2141                        RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2142                ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2143                        RAISE Okl_Api.G_EXCEPTION_ERROR;
2144                END IF;
2145            End If;
2146            -------------------------------------------------------------------------
2147            --Bug#i 3143522 : End Subsidies enhancement
2148            -------------------------------------------------------------------------
2149 
2150        /* dcshanmu 21-Jan-2008 end bug#6688570 */
2151 
2152         -- call the asset release api
2153         okl_activate_asset_pub.RELEASE_ASSET
2154                         (p_api_version   => p_api_version,
2155                          p_init_msg_list => p_init_msg_list,
2156                          x_return_status => x_return_status,
2157                          x_msg_count     => x_msg_count,
2158                          x_msg_data      => x_msg_data,
2159                          p_rel_chr_id    => p_chrv_id);
2160 
2161         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2162             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2163         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2164             RAISE Okl_Api.G_EXCEPTION_ERROR;
2165         END IF;
2166 
2167         --Bug# 3533936 :
2168         --call the install base instance re_lease API
2169         okl_activate_ib_pvt.RELEASE_IB_INSTANCE
2170                         (p_api_version   => p_api_version,
2171                          p_init_msg_list => p_init_msg_list,
2172                          x_return_status => x_return_status,
2173                          x_msg_count     => x_msg_count,
2174                          x_msg_data      => x_msg_data,
2175                          p_rel_chr_id    => p_chrv_id);
2176 
2177         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2178             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2179         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2180             RAISE Okl_Api.G_EXCEPTION_ERROR;
2181         END IF;
2182 
2183         --Bug#2522439 Start
2184         --code added to update status in OKL_ASSET_RETURNS_B
2185         --after the release asset transaction has been processed
2186         OPEN l_asr_csr(p_chrv_id);
2187         LOOP
2188             FETCH l_asr_csr into l_asr_rec;
2189             EXIT When l_asr_csr%NOTFOUND;
2190             l_artv_rec.id := l_asr_rec.asset_return_id;
2191             l_artv_rec.ars_code := 'CANCELLED';
2192             l_artv_rec.like_kind_yn := 'N';
2193             --call to change the release asset status to 'CANCELLED' in asset return
2194             okl_asset_returns_pub.update_asset_returns(
2195                      p_api_version    => p_api_version
2196                     ,p_init_msg_list  => p_init_msg_list
2197                     ,x_return_status  => x_return_status
2198                     ,x_msg_count      => x_msg_count
2199                     ,x_msg_data       => x_msg_data
2200                     ,p_artv_rec       => l_artv_rec
2201                     ,x_artv_rec       => lx_artv_rec);
2202 
2203             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2204                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2205             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2206                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2207             END IF;
2208         END LOOP;
2209         CLOSE l_asr_csr;
2210         --Bug#2522439 End
2211 
2212          -- Bug# 15992711 Start of Modifications
2213          -- Start:update header level re_leased asset flag to 'Y'
2214          --when all the assets on a contract are re-leased
2215               l_rulv_rec.id := l_rul_info;
2216               l_rulv_rec.rule_information1 := 'Y';
2217               OKL_RULE_PUB.update_rule
2218                  (p_api_version   => p_api_version,
2219                   p_init_msg_list => p_init_msg_list,
2220                   x_return_status => x_return_status,
2221                   x_msg_count     => x_msg_count,
2222                   x_msg_data      => x_msg_data,
2223                   p_rulv_rec      => l_rulv_rec,
2224                   p_edit_mode     => 'N',       -- snarasip Bug# 15992711 7-Mar-2013 ,added edit mode as 'N' to retain contract status
2225                   x_rulv_rec      => lx_rulv_rec);
2226 
2227 
2228             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2229                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2230             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2231                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2232             END IF;
2233          -- End:update header level re_leased asset flag to 'Y'
2234          --when all the assets on a contract are re-leased
2235 
2236         --Start:In case of a mixed contract
2237         ELSIF l_mxd_ast = '!' Then
2238 
2239          --bug# 2953906 :
2240          --check for billto status
2241          Validate_bill_To(p_chr_id        => p_chrv_id,
2242                           x_return_status => x_return_status);
2243 
2244          IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2245                  RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2246          ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2247                  RAISE Okl_Api.G_EXCEPTION_ERROR;
2248          END IF;
2249          --bug # 2953906 end.
2250 
2251         -------------------------------------------------------------------------
2252          --Bug# 3541098: If Capitalize interest flag is set to 'NO', then
2253          --              calculate interest on pre-funding amount upto the
2254          --              booking date of the contract and create
2255          --              Billing transaction for the interest amount.
2256          ------------------------------------------------------------------------
2257        open cap_interest_rul_csr (p_chrv_id);
2258        fetch cap_interest_rul_csr  into l_capitalize_interest_flag;
2259        if cap_interest_rul_csr%NOTFOUND then
2260          l_capitalize_interest_flag := 'N';
2261        end if;
2262        close cap_interest_rul_csr;
2263 
2264        if NVL(l_capitalize_interest_flag,'N') = 'N' then
2265 
2266          open chr_csr(p_chrv_id);
2267          fetch chr_csr into l_contract_number,l_start_date;
2268          close chr_csr;
2269 
2270          okl_interest_calc_pub.calc_interest_activate
2271              (p_api_version        => p_api_version,
2272               p_init_msg_list      => p_init_msg_list,
2273               x_return_status      => x_return_status,
2274               x_msg_count          => x_msg_count,
2275               x_msg_data           => x_msg_data,
2276               p_contract_number    => l_contract_number,
2277               p_Activation_date    => l_start_date,
2278               x_amount             => l_amount,
2279               x_source_id          => l_source_id);
2280 
2281           IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2282                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2283           ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2284                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2285           END IF;
2286        end if;
2287        -- Bug# 3541098 end.
2288 
2289 
2290     ---------------------------------------------------------------------------------------
2291     -- Subsidies enhancement : Check for expired subsidies and stop activation
2292     --                               Create billing transaction for 'BILL' subsidies
2293     ---------------------------------------------------------------------------------------
2294 
2295            l_subsidy_exists := OKL_API.G_FALSE;
2296            okl_subsidy_process_pvt.is_contract_subsidized
2297                              (p_api_version   => p_api_version,
2298                              p_init_msg_list => p_init_msg_list,
2299                              x_return_status => x_return_status,
2300                              x_msg_count     => x_msg_count,
2301                              x_msg_data      => x_msg_data,
2302                              p_chr_id        => p_chrv_id,
2303                              x_subsidized    => l_subsidy_exists);
2304            IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2305                    RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2306            ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2307                    RAISE Okl_Api.G_EXCEPTION_ERROR;
2308            END IF;
2309 
2310            IF l_subsidy_exists = OKL_API.G_TRUE THEN
2311              ---------------------------------------------------
2312              --check if expired subsidies exist for the contract
2313              ---------------------------------------------------
2314              l_subsidy_valid_status  := OKL_API.G_RET_STS_SUCCESS;
2315              OPEN l_subsidy_csr (p_chr_id => p_chrv_id);
2316              LOOP
2317                  FETCH l_subsidy_csr INTO l_subsidy_rec;
2318                  EXIT WHEN l_subsidy_csr%NOTFOUND;
2319                  l_applicable := 'N';
2320                    open l_cle_csr(p_subsidy_id   => l_subsidy_rec.subsidy_id,
2321                                 p_asset_cle_id => l_subsidy_rec.asset_id);
2322                    Fetch l_cle_csr into l_applicable;
2323                    If l_cle_csr%NOTFOUND then
2324                        Null;
2325                    End If;
2326                    close l_cle_csr;
2327 
2328                    If (l_applicable = 'N') then
2329                        Okl_Api.set_message(
2330                                p_app_name     => G_APP_NAME,
2331                                p_msg_name     => 'OKL_SUBSIDY_CRITERIA_MATCH',
2332                                p_token1       => 'SUBSIDY_NAME',
2333                                p_token1_value => l_subsidy_rec.subsidy_name,
2334                                p_token2       => 'ASSET_NUMBER',
2335                                p_token2_value => l_subsidy_rec.asset_number);
2336                        l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
2337                    end if;
2338 
2339                  --IF((l_subsidy_rec.effective_to_date + l_subsidy_rec.expire_after_days) < TRUNC(SYSDATE))THEN
2340                   if( TRUNC(sysdate) not between TRUNC(l_subsidy_rec.effective_from_date) and
2341                      TRUNC(nvl(l_subsidy_rec.EFFECTIVE_TO_DATE,sysdate) + nvl(l_subsidy_rec.EXPIRE_AFTER_DAYS,0)))then
2342                      OKL_API.Set_Message(p_app_name     => G_APP_NAME,
2343                                        p_msg_name     => 'OKL_SUBSIDY_EXPIRED',
2344                                        p_token1       => 'SUBSIDY',
2345                                        p_token1_value => l_subsidy_rec.subsidy_name,
2346                                        p_token2       => 'ASSET_NUMBER',
2347                                        p_token2_value => l_subsidy_rec.asset_number);
2348                    l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
2349 
2350 
2351 
2352                  ELSE
2353                    /*
2354                     * added code for subsidy pools enhancement, the subsidy is checked for association
2355                     * with the subsidy pool, if associated, the authoring transaction api is invoked for
2356                     * validation and then create transaction. code logic being merged with subsidy expiration
2357                     * because only when subsidy is not expired and is associated with a pool, will the pool transaction occur.
2358                     * Further, it is not correct to indicate a validation failure on a subsidy pool transaction while the
2359                     * subsidy is actually exipred. START
2360                     */
2361                    IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2362                      okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'verifying subsidy applicability over pool subsidy id '||l_subsidy_rec.subsidy_id);
2363                    END IF;
2364 
2365                    l_sub_pool_applicable := okl_asset_subsidy_pvt.is_sub_assoc_with_pool(p_subsidy_id => l_subsidy_rec.subsidy_id
2366                                                                                         ,x_subsidy_pool_id => lx_sub_pool_id
2367                                                                                         ,x_sub_pool_curr_code => lx_sub_pool_curr_code
2368                                                                                         );
2369 
2370                    IF(l_sub_pool_applicable = 'Y')THEN
2371                      -- initialize for every iteration of the loop
2372                      lv_subsidy_amount := 0;
2373                      -- the amount for transaction is either the override amount if present or the calculated subsidy amount
2374                      lv_subsidy_amount := NVL(l_subsidy_rec.subsidy_override_amount,NVL(l_subsidy_rec.subsidy_amount,0));
2375                      -- write to debug log
2376                      IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2377                        okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'pool applicable sub_pool_id '||lx_sub_pool_id||' amount '||lv_subsidy_amount);
2378                      END IF;
2379                      okl_subsidy_pool_auth_trx_pvt.create_pool_trx_khr_book(p_api_version   => p_api_version
2380                                                                            ,p_init_msg_list => p_init_msg_list
2381                                                                            ,x_return_status => x_return_status
2382                                                                            ,x_msg_count     => x_msg_count
2383                                                                            ,x_msg_data      => x_msg_data
2384                                                                            ,p_chr_id        => p_chrv_id
2385                                                                            ,p_asset_id      => l_subsidy_rec.asset_id
2386                                                                            ,p_subsidy_id    => l_subsidy_rec.subsidy_id
2387                                                                            ,p_subsidy_pool_id => lx_sub_pool_id
2388                                                                            ,p_trx_amount    => lv_subsidy_amount
2389                                                                            );
2390                      l_subsidy_valid_status := x_return_status;
2391                      IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2392                        okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'x_return_status being copied into l_subsidy_valid_status '||l_subsidy_valid_status
2393                                                 ||' x_msg_data '||x_msg_data
2394                                                );
2395                      END IF; -- end of write to debug log
2396                    END IF; -- end of l_sub_pool_applicable = 'Y'
2397                  END IF; -- end of (l_subsidy_rec.effective_to_date + l_subsidy_rec.expire_after_days) < TRUNC(SYSDATE)
2398                    /*
2399                     * added code for subsidy pools enhancement, the subsidy is checked for association
2400                     * with the subsidy pool, if associated, the authoring transaction api is invoked for
2401                     * validation and then create transaction. END
2402                     */
2403              END LOOP;
2404              CLOSE l_subsidy_csr;
2405 
2406              x_return_status := l_subsidy_valid_status;
2407 
2408                IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2409                        RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2410                ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2411                        RAISE Okl_Api.G_EXCEPTION_ERROR;
2412                END IF;
2413 
2414 
2415                --call process API to create Billing transactions for Subsidies ;
2416                OKL_SUBSIDY_PROCESS_PVT.CREATE_BILLING_TRX(
2417                              p_api_version   => p_api_version,
2418                              p_init_msg_list => p_init_msg_list,
2419                              x_return_status => x_return_status,
2420                              x_msg_count     => x_msg_count,
2421                              x_msg_data      => x_msg_data,
2422                              p_chr_id        => p_chrv_id);
2423 
2424                IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2425                        RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2426                ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2427                        RAISE Okl_Api.G_EXCEPTION_ERROR;
2428                END IF;
2429            End If;
2430 
2431          --call fa activation API
2432         Okl_Activate_Asset_Pub.ACTIVATE_ASSET(p_api_version   => p_api_version,
2433                                               p_init_msg_list => p_init_msg_list,
2434         	                                  x_return_status => x_return_status,
2435          	                                  x_msg_count     => x_msg_count,
2436           	 	                              x_msg_data      => x_msg_data,
2437            	                                  p_chrv_id       => p_chrv_id,
2438                                               p_call_mode     => p_call_mode,
2439                                               x_cimv_tbl      => l_cimv_tbl_fa);
2440 
2441     	IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2442        		RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2443     	ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2444        		RAISE Okl_Api.G_EXCEPTION_ERROR;
2445     	END IF;
2446 
2447         --Bug# 2726870 : 11.5.9 enhancment Service contracts integration
2448         --call service integration api :
2449         okl_service_integration_pub.initiate_service_booking(
2450                                     p_api_version    => p_api_version,
2451                                     p_init_msg_list  => p_init_msg_list,
2452                                     x_return_status  => x_return_status,
2453                                     x_msg_count      => x_msg_count,
2454                                     x_msg_data       => x_msg_data,
2455                                     p_okl_chr_id     => p_chrv_id);
2456 
2457     	IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2458        		RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2459     	ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2460        		RAISE Okl_Api.G_EXCEPTION_ERROR;
2461     	END IF;
2462 
2463     	--call ib activation API
2464     	Okl_Activate_Ib_Pub.ACTIVATE_IB_INSTANCE(p_api_version   => p_api_version,
2465      	                                         p_init_msg_list => p_init_msg_list,
2466       	                                         x_return_status => x_return_status,
2467        	                                         x_msg_count     => x_msg_count,
2468         	                                     x_msg_data      => x_msg_data,
2469                                                  p_chrv_id       => p_chrv_id,
2470                                                  p_call_mode     => p_call_mode,
2471                                                  x_cimv_tbl      => l_cimv_tbl_ib);
2472 
2473 	    IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2474   	      RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2475         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2476        		RAISE Okl_Api.G_EXCEPTION_ERROR;
2477     	END IF;
2478 
2479         --check if usage line is there on the contract
2480         l_usage_khr := '?';
2481         OPEN l_chk_usage_csr (p_chr_id => p_chrv_id);
2482         FETCH l_chk_usage_csr INTO l_usage_khr;
2483         IF l_chk_usage_csr%NOTFOUND THEN
2484            NULL;
2485         END IF;
2486         CLOSE l_chk_usage_csr;
2487 
2488         IF l_usage_khr = '!' THEN
2489             --call ubb api for service contracts creation
2490             okl_ubb_integration_pub.create_ubb_contract(
2491                           p_api_version   => p_api_version,
2492                           p_init_msg_list => p_init_msg_list,
2493                           x_return_status => x_return_status,
2494                           x_msg_count     => x_msg_count,
2495                           x_msg_data      => x_msg_data,
2496                           p_chr_id        => p_chrv_id,
2497                           x_chr_id        => l_service_chr_id
2498                          );
2499 
2500             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2501   	            RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2502             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2503        		    RAISE Okl_Api.G_EXCEPTION_ERROR;
2504     	    END IF;
2505         End If;
2506 
2507         -- call the asset release api
2508         okl_activate_asset_pub.RELEASE_ASSET
2509                         (p_api_version   => p_api_version,
2510                          p_init_msg_list => p_init_msg_list,
2511                          x_return_status => x_return_status,
2512                          x_msg_count     => x_msg_count,
2513                          x_msg_data      => x_msg_data,
2514                          p_rel_chr_id    => p_chrv_id);
2515 
2516         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2517             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2518         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2519             RAISE Okl_Api.G_EXCEPTION_ERROR;
2520         END IF;
2521 
2522         --call the install base instance re_lease API
2523         okl_activate_ib_pvt.RELEASE_IB_INSTANCE
2524                         (p_api_version   => p_api_version,
2525                          p_init_msg_list => p_init_msg_list,
2526                          x_return_status => x_return_status,
2527                          x_msg_count     => x_msg_count,
2528                          x_msg_data      => x_msg_data,
2529                          p_rel_chr_id    => p_chrv_id);
2530 
2531         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2532             RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2533         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2534             RAISE Okl_Api.G_EXCEPTION_ERROR;
2535         END IF;
2536 
2537         --code added to update status in OKL_ASSET_RETURNS_B
2538         --after the release asset transaction has been processed
2539         OPEN l_asr_csr(p_chrv_id);
2540         LOOP
2541             FETCH l_asr_csr into l_asr_rec;
2542             EXIT When l_asr_csr%NOTFOUND;
2543             l_artv_rec.id := l_asr_rec.asset_return_id;
2544             l_artv_rec.ars_code := 'CANCELLED';
2545             l_artv_rec.like_kind_yn := 'N';
2546             --call to change the release asset status to 'CANCELLED' in asset return
2547             okl_asset_returns_pub.update_asset_returns(
2548                      p_api_version    => p_api_version
2549                     ,p_init_msg_list  => p_init_msg_list
2550                     ,x_return_status  => x_return_status
2551                     ,x_msg_count      => x_msg_count
2552                     ,x_msg_data       => x_msg_data
2553                     ,p_artv_rec       => l_artv_rec
2554                     ,x_artv_rec       => lx_artv_rec);
2555 
2556             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2557                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2558             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2559                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2560             END IF;
2561         END LOOP;
2562         CLOSE l_asr_csr;
2563         --End:In case of a mixed contract
2564        -- Bug# 15992711 End of Modifications
2565     ELSE
2566         --bug# 2953906 :
2567          --check for billto status
2568         Validate_bill_To(p_chr_id        => p_chrv_id,
2569                          x_return_status => x_return_status);
2570 
2571         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2572                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2573         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2574                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2575         END IF;
2576         --bug # 2953906 end.
2577 
2578        -------------------------------------------------------------------------
2579         --Bug# 3541098: If Capitalize interest flag is set to 'NO', then
2580         --              calculate interest on pre-funding amount upto the
2581         --              booking date of the contract and create
2582         --              Billing transaction for the interest amount.
2583         ------------------------------------------------------------------------
2584        open cap_interest_rul_csr (p_chrv_id);
2585        fetch cap_interest_rul_csr  into l_capitalize_interest_flag;
2586        if cap_interest_rul_csr%NOTFOUND then
2587          l_capitalize_interest_flag := 'N';
2588        end if;
2589        close cap_interest_rul_csr;
2590 
2591        if NVL(l_capitalize_interest_flag,'N') = 'N' then
2592 
2593          open chr_csr(p_chrv_id);
2594          fetch chr_csr into l_contract_number,l_start_date;
2595          close chr_csr;
2596 
2597          okl_interest_calc_pub.calc_interest_activate
2598              (p_api_version        => p_api_version,
2599               p_init_msg_list      => p_init_msg_list,
2600               x_return_status      => x_return_status,
2601               x_msg_count          => x_msg_count,
2602               x_msg_data           => x_msg_data,
2603               p_contract_number    => l_contract_number,
2604               p_Activation_date    => l_start_date,
2605               x_amount             => l_amount,
2606               x_source_id          => l_source_id);
2607 
2608           IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2609                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2610           ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2611                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2612           END IF;
2613        end if;
2614        -- Bug# 3541098 end.
2615 
2616         ---------------------------------------------------------------------------------------
2617         --Bug# 3143522: Subsidies enhancement : Check for expired subsidies and stop activation
2618         --                               Create billing transaction for 'BILL' subsidies
2619         ---------------------------------------------------------------------------------------
2620         l_subsidy_exists := OKL_API.G_FALSE;
2621         okl_subsidy_process_pvt.is_contract_subsidized
2622                           (p_api_version   => p_api_version,
2623                           p_init_msg_list => p_init_msg_list,
2624                           x_return_status => x_return_status,
2625                           x_msg_count     => x_msg_count,
2626                           x_msg_data      => x_msg_data,
2627                           p_chr_id        => p_chrv_id,
2628                           x_subsidized    => l_subsidy_exists);
2629         IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2630                 RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2631         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2632                 RAISE Okl_Api.G_EXCEPTION_ERROR;
2633         END IF;
2634 
2635         IF l_subsidy_exists = OKL_API.G_TRUE THEN
2636           ---------------------------------------------------
2637           --check if expired subsidies exist for the contract
2638           ---------------------------------------------------
2639           l_subsidy_valid_status  := OKL_API.G_RET_STS_SUCCESS;
2640           OPEN l_subsidy_csr (p_chr_id => p_chrv_id);
2641           LOOP
2642               FETCH l_subsidy_csr INTO l_subsidy_rec;
2643               EXIT WHEN l_subsidy_csr%NOTFOUND;
2644               --Start : Bug 6050165 : prasjain
2645                 l_applicable := 'N';
2646                   open l_cle_csr(p_subsidy_id   => l_subsidy_rec.subsidy_id,
2647                                p_asset_cle_id => l_subsidy_rec.asset_id);
2648                   Fetch l_cle_csr into l_applicable;
2649                   If l_cle_csr%NOTFOUND then
2650                       Null;
2651                   End If;
2652                   close l_cle_csr;
2653 
2654                   If (l_applicable = 'N') then
2655                       Okl_Api.set_message(
2656                               p_app_name     => G_APP_NAME,
2657                               p_msg_name     => 'OKL_SUBSIDY_CRITERIA_MATCH',
2658                               p_token1       => 'SUBSIDY_NAME',
2659                               p_token1_value => l_subsidy_rec.subsidy_name,
2660                               p_token2       => 'ASSET_NUMBER',
2661                               p_token2_value => l_subsidy_rec.asset_number);
2662                       l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
2663                   end if;
2664 
2665                 --IF((l_subsidy_rec.effective_to_date + l_subsidy_rec.expire_after_days) < TRUNC(SYSDATE))THEN
2666                  if( TRUNC(sysdate) not between TRUNC(l_subsidy_rec.effective_from_date) and
2667                     TRUNC(nvl(l_subsidy_rec.EFFECTIVE_TO_DATE,sysdate) + nvl(l_subsidy_rec.EXPIRE_AFTER_DAYS,0)))then
2668                --End : Bug 6050165 : prasjain
2669                 OKL_API.Set_Message(p_app_name     => G_APP_NAME,
2670                                     p_msg_name     => 'OKL_SUBSIDY_EXPIRED',
2671                                     p_token1       => 'SUBSIDY',
2672                                     p_token1_value => l_subsidy_rec.subsidy_name,
2673                                     p_token2       => 'ASSET_NUMBER',
2674                                     p_token2_value => l_subsidy_rec.asset_number);
2675                 l_subsidy_valid_status := OKL_API.G_RET_STS_ERROR;
2676               ELSE
2677                 /*
2678                  * sjalasut added code for subsidy pools enhancement, the subsidy is checked for association
2679                  * with the subsidy pool, if associated, the authoring transaction api is invoked for
2680                  * validation and then create transaction. code logic being merged with subsidy expiration
2681                  * because only when subsidy is not expired and is associated with a pool, will the pool transaction occur.
2682                  * Further, it is not correct to indicate a validation failure on a subsidy pool transaction while the
2683                  * subsidy is actually exipred. START
2684                  */
2685                 IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2686                   okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'verifying subsidy applicability over pool subsidy id '||l_subsidy_rec.subsidy_id);
2687                 END IF;
2688 
2689                 l_sub_pool_applicable := okl_asset_subsidy_pvt.is_sub_assoc_with_pool(p_subsidy_id => l_subsidy_rec.subsidy_id
2690                                                                                      ,x_subsidy_pool_id => lx_sub_pool_id
2691                                                                                      ,x_sub_pool_curr_code => lx_sub_pool_curr_code
2692                                                                                      );
2693 
2694                 IF(l_sub_pool_applicable = 'Y')THEN
2695                   -- initialize for every iteration of the loop
2696                   lv_subsidy_amount := 0;
2697                   -- the amount for transaction is either the override amount if present or the calculated subsidy amount
2698                   lv_subsidy_amount := NVL(l_subsidy_rec.subsidy_override_amount,NVL(l_subsidy_rec.subsidy_amount,0));
2699                   -- write to debug log
2700                   IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2701                     okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'pool applicable sub_pool_id '||lx_sub_pool_id||' amount '||lv_subsidy_amount);
2702                   END IF;
2703                   okl_subsidy_pool_auth_trx_pvt.create_pool_trx_khr_book(p_api_version   => p_api_version
2704                                                                         ,p_init_msg_list => p_init_msg_list
2705                                                                         ,x_return_status => x_return_status
2706                                                                         ,x_msg_count     => x_msg_count
2707                                                                         ,x_msg_data      => x_msg_data
2708                                                                         ,p_chr_id        => p_chrv_id
2709                                                                         ,p_asset_id      => l_subsidy_rec.asset_id
2710                                                                         ,p_subsidy_id    => l_subsidy_rec.subsidy_id
2711                                                                         ,p_subsidy_pool_id => lx_sub_pool_id
2712                                                                         ,p_trx_amount    => lv_subsidy_amount
2713                                                                         );
2714                   l_subsidy_valid_status := x_return_status;
2715                   IF(NVL(l_debug_enabled,'N')='Y' AND is_debug_statement_on) THEN
2716                     okl_debug_pub.log_debug( FND_LOG.LEVEL_STATEMENT, l_module, 'x_return_status being copied into l_subsidy_valid_status '||l_subsidy_valid_status
2717                                              ||' x_msg_data '||x_msg_data
2718                                             );
2719                   END IF; -- end of write to debug log
2720                 END IF; -- end of l_sub_pool_applicable = 'Y'
2721               END IF; -- end of (l_subsidy_rec.effective_to_date + l_subsidy_rec.expire_after_days) < TRUNC(SYSDATE)
2722                 /*
2723                  * sjalasut added code for subsidy pools enhancement, the subsidy is checked for association
2724                  * with the subsidy pool, if associated, the authoring transaction api is invoked for
2725                  * validation and then create transaction. END
2726                  */
2727           END LOOP;
2728           CLOSE l_subsidy_csr;
2729 
2730           x_return_status := l_subsidy_valid_status;
2731 
2732             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2733                     RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2734             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2735                     RAISE Okl_Api.G_EXCEPTION_ERROR;
2736             END IF;
2737 
2738 
2739 
2740 
2741             --call process API to create Billing transactions for Subsidies ;
2742             OKL_SUBSIDY_PROCESS_PVT.CREATE_BILLING_TRX(
2743                           p_api_version   => p_api_version,
2744                           p_init_msg_list => p_init_msg_list,
2745                           x_return_status => x_return_status,
2746                           x_msg_count     => x_msg_count,
2747                           x_msg_data      => x_msg_data,
2748                           p_chr_id        => p_chrv_id);
2749 
2750             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2751                     RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2752             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2753                     RAISE Okl_Api.G_EXCEPTION_ERROR;
2754             END IF;
2755         End If;
2756         -------------------------------------------------------------------------
2757         --Bug#i 3143522 : End Subsidies enhancement
2758         -------------------------------------------------------------------------
2759 
2760          --call fa activation API
2761         Okl_Activate_Asset_Pub.ACTIVATE_ASSET(p_api_version   => p_api_version,
2762                                               p_init_msg_list => p_init_msg_list,
2763         	                                  x_return_status => x_return_status,
2764          	                                  x_msg_count     => x_msg_count,
2765           	 	                              x_msg_data      => x_msg_data,
2766            	                                  p_chrv_id       => p_chrv_id,
2767                                               p_call_mode     => p_call_mode,
2768                                               x_cimv_tbl      => l_cimv_tbl_fa);
2769 
2770     	IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2771        		RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2772     	ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2773        		RAISE Okl_Api.G_EXCEPTION_ERROR;
2774     	END IF;
2775 
2776         --Bug# 2726870 : 11.5.9 enhancment Service contracts integration
2777         --call service integration api :
2778         okl_service_integration_pub.initiate_service_booking(
2779                                     p_api_version    => p_api_version,
2780                                     p_init_msg_list  => p_init_msg_list,
2781                                     x_return_status  => x_return_status,
2782                                     x_msg_count      => x_msg_count,
2783                                     x_msg_data       => x_msg_data,
2784                                     p_okl_chr_id     => p_chrv_id);
2785 
2786     	IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2787        		RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2788     	ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2789        		RAISE Okl_Api.G_EXCEPTION_ERROR;
2790     	END IF;
2791 
2792     	--call ib activation API
2793     	Okl_Activate_Ib_Pub.ACTIVATE_IB_INSTANCE(p_api_version   => p_api_version,
2794      	                                         p_init_msg_list => p_init_msg_list,
2795       	                                         x_return_status => x_return_status,
2796        	                                         x_msg_count     => x_msg_count,
2797         	                                     x_msg_data      => x_msg_data,
2798                                                  p_chrv_id       => p_chrv_id,
2799                                                  p_call_mode     => p_call_mode,
2800                                                  x_cimv_tbl      => l_cimv_tbl_ib);
2801 
2802 	    IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2803   	      RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2804         ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2805        		RAISE Okl_Api.G_EXCEPTION_ERROR;
2806     	END IF;
2807 
2808         --check if usage line is there on the contract
2809         l_usage_khr := '?';
2810         OPEN l_chk_usage_csr (p_chr_id => p_chrv_id);
2811         FETCH l_chk_usage_csr INTO l_usage_khr;
2812         IF l_chk_usage_csr%NOTFOUND THEN
2813            NULL;
2814         END IF;
2815         CLOSE l_chk_usage_csr;
2816 
2817         IF l_usage_khr = '!' THEN
2818             --call ubb api for service contracts creation
2819             okl_ubb_integration_pub.create_ubb_contract(
2820                           p_api_version   => p_api_version,
2821                           p_init_msg_list => p_init_msg_list,
2822                           x_return_status => x_return_status,
2823                           x_msg_count     => x_msg_count,
2824                           x_msg_data      => x_msg_data,
2825                           p_chr_id        => p_chrv_id,
2826                           x_chr_id        => l_service_chr_id
2827                          );
2828 
2829             IF (x_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
2830   	            RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
2831             ELSIF (x_return_status = Okl_Api.G_RET_STS_ERROR) THEN
2832        		    RAISE Okl_Api.G_EXCEPTION_ERROR;
2833     	    END IF;
2834         End If;
2835 
2836     END IF;
2837 
2838 	  -- added update of okl_stream_trx_data.last_trx_state value
2839 	  -- racheruv
2840 
2841       if l_rbk_khr = '!' then
2842 	    l_contract_id := l_orig_khr_id;
2843       else
2844 	    l_contract_id := p_chrv_id;
2845 	  end if;
2846 
2847 	  okl_streams_util.update_trx_state(l_contract_id, 'BOTH');
2848 
2849 	  -- end update of okl_stream_trx_data.last_trx_state value
2850 
2851 	    Okl_Api.END_ACTIVITY (x_msg_count,x_msg_data );
2852 
2853     EXCEPTION
2854     WHEN Okl_Api.G_EXCEPTION_ERROR THEN
2855     x_return_status := Okl_Api.HANDLE_EXCEPTIONS(
2856                                l_api_name,
2857                                G_PKG_NAME,
2858                                'OKL_API.G_RET_STS_ERROR',
2859                                x_msg_count,
2860                                x_msg_data,
2861                                '_PUB');
2862     WHEN Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR THEN
2863 	--dbms_output.put_line('Unexpected Error Routine');
2864     x_return_status :=Okl_Api.HANDLE_EXCEPTIONS(
2865                               l_api_name,
2866                               G_PKG_NAME,
2867                               'Okl_Api.G_RET_STS_UNEXP_ERROR',
2868                               x_msg_count,
2869                               x_msg_data,
2870                               '_PUB');
2871 	--dbms_output.put_line('2 Unexpected Error Routine');
2872     WHEN OTHERS THEN
2873     x_return_status :=Okl_Api.HANDLE_EXCEPTIONS(
2874                               l_api_name,
2875                               G_PKG_NAME,
2876                               'OTHERS',
2877                               x_msg_count,
2878                               x_msg_data,
2879                               '_PUB');
2880 END ACTIVATE_CONTRACT;
2881 END OKL_ACTIVATE_CONTRACT_PUB;