DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKL_SLA_ACC_SOURCES_PVT

Source


1 PACKAGE BODY okl_sla_acc_sources_pvt AS
2 /*$Header: OKLRSLAB.pls 120.41.12020000.3 2012/12/19 10:50:47 racheruv ship $*/
3 
4   -- Package level variables
5   G_MODULE                  CONSTANT  VARCHAR2(255):= 'LEASE.ACCOUNTING.SOURCES.OKL_SLA_ACC_SOURCES_PVT';
6   G_DEBUG_ENABLED           CONSTANT  VARCHAR2(10) := OKL_DEBUG_PUB.CHECK_LOG_ENABLED;
7   G_IS_DEBUG_STATEMENT_ON             BOOLEAN;
8   G_REPRESENTATION_TYPE               VARCHAR2(20);
9   --------------------------------------------------------------------------------
10   -- Common Cursor definitions.
11   --------------------------------------------------------------------------------
12   -- Cursor to fetch the Ledger Language
13   CURSOR c_ledger_lang_csr(p_ledger_id   NUMBER)
14   IS
15     SELECT  DISTINCT NVL(led.sla_description_language, USERENV('LANG')) language_code
16       FROM  gl_ledgers              led
17            ,xla_ledger_options      lopt
18            ,gl_ledger_relationships led_rel
19     WHERE  led.ledger_category_code in ('PRIMARY', 'SECONDARY')
20       AND  led_rel.target_ledger_category_code in ('PRIMARY', 'SECONDARY')
21       AND  led.ledger_id = lopt.ledger_id
22       AND  lopt.enabled_flag = 'Y'
23       AND  lopt.application_id = 540
24       AND  led.ledger_id = led_rel.target_ledger_id
25       AND  led_rel.primary_ledger_id = p_ledger_id;
26 
27   CURSOR c_org_name_csr( p_org_id NUMBER, p_ledger_lang VARCHAR2 )
28   IS
29     SELECT  htl.NAME org_name
30       FROM  HR_ALL_ORGANIZATION_UNITS_TL htl
31      WHERE htl.organization_id = p_org_id
32        AND htl.LANGUAGE = p_ledger_lang;
33   CURSOR c_org_name_code_csr( p_org_id NUMBER )
34   IS
35     SELECT  ht.NAME org_name
36       FROM  hr_all_organization_units ht
37      WHERE ht.organization_id = p_org_id;
38 
39   -- Cursor to fetch basic Contract Attributes
40   CURSOR  c_khr_attributes_csr  (l_khr_id NUMBER)
41   IS
42     SELECT   khr.khr_id                              khr_khr_id
43             ,chr.cust_acct_id                        cust_acct_id
44             ,chr.contract_number                     contract_number
45             ,chr.currency_code                       currency_code
46             ,chr.START_DATE                          start_date
47             ,chr.bill_to_site_use_id                 bill_to_site_use_id
48             ,chr.orig_system_reference1              orig_system_reference1
49             ,khr.assignable_yn                       assignable_yn
50             ,chr.authoring_org_id                    authoring_org_id
51             ,khr.converted_account_yn                converted_account_yn
52             ,khr.generate_accrual_override_yn        generate_accrual_override_yn
53             ,chr.cust_po_number                      cust_po_number
54             ,chr.sts_code                            sts_code
55             ,hr_org.NAME                             hr_org_name
56             ,khr.pdt_id                              pdt_id
57             ,chr.scs_code                            scs_code
58       FROM   okc_k_headers_all_b         chr
59             ,okl_k_headers               khr
60             ,hr_all_organization_units   hr_org
61      WHERE  khr.id =  l_khr_id
62        AND  chr.id = khr.id
63        AND  hr_org.organization_id = chr.authoring_org_id;
64 
65   -- Use this cursor to fetch the Lesses DFF Information.
66   CURSOR c_kpl_attributes_csr (l_khr_id NUMBER)
67   IS
68     SELECT   kpl.attribute_category
69             ,kpl.attribute1
70             ,kpl.attribute2
71             ,kpl.attribute3
72             ,kpl.attribute4
73             ,kpl.attribute5
74             ,kpl.attribute6
75             ,kpl.attribute7
76             ,kpl.attribute8
77             ,kpl.attribute9
78             ,kpl.attribute10
79             ,kpl.attribute11
80             ,kpl.attribute12
81             ,kpl.attribute13
82             ,kpl.attribute14
83             ,kpl.attribute15
84       FROM   okl_k_party_roles    kpl
85             ,okc_k_party_roles_b  cplb
86      WHERE  cplb.chr_id =  l_khr_id
87        AND  cplb.dnz_chr_id = cplb.chr_id
88        AND  kpl.id = cplb.id
89        AND  cplb.rle_code = 'LESSEE';
90 
91   -- Use this cursor to fetch the RRB and ICM values of a particular product
92   CURSOR c_rev_rec_int_calc_methods_csr (l_pdt_id NUMBER)
93   IS
94     SELECT  rrb_qve.value  rev_rec_method_code
95            ,icm_qve.value int_calc_method_code
96       FROM  okl_pdt_qualitys  icm_pqy
97            ,okl_pdt_pqy_vals  icm_pqv
98            ,okl_pqy_values    icm_qve
99            ,okl_pdt_qualitys  rrb_pqy
100            ,okl_pdt_pqy_vals  rrb_pqv
101            ,okl_pqy_values    rrb_qve
102      WHERE  icm_pqv.pdt_id = l_pdt_id
103        AND  icm_pqv.qve_id = icm_qve.id
104        AND  icm_qve.pqy_id = icm_pqy.id
105        AND  icm_pqy.name   = 'INTEREST_CALCULATION_BASIS'
106        AND  rrb_pqv.pdt_id = l_pdt_id
107        AND  rrb_pqv.qve_id = rrb_qve.id
108        AND  rrb_qve.pqy_id = rrb_pqy.id
109        AND  rrb_pqy.name   = 'REVENUE_RECOGNITION_METHOD';
110 
111   -- Cursor to fetch the Investor Agreement Details provided the
112   --  Contract ID and RENT/RESIDUAL stream type
113   CURSOR c_investor_agreement_main_csr(p_khr_id NUMBER, p_sty_type VARCHAR2)
114   IS
115     SELECT
116        ia_chr.id               ia_chr_id
117       ,ia_chr.contract_number  ia_contract_number
118       ,ia_chr.START_DATE       ia_start_date
119       ,ia_pdt.NAME             ia_product_name
120       FROM  okl_pool_contents   ia_pool_c
121            ,okc_k_headers_all_b ia_chr
122            ,okl_k_headers       ia_khr
123            ,okl_products        ia_pdt
124            ,okl_pools_all       ia_pool
125      WHERE  ia_pool_c.sty_code  =  p_sty_type
126        AND  ia_pool_c.pol_id = ia_pool.id
127        AND  ia_pool.khr_id = ia_chr.id
128        AND  ia_chr.scs_code  = G_INVESTOR
129        AND  ia_chr.id = ia_khr.id
130        AND  ia_pdt.id = ia_khr.pdt_id
131        AND  ia_chr.id = ia_khr.id
132        AND  ia_pool_c.khr_id = p_khr_id
133        AND  ia_pool_c.status_code <> Okl_Pool_Pvt.G_POC_STS_PENDING ; --Added by VARANGAN -Pool Contents Impact(Bug#6658065)
134   -- Cursor to fetch IA Accounting Code setup in Terms and Conditions..
135   CURSOR c_investor_agree_acc_code_csr (l_rent_ia_chr_id NUMBER, l_res_ia_chr_id NUMBER)
136   IS
137     SELECT
138         DECODE(ia_rule.dnz_chr_id,l_rent_ia_chr_id, ia_rule.rule_information1,NULL) rent_ia_accounting_code
139        ,DECODE(ia_rule.dnz_chr_id,l_res_ia_chr_id,ia_rule.rule_information1,NULL)   res_ia_accounting_code
140       FROM  okc_rules_b        ia_rule
141            ,okc_rule_groups_b  ia_rule_groups
142      WHERE  ia_rule.rgp_id                    = ia_rule_groups.id
143        AND ia_rule.dnz_chr_id  IN (l_rent_ia_chr_id, l_res_ia_chr_id)
144        AND ia_rule_groups.rgd_code           = 'LASEAC'
145        AND ia_rule.rule_information_category = 'LASEAC';
146 
147   -- Cursor to fetch the Customer Name and Account Number details
148   -- Modifed by zrehman Bug#6707320 for Party Merge impact on transaction sources tables
149   CURSOR c_cust_name_account_csr (l_khr_id NUMBER,l_cust_acct_id NUMBER )
150   IS
151     SELECT   cust_party.party_name
152             ,cust_party.party_id
153             ,cust_accounts.account_number
154     FROM   okc_k_party_roles_b  cust_party_roles
155             ,hz_parties           cust_party
156             ,hz_cust_accounts     cust_accounts
157      WHERE  cust_party.party_type in ( 'PERSON','ORGANIZATION')
158        AND  cust_party.party_id = cust_party_roles.object1_id1
159        AND  '#' = cust_party_roles.object1_id2
160        AND  cust_party_roles.jtot_object1_code = 'OKX_PARTY'
161        AND  cust_party_roles.rle_code = 'LESSEE'
162        AND  cust_party_roles.chr_id = l_khr_id
163        AND  cust_party_roles.dnz_chr_id = l_khr_id
164        AND  cust_accounts.cust_account_id = l_cust_acct_id;
165 
166   -- Cursor to fetch the Active Insurance policy details
167   CURSOR c_insurance_csr (l_khr_id NUMBER)
168   IS
169     SELECT   ins.policy_number
170             ,ins.ipe_code
171       FROM   okl_ins_policies_all_b ins
172      WHERE  ins.khr_id   = l_khr_id
173        AND  ins.ipy_type = 'LEASE_POLICY'
174        AND  ins.quote_yn = 'N'
175        AND  ins.iss_code = 'ACTIVE';
176 
177   -- Cursor to fetch the Sales Representative Name using the AGS PK ...
178   CURSOR c_sales_rep_acc_sources_csr (p_jtf_sales_rep_pk NUMBER)
179   IS
180     SELECT  rep.name
181       FROM  jtf_rs_salesreps_mo_v rep
182      WHERE  salesrep_id = p_jtf_sales_rep_pk;
183 
184   -- Cursor to fetch the Sales Representative Details
185   CURSOR c_sales_rep_csr (l_khr_id NUMBER)
186   IS
187     SELECT   rep.name
188       FROM   okc_contacts    contact
189             ,okx_salesreps_v rep
190      WHERE  contact.DNZ_CHR_ID = l_khr_id
191        AND  rep.id1 = contact.object1_id1
192        AND  rep.id2 = contact.object1_id2;
193 
194   -- Cursor to fetch the Credit Line and Master Lease Details
195   CURSOR c_creditline_master_lease_csr (l_khr_id NUMBER)
196   IS
197     SELECT    chr_cr_master.scs_code     CHR_TYPE
198              ,decode(chr_cr_master.scs_code,'CREDITLINE_CONTRACT'
199                    ,chr_cr_master.contract_number, NULL)  credit_line_number
200             ,decode(chr_cr_master.scs_code,'MASTER_LEASE'
201                    ,chr_cr_master.contract_number, NULL)  master_lease_number
202             ,decode(chr_cr_master.scs_code,'MASTER_LEASE'
203                    ,chr_cr_master.id, TO_NUMBER(NULL))    master_lease_id
204       FROM   okc_k_headers_all_b chr_cr_master
205             ,okc_governances     governances
206      WHERE  governances.dnz_chr_id = l_khr_id
207        AND  governances.chr_id_referred = chr_cr_master.ID
208        AND  chr_cr_master.scs_code in  ('CREDITLINE_CONTRACT', 'MASTER_LEASE');
209 
210   -- Sometimes credit line may be associated with Master Lease instead with a contract
211   CURSOR c_creditline_sub_csr (l_mla_chr_id NUMBER)
212   IS
213     SELECT   crline_sub_chr.contract_number
214       FROM  okc_k_headers_all_b   crline_sub_chr
215            ,okc_governances       crline_gov
216      WHERE  crline_gov.dnz_chr_id = l_mla_chr_id
217        AND  crline_gov.chr_id_referred = crline_sub_chr.id
218        AND  crline_sub_chr.scs_code = 'CREDITLINE_CONTRACT';
219 
220   -- Cursor to fetch the Vendor Program Agreement Number
221   CURSOR c_vendor_program_number_csr (p_khr_id NUMBER)
222   IS
223     SELECT   vp_chr.contract_number
224       FROM   okc_k_headers_all_b   vp_chr
225             ,okl_k_headers         khr
226      WHERE  vp_chr.id = khr.khr_id
227        AND  vp_chr.scs_code = 'PROGRAM'
228        AND  khr.id = p_khr_id;
229 
230   -- Use this cursor to fetch the meaning of the of the Contract Status
231   CURSOR c_get_status_meaning_csr( p_sts_code VARCHAR2, p_led_lang  VARCHAR2)
232   IS
233     SELECT   status.meaning       status_meaning
234       FROM   okc_statuses_tl      status
235      WHERE  status.code     = p_sts_code
236        AND  status.language = p_led_lang;
237 
238   -- Cursor to fetch the Transaction type in the ledger language.
239   CURSOR  c_trx_type_name_csr( p_try_id NUMBER, p_led_lang VARCHAR2 )
240   IS
241     SELECT  try_tl.NAME          transaction_type_name
242            ,try_b.trx_type_class trx_type_class_code
243       FROM  okl_trx_types_tl try_tl
244            ,okl_trx_types_b  try_b
245      WHERE  try_tl.id       = p_try_id
246        AND  TRY_B.ID = try_tl.id
247        AND  try_tl.language = p_led_lang;
248 
249   -- Cursor to fetch the Contract Id from the OKL_TXL_ASSETS table.
250   CURSOR c_tas_khr_id_csr( p_source_id  okl_trx_assets.id%TYPE )
251   IS
252     SELECT DISTINCT tal.dnz_khr_id  khr_id
253              ,kle_id                kle_id
254       FROM   okl_trx_assets    tas
255             ,okl_txl_assets_b  tal
256      WHERE  tal.tas_id = tas.id
257        AND  tas.id = p_source_id;
258 
259   -- Cursor to fetch the Contract Id from the OKL_TXL_ASSETS table.
260   CURSOR c_tal_khr_id_csr( p_source_id  okl_txl_assets_b.id%TYPE )
261   IS
262     SELECT    tal.dnz_khr_id  khr_id
263              ,tal.kle_id      kle_id
264       FROM   okl_txl_assets_b  tal
265      WHERE  tal.id = p_source_id;
266 
267   -- Cursor to fetch the Contract Line Information
268   CURSOR c_k_lines_csr (p_kle_id NUMBER)
269   IS
270     SELECT   cleb.line_number
271             ,kle.fee_type
272             ,DECODE(cleb.lse_id,
273               33,    clet.name,  -- For FREE_FORM1 Asset
274               NULL)  asset_number
275             ,kle.date_delivery_expected
276             ,decode(cleb.lse_id,
277               33, 'FREE_FORM1',  -- Asset
278               1,  'SERVICE',     -- Service
279               48, 'SERVICE',
280               52, 'FEE',         -- Fee
281               NULL)  contract_line_type
282       FROM   okc_k_lines_b  cleb
283             ,okl_k_lines  kle
284             ,okc_k_lines_tl clet
285      WHERE  cleb.id = p_kle_id
286        AND  kle.id  = cleb.id
287        AND  cleb.id = clet.id
288        AND  clet.language = USERENV('LANG');
289 
290 
291   -- Cursor to fetch the vendor details along with the Line Number
292   CURSOR c_vendor_name_csr (p_kle_id NUMBER, p_khr_id NUMBER)
293   IS
294     SELECT   pov.vendor_id
295             ,pov.vendor_name
296       FROM   okc_k_lines_b       cleb_vendor
297             ,po_vendors          pov
298             ,okc_k_party_roles_b pty
299      WHERE  cleb_vendor.cle_id     = p_kle_id
300        AND  cleb_vendor.dnz_chr_id = p_khr_id
301        AND  cleb_vendor.lse_id     = 34
302        AND  pty.cle_id             = cleb_vendor.id
303        AND  pty.rle_code           = 'OKL_VENDOR'
304        AND  pty.dnz_chr_id         = p_khr_id
305        AND  pov.vendor_id          = pty.object1_id1;
306 
307   -- Cursor to fetch the Asset Installed Site
308   CURSOR  c_installed_site_csr (p_kle_id NUMBER, p_khr_id NUMBER)
309   IS
310     SELECT hl.location_id installed_site_id
311       FROM hz_locations hl,
312           hz_party_sites hps,
313           csi_item_instances csi,
314           okc_k_items cim_ib,
315           okc_k_lines_b cle_ib,
316           okc_k_lines_b cle_inst,
317           okc_k_lines_b cle_fin
318     WHERE cle_fin.cle_id is null
319       AND cle_fin.chr_id = cle_fin.dnz_chr_id
320       AND cle_fin.lse_id = 33
321       AND cle_inst.cle_id = cle_fin.id
322       AND cle_inst.dnz_chr_id = cle_fin.dnz_chr_id
323       AND cle_inst.lse_id = 43
324       AND cle_ib.cle_id = cle_inst.id
325       AND cle_ib.dnz_chr_id = cle_inst.dnz_chr_id
326       AND cle_ib.lse_id = 45
327       AND cim_ib.cle_id = cle_ib.id
328       AND cim_ib.dnz_chr_id = cle_ib.dnz_chr_id
329       AND cim_ib.object1_id1 = csi.instance_id
330       AND cim_ib.object1_id2 = '#'
331       AND cim_ib.jtot_object1_code = 'OKX_IB_ITEM'
332       AND csi.install_location_id = hps.party_site_id
333       AND csi.install_location_type_code = 'HZ_PARTY_SITES'
334       AND hps.location_id = hl.location_id
335       AND cle_fin.dnz_chr_id = p_khr_id
336       AND cle_fin.id = p_kle_id;
337 
338   -- Cursor to fetch the Inventory Item Name
339   CURSOR c_inventory_item_name_csr (p_inventory_item_id_pk1 VARCHAR2
340                                    ,p_inventory_org_id_pk2  VARCHAR2
341                                    ,p_ledger_language       VARCHAR2)
342   IS
343     SELECT   msitl.description      description
344             ,msitb.description      b_description
345       FROM   mtl_system_items_tl msitl
346             ,mtl_system_items_b  msitb
347      WHERE   msitl.inventory_item_id = p_inventory_item_id_pk1
348        AND   msitl.organization_id   = p_inventory_org_id_pk2
349        AND   msitl.inventory_item_id = msitb.inventory_item_id
350        AND   msitl.organization_id = msitb.organization_id
351        AND   msitl.LANGUAGE          = p_ledger_language;
352 
353   CURSOR c_inventory_org_id_csr( p_khr_id NUMBER )
354   IS
355     SELECT  khr.inv_organization_id    inv_organization_id
356            ,hrb.NAME                   hrb_name
357       FROM  okc_k_headers_all_b        khr
358            ,hr_all_organization_units  hrb
359      WHERE  khr.id = p_khr_id
360        AND  hrb.organization_id = khr.inv_organization_id;
361 
362   CURSOR c_khr_to_ledger_id_csr( p_khr_id NUMBER )
363   IS
364     SELECT  set_of_books_id       ledger_id
365       FROM  okl_sys_acct_opts_all sysop
366            ,okc_k_headers_all_b   cntrct
367      WHERE  cntrct.id = p_khr_id
368        AND  cntrct.authoring_org_id = sysop.org_id;
369 
370   -- for khr category and attributes
371   CURSOR c_khr_category_attributes_csr (l_khr_id NUMBER)
372   IS
373     SELECT   khr.attribute_category
374             ,khr.attribute1
375             ,khr.attribute2
376             ,khr.attribute3
377             ,khr.attribute4
378             ,khr.attribute5
379             ,khr.attribute6
380             ,khr.attribute7
381             ,khr.attribute8
382             ,khr.attribute9
383             ,khr.attribute10
384             ,khr.attribute11
385             ,khr.attribute12
386             ,khr.attribute13
387             ,khr.attribute14
388             ,khr.attribute15
389       FROM   okl_k_headers khr
390      WHERE   khr.id =  l_khr_id;
391 
392   -- for book classification code and tax owner code
393   CURSOR c_pdt_bc_to_icm_rrb_csr(p_pdt_id NUMBER)
394   IS
395     SELECT  pdt.name                     pdt_name
396            ,aes.name                     aes_name
397            ,gts.name                     sgt_name
398            ,gts.deal_type                deal_type
399            ,gts.tax_owner                tax_owner
400            ,gts.interest_calc_meth_code  interest_calc_meth_code
401            ,gts.revenue_recog_meth_code  revenue_recog_meth_code
402       FROM  okl_products                 pdt
403            ,okl_ae_tmpt_sets_all         aes
404            ,okl_st_gen_tmpt_sets_all     gts
405      WHERE  pdt.aes_id = aes.id
406        AND  aes.gts_id = gts.id
407        AND  pdt.id = p_pdt_id;
408 
409   --for line attribute category and line attributes
410   CURSOR c_line_attributes_csr (l_kle_id NUMBER)
411   IS
412     SELECT   kle.attribute_category
413             ,kle.attribute1
414             ,kle.attribute2
415             ,kle.attribute3
416             ,kle.attribute4
417             ,kle.attribute5
418             ,kle.attribute6
419             ,kle.attribute7
420             ,kle.attribute8
421             ,kle.attribute9
422             ,kle.attribute10
423             ,kle.attribute11
424             ,kle.attribute12
425             ,kle.attribute13
426             ,kle.attribute14
427             ,kle.attribute15
428       FROM   okl_k_lines kle
429      WHERE  kle.id =  l_kle_id;
430 
431   -- Cursor to fetch the Asset Manufacturer Name, Model Number and Category Name
432   CURSOR c_manufacture_model_csr (p_kle_id NUMBER, p_khr_id NUMBER)
433   IS
434     SELECT   fac.category_id             category_id
435               ,fab.manufacturer_name     manufacturer_name
436               ,fab.model_number          model_number
437               ,fac.SEGMENT1 || '-' || fac.SEGMENT2 asset_category_name
438         FROM   okc_k_lines_b        cleb_fa
439               ,fa_additions_b       fab
440               ,okc_k_items          cim
441               ,fa_categories    fac
442        WHERE  cleb_fa.cle_id = p_kle_id
443          AND  cleb_fa.dnz_chr_id = p_khr_id
444          AND  cleb_fa.lse_id = 42
445          AND  cim.cle_id    = cleb_fa.id
446          AND  cim.dnz_chr_id = p_khr_id
447          AND  cim.jtot_object1_code = 'OKX_ASSET'
448          AND  fab.asset_id =  cim.object1_id1
449          AND  fac.category_id = fab.asset_category_id;
450 
451   -- Cursor to fetch the Asset Location Id
452   CURSOR c_location_id_csr (p_kle_id NUMBER, p_khr_id NUMBER )
453   IS
454     SELECT   fdh.location_id
455       FROM   okc_k_lines_b           cleb_loc
456             ,fa_distribution_history fdh
457             ,okc_k_items             cim
458      WHERE  cleb_loc.cle_id = p_kle_id
459        AND  cleb_loc.dnz_chr_id = p_khr_id
460        AND  cleb_loc.lse_id = 42
461        AND  cim.cle_id    = cleb_loc.id
462        AND  cim.dnz_chr_id = p_khr_id
463        AND  fdh.asset_id =  cim.object1_id1
464        AND  cim.jtot_object1_code = 'OKX_ASSET'
465        AND  fdh.transaction_header_id_out IS NULL;
466 
467   -- Cursor to fetch the Asset Location Name
468   CURSOR c_asset_location_name_csr (p_fdh_location_id NUMBER)
469   IS
470     SELECT  location_id                location_id
471            ,loc.concatenated_segments  asset_location_name
472       FROM   fa_locations_kfv         loc
473      WHERE  loc.location_id  = p_fdh_location_id;
474 
475   -- Cursor to fetch the transaction number
476   -- source table : okl_txl_assets_b
477   CURSOR c_txl_trans_number_csr (p_source_id NUMBER)
478   IS
479     SELECT   tas.trans_number trans_number
480             ,txl.id           txl_id
481             ,tas.id           tas_id
482       FROM   okl_trx_assets   tas
483             ,okl_txl_assets_b txl
484      WHERE   tas.id = txl.tas_id and
485              txl.id = p_source_id;
486 
487   -- Cursor to fetch the transaction number
488   -- source table : okl_txd_assets_b
489   CURSOR c_txd_trans_number_csr (p_source_id NUMBER)
490   IS
491     SELECT   tas.trans_number trans_number
492             ,txl.id           txl_id
493             ,tas.id           tas_id
494       FROM   okl_trx_assets   tas
495             ,okl_txl_assets_b txl
496             ,okl_txd_assets_b txd
497      WHERE   tas.id = txl.tas_id and
498              txl.id = txd.tal_id and
499              txd.id = p_source_id;
500 
501   -- Cursor to fetch the Transaction Line Description
502   CURSOR get_txl_line_desc_csr( p_txl_id NUMBER, p_ledger_lang VARCHAR2 )
503   IS
504     SELECT   txl_tl.description   trans_line_description
505       FROM   okl_txl_assets_tl    txl_tl
506      WHERE   txl_tl.id       = p_txl_id
507        AND   txl_tl.language = p_ledger_lang;
508 
509   -- Cursor to fetch the Asset Year Manufactured
510   CURSOR c_asset_year_manufactured_csr (p_kle_id NUMBER, p_khr_id NUMBER)
511   IS
512     SELECT kle.Year_built year_of_manufacture
513       FROM okl_k_lines kle,
514            okc_k_lines_b cleb_year
515      WHERE kle.id = cleb_year.id
516        AND cleb_year.cle_id = p_kle_id
517        AND cleb_year.dnz_chr_id = p_khr_id
518        AND cleb_year.lse_id = 42;
519 
520   -- Cursor to fetch the Aging Bucket Name
521   CURSOR c_aging_bucket_name_csr (p_bkt_id NUMBER)
522   IS
523     SELECT ARB.BUCKET_NAME BUCKET_NAME
524       FROM  OKL_BUCKETS OBKT
525            ,AR_AGING_BUCKET_LINES_B ARBL
526            ,AR_AGING_BUCKETS ARB
527      WHERE OBKT.IBC_ID          = ARBL.AGING_BUCKET_LINE_ID
528        AND ARBL.AGING_BUCKET_ID = ARB.AGING_BUCKET_ID
529        AND OBKT.ID = p_bkt_id;
530 
531   -- Cursor to fetch the Receivables Transaction Type using AGS ID
532   CURSOR  c_cust_trx_type_csr( p_trx_id NUMBER)
533   IS
534     SELECT   ctt.name            trx_name
535       FROM   ra_cust_trx_types   ctt
536      WHERE  ctt.cust_trx_type_id = p_trx_id;
537 
538   -- Cursor to fetch termination quote attr
539   CURSOR c_termination_qte_csr (l_qte_id NUMBER)
540   IS
541     SELECT   date_effective_from
542             ,quote_number
543             ,qtp_code
544       FROM  okl_trx_quotes_all_b
545      WHERE  id = l_qte_id;
546 
547   -- Cursor to fetch contingency code and stream type name
548   --  applicable only for AR.
549   CURSOR c_contingency_strm_b_csr (p_sty_id NUMBER )
550   IS
551     SELECT    styb.code                 stream_type_code
552              ,styb.stream_type_purpose  stream_type_purpose
553 			 -- changed to contingency_name from styb.contingency
554 			 -- for bug fix 6744584. racheruv
555              ,adr.contingency_name      contingency_code
556       FROM    okl_strm_type_b  styb, ar_deferral_reasons adr
557      WHERE    styb.id = p_sty_id
558 	   AND    styb.contingency_id = adr.contingency_id(+);
559 
560   CURSOR c_strm_name_tl_csr (p_sty_id NUMBER, p_lang VARCHAR2)
561   IS
562     SELECT    stytl.NAME             stream_type_name
563       FROM    okl_strm_type_tl stytl
564      WHERE    stytl.id = p_sty_id
565        AND    stytl.language = p_lang;
566 
567   -- Cursor to fetch Investor Related Information
568   CURSOR   c_inv_agrmnt_details_csr( p_inv_agrmnt_id   NUMBER)
569   IS
570     SELECT   invc.contract_number                inv_agrmnt_number
571             ,DECODE(invk.securitization_type,
572               'SALE',          'SECURITIZATION',
573               'LOAN',          'SYNDICATION',
574               'SECURITIZATION','SECURITIZATION',
575               'SYNDICATION',   'SYNDICATION')    inv_agrmnt_synd_code
576             ,pol.pool_number                     inv_agrmnt_pool_number
577             ,invc.currency_code                  inv_agrmnt_currency_code
578             ,invc.START_DATE                     inv_agrmnt_effective_from
579             ,invc.sts_code                       inv_agrmnt_status_code
580       FROM   okc_k_headers_all_b  invc
581             ,okl_k_headers        invk
582             ,okl_pools_all        pol
583      WHERE  invc.id = invk.id
584        AND  invc.scs_code = G_INVESTOR
585        AND  pol.khr_id = invk.id
586        AND  invc.id = p_inv_agrmnt_id;
587 
588   -- Cursor to fetch the Accounting Distributions
589   --  Note: This cursor is used in AR and AP Populate Sources alone
590   CURSOR c_account_dist_csr (
591            p_source_id     NUMBER
592           ,p_source_table  VARCHAR2)
593   IS
594     SELECT   DISTINCT template_id
595       FROM   okl_trns_acc_dstrs_all dist
596      WHERE  source_table = p_source_table
597        AND  source_id = p_source_id;
598 
599   -- Cursor to fetch the template information
600   --  Note: This cursor is used in AR and AP Populate Sources alone
601   CURSOR c_ae_templates_csr (p_template_id NUMBER)
602   IS
603     SELECT   name
604             ,memo_yn
605       FROM   okl_ae_templates_all
606      WHERE id = p_template_id;
607 
608   -- This cursor is used to fetch the Subsidy Details like
609   --  Subsidy Name and Subsidy Party Name. Used only by AR Populate Sources
610   -- Modified by zrehman Bug#6707320 for Party Merge Impact on Transaction Sources tables
611   CURSOR get_subsidy_details_csr( p_kle_id NUMBER)
612   IS
613     SELECT  sub.NAME                subsidy_name
614            ,party.vendor_name       subsidy_party_name
615 	   ,party.vendor_id         subsidy_vendor_id
616       FROM  okl_subsidies_b sub
617            ,okl_k_lines subsidy_line
618            ,okc_k_party_roles_b role
619            ,po_vendors party
620      WHERE  sub.id = subsidy_line.subsidy_id
621        AND  role.cle_id = subsidy_line.id
622        AND  role.object1_id1 = party.vendor_id
623        AND  subsidy_line.id = p_kle_id;
624 
625   -- Cursor to fetch the product name
626   CURSOR c_get_pdt_name_csr( p_pdt_id NUMBER)
627   IS
628     SELECT   pdt.name  pdt_name
629       FROM   okl_products pdt
630      WHERE   pdt.id = p_pdt_id;
631 
632   -- Cursor to fetch the Line Style of the given Line ID
633   -- Used by FA Populate sources for validation Purposes
634   -- Used by AR Populate sources for getting parent_line_id
635   CURSOR get_line_style_csr(p_kle_id IN NUMBER)
636   IS
637     SELECT  lse.lty_code       line_style
638            ,cle.cle_id         parent_line_id
639       FROM  okc_k_lines_b      cle
640            ,okc_line_styles_b  lse
641      WHERE  cle.lse_id = lse.id
642       AND   cle.id = p_kle_id;
643 
644   -- Cursor to fetch the Transaction Line Description for AR TXD
645   CURSOR c_tld_line_description (p_tld_tl_id NUMBER, p_lang VARCHAR2)
646   IS
647     SELECT    tldl.id                tldl_id
648              ,tldl.description       trans_line_description
649      FROM     okl_txd_ar_ln_dtls_tl  tldl
650     WHERE     tldl.id = p_tld_tl_id
651       AND     tldl.language = p_lang;
652 
653   -- Cursor to fetch the AP Invoice Invoice Transaction Line Description
654   CURSOR c_txl_ap_inv_desc_csr (p_tpld_id NUMBER, p_lang  VARCHAR2)
655     IS
656       SELECT    tpld.id                   tpld_id
657                ,tpld.description          trans_line_description
658        FROM     okl_txl_ap_inv_lns_tl     tpld
659       WHERE     tpld.id = p_tpld_id
660         AND     tpld.LANGUAGE = p_lang;
661 
662   -- Cursors to fetch the Termination Quote Related Sources for FA Transactions
663   -- For Offlease Amortization Transaction
664   CURSOR c_tq_dtls_offlease( p_kle_id NUMBER)
665   IS
666     SELECT   qte.quote_number       quote_number
667             ,qte.date_accepted      quote_accepted_date
668             ,qte.qtp_code           quote_type
669       FROM  okl_trx_quotes_all_b  qte
670            ,okl_txl_quote_lines_b tql
671      WHERE  qte.id = tql.qte_id
672        AND  qte.qst_code in ('ACCEPTED', 'COMPLETE')
673        AND  qte.accepted_yn = 'Y'
674        AND  tql.qlt_code = 'AMCFIA'
675        AND  tql.kle_id = p_kle_id;
676 
677   -- For Split Asset Transaction
678   CURSOR c_tq_dtls_split_ast( p_kle_id              NUMBER
679                              ,p_split_asset_trx_id  NUMBER )
680   IS
681     SELECT   qte.quote_number       quote_number
682             ,qte.date_accepted      quote_accepted_date
683             ,qte.qtp_code           quote_type
684       FROM   okl_trx_quotes_all_b   qte
685             ,okl_txl_quote_lines_b  tql
686      WHERE   qte.id = tql.qte_id
687        AND   qte.qst_code in ('ACCEPTED', 'COMPLETE')
688        AND   qte.accepted_yn = 'Y'
689        AND   tql.qlt_code = 'AMCFIA'
690        AND   tql.kle_id = p_kle_id
691        AND   EXISTS
692             (
693               SELECT  1
694                 FROM  okl_trx_assets    tas
695                      ,okl_txl_assets_b  tal
696                      ,okc_k_lines_b     cleb
697                WHERE  cleb.id     = tql.kle_id
698                  AND  cleb.cle_id = tal.kle_id
699                  AND  tal.tas_id  = tas.id
700                  AND  tas.id      = p_split_asset_trx_id
701              );
702 
703   -- For Release Transaction
704   CURSOR c_tq_dtls_release( p_khr_id          NUMBER )
705   IS
706     SELECT   qte.quote_number       quote_number
707             ,qte.date_accepted      quote_accepted_date
708             ,qte.qtp_code           quote_type
709       FROM   okl_trx_types_b        trx_b
710             ,okl_trx_contracts_all  rel_trx
711             ,okl_trx_quotes_all_b   qte
712      WHERE   trx_b.trx_type_class = 'RE_LEASE'
713        AND   trx_b.id = rel_trx.try_id
714        AND   rel_trx.khr_id_new = p_khr_id
715        AND   rel_trx.tsu_code <> 'PROCESSED'
716        AND   qte.id = rel_trx.qte_id;
717 
718 -- For retirement transaction, result of termination quote ,
719 -- i.e. quote with purchase
720 -- Fix for Bug13090374
721 -- vsgandhi 13Dec2011
722 CURSOR c_tq_dtls( p_khr_id          NUMBER,
723                     p_kle_id          NUMBER)
724   IS
725      SELECT  qte.quote_number       quote_number,
726              qte.date_accepted      quote_accepted_date,
727              qte.qtp_code           quote_type
728 
729        FROM   okl_trx_types_b        trx_b
730              ,okl_trx_contracts_all  rel_trx
731              ,okl_trx_quotes_all_b   qte
732              ,okl_txl_quote_lines_b  qtl
733       WHERE   trx_b.trx_type_class = 'TERMINATION'
734         AND   trx_b.id = rel_trx.try_id
735         AND   rel_trx.khr_id = p_khr_id
736         AND   qte.qst_code in ( 'ACCEPTED', 'COMPLETE')
737         AND   qte.accepted_yn = 'Y'
738         AND   qte.id = rel_trx.qte_id
739         AND   qte.qtp_code = 'TER_PURCHASE'
740         AND   qte.id = qtl.qte_id
741         AND   qtl.kle_id = p_kle_id
742         AND   qtl.qlt_code = 'AMCFIA'       ;
743 
744 
745   -- get the representations. MG uptake
746   CURSOR get_rep_type_csr(p_book_type_name varchar2) IS
747   SELECT o.ledger_id,
748          o.representation_code,
749          o.representation_name,
750 		 o.representation_type
751     FROM okl_representations_v o,
752 	     fa_book_controls f
753    WHERE o.ledger_id = f.set_of_books_id
754      AND f.book_type_name = p_book_type_name;
755 
756   -- get the representations based on book_type_code .. MG uptake
757   CURSOR get_reps_csr(p_book_type_code varchar2) IS
758   SELECT o.ledger_id,
759          o.representation_code,
760          o.representation_name,
761 		 o.representation_type
762     FROM okl_representations_v o,
763 	     fa_book_controls f
764    WHERE o.ledger_id = f.set_of_books_id
765      AND f.book_type_code = p_book_type_code;
766 
767   -- get the reporting product based on the contract product .. MG uptake
768   CURSOR c_rep_pdt_csr(p_pdt_id number) IS
769   SELECT reporting_pdt_id
770     FROM okl_products p
771    WHERE p.id = p_pdt_id;
772 
773   -- get the book_type_name for asset book type code .. MG uptake
774 	CURSOR get_book_type_name(p_book_type_code varchar2) IS
775 	SELECT book_type_name
776 	  FROM fa_book_controls
777      WHERE book_type_code = p_book_type_code;
778 
779   PROCEDURE write_to_log(
780               p_level                 IN VARCHAR2,
781               p_module                IN fnd_log_messages.module%TYPE,
782               msg                     IN VARCHAR2 )
783   AS
784     -- l_level: S - Statement, P- Procedure, B - Both
785   BEGIN
786     okl_debug_pub.log_debug(
787       p_level,
788       p_module,
789       msg);
790   END;
791 
792   PROCEDURE put_in_log(
793               p_debug_enabled         IN VARCHAR2,
794               is_debug_procedure_on   IN BOOLEAN,
795               is_debug_statement_on   IN BOOLEAN,
796               p_module                IN fnd_log_messages.module%TYPE,
797               p_level                 IN VARCHAR2,
798               msg                     IN VARCHAR2 )
799   AS
800     -- l_level: S - Statement, P- Procedure, B - Both
801   BEGIN
802     IF(p_debug_enabled='Y' AND is_debug_procedure_on AND p_level = 'P')
803     THEN
804         write_to_log(
805           p_level   => FND_LOG.LEVEL_PROCEDURE,
806           p_module  => p_module,
807           msg       => msg);
808     ELSIF (p_debug_enabled='Y' AND is_debug_statement_on AND
809           (p_level = 'S' OR p_level = 'B' ))
810     THEN
811         write_to_log(
812           p_level   => FND_LOG.LEVEL_STATEMENT,
813           p_module  => p_module,
814           msg       => msg);
815     END IF;
816   END put_in_log;
817 
818   PROCEDURE write_ext_hdr_to_log(
819                p_teh_rec              IN      okl_teh_pvt.teh_rec_type
820               ,p_tehl_tbl             IN      okl_teh_pvt.tehl_tbl_type
821               ,p_module               IN      fnd_log_messages.module%TYPE)
822   AS
823     tl_index   NUMBER;
824   BEGIN
825     -- Print the Sources captured at extension Header Level
826     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'HEADER_EXTENSION_ID       =' || p_teh_rec.HEADER_EXTENSION_ID );
827     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SOURCE_ID                 =' || p_teh_rec.SOURCE_ID );
828     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SOURCE_TABLE              =' || p_teh_rec.SOURCE_TABLE );
829     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'OBJECT_VERSION_NUMBER     =' || p_teh_rec.OBJECT_VERSION_NUMBER );
830     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_NUMBER           =' || p_teh_rec.CONTRACT_NUMBER );
831     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_NUMBER         =' || p_teh_rec.INV_AGRMNT_NUMBER );
832     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_CURRENCY_CODE    =' || p_teh_rec.CONTRACT_CURRENCY_CODE );
833     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_CURRENCY_CODE  =' || p_teh_rec.INV_AGRMNT_CURRENCY_CODE );
834     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_EFFECTIVE_FROM   =' || p_teh_rec.CONTRACT_EFFECTIVE_FROM );
835     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_EFFECTIVE_FROM =' || p_teh_rec.INV_AGRMNT_EFFECTIVE_FROM );
836     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUSTOMER_NAME             =' || p_teh_rec.CUSTOMER_NAME );
837     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SALES_REP_NAME            =' || p_teh_rec.SALES_REP_NAME );
838     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUSTOMER_ACCOUNT_NUMBER   =' || p_teh_rec.CUSTOMER_ACCOUNT_NUMBER );
839     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'BILL_TO_ADDRESS_NUM       =' || p_teh_rec.BILL_TO_ADDRESS_NUM );
840     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INT_CALC_METHOD_CODE      =' || p_teh_rec.INT_CALC_METHOD_CODE );
841     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'REV_REC_METHOD_CODE       =' || p_teh_rec.REV_REC_METHOD_CODE );
842     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONVERTED_NUMBER          =' || p_teh_rec.CONVERTED_NUMBER );
843     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSIGNABLE_FLAG           =' || p_teh_rec.ASSIGNABLE_FLAG );
844     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CREDIT_LINE_NUMBER        =' || p_teh_rec.CREDIT_LINE_NUMBER );
845     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'MASTER_LEASE_NUMBER       =' || p_teh_rec.MASTER_LEASE_NUMBER );
846     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'PO_ORDER_NUMBER           =' || p_teh_rec.PO_ORDER_NUMBER );
847     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'VENDOR_PROGRAM_NUMBER     =' || p_teh_rec.VENDOR_PROGRAM_NUMBER );
848     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INS_POLICY_TYPE_CODE      =' || p_teh_rec.INS_POLICY_TYPE_CODE );
849     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INS_POLICY_NUMBER         =' || p_teh_rec.INS_POLICY_NUMBER );
850     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TERM_QUOTE_ACCEPT_DATE    =' || p_teh_rec.TERM_QUOTE_ACCEPT_DATE );
851     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TERM_QUOTE_NUM            =' || p_teh_rec.TERM_QUOTE_NUM );
852     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TERM_QUOTE_TYPE_CODE      =' || p_teh_rec.TERM_QUOTE_TYPE_CODE );
853     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONVERTED_ACCOUNT_FLAG    =' || p_teh_rec.CONVERTED_ACCOUNT_FLAG );
854     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ACCRUAL_OVERRIDE_FLAG     =' || p_teh_rec.ACCRUAL_OVERRIDE_FLAG );
855     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE_CATEGORY   =' || p_teh_rec.CUST_ATTRIBUTE_CATEGORY );
856     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE1           =' || p_teh_rec.CUST_ATTRIBUTE1 );
857     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE2           =' || p_teh_rec.CUST_ATTRIBUTE2 );
858     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE3           =' || p_teh_rec.CUST_ATTRIBUTE3 );
859     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE4           =' || p_teh_rec.CUST_ATTRIBUTE4 );
860     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE5           =' || p_teh_rec.CUST_ATTRIBUTE5 );
861     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE6           =' || p_teh_rec.CUST_ATTRIBUTE6 );
862     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE7           =' || p_teh_rec.CUST_ATTRIBUTE7 );
863     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE8           =' || p_teh_rec.CUST_ATTRIBUTE8 );
864     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE9           =' || p_teh_rec.CUST_ATTRIBUTE9 );
865     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE10          =' || p_teh_rec.CUST_ATTRIBUTE10 );
866     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE11          =' || p_teh_rec.CUST_ATTRIBUTE11 );
867     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE12          =' || p_teh_rec.CUST_ATTRIBUTE12 );
868     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE13          =' || p_teh_rec.CUST_ATTRIBUTE13 );
869     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE14          =' || p_teh_rec.CUST_ATTRIBUTE14 );
870     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE15          =' || p_teh_rec.CUST_ATTRIBUTE15 );
871     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RENT_IA_CONTRACT_NUMBER   =' || p_teh_rec.RENT_IA_CONTRACT_NUMBER );
872     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RES_IA_CONTRACT_NUMBER    =' || p_teh_rec.RES_IA_CONTRACT_NUMBER );
873     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_POOL_NUMBER    =' || p_teh_rec.INV_AGRMNT_POOL_NUMBER );
874     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RENT_IA_PRODUCT_NAME      =' || p_teh_rec.RENT_IA_PRODUCT_NAME );
875     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RES_IA_PRODUCT_NAME       =' || p_teh_rec.RES_IA_PRODUCT_NAME );
876     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RENT_IA_ACCOUNTING_CODE   =' || p_teh_rec.RENT_IA_ACCOUNTING_CODE );
877     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RES_IA_ACCOUNTING_CODE    =' || p_teh_rec.RES_IA_ACCOUNTING_CODE );
878     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_SYND_CODE      =' || p_teh_rec.INV_AGRMNT_SYND_CODE );
879     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_STATUS_CODE      =' || p_teh_rec.CONTRACT_STATUS_CODE );
880     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_STATUS_CODE    =' || p_teh_rec.INV_AGRMNT_STATUS_CODE );
881     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TRX_TYPE_CLASS_CODE       =' || p_teh_rec.TRX_TYPE_CLASS_CODE );
882     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CHR_OPERATING_UNIT_CODE   =' || p_teh_rec.CHR_OPERATING_UNIT_CODE );
883     -- Print translatable sources
884     FOR tl_index IN p_tehl_tbl.FIRST .. p_tehl_tbl.LAST
885     LOOP
886       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LANGUAGE                =' || p_tehl_tbl(tl_index).LANGUAGE );
887       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_STATUS         =' || p_tehl_tbl(tl_index).CONTRACT_STATUS );
888       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INV_AGRMNT_STATUS       =' || p_tehl_tbl(tl_index).INV_AGRMNT_STATUS );
889       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CHR_OPERATING_UNIT_NAME =' || p_tehl_tbl(tl_index).CHR_OPERATING_UNIT_NAME );
890       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TRANSACTION_TYPE_NAME   =' || p_tehl_tbl(tl_index).TRANSACTION_TYPE_NAME );
891     END LOOP;
892   END;
893 
894   PROCEDURE write_ext_line_to_log(
895                p_tel_rec              IN      tel_rec_type
896               ,p_tell_tbl             IN      tell_tbl_type
897               ,p_module               IN      fnd_log_messages.module%TYPE)
898   AS
899     tl_index   NUMBER;
900   BEGIN
901     -- Print the Sources captured at Extension Line Level
902     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_EXTENSION_ID           =' || p_tel_rec.LINE_EXTENSION_ID );
903     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SOURCE_ID                   =' || p_tel_rec.SOURCE_ID );
904     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SOURCE_TABLE                =' || p_tel_rec.SOURCE_TABLE );
905     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TEH_ID                      =' || p_tel_rec.TEH_ID );
906     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_LINE_NUMBER        =' || p_tel_rec.CONTRACT_LINE_NUMBER );
907     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'FEE_TYPE_CODE               =' || p_tel_rec.FEE_TYPE_CODE );
908     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_NUMBER                =' || p_tel_rec.ASSET_NUMBER );
909     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_CATEGORY_NAME         =' || p_tel_rec.ASSET_CATEGORY_NAME );
910     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_VENDOR_NAME           =' || p_tel_rec.ASSET_VENDOR_NAME );
911     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_MANUFACTURER_NAME     =' || p_tel_rec.ASSET_MANUFACTURER_NAME );
912     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_YEAR_MANUFACTURED     =' || p_tel_rec.ASSET_YEAR_MANUFACTURED );
913     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_MODEL_NUMBER          =' || p_tel_rec.ASSET_MODEL_NUMBER );
914     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_DELIVERED_DATE        =' || p_tel_rec.ASSET_DELIVERED_DATE );
915     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INSTALLED_SITE_ID           =' || p_tel_rec.INSTALLED_SITE_ID );
916     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'FIXED_ASSET_LOCATION_NAME   =' || p_tel_rec.FIXED_ASSET_LOCATION_NAME );
917     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTINGENCY_CODE            =' || p_tel_rec.CONTINGENCY_CODE );
918     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SUBSIDY_NAME                =' || p_tel_rec.SUBSIDY_NAME );
919     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'SUBSIDY_PARTY_NAME          =' || p_tel_rec.SUBSIDY_PARTY_NAME );
920     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'MEMO_FLAG                   =' || p_tel_rec.MEMO_FLAG );
921     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RECIEVABLES_TRX_TYPE_NAME   =' || p_tel_rec.RECIEVABLES_TRX_TYPE_NAME );
922     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'AGING_BUCKET_NAME           =' || p_tel_rec.AGING_BUCKET_NAME );
923     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_LINE_TYPE          =' || p_tel_rec.CONTRACT_LINE_TYPE );
924     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'PAY_SUPPLIER_SITE_NAME      =' || p_tel_rec.PAY_SUPPLIER_SITE_NAME );
925     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INVENTORY_ITEM_NAME_CODE    =' || p_tel_rec.INVENTORY_ITEM_NAME_CODE );
926     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INVENTORY_ORG_CODE          =' || p_tel_rec.INVENTORY_ORG_CODE );
927     -- Print translatable sources
928     FOR tl_index IN p_tell_tbl.FIRST .. p_tell_tbl.LAST
929     LOOP
930       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LANGUAGE                  =' || p_tell_tbl(tl_index).LANGUAGE );
931       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INVENTORY_ITEM_NAME       =' || p_tell_tbl(tl_index).INVENTORY_ITEM_NAME );
932       write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INVENTORY_ORG_NAMES       =' || p_tell_tbl(tl_index).INVENTORY_ORG_NAME );
933     END LOOP;
934   END;
935 
936   ---------------------------------------------------------------------------
937   -- Start of comments
938   --      API name        : populate_tcn_sources
939   --      Pre-reqs        : None
940   --      Function        : Creates records for OKL_TRX_EXTENSION_V
941   --      Parameters      :
942   --      IN              : p_source_id IN NUMBER            Required
943   --                        Corresponds to the column ID
944   --                           in the table OKL_TRX_CONTRACTS.
945   --                        p_source_table IN VARCHAR2     Required
946   --                        Value  G_TRX_CONTRACTS
947   --      Version         : 1.0
948   --      History         : Ravi Gooty created
949   -- End of comments
950   ---------------------------------------------------------------------------
951   PROCEDURE populate_tcn_sources(
952     p_api_version                IN             NUMBER
953    ,p_init_msg_list              IN             VARCHAR2
954    ,px_trans_hdr_rec             IN OUT NOCOPY  tehv_rec_type
955    ,p_acc_sources_rec            IN             asev_rec_type
956    ,x_return_status              OUT    NOCOPY  VARCHAR2
957    ,x_msg_count                  OUT    NOCOPY  NUMBER
958    ,x_msg_data                   OUT    NOCOPY  VARCHAR2
959   )
960   IS
961     -----------------------------------------------------------------
962     -- Declare Process Variable
963     -----------------------------------------------------------------
964     l_api_version      CONSTANT NUMBER         := 1;
965     l_api_name         CONSTANT VARCHAR2(30)   := 'POPULATE_TCN_SOURCES';
966     l_return_status    VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
967     -----------------------------------------------------------------
968     -- Declare records: Extension Headers
969     -----------------------------------------------------------------
970     l_teh_rec_in       okl_teh_pvt.teh_rec_type;
971     l_teh_rec_out      okl_teh_pvt.teh_rec_type;
972     l_tehl_tbl_in      okl_teh_pvt.tehl_tbl_type;
973     l_tehl_tbl_out     okl_teh_pvt.tehl_tbl_type;
974 
975     -- To fetch  khr_id, Termination Quote_id, Event Class
976     CURSOR c_tcn_basic_csr (p_source_id   NUMBER)
977     IS
978       SELECT   tcn.khr_id                      khr_id
979               ,tcn.qte_id                      qte_id
980               ,tcn.pdt_id                      pdt_id
981               ,tcn.set_of_books_id             ledger_id
982               ,try.accounting_event_class_code accounting_event_class_code
983               ,try.id                          try_id
984               ,tcn_type                        tcn_type
985         FROM   okl_trx_contracts_all tcn
986               ,okl_trx_types_b       try
987        WHERE  tcn.id = p_source_id
988          AND  tcn.try_id = try.id
989          AND  try.accounting_event_class_code IS NOT NULL;
990     l_tcn_basic_csr_rec  c_tcn_basic_csr%ROWTYPE;
991 
992     -- Record structures based on the cursor variables.
993     l_ledger_lang_rec               c_ledger_lang_csr%ROWTYPE;
994     l_get_status_meaning_rec        c_get_status_meaning_csr%ROWTYPE;
995     l_khr_attributes_csr_rec        c_khr_attributes_csr%ROWTYPE;
996     l_kpl_attributes_csr_rec        c_kpl_attributes_csr%ROWTYPE;
997     l_rev_rec_int_calc_mtd_csr_rec  c_rev_rec_int_calc_methods_csr%ROWTYPE;
998     l_investor_agree_main_csr_rec   c_investor_agreement_main_csr%ROWTYPE;
999     l_inv_agree_acc_code_csr_rec    c_investor_agree_acc_code_csr%ROWTYPE;
1000     l_cust_name_account_csr_rec     c_cust_name_account_csr%ROWTYPE;
1001     l_insurance_csr_rec             c_insurance_csr%ROWTYPE;
1002     l_sales_rep_acc_sources_csr     c_sales_rep_acc_sources_csr%ROWTYPE;
1003     l_crline_master_lease_csr_rec   c_creditline_master_lease_csr%ROWTYPE;
1004     l_creditline_sub_csr_rec        c_creditline_sub_csr%ROWTYPE;
1005     l_vendor_program_number_csr     c_vendor_program_number_csr%ROWTYPE;
1006     l_trx_type_name_rec             c_trx_type_name_csr%ROWTYPE;
1007     l_termination_qte_csr_rec       c_termination_qte_csr%ROWTYPE;
1008     l_inv_agrmnt_details_rec        c_inv_agrmnt_details_csr%ROWTYPE;
1009     -- Local Variables
1010     l_khr_id                        okl_trx_contracts_all.khr_id%TYPE;
1011     l_qte_id                        okl_trx_contracts_all.qte_id%TYPE;
1012     l_pdt_id                        okl_trx_contracts_all.pdt_id%TYPE;
1013     l_ledger_id                     okl_trx_contracts_all.set_of_books_id%TYPE;
1014     l_accounting_event_class_code   okl_trx_types_b.accounting_event_class_code%TYPE;
1015     l_cust_acct_id                  okc_k_headers_all_b.cust_acct_id%TYPE;
1016     l_rent_ia_chr_id                okc_k_headers_all_b.id%TYPE;
1017     l_res_ia_chr_id                 okc_k_headers_all_b.id%TYPE;
1018     l_master_lease_id               okc_k_headers_all_b.id%TYPE;
1019     l_acc_sources_rec               asev_rec_type;
1020     -- Local Variables for enabling the Debug Statements
1021     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
1022     l_debug_enabled                    VARCHAR2(10);
1023     is_debug_procedure_on              BOOLEAN;
1024     is_debug_statement_on              BOOLEAN;
1025     tl_sources_in                      NUMBER := 1;
1026   BEGIN
1027     l_debug_enabled := okl_debug_pub.check_log_enabled;
1028     -- check for logging on PROCEDURE level
1029     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
1030     -- check for logging on STATEMENT level
1031     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
1032     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1033                'begin debug OKLRSLAB.pls call ' || l_api_name);
1034     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1035                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_TCN_SOURCES');
1036     l_return_status := OKL_API.G_RET_STS_SUCCESS;
1037     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1038       'Calling OKL_API.START_ACTIVITY');
1039     l_return_status := OKL_API.START_ACTIVITY(
1040                          p_api_name       => l_api_name
1041                         ,p_pkg_name       => g_pkg_name
1042                         ,p_init_msg_list  => p_init_msg_list
1043                         ,l_api_version    => l_api_version
1044                         ,p_api_version    => p_api_version
1045                         ,p_api_type       => '_PVT'
1046                         ,x_return_status  => l_return_status);
1047     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1048       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1049     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
1050       RAISE OKL_API.G_EXCEPTION_ERROR;
1051     END IF;
1052     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1053       'Return status from OKL_API.START_ACTIVITY :'||l_return_status);
1054     -- Store the source id and source table in the rec to be passed to the Insert API
1055     l_teh_rec_in.source_id     := px_trans_hdr_rec.source_id;
1056     l_teh_rec_in.source_table  := px_trans_hdr_rec.source_table;
1057     -- Validations ..
1058     IF px_trans_hdr_rec.source_table NOT LIKE G_TRX_CONTRACTS
1059     THEN
1060       OKL_API.set_message(
1061          p_app_name      => G_APP_NAME
1062         ,p_msg_name      => G_INVALID_VALUE
1063         ,p_token1        => G_COL_NAME_TOKEN
1064         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
1065       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1066       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1067     END IF;
1068     -- Assign the AGS Record to the Local Record Structure
1069     l_acc_sources_rec := p_acc_sources_rec;
1070     -- Validation on the AGS Record
1071     IF l_acc_sources_rec.source_id IS NULL
1072     THEN
1073       OKL_API.set_message(
1074          p_app_name      => G_APP_NAME
1075         ,p_msg_name      => G_INVALID_VALUE
1076         ,p_token1        => G_COL_NAME_TOKEN
1077         ,p_token1_value  => 'ACCT_SOURCES.SOURCE_ID');
1078       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1079       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1080     END IF;
1081 
1082     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1083       'Executing Cursor c_tcn_basic_csr: Source ID: ' || px_trans_hdr_rec.source_id);
1084     FOR  t_rec IN  c_tcn_basic_csr (p_source_id => px_trans_hdr_rec.source_id)
1085     LOOP
1086       l_tcn_basic_csr_rec := t_rec;
1087       IF l_tcn_basic_csr_rec.accounting_event_class_code IS NULL
1088       THEN
1089         -- accounting_event_class_code is missing
1090         OKL_API.set_message(
1091            p_app_name      => G_APP_NAME
1092           ,p_msg_name      => G_INVALID_VALUE
1093           ,p_token1        => G_COL_NAME_TOKEN
1094           ,p_token1_value  => 'ACCOUNTING_EVENT_CLASS_CODE');
1095         l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1096         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1097       END IF;
1098       l_khr_id    := l_tcn_basic_csr_rec.khr_id;
1099       l_qte_id    := l_tcn_basic_csr_rec.qte_id;
1100       l_pdt_id    := l_tcn_basic_csr_rec.pdt_id;
1101       l_ledger_id := l_tcn_basic_csr_rec.ledger_id;
1102       l_accounting_event_class_code    := l_tcn_basic_csr_rec.accounting_event_class_code;
1103       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1104         ' l_khr_id : ' || l_khr_id ||
1105         ' l_qte_id : ' || l_qte_id ||
1106         ' l_pdt_id : ' || l_pdt_id ||
1107         ' l_accounting_event_class_code : ' || l_accounting_event_class_code ||
1108         ' ledger_id ' ||  TO_CHAR( l_tcn_basic_csr_rec.ledger_id));
1109     END LOOP; --  c_tcn_basic_csr;
1110 
1111     -- Fetch the Ledger language in order to populate the MLS Sources at header level.
1112     -- Store the Ledger Language so that its passed to the TAPI
1113     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1114       'Picked Language | Ledger Language | USERENV Language p_ledger_id=' || TO_CHAR(l_ledger_id));
1115     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_ledger_id )
1116     LOOP
1117       l_tehl_tbl_in(tl_sources_in).language := t_rec.language_code;
1118       tl_sources_in := tl_sources_in + 1;
1119     END LOOP;
1120 
1121     FOR tl_sources_in in l_tehl_tbl_in.FIRST .. l_tehl_tbl_in.LAST
1122     LOOP
1123       -- Fetch the Transaction Type in Ledger language
1124       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1125         'Executing the Cursor c_trx_type_name_csr. p_try_id=' || TO_CHAR(l_tcn_basic_csr_rec.try_id)
1126         || 'p_led_lang= ' || l_tehl_tbl_in(tl_sources_in).language );
1127       FOR t_rec IN c_trx_type_name_csr(
1128                                     p_try_id   => l_tcn_basic_csr_rec.try_id
1129                                    ,p_led_lang => l_tehl_tbl_in(tl_sources_in).language )
1130       LOOP
1131         l_trx_type_name_rec := t_rec;
1132         l_tehl_tbl_in(tl_sources_in).transaction_type_name  := l_trx_type_name_rec.transaction_type_name;
1133         l_teh_rec_in.trx_type_class_code    := l_trx_type_name_rec.trx_type_class_code;
1134         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1135           'Fetched Transaction Type ' || l_tehl_tbl_in(tl_sources_in).transaction_type_name );
1136       END LOOP;
1137     END LOOP;
1138 
1139     IF l_accounting_event_class_code NOT IN ( G_INVESTOR )
1140     THEN
1141       --------------------------------------------------------------------------------
1142       -- Populating Common Header Sources
1143       --------------------------------------------------------------------------------
1144       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1145         'Executing Cursor c_khr_attributes_csr : l_khr_id = ' ||to_char(l_khr_id));
1146       FOR t_rec IN c_khr_attributes_csr (l_khr_id)
1147       LOOP
1148         l_khr_attributes_csr_rec             := t_rec;
1149         l_teh_rec_in.source_id               := px_trans_hdr_rec.source_id;
1150         l_teh_rec_in.source_table            := px_trans_hdr_rec.source_table;
1151         l_cust_acct_id                       := l_khr_attributes_csr_rec.cust_acct_id;
1152         l_teh_rec_in.contract_number         := l_khr_attributes_csr_rec.contract_number;
1153         l_teh_rec_in.contract_currency_code  := l_khr_attributes_csr_rec.currency_code;
1154         l_teh_rec_in.contract_effective_from := l_khr_attributes_csr_rec.start_date;
1155         l_teh_rec_in.bill_to_address_num     := l_khr_attributes_csr_rec.bill_to_site_use_id;
1156 -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
1157 	l_teh_rec_in.cust_site_use_id        := l_khr_attributes_csr_rec.bill_to_site_use_id;
1158 -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
1159         l_teh_rec_in.converted_number        := l_khr_attributes_csr_rec.orig_system_reference1;
1160         l_teh_rec_in.assignable_flag         := l_khr_attributes_csr_rec.assignable_yn;
1161         l_teh_rec_in.converted_account_flag  := l_khr_attributes_csr_rec.converted_account_yn;
1162         l_teh_rec_in.po_order_number         := l_khr_attributes_csr_rec.cust_po_number;
1163         l_teh_rec_in.accrual_override_flag   := l_khr_attributes_csr_rec.generate_accrual_override_yn;
1164         l_teh_rec_in.chr_operating_unit_code := l_khr_attributes_csr_rec.hr_org_name;
1165         l_teh_rec_in.contract_status_code    := l_khr_attributes_csr_rec.sts_code;
1166         IF l_accounting_event_class_code IN ( G_BOOKING, G_REBOOK, G_RE_LEASE )
1167         THEN
1168           l_teh_rec_in.contract_status_code := 'BOOKED';
1169         ELSIF l_accounting_event_class_code = G_TERMINATION AND
1170               l_tcn_basic_csr_rec.tcn_type = 'TMT'
1171         THEN
1172           -- Full Termination Transaction
1173           l_teh_rec_in.contract_status_code := 'TERMINATED';
1174         ELSIF l_accounting_event_class_code = G_EVERGREEN
1175         THEN
1176           l_teh_rec_in.contract_status_code := 'EVERGREEN';
1177         END IF;
1178       END LOOP; -- c_khr_attributes_csr
1179 
1180       FOR tl_sources_in in l_tehl_tbl_in.FIRST .. l_tehl_tbl_in.LAST
1181       LOOP
1182         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1183           'Executing the Cursor c_get_status_meaning_csr. p_sts_code=' ||
1184           l_khr_attributes_csr_rec.sts_code || 'p_led_lang= ' || l_tehl_tbl_in(tl_sources_in).language );
1185         FOR t_rec IN c_get_status_meaning_csr(
1186                                         p_sts_code  => l_teh_rec_in.contract_status_code
1187                                        ,p_led_lang  => l_tehl_tbl_in(tl_sources_in).language )
1188         LOOP
1189           l_get_status_meaning_rec      := t_rec;
1190           l_tehl_tbl_in(tl_sources_in).contract_status := l_get_status_meaning_rec.status_meaning;
1191         END LOOP; -- End for c_get_status_meaning_csr
1192 
1193         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1194           'Executing the Cursor c_org_name_csr. p_org_id= ' || to_char(l_khr_attributes_csr_rec.authoring_org_id) ||
1195           ' ledger_language=' || l_tehl_tbl_in(tl_sources_in).language );
1196         FOR t_rec IN c_org_name_csr(
1197                       p_org_id      => l_khr_attributes_csr_rec.authoring_org_id
1198                      ,p_ledger_lang => l_tehl_tbl_in(tl_sources_in).language )
1199         LOOP
1200           l_tehl_tbl_in(tl_sources_in).chr_operating_unit_name := t_rec.org_name;
1201         END LOOP;
1202       END LOOP;
1203 
1204       IF l_accounting_event_class_code NOT IN ( G_BOOKING )
1205       THEN
1206         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1207           'RENT: Executing the Cursor c_investor_agreement_main_csr l_khr_id = : ' || TO_CHAR(l_khr_id));
1208         FOR t_rec IN c_investor_agreement_main_csr(
1209                         p_khr_id   => l_khr_id
1210                        ,p_sty_type => 'RENT')
1211         LOOP
1212           l_rent_ia_chr_id                      := t_rec.ia_chr_id;
1213           l_teh_rec_in.rent_ia_contract_number := t_rec.ia_contract_number;
1214           l_teh_rec_in.rent_ia_product_name    := t_rec.ia_product_name;
1215         END LOOP;  -- c_investor_agreement_main_csr
1216 
1217         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1218           'RESIDUAL VALUE: Executing the Cursor c_investor_agreement_main_csr l_khr_id = : ' || TO_CHAR(l_khr_id));
1219         FOR t_rec IN c_investor_agreement_main_csr(
1220                         p_khr_id   => l_khr_id
1221                        ,p_sty_type => 'RESIDUAL VALUE')
1222         LOOP
1223           l_res_ia_chr_id                       := t_rec.ia_chr_id;
1224           l_teh_rec_in.res_ia_contract_number  := t_rec.ia_contract_number;
1225           l_teh_rec_in.res_ia_product_name     := t_rec.ia_product_name;
1226         END LOOP;  -- c_investor_agreement_main_csr
1227       END IF; -- IF l_accounting_event_class_code NOT IN ( G_BOOKING )
1228 
1229       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1230         'Executing the Cursor c_kpl_attributes_csr l_khr_id = ' || TO_CHAR(l_khr_id) );
1231       FOR t_rec IN c_kpl_attributes_csr (l_khr_id)
1232       LOOP
1233         l_kpl_attributes_csr_rec  := t_rec;
1234         l_teh_rec_in.cust_attribute_category := l_kpl_attributes_csr_rec.attribute_category;
1235         l_teh_rec_in.cust_attribute1  := l_kpl_attributes_csr_rec.attribute1;
1236         l_teh_rec_in.cust_attribute2  := l_kpl_attributes_csr_rec.attribute2;
1237         l_teh_rec_in.cust_attribute3  := l_kpl_attributes_csr_rec.attribute3;
1238         l_teh_rec_in.cust_attribute4  := l_kpl_attributes_csr_rec.attribute4;
1239         l_teh_rec_in.cust_attribute5  := l_kpl_attributes_csr_rec.attribute5;
1240         l_teh_rec_in.cust_attribute6  := l_kpl_attributes_csr_rec.attribute6;
1241         l_teh_rec_in.cust_attribute7  := l_kpl_attributes_csr_rec.attribute7;
1242         l_teh_rec_in.cust_attribute8  := l_kpl_attributes_csr_rec.attribute8;
1243         l_teh_rec_in.cust_attribute9  := l_kpl_attributes_csr_rec.attribute9;
1244         l_teh_rec_in.cust_attribute10 := l_kpl_attributes_csr_rec.attribute10;
1245         l_teh_rec_in.cust_attribute11 := l_kpl_attributes_csr_rec.attribute11;
1246         l_teh_rec_in.cust_attribute12 := l_kpl_attributes_csr_rec.attribute12;
1247         l_teh_rec_in.cust_attribute13 := l_kpl_attributes_csr_rec.attribute13;
1248         l_teh_rec_in.cust_attribute14 := l_kpl_attributes_csr_rec.attribute14;
1249         l_teh_rec_in.cust_attribute15 := l_kpl_attributes_csr_rec.attribute15;
1250       END LOOP;   -- c_kpl_attributes_csr_attributes_csr_attributes_csr
1251 
1252       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1253         'Executing the Cursor  c_vendor_program_number_csr p_khr_id = ' || TO_CHAR(l_khr_id) );
1254       FOR t_rec IN c_vendor_program_number_csr (p_khr_id => l_khr_id)
1255       LOOP
1256         l_teh_rec_in.vendor_program_number  := t_rec.contract_number;
1257       END LOOP;  -- c_vendor_program_number_csr
1258 
1259       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1260         'Executing the Cursor l_cust_name_account_csr. l_khr_id = ' || TO_CHAR(l_khr_id)
1261         || ' l_cust_acct_id = ' || TO_CHAR(l_cust_acct_id ) );
1262       FOR t_rec IN  c_cust_name_account_csr (l_khr_id,l_cust_acct_id)
1263       LOOP
1264         l_cust_name_account_csr_rec := t_rec;
1265         l_teh_rec_in.customer_name        := l_cust_name_account_csr_rec.party_name;
1266         l_teh_rec_in.customer_account_number  := l_cust_name_account_csr_rec.account_number;
1267 -- added by zrehman Bug#6707320 for Party Merge Impact on Transaction Sources tables start
1268         l_teh_rec_in.cust_account_id  := l_cust_acct_id;
1269 	l_teh_rec_in.party_id := l_cust_name_account_csr_rec.party_id;
1270 -- added by zrehman Bug#6707320 for Party Merge Impact on Transaction Sources tables end
1271       END LOOP;  -- c_cust_name_account_csr
1272 
1273       IF l_accounting_event_class_code NOT IN ( G_BOOKING )
1274       THEN
1275         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1276           'Executing the Cursor c_investor_agree_acc_code_csr. l_rent_ia_chr_id = '
1277           || TO_CHAR(l_rent_ia_chr_id) || ' l_res_ia_chr_id = ' || l_res_ia_chr_id);
1278         FOR t_rec in c_investor_agree_acc_code_csr (l_rent_ia_chr_id, l_res_ia_chr_id)
1279         LOOP
1280           l_inv_agree_acc_code_csr_rec := t_rec;
1281           l_teh_rec_in.rent_ia_accounting_code    := l_inv_agree_acc_code_csr_rec.rent_ia_accounting_code;
1282           l_teh_rec_in.res_ia_accounting_code     := l_inv_agree_acc_code_csr_rec.res_ia_accounting_code;
1283         END LOOP;  -- c_investor_agree_acc_code_csr
1284       END IF; -- IF l_accounting_event_class_code NOT IN ( G_BOOKING )
1285 
1286       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1287         'Executing the Cursor c_rev_rec_int_calc_methods_csr. l_pdt_id = ' || TO_CHAR(l_pdt_id) );
1288       FOR t_rec  IN c_rev_rec_int_calc_methods_csr(l_pdt_id)
1289       LOOP
1290         l_rev_rec_int_calc_mtd_csr_rec := t_rec;
1291         l_teh_rec_in.rev_rec_method_code  := l_rev_rec_int_calc_mtd_csr_rec.rev_rec_method_code;
1292         l_teh_rec_in.int_calc_method_code := l_rev_rec_int_calc_mtd_csr_rec.int_calc_method_code;
1293       END LOOP;
1294 
1295       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1296         'Executing the Cursor c_creditline_master_lease_csr. l_khr_id = ' || TO_CHAR(l_khr_id) );
1297       FOR t_rec IN c_creditline_master_lease_csr (l_khr_id)
1298       LOOP
1299         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1300           ' Line Type ' || t_rec.chr_type );
1301         IF t_rec.chr_type = 'CREDITLINE_CONTRACT'
1302         THEN
1303           l_teh_rec_in.credit_line_number   := t_rec.credit_line_number;
1304           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1305             'Credit Line Number ' || l_teh_rec_in.credit_line_number );
1306         END IF;
1307         IF t_rec.chr_type = 'MASTER_LEASE'
1308         THEN
1309           l_master_lease_id                  := t_rec.master_lease_id;
1310           l_teh_rec_in.master_lease_number  := t_rec.master_lease_number;
1311           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1312             'Master Lease Number ' ||  l_teh_rec_in.master_lease_number );
1313         END IF;
1314       END LOOP;
1315       IF (l_teh_rec_in.credit_line_number IS NULL AND
1316           l_master_lease_id IS NOT NULL)
1317       THEN
1318         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1319           'Executing the Cursor c_creditline_sub_csr. l_master_lease_id = ' || TO_CHAR(l_master_lease_id) );
1320         FOR t_rec IN c_creditline_sub_csr (l_master_lease_id)
1321         LOOP
1322           l_creditline_sub_csr_rec := t_rec;
1323           l_teh_rec_in.credit_line_number := l_creditline_sub_csr_rec.contract_number;
1324         END LOOP;
1325       END IF;
1326     END IF;  -- NOT LIKE G_INVESTOR
1327     --------------------------------------------------------------------------------
1328     -- Populating Sources specific to Event Classe(s)
1329     --------------------------------------------------------------------------------
1330     IF (l_accounting_event_class_code IN (G_TERMINATION, G_ASSET_DISPOSITION, G_SPLIT_ASSET))
1331     THEN
1332       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1333         'Executing the Cursor c_termination_qte_csr. l_qte_id = ' || TO_CHAR(l_qte_id) );
1334       FOR t_rec IN  c_termination_qte_csr (l_qte_id)
1335       LOOP
1336         l_termination_qte_csr_rec := t_rec;
1337         l_teh_rec_in.term_quote_accept_date := l_termination_qte_csr_rec.date_effective_from;
1338         l_teh_rec_in.term_quote_num         := l_termination_qte_csr_rec.quote_number;
1339         l_teh_rec_in.term_quote_type_code   :=  l_termination_qte_csr_rec.qtp_code;
1340       END LOOP;  -- c_termination_qte_csr
1341     END IF; -- TERMINATION/ ASSET_DISPOSITION Specific.
1342 
1343     IF  l_accounting_event_class_code IN (G_ACCRUAL)
1344     THEN
1345       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1346         'Executing the Cursor c_insurance_csr. l_khr_id = ' || TO_CHAR(l_khr_id) );
1347       FOR t_rec IN c_insurance_csr  (l_khr_id)
1348       LOOP
1349         l_insurance_csr_rec := t_rec;
1350         l_teh_rec_in.ins_policy_type_code  := l_insurance_csr_rec.ipe_code;
1351         l_teh_rec_in.ins_policy_number  := l_insurance_csr_rec.policy_number;
1352       END LOOP; -- c_insurance_csr
1353     END IF; -- ACCRUAL SPECIFIC
1354 
1355     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1356       '** Sales Representative ID passed = ' || TO_CHAR(l_acc_sources_rec.jtf_sales_reps_pk) );
1357     IF ( l_accounting_event_class_code NOT IN
1358          (G_RECEIPT_APPLICATION, G_INVESTOR) ) AND
1359         l_acc_sources_rec.jtf_sales_reps_pk IS NOT NULL -- Account Generator Source should not be NULL
1360     THEN
1361       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1362         'Executing the Cursor  c_sales_rep_acc_sources_csr. l_sales_rep_id = ' || TO_CHAR(l_acc_sources_rec.jtf_sales_reps_pk) );
1363       FOR t_rec IN  c_sales_rep_acc_sources_csr (p_jtf_sales_rep_pk => l_acc_sources_rec.jtf_sales_reps_pk)
1364       LOOP
1365         l_sales_rep_acc_sources_csr  := t_rec;
1366         l_teh_rec_in.sales_rep_name := l_sales_rep_acc_sources_csr.name;
1367       END LOOP;  -- c_sales_rep_acc_sources_csr
1368     END IF;
1369     --------------------------------------------------------------------------------
1370     -- Populating Investor Specfic Sources
1371     --------------------------------------------------------------------------------
1372     IF  l_accounting_event_class_code IN (G_INVESTOR)
1373     THEN
1374       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1375         ' POPULATING INVESTOR SPECIFIC Sources ' );
1376       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1377         'Executing the Cursor c_inv_agrmnt_details_csr. l_khr_id = ' || TO_CHAR(l_khr_id) );
1378       FOR t_rec IN c_inv_agrmnt_details_csr( p_inv_agrmnt_id => l_khr_id )
1379       LOOP
1380         l_inv_agrmnt_details_rec := t_rec;
1381         l_teh_rec_in.inv_agrmnt_number         := l_inv_agrmnt_details_rec.inv_agrmnt_number;
1382         l_teh_rec_in.inv_agrmnt_synd_code      := l_inv_agrmnt_details_rec.inv_agrmnt_synd_code;
1383         l_teh_rec_in.inv_agrmnt_pool_number    := l_inv_agrmnt_details_rec.inv_agrmnt_pool_number;
1384         l_teh_rec_in.inv_agrmnt_currency_code  := l_inv_agrmnt_details_rec.inv_agrmnt_currency_code;
1385         l_teh_rec_in.inv_agrmnt_effective_from := l_inv_agrmnt_details_rec.inv_agrmnt_effective_from;
1386         -- Hard Code the Investor Agreement Status always to ACTIVE
1387         l_teh_rec_in.inv_agrmnt_status_code    := 'ACTIVE';
1388 
1389         FOR tl_sources_in in l_tehl_tbl_in.FIRST .. l_tehl_tbl_in.LAST
1390         LOOP
1391           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1392             'INV_AGRMNT_STATUS: Executing the Cursor c_get_status_meaning_csr. p_sts_code=' ||
1393             l_inv_agrmnt_details_rec.inv_agrmnt_status_code || 'p_led_lang= ' || l_tehl_tbl_in(tl_sources_in).language );
1394           FOR t_meaning_rec IN c_get_status_meaning_csr(
1395                                             p_sts_code  => l_inv_agrmnt_details_rec.inv_agrmnt_status_code
1396                                            ,p_led_lang  => l_tehl_tbl_in(tl_sources_in).language )
1397           LOOP
1398             l_get_status_meaning_rec        := t_meaning_rec;
1399             l_tehl_tbl_in(tl_sources_in).inv_agrmnt_status := l_get_status_meaning_rec.status_meaning;
1400           END LOOP; -- End for c_get_status_meaning_csr
1401         END LOOP;
1402       END LOOP; --
1403     END IF; -- G_INVESTOR SPECIFIC
1404     -- If Log is enabled, print all the sources fetched.
1405     IF (l_debug_enabled='Y' AND is_debug_statement_on)
1406     THEN
1407       write_ext_hdr_to_log(
1408          p_teh_rec  => l_teh_rec_in
1409         ,p_tehl_tbl => l_tehl_tbl_in
1410         ,p_module   => l_module);
1411     END IF;
1412     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1413       'Calling OKL_TRX_EXTENSION_PVT.create_trx_extension API. ' || l_tehl_tbl_in.COUNT);
1414     okl_trx_extension_pvt.create_trx_extension(
1415        p_api_version     => p_api_version
1416       ,p_init_msg_list   => p_init_msg_list
1417       ,x_return_status   => l_return_status
1418       ,x_msg_count       => x_msg_count
1419       ,x_msg_data        => x_msg_data
1420       ,p_teh_rec         => l_teh_rec_in
1421       ,p_tehl_tbl        => l_tehl_tbl_in
1422       ,x_teh_rec         => l_teh_rec_out
1423       ,x_tehl_tbl        => l_tehl_tbl_out
1424     );
1425     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1426       'After execution of OKL_TRX_EXTENSION_PVT.create_trx_extension API. l_return_status ' || l_return_status);
1427     IF l_return_status = FND_API.G_RET_STS_ERROR
1428     THEN
1429       RAISE FND_API.G_EXC_ERROR;
1430     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
1431     THEN
1432       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1433     END IF;
1434     -- Returning back the record structure
1435     px_trans_hdr_rec.header_extension_id := l_teh_rec_out.header_extension_id;
1436     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1437       'Calling okl_api.end_activity');
1438     okl_api.end_activity(
1439        x_msg_count => x_msg_count
1440       ,x_msg_data  => x_msg_data);
1441     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1442       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_TCN_SOURCES');
1443     x_return_status := OKL_API.G_RET_STS_SUCCESS;
1444   EXCEPTION
1445     ------------------------------------------------------------
1446     -- Exception handling
1447     ------------------------------------------------------------
1448     WHEN OKL_API.G_EXCEPTION_ERROR
1449     THEN
1450       IF c_tcn_basic_csr%ISOPEN THEN
1451         CLOSE c_tcn_basic_csr;
1452       END IF;
1453       IF c_khr_attributes_csr%ISOPEN THEN
1454         CLOSE c_khr_attributes_csr;
1455       END IF;
1456       IF c_kpl_attributes_csr%ISOPEN THEN
1457         CLOSE c_kpl_attributes_csr;
1458       END IF;
1459       IF c_termination_qte_csr%ISOPEN THEN
1460         CLOSE c_termination_qte_csr;
1461       END IF;
1462       IF c_cust_name_account_csr%ISOPEN THEN
1463         CLOSE c_cust_name_account_csr;
1464       END IF;
1465       IF c_insurance_csr%ISOPEN THEN
1466         CLOSE c_insurance_csr;
1467       END IF;
1468       IF c_sales_rep_acc_sources_csr%ISOPEN THEN
1469         CLOSE c_sales_rep_acc_sources_csr;
1470       END IF;
1471       IF c_creditline_master_lease_csr%ISOPEN THEN
1472         CLOSE c_creditline_master_lease_csr;
1473       END IF;
1474       IF c_creditline_sub_csr%ISOPEN THEN
1475         CLOSE c_creditline_sub_csr;
1476       END IF;
1477       IF c_vendor_program_number_csr%ISOPEN THEN
1478         CLOSE c_vendor_program_number_csr;
1479       END IF;
1480       IF c_investor_agreement_main_csr%ISOPEN THEN
1481         CLOSE c_investor_agreement_main_csr;
1482       END IF;
1483       IF c_investor_agree_acc_code_csr%ISOPEN THEN
1484         CLOSE c_investor_agree_acc_code_csr;
1485       END IF;
1486       IF c_rev_rec_int_calc_methods_csr%ISOPEN THEN
1487         CLOSE c_rev_rec_int_calc_methods_csr;
1488       END IF;
1489       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
1490                             p_api_name  => l_api_name
1491                            ,p_pkg_name  => G_PKG_NAME
1492                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
1493                            ,x_msg_count => x_msg_count
1494                            ,x_msg_data  => x_msg_data
1495                            ,p_api_type  => '_PVT');
1496     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
1497     THEN
1498       IF c_tcn_basic_csr%ISOPEN THEN
1499         CLOSE c_tcn_basic_csr;
1500       END IF;
1501       IF c_khr_attributes_csr%ISOPEN THEN
1502         CLOSE c_khr_attributes_csr;
1503       END IF;
1504       IF c_kpl_attributes_csr%ISOPEN THEN
1505         CLOSE c_kpl_attributes_csr;
1506       END IF;
1507       IF c_termination_qte_csr%ISOPEN THEN
1508         CLOSE c_termination_qte_csr;
1509       END IF;
1510       IF c_cust_name_account_csr%ISOPEN THEN
1511         CLOSE c_cust_name_account_csr;
1512       END IF;
1513       IF c_insurance_csr%ISOPEN THEN
1514         CLOSE c_insurance_csr;
1515       END IF;
1516       IF c_sales_rep_acc_sources_csr%ISOPEN THEN
1517         CLOSE c_sales_rep_acc_sources_csr;
1518       END IF;
1519       IF c_creditline_master_lease_csr%ISOPEN THEN
1520         CLOSE c_creditline_master_lease_csr;
1521       END IF;
1522       IF c_creditline_sub_csr%ISOPEN THEN
1523         CLOSE c_creditline_sub_csr;
1524       END IF;
1525       IF c_vendor_program_number_csr%ISOPEN THEN
1526         CLOSE c_vendor_program_number_csr;
1527       END IF;
1528       IF c_investor_agreement_main_csr%ISOPEN THEN
1529         CLOSE c_investor_agreement_main_csr;
1530       END IF;
1531       IF c_investor_agree_acc_code_csr%ISOPEN THEN
1532         CLOSE c_investor_agree_acc_code_csr;
1533       END IF;
1534       IF c_rev_rec_int_calc_methods_csr%ISOPEN THEN
1535         CLOSE c_rev_rec_int_calc_methods_csr;
1536       END IF;
1537       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
1538                             p_api_name  => l_api_name
1539                            ,p_pkg_name  => G_PKG_NAME
1540                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
1541                            ,x_msg_count => x_msg_count
1542                            ,x_msg_data  => x_msg_data
1543                            ,p_api_type  => '_PVT');
1544     WHEN OTHERS
1545     THEN
1546       IF c_tcn_basic_csr%ISOPEN THEN
1547         CLOSE c_tcn_basic_csr;
1548       END IF;
1549       IF c_khr_attributes_csr%ISOPEN THEN
1550         CLOSE c_khr_attributes_csr;
1551       END IF;
1552       IF c_kpl_attributes_csr%ISOPEN THEN
1553         CLOSE c_kpl_attributes_csr;
1554       END IF;
1555       IF c_termination_qte_csr%ISOPEN THEN
1556         CLOSE c_termination_qte_csr;
1557       END IF;
1558       IF c_cust_name_account_csr%ISOPEN THEN
1559         CLOSE c_cust_name_account_csr;
1560       END IF;
1561       IF c_insurance_csr%ISOPEN THEN
1562         CLOSE c_insurance_csr;
1563       END IF;
1564       IF c_sales_rep_acc_sources_csr%ISOPEN THEN
1565         CLOSE c_sales_rep_acc_sources_csr;
1566       END IF;
1567       IF c_creditline_master_lease_csr%ISOPEN THEN
1568         CLOSE c_creditline_master_lease_csr;
1569       END IF;
1570       IF c_creditline_sub_csr%ISOPEN THEN
1571         CLOSE c_creditline_sub_csr;
1572       END IF;
1573       IF c_vendor_program_number_csr%ISOPEN THEN
1574         CLOSE c_vendor_program_number_csr;
1575       END IF;
1576       IF c_investor_agreement_main_csr%ISOPEN THEN
1577         CLOSE c_investor_agreement_main_csr;
1578       END IF;
1579       IF c_investor_agree_acc_code_csr%ISOPEN THEN
1580         CLOSE c_investor_agree_acc_code_csr;
1581       END IF;
1582       IF c_rev_rec_int_calc_methods_csr%ISOPEN THEN
1583         CLOSE c_rev_rec_int_calc_methods_csr;
1584       END IF;
1585      x_return_status := OKL_API.HANDLE_EXCEPTIONS (
1586                             p_api_name  => l_api_name
1587                            ,p_pkg_name  => G_PKG_NAME
1588                            ,p_exc_name  => 'OTHERS'
1589                            ,x_msg_count => x_msg_count
1590                            ,x_msg_data  => x_msg_data
1591                            ,p_api_type  => '_PVT');
1592   END populate_tcn_sources;
1593 
1594   ---------------------------------------------------------------------------
1595   -- Start of comments
1596   --      API name        : populate_tcl_sources
1597   --      Pre-reqs        : None
1598   --      Function        : Creates records for OKL_TXL_EXTENSION_V
1599   --      Parameters      :
1600   --      IN              : px_trans_line_rec.source_id IN NUMBER  Required
1601   --                        Corresponds to the column ID
1602   --                           in the table OKL_TXL_CNTRCT_LNS.
1603   --                        px_trans_line_rec.source_table IN VARCHAR2 Required
1604   --                         Value  G_TXL_CONTRACTS
1605   --      Version         : 1.0
1606   --      History         : Ravi Gooty created
1607   -- End of comments
1608   ---------------------------------------------------------------------------
1609   PROCEDURE populate_tcl_sources(
1610     p_api_version               IN             NUMBER
1611    ,p_init_msg_list             IN             VARCHAR2
1612    ,px_trans_line_rec           IN OUT NOCOPY  telv_rec_type
1613    ,p_acc_sources_rec           IN             asev_rec_type
1614    ,x_return_status             OUT    NOCOPY  VARCHAR2
1615    ,x_msg_count                 OUT    NOCOPY  NUMBER
1616    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
1617   )
1618   IS
1619     -----------------------------------------------------------------
1620     -- Declare Process Variable
1621     -----------------------------------------------------------------
1622     l_api_version              CONSTANT NUMBER         := 1;
1623     l_api_name                 CONSTANT VARCHAR2(30)   := 'POPULATE_TCL_SOURCES';
1624     l_return_status            VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
1625     ------------------------------------------------------------
1626     -- Declare records: Extension Headers, Extension Lines
1627     ------------------------------------------------------------
1628     l_tel_rec_in        tel_rec_type;
1629     l_tel_rec_out       tel_rec_type;
1630     l_tell_tbl_in       tell_tbl_type;
1631     l_tell_tbl_out      tell_tbl_type;
1632 
1633     -- to fetch  kle_id,  event_class
1634     CURSOR c_tcl_basic_csr (p_source_id NUMBER)
1635     IS
1636       SELECT   tcl.kle_id
1637               ,tcl.khr_id
1638               ,tcl.id
1639               ,tcl.bkt_id
1640               ,tcl.sty_id
1641               ,tcn.set_of_books_id ledger_id
1642               ,try.accounting_event_class_code
1643         FROM   okl_txl_cntrct_lns_all tcl
1644               ,okl_trx_contracts_all  tcn
1645               ,okl_trx_types_b        try
1646        WHERE  tcl.id = p_source_id
1647          AND  tcl.tcn_id = tcn.id
1648          AND  try.id = tcn.try_id
1649          AND  try.accounting_event_class_code IS NOT NULL;
1650     l_tcl_basic_csr_rec  c_tcl_basic_csr%ROWTYPE;
1651 
1652     -- Record structures based on Cursor Definitions
1653     l_ledger_lang_rec               c_ledger_lang_csr%ROWTYPE;
1654     l_k_lines_rec                   c_k_lines_csr%ROWTYPE;
1655     l_vendor_name_csr_rec           c_vendor_name_csr%ROWTYPE;
1656     l_installed_site_csr_rec        c_installed_site_csr%ROWTYPE;
1657     l_inventory_item_name_csr_rec   c_inventory_item_name_csr%ROWTYPE;
1658     l_manufacture_model_csr_rec     c_manufacture_model_csr%ROWTYPE;
1659     l_location_id_csr_rec           c_location_id_csr%ROWTYPE;
1660     l_asset_location_name_csr_rec   c_asset_location_name_csr%ROWTYPE;
1661     l_asset_year_mfg_csr_rec        c_asset_year_manufactured_csr%ROWTYPE;
1662     l_aging_bucket_name_csr_rec     c_aging_bucket_name_csr%ROWTYPE;
1663     l_cust_trx_type_csr_rec         c_cust_trx_type_csr%ROWTYPE;
1664     l_acc_sources_rec               asev_rec_type;
1665     -- Local Variables
1666     i                               NUMBER := 0;
1667     tl_sources_in                   NUMBER := 1;
1668     -- Local Variables for enabling the Debug Statements
1669     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
1670     l_debug_enabled                    VARCHAR2(10);
1671     is_debug_procedure_on              BOOLEAN;
1672     is_debug_statement_on BOOLEAN;
1673   BEGIN
1674     l_debug_enabled := okl_debug_pub.check_log_enabled;
1675     -- check for logging on PROCEDURE level
1676     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
1677     -- check for logging on STATEMENT level
1678     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
1679     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1680                'begin debug OKLRSLAB.pls call ' || l_api_name);
1681     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1682                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_TCL_SOURCES');
1683     l_return_status := OKL_API.G_RET_STS_SUCCESS;
1684     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1685       'Calling OKL_API.START_ACTIVITY');
1686     l_return_status := OKL_API.START_ACTIVITY(
1687                          p_api_name       => l_api_name
1688                         ,p_pkg_name       => g_pkg_name
1689                         ,p_init_msg_list  => p_init_msg_list
1690                         ,l_api_version    => l_api_version
1691                         ,p_api_version    => p_api_version
1692                         ,p_api_type       => '_PVT'
1693                         ,x_return_status  => l_return_status);
1694     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1695       'After Start Activity l_return_status ' || l_return_status );
1696     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
1697     THEN
1698       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1699     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
1700     THEN
1701       RAISE OKL_API.G_EXCEPTION_ERROR;
1702     END IF;
1703     -- Copy the input parameters to the local variables and start using them.
1704     l_tel_rec_in.source_id := px_trans_line_rec.source_id;
1705     l_tel_rec_in.source_table := px_trans_line_rec.source_table;
1706     l_tel_rec_in.teh_id := px_trans_line_rec.teh_id;
1707     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1708       ' Input Parameters : p_api_version=' || TO_CHAR(p_api_version) ||
1709       ' p_init_msg_list=' || p_init_msg_list || 'line_id=' || to_char(l_tel_rec_in.source_id) ||
1710       ' line_table='|| l_tel_rec_in.source_table);
1711 
1712     IF l_tel_rec_in.source_table <> G_TXL_CONTRACTS
1713     THEN
1714       OKL_API.set_message(
1715          p_app_name      => G_APP_NAME
1716         ,p_msg_name      => G_INVALID_VALUE
1717         ,p_token1        => G_COL_NAME_TOKEN
1718         ,p_token1_value  => 'LINE.SOURCE_TABLE');
1719       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1720       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1721     END IF;
1722 
1723     -- Assign the AGS Record to the Local Record Structure
1724     l_acc_sources_rec := p_acc_sources_rec;
1725     -- Validation on the AGS Record
1726     IF l_acc_sources_rec.source_id IS NULL
1727     THEN
1728       OKL_API.set_message(
1729          p_app_name      => G_APP_NAME
1730         ,p_msg_name      => G_INVALID_VALUE
1731         ,p_token1        => G_COL_NAME_TOKEN
1732         ,p_token1_value  => 'ACCT_SOURCES.SOURCE_ID');
1733       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1734       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1735     END IF;
1736 
1737     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1738       'Executing the Cursor c_tcl_basic_csr. p_source_id = ' || TO_CHAR(l_tel_rec_in.source_id) );
1739     OPEN  c_tcl_basic_csr (l_tel_rec_in.source_id);
1740     FETCH c_tcl_basic_csr INTO l_tcl_basic_csr_rec;
1741     CLOSE c_tcl_basic_csr;
1742     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1743       'Closed Cursor c_tcl_basic_csr' );
1744 
1745     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1746       'input parameter l_tel_rec_in.line_id='|| to_char(l_tel_rec_in.source_id) ||
1747       ' l_tcl_basic_csr_rec.khr_id='|| to_char(l_tcl_basic_csr_rec.khr_id) ||
1748       ' l_tcl_basic_csr_rec.kle_id='|| to_char(l_tcl_basic_csr_rec.kle_id) ||
1749       ' l_tcl_basic_csr_rec.accounting_event_class_code=' || l_tcl_basic_csr_rec.accounting_event_class_code ||
1750       ' l_tcl_basic_csr_rec.bkt_id=' || to_char(l_tcl_basic_csr_rec.bkt_id) ||
1751       ' l_tcl_basic_csr_rec.sty_id=' || to_char(l_tcl_basic_csr_rec.sty_id) ||
1752       ' l_tcl_basic_csr_rec.ledger_id=' || to_char(l_tcl_basic_csr_rec.ledger_id) );
1753 
1754     IF l_tcl_basic_csr_rec.accounting_event_class_code IS NULL
1755     THEN
1756       -- accounting_event_class_code is missing
1757       OKL_API.set_message(
1758          p_app_name      => G_APP_NAME
1759         ,p_msg_name      => G_INVALID_VALUE
1760         ,p_token1        => G_COL_NAME_TOKEN
1761         ,p_token1_value  => 'ACCOUNTING_EVENT_CLASS_CODE');
1762       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
1763       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1764     END IF;
1765 
1766     -- Store the Ledger Language so that its passed to the TAPI
1767     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1768       'Picked Language | Ledger Language | USERENV Language p_ledger_id=' || TO_CHAR(l_tcl_basic_csr_rec.ledger_id));
1769     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_tcl_basic_csr_rec.ledger_id )
1770     LOOP
1771       l_tell_tbl_in(tl_sources_in).language := t_rec.language_code;
1772     END LOOP;
1773 
1774     IF l_tcl_basic_csr_rec.kle_id IS NOT NULL
1775     THEN
1776       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1777         'Executing the curosr c_k_lines_csr. kle_id= ' || to_char(l_tcl_basic_csr_rec.kle_id) );
1778       FOR t_rec IN  c_k_lines_csr (l_tcl_basic_csr_rec.kle_id)
1779       LOOP
1780         l_k_lines_rec   := t_rec;
1781         l_tel_rec_in.contract_line_type       := l_k_lines_rec.contract_line_type;
1782         IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1783             ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_PRINCIPAL_ADJUSTMENT )
1784         THEN
1785           l_tel_rec_in.fee_type_code          := l_k_lines_rec.fee_type;
1786         END IF;
1787         IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1788              ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_PRINCIPAL_ADJUSTMENT,
1789                G_MISCELLANEOUS, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET )
1790         THEN
1791           l_tel_rec_in.asset_number           := l_k_lines_rec.asset_number;
1792         END IF;
1793         IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1794            (G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET)
1795         THEN
1796           l_tel_rec_in.contract_line_number   := l_k_lines_rec.line_number;
1797         END IF;
1798         IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1799              ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_RECEIPT_APPLICATION,
1800                G_PRINCIPAL_ADJUSTMENT, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET )
1801         THEN
1802           l_tel_rec_in.asset_delivered_date   := l_k_lines_rec.date_delivery_expected;
1803         END IF;
1804       END LOOP; -- c_k_lines_csr
1805 
1806       IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1807           (G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_PRINCIPAL_ADJUSTMENT,
1808             G_MISCELLANEOUS, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET)
1809       THEN
1810         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1811           'Executing the Cursor c_location_id_csr. kle_id= ' || to_char(l_tcl_basic_csr_rec.kle_id) ||
1812           ' khr_id=' || to_char(l_tcl_basic_csr_rec.khr_id) );
1813         OPEN c_location_id_csr(l_tcl_basic_csr_rec.kle_id,l_tcl_basic_csr_rec.khr_id );
1814         FETCH c_location_id_csr into l_location_id_csr_rec;
1815         CLOSE c_location_id_csr;
1816         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1817           'Executing the Cursor l_vendor_name_csr_rec. kle_id= ' || to_char(l_tcl_basic_csr_rec.kle_id) ||
1818           ' khr_id=' || to_char(l_tcl_basic_csr_rec.khr_id) );
1819         FOR t_rec  IN c_vendor_name_csr(
1820                                          l_tcl_basic_csr_rec.kle_id
1821                                         ,l_tcl_basic_csr_rec.khr_id)
1822         LOOP
1823           l_vendor_name_csr_rec := t_rec;
1824           l_tel_rec_in.asset_vendor_name   := l_vendor_name_csr_rec.vendor_name;
1825           -- added by zrehman Bug#6707320 for Party Merge impact on transaction sources tables start
1826           l_tel_rec_in.asset_vendor_id   := l_vendor_name_csr_rec.vendor_id;
1827           -- added by zrehman Bug#6707320 for Party Merge impact on transaction sources tables end
1828         END LOOP;  -- c_vendor_name_csr
1829         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1830           'Executing the Cursor c_asset_location_name_csr. location_id=' ||
1831           TO_CHAR(l_location_id_csr_rec.location_id) );
1832         FOR t_rec  IN  c_asset_location_name_csr(l_location_id_csr_rec.location_id)
1833         LOOP
1834           l_asset_location_name_csr_rec := t_rec;
1835           l_tel_rec_in.fixed_asset_location_name := l_asset_location_name_csr_rec.asset_location_name;
1836         END LOOP;  -- c_asset_location_name_csr
1837         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1838           'Executing the Cursor l_installed_site_csr_rec. kle_id= ' || to_char(l_tcl_basic_csr_rec.kle_id) ||
1839           ' khr_id=' || to_char(l_tcl_basic_csr_rec.khr_id) );
1840         FOR t_rec  IN  c_installed_site_csr(
1841                                             l_tcl_basic_csr_rec.kle_id
1842                                            ,l_tcl_basic_csr_rec.khr_id)
1843         LOOP
1844           l_installed_site_csr_rec := t_rec;
1845           l_tel_rec_in.installed_site_id   := l_installed_site_csr_rec.installed_site_id;
1846         END LOOP;  -- c_installed_site_csr
1847       END IF;  -- accounting_event_class_code for 7 events
1848 
1849       IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1850              ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_RECEIPT_APPLICATION,
1851                G_PRINCIPAL_ADJUSTMENT, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET )
1852       THEN
1853         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1854           'Executing the Cursor c_manufacture_model_csr. kle_id= ' || to_char(l_tcl_basic_csr_rec.kle_id) ||
1855           ' khr_id=' || to_char(l_tcl_basic_csr_rec.khr_id) );
1856         FOR t_rec IN  c_manufacture_model_csr (
1857                                               l_tcl_basic_csr_rec.kle_id
1858                                              ,l_tcl_basic_csr_rec.khr_ID)
1859         LOOP
1860           l_manufacture_model_csr_rec := t_rec;
1861           IF l_tcl_basic_csr_rec.accounting_event_class_code NOT LIKE G_ACCRUAL
1862           THEN
1863             l_tel_rec_in.asset_manufacturer_name    :=  l_manufacture_model_csr_rec.manufacturer_name;
1864           END IF;
1865           l_tel_rec_in.asset_model_number         :=  l_manufacture_model_csr_rec.model_number;
1866           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1867             'Executing the Cursor c_asset_year_manufactured_csr. kle_id= ' || to_char(l_tcl_basic_csr_rec.kle_id) ||
1868             ' khr_id=' || to_char(l_tcl_basic_csr_rec.khr_id) );
1869           FOR  t_year_man_rec IN c_asset_year_manufactured_csr (
1870                                              l_tcl_basic_csr_rec.kle_id
1871                                             ,l_tcl_basic_csr_rec.khr_id)
1872           LOOP
1873             l_asset_year_mfg_csr_rec := t_year_man_rec;
1874             l_tel_rec_in.asset_year_manufactured := l_asset_year_mfg_csr_rec.Year_of_manufacture;
1875           END LOOP; -- c_asset_year_manufactured_csr
1876           IF l_tcl_basic_csr_rec.accounting_event_class_code NOT IN
1877                  ( G_RECEIPT_APPLICATION, G_PRINCIPAL_ADJUSTMENT, G_ACCRUAL, G_MISCELLANEOUS )
1878           THEN
1879             l_tel_rec_in.asset_category_name        :=  l_manufacture_model_csr_rec.asset_category_name;
1880           END IF;
1881         END LOOP;  -- c_manufacture_model_csr
1882       END IF;  -- accounting_event_class_code for 5 events
1883 
1884     END IF; --     IF l_tcl_basic_csr_rec.kle_id IS NOT NULL
1885 
1886     IF l_tcl_basic_csr_rec.accounting_event_class_code IN
1887        (G_BOOKING, G_REBOOK, G_RE_LEASE,  G_ACCRUAL, G_MISCELLANEOUS)
1888     THEN
1889       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1890         'Executing the Cursor c_cust_trx_type_csr rec_trx_types_pk=' || to_char(l_acc_sources_rec.rec_trx_types_pk) );
1891       FOR t_rec IN  c_cust_trx_type_csr( p_trx_id => l_acc_sources_rec.rec_trx_types_pk )
1892       LOOP
1893         l_cust_trx_type_csr_rec := t_rec;
1894         l_tel_rec_in.recievables_trx_type_name  :=l_cust_trx_type_csr_rec.trx_name;
1895       END LOOP;
1896     END IF;  -- c_cust_trx_type_csr
1897 
1898     IF l_tcl_basic_csr_rec.accounting_event_class_code IN (G_GLP)
1899     THEN
1900       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1901         'Executing cursor c_aging_bucket_name_csr bkt_id=' || l_tcl_basic_csr_rec.bkt_id );
1902       FOR t_rec IN c_aging_bucket_name_csr(l_tcl_basic_csr_rec.bkt_id)
1903       LOOP
1904         l_aging_bucket_name_csr_rec := t_rec;
1905         l_tel_rec_in.aging_bucket_name  :=l_aging_bucket_name_csr_rec.bucket_name;
1906       END LOOP;  -- c_aging_bucket_name_csr
1907     END IF;
1908 
1909     -- Populating MLS Sources at Transaction Line Level
1910     IF l_tcl_basic_csr_rec.accounting_event_class_code IN (G_ACCRUAL,G_ASSET_DISPOSITION, G_SPLIT_ASSET)
1911     THEN
1912       FOR tl_sources_in IN l_tell_tbl_in.FIRST .. l_tell_tbl_in.LAST
1913       LOOP
1914       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1915         'Executing the Cursor c_inventory_item_name_csr. p_inventory_item_id_pk1= ' ||
1916         to_char(l_acc_sources_rec.inventory_item_id_pk1) || ' p_inventory_org_id_pk2=' ||
1917         to_char(l_acc_sources_rec.inventory_org_id_pk2) || ' ledger_language=' ||
1918         l_tell_tbl_in(tl_sources_in).language );
1919       FOR t_rec IN c_inventory_item_name_csr(
1920                      p_inventory_item_id_pk1 => l_acc_sources_rec.inventory_item_id_pk1
1921                     ,p_inventory_org_id_pk2  => l_acc_sources_rec.inventory_org_id_pk2
1922                     ,p_ledger_language       => l_tell_tbl_in(tl_sources_in).language)
1923       LOOP
1924         l_inventory_item_name_csr_rec := t_rec;
1925         l_tell_tbl_in(tl_sources_in).inventory_item_name      := l_inventory_item_name_csr_rec.description;
1926         l_tel_rec_in.inventory_item_name_code := l_inventory_item_name_csr_rec.b_description;
1927       END LOOP;
1928       END LOOP;
1929     END IF; -- IF l_tcn_basic_csr_rec.accounting_event_class_code IN (G_ACCRUAL,G_ASSET_DISPOSITION, G_SPLIT_ASSET)
1930 
1931     -- Populating Common MLS Sources at Transaction Line Level
1932     IF l_tcl_basic_csr_rec.accounting_event_class_code NOT IN (G_UPFRONT_TAX)
1933     THEN
1934       -- Populate Inventory Organization Name
1935       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1936         '*** AGS Inventory Org ID used to fetch teh Inventory Organization Code : Org ID=' ||
1937       l_acc_sources_rec.inventory_org_id_pk2 );
1938       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1939         'Executing the Cursor c_org_name_code_csr. p_org_id= ' || to_char(l_acc_sources_rec.inventory_org_id_pk2) );
1940       FOR t_rec IN c_org_name_code_csr(
1941                       p_org_id      => l_acc_sources_rec.inventory_org_id_pk2 )
1942       LOOP
1943         l_tel_rec_in.inventory_org_code := t_rec.org_name;
1944       END LOOP;
1945 
1946       FOR tl_sources_in IN l_tell_tbl_in.FIRST .. l_tell_tbl_in.LAST
1947       LOOP
1948       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1949         'Executing the Cursor c_org_name_csr. p_org_id= ' || to_char(l_acc_sources_rec.inventory_org_id_pk2) ||
1950         ' ledger_language=' || l_tell_tbl_in(tl_sources_in).language );
1951       FOR t_rec IN c_org_name_csr(
1952                       p_org_id      => l_acc_sources_rec.inventory_org_id_pk2
1953                      ,p_ledger_lang => l_tell_tbl_in(tl_sources_in).language )
1954       LOOP
1955         l_tell_tbl_in(tl_sources_in).inventory_org_name := t_rec.org_name;
1956       END LOOP;
1957       END LOOP;
1958     END IF; -- IF l_tcl_basic_csr_rec.accounting_event_class_code IN (G_UPFRONT_TAX)
1959 
1960     -- Assigning the Memo Indicator to the Extension Line Record structure ..
1961     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1962       '** AGS Memo Flag ' || l_acc_sources_rec.memo_yn );
1963     l_tel_rec_in.memo_flag := l_acc_sources_rec.memo_yn;
1964 
1965     -- If Log is enabled, print all the sources fetched.
1966     IF (l_debug_enabled='Y' AND is_debug_statement_on)
1967     THEN
1968       write_ext_line_to_log(
1969         p_tel_rec  => l_tel_rec_in
1970        ,p_tell_tbl => l_tell_tbl_in
1971        ,p_module   => l_module);
1972     END IF;
1973     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
1974       'Calling OKL_TRX_EXTENSION_PVT.create_txl_extension API.' );
1975 
1976     okl_trx_extension_pvt.create_txl_extension(
1977        p_api_version     => p_api_version
1978       ,p_init_msg_list   => p_init_msg_list
1979       ,x_return_status   => l_return_status
1980       ,x_msg_count       => x_msg_count
1981       ,x_msg_data        => x_msg_data
1982       ,p_tel_rec         => l_tel_rec_in
1983       ,p_tell_tbl        => l_tell_tbl_in
1984       ,x_tel_rec         => l_tel_rec_out
1985       ,x_tell_tbl        => l_tell_tbl_out
1986     );
1987     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1988       'After okl_trx_extension_pvt.create_txl_extension. l_return_status ' || l_return_status );
1989     IF l_return_status = FND_API.G_RET_STS_ERROR
1990     THEN
1991       RAISE FND_API.G_EXC_ERROR;
1992     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
1993     THEN
1994       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1995     END IF;
1996     -- Return the values
1997     px_trans_line_rec.line_extension_id := l_tel_rec_out.line_extension_id;
1998     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
1999       'Calling okl_api.end_activity');
2000     okl_api.end_activity(
2001        x_msg_count => x_msg_count
2002       ,x_msg_data => x_msg_data);
2003     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2004       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_TCL_SOURCES');
2005     x_return_status := OKL_API.G_RET_STS_SUCCESS;
2006   EXCEPTION
2007     ------------------------------------------------------------
2008     -- Exception handling
2009     ------------------------------------------------------------
2010     WHEN OKL_API.G_EXCEPTION_ERROR
2011     THEN
2012       IF  c_tcl_basic_csr%ISOPEN THEN
2013         CLOSE c_tcl_basic_csr;
2014       END IF;
2015       IF  c_k_lines_csr%ISOPEN THEN
2016         CLOSE c_k_lines_csr;
2017       END IF;
2018       IF  c_vendor_name_csr%ISOPEN THEN
2019         CLOSE c_vendor_name_csr;
2020       END IF;
2021       IF  c_manufacture_model_csr%ISOPEN THEN
2022         CLOSE c_manufacture_model_csr;
2023       END IF;
2024       IF  c_location_id_csr%ISOPEN THEN
2025         CLOSE c_location_id_csr;
2026       END IF;
2027       IF  c_asset_location_name_csr%ISOPEN THEN
2028         CLOSE c_asset_location_name_csr;
2029       END IF;
2030       IF  c_asset_year_manufactured_csr%ISOPEN THEN
2031         CLOSE c_asset_year_manufactured_csr;
2032       END IF;
2033       IF   c_installed_site_csr%ISOPEN THEN
2034         CLOSE c_installed_site_csr;
2035       END IF;
2036       IF  c_aging_bucket_name_csr%ISOPEN THEN
2037         CLOSE c_aging_bucket_name_csr;
2038       END IF;
2039       IF   c_cust_trx_type_csr%ISOPEN THEN
2040         CLOSE c_cust_trx_type_csr;
2041       END IF;
2042       IF   c_inventory_item_name_csr%ISOPEN THEN
2043         CLOSE c_inventory_item_name_csr;
2044       END IF;
2045       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
2046                             p_api_name  => l_api_name
2047                            ,p_pkg_name  => G_PKG_NAME
2048                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
2049                            ,x_msg_count  => x_msg_count
2050                            ,x_msg_data  => x_msg_data
2051                            ,p_api_type  => '_PVT');
2052 
2053     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
2054     THEN
2055       IF  c_tcl_basic_csr%ISOPEN THEN
2056         CLOSE c_tcl_basic_csr;
2057       END IF;
2058       IF  c_k_lines_csr%ISOPEN THEN
2059         CLOSE c_k_lines_csr;
2060       END IF;
2061       IF  c_vendor_name_csr%ISOPEN THEN
2062         CLOSE c_vendor_name_csr;
2063       END IF;
2064       IF  c_manufacture_model_csr%ISOPEN THEN
2065         CLOSE c_manufacture_model_csr;
2066       END IF;
2067       IF  c_location_id_csr%ISOPEN THEN
2068         CLOSE c_location_id_csr;
2069       END IF;
2070       IF  c_asset_location_name_csr%ISOPEN THEN
2071         CLOSE c_asset_location_name_csr;
2072       END IF;
2073       IF  c_asset_year_manufactured_csr%ISOPEN THEN
2074         CLOSE c_asset_year_manufactured_csr;
2075       END IF;
2076       IF   c_installed_site_csr%ISOPEN THEN
2077         CLOSE c_installed_site_csr;
2078       END IF;
2079       IF  c_aging_bucket_name_csr%ISOPEN THEN
2080         CLOSE c_aging_bucket_name_csr;
2081       END IF;
2082       IF   c_cust_trx_type_csr%ISOPEN THEN
2083         CLOSE c_cust_trx_type_csr;
2084       END IF;
2085       IF   c_inventory_item_name_csr%ISOPEN THEN
2086         CLOSE c_inventory_item_name_csr;
2087       END IF;
2088       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
2089                             p_api_name  => l_api_name
2090                            ,p_pkg_name  => G_PKG_NAME
2091                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
2092                            ,x_msg_count  => x_msg_count
2093                            ,x_msg_data  => x_msg_data
2094                            ,p_api_type  => '_PVT');
2095     WHEN OTHERS
2096     THEN
2097       IF  c_tcl_basic_csr%ISOPEN THEN
2098         CLOSE c_tcl_basic_csr;
2099       END IF;
2100       IF  c_k_lines_csr%ISOPEN THEN
2101         CLOSE c_k_lines_csr;
2102       END IF;
2103       IF  c_vendor_name_csr%ISOPEN THEN
2104         CLOSE c_vendor_name_csr;
2105       END IF;
2106       IF  c_manufacture_model_csr%ISOPEN THEN
2107         CLOSE c_manufacture_model_csr;
2108       END IF;
2109       IF  c_location_id_csr%ISOPEN THEN
2110         CLOSE c_location_id_csr;
2111       END IF;
2112       IF  c_asset_location_name_csr%ISOPEN THEN
2113         CLOSE c_asset_location_name_csr;
2114       END IF;
2115       IF  c_asset_year_manufactured_csr%ISOPEN THEN
2116         CLOSE c_asset_year_manufactured_csr;
2117       END IF;
2118       IF   c_installed_site_csr%ISOPEN THEN
2119         CLOSE c_installed_site_csr;
2120       END IF;
2121       IF  c_aging_bucket_name_csr%ISOPEN THEN
2122         CLOSE c_aging_bucket_name_csr;
2123       END IF;
2124       IF   c_cust_trx_type_csr%ISOPEN THEN
2125         CLOSE c_cust_trx_type_csr;
2126       END IF;
2127       IF   c_inventory_item_name_csr%ISOPEN THEN
2128         CLOSE c_inventory_item_name_csr;
2129       END IF;
2130       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
2131                             p_api_name  => l_api_name
2132                            ,p_pkg_name  => G_PKG_NAME
2133                            ,p_exc_name  => 'OTHERS'
2134                            ,x_msg_count  => x_msg_count
2135                            ,x_msg_data  => x_msg_data
2136                            ,p_api_type  => '_PVT');
2137   END populate_tcl_sources;
2138 
2139 
2140   ---------------------------------------------------------------------------
2141   -- Start of comments
2142   --      API name        : populate_tcl_sources
2143   --      Pre-reqs        : None
2144   --      Function        : Creates records for OKL_TXL_EXTENSION_V
2145   --                         This API will be called by Populate Sources
2146   --                         to do the bulk INSERTs of the Extension Line Sources
2147   --      Parameters      :
2148   --      IN              : p_trans_hdr_rec.source_id Required
2149   --                        p_trans_hdr_rec.source_table Required.
2150   --                          Value  G_TXL_CONTRACTS
2151   --      Version         : 1.0
2152   --      History         : Ravi Gooty created
2153   -- End of comments
2154   ---------------------------------------------------------------------------
2155   PROCEDURE populate_tcl_sources(
2156     p_api_version               IN             NUMBER
2157    ,p_init_msg_list             IN             VARCHAR2
2158    ,p_trans_hdr_rec             IN             tehv_rec_type
2159    ,p_acc_sources_tbl           IN             asev_tbl_type
2160    ,p_trans_line_tbl            IN             telv_tbl_type
2161    ,x_trans_line_tbl            OUT    NOCOPY  telv_tbl_type
2162    ,x_return_status             OUT    NOCOPY  VARCHAR2
2163    ,x_msg_count                 OUT    NOCOPY  NUMBER
2164    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
2165   )
2166   IS
2167     -----------------------------------------------------------------
2168     -- Declare Process Variable
2169     -----------------------------------------------------------------
2170     l_api_version              CONSTANT NUMBER         := 1;
2171     l_api_name                 CONSTANT VARCHAR2(30)   := 'POPULATE_TCL_SOURCES';
2172     l_return_status            VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
2173     ------------------------------------------------------------
2174     -- Declare records: Extension Headers, Extension Lines
2175     ------------------------------------------------------------
2176     l_tel_tbl_tbl         tel_tbl_tbl_type;
2177     l_tel_tbl_tbl_out     tel_tbl_tbl_type;
2178     l_tell_tbl_in         tell_tbl_type;
2179     l_tell_tbl_in_base    tell_tbl_type;
2180     l_tel_tbl_in          tel_tbl_type;
2181     l_tel_tbl_out         tel_tbl_type;
2182 
2183     -- Performant Cursor to fetch all the Kle_ids in Order
2184     CURSOR c_tcl_tbl_csr (p_tcn_id NUMBER)
2185     IS
2186       SELECT   tcl.khr_id           khr_id
2187               ,tcl.kle_id           kle_id
2188               ,tcl.sty_id           sty_id
2189               ,tcl.bkt_id           bkt_id
2190               ,tcl.id               tcl_id
2191         FROM   okl_txl_cntrct_lns_all tcl
2192        WHERE   tcl.tcn_id = p_tcn_id
2193     ORDER BY   kle_id, sty_id, bkt_id;
2194     l_prev_tcl_rec    c_tcl_tbl_csr%ROWTYPE;
2195     l_curr_tcl_rec    c_tcl_tbl_csr%ROWTYPE;
2196 
2197     TYPE tcl_tbl_type IS TABLE OF c_tcl_tbl_csr%ROWTYPE INDEX BY BINARY_INTEGER;  -- Added by PRASJAIN Bug#6134235
2198     l_tcl_tbl       tcl_tbl_type;  -- Added by PRASJAIN Bug#6134235
2199 
2200     CURSOR c_tcn_basic_csr ( p_tcn_id NUMBER)
2201     IS
2202       SELECT   tcn.id                           tcn_id
2203               ,tcn.khr_id                       khr_id
2204               ,tcn.set_of_books_id              ledger_id
2205               ,try.accounting_event_class_code  accounting_event_class_code
2206         FROM   okl_trx_contracts_all  tcn
2207               ,okl_trx_types_b        try
2208        WHERE  tcn.id = p_tcn_id
2209          AND  tcn.try_id = try.id
2210          AND  try.accounting_event_class_code IS NOT NULL;
2211     l_tcn_basic_csr_rec    c_tcn_basic_csr%ROWTYPE;
2212 
2213     -- Record structures based on Cursor Definitions
2214     l_ledger_lang_rec               c_ledger_lang_csr%ROWTYPE;
2215     l_k_lines_rec                   c_k_lines_csr%ROWTYPE;
2216     l_vendor_name_csr_rec           c_vendor_name_csr%ROWTYPE;
2217     l_installed_site_csr_rec        c_installed_site_csr%ROWTYPE;
2218     l_inventory_item_name_csr_rec   c_inventory_item_name_csr%ROWTYPE;
2219     l_inventory_org_name_rec        c_org_name_csr%ROWTYPE;
2220     l_cust_trx_type_csr_rec         c_cust_trx_type_csr%ROWTYPE;
2221     l_location_id_csr_rec           c_location_id_csr%ROWTYPE;
2222     l_manufacture_model_csr_rec     c_manufacture_model_csr%ROWTYPE;
2223     l_asset_year_mfg_csr_rec        c_asset_year_manufactured_csr%ROWTYPE;
2224     l_asset_location_name_csr_rec   c_asset_location_name_csr%ROWTYPE;
2225     l_aging_bucket_name_csr_rec     c_aging_bucket_name_csr%ROWTYPE;
2226     l_inv_org_name_code_csr         c_org_name_code_csr%ROWTYPE;
2227     l_acc_sources_tbl               asev_tbl_type;
2228     l_acc_sources_rec               asev_rec_type;
2229     l_acc_sources_found             BOOLEAN;
2230     ags_index                       NUMBER;
2231     -- Local Variables
2232     tel_index             NUMBER  := 0;
2233     tcl_count             NUMBER  := 0;
2234     idx                   NUMBER  := 0;
2235     idx1                  NUMBER  := 0;
2236     tl_sources_in         NUMBER  := 1;
2237     l_capture_sources     VARCHAR2(3); -- Flag to decide whether to Capture Sources or Not !
2238     l_trans_line_tbl      telv_tbl_type;
2239     l_fetch_sources       BOOLEAN := FALSE;
2240 
2241     -- Local Variables for enabling the Debug Statements
2242     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
2243     l_debug_enabled                    VARCHAR2(10);
2244     is_debug_procedure_on              BOOLEAN;
2245     is_debug_statement_on BOOLEAN;
2246   BEGIN
2247     l_debug_enabled := okl_debug_pub.check_log_enabled;
2248     -- check for logging on PROCEDURE level
2249     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
2250     -- check for logging on STATEMENT level
2251     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
2252     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2253                'begin debug APOKLRSLAB.pls call ' || l_api_name);
2254     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2255                'BEGIN API okl_sla_acc_sources_pvt.POPULATE_TCL_SOURCES');
2256     l_return_status := OKL_API.G_RET_STS_SUCCESS;
2257     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2258       'Calling OKL_API.START_ACTIVITY');
2259     l_return_status := OKL_API.START_ACTIVITY(
2260                          p_api_name       => l_api_name
2261                         ,p_pkg_name       => g_pkg_name
2262                         ,p_init_msg_list  => p_init_msg_list
2263                         ,l_api_version    => l_api_version
2264                         ,p_api_version    => p_api_version
2265                         ,p_api_type       => '_PVT'
2266                         ,x_return_status  => l_return_status);
2267     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2268       'After Start Activity l_return_status ' || l_return_status );
2269     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
2270     THEN
2271       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2272     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
2273     THEN
2274       RAISE OKL_API.G_EXCEPTION_ERROR;
2275     END IF;
2276 
2277     IF p_trans_hdr_rec.source_table <> G_TRX_CONTRACTS
2278     THEN
2279       OKL_API.set_message(
2280          p_app_name      => G_APP_NAME
2281         ,p_msg_name      => G_INVALID_VALUE
2282         ,p_token1        => G_COL_NAME_TOKEN
2283         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
2284       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2285       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2286     END IF;
2287 
2288     IF p_trans_hdr_rec.header_extension_id IS NULL
2289     THEN
2290       OKL_API.set_message(
2291          p_app_name      => G_APP_NAME
2292         ,p_msg_name      => G_INVALID_VALUE
2293         ,p_token1        => G_COL_NAME_TOKEN
2294         ,p_token1_value  => 'HEADER.HEADER_EXTENSION_ID');
2295       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2296       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2297     END IF;
2298 
2299     -- Assign the AGS Record to the Local Record Structure
2300     l_acc_sources_tbl := p_acc_sources_tbl;
2301     l_trans_line_tbl  := p_trans_line_tbl;
2302     -- Validation: Check whether the AGS Table is passed properly or not ..
2303     IF l_acc_sources_tbl.COUNT <= 0
2304     THEN
2305       OKL_API.set_message(
2306          p_app_name      => G_APP_NAME
2307         ,p_msg_name      => G_INVALID_VALUE
2308         ,p_token1        => G_COL_NAME_TOKEN
2309         ,p_token1_value  => 'ACCT_SOURCES.COUNT');
2310       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2311       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2312     END IF;
2313     -- Assign the l_acc_sources_rec as the first one of the l_acc_sources_tbl
2314     --  so that we can reuse the Inventory Organization ID
2315     l_acc_sources_rec := l_acc_sources_tbl( l_acc_sources_tbl.FIRST );
2316 
2317     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2318       'Executing the Cursor  c_tcn_basic_csr, tcn_id = ' || TO_CHAR( p_trans_hdr_rec.source_id) );
2319     FOR t_rec IN c_tcn_basic_csr (p_tcn_id => p_trans_hdr_rec.source_id )
2320     LOOP
2321       l_tcn_basic_csr_rec := t_rec;
2322     END LOOP;
2323 
2324     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2325       ' l_tcn_basic_csr_rec.accounting_event_class_code=' || l_tcn_basic_csr_rec.accounting_event_class_code ||
2326       ' l_tcn_basic_csr_rec.ledger_id=' || to_char(l_tcn_basic_csr_rec.ledger_id) );
2327 
2328     IF l_tcn_basic_csr_rec.accounting_event_class_code IS NULL
2329     THEN
2330       -- accounting_event_class_code is missing
2331       OKL_API.set_message(
2332          p_app_name      => G_APP_NAME
2333         ,p_msg_name      => G_INVALID_VALUE
2334         ,p_token1        => G_COL_NAME_TOKEN
2335         ,p_token1_value  => 'ACCOUNTING_EVENT_CLASS_CODE');
2336       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2337       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2338     END IF;
2339 
2340     -- Fetch the Ledger Language
2341     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2342       'Picked Language | Ledger Language | USERENV Language p_ledger_id=' || TO_CHAR(l_tcn_basic_csr_rec.ledger_id));
2343     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_tcn_basic_csr_rec.ledger_id )
2344     LOOP
2345       l_tell_tbl_in_base(tl_sources_in).language := t_rec.language_code;
2346       tl_sources_in := tl_sources_in + 1;
2347     END LOOP;
2348 
2349     -- Fetching Common Sources
2350     -- Populating MLS Sources at Transaction Line Level
2351     -- Populate Inventory Organization Name
2352     IF l_tcn_basic_csr_rec.accounting_event_class_code NOT IN (G_UPFRONT_TAX)
2353     THEN
2354       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2355         '*** AGS Inventory Org ID used to fetch teh Inventory Organization Name: Org ID=' ||
2356       l_acc_sources_rec.inventory_org_id_pk2 );
2357       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2358         '*** AGS Inventory Org ID used to fetch teh Inventory Organization Code : Org ID=' ||
2359       l_acc_sources_rec.inventory_org_id_pk2 );
2360       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2361         'Executing the Cursor c_org_name_code_csr. p_org_id= ' || to_char(l_acc_sources_rec.inventory_org_id_pk2) );
2362       FOR t_rec IN c_org_name_code_csr(
2363                      p_org_id      => l_acc_sources_rec.inventory_org_id_pk2 )
2364       LOOP
2365         l_inv_org_name_code_csr := t_rec;
2366       END LOOP;
2367 
2368       FOR tl_sources_in IN l_tell_tbl_in_base.FIRST .. l_tell_tbl_in_base.LAST
2369       LOOP
2370         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2371           'Executing the Cursor c_org_name_csr. p_org_id= ' || to_char(l_acc_sources_rec.inventory_org_id_pk2) ||
2372           ' ledger_language=' || l_tell_tbl_in_base(tl_sources_in).language );
2373         FOR t_rec IN c_org_name_csr(
2374                         p_org_id      => l_acc_sources_rec.inventory_org_id_pk2
2375                        ,p_ledger_lang => l_tell_tbl_in_base(tl_sources_in).language )
2376         LOOP
2377           l_tell_tbl_in_base(tl_sources_in).inventory_org_name := t_rec.org_name;
2378         END LOOP;
2379       END LOOP;
2380     END IF;
2381 
2382     -- Fetch all the Transaction Lines for the given Transaction Header
2383     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2384       'Executing the Cursor  c_tcl_tbl_csr, tcn_id = ' || TO_CHAR( p_trans_hdr_rec.source_id) );
2385     -- Initialize the tel_index
2386     tel_index := 1;
2387     -- Initialize the tcl_count to ZERO
2388     tcl_count := 0;
2389     -- Start PRASJAIN Bug#6134235
2390     FOR t_rec IN c_tcl_tbl_csr( p_tcn_id => p_trans_hdr_rec.source_id )
2391     LOOP
2392       tcl_count := tcl_count + 1;
2393       l_tcl_tbl(tcl_count) := t_rec;
2394     END LOOP;
2395     -- End PRASJAIN Bug#6134235
2396 
2397     -- Start PRASJAIN Bug#6134235
2398     FOR idx IN l_tcl_tbl.FIRST .. l_tcl_tbl.LAST
2399     LOOP
2400       -- Logic Explanation:
2401       -- 1. Check for the Count of the Trx. Lines fetched from DB
2402       -- 2. Compare this count with the count of Trx. Lines passed to this API
2403       -- 3. If the count is same, then, capture sources for every Trx. Line
2404       --    otherwise, capture sources for only those transaction line, which have
2405       --    been passed by the Accounting Engine
2406       l_capture_sources := 'N';
2407       IF tcl_count = l_trans_line_tbl.COUNT
2408       THEN
2409         -- If count is same, then capture sources for every Transaction Detail Line
2410         l_capture_sources := 'Y';
2411         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2412           'Case 1: Transaction Line Count in DB = Transaction Detail Line Count of the Input Param Table !' );
2413       ELSE
2414         idx1 := l_trans_line_tbl.FIRST;
2415         LOOP
2416           IF l_tcl_tbl(idx).tcl_id    = l_trans_line_tbl(idx1).source_id
2417           THEN
2418             l_capture_sources := 'Y';
2419             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2420               'Case 2: Populate Sources has been asked to capture sources for the Current Transaction Detail by Accounting Engine ' ||
2421               ' TCL ID = ' || TO_CHAR( l_trans_line_tbl(idx1).source_id ) );
2422           END IF;
2423           -- Exit when this is the Last Record or the Transaction Details has been found
2424           EXIT WHEN ( idx1 = l_trans_line_tbl.LAST )  -- When reached End of the Table
2425                  OR ( l_capture_sources = 'Y'     ); -- Or When the TXD has been found
2426           -- Increment the rxl_index
2427           idx1 := l_trans_line_tbl.NEXT( idx1 );
2428         END LOOP; -- Loop on l_trans_line_tbl ..
2429       END IF; --  IF tcl_count = l_trans_line_tbl.COUNT ..
2430 
2431       IF (l_capture_sources = 'Y')
2432       THEN
2433         -- Store the iterative recrod to the Local variable
2434         l_curr_tcl_rec := l_tcl_tbl(idx);
2435         -- End PRASJAIN Bug#6134235
2436 
2437         -- Fetch the Sources using the cursors only if
2438         --  If this the First Transaction Line (Or)
2439         --  The previous Transation Line kle_id is different than the Current Transaction Line
2440         l_fetch_sources := FALSE;
2441         IF tel_index = 1
2442         THEN
2443           l_fetch_sources := TRUE;
2444         ELSE
2445           IF l_curr_tcl_rec.kle_id <> l_prev_tcl_rec.kle_id
2446           THEN
2447             l_fetch_sources := TRUE;
2448           END IF;
2449         END IF;
2450 
2451         IF l_fetch_sources
2452         THEN
2453           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2454             '**** Need to fetch the Sources Afresh ****** ' ||
2455             'Current Kle_id = ' || l_curr_tcl_rec.kle_id || '| Previous Kle_id = ' || l_prev_tcl_rec.kle_id );
2456         ELSE
2457           -- Store Previously Fetched Transaction Related Sources to the Current Transaction Line
2458 --          l_tel_tbl_tbl(tel_index) := l_tel_tbl_tbl(tel_index - 1);
2459           l_tel_tbl_in(tel_index) := l_tel_tbl_in(tel_index - 1);
2460         END IF;
2461         -- For a given transaction Line fetch the corresponding Account Generator Sources
2462         -- Logic:
2463         --   Loop on the l_acc_sources_tbl till we find that
2464         --     l_acc_sources_tbl.source_id = l_curr_tcl_rec.tcl_id
2465         --   If the AGS record has been found assign it to l_acc_sources_rec
2466         --     else raise an exception.
2467         l_acc_sources_found := FALSE;
2468         l_acc_sources_rec   := NULL;
2469         ags_index := l_acc_sources_tbl.FIRST;
2470         LOOP
2471           IF l_acc_sources_tbl(ags_index).source_id = l_curr_tcl_rec.tcl_id
2472           THEN
2473             l_acc_sources_found := TRUE;
2474             l_acc_sources_rec := l_acc_sources_tbl(ags_index);
2475           END IF;
2476           EXIT WHEN l_acc_sources_found OR ( ags_index = l_acc_sources_tbl.LAST );
2477           ags_index := l_acc_sources_tbl.NEXT(ags_index);
2478         END LOOP;
2479         -- If the AGS Index is not found then return error
2480         IF l_acc_sources_found = FALSE
2481         THEN
2482           -- accounting_event_class_code is missing
2483           OKL_API.set_message(
2484              p_app_name      => G_APP_NAME
2485             ,p_msg_name      => G_INVALID_VALUE
2486             ,p_token1        => G_COL_NAME_TOKEN
2487             ,p_token1_value  => 'AGS_SOURCES.SOURCE_ID');
2488           l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2489           RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2490         END IF; -- IF l_acc_sources_found = FALSE
2491         -- Override the Source ID, Table and other related sources
2492         l_tel_tbl_in(tel_index).source_id    := l_curr_tcl_rec.tcl_id;
2493         l_tel_tbl_in(tel_index).source_table := G_TXL_CONTRACTS;
2494         l_tel_tbl_in(tel_index).teh_id       := p_trans_hdr_rec.header_extension_id;
2495 
2496         l_tell_tbl_in := l_tell_tbl_in_base;
2497 
2498         IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2499            (G_BOOKING, G_REBOOK, G_RE_LEASE,  G_ACCRUAL, G_MISCELLANEOUS)
2500         THEN
2501           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2502             'Executing the Cursor c_cust_trx_type_csr rec_trx_types_pk=' || to_char(l_acc_sources_rec.rec_trx_types_pk) );
2503           FOR t_rec IN  c_cust_trx_type_csr( p_trx_id => l_acc_sources_rec.rec_trx_types_pk )
2504           LOOP
2505             l_cust_trx_type_csr_rec := t_rec;
2506             l_tel_tbl_in(tel_index).recievables_trx_type_name  :=l_cust_trx_type_csr_rec.trx_name;
2507           END LOOP; -- c_cust_trx_type_csr
2508         END IF;
2509 
2510         -- Store the Inventory Organization Code
2511         l_tel_tbl_in(tel_index).inventory_org_code := l_inv_org_name_code_csr.org_name;
2512 
2513         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2514           ' l_curr_tcl_rec.tcl_id=' || to_char(l_curr_tcl_rec.tcl_id) ||
2515           ' l_curr_tcl_rec.khr_id=' || to_char(l_curr_tcl_rec.khr_id) ||
2516           ' l_curr_tcl_rec.kle_id=' || to_char(l_curr_tcl_rec.kle_id) ||
2517           ' l_curr_tcl_rec.bkt_id=' || to_char(l_curr_tcl_rec.bkt_id) ||
2518           ' l_curr_tcl_rec.sty_id=' || to_char(l_curr_tcl_rec.sty_id) );
2519 
2520         -- If kle_id IS NOT NULL and l_fetch_sources is TRUE then ..
2521         IF l_fetch_sources AND
2522            l_curr_tcl_rec.kle_id IS NOT NULL
2523         THEN
2524           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2525             'Executing the curosr c_k_lines_csr. kle_id= ' || to_char(l_curr_tcl_rec.kle_id) );
2526           FOR t_rec IN  c_k_lines_csr (l_curr_tcl_rec.kle_id)
2527           LOOP
2528             l_k_lines_rec   := t_rec;
2529             l_tel_tbl_in(tel_index).contract_line_type       := l_k_lines_rec.contract_line_type;
2530             IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2531                 ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_PRINCIPAL_ADJUSTMENT )
2532             THEN
2533               l_tel_tbl_in(tel_index).fee_type_code          := l_k_lines_rec.fee_type;
2534             END IF;
2535             IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2536                  ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_PRINCIPAL_ADJUSTMENT,
2537                    G_MISCELLANEOUS, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET )
2538             THEN
2539               l_tel_tbl_in(tel_index).asset_number           := l_k_lines_rec.asset_number;
2540             END IF;
2541             IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2542                (G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET)
2543             THEN
2544               l_tel_tbl_in(tel_index).contract_line_number   := l_k_lines_rec.line_number;
2545             END IF;
2546             IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2547                  ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_RECEIPT_APPLICATION,
2548                    G_PRINCIPAL_ADJUSTMENT, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET )
2549             THEN
2550               l_tel_tbl_in(tel_index).asset_delivered_date   := l_k_lines_rec.date_delivery_expected;
2551             END IF;
2552           END LOOP; -- c_k_lines_csr
2553 
2554           IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2555               (G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_PRINCIPAL_ADJUSTMENT,
2556                 G_MISCELLANEOUS, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET)
2557           THEN
2558             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2559               'Executing the Cursor c_location_id_csr. kle_id= ' || to_char(l_curr_tcl_rec.kle_id) ||
2560               ' khr_id=' || to_char(l_tcn_basic_csr_rec.khr_id) );
2561             OPEN c_location_id_csr(l_curr_tcl_rec.kle_id,l_tcn_basic_csr_rec.khr_id );
2562             FETCH c_location_id_csr into l_location_id_csr_rec;
2563             CLOSE c_location_id_csr;
2564             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2565               'Executing the Cursor l_vendor_name_csr_rec. kle_id= ' || to_char(l_curr_tcl_rec.kle_id) ||
2566               ' khr_id=' || to_char(l_tcn_basic_csr_rec.khr_id) );
2567             FOR t_rec  IN c_vendor_name_csr(
2568                              l_curr_tcl_rec.kle_id
2569                             ,l_tcn_basic_csr_rec.khr_id)
2570             LOOP
2571               l_vendor_name_csr_rec := t_rec;
2572               l_tel_tbl_in(tel_index).asset_vendor_name   := l_vendor_name_csr_rec.vendor_name;
2573 	      -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
2574               l_tel_tbl_in(tel_index).asset_vendor_id   := l_vendor_name_csr_rec.vendor_id;
2575               -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
2576             END LOOP;  -- c_vendor_name_csr
2577             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2578               'Executing the Cursor c_asset_location_name_csr. location_id=' ||
2579               TO_CHAR(l_location_id_csr_rec.location_id) );
2580             FOR t_rec  IN  c_asset_location_name_csr(l_location_id_csr_rec.location_id)
2581             LOOP
2582               l_asset_location_name_csr_rec := t_rec;
2583               l_tel_tbl_in(tel_index).fixed_asset_location_name := l_asset_location_name_csr_rec.asset_location_name;
2584             END LOOP;  -- c_asset_location_name_csr
2585             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2586               'Executing the Cursor l_installed_site_csr_rec. kle_id= ' || to_char(l_curr_tcl_rec.kle_id) ||
2587               ' khr_id=' || to_char(l_tcn_basic_csr_rec.khr_id) );
2588             FOR t_rec  IN  c_installed_site_csr(
2589                                                 l_curr_tcl_rec.kle_id
2590                                                ,l_tcn_basic_csr_rec.khr_id)
2591             LOOP
2592               l_installed_site_csr_rec := t_rec;
2593               l_tel_tbl_in(tel_index).installed_site_id   := l_installed_site_csr_rec.installed_site_id;
2594             END LOOP;  -- c_installed_site_csr
2595           END IF;  -- accounting_event_class_code for 7 events
2596 
2597           IF l_tcn_basic_csr_rec.accounting_event_class_code IN
2598                  ( G_TERMINATION, G_EVERGREEN, G_ACCRUAL, G_RECEIPT_APPLICATION,
2599                    G_PRINCIPAL_ADJUSTMENT, G_ASSET_DISPOSITION, G_UPFRONT_TAX, G_SPLIT_ASSET )
2600           THEN
2601             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2602               'Executing the Cursor c_manufacture_model_csr. kle_id= ' || to_char(l_curr_tcl_rec.kle_id) ||
2603               ' khr_id=' || to_char(l_tcn_basic_csr_rec.khr_id) );
2604             FOR t_rec IN  c_manufacture_model_csr (
2605                             l_curr_tcl_rec.kle_id
2606                            ,l_tcn_basic_csr_rec.khr_ID)
2607             LOOP
2608               l_manufacture_model_csr_rec := t_rec;
2609               IF l_tcn_basic_csr_rec.accounting_event_class_code NOT LIKE G_ACCRUAL
2610               THEN
2611                 l_tel_tbl_in(tel_index).asset_manufacturer_name    :=  l_manufacture_model_csr_rec.manufacturer_name;
2612               END IF;
2613               l_tel_tbl_in(tel_index).asset_model_number         :=  l_manufacture_model_csr_rec.model_number;
2614               put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2615                 'Executing the Cursor c_asset_year_manufactured_csr. kle_id= ' || to_char(l_curr_tcl_rec.kle_id) ||
2616                 ' khr_id=' || to_char(l_tcn_basic_csr_rec.khr_id) );
2617               FOR  t_year_man_rec IN c_asset_year_manufactured_csr (
2618                                                  l_curr_tcl_rec.kle_id
2619                                                 ,l_tcn_basic_csr_rec.khr_id)
2620               LOOP
2621                 l_asset_year_mfg_csr_rec := t_year_man_rec;
2622                 l_tel_tbl_in(tel_index).asset_year_manufactured := l_asset_year_mfg_csr_rec.Year_of_manufacture;
2623               END LOOP; -- c_asset_year_manufactured_csr
2624               IF l_tcn_basic_csr_rec.accounting_event_class_code NOT IN
2625                      ( G_RECEIPT_APPLICATION, G_PRINCIPAL_ADJUSTMENT, G_ACCRUAL, G_MISCELLANEOUS )
2626               THEN
2627                 l_tel_tbl_in(tel_index).asset_category_name        :=  l_manufacture_model_csr_rec.asset_category_name;
2628               END IF;
2629             END LOOP;  -- c_manufacture_model_csr
2630           END IF;  -- accounting_event_class_code for 5 events
2631         END IF; -- IF l_tcn_basic_csr_rec.kle_id IS NOT NULL
2632 
2633         IF l_tcn_basic_csr_rec.accounting_event_class_code IN (G_ACCRUAL,G_ASSET_DISPOSITION, G_SPLIT_ASSET)
2634         THEN
2635           FOR tl_sources_in IN l_tell_tbl_in.FIRST .. l_tell_tbl_in.LAST
2636           LOOP
2637             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2638               'Executing the Cursor c_asset_year_manufactured_csr. p_inventory_item_id_pk1= ' ||
2639               to_char(l_acc_sources_rec.inventory_item_id_pk1) || ' p_inventory_org_id_pk2=' ||
2640               to_char(l_acc_sources_rec.inventory_org_id_pk2) || ' ledger_language=' ||
2641               l_tell_tbl_in(tl_sources_in).language );
2642             FOR t_rec IN c_inventory_item_name_csr(
2643                          p_inventory_item_id_pk1 => l_acc_sources_rec.inventory_item_id_pk1
2644                         ,p_inventory_org_id_pk2  => l_acc_sources_rec.inventory_org_id_pk2
2645                         ,p_ledger_language       => l_tell_tbl_in(tl_sources_in).language)
2646             LOOP
2647               l_inventory_item_name_csr_rec := t_rec;
2648               l_tell_tbl_in(tl_sources_in).inventory_item_name      := l_inventory_item_name_csr_rec.description;
2649               l_tel_tbl_in(tel_index).inventory_item_name_code := l_inventory_item_name_csr_rec.b_description;
2650             END LOOP;
2651           END LOOP;
2652         END IF; -- IF l_tcn_basic_csr_rec.accounting_event_class_code IN (G_ACCRUAL,G_ASSET_DISPOSITION, G_SPLIT_ASSET)
2653 
2654         IF l_tcn_basic_csr_rec.accounting_event_class_code IN (G_GLP)
2655         THEN
2656           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2657             'Executing cursor c_aging_bucket_name_csr bkt_id=' || l_curr_tcl_rec.bkt_id );
2658           FOR t_rec IN c_aging_bucket_name_csr(l_curr_tcl_rec.bkt_id)
2659           LOOP
2660             l_aging_bucket_name_csr_rec := t_rec;
2661             l_tel_tbl_in(tel_index).aging_bucket_name  :=l_aging_bucket_name_csr_rec.bucket_name;
2662           END LOOP;  -- c_aging_bucket_name_csr
2663         END IF;
2664 
2665         -- Assigning the Memo Indicator to the Extension Line Record structure ..
2666         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2667           '** AGS Memo Flag ' || l_acc_sources_rec.memo_yn );
2668         l_tel_tbl_in(tel_index).memo_flag := l_acc_sources_rec.memo_yn;
2669 
2670         -- If Log is enabled, print all the sources fetched.
2671         IF (l_debug_enabled='Y' AND is_debug_statement_on)
2672         THEN
2673           write_ext_line_to_log(
2674             p_tel_rec  => l_tel_tbl_in(tel_index)
2675            ,p_tell_tbl => l_tell_tbl_in
2676            ,p_module   => l_module);
2677         END IF;
2678 
2679         -- Store khr_id, kle_id, sty_id, bkt_id of the current transaction line.
2680         -- This recrod will be used during comparision from next iteration onwards
2681         l_prev_tcl_rec := l_tcl_tbl(idx);
2682         -- Build the record strucutre now ..
2683         l_tel_tbl_tbl(tel_index).tel_rec  := l_tel_tbl_in(tel_index);
2684         l_tel_tbl_tbl(tel_index).tell_tbl := l_tell_tbl_in; -- Translatable Table capturing sources
2685         -- Increment the tel_index
2686         tel_index := tel_index + 1;
2687       END IF;
2688     END LOOP;
2689 
2690 
2691     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2692       'Calling OKL_TRX_EXTENSION_PVT.create_txl_extension API.' );
2693 
2694     okl_trx_extension_pvt.create_txl_extension(
2695        p_api_version     => p_api_version
2696       ,p_init_msg_list   => p_init_msg_list
2697       ,x_return_status   => l_return_status
2698       ,x_msg_count       => x_msg_count
2699       ,x_msg_data        => x_msg_data
2700       ,p_tel_tbl_tbl     => l_tel_tbl_tbl
2701       ,x_tel_tbl_tbl     => l_tel_tbl_tbl_out
2702     );
2703     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2704       'After okl_trx_extension_pvt.create_txl_extension-tbl. l_return_status ' || l_return_status );
2705     IF l_return_status = FND_API.G_RET_STS_ERROR
2706     THEN
2707       RAISE FND_API.G_EXC_ERROR;
2708     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
2709     THEN
2710       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2711     END IF;
2712 
2713     -- Return the values
2714     x_trans_line_tbl := p_trans_line_tbl;  --Added PRASJAIN Bug#6134235
2715     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2716       'Calling okl_api.end_activity');
2717     okl_api.end_activity(
2718        x_msg_count => x_msg_count
2719       ,x_msg_data => x_msg_data);
2720     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2721       'END okl_sla_acc_sources_pvt.POPULATE_TCL_SOURCES');
2722     x_return_status := OKL_API.G_RET_STS_SUCCESS;
2723   EXCEPTION
2724     ------------------------------------------------------------
2725     -- Exception handling
2726     ------------------------------------------------------------
2727     WHEN OKL_API.G_EXCEPTION_ERROR
2728     THEN
2729       IF  c_tcl_tbl_csr%ISOPEN THEN
2730         CLOSE c_tcl_tbl_csr;
2731       END IF;
2732       IF  c_k_lines_csr%ISOPEN THEN
2733         CLOSE c_k_lines_csr;
2734       END IF;
2735       IF  c_vendor_name_csr%ISOPEN THEN
2736         CLOSE c_vendor_name_csr;
2737       END IF;
2738       IF  c_manufacture_model_csr%ISOPEN THEN
2739         CLOSE c_manufacture_model_csr;
2740       END IF;
2741       IF  c_location_id_csr%ISOPEN THEN
2742         CLOSE c_location_id_csr;
2743       END IF;
2744       IF  c_asset_location_name_csr%ISOPEN THEN
2745         CLOSE c_asset_location_name_csr;
2746       END IF;
2747       IF  c_asset_year_manufactured_csr%ISOPEN THEN
2748         CLOSE c_asset_year_manufactured_csr;
2749       END IF;
2750       IF   c_installed_site_csr%ISOPEN THEN
2751         CLOSE c_installed_site_csr;
2752       END IF;
2753       IF  c_aging_bucket_name_csr%ISOPEN THEN
2754         CLOSE c_aging_bucket_name_csr;
2755       END IF;
2756       IF   c_cust_trx_type_csr%ISOPEN THEN
2757         CLOSE c_cust_trx_type_csr;
2758       END IF;
2759       IF   c_inventory_item_name_csr%ISOPEN THEN
2760         CLOSE c_inventory_item_name_csr;
2761       END IF;
2762       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
2763                             p_api_name  => l_api_name
2764                            ,p_pkg_name  => G_PKG_NAME
2765                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
2766                            ,x_msg_count  => x_msg_count
2767                            ,x_msg_data  => x_msg_data
2768                            ,p_api_type  => '_PVT');
2769 
2770     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
2771     THEN
2772       IF  c_tcl_tbl_csr%ISOPEN THEN
2773         CLOSE c_tcl_tbl_csr;
2774       END IF;
2775       IF  c_k_lines_csr%ISOPEN THEN
2776         CLOSE c_k_lines_csr;
2777       END IF;
2778       IF  c_vendor_name_csr%ISOPEN THEN
2779         CLOSE c_vendor_name_csr;
2780       END IF;
2781       IF  c_manufacture_model_csr%ISOPEN THEN
2782         CLOSE c_manufacture_model_csr;
2783       END IF;
2784       IF  c_location_id_csr%ISOPEN THEN
2785         CLOSE c_location_id_csr;
2786       END IF;
2787       IF  c_asset_location_name_csr%ISOPEN THEN
2788         CLOSE c_asset_location_name_csr;
2789       END IF;
2790       IF  c_asset_year_manufactured_csr%ISOPEN THEN
2791         CLOSE c_asset_year_manufactured_csr;
2792       END IF;
2793       IF   c_installed_site_csr%ISOPEN THEN
2794         CLOSE c_installed_site_csr;
2795       END IF;
2796       IF  c_aging_bucket_name_csr%ISOPEN THEN
2797         CLOSE c_aging_bucket_name_csr;
2798       END IF;
2799       IF   c_cust_trx_type_csr%ISOPEN THEN
2800         CLOSE c_cust_trx_type_csr;
2801       END IF;
2802       IF   c_inventory_item_name_csr%ISOPEN THEN
2803         CLOSE c_inventory_item_name_csr;
2804       END IF;
2805       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
2806                             p_api_name  => l_api_name
2807                            ,p_pkg_name  => G_PKG_NAME
2808                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
2809                            ,x_msg_count  => x_msg_count
2810                            ,x_msg_data  => x_msg_data
2811                            ,p_api_type  => '_PVT');
2812     WHEN OTHERS
2813     THEN
2814       IF  c_tcl_tbl_csr%ISOPEN THEN
2815         CLOSE c_tcl_tbl_csr;
2816       END IF;
2817       IF  c_k_lines_csr%ISOPEN THEN
2818         CLOSE c_k_lines_csr;
2819       END IF;
2820       IF  c_vendor_name_csr%ISOPEN THEN
2821         CLOSE c_vendor_name_csr;
2822       END IF;
2823       IF  c_manufacture_model_csr%ISOPEN THEN
2824         CLOSE c_manufacture_model_csr;
2825       END IF;
2826       IF  c_location_id_csr%ISOPEN THEN
2827         CLOSE c_location_id_csr;
2828       END IF;
2829       IF  c_asset_location_name_csr%ISOPEN THEN
2830         CLOSE c_asset_location_name_csr;
2831       END IF;
2832       IF  c_asset_year_manufactured_csr%ISOPEN THEN
2833         CLOSE c_asset_year_manufactured_csr;
2834       END IF;
2835       IF   c_installed_site_csr%ISOPEN THEN
2836         CLOSE c_installed_site_csr;
2837       END IF;
2838       IF  c_aging_bucket_name_csr%ISOPEN THEN
2839         CLOSE c_aging_bucket_name_csr;
2840       END IF;
2841       IF   c_cust_trx_type_csr%ISOPEN THEN
2842         CLOSE c_cust_trx_type_csr;
2843       END IF;
2844       IF   c_inventory_item_name_csr%ISOPEN THEN
2845         CLOSE c_inventory_item_name_csr;
2846       END IF;
2847       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
2848                             p_api_name  => l_api_name
2849                            ,p_pkg_name  => G_PKG_NAME
2850                            ,p_exc_name  => 'OTHERS'
2851                            ,x_msg_count  => x_msg_count
2852                            ,x_msg_data  => x_msg_data
2853                            ,p_api_type  => '_PVT');
2854   END populate_tcl_sources;
2855 
2856   ---------------------------------------------------------------------------
2857   -- Start of comments
2858   -- API name    : populate_sources
2859   -- Pre-reqs    : None
2860   -- Function    : Use this API to populate sources at the Transaction Header
2861   --                level and at the Transaction Line level too.
2862   -- Parameters  :
2863   -- IN          : p_source_id  IN NUMBER  Required
2864   --                  Pass Transaction Header id.
2865   --               p_source_hdr_table IN VARCHAR2 Required
2866   --                 Pass the table name of the Transaction Header.
2867   --                 Eg. OKL_TRX_CONTRACTS, OKL_TRX_ASSETS ..
2868   --               p_trans_line_tbl  trans_line_tbl_type Required.
2869   --                 source_line_id     NUMBER Required
2870   --                   Pass the Transaction Line id
2871   --                 source_line_table  VARCHAR2(30) Required
2872   --                   Pass the table name of the Transaction Table.
2873   --                   Eg. OKL_TXL_CNTRCT_LNS ..
2874   -- Version     : 1.0
2875   -- History     : Ravindranath Gooty created
2876   -- End of comments
2877   ---------------------------------------------------------------------------
2878   PROCEDURE populate_sources(
2879     p_api_version               IN             NUMBER
2880    ,p_init_msg_list             IN             VARCHAR2
2881    ,p_trans_hdr_rec             IN             tehv_rec_type
2882    ,p_trans_line_tbl            IN             telv_tbl_type
2883    ,p_acc_sources_tbl           IN             asev_tbl_type
2884    ,x_return_status             OUT    NOCOPY  VARCHAR2
2885    ,x_msg_count                 OUT    NOCOPY  NUMBER
2886    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
2887   )
2888   IS
2889     -----------------------------------------------------------------
2890     -- Declare Process Variable
2891     -----------------------------------------------------------------
2892     l_api_version      CONSTANT NUMBER         := 1;
2893     l_api_name         CONSTANT VARCHAR2(30)   := 'POPULATE_SOURCES-OKL';
2894     l_return_status    VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
2895     -- Local Variables for enabling the Debug Statements
2896     l_trans_hdr_rec       tehv_rec_type;
2897     l_acc_sources_tbl     asev_tbl_type;
2898     l_trans_line_tbl      telv_tbl_type; -- Added by PRASJAIN Bug#6134235
2899     x_trans_line_tbl      telv_tbl_type; -- Added by PRASJAIN Bug#6134235
2900 
2901     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
2902     l_debug_enabled       VARCHAR2(10);
2903     is_debug_procedure_on BOOLEAN;
2904     is_debug_statement_on BOOLEAN;
2905   BEGIN
2906     l_debug_enabled := okl_debug_pub.check_log_enabled;
2907     -- check for logging on PROCEDURE level
2908     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
2909     -- check for logging on STATEMENT level
2910     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
2911     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2912                'begin debug APOKLRSLAB.pls call ' || l_api_name);
2913     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2914                'BEGIN API okl_sla_acc_sources_pvt.POPULATE_SOURCES');
2915     l_return_status := OKL_API.G_RET_STS_SUCCESS;
2916     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2917       'Calling OKL_API.START_ACTIVITY');
2918     l_return_status := OKL_API.START_ACTIVITY(
2919                          p_api_name       => l_api_name
2920                         ,p_pkg_name       => g_pkg_name
2921                         ,p_init_msg_list  => p_init_msg_list
2922                         ,l_api_version    => l_api_version
2923                         ,p_api_version    => p_api_version
2924                         ,p_api_type       => '_PVT'
2925                         ,x_return_status  => l_return_status);
2926     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2927       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2928     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
2929       RAISE OKL_API.G_EXCEPTION_ERROR;
2930     END IF;
2931     -- Copy the input parameters to the local variables
2932     l_trans_hdr_rec   := p_trans_hdr_rec;
2933     l_acc_sources_tbl := p_acc_sources_tbl;
2934     l_trans_line_tbl  := p_trans_line_tbl; -- Added by PRASJAIN Bug#6134235
2935     IF l_acc_sources_tbl.COUNT <= 0
2936     THEN
2937       -- Raise an error message saying that the Sources should be passed !
2938       OKL_API.set_message(
2939          p_app_name      => G_APP_NAME
2940         ,p_msg_name      => G_INVALID_VALUE
2941         ,p_token1        => G_COL_NAME_TOKEN
2942         ,p_token1_value  => 'P_ACC_SOURCES_TBL.COUNT');
2943       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2944       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2945     END IF;
2946 
2947     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
2948       'Input Parameters p_source_hdr_id=' || to_char(l_trans_hdr_rec.source_id) || ' Header Table=' || l_trans_hdr_rec.source_table );
2949     IF l_trans_hdr_rec.source_table = G_TRX_CONTRACTS
2950     THEN
2951       -- Calling populate_tcn_sources for OKL Transactions..
2952       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2953         'Calling the populate_tcn_sources' );
2954       populate_tcn_sources(
2955          p_api_version     => l_api_version
2956         ,p_init_msg_list   => p_init_msg_list
2957         ,px_trans_hdr_rec  => l_trans_hdr_rec
2958         ,p_acc_sources_rec => l_acc_sources_tbl( l_acc_sources_tbl.FIRST )
2959         ,x_return_status   => l_return_status
2960         ,x_msg_count       => x_msg_count
2961         ,x_msg_data        => x_msg_data );
2962       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2963         'After populate_tcn_sources: l_return_status ' || l_return_status );
2964     ELSE
2965       -- Return with an error message
2966       OKL_API.set_message(
2967         p_app_name      => G_APP_NAME
2968        ,p_msg_name      => G_INVALID_VALUE
2969        ,p_token1        => G_COL_NAME_TOKEN
2970        ,p_token1_value  => 'HEADER.SOURCE_TABLE');
2971       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
2972       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2973     END IF;
2974     -- Check the return status and if errored, return the error back
2975     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2976       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2977     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
2978       RAISE OKL_API.G_EXCEPTION_ERROR;
2979     END IF;
2980     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2981       'After populate_tcn_sources: HEADER_EXTENSION_ID= ' || l_trans_hdr_rec.header_extension_id );
2982     -- Call the Populate TCL Sources API to populate the Transaction Line Level Sources
2983     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2984       'Before the Call to the Populate_tcl_sources_tbl version');
2985     populate_tcl_sources(
2986        p_api_version     => l_api_version
2987       ,p_init_msg_list   => p_init_msg_list
2988       ,p_trans_hdr_rec   => l_trans_hdr_rec
2989       ,p_acc_sources_tbl => l_acc_sources_tbl
2990       ,p_trans_line_tbl  => l_trans_line_tbl -- Added by PRASJAIN Bug#6134235
2991       ,x_trans_line_tbl  => x_trans_line_tbl -- Added by PRASJAIN Bug#6134235
2992       ,x_return_status   => l_return_status
2993       ,x_msg_count       => x_msg_count
2994       ,x_msg_data        => x_msg_data );
2995     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
2996       'After the Call to the Populate_tcl_sources_tbl version' || l_return_status);
2997     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
2998       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
2999     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
3000       RAISE OKL_API.G_EXCEPTION_ERROR;
3001     END IF;
3002     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3003       'Calling okl_api.end_activity');
3004     okl_api.end_activity(
3005        x_msg_count => x_msg_count
3006       ,x_msg_data  => x_msg_data);
3007     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3008       'END okl_sla_acc_sources_pvt.POPULATE_SOURCES');
3009     x_return_status := OKL_API.G_RET_STS_SUCCESS;
3010   EXCEPTION
3011     ------------------------------------------------------------
3012     -- Exception handling
3013     ------------------------------------------------------------
3014     WHEN OKL_API.G_EXCEPTION_ERROR
3015     THEN
3016       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3017                             p_api_name  => l_api_name
3018                            ,p_pkg_name  => G_PKG_NAME
3019                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
3020                            ,x_msg_count => x_msg_count
3021                            ,x_msg_data  => x_msg_data
3022                            ,p_api_type  => '_PVT');
3023     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
3024     THEN
3025       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3026                             p_api_name  => l_api_name
3027                            ,p_pkg_name  => G_PKG_NAME
3028                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
3029                            ,x_msg_count => x_msg_count
3030                            ,x_msg_data  => x_msg_data
3031                            ,p_api_type  => '_PVT');
3032     WHEN OTHERS
3033     THEN
3034      x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3035                             p_api_name  => l_api_name
3036                            ,p_pkg_name  => G_PKG_NAME
3037                            ,p_exc_name  => 'OTHERS'
3038                            ,x_msg_count => x_msg_count
3039                            ,x_msg_data  => x_msg_data
3040                            ,p_api_type  => '_PVT');
3041   END populate_sources;
3042 
3043   PROCEDURE delete_trx_extension(
3044     p_api_version               IN             NUMBER
3045    ,p_init_msg_list             IN             VARCHAR2
3046    ,p_trans_hdr_rec             IN             tehv_rec_type
3047    ,x_trans_line_tbl            OUT    NOCOPY  telv_tbl_type
3048    ,x_return_status             OUT    NOCOPY  VARCHAR2
3049    ,x_msg_count                 OUT    NOCOPY  NUMBER
3050    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
3051   )
3052   IS
3053     -----------------------------------------------------------------
3054     -- Declare Process Variable
3055     -----------------------------------------------------------------
3056     l_api_version      CONSTANT NUMBER         := 1;
3057     l_api_name         CONSTANT VARCHAR2(30)   := 'DELETE_TRX_EXTENSION';
3058     l_return_status    VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
3059     l_telv_tbl         okl_tel_pvt.telv_tbl_type;
3060     tel_index          BINARY_INTEGER;
3061     l_trans_hdr_rec    tehv_rec_type;
3062     -- Cursor Definitions
3063     CURSOR get_txl_ext_hdr_id( p_trx_hdr_id  NUMBER, p_trx_hdr_table VARCHAR2)
3064     IS
3065       SELECT   teh.header_extension_id  header_extension_id
3066         FROM   OKL_TRX_EXTENSION_B teh
3067        WHERE  teh.source_id = p_trx_hdr_id
3068          AND  teh.source_table = p_trx_hdr_table;
3069 
3070     CURSOR get_txl_ext_line_ids( p_teh_id  NUMBER)
3071     IS
3072       SELECT   tel.line_extension_id  line_extension_id
3073               ,tel.source_id          source_id
3074               ,tel.source_table       source_table
3075         FROM   OKL_TXL_EXTENSION_B tel
3076        WHERE  tel.teh_id = p_teh_id;
3077     -- Local Variables for enabling the Debug Statements
3078     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
3079     l_debug_enabled                    VARCHAR2(10);
3080     is_debug_procedure_on              BOOLEAN;
3081     is_debug_statement_on              BOOLEAN;
3082   BEGIN
3083     l_debug_enabled := okl_debug_pub.check_log_enabled;
3084     -- check for logging on PROCEDURE level
3085     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
3086     -- check for logging on STATEMENT level
3087     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
3088     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3089                'begin debug OKLRSLAB.pls call ' || l_api_name);
3090     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3091                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.DELETE_TRX_EXTENSION');
3092     l_return_status := OKL_API.G_RET_STS_SUCCESS;
3093     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3094       'Calling OKL_API.START_ACTIVITY');
3095     l_return_status := OKL_API.START_ACTIVITY(
3096                          p_api_name       => l_api_name
3097                         ,p_pkg_name       => g_pkg_name
3098                         ,p_init_msg_list  => p_init_msg_list
3099                         ,l_api_version    => l_api_version
3100                         ,p_api_version    => p_api_version
3101                         ,p_api_type       => '_PVT'
3102                         ,x_return_status  => l_return_status);
3103     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3104       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3105     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
3106       RAISE OKL_API.G_EXCEPTION_ERROR;
3107     END IF;
3108     -- Actual Logic Starts Here ..
3109     l_trans_hdr_rec := p_trans_hdr_rec;
3110     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3111       'Source ID=' || to_char(l_trans_hdr_rec.source_id) || 'Source Header Table=' || l_trans_hdr_rec.source_table );
3112     IF ( l_trans_hdr_rec.source_id = OKL_API.G_MISS_NUM or l_trans_hdr_rec.source_id IS NULL )
3113     THEN
3114       OKL_API.set_message(
3115          p_app_name      => G_APP_NAME
3116         ,p_msg_name      => G_INVALID_VALUE
3117         ,p_token1        => G_COL_NAME_TOKEN
3118         ,p_token1_value  => 'HEADER.SOURCE_ID');
3119       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
3120       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3121     END IF;
3122     IF ( l_trans_hdr_rec.source_table = OKL_API.G_MISS_CHAR or l_trans_hdr_rec.source_table IS NULL
3123         OR l_trans_hdr_rec.source_table NOT IN ( G_TRX_CONTRACTS) )
3124     THEN
3125       OKL_API.set_message(
3126          p_app_name      => G_APP_NAME
3127         ,p_msg_name      => G_INVALID_VALUE
3128         ,p_token1        => G_COL_NAME_TOKEN
3129         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
3130       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
3131       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3132     END IF;
3133     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3134       'Fetch the Extension Header ID by executing cursor get_txl_ext_hdr_id' );
3135     FOR t_rec IN get_txl_ext_hdr_id(
3136                     p_trx_hdr_id    => l_trans_hdr_rec.source_id
3137                    ,p_trx_hdr_table => l_trans_hdr_rec.source_table)
3138     LOOP
3139       l_trans_hdr_rec.header_extension_id := t_rec.header_extension_id;
3140     END LOOP;
3141     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3142       'Extension Header ID To be Deleted='  || TO_CHAR(l_trans_hdr_rec.header_extension_id));
3143     -- Fetch the Transaction Extension Line IDs to be deleted
3144     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3145       'Extension Line ID(s) To be Deleted=');
3146     tel_index := 1;
3147     FOR t_rec IN get_txl_ext_line_ids( p_teh_id  => l_trans_hdr_rec.header_extension_id)
3148     LOOP
3149       l_telv_tbl(tel_index).line_extension_id  := t_rec.line_extension_id;
3150       l_telv_tbl(tel_index).source_id          := t_rec.source_id;
3151       l_telv_tbl(tel_index).source_table       := t_rec.source_table;
3152       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3153         'LINE_EXTENSION_ID[' || tel_index || '] = ' || TO_CHAR(l_telv_tbl(tel_index).line_extension_id) );
3154       -- Increment i
3155       tel_index := tel_index + 1;
3156     END LOOP; -- End get_trans_line_ids
3157     -- Store the Transaction Line IDs and Line Source Tables so as to return back
3158     x_trans_line_tbl := l_telv_tbl;
3159     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3160       'Calling the okl_trx_extension_pvt.delete_trx_extension. HEADER_EXTENSION_ID = ' ||
3161       TO_CHAR(l_trans_hdr_rec.header_extension_id) );
3162     okl_trx_extension_pvt.delete_trx_extension(
3163        p_api_version     => p_api_version
3164       ,p_init_msg_list   => p_init_msg_list
3165       ,x_return_status   => l_return_status
3166       ,x_msg_count       => x_msg_count
3167       ,x_msg_data        => x_msg_data
3168       ,p_tehv_rec        => l_trans_hdr_rec  -- Initalized with the HEADER_EXTENSION_ID
3169     );
3170     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3171       'After executing the okl_trx_extension_pvt.delete_trx_extension l_return_status' || l_return_status );
3172     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
3173       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3174     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
3175       RAISE OKL_API.G_EXCEPTION_ERROR;
3176     END IF;
3177     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3178       'Calling okl_api.end_activity');
3179     okl_api.end_activity(
3180        x_msg_count => x_msg_count
3181       ,x_msg_data  => x_msg_data);
3182     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3183       'END OKL_SLA_ACC_SOURCES_PVT.DELETE_TRX_EXTENSION');
3184     x_return_status := OKL_API.G_RET_STS_SUCCESS;
3185   EXCEPTION
3186     ------------------------------------------------------------
3187     -- Exception handling
3188     ------------------------------------------------------------
3189     WHEN OKL_API.G_EXCEPTION_ERROR
3190     THEN
3191       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3192                             p_api_name  => l_api_name
3193                            ,p_pkg_name  => G_PKG_NAME
3194                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
3195                            ,x_msg_count => x_msg_count
3196                            ,x_msg_data  => x_msg_data
3197                            ,p_api_type  => '_PVT');
3198     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
3199     THEN
3200       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3201                             p_api_name  => l_api_name
3202                            ,p_pkg_name  => G_PKG_NAME
3203                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
3204                            ,x_msg_count => x_msg_count
3205                            ,x_msg_data  => x_msg_data
3206                            ,p_api_type  => '_PVT');
3207     WHEN OTHERS
3208     THEN
3209      x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3210                             p_api_name  => l_api_name
3211                            ,p_pkg_name  => G_PKG_NAME
3212                            ,p_exc_name  => 'OTHERS'
3213                            ,x_msg_count => x_msg_count
3214                            ,x_msg_data  => x_msg_data
3215                            ,p_api_type  => '_PVT');
3216   END delete_trx_extension;
3217 
3218   ------------------------------------------------------------------------------
3219   -- Start of comments
3220   --      API name        : write_khr_sources_to_log
3221   --      Pre-reqs        : None
3222   --      Function        : log captured khr sources for FA/AR/AP OKL Transactions
3223   --      Parameters      :
3224   --      IN              : p_khr_source_rec     khr_source_rec_type
3225   --      Version         : 1.0
3226   --      History         : Prashant Jain created
3227   -- End of comments
3228   ------------------------------------------------------------------------------
3229 
3230   PROCEDURE write_khr_sources_to_log(
3231     p_khr_source_rec  IN   khr_source_rec_type
3232    ,p_module          IN   fnd_log_messages.module%TYPE)
3233   AS
3234   BEGIN
3235     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ID                  =' || p_khr_source_rec.KHR_ID );
3236     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_NUMBER         =' || p_khr_source_rec.CONTRACT_NUMBER );
3237     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_STATUS         =' || p_khr_source_rec.CONTRACT_STATUS );
3238     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUSTOMER_NAME           =' || p_khr_source_rec.CUSTOMER_NAME );
3239     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUSTOMER_ACCOUNT_NUMBER =' || p_khr_source_rec.CUSTOMER_ACCOUNT_NUMBER );
3240     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_CURRENCY_CODE  =' || p_khr_source_rec.CONTRACT_CURRENCY_CODE );
3241     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_EFFECTIVE_FROM =' || p_khr_source_rec.CONTRACT_EFFECTIVE_FROM );
3242     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'PRODUCT_NAME            =' || p_khr_source_rec.PRODUCT_NAME );
3243     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'BOOK_CLASSIFICATION_CODE=' || p_khr_source_rec.BOOK_CLASSIFICATION_CODE );
3244     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'TAX_OWNER_CODE          =' || p_khr_source_rec.TAX_OWNER_CODE );
3245     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'REV_REC_METHOD_CODE     =' || p_khr_source_rec.REV_REC_METHOD_CODE );
3246     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INT_CALC_METHOD_CODE    =' || p_khr_source_rec.INT_CALC_METHOD_CODE );
3247     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'VENDOR_PROGRAM_NUMBER   =' || p_khr_source_rec.VENDOR_PROGRAM_NUMBER );
3248     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONVERTED_NUMBER        =' || p_khr_source_rec.CONVERTED_NUMBER );
3249     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONVERTED_ACCOUNT_FLAG  =' || p_khr_source_rec.CONVERTED_ACCOUNT_FLAG );
3250     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSIGNABLE_FLAG         =' || p_khr_source_rec.ASSIGNABLE_FLAG );
3251     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'PO_ORDER_NUMBER         =' || p_khr_source_rec.PO_ORDER_NUMBER );
3252     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ACCRUAL_OVERRIDE_FLAG   =' || p_khr_source_rec.ACCRUAL_OVERRIDE_FLAG );
3253     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RENT_IA_CONTRACT_NUMBER =' || p_khr_source_rec.RENT_IA_CONTRACT_NUMBER );
3254     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RENT_IA_PRODUCT_NAME    =' || p_khr_source_rec.RENT_IA_PRODUCT_NAME );
3255     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RENT_IA_ACCOUNTING_CODE =' || p_khr_source_rec.RENT_IA_ACCOUNTING_CODE );
3256     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RES_IA_CONTRACT_NUMBER  =' || p_khr_source_rec.RES_IA_CONTRACT_NUMBER );
3257     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RES_IA_PRODUCT_NAME     =' || p_khr_source_rec.RES_IA_PRODUCT_NAME );
3258     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'RES_IA_ACCOUNTING_CODE  =' || p_khr_source_rec.RES_IA_ACCOUNTING_CODE );
3259     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE_CATEGORY  =' || p_khr_source_rec.KHR_ATTRIBUTE_CATEGORY );
3260     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE1          =' || p_khr_source_rec.KHR_ATTRIBUTE1 );
3261     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE2          =' || p_khr_source_rec.KHR_ATTRIBUTE2 );
3262     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE3          =' || p_khr_source_rec.KHR_ATTRIBUTE3 );
3263     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE4          =' || p_khr_source_rec.KHR_ATTRIBUTE4 );
3264     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE5          =' || p_khr_source_rec.KHR_ATTRIBUTE5 );
3265     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE6          =' || p_khr_source_rec.KHR_ATTRIBUTE6 );
3266     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE7          =' || p_khr_source_rec.KHR_ATTRIBUTE7 );
3267     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE8          =' || p_khr_source_rec.KHR_ATTRIBUTE8 );
3268     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE9          =' || p_khr_source_rec.KHR_ATTRIBUTE9 );
3269     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE10         =' || p_khr_source_rec.KHR_ATTRIBUTE10 );
3270     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE11         =' || p_khr_source_rec.KHR_ATTRIBUTE11 );
3271     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE12         =' || p_khr_source_rec.KHR_ATTRIBUTE12 );
3272     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE13         =' || p_khr_source_rec.KHR_ATTRIBUTE13 );
3273     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE14         =' || p_khr_source_rec.KHR_ATTRIBUTE14 );
3274     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ATTRIBUTE15         =' || p_khr_source_rec.KHR_ATTRIBUTE15 );
3275     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE_CATEGORY =' || p_khr_source_rec.CUST_ATTRIBUTE_CATEGORY );
3276     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE1         =' || p_khr_source_rec.CUST_ATTRIBUTE1 );
3277     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE2         =' || p_khr_source_rec.CUST_ATTRIBUTE2 );
3278     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE3         =' || p_khr_source_rec.CUST_ATTRIBUTE3 );
3279     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE4         =' || p_khr_source_rec.CUST_ATTRIBUTE4 );
3280     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE5         =' || p_khr_source_rec.CUST_ATTRIBUTE5 );
3281     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE6         =' || p_khr_source_rec.CUST_ATTRIBUTE6 );
3282     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE7         =' || p_khr_source_rec.CUST_ATTRIBUTE7 );
3283     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE8         =' || p_khr_source_rec.CUST_ATTRIBUTE8 );
3284     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE9         =' || p_khr_source_rec.CUST_ATTRIBUTE9 );
3285     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE10        =' || p_khr_source_rec.CUST_ATTRIBUTE10 );
3286     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE11        =' || p_khr_source_rec.CUST_ATTRIBUTE11 );
3287     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE12        =' || p_khr_source_rec.CUST_ATTRIBUTE12 );
3288     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE13        =' || p_khr_source_rec.CUST_ATTRIBUTE13 );
3289     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE14        =' || p_khr_source_rec.CUST_ATTRIBUTE14 );
3290     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CUST_ATTRIBUTE15        =' || p_khr_source_rec.CUST_ATTRIBUTE15 );
3291     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'CONTRACT_STATUS_CODE    =' || p_khr_source_rec.CONTRACT_STATUS_CODE );
3292     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_NUMBER     =' || p_khr_source_rec.INV_AGRMNT_NUMBER );
3293     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_EFFECTIVE_FROM =' || p_khr_source_rec.INV_AGRMNT_EFFECTIVE_FROM );
3294     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_PRODUCT_NAME   =' || p_khr_source_rec.INV_AGRMNT_PRODUCT_NAME );
3295     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_CURRENCY_CODE  =' || p_khr_source_rec.INV_AGRMNT_CURRENCY_CODE );
3296     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_SYND_CODE      =' || p_khr_source_rec.INV_AGRMNT_SYND_CODE );
3297     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_POOL_NUMBER    =' || p_khr_source_rec.INV_AGRMNT_POOL_NUMBER );
3298     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_STATUS_CODE    =' || p_khr_source_rec.INV_AGRMNT_STATUS_CODE );
3299     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'INV_AGRMNT_STATUS         =' || p_khr_source_rec.INV_AGRMNT_STATUS );
3300     write_to_log(FND_LOG.LEVEL_STATEMENT,P_MODULE,'SCS_CODE                  =' || p_khr_source_rec.SCS_CODE );
3301   END write_khr_sources_to_log;
3302 
3303   ------------------------------------------------------------------------------
3304   -- Start of comments
3305   --      API name        : write_kle_sources_to_log
3306   --      Pre-reqs        : None
3307   --      Function        : log captured kle sources for FA/AR/AP OKL Transactions
3308   --      Parameters      :
3309   --      IN              : p_kle_source_rec     kle_source_rec_type
3310   --      Version         : 1.0
3311   --      History         : Prashant Jain created
3312   -- End of comments
3313   ------------------------------------------------------------------------------
3314 
3315   PROCEDURE write_kle_sources_to_log(
3316                p_kle_source_rec       IN      kle_source_rec_type
3317               ,p_module               IN      fnd_log_messages.module%TYPE)
3318   AS
3319   BEGIN
3320     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KHR_ID                    =' || p_kle_source_rec.KHR_ID );
3321     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'KLE_ID                    =' || p_kle_source_rec.KLE_ID );
3322     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_NUMBER              =' || p_kle_source_rec.ASSET_NUMBER );
3323     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'CONTRACT_LINE_NUMBER      =' || p_kle_source_rec.CONTRACT_LINE_NUMBER );
3324     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'ASSET_VENDOR_NAME         =' || p_kle_source_rec.ASSET_VENDOR_NAME );
3325     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'INSTALLED_SITE_ID         =' || p_kle_source_rec.INSTALLED_SITE_ID );
3326     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'FIXED_ASSET_LOCATION_NAME =' || p_kle_source_rec.FIXED_ASSET_LOCATION_NAME );
3327     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_TYPE_CODE            =' || p_kle_source_rec.LINE_TYPE_CODE );
3328     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE_CATEGORY   =' || p_kle_source_rec.LINE_ATTRIBUTE_CATEGORY );
3329     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE1           =' || p_kle_source_rec.LINE_ATTRIBUTE1 );
3330     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE2           =' || p_kle_source_rec.LINE_ATTRIBUTE2 );
3331     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE3           =' || p_kle_source_rec.LINE_ATTRIBUTE3 );
3332     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE4           =' || p_kle_source_rec.LINE_ATTRIBUTE4 );
3333     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE5           =' || p_kle_source_rec.LINE_ATTRIBUTE5 );
3334     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE6           =' || p_kle_source_rec.LINE_ATTRIBUTE6 );
3335     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE7           =' || p_kle_source_rec.LINE_ATTRIBUTE7 );
3336     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE8           =' || p_kle_source_rec.LINE_ATTRIBUTE8 );
3337     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE9           =' || p_kle_source_rec.LINE_ATTRIBUTE9 );
3338     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE10          =' || p_kle_source_rec.LINE_ATTRIBUTE10 );
3339     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE11          =' || p_kle_source_rec.LINE_ATTRIBUTE11 );
3340     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE12          =' || p_kle_source_rec.LINE_ATTRIBUTE12 );
3341     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE13          =' || p_kle_source_rec.LINE_ATTRIBUTE13 );
3342     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE14          =' || p_kle_source_rec.LINE_ATTRIBUTE14 );
3343     write_to_log(FND_LOG.LEVEL_STATEMENT,p_module,'LINE_ATTRIBUTE15          =' || p_kle_source_rec.LINE_ATTRIBUTE15 );
3344   END write_kle_sources_to_log;
3345 
3346   ------------------------------------------------------------------------------
3347   -- Start of comments
3348   --      API name        : assign_khr_rec_to_fxhv_rec
3349   --      Pre-reqs        : None
3350   --      Function        : assign khr rec to fxhv rec for FA OKL Transactions
3351   --      Parameters      :
3352   --      IN              : p_khr_source_rec     khr_source_rec_type
3353   --      OUT             : x_fxhv_rec           fxhv_rec_type
3354   --      Version         : 1.0
3355   --      History         : Prashant Jain created
3356   -- End of comments
3357   ------------------------------------------------------------------------------
3358   -- Changes for Bug# 6268782 : PRASJAIN
3359   -- 1. func name assign_khr_rec_to_fxhv_rec to assign_khr_rec_to_fxh_rec
3360   -- 2. out param fxhv_rec_type to fxh_rec_type
3361   ------------------------------------------------------------------------------
3362   PROCEDURE assign_khr_rec_to_fxh_rec(
3363     p_khr_source_rec  IN       khr_source_rec_type
3364    ,x_fxh_rec        IN OUT   NOCOPY fxh_rec_type
3365   )
3366   AS
3367   BEGIN
3368     x_fxh_rec.khr_id                  := p_khr_source_rec.khr_id;
3369     x_fxh_rec.contract_number         := p_khr_source_rec.contract_number;
3370     x_fxh_rec.customer_name           := p_khr_source_rec.customer_name;
3371     x_fxh_rec.customer_account_number := p_khr_source_rec.customer_account_number;
3372     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
3373     x_fxh_rec.party_id		      := p_khr_source_rec.customer_id;
3374     x_fxh_rec.cust_account_id         := p_khr_source_rec.cust_account_id;
3375     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
3376     x_fxh_rec.contract_currency_code  := p_khr_source_rec.contract_currency_code;
3377     x_fxh_rec.contract_effective_from := p_khr_source_rec.contract_effective_from;
3378     x_fxh_rec.product_name            := p_khr_source_rec.product_name;
3379     x_fxh_rec.book_classification_code:= p_khr_source_rec.book_classification_code;
3380     x_fxh_rec.tax_owner_code          := p_khr_source_rec.tax_owner_code;
3381     x_fxh_rec.rev_rec_method_code     := p_khr_source_rec.rev_rec_method_code;
3382     x_fxh_rec.int_calc_method_code    := p_khr_source_rec.int_calc_method_code;
3383     x_fxh_rec.vendor_program_number   := p_khr_source_rec.vendor_program_number;
3384     x_fxh_rec.converted_number        := p_khr_source_rec.converted_number;
3385     x_fxh_rec.converted_account_flag  := p_khr_source_rec.converted_account_flag;
3386     x_fxh_rec.assignable_flag         := p_khr_source_rec.assignable_flag;
3387     x_fxh_rec.po_order_number         := p_khr_source_rec.po_order_number;
3388     x_fxh_rec.accrual_override_flag   := p_khr_source_rec.accrual_override_flag;
3389     x_fxh_rec.rent_ia_contract_number := p_khr_source_rec.rent_ia_contract_number;
3390     x_fxh_rec.rent_ia_product_name    := p_khr_source_rec.rent_ia_product_name;
3391     x_fxh_rec.rent_ia_accounting_code := p_khr_source_rec.rent_ia_accounting_code;
3392     x_fxh_rec.res_ia_contract_number  := p_khr_source_rec.res_ia_contract_number;
3393     x_fxh_rec.res_ia_product_name     := p_khr_source_rec.res_ia_product_name;
3394     x_fxh_rec.res_ia_accounting_code  := p_khr_source_rec.res_ia_accounting_code;
3395     x_fxh_rec.khr_attribute_category  := p_khr_source_rec.khr_attribute_category;
3396     x_fxh_rec.khr_attribute1          := p_khr_source_rec.khr_attribute1;
3397     x_fxh_rec.khr_attribute2          := p_khr_source_rec.khr_attribute2;
3398     x_fxh_rec.khr_attribute3          := p_khr_source_rec.khr_attribute3;
3399     x_fxh_rec.khr_attribute4          := p_khr_source_rec.khr_attribute4;
3400     x_fxh_rec.khr_attribute5          := p_khr_source_rec.khr_attribute5;
3401     x_fxh_rec.khr_attribute6          := p_khr_source_rec.khr_attribute6;
3402     x_fxh_rec.khr_attribute7          := p_khr_source_rec.khr_attribute7;
3403     x_fxh_rec.khr_attribute8          := p_khr_source_rec.khr_attribute8;
3404     x_fxh_rec.khr_attribute9          := p_khr_source_rec.khr_attribute9;
3405     x_fxh_rec.khr_attribute10         := p_khr_source_rec.khr_attribute10;
3406     x_fxh_rec.khr_attribute11         := p_khr_source_rec.khr_attribute11;
3407     x_fxh_rec.khr_attribute12         := p_khr_source_rec.khr_attribute12;
3408     x_fxh_rec.khr_attribute13         := p_khr_source_rec.khr_attribute13;
3409     x_fxh_rec.khr_attribute14         := p_khr_source_rec.khr_attribute14;
3410     x_fxh_rec.khr_attribute15         := p_khr_source_rec.khr_attribute15;
3411     x_fxh_rec.cust_attribute_category := p_khr_source_rec.cust_attribute_category;
3412     x_fxh_rec.cust_attribute1         := p_khr_source_rec.cust_attribute1;
3413     x_fxh_rec.cust_attribute2         := p_khr_source_rec.cust_attribute2;
3414     x_fxh_rec.cust_attribute3         := p_khr_source_rec.cust_attribute3;
3415     x_fxh_rec.cust_attribute4         := p_khr_source_rec.cust_attribute4;
3416     x_fxh_rec.cust_attribute5         := p_khr_source_rec.cust_attribute5;
3417     x_fxh_rec.cust_attribute6         := p_khr_source_rec.cust_attribute6;
3418     x_fxh_rec.cust_attribute7         := p_khr_source_rec.cust_attribute7;
3419     x_fxh_rec.cust_attribute8         := p_khr_source_rec.cust_attribute8;
3420     x_fxh_rec.cust_attribute9         := p_khr_source_rec.cust_attribute9;
3421     x_fxh_rec.cust_attribute10        := p_khr_source_rec.cust_attribute10;
3422     x_fxh_rec.cust_attribute11        := p_khr_source_rec.cust_attribute11;
3423     x_fxh_rec.cust_attribute12        := p_khr_source_rec.cust_attribute12;
3424     x_fxh_rec.cust_attribute13        := p_khr_source_rec.cust_attribute13;
3425     x_fxh_rec.cust_attribute14        := p_khr_source_rec.cust_attribute14;
3426     x_fxh_rec.cust_attribute15        := p_khr_source_rec.cust_attribute15;
3427     x_fxh_rec.contract_status_code    := p_khr_source_rec.contract_status_code;
3428   END assign_khr_rec_to_fxh_rec;
3429   ------------------------------------------------------------------------------
3430   -- Start of comments
3431   --      API name        : assign_kle_rec_to_fxlv_rec
3432   --      Pre-reqs        : None
3433   --      Function        : assign kle rec to fxlv rec for FA OKL Transactions
3434   --      Parameters      :
3435   --      IN              : p_kle_source_rec     kle_source_rec_type
3436   --      OUT             : x_fxlv_rec           fxlv_rec_type
3437   --      Version         : 1.0
3438   --      History         : Prashant Jain created
3439   -- End of comments
3440   ------------------------------------------------------------------------------
3441   -- Changes for Bug# 6268782 : PRASJAIN
3442   -- 1. func name assign_kle_rec_to_fxlv_rec to assign_kle_rec_to_fxl_rec
3443   -- 2. out param fxlv_rec_type to fxl_rec_type
3444   ------------------------------------------------------------------------------
3445   PROCEDURE assign_kle_rec_to_fxl_rec(
3446     p_kle_source_rec  IN       kle_source_rec_type
3447    ,x_fxl_rec        IN OUT   NOCOPY fxl_rec_type
3448   )
3449   AS
3450   BEGIN
3451     x_fxl_rec.kle_id                    := p_kle_source_rec.kle_id;
3452     x_fxl_rec.asset_number              := p_kle_source_rec.asset_number;
3453     x_fxl_rec.contract_line_number      := p_kle_source_rec.contract_line_number;
3454     x_fxl_rec.asset_vendor_name         := p_kle_source_rec.asset_vendor_name;
3455     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
3456     x_fxl_rec.asset_vendor_id           := p_kle_source_rec.asset_vendor_id;
3457     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
3458     x_fxl_rec.installed_site_id         := p_kle_source_rec.installed_site_id;
3459     x_fxl_rec.line_attribute_category   := p_kle_source_rec.line_attribute_category;
3460     x_fxl_rec.line_attribute1           := p_kle_source_rec.line_attribute1;
3461     x_fxl_rec.line_attribute2           := p_kle_source_rec.line_attribute2;
3462     x_fxl_rec.line_attribute3           := p_kle_source_rec.line_attribute3;
3463     x_fxl_rec.line_attribute4           := p_kle_source_rec.line_attribute4;
3464     x_fxl_rec.line_attribute5           := p_kle_source_rec.line_attribute5;
3465     x_fxl_rec.line_attribute6           := p_kle_source_rec.line_attribute6;
3466     x_fxl_rec.line_attribute7           := p_kle_source_rec.line_attribute7;
3467     x_fxl_rec.line_attribute8           := p_kle_source_rec.line_attribute8;
3468     x_fxl_rec.line_attribute9           := p_kle_source_rec.line_attribute9;
3469     x_fxl_rec.line_attribute10          := p_kle_source_rec.line_attribute10;
3470     x_fxl_rec.line_attribute11          := p_kle_source_rec.line_attribute11;
3471     x_fxl_rec.line_attribute12          := p_kle_source_rec.line_attribute12;
3472     x_fxl_rec.line_attribute13          := p_kle_source_rec.line_attribute13;
3473     x_fxl_rec.line_attribute14          := p_kle_source_rec.line_attribute14;
3474     x_fxl_rec.line_attribute15          := p_kle_source_rec.line_attribute15;
3475   END assign_kle_rec_to_fxl_rec;
3476   -----------------------------------------------------------------------------------------
3477   -- Start of comments
3478   --      API name        : populate_khr_sources
3479   --      Pre-reqs        : None
3480   --      Function        : populate khr header sources for FA/AR/AP OKL Transactions
3481   --      Parameters      :
3482   --      IN              : x_khr_source_rec.khr_id          NUMBER                Required
3483   --                        -- Change for Bug# 6268782 : PRASJAIN
3484   --                        x_led_lang_tbl                   led_lang_tbl_type     Required
3485   --      OUT             : x_khr_source_rec                 khr_source_rec_type
3486   --      Version         : 1.0
3487   --      History         : Prashant Jain created
3488   -- End of comments
3489   -----------------------------------------------------------------------------------------
3490 
3491   PROCEDURE populate_khr_sources(
3492     p_api_version               IN                NUMBER
3493    ,p_init_msg_list             IN                VARCHAR2
3494    ,x_khr_source_rec            IN OUT    NOCOPY  khr_source_rec_type
3495    ,x_led_lang_tbl              IN OUT    NOCOPY  led_lang_tbl_type
3496    ,x_return_status             OUT       NOCOPY  VARCHAR2
3497    ,x_msg_count                 OUT       NOCOPY  NUMBER
3498    ,x_msg_data                  OUT       NOCOPY  VARCHAR2
3499   )
3500   IS
3501     -----------------------------------------------------------------
3502     -- Declare Process Variable
3503     -----------------------------------------------------------------
3504     l_api_version              CONSTANT NUMBER         := 1;
3505     l_api_name                 CONSTANT VARCHAR2(30)   := 'POPULATE_KHR_SOURCES';
3506     l_return_status                     VARCHAR2(1)    := OKL_API.G_RET_STS_SUCCESS;
3507 
3508     ----------------------------------------------
3509     -- Variables based on Cursor record structures
3510     ----------------------------------------------
3511     l_kpl_attributes_csr_rec          c_kpl_attributes_csr%ROWTYPE;
3512     l_khr_category_attr_csr_rec       c_khr_category_attributes_csr%ROWTYPE;
3513     l_khr_attributes_csr_rec          c_khr_attributes_csr%ROWTYPE;
3514     l_get_status_meaning_csr_rec      c_get_status_meaning_csr%ROWTYPE;
3515     l_insurance_csr_rec               c_insurance_csr%ROWTYPE;
3516     l_rev_rec_int_calc_mtd_csr_rec    c_rev_rec_int_calc_methods_csr%ROWTYPE;
3517     l_cust_name_account_csr_rec       c_cust_name_account_csr%ROWTYPE;
3518     l_inv_agree_acc_code_csr_rec      c_investor_agree_acc_code_csr%ROWTYPE;
3519     l_investor_agree_main_csr_rec     c_investor_agreement_main_csr%ROWTYPE;
3520     l_vendor_prg_number_csr_rec       c_vendor_program_number_csr%ROWTYPE;
3521     l_pdt_bc_to_icm_rrb_rec           c_pdt_bc_to_icm_rrb_csr%ROWTYPE;
3522     l_inv_agrmnt_details_rec     c_inv_agrmnt_details_csr%ROWTYPE;
3523     ---------------------------------------------------------------
3524     -- Local Variables for storing value used in another procedure
3525     ---------------------------------------------------------------
3526     l_khr_id               NUMBER;
3527     l_cust_acct_id         NUMBER;
3528     l_pdt_id               NUMBER;
3529     l_rent_ia_chr_id       NUMBER;
3530     l_res_ia_chr_id        NUMBER;
3531     l_ledger_language      VARCHAR2(12);
3532     tl_sources_in          NUMBER := 1;
3533 
3534     ----------------------------------------------------
3535     -- Local variables for enabling the debug statements
3536     ----------------------------------------------------
3537     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
3538     l_debug_enabled                    VARCHAR2(10);
3539     is_debug_procedure_on              BOOLEAN;
3540     is_debug_statement_on              BOOLEAN;
3541   BEGIN
3542     l_debug_enabled := okl_debug_pub.check_log_enabled;
3543     -- check for logging on PROCEDURE level
3544     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
3545     -- check for logging on STATEMENT level
3546     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
3547     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3548                'BEGIN DEBUG OKLRSLAB.PLS CALL ' || l_api_name);
3549     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3550                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_KHR_SOURCES');
3551     l_return_status := OKL_API.G_RET_STS_SUCCESS;
3552     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3553       'CALLING OKL_API.START_ACTIVITY');
3554     l_return_status := OKL_API.START_ACTIVITY(
3555                          p_api_name       => l_api_name
3556                         ,p_pkg_name       => g_pkg_name
3557                         ,p_init_msg_list  => p_init_msg_list
3558                         ,l_api_version    => l_api_version
3559                         ,p_api_version    => p_api_version
3560                         ,p_api_type       => '_PVT'
3561                         ,x_return_status  => l_return_status);
3562     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3563       'AFTER START ACTIVITY L_RETURN_STATUS ' || l_return_status );
3564 
3565     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
3566     THEN
3567       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3568     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
3569     THEN
3570       RAISE OKL_API.G_EXCEPTION_ERROR;
3571     END IF;
3572 
3573     -- Copy input parameter to local variable
3574     l_khr_id          := x_khr_source_rec.khr_id;
3575 
3576     -- fetch and populate contract attributes
3577     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3578       'Executing Cursor l_khr_attributes_csr_rec : l_khr_id = ' || TO_CHAR(l_khr_id));
3579     FOR t_rec IN c_khr_attributes_csr (l_khr_id)
3580     LOOP
3581 
3582     --sechawla 4/28 12375727 : added debug message : begin
3583     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3584       'inside c_khr_attributes_csr loop.. ');
3585     --sechawla 4/28 12375727 : added debug message : end
3586 
3587 
3588       l_khr_attributes_csr_rec                 := t_rec;
3589       -- First Capture the scs_code of the Entity ..
3590       --  If its lease then capture contract related sources, other wise not !!
3591       x_khr_source_rec.scs_code := l_khr_attributes_csr_rec.scs_code;
3592 
3593       --sechawla 4/28 12375727 : added debug message : begin
3594       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3595       'l_khr_attributes_csr_rec.scs_code..  '||l_khr_attributes_csr_rec.scs_code);
3596       --sechawla 4/28 12375727 : added debug message : end
3597 
3598       IF l_khr_attributes_csr_rec.scs_code = G_LEASE
3599       THEN
3600         x_khr_source_rec.contract_number         := l_khr_attributes_csr_rec.contract_number;
3601         x_khr_source_rec.contract_currency_code  := l_khr_attributes_csr_rec.currency_code;
3602         x_khr_source_rec.contract_effective_from := l_khr_attributes_csr_rec.start_date;
3603         x_khr_source_rec.converted_number        := l_khr_attributes_csr_rec.orig_system_reference1;
3604         x_khr_source_rec.assignable_flag         := l_khr_attributes_csr_rec.assignable_yn;
3605         x_khr_source_rec.converted_account_flag  := l_khr_attributes_csr_rec.converted_account_yn;
3606         x_khr_source_rec.po_order_number         := l_khr_attributes_csr_rec.cust_po_number;
3607         x_khr_source_rec.accrual_override_flag   := l_khr_attributes_csr_rec.generate_accrual_override_yn;
3608         l_cust_acct_id                           := l_khr_attributes_csr_rec.cust_acct_id;
3609         l_pdt_id                                 := l_khr_attributes_csr_rec.pdt_id;
3610         -- Assign the Contract Status Code
3611         x_khr_source_rec.contract_status_code    := l_khr_attributes_csr_rec.sts_code;
3612 
3613 --sechawla 4/28 12375727 : added debug message : begin
3614 put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3615       'G_REPRESENTATION_TYPE..  '||G_REPRESENTATION_TYPE);
3616  --sechawla 4/28 12375727 : added debug message : end
3617 
3618 		-- MG uptake .. for secondary rep get the reporting product id.
3619 		if G_REPRESENTATION_TYPE = 'SECONDARY' then
3620 		  open c_rep_pdt_csr(l_pdt_id);
3621 		  fetch c_rep_pdt_csr into l_pdt_id;
3622 		  close c_rep_pdt_csr;
3623 		end if;
3624 
3625 --sechawla 4/28 12375727 : added debug message : begin
3626 put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3627       'before x_led_lang_tbl loop.. ');
3628 --sechawla 4/28 12375727 : added debug message : end
3629 
3630         -- Fetch contract status wrt ledger language
3631         FOR tl_sources_in IN x_led_lang_tbl.FIRST .. x_led_lang_tbl.LAST
3632         LOOP
3633           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3634             'Executing the Cursor c_get_status_meaning_csr. p_sts_code=' ||
3635             l_khr_attributes_csr_rec.sts_code || 'p_led_lang= ' || x_led_lang_tbl(tl_sources_in).language );
3636           FOR t_rec IN c_get_status_meaning_csr(
3637                       p_sts_code  => l_khr_attributes_csr_rec.sts_code
3638                      ,p_led_lang  => x_led_lang_tbl(tl_sources_in).language )
3639           LOOP
3640             l_get_status_meaning_csr_rec   := t_rec;
3641             x_led_lang_tbl(tl_sources_in).contract_status := l_get_status_meaning_csr_rec.status_meaning;
3642           END LOOP; -- End for c_get_status_meaning_csr
3643         END LOOP;
3644 
3645 --sechawla 4/28 12375727 : added debug message : begin
3646 put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3647       'skipped x_led_lang_tbl loop... ');
3648 --sechawla 4/28 12375727 : added debug message : end
3649 
3650 
3651       ELSIF l_khr_attributes_csr_rec.scs_code = G_INVESTOR
3652       THEN
3653         x_khr_source_rec.inv_agrmnt_number         := l_khr_attributes_csr_rec.contract_number;
3654         x_khr_source_rec.inv_agrmnt_effective_from := l_khr_attributes_csr_rec.start_date;
3655         x_khr_source_rec.inv_agrmnt_currency_code  := l_khr_attributes_csr_rec.currency_code;
3656         x_khr_source_rec.inv_agrmnt_status_code    := l_khr_attributes_csr_rec.sts_code;
3657         -- Fetch Investor Agreement status wrt ledger language
3658         FOR tl_sources_in IN x_led_lang_tbl.FIRST .. x_led_lang_tbl.LAST
3659         LOOP
3660           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3661             'Executing the Cursor c_get_status_meaning_csr. p_sts_code=' ||
3662             l_khr_attributes_csr_rec.sts_code || 'p_led_lang= ' || x_led_lang_tbl(tl_sources_in).language );
3663           FOR t_rec IN c_get_status_meaning_csr(
3664                       p_sts_code  => l_khr_attributes_csr_rec.sts_code
3665                      ,p_led_lang  => x_led_lang_tbl(tl_sources_in).language )
3666           LOOP
3667             l_get_status_meaning_csr_rec   := t_rec;
3668             x_led_lang_tbl(tl_sources_in).inv_agrmnt_status := l_get_status_meaning_csr_rec.status_meaning;
3669           END LOOP; -- End for c_get_status_meaning_csr
3670         END LOOP;
3671       END IF;
3672 
3673 
3674     END LOOP; -- End for c_khr_attributes_csr
3675 
3676     IF l_khr_attributes_csr_rec.scs_code = G_LEASE
3677     THEN
3678       -- fetch and populate contract attribute category and attributes
3679       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3680         'Executing the Cursor c_khr_category_attributes_csr l_khr_id = ' || TO_CHAR(l_khr_id) );
3681       FOR t_rec IN c_khr_category_attributes_csr (l_khr_id)
3682       LOOP
3683         l_khr_category_attr_csr_rec := t_rec;
3684         x_khr_source_rec.khr_attribute_category := l_khr_category_attr_csr_rec.attribute_category;
3685         x_khr_source_rec.khr_attribute1  := l_khr_category_attr_csr_rec.attribute1;
3686         x_khr_source_rec.khr_attribute2  := l_khr_category_attr_csr_rec.attribute2;
3687         x_khr_source_rec.khr_attribute3  := l_khr_category_attr_csr_rec.attribute3;
3688         x_khr_source_rec.khr_attribute4  := l_khr_category_attr_csr_rec.attribute4;
3689         x_khr_source_rec.khr_attribute5  := l_khr_category_attr_csr_rec.attribute5;
3690         x_khr_source_rec.khr_attribute6  := l_khr_category_attr_csr_rec.attribute6;
3691         x_khr_source_rec.khr_attribute7  := l_khr_category_attr_csr_rec.attribute7;
3692         x_khr_source_rec.khr_attribute8  := l_khr_category_attr_csr_rec.attribute8;
3693         x_khr_source_rec.khr_attribute9  := l_khr_category_attr_csr_rec.attribute9;
3694         x_khr_source_rec.khr_attribute10 := l_khr_category_attr_csr_rec.attribute10;
3695         x_khr_source_rec.khr_attribute11 := l_khr_category_attr_csr_rec.attribute11;
3696         x_khr_source_rec.khr_attribute12 := l_khr_category_attr_csr_rec.attribute12;
3697         x_khr_source_rec.khr_attribute13 := l_khr_category_attr_csr_rec.attribute13;
3698         x_khr_source_rec.khr_attribute14 := l_khr_category_attr_csr_rec.attribute14;
3699         x_khr_source_rec.khr_attribute15 := l_khr_category_attr_csr_rec.attribute15;
3700       END LOOP; -- End for c_khr_category_attributes_csr
3701 
3702       -- Fetch and populate book classification code and tax owner code
3703       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3704         'Executing the Cursor c_pdt_bc_to_icm_rrb_csr. l_pdt_id = ' || TO_CHAR(l_pdt_id) );
3705       FOR t_rec IN c_pdt_bc_to_icm_rrb_csr (p_pdt_id => l_pdt_id)
3706       LOOP
3707         l_pdt_bc_to_icm_rrb_rec := t_rec;
3708         x_khr_source_rec.product_name             := l_pdt_bc_to_icm_rrb_rec.pdt_name;
3709         x_khr_source_rec.book_classification_code := l_pdt_bc_to_icm_rrb_rec.deal_type;
3710         x_khr_source_rec.tax_owner_code           := l_pdt_bc_to_icm_rrb_rec.tax_owner;
3711         x_khr_source_rec.int_calc_method_code     := l_pdt_bc_to_icm_rrb_rec.interest_calc_meth_code;
3712         x_khr_source_rec.rev_rec_method_code      := l_pdt_bc_to_icm_rrb_rec.revenue_recog_meth_code;
3713       END LOOP; -- End for c_book_tax_csr
3714 
3715       -- fetch and populate vendor program number
3716       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3717         'Executing the Cursor  c_vendor_program_number_csr p_khr_id = ' || TO_CHAR(l_khr_id) );
3718       FOR t_rec IN c_vendor_program_number_csr (p_khr_id => l_khr_id)
3719       LOOP
3720         l_vendor_prg_number_csr_rec := t_rec;
3721         x_khr_source_rec.vendor_program_number  := l_vendor_prg_number_csr_rec.contract_number;
3722       END LOOP; -- End for c_vendor_program_number_csr
3723 
3724       -- fetch and populate customer account properties
3725       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3726         'Executing the Cursor l_cust_name_account_csr. p_khr_id = ' || TO_CHAR(l_khr_id)
3727         || ' p_cust_acct_id = ' || TO_CHAR(l_cust_acct_id ) );
3728       FOR t_rec IN  c_cust_name_account_csr (l_khr_id,l_cust_acct_id)
3729       LOOP
3730         l_cust_name_account_csr_rec := t_rec;
3731         x_khr_source_rec.customer_name            := l_cust_name_account_csr_rec.party_name;
3732         x_khr_source_rec.customer_account_number  := l_cust_name_account_csr_rec.account_number;
3733         -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
3734         x_khr_source_rec.cust_account_id  := l_cust_acct_id;
3735 	x_khr_source_rec.customer_id      := l_cust_name_account_csr_rec.party_id;
3736         -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
3737       END LOOP; -- End for c_cust_name_account_csr
3738 
3739       -- fetch and populate customer attribute category and attributes
3740       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3741         'Executing the Cursor c_kpl_attributes_csr l_khr_id = ' || TO_CHAR(l_khr_id) );
3742       FOR t_rec IN c_kpl_attributes_csr (l_khr_id)
3743       LOOP
3744         l_kpl_attributes_csr_rec := t_rec;
3745         x_khr_source_rec.cust_attribute_category := l_kpl_attributes_csr_rec.attribute_category;
3746         x_khr_source_rec.cust_attribute1  := l_kpl_attributes_csr_rec.attribute1;
3747         x_khr_source_rec.cust_attribute2  := l_kpl_attributes_csr_rec.attribute2;
3748         x_khr_source_rec.cust_attribute3  := l_kpl_attributes_csr_rec.attribute3;
3749         x_khr_source_rec.cust_attribute4  := l_kpl_attributes_csr_rec.attribute4;
3750         x_khr_source_rec.cust_attribute5  := l_kpl_attributes_csr_rec.attribute5;
3751         x_khr_source_rec.cust_attribute6  := l_kpl_attributes_csr_rec.attribute6;
3752         x_khr_source_rec.cust_attribute7  := l_kpl_attributes_csr_rec.attribute7;
3753         x_khr_source_rec.cust_attribute8  := l_kpl_attributes_csr_rec.attribute8;
3754         x_khr_source_rec.cust_attribute9  := l_kpl_attributes_csr_rec.attribute9;
3755         x_khr_source_rec.cust_attribute10 := l_kpl_attributes_csr_rec.attribute10;
3756         x_khr_source_rec.cust_attribute11 := l_kpl_attributes_csr_rec.attribute11;
3757         x_khr_source_rec.cust_attribute12 := l_kpl_attributes_csr_rec.attribute12;
3758         x_khr_source_rec.cust_attribute13 := l_kpl_attributes_csr_rec.attribute13;
3759         x_khr_source_rec.cust_attribute14 := l_kpl_attributes_csr_rec.attribute14;
3760         x_khr_source_rec.cust_attribute15 := l_kpl_attributes_csr_rec.attribute15;
3761       END LOOP; -- End for c_kpl_attributes_csr
3762 
3763       -- fetch and populate rent investor agreement attributes
3764       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3765         'RENT: Executing the Cursor c_investor_agreement_main_csr l_khr_id = : ' || TO_CHAR(l_khr_id));
3766       FOR t_rec IN c_investor_agreement_main_csr(
3767                           p_khr_id   => l_khr_id
3768                          ,p_sty_type => 'RENT')
3769       LOOP
3770         l_investor_agree_main_csr_rec := t_rec;
3771         l_rent_ia_chr_id  := l_investor_agree_main_csr_rec.ia_chr_id;
3772         x_khr_source_rec.rent_ia_contract_number := l_investor_agree_main_csr_rec.ia_contract_number;
3773         x_khr_source_rec.rent_ia_product_name    := l_investor_agree_main_csr_rec.ia_product_name;
3774       END LOOP;  -- End for c_investor_agreement_main_csr
3775 
3776       -- fetch and populate residual investor agreement attributes
3777       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3778         'RESIDUAL VALUE: Executing the Cursor c_investor_agreement_main_csr l_khr_id = : ' || TO_CHAR(l_khr_id));
3779       FOR t_rec IN c_investor_agreement_main_csr(
3780                           p_khr_id   => l_khr_id
3781                          ,p_sty_type => 'RESIDUAL VALUE')
3782       LOOP
3783         l_investor_agree_main_csr_rec := t_rec;
3784         l_res_ia_chr_id := l_investor_agree_main_csr_rec.ia_chr_id;
3785         x_khr_source_rec.res_ia_contract_number  := l_investor_agree_main_csr_rec.ia_contract_number;
3786         x_khr_source_rec.res_ia_product_name     := l_investor_agree_main_csr_rec.ia_product_name;
3787       END LOOP;  -- Enf for c_investor_agreement_main_csr
3788 
3789       -- fetch and populate rent investor agreement account properties
3790       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3791         'Executing the Cursor c_investor_agree_acc_code_csr. p_rent_ia_chr_id = '
3792         || TO_CHAR(l_rent_ia_chr_id) || ' p_res_ia_chr_id = ' || TO_CHAR(l_res_ia_chr_id));
3793       FOR t_rec in c_investor_agree_acc_code_csr (l_rent_ia_chr_id, l_res_ia_chr_id)
3794       LOOP
3795         l_inv_agree_acc_code_csr_rec := t_rec;
3796         x_khr_source_rec.rent_ia_accounting_code    := l_inv_agree_acc_code_csr_rec.rent_ia_accounting_code;
3797         x_khr_source_rec.res_ia_accounting_code     := l_inv_agree_acc_code_csr_rec.res_ia_accounting_code;
3798       END LOOP;  -- End for c_investor_agree_acc_code_csr
3799 
3800     ELSIF l_khr_attributes_csr_rec.scs_code = G_INVESTOR
3801     THEN
3802 
3803       -- Code to fetch the Sources like
3804       -- Investor Agreement Type, Pool Number and Product Name
3805       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3806         'Executing the Cursor c_inv_agrmnt_details_csr. l_khr_id = ' || TO_CHAR(l_khr_id) );
3807       FOR t_rec IN c_inv_agrmnt_details_csr( p_inv_agrmnt_id => l_khr_id )
3808       LOOP
3809         l_inv_agrmnt_details_rec  := t_rec;
3810         x_khr_source_rec.inv_agrmnt_synd_code     := l_inv_agrmnt_details_rec.inv_agrmnt_synd_code;
3811         -- Commented out the Investor Pool Agreement Source, as this is not mentioned as Source by PMs
3812         -- x_khr_source_rec.inv_agrmnt_pool_number   := l_inv_agrmnt_details_rec.inv_agrmnt_pool_number;
3813       END LOOP; -- FOR t_rec IN c_inv_agrmnt_details_csr( p_inv_agrmnt_id => l_khr_id )
3814       FOR t_rec IN c_get_pdt_name_csr( p_pdt_id => l_khr_attributes_csr_rec.pdt_id )
3815       LOOP
3816         x_khr_source_rec.inv_agrmnt_product_name     := t_rec.pdt_name;
3817       END LOOP;
3818 
3819     END IF;  -- IF l_khr_attributes_csr_rec.scs_code = G_INVESTOR
3820     -- If Log is enabled, print all khr sources fetched.
3821     IF (l_debug_enabled='Y' AND is_debug_statement_on)
3822     THEN
3823       write_khr_sources_to_log(
3824         p_khr_source_rec => x_khr_source_rec
3825        ,p_module         => l_module);
3826     END IF;
3827     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3828       'CALLING OKL_API.END_ACTIVITY');
3829     okl_api.end_activity(
3830        x_msg_count => x_msg_count
3831       ,x_msg_data => x_msg_data);
3832     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3833       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_KHR_SOURCES');
3834     x_return_status := OKL_API.G_RET_STS_SUCCESS;
3835   EXCEPTION
3836     ------------------------------------------------------------
3837     -- Exception handling
3838     ------------------------------------------------------------
3839     WHEN OKL_API.G_EXCEPTION_ERROR
3840     THEN
3841       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3842                             p_api_name  => l_api_name
3843                            ,p_pkg_name  => G_PKG_NAME
3844                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
3845                            ,x_msg_count  => x_msg_count
3846                            ,x_msg_data  => x_msg_data
3847                            ,p_api_type  => '_PVT');
3848     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
3849     THEN
3850       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3851                             p_api_name  => l_api_name
3852                            ,p_pkg_name  => G_PKG_NAME
3853                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
3854                            ,x_msg_count  => x_msg_count
3855                            ,x_msg_data  => x_msg_data
3856                            ,p_api_type  => '_PVT');
3857     WHEN OTHERS
3858     THEN
3859       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
3860                             p_api_name  => l_api_name
3861                            ,p_pkg_name  => G_PKG_NAME
3862                            ,p_exc_name  => 'OTHERS'
3863                            ,x_msg_count  => x_msg_count
3864                            ,x_msg_data  => x_msg_data
3865                            ,p_api_type  => '_PVT');
3866   END populate_khr_sources;
3867   ---------------------------------------------------------------------------------------
3868   -- Start of comments
3869   --      API name        : populate_kle_sources
3870   --      Pre-reqs        : None
3871   --      Function        : populate khr / kle line sources for FA/AR/AP OKL Transactions
3872   --      Parameters      :
3873   --      IN              : x_kle_source_rec.khr_id          NUMBER   Required
3874   --                        x_kle_source_rec.kle_id          NUMBER   Required
3875   --      Version         : 1.0
3876   --      History         : Prashant Jain created
3877   -- End of comments
3878   ---------------------------------------------------------------------------------------
3879 
3880   PROCEDURE populate_kle_sources(
3881     p_api_version               IN                NUMBER
3882    ,p_init_msg_list             IN                VARCHAR2
3883    ,x_kle_source_rec            IN OUT    NOCOPY  kle_source_rec_type
3884    ,x_return_status             OUT       NOCOPY  VARCHAR2
3885    ,x_msg_count                 OUT       NOCOPY  NUMBER
3886    ,x_msg_data                  OUT       NOCOPY  VARCHAR2
3887   )
3888   IS
3889     -----------------------------------------------------------------
3890     -- Declare Process Variable
3891     -----------------------------------------------------------------
3892     l_api_version              CONSTANT NUMBER         := 1;
3893     l_api_name                 CONSTANT VARCHAR2(30)   := 'POPULATE_KLE_SOURCES';
3894     l_return_status                     VARCHAR2(1)    := OKL_API.G_RET_STS_SUCCESS;
3895 
3896     ----------------------------------------------
3897     -- Variables based on cursor record structures
3898     ----------------------------------------------
3899     l_line_attributes_rec           c_line_attributes_csr%ROWTYPE;
3900     l_k_lines_rec                   c_k_lines_csr%ROWTYPE;
3901     l_vendor_name_rec               c_vendor_name_csr%ROWTYPE;
3902     l_installed_site_rec            c_installed_site_csr%ROWTYPE;
3903     l_location_id_rec               c_location_id_csr%ROWTYPE;
3904     l_asset_location_name_rec       c_asset_location_name_csr%ROWTYPE;
3905     l_khr_attributes_csr_rec        c_khr_attributes_csr%ROWTYPE;
3906     ---------------------------------------------------------------
3907     -- Local Variables for storing value used in another procedure
3908     ---------------------------------------------------------------
3909     l_khr_id               NUMBER;
3910     l_kle_id               NUMBER;
3911     l_ledger_language      VARCHAR2(12);
3912 
3913     ----------------------------------------------------
3914     -- Local Variables for enabling the Debug Statements
3915     ----------------------------------------------------
3916     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
3917     l_debug_enabled                    VARCHAR2(10);
3918     is_debug_procedure_on              BOOLEAN;
3919     is_debug_statement_on              BOOLEAN;
3920   BEGIN
3921     l_debug_enabled := okl_debug_pub.check_log_enabled;
3922     -- check for logging on PROCEDURE level
3923     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
3924     -- check for logging on STATEMENT level
3925     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
3926     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3927                'BEGIN DEBUG OKLRSLAB.PLS CALL ' || l_api_name);
3928     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
3929                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_KLE_SOURCES');
3930     l_return_status := OKL_API.G_RET_STS_SUCCESS;
3931     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3932       'CALLING OKL_API.START_ACTIVITY');
3933     l_return_status := OKL_API.START_ACTIVITY(
3934                          p_api_name       => l_api_name
3935                         ,p_pkg_name       => g_pkg_name
3936                         ,p_init_msg_list  => p_init_msg_list
3937                         ,l_api_version    => l_api_version
3938                         ,p_api_version    => p_api_version
3939                         ,p_api_type       => '_PVT'
3940                         ,x_return_status  => l_return_status);
3941     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3942       'AFTER START ACTIVITY L_RETURN_STATUS ' || l_return_status );
3943 
3944     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
3945     THEN
3946       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
3947     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
3948     THEN
3949       RAISE OKL_API.G_EXCEPTION_ERROR;
3950     END IF;
3951 
3952     -- Copy input parameter to local variables
3953     l_khr_id          := x_kle_source_rec.khr_id;
3954     l_kle_id          := x_kle_source_rec.kle_id;
3955 
3956     -- fetch and populate line attribute category and attributes
3957     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3958       'Executing the Cursor c_line_attributes_csr l_kle_id = ' || TO_CHAR(l_kle_id) );
3959     FOR t_rec IN c_line_attributes_csr (l_kle_id)
3960     LOOP
3961       l_line_attributes_rec  := t_rec;
3962       x_kle_source_rec.line_attribute_category := l_line_attributes_rec.attribute_category;
3963       x_kle_source_rec.line_attribute1  := l_line_attributes_rec.attribute1;
3964       x_kle_source_rec.line_attribute2  := l_line_attributes_rec.attribute2;
3965       x_kle_source_rec.line_attribute3  := l_line_attributes_rec.attribute3;
3966       x_kle_source_rec.line_attribute4  := l_line_attributes_rec.attribute4;
3967       x_kle_source_rec.line_attribute5  := l_line_attributes_rec.attribute5;
3968       x_kle_source_rec.line_attribute6  := l_line_attributes_rec.attribute6;
3969       x_kle_source_rec.line_attribute7  := l_line_attributes_rec.attribute7;
3970       x_kle_source_rec.line_attribute8  := l_line_attributes_rec.attribute8;
3971       x_kle_source_rec.line_attribute9  := l_line_attributes_rec.attribute9;
3972       x_kle_source_rec.line_attribute10 := l_line_attributes_rec.attribute10;
3973       x_kle_source_rec.line_attribute11 := l_line_attributes_rec.attribute11;
3974       x_kle_source_rec.line_attribute12 := l_line_attributes_rec.attribute12;
3975       x_kle_source_rec.line_attribute13 := l_line_attributes_rec.attribute13;
3976       x_kle_source_rec.line_attribute14 := l_line_attributes_rec.attribute14;
3977       x_kle_source_rec.line_attribute15 := l_line_attributes_rec.attribute15;
3978     END LOOP; -- End for c_line_attributes_csr
3979 
3980     -- fetch and populate line type code, asset number and contract line number
3981     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3982       'Executing the Cursor c_k_lines_csr l_kle_id = ' || TO_CHAR(l_kle_id) );
3983     FOR t_rec IN c_k_lines_csr (l_kle_id)
3984     LOOP
3985       l_k_lines_rec  := t_rec;
3986       x_kle_source_rec.line_type_code       := l_k_lines_rec.contract_line_type;
3987       x_kle_source_rec.asset_number         := l_k_lines_rec.asset_number;
3988       x_kle_source_rec.contract_line_number := l_k_lines_rec.line_number;
3989     END LOOP; -- End for c_k_lines_csr
3990 
3991     -- fetch and populate assest vendor name
3992     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
3993       'Executing the Cursor c_vendor_name_csr l_kle_id = ' || TO_CHAR(l_kle_id) ||
3994       ' l_khr_id = ' || TO_CHAR(l_khr_id));
3995     FOR t_rec IN c_vendor_name_csr (
3996                         p_kle_id => l_kle_id
3997                        ,p_khr_id => l_khr_id)
3998     LOOP
3999       l_vendor_name_rec  := t_rec;
4000       x_kle_source_rec.asset_vendor_name       := l_vendor_name_rec.vendor_name;
4001       -- added by zrehman Bug#6707320 as part of Party Merge impact on transaction sources tables start
4002       x_kle_source_rec.asset_vendor_id         := l_vendor_name_rec.vendor_id;
4003       -- added by zrehman Bug#6707320 as part of Party Merge impact on transaction sources tables end
4004     END LOOP; -- End for c_vendor_name_csr
4005 
4006     -- fetch and populate installed site
4007     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4008       'Executing the Cursor c_installed_site_csr l_kle_id = ' || TO_CHAR(l_kle_id) ||
4009       ' l_khr_id = ' || TO_CHAR(l_khr_id));
4010     FOR t_rec IN c_installed_site_csr (
4011                         p_kle_id => l_kle_id
4012                        ,p_khr_id => l_khr_id)
4013     LOOP
4014       l_installed_site_rec  := t_rec;
4015       x_kle_source_rec.installed_site_id       := l_installed_site_rec.installed_site_id;
4016     END LOOP; -- End for c_installed_site_csr
4017 
4018     -- fetch and populate fixed asset location name
4019     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4020       'Executing the Cursor c_location_id_csr l_kle_id = ' || TO_CHAR(l_kle_id) ||
4021       ' l_khr_id = ' || TO_CHAR(l_khr_id));
4022     FOR t_rec IN c_location_id_csr (
4023                         p_kle_id => l_kle_id
4024                        ,p_khr_id => l_khr_id)
4025     LOOP
4026       l_location_id_rec  := t_rec;
4027 
4028       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4029         'Executing the Cursor c_asset_location_name_csr location_id = ' || TO_CHAR(l_location_id_rec.location_id));
4030       FOR t_rec IN c_asset_location_name_csr (p_fdh_location_id => l_location_id_rec.location_id)
4031       LOOP
4032         l_asset_location_name_rec  := t_rec;
4033         x_kle_source_rec.fixed_asset_location_name   := l_asset_location_name_rec.asset_location_name;
4034       END LOOP; -- End for c_asset_location_name_csr
4035     END LOOP; -- End for c_location_id_csr
4036 
4037     -- fetch and populate product id
4038     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4039       'Executing Cursor c_khr_attributes_csr : l_khr_id = ' ||to_char(l_khr_id));
4040     FOR t_rec IN c_khr_attributes_csr (l_khr_id)
4041     LOOP
4042       l_khr_attributes_csr_rec := t_rec;
4043     END LOOP; -- End for c_khr_attributes_csr
4044 
4045     -- If log is enabled, print all the sources fetched.
4046     IF (l_debug_enabled='Y' AND is_debug_statement_on)
4047     THEN
4048       write_kle_sources_to_log(
4049         p_kle_source_rec => x_kle_source_rec
4050        ,p_module         => l_module);
4051     END IF;
4052 
4053     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4054       'CALLING OKL_API.END_ACTIVITY');
4055     okl_api.end_activity(
4056        x_msg_count => x_msg_count
4057       ,x_msg_data => x_msg_data);
4058     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4059       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_KLE_SOURCES');
4060     x_return_status := OKL_API.G_RET_STS_SUCCESS;
4061   EXCEPTION
4062     ------------------------------------------------------------
4063     -- Exception handling
4064     ------------------------------------------------------------
4065     WHEN OKL_API.G_EXCEPTION_ERROR
4066     THEN
4067       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4068                             p_api_name  => l_api_name
4069                            ,p_pkg_name  => G_PKG_NAME
4070                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
4071                            ,x_msg_count  => x_msg_count
4072                            ,x_msg_data  => x_msg_data
4073                            ,p_api_type  => '_PVT');
4074     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
4075     THEN
4076       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4077                             p_api_name  => l_api_name
4078                            ,p_pkg_name  => G_PKG_NAME
4079                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
4080                            ,x_msg_count  => x_msg_count
4081                            ,x_msg_data  => x_msg_data
4082                            ,p_api_type  => '_PVT');
4083     WHEN OTHERS
4084     THEN
4085       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4086                             p_api_name  => l_api_name
4087                            ,p_pkg_name  => G_PKG_NAME
4088                            ,p_exc_name  => 'OTHERS'
4089                            ,x_msg_count  => x_msg_count
4090                            ,x_msg_data  => x_msg_data
4091                            ,p_api_type  => '_PVT');
4092   END populate_kle_sources;
4093   ------------------------------------------------------------------------------
4094   -- Start of comments
4095   --      API name        : populate_sources
4096   --      Pre-reqs        : None
4097   --      Function        : populate sources for OKL FA Transactions
4098   --      Parameters      :
4099   --      IN              :
4100   --                        fxhv_rec_type.source_id            IN NUMBER    Required
4101   --                        fxhv_rec_type.source_table         IN VARCHAR2  Required
4102   --                        fxhv_rec_type.khr_id               IN NUMBER    Required
4103   --                        fxhv_rec_type.try_id               IN NUMBER    Required
4104   --                        fxlv_rec_type.source_id            IN NUMBER    Required
4105   --                        fxlv_rec_type.source_table         IN VARCHAR2  Required
4106   --                        fxlv_rec_type.kle_id               IN NUMBER    Required
4107   --                        fxlv_rec_type.asset_id             IN NUMBER    Required
4108   --                        fxlv_rec_type.fa_transaction_id    IN NUMBER    Required
4109   --                        fxlv_rec_type.asset_book_type_name IN VARCHAR2  Required
4110   --      History         : Prashant Jain created
4111   --                      : Dec 11 2007 Rkuttiya modfied for bug# 6674730
4112   --      Version         : 1.0
4113   -- End of comments
4114   ------------------------------------------------------------------------------
4115 
4116   PROCEDURE populate_sources(
4117     p_api_version           IN        NUMBER
4118    ,p_init_msg_list         IN        VARCHAR2
4119    ,p_fxhv_rec              IN        fxhv_rec_type
4120    ,p_fxlv_rec              IN        fxlv_rec_type
4121    ,x_return_status         OUT       NOCOPY  VARCHAR2
4122    ,x_msg_count             OUT       NOCOPY  NUMBER
4123    ,x_msg_data              OUT       NOCOPY  VARCHAR2
4124   )
4125   IS
4126     -----------------------------------------------------------------
4127     -- Declare Process Variable
4128     -----------------------------------------------------------------
4129     l_api_version          CONSTANT NUMBER         := 1;
4130     l_api_name             CONSTANT VARCHAR2(30)   := 'POPULATE_SOURCES-FA';
4131     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
4132     -----------------------------------------------------------------
4133     -- Local Variables
4134     -----------------------------------------------------------------
4135     l_khr_id               NUMBER;
4136     l_kle_id               NUMBER;
4137     l_try_id               NUMBER;
4138     l_ledger_id            NUMBER;
4139     l_ledger_language      VARCHAR2(12);
4140     l_header_extension_id  NUMBER;
4141     l_txl_id               NUMBER;
4142     l_pk_attributes        VARCHAR2(1000);
4143     l_line_style           VARCHAR2(100);
4144     -- KHR and KLE Based Record Structures
4145     l_khr_source_rec       khr_source_rec_type;
4146     l_kle_source_rec       kle_source_rec_type;
4147     -- Record structures based on FA Extension Header and Line Tables
4148     l_fxh_rec             okl_fxh_pvt.fxh_rec_type;
4149     lx_fxh_rec            okl_fxh_pvt.fxh_rec_type;
4150     -- for capture header translatable sources
4151     l_fxhl_tbl            okl_fxh_pvt.fxhl_tbl_type;
4152     lx_fxhl_tbl           okl_fxh_pvt.fxhl_tbl_type;
4153 
4154     l_fxl_rec             okl_fxl_pvt.fxl_rec_type;
4155     lx_fxl_rec            okl_fxl_pvt.fxl_rec_type;
4156     -- for capture header translatable sources
4157     l_fxll_tbl            okl_fxl_pvt.fxll_tbl_type;
4158     lx_fxll_tbl           okl_fxl_pvt.fxll_tbl_type;
4159 
4160     l_led_lang_tbl        led_lang_tbl_type;
4161 
4162     -- Record structures based on the Cursor defintions
4163     l_sales_rep_csr_rec    c_sales_rep_csr%ROWTYPE;
4164     -- Local Variables for enabling the Debug Statements
4165     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
4166     l_debug_enabled       VARCHAR2(10);
4167     is_debug_procedure_on BOOLEAN;
4168     is_debug_statement_on BOOLEAN;
4169     tl_sources_in         NUMBER := 1;
4170 
4171 	l_rep_code            VARCHAR2(30);
4172 	l_rep_name            VARCHAR2(30);
4173 	l_rep_type            VARCHAR2(20);
4174   BEGIN
4175     l_debug_enabled := okl_debug_pub.check_log_enabled;
4176     -- check for logging on PROCEDURE level
4177     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
4178     -- check for logging on STATEMENT level
4179     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
4180     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4181                'begin debug OKLRSLAB.pls call ' || l_api_name);
4182     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4183                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
4184     l_return_status := OKL_API.G_RET_STS_SUCCESS;
4185     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4186       'Calling OKL_API.START_ACTIVITY');
4187     l_return_status := OKL_API.START_ACTIVITY(
4188                          p_api_name       => l_api_name
4189                         ,p_pkg_name       => g_pkg_name
4190                         ,p_init_msg_list  => p_init_msg_list
4191                         ,l_api_version    => l_api_version
4192                         ,p_api_version    => p_api_version
4193                         ,p_api_type       => '_PVT'
4194                         ,x_return_status  => l_return_status);
4195     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4196       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4197     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4198       RAISE OKL_API.G_EXCEPTION_ERROR;
4199     END IF;
4200     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4201       'Before Performing validations');
4202     -- Validations to be done:
4203     --  1. The following should be NOT NULL
4204     --     dnz_khr_id, kle_id, try_id, asset_id, fa_transaction_id, source_id,
4205     --     source_table and asset_book_type_code
4206     l_pk_attributes := NULL;
4207     IF p_fxhv_rec.source_id IS NULL OR
4208        p_fxhv_rec.source_id = OKL_API.G_MISS_NUM
4209     THEN
4210       IF l_pk_attributes IS NOT NULL
4211       THEN
4212         l_pk_attributes := l_pk_attributes || ' , ';
4213       END IF;
4214       l_pk_attributes := l_pk_attributes || 'FXH.SOURCE_ID';
4215     END IF;
4216     IF p_fxhv_rec.source_table IS NULL OR
4217        p_fxhv_rec.source_table = OKL_API.G_MISS_CHAR
4218     THEN
4219       IF l_pk_attributes IS NOT NULL
4220       THEN
4221         l_pk_attributes := l_pk_attributes || ' , ';
4222       END IF;
4223       l_pk_attributes := l_pk_attributes || 'FXH.SOURCE_TABLE';
4224     END IF;
4225     IF p_fxhv_rec.khr_id IS NULL OR
4226        p_fxhv_rec.khr_id = OKL_API.G_MISS_NUM
4227     THEN
4228       IF l_pk_attributes IS NOT NULL
4229       THEN
4230         l_pk_attributes := l_pk_attributes || ' , ';
4231       END IF;
4232       l_pk_attributes := l_pk_attributes || 'KHR_ID';
4233     END IF;
4234     IF p_fxlv_rec.kle_id IS NULL OR
4235        p_fxlv_rec.kle_id = OKL_API.G_MISS_NUM
4236     THEN
4237       IF l_pk_attributes IS NOT NULL
4238       THEN
4239         l_pk_attributes := l_pk_attributes || ' , ';
4240       END IF;
4241       l_pk_attributes := l_pk_attributes || 'KLE_ID';
4242     END IF;
4243     IF p_fxhv_rec.try_id IS NULL OR
4244        p_fxhv_rec.try_id = OKL_API.G_MISS_NUM
4245     THEN
4246       IF l_pk_attributes IS NOT NULL
4247       THEN
4248         l_pk_attributes := l_pk_attributes || ' , ';
4249       END IF;
4250       l_pk_attributes := l_pk_attributes || 'TRY_ID';
4251     END IF;
4252     IF p_fxlv_rec.asset_id IS NULL OR
4253        p_fxlv_rec.asset_id = OKL_API.G_MISS_NUM
4254     THEN
4255       IF l_pk_attributes IS NOT NULL
4256       THEN
4257         l_pk_attributes := l_pk_attributes || ' , ';
4258       END IF;
4259       l_pk_attributes := l_pk_attributes || 'ASSET_ID';
4260     END IF;
4261 
4262     IF p_fxlv_rec.fa_transaction_id IS NULL OR
4263        p_fxlv_rec.fa_transaction_id = OKL_API.G_MISS_NUM
4264     THEN
4265       IF l_pk_attributes IS NOT NULL
4266       THEN
4267         l_pk_attributes := l_pk_attributes || ' , ';
4268       END IF;
4269       l_pk_attributes := l_pk_attributes || 'FA_TRANSACTION_ID';
4270     END IF;
4271     IF p_fxlv_rec.asset_book_type_name IS NULL OR
4272        p_fxlv_rec.asset_book_type_name = OKL_API.G_MISS_CHAR
4273     THEN
4274       IF l_pk_attributes IS NOT NULL
4275       THEN
4276         l_pk_attributes := l_pk_attributes || ' , ';
4277       END IF;
4278       l_pk_attributes := l_pk_attributes || 'ASSET_BOOK_TYPE_NAME';
4279     END IF;
4280     IF p_fxlv_rec.source_id IS NULL OR
4281        p_fxlv_rec.source_id = OKL_API.G_MISS_NUM
4282     THEN
4283       IF l_pk_attributes IS NOT NULL
4284       THEN
4285         l_pk_attributes := l_pk_attributes || ' , ';
4286       END IF;
4287       l_pk_attributes := l_pk_attributes || 'FXL.SOURCE_ID';
4288     END IF;
4289     IF p_fxlv_rec.source_table IS NULL OR
4290        p_fxlv_rec.source_table = OKL_API.G_MISS_CHAR
4291     THEN
4292       IF l_pk_attributes IS NOT NULL
4293       THEN
4294         l_pk_attributes := l_pk_attributes || ' , ';
4295       END IF;
4296       l_pk_attributes := l_pk_attributes || 'FXL.SOURCE_TABLE';
4297     END IF;
4298     IF LENGTH(l_pk_attributes) > 0
4299     THEN
4300       -- Raise an Exception
4301       OKL_API.set_message(
4302          p_app_name      => G_APP_NAME
4303         ,p_msg_name      => G_INVALID_VALUE
4304         ,p_token1        => G_COL_NAME_TOKEN
4305         ,p_token1_value  => l_pk_attributes);
4306       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
4307       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4308     END IF;
4309     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4310       'Validation 1 Successfull !');
4311     -- Validation 2: Source Table should be OKL_TXL_ASSETS_B/OKL_TXD_ASSETS_B only
4312     IF p_fxhv_rec.source_table <> G_TRX_ASSETS
4313     THEN
4314       -- Raise an Exception
4315       OKL_API.set_message(
4316          p_app_name      => G_APP_NAME
4317         ,p_msg_name      => G_INVALID_VALUE
4318         ,p_token1        => G_COL_NAME_TOKEN
4319         ,p_token1_value  => 'SOURCE_TABLE');
4320       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
4321       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4322     END IF;
4323     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4324       'Validation 2 Successfull !');
4325     -- Validation 3: Source Table should be OKL_TXL_ASSETS_B/OKL_TXD_ASSETS_B only
4326     IF p_fxlv_rec.source_table NOT IN ( G_TXL_ASSETS, G_TXD_ASSETS )
4327     THEN
4328       -- Raise an Exception
4329       OKL_API.set_message(
4330          p_app_name      => G_APP_NAME
4331         ,p_msg_name      => G_INVALID_VALUE
4332         ,p_token1        => G_COL_NAME_TOKEN
4333         ,p_token1_value  => 'SOURCE_TABLE');
4334       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
4335       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4336     END IF;
4337     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4338       'Validation 3 Successfull !');
4339     -- Validation 4: The kle_id value passed should be the Id of the Line with
4340     --               line style as FREE_FORM1
4341     FOR t_rec IN get_line_style_csr ( p_kle_id  => p_fxlv_rec.kle_id )
4342     LOOP
4343       l_line_style := t_rec.line_style;
4344     END LOOP;
4345     IF l_line_style IS NULL OR
4346        l_line_style <> 'FREE_FORM1'
4347     THEN
4348       -- Raise an Exception
4349       OKL_API.set_message(
4350          p_app_name      => G_APP_NAME
4351         ,p_msg_name      => G_INVALID_VALUE
4352         ,p_token1        => G_COL_NAME_TOKEN
4353         ,p_token1_value  => 'KLE_ID');
4354       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
4355       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4356     END IF;
4357 
4358     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4359       'Validation 4 Successfull !');
4360     -- Copy the Input Parameters to the Local Variables
4361     l_khr_id  := p_fxhv_rec.khr_id;
4362     l_kle_id  := p_fxlv_rec.kle_id;
4363     l_try_id  := p_fxhv_rec.try_id;
4364 
4365     -- initialize the local l_fxlv_rec to the input record values
4366     l_fxh_rec.source_id     := p_fxhv_rec.source_id;
4367     l_fxh_rec.source_table  := p_fxhv_rec.source_table;
4368     l_fxh_rec.khr_id        := p_fxhv_rec.khr_id;
4369     l_fxh_rec.try_id        := p_fxhv_rec.try_id;
4370 
4371     l_fxl_rec.source_id            := p_fxlv_rec.source_id;
4372     l_fxl_rec.source_table         := p_fxlv_rec.source_table;
4373     l_fxl_rec.kle_id               := p_fxlv_rec.kle_id;
4374     l_fxl_rec.asset_id             := p_fxlv_rec.asset_id;
4375     l_fxl_rec.fa_transaction_id    := p_fxlv_rec.fa_transaction_id;
4376     l_fxl_rec.asset_book_type_code := p_fxlv_rec.asset_book_type_name;
4377 
4378 	-- get the book type code based on asset_book_type_name .. MG uptake
4379 	OPEN get_book_type_name(l_fxl_rec.asset_book_type_code);
4380 	FETCH get_book_type_name INTO l_fxl_rec.asset_book_type_name;
4381 	CLOSE get_book_type_name;
4382 
4383 --sechawla 4/28 12375727 : added debug message : begin
4384 put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4385       'l_fxl_rec.asset_book_type_code = '||l_fxl_rec.asset_book_type_code);
4386 --sechawla 4/28 12375727 : added debug message : end
4387 
4388 
4389 	-- get the ledger based on the asset_book_type_name. MG uptake
4390     OPEN  get_reps_csr(l_fxl_rec.asset_book_type_code);
4391 	FETCH get_reps_csr into l_ledger_id, l_fxh_rec.representation_code,
4392 	                            l_fxh_rec.representation_name, l_rep_type;
4393 	CLOSE get_reps_csr;
4394 
4395 --sechawla 4/28 12375727 : added debug message : begin
4396       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4397       'after get_reps_csr l_ledger_id = '||l_ledger_id);
4398       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4399       'after get_reps_csr l_fxh_rec.representation_code = '||l_fxh_rec.representation_code);
4400       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4401       'after get_reps_csr l_fxh_rec.representation_name = '||l_fxh_rec.representation_name);
4402       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4403       'after get_reps_csr l_rep_type = '||l_rep_type);
4404  --sechawla 4/28 12375727 : added debug message : end
4405 
4406 
4407     if l_rep_type is not null then
4408 	  G_REPRESENTATION_TYPE := l_rep_type;
4409     else
4410 	  G_REPRESENTATION_TYPE := 'PRIMARY';
4411     end if;
4412 
4413 	  /* -- commented as the ledger is obtained above. MG uptake.
4414       -- Fetch Ledger ID to fetch the Ledger Language associated to the contracts
4415       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4416         'Executing the Cursor c_khr_to_ledger_id_csr. p_khr_id=' || TO_CHAR(l_khr_id));
4417       FOR t_rec IN c_khr_to_ledger_id_csr( p_khr_id => l_khr_id )
4418       LOOP
4419         l_ledger_id := t_rec.ledger_id;
4420       END LOOP;
4421       */
4422 
4423     -- Using the Ledger ID fetch the Ledger Language
4424     -- Fetch the ledger language in order to populate the sources
4425     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4426       'Executing the Cursor c_ledger_lang_csr. p_ledger_id=' || TO_CHAR(l_ledger_id));
4427     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_ledger_id )
4428     LOOP
4429       l_led_lang_tbl(tl_sources_in).language := t_rec.language_code;
4430       l_fxll_tbl(tl_sources_in).language     := t_rec.language_code;
4431     END LOOP;
4432 
4433     -- Prepare khr_source_rec_type with khr_id and ledger_language
4434     l_khr_source_rec.khr_id            := l_khr_id;
4435 
4436     -- Calling populate_khr_sources
4437     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4438       'Calling the populate_khr_sources' );
4439 
4440      --sechawla 4/28 12375727 : added debug message : begin
4441       if l_led_lang_tbl.count >0 then
4442       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4443       'l_led_lang_tbl.count >0' );
4444       elsif l_led_lang_tbl.count = 0 then
4445       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4446       'l_led_lang_tbl.count = 0' );
4447       end if;
4448       --sechawla 4/28 12375727 : added debug message : end
4449 
4450 
4451     populate_khr_sources(
4452        p_api_version      => l_api_version
4453       ,p_init_msg_list    => p_init_msg_list
4454       ,x_khr_source_rec   => l_khr_source_rec
4455       ,x_led_lang_tbl     => l_led_lang_tbl
4456       ,x_return_status    => l_return_status
4457       ,x_msg_count        => x_msg_count
4458       ,x_msg_data         => x_msg_data );
4459     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4460       'After populate_khr_sources: l_return_status ' || l_return_status );
4461     -- Check the return status and if errored, return the error back
4462     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4463       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4464     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4465       RAISE OKL_API.G_EXCEPTION_ERROR;
4466     END IF;
4467 
4468     --calling assign_khr_rec_to_fxhv_rec
4469     assign_khr_rec_to_fxh_rec(
4470        p_khr_source_rec => l_khr_source_rec
4471       ,x_fxh_rec       => l_fxh_rec );
4472 
4473     FOR tl_sources_in IN l_led_lang_tbl.FIRST .. l_led_lang_tbl.LAST
4474     LOOP
4475       l_fxhl_tbl(tl_sources_in).language             := l_led_lang_tbl(tl_sources_in).language;
4476       l_fxhl_tbl(tl_sources_in).contract_status      := l_led_lang_tbl(tl_sources_in).contract_status;
4477 
4478       -- Fetch transaction type name wrt ledger language
4479       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4480         'Executing the Cursor c_trx_type_name_csr. p_try_id=' || l_try_id || 'p_led_lang= ' || l_fxhl_tbl(tl_sources_in).language );
4481       FOR t_rec IN c_trx_type_name_csr(
4482                       p_try_id    => l_try_id
4483                      ,p_led_lang  => l_fxhl_tbl(tl_sources_in).language )
4484       LOOP
4485         l_fxhl_tbl(tl_sources_in).transaction_type_name := t_rec.transaction_type_name;
4486         -- Assign the Trx. Type Class Code also.
4487         l_fxh_rec.trx_type_class_code  := t_rec.trx_type_class_code;
4488       END LOOP; -- End for c_trx_type_name_csr
4489     END LOOP;
4490 
4491 put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4492 'l_fxh_rec.trx_type_class_code = ' || l_fxh_rec.trx_type_class_code );
4493 put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module,
4494 'S', 'p_khr_id = ' || l_khr_id || 'l_kle_id = '|| l_kle_id);
4495 
4496     IF l_fxh_rec.trx_type_class_code = 'OFFLEASE_AMORTIZATION'
4497     THEN
4498       -- Fetch Termination Quote related Sources during Offlease Amortization
4499       FOR t_rec IN c_tq_dtls_offlease( p_kle_id => l_kle_id )
4500       LOOP
4501         l_fxh_rec.term_quote_num         := t_rec.quote_number;
4502         l_fxh_rec.term_quote_accept_date := t_rec.quote_accepted_date;
4503         l_fxh_rec.term_quote_type_code   := t_rec.quote_type;
4504       END LOOP;
4505     ELSIF l_fxh_rec.trx_type_class_code = 'SPLIT_ASSET'
4506     THEN
4507       -- Fetch Termination Quote related Sources during Split Asset
4508       FOR t_rec IN c_tq_dtls_split_ast(
4509                       p_kle_id              => l_kle_id
4510                      ,p_split_asset_trx_id  => l_fxh_rec.source_id )
4511       LOOP
4512         l_fxh_rec.term_quote_num         := t_rec.quote_number;
4513         l_fxh_rec.term_quote_accept_date := t_rec.quote_accepted_date;
4514         l_fxh_rec.term_quote_type_code   := t_rec.quote_type;
4515       END LOOP;
4516     ELSIF l_fxh_rec.trx_type_class_code = 'RELEASE'
4517     THEN
4518       -- Fetch Termination Quote related Sources during Release
4519       FOR t_rec IN c_tq_dtls_release( p_khr_id  => l_khr_id )
4520       LOOP
4521         l_fxh_rec.term_quote_num         := t_rec.quote_number;
4522         l_fxh_rec.term_quote_accept_date := t_rec.quote_accepted_date;
4523         l_fxh_rec.term_quote_type_code   := t_rec.quote_type;
4524       END LOOP;
4525    --rkuttiya added for bug#6674730  Loans Repossession
4526     ELSIF l_fxh_rec.trx_type_class_code = 'INTERNAL_ASSET_CREATION' AND
4527           p_fxhv_rec.repossess_flag = 'Y' THEN
4528     --Fetch Termination Quote related Sources during Repossession
4529       l_fxh_rec.term_quote_num := p_fxhv_rec.term_quote_num;
4530       l_fxh_rec.term_quote_accept_date := p_fxhv_rec.term_quote_accept_date;
4531       l_fxh_rec.term_quote_type_code   := p_fxhv_rec.term_quote_type_code;
4532       l_fxh_rec.repossess_flag         := p_fxhv_rec.repossess_flag;
4533 
4534   -- vsgandhi Bug: 1390374
4535   -- start
4536    ELSIF l_fxh_rec.trx_type_class_code = 'ASSET_DISPOSITION'
4537     THEN
4538       -- Fetch Termination Quote related Sources during Release
4539       FOR t_rec IN c_tq_dtls( p_khr_id  => l_khr_id ,
4540                               p_kle_id  => l_kle_id)
4541       LOOP
4542         l_fxh_rec.term_quote_num         := t_rec.quote_number;
4543         l_fxh_rec.term_quote_accept_date := t_rec.quote_accepted_date;
4544         l_fxh_rec.term_quote_type_code   := t_rec.quote_type;
4545       END LOOP;
4546   -- end
4547 
4548     END IF;
4549 
4550     -- Start populating the FXLV Record Structure
4551     -- Fetch transaction number
4552     IF p_fxlv_rec.source_table = 'OKL_TXL_ASSETS_B'
4553     THEN
4554       -- if source table is OKL_TXL_ASSETS_B
4555       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4556         'Executing the Cursor c_txl_trans_number_csr. p_source_id=' || p_fxlv_rec.source_id);
4557       FOR t_rec IN c_txl_trans_number_csr(
4558                     p_source_id    => p_fxlv_rec.source_id )
4559       LOOP
4560         l_fxh_rec.trans_number  := t_rec.trans_number;
4561         l_txl_id                := t_rec.txl_id;
4562         l_fxh_rec.source_id     := t_rec.tas_id;
4563       END LOOP; -- End for c_txl_trans_number_csr
4564     ELSIF p_fxlv_rec.source_table = 'OKL_TXD_ASSETS_B'
4565     THEN
4566       --if source table is OKL_TXD_ASSETS_B
4567       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4568         'Executing the Cursor c_txd_trans_number_csr. p_source_id=' || p_fxlv_rec.source_id);
4569       FOR t_rec IN c_txd_trans_number_csr(
4570                     p_source_id    => p_fxlv_rec.source_id )
4571       LOOP
4572         l_fxh_rec.trans_number  := t_rec.trans_number;
4573         l_txl_id                := t_rec.txl_id;
4574         l_fxh_rec.source_id     := t_rec.tas_id;
4575       END LOOP; -- End for c_txd_trans_number_csr
4576     END IF;
4577 
4578     -- Fetch and Populate Sales Representative Name
4579     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4580       'Executing the Cursor  c_sales_rep_csr. p_khr_id = ' || TO_CHAR(l_khr_id) );
4581     FOR t_rec IN  c_sales_rep_csr (l_khr_id)
4582     LOOP
4583       l_sales_rep_csr_rec := t_rec;
4584       l_fxh_rec.sales_rep_name := l_sales_rep_csr_rec.name;
4585     END LOOP; -- End for c_sales_rep_csr
4586 
4587     -- Calling insert_row
4588     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4589       'Calling the okl_fa_extension_pvt.create_fxh_extension ' || l_fxh_rec.source_id );
4590     okl_fa_extension_pvt.create_fxh_extension(
4591        p_api_version     => l_api_version
4592       ,p_init_msg_list   => p_init_msg_list
4593       ,x_return_status   => l_return_status
4594       ,x_msg_count       => x_msg_count
4595       ,x_msg_data        => x_msg_data
4596       ,p_fxh_rec         => l_fxh_rec
4597       ,p_fxhl_tbl        => l_fxhl_tbl
4598       ,x_fxh_rec         => lx_fxh_rec
4599       ,x_fxhl_tbl        => lx_fxhl_tbl
4600     );
4601     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4602       'After okl_fa_extension_pvt.create_fxh_extension: l_return_status ' || l_return_status );
4603     -- Check the return status and if errored, return the error back
4604     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
4605     THEN
4606       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4607     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4608       RAISE OKL_API.G_EXCEPTION_ERROR;
4609     END IF;
4610 
4611     l_header_extension_id := lx_fxh_rec.header_extension_id;
4612     -- Prepare kle_source_rec_type with khr_id, kle_id and ledger_language
4613     l_kle_source_rec.khr_id            := l_khr_id;
4614     l_kle_source_rec.kle_id            := l_kle_id;
4615     -- Calling populate_kle_sources
4616     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4617       'Calling the populate_kle_sources' );
4618     populate_kle_sources(
4619       p_api_version      => l_api_version
4620      ,p_init_msg_list    => p_init_msg_list
4621      ,x_kle_source_rec   => l_kle_source_rec
4622      ,x_return_status    => l_return_status
4623      ,x_msg_count        => x_msg_count
4624      ,x_msg_data         => x_msg_data );
4625     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4626       'After populate_kle_sources: l_return_status ' || l_return_status );
4627     -- Check the return status and if errored, return the error back
4628     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
4629     THEN
4630       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4631     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4632       RAISE OKL_API.G_EXCEPTION_ERROR;
4633     END IF;
4634 
4635     -- Assin the KLE Sources to the FA Extension Line
4636     assign_kle_rec_to_fxl_rec(
4637        p_kle_source_rec => l_kle_source_rec
4638       ,x_fxl_rec => l_fxl_rec );
4639 
4640     -- Fetch and Populate Inventory Organization Name
4641     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4642       'Executing Cursor c_inventory_org_id_csr : l_khr_id = ' ||to_char(l_khr_id));
4643     FOR t_rec IN c_inventory_org_id_csr (l_khr_id)
4644     LOOP
4645       -- Assign the Inventory Organization Code
4646       l_fxl_rec.inventory_org_code := t_rec.hrb_name;
4647       FOR tl_sources_in IN l_fxll_tbl.FIRST .. l_fxll_tbl.LAST
4648       LOOP
4649         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4650           'Executing Cursor c_org_name_csr : p_org_id = ' ||to_char(t_rec.inv_organization_id)
4651           || ' p_ledger_lang = ' || to_char(l_fxll_tbl(tl_sources_in).language));
4652         FOR t_org_rec IN c_org_name_csr (
4653                      p_org_id        => t_rec.inv_organization_id
4654                     ,p_ledger_lang   => l_fxll_tbl(tl_sources_in).language)
4655         LOOP
4656           l_fxll_tbl(tl_sources_in).inventory_org_name := t_org_rec.org_name;
4657         END LOOP; -- End for c_org_name_csr
4658 
4659         -- Fetch transaction line description
4660         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4661           'Executing the Cursor get_txl_line_desc_csr. p_txl_id=' || l_txl_id
4662           || ' p_ledger_language=' || l_fxll_tbl(tl_sources_in).language);
4663         FOR t_rec IN get_txl_line_desc_csr(
4664                      p_txl_id        => l_txl_id
4665                     ,p_ledger_lang   => l_fxll_tbl(tl_sources_in).language )
4666         LOOP
4667           l_fxll_tbl(tl_sources_in).trans_line_description := t_rec.trans_line_description;
4668         END LOOP; -- End for get_txl_line_desc_csr
4669       END LOOP;
4670     END LOOP; -- End for c_inventory_org_id_csr
4671 
4672     -- Stamp the FA Extension Header ID on the FA Extension Line Table also
4673     l_fxl_rec.header_extension_id := l_header_extension_id;
4674     -- Calling insert_row
4675     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4676       'Calling the okl_fa_extension_pvt.create_fxl_extension' );
4677     okl_fa_extension_pvt.create_fxl_extension(
4678        p_api_version     => l_api_version
4679       ,p_init_msg_list   => p_init_msg_list
4680       ,x_return_status   => l_return_status
4681       ,x_msg_count       => x_msg_count
4682       ,x_msg_data        => x_msg_data
4683       ,p_fxl_rec         => l_fxl_rec
4684       ,p_fxll_tbl        => l_fxll_tbl
4685       ,x_fxl_rec         => lx_fxl_rec
4686       ,x_fxll_tbl        => lx_fxll_tbl
4687      );
4688     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4689       'After okl_fa_extension_pvt.create_fxl_extension: l_return_status ' || l_return_status );
4690     -- Check the return status and if errored, return the error back
4691     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
4692     THEN
4693       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4694     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
4695     THEN
4696       RAISE OKL_API.G_EXCEPTION_ERROR;
4697     END IF;
4698     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4699       'Calling okl_api.end_activity');
4700     okl_api.end_activity(
4701        x_msg_count => x_msg_count
4702       ,x_msg_data  => x_msg_data);
4703     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4704       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
4705     x_return_status := OKL_API.G_RET_STS_SUCCESS;
4706   EXCEPTION
4707     ------------------------------------------------------------
4708     -- Exception handling
4709     ------------------------------------------------------------
4710     WHEN OKL_API.G_EXCEPTION_ERROR
4711     THEN
4712       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4713                             p_api_name  => l_api_name
4714                            ,p_pkg_name  => G_PKG_NAME
4715                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
4716                            ,x_msg_count  => x_msg_count
4717                            ,x_msg_data  => x_msg_data
4718                            ,p_api_type  => '_PVT');
4719     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
4720     THEN
4721       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4722                             p_api_name  => l_api_name
4723                            ,p_pkg_name  => G_PKG_NAME
4724                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
4725                            ,x_msg_count  => x_msg_count
4726                            ,x_msg_data  => x_msg_data
4727                            ,p_api_type  => '_PVT');
4728     WHEN OTHERS
4729     THEN
4730       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4731                             p_api_name  => l_api_name
4732                            ,p_pkg_name  => G_PKG_NAME
4733                            ,p_exc_name  => 'OTHERS'
4734                            ,x_msg_count  => x_msg_count
4735                            ,x_msg_data  => x_msg_data
4736                            ,p_api_type  => '_PVT');
4737   END populate_sources;
4738 
4739   PROCEDURE delete_fa_extension(
4740     p_api_version               IN             NUMBER
4741    ,p_init_msg_list             IN             VARCHAR2
4742    ,p_fxhv_rec                  IN             fxhv_rec_type
4743    ,x_fxlv_tbl                  OUT    NOCOPY  fxlv_tbl_type
4744    ,x_return_status             OUT    NOCOPY  VARCHAR2
4745    ,x_msg_count                 OUT    NOCOPY  NUMBER
4746    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
4747   )
4748   IS
4749     -----------------------------------------------------------------
4750     -- Declare Process Variable
4751     -----------------------------------------------------------------
4752     l_api_version      CONSTANT NUMBER         := 1;
4753     l_api_name         CONSTANT VARCHAR2(30)   := 'DELETE_TRX_EXTENSION';
4754     l_return_status    VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
4755     fxl_index          BINARY_INTEGER;
4756     l_fxhv_rec         okl_fxh_pvt.fxhv_rec_type;
4757     l_fxlv_tbl         okl_fxl_pvt.fxlv_tbl_type;
4758     lx_fxhv_rec        okl_fxh_pvt.fxhv_rec_type;
4759     lx_fxlv_tbl        okl_fxl_pvt.fxlv_tbl_type;
4760     -- Cursor Definitions
4761     CURSOR get_fa_ext_hdr_id( p_source_id  NUMBER, p_source_table VARCHAR2)
4762     IS
4763       SELECT   fxh.header_extension_id      header_extension_id
4764         FROM   okl_ext_fa_header_sources_b	fxh
4765        WHERE   fxh.source_id = p_source_id
4766          AND   fxh.source_table = p_source_table;
4767 
4768     CURSOR get_fa_ext_lns_id( p_hdr_ext_id  NUMBER)
4769     IS
4770       SELECT   fxl.line_extension_id     line_extension_id
4771               ,fxl.source_id             source_id
4772               ,fxl.source_table          source_table
4773         FROM   okl_ext_fa_line_sources_b fxl
4774        WHERE   fxl.header_extension_id = p_hdr_ext_id;
4775     -- Local Variables for enabling the Debug Statements
4776     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
4777     l_debug_enabled                    VARCHAR2(10);
4778     is_debug_procedure_on              BOOLEAN;
4779     is_debug_statement_on              BOOLEAN;
4780   BEGIN
4781     l_debug_enabled := okl_debug_pub.check_log_enabled;
4782     -- check for logging on PROCEDURE level
4783     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
4784     -- check for logging on STATEMENT level
4785     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
4786     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4787                'begin debug OKLRSLAB.pls call ' || l_api_name);
4788     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4789                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.DELETE_TRX_EXTENSION');
4790     l_return_status := OKL_API.G_RET_STS_SUCCESS;
4791     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4792       'Calling OKL_API.START_ACTIVITY');
4793     l_return_status := OKL_API.START_ACTIVITY(
4794                          p_api_name       => l_api_name
4795                         ,p_pkg_name       => g_pkg_name
4796                         ,p_init_msg_list  => p_init_msg_list
4797                         ,l_api_version    => l_api_version
4798                         ,p_api_version    => p_api_version
4799                         ,p_api_type       => '_PVT'
4800                         ,x_return_status  => l_return_status);
4801     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
4802       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4803     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4804       RAISE OKL_API.G_EXCEPTION_ERROR;
4805     END IF;
4806     -- Actual Logic Starts Here ..
4807     l_fxhv_rec := p_fxhv_rec;
4808     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4809       'Source ID=' || to_char(l_fxhv_rec.source_id) || 'Source Header Table=' || l_fxhv_rec.source_table );
4810     IF ( l_fxhv_rec.source_id = OKL_API.G_MISS_NUM or l_fxhv_rec.source_id IS NULL )
4811     THEN
4812       OKL_API.set_message(
4813          p_app_name      => G_APP_NAME
4814         ,p_msg_name      => G_INVALID_VALUE
4815         ,p_token1        => G_COL_NAME_TOKEN
4816         ,p_token1_value  => 'FXH.SOURCE_ID');
4817       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
4818       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4819     END IF;
4820     IF ( l_fxhv_rec.source_table = OKL_API.G_MISS_CHAR OR l_fxhv_rec.source_table IS NULL
4821         OR l_fxhv_rec.source_table NOT IN ( G_TRX_ASSETS) )
4822     THEN
4823       OKL_API.set_message(
4824          p_app_name      => G_APP_NAME
4825         ,p_msg_name      => G_INVALID_VALUE
4826         ,p_token1        => G_COL_NAME_TOKEN
4827         ,p_token1_value  => 'FXH.SOURCE_TABLE');
4828       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
4829       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4830     END IF;
4831     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4832       'Fetch the Extension Header ID by executing cursor get_txl_ext_hdr_id' );
4833     FOR t_rec IN get_fa_ext_hdr_id(
4834                     p_source_id     => l_fxhv_rec.source_id
4835                    ,p_source_table  => l_fxhv_rec.source_table)
4836     LOOP
4837       l_fxhv_rec.header_extension_id := t_rec.header_extension_id;
4838     END LOOP;
4839     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4840       'Extension Header ID To be Deleted='  || TO_CHAR(l_fxhv_rec.header_extension_id));
4841 
4842     -- Fetch the Transaction Extension Line IDs to be deleted
4843     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4844       'Extension Line ID(s) To be Deleted=');
4845     fxl_index := 1;
4846     FOR t_rec IN get_fa_ext_lns_id( p_hdr_ext_id  => l_fxhv_rec.header_extension_id)
4847     LOOP
4848       l_fxlv_tbl(fxl_index).line_extension_id  := t_rec.line_extension_id;
4849       l_fxlv_tbl(fxl_index).source_id          := t_rec.source_id;
4850       l_fxlv_tbl(fxl_index).source_table       := t_rec.source_table;
4851       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4852         'LINE_EXTENSION_ID[' || fxl_index || '] = ' || TO_CHAR(l_fxlv_tbl(fxl_index).line_extension_id) );
4853       -- Increment i
4854       fxl_index := fxl_index + 1;
4855     END LOOP; -- End get_trans_line_ids
4856     -- Store the Transaction Line IDs and Line Source Tables so as to return back
4857     x_fxlv_tbl := l_fxlv_tbl;
4858 
4859     -- Delete the FA Extension Lines by calling the TAPI first
4860     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4861       'calling the okl_fa_extension_pvt okl_fxl_pvt.delete_row Line Count=' || l_fxlv_tbl.COUNT );
4862     okl_fa_extension_pvt.delete_fxh_extension(
4863       p_api_version     => p_api_version
4864      ,p_init_msg_list   => p_init_msg_list
4865      ,x_return_status   => x_return_status
4866      ,x_msg_count       => x_msg_count
4867      ,x_msg_data        => x_msg_data
4868      ,p_fxhv_rec        => l_fxhv_rec
4869     );
4870     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4871       'After okl_fa_extension_pvt.delete_fxh_extension: l_return_status ' || l_return_status );
4872     -- Check the return status and if errored, return the error back
4873     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
4874     THEN
4875       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
4876     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
4877       RAISE OKL_API.G_EXCEPTION_ERROR;
4878     END IF;
4879     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
4880       'Calling okl_api.end_activity');
4881     okl_api.end_activity(
4882        x_msg_count => x_msg_count
4883       ,x_msg_data  => x_msg_data);
4884     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
4885       'END OKL_SLA_ACC_SOURCES_PVT.DELETE_TRX_EXTENSION');
4886     x_return_status := OKL_API.G_RET_STS_SUCCESS;
4887   EXCEPTION
4888     ------------------------------------------------------------
4889     -- Exception handling
4890     ------------------------------------------------------------
4891     WHEN OKL_API.G_EXCEPTION_ERROR
4892     THEN
4893       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4894                             p_api_name  => l_api_name
4895                            ,p_pkg_name  => G_PKG_NAME
4896                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
4897                            ,x_msg_count => x_msg_count
4898                            ,x_msg_data  => x_msg_data
4899                            ,p_api_type  => '_PVT');
4900     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
4901     THEN
4902       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4903                             p_api_name  => l_api_name
4904                            ,p_pkg_name  => G_PKG_NAME
4905                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
4906                            ,x_msg_count => x_msg_count
4907                            ,x_msg_data  => x_msg_data
4908                            ,p_api_type  => '_PVT');
4909     WHEN OTHERS
4910     THEN
4911      x_return_status := OKL_API.HANDLE_EXCEPTIONS (
4912                             p_api_name  => l_api_name
4913                            ,p_pkg_name  => G_PKG_NAME
4914                            ,p_exc_name  => 'OTHERS'
4915                            ,x_msg_count => x_msg_count
4916                            ,x_msg_data  => x_msg_data
4917                            ,p_api_type  => '_PVT');
4918   END delete_fa_extension;
4919 
4920   ------------------------------------------------------------------------------
4921   -- Start of comments
4922   --      API name        : assign_khr_rec_to_rxhv_rec
4923   --      Pre-reqs        : None
4924   --      Function        : assign khr rec to rxhv rec for AR OKL Transactions
4925   --      Parameters      :
4926   --      IN              : p_khr_source_rec     khr_source_rec_type
4927   --      OUT             : x_rxhv_rec           rxhv_rec_type
4928   --      Version         : 1.0
4929   --      History         : Prashant Jain created
4930   -- End of comments
4931   ------------------------------------------------------------------------------
4932   -- Changes for Bug# 6268782 : PRASJAIN
4933   -- 1. func name assign_khr_rec_to_rxhv_rec to assign_khr_rec_to_rxh_rec
4934   -- 2. out param rxhv_rec_type to rxh_rec_type
4935   ------------------------------------------------------------------------------
4936   PROCEDURE assign_khr_rec_to_rxh_rec(
4937     p_khr_source_rec  IN       khr_source_rec_type
4938    ,x_rxh_rec         IN OUT   NOCOPY rxh_rec_type
4939   )
4940   AS
4941   BEGIN
4942     x_rxh_rec.khr_id                  := p_khr_source_rec.khr_id;
4943     x_rxh_rec.contract_number         := p_khr_source_rec.contract_number;
4944     x_rxh_rec.contract_currency_code  := p_khr_source_rec.contract_currency_code;
4945     x_rxh_rec.contract_effective_from := p_khr_source_rec.contract_effective_from;
4946     x_rxh_rec.product_name            := p_khr_source_rec.product_name;
4947     x_rxh_rec.book_classification_code:= p_khr_source_rec.book_classification_code;
4948     x_rxh_rec.tax_owner_code          := p_khr_source_rec.tax_owner_code;
4949     x_rxh_rec.rev_rec_method_code     := p_khr_source_rec.rev_rec_method_code;
4950     x_rxh_rec.int_calc_method_code    := p_khr_source_rec.int_calc_method_code;
4951     x_rxh_rec.vendor_program_number   := p_khr_source_rec.vendor_program_number;
4952     x_rxh_rec.converted_number        := p_khr_source_rec.converted_number;
4953     x_rxh_rec.converted_account_flag  := p_khr_source_rec.converted_account_flag;
4954     x_rxh_rec.assignable_flag         := p_khr_source_rec.assignable_flag;
4955     x_rxh_rec.po_order_number         := p_khr_source_rec.po_order_number;
4956     x_rxh_rec.accrual_override_flag   := p_khr_source_rec.accrual_override_flag;
4957     x_rxh_rec.rent_ia_contract_number := p_khr_source_rec.rent_ia_contract_number;
4958     x_rxh_rec.rent_ia_product_name    := p_khr_source_rec.rent_ia_product_name;
4959     x_rxh_rec.rent_ia_accounting_code := p_khr_source_rec.rent_ia_accounting_code;
4960     x_rxh_rec.res_ia_contract_number  := p_khr_source_rec.res_ia_contract_number;
4961     x_rxh_rec.res_ia_product_name     := p_khr_source_rec.res_ia_product_name;
4962     x_rxh_rec.res_ia_accounting_code  := p_khr_source_rec.res_ia_accounting_code;
4963     x_rxh_rec.khr_attribute_category  := p_khr_source_rec.khr_attribute_category;
4964     x_rxh_rec.khr_attribute1          := p_khr_source_rec.khr_attribute1;
4965     x_rxh_rec.khr_attribute2          := p_khr_source_rec.khr_attribute2;
4966     x_rxh_rec.khr_attribute3          := p_khr_source_rec.khr_attribute3;
4967     x_rxh_rec.khr_attribute4          := p_khr_source_rec.khr_attribute4;
4968     x_rxh_rec.khr_attribute5          := p_khr_source_rec.khr_attribute5;
4969     x_rxh_rec.khr_attribute6          := p_khr_source_rec.khr_attribute6;
4970     x_rxh_rec.khr_attribute7          := p_khr_source_rec.khr_attribute7;
4971     x_rxh_rec.khr_attribute8          := p_khr_source_rec.khr_attribute8;
4972     x_rxh_rec.khr_attribute9          := p_khr_source_rec.khr_attribute9;
4973     x_rxh_rec.khr_attribute10         := p_khr_source_rec.khr_attribute10;
4974     x_rxh_rec.khr_attribute11         := p_khr_source_rec.khr_attribute11;
4975     x_rxh_rec.khr_attribute12         := p_khr_source_rec.khr_attribute12;
4976     x_rxh_rec.khr_attribute13         := p_khr_source_rec.khr_attribute13;
4977     x_rxh_rec.khr_attribute14         := p_khr_source_rec.khr_attribute14;
4978     x_rxh_rec.khr_attribute15         := p_khr_source_rec.khr_attribute15;
4979     x_rxh_rec.cust_attribute_category := p_khr_source_rec.cust_attribute_category;
4980     x_rxh_rec.cust_attribute1         := p_khr_source_rec.cust_attribute1;
4981     x_rxh_rec.cust_attribute2         := p_khr_source_rec.cust_attribute2;
4982     x_rxh_rec.cust_attribute3         := p_khr_source_rec.cust_attribute3;
4983     x_rxh_rec.cust_attribute4         := p_khr_source_rec.cust_attribute4;
4984     x_rxh_rec.cust_attribute5         := p_khr_source_rec.cust_attribute5;
4985     x_rxh_rec.cust_attribute6         := p_khr_source_rec.cust_attribute6;
4986     x_rxh_rec.cust_attribute7         := p_khr_source_rec.cust_attribute7;
4987     x_rxh_rec.cust_attribute8         := p_khr_source_rec.cust_attribute8;
4988     x_rxh_rec.cust_attribute9         := p_khr_source_rec.cust_attribute9;
4989     x_rxh_rec.cust_attribute10        := p_khr_source_rec.cust_attribute10;
4990     x_rxh_rec.cust_attribute11        := p_khr_source_rec.cust_attribute11;
4991     x_rxh_rec.cust_attribute12        := p_khr_source_rec.cust_attribute12;
4992     x_rxh_rec.cust_attribute13        := p_khr_source_rec.cust_attribute13;
4993     x_rxh_rec.cust_attribute14        := p_khr_source_rec.cust_attribute14;
4994     x_rxh_rec.cust_attribute15        := p_khr_source_rec.cust_attribute15;
4995     x_rxh_rec.contract_status_code    := p_khr_source_rec.contract_status_code;
4996     x_rxh_rec.inv_agrmnt_number         := p_khr_source_rec.inv_agrmnt_number;
4997     x_rxh_rec.inv_agrmnt_effective_from := p_khr_source_rec.inv_agrmnt_effective_from;
4998     x_rxh_rec.inv_agrmnt_product_name   := p_khr_source_rec.inv_agrmnt_product_name;
4999     x_rxh_rec.inv_agrmnt_currency_code  := p_khr_source_rec.inv_agrmnt_currency_code;
5000     x_rxh_rec.inv_agrmnt_synd_code      := p_khr_source_rec.inv_agrmnt_synd_code;
5001     x_rxh_rec.inv_agrmnt_pool_number    := p_khr_source_rec.inv_agrmnt_pool_number;
5002     x_rxh_rec.inv_agrmnt_status_code    := p_khr_source_rec.inv_agrmnt_status_code;
5003     x_rxh_rec.scs_code                  := p_khr_source_rec.scs_code;
5004   END assign_khr_rec_to_rxh_rec;
5005 
5006  ------------------------------------------------------------------------------
5007   -- Start of comments
5008   --      API name        : assign_kle_rec_to_rxlv_rec
5009   --      Pre-reqs        : None
5010   --      Function        : assign kle rec to rxlv rec for AR OKL Transactions
5011   --      Parameters      :
5012   --      IN              : p_kle_source_rec     kle_source_rec_type
5013   --      OUT             : x_rxlv_rec           rxlv_rec_type
5014   --      Version         : 1.0
5015   --      History         : Prashant Jain created
5016   -- End of comments
5017   ------------------------------------------------------------------------------
5018   -- Changes for Bug# 6268782 : PRASJAIN
5019   -- 1. func name assign_kle_rec_to_rxlv_rec to assign_kle_rec_to_rxl_rec
5020   -- 2. out param rxlv_rec_type to rxl_rec_type
5021   ------------------------------------------------------------------------------
5022   PROCEDURE assign_kle_rec_to_rxl_rec(
5023     p_kle_source_rec  IN       kle_source_rec_type
5024    ,x_rxl_rec        IN OUT   NOCOPY rxl_rec_type
5025   )
5026   AS
5027   BEGIN
5028     x_rxl_rec.kle_id                    := p_kle_source_rec.kle_id;
5029     x_rxl_rec.asset_number              := p_kle_source_rec.asset_number;
5030     x_rxl_rec.contract_line_number      := p_kle_source_rec.contract_line_number;
5031     x_rxl_rec.asset_vendor_name         := p_kle_source_rec.asset_vendor_name;
5032     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
5033     x_rxl_rec.asset_vendor_id           := p_kle_source_rec.asset_vendor_id;
5034     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
5035     x_rxl_rec.installed_site_id         := p_kle_source_rec.installed_site_id;
5036     x_rxl_rec.fixed_asset_location_name := p_kle_source_rec.fixed_asset_location_name;
5037     x_rxl_rec.contract_line_type        := p_kle_source_rec.line_type_code;
5038     x_rxl_rec.line_attribute_category   := p_kle_source_rec.line_attribute_category;
5039     x_rxl_rec.line_attribute1           := p_kle_source_rec.line_attribute1;
5040     x_rxl_rec.line_attribute2           := p_kle_source_rec.line_attribute2;
5041     x_rxl_rec.line_attribute3           := p_kle_source_rec.line_attribute3;
5042     x_rxl_rec.line_attribute4           := p_kle_source_rec.line_attribute4;
5043     x_rxl_rec.line_attribute5           := p_kle_source_rec.line_attribute5;
5044     x_rxl_rec.line_attribute6           := p_kle_source_rec.line_attribute6;
5045     x_rxl_rec.line_attribute7           := p_kle_source_rec.line_attribute7;
5046     x_rxl_rec.line_attribute8           := p_kle_source_rec.line_attribute8;
5047     x_rxl_rec.line_attribute9           := p_kle_source_rec.line_attribute9;
5048     x_rxl_rec.line_attribute10          := p_kle_source_rec.line_attribute10;
5049     x_rxl_rec.line_attribute11          := p_kle_source_rec.line_attribute11;
5050     x_rxl_rec.line_attribute12          := p_kle_source_rec.line_attribute12;
5051     x_rxl_rec.line_attribute13          := p_kle_source_rec.line_attribute13;
5052     x_rxl_rec.line_attribute14          := p_kle_source_rec.line_attribute14;
5053     x_rxl_rec.line_attribute15          := p_kle_source_rec.line_attribute15;
5054   END assign_kle_rec_to_rxl_rec;
5055 
5056   ------------------------------------------------------------------------------
5057   -- Start of comments
5058   --      API name        : populate_ar_sources
5059   --      Pre-reqs        : None
5060   --      Function        : populate sources for OKL AR Transactions
5061   --      Parameters      :
5062   --      IN              : rxhv_rec_type.source_id            IN NUMBER    Required
5063   --                        rxhv_rec_type.source_table         IN VARCHAR2  Required
5064 
5065   --                        rxhv_rec_type.khr_id               IN NUMBER    Required
5066   --                        rxlv_rec_type.kle_id               IN NUMBER    Optional
5067   --                        rxhv_rec_type.try_id               IN NUMBER    Required
5068   --                        rxlv_rec_type.sty_id               IN NUMBER    Optional
5069   --                        rxlv_rec_type.source_id            IN NUMBER    Required
5070   --                        rxlv_rec_type.source_table         IN VARCHAR2  Required
5071   --      History         : Prashant Jain created
5072   --      Version         : 1.0
5073   -- End of comments
5074   ------------------------------------------------------------------------------
5075   PROCEDURE populate_ar_sources(
5076     p_api_version           IN        NUMBER
5077    ,p_init_msg_list         IN        VARCHAR2
5078    ,p_rxhv_rec              IN        rxhv_rec_type
5079    ,p_rxlv_rec              IN        rxlv_rec_type
5080    ,p_acc_sources_rec       IN        asev_rec_type
5081    ,x_return_status         OUT       NOCOPY  VARCHAR2
5082    ,x_msg_count             OUT       NOCOPY  NUMBER
5083    ,x_msg_data              OUT       NOCOPY  VARCHAR2
5084   )
5085   IS
5086     -- Cursor to fetch header_extension_id
5087     CURSOR c_header_extension_id_csr (
5088              p_header_source_id    NUMBER
5089             ,p_header_source_table VARCHAR2
5090             ,p_khr_id              NUMBER)
5091     IS
5092       SELECT    hdr.header_extension_id     header_extension_id
5093         FROM    okl_ext_ar_header_sources_b hdr
5094        WHERE    hdr.source_id = p_header_source_id
5095          AND    hdr.khr_id    = p_khr_id;
5096 
5097     -- Cursor to fetch trans number
5098     CURSOR c_trans_number_csr (p_header_source_id NUMBER)
5099     IS
5100       SELECT    tai.trx_number trans_number
5101                -- ,tai.tcn_id     tai_tcn_id -- added qte_id below. racheruv 15978873
5102 			   ,tai.qte_id     qte_id
5103         FROM    okl_trx_ar_invoices_b tai
5104        WHERE    tai.id = p_header_source_id;
5105 
5106     -- Cursor to fetch the Qte_id from the AR Transaction Header
5107     --
5108     CURSOR get_tai_tcn_qte_id_csr( p_tcn_id NUMBER)
5109     IS
5110       SELECT   tcn.qte_id  qte_id
5111         FROM   okl_trx_contracts_all tcn
5112        WHERE   tcn.id = p_tcn_id;
5113     -----------------------------------------------------------------
5114     -- Declare Process Variable
5115     -----------------------------------------------------------------
5116     l_api_version          CONSTANT NUMBER         := 1;
5117     l_api_name             CONSTANT VARCHAR2(30)   := 'populate_ar_sources';
5118     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
5119     -----------------------------------------------------------------
5120     -- Local Variables
5121     -----------------------------------------------------------------
5122     l_khr_id               NUMBER;
5123     l_try_id               NUMBER;
5124     l_kle_id               NUMBER;
5125     l_sty_id               NUMBER;
5126     l_ledger_id            NUMBER;
5127     l_ledger_language      VARCHAR2(12);
5128     l_header_source_id     NUMBER;
5129     l_header_source_table  VARCHAR2(30);
5130     l_template_id          NUMBER;
5131     l_source_id            NUMBER;
5132     l_source_table         VARCHAR2(30);
5133     l_header_extension_id  NUMBER;
5134     l_pk_attributes        VARCHAR2(1000);
5135     l_tcn_id               NUMBER;
5136     l_line_style           VARCHAR2(30);
5137     l_parent_line_id       NUMBER;
5138     -- KHR and KLE Based Record Structures
5139     l_khr_source_rec       khr_source_rec_type;
5140     l_kle_source_rec       kle_source_rec_type;
5141     -- Record structures based on the Cursor Definitions
5142     l_termination_qte_csr_rec   c_termination_qte_csr%ROWTYPE;
5143     -- Record Structures based on OKL AR Extension Header and Line Tables
5144     -- Start : PRASJAIN : Bug# 6268782
5145     l_rxh_rec              rxh_rec_type;
5146     lx_rxh_rec             rxh_rec_type;
5147     l_rxhl_tbl             rxhl_tbl_type;
5148     lx_rxhl_tbl            rxhl_tbl_type;
5149     l_rxl_rec              rxl_rec_type;
5150     lx_rxl_rec             rxl_rec_type;
5151     l_rxll_tbl             rxll_tbl_type;
5152     lx_rxll_tbl            rxll_tbl_type;
5153     l_led_lang_tbl         led_lang_tbl_type;
5154     -- End : PRASJAIN : Bug# 6268782
5155     l_ledger_lang_rec      c_ledger_lang_csr%ROWTYPE;
5156     -- Local Variables for enabling the Debug Statements
5157     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
5158     l_debug_enabled       VARCHAR2(10);
5159     is_debug_procedure_on BOOLEAN;
5160     is_debug_statement_on BOOLEAN;
5161     tl_sources_in         NUMBER := 1;
5162 
5163 	l_qte_id              NUMBER; -- racheruv 15978873
5164   BEGIN
5165     l_debug_enabled := okl_debug_pub.check_log_enabled;
5166     -- check for logging on PROCEDURE level
5167     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
5168     -- check for logging on STATEMENT level
5169     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
5170     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5171                'begin debug OKLRSLAB.pls call ' || l_api_name);
5172     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5173                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.populate_ar_sources');
5174     l_return_status := OKL_API.G_RET_STS_SUCCESS;
5175     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5176       'Calling OKL_API.START_ACTIVITY');
5177     l_return_status := OKL_API.START_ACTIVITY(
5178                          p_api_name       => l_api_name
5179                         ,p_pkg_name       => g_pkg_name
5180                         ,p_init_msg_list  => p_init_msg_list
5181                         ,l_api_version    => l_api_version
5182                         ,p_api_version    => p_api_version
5183                         ,p_api_type       => '_PVT'
5184                         ,x_return_status  => l_return_status);
5185     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5186       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5187     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5188       RAISE OKL_API.G_EXCEPTION_ERROR;
5189     END IF;
5190     -- Validations to be done
5191     -- Validation 1:
5192     --   The following attributes should not be NULL
5193     --    hdr.source_id, hdr.source_table, khr_id, try_id
5194     --    line.source_id, line.source_table
5195     -- Bug 6328168: sty_id is made optional as for On-Account Credit Memo
5196     --                its not mandatory at all
5197     l_pk_attributes := NULL;
5198     IF p_rxhv_rec.source_id IS NULL OR
5199        p_rxhv_rec.source_id = OKL_API.G_MISS_NUM
5200     THEN
5201       IF l_pk_attributes IS NOT NULL
5202       THEN
5203         l_pk_attributes := l_pk_attributes || ' , ';
5204       END IF;
5205       l_pk_attributes := l_pk_attributes || 'RXH.SOURCE_ID';
5206     END IF;
5207     IF p_rxhv_rec.source_table IS NULL OR
5208        p_rxhv_rec.source_table = OKL_API.G_MISS_CHAR
5209     THEN
5210       IF l_pk_attributes IS NOT NULL
5211       THEN
5212         l_pk_attributes := l_pk_attributes || ' , ';
5213       END IF;
5214       l_pk_attributes := l_pk_attributes || 'RXH.SOURCE_TABLE';
5215     END IF;
5216     IF p_rxhv_rec.khr_id IS NULL OR
5217        p_rxhv_rec.khr_id = OKL_API.G_MISS_NUM
5218     THEN
5219       IF l_pk_attributes IS NOT NULL
5220       THEN
5221         l_pk_attributes := l_pk_attributes || ' , ';
5222       END IF;
5223       l_pk_attributes := l_pk_attributes || 'KHR_ID';
5224     END IF;
5225     IF p_rxhv_rec.try_id IS NULL OR
5226        p_rxhv_rec.try_id = OKL_API.G_MISS_NUM
5227     THEN
5228       IF l_pk_attributes IS NOT NULL
5229       THEN
5230         l_pk_attributes := l_pk_attributes || ' , ';
5231       END IF;
5232       l_pk_attributes := l_pk_attributes || 'TRY_ID';
5233     END IF;
5234     -- For few Transactions kle_id is not mandatory at all ..
5235     -- hence knocking off kle_id as the mandatory parameter
5236     IF p_rxlv_rec.source_id IS NULL OR
5237        p_rxlv_rec.source_id = OKL_API.G_MISS_NUM
5238     THEN
5239       IF l_pk_attributes IS NOT NULL
5240       THEN
5241         l_pk_attributes := l_pk_attributes || ' , ';
5242       END IF;
5243       l_pk_attributes := l_pk_attributes || 'RXL.SOURCE_ID';
5244     END IF;
5245     IF p_rxlv_rec.source_table IS NULL OR
5246        p_rxlv_rec.source_table = OKL_API.G_MISS_CHAR
5247     THEN
5248       IF l_pk_attributes IS NOT NULL
5249       THEN
5250         l_pk_attributes := l_pk_attributes || ' , ';
5251       END IF;
5252       l_pk_attributes := l_pk_attributes || 'RXL.SOURCE_TABLE';
5253     END IF;
5254     IF LENGTH(l_pk_attributes) > 0
5255     THEN
5256       -- Raise an Exception
5257       OKL_API.set_message(
5258          p_app_name      => G_APP_NAME
5259         ,p_msg_name      => G_INVALID_VALUE
5260         ,p_token1        => G_COL_NAME_TOKEN
5261         ,p_token1_value  => l_pk_attributes);
5262       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5263       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5264     END IF;
5265     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5266       'Validation 1 Successfull !');
5267     -- Validation 2:
5268     --   Source Table should be OKL_TXD_AR_LN_DTLS_B/OKL_TXL_ADJSTS_LNS_B
5269     -- Comparing with the Upper(Source_table) as billing is passing the value in the
5270     --  lower cases currently, need to knock this upper once billing passes it correctly
5271     IF UPPER(p_rxlv_rec.source_table) NOT IN ( G_TXD_AR_LN_DTLS_B, G_TXL_ADJSTS_LNS_B )
5272     THEN
5273       -- Raise an Exception
5274       OKL_API.set_message(
5275          p_app_name      => G_APP_NAME
5276         ,p_msg_name      => G_INVALID_VALUE
5277         ,p_token1        => G_COL_NAME_TOKEN
5278         ,p_token1_value  => 'SOURCE_TABLE');
5279       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5280       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5281     END IF;
5282     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5283       'Validation 2 Successfull !');
5284     -- Copy input rec to local variable
5285     -- Start : PRASJAIN : Bug# 6268782
5286     l_rxh_rec.source_id    := p_rxhv_rec.source_id;
5287     l_rxh_rec.source_table := p_rxhv_rec.source_table;
5288     l_rxh_rec.khr_id       := p_rxhv_rec.khr_id;
5289     l_rxh_rec.try_id       := p_rxhv_rec.try_id;
5290 
5291     l_rxl_rec.kle_id       := p_rxlv_rec.kle_id;
5292     l_rxl_rec.sty_id       := p_rxlv_rec.sty_id;
5293     l_rxl_rec.source_id    := p_rxlv_rec.source_id;
5294     l_rxl_rec.source_table := p_rxlv_rec.source_table;
5295     -- End : PRASJAIN : Bug# 6268782
5296     -- Make sure that the source_tables are in upper case
5297     l_rxh_rec.source_table := UPPER(l_rxh_rec.source_table);
5298     l_rxl_rec.source_table := UPPER(l_rxl_rec.source_table);
5299     -- Copy the input parameters to the local variables
5300     l_header_source_id    := l_rxh_rec.source_id;
5301     l_header_source_table := l_rxh_rec.source_table;
5302     l_khr_id              := l_rxh_rec.khr_id;
5303     l_try_id              := l_rxh_rec.try_id;
5304     l_source_id           := l_rxl_rec.source_id;
5305     l_source_table        := l_rxl_rec.source_table;
5306     l_kle_id              := l_rxl_rec.kle_id;  -- For Subsidy this is will be a SUBSIDY Line but not the Asset
5307     l_sty_id              := l_rxl_rec.sty_id;
5308 
5309     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5310       '**** KLE_ID = ' || l_kle_id );
5311     IF l_kle_id IS NOT NULL OR l_kle_id <> OKL_API.G_MISS_NUM
5312     THEN
5313       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5314         'Executing the Cursor get_line_style_csr kle_id=' || l_rxl_rec.kle_id );
5315       FOR t_rec IN get_line_style_csr(p_kle_id => l_rxl_rec.kle_id )
5316       LOOP
5317         l_line_style       := t_rec.line_style;
5318         IF l_line_style = 'SUBSIDY'
5319         THEN
5320           l_parent_line_id := t_rec.parent_line_id;
5321         END IF;
5322       END LOOP;
5323       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5324         '**** LINE STYLE = ' || l_line_style || ' PARENT LINE ID = ' || l_parent_line_id );
5325     END IF; -- IF l_kle_id IS NOT NULL OR l_kle_id <> OKL_API.G_MISS_NUM
5326 
5327     -- Fetch ledger id and ledger language associated to the contracts
5328     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5329       'Executing the Cursor c_khr_to_ledger_id_csr. p_khr_id=' || TO_CHAR(l_khr_id));
5330     FOR t_rec IN c_khr_to_ledger_id_csr( p_khr_id => l_khr_id )
5331     LOOP
5332       l_ledger_id := t_rec.ledger_id;
5333     END LOOP;
5334 
5335     -- Fetch the ledger language in order to populate the sources
5336     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5337       'Executing the Cursor c_ledger_lang_csr. p_ledger_id=' || TO_CHAR(l_ledger_id));
5338     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_ledger_id )
5339     LOOP
5340       l_ledger_lang_rec := t_rec;
5341       -- Start : PRASJAIN : Bug# 6268782
5342       l_led_lang_tbl(tl_sources_in).language := t_rec.language_code;
5343       l_rxll_tbl(tl_sources_in).language     := t_rec.language_code;
5344       tl_sources_in := tl_sources_in + 1;
5345       -- End : PRASJAIN : Bug# 6268782
5346     END LOOP;
5347 
5348     -- Logic Description:
5349     --   1. The OKL AR Extension Header _B/_TL sources will be captured only once
5350     --       for a KHR_ID.
5351     --   2. For every AR Transaction Line, there will be a single record in the
5352     --       OKL AR Extension Line _B/_TL
5353     --  For Eg., if a Transaction is having 10 transaction lines with two different khr_id1, khr_id2
5354     --  there will be only two records in the Header but 10 transaction lines in Extension Line.
5355     --  Hence, for every Transaction Line check whether the KHR Sources have been captured
5356     --  already or not by passing the Transaction ID and KHR_ID
5357     -- Fetch header extension id
5358     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5359       'Executing the Cursor c_header_extension_id_csr.
5360          p_header_source_id=' || TO_CHAR(l_header_source_id)
5361         || ' p_header_source_table=' || l_header_source_table
5362         || ' p_khr_id= ' || TO_CHAR(l_khr_id));
5363     l_header_extension_id := NULL;
5364     FOR t_rec IN c_header_extension_id_csr(
5365                           p_header_source_id    => l_header_source_id
5366                          ,p_header_source_table => l_header_source_table
5367                          ,p_khr_id              => l_khr_id )
5368     LOOP
5369       l_header_extension_id := t_rec.header_extension_id;
5370     END LOOP; -- End for c_header_extension_id_csr
5371 
5372     -- If l_header_extension_id is NOT NULL, then it means the KHR sources are already captured
5373     --   So, populate extension line sources only.
5374     -- Else Populate both the Extension Header and Line Sources.
5375     IF l_header_extension_id IS NULL
5376     THEN
5377       -- Prepare khr_source_rec_type with khr_id and ledger_language
5378       l_khr_source_rec.khr_id            := l_khr_id;
5379       -- Calling populate_khr_sources to fetch the KHR Sources
5380       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5381         'Calling the populate_khr_sources' );
5382       populate_khr_sources(     -- Change : PRASJAIN : Bug# 6268782
5383          p_api_version      => l_api_version
5384         ,p_init_msg_list    => p_init_msg_list
5385         ,x_khr_source_rec   => l_khr_source_rec
5386         ,x_led_lang_tbl     => l_led_lang_tbl
5387         ,x_return_status    => l_return_status
5388         ,x_msg_count        => x_msg_count
5389         ,x_msg_data         => x_msg_data );
5390       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5391         'After populate_khr_sources: l_return_status ' || l_return_status );
5392       -- Check the return status and if errored, return the error back
5393       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5394         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5395       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5396         RAISE OKL_API.G_EXCEPTION_ERROR;
5397       END IF;
5398       -- Assign the KHR Sources to the rxhv_rec
5399       assign_khr_rec_to_rxh_rec(
5400          p_khr_source_rec => l_khr_source_rec
5401         ,x_rxh_rec => l_rxh_rec );
5402 
5403       -- Start : PRASJAIN : Bug# 6268782
5404       FOR tl_sources_in IN l_led_lang_tbl.FIRST .. l_led_lang_tbl.LAST
5405       LOOP
5406         l_rxhl_tbl(tl_sources_in).language          := l_led_lang_tbl(tl_sources_in).language;
5407         l_rxhl_tbl(tl_sources_in).contract_status   := l_led_lang_tbl(tl_sources_in).contract_status;
5408         l_rxhl_tbl(tl_sources_in).inv_agrmnt_status := l_led_lang_tbl(tl_sources_in).inv_agrmnt_status;
5409 
5410         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5411           'Executing the Cursor c_trx_type_name_csr. p_try_id=' ||
5412           l_try_id || 'p_led_lang= ' || l_rxhl_tbl(tl_sources_in).language );
5413         FOR t_rec IN c_trx_type_name_csr(
5414                       p_try_id    => l_try_id
5415                      ,p_led_lang  => l_rxhl_tbl(tl_sources_in).language ) -- Change : PRASJAIN : Bug# 6268782
5416         LOOP
5417           l_rxhl_tbl(tl_sources_in).transaction_type_name := t_rec.transaction_type_name;-- Change : PRASJAIN : Bug# 6268782
5418           -- Assign the Trx. Type Class Code also.
5419           l_rxh_rec.trx_type_class_code  := t_rec.trx_type_class_code;
5420         END LOOP; -- End for c_trx_type_name_csr
5421       END LOOP;
5422       -- End : PRASJAIN : Bug# 6268782
5423 
5424 
5425       -- Fetch the Transaction Number
5426       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5427         'Executing the Cursor c_trans_number_csr. p_header_source_id=' || l_header_source_id );
5428       FOR t_rec IN c_trans_number_csr( p_header_source_id => l_header_source_id )
5429       LOOP
5430         l_rxh_rec.trans_number  := t_rec.trans_number;
5431         --l_tcn_id                := t_rec.tai_tcn_id; -- racheruv 15978873
5432 		l_qte_id                := t_rec.qte_id; -- racheruv 15978873
5433       END LOOP; -- End for c_trans_number_csr
5434 
5435 	  /* racheruv 15978873
5436       -- Fetch the Transaction Number
5437       --put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5438         --'Executing the Cursor get_tai_tcn_qte_id_csr. p_tcn_id=' || l_tcn_id );
5439       --FOR t_rec IN get_tai_tcn_qte_id_csr(p_tcn_id => l_tcn_id )
5440       --LOOP
5441         --put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5442           --'Executing the Cursor c_termination_qte_csr. l_qte_id=' || t_rec.qte_id );
5443 		  */ -- racheruv
5444         -- Cursor to fetch termination quote attr
5445         FOR l_termination_qte_csr_rec IN  c_termination_qte_csr (l_qte_id => l_qte_id)
5446         LOOP
5447           l_rxh_rec.term_quote_accept_date := l_termination_qte_csr_rec.date_effective_from;
5448           l_rxh_rec.term_quote_num         := l_termination_qte_csr_rec.quote_number;
5449           l_rxh_rec.term_quote_type_code   := l_termination_qte_csr_rec.qtp_code;
5450         END LOOP;  -- c_termination_qte_csr
5451       --END LOOP; -- racheruv 15978873
5452 
5453       IF(p_acc_sources_rec.jtf_sales_reps_pk IS NOT NULL AND
5454          p_acc_sources_rec.jtf_sales_reps_pk <> OKL_API.G_MISS_CHAR) THEN
5455          -- Need to populate the Sales Representative Name
5456          put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5457            'Executing the Cursor  c_sales_rep_acc_sources_csr. l_sales_rep_id = ' ||
5458              TO_CHAR(p_acc_sources_rec.jtf_sales_reps_pk) );
5459          FOR t_rec IN  c_sales_rep_acc_sources_csr (p_jtf_sales_rep_pk => p_acc_sources_rec.jtf_sales_reps_pk)
5460          LOOP
5461            l_rxh_rec.sales_rep_name := t_rec.name;
5462 
5463          END LOOP;  -- c_sales_rep_acc_sources_csr
5464       END IF;
5465 
5466       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5467         'Calling the okl_ar_extension_pvt.create_rxh_extension ' || l_rxh_rec.source_id );
5468       okl_ar_extension_pvt.create_rxh_extension(      -- Change : PRASJAIN : Bug# 6268782
5469          p_api_version     => l_api_version
5470         ,p_init_msg_list   => p_init_msg_list
5471         ,x_return_status   => l_return_status
5472         ,x_msg_count       => x_msg_count
5473         ,x_msg_data        => x_msg_data
5474         ,p_rxh_rec         => l_rxh_rec
5475         ,p_rxhl_tbl        => l_rxhl_tbl
5476         ,x_rxh_rec         => lx_rxh_rec
5477         ,x_rxhl_tbl        => lx_rxhl_tbl
5478       );
5479       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5480         'After okl_ar_extension_pvt.create_rxh_extension: l_return_status ' || l_return_status );
5481       -- Check the return status and if errored, return the error back
5482       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5483         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5484       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5485         RAISE OKL_API.G_EXCEPTION_ERROR;
5486       END IF;
5487       -- Store the Header Extension ID into the Local Variable l_header_extension_id
5488       l_header_extension_id := lx_rxh_rec.header_extension_id;
5489     END IF;
5490     IF l_kle_id IS NOT NULL AND
5491        l_kle_id <> OKL_API.G_MISS_NUM
5492     THEN
5493       -- Start populating the Sources at the Extension Line Level
5494       -- Prepare kle_source_rec_type with khr_id, kle_id and ledger_language
5495       l_kle_source_rec.khr_id            := l_khr_id;
5496       l_kle_source_rec.kle_id            := l_kle_id;
5497       IF l_line_style = 'SUBSIDY'
5498       THEN
5499         -- If the Line Style is SUBSIDY, then pass the Asset line id to the
5500         --  Populate KLE Sources to fetch the Asset Details
5501         l_kle_source_rec.kle_id            := l_parent_line_id;
5502       END IF;
5503       -- Calling populate_kle_sources only when kle_id is not NULL or G_MISS_NUM
5504       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5505         'Before Calling the populate_kle_sources' );
5506       populate_kle_sources(
5507         p_api_version      => l_api_version
5508        ,p_init_msg_list    => p_init_msg_list
5509        ,x_kle_source_rec   => l_kle_source_rec
5510        ,x_return_status    => l_return_status
5511        ,x_msg_count        => x_msg_count
5512        ,x_msg_data         => x_msg_data );
5513       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5514         'After populate_kle_sources: l_return_status ' || l_return_status );
5515       -- Check the return status and if errored, return the error back
5516       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5517         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5518       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5519         RAISE OKL_API.G_EXCEPTION_ERROR;
5520       END IF;
5521       -- calling assign_kle_rec_to_rxlv_rec
5522       assign_kle_rec_to_rxl_rec(
5523          p_kle_source_rec => l_kle_source_rec
5524          ,x_rxl_rec => l_rxl_rec );
5525       -- Fetch fee type code
5526       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5527         'Executing the curosr c_k_lines_csr. p_kle_id= ' || TO_CHAR(l_kle_id));
5528       FOR t_rec  IN c_k_lines_csr ( p_kle_id => l_kle_id )
5529       LOOP
5530         l_rxl_rec.fee_type_code := t_rec.fee_type;
5531       END LOOP;  -- End for c_k_lines_csr
5532 
5533       -- Fetch asset category name
5534       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5535         'Executing the curosr c_manufacture_model_csr. p_kle_id= ' || TO_CHAR(l_kle_id)
5536         || ' p_khr_id= ' || TO_CHAR(l_khr_id));
5537       FOR t_rec  IN c_manufacture_model_csr ( p_kle_id => l_kle_id, p_khr_id => l_khr_id )
5538       LOOP
5539         l_rxl_rec.asset_category_name := t_rec.asset_category_name;
5540       END LOOP;  -- End for c_manufacture_model_csr
5541 
5542       FOR tl_sources_in IN l_rxll_tbl.FIRST .. l_rxll_tbl.LAST
5543       LOOP
5544         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5545           'Executing the Cursor c_inventory_item_name_csr. p_inventory_item_id_pk1= ' ||
5546           to_char(p_acc_sources_rec.inventory_item_id_pk1) || ' p_inventory_org_id_pk2=' ||
5547           to_char(p_acc_sources_rec.inventory_org_id_pk2) || ' ledger_language=' ||
5548           l_rxll_tbl(tl_sources_in).language );
5549         FOR t_rec IN c_inventory_item_name_csr(
5550                      p_inventory_item_id_pk1 => p_acc_sources_rec.inventory_item_id_pk1
5551                     ,p_inventory_org_id_pk2  => p_acc_sources_rec.inventory_org_id_pk2
5552                     ,p_ledger_language       => l_rxll_tbl(tl_sources_in).language)
5553         LOOP
5554           l_rxll_tbl(tl_sources_in).inventory_item_name      := t_rec.description;
5555           l_rxl_rec.inventory_item_name_code := t_rec.b_description;
5556         END LOOP;
5557       END LOOP;
5558       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5559         'Fetching the Subsidy Sources LINE_STYLE =' || l_line_style );
5560       IF l_line_style = 'SUBSIDY'
5561       THEN
5562         -- Fetch Subsidy Name and Subsidy Party Name
5563         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5564           'Executing the curosr get_subsidy_details_csr. p_kle_id= ' || TO_CHAR(l_kle_id));
5565         FOR t_rec  IN get_subsidy_details_csr ( p_kle_id => l_kle_id )
5566         LOOP
5567           l_rxl_rec.subsidy_name       := t_rec.subsidy_name;
5568           l_rxl_rec.subsidy_party_name := t_rec.subsidy_party_name;
5569           -- added by zrehman Bug#6707320 for Party Merge impact on Transaction sources tables start
5570 	  l_rxl_rec.subsidy_vendor_id := t_rec.subsidy_vendor_id;
5571           -- added by zrehman Bug#6707320 for Party Merge impact on Transaction sources tables end
5572         END LOOP;  -- End for c_k_lines_csr
5573       END IF;
5574     --ELSE
5575       -- Populate the l_pxlv_rec with the khr_id, ledger_language
5576       -- but not with the kle_id
5577       -- l_rxl_rec.language := l_ledger_language ;
5578     END IF; -- IF l_kle_id IS NOT NULL OR l_kle_id <> OKL_API.G_MISS_NUM
5579 
5580     -- Stamp the Header Extension ID on the Extension Line Table
5581     l_rxl_rec.header_extension_id := l_header_extension_id;
5582 
5583     -- Fetch the Account Template ID
5584     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5585       'Executing the curosr c_account_dist_csr. p_source_id= ' || to_char(l_source_id)
5586       || ' p_source_table= ' || to_char(l_source_table));
5587     FOR t_rec  IN c_account_dist_csr (
5588                     p_source_id    => l_source_id
5589                    ,p_source_table => l_source_table)
5590     LOOP
5591       l_template_id := t_rec.template_id;
5592     END LOOP;  -- End for c_account_dist_csr
5593 
5594     -- Assigning the Memo Indicator to the Extension Line Record structure ..
5595     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5596       '** AGS Memo Flag ' || p_acc_sources_rec.memo_yn );
5597     l_rxl_rec.memo_flag := p_acc_sources_rec.memo_yn;
5598 
5599     -- Fetch Memo Flag and Accounting Template Name using the template_id
5600     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5601       'Executing the curosr c_ae_templates_csr. template_id= ' || to_char(l_template_id) );
5602     FOR t_rec  IN c_ae_templates_csr (p_template_id => l_template_id)
5603     LOOP
5604       l_rxl_rec.accounting_template_name := t_rec.name;
5605     END LOOP;  -- End for c_ae_templates_csr
5606 
5607     -- Bug 6328168: STY_ID is Optional
5608     IF l_sty_id IS NOT NULL
5609     THEN
5610       -- Fetch contingency code and stream type name
5611       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5612         'Executing the curosr c_contingency_strm_b_csr. p_sty_id= ' || TO_CHAR(l_sty_id)
5613         || ' Ledger Language = ' || l_ledger_language);
5614       FOR t_rec  IN c_contingency_strm_b_csr ( p_sty_id => l_sty_id )
5615       LOOP
5616         l_rxl_rec.contingency_code         := t_rec.contingency_code;
5617         l_rxl_rec.stream_type_code         := t_rec.stream_type_code;
5618         l_rxl_rec.stream_type_purpose_code := t_rec.stream_type_purpose;
5619       END LOOP;  -- End for c_contingency_strm_b_csr
5620     END IF; -- IF l_sty_id IS NOT NULL
5621 
5622     -- Fetch contingency code and stream type name
5623     FOR tl_sources_in IN l_rxll_tbl.FIRST .. l_rxll_tbl.LAST
5624     LOOP
5625       -- Bug 6328168: STY_ID is Optional
5626       IF l_sty_id IS NOT NULL
5627       THEN
5628         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5629           'Executing the curosr c_strm_name_tl_csr. p_sty_id= ' || TO_CHAR(l_sty_id)
5630           || ' Ledger Language = ' || l_rxll_tbl(tl_sources_in).language);
5631         FOR t_rec  IN c_strm_name_tl_csr ( p_sty_id => l_sty_id, p_lang => l_rxll_tbl(tl_sources_in).language )
5632         LOOP
5633           l_rxll_tbl(tl_sources_in).stream_type_name := t_rec.stream_type_name;
5634         END LOOP;  -- End for c_strm_name_tl_csr
5635       END IF; --  IF l_sty_id IS NOT NULL
5636       -- Unable to find the corresponding Transaction Line Description Column in okl_txl_adjsts_lns_all_tl Table
5637       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5638         'Executing the curosr c_tld_line_description. p_tld_tl_id= ' || TO_CHAR(l_source_id)
5639         || ' p_lang = ' || l_rxll_tbl(tl_sources_in).language);
5640       FOR t_rec IN c_tld_line_description (
5641                      p_tld_tl_id => l_source_id
5642                     ,p_lang      => l_rxll_tbl(tl_sources_in).language )
5643       LOOP
5644         l_rxll_tbl(tl_sources_in).trans_line_description := t_rec.trans_line_description;
5645       END LOOP;
5646     END LOOP; -- Loop on l_rxll_tbl
5647 
5648     IF(p_acc_sources_rec.inventory_org_id_pk2 IS NOT NULL AND
5649        p_acc_sources_rec.inventory_org_id_pk2 <> OKL_API.G_MISS_CHAR) THEN
5650        -- Populate Inventory Organization Name
5651        put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5652          '*** AGS Inventory Org ID used to fetch teh Inventory Organization Code : Org ID=' ||
5653          p_acc_sources_rec.inventory_org_id_pk2 );
5654        put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5655          'Executing the Cursor c_org_name_code_csr. p_org_id= ' || TO_CHAR(p_acc_sources_rec.inventory_org_id_pk2) );
5656        FOR t_rec IN c_org_name_code_csr(
5657                        p_org_id      => p_acc_sources_rec.inventory_org_id_pk2 )
5658        LOOP
5659          l_rxl_rec.inventory_org_code := t_rec.org_name;
5660        END LOOP;
5661 
5662        FOR tl_sources_in IN l_rxll_tbl.FIRST .. l_rxll_tbl.LAST
5663        LOOP
5664          put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5665            'Executing the Cursor c_org_name_csr. p_org_id= ' || TO_CHAR(p_acc_sources_rec.inventory_org_id_pk2) ||
5666            ' ledger_language=' || l_rxll_tbl(tl_sources_in).language );
5667          FOR t_rec IN c_org_name_csr(
5668                          p_org_id      => p_acc_sources_rec.inventory_org_id_pk2
5669                         ,p_ledger_lang => l_rxll_tbl(tl_sources_in).language )
5670          LOOP
5671            l_rxll_tbl(tl_sources_in).inventory_org_name := t_rec.org_name;
5672          END LOOP;
5673        END LOOP;
5674     END IF;
5675 
5676     -- Calling insert_row
5677     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5678       'Calling the okl_ar_extension_pvt.create_rxl_extension source_id=' || l_rxl_rec.source_id );
5679     okl_ar_extension_pvt.create_rxl_extension(
5680        p_api_version     => l_api_version
5681       ,p_init_msg_list   => p_init_msg_list
5682       ,x_return_status   => l_return_status
5683       ,x_msg_count       => x_msg_count
5684       ,x_msg_data        => x_msg_data
5685       ,p_rxl_rec         => l_rxl_rec
5686       ,p_rxll_tbl        => l_rxll_tbl
5687       ,x_rxl_rec         => lx_rxl_rec
5688       ,x_rxll_tbl        => lx_rxll_tbl
5689      );
5690     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5691       'After okl_ar_extension_pvt.create_rxl_extension: l_return_status ' || l_return_status );
5692     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5693       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5694     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5695       RAISE OKL_API.G_EXCEPTION_ERROR;
5696     END IF;
5697     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5698       'Calling okl_api.end_activity');
5699     okl_api.end_activity(
5700        x_msg_count => x_msg_count
5701       ,x_msg_data  => x_msg_data);
5702     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5703       'END OKL_SLA_ACC_SOURCES_PVT.populate_ar_sources');
5704     x_return_status := OKL_API.G_RET_STS_SUCCESS;
5705   EXCEPTION
5706     ------------------------------------------------------------
5707     -- Exception handling
5708     ------------------------------------------------------------
5709     WHEN OKL_API.G_EXCEPTION_ERROR
5710     THEN
5711       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
5712                             p_api_name  => l_api_name
5713                            ,p_pkg_name  => G_PKG_NAME
5714                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
5715                            ,x_msg_count  => x_msg_count
5716                            ,x_msg_data  => x_msg_data
5717                            ,p_api_type  => '_PVT');
5718     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
5719     THEN
5720       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
5721                             p_api_name  => l_api_name
5722                            ,p_pkg_name  => G_PKG_NAME
5723                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
5724                            ,x_msg_count  => x_msg_count
5725                            ,x_msg_data  => x_msg_data
5726                            ,p_api_type  => '_PVT');
5727     WHEN OTHERS
5728     THEN
5729       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
5730                             p_api_name  => l_api_name
5731                            ,p_pkg_name  => G_PKG_NAME
5732                            ,p_exc_name  => 'OTHERS'
5733                            ,x_msg_count  => x_msg_count
5734                            ,x_msg_data  => x_msg_data
5735                            ,p_api_type  => '_PVT');
5736   END populate_ar_sources;
5737 
5738   ------------------------------------------------------------------------------
5739   -- Start of comments
5740   --      API name        : populate_sources
5741   --      Pre-reqs        : None
5742   --      Function        : populate sources for OKL AR Transactions
5743   --      Parameters      :
5744   --      IN              :
5745   --                        rxhv_rec_type.source_id            IN NUMBER    Required
5746   --                        rxhv_rec_type.source_table         IN VARCHAR2  Required
5747   --      History         : Prashant Jain created
5748   --      Version         : 1.0
5749   -- End of comments
5750   ------------------------------------------------------------------------------
5751   PROCEDURE populate_sources(
5752     p_api_version           IN        NUMBER
5753    ,p_init_msg_list         IN        VARCHAR2
5754    ,p_rxhv_rec              IN        rxhv_rec_type
5755    ,p_rxlv_tbl              IN        rxlv_tbl_type
5756    ,p_acc_sources_tbl       IN        asev_tbl_type
5757    ,x_return_status         OUT       NOCOPY  VARCHAR2
5758    ,x_msg_count             OUT       NOCOPY  NUMBER
5759    ,x_msg_data              OUT       NOCOPY  VARCHAR2
5760   )
5761   IS
5762     -- Cursor to fetch source_id, khr_id, kle_id,
5763     -- sty_id, try_id
5764     CURSOR c_trx_ar_inv_lines_csr (p_header_source_id NUMBER)
5765     IS
5766       SELECT    tld.id                 source_id
5767                ,'OKL_TXD_AR_LN_DTLS_B' source_table
5768                ,tld.khr_id             khr_id
5769                ,tld.kle_id             kle_id
5770                ,tld.sty_id             sty_id
5771                ,tai.try_id             try_id
5772        FROM     okl_trx_ar_invoices_b tai
5773                ,okl_txl_ar_inv_lns_b  til
5774                ,okl_txd_ar_ln_dtls_b  tld
5775       WHERE     tld.til_id_details = til.id
5776         AND     til.tai_id = tai.id
5777         AND     tai.id = p_header_source_id;
5778 
5779     -- Cursor to fetch source_id, khr_id, kle_id,
5780     -- sty_id, try_id
5781     CURSOR c_trx_ar_adj_lines_csr (p_header_source_id NUMBER)
5782      IS
5783       SELECT    adjl.id                                 source_id
5784                ,'OKL_TXL_ADJSTS_LNS_B'                  source_table
5785                ,adjl.khr_id                             khr_id
5786                ,adjl.kle_id                             kle_id
5787                ,adjl.sty_id                             sty_id
5788                ,adj.try_id                              try_id
5789        FROM     okl_trx_ar_adjsts_all_b   adj
5790                ,okl_txl_adjsts_lns_all_b  adjl
5791       WHERE     adj.id = adjl.adj_id
5792         AND     adj.id = p_header_source_id;
5793 
5794     -- Data structures based on the Cursor Variables
5795     TYPE c_trx_ar_inv_lines_tbl IS TABLE OF c_trx_ar_inv_lines_csr%ROWTYPE
5796       INDEX BY BINARY_INTEGER;
5797     l_trx_ar_inv_lines_tbl     c_trx_ar_inv_lines_tbl;
5798     TYPE c_trx_ar_adj_lines_tbl IS TABLE OF c_trx_ar_adj_lines_csr%ROWTYPE
5799       INDEX BY BINARY_INTEGER;
5800     l_trx_ar_adj_lines_tbl     c_trx_ar_adj_lines_tbl;
5801     tld_count                  NUMBER; -- Count of the l_trx_ar_inv_lines_tbl
5802     tld_index                  NUMBER; -- Index for the l_trx_ar_inv_lines_tbl
5803     rxl_index                  NUMBER; -- Index for the l_rxlv_tbl
5804     l_acc_srcs_index           NUMBER; -- Index for the p_acc_sources_tbl
5805     l_capture_sources          VARCHAR2(3); -- Flag to decide whether to Capture Sources or Not !
5806     -----------------------------------------------------------------
5807     -- Declare Process Variable
5808     -----------------------------------------------------------------
5809     l_api_version          CONSTANT NUMBER         := 1;
5810     l_api_name             CONSTANT VARCHAR2(30)   := 'POPULATE_SOURCES-AR';
5811     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
5812 
5813     -----------------------------------------------------------------
5814     -- Local Variables
5815     -----------------------------------------------------------------
5816     l_header_source_id            NUMBER;
5817     l_header_source_table         VARCHAR2(30);
5818     l_rxhv_rec                    rxhv_rec_type;
5819     l_rxlv_rec                    rxlv_rec_type;
5820     l_rxlv_tbl                    rxlv_tbl_type;
5821     -- Local Variables for enabling the Debug Statements
5822     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
5823     l_debug_enabled       VARCHAR2(10);
5824     is_debug_procedure_on BOOLEAN;
5825     is_debug_statement_on BOOLEAN;
5826   BEGIN
5827     l_debug_enabled := okl_debug_pub.check_log_enabled;
5828     -- check for logging on PROCEDURE level
5829     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
5830     -- check for logging on STATEMENT level
5831     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
5832     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5833                'begin debug OKLRSLAB.pls call ' || l_api_name);
5834     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5835                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
5836     l_return_status := OKL_API.G_RET_STS_SUCCESS;
5837     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5838       'Calling OKL_API.START_ACTIVITY');
5839     l_return_status := OKL_API.START_ACTIVITY(
5840                          p_api_name       => l_api_name
5841                         ,p_pkg_name       => g_pkg_name
5842                         ,p_init_msg_list  => p_init_msg_list
5843                         ,l_api_version    => l_api_version
5844                         ,p_api_version    => p_api_version
5845                         ,p_api_type       => '_PVT'
5846                         ,x_return_status  => l_return_status);
5847     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
5848       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5849     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
5850       RAISE OKL_API.G_EXCEPTION_ERROR;
5851     END IF;
5852 
5853     -- Validation 1: Source ID and Source Table should not be NULL in the
5854     --   AR Extension Header Record Structure
5855     IF (p_rxhv_rec.source_id      IS NULL OR
5856         p_rxhv_rec.source_table   IS NULL)
5857     THEN
5858       OKL_API.set_message(
5859          p_app_name      => G_APP_NAME
5860         ,p_msg_name      => G_INVALID_VALUE
5861         ,p_token1        => G_COL_NAME_TOKEN
5862         ,p_token1_value  => 'HEADER.SOURCE_ID_TABLE');
5863       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5864       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5865     END IF;
5866     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5867       'Header SOURCE_ID= ' || p_rxhv_rec.source_id || '  SOURCE_TABLE=' || p_rxhv_rec.source_table );
5868     -- Validation 2: The Header Source Table should be either the
5869     --  OKL AR Invoice Trx Header or OKL AR Adjustment Trx. Header table only
5870     --   ie. it should be either OKL_TRX_AR_INVOICES_B or OKL_TRX_AR_ADJSTS_B only
5871     IF UPPER(p_rxhv_rec.source_table) NOT IN ( G_TRX_AR_INVOICES_B, G_TRX_AR_ADJSTS_B)
5872     THEN
5873       OKL_API.set_message(
5874          p_app_name      => G_APP_NAME
5875         ,p_msg_name      => G_INVALID_VALUE
5876         ,p_token1        => G_COL_NAME_TOKEN
5877         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
5878       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5879       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5880     END IF;
5881 
5882     -- Copy to local variables
5883     l_rxhv_rec              := p_rxhv_rec;
5884     l_rxhv_rec.source_table := UPPER(p_rxhv_rec.source_table);
5885     l_header_source_id      := p_rxhv_rec.source_id;
5886     l_header_source_table   := UPPER(p_rxhv_rec.source_table);
5887     l_rxlv_tbl              := p_rxlv_tbl;
5888     -- Validation 3: There should be atleast one Transaction Detail Line
5889     --  for which the Populate AR Sources should be called
5890     IF l_rxlv_tbl.COUNT = 0
5891     THEN
5892       OKL_API.set_message(
5893          p_app_name      => G_APP_NAME
5894         ,p_msg_name      => G_INVALID_VALUE
5895         ,p_token1        => G_COL_NAME_TOKEN
5896         ,p_token1_value  => 'RXLV_TBL.COUNT()');
5897       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5898       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5899     END IF;
5900 
5901     -- Validation 4: p_rxlv_tbl.COUNT should be equal to the p_acc_sources_tbl.COUNT
5902     IF l_rxlv_tbl.COUNT <> p_acc_sources_tbl.COUNT
5903     THEN
5904       OKL_API.set_message(
5905          p_app_name      => G_APP_NAME
5906         ,p_msg_name      => G_INVALID_VALUE
5907         ,p_token1        => G_COL_NAME_TOKEN
5908         ,p_token1_value  => 'P_ACC_SOURCES_TBL.COUNT()');
5909       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5910       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5911     END IF;
5912 
5913     -- Loop on the details for the current transaction header
5914     -- Call the populate_tld_sources
5915     IF l_header_source_table = 'OKL_TRX_AR_INVOICES_B'
5916     THEN
5917       -- As we wanted to store the records in the PL/SQL table starting from 1
5918       -- and after the loop, the tld_index should be nothing but the count of the
5919       -- Transaction Detail Lines fetched ...
5920       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5921         'Executing the Cursor c_trx_ar_inv_lines_csr. p_header_source_id=' ||
5922            TO_CHAR(l_header_source_id));
5923       -- Initialize the tld_count to ZERO
5924       tld_count  := 0;
5925       FOR t_rec IN c_trx_ar_inv_lines_csr( p_header_source_id => l_header_source_id )
5926       LOOP
5927         -- Increment the tld_count
5928         tld_count := tld_count + 1;
5929         -- Store the Current Record in the PL/SQL Table for further usage
5930         l_trx_ar_inv_lines_tbl(tld_count) := t_rec;
5931       END LOOP;
5932       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5933         'Number of Transaction Detail Lines present in DB     = ' || TO_CHAR(tld_count) );
5934       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5935         'Number of Transaction Detail Lines passed to the API = ' || TO_CHAR(l_rxlv_tbl.COUNT) );
5936       FOR tld_index IN l_trx_ar_inv_lines_tbl.FIRST .. l_trx_ar_inv_lines_tbl.LAST
5937       LOOP
5938         -- Logic Explanation:
5939         -- 1. Check for the Count of the Trx. Detail Lines fetched from DB
5940         -- 2. Compare this count with the count of Trx. Detail Lines passed to this API
5941         -- 3. If the count is same, then, capture sources for every Trx. Detail Line
5942         --    otherwise, capture sources for only those transaction detail line, which have
5943         --    been passed by the Accounting Engine
5944         l_capture_sources := 'N';
5945         l_acc_srcs_index  := NULL;
5946         rxl_index := l_rxlv_tbl.FIRST;
5947         LOOP
5948           IF l_rxlv_tbl(rxl_index).source_id    = l_trx_ar_inv_lines_tbl(tld_index).source_id AND
5949              l_rxlv_tbl(rxl_index).source_table = l_trx_ar_inv_lines_tbl(tld_index).source_table
5950           THEN
5951             -- Need to the Call the Populate AR Sources for this Transaction Detail Line
5952             l_capture_sources := 'Y';
5953             -- Assumption: p_rxlv_tbl and p_acc_sources_tbl are populated using the Same Index.
5954             l_acc_srcs_index  := rxl_index;
5955             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
5956               'Case 2: Populate Sources has been asked to capture sources for the Current Transaction Detail by Accounting Engine ' ||
5957               ' TXD ID = ' || TO_CHAR( l_trx_ar_inv_lines_tbl(tld_index).source_id ) );
5958           END IF;
5959           -- Exit when this is the Last Record or the Transaction Details has been found
5960           EXIT WHEN ( rxl_index = l_rxlv_tbl.LAST )  -- When reached End of the Table
5961                  OR ( l_capture_sources = 'Y'     ); -- Or When the TXD has been found
5962           -- Increment the rxl_index
5963           rxl_index := l_rxlv_tbl.NEXT( rxl_index );
5964         END LOOP; -- Loop on l_rxlv_tbl ..
5965 
5966         IF l_capture_sources = 'Y'
5967         THEN
5968           -- If the AGS Index is not found then return error
5969           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5970             'Account Generator Sources Index =' || TO_CHAR(l_acc_srcs_index)  );
5971           IF l_acc_srcs_index IS NULL OR
5972              ( p_acc_sources_tbl.EXISTS(l_acc_srcs_index) = FALSE )
5973           THEN
5974             -- accounting_event_class_code is missing
5975             OKL_API.set_message(
5976                p_app_name      => G_APP_NAME
5977               ,p_msg_name      => G_INVALID_VALUE
5978               ,p_token1        => G_COL_NAME_TOKEN
5979               ,p_token1_value  => 'AGS_SOURCES_INDEX');
5980             l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
5981             RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
5982           END IF; -- IF l_acc_sources_found = FALSE
5983 
5984           -- l_rxhv_rec.source_id and l_rxhv_rec.source_table are already assigned
5985           l_rxhv_rec.khr_id    := l_trx_ar_inv_lines_tbl(tld_index).khr_id;
5986           l_rxhv_rec.try_id    := l_trx_ar_inv_lines_tbl(tld_index).try_id;
5987           -- Id of Detail Line Table
5988           l_rxlv_rec.source_id := l_trx_ar_inv_lines_tbl(tld_index).source_id;
5989           l_rxlv_rec.source_table := l_trx_ar_inv_lines_tbl(tld_index).source_table;
5990           l_rxlv_rec.kle_id    := l_trx_ar_inv_lines_tbl(tld_index).kle_id;
5991           l_rxlv_rec.sty_id    := l_trx_ar_inv_lines_tbl(tld_index).sty_id;
5992           -- The populate_tld_sources will capture sources at extension line level always
5993           -- If the extension header sources with the l_rxlv_rec.source_id and l_rxhv_rec.khr_id is not captured
5994           -- Then only capture the extension header sources
5995           -- Calling populate_tld_sources
5996           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
5997             'Calling the populate_ar_sources' );
5998           populate_ar_sources(
5999             p_api_version       => l_api_version
6000            ,p_init_msg_list     => p_init_msg_list
6001            ,p_rxhv_rec          => l_rxhv_rec
6002            ,p_rxlv_rec          => l_rxlv_rec
6003            ,p_acc_sources_rec   => p_acc_sources_tbl(l_acc_srcs_index)
6004            ,x_return_status     => l_return_status
6005            ,x_msg_count         => x_msg_count
6006            ,x_msg_data          => x_msg_data);
6007           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6008             'After populate_ar_sources: l_return_status ' || l_return_status );
6009           -- Check the return status and if errored, return the error back
6010           IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6011             RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6012           ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6013             RAISE OKL_API.G_EXCEPTION_ERROR;
6014           END IF;
6015         END IF; -- IF l_capture_sources = 'Y'
6016       END LOOP; -- Loop on l_trx_ar_inv_lines_tbl ..
6017     ELSE
6018       -- As we wanted to store the records in the PL/SQL table starting from 1
6019       -- and after the loop, the tld_index should be nothing but the count of the
6020       -- Transaction Detail Lines fetched ...
6021       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6022         'Executing the Cursor c_trx_ar_adj_lines_csr. p_header_source_id=' ||
6023            TO_CHAR(l_header_source_id));
6024       -- Initialize the tld_count to ZERO
6025       tld_count  := 0;
6026       FOR t_rec IN c_trx_ar_adj_lines_csr( p_header_source_id => l_header_source_id )
6027       LOOP
6028         -- Increment the tld_count
6029         tld_count := tld_count + 1;
6030         -- Store the Current Record in the PL/SQL Table for further usage
6031         l_trx_ar_adj_lines_tbl(tld_count) := t_rec;
6032       END LOOP;
6033       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6034         'Number of Transaction Detail Lines present in DB     = ' || TO_CHAR(tld_count) );
6035       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6036         'Number of Transaction Detail Lines passed to the API = ' || TO_CHAR(l_rxlv_tbl.COUNT) );
6037       FOR tld_index IN l_trx_ar_adj_lines_tbl.FIRST .. l_trx_ar_adj_lines_tbl.LAST
6038       LOOP
6039         -- Logic Explanation:
6040         -- 1. Check for the Count of the Trx. Detail Lines fetched from DB
6041         -- 2. Compare this count with the count of Trx. Detail Lines passed to this API
6042         -- 3. If the count is same, then, capture sources for every Trx. Detail Line
6043         --    otherwise, capture sources for only those transaction detail line, which have
6044         --    been passed by the Accounting Engine
6045         l_capture_sources := 'N';
6046         l_acc_srcs_index  := NULL;
6047         rxl_index := l_rxlv_tbl.FIRST;
6048         LOOP
6049           IF l_rxlv_tbl(rxl_index).source_id    = l_trx_ar_adj_lines_tbl(tld_index).source_id AND
6050              l_rxlv_tbl(rxl_index).source_table = l_trx_ar_adj_lines_tbl(tld_index).source_table
6051           THEN
6052             -- Need to the Call the Populate AR Sources for this Transaction Detail Line
6053             l_capture_sources := 'Y';
6054             -- Assumption: p_rxlv_tbl and p_acc_sources_tbl are populated using the Same Index.
6055             l_acc_srcs_index  := rxl_index;
6056             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6057               'Case 2: Populate Sources has been asked to capture sources for the Current Transaction Detail by Accounting Engine ' ||
6058               ' TXD ID = ' || TO_CHAR( l_trx_ar_adj_lines_tbl(tld_index).source_id ) );
6059           END IF;
6060           -- Exit when this is the Last Record or the Transaction Details has been found
6061           EXIT WHEN ( rxl_index = l_rxlv_tbl.LAST )  -- When reached End of the Table
6062                  OR ( l_capture_sources = 'Y'     ); -- Or When the TXD has been found
6063           -- Increment the rxl_index
6064           rxl_index := l_rxlv_tbl.NEXT( rxl_index );
6065         END LOOP; -- Loop on l_rxlv_tbl ..
6066 
6067         IF l_capture_sources = 'Y'
6068         THEN
6069           -- If the AGS Index is not found then return error
6070           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6071             'Account Generator Sources Index =' || TO_CHAR(l_acc_srcs_index)  );
6072           IF l_acc_srcs_index IS NULL OR
6073              ( p_acc_sources_tbl.EXISTS(l_acc_srcs_index) = FALSE )
6074           THEN
6075             -- accounting_event_class_code is missing
6076             OKL_API.set_message(
6077                p_app_name      => G_APP_NAME
6078               ,p_msg_name      => G_INVALID_VALUE
6079               ,p_token1        => G_COL_NAME_TOKEN
6080               ,p_token1_value  => 'AGS_SOURCES_INDEX');
6081             l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6082             RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6083           END IF; -- IF l_acc_sources_found = FALSE
6084 
6085           -- l_rxhv_rec.source_id and l_rxhv_rec.source_table are already assigned
6086           l_rxhv_rec.khr_id    := l_trx_ar_adj_lines_tbl(tld_index).khr_id;
6087           l_rxhv_rec.try_id    := l_trx_ar_adj_lines_tbl(tld_index).try_id;
6088           -- Id of Detail Line Table
6089           l_rxlv_rec.source_id := l_trx_ar_adj_lines_tbl(tld_index).source_id;
6090           l_rxlv_rec.source_table := l_trx_ar_adj_lines_tbl(tld_index).source_table;
6091           l_rxlv_rec.kle_id    := l_trx_ar_adj_lines_tbl(tld_index).kle_id;
6092           l_rxlv_rec.sty_id    := l_trx_ar_adj_lines_tbl(tld_index).sty_id;
6093 --          l_rxlv_rec.trans_line_description := l_trx_ar_adj_lines_tbl(tld_index).trans_line_description;
6094           -- The populate_tld_sources will capture sources at extension line level always
6095           -- If the extension header sources with the l_rxlv_rec.source_id and l_rxhv_rec.khr_id is not captured
6096           -- Then only capture the extension header sources
6097           -- Calling populate_tld_sources
6098           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6099             'Calling the populate_ar_sources' );
6100           populate_ar_sources(
6101             p_api_version       => l_api_version
6102            ,p_init_msg_list     => p_init_msg_list
6103            ,p_rxhv_rec          => l_rxhv_rec
6104            ,p_rxlv_rec          => l_rxlv_rec
6105            ,p_acc_sources_rec   => p_acc_sources_tbl(l_acc_srcs_index)
6106            ,x_return_status     => l_return_status
6107            ,x_msg_count         => x_msg_count
6108            ,x_msg_data          => x_msg_data);
6109           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6110             'After populate_ar_sources: l_return_status ' || l_return_status );
6111           -- Check the return status and if errored, return the error back
6112           IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6113             RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6114           ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6115             RAISE OKL_API.G_EXCEPTION_ERROR;
6116           END IF;
6117         END IF; -- IF l_capture_sources = 'Y'
6118       END LOOP; -- Loop on l_trx_ar_adj_lines_tbl ..
6119     END IF; -- IF l_header_source_table = 'OKL_TRX_AR_INVOICES_B'
6120     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6121       'Calling okl_api.end_activity');
6122     okl_api.end_activity(
6123        x_msg_count => x_msg_count
6124       ,x_msg_data  => x_msg_data);
6125     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6126       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
6127     x_return_status := OKL_API.G_RET_STS_SUCCESS;
6128   EXCEPTION
6129     ------------------------------------------------------------
6130     -- Exception handling
6131     ------------------------------------------------------------
6132     WHEN OKL_API.G_EXCEPTION_ERROR
6133     THEN
6134       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
6135                             p_api_name  => l_api_name
6136                            ,p_pkg_name  => G_PKG_NAME
6137                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
6138                            ,x_msg_count  => x_msg_count
6139                            ,x_msg_data  => x_msg_data
6140                            ,p_api_type  => '_PVT');
6141     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
6142     THEN
6143       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
6144                            p_api_name  => l_api_name
6145                           ,p_pkg_name  => G_PKG_NAME
6146                           ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
6147                           ,x_msg_count  => x_msg_count
6148                           ,x_msg_data  => x_msg_data
6149                            ,p_api_type  => '_PVT');
6150     WHEN OTHERS
6151     THEN
6152       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
6153                             p_api_name  => l_api_name
6154                            ,p_pkg_name  => G_PKG_NAME
6155                            ,p_exc_name  => 'OTHERS'
6156                            ,x_msg_count  => x_msg_count
6157                            ,x_msg_data  => x_msg_data
6158                            ,p_api_type  => '_PVT');
6159   END populate_sources;
6160 
6161   PROCEDURE delete_ar_extension(
6162     p_api_version               IN              NUMBER
6163    ,p_init_msg_list             IN              VARCHAR2
6164    ,p_rxhv_rec                  IN              rxhv_rec_type
6165    ,x_rxlv_tbl                  OUT    NOCOPY   rxlv_tbl_type
6166    ,x_return_status             OUT    NOCOPY  VARCHAR2
6167    ,x_msg_count                 OUT    NOCOPY  NUMBER
6168    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
6169   )
6170   IS
6171     -----------------------------------------------------------------
6172     -- Declare Process Variable
6173     -----------------------------------------------------------------
6174     l_api_version      CONSTANT NUMBER         := 1;
6175     l_api_name         CONSTANT VARCHAR2(30)   := 'DELETE_TRX_EXTENSION';
6176     l_return_status    VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
6177     rxl_index          BINARY_INTEGER;
6178     l_rxhv_rec         okl_rxh_pvt.rxhv_rec_type;
6179     l_rxlv_tbl         okl_rxl_pvt.rxlv_tbl_type;
6180     lx_rxhv_rec        okl_rxh_pvt.rxhv_rec_type;
6181     lx_rxlv_tbl        okl_rxl_pvt.rxlv_tbl_type;
6182     -- Cursor Definitions
6183     CURSOR get_ar_ext_hdr_id( p_source_id  NUMBER, p_source_table VARCHAR2)
6184     IS
6185       SELECT   rxh.header_extension_id      header_extension_id
6186         FROM   okl_ext_ar_header_sources_b	rxh
6187        WHERE   rxh.source_id = p_source_id
6188          AND   rxh.source_table = p_source_table;
6189 
6190     CURSOR get_ar_ext_lns_id( p_hdr_ext_id  NUMBER)
6191     IS
6192       SELECT   rxl.line_extension_id     line_extension_id
6193               ,rxl.source_id             source_id
6194               ,rxl.source_table          source_table
6195         FROM   okl_ext_ar_line_sources_b rxl
6196        WHERE   rxl.header_extension_id = p_hdr_ext_id;
6197     -- Local Variables for enabling the Debug Statements
6198     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
6199     l_debug_enabled                    VARCHAR2(10);
6200     is_debug_procedure_on              BOOLEAN;
6201     is_debug_statement_on              BOOLEAN;
6202   BEGIN
6203     l_debug_enabled := okl_debug_pub.check_log_enabled;
6204     -- check for logging on PROCEDURE level
6205     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
6206     -- check for logging on STATEMENT level
6207     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
6208     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6209                'begin debug OKLRSLAB.pls call ' || l_api_name);
6210     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6211                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.DELETE_TRX_EXTENSION');
6212     l_return_status := OKL_API.G_RET_STS_SUCCESS;
6213     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6214       'Calling OKL_API.START_ACTIVITY');
6215     l_return_status := OKL_API.START_ACTIVITY(
6216                          p_api_name       => l_api_name
6217                         ,p_pkg_name       => g_pkg_name
6218                         ,p_init_msg_list  => p_init_msg_list
6219                         ,l_api_version    => l_api_version
6220                         ,p_api_version    => p_api_version
6221                         ,p_api_type       => '_PVT'
6222                         ,x_return_status  => l_return_status);
6223     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6224       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6225     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6226       RAISE OKL_API.G_EXCEPTION_ERROR;
6227     END IF;
6228     -- Actual Logic Starts Here ..
6229     l_rxhv_rec := p_rxhv_rec;
6230     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6231       'Source ID=' || to_char(l_rxhv_rec.source_id) || 'Source Header Table=' || l_rxhv_rec.source_table );
6232     IF ( l_rxhv_rec.source_id = OKL_API.G_MISS_NUM or l_rxhv_rec.source_id IS NULL )
6233     THEN
6234       OKL_API.set_message(
6235          p_app_name      => G_APP_NAME
6236         ,p_msg_name      => G_INVALID_VALUE
6237         ,p_token1        => G_COL_NAME_TOKEN
6238         ,p_token1_value  => 'HEADER.SOURCE_ID');
6239       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6240       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6241     END IF;
6242     IF ( l_rxhv_rec.source_table = OKL_API.G_MISS_CHAR or l_rxhv_rec.source_table IS NULL
6243         OR l_rxhv_rec.source_table NOT IN ( G_TRX_AR_INVOICES_B, G_TRX_AR_ADJSTS_B) )
6244     THEN
6245       OKL_API.set_message(
6246          p_app_name      => G_APP_NAME
6247         ,p_msg_name      => G_INVALID_VALUE
6248         ,p_token1        => G_COL_NAME_TOKEN
6249         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
6250       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6251       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6252     END IF;
6253     -- Initialize the rxl_index
6254     rxl_index := 1;
6255     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6256       'Fetch the Extension Header ID by executing cursor get_txl_ext_hdr_id' );
6257     FOR t_rec IN get_ar_ext_hdr_id(
6258                     p_source_id     => l_rxhv_rec.source_id
6259                    ,p_source_table  => l_rxhv_rec.source_table)
6260     LOOP
6261       -- Note that for a given Source ID and Source Table in OKL_EXT_AR_HEADER_SOURCES_B
6262       --  there can be multiple records each having different KHR_ID ..
6263       l_rxhv_rec.header_extension_id := t_rec.header_extension_id;
6264       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6265         'Extension Header ID To be Deleted='  || TO_CHAR(l_rxhv_rec.header_extension_id));
6266       -- Fetch the Transaction Extension Line IDs to be deleted
6267       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6268         'Extension Line ID(s) To be Deleted=');
6269       FOR t_rec IN get_ar_ext_lns_id( p_hdr_ext_id  => l_rxhv_rec.header_extension_id)
6270       LOOP
6271         l_rxlv_tbl(rxl_index).line_extension_id  := t_rec.line_extension_id;
6272         l_rxlv_tbl(rxl_index).source_id          := t_rec.source_id;
6273         l_rxlv_tbl(rxl_index).source_table       := t_rec.source_table;
6274         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6275           'LINE_EXTENSION_ID[' || rxl_index || '] = ' || TO_CHAR(l_rxlv_tbl(rxl_index).line_extension_id) );
6276         -- Increment i
6277         rxl_index := rxl_index + 1;
6278       END LOOP; -- End get_trans_line_ids
6279       -- Call the Wrapper API to delete the Extension Lines and then Header
6280       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6281         'calling the okl_ar_extension_pvt.delete_rxh_extension Line Count=' || l_rxlv_tbl.COUNT );
6282       okl_ar_extension_pvt.delete_rxh_extension(
6283         p_api_version     => p_api_version
6284        ,p_init_msg_list   => p_init_msg_list
6285        ,x_return_status   => x_return_status
6286        ,x_msg_count       => x_msg_count
6287        ,x_msg_data        => x_msg_data
6288        ,p_rxhv_rec        => l_rxhv_rec
6289       );
6290       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6291         'After okl_ar_extension_pvt.delete_rxh_extension: l_return_status ' || l_return_status );
6292       -- Check the return status and if errored, return the error back
6293       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
6294       THEN
6295         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6296       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6297         RAISE OKL_API.G_EXCEPTION_ERROR;
6298       END IF;
6299     END LOOP; -- Loop on the get_ar_ext_hdr_id
6300     -- Store the Transaction Line IDs and Line Source Tables so as to return back
6301     x_rxlv_tbl := l_rxlv_tbl;
6302     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6303       'Calling okl_api.end_activity');
6304     okl_api.end_activity(
6305        x_msg_count => x_msg_count
6306       ,x_msg_data  => x_msg_data);
6307     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6308       'END OKL_SLA_ACC_SOURCES_PVT.DELETE_TRX_EXTENSION');
6309     x_return_status := OKL_API.G_RET_STS_SUCCESS;
6310   EXCEPTION
6311     ------------------------------------------------------------
6312     -- Exception handling
6313     ------------------------------------------------------------
6314     WHEN OKL_API.G_EXCEPTION_ERROR
6315     THEN
6316       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
6317                             p_api_name  => l_api_name
6318                            ,p_pkg_name  => G_PKG_NAME
6319                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
6320                            ,x_msg_count => x_msg_count
6321                            ,x_msg_data  => x_msg_data
6322                            ,p_api_type  => '_PVT');
6323     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
6324     THEN
6325       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
6326                             p_api_name  => l_api_name
6327                            ,p_pkg_name  => G_PKG_NAME
6328                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
6329                            ,x_msg_count => x_msg_count
6330                            ,x_msg_data  => x_msg_data
6331                            ,p_api_type  => '_PVT');
6332     WHEN OTHERS
6333     THEN
6334      x_return_status := OKL_API.HANDLE_EXCEPTIONS (
6335                             p_api_name  => l_api_name
6336                            ,p_pkg_name  => G_PKG_NAME
6337                            ,p_exc_name  => 'OTHERS'
6338                            ,x_msg_count => x_msg_count
6339                            ,x_msg_data  => x_msg_data
6340                            ,p_api_type  => '_PVT');
6341   END delete_ar_extension;
6342 
6343   ------------------------------------------------------------------------------
6344   -- Start of comments
6345   --      API name        : assign_khr_rec_to_pxhv_rec
6346   --      Pre-reqs        : None
6347   --      Function        : assign khr rec to pxhv rec for AP OKL Transactions
6348   --      Parameters      :
6349   --      IN              : p_khr_source_rec     khr_source_rec_type
6350   --      OUT             : x_pxhv_rec           pxhv_rec_type
6351   --      Version         : 1.0
6352   --      History         : Prashant Jain created
6353   -- End of comments
6354   ------------------------------------------------------------------------------
6355   -- Changes for Bug# 6268782 : PRASJAIN
6356   -- 1. func name assign_khr_rec_to_pxhv_rec to assign_khr_rec_to_pxh_rec
6357   -- 2. out param pxhv_rec_type to pxh_rec_type
6358   ------------------------------------------------------------------------------
6359   PROCEDURE assign_khr_rec_to_pxh_rec(
6360     p_khr_source_rec  IN       khr_source_rec_type
6361    ,x_pxh_rec         IN OUT   NOCOPY pxh_rec_type
6362   )
6363   AS
6364   BEGIN
6365     x_pxh_rec.khr_id                  := p_khr_source_rec.khr_id;
6366     x_pxh_rec.contract_number         := p_khr_source_rec.contract_number;
6367     x_pxh_rec.customer_name           := p_khr_source_rec.customer_name;
6368     x_pxh_rec.cust_account_number     := p_khr_source_rec.customer_account_number;
6369     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
6370     x_pxh_rec.party_id                := p_khr_source_rec.customer_id;
6371     x_pxh_rec.cust_account_id         := p_khr_source_rec.cust_account_id;
6372     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
6373     x_pxh_rec.contract_currency_code  := p_khr_source_rec.contract_currency_code;
6374     x_pxh_rec.contract_effective_from := p_khr_source_rec.contract_effective_from;
6375     x_pxh_rec.product_name            := p_khr_source_rec.product_name;
6376     x_pxh_rec.book_classification_code:= p_khr_source_rec.book_classification_code;
6377     x_pxh_rec.tax_owner_code          := p_khr_source_rec.tax_owner_code;
6378     x_pxh_rec.rev_rec_method_code     := p_khr_source_rec.rev_rec_method_code;
6379     x_pxh_rec.int_calc_method_code    := p_khr_source_rec.int_calc_method_code;
6380     x_pxh_rec.vendor_program_number   := p_khr_source_rec.vendor_program_number;
6381     x_pxh_rec.converted_number        := p_khr_source_rec.converted_number;
6382     x_pxh_rec.converted_account_flag  := p_khr_source_rec.converted_account_flag;
6383     x_pxh_rec.assignable_flag         := p_khr_source_rec.assignable_flag;
6384     x_pxh_rec.po_order_number         := p_khr_source_rec.po_order_number;
6385     x_pxh_rec.accrual_override_flag   := p_khr_source_rec.accrual_override_flag;
6386     x_pxh_rec.rent_ia_contract_number := p_khr_source_rec.rent_ia_contract_number;
6387     x_pxh_rec.rent_ia_product_name    := p_khr_source_rec.rent_ia_product_name;
6388     x_pxh_rec.rent_ia_accounting_code := p_khr_source_rec.rent_ia_accounting_code;
6389     x_pxh_rec.res_ia_contract_number  := p_khr_source_rec.res_ia_contract_number;
6390     x_pxh_rec.res_ia_product_name     := p_khr_source_rec.res_ia_product_name;
6391     x_pxh_rec.res_ia_accounting_code  := p_khr_source_rec.res_ia_accounting_code;
6392     x_pxh_rec.khr_attribute_category  := p_khr_source_rec.khr_attribute_category;
6393     x_pxh_rec.khr_attribute1          := p_khr_source_rec.khr_attribute1;
6394     x_pxh_rec.khr_attribute2          := p_khr_source_rec.khr_attribute2;
6395     x_pxh_rec.khr_attribute3          := p_khr_source_rec.khr_attribute3;
6396     x_pxh_rec.khr_attribute4          := p_khr_source_rec.khr_attribute4;
6397     x_pxh_rec.khr_attribute5          := p_khr_source_rec.khr_attribute5;
6398     x_pxh_rec.khr_attribute6          := p_khr_source_rec.khr_attribute6;
6399     x_pxh_rec.khr_attribute7          := p_khr_source_rec.khr_attribute7;
6400     x_pxh_rec.khr_attribute8          := p_khr_source_rec.khr_attribute8;
6401     x_pxh_rec.khr_attribute9          := p_khr_source_rec.khr_attribute9;
6402     x_pxh_rec.khr_attribute10         := p_khr_source_rec.khr_attribute10;
6403     x_pxh_rec.khr_attribute11         := p_khr_source_rec.khr_attribute11;
6404     x_pxh_rec.khr_attribute12         := p_khr_source_rec.khr_attribute12;
6405     x_pxh_rec.khr_attribute13         := p_khr_source_rec.khr_attribute13;
6406     x_pxh_rec.khr_attribute14         := p_khr_source_rec.khr_attribute14;
6407     x_pxh_rec.khr_attribute15         := p_khr_source_rec.khr_attribute15;
6408     x_pxh_rec.cust_attribute_category := p_khr_source_rec.cust_attribute_category;
6409     x_pxh_rec.cust_attribute1         := p_khr_source_rec.cust_attribute1;
6410     x_pxh_rec.cust_attribute2         := p_khr_source_rec.cust_attribute2;
6411     x_pxh_rec.cust_attribute3         := p_khr_source_rec.cust_attribute3;
6412     x_pxh_rec.cust_attribute4         := p_khr_source_rec.cust_attribute4;
6413     x_pxh_rec.cust_attribute5         := p_khr_source_rec.cust_attribute5;
6414     x_pxh_rec.cust_attribute6         := p_khr_source_rec.cust_attribute6;
6415     x_pxh_rec.cust_attribute7         := p_khr_source_rec.cust_attribute7;
6416     x_pxh_rec.cust_attribute8         := p_khr_source_rec.cust_attribute8;
6417     x_pxh_rec.cust_attribute9         := p_khr_source_rec.cust_attribute9;
6418     x_pxh_rec.cust_attribute10        := p_khr_source_rec.cust_attribute10;
6419     x_pxh_rec.cust_attribute11        := p_khr_source_rec.cust_attribute11;
6420     x_pxh_rec.cust_attribute12        := p_khr_source_rec.cust_attribute12;
6421     x_pxh_rec.cust_attribute13        := p_khr_source_rec.cust_attribute13;
6422     x_pxh_rec.cust_attribute14        := p_khr_source_rec.cust_attribute14;
6423     x_pxh_rec.cust_attribute15        := p_khr_source_rec.cust_attribute15;
6424     x_pxh_rec.contract_status_code    := p_khr_source_rec.contract_status_code;
6425     x_pxh_rec.inv_agrmnt_number         := p_khr_source_rec.inv_agrmnt_number;
6426     x_pxh_rec.inv_agrmnt_effective_from := p_khr_source_rec.inv_agrmnt_effective_from;
6427     x_pxh_rec.inv_agrmnt_product_name   := p_khr_source_rec.inv_agrmnt_product_name;
6428     x_pxh_rec.inv_agrmnt_currency_code  := p_khr_source_rec.inv_agrmnt_currency_code;
6429     x_pxh_rec.inv_agrmnt_synd_code      := p_khr_source_rec.inv_agrmnt_synd_code;
6430     x_pxh_rec.inv_agrmnt_pool_number    := p_khr_source_rec.inv_agrmnt_pool_number;
6431     x_pxh_rec.inv_agrmnt_status_code    := p_khr_source_rec.inv_agrmnt_status_code;
6432     x_pxh_rec.scs_code                  := p_khr_source_rec.scs_code;
6433   END assign_khr_rec_to_pxh_rec;
6434 
6435  ------------------------------------------------------------------------------
6436   -- Start of comments
6437   --      API name        : assign_kle_rec_to_pxlv_rec
6438   --      Pre-reqs        : None
6439   --      Function        : assign kle rec to pxlv rec for AP OKL Transactions
6440   --      Parameters      :
6441   --      IN              : p_kle_source_rec     kle_source_rec_type
6442   --      OUT             : x_pxlv_rec           pxlv_rec_type
6443   --      Version         : 1.0
6444   --      History         : Prashant Jain created
6445   -- End of comments
6446   ------------------------------------------------------------------------------
6447   -- Changes for Bug# 6268782 : PRASJAIN
6448   -- 1. func name assign_kle_rec_to_pxlv_rec to assign_kle_rec_to_pxl_rec
6449   -- 2. out param pxlv_rec_type to pxl_rec_type
6450   ------------------------------------------------------------------------------
6451   PROCEDURE assign_kle_rec_to_pxl_rec(
6452     p_kle_source_rec  IN       kle_source_rec_type
6453    ,x_pxl_rec         IN OUT   NOCOPY pxl_rec_type
6454   )
6455   AS
6456   BEGIN
6457     x_pxl_rec.kle_id                    := p_kle_source_rec.kle_id;
6458     x_pxl_rec.asset_number              := p_kle_source_rec.asset_number;
6459     x_pxl_rec.contract_line_number      := p_kle_source_rec.contract_line_number;
6460     x_pxl_rec.asset_vendor_name         := p_kle_source_rec.asset_vendor_name;
6461     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables start
6462     x_pxl_rec.asset_vendor_id           := p_kle_source_rec.asset_vendor_id;
6463     -- added by zrehman Bug#6707320 for Party Merge impact on Accounting sources tables end
6464     x_pxl_rec.installed_site_id         := p_kle_source_rec.installed_site_id;
6465     x_pxl_rec.fixed_asset_location_name := p_kle_source_rec.fixed_asset_location_name;
6466     x_pxl_rec.contract_line_type        := p_kle_source_rec.line_type_code;
6467     x_pxl_rec.line_attribute_category   := p_kle_source_rec.line_attribute_category;
6468     x_pxl_rec.line_attribute1           := p_kle_source_rec.line_attribute1;
6469     x_pxl_rec.line_attribute2           := p_kle_source_rec.line_attribute2;
6470     x_pxl_rec.line_attribute3           := p_kle_source_rec.line_attribute3;
6471     x_pxl_rec.line_attribute4           := p_kle_source_rec.line_attribute4;
6472     x_pxl_rec.line_attribute5           := p_kle_source_rec.line_attribute5;
6473     x_pxl_rec.line_attribute6           := p_kle_source_rec.line_attribute6;
6474     x_pxl_rec.line_attribute7           := p_kle_source_rec.line_attribute7;
6475     x_pxl_rec.line_attribute8           := p_kle_source_rec.line_attribute8;
6476     x_pxl_rec.line_attribute9           := p_kle_source_rec.line_attribute9;
6477     x_pxl_rec.line_attribute10          := p_kle_source_rec.line_attribute10;
6478     x_pxl_rec.line_attribute11          := p_kle_source_rec.line_attribute11;
6479     x_pxl_rec.line_attribute12          := p_kle_source_rec.line_attribute12;
6480     x_pxl_rec.line_attribute13          := p_kle_source_rec.line_attribute13;
6481     x_pxl_rec.line_attribute14          := p_kle_source_rec.line_attribute14;
6482     x_pxl_rec.line_attribute15          := p_kle_source_rec.line_attribute15;
6483   END assign_kle_rec_to_pxl_rec;
6484 
6485   ------------------------------------------------------------------------------
6486   -- Start of comments
6487   --      API name        : populate_ap_sources
6488   --      Pre-reqs        : None
6489   --      Function        : populate sources for OKL AP Transactions
6490   --      Parameters      :
6491   --      IN              : pxhv_rec_type.source_id            IN NUMBER    Required
6492   --                        pxhv_rec_type.source_table         IN VARCHAR2  Required
6493 
6494   --                        pxhv_rec_type.khr_id               IN NUMBER    Required
6495   --                        pxlv_rec_type.kle_id               IN NUMBER    Required
6496   --                        pxhv_rec_type.try_id               IN NUMBER    Required
6497   --                        pxlv_rec_type.sty_id               IN NUMBER    Required
6498   --                        pxlv_rec_type.source_id            IN NUMBER    Required
6499   --                        pxlv_rec_type.source_table         IN VARCHAR2  Required
6500   --      History         : Prashant Jain created
6501   --      Version         : 1.0
6502   -- End of comments
6503   ------------------------------------------------------------------------------
6504   PROCEDURE populate_ap_sources(
6505     p_api_version           IN        NUMBER
6506    ,p_init_msg_list         IN        VARCHAR2
6507    ,p_pxhv_rec              IN        pxhv_rec_type
6508    ,p_pxlv_rec              IN        pxlv_rec_type
6509    ,p_acc_sources_rec       IN        asev_rec_type
6510    ,x_return_status         OUT       NOCOPY  VARCHAR2
6511    ,x_msg_count             OUT       NOCOPY  NUMBER
6512    ,x_msg_data              OUT       NOCOPY  VARCHAR2
6513   )
6514   IS
6515     -- Cursor to fetch header_extension_id
6516     CURSOR c_header_extension_id_csr (p_header_source_id NUMBER, p_khr_id NUMBER)
6517     IS
6518       SELECT    hdr.header_extension_id header_extension_id
6519         FROM    okl_ext_ap_header_sources_b hdr
6520        WHERE    hdr.source_id = p_header_source_id
6521          AND    hdr.khr_id    = p_khr_id;
6522     -- Cursor to fetch trans number
6523     CURSOR c_trans_number_csr (p_header_source_id NUMBER)
6524     IS
6525       SELECT    tap.vendor_invoice_number trans_number
6526         FROM    okl_trx_ap_invoices_b tap
6527        WHERE    tap.id = p_header_source_id;
6528 
6529     -----------------------------------------------------------------
6530     -- Declare Process Variable
6531     -----------------------------------------------------------------
6532     l_api_version          CONSTANT NUMBER         := 1;
6533     l_api_name             CONSTANT VARCHAR2(30)   := 'populate_ap_sources';
6534     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
6535     -----------------------------------------------------------------
6536     -- Local Variables
6537     -----------------------------------------------------------------
6538     l_khr_id               NUMBER;
6539     l_try_id               NUMBER;
6540     l_kle_id               NUMBER;
6541     l_sty_id               NUMBER;
6542     l_ledger_id            NUMBER;
6543     l_ledger_language      VARCHAR2(12);
6544     l_header_source_id     NUMBER;
6545     l_header_source_table  VARCHAR2(30);
6546     l_template_id          NUMBER;
6547     l_source_id            NUMBER;
6548     l_source_table         VARCHAR2(30);
6549     l_header_extension_id  NUMBER;
6550     l_pk_attributes        VARCHAR2(1000);
6551     l_tcn_id               NUMBER;
6552     l_line_style           VARCHAR2(30);
6553     l_parent_line_id       NUMBER;
6554     -- KHR and KLE Based Record Structures
6555     l_khr_source_rec       khr_source_rec_type;
6556     l_kle_source_rec       kle_source_rec_type;
6557     -- Record structures based on the Cursor Definitions
6558     l_termination_qte_csr_rec   c_termination_qte_csr%ROWTYPE;
6559     -- Record Structures based on OKL AP Extension Header and Line Tables
6560     l_pxh_rec              pxh_rec_type;
6561     lx_pxh_rec             pxh_rec_type;
6562 
6563     l_pxhl_tbl             pxhl_tbl_type;
6564     lx_pxhl_tbl            pxhl_tbl_type;
6565 
6566     l_pxl_rec              pxl_rec_type;
6567     lx_pxl_rec             pxl_rec_type;
6568 
6569     l_pxll_tbl             pxll_tbl_type;
6570     lx_pxll_tbl            pxll_tbl_type;
6571 
6572     l_led_lang_tbl        led_lang_tbl_type;
6573 
6574     l_ledger_lang_rec      c_ledger_lang_csr%ROWTYPE;
6575     -- Local Variables for enabling the Debug Statements
6576     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
6577     l_debug_enabled       VARCHAR2(10);
6578     is_debug_procedure_on BOOLEAN;
6579     is_debug_statement_on BOOLEAN;
6580     tl_sources_in         NUMBER := 1;
6581   BEGIN
6582     l_debug_enabled := okl_debug_pub.check_log_enabled;
6583     -- check for logging on PROCEDURE level
6584     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
6585     -- check for logging on STATEMENT level
6586     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
6587     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6588                'begin debug OKLRSLAB.pls call ' || l_api_name);
6589     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6590                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.populate_ap_sources');
6591     l_return_status := OKL_API.G_RET_STS_SUCCESS;
6592     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6593       'Calling OKL_API.START_ACTIVITY');
6594     l_return_status := OKL_API.START_ACTIVITY(
6595                          p_api_name       => l_api_name
6596                         ,p_pkg_name       => g_pkg_name
6597                         ,p_init_msg_list  => p_init_msg_list
6598                         ,l_api_version    => l_api_version
6599                         ,p_api_version    => p_api_version
6600                         ,p_api_type       => '_PVT'
6601                         ,x_return_status  => l_return_status);
6602     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6603       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6604     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6605       RAISE OKL_API.G_EXCEPTION_ERROR;
6606     END IF;
6607     -- Validations to be done
6608     -- Validation 1:
6609     --   The following attributes should not be NULL
6610     --    dnz_khr_id, kle_id, try_id, source_id, sty_id
6611     l_pk_attributes := NULL;
6612     IF p_pxhv_rec.source_id IS NULL OR
6613        p_pxhv_rec.source_id = OKL_API.G_MISS_NUM
6614     THEN
6615       IF l_pk_attributes IS NOT NULL
6616       THEN
6617         l_pk_attributes := l_pk_attributes || ' , ';
6618       END IF;
6619       l_pk_attributes := l_pk_attributes || 'PXH.SOURCE_ID';
6620     END IF;
6621     IF p_pxhv_rec.source_table IS NULL OR
6622        p_pxhv_rec.source_table = OKL_API.G_MISS_CHAR
6623     THEN
6624       IF l_pk_attributes IS NOT NULL
6625       THEN
6626         l_pk_attributes := l_pk_attributes || ' , ';
6627       END IF;
6628       l_pk_attributes := l_pk_attributes || 'PXH.SOURCE_TABLE';
6629     END IF;
6630     IF p_pxhv_rec.khr_id IS NULL OR
6631        p_pxhv_rec.khr_id = OKL_API.G_MISS_NUM
6632     THEN
6633       IF l_pk_attributes IS NOT NULL
6634       THEN
6635         l_pk_attributes := l_pk_attributes || ' , ';
6636       END IF;
6637       l_pk_attributes := l_pk_attributes || 'KHR_ID';
6638     END IF;
6639     IF p_pxhv_rec.try_id IS NULL OR
6640        p_pxhv_rec.try_id = OKL_API.G_MISS_NUM
6641     THEN
6642       IF l_pk_attributes IS NOT NULL
6643       THEN
6644         l_pk_attributes := l_pk_attributes || ' , ';
6645       END IF;
6646       l_pk_attributes := l_pk_attributes || 'TRY_ID';
6647     END IF;
6648     IF p_pxlv_rec.source_id IS NULL OR
6649        p_pxlv_rec.source_id = OKL_API.G_MISS_NUM
6650     THEN
6651       IF l_pk_attributes IS NOT NULL
6652       THEN
6653         l_pk_attributes := l_pk_attributes || ' , ';
6654       END IF;
6655       l_pk_attributes := l_pk_attributes || 'PXL.SOURCE_ID';
6656     END IF;
6657     IF p_pxlv_rec.source_table IS NULL OR
6658        p_pxlv_rec.source_table = OKL_API.G_MISS_CHAR
6659     THEN
6660       IF l_pk_attributes IS NOT NULL
6661       THEN
6662         l_pk_attributes := l_pk_attributes || ' , ';
6663       END IF;
6664       l_pk_attributes := l_pk_attributes || 'PXL.SOURCE_TABLE';
6665     END IF;
6666     IF p_pxlv_rec.sty_id IS NULL OR
6667        p_pxlv_rec.sty_id = OKL_API.G_MISS_NUM
6668     THEN
6669       IF l_pk_attributes IS NOT NULL
6670       THEN
6671         l_pk_attributes := l_pk_attributes || ' , ';
6672       END IF;
6673       l_pk_attributes := l_pk_attributes || 'STY_ID';
6674     END IF;
6675     IF LENGTH(l_pk_attributes) > 0
6676     THEN
6677       -- Raise an Exception
6678       OKL_API.set_message(
6679          p_app_name      => G_APP_NAME
6680         ,p_msg_name      => G_INVALID_VALUE
6681         ,p_token1        => G_COL_NAME_TOKEN
6682         ,p_token1_value  => l_pk_attributes);
6683       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6684       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6685     END IF;
6686     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6687       'Validation 1 Successfull !');
6688     -- Validation 2:
6689     --   Source Table should be OKL_TXL_AP_INV_LNS_B
6690     IF p_pxlv_rec.source_table NOT IN ( G_TXL_AP_INV_LNS_B )
6691     THEN
6692       -- Raise an Exception
6693       OKL_API.set_message(
6694          p_app_name      => G_APP_NAME
6695         ,p_msg_name      => G_INVALID_VALUE
6696         ,p_token1        => G_COL_NAME_TOKEN
6697         ,p_token1_value  => 'SOURCE_TABLE');
6698       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
6699       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6700     END IF;
6701     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6702       'Validation 2 Successfull !');
6703     -- Copy input rec to local variable
6704     l_pxh_rec.source_id    := p_pxhv_rec.source_id;
6705     l_pxh_rec.source_table := p_pxhv_rec.source_table;
6706     l_pxh_rec.khr_id       := p_pxhv_rec.khr_id;
6707     l_pxh_rec.try_id       := p_pxhv_rec.try_id;
6708 
6709     l_pxl_rec.source_id    := p_pxlv_rec.source_id;
6710     l_pxl_rec.source_table := p_pxlv_rec.source_table;
6711     l_pxl_rec.kle_id       := p_pxlv_rec.kle_id;
6712     l_pxl_rec.sty_id       := p_pxlv_rec.sty_id;
6713     -- Copy the input parameters to the local variables
6714     l_header_source_id    := l_pxh_rec.source_id;
6715     l_header_source_table := l_pxh_rec.source_table;
6716     l_khr_id              := l_pxh_rec.khr_id;
6717     l_try_id              := l_pxh_rec.try_id;
6718     l_source_id           := l_pxl_rec.source_id;
6719     l_source_table        := l_pxl_rec.source_table;
6720     l_kle_id              := l_pxl_rec.kle_id;  -- For Subsidy this is will be a SUBSIDY Line but not the Asset
6721     l_sty_id              := l_pxl_rec.sty_id;
6722 
6723     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6724       '**** KLE_ID = ' || l_kle_id );
6725     IF l_kle_id IS NOT NULL OR
6726        l_kle_id <> OKL_API.G_MISS_NUM
6727     THEN
6728       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6729         'Executing the Cursor get_line_style_csr kle_id=' || l_pxl_rec.kle_id );
6730       FOR t_rec IN get_line_style_csr(p_kle_id => l_pxl_rec.kle_id )
6731       LOOP
6732         l_line_style       := t_rec.line_style;
6733         IF l_line_style = 'SUBSIDY'
6734         THEN
6735           l_parent_line_id := t_rec.parent_line_id;
6736         END IF;
6737       END LOOP;
6738       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6739         '**** LINE STYLE = ' || l_line_style || ' PARENT LINE ID = ' || l_parent_line_id );
6740     END IF; -- IF l_kle_id IS NOT NULL OR l_kle_id <> OKL_API.G_MISS_NUM
6741 
6742     -- Fetch ledger id and ledger language associated to the contracts
6743     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6744       'Executing the Cursor c_khr_to_ledger_id_csr. p_khr_id=' || TO_CHAR(l_khr_id));
6745     FOR t_rec IN c_khr_to_ledger_id_csr( p_khr_id => l_khr_id )
6746     LOOP
6747       l_ledger_id := t_rec.ledger_id;
6748     END LOOP;
6749 
6750     -- Fetch the ledger language in order to populate the sources
6751     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6752       'Executing the Cursor c_ledger_lang_csr. p_ledger_id=' || TO_CHAR(l_ledger_id));
6753     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_ledger_id )
6754     LOOP
6755       l_ledger_lang_rec := t_rec;
6756       l_led_lang_tbl(tl_sources_in).language := t_rec.language_code;
6757       l_pxll_tbl(tl_sources_in).language     := t_rec.language_code;
6758       tl_sources_in := tl_sources_in + 1;
6759     END LOOP;
6760 
6761     -- Logic Description:
6762     --   1. The OKL AP Extension Header _B/_TL sources will be captured only once
6763     --       for a KHR_ID.
6764     --   2. For every AP Transaction Line, there will be a single record in the
6765     --       OKL AP Extension Line _B/_TL
6766     --  For Eg., if a Transaction is having 10 transaction lines with two different khr_id1, khr_id2
6767     --  there will be only two records in the Header but 10 transaction lines in Extension Line.
6768     --  Hence, for every Transaction Line check whether the KHR Sources have been captured
6769     --  already or not by passing the Transaction ID and KHR_ID
6770     -- Fetch header extension id
6771     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6772       'Executing the Cursor c_header_extension_id_csr.
6773          p_header_source_id=' || TO_CHAR(l_header_source_id)
6774         || ' p_khr_id= ' || TO_CHAR(l_khr_id));
6775     l_header_extension_id := NULL;
6776     FOR t_rec IN c_header_extension_id_csr(
6777                           p_header_source_id    => l_header_source_id
6778                          ,p_khr_id              => l_khr_id )
6779     LOOP
6780       l_header_extension_id := t_rec.header_extension_id;
6781     END LOOP; -- End for c_header_extension_id_csr
6782 
6783     -- If l_header_extension_id is NOT NULL, then it means the KHR sources are already captured
6784     --   So, populate extension line sources only.
6785     -- Else Populate both the Extension Header and Line Sources.
6786     IF l_header_extension_id IS NULL
6787     THEN
6788       -- Prepare khr_source_rec_type with khr_id and ledger_language
6789       l_khr_source_rec.khr_id            := l_khr_id;
6790       -- Calling populate_khr_sources to fetch the KHR Sources
6791       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6792         'Calling the populate_khr_sources' );
6793       populate_khr_sources(
6794          p_api_version      => l_api_version
6795         ,p_init_msg_list    => p_init_msg_list
6796         ,x_khr_source_rec   => l_khr_source_rec
6797         ,x_led_lang_tbl     => l_led_lang_tbl
6798         ,x_return_status    => l_return_status
6799         ,x_msg_count        => x_msg_count
6800         ,x_msg_data         => x_msg_data );
6801       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6802         'After populate_khr_sources: l_return_status ' || l_return_status );
6803       -- Check the return status and if errored, return the error back
6804       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6805         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6806       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6807         RAISE OKL_API.G_EXCEPTION_ERROR;
6808       END IF;
6809       -- Assign the KHR Sources to the pxhv_rec
6810       assign_khr_rec_to_pxh_rec(
6811          p_khr_source_rec => l_khr_source_rec
6812         ,x_pxh_rec => l_pxh_rec );
6813 
6814       FOR tl_sources_in IN l_led_lang_tbl.FIRST .. l_led_lang_tbl.LAST
6815       LOOP
6816         l_pxhl_tbl(tl_sources_in).language          := l_led_lang_tbl(tl_sources_in).language;
6817         l_pxhl_tbl(tl_sources_in).contract_status   := l_led_lang_tbl(tl_sources_in).contract_status;
6818         l_pxhl_tbl(tl_sources_in).inv_agrmnt_status := l_led_lang_tbl(tl_sources_in).inv_agrmnt_status;
6819 
6820         -- Fetch transaction type name wrt ledger language
6821         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6822           'Executing the Cursor c_trx_type_name_csr. p_try_id=' ||
6823           l_try_id || 'p_led_lang= ' || l_pxhl_tbl(tl_sources_in).language );
6824         FOR t_rec IN c_trx_type_name_csr(
6825                       p_try_id    => l_try_id
6826                      ,p_led_lang  => l_pxhl_tbl(tl_sources_in).language )
6827         LOOP
6828           l_pxhl_tbl(tl_sources_in).transaction_type_name := t_rec.transaction_type_name;
6829           -- Assign the Trx. Type Class Code also.
6830           l_pxh_rec.trx_type_class_code  := t_rec.trx_type_class_code;
6831         END LOOP; -- End for c_trx_type_name_csr
6832       END LOOP;
6833 
6834       IF(p_acc_sources_rec.jtf_sales_reps_pk IS NOT NULL AND
6835          p_acc_sources_rec.jtf_sales_reps_pk <> OKL_API.G_MISS_CHAR) THEN
6836          -- Need to populate the Sales Representative Name
6837          put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6838            'Executing the Cursor  c_sales_rep_acc_sources_csr. l_sales_rep_id = ' ||
6839              TO_CHAR(p_acc_sources_rec.jtf_sales_reps_pk) );
6840          FOR t_rec IN  c_sales_rep_acc_sources_csr (p_jtf_sales_rep_pk => p_acc_sources_rec.jtf_sales_reps_pk)
6841          LOOP
6842            l_pxh_rec.sales_rep_name := t_rec.name;
6843          END LOOP;  -- c_sales_rep_acc_sources_csr
6844       END IF;
6845 
6846       -- Fetch the Transaction Number
6847       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6848         'Executing the Cursor c_trans_number_csr. p_header_source_id=' || l_header_source_id );
6849       FOR t_rec IN c_trans_number_csr( p_header_source_id => l_header_source_id )
6850       LOOP
6851         l_pxh_rec.trans_number := t_rec.trans_number;
6852       END LOOP; -- End for c_trans_number_csr
6853       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
6854         'Calling the okl_ap_extension_pvt.create_pxh_extension ' || l_pxh_rec.source_id );
6855       okl_ap_extension_pvt.create_pxh_extension(
6856          p_api_version     => l_api_version
6857         ,p_init_msg_list   => p_init_msg_list
6858         ,x_return_status   => l_return_status
6859         ,x_msg_count       => x_msg_count
6860         ,x_msg_data        => x_msg_data
6861         ,p_pxh_rec         => l_pxh_rec
6862         ,p_pxhl_tbl        => l_pxhl_tbl
6863         ,x_pxh_rec         => lx_pxh_rec
6864         ,x_pxhl_tbl        => lx_pxhl_tbl
6865       );
6866       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6867         'After okl_ap_extension_pvt.create_pxh_extension: l_return_status ' || l_return_status );
6868       -- Check the return status and if errored, return the error back
6869       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6870         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6871       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6872         RAISE OKL_API.G_EXCEPTION_ERROR;
6873       END IF;
6874       -- Store the Header Extension ID into the Local Variable l_header_extension_id
6875       l_header_extension_id := lx_pxh_rec.header_extension_id;
6876     END IF;
6877     IF l_kle_id IS NOT NULL OR
6878        l_kle_id <> OKL_API.G_MISS_NUM
6879     THEN
6880       -- Start populating the Sources at the Extension Line Level
6881       -- Prepare kle_source_rec_type with khr_id, kle_id and ledger_language
6882       l_kle_source_rec.khr_id            := l_khr_id;
6883       l_kle_source_rec.kle_id            := l_kle_id;
6884       IF l_line_style = 'SUBSIDY'
6885       THEN
6886         -- If the Line Style is SUBSIDY, then pass the Asset line id to the
6887         --  Populate KLE Sources to fetch the Asset Details
6888         l_kle_source_rec.kle_id            := l_parent_line_id;
6889       END IF;
6890       -- l_kle_source_rec.ledger_language   := l_ledger_language;
6891       -- Calling populate_kle_sources
6892       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6893         'Before Calling the populate_kle_sources' );
6894       populate_kle_sources(
6895         p_api_version      => l_api_version
6896        ,p_init_msg_list    => p_init_msg_list
6897        ,x_kle_source_rec   => l_kle_source_rec
6898        ,x_return_status    => l_return_status
6899        ,x_msg_count        => x_msg_count
6900        ,x_msg_data         => x_msg_data );
6901       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6902         'After populate_kle_sources: l_return_status ' || l_return_status );
6903       -- Check the return status and if errored, return the error back
6904       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
6905         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
6906       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
6907         RAISE OKL_API.G_EXCEPTION_ERROR;
6908       END IF;
6909       -- calling assign_kle_rec_to_pxlv_rec
6910       assign_kle_rec_to_pxl_rec(
6911          p_kle_source_rec => l_kle_source_rec
6912          ,x_pxl_rec => l_pxl_rec );
6913 
6914       -- Fetch fee type code
6915       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6916         'Executing the curosr c_k_lines_csr. p_kle_id= ' || TO_CHAR(l_kle_id));
6917       FOR t_rec  IN c_k_lines_csr ( p_kle_id => l_kle_id )
6918       LOOP
6919         l_pxl_rec.fee_type_code := t_rec.fee_type;
6920       END LOOP;  -- End for c_k_lines_csr
6921     --ELSE
6922       -- Populate the l_pxlv_rec with the khr_id, ledger_language
6923       -- but not with the kle_id
6924       --l_pxlv_rec.language := l_ledger_language ;
6925     END IF; -- IF l_kle_id IS NOT NULL OR l_kle_id <> OKL_API.G_MISS_NUM
6926 
6927     -- Stamp the Header Extension ID on the Extension Line Table
6928     l_pxl_rec.header_extension_id := l_header_extension_id;
6929 
6930     -- Fetch the Account Template ID
6931     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6932       'Executing the curosr c_account_dist_csr. p_source_id= ' || to_char(l_source_id)
6933       || ' p_source_table= ' || to_char(l_source_table));
6934     FOR t_rec  IN c_account_dist_csr (
6935                     p_source_id    => l_source_id
6936                    ,p_source_table => l_source_table)
6937     LOOP
6938       l_template_id := t_rec.template_id;
6939     END LOOP;  -- End for c_account_dist_csr
6940 
6941     -- Assigning the Memo Indicator to the Extension Line Record structure ..
6942     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6943       '** AGS Memo Flag ' || p_acc_sources_rec.memo_yn );
6944     l_pxl_rec.memo_flag := p_acc_sources_rec.memo_yn;
6945 
6946     -- Fetch Memo Flag and Accounting Template Name using the template_id
6947     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6948       'Executing the curosr c_ae_templates_csr. template_id= ' || to_char(l_template_id) );
6949     FOR t_rec  IN c_ae_templates_csr (p_template_id => l_template_id)
6950     LOOP
6951       l_pxl_rec.accounting_template_name := t_rec.name;
6952     END LOOP;  -- End for c_ae_templates_csr
6953 
6954     -- Fetch stream type code and stream type purpose code
6955     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6956       'Executing the curosr c_contingency_strm_b_csr. p_sty_id= ' || TO_CHAR(l_sty_id));
6957     FOR t_rec  IN c_contingency_strm_b_csr ( p_sty_id => l_sty_id )
6958     LOOP
6959       l_pxl_rec.stream_type_code         := t_rec.stream_type_code;
6960       l_pxl_rec.stream_type_purpose_code := t_rec.stream_type_purpose;
6961     END LOOP;  -- End for c_contingency_strm_b_csr
6962 
6963     -- Fetch stream type name
6964     FOR tl_sources_in IN l_pxll_tbl.FIRST .. l_pxll_tbl.LAST
6965     LOOP
6966       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6967         'Executing the curosr c_strm_name_tl_csr. p_sty_id= ' || TO_CHAR(l_sty_id)
6968         || ' Ledger Language = ' || l_pxll_tbl(tl_sources_in).language);
6969       FOR t_rec  IN c_strm_name_tl_csr ( p_sty_id => l_sty_id, p_lang => l_pxll_tbl(tl_sources_in).language )
6970       LOOP
6971         l_pxll_tbl(tl_sources_in).stream_type_name := t_rec.stream_type_name;
6972       END LOOP;  -- End for c_strm_name_tl_csr
6973       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6974         'Executing the curosr c_txl_ap_inv_desc_csr. p_tpld_id= ' || TO_CHAR(l_source_id)
6975         || ' p_lang = ' || l_pxll_tbl(tl_sources_in).language);
6976       FOR t_rec IN c_txl_ap_inv_desc_csr (
6977                      p_tpld_id   => l_source_id
6978                     ,p_lang      => l_pxll_tbl(tl_sources_in).language )
6979       LOOP
6980         l_pxll_tbl(tl_sources_in).trans_line_description := t_rec.trans_line_description;
6981       END LOOP;
6982     END LOOP;
6983 
6984     -- Fetch asset category name
6985     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
6986       'Executing the curosr c_manufacture_model_csr. p_kle_id= ' || TO_CHAR(l_kle_id)
6987       || ' p_khr_id= ' || TO_CHAR(l_khr_id));
6988     FOR t_rec  IN c_manufacture_model_csr ( p_kle_id => l_kle_id, p_khr_id => l_khr_id )
6989     LOOP
6990       l_pxl_rec.asset_category_name := t_rec.asset_category_name;
6991     END LOOP;  -- End for c_manufacture_model_csr
6992 
6993     IF(p_acc_sources_rec.inventory_org_id_pk2 IS NOT NULL AND
6994        p_acc_sources_rec.inventory_org_id_pk2 <> OKL_API.G_MISS_CHAR AND
6995        p_acc_sources_rec.inventory_item_id_pk1 IS NOT NULL AND
6996        p_acc_sources_rec.inventory_item_id_pk1 <> OKL_API.G_MISS_CHAR) THEN
6997       FOR tl_sources_in IN l_pxll_tbl.FIRST .. l_pxll_tbl.LAST
6998       LOOP
6999         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7000           'Executing the Cursor c_inventory_item_name_csr. p_inventory_item_id_pk1= ' ||
7001           to_char(p_acc_sources_rec.inventory_item_id_pk1) || ' p_inventory_org_id_pk2=' ||
7002           to_char(p_acc_sources_rec.inventory_org_id_pk2) || ' ledger_language=' ||
7003           l_pxll_tbl(tl_sources_in).language );
7004         FOR t_rec IN c_inventory_item_name_csr(
7005                      p_inventory_item_id_pk1 => p_acc_sources_rec.inventory_item_id_pk1
7006                     ,p_inventory_org_id_pk2  => p_acc_sources_rec.inventory_org_id_pk2
7007                     ,p_ledger_language       => l_pxll_tbl(tl_sources_in).language)
7008         LOOP
7009           l_pxll_tbl(tl_sources_in).inventory_item_name      := t_rec.description;
7010           l_pxl_rec.inventory_item_name_code := t_rec.b_description;
7011         END LOOP;
7012       END LOOP;
7013     END IF;
7014     IF(p_acc_sources_rec.inventory_org_id_pk2 IS NOT NULL AND
7015        p_acc_sources_rec.inventory_org_id_pk2 <> OKL_API.G_MISS_CHAR) THEN
7016        -- Populate Inventory Organization Name
7017        put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7018          '*** AGS Inventory Org ID used to fetch teh Inventory Organization Code : Org ID=' ||
7019          p_acc_sources_rec.inventory_org_id_pk2 );
7020        put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7021          'Executing the Cursor c_org_name_code_csr. p_org_id= ' || TO_CHAR(p_acc_sources_rec.inventory_org_id_pk2) );
7022        FOR t_rec IN c_org_name_code_csr(
7023                        p_org_id      => p_acc_sources_rec.inventory_org_id_pk2 )
7024        LOOP
7025          l_pxl_rec.inventory_org_code := t_rec.org_name;
7026        END LOOP;
7027 
7028        FOR tl_sources_in IN l_pxll_tbl.FIRST .. l_pxll_tbl.LAST
7029        LOOP
7030          put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7031            'Executing the Cursor c_org_name_csr. p_org_id= ' || TO_CHAR(p_acc_sources_rec.inventory_org_id_pk2) ||
7032            ' ledger_language=' || l_pxll_tbl(tl_sources_in).language );
7033          FOR t_rec IN c_org_name_csr(
7034                          p_org_id      => p_acc_sources_rec.inventory_org_id_pk2
7035                         ,p_ledger_lang => l_pxll_tbl(tl_sources_in).language )
7036          LOOP
7037            l_pxll_tbl(tl_sources_in).inventory_org_name := t_rec.org_name;
7038          END LOOP;
7039        END LOOP;
7040     END IF;
7041 
7042     -- Calling insert_row
7043     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7044       'Calling the okl_ap_extension_pvt.create_pxl_extension source_id=' || l_pxl_rec.source_id );
7045     okl_ap_extension_pvt.create_pxl_extension(
7046        p_api_version     => l_api_version
7047       ,p_init_msg_list   => p_init_msg_list
7048       ,x_return_status   => l_return_status
7049       ,x_msg_count       => x_msg_count
7050       ,x_msg_data        => x_msg_data
7051       ,p_pxl_rec         => l_pxl_rec
7052       ,p_pxll_tbl        => l_pxll_tbl
7053       ,x_pxl_rec         => lx_pxl_rec
7054       ,x_pxll_tbl        => lx_pxll_tbl
7055      );
7056     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7057       'After okl_ap_extension_pvt.create_pxl_extension: l_return_status ' || l_return_status );
7058     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
7059       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7060     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7061       RAISE OKL_API.G_EXCEPTION_ERROR;
7062     END IF;
7063     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7064       'Calling okl_api.end_activity');
7065     okl_api.end_activity(
7066        x_msg_count => x_msg_count
7067       ,x_msg_data  => x_msg_data);
7068     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7069       'END OKL_SLA_ACC_SOURCES_PVT.populate_ap_sources');
7070     x_return_status := OKL_API.G_RET_STS_SUCCESS;
7071   EXCEPTION
7072     ------------------------------------------------------------
7073     -- Exception handling
7074     ------------------------------------------------------------
7075     WHEN OKL_API.G_EXCEPTION_ERROR
7076     THEN
7077       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7078                             p_api_name  => l_api_name
7079                            ,p_pkg_name  => G_PKG_NAME
7080                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
7081                            ,x_msg_count  => x_msg_count
7082                            ,x_msg_data  => x_msg_data
7083                            ,p_api_type  => '_PVT');
7084     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
7085     THEN
7086       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7087                             p_api_name  => l_api_name
7088                            ,p_pkg_name  => G_PKG_NAME
7089                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
7090                            ,x_msg_count  => x_msg_count
7091                            ,x_msg_data  => x_msg_data
7092                            ,p_api_type  => '_PVT');
7093     WHEN OTHERS
7094     THEN
7095       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7096                             p_api_name  => l_api_name
7097                            ,p_pkg_name  => G_PKG_NAME
7098                            ,p_exc_name  => 'OTHERS'
7099                            ,x_msg_count  => x_msg_count
7100                            ,x_msg_data  => x_msg_data
7101                            ,p_api_type  => '_PVT');
7102   END populate_ap_sources;
7103 
7104   ------------------------------------------------------------------------------
7105   -- Start of comments
7106   --      API name        : populate_sources
7107   --      Pre-reqs        : None
7108   --      Function        : populate sources for OKL AP Transactions
7109   --      Parameters      :
7110   --      IN              :
7111   --                        pxhv_rec_type.source_id            IN NUMBER    Required
7112   --                        pxhv_rec_type.source_table         IN VARCHAR2  Required
7113   --      History         : Prashant Jain created
7114   --      Version         : 1.0
7115   -- End of comments
7116   ------------------------------------------------------------------------------
7117   PROCEDURE populate_sources(
7118     p_api_version           IN        NUMBER
7119    ,p_init_msg_list         IN        VARCHAR2
7120    ,p_pxhv_rec              IN        pxhv_rec_type
7121    ,p_pxlv_tbl              IN        pxlv_tbl_type
7122    ,p_acc_sources_tbl       IN        asev_tbl_type
7123    ,x_return_status         OUT       NOCOPY  VARCHAR2
7124    ,x_msg_count             OUT       NOCOPY  NUMBER
7125    ,x_msg_data              OUT       NOCOPY  VARCHAR2
7126   )
7127   IS
7128     -- Cursor to fetch source_id, khr_id, kle_id,
7129     -- sty_id, try_id
7130     CURSOR c_ap_fcase_csr (p_header_source_id NUMBER)
7131     IS
7132       SELECT    tpl.id                    source_id
7133                ,'OKL_TXL_AP_INV_LNS_B'    source_table
7134                ,tpl.khr_id                khr_id
7135                ,tpl.kle_id                kle_id
7136                ,tpl.sty_id                sty_id
7137                ,tap.try_id                try_id
7138                ,tap.vendor_invoice_number trans_number
7139        FROM     okl_trx_ap_invoices_b tap
7140                ,okl_txl_ap_inv_lns_b  tpl
7141       WHERE     tap.id = tpl.tap_id
7142         AND     tap.id = p_header_source_id;
7143 
7144     -- Data structures based on the Cursor Variables
7145     TYPE c_ap_fcase_tbl IS TABLE OF c_ap_fcase_csr%ROWTYPE
7146       INDEX BY BINARY_INTEGER;
7147     l_ap_fcase_tbl             c_ap_fcase_tbl;
7148     tld_count                  NUMBER; -- Count of the l_ap_fcase_tbl
7149     tld_index                  NUMBER; -- Index for the l_ap_fcase_tbl
7150     pxl_index                  NUMBER; -- Index for the l_pxlv_tbl
7151     l_acc_srcs_index           NUMBER; -- Index for the p_acc_sources_tbl
7152     l_capture_sources          VARCHAR2(3); -- Flag to decide whether to Capture Sources or Not !
7153     -----------------------------------------------------------------
7154     -- Declare Process Variable
7155     -----------------------------------------------------------------
7156     l_api_version          CONSTANT NUMBER         := 1;
7157     l_api_name             CONSTANT VARCHAR2(30)   := 'POPULATE_SOURCES-AP';
7158     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
7159 
7160     -----------------------------------------------------------------
7161     -- Local Variables
7162     -----------------------------------------------------------------
7163     l_header_source_id            NUMBER;
7164     l_header_source_table         VARCHAR2(30);
7165     l_pxhv_rec                    pxhv_rec_type;
7166     l_pxlv_rec                    pxlv_rec_type;
7167     l_pxlv_tbl                    pxlv_tbl_type;
7168     -- Local Variables for enabling the Debug Statements
7169     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
7170     l_debug_enabled       VARCHAR2(10);
7171     is_debug_procedure_on BOOLEAN;
7172     is_debug_statement_on BOOLEAN;
7173   BEGIN
7174     l_debug_enabled := okl_debug_pub.check_log_enabled;
7175     -- check for logging on PROCEDURE level
7176     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
7177     -- check for logging on STATEMENT level
7178     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
7179     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7180                'begin debug OKLRSLAB.pls call ' || l_api_name);
7181     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7182                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
7183     l_return_status := OKL_API.G_RET_STS_SUCCESS;
7184     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7185       'Calling OKL_API.START_ACTIVITY');
7186     l_return_status := OKL_API.START_ACTIVITY(
7187                          p_api_name       => l_api_name
7188                         ,p_pkg_name       => g_pkg_name
7189                         ,p_init_msg_list  => p_init_msg_list
7190                         ,l_api_version    => l_api_version
7191                         ,p_api_version    => p_api_version
7192                         ,p_api_type       => '_PVT'
7193                         ,x_return_status  => l_return_status);
7194     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
7195       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7196     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7197       RAISE OKL_API.G_EXCEPTION_ERROR;
7198     END IF;
7199 
7200     -- Validation 1: Source ID and Source Table should not be NULL in the
7201     --   AP Extension Header Record Structure
7202     IF (p_pxhv_rec.source_id      IS NULL OR
7203         p_pxhv_rec.source_table   IS NULL)
7204     THEN
7205       OKL_API.set_message(
7206          p_app_name      => G_APP_NAME
7207         ,p_msg_name      => G_INVALID_VALUE
7208         ,p_token1        => G_COL_NAME_TOKEN
7209         ,p_token1_value  => 'HEADER.SOURCE_ID_TABLE');
7210       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7211       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7212     END IF;
7213 
7214     -- Validation 2: The Header Source Table should be the
7215     --  OKL AP Invoice Trx Header . Header table only
7216     --   ie. it should be okl_trx_ap_invoices_b only
7217     IF (p_pxhv_rec.source_table <> G_TRX_AP_INVOICES_B)
7218     THEN
7219       OKL_API.set_message(
7220          p_app_name      => G_APP_NAME
7221         ,p_msg_name      => G_INVALID_VALUE
7222         ,p_token1        => G_COL_NAME_TOKEN
7223         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
7224       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7225       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7226     END IF;
7227 
7228     -- Copy to local variables
7229     l_pxhv_rec            := p_pxhv_rec;
7230     l_header_source_id    := p_pxhv_rec.source_id;
7231     l_header_source_table := p_pxhv_rec.source_table;
7232     l_pxlv_tbl            := p_pxlv_tbl;
7233     -- Validation 3: There should be atleast one Transaction Detail Line
7234     --  for which the Populate AP Sources should be called
7235     IF l_pxlv_tbl.COUNT = 0
7236     THEN
7237       OKL_API.set_message(
7238          p_app_name      => G_APP_NAME
7239         ,p_msg_name      => G_INVALID_VALUE
7240         ,p_token1        => G_COL_NAME_TOKEN
7241         ,p_token1_value  => 'PXLV_TBL.COUNT()');
7242       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7243       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7244     END IF;
7245 
7246     -- Validation 4: p_pxlv_tbl.COUNT should be equal to the p_acc_sources_tbl.COUNT
7247     IF l_pxlv_tbl.COUNT <> p_acc_sources_tbl.COUNT
7248     THEN
7249       OKL_API.set_message(
7250          p_app_name      => G_APP_NAME
7251         ,p_msg_name      => G_INVALID_VALUE
7252         ,p_token1        => G_COL_NAME_TOKEN
7253         ,p_token1_value  => 'P_ACC_SOURCES_TBL.COUNT()');
7254       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7255       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7256     END IF;
7257 
7258     -- Loop on the details for the current transaction header
7259     -- Call the populate_ap_sources
7260       -- As we wanted to store the records in the PL/SQL table starting from 1
7261       -- and after the loop, the tld_index should be nothing but the count of the
7262       -- Transaction Detail Lines fetched ...
7263       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7264         'Executing the Cursor c_ap_fcase_csr. p_header_source_id=' ||
7265            TO_CHAR(l_header_source_id));
7266       -- Initialize the tld_count to ZERO
7267       tld_count  := 0;
7268       FOR t_rec IN c_ap_fcase_csr( p_header_source_id => l_header_source_id )
7269       LOOP
7270         -- Increment the tld_count
7271         tld_count := tld_count + 1;
7272         -- Store the Current Record in the PL/SQL Table for further usage
7273         l_ap_fcase_tbl(tld_count) := t_rec;
7274       END LOOP;
7275       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7276         'Number of Transaction Detail Lines present in DB     = ' || TO_CHAR(tld_count) );
7277       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7278         'Number of Transaction Detail Lines passed to the API = ' || TO_CHAR(l_pxlv_tbl.COUNT) );
7279       FOR tld_index IN l_ap_fcase_tbl.FIRST .. l_ap_fcase_tbl.LAST
7280       LOOP
7281         -- Logic Explanation:
7282         -- 1. Check for the Count of the Trx. Detail Lines fetched from DB
7283         -- 2. Compare this count with the count of Trx. Detail Lines passed to this API
7284         -- 3. If the count is same, then, capture sources for every Trx. Detail Line
7285         --    otherwise, capture sources for only those transaction detail line, which have
7286         --    been passed by the Accounting Engine
7287         l_capture_sources := 'N';
7288         l_acc_srcs_index  := NULL;
7289         pxl_index := l_pxlv_tbl.FIRST;
7290         LOOP
7291           IF l_pxlv_tbl(pxl_index).source_id    = l_ap_fcase_tbl(tld_index).source_id AND
7292              l_pxlv_tbl(pxl_index).source_table = l_ap_fcase_tbl(tld_index).source_table
7293           THEN
7294             -- Need to the Call the Populate AP Sources for this Transaction Detail Line
7295             l_capture_sources := 'Y';
7296             -- Assumption: p_pxlv_tbl and p_acc_sources_tbl are populated using the Same Index.
7297             l_acc_srcs_index  := pxl_index;
7298             put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7299               'Case 2: Populate Sources has been asked to capture sources for the Current Transaction Detail by Accounting Engine ' ||
7300               ' TXD ID = ' || TO_CHAR( l_ap_fcase_tbl(tld_index).source_id ) );
7301           END IF;
7302           -- Exit when this is the Last Record or the Transaction Details has been found
7303           EXIT WHEN ( pxl_index = l_pxlv_tbl.LAST )  -- When reached End of the Table
7304                  OR ( l_capture_sources = 'Y'     ); -- Or When the TXD has been found
7305           -- Increment the pxl_index
7306           pxl_index := l_pxlv_tbl.NEXT( pxl_index );
7307         END LOOP; -- Loop on l_pxlv_tbl ..
7308 
7309         IF l_capture_sources = 'Y'
7310         THEN
7311           -- If the AGS Index is not found then return error
7312           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7313             'Account Generator Sources Index =' || TO_CHAR(l_acc_srcs_index)  );
7314           IF l_acc_srcs_index IS NULL OR
7315              ( p_acc_sources_tbl.EXISTS(l_acc_srcs_index) = FALSE )
7316           THEN
7317             -- accounting_event_class_code is missing
7318             OKL_API.set_message(
7319                p_app_name      => G_APP_NAME
7320               ,p_msg_name      => G_INVALID_VALUE
7321               ,p_token1        => G_COL_NAME_TOKEN
7322               ,p_token1_value  => 'AGS_SOURCES_INDEX');
7323             l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7324             RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7325           END IF; -- IF l_acc_sources_found = FALSE
7326 
7327           l_pxhv_rec.try_id       := l_ap_fcase_tbl(tld_index).try_id;
7328           l_pxhv_rec.khr_id       := l_ap_fcase_tbl(tld_index).khr_id;
7329           -- l_pxhv_rec.source_id and l_pxhv_rec.source_table are already assigned
7330           -- Id of Detail Line Table
7331           l_pxlv_rec.source_id := l_ap_fcase_tbl(tld_index).source_id;
7332           l_pxlv_rec.source_table := l_ap_fcase_tbl(tld_index).source_table;
7333           l_pxlv_rec.kle_id    := l_ap_fcase_tbl(tld_index).kle_id;
7334           l_pxlv_rec.sty_id    := l_ap_fcase_tbl(tld_index).sty_id;
7335           --l_pxhv_rec.trans_number := l_ap_fcase_tbl(tld_index).trans_number;
7336           -- The populate_ap_sources will capture sources at extension line level always
7337           -- If the extension header sources with the l_pxlv_rec.source_id and l_pxhv_rec.khr_id is not captured
7338           -- Then only capture the extension header sources
7339           -- Calling populate_ap_sources
7340           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7341             'Calling the populate_ap_sources' );
7342           populate_ap_sources(
7343             p_api_version       => l_api_version
7344            ,p_init_msg_list     => p_init_msg_list
7345            ,p_pxhv_rec          => l_pxhv_rec
7346            ,p_pxlv_rec          => l_pxlv_rec
7347            ,p_acc_sources_rec   => p_acc_sources_tbl(l_acc_srcs_index)
7348            ,x_return_status     => l_return_status
7349            ,x_msg_count         => x_msg_count
7350            ,x_msg_data          => x_msg_data);
7351           put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7352             'After populate_ap_sources: l_return_status ' || l_return_status );
7353           -- Check the return status and if errored, return the error back
7354           IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
7355             RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7356           ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7357             RAISE OKL_API.G_EXCEPTION_ERROR;
7358           END IF;
7359         END IF; -- IF l_capture_sources = 'Y'
7360       END LOOP; -- Loop on l_ap_fcase_tbl ..
7361     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7362       'Calling okl_api.end_activity');
7363     okl_api.end_activity(
7364        x_msg_count => x_msg_count
7365       ,x_msg_data  => x_msg_data);
7366     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7367       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
7368     x_return_status := OKL_API.G_RET_STS_SUCCESS;
7369   EXCEPTION
7370     ------------------------------------------------------------
7371     -- Exception handling
7372     ------------------------------------------------------------
7373     WHEN OKL_API.G_EXCEPTION_ERROR
7374     THEN
7375       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7376                             p_api_name  => l_api_name
7377                            ,p_pkg_name  => G_PKG_NAME
7378                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
7379                            ,x_msg_count  => x_msg_count
7380                            ,x_msg_data  => x_msg_data
7381                            ,p_api_type  => '_PVT');
7382     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
7383     THEN
7384       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7385                            p_api_name  => l_api_name
7386                           ,p_pkg_name  => G_PKG_NAME
7387                           ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
7388                           ,x_msg_count  => x_msg_count
7389                           ,x_msg_data  => x_msg_data
7390                            ,p_api_type  => '_PVT');
7391     WHEN OTHERS
7392     THEN
7393       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7394                             p_api_name  => l_api_name
7395                            ,p_pkg_name  => G_PKG_NAME
7396                            ,p_exc_name  => 'OTHERS'
7397                            ,x_msg_count  => x_msg_count
7398                            ,x_msg_data  => x_msg_data
7399                            ,p_api_type  => '_PVT');
7400   END populate_sources;
7401 
7402   PROCEDURE delete_ap_extension(
7403     p_api_version               IN              NUMBER
7404    ,p_init_msg_list             IN              VARCHAR2
7405    ,p_pxhv_rec                  IN              pxhv_rec_type
7406    ,x_pxlv_tbl                  OUT    NOCOPY   pxlv_tbl_type
7407    ,x_return_status             OUT    NOCOPY  VARCHAR2
7408    ,x_msg_count                 OUT    NOCOPY  NUMBER
7409    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
7410   )
7411   IS
7412     -----------------------------------------------------------------
7413     -- Declare Process Variable
7414     -----------------------------------------------------------------
7415     l_api_version      CONSTANT NUMBER         := 1;
7416     l_api_name         CONSTANT VARCHAR2(30)   := 'DELETE_AP_EXTENSION';
7417     l_return_status    VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
7418     pxl_index          BINARY_INTEGER;
7419     l_pxhv_rec         okl_pxh_pvt.pxhv_rec_type;
7420     l_pxlv_tbl         okl_pxl_pvt.pxlv_tbl_type;
7421     lx_pxhv_rec        okl_pxh_pvt.pxhv_rec_type;
7422     lx_pxlv_tbl        okl_pxl_pvt.pxlv_tbl_type;
7423     -- Cursor Definitions
7424     CURSOR get_ap_ext_hdr_id( p_source_id  NUMBER, p_source_table VARCHAR2)
7425     IS
7426       SELECT   pxh.header_extension_id      header_extension_id
7427         FROM   okl_ext_ap_header_sources_b	pxh
7428        WHERE   pxh.source_id = p_source_id
7429          AND   pxh.source_table = p_source_table;
7430 
7431     CURSOR get_ap_ext_lns_id( p_hdr_ext_id  NUMBER)
7432     IS
7433       SELECT   pxl.line_extension_id     line_extension_id
7434               ,pxl.source_id             source_id
7435               ,pxl.source_table          source_table
7436         FROM   okl_ext_ap_line_sources_b pxl
7437        WHERE   pxl.header_extension_id = p_hdr_ext_id;
7438     -- Local Variables for enabling the Debug Statements
7439     l_module              CONSTANT     fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
7440     l_debug_enabled                    VARCHAR2(10);
7441     is_debug_procedure_on              BOOLEAN;
7442     is_debug_statement_on              BOOLEAN;
7443   BEGIN
7444     l_debug_enabled := okl_debug_pub.check_log_enabled;
7445     -- check for logging on PROCEDURE level
7446     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
7447     -- check for logging on STATEMENT level
7448     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
7449     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7450                'begin debug OKLRSLAB.pls call ' || l_api_name);
7451     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7452                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.DELETE_AP_EXTENSION');
7453     l_return_status := OKL_API.G_RET_STS_SUCCESS;
7454     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7455       'Calling OKL_API.START_ACTIVITY');
7456     l_return_status := OKL_API.START_ACTIVITY(
7457                          p_api_name       => l_api_name
7458                         ,p_pkg_name       => g_pkg_name
7459                         ,p_init_msg_list  => p_init_msg_list
7460                         ,l_api_version    => l_api_version
7461                         ,p_api_version    => p_api_version
7462                         ,p_api_type       => '_PVT'
7463                         ,x_return_status  => l_return_status);
7464     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
7465       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7466     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7467       RAISE OKL_API.G_EXCEPTION_ERROR;
7468     END IF;
7469     -- Actual Logic Starts Here ..
7470     l_pxhv_rec := p_pxhv_rec;
7471     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7472       'Source ID=' || to_char(l_pxhv_rec.source_id) || 'Source Header Table=' || l_pxhv_rec.source_table );
7473     IF ( l_pxhv_rec.source_id = OKL_API.G_MISS_NUM or l_pxhv_rec.source_id IS NULL )
7474     THEN
7475       OKL_API.set_message(
7476          p_app_name      => G_APP_NAME
7477         ,p_msg_name      => G_INVALID_VALUE
7478         ,p_token1        => G_COL_NAME_TOKEN
7479         ,p_token1_value  => 'HEADER.SOURCE_ID');
7480       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7481       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7482     END IF;
7483     IF ( l_pxhv_rec.source_table = OKL_API.G_MISS_CHAR or l_pxhv_rec.source_table IS NULL
7484         OR l_pxhv_rec.source_table NOT IN ( G_TRX_AP_INVOICES_B) )
7485     THEN
7486       OKL_API.set_message(
7487          p_app_name      => G_APP_NAME
7488         ,p_msg_name      => G_INVALID_VALUE
7489         ,p_token1        => G_COL_NAME_TOKEN
7490         ,p_token1_value  => 'HEADER.SOURCE_TABLE');
7491       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7492       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7493     END IF;
7494     -- Initialize the pxl_index
7495     pxl_index := 1;
7496     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7497       'Fetch the Extension Header ID by executing cursor get_ap_ext_hdr_id' );
7498     FOR t_rec IN get_ap_ext_hdr_id(
7499                     p_source_id     => l_pxhv_rec.source_id
7500                    ,p_source_table  => l_pxhv_rec.source_table)
7501     LOOP
7502       -- Note that for a given Source ID and Source Table in OKL_EXT_AP_HEADER_SOURCES_B
7503       --  there can be multiple records each having different KHR_ID ..
7504       l_pxhv_rec.header_extension_id := t_rec.header_extension_id;
7505       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7506         'Extension Header ID To be Deleted='  || TO_CHAR(l_pxhv_rec.header_extension_id));
7507       -- Fetch the Transaction Extension Line IDs to be deleted
7508       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7509         'Extension Line ID(s) To be Deleted=');
7510       FOR t_rec IN get_ap_ext_lns_id( p_hdr_ext_id  => l_pxhv_rec.header_extension_id)
7511       LOOP
7512         l_pxlv_tbl(pxl_index).line_extension_id  := t_rec.line_extension_id;
7513         l_pxlv_tbl(pxl_index).source_id          := t_rec.source_id;
7514         l_pxlv_tbl(pxl_index).source_table       := t_rec.source_table;
7515         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7516           'LINE_EXTENSION_ID[' || pxl_index || '] = ' || TO_CHAR(l_pxlv_tbl(pxl_index).line_extension_id) );
7517         -- Increment i
7518         pxl_index := pxl_index + 1;
7519       END LOOP; -- End get_trans_line_ids
7520       -- Call the Wrapper API to delete the Extension Lines and then Header
7521       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7522         'calling the okl_ap_extension_pvt.delete_pxh_extension Line Count=' || l_pxlv_tbl.COUNT );
7523       okl_ap_extension_pvt.delete_pxh_extension(
7524         p_api_version     => p_api_version
7525        ,p_init_msg_list   => p_init_msg_list
7526        ,x_return_status   => x_return_status
7527        ,x_msg_count       => x_msg_count
7528        ,x_msg_data        => x_msg_data
7529        ,p_pxhv_rec        => l_pxhv_rec
7530       );
7531       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7532         'After okl_ap_extension_pvt.delete_pxh_extension: l_return_status ' || l_return_status );
7533       -- Check the return status and if errored, return the error back
7534       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
7535       THEN
7536         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7537       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7538         RAISE OKL_API.G_EXCEPTION_ERROR;
7539       END IF;
7540     END LOOP; -- Loop on the get_ap_ext_hdr_id
7541     -- Store the Transaction Line IDs and Line Source Tables so as to return back
7542     x_pxlv_tbl := l_pxlv_tbl;
7543     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7544       'Calling okl_api.end_activity');
7545     okl_api.end_activity(
7546        x_msg_count => x_msg_count
7547       ,x_msg_data  => x_msg_data);
7548     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7549       'END OKL_SLA_ACC_SOURCES_PVT.DELETE_AP_EXTENSION');
7550     x_return_status := OKL_API.G_RET_STS_SUCCESS;
7551   EXCEPTION
7552     ------------------------------------------------------------
7553     -- Exception handling
7554     ------------------------------------------------------------
7555     WHEN OKL_API.G_EXCEPTION_ERROR
7556     THEN
7557       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7558                             p_api_name  => l_api_name
7559                            ,p_pkg_name  => G_PKG_NAME
7560                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
7561                            ,x_msg_count => x_msg_count
7562                            ,x_msg_data  => x_msg_data
7563                            ,p_api_type  => '_PVT');
7564     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
7565     THEN
7566       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7567                             p_api_name  => l_api_name
7568                            ,p_pkg_name  => G_PKG_NAME
7569                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
7570                            ,x_msg_count => x_msg_count
7571                            ,x_msg_data  => x_msg_data
7572                            ,p_api_type  => '_PVT');
7573     WHEN OTHERS
7574     THEN
7575      x_return_status := OKL_API.HANDLE_EXCEPTIONS (
7576                             p_api_name  => l_api_name
7577                            ,p_pkg_name  => G_PKG_NAME
7578                            ,p_exc_name  => 'OTHERS'
7579                            ,x_msg_count => x_msg_count
7580                            ,x_msg_data  => x_msg_data
7581                            ,p_api_type  => '_PVT');
7582   END delete_ap_extension;
7583   ------------------------------------------------------------------------------
7584   -- Start of comments
7585   --      API name        : populate_sources
7586   --      Pre-reqs        : None
7587   --      Function        : populate sources for OKL FA Depreciation Transactions
7588   --      Parameters      :
7589   --      IN              :
7590   --      History         : Prashant Jain created
7591   --      Version         : 1.0
7592   -- End of comments
7593   ------------------------------------------------------------------------------
7594   PROCEDURE populate_sources(
7595     p_api_version               IN             NUMBER
7596    ,p_init_msg_list             IN             VARCHAR2
7597    ,p_khr_id                    IN             NUMBER
7598    ,p_deprn_asset_tbl           IN             deprn_asset_tbl_type
7599    ,p_deprn_run_id              IN             NUMBER
7600    ,p_book_type_code            IN             VARCHAR2
7601    ,p_period_counter            IN             NUMBER
7602    ,x_return_status             OUT    NOCOPY  VARCHAR2
7603    ,x_msg_count                 OUT    NOCOPY  NUMBER
7604    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
7605   )
7606   IS
7607     -----------------------------------------------------------------
7608     -- Declare Process Variable
7609     -----------------------------------------------------------------
7610     l_api_version          CONSTANT NUMBER         := 1;
7611     l_api_name             CONSTANT VARCHAR2(30)   := 'POPULATE_SOURCES-DEPRN';
7612     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
7613     -----------------------------------------------------------------
7614     -- Local Variables
7615     -----------------------------------------------------------------
7616     l_khr_id               NUMBER;
7617     l_kle_id               NUMBER;
7618     l_asset_id             NUMBER;
7619     l_try_id               NUMBER;
7620     l_ledger_id            NUMBER;
7621     l_ledger_language      VARCHAR2(12);
7622     l_header_extension_id  NUMBER;
7623     l_pk_attributes        VARCHAR2(1000);
7624     l_deprn_asset_tbl      deprn_asset_tbl_type;
7625     l_inventory_org_name   VARCHAR2(240);
7626     l_inventory_org_code   VARCHAR2(240);
7627     l_line_index           NUMBER;
7628     -- KHR and KLE Based Record Structures
7629     l_khr_source_rec       khr_source_rec_type;
7630     l_kle_source_rec       kle_source_rec_type;
7631     -- Record structures based on FA Extension Header and Line Tables
7632     l_fxh_rec              okl_fxh_pvt.fxh_rec_type;
7633     lx_fxh_rec             okl_fxh_pvt.fxh_rec_type;
7634     l_fxhl_tbl             okl_fxh_pvt.fxhl_tbl_type;
7635     lx_fxhl_tbl            okl_fxh_pvt.fxhl_tbl_type;
7636     l_fxl_tbl_tbl          fxl_tbl_tbl_type;
7637     lx_fxl_tbl_tbl         fxl_tbl_tbl_type;
7638     l_fxl_tbl_tbl_out      fxl_tbl_tbl_type;
7639     l_fxl_rec              okl_fxl_pvt.fxl_rec_type;
7640     l_fxll_tbl             okl_fxl_pvt.fxll_tbl_type;
7641     l_null_fxl_rec         okl_fxl_pvt.fxl_rec_type;
7642     l_null_fxll_tbl        okl_fxl_pvt.fxll_tbl_type;
7643     l_led_lang_tbl         led_lang_tbl_type;
7644     -- Record structures based on the Cursor defintions
7645     l_sales_rep_csr_rec    c_sales_rep_csr%ROWTYPE;
7646     l_ledger_lang_rec      c_ledger_lang_csr%ROWTYPE;
7647     -- Local Variables for enabling the Debug Statements
7648     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
7649     l_debug_enabled       VARCHAR2(10);
7650     is_debug_procedure_on BOOLEAN;
7651     is_debug_statement_on BOOLEAN;
7652     tl_sources_in         NUMBER := 1;
7653 
7654 	l_rep_type            VARCHAR2(20);
7655 	l_book_type_name      VARCHAR2(30);
7656 
7657   BEGIN
7658     l_debug_enabled := okl_debug_pub.check_log_enabled;
7659     -- check for logging on PROCEDURE level
7660     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
7661     -- check for logging on STATEMENT level
7662     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
7663     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7664                'begin debug OKLRSLAB.pls call ' || l_api_name);
7665     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7666                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
7667     l_return_status := OKL_API.G_RET_STS_SUCCESS;
7668     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7669       'Calling OKL_API.START_ACTIVITY');
7670     l_return_status := OKL_API.START_ACTIVITY(
7671                          p_api_name       => l_api_name
7672                         ,p_pkg_name       => g_pkg_name
7673                         ,p_init_msg_list  => p_init_msg_list
7674                         ,l_api_version    => l_api_version
7675                         ,p_api_version    => p_api_version
7676                         ,p_api_type       => '_PVT'
7677                         ,x_return_status  => l_return_status);
7678     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
7679       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7680     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7681       RAISE OKL_API.G_EXCEPTION_ERROR;
7682     END IF;
7683     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7684       'Before Performing validations');
7685     -- Validations to be done:
7686     --  1. The following should be NOT NULL
7687     --     KHR_ID, Depreciation Run ID, Book Type Code, Period Name and Period Counter
7688     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7689       'Parameters Passed: ');
7690     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7691       'KHR_ID | DEPRN_RUN_ID ' );
7692     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7693       p_khr_id || ' | ' || p_deprn_run_id);
7694 
7695     l_pk_attributes := NULL;
7696     IF p_khr_ID IS NULL OR
7697        p_khr_ID = OKL_API.G_MISS_NUM
7698     THEN
7699       IF l_pk_attributes IS NOT NULL
7700       THEN
7701         l_pk_attributes := l_pk_attributes || ' , ';
7702       END IF;
7703       l_pk_attributes := l_pk_attributes || 'P_KHR_ID';
7704     END IF;
7705     IF p_deprn_run_id IS NULL OR
7706        p_deprn_run_id = OKL_API.G_MISS_NUM
7707     THEN
7708       IF l_pk_attributes IS NOT NULL
7709       THEN
7710         l_pk_attributes := l_pk_attributes || ' , ';
7711       END IF;
7712       l_pk_attributes := l_pk_attributes || 'P_DEPRN_RUN_ID';
7713     END IF;
7714     IF p_book_type_code IS NULL OR
7715        p_book_type_code = OKL_API.G_MISS_CHAR
7716     THEN
7717       IF l_pk_attributes IS NOT NULL
7718       THEN
7719         l_pk_attributes := l_pk_attributes || ' , ';
7720       END IF;
7721       l_pk_attributes := l_pk_attributes || 'P_BOOK_TYPE_CODE';
7722     END IF;
7723     IF p_period_counter IS NULL OR
7724        p_period_counter = OKL_API.G_MISS_NUM
7725     THEN
7726       IF l_pk_attributes IS NOT NULL
7727       THEN
7728         l_pk_attributes := l_pk_attributes || ' , ';
7729       END IF;
7730       l_pk_attributes := l_pk_attributes || 'P_PERIOD_COUNTER';
7731     END IF;
7732     IF LENGTH(l_pk_attributes) > 0
7733     THEN
7734       -- Raise an Exception
7735       OKL_API.set_message(
7736          p_app_name      => G_APP_NAME
7737         ,p_msg_name      => G_INVALID_VALUE
7738         ,p_token1        => G_COL_NAME_TOKEN
7739         ,p_token1_value  => l_pk_attributes);
7740       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7741       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7742     END IF;
7743     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7744       'Validation 1 Successfull !');
7745     -- Assign the p_deprn_asset_tbl to l_deprn_asset_tbl
7746     l_deprn_asset_tbl := p_deprn_asset_tbl;
7747     -- Validation 2: Atleast one KLE_ID has to be there to populate the source for ..
7748     IF l_deprn_asset_tbl.COUNT = 0
7749     THEN
7750       -- Raise an Exception
7751       OKL_API.set_message(
7752          p_app_name      => G_APP_NAME
7753         ,p_msg_name      => G_INVALID_VALUE
7754         ,p_token1        => G_COL_NAME_TOKEN
7755         ,p_token1_value  => 'P_DEPRN_ASSET_TBL.COUNT');
7756       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
7757       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7758     END IF;
7759 
7760     -- Copy the Input Parameters to the Local Variables
7761     l_khr_id  := p_khr_id;
7762     --l_try_id  := NULL;
7763 
7764     -- Need to stamp the Mandatory Columns Like
7765     -- KHR_ID, TRY_ID, SOURCE_ID, SOURCE_TABLE,
7766     -- initialize the local l_fxlv_rec to the input record values
7767     l_fxh_rec.khr_id := l_khr_id;
7768     l_fxh_rec.try_id := NULL;  -- Not sure what to be stamped here
7769     l_fxh_rec.source_id := p_deprn_run_id; -- For time being stamping the Deprn Run ID
7770     l_fxh_rec.source_table := G_FA_DEPRN_SUMMARY;
7771 
7772 	-- get the representation details based on book_type_code. MG uptake
7773 	OPEN get_reps_csr(p_book_type_code);
7774 	FETCH get_reps_csr INTO l_ledger_id, l_fxh_rec.representation_code,
7775 	                        l_fxh_rec.representation_name, l_rep_type;
7776     CLOSE get_reps_csr;
7777 
7778     IF l_rep_type is not null then
7779 	   g_representation_type := l_rep_type;
7780     ELSE
7781 	   g_representation_type := 'PRIMARY';
7782 	END IF;
7783 
7784 	/* commented as the ledger is obtained above.. MG Uptake.
7785     -- Fetch Ledger ID to fetch the Ledger Language associated to the contracts
7786     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7787       'Executing the Cursor c_khr_to_ledger_id_csr. p_khr_id=' || TO_CHAR(l_khr_id));
7788 
7789       FOR t_rec IN c_khr_to_ledger_id_csr( p_khr_id => l_khr_id )
7790       LOOP
7791         l_ledger_id := t_rec.ledger_id;
7792       END LOOP;
7793 	*/
7794 
7795     -- Using the Ledger ID fetch the Ledger Language
7796     -- Fetch the ledger language in order to populate the sources
7797     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7798       'Executing the Cursor c_ledger_lang_csr. p_ledger_id=' || TO_CHAR(l_ledger_id));
7799     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_ledger_id )
7800     LOOP
7801       l_ledger_lang_rec := t_rec;
7802       l_led_lang_tbl(tl_sources_in).language := t_rec.language_code;
7803       l_fxll_tbl(tl_sources_in).language     := t_rec.language_code;
7804       tl_sources_in := tl_sources_in + 1;
7805     END LOOP;
7806 
7807     -- Prepare khr_source_rec_type with khr_id and ledger_language
7808     l_khr_source_rec.khr_id            := l_khr_id;
7809 
7810     -- Calling populate_khr_sources
7811     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7812       'Calling the populate_khr_sources' );
7813     populate_khr_sources(
7814        p_api_version      => l_api_version
7815       ,p_init_msg_list    => p_init_msg_list
7816       ,x_khr_source_rec   => l_khr_source_rec
7817       ,x_led_lang_tbl     => l_led_lang_tbl
7818       ,x_return_status    => l_return_status
7819       ,x_msg_count        => x_msg_count
7820       ,x_msg_data         => x_msg_data );
7821     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7822       'After populate_khr_sources: l_return_status ' || l_return_status );
7823     -- Check the return status and if errored, return the error back
7824     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
7825       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7826     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7827       RAISE OKL_API.G_EXCEPTION_ERROR;
7828     END IF;
7829 
7830     --calling assign_khr_rec_to_fxhv_rec
7831     assign_khr_rec_to_fxh_rec(
7832        p_khr_source_rec => l_khr_source_rec
7833       ,x_fxh_rec        => l_fxh_rec );
7834 
7835     FOR tl_sources_in IN l_led_lang_tbl.FIRST .. l_led_lang_tbl.LAST
7836     LOOP
7837       l_fxhl_tbl(tl_sources_in).language          := l_led_lang_tbl(tl_sources_in).language;
7838       l_fxhl_tbl(tl_sources_in).contract_status   := l_led_lang_tbl(tl_sources_in).contract_status;
7839       -- l_fxhl_tbl(tl_sources_in).inv_agrmnt_status := l_led_lang_tbl(tl_sources_in).inv_agrmnt_status;
7840     END LOOP;
7841 
7842     -- Fetch and Populate Sales Representative Name
7843     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7844       'Executing the Cursor  c_sales_rep_csr. p_khr_id = ' || TO_CHAR(l_khr_id) );
7845     FOR t_rec IN  c_sales_rep_csr (l_khr_id)
7846     LOOP
7847       l_sales_rep_csr_rec := t_rec;
7848       l_fxh_rec.sales_rep_name := l_sales_rep_csr_rec.name;
7849     END LOOP; -- End for c_sales_rep_csr
7850 
7851     -- Fetch and Populate Inventory Organization Name
7852     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7853       'Executing Cursor c_inventory_org_id_csr : l_khr_id = ' ||to_char(l_khr_id));
7854     FOR t_rec IN c_inventory_org_id_csr (l_khr_id)
7855     LOOP
7856       -- Assign the Inventory Organization Code
7857       l_inventory_org_code := t_rec.hrb_name;
7858       FOR tl_sources_in IN l_fxll_tbl.FIRST .. l_fxll_tbl.LAST
7859       LOOP
7860         put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7861           'Executing Cursor c_org_name_csr : p_org_id = ' ||to_char(t_rec.inv_organization_id)
7862           || ' p_ledger_lang = ' || to_char(l_fxll_tbl(tl_sources_in).language));
7863         FOR t_org_rec IN c_org_name_csr (
7864                      p_org_id        => t_rec.inv_organization_id
7865                     ,p_ledger_lang   => l_fxll_tbl(tl_sources_in).language)
7866         LOOP
7867           l_fxll_tbl(tl_sources_in).inventory_org_name := t_org_rec.org_name;
7868         END LOOP; -- End for c_org_name_csr
7869       END LOOP;
7870     END LOOP; -- End for c_inventory_org_id_csr
7871 
7872     -- Calling insert_row
7873     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7874       'Calling the okl_fa_extension_pvt.create_fxh_extension ' || l_fxh_rec.source_id );
7875     okl_fa_extension_pvt.create_fxh_extension(
7876        p_api_version     => l_api_version
7877       ,p_init_msg_list   => p_init_msg_list
7878       ,x_return_status   => l_return_status
7879       ,x_msg_count       => x_msg_count
7880       ,x_msg_data        => x_msg_data
7881       ,p_fxh_rec         => l_fxh_rec
7882       ,x_fxh_rec         => lx_fxh_rec
7883       ,p_fxhl_tbl        => l_fxhl_tbl
7884       ,x_fxhl_tbl        => lx_fxhl_tbl
7885     );
7886     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7887       'After okl_fa_extension_pvt.create_fxh_extension: l_return_status ' || l_return_status );
7888     -- Check the return status and if errored, return the error back
7889     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
7890     THEN
7891       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7892     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7893       RAISE OKL_API.G_EXCEPTION_ERROR;
7894     END IF;
7895     -- Store the Header Extension ID in to the Local Variable: l_header_extension_id
7896     l_header_extension_id := lx_fxh_rec.header_extension_id;
7897     -- Initialize the l_line_index
7898     l_line_index := 1;
7899     -- Now Loop on the Depreciated Assets Table and Capture Sources at Line Level
7900     FOR i IN l_deprn_asset_tbl.FIRST .. l_deprn_asset_tbl.LAST
7901     LOOP
7902       -- First of all Nullify the l_fxlv_rec
7903       l_fxl_rec := l_null_fxl_rec;
7904       --l_fxll_tbl := l_null_fxll_tbl;
7905       -- Assign the Mandatory Fields first like header_extension_id, fa_transaction_id [Deprn Run Id]
7906       -- kle_id, Asset ID, Source ID and Source ID.
7907       l_fxl_rec.source_id           := p_deprn_run_id; -- For time bing stamping the Deprn Run ID
7908       l_fxl_rec.source_table        := G_FA_DEPRN_SUMMARY;
7909       l_fxl_rec.header_extension_id := l_header_extension_id;
7910       l_fxl_rec.fa_transaction_id   := p_deprn_run_id;
7911       l_fxl_rec.kle_id              := l_deprn_asset_tbl(i).kle_id;
7912       l_fxl_rec.asset_id            := l_deprn_asset_tbl(i).asset_id;
7913 
7914       -- Store now the optional columns [But predicates for Deprn Ref. Views] like
7915       -- Book Type Code, Period Name, Period Counter
7916       l_fxl_rec.asset_book_type_code := p_book_type_code;
7917       l_fxl_rec.period_counter       := p_period_counter;
7918 
7919       -- MG uptake.
7920 	  OPEN get_book_type_name(p_book_type_code);
7921 	  FETCH get_book_type_name into l_fxl_rec.asset_book_type_name;
7922 	  CLOSE get_book_type_name;
7923 
7924       -- Store the Asset and KLE_ID in the Local Varaibles for further Use
7925       l_kle_id   := l_deprn_asset_tbl(i).kle_id;
7926       l_asset_id := l_deprn_asset_tbl(i).asset_id;
7927       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
7928         'KLE_ID= ' || TO_CHAR( l_kle_id) || ' ASSET_ID= ' || l_asset_id );
7929 
7930       -- Prepare kle_source_rec_type with khr_id, kle_id and ledger_language
7931       l_kle_source_rec.khr_id            := l_khr_id;
7932       l_kle_source_rec.kle_id            := l_kle_id;
7933 
7934       -- Calling populate_kle_sources
7935       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7936         'Calling the populate_kle_sources' );
7937       populate_kle_sources(
7938         p_api_version      => l_api_version
7939        ,p_init_msg_list    => p_init_msg_list
7940        ,x_kle_source_rec   => l_kle_source_rec
7941        ,x_return_status    => l_return_status
7942        ,x_msg_count        => x_msg_count
7943        ,x_msg_data         => x_msg_data );
7944       put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7945         'After populate_kle_sources: l_return_status ' || l_return_status );
7946       -- Check the return status and if errored, return the error back
7947       IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
7948       THEN
7949         RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7950       ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
7951         RAISE OKL_API.G_EXCEPTION_ERROR;
7952       END IF;
7953       -- Assin the KLE Sources to the FA Extension Line
7954       assign_kle_rec_to_fxl_rec(
7955          p_kle_source_rec => l_kle_source_rec
7956         ,x_fxl_rec => l_fxl_rec );
7957 
7958       -- Stamp the Inventory Org Code and Name on the Asset Line
7959       l_fxl_rec.inventory_org_code := l_inventory_org_code;
7960       --l_fxl_rec.inventory_org_name := l_inventory_org_name;
7961       -- Store the Record Structure into the table
7962       l_fxl_tbl_tbl(l_line_index).fxl_rec := l_fxl_rec;
7963       l_fxl_tbl_tbl(l_line_index).fxll_tbl := l_fxll_tbl;
7964       -- l_fxlv_tbl(l_line_index) := l_fxlv_rec;
7965       -- Increment the l_line_index
7966       l_line_index := l_line_index + 1;
7967     END LOOP; -- FOR l_line_index IN l_deprn_asset_tbl.FIRST .. l_deprn_asset_tbl.LAST
7968     -- Calling insert_row
7969     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7970       'Calling the okl_fa_extension_pvt.create_fxl_extension-tbl Version' );
7971     okl_fa_extension_pvt.create_fxl_extension(
7972        p_api_version     => l_api_version
7973       ,p_init_msg_list   => p_init_msg_list
7974       ,x_return_status   => l_return_status
7975       ,x_msg_count       => x_msg_count
7976       ,x_msg_data        => x_msg_data
7977       ,p_fxl_tbl_tbl     => l_fxl_tbl_tbl
7978       ,x_fxl_tbl_tbl     => lx_fxl_tbl_tbl
7979      );
7980     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7981       'After okl_fa_extension_pvt.create_fxl_extension-tbl Version: l_return_status ' || l_return_status );
7982     -- Check the return status and if errored, return the error back
7983     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
7984     THEN
7985       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
7986     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
7987     THEN
7988       RAISE OKL_API.G_EXCEPTION_ERROR;
7989     END IF;
7990     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7991       'Calling okl_api.end_activity');
7992     okl_api.end_activity(
7993        x_msg_count => x_msg_count
7994       ,x_msg_data  => x_msg_data);
7995     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
7996       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
7997     x_return_status := OKL_API.G_RET_STS_SUCCESS;
7998   EXCEPTION
7999     ------------------------------------------------------------
8000     -- Exception handling
8001     ------------------------------------------------------------
8002     WHEN OKL_API.G_EXCEPTION_ERROR
8003     THEN
8004       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
8005                             p_api_name  => l_api_name
8006                            ,p_pkg_name  => G_PKG_NAME
8007                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
8008                            ,x_msg_count  => x_msg_count
8009                            ,x_msg_data  => x_msg_data
8010                            ,p_api_type  => '_PVT');
8011     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
8012     THEN
8013       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
8014                             p_api_name  => l_api_name
8015                            ,p_pkg_name  => G_PKG_NAME
8016                            ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
8017                            ,x_msg_count  => x_msg_count
8018                            ,x_msg_data  => x_msg_data
8019                            ,p_api_type  => '_PVT');
8020     WHEN OTHERS
8021     THEN
8022       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
8023                             p_api_name  => l_api_name
8024                            ,p_pkg_name  => G_PKG_NAME
8025                            ,p_exc_name  => 'OTHERS'
8026                            ,x_msg_count  => x_msg_count
8027                            ,x_msg_data  => x_msg_data
8028                            ,p_api_type  => '_PVT');
8029   END populate_sources;
8030 
8031   PROCEDURE log_msg(
8032               p_destination  IN NUMBER
8033              ,p_msg          IN VARCHAR2)
8034   IS
8035   BEGIN
8036    FND_FILE.PUT_LINE(p_destination, p_msg );
8037   END;
8038 
8039   ------------------------------------------------------------------------------
8040   -- Start of comments
8041   --      API name        : populate_deprn_sources
8042   --      Pre-reqs        : None
8043   --      Function        : populate sources for OKL AP Transactions
8044   --      Parameters      :
8045   --      IN              :  Asset Book Type Code      Mandatory
8046   --                         Period Counter            Mandatory
8047   --                         Worker ID                 Mandatory
8048   --                         Max. Deprn. Run ID        Mandatory
8049   --
8050   --      History         : Ravindranath Gooty created
8051   --      Version         : 1.0
8052   --      Description: API called by the Parallel worker for the
8053   --                   OKL: FA Capture Sources for Depreciation Transaction
8054   -- End of comments
8055   ------------------------------------------------------------------------------
8056   PROCEDURE populate_deprn_sources(
8057     errbuf                    OUT      NOCOPY  VARCHAR2
8058    ,retcode                   OUT      NOCOPY  NUMBER
8059    ,p_book_type_code          IN               VARCHAR2
8060    ,p_period_counter          IN               VARCHAR2
8061    ,p_worker_id               IN               VARCHAR2
8062    ,p_max_deprn_run_id        IN               VARCHAR2
8063   )
8064   IS
8065     CURSOR get_okl_assets_csr(
8066        p_book_type_code       VARCHAR2
8067       ,p_period_counter       NUMBER
8068       ,p_max_deprn_run_id     NUMBER
8069       ,p_worker_id            VARCHAR2
8070     )
8071     IS
8072       SELECT  fa_dep.deprn_run_id     deprn_run_id
8073               ,ast.dnz_chr_id         khr_id
8074               ,ast.cle_id             kle_id
8075               ,fa_dep.asset_id        asset_id
8076         FROM   fa_deprn_summary       fa_dep
8077               ,okc_k_items            okc_item
8078               ,okc_k_lines_b          ast
8079               ,okl_parallel_processes opp
8080        WHERE   fa_dep.book_type_code    = p_book_type_code
8081          AND   fa_dep.period_counter    = p_period_counter
8082          AND   fa_dep.deprn_source_code = 'DEPRN'
8083          AND   fa_dep.deprn_run_id IS NOT NULL
8084         AND   ( fa_dep.deprn_run_id > p_max_deprn_run_id OR
8085                  p_max_deprn_run_id IS NULL )
8086          AND   NVL(okc_item.object1_id2, '#') = '#'
8087          AND   okc_item.jtot_object1_code = 'OKX_ASSET'
8088          AND   okc_item.object1_id1 = fa_dep.asset_id
8089          AND   okc_item.cle_id  = ast.id
8090          AND   ast.lse_id = 42 -- FIXED_ASSET Line Style ID
8091          AND   opp.assigned_process = p_worker_id -- Fetch only Current Workers Contracts
8092          AND   ast.dnz_chr_id = opp.khr_id
8093     ORDER BY   fa_dep.deprn_run_id, ast.dnz_chr_id, ast.cle_id
8094     ; -- End of Cursor: get_okl_assets_csr
8095 
8096     -- Type Declaration based on the Cursor Record Structure
8097     TYPE okl_deprn_assets_tbl IS TABLE OF get_okl_assets_csr%ROWTYPE
8098       INDEX BY BINARY_INTEGER;
8099 
8100     CURSOR get_max_deprn_run_id(
8101        p_asset_book_type_code    VARCHAR2
8102       ,p_period_counter          NUMBER
8103     )
8104     IS
8105       SELECT  MAX(fa_transaction_id)  max_deprn_run_id
8106         FROM  okl_ext_fa_line_sources_b  fxl
8107        WHERE  fxl.source_table = 'FA_DEPRN_SUMMARY'
8108          AND  fxl.asset_book_type_code = p_asset_book_type_code
8109          AND  fxl.period_counter = p_period_counter
8110     ; -- End of Cursor get_max_deprn_run_id
8111 
8112     -- Local Variable Declaration
8113     l_outer_error_msg_tbl        Okl_Accounting_Util.Error_Message_Type;
8114     l_book_type_code             VARCHAR2(240);
8115     l_period_counter             NUMBER;
8116     l_max_deprn_run_id           NUMBER;
8117     l_fa_deprn_assets_tbl        okl_deprn_assets_tbl;
8118     l_deprn_asset_tbl            deprn_asset_tbl_type;
8119     l_khr_id                     NUMBER;
8120     l_curr_deprn_run_id          NUMBER;
8121     ast_index                    NUMBER; -- Index for the l_deprn_asset_tbl
8122     -- Common Local Variables
8123     l_api_name                   CONSTANT VARCHAR2(30) := 'POPULATE_DEPRN_SOURCES';
8124     l_init_msg_list              VARCHAR2(2000)        := OKL_API.G_FALSE;
8125     l_return_status              VARCHAR2(1)           := OKL_API.G_RET_STS_SUCCESS;
8126     l_msg_count                  NUMBER;
8127     l_msg_data                   VARCHAR2(2000);
8128     l_api_version                CONSTANT NUMBER := 1.0;
8129     l_khr_id_tbl                 Okl_Streams_Util.NumberTabTyp;
8130     khr_index                    NUMBER;
8131   BEGIN
8132     -- Assign the input params to the Local Variables
8133     l_book_type_code := p_book_type_code;
8134     l_period_counter := TO_NUMBER(p_period_counter);
8135     log_msg(FND_FILE.LOG, 'Parameters: ' );
8136     log_msg(FND_FILE.LOG, ' Book Type Code = ' || l_book_type_code );
8137     log_msg(FND_FILE.LOG, ' Period Counter = ' || l_period_counter );
8138     log_msg(FND_FILE.LOG, ' Worker ID      = ' || p_worker_id );
8139     log_msg(FND_FILE.LOG, ' Max. Deprn. ID = ' || p_max_deprn_run_id );
8140     -- Find the Last Depreciation Run for which the Sources are captured
8141     --  for the inputted Book Type Code and Period
8142     l_max_deprn_run_id := TO_NUMBER( p_max_deprn_run_id );
8143     -- Initialize the khr_index
8144     khr_index := 0;
8145     -- Fetch all the OKL Assets for which FA has generated Depreciation Transactions
8146     --  in the inputted Asset Book and Period
8147     log_msg(FND_FILE.LOG, 'Before Executing the Cursor get_okl_assets_csr' );
8148     OPEN get_okl_assets_csr(
8149        p_book_type_code       => l_book_type_code
8150       ,p_period_counter       => l_period_counter
8151       ,p_max_deprn_run_id     => l_max_deprn_run_id
8152       ,p_worker_id            => p_worker_id
8153     );
8154     LOOP
8155       FETCH get_okl_assets_csr BULK COLLECT INTO l_fa_deprn_assets_tbl
8156         LIMIT 10000;
8157       log_msg(FND_FILE.LOG, 'After Executing the Cursor get_okl_assets_csr' );
8158       -- Exit when there are no Assets to be Processed
8159       EXIT WHEN get_okl_assets_csr%ROWCOUNT = 0;
8160       IF l_fa_deprn_assets_tbl.COUNT > 0
8161       THEN
8162         log_msg(FND_FILE.LOG, 'Total Number of Assets to be Processed in this iteration=' || l_fa_deprn_assets_tbl.COUNT );
8163         l_curr_deprn_run_id := l_fa_deprn_assets_tbl(l_fa_deprn_assets_tbl.FIRST).deprn_run_id;
8164         l_khr_id := l_fa_deprn_assets_tbl(l_fa_deprn_assets_tbl.FIRST).khr_id;
8165         -- Increment the khr_index and store the contract number in the l_khr_id_tbl
8166         khr_index := khr_index + 1;
8167         l_khr_id_tbl(khr_index) := l_khr_id; -- Store the Contract ID Already processed
8168         l_deprn_asset_tbl.DELETE;
8169         -- Initialize the ast_index
8170         ast_index := 1;
8171         log_msg(FND_FILE.OUTPUT, '-------------------------------------------------------------------' );
8172         log_msg(FND_FILE.OUTPUT, 'Capturing Sources for Deprn Run ID: ' || l_curr_deprn_run_id );
8173         log_msg(FND_FILE.OUTPUT, '-------------------------------------------------------------------' );
8174         log_msg(FND_FILE.OUTPUT, '  Capture Sources for ' );
8175         log_msg(FND_FILE.OUTPUT, '    KHR_ID=' || l_khr_id );
8176         FOR i IN l_fa_deprn_assets_tbl.FIRST .. l_fa_deprn_assets_tbl.LAST
8177         LOOP
8178           -- Logic:
8179           --  Loop on the OKL Assets Table [Ordered by KHR_ID]
8180           --  Once a break on the KHR_ID or Deprn. Run ID comes up .. Call the Populate Sources API
8181           --   Till then .. store all the assets in a collection ..
8182           IF l_curr_deprn_run_id = l_fa_deprn_assets_tbl(i).deprn_run_id AND
8183              l_khr_id = l_fa_deprn_assets_tbl(i).khr_id
8184           THEN
8185             -- Keep Storing the KLE_ID and ASSET_ID in the l_deprn_asset_tbl
8186             l_deprn_asset_tbl(ast_index).kle_id   := l_fa_deprn_assets_tbl(i).kle_id;
8187             l_deprn_asset_tbl(ast_index).asset_id := l_fa_deprn_assets_tbl(i).asset_id;
8188             log_msg(FND_FILE.OUTPUT, '      KLE_ID=' || l_fa_deprn_assets_tbl(i).kle_id ||
8189               ' ASSET_ID=' || l_fa_deprn_assets_tbl(i).asset_id );
8190             -- Increment the Index
8191             ast_index := ast_index + 1;
8192           ELSE
8193             -- Call the Populate Sources
8194             log_msg(FND_FILE.LOG, 'Before Calling Populate Sources - Contract/Deprn Run Break' );
8195             log_msg(FND_FILE.LOG, ' khr_id=' || l_khr_id );
8196             log_msg(FND_FILE.LOG, ' Asset Count=' || l_deprn_asset_tbl.COUNT );
8197             log_msg(FND_FILE.LOG, ' Book Type=' || l_book_type_code );
8198             log_msg(FND_FILE.LOG, ' Period Counter=' || l_period_counter );
8199             populate_sources(
8200               p_api_version     => l_api_version
8201              ,p_init_msg_list   => l_init_msg_list
8202              ,p_khr_id          => l_khr_id
8203              ,p_deprn_asset_tbl => l_deprn_asset_tbl
8204              ,p_deprn_run_id    => l_curr_deprn_run_id
8205              ,p_book_type_code  => l_book_type_code
8206              ,p_period_counter  => l_period_counter
8207              ,x_return_status   => l_return_status
8208              ,x_msg_count       => l_msg_count
8209              ,x_msg_data        => l_msg_data
8210             );
8211             log_msg(FND_FILE.LOG, ' After Calling the Populate Sources return_status=' || l_return_status );
8212             IF l_return_status = OKL_API.G_RET_STS_ERROR
8213             THEN
8214               RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8215             ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
8216               RAISE OKL_API.G_EXCEPTION_ERROR;
8217             END IF;
8218             log_msg(FND_FILE.OUTPUT, '---------------------------------------------------------' );
8219             -- Reset the Khr_id to the current KHR_ID
8220             l_khr_id := l_fa_deprn_assets_tbl(i).khr_id;
8221             -- Increment the khr_index and store the contract number in the l_khr_id_tbl
8222             khr_index := khr_index + 1;
8223             l_khr_id_tbl(khr_index) := l_khr_id; -- Store the Contract ID Already processed
8224             IF l_curr_deprn_run_id <> l_fa_deprn_assets_tbl(i).deprn_run_id
8225             THEN
8226               -- Break Happened on the Deprn Run ID itself .. Hence,
8227               -- Reset the Depreciation Run ID
8228               l_curr_deprn_run_id := l_fa_deprn_assets_tbl(i).deprn_run_id;
8229               log_msg(FND_FILE.OUTPUT, '-------------------------------------------------------------------' );
8230               log_msg(FND_FILE.OUTPUT, 'Capturing Sources for Deprn Run ID: ' || l_curr_deprn_run_id );
8231               log_msg(FND_FILE.OUTPUT, '-------------------------------------------------------------------' );
8232             END IF; -- Break on the Deprn Run ID
8233             -- Delete the l_deprn_asset_tbl
8234             l_deprn_asset_tbl.DELETE;
8235             -- Initialize teh ast_index
8236             ast_index := 1;
8237             -- Store the kle_id and asset_id in the current index of the l_deprn_asset_tbl
8238             l_deprn_asset_tbl(ast_index).kle_id   := l_fa_deprn_assets_tbl(i).kle_id;
8239             l_deprn_asset_tbl(ast_index).asset_id := l_fa_deprn_assets_tbl(i).asset_id;
8240             log_msg(FND_FILE.OUTPUT, 'Capture Sources for ' );
8241             log_msg(FND_FILE.OUTPUT, '  KHR_ID=' || l_khr_id );
8242             log_msg(FND_FILE.OUTPUT, '    KLE_ID=' || l_fa_deprn_assets_tbl(i).kle_id ||
8243               ' ASSET_ID=' || l_fa_deprn_assets_tbl(i).asset_id );
8244             -- Increment the Index
8245             ast_index := ast_index + 1;
8246           END IF;
8247         END LOOP; -- FOR i IN l_deprn_assets_tbl.FIRST .. l_deprn_assets_tbl.LAST
8248         -- Call the Populate Sources at the End too for the lastly Populated Records
8249         log_msg(FND_FILE.OUTPUT, '---------------------------------------------------------' );
8250         -- Call the Populate Sources
8251         log_msg(FND_FILE.LOG, 'Before Calling Populate Sources - At the End of the Loop' );
8252         log_msg(FND_FILE.LOG, ' khr_id=' || l_khr_id );
8253         log_msg(FND_FILE.LOG, ' Asset Count=' || l_deprn_asset_tbl.COUNT );
8254         log_msg(FND_FILE.LOG, ' Book Type=' || l_book_type_code );
8255         log_msg(FND_FILE.LOG, ' Period Counter=' || l_period_counter );
8256         populate_sources(
8257           p_api_version     => l_api_version
8258          ,p_init_msg_list   => l_init_msg_list
8259          ,p_khr_id          => l_khr_id
8260          ,p_deprn_asset_tbl => l_deprn_asset_tbl
8261          ,p_deprn_run_id    => l_curr_deprn_run_id
8262          ,p_book_type_code  => l_book_type_code
8263          ,p_period_counter  => l_period_counter
8264          ,x_return_status   => l_return_status
8265          ,x_msg_count       => l_msg_count
8266          ,x_msg_data        => l_msg_data
8267         );
8268         log_msg(FND_FILE.LOG, ' After Calling the Populate Sources return_status=' || l_return_status );
8269         IF l_return_status = OKL_API.G_RET_STS_ERROR
8270         THEN
8271           RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8272         ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
8273           RAISE OKL_API.G_EXCEPTION_ERROR;
8274         END IF;
8275       END IF; -- IF l_deprn_assets_tbl.COUNT > 0
8276       -- Exit When Cursor Has been Exhausted fetching all the Records
8277       EXIT WHEN get_okl_assets_csr%NOTFOUND;
8278     END LOOP; -- Loop on get_okl_assets_csr
8279     CLOSE get_okl_assets_csr;  -- Close the Cursor
8280     -- Now Delete all the processed records from parallel process table
8281     FORALL khr_index IN l_khr_id_tbl.FIRST .. l_khr_id_tbl.LAST
8282       DELETE  OKL_PARALLEL_PROCESSES
8283        WHERE  khr_id = l_khr_id_tbl(khr_index);
8284     -- Return the Proper Return status
8285     retcode := 0; -- 0 Indicates 'S'uccess Status
8286   EXCEPTION
8287     ------------------------------------------------------------
8288     -- Exception handling
8289     ------------------------------------------------------------
8290     WHEN Okl_Api.G_EXCEPTION_ERROR
8291     THEN
8292       l_return_status := Okl_Api.G_RET_STS_ERROR;
8293       -- print the error message in the log file and output files
8294       log_msg(FND_FILE.OUTPUT,'');
8295       log_msg(FND_FILE.OUTPUT,FND_MESSAGE.GET_STRING('OKL','OKL_AGN_RPT_PROGRAM_ERROR'));
8296       log_msg(FND_FILE.LOG,FND_MESSAGE.GET_STRING('OKL','OKL_AGN_RPT_PROGRAM_STATUS')
8297 	                    ||' '||l_return_status);
8298       Okl_Accounting_Util.GET_ERROR_MESSAGE(l_outer_error_msg_tbl);
8299       IF (l_outer_error_msg_tbl.COUNT > 0) THEN
8300         FOR i IN l_outer_error_msg_tbl.FIRST..l_outer_error_msg_tbl.LAST
8301         LOOP
8302            log_msg(FND_FILE.LOG, l_outer_error_msg_tbl(i));
8303         END LOOP;
8304       END IF;
8305       retcode := 2;
8306 
8307     WHEN Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR
8308     THEN
8309       l_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
8310       -- print the error message in the log file
8311       log_msg(FND_FILE.OUTPUT,'');
8312       log_msg(FND_FILE.OUTPUT,FND_MESSAGE.GET_STRING('OKL','OKL_AGN_RPT_PROGRAM_ERROR'));
8313       log_msg(FND_FILE.LOG,FND_MESSAGE.GET_STRING('OKL','OKL_AGN_RPT_PROGRAM_STATUS')
8314 	                    ||' '||l_return_status);
8315       Okl_Accounting_Util.GET_ERROR_MESSAGE(l_outer_error_msg_tbl);
8316       IF (l_outer_error_msg_tbl.COUNT > 0)
8317       THEN
8318         FOR i IN l_outer_error_msg_tbl.FIRST..l_outer_error_msg_tbl.LAST
8319         LOOP
8320           log_msg(FND_FILE.LOG, l_outer_error_msg_tbl(i));
8321         END LOOP;
8322       END IF;
8323       retcode := 2;
8324 
8325     WHEN OTHERS
8326     THEN
8327       l_return_status := Okl_Api.G_RET_STS_UNEXP_ERROR;
8328       -- print the error message in the log file
8329       log_msg(FND_FILE.OUTPUT,'');
8330       log_msg(FND_FILE.OUTPUT,FND_MESSAGE.GET_STRING('OKL','OKL_AGN_RPT_PROGRAM_ERROR'));
8331       log_msg(FND_FILE.LOG,FND_MESSAGE.GET_STRING('OKL','OKL_AGN_RPT_PROGRAM_STATUS')
8332 	                    ||' '||l_return_status);
8333       Okl_Accounting_Util.GET_ERROR_MESSAGE(l_outer_error_msg_tbl);
8334       IF (l_outer_error_msg_tbl.COUNT > 0)
8335       THEN
8336         FOR i IN l_outer_error_msg_tbl.FIRST..l_outer_error_msg_tbl.LAST
8337         LOOP
8338           log_msg(FND_FILE.LOG, l_outer_error_msg_tbl(i));
8339         END LOOP;
8340       END IF;
8341       errbuf := SQLERRM;
8342       retcode := 2;
8343   END populate_deprn_sources;
8344 
8345   ------------------------------------------------------------------------------
8346   -- Start of comments
8347   --      API name        : populate_deprn_sources_conc
8348   --      Pre-reqs        : None
8349   --      Function        : populate sources for OKL AP Transactions
8350   --      Parameters      :
8351   --      IN              :  Asset Book Type Code      Mandatory
8352   --                         Period Counter            Mandatory
8353   --      History         : Ravindranath Gooty created
8354   --      Version         : 1.0
8355   --      Description: API called by the Master Program of the conc. job
8356   --                   OKL: FA Capture Sources for Depreciation Transaction
8357   -- End of comments
8358   ------------------------------------------------------------------------------
8359   PROCEDURE populate_deprn_sources_conc(
8360     errbuf                    OUT      NOCOPY  VARCHAR2
8361    ,retcode                   OUT      NOCOPY  NUMBER
8362    ,p_book_type_code          IN               VARCHAR2
8363    ,p_period_counter          IN               NUMBER
8364   )
8365   IS
8366     CURSOR get_deprn_contracts_csr(
8367        p_book_type_code       VARCHAR2
8368       ,p_period_counter       NUMBER
8369       ,p_max_deprn_run_id     NUMBER
8370     )
8371     IS
8372       SELECT   chr.id                 khr_id
8373               ,chr.contract_number    contract_number
8374               ,COUNT(fa_dep.asset_id) no_of_assets
8375         FROM   fa_deprn_summary       fa_dep
8376               ,fa_books               fa_books
8377               ,okc_k_headers_all_b    chr
8378        WHERE   -- Predicates on fa_deprn_summary
8379                fa_dep.book_type_code    = p_book_type_code
8380          AND   fa_dep.period_counter    = p_period_counter
8381          AND   fa_dep.deprn_source_code = 'DEPRN'
8382          AND   fa_dep.deprn_run_id IS NOT NULL
8383          AND   ( fa_dep.deprn_run_id > p_max_deprn_run_id OR
8384                  p_max_deprn_run_id IS NULL )
8385          -- Predicates on fa_books
8386          AND   fa_books.transaction_header_id_out IS NULL
8387          AND   fa_books.date_ineffective IS NULL
8388          AND   fa_books.contract_id IS NOT NULL
8389          -- Join Conditions between fa_deprn_summary and fa_books
8390          AND   fa_dep.asset_id = fa_books.asset_id
8391          AND   fa_dep.book_type_code = fa_books.book_type_code
8392          -- Join conditions between fa_books and okc_k_headers_all_b
8393          AND   fa_books.contract_id = chr.id
8394     GROUP BY   chr.id, CHR.contract_number
8395     ORDER BY   COUNT(fa_dep.asset_id) DESC;
8396 
8397     -- Cursor to fetch the Maximum Deprecation ID from the FA Extension Line Table
8398     CURSOR get_max_deprn_run_id(
8399        p_asset_book_type_code    VARCHAR2
8400       ,p_period_counter          NUMBER
8401     )
8402     IS
8403       SELECT  MAX(fa_transaction_id)  max_deprn_run_id
8404         FROM  okl_ext_fa_line_sources_b  fxl
8405        WHERE  fxl.source_table = 'FA_DEPRN_SUMMARY'
8406          AND  fxl.asset_book_type_code = p_asset_book_type_code
8407          AND  fxl.period_counter = p_period_counter
8408     ; -- End of Cursor get_max_deprn_run_id
8409 
8410     -- Local Record and Table Variables based on Cursors/Tables
8411     get_deprn_contracts_rec           get_deprn_contracts_csr%ROWTYPE;
8412     TYPE deprn_contracts_tbl_type  IS TABLE OF get_deprn_contracts_csr%ROWTYPE
8413       INDEX BY BINARY_INTEGER;
8414     l_deprn_contracts_tbl         deprn_contracts_tbl_type;
8415     l_temp_deprn_contracts_tbl    deprn_contracts_tbl_type;
8416     l_object_value_tbl            Okl_Streams_Util.Var240TabTyp;
8417     l_assigned_process_tbl        Okl_Streams_Util.Var30TabTyp;
8418     l_khr_id_tbl                  Okl_Streams_Util.NumberTabTyp;
8419     l_volume_tbl                  Okl_Streams_Util.NumberTabTyp;
8420     -- Local Variable Declaration
8421     dep_index                     NUMBER; -- Index for the l_deprn_contracts_tbl
8422     req_data                      VARCHAR2(10);
8423     l_book_type_code              VARCHAR2(240);
8424     l_period_counter              NUMBER;
8425     l_max_deprn_run_id            NUMBER;
8426     l_num_workers                 NUMBER;
8427     l_seq_next                    NUMBER;
8428     l_data_found                  BOOLEAN := FALSE;
8429     l_worker_id                   VARCHAR2(2000);
8430     l_worker_load                 worker_load_tab;
8431     l_lightest_worker             NUMBER;
8432     l_lightest_load               NUMBER;
8433     l_reqid                       FND_CONCURRENT_REQUESTS.request_id%TYPE;
8434   BEGIN
8435     req_data := fnd_conc_global.request_data;
8436     log_msg(FND_FILE.LOG, 'Request Data= ' || req_data );
8437     IF req_data IS NOT NULL
8438     THEN
8439       errbuf:='Done';
8440       retcode := 0;
8441       log_msg(FND_FILE.LOG, 'Returning Out Successfully !' );
8442       RETURN;
8443     ELSE
8444       -- When the req_data is NULL, it means that this is the first run of the Program ..
8445       -- in the Sense, the current request is the run before triggerring off any parallel workers
8446       -- Fetch the Number of Workers to be Assigned
8447       l_num_workers := FND_PROFILE.VALUE(G_OKL_DEPRN_WORKERS);
8448       log_msg(FND_FILE.LOG, 'Number of Workers ' || TO_CHAR(l_num_workers) );
8449       IF l_num_workers IS NULL OR l_num_workers <= 0
8450       THEN
8451         OKL_API.set_message(
8452            p_app_name     => G_APP_NAME
8453 	        ,p_msg_name     => G_OKL_DEPRN_WORKER_ERROR);
8454         log_msg(FND_FILE.LOG, 'Please specify positive value for the profile option OKL: Capture Sources for Asset Depreciation Concurrent Workers');
8455         RAISE OKL_API.G_EXCEPTION_ERROR;
8456       END IF;
8457       -- Select sequence for marking processes
8458       SELECT  okl_opp_seq.NEXTVAL
8459         INTO  l_seq_next
8460         FROM  DUAL;
8461       -- Assign the input params to the Local Variables
8462       l_book_type_code := p_book_type_code;
8463       l_period_counter := p_period_counter;
8464       -- Log the Input Variables
8465       log_msg(FND_FILE.LOG, 'Parameters: ' );
8466       log_msg(FND_FILE.LOG, ' Book Type Code =' || l_book_type_code );
8467       log_msg(FND_FILE.LOG, ' Period Counter =' || l_period_counter );
8468       -- Find the Last Depreciation Run for which the Sources are captured
8469       --  for the inputted Book Type Code and Period
8470       log_msg(FND_FILE.LOG, 'Before Executing the Cursor get_max_deprn_run_id' );
8471       l_max_deprn_run_id := NULL;
8472       FOR t_rec IN get_max_deprn_run_id(
8473          p_asset_book_type_code    => l_book_type_code
8474         ,p_period_counter          => l_period_counter
8475       )
8476       LOOP
8477         -- Store the Max. Deprn Run ID in the l_max_deprn_run_id
8478         l_max_deprn_run_id := t_rec.max_deprn_run_id;
8479       END LOOP; -- FOR t_rec IN get_max_deprn_run_id(
8480       log_msg(FND_FILE.LOG, 'After Executing the Cursor get_max_deprn_run_id. Max Deprn Run ID= ' || l_max_deprn_run_id );
8481       -- Initialize the dep_index first
8482       dep_index := 1;
8483       -- Fetch all the OKL Assets for which FA has generated Depreciation Transactions
8484       --  in the inputted Asset Book and Period
8485       log_msg(FND_FILE.LOG, 'Before Executing the Cursor get_deprn_contracts_csr' );
8486       OPEN get_deprn_contracts_csr(
8487          p_book_type_code       => l_book_type_code
8488         ,p_period_counter       => l_period_counter
8489         ,p_max_deprn_run_id     => l_max_deprn_run_id
8490       );
8491       LOOP
8492         -- Bulk Collect the Contracts which has Assets depreciated in the inputted
8493         --  Book Type and Period
8494         FETCH get_deprn_contracts_csr BULK COLLECT INTO l_temp_deprn_contracts_tbl
8495           LIMIT G_LIMIT_SIZE;
8496         log_msg(FND_FILE.LOG, 'After Executing the fetch on the Cursor get_okl_assets_csr' );
8497         log_msg(FND_FILE.LOG, 'Distinct Contracts fetched in this Loop ' || l_temp_deprn_contracts_tbl.COUNT );
8498         -- Exit without setting the l_data_found to TRUE as no records found here
8499         EXIT WHEN get_deprn_contracts_csr%ROWCOUNT = 0;
8500         -- Assign the flag to indicate that there are few records found
8501         l_data_found := TRUE;
8502         -- Loop on the l_temp_deprn_contracts_tbl and append the records at the end of the
8503         -- l_deprn_contracts_tbl
8504         FOR i IN l_temp_deprn_contracts_tbl.FIRST .. l_temp_deprn_contracts_tbl.LAST
8505         LOOP
8506           l_deprn_contracts_tbl(dep_index) := l_temp_deprn_contracts_tbl(i);
8507           -- Increment the dep_index
8508           dep_index := dep_index + 1;
8509         END LOOP;
8510         -- Delete the Temporary Table now ..
8511         l_temp_deprn_contracts_tbl.DELETE;
8512         -- Exit when there are no Assets to be Processed
8513         EXIT WHEN get_deprn_contracts_csr%NOTFOUND;
8514       END LOOP; -- Loop on get_deprn_contracts_csr
8515       CLOSE get_deprn_contracts_csr;  -- Close the Cursor
8516 
8517       IF l_data_found = TRUE
8518       THEN
8519         log_msg(FND_FILE.LOG, 'Total Number of records fetched=' || l_deprn_contracts_tbl.COUNT );
8520         -- Assign the data from the l_deprn_contracts_tbl to l_pp_deprn_khrs_tbl
8521         FOR dep_index IN l_deprn_contracts_tbl.FIRST .. l_deprn_contracts_tbl.LAST
8522         LOOP
8523           l_object_value_tbl(dep_index)     := l_deprn_contracts_tbl(dep_index).contract_number;
8524           l_khr_id_tbl(dep_index)           := l_deprn_contracts_tbl(dep_index).khr_id;
8525           l_volume_tbl(dep_index)           := l_deprn_contracts_tbl(dep_index).no_of_assets;
8526           l_assigned_process_tbl(dep_index) := TO_CHAR(l_seq_next);
8527         END LOOP;
8528         log_msg(FND_FILE.LOG, 'Successfully Populated the Individual Collection Tables object_value, khr_id, volume tables');
8529         -- Bulk Insert all the records into the OKL_PARALLEL_PROCESSES
8530         log_msg(FND_FILE.LOG, 'Before calling the Bulk Insert into the OKL_PARALLEL_PROCESSES' );
8531         FORALL dep_index IN l_deprn_contracts_tbl.FIRST .. l_deprn_contracts_tbl.LAST
8532           INSERT INTO OKL_PARALLEL_PROCESSES (
8533              OBJECT_TYPE
8534             ,OBJECT_VALUE
8535             ,ASSIGNED_PROCESS
8536             ,PROCESS_STATUS
8537             ,CREATION_DATE
8538             ,KHR_ID
8539             ,VOLUME
8540           )
8541           VALUES (
8542              G_OBJECT_TYPE_DEP_KHR             -- Object Type
8543             ,l_object_value_tbl(dep_index)     -- Object Value
8544             ,l_assigned_process_tbl(dep_index) -- Assigned Process
8545             ,'PENDING_ASSIGNMENT'              -- Process Status
8546             ,SYSDATE                           -- Creation Date
8547             ,l_khr_id_tbl(dep_index)           -- KHR_ID
8548             ,l_volume_tbl(dep_index)           -- Volume
8549           );
8550         log_msg(FND_FILE.LOG, 'After calling the Bulk Insert into the OKL_PARALLEL_PROCESSES' );
8551         -- Commit the Records
8552         COMMIT;
8553         log_msg(FND_FILE.LOG, 'Committed the Insertion of the OKL_PARALLEL_PROCESSES Records' );
8554         -- Create l_num_workers number of Workers
8555         FOR i in 1..l_num_workers
8556         LOOP -- put all workers into a table
8557           l_worker_load(i).worker_number := i;
8558           l_worker_load(i).worker_load := 0; -- initialize load with zero
8559           l_worker_load(i).used := FALSE; -- Initialize with FALSE as none are assigned to this
8560         END LOOP;
8561         log_msg(FND_FILE.LOG, 'Initialized totally ' || l_num_workers || ' workers ' );
8562         log_msg(FND_FILE.LOG, 'Allocation of Workers for every contract is in Progress .. ' );
8563         l_lightest_worker := 1;
8564         -- Loop through the Depreciation Contracts and Assign the Workers
8565         FOR dep_index IN l_deprn_contracts_tbl.FIRST .. l_deprn_contracts_tbl.LAST
8566         LOOP
8567           l_assigned_process_tbl(dep_index) := l_lightest_worker;
8568           -- put current contract into the lightest worker
8569           IF l_worker_load.EXISTS(l_lightest_worker)
8570           THEN
8571             -- Increment the Assigned Worker Load by Number of Assets
8572             l_worker_load(l_lightest_worker).worker_load :=
8573               l_worker_load(l_lightest_worker).worker_load +
8574               l_deprn_contracts_tbl(dep_index).no_of_assets;
8575             -- Update the used flag of the current lightest worker to indicate that its used.
8576             l_worker_load(l_lightest_worker).used := TRUE;
8577           END IF;
8578           -- default the lighest load with the first element as a starting point
8579           IF l_worker_load.EXISTS(1)
8580           THEN
8581             l_lightest_load := l_worker_load(1).worker_load;
8582             l_lightest_worker := l_worker_load(1).worker_number;
8583             -- logic to find lightest load
8584             FOR i in 1..l_worker_load.COUNT
8585             LOOP
8586               IF (l_worker_load(i).worker_load = 0)
8587                  OR (l_worker_load(i).worker_load < l_lightest_load)
8588               THEN
8589                 l_lightest_load   := l_worker_load(i).worker_load;
8590                 l_lightest_worker := l_worker_load(i).worker_number;
8591               END IF;
8592             END LOOP;
8593           END IF;
8594         END LOOP; -- FOR dep_index IN l_deprn_contracts_tbl.FIRST .. l_deprn_contracts_tbl.LAST
8595         log_msg(FND_FILE.LOG, 'Done with allocation of Workers for every contract.' );
8596         log_msg(FND_FILE.LOG, 'Process Sequence Number =' || l_seq_next );
8597         log_msg(FND_FILE.LOG, 'G_OBJECT_TYPE_DEP_KHR   =' || G_OBJECT_TYPE_DEP_KHR );
8598         log_msg(FND_FILE.LOG, 'Assigned Process              Contract Number                         KHR_ID                           Volume           ');
8599         log_msg(FND_FILE.LOG, '------------------------------------------------------------------------------------------------------------------------');
8600         FOR dep_index in l_deprn_contracts_tbl.FIRST .. l_deprn_contracts_tbl.LAST
8601         LOOP
8602           log_msg(FND_FILE.LOG, RPAD(l_assigned_process_tbl(dep_index),30, ' ') ||
8603                                 RPAD(l_object_value_tbl(dep_index),40, ' ')  ||
8604                                 RPAD(l_khr_id_tbl(dep_index),32, ' ' ) ||
8605                                 LPAD(l_volume_tbl(dep_index),15, ' ') );
8606         END LOOP;
8607         -- Now Bulk Update the Contract Numbers in Parallel Processes with the
8608         -- Assigned Worker Number
8609         FORALL dep_index in l_deprn_contracts_tbl.FIRST .. l_deprn_contracts_tbl.LAST
8610           UPDATE  OKL_PARALLEL_PROCESSES
8611              SET  assigned_process =  l_seq_next || '-' || l_assigned_process_tbl(dep_index)
8612                  ,process_status   = 'ASSIGNED'
8613            WHERE  object_type      = G_OBJECT_TYPE_DEP_KHR
8614              AND  object_value     = l_object_value_tbl(dep_index)
8615              AND  process_status   = 'PENDING_ASSIGNMENT'
8616              AND  khr_id           = l_khr_id_tbl(dep_index);
8617         log_msg(FND_FILE.LOG, 'Updated the Records in OKL_PARALLEL_PROCESSES with the Assigned Process' );
8618         -- COMMIT the Updation;
8619         COMMIT;
8620         log_msg(FND_FILE.LOG, 'Committed the Updation Changes' );
8621         FOR i in l_worker_load.FIRST .. l_worker_load.LAST
8622         LOOP
8623           -- Request only if the Worker is used and has some load to process ..
8624           IF l_worker_load(i).used
8625           THEN
8626             l_worker_id := TO_CHAR(l_seq_next)||'-'||TO_CHAR(i);
8627             -- FND_REQUEST.set_org_id(MO_GLOBAL.get_current_org_id); --MOAC- Concurrent request
8628             log_msg(FND_FILE.LOG, 'Submitted the Request with worker_id=' || l_worker_id );
8629             l_reqid := FND_REQUEST.submit_request(
8630                           application  => 'OKL'
8631                          ,program      => 'OKLCAPFADEPRNW' -- Parallel Worker Conc. Program
8632                          ,sub_request  => TRUE
8633                          ,argument1    => p_book_type_code
8634                          ,argument2    => p_period_counter
8635                          ,argument3    => l_worker_id
8636                          ,argument4    => l_max_deprn_run_id);
8637             log_msg(FND_FILE.LOG, '  Returned request_id=' || l_reqid );
8638             IF l_reqid = 0
8639             THEN
8640               -- Request Submission failed with Error .. Hence, Exit with Error
8641               errbuf := fnd_message.get;
8642               retcode := 2;
8643             ELSE
8644               errbuf := 'Sub-Request submitted successfully';
8645               retcode := 0 ;
8646             END IF;
8647             FND_FILE.PUT_LINE(FND_FILE.LOG, 'Launching Process '||l_worker_id||' with Request ID '||l_reqid);
8648           END IF; -- IF l_worker_load(i).used
8649         END LOOP; -- FOR j in 1 .. l_worker_load.LAST
8650         -- Set the Request Data to be used in the re-run of the Master Program ..
8651         FND_CONC_GLOBAL.set_req_globals(
8652             conc_status => 'PAUSED'
8653            ,request_data => '2 RUN'); -- Instead of NULL, it was i here ..
8654       ELSE
8655         log_msg(FND_FILE.LOG, 'No workers assigned due to no data found for prcocesing');
8656       END IF; -- IF l_data_found = TRUE
8657     END IF;
8658   END populate_deprn_sources_conc;
8659 
8660   ------------------------------------------------------------------------------
8661   -- Start of comments
8662   --      API name        : populate_sources
8663   --      Pre-reqs        : None
8664   --      Function        : populate sources for OKL Receipt Transactions
8665   --      Parameters      :
8666   --      IN              :
8667   --      History         : Ravindranath Gooty Created
8668   --      Version         : 1.0
8669   -- End of comments
8670   ------------------------------------------------------------------------------
8671   PROCEDURE populate_sources(
8672     p_api_version               IN             NUMBER
8673    ,p_init_msg_list             IN             VARCHAR2
8674    ,p_rxh_rec                   IN             rxh_rec_type
8675    ,x_return_status             OUT    NOCOPY  VARCHAR2
8676    ,x_msg_count                 OUT    NOCOPY  NUMBER
8677    ,x_msg_data                  OUT    NOCOPY  VARCHAR2
8678   )
8679   IS
8680     -----------------------------------------------------------------
8681     -- Declare Process Variable
8682     -----------------------------------------------------------------
8683     l_api_version          CONSTANT NUMBER         := 1;
8684     l_api_name             CONSTANT VARCHAR2(30)   := 'POPULATE_SOURCES-RECEIPT';
8685     l_return_status        VARCHAR2(1)             := OKL_API.G_RET_STS_SUCCESS;
8686     -- Local Variables for enabling the Debug Statements
8687     l_module CONSTANT fnd_log_messages.module%TYPE := G_MODULE || l_api_name;
8688     l_debug_enabled       VARCHAR2(10);
8689     is_debug_procedure_on BOOLEAN;
8690     is_debug_statement_on BOOLEAN;
8691     -----------------------------------------------------------------
8692     -- Local Variables
8693     -----------------------------------------------------------------
8694     l_ar_receipt_id               NUMBER;
8695     l_khr_id                      NUMBER;
8696     l_ledger_id                   NUMBER;
8697     l_rxh_rec                     rxh_rec_type;
8698     lx_rxh_rec                    rxh_rec_type;
8699     l_rxhl_tbl                    rxhl_tbl_type;
8700     lx_rxhl_tbl                   rxhl_tbl_type;
8701     tl_indx                       NUMBER; -- Index for the l_rxhl_tbl
8702     l_khr_source_rec              khr_source_rec_type;
8703     l_led_lang_tbl                led_lang_tbl_type;
8704   BEGIN
8705     l_debug_enabled := okl_debug_pub.check_log_enabled;
8706     -- check for logging on PROCEDURE level
8707     is_debug_procedure_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_PROCEDURE);
8708     -- check for logging on STATEMENT level
8709     is_debug_statement_on := okl_debug_pub.check_log_on(l_module,FND_LOG.LEVEL_STATEMENT);
8710     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
8711                'begin debug OKLRSLAB.pls call ' || l_api_name);
8712     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
8713                'BEGIN API OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES');
8714     l_return_status := OKL_API.G_RET_STS_SUCCESS;
8715     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8716       'Calling OKL_API.START_ACTIVITY');
8717     l_return_status := OKL_API.START_ACTIVITY(
8718                          p_api_name       => l_api_name
8719                         ,p_pkg_name       => g_pkg_name
8720                         ,p_init_msg_list  => p_init_msg_list
8721                         ,l_api_version    => l_api_version
8722                         ,p_api_version    => p_api_version
8723                         ,p_api_type       => '_PVT'
8724                         ,x_return_status  => l_return_status);
8725     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
8726       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8727     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR) THEN
8728       RAISE OKL_API.G_EXCEPTION_ERROR;
8729     END IF;
8730     -- Assign the Input Parameters to the Local Variables
8731     l_ar_receipt_id := p_rxh_rec.source_id;
8732     l_khr_id        := p_rxh_rec.khr_id;
8733     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8734       'L_AR_RECEIPT_ID= ' || TO_CHAR(l_ar_receipt_id) || ' L_KHR_ID= ' || TO_CHAR(l_khr_id) );
8735     -- Validation 1: p_ar_receipt_id Should not be NULL
8736     IF l_ar_receipt_id IS NULL
8737     THEN
8738       OKL_API.set_message(
8739          p_app_name      => G_APP_NAME
8740         ,p_msg_name      => G_INVALID_VALUE
8741         ,p_token1        => G_COL_NAME_TOKEN
8742         ,p_token1_value  => 'P_RXH_REC.SOURCE_ID');
8743       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
8744       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8745     END IF;
8746     -- Validation 2: p_khr_id Should not be NULL
8747     IF l_khr_id IS NULL
8748     THEN
8749       OKL_API.set_message(
8750          p_app_name      => G_APP_NAME
8751         ,p_msg_name      => G_INVALID_VALUE
8752         ,p_token1        => G_COL_NAME_TOKEN
8753         ,p_token1_value  => 'P_RXH_REC.KHR_ID');
8754       l_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
8755       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8756     END IF;
8757     -- Assign the AR Receipt ID to the Header Extension Source ID Column
8758     l_rxh_rec := p_rxh_rec; -- Source ID and KHR_ID will be initalized
8759     l_rxh_rec.source_table := G_AR_CASH_RECEIPTS;
8760 
8761     -- Now, fetch ledger id and ledger language associated to the contracts
8762     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8763       'Executing the Cursor c_khr_to_ledger_id_csr. p_khr_id=' || TO_CHAR(l_khr_id));
8764     FOR t_rec IN c_khr_to_ledger_id_csr( p_khr_id => l_khr_id )
8765     LOOP
8766       l_ledger_id := t_rec.ledger_id;
8767     END LOOP;
8768 
8769     -- Initialize the tl_indx
8770     tl_indx := 1;
8771     -- Fetch the ledger language in order to populate the sources
8772     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8773       'Executing the Cursor c_ledger_lang_csr. p_ledger_id=' || TO_CHAR(l_ledger_id));
8774     FOR t_rec IN c_ledger_lang_csr( p_ledger_id => l_ledger_id )
8775     LOOP
8776       l_led_lang_tbl(tl_indx).language := t_rec.language_code;
8777       -- Increment the tl_indx
8778       tl_indx := tl_indx + 1;
8779     END LOOP;
8780     -- Call the Populate Sources to fetch the Lease Contract/IA related Sources
8781     l_khr_source_rec.khr_id  := l_khr_id;
8782     -- Calling populate_khr_sources to fetch the KHR Sources
8783     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8784       'Before calling the populate_khr_sources' );
8785     populate_khr_sources(
8786        p_api_version      => l_api_version
8787       ,p_init_msg_list    => p_init_msg_list
8788       ,x_khr_source_rec   => l_khr_source_rec
8789       ,x_led_lang_tbl     => l_led_lang_tbl
8790       ,x_return_status    => l_return_status
8791       ,x_msg_count        => x_msg_count
8792       ,x_msg_data         => x_msg_data
8793     );
8794     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8795       'After populate_khr_sources: l_return_status ' || l_return_status );
8796     -- Check the return status and if errored, return the error back
8797     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
8798     THEN
8799       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8800     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
8801     THEN
8802       RAISE OKL_API.G_EXCEPTION_ERROR;
8803     END IF;
8804     -- Assign the KHR Sources to the AR Extension Header Table Record
8805     assign_khr_rec_to_rxh_rec(
8806        p_khr_source_rec => l_khr_source_rec
8807       ,x_rxh_rec        => l_rxh_rec );
8808     -- Fetch and Populate Sales Representative Name
8809     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8810       'Executing the Cursor  c_sales_rep_csr. p_khr_id = ' || TO_CHAR(l_khr_id) );
8811     FOR t_rec IN  c_sales_rep_csr (l_khr_id)
8812     LOOP
8813       l_rxh_rec.sales_rep_name := t_rec.name;
8814     END LOOP; -- End for c_sales_rep_csr
8815 
8816     FOR tl_indx IN l_led_lang_tbl.FIRST .. l_led_lang_tbl.LAST
8817     LOOP
8818       l_rxhl_tbl(tl_indx).language          := l_led_lang_tbl(tl_indx).language;
8819       l_rxhl_tbl(tl_indx).contract_status   := l_led_lang_tbl(tl_indx).contract_status;
8820       l_rxhl_tbl(tl_indx).inv_agrmnt_status := l_led_lang_tbl(tl_indx).inv_agrmnt_status;
8821     END LOOP;
8822 
8823     -- Now call the API to insert the Sources in the OKL_EXT_AR_HEADER_SOURCES_B/_TL table
8824     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
8825       'Calling the okl_ar_extension_pvt.create_rxh_extension ' || l_rxh_rec.source_id );
8826     okl_ar_extension_pvt.create_rxh_extension(
8827        p_api_version     => l_api_version
8828       ,p_init_msg_list   => p_init_msg_list
8829       ,x_return_status   => l_return_status
8830       ,x_msg_count       => x_msg_count
8831       ,x_msg_data        => x_msg_data
8832       ,p_rxh_rec         => l_rxh_rec
8833       ,p_rxhl_tbl        => l_rxhl_tbl
8834       ,x_rxh_rec         => lx_rxh_rec
8835       ,x_rxhl_tbl        => lx_rxhl_tbl
8836     );
8837     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'S',
8838       'After call to okl_ar_extension_pvt.create_rxh_extension: l_return_status ' || l_return_status );
8839     IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR)
8840     THEN
8841       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
8842     ELSIF (l_return_status = OKL_API.G_RET_STS_ERROR)
8843     THEN
8844       RAISE OKL_API.G_EXCEPTION_ERROR;
8845     END IF;
8846     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
8847       'Calling okl_api.end_activity');
8848     OKL_API.end_activity(
8849        x_msg_count => x_msg_count
8850       ,x_msg_data  => x_msg_data);
8851     put_in_log(l_debug_enabled,is_debug_procedure_on,is_debug_statement_on,l_module, 'P',
8852       'END OKL_SLA_ACC_SOURCES_PVT.POPULATE_SOURCES_RECEIPT');
8853     x_return_status := OKL_API.G_RET_STS_SUCCESS;
8854   EXCEPTION
8855     ------------------------------------------------------------
8856     -- Exception handling
8857     ------------------------------------------------------------
8858     WHEN OKL_API.G_EXCEPTION_ERROR
8859     THEN
8860       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
8861                             p_api_name  => l_api_name
8862                            ,p_pkg_name  => G_PKG_NAME
8863                            ,p_exc_name  => OKL_API.G_RET_STS_ERROR
8864                            ,x_msg_count  => x_msg_count
8865                            ,x_msg_data  => x_msg_data
8866                            ,p_api_type  => '_PVT');
8867     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR
8868     THEN
8869       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
8870                            p_api_name  => l_api_name
8871                           ,p_pkg_name  => G_PKG_NAME
8872                           ,p_exc_name  => OKL_API.G_RET_STS_UNEXP_ERROR
8873                           ,x_msg_count  => x_msg_count
8874                           ,x_msg_data  => x_msg_data
8875                            ,p_api_type  => '_PVT');
8876     WHEN OTHERS
8877     THEN
8878       x_return_status := OKL_API.HANDLE_EXCEPTIONS (
8879                             p_api_name  => l_api_name
8880                            ,p_pkg_name  => G_PKG_NAME
8881                            ,p_exc_name  => 'OTHERS'
8882                            ,x_msg_count  => x_msg_count
8883                            ,x_msg_data  => x_msg_data
8884                            ,p_api_type  => '_PVT');
8885   END populate_sources;
8886 
8887 END okl_sla_acc_sources_pvt;