DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKS_BILLING_PUB

Source


1 Package Body OKS_BILLING_PUB as
2 /* $Header: OKSPBILB.pls 120.33.12020000.7 2013/04/05 11:55:21 skuchima ship $ */
3 
4 
5  /*
6      This Procedure is used for billing
7      of Service / Usage / Subscription lines either
8      of a single contract or all the contract lines eligibile for billing.
9  */
10 
11 -- Global var holding the User Id
12          user_id          NUMBER;
13 
14 -- Global var to hold the ERROR value.
15          ERROR            NUMBER := 0;
16 
17 -- Global var to hold the SUCCESS value.
18          SUCCESS          NUMBER := 1;
19          WARNING          NUMBER := 1;
20 
21 
22 -- Global var to hold the Concurrent Process return value
23          conc_ret_code   NUMBER := SUCCESS;
24 
25 -- Global constant for the threshold count before splitting into sub-requests
26          MAX_SINGLE_REQUEST     NUMBER := 500;
27 
28 -- Global constant for the maximum allowed sub-requests (parallel workers)
29          MAX_JOBS               NUMBER := 30;
30 
31 -- Global vars to hold the min and max hdr_id for each sub-request range
32          type range_rec is record (
33               lo number,
34               hi number);
35          type rangeArray is VARRAY(50) of range_rec;
36          range_arr rangeArray;
37 
38 /* *** PL/sql tables and variables for report **** */
39 
40   l_processed_lines_tbl           OKS_BILL_REC_PUB.line_report_tbl_type;
41   l_processed_sub_lines_tbl       OKS_BILL_REC_PUB.line_report_tbl_type;
42 
43   l_pr_tbl_idx               Number := 0; /* Lines table */
44   l_prs_tbl_idx              Number := 0; /* Sub Lines table */
45 
46 -- Global table  for holding number of periods to process
47   level_elements_tab Oks_bill_util_pub.level_element_tab;
48   level_coverage     Oks_bill_util_pub.level_element_tab;
49   -- Variables to control log writing and report generation.
50 /*****
51   l_write_log              BOOLEAN;
52   l_write_report           BOOLEAN;
53   l_yes_no                 VARCHAR2(10);
54 *****/
55 
56  /*
57     Procedure LEVEL is for levelling across cps
58     of usage items if level flag is set to 'Y'.
59     It is done only if usage type is Actual per period.
60  */
61 
62 -------------------------------------------------------------------------
63 -- Begin partial period computation logic
64 -- Developer Mani Choudhary
65 -- Date 10-JUN-2005
66 -- Added  parameters p_period_type,p_period_start to the procedure level.
67 -------------------------------------------------------------------------
68 Procedure level
69  (
70   P_level_qty          IN                  NUMBER,
71   P_cov_tbl            IN OUT      NOCOPY  OKS_BILL_REC_PUB.COVERED_TBL,
72   P_qty                IN                  NUMBER,
73   --P_line_tbl           IN OUT      NOCOPY  OKS_QP_INT_PVT.G_SLINE_TBL_TYPE ,
74   p_usage_period       IN                  VARCHAR2,
75   p_time_uom_code      IN                  VARCHAR2,
76   p_uom_code           IN                  VARCHAR2,
77   p_period_type        IN                  VARCHAR2,
78   p_period_start       IN                  VARCHAR2,
79   X_return_status      OUT         NOCOPY  VARCHAR2
80  )
81  IS
82 Cursor l_bill_qty_csr (p_id IN NUMBER) IS
83 SELECT fixed_quantity         fixed_qty
84       ,minimum_quantity       minimum_qty
85       ,default_quantity       default_qty
86       ,amcv_flag              amcv_flag
87       ,usage_period           usage_period
88       ,usage_duration         usage_duration
89       ,level_yn               level_yn
90       ,base_reading           base_reading
91       ,usage_type             usage_Type
92   FROM oks_k_lines_b
93   WHERE cle_id = p_id ;
94 
95 l_bill_qty_rec               l_bill_qty_csr%rowtype;
96 l_from_date                  DATE;
97 l_to_date                    DATE;
98 l_minimum                    NUMBER;
99 l_temp                       NUMBER;
100 l_temp_qty                   NUMBER;
101 l_negative_yn                VARCHAR2(10);
102 
103 BEGIN
104 
105   X_return_status := 'S';
106   l_negative_yn := NVL(FND_PROFILE.VALUE('OKS_NEGATIVE_BILLING_YN'),'NO');
107   FOR l_ptr in 1..p_cov_tbl.count
108   LOOP
109     OPEN  l_bill_qty_csr(p_cov_tbl(l_ptr).id);
110     FETCH l_bill_qty_csr into l_bill_qty_rec;
111     CLOSE l_bill_qty_csr;
112 
113     l_minimum := NVL(l_bill_qty_rec.Minimum_qty,0) ;
114     l_temp_qty := p_cov_tbl(l_ptr).result ;  --used to temp storage of result
115     l_from_date := p_cov_tbl(l_ptr).date_billed_from;
116     l_to_date   := p_cov_tbl(l_ptr).date_billed_to;
117 
118     IF (l_minimum > 0) THEN
119       -------------------------------------------------------------------------
120       -- Begin partial period computation logic
121       -- Developer Mani Choudhary
122       -- Date 11-JUN-2005
123       -- call oks_bill_rec_pub.Get_prorated_Usage_Qty to get the prorated usage
124       -------------------------------------------------------------------------
125       IF p_period_type IS NOT NULL AND
126          p_period_start IS NOT NULL
127       THEN
128         l_minimum := OKS_BILL_REC_PUB.Get_Prorated_Usage_Qty
129                        (
130                        p_start_date  => l_from_date,
131                        p_end_date    => l_to_date,
132                        p_qty         => l_minimum,
133                        p_usage_uom   => p_usage_period,
134                        p_billing_uom => p_uom_code,
135                        p_period_type => p_period_type
136                        );
137         IF Nvl(l_minimum,0) = 0 THEN
138           FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error OKS_BILL_REC_PUB.Get_Prorated_Usage_Qty returns l_minimum as '||l_minimum);
139           Raise G_EXCEPTION_HALT_VALIDATION;
140         END IF;
141         l_minimum := Round(l_minimum,0);
142       ELSE
143         --Existing logic
144         l_temp := OKS_TIME_MEASURES_PUB.GET_TARGET_QTY
145                    (
146                     p_start_date  => l_from_date,
147                     p_source_qty  => 1,
148                     p_source_uom  => p_usage_period,
149                     p_target_uom  => p_time_uom_code,
150                     p_round_dec   => 0
151                    );
152 
153         IF Nvl(l_temp,0) = 0 THEN
154           FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error Get_target_qty returns Zero');
155           Raise G_EXCEPTION_HALT_VALIDATION;
156         END IF;
157         l_minimum  := Round((trunc(l_to_date) - trunc(l_from_date) + 1)
158                                 * (l_minimum /l_temp) ,0) ;
159       END IF;
160       ------------------------------------------------------------------------------
161     END IF;
162 
163     IF (l_bill_qty_rec.level_yn = 'Y') THEN
164       p_cov_tbl(l_ptr).result :=  nvl(p_level_qty, 0);
165       IF (p_level_qty = 0)  THEN
166         p_cov_tbl(l_ptr).adjustment_level := 0;
167       ELSE
168         p_cov_tbl(l_ptr).adjustment_level := p_cov_tbl(l_ptr).result - p_qty;
169       END IF;
170 
171       p_cov_tbl(l_ptr).adjustment_minimum := 0;
172       --p_line_tbl(l_ptr).item_qty := nvl(p_level_qty, 0);
173 
174       IF ((p_level_qty < l_minimum) AND (nvl(p_cov_tbl(l_ptr).flag,'X') <> 'S')) THEN
175         p_cov_tbl(l_ptr).result := l_minimum;
176         -- BUG FIX 3402724.
177         -- populate adjustment_minimum with L_minimum
178         p_cov_tbl(l_ptr).adjustment_minimum := l_minimum ; -- p_level_qty;
179       END IF;
180 
181     ELSIF (nvl(p_cov_tbl(l_ptr).flag,'X') not in ('D','S')) THEN
182       IF ((p_cov_tbl(l_ptr).result < l_minimum) AND  (l_bill_qty_rec.Minimum_qty is NOT NULL)) THEN
183         p_cov_tbl(l_ptr).result :=  l_minimum;
184         -- BUG FIX 3402724.
185         -- populate adjustment_minimum with L_minimum
186         p_cov_tbl(l_ptr).adjustment_minimum := l_minimum ; -- p_level_qty;
187       END IF;
188 
189 
190     END IF;
191 
192     /* If flag is Default */
193     -- BUG FIX 3443896.Default qty in billing history not populated properly
194     IF ( p_cov_tbl(l_ptr).flag = 'D') THEN
195       p_cov_tbl(l_ptr).default_default := p_cov_tbl(l_ptr).result;  -- p_qty ;
196     /* If flag is AMCV */
197     ELSIF (p_cov_tbl(l_ptr).flag = 'M')  THEN
198       p_cov_tbl(l_ptr).amcv_yn := 'Y';
199       --p_cov_tbl(l_ptr).default_default := p_qty ;
200     END IF;
201 
202     IF ( sign(p_cov_tbl(l_ptr).result) = -1) THEN
203 
204       IF (l_negative_yn = 'YES') THEN
205         p_cov_tbl(l_ptr).sign := -1;
206         p_cov_tbl(l_ptr).result := abs(p_cov_tbl(l_ptr).result);
207         --p_line_tbl(l_ptr).item_qty  :=  abs(p_line_tbl(l_ptr).item_qty );
208 
209       ELSE
210         p_cov_tbl(l_ptr).sign := 1;
211         p_cov_tbl(l_ptr).result := nvl(l_minimum,0);
212         --p_line_tbl(l_ptr).item_qty  :=  0;
213       END IF;
214     ELSE
215       p_cov_tbl(l_ptr).sign := 1;
216     END IF ;
217 
218 
219     /****
220      added this code for new pricing API to retain the Quantity and
221      to be passed as a parameter to pricing API
222     ****/
223      p_cov_tbl(l_ptr).average := nvl(p_cov_tbl(l_ptr).result, 0);
224 
225   END LOOP;
226 
227 EXCEPTION
228   WHEN  G_EXCEPTION_HALT_VALIDATION THEN
229     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error in Level Procedure --G_exception_halt_validation raised' || sqlerrm);
230     x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
231   WHEN OTHERS THEN
232     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error in Level Procedure --OTHERS Exception raised' || sqlerrm);
233     x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
234     OKC_API.set_message(G_APP_NAME, G_UNEXPECTED_ERROR,G_SQLCODE_TOKEN,SQLCODE,G_SQLERRM_TOKEN,SQLERRM);
235 
236 END level;
237 
238 
239 /* Procedure to calculate AMCV */
240 PROCEDURE OKS_REG_GET_AMCV
241  (
242   X_Return_Status  OUT   NOCOPY  VARCHAR2,
243   P_cle_id          IN           NUMBER,
244   X_Volume         OUT   NOCOPY  NUMBER
245  )
246  IS
247 l_mth                NUMBER := 1;
248 l_prddays            NUMBER;
249 l_TotVol             NUMBER;
250 l_Date_Billed_From   DATE;
251 l_Date_Billed_To     DATE;
252 
253 Cursor l_date_csr Is
254   SELECT  Min(bsl.DATE_BILLED_FROM)
255          ,Max(bsl.DATE_BILLED_TO)
256   FROM  oks_bill_cont_lines bcl  ,
257         oks_bill_sub_lines  bsl
258   WHERE  bsl.cle_id = p_cle_id
259   AND    bsl.bcl_id = bcl.id
260   AND    bcl.bill_action <> 'AVG';
261 
262 Cursor l_tot_csr Is
263   SELECT NVL(Sum(NVL(bsd.Result,0)),0)
264   FROM   oks_bill_cont_lines    bcl,
265          oks_bill_sub_lines     bsl,
266          oks_bill_sub_line_dtls bsd
267   WHERE  bsl.cle_id = p_cle_id
268   AND    bsl.bcl_id = bcl.id
269   AND    bcl.bill_action <> 'AVG'
270   AND    bsd.bsl_id = bsl.id;
271 
272 
273 
274 BEGIN
275    x_Volume        := 0;
276    l_totvol := 0;
277    x_Return_Status := OKC_API.G_RET_STS_SUCCESS;
278 
279 
280    OPEN  l_date_csr;
281    FETCH l_date_csr into l_date_billed_from,l_date_billed_to;
282    CLOSE l_date_csr;
283 
284    OPEN  l_tot_csr;
285    FETCH l_tot_csr into l_totvol;
286    CLOSE l_tot_csr;
287 
288    l_prddays := trunc(l_Date_Billed_To) - trunc(l_Date_Billed_From) + 1;
289 
290 
291    x_Volume := Round(l_TotVol / l_prddays,0);
292 
293 
294 EXCEPTION
295   WHEN G_EXCEPTION_HALT_VALIDATION THEN
296     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error in OKS_REG_GET_AMCV -- G_Exception_halt_validation raised' );
297     x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
298   WHEN OTHERS THEN
299     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error in OKS_REG_GET_AMCV -- Others Exception raised' );
300     OKC_API.set_message(G_APP_NAME, G_UNEXPECTED_ERROR,
301                         G_SQLCODE_TOKEN,SQLCODE,G_SQLERRM_TOKEN,SQLERRM);
302     x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
303 
304 
305 
306 END  OKS_REG_GET_AMCV;
307 
308 /*Procedure Create_line_for_report is for billing Output report.
309   It copies each processed line in table
310 */
311 Procedure Create_line_for_report(
312              P_L_PR_TBL_IDX               IN NUMBER,
313              P_DNZ_CHR_ID                 IN NUMBER,
314              P_CONTRACT_NUMBER            IN VARCHAR2,
315              P_CONTRACT_NUMBER_MODIFIER   IN VARCHAR2,
316              P_CURRENCY_CODE              IN VARCHAR2,
317              P_INV_ORGANIZATION_ID        IN NUMBER,
318              P_ID                         IN NUMBER,
319              P_LINE_NUMBER                IN VARCHAR2,
320              P_CLE_ID                     IN NUMBER,
321              P_LSE_ID                     IN NUMBER,
322              P_OBJECT1_ID1                IN VARCHAR2,
323              P_OBJECT1_ID2                IN VARCHAR2,
324              P_SUMMARY_YN                 IN VARCHAR2)
325 IS
326 BEGIN
327  l_processed_lines_tbl(l_pr_tbl_idx).dnz_chr_id      := p_dnz_chr_id ;
328  l_processed_lines_tbl(l_pr_tbl_idx).Contract_number := p_Contract_number ;
329  l_processed_lines_tbl(l_pr_tbl_idx).Contract_number_modifier := p_Contract_number_modifier ;
330  l_processed_lines_tbl(l_pr_tbl_idx).Currency_code   := p_Currency_code;
331  l_processed_lines_tbl(l_pr_tbl_idx).Organization_id := p_Inv_Organization_id;
332  l_processed_lines_tbl(l_pr_tbl_idx).Line_id         := p_id ;
333  l_processed_lines_tbl(l_pr_tbl_idx).Line_Number     := p_Line_Number ;
334  l_processed_lines_tbl(l_pr_tbl_idx).Cle_id          := p_cle_id ;
335  l_processed_lines_tbl(l_pr_tbl_idx).Lse_Id          := p_lse_id ;
336  l_processed_lines_tbl(l_pr_tbl_idx).Sub_line_id     := Null ;
337  l_processed_lines_tbl(l_pr_tbl_idx).Sub_line_Number := Null ;
338  l_processed_lines_tbl(l_pr_tbl_idx).Pty_object1_id1 := p_object1_id1 ;
339  l_processed_lines_tbl(l_pr_tbl_idx).Pty_object1_id2 := p_object1_id2 ;
340  l_processed_lines_tbl(l_pr_tbl_idx).record_type     := 'LINE' ;
341  l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN       := 'Y' ;
342  l_processed_lines_tbl(l_pr_tbl_idx).Bill_Amount     := 0 ;
343  l_processed_lines_tbl(l_pr_tbl_idx).Line_Type       := Null ;
344 
345  IF (l_processed_lines_tbl(l_pr_tbl_idx).lse_id = 12) THEN
346    l_processed_lines_tbl(l_pr_tbl_idx).Summary_bill_YN := 'N';
347  ELSIF (l_processed_lines_tbl(l_pr_tbl_idx).lse_id = 46) THEN
348    l_processed_lines_tbl(l_pr_tbl_idx).Summary_bill_YN := 'Y';
349  ELSE
350    IF (p_summary_yn = 'Y') THEN
351      l_processed_lines_tbl(l_pr_tbl_idx).Summary_bill_YN := 'Y';
352    ELSE
353      IF ( FND_PROFILE.VALUE('OKS_AR_TRANSACTIONS_SUBMIT_SUMMARY_YN') = 'YES') THEN
354        l_processed_lines_tbl(l_pr_tbl_idx).Summary_bill_YN := 'Y';
355      ELSE
356        l_processed_lines_tbl(l_pr_tbl_idx).Summary_bill_YN := 'N';
357      END IF;
358    END IF;
359  END IF;
360 END;
361 
362 
363 /*Procedure Create_subline_for_report is for billing Output report.
364   It copies each processed subline in table
365 */
366 Procedure Create_subline_for_report(
367                 l_prs_tbl_idx              IN     NUMBER ,
368                 p_dnz_chr_id               IN     NUMBER,
369                 p_contract_number          IN     VARCHAR2,
370                 p_con_num_modifier         IN     VARCHAR2,
371                 p_currency_code            IN     VARCHAR2,
372                 p_inv_organization_id      IN     NUMBER,
373                 p_line_id                  IN     NUMBER,
374                 p_line_number              IN     VARCHAR2,
375                 p_lse_id                   IN     NUMBER,
376                 p_cov_id                   IN     NUMBER,
377                 p_cov_line_number          IN     VARCHAR2,
378                 p_object1_id1              IN     VARCHAR2,
379                 p_object1_id2              IN     VARCHAR2,
380                 p_line_type                IN     VARCHAR2,
381                 p_amount                   IN     NUMBER,
382                 p_summary_yn               IN     VARCHAR2
383                 )
384 IS
385 BEGIN
386   l_processed_sub_lines_tbl(l_prs_tbl_idx).dnz_chr_id := p_dnz_chr_id ;
387   l_processed_sub_lines_tbl(l_prs_tbl_idx).Contract_number := p_Contract_number ;
388   l_processed_sub_lines_tbl(l_prs_tbl_idx).Contract_number_modifier := p_con_num_modifier ;
389   l_processed_sub_lines_tbl(l_prs_tbl_idx).Currency_code := p_Currency_code;
390   l_processed_sub_lines_tbl(l_prs_tbl_idx).Organization_id := p_Inv_Organization_id;
391   l_processed_sub_lines_tbl(l_prs_tbl_idx).Line_id := p_line_id ;
392   l_processed_sub_lines_tbl(l_prs_tbl_idx).Line_Number := p_line_Number ;
393   l_processed_sub_lines_tbl(l_prs_tbl_idx).Cle_id := p_line_id ;
394   l_processed_sub_lines_tbl(l_prs_tbl_idx).Lse_Id := p_lse_id ;
395   l_processed_sub_lines_tbl(l_prs_tbl_idx).Sub_line_id := p_cov_id ;
396   l_processed_sub_lines_tbl(l_prs_tbl_idx).Sub_line_Number := p_Line_Number||'.'||p_cov_line_number ;
397   l_processed_sub_lines_tbl(l_prs_tbl_idx).Pty_object1_id1 := p_object1_id1 ;
398   l_processed_sub_lines_tbl(l_prs_tbl_idx).Pty_object1_id2 := p_object1_id2 ;
399   l_processed_sub_lines_tbl(l_prs_tbl_idx).record_type := 'SUB_LINE' ;
400   l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN := 'Y' ;
401   --l_processed_sub_lines_tbl(l_prs_tbl_idx).Bill_Amount := 0 ;
402   l_processed_sub_lines_tbl(l_prs_tbl_idx).Line_Type := p_line_type ;
403 
404   IF (l_processed_sub_lines_tbl(l_prs_tbl_idx).lse_id = 12) THEN
405     l_processed_sub_lines_tbl(l_prs_tbl_idx).Summary_bill_YN := 'N';
406   ELSIF (l_processed_sub_lines_tbl(l_prs_tbl_idx).lse_id = 46) THEN
407     l_processed_sub_lines_tbl(l_prs_tbl_idx).Summary_bill_YN := 'Y';
408   ELSE
409     IF (p_summary_yn = 'Y') THEN
410       l_processed_sub_lines_tbl(l_prs_tbl_idx).Summary_bill_YN := 'Y';
411     ELSE
412       IF ( FND_PROFILE.VALUE('OKS_AR_TRANSACTIONS_SUBMIT_SUMMARY_YN') = 'YES') THEN
413         l_processed_sub_lines_tbl(l_prs_tbl_idx).Summary_bill_YN := 'Y';
414       ELSE
415         l_processed_sub_lines_tbl(l_prs_tbl_idx).Summary_bill_YN := 'N';
416       END IF;
417     END IF;
418   END IF;
419 
420 
421 END Create_subline_for_report;
422 
423 --------------------------------------------------------------
424 --Procedure to insert data into OKS_USG_QP_CALL_TBL for calling QP in bulk
425 --skuchima 05-Jan-2012 Bug 13105205 Ceredian ER
426 --------------------------------------------------------------
427 Procedure Insert_usg_qp_dtls_prc
428      (p_detail_rec in oks_qp_pkg.input_details,
429       dnz_chr_id in number,
430       currency_code IN VARCHAR2 ,
431       prorate   IN VARCHAR2,
432       prv     IN number,
433       p_sign   IN NUMBER   ,
434       p_bcl_id IN NUMBER,
435       level_element_id IN NUMBER,
436       level_coverage_id IN NUMBER    ,
437       p_prorate IN VARCHAR2     ,
438       p_amount IN number
439       ) is
440 
441 pragma autonomous_transaction;
442 
443 Begin
444 
445 Insert into oks_usg_qp_call_tbl(
446       price_list ,
447       price_list_line_id,
448       chr_id  ,
449       line_id ,
450       subline_id,
451       intent          ,
452       currency      ,
453       bcl_id           ,
454       bsl_id            ,
455       usage_qty      ,
456       usage_uom_code,
457       break_uom_code  ,
458       proration_yn            ,
459       bill_from_date           ,
460       bill_to_date                 ,
461       asking_unit_price   ,
462       dnz_chr_id ,
463       currency_code ,
464       prorate   ,
465       prv     ,
466       bill_sign ,
467       usg_bcl_id  ,
468       level_element_id,
469       level_coverage_id   ,
470       line_prorate  ,
471       amount
472                                              )
473 values
474 (
475 p_detail_rec.price_list ,
476 p_detail_rec.price_list_line_id,
477 p_detail_rec.chr_id  ,
478 p_detail_rec.line_id ,
479 p_detail_rec.subline_id,
480 p_detail_rec.intent          ,
481 p_detail_rec.currency      ,
482 p_detail_rec.bcl_id            ,
483 p_detail_rec.bsl_id            ,
484 p_detail_rec.usage_qty      ,
485 p_detail_rec.usage_uom_code,
486 p_detail_rec.break_uom_code  ,
487 p_detail_rec.proration_yn            ,
488 p_detail_rec.bill_from_date           ,
489 p_detail_rec.bill_to_date                 ,
490 p_detail_rec.asking_unit_price ,
491 dnz_chr_id ,
492 currency_code ,
493 prorate   ,
494 prv     ,
495 p_sign ,
496 p_bcl_id,
497 level_element_id,
498 level_coverage_id,
499 p_prorate    ,
500 p_amount
501 ) ;
502 
503 commit;
504 
505 END Insert_usg_qp_dtls_prc;
506 
507 ---------------------------------------------------------------------------------------------------------
508 --Procedure Bill_usage_item_bulk Ignores QP call for zero quantity and calls procedure Insert_usg_qp_dtls_prc
509 --skuchima 05-Jan-2012 Bug 13105205 Ceredian ER
510 ----------------------------------------------------------------------------------------------------------
511 
512 Procedure Bill_usage_item_bulk(
513                p_dnz_chr_id              IN            NUMBER,
514                p_contract_number         IN            VARCHAR2,
515                p_con_num_modifier        IN            VARCHAR2,
516                p_line_number             IN            NUMBER,
517                p_lse_id                  IN            NUMBER,
518                p_object1_id1             IN            VARCHAR2,
519                p_object1_id2             IN            VARCHAR2,
520                p_top_line_id             IN            NUMBER,
521                p_top_line_start_date     IN            DATE,
522                p_top_line_term_date      IN            DATE,
523                p_top_line_end_date       IN            DATE,
524                p_inv_organization_id     IN            NUMBER,
525                p_currency_code           IN            VARCHAR2,
526                p_settlement_interval     IN            VARCHAR2,
527                p_uom_code                IN            VARCHAR2,
528                p_time_uom_code           IN            VARCHAR2,
529                p_okl_flag                IN            NUMBER,
530                p_prv                     IN            NUMBER,
531                p_date                    IN            DATE,
532                p_billrep_tbl             IN OUT NOCOPY OKS_BILL_REC_PUB.bill_report_tbl_type,
533                p_billrep_tbl_idx         IN            NUMBER,
534                p_billrep_err_tbl         IN OUT NOCOPY OKS_BILL_REC_PUB.billrep_error_tbl_type,
535                p_billrep_err_tbl_idx     IN OUT NOCOPY NUMBER,
536                p_ar_feeder_ctr           IN OUT NOCOPY NUMBER,
537                p_period_type             IN            VARCHAR2,
538                p_period_start            IN            VARCHAR2,
539                p_return_status           IN OUT NOCOPY VARCHAR2
540                )
541 IS
542 l_usage_type                VARCHAR2(10);
543 l_usage_period              VARCHAR2(10);
544 l_counter_uom_code          VARCHAR2(30);
545 l_flag                      VARCHAR2(10);
546 l_prorate                   VARCHAR2(10);
547 l_break_uom_code            VARCHAR2(10);
548 e_ptr                       NUMBER;
549 l_ptr                       NUMBER;
550 l_qty                       NUMBER;
551 l_level_qty                 NUMBER;
552 l_break_amount              NUMBER;
553 l_temp                      NUMBER;
554 l_sign                      NUMBER;
555 no_of_cycles                NUMBER;
556 l_line_total                NUMBER;
557 l_total                     NUMBER;
558 l_final_qty                 NUMBER;
559 l_bcl_id                    NUMBER;
560 l_amount                    NUMBER;
561 l_init_value                NUMBER;
562 l_final_value               NUMBER;
563 l_base_reading              NUMBER;
564 l_counter_value_id          NUMBER;
565 l_counter_grp_id            NUMBER;
566 l_sub_id                    NUMBER;
567 l_tsub_id                   NUMBER;
568 l_estimated_qty             NUMBER;
569 l_actual_qty                NUMBER;
570 l_quantity_ordered          NUMBER;
571 l_locked_price_list_id      NUMBER;
572 l_locked_price_list_line_id NUMBER;
573 i                           NUMBER;
574 l_inv_date                  DATE;
575 l_ar_inv_date               DATE;
576 l_bill_start_date           DATE;
577 l_bill_end_date             DATE;
578 l_exception_amount          NUMBER;
579 l_subline_count             NUMBER := 0;
580 l_counter_id                NUMBER;
581 l_lock_id                   NUMBER;
582 l_object_version            NUMBER;
583 l_lock_date                 DATE;
584 
585 
586 /* Variable for calling std API*/
587 l_api_version      CONSTANT NUMBER      := 1.0;
588 l_called_from      CONSTANT NUMBER      := 1;
589 l_init_msg_list    CONSTANT VARCHAR2(1) := 'F';
590 l_msg_count                 NUMBER;
591 l_msg_data                  VARCHAR2(2000);
592 l_return_status             VARCHAR2(1);
593 
594 
595 l_counter_reading_lock_rec  csi_ctr_datastructures_pub.ctr_reading_lock_rec;
596 
597 l_pbr_rec_in                OKS_PBR_PVT.pbrv_rec_type;
598 l_pbr_rec_out               OKS_PBR_PVT.pbrv_rec_type;
599 -------------------------------------------------------------------------
600 -- Begin partial period computation logic
601 -- Developer Mani Choudhary
602 -- Date 11-JUN-2005
603 -- local variables and cursors declared
604 -------------------------------------------------------------------------
605 l_rule_id                    NUMBER;
606 l_uom_code                   VARCHAR2(30);
607 CURSOR  l_billing_uom_csr(p_rul_id IN NUMBER) IS
608 SELECT  uom_code
609 FROM    oks_stream_levels_b
610 WHERE   id = p_rul_id;
611 -------------------------------------------------------------------------
612 
613 CURSOR l_inv_item_csr(p_cle_id Number,p_org_id Number) Is
614   SELECT item.Object1_id1
615         ,mtl.usage_item_flag
616         ,mtl.service_item_flag
617         ,mtl.primary_uom_code
618   FROM   Okc_K_items Item
619         ,mtl_system_items_b   mtl  --Okx_system_items_v mtl
620   WHERE  item.cle_id = p_cle_id
621   --AND    mtl.id1 = item.object1_id1
622   AND    mtl.inventory_item_id = item.object1_id1
623   AND    mtl.organization_id = p_org_id;
624 
625 
626 CURSOR l_usage_csr (p_cle_id IN NUMBER) IS
627   SELECT  usage_type                   Usage_Type,
628           usage_period                 Usage_period,
629           prorate                      Prorate,
630           locked_price_list_id         locked_price_list_id,
631           locked_price_list_line_id    locked_price_list_line_id
632   FROM    OKS_K_LINES_B
633   WHERE   cle_id = p_cle_id ;
634 
635 Cursor qty_uom_csr_sub(p_cle_id  Number) Is
636    SELECT  okc.Number_of_items
637             ,tl.Unit_of_measure uom_code
638      FROM   okc_k_items okc
639            ,mtl_units_of_measure_tl tl
640      WHERE  okc.cle_id = p_cle_id
641      AND    tl.uom_code = okc.uom_code
642      AND    tl.language = USERENV('LANG');
643 
644   /*
645   SELECT  Number_of_items
646          ,OKX.Unit_of_measure uom_code
647   FROM   OKC_K_ITEMS OKC
648         ,OKX_UNITS_OF_MEASURE_V OKX
649   WHERE  cle_id = P_cle_id
650   AND    Okx.uom_code = OKC.uom_code ;
651   */
652 
653 Cursor bsl_price_csr(p_bcl_id IN NUMBER, p_prv  IN   NUMBER) is
654   SELECT bsl.id bsl_id, bsl.average average, bsd.unit_of_measure uom_code,
655          bsl.date_billed_from ,bsl.date_billed_to,
656          bsl.cle_id, rline.prorate,
657          rline.locked_price_list_id,
658          rline.locked_price_list_line_id,
659          rline.dnz_chr_id
660   FROM
661         oks_k_lines_b           rline,
662         oks_bill_sub_lines      bsl,
663         oks_bill_sub_line_dtls  bsd
664   WHERE bsl.bcl_id = p_bcl_id
665   AND   bsl.id     = bsd.bsl_id
666   AND   rline.cle_id = bsl.cle_id
667   AND   p_prv      = 1
668   UNION
669   SELECT bsl.id bsl_id, bsl.average average, bsd.unit_of_measure uom_code,
670          bsl.date_billed_from ,bsl.date_billed_to,
671          bsl.cle_id , rline.prorate,
672          rline.LOCKED_PRICE_LIST_ID,
673          rline.locked_price_list_line_id,
674          rline.dnz_chr_id
675   FROM
676         oks_k_lines_b   rline,
677         oks_bsl_pr      bsl,
678         oks_bsd_pr      bsd
679   WHERE bsl.bcl_id = p_bcl_id
680   AND   bsl.id     = bsd.bsl_id
681   AND   rline.cle_id = bsl.cle_id
682   AND   p_prv      = 2;
683 
684 
685 CURSOR l_subline_Csr(p_cle_id  Number) Is
686    SELECT
687       sub_line.id                                        id
688      ,sub_line.cle_id                                    cle_id
689      ,sub_line.dnz_chr_id                                dnz_chr_id
690      ,sub_line.price_negotiated                          price_negotiated
691      ,sub_line.start_date                                start_date
692      ,sub_line.end_date                                  end_date
693      ,sub_line.date_terminated                           date_terminated
694      ,sub_line.line_number                               line_number
695      ,rul.fixed_quantity                                 fixed_qty
696      ,rul.minimum_quantity                               minimum_qty
697      ,rul.default_quantity                               default_qty
698      ,rul.amcv_flag                                      amcv_flag
699      ,rul.usage_period                                   usage_period
700      ,rul.usage_duration                                 usage_duration
701      ,rul.level_yn                                       level_yn
702      ,rul.base_reading                                   base_reading
703      ,rul.usage_type                                     usage_Type
704      ,rul.usage_est_yn                                   usage_est_yn
705      ,rul.usage_est_method                               usage_est_method
706      ,rul.usage_est_start_date                           usage_est_start_date
707    FROM   OKC_K_LINES_B sub_line ,
708           OKS_K_LINES_B rul
709    WHERE  sub_line.cle_id = p_cle_id
710    AND    sub_line.date_cancelled is NULL               --[llc]
711    AND    sub_line.id = rul.cle_id
712    AND    sub_line.lse_id in (8,7,9,10,11,13,25,35);
713    /*AND    not  exists ( select 1 from okc_k_rel_objs rel
714                         WHERE rel.cle_id = sub_line.id ); Commented for 16039680 */
715 
716 
717 /*FOR BILLING REPORT*/
718 
719 Cursor subline_count(p_cle_id  Number) Is
720         SELECT count(sub_line.id)
721         FROM   OKC_K_LINES_B sub_line
722         WHERE  sub_line.cle_id = p_cle_id
723         AND    sub_line.lse_id in (8,7,9,10,11,13,25,35)
724         AND    sub_line.date_cancelled is NULL;               --[llc]
725         /*AND    not  exists ( select 1 from okc_k_rel_objs rel
726                              where rel.cle_id = sub_line.id ); Commented for 16039680 */
727 
728 
729 Cursor get_counter_qty(p_cle_id Number, p_lock_read number) IS
730         select value_timestamp, counter_id
731         from cs_counter_values, okc_k_items
732         where cle_id = p_cle_id
733         and   to_char(counter_id) = object1_id1
734         and   counter_reading = p_lock_read;
735 
736 Cursor get_counter_vrt(p_cle_id Number) IS
737         select to_number(object1_id1)
738         from okc_k_items
739         where cle_id = p_cle_id;
740 
741 
742 --23-DEC-2005 mchoudha fix for bug#4915367
743 Cursor bill_amount_npr (p_id IN NUMBER,p_hdr_id IN NUMBER,p_date_start IN DATE,p_date_end IN DATE) IS
744 SELECT lvl.amount
745 FROM   oks_level_elements lvl
746 WHERE  lvl.cle_id = p_id
747 And    lvl.dnz_chr_id = p_hdr_id
748 And    lvl.date_start = p_date_start
749 And    lvl.date_end = p_date_end;
750 
751 
752 l_item_rec         l_inv_item_csr%ROWTYPE;
753 l_qty_uom_sub_rec  qty_uom_csr_sub%ROWTYPE;
754 l_subline_id       NUMBER;
755 l_status_text     varchar2(200);  --added for bug 9927490
756 
757 usage_exception EXCEPTION;
758 
759 BEGIN
760   If l_write_log then
761      FND_FILE.PUT_LINE(FND_FILE.LOG,'***Processing Usage Item ***');
762      FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Id:  ' || p_top_line_id);
763      FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Start Date: ' || p_top_line_start_date);
764      FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Termination Date/End date: ' || nvl(p_top_line_term_date,p_top_line_end_date));
765   End If;
766 
767 
768   p_return_status := 'S';
769   l_prorate  := '';
770   l_locked_price_list_id:= '';
771   l_locked_price_list_line_id:= '';
772 
773   --Start mchoudha Bug#3537100 22-APR-04
774   --For Billing Report
775   OPEN  subline_count(p_top_line_id);
776   FETCH subline_count into l_subline_count;
777   CLOSE subline_count;
778   --End  mchoudha Bug#3537100
779 
780 
781   OPEN  l_inv_item_csr(p_top_line_id,p_inv_organization_id);
782   FETCH l_inv_item_csr into l_item_rec;
783   CLOSE l_inv_item_csr;
784 
785   OPEN  l_usage_csr(p_top_line_id);
786   FETCH l_usage_csr into l_usage_type, l_usage_period , l_prorate ,
787         l_locked_price_list_id, l_locked_price_list_line_id;
788   CLOSE l_usage_csr;
789 
790   l_processed_lines_tbl(l_pr_tbl_idx).record_type  := 'Usage' ;
791   level_elements_tab.delete;
792 
793   OKS_BILL_UTIL_PUB.get_next_level_element(
794         P_API_VERSION        => l_api_version,
795         P_ID                 => p_top_line_id,
796         P_COVD_FLAG          => 'N',     ---- flag to indicate Top line
797         P_DATE               => p_date,
798         P_INIT_MSG_LIST      => l_init_msg_list,
799         X_RETURN_STATUS      => l_return_status,
800         X_MSG_COUNT          => l_msg_count,
801         X_MSG_DATA           => l_msg_data,
802         X_NEXT_LEVEL_ELEMENT => level_elements_tab );
803 
804   IF (l_return_status <> 'S')  THEN
805     oks_bill_rec_pub.get_message(
806                 l_msg_cnt  => l_msg_count,
807                 l_msg_data => l_msg_data);
808     l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
809     l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
810 
811     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in getting next level ');
812 
813     /*Needs to determine or revisited */
814     --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
815     Raise USAGE_EXCEPTION;
816    END IF;
817 
818    IF (level_elements_tab.count < 1)  THEN
819      l_processed_lines_tbl.DELETE(l_pr_tbl_idx) ;
820    END IF;
821 
822    e_ptr := 1;
823    no_of_cycles := level_elements_tab.count;
824    l_tsub_id := l_prs_tbl_idx;
825 
826    WHILE (e_ptr <= no_of_cycles)
827    LOOP
828      l_line_total      := l_line_total + level_elements_tab(e_ptr).bill_amount ;
829 
830      l_inv_date        := level_elements_tab(e_ptr).date_to_interface;
831      l_ar_inv_date     := level_elements_tab(e_ptr).date_transaction;
832      l_bill_start_date := level_elements_tab(e_ptr).bill_from_date;
833      l_bill_end_date   := level_elements_tab(e_ptr).bill_to_date;
834      -------------------------------------------------------------------------
835      -- Begin partial period computation logic
836      -- Developer Mani Choudhary
837      -- Date 11-JUN-2005
838      -- get the rul_id for oks_level_elements
839      -------------------------------------------------------------------------
840      IF p_period_type IS NOT NULL AND
841         p_period_start IS NOT NULL
842      THEN
843        l_rule_id         := level_elements_tab(e_ptr).rule_id;
844        OPEN l_billing_uom_csr(l_rule_id);
845        FETCH l_billing_uom_csr INTO l_uom_code;
846        CLOSE l_billing_uom_csr;
847      END IF;
848      --------------------------------------------------------------------------
849      /* Date_billed_to of top line should be manipulated if
850         termination_date lies between start_date and end_date
851         of billing period
852      */
853 
854      IF ( ( p_top_line_term_date  >= l_bill_start_date) AND
855           ( p_top_line_term_date <= l_bill_end_date)  ) THEN
856        l_bill_end_date := p_top_line_term_date - 1 ;
857      END IF;
858 
859      If l_write_log then
860         FND_FILE.PUT_LINE( FND_FILE.LOG,'Line Interface Date :' ||l_inv_date );
861         FND_FILE.PUT_LINE( FND_FILE.LOG,'Billing Period Start_date: ' || l_bill_start_date||' To '||l_bill_end_date);
862      End If;
863 
864      l_ptr       := 0;
865      l_total     := 0;
866      l_final_qty := 0;
867 
868      l_cov_tbl.delete;
869 
870      IF (trunc(l_inv_date) <= trunc(p_date)) THEN
871 
872 /*******
873      create bank account is no longer needed as part of R12 Bank account
874     consolidation project
875 
876        OKS_BILL_REC_PUB.create_bank_Account(
877                     p_dnz_chr_id      => p_dnz_chr_id,
878                     p_bill_start_date => p_top_line_start_date,
879                     p_currency_code   => p_currency_code,
880                     x_status          => l_return_status,
881                     l_msg_count       => l_msg_count,
882                     l_msg_data        => l_msg_data
883                     );
884 
885        IF (l_return_status <> 'S') THEN
886          OKS_BILL_REC_PUB.get_message
887                    (l_msg_cnt  => l_msg_count,
888                     l_msg_data => l_msg_data);
889          l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N';
890          l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
891 
892          FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in creating account');
893 
894 
895 
896          --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION') ;
897          Raise USAGE_EXCEPTION;
898        END IF;
899 
900 *******/
901 
902        FOR l_covlvl_rec in l_subline_csr(p_top_line_id)
903        LOOP
904 
905          IF ( ((l_covlvl_rec.date_terminated is not null) and
906                 (l_covlvl_rec.date_terminated > l_bill_start_date)) --l_inv_date))
907                 OR
908                 (l_covlvl_rec.date_terminated is  null))THEN
909            IF  ((l_ar_inv_date is not null)
910                  And (trunc(l_ar_inv_date) < trunc(sysdate)))  THEN
911              l_ar_inv_date := sysdate;
912            END IF;
913 
914               /*FOR BILLING REPORT*/
915               l_subline_id := l_covlvl_rec.id;
916 
917            OKS_BILL_REC_PUB.Insert_bcl
918                (P_CALLEDFROM        => l_called_from,
919                 X_RETURN_STAT       => l_return_status,
920                 P_CLE_ID            => p_top_line_id,
921                 P_DATE_BILLED_FROM  => l_bill_start_date,
922                 P_DATE_BILLED_TO    => l_bill_end_date,
923                 P_DATE_NEXT_INVOICE => l_ar_inv_date,
924                 P_BILL_ACTION       => 'RI',
925                 P_OKL_FLAG          => p_okl_flag,
926                 P_PRV               => p_prv,
927                 P_MSG_COUNT         => l_msg_count,
928                 P_MSG_DATA          => l_msg_data,
929                 X_BCL_ID            => l_bcl_id);
930 
931            IF (l_return_status <> 'S')  THEN
932              oks_bill_rec_pub.get_message
933                    (l_msg_cnt  => l_msg_count,
934                     l_msg_data => l_msg_data);
935              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
936              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
937              FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in insert bcl');
938 
939              --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
940              Raise USAGE_EXCEPTION;
941            END IF;
942 
943            IF (p_prv <> 2) THEN
944              UPDATE oks_level_elements
945              SET date_completed = l_bill_end_date
946              WHERE id =  level_elements_tab(e_ptr).id;
947            END IF;
948 
949            l_ptr := l_ptr + 1;
950            level_coverage.delete;
951 
952            OKS_BILL_UTIL_PUB.get_next_level_element(
953                P_API_VERSION        => l_api_version,
954                P_ID                 => l_covlvl_rec.id,
955                P_COVD_FLAG          => 'Y', -- flag to indicate Covered level
956                P_DATE               => l_inv_date ,      --l_bill_end_date,
957                P_INIT_MSG_LIST      => l_init_msg_list,
958                X_RETURN_STATUS      => l_return_status,
959                X_MSG_COUNT          => l_msg_count,
960                X_MSG_DATA           => l_msg_data,
961                X_NEXT_LEVEL_ELEMENT => level_coverage );
962 
963            IF ((l_return_status <> 'S')
964                    OR (level_coverage.count = 0)) THEN
965              OKS_BILL_REC_PUB.get_message
966                  (l_msg_cnt  => l_msg_count,
967                   l_msg_data => l_msg_data);
968              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
969              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
970              l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN := 'N' ;
971              l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
972              FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in get next level of coverage ');
973              --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
974              Raise USAGE_EXCEPTION;
975            END IF;
976 
977            /*Update date completed in coverage line */
978            IF (P_PRV <> 2) THEN
979              UPDATE oks_level_elements
980              SET date_completed = l_bill_end_date
981              WHERE id = level_coverage(1).id;
982            END IF;
983 
984            l_amount                := nvl(level_coverage(1).bill_amount,0);
985            l_calc_rec.l_calc_sdate := level_coverage(1).bill_from_date;
986            l_calc_rec.l_calc_edate := level_coverage(1).bill_to_date;
987 
988            IF (l_write_log) THEN
989              FND_FILE.PUT_LINE( FND_FILE.LOG,' Coverage amount    : '||l_amount);
990              FND_FILE.PUT_LINE( FND_FILE.LOG,' Coverage start_date: '||l_calc_rec.l_calc_sdate);
991              FND_FILE.PUT_LINE( FND_FILE.LOG,' Coverage end_date  : '||l_calc_rec.l_calc_edate);
992            END IF;
993 
994            IF (  l_covlvl_rec.date_terminated is not null)  AND
995                ( trunc(l_calc_rec.l_calc_edate) >=
996                               trunc(l_covlvl_rec.date_terminated)) THEN
997              l_calc_rec.l_calc_edate := l_covlvl_rec.date_terminated - 1;
998            END IF;
999 
1000            l_cov_tbl(l_ptr).flag              := Null;
1001            l_cov_tbl(l_ptr).id                := l_covlvl_rec.id ;
1002            l_cov_tbl(l_ptr).bcl_id            := l_bcl_id;
1003            l_cov_tbl(l_ptr).date_billed_from  := l_calc_rec.l_calc_sdate;
1004            l_cov_tbl(l_ptr).date_billed_to    := l_calc_rec.l_calc_edate;
1005 
1006            IF (p_prv = 2) THEN  -- FIX for BUG# 2998682
1007              l_cov_tbl(l_ptr).date_billed_from
1008                                := level_elements_tab(e_ptr).bill_from_date;
1009              l_cov_tbl(l_ptr).date_billed_to
1010                                := level_elements_tab(e_ptr).bill_to_date;
1011 
1012              ----for bug 4455174
1013              l_calc_rec.l_calc_sdate :=level_elements_tab(e_ptr).bill_from_date;
1014              l_calc_rec.l_calc_edate :=level_elements_tab(e_ptr).bill_to_date;
1015 
1016 	     --23-DEC-2005 mchoudha  Fix for bug#4915367
1017              --fetching amount in case of negotiated usage type
1018              IF l_usage_type = 'NPR' THEN
1019                Open bill_amount_npr(l_covlvl_rec.id,l_covlvl_rec.dnz_chr_id,l_cov_tbl(l_ptr).date_billed_from,
1020 	                             l_cov_tbl(l_ptr).date_billed_to);
1021                Fetch bill_amount_npr into l_amount;
1022                Close bill_amount_npr;
1023              END IF;
1024 
1025            END IF;
1026 
1027            l_cov_tbl(l_ptr).amount            := 0;
1028            l_cov_tbl(l_ptr).average           := 0;
1029            l_cov_tbl(l_ptr).unit_of_measure   := p_uom_code;
1030            l_cov_tbl(l_ptr).fixed             := 0;
1031            l_cov_tbl(l_ptr).actual            := null;
1032            l_cov_tbl(l_ptr).default_default   := 0;
1033            l_cov_tbl(l_ptr).amcv_yn      := NVL(l_covlvl_rec.amcv_flag,'N');
1034            l_cov_tbl(l_ptr).adjustment_level  := 0 ;
1035            l_cov_tbl(l_ptr).adjustment_minimum:= 0 ;
1036            l_cov_tbl(l_ptr).result            := 1 ;--0 ; --check it out
1037            l_cov_tbl(l_ptr).x_stat            := Null ;
1038            l_cov_tbl(l_ptr).amount            := l_amount;
1039            l_cov_tbl(l_ptr).bcl_amount        :=nvl(l_calc_rec.l_bcl_amount,0);
1040            l_cov_tbl(l_ptr).date_to_interface := sysdate;
1041 
1042            IF  (l_usage_type = 'NPR') THEN
1043              IF (l_write_log) THEN
1044                FND_FILE.PUT_LINE( FND_FILE.LOG, 'USAGE_TYPE of subline = NPR' );
1045              END IF;
1046 
1047              OPEN  qty_uom_csr_sub(l_covlvl_rec.id);
1048              FETCH qty_uom_csr_sub into l_qty_uom_sub_rec;
1049              CLOSE qty_uom_csr_sub;
1050 
1051              l_cov_tbl(l_ptr).result             := 0; --l_qty_uom_sub_rec.number_of_items;
1052              l_cov_tbl(l_ptr).actual             := 0;
1053              l_cov_tbl(l_ptr).estimated_quantity := 0;
1054              l_cov_tbl(l_ptr).x_stat             := null;
1055              l_cov_tbl(l_ptr).unit_of_measure    := l_qty_uom_sub_rec.uom_code;
1056              l_cov_tbl(l_ptr).amount             := l_amount;
1057 
1058 
1059            ELSIF (l_usage_type = 'FRT')  THEN
1060              IF (l_write_log) THEN
1061                FND_FILE.PUT_LINE( FND_FILE.LOG, 'USAGE_TYPE of subline = FRT');
1062              END IF;
1063 
1064              l_qty := l_covlvl_rec.fixed_qty;
1065 
1066              IF (nvl(l_qty,0) <> 0) THEN
1067                -------------------------------------------------------------------------
1068                -- Begin partial period computation logic
1069                -- Developer Mani Choudhary
1070                -- Date 11-JUN-2005
1071                -- call oks_bill_rec_pub.Get_prorated_Usage_Qty to get the prorated usage
1072                -------------------------------------------------------------------------
1073                IF p_period_type IS NOT NULL AND
1074                   p_period_start IS NOT NULL
1075                THEN
1076 
1077                  l_qty := OKS_BILL_REC_PUB.Get_Prorated_Usage_Qty
1078                        (
1079                        p_start_date  => l_calc_rec.l_calc_sdate,
1080                        p_end_date    => l_calc_rec.l_calc_edate,
1081                        p_qty         => l_qty,
1082                        p_usage_uom   => l_usage_period,
1083                        p_billing_uom => l_uom_code,
1084                        p_period_type => p_period_type
1085                        );
1086                  IF (Nvl(l_qty,0) = 0)  THEN
1087                    l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN := 'N' ;
1088                    l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero ';
1089                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
1090                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero';
1091                    FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error Get_Prorated_Usage_Qty returns l_qty as '||l_qty);
1092 
1093                   --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
1094                    Raise USAGE_EXCEPTION;
1095                  END IF;
1096                  l_qty := Round(l_qty,0);
1097                ELSE
1098                  --Existing logic
1099                  l_temp := OKS_TIME_MEASURES_PUB.GET_TARGET_QTY
1100                             (p_start_date  => l_calc_rec.l_calc_sdate,
1101                              p_source_qty  => 1,
1102                              p_source_uom  => l_usage_period,
1103                              p_target_uom  => p_time_uom_code,
1104                              p_round_dec   => 0
1105                              );
1106 
1107                  IF (Nvl(l_temp,0) = 0)  THEN
1108                    l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN := 'N' ;
1109                    l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero ';
1110                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
1111                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero';
1112                    FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error Get_target_qty returns Zero');
1113 
1114                   --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
1115                    Raise USAGE_EXCEPTION;
1116                  END IF;
1117 		 /* Modified for Bug#15897052 */
1118                  l_qty := ((l_qty * (l_calc_rec.l_calc_edate -
1119                                 l_calc_rec.l_calc_sdate + 1))/l_temp) ;
1120 
1121                END IF; --p_period_type IS NOT NULL
1122              END IF;   --IF (nvl(l_qty,0) <> 0)
1123              l_cov_tbl(l_ptr).unit_of_measure    := p_uom_code;
1124              l_cov_tbl(l_ptr).fixed              := l_qty;
1125              l_cov_tbl(l_ptr).result             := l_qty;
1126              l_cov_tbl(l_ptr).actual             := 0;
1127              l_cov_tbl(l_ptr).estimated_quantity := 0;
1128              l_cov_tbl(l_ptr).sign               := 1;
1129              l_cov_tbl(l_ptr).average            := l_qty;
1130              l_cov_tbl(l_ptr).unit_of_measure    :=l_item_rec.primary_uom_code;
1131 
1132            ELSIF (l_usage_type in ('VRT','QTY')) THEN
1133              -------------------------------------------------------------------------
1134              -- Begin partial period computation logic
1135              -- Developer Mani Choudhary
1136              -- Date 11-JUN-2005
1137              -- Added additional period_type, period start parameters
1138              -------------------------------------------------------------------------
1139              OKS_BILL_REC_PUB.Usage_qty_to_bill
1140                 (
1141                 P_calledfrom            => p_prv, --1 for normal ,2 for preview,
1142                 P_cle_id                => l_covlvl_rec.id,
1143                 P_Usage_type            => l_usage_type,
1144                 P_estimation_flag       => l_covlvl_rec.usage_est_yn,
1145                 P_estimation_method     => l_covlvl_rec.usage_est_method,
1146                 p_default_qty           => l_covlvl_rec.Default_qty,
1147                 P_cov_start_date        => l_covlvl_rec.start_date,
1148                 P_cov_end_date          => l_covlvl_rec.end_date,
1149                 P_cov_prd_start_date    => l_calc_rec.l_calc_sdate,
1150                 P_cov_prd_end_date      => l_calc_rec.l_calc_edate,
1151                 p_usage_period          => l_usage_period,
1152                 p_time_uom_code         => p_time_uom_code,
1153                 p_settle_interval       => p_settlement_interval,
1154                 p_minimum_quantity      => l_covlvl_rec.minimum_qty,
1155                 p_usg_est_start_date    => l_covlvl_rec.usage_est_start_date,
1156                 p_period_type           => p_period_type, --period type
1157                 p_period_start          => p_period_start, --period start
1158                 X_qty                   => l_qty,
1159                 X_Uom_Code              => l_counter_uom_code,
1160                 X_flag                  => l_flag,
1161                 X_end_reading           => l_final_value,
1162                 X_start_reading         => l_init_value,
1163                 X_base_reading          => l_base_reading,
1164                 X_estimated_qty         => l_estimated_qty,
1165                 X_actual_qty            => l_actual_qty,
1166                 X_counter_value_id      => l_counter_value_id,
1167                 X_counter_group_id      => l_counter_grp_id,
1168                 X_return_status         => l_return_status
1169                   );
1170 
1171 
1172              IF (l_return_status <> 'S') THEN
1173                oks_bill_rec_pub.get_message
1174                        (l_msg_cnt  => l_msg_count,
1175                         l_msg_data => l_msg_data);
1176                l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN := 'N' ;
1177                l_processed_lines_tbl(l_pr_tbl_idx).Error_Message:= 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
1178                l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN := 'N' ;
1179                l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message:= 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
1180 
1181                Raise USAGE_EXCEPTION;
1182              END IF;
1183 
1184 
1185             IF (l_write_log) THEN
1186                FND_FILE.PUT_LINE( FND_FILE.LOG, 'After counter values X_value'||' '||l_qty);
1187             END IF;
1188 
1189             l_cov_tbl(l_ptr).result             :=nvl(l_qty, 0);
1190             l_cov_tbl(l_ptr).actual             :=l_actual_qty ;
1191             l_cov_tbl(l_ptr).unit_of_measure    :=l_item_rec.primary_uom_code;
1192             l_cov_tbl(l_ptr).start_reading      :=l_init_value;
1193             l_cov_tbl(l_ptr).end_reading        :=l_final_value;
1194             l_cov_tbl(l_ptr).base_reading       :=l_base_reading;
1195             l_cov_tbl(l_ptr).ccr_id             :=l_counter_value_id;
1196             l_cov_tbl(l_ptr).cgr_id             :=l_counter_grp_id;
1197             l_cov_tbl(l_ptr).flag               :=l_flag;
1198             l_cov_tbl(l_ptr).estimated_quantity :=l_estimated_qty;
1199 
1200 /******
1201      code changes for R12 project IB Counters Uptake.
1202      The below code is to lock the counter for Actual Per Period and Actual By Qty
1203 *****/
1204 
1205           if p_prv = 1 Then
1206             IF nvl(l_actual_qty,0) > 0 Then   ---- reading captured for the billed period
1207                 open get_counter_qty(l_covlvl_rec.id,l_final_value);
1208 	        fetch get_counter_qty into l_lock_date, l_counter_id;
1209 	        close get_counter_qty;
1210 
1211                IF (l_write_log) THEN
1212                    FND_FILE.PUT_LINE( FND_FILE.LOG, 'Cll IB Lock '||l_lock_date||', Counter id '||l_counter_id);
1213                END IF;
1214 
1215                l_counter_reading_lock_rec.reading_lock_date := l_lock_date;
1216                l_counter_reading_lock_rec.counter_id := l_counter_id;
1217                l_counter_reading_lock_rec.source_line_ref_id := l_covlvl_rec.id;
1218                l_counter_reading_lock_rec.source_line_ref := 'CONTRACT_LINE';
1219 
1220                Csi_Counter_Pub.create_reading_lock
1221                (
1222                     p_api_version          => 1.0,
1223                     p_commit               => 'F',
1224                     p_init_msg_list        => 'T',
1225                     p_validation_level     => 100,
1226                     p_ctr_reading_lock_rec => l_counter_reading_lock_rec,
1227                     x_return_status       => l_return_status,
1228                     x_msg_count           => l_msg_count,
1229                     x_msg_data            => l_msg_data,
1230                     x_reading_lock_id     => l_lock_id
1231 		);
1232 
1233             End If; --- for actual qty check
1234           End if;
1235 
1236 
1237          END IF;  -- l_usage_type = NPR
1238 
1239          IF (l_covlvl_rec.level_yn = 'Y') THEN
1240              l_final_qty := nvl(l_final_qty,0) + nvl(l_qty,0);
1241              l_total := nvl(l_total,0) + 1;
1242            END IF;
1243 
1244            l_cov_tbl(l_ptr).average := nvl(l_qty, 0);
1245 
1246          END IF;
1247          l_tsub_id := l_tsub_id +1;
1248        END LOOP;  --Covered level for loop
1249 
1250        IF (l_cov_tbl.count > 0) THEN
1251          IF (l_usage_type in ('VRT','QTY')) THEN
1252            IF (( nvl(l_total,0) <> 0) and (nvl(l_final_qty,0) <> 0) ) THEN
1253              l_level_qty := Round(l_final_qty/l_total);
1254            END IF;
1255 
1256            -------------------------------------------------------------------------
1257            -- Begin partial period computation logic
1258            -- Developer Mani Choudhary
1259            -- Date 12-JUN-2005
1260            -- Added two parameters p_period_start and p_period_type
1261            -------------------------------------------------------------------------
1262            level
1263              (
1264               P_LEVEL_QTY     => l_level_qty,
1265               P_COV_TBL       => l_cov_tbl,
1266               P_QTY           => l_qty,
1267               --P_LINE_TBL      => l_line_tbl,
1268               P_USAGE_PERIOD  => l_usage_period,
1269               P_TIME_UOM_CODE => p_time_uom_code,
1270               P_UOM_CODE      => l_uom_code,
1271               P_PERIOD_TYPE   => P_PERIOD_TYPE,
1272               P_PERIOD_START  => P_PERIOD_START,
1273               X_RETURN_STATUS => l_return_status
1274               );
1275 
1276            IF (l_write_log) THEN
1277               FND_FILE.PUT_LINE( FND_FILE.LOG, 'Level '||'  '||l_return_status);
1278            END IF;
1279 
1280            IF (l_return_status <> 'S') THEN
1281              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
1282              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message:= 'Error: '|| sqlerrm||'. Error Message:' ;
1283 
1284              FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error in LEVEL ') ;
1285              --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
1286              Raise USAGE_EXCEPTION;
1287            END IF;
1288          END IF; -- l_usage_type in 'VRT','QTY'
1289 
1290          p_ar_feeder_ctr := 1;
1291          l_sign := l_cov_tbl(l_ptr).sign;
1292 
1293          OKS_BILL_REC_PUB.Insert_all_subline
1294            (
1295             P_CALLEDFROM     => l_called_from,
1296             X_RETURN_STAT    => l_return_status,
1297             P_COVERED_TBL    => l_cov_tbl,
1298             P_CURRENCY_CODE  => p_currency_code,
1299             P_DNZ_CHR_ID     => p_dnz_chr_id,
1300             P_PRV            => p_prv,
1301             P_MSG_COUNT      => l_msg_count,
1302             P_MSG_DATA       => l_msg_data
1303             );
1304 
1305          IF (l_usage_type <> 'NPR') THEN
1306             l_sub_id := l_prs_tbl_idx;
1307 
1308             FOR bsl_price_rec in bsl_price_csr(l_bcl_id,p_prv)
1309             LOOP
1310               l_price_break_details.delete;
1311 
1312               l_line_rec.line_id          := p_top_line_id;
1313               l_line_rec.intent           := 'USG';
1314               l_line_rec.usage_qty        := bsl_price_rec.average; -- qty
1315               l_line_rec.usage_uom_code   := bsl_price_rec.uom_code;
1316               l_line_rec.bsl_id           := bsl_price_rec.bsl_id;
1317               l_line_rec.subline_id       := bsl_price_rec.cle_id;
1318 
1319               IF ( nvl(bsl_price_rec.prorate,l_prorate) = 'ALL') THEN
1320                 l_line_rec.bill_from_date := bsl_price_rec.date_billed_from;
1321                 l_line_rec.bill_to_date   := bsl_price_rec.date_billed_to;
1322 
1323 
1324                 OKS_TIME_MEASURES_PUB.get_duration_uom
1325                    ( P_START_DATE    => bsl_price_rec.date_billed_from,
1326                      P_END_DATE      => bsl_price_rec.date_billed_to,
1327                      X_DURATION      => l_quantity_ordered,
1328                      X_TIMEUNIT      => l_break_uom_code,
1329                      X_RETURN_STATUS => l_return_status
1330                    );
1331 
1332                 l_line_rec.break_uom_code   := l_break_uom_code;
1333 
1334               ELSE
1335                 l_line_rec.bill_from_date := '';
1336                 l_line_rec.bill_to_date   := '';
1337 		--mchoudha bug#4128070 22-JAN-2005
1338                 l_line_rec.break_uom_code   := NULL;
1339               END IF;
1340 
1341 
1342               l_line_rec.price_list
1343                :=nvl(bsl_price_rec.LOCKED_PRICE_LIST_ID,l_locked_price_list_id);
1344               l_line_rec.price_list_line_id
1345                :=nvl(bsl_price_rec.locked_price_list_line_id,l_locked_price_list_line_id);
1346 
1347 
1348                /*skuchima Ceredian ER comment the call to OKS_QP_PKG and dump the data into a temp table */
1349               /*Pricing API to calculate amount */
1350              /* OKS_QP_PKG.CALC_PRICE
1351                 (
1352                  P_DETAIL_REC          => l_line_rec,
1353                  X_PRICE_DETAILS       => l_price_rec,
1354                  X_MODIFIER_DETAILS    => l_modifier_details,
1355                  X_PRICE_BREAK_DETAILS => l_price_break_details,
1356                  X_RETURN_STATUS       => l_return_status,
1357                  X_MSG_COUNT           => l_msg_count,
1358                  X_MSG_DATA            => l_msg_data
1359                 );
1360               */
1361 
1362      If (l_line_rec.usage_qty <>0 OR ( l_line_rec.usage_qty=0 AND nvl(FND_PROFILE.VALUE('OKS_USAGE_SKIP_QP_CALL_ZERO_QTY'),'N') = 'N')) THEN
1363         Begin
1364         --skuchima Ceredian ER call the procedure to insert data into temp table
1365                 Insert_usg_qp_dtls_prc(
1366                                  l_line_rec,
1367                                  bsl_price_rec.dnz_chr_id ,
1368                                  p_currency_code ,
1369                                  bsl_price_rec.prorate   ,
1370                                  p_prv     ,
1371                                  l_sign    ,
1372                                  l_bcl_id  ,
1373                                  level_elements_tab(e_ptr).id,
1374                                  level_coverage(1).id ,
1375                                  l_prorate   ,
1376                                  l_amount
1377                                 );
1378          Exception
1379            WHEN OTHERS THEN
1380                l_msg_data := 'Error inserting data into oks_usg_qp_call_tbl '||SQLERRM;
1381                Raise USAGE_EXCEPTION;
1382 
1383           END;
1384 
1385       Else
1386             /*FOR BILLING REPORT*/
1387               l_exception_amount := 0;
1388               l_price_rec.PROD_EXT_AMOUNT :=0;
1389               l_price_rec.PROD_EXT_AMOUNT:=l_price_rec.PROD_EXT_AMOUNT*l_sign;
1390 
1391               OKS_BILL_REC_PUB.update_bsl
1392                   (
1393                    X_RET_STAT     => l_return_status,
1394                    P_DNZ_CHR_ID   => p_dnz_chr_id,
1395                    P_BSL_ID       => bsl_price_rec.bsl_id,
1396                    P_BCL_ID       => l_bcl_id,
1397                    P_AMOUNT       => l_price_rec.PROD_EXT_AMOUNT,
1398                    P_CURRENCY_CODE=> p_currency_code,
1399                    P_PRV          => p_prv
1400                    );
1401 
1402               IF (l_return_status <> 'S') THEN
1403                 oks_bill_rec_pub.get_message
1404                    (l_msg_cnt  => l_msg_count,
1405                     l_msg_data => l_msg_data);
1406 
1407                 FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error update bsl'||'  '||l_return_status);
1408                 --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
1409                 Raise USAGE_EXCEPTION;
1410               END IF;
1411 
1412      END IF; --l_line_rec.usage_qty <>0
1413 
1414               l_sub_id := l_sub_id + 1;
1415             END LOOP; --FOR bsl_price_rec in bsl_price_csr(l_bcl_id)
1416 
1417          END IF;   -- (l_usage_type <> 'NPR')
1418 
1419        END IF;
1420 
1421      END IF;  -- l_inv_date <= p_date
1422 
1423 
1424      e_ptr  :=  e_ptr  + 1;
1425      l_tsub_id := l_prs_tbl_idx;
1426 
1427    END LOOP;  --While eptr < no_of_cycles
1428 
1429 
1430 
1431 
1432 EXCEPTION
1433   WHEN USAGE_EXCEPTION THEN
1434   /*FOR BILLING REPORT*/
1435   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
1436   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_amount,0) + nvl(l_exception_amount,0) ;
1437   /*FOR ERROR REPORT*/
1438   p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
1439   p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
1440   p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 12;
1441   p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=  l_subline_id ;
1442   p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
1443 
1444   p_return_status := 'E';
1445   WHEN OTHERS THEN
1446   /*FOR BILLING REPORT*/
1447   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
1448   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_amount,0) + nvl(l_exception_amount,0) ;
1449   /*FOR ERROR REPORT*/
1450   p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
1451   p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
1452   p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 12;
1453   p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=  l_subline_id ;
1454   p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
1455 
1456 
1457   p_return_status := 'E';
1458 END  Bill_usage_item_bulk;
1459 
1460 /*
1461 ---------------------------------------------------------------------------------------------------------
1462 --Procedure Rollback_usg_bill_dtls_prc rollbacks the data of usage lines from billing tables if there is any error in QP bulk mode
1463 --skuchima 05-Jan-2012 Bug 13105205 Ceredian ER
1464 ----------------------------------------------------------------------------------------------------------
1465 */
1466 
1467 Procedure Rollback_usg_bill_dtls_prc(
1468 p_line_id in number,
1469 p_dnz_chr_id in number,
1470 p_prv in number
1471 ) is
1472 
1473 Begin
1474 
1475 If p_prv=1 Then
1476 
1477 Delete from OKS_BILL_SUB_LINE_DTLS
1478 where bsl_id in
1479          (select bsl_id from oks_usg_qp_call_tbl where line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1480 
1481 Delete from OKS_BILL_SUB_LINES
1482 where id in
1483          (select bsl_id from oks_usg_qp_call_tbl where line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1484 
1485 Delete from OKS_BILL_CONT_LINES
1486 where id in
1487          (select usg_bcl_id from oks_usg_qp_call_tbl where line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1488 
1489 UPDATE oks_level_elements
1490 SET date_completed = null
1491 WHERE id in
1492          (select level_element_id from oks_usg_qp_call_tbl where  line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1493 
1494 UPDATE oks_level_elements
1495 SET date_completed = null
1496 WHERE id in
1497           (select level_coverage_id from oks_usg_qp_call_tbl where  line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1498 
1499 Else
1500 
1501 Delete from OKS_BSD_PR
1502 where bsl_id in
1503           (select bsl_id from oks_usg_qp_call_tbl where line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1504 
1505 Delete from OKS_BSL_PR
1506 where id in
1507           (select bsl_id from oks_usg_qp_call_tbl where line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1508 
1509 Delete from OKS_BCL_PR
1510 where id in
1511            (select usg_bcl_id from oks_usg_qp_call_tbl where line_id=Nvl(p_line_id,LINE_ID) and dnz_chr_id=p_dnz_chr_id);
1512 
1513 end if;
1514 
1515 Exception
1516 When others then
1517 FND_FILE.PUT_LINE(FND_FILE.LOG,'Error in procedure delete_billing_tables '||sqlerrm || 'for line_id '||p_line_id ||' for header id '||p_dnz_chr_id);
1518 End Rollback_usg_bill_dtls_prc;
1519 
1520 
1521 ---------------------------------------------------------------------------------------------------------
1522 --Procedure modifier_4_usg Inserts modifiers data into price adjustments table after call to QP
1523 --skuchima 05-Jan-2012 Bug 13105205 Ceredian ER
1524 ----------------------------------------------------------------------------------------------------------
1525 Procedure Modifier_4_usg (
1526       p_bsl_id                        IN       NUMBER,
1527       p_modifier_details              IN       qp_preq_grp.line_detail_tbl_type,
1528       x_return_status                 OUT NOCOPY VARCHAR2
1529    )
1530    IS
1531       l_api_name                     CONSTANT VARCHAR2 (30)
1532                                                           := 'modifier_4_usg';
1533       i                                       NUMBER;
1534       l_in_tbl                                okc_price_adjustment_pub.patv_tbl_type;
1535       l_out_tbl                               okc_price_adjustment_pub.patv_tbl_type;
1536       l_return_status                         VARCHAR2 (1) := 'S';
1537       l_msg_count                             NUMBER;
1538       l_msg_data                              VARCHAR2 (2000) := NULL;
1539       l_api_version                  CONSTANT NUMBER := 1.0;
1540       l_init_msg_list                CONSTANT VARCHAR2 (1) := 'F';
1541    BEGIN
1542 
1543 
1544       i                          := p_modifier_details.FIRST;
1545 
1546       IF i IS NOT NULL
1547       THEN
1548          LOOP
1549             l_in_tbl (1).bsl_id        := p_bsl_id;
1550             l_in_tbl (1).list_line_id  := p_modifier_details (i).list_line_id;
1551             l_in_tbl (1).adjusted_amount :=
1552                                      p_modifier_details (i).adjustment_amount;
1553             l_in_tbl (1).operand       :=
1554                                          p_modifier_details (i).operand_value;
1555             l_in_tbl (1).arithmetic_operator :=
1556                               p_modifier_details (i).operand_calculation_code;
1557             l_in_tbl (1).accrual_conversion_rate :=
1558                                p_modifier_details (i).accrual_conversion_rate;
1559             l_in_tbl (1).accrual_flag  := p_modifier_details (i).accrual_flag;
1560             l_in_tbl (1).applied_flag  := p_modifier_details (i).applied_flag;
1561             l_in_tbl (1).automatic_flag :=
1562                                         p_modifier_details (i).automatic_flag;
1563             l_in_tbl (1).benefit_qty   := p_modifier_details (i).benefit_qty;
1564             l_in_tbl (1).benefit_uom_code :=
1565                                       p_modifier_details (i).benefit_uom_code;
1566             l_in_tbl (1).charge_subtype_code :=
1567                                    p_modifier_details (i).charge_subtype_code;
1568             l_in_tbl (1).charge_type_code :=
1569                                       p_modifier_details (i).charge_type_code;
1570             l_in_tbl (1).expiration_date :=
1571                                        p_modifier_details (i).expiration_date;
1572             l_in_tbl (1).include_on_returns_flag :=
1573                                p_modifier_details (i).include_on_returns_flag;
1574             l_in_tbl (1).list_header_id :=
1575                                         p_modifier_details (i).list_header_id;
1576             l_in_tbl (1).list_line_no  := p_modifier_details (i).list_line_no;
1577             l_in_tbl (1).list_line_type_code :=
1578                                    p_modifier_details (i).list_line_type_code;
1579             l_in_tbl (1).modifier_level_code :=
1580                                    p_modifier_details (i).modifier_level_code;
1581             l_in_tbl (1).modifier_mechanism_type_code :=
1582                            p_modifier_details (i).created_from_list_type_code;
1583             l_in_tbl (1).price_break_type_code :=
1584                                  p_modifier_details (i).price_break_type_code;
1585             l_in_tbl (1).pricing_group_sequence :=
1586                                 p_modifier_details (i).pricing_group_sequence;
1587             l_in_tbl (1).pricing_phase_id :=
1588                                       p_modifier_details (i).pricing_phase_id;
1589             l_in_tbl (1).proration_type_code :=
1590                                    p_modifier_details (i).proration_type_code;
1591             l_in_tbl (1).rebate_transaction_type_code :=
1592                           p_modifier_details (i).rebate_transaction_type_code;
1593             l_in_tbl (1).source_system_code :=
1594                                     p_modifier_details (i).source_system_code;
1595             l_in_tbl (1).substitution_attribute :=
1596                                 p_modifier_details (i).substitution_attribute;
1597             l_in_tbl (1).update_allowed :=
1598                                          p_modifier_details (i).override_flag;
1599             l_in_tbl (1).updated_flag  := p_modifier_details (i).updated_flag;
1600             okc_price_adjustment_pub.create_price_adjustment
1601                                          (p_api_version                      => 1.0,
1602                                           p_init_msg_list                    => okc_api.g_false,
1603                                           x_return_status                    => l_return_status,
1604                                           x_msg_count                        => l_msg_count,
1605                                           x_msg_data                         => l_msg_data,
1606                                           p_patv_tbl                         => l_in_tbl,
1607                                           x_patv_tbl                         => l_out_tbl
1608                                          );
1609 
1610             IF l_return_status <> 'S'
1611             THEN
1612                x_return_status            := l_return_status;
1613                okc_api.set_message
1614                                   (g_app_name,
1615                                    g_required_value,
1616                                    g_col_name_token,
1617                                    'Usage Modifier creation Error bsl id ' ||
1618                                    p_bsl_id ||
1619                                    ' Modifier ' ||
1620                                    p_modifier_details (i).list_line_id
1621                                   );
1622                RAISE fnd_api.g_exc_error;
1623             END IF;
1624 
1625             EXIT WHEN i = p_modifier_details.LAST;
1626             i                          := p_modifier_details.NEXT (i);
1627          END LOOP;
1628       END IF;                                                       -- i check
1629 
1630       x_return_status            := l_return_status;
1631 
1632 
1633  END modifier_4_usg;
1634 
1635 Procedure update_version (
1636      p_dnz_chr_id  IN NUMBER
1637 ) IS  pragma autonomous_transaction;
1638 
1639  l_con_update_date  date;
1640  l_chrv_rec         OKC_CONTRACT_PUB.chrv_rec_type;
1641  l_chrv_out_rec     OKC_CONTRACT_PUB.chrv_rec_type;
1642  l_cvmv_rec         OKC_CVM_PVT.cvmv_rec_type ;
1643  l_cvmv_out_rec     OKC_CVM_PVT.cvmv_rec_type ;
1644  l_return_status               VARCHAR2(1);
1645  l_msg_data                    VARCHAR2(2000);
1646  l_msg_cnt                     NUMBER;
1647  l_api_version      CONSTANT   NUMBER      := 1.0;
1648  l_init_msg_list    CONSTANT   VARCHAR2(1) := 'F';
1649 
1650 Cursor l_contract_update_date(p_chr_id IN NUMBER) is
1651   SELECT last_update_date from okc_k_headers_b
1652   WHERE id = p_chr_id;
1653 
1654 
1655   BEGIN
1656 
1657 	   OPEN  l_contract_update_date(p_dnz_chr_id);
1658 	   FETCH l_contract_update_date into l_con_update_date;
1659 	   CLOSE l_contract_update_date;
1660 
1661 	   IF (trunc(l_con_update_date) <> trunc(sysdate)) THEN
1662 	     okc_cvm_pvt.g_trans_id := 'XXX';
1663 	     l_cvmv_rec.chr_id := p_dnz_chr_id;
1664 
1665           OKC_CVM_PVT.update_contract_version(
1666 	       P_API_VERSION    => l_api_version,
1667 	       P_INIT_MSG_LIST  => l_init_msg_list,
1668 	       X_RETURN_STATUS  => l_return_status,
1669 	       X_MSG_COUNT      => l_msg_cnt,
1670 	       X_MSG_DATA       => l_msg_data,
1671 	       P_CVMV_REC       => l_cvmv_rec,
1672 	       X_CVMV_REC       => l_cvmv_out_rec);
1673 
1674           IF l_write_log THEN
1675             FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After calling OKC_CVM_PVT.update_contract_version l_return_status '||l_return_status);
1676           END IF;
1677 
1678           l_chrv_rec.id := p_dnz_chr_id;
1679 	     l_chrv_rec.last_update_date := sysdate;
1680 
1681 	     OKC_CONTRACT_PUB.update_contract_header(
1682 	       P_API_VERSION       => l_api_version,
1683 	       X_RETURN_STATUS     => l_return_status,
1684 	       P_INIT_MSG_LIST     => OKC_API.G_TRUE,
1685 	       X_MSG_COUNT         => l_msg_cnt,
1686 	       X_MSG_DATA          => l_msg_data,
1687 	       P_RESTRICTED_UPDATE => OKC_API.G_TRUE,
1688 	       P_CHRV_REC          => l_chrv_rec,
1689 	       X_CHRV_REC          => l_chrv_out_rec);
1690 
1691           IF l_write_log THEN
1692              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After calling OKC_CONTRACT_PUB.update_contract_header l_return_status '||l_return_status);
1693           END IF;
1694 
1695 		COMMIT;
1696 
1697         END IF;
1698 
1699     EXCEPTION
1700         WHEN  OTHERS THEN
1701         FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Failed- updating version'||sqlerrm );
1702 
1703 End update_version;
1704 
1705 
1706 ---------------------------------------------------------------------------------------------------------
1707 --Procedure Usg_billing_bulk_qp_call_prc Calls the QP to calculate price for usage billing
1708 --skuchima 05-Jan-2012 Bug 13105205 Ceredian ER
1709 ----------------------------------------------------------------------------------------------------------
1710 
1711 Procedure Usg_billing_bulk_qp_call_prc (
1712                               p_process_counter IN OUT NOCOPY NUMBER,
1713                               p_reject_counter  IN OUT NOCOPY NUMBER,
1714                               p_billrep_tbl             IN OUT NOCOPY OKS_BILL_REC_PUB.bill_report_tbl_type,
1715                               p_billrep_err_tbl         IN OUT NOCOPY OKS_BILL_REC_PUB.billrep_error_tbl_type,
1716                               p_billrep_err_tbl_idx     IN OUT NOCOPY NUMBER,
1717                               P_calledfrom                IN         NUMBER,
1718                               P_flag                      IN         NUMBER                               ,
1719                               P_date                      IN         DATE                                  ,
1720                               p_prv IN NUMBER,
1721                               RETCODE OUT NOCOPY NUMBER
1722                              ) IS
1723 
1724 
1725 CURSOR bulk_qp_hdr_id_csr is
1726   SELECT distinct dnz_chr_id
1727   FROM   oks_usg_qp_call_tbl;
1728 
1729 CURSOR bulk_qp_call_csr(p_chr_id IN number) is
1730   SELECT price_list ,
1731          price_list_line_id,
1732          chr_id  ,
1733          line_id ,
1734          subline_id,
1735          intent          ,
1736          currency      ,
1737          bcl_id           ,
1738          bsl_id            ,
1739          usage_qty      ,
1740          usage_uom_code,
1741          break_uom_code  ,
1742          proration_yn            ,
1743          bill_from_date           ,
1744          bill_to_date                 ,
1745          asking_unit_price,
1746          dnz_chr_id ,
1747          currency_code ,
1748          prorate   ,
1749          prv     ,
1750          bill_sign  ,
1751          usg_bcl_id ,
1752          level_element_id,
1753          level_coverage_id  ,
1754          amount
1755   FROM   oks_usg_qp_call_tbl
1756   WHERE  dnz_chr_id=p_chr_id;
1757 
1758  CURSOR usage_line_csr (p_dnz_chr_id IN number) is
1759    SELECT DISTINCT line_id,currency_code
1760    FROM   oks_usg_qp_call_tbl
1761    WHERE  dnz_Chr_id=p_dnz_chr_id;
1762 
1763 CURSOR bsl_cur (p_line_id IN NUMBER,p_dnz_chr_id IN number) is
1764    SELECT *
1765    FROM  oks_usg_qp_call_tbl
1766    WHERE dnz_Chr_id=p_dnz_chr_id
1767    AND   line_id=p_line_id;
1768 
1769 l_subline_id     NUMBER;
1770 bsl_index        NUMBER;
1771 l_amount         NUMBER;
1772 l_subline_count  NUMBER;
1773 l_top_ctr        NUMBER;
1774 l_rel_index      NUMBER;
1775 l_lin_index      NUMBER;
1776 l_ctr            NUMBER;
1777 p_billrep_tbl_idx NUMBER;
1778 p                 NUMBER;
1779 l_visit_cnt       NUMBER:=0;
1780 
1781 bulk_usage_exception       EXCEPTION;
1782 
1783 bulk_contract_exception    EXCEPTION;
1784 
1785 bulk_usage_line_exception  EXCEPTION;
1786 
1787 
1788 g_module  CONSTANT VARCHAR2 (250)  := 'oks.plsql.BILLING.' || '.';
1789 
1790       l_control_rec                           qp_preq_grp.control_record_type;
1791       l_req_line_tbl                          qp_preq_grp.line_tbl_type;
1792       l_req_line_detail_tbl                   qp_preq_grp.line_detail_tbl_type;
1793       l_req_related_lines_tbl                 qp_preq_grp.related_lines_tbl_type;
1794       l_req_qual_tbl                          qp_preq_grp.qual_tbl_type;
1795       l_req_line_attr_tbl                     qp_preq_grp.line_attr_tbl_type;
1796       l_req_line_detail_qual_tbl              qp_preq_grp.line_detail_qual_tbl_type;
1797       l_req_line_detail_attr_tbl              qp_preq_grp.line_detail_attr_tbl_type;
1798 
1799       lx_return_status                        varchar2 (1);
1800       lx_return_status_text                   varchar2 (2000);
1801 
1802       l_price_break_tbl                       OKS_QP_PKG.G_PRICE_BREAK_TBL_TYPE;
1803 
1804 
1805       g_req_line_tbl_blk                 qp_preq_grp.line_tbl_type;
1806       g_req_line_detail_tbl_blk          qp_preq_grp.line_detail_tbl_type;
1807       g_req_related_lines_tbl_blk        qp_preq_grp.related_lines_tbl_type;
1808       g_req_qual_tbl_blk                 qp_preq_grp.qual_tbl_type;
1809       g_req_line_attr_tbl_blk            qp_preq_grp.line_attr_tbl_type;
1810       g_req_line_detail_qual_tbl_blk     qp_preq_grp.line_detail_qual_tbl_type;
1811       g_req_line_detail_attr_tbl_blk     qp_preq_grp.line_detail_attr_tbl_type;
1812       g_line_tbl_ctr                      NUMBER:=0;
1813       g_qual_tbl_ctr                     NUMBER:=0;
1814       g_line_attr_tbl_ctr                NUMBER:=0;
1815       g_line_detail_tbl_ctr              NUMBER:=0;
1816       g_related_lines_tbl_ctr          NUMBER:=0;
1817 
1818       gx_req_line_tbl                   qp_preq_grp.line_tbl_type;
1819       gx_req_qual_tbl                   qp_preq_grp.qual_tbl_type;
1820       gx_req_line_attr_tbl              qp_preq_grp.line_attr_tbl_type;
1821       gx_req_line_detail_tbl            qp_preq_grp.line_detail_tbl_type;
1822       gx_req_line_detail_qual_tbl       qp_preq_grp.line_detail_qual_tbl_type;
1823       gx_req_line_detail_attr_tbl       qp_preq_grp.line_detail_attr_tbl_type;
1824       gx_req_related_lines_tbl          qp_preq_grp.related_lines_tbl_type;
1825 
1826 l_pbr_rec_in                OKS_PBR_PVT.pbrv_rec_type;
1827 l_pbr_rec_out               OKS_PBR_PVT.pbrv_rec_type;
1828 
1829 x_return_status             VARCHAR2(1);
1830 x_price_details              OKS_QP_PKG.Price_Details ;
1831 x_modifier_details           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
1832 x_price_break_details        OKS_QP_PKG.G_PRICE_BREAK_TBL_TYPE;
1833 x_msg_data                   varchar2(1000);
1834 x_msg_count                  NUMBER;
1835 
1836   i NUMBER;
1837   bsl NUMBER;
1838   l_sign                      NUMBER;
1839 l_break_amount              NUMBER;
1840 l_exception_amount NUMBER;
1841 l_PROD_EXT_AMOUNT NUMBER;
1842 l_prv  NUMBER;
1843 
1844 /* Variable for calling std API*/
1845 l_api_version      CONSTANT NUMBER      := 1.0;
1846 l_called_from      CONSTANT NUMBER      := 1;
1847 l_init_msg_list    CONSTANT VARCHAR2(1) := 'F';
1848 l_msg_count                 NUMBER;
1849 l_msg_data                  VARCHAR2(2000);
1850 l_msg_cnt                  NUMBER;
1851 l_return_status             VARCHAR2(1);
1852 
1853 l_line_rec            OKS_QP_PKG.INPUT_DETAILS ;
1854 
1855 
1856 l_prorate VARCHAR2(10);
1857 
1858 l_api_name                     constant varchar2 (30)
1859                                                  := 'BILL_USAGE_ITEM_BULK';
1860 
1861   l_billrep_found          BOOLEAN;
1862   j                        NUMBER;
1863 
1864 
1865  /* skuchima procedure changes the single input to bulk input */
1866    PROCEDURE single_to_bulk_input(
1867           p_req_line_tbl IN qp_preq_grp.line_tbl_type,
1868           p_req_qual_tbl IN qp_preq_grp.qual_tbl_type,
1869           p_req_line_attr_tbl IN qp_preq_grp.line_attr_tbl_type,
1870           p_req_line_detail_tbl IN qp_preq_grp.line_detail_tbl_type,
1871           p_req_line_detail_qual_tbl IN qp_preq_grp.line_detail_qual_tbl_type,
1872           p_req_line_detail_attr_tbl IN qp_preq_grp.line_detail_attr_tbl_type,
1873           p_req_related_lines_tbl IN qp_preq_grp.related_lines_tbl_type,
1874           p_visit_cnt IN number
1875                )IS
1876 
1877        p NUMBER;
1878        q NUMBER;
1879 
1880    BEGIN
1881                        --input parametr1
1882         if p_req_line_tbl.count > 0 then
1883             p := p_req_line_tbl.first;
1884              LOOP
1885              if(p_req_line_tbl(p).line_type_code<>'ORDER' or p_visit_cnt=1) then
1886 
1887                   g_line_tbl_ctr:=g_line_tbl_ctr+1;
1888                   g_req_line_tbl_blk(g_line_tbl_ctr)  :=p_req_line_tbl(p);
1889                   g_req_line_tbl_blk(g_line_tbl_ctr).line_index:=g_line_tbl_ctr;
1890 
1891                               --input parametr2
1892                         if  p_req_qual_tbl.count > 0 then
1893                             q :=  p_req_qual_tbl.first;
1894                              LOOP
1895                                   if(p_req_qual_tbl(q).line_index=p_req_line_tbl(p).line_index) then
1896                                      g_qual_tbl_ctr:=g_qual_tbl_ctr+1;
1897                                      g_req_qual_tbl_blk(g_qual_tbl_ctr)  := p_req_qual_tbl(q);
1898                                      g_req_qual_tbl_blk(g_qual_tbl_ctr).line_index:=  g_line_tbl_ctr;
1899                                  end if;
1900                               exit when p_req_qual_tbl.last = q;
1901                                  q := p_req_qual_tbl.next(q);
1902                               END LOOP;
1903                        end if; --input 2
1904 
1905                            --input parametr3
1906                       if  p_req_line_attr_tbl.count > 0 then
1907                            q :=  p_req_line_attr_tbl.first;
1908                             LOOP
1909                                   if(p_req_line_attr_tbl(q).line_index=p_req_line_tbl(p).line_index) then
1910                                     g_line_attr_tbl_ctr:=g_line_attr_tbl_ctr+1;
1911                                     g_req_line_attr_tbl_blk(g_line_attr_tbl_ctr)  := p_req_line_attr_tbl(q);
1912                                     g_req_line_attr_tbl_blk(g_line_attr_tbl_ctr).line_index:=g_line_tbl_ctr  ;
1913                                   end if;
1914                             exit when p_req_line_attr_tbl.last = q;
1915                                 q := p_req_line_attr_tbl.next(q);
1916                             END LOOP;
1917                       end if;  --inout3
1918 
1919                               --input parametr4
1920                    if  p_req_line_detail_tbl.count > 0 then
1921                         q :=  p_req_line_detail_tbl.first;
1922                       LOOP
1923                           if(p_req_line_detail_tbl(q).line_index=p_req_line_tbl(p).line_index) then
1924                              g_line_detail_tbl_ctr:=g_line_detail_tbl_ctr+1;
1925                              g_req_line_detail_tbl_blk(g_line_detail_tbl_ctr)  := p_req_line_detail_tbl(q);
1926                              g_req_line_detail_tbl_blk(g_line_detail_tbl_ctr).line_detail_index  :=g_line_detail_tbl_ctr;
1927                              g_req_line_detail_tbl_blk(g_line_detail_tbl_ctr).line_index:=  g_line_tbl_ctr;
1928                           end if;
1929                      exit when p_req_line_detail_tbl.last = q;
1930                           q:= p_req_line_detail_tbl.next(q);
1931                      END LOOP;
1932                    end if;  --input4
1933 
1934                     --input parametr7
1935                   if  p_req_related_lines_tbl.count > 0 then
1936                       q :=  p_req_related_lines_tbl.first;
1937                      LOOP
1938                         if(p_req_related_lines_tbl(q).line_index=p_req_line_tbl(p).line_index) then
1939                             g_related_lines_tbl_ctr:=g_related_lines_tbl_ctr+1;
1940                             g_req_related_lines_tbl_blk(g_related_lines_tbl_ctr)  := p_req_related_lines_tbl(q);
1941                             g_req_related_lines_tbl_blk(g_related_lines_tbl_ctr).related_line_index :=g_line_tbl_ctr+1;
1942                             g_req_related_lines_tbl_blk(g_related_lines_tbl_ctr).line_index:=  g_line_tbl_ctr;
1943                         end if;
1944                       exit when p_req_related_lines_tbl.last = q;
1945                          q := p_req_related_lines_tbl.next(q);
1946                      END LOOP;
1947                 END IF;  --input7
1948 
1949             END IF;---visit_cnt
1950 
1951          EXIT WHEN p_req_line_tbl.last = p;
1952               p := p_req_line_tbl.next(p);
1953          END LOOP;
1954       END IF; --input1
1955 
1956       --ignore g_req_line_detail_qual_tbl_blk
1957        --ignore g_req_line_detail_attr_tbl_blk
1958 
1959   END  single_to_bulk_input;
1960 
1961 
1962   ----main procedure begins
1963   BEGIN
1964 
1965    RETCODE := Nvl(RETCODE,0);
1966 
1967    for  bulk_qp_hdr_id_rec  IN bulk_qp_hdr_id_csr  LOOP
1968 
1969     BEGIN
1970 
1971       g_req_line_tbl_blk.delete;
1972       g_req_line_detail_tbl_blk.delete;
1973       g_req_related_lines_tbl_blk.delete;
1974       g_req_qual_tbl_blk.delete;
1975       g_req_line_attr_tbl_blk.delete;
1976       g_req_line_detail_qual_tbl_blk.delete;
1977       g_req_line_detail_attr_tbl_blk.delete;
1978 
1979 
1980       g_line_tbl_ctr :=0;
1981       g_qual_tbl_ctr :=0;
1982       g_line_attr_tbl_ctr :=0;
1983       g_line_detail_tbl_ctr:=0;
1984       g_related_lines_tbl_ctr:=0;
1985 
1986       gx_req_line_tbl.delete;
1987       gx_req_qual_tbl.delete;
1988       gx_req_line_attr_tbl.delete;
1989       gx_req_line_detail_tbl.delete;
1990       gx_req_line_detail_qual_tbl.delete;
1991       gx_req_line_detail_attr_tbl.delete;
1992       gx_req_related_lines_tbl.delete;
1993 
1994       l_visit_cnt :=0;
1995 
1996           FOR bulk_qp_call_rec IN bulk_qp_call_csr(bulk_qp_hdr_id_rec.DNZ_chr_id) LOOP
1997 
1998       l_line_rec.price_list:= bulk_qp_call_rec.price_list;
1999       l_line_rec.price_list_line_id:=bulk_qp_call_rec.price_list_line_id;
2000       l_line_rec.chr_id :=bulk_qp_call_rec.chr_id;
2001       l_line_rec.line_id :=bulk_qp_call_rec.line_id;
2002       l_line_rec.subline_id :=bulk_qp_call_rec.subline_id;
2003       l_line_rec.intent :=bulk_qp_call_rec.intent;
2004       l_line_rec.currency :=bulk_qp_call_rec.currency;
2005       l_line_rec.bcl_id  :=bulk_qp_call_rec.usg_bcl_id;
2006       l_line_rec.bsl_id :=bulk_qp_call_rec.bsl_id;
2007       l_line_rec.usage_qty :=bulk_qp_call_rec.usage_qty;
2008       l_line_rec.usage_uom_code :=bulk_qp_call_rec.usage_uom_code;
2009       l_line_rec.break_uom_code  :=bulk_qp_call_rec.break_uom_code;
2010       l_line_rec.proration_yn :=bulk_qp_call_rec.proration_yn;
2011       l_line_rec.bill_from_date :=bulk_qp_call_rec.bill_from_date;
2012       l_line_rec.bill_to_date :=bulk_qp_call_rec.bill_to_date;
2013       l_line_rec.asking_unit_price :=bulk_qp_call_rec.asking_unit_price;
2014 
2015 
2016             ---call oks_qp_pkg.calc_price_pre to populate input bulk table
2017                   oks_qp_pkg.calc_price_pre
2018                       (p_detail_rec                       => l_line_rec,
2019                        l_control_rec                      => l_control_rec      ,
2020                        l_req_line_tbl                     => l_req_line_tbl      ,
2021                        l_req_qual_tbl                     => l_req_qual_tbl       ,
2022                        l_req_line_attr_tbl                => l_req_line_attr_tbl   ,
2023                        l_req_line_detail_tbl              => l_req_line_detail_tbl  ,
2024                        l_req_line_detail_qual_tbl         => l_req_line_detail_qual_tbl,
2025                        l_req_line_detail_attr_tbl         => l_req_line_detail_attr_tbl ,
2026                        l_req_related_lines_tbl            => l_req_related_lines_tbl    ,
2027                        x_return_status                    => x_return_status
2028                       );
2029 
2030 
2031 
2032  update oks_usg_qp_call_tbl
2033  set line_index=g_line_tbl_ctr+1
2034  WHERE bsl_id= bulk_qp_call_rec.bsl_id;
2035 
2036                   l_visit_cnt:=l_visit_cnt+1;
2037 
2038               --call procedure to capture the input into bulk table
2039 
2040                    single_to_bulk_input
2041                           (
2042                           p_req_line_tbl =>l_req_line_tbl,
2043                           p_req_qual_tbl =>l_req_qual_tbl,
2044                           p_req_line_attr_tbl => l_req_line_attr_tbl,
2045                           p_req_line_detail_tbl =>l_req_line_detail_tbl,
2046                           p_req_line_detail_qual_tbl => l_req_line_detail_qual_tbl,
2047                           p_req_line_detail_attr_tbl =>l_req_line_detail_attr_tbl,
2048                           p_req_related_lines_tbl =>l_req_related_lines_tbl,
2049                           p_visit_cnt =>l_visit_cnt
2050                         );
2051 
2052 
2053           END LOOP;  --bulk_qp_call_rec
2054 
2055     IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level)
2056       THEN
2057               fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************'
2058                                );
2059                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* input parameter l_control_rec *************'
2060                                 );
2061                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************'
2062                                );
2063                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.pricing_event : '|| l_control_rec.pricing_event
2064                                 );
2065                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.calculate_flag : '|| l_control_rec.calculate_flag
2066                                 );
2067                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.simulation_flag : '|| l_control_rec.simulation_flag
2068                                 );
2069                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.rounding_flag : '|| l_control_rec.rounding_flag
2070                                 );
2071                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.gsa_check_flag : '|| l_control_rec.gsa_check_flag
2072                                 );
2073                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.gsa_dup_check_flag : '|| l_control_rec.gsa_dup_check_flag
2074                                 );
2075                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.temp_table_insert_flag : '|| l_control_rec.temp_table_insert_flag
2076                                 );
2077                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.manual_discount_flag : '|| l_control_rec.manual_discount_flag
2078                                 );
2079                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.debug_flag : '|| l_control_rec.debug_flag
2080                                 );
2081                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.source_order_amount_flag : '|| l_control_rec.source_order_amount_flag
2082                                 );
2083                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.public_api_call_flag : '|| l_control_rec.public_api_call_flag
2084                                 );
2085                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.manual_adjustments_call_flag : '|| l_control_rec.manual_adjustments_call_flag
2086                                 );
2087                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.get_freight_flag : '|| l_control_rec.get_freight_flag
2088                                 );
2089                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.request_type_code : '|| l_control_rec.request_type_code
2090                                 );
2091                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.view_code : '|| l_control_rec.view_code
2092                                 );
2093                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.check_cust_view_flag : '|| l_control_rec.check_cust_view_flag
2094                                 );
2095                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.full_pricing_call : '|| l_control_rec.full_pricing_call
2096                                 );
2097                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.use_multi_currency : '|| l_control_rec.use_multi_currency
2098                                 );
2099                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.user_conversion_rate : '|| l_control_rec.user_conversion_rate
2100                                 );
2101                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.user_conversion_type : '|| l_control_rec.user_conversion_type
2102                                 );
2103                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.function_currency : '|| l_control_rec.function_currency
2104                                 );
2105                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: l_control_rec.org_id : '|| l_control_rec.org_id
2106                                 );
2107 
2108     --
2109     -- input parameter 2: g_req_line_tbl_blk
2110     --
2111         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2112         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ********** input parameter 2: g_req_line_tbl_blk ****************');
2113         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk.count '|| g_req_line_tbl_blk.count
2114                         );
2115         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2116         if g_req_line_tbl_blk.count > 0 then
2117             p := g_req_line_tbl_blk.first;
2118                 loop
2119                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_line_tbl_blk('|| p ||') *************'
2120                                 );
2121                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').request_type_code : '|| g_req_line_tbl_blk(p).request_type_code
2122                                 );
2123                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').pricing_event : '|| g_req_line_tbl_blk(p).pricing_event
2124                                 );
2125                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').header_id : '|| g_req_line_tbl_blk(p).header_id
2126                                 );
2127                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_index : '|| g_req_line_tbl_blk(p).line_index
2128                                 );
2129                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_id : '|| g_req_line_tbl_blk(p).line_id
2130                                 );
2131                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_type_code : '|| g_req_line_tbl_blk(p).line_type_code
2132                                 );
2133                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').pricing_effective_date : '|| g_req_line_tbl_blk(p).pricing_effective_date
2134                                 );
2135                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').active_date_first : '|| g_req_line_tbl_blk(p).active_date_first
2136                                 );
2137                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').active_date_first_type : '|| g_req_line_tbl_blk(p).active_date_first_type
2138                                 );
2139                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').active_date_second : '|| g_req_line_tbl_blk(p).active_date_second
2140                                 );
2141                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').active_date_first_type : '|| g_req_line_tbl_blk(p).active_date_first_type
2142                                 );
2143                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').active_date_second : '|| g_req_line_tbl_blk(p).active_date_second
2144                                 );
2145                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').active_date_second_type : '|| g_req_line_tbl_blk(p).active_date_second_type
2146                                 );
2147                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_quantity : '|| g_req_line_tbl_blk(p).line_quantity
2148                                 );
2149                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_uom_code : '|| g_req_line_tbl_blk(p).line_uom_code
2150                                 );
2151                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').uom_quantity : '|| g_req_line_tbl_blk(p).uom_quantity
2152                                 );
2153                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').priced_quantity : '|| g_req_line_tbl_blk(p).priced_quantity
2154                                 );
2155                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').priced_uom_code : '|| g_req_line_tbl_blk(p).priced_uom_code
2156                                 );
2157                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').currency_code : '|| g_req_line_tbl_blk(p).currency_code
2158                                 );
2159                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').unit_price : '|| g_req_line_tbl_blk(p).unit_price
2160                                 );
2161                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').percent_price : '|| g_req_line_tbl_blk(p).percent_price
2162                                 );
2163                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').adjusted_unit_price : '|| g_req_line_tbl_blk(p).adjusted_unit_price
2164                                 );
2165                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').updated_adjusted_unit_price : '|| g_req_line_tbl_blk(p).updated_adjusted_unit_price
2166                                 );
2167                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').parent_price : '|| g_req_line_tbl_blk(p).parent_price
2168                                 );
2169                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').parent_quantity : '|| g_req_line_tbl_blk(p).parent_quantity
2170                                 );
2171                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').rounding_factor : '|| g_req_line_tbl_blk(p).rounding_factor
2172                                 );
2173                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').parent_uom_code : '|| g_req_line_tbl_blk(p).parent_uom_code
2174                                 );
2175                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').pricing_phase_id : '|| g_req_line_tbl_blk(p).pricing_phase_id
2176                                 );
2177                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').price_flag : '|| g_req_line_tbl_blk(p).price_flag
2178                                 );
2179                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').processed_code : '|| g_req_line_tbl_blk(p).processed_code
2180                                 );
2181                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').price_request_code : '|| g_req_line_tbl_blk(p).price_request_code
2182                                 );
2183                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').hold_code : '|| g_req_line_tbl_blk(p).hold_code
2184                                 );
2185                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').hold_text : '|| g_req_line_tbl_blk(p).hold_text
2186                                 );
2187                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').status_code : '|| g_req_line_tbl_blk(p).status_code
2188                                 );
2189                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').status_text : '|| g_req_line_tbl_blk(p).status_text
2190                                 );
2191                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').usage_pricing_type : '|| g_req_line_tbl_blk(p).usage_pricing_type
2192                                 );
2193                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_category : '|| g_req_line_tbl_blk(p).line_category
2194                                 );
2195                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').contract_start_date : '|| g_req_line_tbl_blk(p).contract_start_date
2196                                 );
2197                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').contract_end_date : '|| g_req_line_tbl_blk(p).contract_end_date
2198                                 );
2199                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').line_unit_price : '|| g_req_line_tbl_blk(p).line_unit_price
2200                                 );
2201                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').extended_price : '|| g_req_line_tbl_blk(p).extended_price
2202                                 );
2203                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').list_price_override_flag : '|| g_req_line_tbl_blk(p).list_price_override_flag
2204                                 );
2205                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_tbl_blk('|| p ||').charge_periodicity_code : '|| g_req_line_tbl_blk(p).charge_periodicity_code
2206                                 );
2207                 exit when g_req_line_tbl_blk.last = p;
2208                 p := g_req_line_tbl_blk.next(p);
2209             end loop;
2210         end if; -- g_req_line_tbl_blk.count > 0
2211 
2212     --
2213     -- input parameter 3: g_req_qual_tbl_blk
2214     --
2215         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2216         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************** input parameter 3: g_req_qual_tbl_blk ******************');
2217         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk.count '|| g_req_qual_tbl_blk.count
2218                         );
2219         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2220         if g_req_qual_tbl_blk.count > 0 then
2221             p := g_req_qual_tbl_blk.first;
2222                 loop
2223                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_qual_tbl_blk('|| p ||') *************'
2224                                 );
2225                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').line_index : '|| g_req_qual_tbl_blk(p).line_index
2226                                 );
2227                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').qualifier_context : '|| g_req_qual_tbl_blk(p).qualifier_context
2228                                 );
2229                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').qualifier_attribute : '|| g_req_qual_tbl_blk(p).qualifier_attribute
2230                                 );
2231                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').qualifier_attr_value_from : '|| g_req_qual_tbl_blk(p).qualifier_attr_value_from
2232                                 );
2233                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').qualifier_attr_value_to : '|| g_req_qual_tbl_blk(p).qualifier_attr_value_to
2234                                 );
2235                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').comparison_operator_code : '|| g_req_qual_tbl_blk(p).comparison_operator_code
2236                                 );
2237                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').validated_flag : '|| g_req_qual_tbl_blk(p).validated_flag
2238                                 );
2239                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').status_code : '|| g_req_qual_tbl_blk(p).status_code
2240                                 );
2241                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_qual_tbl_blk('|| p ||').status_text : '|| g_req_qual_tbl_blk(p).status_text
2242                                 );
2243                 exit when g_req_qual_tbl_blk.last = p;
2244                 p := g_req_qual_tbl_blk.next(p);
2245             end loop;
2246         end if; -- l_req_qual_tbl.count > 0
2247     --
2248     -- input parameter 4: g_req_line_attr_tbl_blk
2249     --
2250         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2251         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** input parameter 4: g_req_line_attr_tbl_blk ******************');
2252         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk.count '|| g_req_line_attr_tbl_blk.count
2253                         );
2254         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2255         if g_req_line_attr_tbl_blk.count > 0 then
2256            p := g_req_line_attr_tbl_blk.first;
2257                 loop
2258                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_line_attr_tbl_blk('|| p ||') *************'
2259                                 );
2260                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').line_index : '|| g_req_line_attr_tbl_blk(p).line_index
2261                                 );
2262                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').pricing_context : '|| g_req_line_attr_tbl_blk(p).pricing_context
2263                                 );
2264                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').pricing_attribute : '|| g_req_line_attr_tbl_blk(p).pricing_attribute
2265                                 );
2266                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').pricing_attr_value_from : '|| g_req_line_attr_tbl_blk(p).pricing_attr_value_from
2267                                 );
2268                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').pricing_attr_value_to : '|| g_req_line_attr_tbl_blk(p).pricing_attr_value_to
2269                                 );
2270                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').validated_flag : '|| g_req_line_attr_tbl_blk(p).validated_flag
2271                                 );
2272                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').status_code : '|| g_req_line_attr_tbl_blk(p).status_code
2273                                 );
2274                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_attr_tbl_blk('|| p ||').status_text : '|| g_req_line_attr_tbl_blk(p).status_text
2275                                 );
2276                 exit when g_req_line_attr_tbl_blk.last = p;
2277                 p := g_req_line_attr_tbl_blk.next(p);
2278             end loop;
2279         end if; -- l_req_line_attr_tbl.count > 0
2280 
2281     --
2282     -- input parameter 5: g_req_line_detail_tbl_blk
2283     --
2284         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2285         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** input parameter 5: g_req_line_detail_tbl_blk ******************');
2286             fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk.count '|| g_req_line_detail_tbl_blk.count
2287                         );
2288         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2289 
2290         if g_req_line_detail_tbl_blk.count > 0 then
2291             p := g_req_line_detail_tbl_blk.first;
2292                 loop
2293                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_line_detail_tbl_blk('|| p ||') *************'
2294                                 );
2295                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').line_detail_index : '|| g_req_line_detail_tbl_blk(p).line_detail_index
2296                                 );
2297                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').line_detail_id : '|| g_req_line_detail_tbl_blk(p).line_detail_id
2298                                 );
2299                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').line_detail_type_code : '|| g_req_line_detail_tbl_blk(p).line_detail_type_code
2300                                 );
2301                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').line_index : '|| g_req_line_detail_tbl_blk(p).line_index
2302                                 );
2303                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').list_header_id : '|| g_req_line_detail_tbl_blk(p).list_header_id
2304                                 );
2305                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').list_line_id : '|| g_req_line_detail_tbl_blk(p).list_line_id
2306                                 );
2307                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').list_line_type_code : '|| g_req_line_detail_tbl_blk(p).list_line_type_code
2308                                 );
2309                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').substitution_type_code : '|| g_req_line_detail_tbl_blk(p).substitution_type_code
2310                                 );
2311                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').substitution_from : '|| g_req_line_detail_tbl_blk(p).substitution_from
2312                                 );
2313                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').substitution_to : '|| g_req_line_detail_tbl_blk(p).substitution_to
2314                                 );
2315                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').automatic_flag : '|| g_req_line_detail_tbl_blk(p).automatic_flag
2316                                 );
2317                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').operand_calculation_code : '|| g_req_line_detail_tbl_blk(p).operand_calculation_code
2318                                 );
2319                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').operand_value : '|| g_req_line_detail_tbl_blk(p).operand_value
2320                                 );
2321                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').pricing_group_sequence : '|| g_req_line_detail_tbl_blk(p).pricing_group_sequence
2322                                 );
2323                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').price_break_type_code : '|| g_req_line_detail_tbl_blk(p).price_break_type_code
2324                                 );
2325                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').created_from_list_type_code : '|| g_req_line_detail_tbl_blk(p).created_from_list_type_code
2326                                 );
2327                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').pricing_phase_id : '|| g_req_line_detail_tbl_blk(p).pricing_phase_id
2328                                 );
2329                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').list_price : '|| g_req_line_detail_tbl_blk(p).list_price
2330                                 );
2331                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').line_quantity : '|| g_req_line_detail_tbl_blk(p).line_quantity
2332                                 );
2333                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').adjustment_amount : '|| g_req_line_detail_tbl_blk(p).adjustment_amount
2334                                 );
2335                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').applied_flag : '|| g_req_line_detail_tbl_blk(p).applied_flag
2336                                 );
2337                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').modifier_level_code : '|| g_req_line_detail_tbl_blk(p).modifier_level_code
2338                                 );
2339                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').status_code : '|| g_req_line_detail_tbl_blk(p).status_code
2340                                 );
2341                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').status_text : '|| g_req_line_detail_tbl_blk(p).status_text
2342                                 );
2343                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').substitution_attribute : '|| g_req_line_detail_tbl_blk(p).substitution_attribute
2344                                 );
2345                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').accrual_flag : '|| g_req_line_detail_tbl_blk(p).accrual_flag
2346                                 );
2347                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').list_line_no : '|| g_req_line_detail_tbl_blk(p).list_line_no
2348                                 );
2349                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').estim_gl_value : '|| g_req_line_detail_tbl_blk(p).estim_gl_value
2350                                 );
2351                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').accrual_conversion_rate : '|| g_req_line_detail_tbl_blk(p).accrual_conversion_rate
2352                                 );
2353                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').override_flag : '|| g_req_line_detail_tbl_blk(p).override_flag
2354                                 );
2355                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').print_on_invoice_flag : '|| g_req_line_detail_tbl_blk(p).print_on_invoice_flag
2356                                 );
2357                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').inventory_item_id : '|| g_req_line_detail_tbl_blk(p).inventory_item_id
2358                                 );
2359                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').organization_id : '|| g_req_line_detail_tbl_blk(p).organization_id
2360                                 );
2361                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').related_item_id : '|| g_req_line_detail_tbl_blk(p).related_item_id
2362                                 );
2363                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').relationship_type_id : '|| g_req_line_detail_tbl_blk(p).relationship_type_id
2364                                 );
2365                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').estim_accrual_rate : '|| g_req_line_detail_tbl_blk(p).estim_accrual_rate
2366                                 );
2367                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').expiration_date : '|| g_req_line_detail_tbl_blk(p).expiration_date
2368                                 );
2369                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').benefit_price_list_line_id : '|| g_req_line_detail_tbl_blk(p).benefit_price_list_line_id
2370                                 );
2371                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').recurring_flag : '|| g_req_line_detail_tbl_blk(p).recurring_flag
2372                                 );
2373                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').recurring_value : '|| g_req_line_detail_tbl_blk(p).recurring_value
2374                                 );
2375                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').benefit_limit : '|| g_req_line_detail_tbl_blk(p).benefit_limit
2376                                 );
2377                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').charge_type_code : '|| g_req_line_detail_tbl_blk(p).charge_type_code
2378                                 );
2379                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').charge_subtype_code : '|| g_req_line_detail_tbl_blk(p).charge_subtype_code
2380                                 );
2381                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').include_on_returns_flag : '|| g_req_line_detail_tbl_blk(p).include_on_returns_flag
2382                                 );
2383                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').benefit_qty : '|| g_req_line_detail_tbl_blk(p).benefit_qty
2384                                 );
2385                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').benefit_uom_code : '|| g_req_line_detail_tbl_blk(p).benefit_uom_code
2386                                 );
2387                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').proration_type_code : '|| g_req_line_detail_tbl_blk(p).proration_type_code
2388                                 );
2389                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').source_system_code : '|| g_req_line_detail_tbl_blk(p).source_system_code
2390                                 );
2391                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').rebate_transaction_type_code : '|| g_req_line_detail_tbl_blk(p).rebate_transaction_type_code
2392                                 );
2393                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').secondary_pricelist_ind : '|| g_req_line_detail_tbl_blk(p).secondary_pricelist_ind
2394                                 );
2395                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').group_value : '|| g_req_line_detail_tbl_blk(p).group_value
2396                                 );
2397                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').comments : '|| g_req_line_detail_tbl_blk(p).comments
2398                                 );
2399                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').updated_flag : '|| g_req_line_detail_tbl_blk(p).updated_flag
2400                                 );
2401                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').process_code : '|| g_req_line_detail_tbl_blk(p).process_code
2402                                 );
2403                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').limit_code : '|| g_req_line_detail_tbl_blk(p).limit_code
2404                                 );
2405                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').limit_text : '|| g_req_line_detail_tbl_blk(p).limit_text
2406                                 );
2407                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').formula_id : '|| g_req_line_detail_tbl_blk(p).formula_id
2408                                 );
2409                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').calculation_code : '|| g_req_line_detail_tbl_blk(p).calculation_code
2410                                 );
2411                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').rounding_factor : '|| g_req_line_detail_tbl_blk(p).rounding_factor
2412                                 );
2413                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').currency_detail_id : '|| g_req_line_detail_tbl_blk(p).currency_detail_id
2414                                 );
2415                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').currency_header_id : '|| g_req_line_detail_tbl_blk(p).currency_header_id
2416                                 );
2417                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').selling_rounding_factor : '|| g_req_line_detail_tbl_blk(p).selling_rounding_factor
2418                                 );
2419                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').order_currency : '|| g_req_line_detail_tbl_blk(p).order_currency
2420                                 );
2421                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').pricing_effective_date : '|| g_req_line_detail_tbl_blk(p).pricing_effective_date
2422                                 );
2423                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').base_currency_code : '|| g_req_line_detail_tbl_blk(p).base_currency_code
2424                                 );
2425                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').change_reason_code : '|| g_req_line_detail_tbl_blk(p).change_reason_code
2426                                 );
2427                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').change_reason_text : '|| g_req_line_detail_tbl_blk(p).change_reason_text
2428                                 );
2429                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').break_uom_code : '|| g_req_line_detail_tbl_blk(p).break_uom_code
2430                                 );
2431                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').break_uom_context : '|| g_req_line_detail_tbl_blk(p).break_uom_context
2432                                 );
2433                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_tbl_blk('|| p ||').break_uom_attribute : '|| g_req_line_detail_tbl_blk(p).break_uom_attribute
2434                                 );
2435                 exit when g_req_line_detail_tbl_blk.last = p;
2436                 p := g_req_line_detail_tbl_blk.next(p);
2437             end loop;
2438         end if; -- g_req_line_detail_tbl_blk.count > 0
2439     --
2440     -- input parameter 6: g_req_line_detail_qual_tbl_blk
2441     --
2442         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2443         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** input parameter 6: g_req_line_detail_qual_tbl_blk ******************');
2444             fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk.count '|| g_req_line_detail_qual_tbl_blk.count
2445                         );
2446         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2447 
2448         if g_req_line_detail_qual_tbl_blk.count > 0 then
2449            p := g_req_line_detail_qual_tbl_blk.first;
2450                 loop
2451                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_line_detail_qual_tbl_blk('|| p ||') *************'
2452                                 );
2453                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').line_detail_index : '|| g_req_line_detail_qual_tbl_blk(p).line_detail_index
2454                                 );
2455                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').qualifier_context : '|| g_req_line_detail_qual_tbl_blk(p).qualifier_context
2456                                 );
2457                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').qualifier_attribute : '|| g_req_line_detail_qual_tbl_blk(p).qualifier_attribute
2458                                 );
2459                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').qualifier_attr_value_from : '|| g_req_line_detail_qual_tbl_blk(p).qualifier_attr_value_from
2460                                 );
2461                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').qualifier_attr_value_to : '|| g_req_line_detail_qual_tbl_blk(p).qualifier_attr_value_to
2462                                 );
2463                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').comparison_operator_code : '|| g_req_line_detail_qual_tbl_blk(p).comparison_operator_code
2464                                 );
2465                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').validated_flag : '|| g_req_line_detail_qual_tbl_blk(p).validated_flag
2466                                 );
2467                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').status_code : '|| g_req_line_detail_qual_tbl_blk(p).status_code
2468                                 );
2469                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_qual_tbl_blk('|| p ||').status_text : '|| g_req_line_detail_qual_tbl_blk(p).status_text
2470                                 );
2471                 exit when g_req_line_detail_qual_tbl_blk.last = p;
2472                 p := g_req_line_detail_qual_tbl_blk.next(p);
2473             end loop;
2474         end if; -- g_req_line_detail_qual_tbl_blk.count > 0
2475     --
2476     -- input parameter 7: g_req_line_detail_attr_tbl_blk
2477     --
2478         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2479         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** input parameter 7: g_req_line_detail_attr_tbl_blk ******************');
2480             fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk.count '|| g_req_line_detail_attr_tbl_blk.count
2481                         );
2482         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2483 
2484         if g_req_line_detail_attr_tbl_blk.count > 0 then
2485            p := g_req_line_detail_attr_tbl_blk.first;
2486                 loop
2487                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_line_detail_attr_tbl_blk('|| p ||') *************'
2488                                 );
2489                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').line_detail_index : '|| g_req_line_detail_attr_tbl_blk(p).line_detail_index
2490                                 );
2491                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').line_index : '|| g_req_line_detail_attr_tbl_blk(p).line_index
2492                                 );
2493                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').pricing_context : '|| g_req_line_detail_attr_tbl_blk(p).pricing_context
2494                                 );
2495                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').pricing_attribute : '|| g_req_line_detail_attr_tbl_blk(p).pricing_attribute
2496                                 );
2497                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').pricing_attr_value_from : '|| g_req_line_detail_attr_tbl_blk(p).pricing_attr_value_from
2498                                 );
2499                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').pricing_attr_value_to : '|| g_req_line_detail_attr_tbl_blk(p).pricing_attr_value_to
2500                                 );
2501                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').validated_flag : '|| g_req_line_detail_attr_tbl_blk(p).validated_flag
2502                                 );
2503                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').status_code : '|| g_req_line_detail_attr_tbl_blk(p).status_code
2504                                 );
2505                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_line_detail_attr_tbl_blk('|| p ||').status_text : '|| g_req_line_detail_attr_tbl_blk(p).status_text
2506                                 );
2507                 exit when g_req_line_detail_attr_tbl_blk.last = p;
2508                 p := g_req_line_detail_attr_tbl_blk.next(p);
2509             end loop;
2510         end if; -- g_req_line_detail_attr_tbl_blk.count > 0
2511 
2512     --
2513     -- input parameter 8: g_req_related_lines_tbl_blk
2514     --
2515         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2516         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** input parameter 8: g_req_related_lines_tbl_blk ******************');
2517         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk.count '|| g_req_related_lines_tbl_blk.count
2518                         );
2519         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2520 
2521         if g_req_related_lines_tbl_blk.count > 0 then
2522            p := g_req_related_lines_tbl_blk.first;
2523                 loop
2524                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter g_req_related_lines_tbl_blk('|| p ||') *************'
2525                                 );
2526                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').line_index : '|| g_req_related_lines_tbl_blk(p).line_index
2527                                 );
2528                  fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').line_detail_index : '|| g_req_related_lines_tbl_blk(p).line_detail_index
2529                                 );
2530                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').relationship_type_code : '|| g_req_related_lines_tbl_blk(p).relationship_type_code
2531                                 );
2532                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').related_line_index : '|| g_req_related_lines_tbl_blk(p).related_line_index
2533                                 );
2534                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').related_line_detail_index : '|| g_req_related_lines_tbl_blk(p).related_line_detail_index
2535                                 );
2536                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').status_code : '|| g_req_related_lines_tbl_blk(p).status_code
2537                                 );
2538                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: g_req_related_lines_tbl_blk('|| p ||').status_text : '|| g_req_related_lines_tbl_blk(p).status_text
2539                                 );
2540                 exit when g_req_related_lines_tbl_blk.last = p;
2541                 p := g_req_related_lines_tbl_blk.next(p);
2542             end loop;
2543         end if; -- g_req_related_lines_tbl_blk.count > 0
2544 
2545    END IF;
2546 
2547          --call the qp package for pricing
2548         qp_preq_pub.price_request
2549                        (p_control_rec                      => l_control_rec,
2550                         p_line_tbl                         => g_req_line_tbl_blk,
2551                         p_qual_tbl                         => g_req_qual_tbl_blk,
2552                         p_line_attr_tbl                    => g_req_line_attr_tbl_blk,
2553                         p_line_detail_tbl                  => g_req_line_detail_tbl_blk,
2554                         p_line_detail_qual_tbl             => g_req_line_detail_qual_tbl_blk,
2555                         p_line_detail_attr_tbl             => g_req_line_detail_attr_tbl_blk,
2556                         p_related_lines_tbl                => g_req_related_lines_tbl_blk,
2557                         x_line_tbl                         => gx_req_line_tbl,
2558                         x_line_qual                        => gx_req_qual_tbl,
2559                         x_line_attr_tbl                    => gx_req_line_attr_tbl,
2560                         x_line_detail_tbl                  => gx_req_line_detail_tbl,
2561                         x_line_detail_qual_tbl             => gx_req_line_detail_qual_tbl,
2562                         x_line_detail_attr_tbl             => gx_req_line_detail_attr_tbl,
2563                         x_related_lines_tbl                => gx_req_related_lines_tbl,
2564                         x_return_status                    => lx_return_status,
2565                         x_return_status_text               => lx_return_status_text
2566                        );
2567 
2568 
2569   IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level)
2570      THEN
2571               --
2572 
2573     --
2574     -- Output Parameter 8: lx_return_status
2575     --
2576                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: *********************************************************');
2577                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: ************* Parameter lx_return_status *************'
2578                                 );
2579                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: lx_return_status '||lx_return_status
2580                                 );
2581                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: *********************************************************');
2582     --
2583     -- Output Parameter 9: lx_return_status_text
2584     --
2585                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: ************* Parameter lx_return_status_text *************'
2586                                 );
2587                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: lx_return_status_text '||lx_return_status_text
2588                                 );
2589                 fnd_log.STRING (fnd_log.level_statement, g_module || l_api_name,'QP_CALL: *********************************************************');
2590 
2591               --
2592 
2593     -- output parameter 1: gx_req_line_tbl
2594     --
2595         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2596         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl.count '|| gx_req_line_tbl.count
2597                         );
2598         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2599         if gx_req_line_tbl.count > 0 then
2600             p := gx_req_line_tbl.first;
2601                 loop
2602                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_line_tbl('|| p ||') *************'
2603                                 );
2604                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').request_type_code : '|| gx_req_line_tbl(p).request_type_code
2605                                 );
2606                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').pricing_event : '|| gx_req_line_tbl(p).pricing_event
2607                                 );
2608                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').header_id : '|| gx_req_line_tbl(p).header_id
2609                                 );
2610                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_index : '|| gx_req_line_tbl(p).line_index
2611                                 );
2612                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_id : '|| gx_req_line_tbl(p).line_id
2613                                 );
2614                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_type_code : '|| gx_req_line_tbl(p).line_type_code
2615                                 );
2616                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').pricing_effective_date : '|| gx_req_line_tbl(p).pricing_effective_date
2617                                 );
2618                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').active_date_first : '|| gx_req_line_tbl(p).active_date_first
2619                                 );
2620                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').active_date_first_type : '|| gx_req_line_tbl(p).active_date_first_type
2621                                 );
2622                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').active_date_second : '|| gx_req_line_tbl(p).active_date_second
2623                                 );
2624                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').active_date_first_type : '|| gx_req_line_tbl(p).active_date_first_type
2625                                 );
2626                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').active_date_second : '|| gx_req_line_tbl(p).active_date_second
2627                                 );
2628                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').active_date_second_type : '|| gx_req_line_tbl(p).active_date_second_type
2629                                 );
2630                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_quantity : '|| gx_req_line_tbl(p).line_quantity
2631                                 );
2632                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_uom_code : '|| gx_req_line_tbl(p).line_uom_code
2633                                 );
2634                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').uom_quantity : '|| gx_req_line_tbl(p).uom_quantity
2635                                 );
2636                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').priced_quantity : '|| gx_req_line_tbl(p).priced_quantity
2637                                 );
2638                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').priced_uom_code : '|| gx_req_line_tbl(p).priced_uom_code
2639                                 );
2640                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').currency_code : '|| gx_req_line_tbl(p).currency_code
2641                                 );
2642                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').unit_price : '|| gx_req_line_tbl(p).unit_price
2643                                 );
2644                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').percent_price : '|| gx_req_line_tbl(p).percent_price
2645                                 );
2646                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').adjusted_unit_price : '|| gx_req_line_tbl(p).adjusted_unit_price
2647                                 );
2648                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').updated_adjusted_unit_price : '|| gx_req_line_tbl(p).updated_adjusted_unit_price
2649                                 );
2650                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').parent_price : '|| gx_req_line_tbl(p).parent_price
2651                                 );
2652                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').parent_quantity : '|| gx_req_line_tbl(p).parent_quantity
2653                                 );
2654                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').rounding_factor : '|| gx_req_line_tbl(p).rounding_factor
2655                                 );
2656                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').parent_uom_code : '|| gx_req_line_tbl(p).parent_uom_code
2657                                 );
2658                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').pricing_phase_id : '|| gx_req_line_tbl(p).pricing_phase_id
2659                                 );
2660                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').price_flag : '|| gx_req_line_tbl(p).price_flag
2661                                 );
2662                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').processed_code : '|| gx_req_line_tbl(p).processed_code
2663                                 );
2664                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').price_request_code : '|| gx_req_line_tbl(p).price_request_code
2665                                 );
2666                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').hold_code : '|| gx_req_line_tbl(p).hold_code
2667                                 );
2668                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').hold_text : '|| gx_req_line_tbl(p).hold_text
2669                                 );
2670                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').status_code : '|| gx_req_line_tbl(p).status_code
2671                                 );
2672                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').status_text : '|| gx_req_line_tbl(p).status_text
2673                                 );
2674                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').usage_pricing_type : '|| gx_req_line_tbl(p).usage_pricing_type
2675                                 );
2676                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_category : '|| gx_req_line_tbl(p).line_category
2677                                 );
2678                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').contract_start_date : '|| gx_req_line_tbl(p).contract_start_date
2679                                 );
2680                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').contract_end_date : '|| gx_req_line_tbl(p).contract_end_date
2681                                 );
2682                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').line_unit_price : '|| gx_req_line_tbl(p).line_unit_price
2683                                 );
2684                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').extended_price : '|| gx_req_line_tbl(p).extended_price
2685                                 );
2686                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').list_price_override_flag : '|| gx_req_line_tbl(p).list_price_override_flag
2687                                 );
2688                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_tbl('|| p ||').charge_periodicity_code : '|| gx_req_line_tbl(p).charge_periodicity_code
2689                                 );
2690                 exit when gx_req_line_tbl.last = p;
2691                 p := gx_req_line_tbl.next(p);
2692             end loop;
2693         end if; -- gx_req_line_tbl.count > 0
2694 
2695     --
2696     -- output parameter 2: gx_req_qual_tbl
2697     --
2698         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2699         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* output parameter 2: gx_req_qual_tbl ************');
2700         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl.count '|| gx_req_qual_tbl.count
2701                         );
2702         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2703         if gx_req_qual_tbl.count > 0 then
2704             p := gx_req_qual_tbl.first;
2705                 loop
2706                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_qual_tbl('|| p ||') *************'
2707                                 );
2708                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').line_index : '|| gx_req_qual_tbl(p).line_index
2709                                 );
2710                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').qualifier_context : '|| gx_req_qual_tbl(p).qualifier_context
2711                                 );
2712                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').qualifier_attribute : '|| gx_req_qual_tbl(p).qualifier_attribute
2713                                 );
2714                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').qualifier_attr_value_from : '|| gx_req_qual_tbl(p).qualifier_attr_value_from
2715                                 );
2716                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').qualifier_attr_value_to : '|| gx_req_qual_tbl(p).qualifier_attr_value_to
2717                                 );
2718                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').comparison_operator_code : '|| gx_req_qual_tbl(p).comparison_operator_code
2719                                 );
2720                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').validated_flag : '|| gx_req_qual_tbl(p).validated_flag
2721                                 );
2722                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').status_code : '|| gx_req_qual_tbl(p).status_code
2723                                 );
2724                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_qual_tbl('|| p ||').status_text : '|| gx_req_qual_tbl(p).status_text
2725                                 );
2726                 exit when gx_req_qual_tbl.last = p;
2727                 p := gx_req_qual_tbl.next(p);
2728             end loop;
2729         end if; -- gx_req_qual_tbl.count > 0
2730     --
2731     -- output parameter 3: gx_req_line_attr_tbl
2732     --
2733         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2734         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ****************** output parameter 3: gx_req_line_attr_tbl ************');
2735         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl.count '|| gx_req_qual_tbl.count
2736                         );
2737         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2738         if gx_req_line_attr_tbl.count > 0 then
2739             p := gx_req_line_attr_tbl.first;
2740                 loop
2741                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_line_attr_tbl('|| p ||') *************'
2742                                 );
2743                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').line_index : '|| gx_req_line_attr_tbl(p).line_index
2744                                 );
2745                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').pricing_context : '|| gx_req_line_attr_tbl(p).pricing_context
2746                                 );
2747                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').pricing_attribute : '|| gx_req_line_attr_tbl(p).pricing_attribute
2748                                 );
2749                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').pricing_attr_value_from : '|| gx_req_line_attr_tbl(p).pricing_attr_value_from
2750                                 );
2751                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').pricing_attr_value_to : '|| gx_req_line_attr_tbl(p).pricing_attr_value_to
2752                                 );
2753                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').validated_flag : '|| gx_req_line_attr_tbl(p).validated_flag
2754                                 );
2755                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').status_code : '|| gx_req_line_attr_tbl(p).status_code
2756                                 );
2757                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_attr_tbl('|| p ||').status_text : '|| gx_req_line_attr_tbl(p).status_text
2758                                 );
2759                 exit when gx_req_line_attr_tbl.last = p;
2760                 p := gx_req_line_attr_tbl.next(p);
2761             end loop;
2762         end if; -- gx_req_line_attr_tbl.count > 0
2763 
2764     --
2765     -- output parameter 4: gx_req_line_detail_tbl
2766     --
2767         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2768         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ****************** output parameter 4: gx_req_line_detail_tbl ************');
2769             fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl.count '|| gx_req_line_detail_tbl.count
2770                         );
2771         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2772 
2773         if gx_req_line_detail_tbl.count > 0 then
2774             p := gx_req_line_detail_tbl.first;
2775                 loop
2776                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_line_detail_tbl('|| p ||') *************'
2777                                 );
2778                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').line_detail_index : '|| gx_req_line_detail_tbl(p).line_detail_index
2779                                 );
2780                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').line_detail_id : '|| gx_req_line_detail_tbl(p).line_detail_id
2781                                 );
2782                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').line_detail_type_code : '|| gx_req_line_detail_tbl(p).line_detail_type_code
2783                                 );
2784                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').line_index : '|| gx_req_line_detail_tbl(p).line_index
2785                                 );
2786                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').list_header_id : '|| gx_req_line_detail_tbl(p).list_header_id
2787                                 );
2788                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').list_line_id : '|| gx_req_line_detail_tbl(p).list_line_id
2789                                 );
2790                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').list_line_type_code : '|| gx_req_line_detail_tbl(p).list_line_type_code
2791                                 );
2792                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').substitution_type_code : '|| gx_req_line_detail_tbl(p).substitution_type_code
2793                                 );
2794                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').substitution_from : '|| gx_req_line_detail_tbl(p).substitution_from
2795                                 );
2796                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').substitution_to : '|| gx_req_line_detail_tbl(p).substitution_to
2797                                 );
2798                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').automatic_flag : '|| gx_req_line_detail_tbl(p).automatic_flag
2799                                 );
2800                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').operand_calculation_code : '|| gx_req_line_detail_tbl(p).operand_calculation_code
2801                                 );
2802                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').operand_value : '|| gx_req_line_detail_tbl(p).operand_value
2803                                 );
2804                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').pricing_group_sequence : '|| gx_req_line_detail_tbl(p).pricing_group_sequence
2805                                 );
2806                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').price_break_type_code : '|| gx_req_line_detail_tbl(p).price_break_type_code
2807                                 );
2808                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').created_from_list_type_code : '|| gx_req_line_detail_tbl(p).created_from_list_type_code
2809                                 );
2810                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').pricing_phase_id : '|| gx_req_line_detail_tbl(p).pricing_phase_id
2811                                 );
2812                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').list_price : '|| gx_req_line_detail_tbl(p).list_price
2813                                 );
2814                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').line_quantity : '|| gx_req_line_detail_tbl(p).line_quantity
2815                                 );
2816                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').adjustment_amount : '|| gx_req_line_detail_tbl(p).adjustment_amount
2817                                 );
2818                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').applied_flag : '|| gx_req_line_detail_tbl(p).applied_flag
2819                                 );
2820                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').modifier_level_code : '|| gx_req_line_detail_tbl(p).modifier_level_code
2821                                 );
2822                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').status_code : '|| gx_req_line_detail_tbl(p).status_code
2823                                 );
2824                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').status_text : '|| gx_req_line_detail_tbl(p).status_text
2825                                 );
2826                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').substitution_attribute : '|| gx_req_line_detail_tbl(p).substitution_attribute
2827                                 );
2828                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').accrual_flag : '|| gx_req_line_detail_tbl(p).accrual_flag
2829                                 );
2830                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').list_line_no : '|| gx_req_line_detail_tbl(p).list_line_no
2831                                 );
2832                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').estim_gl_value : '|| gx_req_line_detail_tbl(p).estim_gl_value
2833                                 );
2834                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').accrual_conversion_rate : '|| gx_req_line_detail_tbl(p).accrual_conversion_rate
2835                                 );
2836                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').override_flag : '|| gx_req_line_detail_tbl(p).override_flag
2837                                 );
2838                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').print_on_invoice_flag : '|| gx_req_line_detail_tbl(p).print_on_invoice_flag
2839                                 );
2840                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').inventory_item_id : '|| gx_req_line_detail_tbl(p).inventory_item_id
2841                                 );
2842                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').organization_id : '|| gx_req_line_detail_tbl(p).organization_id
2843                                 );
2844                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').related_item_id : '|| gx_req_line_detail_tbl(p).related_item_id
2845                                 );
2846                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').relationship_type_id : '|| gx_req_line_detail_tbl(p).relationship_type_id
2847                                 );
2848                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').estim_accrual_rate : '|| gx_req_line_detail_tbl(p).estim_accrual_rate
2849                                 );
2850                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').expiration_date : '|| gx_req_line_detail_tbl(p).expiration_date
2851                                 );
2852                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').benefit_price_list_line_id : '|| gx_req_line_detail_tbl(p).benefit_price_list_line_id
2853                                 );
2854                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').recurring_flag : '|| gx_req_line_detail_tbl(p).recurring_flag
2855                                 );
2856                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').recurring_value : '|| gx_req_line_detail_tbl(p).recurring_value
2857                                 );
2858                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').benefit_limit : '|| gx_req_line_detail_tbl(p).benefit_limit
2859                                 );
2860                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').charge_type_code : '|| gx_req_line_detail_tbl(p).charge_type_code
2861                                 );
2862                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').charge_subtype_code : '|| gx_req_line_detail_tbl(p).charge_subtype_code
2863                                 );
2864                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').include_on_returns_flag : '|| gx_req_line_detail_tbl(p).include_on_returns_flag
2865                                 );
2866                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').benefit_qty : '|| gx_req_line_detail_tbl(p).benefit_qty
2867                                 );
2868                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').benefit_uom_code : '|| gx_req_line_detail_tbl(p).benefit_uom_code
2869                                 );
2870                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').proration_type_code : '|| gx_req_line_detail_tbl(p).proration_type_code
2871                                 );
2872                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').source_system_code : '|| gx_req_line_detail_tbl(p).source_system_code
2873                                 );
2874                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').rebate_transaction_type_code : '|| gx_req_line_detail_tbl(p).rebate_transaction_type_code
2875                                 );
2876                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').secondary_pricelist_ind : '|| gx_req_line_detail_tbl(p).secondary_pricelist_ind
2877                                 );
2878                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').group_value : '|| gx_req_line_detail_tbl(p).group_value
2879                                 );
2880                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').comments : '|| gx_req_line_detail_tbl(p).comments
2881                                 );
2882                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').updated_flag : '|| gx_req_line_detail_tbl(p).updated_flag
2883                                 );
2884                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').process_code : '|| gx_req_line_detail_tbl(p).process_code
2885                                 );
2886                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').limit_code : '|| gx_req_line_detail_tbl(p).limit_code
2887                                 );
2888                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').limit_text : '|| gx_req_line_detail_tbl(p).limit_text
2889                                 );
2890                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').formula_id : '|| gx_req_line_detail_tbl(p).formula_id
2891                                 );
2892                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').calculation_code : '|| gx_req_line_detail_tbl(p).calculation_code
2893                                 );
2894                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').rounding_factor : '|| gx_req_line_detail_tbl(p).rounding_factor
2895                                 );
2896                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').currency_detail_id : '|| gx_req_line_detail_tbl(p).currency_detail_id
2897                                 );
2898                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').currency_header_id : '|| gx_req_line_detail_tbl(p).currency_header_id
2899                                 );
2900                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').selling_rounding_factor : '|| gx_req_line_detail_tbl(p).selling_rounding_factor
2901                                 );
2902                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').order_currency : '|| gx_req_line_detail_tbl(p).order_currency
2903                                 );
2904                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').pricing_effective_date : '|| gx_req_line_detail_tbl(p).pricing_effective_date
2905                                 );
2906                         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').base_currency_code : '|| gx_req_line_detail_tbl(p).base_currency_code
2907                                 );
2908                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').change_reason_code : '|| gx_req_line_detail_tbl(p).change_reason_code
2909                                 );
2910                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').change_reason_text : '|| gx_req_line_detail_tbl(p).change_reason_text
2911                                 );
2912                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').break_uom_code : '|| gx_req_line_detail_tbl(p).break_uom_code
2913                                 );
2914                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').break_uom_context : '|| gx_req_line_detail_tbl(p).break_uom_context
2915                                 );
2916                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_tbl('|| p ||').break_uom_attribute : '|| gx_req_line_detail_tbl(p).break_uom_attribute
2917                                 );
2918                 exit when gx_req_line_detail_tbl.last = p;
2919                 p := gx_req_line_detail_tbl.next(p);
2920             end loop;
2921         end if; -- gx_req_line_detail_tbl.count > 0
2922 
2923     --
2924     -- output parameter 5: gx_req_line_detail_qual_tbl
2925     --
2926         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2927         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** output parameter 5: gx_req_line_detail_qual_tbl ******************');
2928             fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl.count '|| gx_req_line_detail_qual_tbl.count
2929                         );
2930         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2931 
2932         if gx_req_line_detail_qual_tbl.count > 0 then
2933             p := gx_req_line_detail_qual_tbl.first;
2934                 loop
2935                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_line_detail_qual_tbl('|| p ||') *************'
2936                                 );
2937                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').line_detail_index : '|| gx_req_line_detail_qual_tbl(p).line_detail_index
2938                                 );
2939                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').qualifier_context : '|| gx_req_line_detail_qual_tbl(p).qualifier_context
2940                                 );
2941                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').qualifier_attribute : '|| gx_req_line_detail_qual_tbl(p).qualifier_attribute
2942                                 );
2943                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').qualifier_attr_value_from : '|| gx_req_line_detail_qual_tbl(p).qualifier_attr_value_from
2944                                 );
2945                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').qualifier_attr_value_to : '|| gx_req_line_detail_qual_tbl(p).qualifier_attr_value_to
2946                                 );
2947                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').comparison_operator_code : '|| gx_req_line_detail_qual_tbl(p).comparison_operator_code
2948                                 );
2949                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').validated_flag : '|| gx_req_line_detail_qual_tbl(p).validated_flag
2950                                 );
2951                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').status_code : '|| gx_req_line_detail_qual_tbl(p).status_code
2952                                 );
2953                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_qual_tbl('|| p ||').status_text : '|| gx_req_line_detail_qual_tbl(p).status_text
2954                                 );
2955                 exit when gx_req_line_detail_qual_tbl.last = p;
2956                 p := gx_req_line_detail_qual_tbl.next(p);
2957             end loop;
2958         end if; -- gx_req_line_detail_qual_tbl.count > 0
2959  --
2960     -- output parameter 6: gx_req_line_detail_attr_tbl
2961     --
2962         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2963         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** output parameter 6: gx_req_line_detail_attr_tbl ******************');
2964             fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl.count '|| gx_req_line_detail_attr_tbl.count
2965                         );
2966         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
2967 
2968         if gx_req_line_detail_attr_tbl.count > 0 then
2969             p := gx_req_line_detail_attr_tbl.first;
2970                 loop
2971                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_line_detail_attr_tbl('|| p ||') *************'
2972                                 );
2973                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').line_detail_index : '|| gx_req_line_detail_attr_tbl(p).line_detail_index
2974                                 );
2975                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').line_index : '|| gx_req_line_detail_attr_tbl(p).line_index
2976                                 );
2977                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').pricing_context : '|| gx_req_line_detail_attr_tbl(p).pricing_context
2978                                 );
2979                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').pricing_attribute : '|| gx_req_line_detail_attr_tbl(p).pricing_attribute
2980                                 );
2981                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').pricing_attr_value_from : '|| gx_req_line_detail_attr_tbl(p).pricing_attr_value_from
2982                                 );
2983                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').pricing_attr_value_to : '|| gx_req_line_detail_attr_tbl(p).pricing_attr_value_to
2984                                 );
2985                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').validated_flag : '|| gx_req_line_detail_attr_tbl(p).validated_flag
2986                                 );
2987                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').status_code : '|| gx_req_line_detail_attr_tbl(p).status_code
2988                                 );
2989                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_line_detail_attr_tbl('|| p ||').status_text : '|| gx_req_line_detail_attr_tbl(p).status_text
2990                                 );
2991                 exit when gx_req_line_detail_attr_tbl.last = p;
2992                 p := gx_req_line_detail_attr_tbl.next(p);
2993             end loop;
2994         end if; -- gx_req_line_detail_attr_tbl.count > 0
2995 
2996     --
2997     -- output parameter 7: gx_req_related_lines_tbl
2998     --
2999         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
3000         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ***************** output parameter 7: gx_req_related_lines_tbl ******************');
3001         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl.count '|| gx_req_related_lines_tbl.count
3002                         );
3003         fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: *********************************************************');
3004 
3005         if gx_req_related_lines_tbl.count > 0 then
3006             p := gx_req_related_lines_tbl.first;
3007                 loop
3008                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: ************* parameter gx_req_related_lines_tbl('|| p ||') *************'
3009                                 );
3010                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').line_index : '|| gx_req_related_lines_tbl(p).line_index
3011                                 );
3012                  fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').line_detail_index : '|| gx_req_related_lines_tbl(p).line_detail_index
3013                                 );
3014                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').relationship_type_code : '|| gx_req_related_lines_tbl(p).relationship_type_code
3015                                 );
3016                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').related_line_index : '|| gx_req_related_lines_tbl(p).related_line_index
3017                                 );
3018                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').related_line_detail_index : '|| gx_req_related_lines_tbl(p).related_line_detail_index
3019                                 );
3020                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').status_code : '|| gx_req_related_lines_tbl(p).status_code
3021                                 );
3022                 fnd_log.string (fnd_log.level_statement, g_module || l_api_name,'qp_call: gx_req_related_lines_tbl('|| p ||').status_text : '|| gx_req_related_lines_tbl(p).status_text
3023                                 );
3024                 exit when gx_req_related_lines_tbl.last = p;
3025                 p := gx_req_related_lines_tbl.next(p);
3026             end loop;
3027         end if; -- gx_req_related_lines_tbl.count > 0
3028 
3029     END IF;
3030 
3031 
3032  IF NVL (lx_return_status, 'S') <> 'S'
3033       THEN
3034          FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => QP API error  '||lx_return_status_text);
3035          RAISE bulk_contract_exception;
3036   END IF;
3037 
3038    for usage_line_rec IN usage_line_csr(bulk_qp_hdr_id_rec.dnz_chr_id)
3039     LOOP
3040       BEGIN
3041          DBMS_TRANSACTION.SAVEPOINT('BEFORE_TRANSACTION');
3042 
3043           If l_write_log then
3044              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 initializing Billing Report ');
3045            End If;
3046 
3047               l_billrep_found          := FALSE;
3048 
3049            IF (p_billrep_tbl.count > 0) THEN
3050              j := p_billrep_tbl.FIRST;
3051              LOOP
3052                   IF(p_billrep_tbl(j).Currency_code = usage_line_rec.Currency_code) THEN
3053                        l_billrep_found := TRUE;
3054                  p_billrep_tbl_idx := j;         --point to the index containing the currency code
3055                  EXIT;
3056                END IF;
3057                EXIT WHEN j = p_billrep_tbl.LAST;
3058                j := p_billrep_tbl.NEXT(j);
3059              END LOOP;
3060            END IF;
3061 
3062 
3063            IF (l_billrep_found = FALSE) THEN
3064              p_billrep_tbl_idx      := p_billrep_tbl_idx + 1;
3065              p_billrep_tbl(p_billrep_tbl_idx).Currency_code := usage_line_rec.Currency_code;
3066              p_billrep_tbl(p_billrep_tbl_idx).Successful_Lines := 0;
3067              p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := 0;
3068              p_billrep_tbl(p_billrep_tbl_idx).Successful_SubLines := 0;
3069              p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := 0;
3070              p_billrep_tbl(p_billrep_tbl_idx).Successful_Lines_Value := 0;
3071              p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := 0;
3072              p_billrep_tbl(p_billrep_tbl_idx).Successful_SubLines_Value := 0;
3073              p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := 0;
3074            END IF;
3075 
3076            If l_write_log then
3077              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After initializing Billing Report ');
3078            End If;
3079 
3080 
3081         SELECT count(usage_line_rec.line_id)  INTO l_subline_count
3082         FROM   OKC_K_LINES_B sub_line
3083         WHERE  sub_line.cle_id =usage_line_Rec.line_id
3084                 AND    sub_line.lse_id in (8,7,9,10,11,13,25,35)
3085         AND    sub_line.date_cancelled is NULL ;              --[llc]
3086         /*AND    not  exists ( select 1 from okc_k_rel_objs rel
3087                              where rel.cle_id = sub_line.id ); Commented for 16039680 */
3088 
3089        for bsl_rec IN bsl_cur(usage_line_rec.line_id,bulk_qp_hdr_id_rec.DNZ_chr_id)
3090           LOOP
3091 
3092                    bsl_index:=bsl_rec.line_index ;
3093                    l_subline_id:=bsl_Rec.subline_id;
3094                    l_prv:=bsl_rec.prv;
3095                    l_price_break_tbl.DELETE;
3096                    l_amount:= bsl_rec.amount;
3097                    l_PROD_EXT_AMOUNT:=0;
3098 
3099               IF NVL (gx_req_line_tbl(bsl_index).status_code, qp_preq_grp.g_status_new) NOT IN
3100                      (qp_preq_grp.g_status_updated,
3101                       qp_preq_grp.g_status_system_generated,
3102                       qp_preq_grp.g_by_engine,
3103                       qp_preq_grp.g_status_unchanged,
3104                       qp_preq_grp.g_status_new
3105                      )
3106                THEN
3107 
3108                l_msg_data:=gx_req_line_tbl(bsl_index).status_text;
3109                RAISE bulk_usage_exception;
3110 
3111                END IF; ---status code
3112 
3113 
3114          --If pricing is success Apply modifiers
3115 
3116           i                          := gx_req_line_detail_tbl.FIRST;
3117 
3118            IF i IS NOT NULL THEN
3119             LOOP
3120 
3121              if (
3122                  gx_req_line_detail_tbl (i).line_index = bsl_index   AND
3123                  gx_req_line_detail_tbl (i).applied_flag = 'Y'   AND
3124                   (
3125                    gx_req_line_detail_tbl (i).list_line_type_code = 'DIS' OR
3126                    gx_req_line_detail_tbl (i).list_line_type_code = 'SUR'
3127                   )
3128                 ) then
3129                l_modifier_details (i)     := gx_req_line_detail_tbl (i);
3130 
3131             end if;
3132 
3133 
3134           EXIT WHEN i = gx_req_line_detail_tbl.LAST;
3135                i                          := gx_req_line_detail_tbl.NEXT (i);
3136           END LOOP;
3137 
3138            END IF; --req_line_detail_tbl
3139 
3140 
3141 
3142 
3143            modifier_4_usg (p_bsl_id                           => bsl_rec.bsl_id,
3144                             p_modifier_details                 => x_modifier_details,
3145                             x_return_status                    => l_return_status
3146                            );
3147 
3148             IF l_return_status <> 'S'
3149             THEN
3150                     l_msg_data:= 'Modifier Creation Error - Usage' ;
3151 
3152                RAISE bulk_usage_exception;
3153             END IF;
3154 
3155             --Pricing details
3156                l_PROD_EXT_AMOUNT :=
3157                   ROUND (NVL (gx_req_line_tbl (bsl_index).adjusted_unit_price,
3158                               gx_req_line_tbl (bsl_index).unit_price) *
3159                          gx_req_line_tbl (bsl_index).priced_quantity,
3160                          29);
3161 
3162                      --Price breaks
3163               l_top_ctr                  := gx_req_related_lines_tbl.FIRST;
3164 
3165               IF l_top_ctr IS NOT NULL THEN
3166               LOOP
3167 
3168                 IF gx_req_related_lines_tbl (l_top_ctr).relationship_type_code = qp_preq_grp.g_pbh_line AND
3169                 gx_req_related_lines_tbl(l_top_ctr).line_index = bsl_index THEN
3170 
3171 
3172 
3173                   l_rel_index                :=
3174                      gx_req_related_lines_tbl (l_top_ctr).related_line_detail_index;
3175                   l_lin_index                :=
3176                      gx_req_related_lines_tbl (l_top_ctr).line_detail_index;
3177 
3178 
3179 
3180 
3181                   l_ctr                      :=
3182                                             gx_req_line_detail_attr_tbl.FIRST;
3183 
3184                     LOOP
3185 
3186 
3187 
3188                   IF gx_req_line_detail_attr_tbl (l_ctr).line_detail_index = l_rel_index THEN
3189 
3190                     l_price_break_tbl (l_top_ctr).quantity_from :=
3191                            fnd_number.canonical_to_number(gx_req_line_detail_attr_tbl (l_ctr).pricing_attr_value_from);
3192                     l_price_break_tbl (l_top_ctr).quantity_to :=
3193                            fnd_number.canonical_to_number(gx_req_line_detail_attr_tbl (l_ctr).pricing_attr_value_to);
3194 
3195                   END IF; --req_line_detail_attr_tbl =rel_indx
3196 
3197                   EXIT WHEN l_ctr = gx_req_line_detail_attr_tbl.LAST;
3198                   l_ctr                      :=
3199                                            gx_req_line_detail_attr_tbl.NEXT (l_ctr);
3200                   END LOOP;
3201 
3202 
3203                   l_ctr                      := gx_req_line_detail_tbl.FIRST;
3204 
3205                   LOOP
3206 
3207 
3208                     IF gx_req_line_detail_tbl (l_ctr).line_detail_index =
3209                                                                   l_rel_index
3210                      THEN
3211 
3212                      IF gx_req_line_detail_tbl (l_ctr).created_from_list_type_code IN
3213                                                               ('PRL', 'AGR')
3214                         THEN
3215                            -- end FP Bug 4534076
3216                            l_price_break_tbl (l_top_ctr).list_price :=
3217                                  gx_req_line_detail_tbl (l_ctr).operand_value;
3218                            l_price_break_tbl (l_top_ctr).break_method :=
3219                               gx_req_line_detail_tbl (l_ctr).price_break_type_code;
3220 
3221                             IF gx_req_line_detail_tbl (l_ctr).created_from_list_type_code =
3222                                                                         'PBH'
3223                            THEN
3224 
3225                             IF bsl_rec.break_uom_code IS NULL
3226                               THEN
3227                                  l_price_break_tbl (l_top_ctr).break_uom_code :=
3228                                     gx_req_line_detail_tbl (l_ctr).break_uom_code;
3229                                  l_price_break_tbl (l_top_ctr).break_uom_context :=
3230                                     gx_req_line_detail_tbl (l_ctr).break_uom_context;
3231                                  l_price_break_tbl (l_top_ctr).break_uom_attribute :=
3232                                     gx_req_line_detail_tbl (l_ctr).break_uom_attribute;
3233                               ELSE
3234                                  l_price_break_tbl (l_top_ctr).break_uom_code :=
3235                                                   bsl_rec.break_uom_code;
3236                                  l_price_break_tbl (l_top_ctr).break_uom_context :=
3237                                                                          NULL;
3238                                  l_price_break_tbl (l_top_ctr).break_uom_attribute :=
3239                                                                          NULL;
3240                               END IF; --breaskuom code
3241 
3242                            END IF; ---pbh
3243 
3244                            l_price_break_tbl (l_top_ctr).unit_price :=
3245                               NVL
3246                                  (gx_req_line_detail_tbl (l_ctr).adjustment_amount,
3247                                   gx_req_line_detail_tbl (l_ctr).list_price);
3248                            l_price_break_tbl (l_top_ctr).quantity :=
3249                                   gx_req_line_detail_tbl (l_ctr).line_quantity;
3250 
3251 IF (gx_req_line_detail_tbl(l_ctr).OPERAND_CALCULATION_CODE='BLOCK_PRICE') THEN
3252                               l_price_break_tbl (l_top_ctr).amount :=
3253                               l_price_break_tbl (l_top_ctr).unit_price;
3254                           else
3255                                l_price_break_tbl (l_top_ctr).amount :=
3256                               l_price_break_tbl (l_top_ctr).unit_price *
3257                               l_price_break_tbl (l_top_ctr).quantity;
3258                           END IF;
3259 
3260                           ELSE
3261 
3262                           l_price_break_tbl.DELETE (l_top_ctr);
3263                      END IF;--gx_req_line_dtl_tbl = prl agr
3264 
3265                     END IF;  --req_line_detail_tbl=rel_index
3266 
3267                   EXIT WHEN l_ctr = gx_req_line_detail_tbl.LAST;
3268                      l_ctr                      :=
3269                                            gx_req_line_detail_tbl.NEXT (l_ctr);
3270                   END LOOP;
3271 
3272 
3273 
3274   --break uom
3275 
3276     l_ctr                      := gx_req_line_detail_tbl.FIRST;
3277 
3278                   LOOP
3279                      IF gx_req_line_detail_tbl (l_ctr).line_detail_index =
3280                                                                   l_lin_index
3281                      THEN
3282                         -- skekkar forward port Bug 4534076 added 'AGR'
3283                         IF gx_req_line_detail_tbl (l_ctr).created_from_list_type_code IN
3284                                                               ('PRL', 'AGR')
3285                         THEN
3286                            -- end FP Bug 4534076
3287                            IF bsl_rec.break_uom_code IS NOT NULL
3288                            THEN
3289                               l_price_break_tbl (l_top_ctr).break_uom_code :=
3290                                                   bsl_rec.break_uom_code;
3291                               l_price_break_tbl (l_top_ctr).break_uom_context :=
3292                                                                          NULL;
3293                               l_price_break_tbl (l_top_ctr).break_uom_attribute :=
3294                                                                          NULL;
3295                            ELSE
3296                               l_price_break_tbl (l_top_ctr).break_uom_code :=
3297                                  gx_req_line_detail_tbl (l_ctr).break_uom_code;
3298                               l_price_break_tbl (l_top_ctr).break_uom_context :=
3299                                  gx_req_line_detail_tbl (l_ctr).break_uom_context;
3300                               l_price_break_tbl (l_top_ctr).break_uom_attribute :=
3301                                  gx_req_line_detail_tbl (l_ctr).break_uom_attribute;
3302                            END IF;
3303                         ELSE
3304                            l_price_break_tbl.DELETE (l_top_ctr);
3305                         END IF;
3306                      END IF;
3307 
3308                      EXIT WHEN l_ctr = gx_req_line_detail_tbl.LAST;
3309                      l_ctr                      :=
3310                                            gx_req_line_detail_tbl.NEXT (l_ctr);
3311                   END LOOP;
3312 --END BREAK UOM
3313 
3314                 END IF; --g_pbh_line
3315 
3316 
3317               EXIT WHEN l_top_ctr = gx_req_related_lines_tbl.LAST;
3318                l_top_ctr          :=  gx_req_related_lines_tbl.NEXT (l_top_ctr);
3319               END LOOP;
3320 
3321               END IF; --l_top_ctr
3322 
3323 
3324 
3325              l_price_rec.PROD_EXT_AMOUNT:=l_PROD_EXT_AMOUNT*bsl_rec.bill_sign;
3326 
3327 
3328               OKS_BILL_REC_PUB.update_bsl
3329                   (
3330                    X_RET_STAT     => l_return_status,
3331                    P_DNZ_CHR_ID   => bsl_rec.dnz_chr_id,
3332                    P_BSL_ID       => bsl_rec.bsl_id,
3333                    P_BCL_ID       => bsl_rec.usg_bcl_id,
3334                    P_AMOUNT       => l_price_rec.PROD_EXT_AMOUNT,
3335                    P_CURRENCY_CODE=> bsl_rec.currency_code,
3336                    P_PRV          => bsl_rec.prv
3337                    );
3338 
3339               IF (l_return_status <> 'S') THEN
3340                 oks_bill_rec_pub.get_message
3341                    (l_msg_cnt  => l_msg_count,
3342                     l_msg_data => l_msg_data);
3343 
3344                 Raise bulk_USAGE_EXCEPTION;
3345               END IF;
3346 
3347               l_break_amount := 0;
3348               -- Populate Price Break Record here and Insert Price Breaks  Details
3349               --FOR i in l_price_break_details.first..l_price_break_details.last
3350               IF (l_price_break_tbl.COUNT)  > 0 THEN
3351                 i := l_price_break_tbl.FIRST;
3352                 LOOP
3353 
3354                   l_pbr_rec_in.bcl_id     := bsl_rec.usg_bcl_id;
3355                   l_pbr_rec_in.bsl_id     := bsl_rec.bsl_id;
3356                   l_pbr_rec_in.cle_id     := bsl_rec.subline_id;
3357                   l_pbr_rec_in.chr_id     := bsl_rec.dnz_chr_id;
3358                   l_pbr_rec_in.unit_price := l_price_break_tbl(i).unit_price;
3359                   l_pbr_rec_in.amount     := l_price_break_tbl(i).amount;
3360 
3361 
3362                   l_pbr_rec_in.amount  :=
3363                     OKS_EXTWAR_UTIL_PVT.round_currency_amt(l_price_break_tbl(i).amount, bsl_Rec.currency_code);
3364 
3365                   l_pbr_rec_in.quantity_from
3366                            := l_price_break_tbl(i).quantity_from;
3367                            --:= l_price_break_details(i).pricing_attr_value_from;
3368                   l_pbr_rec_in.quantity_to
3369                            := l_price_break_tbl(i).quantity_to;
3370                   l_pbr_rec_in.quantity
3371                            := l_price_break_tbl(i).quantity;
3372                   l_pbr_rec_in.prorate := nvl(bsl_rec.prorate,bsl_rec.line_prorate);
3373                   --l_pbr_rec_in.lock_flag
3374                   --           := l_price_break_details(i).lock_flag;
3375                   --l_pbr_rec_in.locked_price_list_id
3376                   --           := l_price_break_details(i).locked_price_list_id;
3377                   --l_pbr_rec_in.locked_price_list_line_id
3378                   --          := l_price_break_details(i).locked_price_list_line_id;
3379                   --l_pbr_rec_in.price_list_id
3380                   --          := l_price_break_details(i).price_list_id;
3381                   --l_pbr_rec_in.price_list_line_id
3382                   --           := l_price_break_details(i).price_list_line_id;
3383 
3384 
3385                   l_break_amount := nvl(l_break_amount,0) + nvl(l_pbr_rec_in.amount,0) ;
3386 
3387                   IF ( nvl(l_pbr_rec_in.quantity,0)  > 0) THEN
3388                     OKS_PBR_PVT.insert_row(
3389                        P_API_VERSION       => 1,
3390                        P_INIT_MSG_LIST     => l_init_msg_list,
3391                        X_RETURN_STATUS     => l_return_status,
3392                        X_MSG_COUNT         => l_msg_count,
3393                        X_MSG_DATA          => l_msg_data,
3394                        P_PBRV_REC          => l_pbr_rec_in,
3395                        X_PBRV_REC          => l_pbr_rec_out) ;
3396 
3397                   END IF;
3398                   EXIT WHEN i = l_price_break_tbl.LAST;
3399                   i := l_price_break_tbl.NEXT(i);
3400                 END LOOP;
3401               END IF; --  l_price_break_details.COUNT > 0
3402 
3403           --Modified for bug:9900133
3404             IF ((l_break_amount <> 0 ) and ( l_break_amount <> abs(l_price_rec.PROD_EXT_AMOUNT))) THEN
3405                 OKS_BILL_REC_PUB.prorate_price_breaks (
3406                        P_BSL_ID        =>      bsl_rec.bsl_id,
3407                        P_BREAK_AMOUNT  =>      l_break_amount,
3408                        P_TOT_AMOUNT    =>      l_price_rec.PROD_EXT_AMOUNT   ,
3409                        X_RETURN_STATUS =>      l_return_status) ;
3410               END IF;
3411 
3412 
3413 
3414          END loop; --bsl_rec
3415 
3416 
3417          OKS_ARFEEDER_PUB.Get_REC_FEEDER
3418                         (
3419                          X_RETURN_STATUS            => l_return_status,
3420                          X_MSG_COUNT                => l_msg_cnt,
3421                          X_MSG_DATA                 => l_msg_data,
3422                          P_FLAG                     => p_flag,  -- checkout
3423                          P_CALLED_FROM              => p_calledfrom,
3424                          P_DATE                     => p_date,
3425                          P_CLE_ID                   => usage_line_Rec.line_id,
3426                          P_PRV                      => p_prv,
3427                          P_BILLREP_TBL              => p_billrep_tbl,
3428                          P_BILLREP_TBL_IDX          => p_billrep_tbl_idx,
3429                          P_BILLREP_ERR_TBL          => p_billrep_err_tbl,
3430                          P_BILLREP_ERR_TBL_IDX      => p_billrep_err_tbl_idx
3431                         );
3432 
3433            IF (l_return_status   <>  OKC_API.G_RET_STS_SUCCESS) Then
3434                 oks_bill_rec_pub.get_message (
3435                   l_msg_cnt  => l_msg_count,
3436                      l_msg_data => l_msg_data);
3437            FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => Failed in AR FEEDER :'||'  '||usage_line_rec.line_id);
3438 
3439            RAISE Bulk_USAGE_line_EXCEPTION;
3440 
3441 
3442            END IF;
3443 
3444             update_version(p_dnz_chr_id => bulk_qp_hdr_id_rec.dnz_chr_id);
3445 
3446             p_process_counter := p_process_counter + 1;
3447 
3448 
3449 
3450          EXCEPTION
3451 
3452          WHEN Bulk_USAGE_EXCEPTION THEN
3453 
3454   /*FOR BILLING REPORT*/
3455              p_reject_counter := p_reject_counter + 1;
3456   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
3457   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_amount,0) + nvl(l_PROD_EXT_AMOUNT,0) ;
3458   /*FOR ERROR REPORT*/
3459   p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
3460   p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := usage_line_rec.line_id;
3461   p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 12;
3462   p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=  l_subline_id ;
3463   p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3464 
3465 
3466   DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
3467 
3468   Rollback_usg_bill_dtls_prc(usage_line_rec.line_id,bulk_qp_hdr_id_rec.DNZ_chr_id,l_prv);
3469   RETCODE := 1;
3470 
3471   WHEN Bulk_USAGE_line_EXCEPTION THEN
3472 
3473   p_reject_counter := p_reject_counter + 1;
3474   DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
3475   Rollback_usg_bill_dtls_prc(usage_line_rec.line_id,bulk_qp_hdr_id_rec.DNZ_chr_id,l_prv);
3476   RETCODE := 1;
3477 
3478   WHEN OTHERS THEN
3479   /*FOR BILLING REPORT*/
3480   p_reject_counter := p_reject_counter + 1;
3481   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
3482   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_amount,0) + nvl(l_PROD_EXT_AMOUNT,0) ;
3483   /*FOR ERROR REPORT*/
3484   p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
3485   p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := usage_line_rec.line_id;
3486   p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 12;
3487   p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=  l_subline_id ;
3488   p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3489 
3490 
3491 
3492 
3493   DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
3494 
3495   Rollback_usg_bill_dtls_prc(usage_line_rec.line_id,bulk_qp_hdr_id_rec.DNZ_chr_id,l_prv);
3496   RETCODE := 1;
3497 
3498          END;
3499 
3500 
3501       end loop; --usage_line_rec
3502 
3503       EXCEPTION
3504       WHEN   Bulk_contract_EXCEPTION THEN
3505          Rollback_usg_bill_dtls_prc(null,bulk_qp_hdr_id_rec.DNZ_chr_id,l_prv);
3506          SELECT Count(DISTINCT line_id) INTO p_reject_counter FROM oks_usg_qp_call_tbl WHERE dnz_chr_id= bulk_qp_hdr_id_rec.DNZ_chr_id;
3507          RETCODE := 1;
3508 
3509           WHEN   OTHERS THEN
3510              Rollback_usg_bill_dtls_prc(null,bulk_qp_hdr_id_rec.DNZ_chr_id,l_prv);
3511              SELECT Count(DISTINCT line_id) INTO p_reject_counter FROM oks_usg_qp_call_tbl WHERE dnz_chr_id= bulk_qp_hdr_id_rec.DNZ_chr_id;
3512              RETCODE := 1;
3513 
3514       END;
3515 
3516      end loop; --header_Cur
3517 
3518 
3519 
3520 
3521     EXCEPTION
3522     WHEN OTHERS THEN
3523         FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Usg_billing_bulk_qp_call_prc=> when others raised'||sqlerrm);
3524 END Usg_billing_bulk_qp_call_prc;
3525 
3526 
3527 -------------------------------------------------------------------------
3528 -- Begin partial period computation logic
3529 -- Developer Mani Choudhary
3530 -- Date 10-JUN-2005
3531 -- Added  parameters p_period_type,p_period_start
3532 -------------------------------------------------------------------------
3533 Procedure Bill_usage_item(
3534                p_dnz_chr_id              IN            NUMBER,
3535                p_contract_number         IN            VARCHAR2,
3536                p_con_num_modifier        IN            VARCHAR2,
3537                p_line_number             IN            NUMBER,
3538                p_lse_id                  IN            NUMBER,
3539                p_object1_id1             IN            VARCHAR2,
3540                p_object1_id2             IN            VARCHAR2,
3541                p_top_line_id             IN            NUMBER,
3542                p_top_line_start_date     IN            DATE,
3543                p_top_line_term_date      IN            DATE,
3544                p_top_line_end_date       IN            DATE,
3545                p_inv_organization_id     IN            NUMBER,
3546                p_currency_code           IN            VARCHAR2,
3547                p_settlement_interval     IN            VARCHAR2,
3548                p_uom_code                IN            VARCHAR2,
3549                p_time_uom_code           IN            VARCHAR2,
3550                p_okl_flag                IN            NUMBER,
3551                p_prv                     IN            NUMBER,
3552                p_date                    IN            DATE,
3553                p_billrep_tbl             IN OUT NOCOPY OKS_BILL_REC_PUB.bill_report_tbl_type,
3554                p_billrep_tbl_idx         IN            NUMBER,
3555                p_billrep_err_tbl         IN OUT NOCOPY OKS_BILL_REC_PUB.billrep_error_tbl_type,
3556                p_billrep_err_tbl_idx     IN OUT NOCOPY NUMBER,
3557                p_ar_feeder_ctr           IN OUT NOCOPY NUMBER,
3558                p_period_type             IN            VARCHAR2,
3559                p_period_start            IN            VARCHAR2,
3560                p_return_status           IN OUT NOCOPY VARCHAR2
3561                )
3562 IS
3563 l_usage_type                VARCHAR2(10);
3564 l_usage_period              VARCHAR2(10);
3565 l_counter_uom_code          VARCHAR2(30);
3566 l_flag                      VARCHAR2(10);
3567 l_prorate                   VARCHAR2(10);
3568 l_break_uom_code            VARCHAR2(10);
3569 e_ptr                       NUMBER;
3570 l_ptr                       NUMBER;
3571 l_qty                       NUMBER;
3572 l_level_qty                 NUMBER;
3573 l_break_amount              NUMBER;
3574 l_temp                      NUMBER;
3575 l_sign                      NUMBER;
3576 no_of_cycles                NUMBER;
3577 l_line_total                NUMBER;
3578 l_total                     NUMBER;
3579 l_final_qty                 NUMBER;
3580 l_bcl_id                    NUMBER;
3581 l_amount                    NUMBER;
3582 l_init_value                NUMBER;
3583 l_final_value               NUMBER;
3584 l_base_reading              NUMBER;
3585 l_counter_value_id          NUMBER;
3586 l_counter_grp_id            NUMBER;
3587 l_sub_id                    NUMBER;
3588 l_tsub_id                   NUMBER;
3589 l_estimated_qty             NUMBER;
3590 l_actual_qty                NUMBER;
3591 l_quantity_ordered          NUMBER;
3592 l_locked_price_list_id      NUMBER;
3593 l_locked_price_list_line_id NUMBER;
3594 i                           NUMBER;
3595 l_inv_date                  DATE;
3596 l_ar_inv_date               DATE;
3597 l_bill_start_date           DATE;
3598 l_bill_end_date             DATE;
3599 l_exception_amount          NUMBER;
3600 l_subline_count             NUMBER := 0;
3601 l_counter_id                NUMBER;
3602 l_lock_id                   NUMBER;
3603 l_object_version            NUMBER;
3604 l_lock_date                 DATE;
3605 
3606 
3607 /* Variable for calling std API*/
3608 l_api_version      CONSTANT NUMBER      := 1.0;
3609 l_called_from      CONSTANT NUMBER      := 1;
3610 l_init_msg_list    CONSTANT VARCHAR2(1) := 'F';
3611 l_msg_count                 NUMBER;
3612 l_msg_data                  VARCHAR2(2000);
3613 l_return_status             VARCHAR2(1);
3614 
3615 
3616 l_counter_reading_lock_rec  csi_ctr_datastructures_pub.ctr_reading_lock_rec;
3617 
3618 l_pbr_rec_in                OKS_PBR_PVT.pbrv_rec_type;
3619 l_pbr_rec_out               OKS_PBR_PVT.pbrv_rec_type;
3620 -------------------------------------------------------------------------
3621 -- Begin partial period computation logic
3622 -- Developer Mani Choudhary
3623 -- Date 11-JUN-2005
3624 -- local variables and cursors declared
3625 -------------------------------------------------------------------------
3626 l_rule_id                    NUMBER;
3627 l_uom_code                   VARCHAR2(30);
3628 CURSOR  l_billing_uom_csr(p_rul_id IN NUMBER) IS
3629 SELECT  uom_code
3630 FROM    oks_stream_levels_b
3631 WHERE   id = p_rul_id;
3632 -------------------------------------------------------------------------
3633 
3634 CURSOR l_inv_item_csr(p_cle_id Number,p_org_id Number) Is
3635   SELECT item.Object1_id1
3636         ,mtl.usage_item_flag
3637         ,mtl.service_item_flag
3638         ,mtl.primary_uom_code
3639   FROM   Okc_K_items Item
3640         ,mtl_system_items_b   mtl  --Okx_system_items_v mtl
3641   WHERE  item.cle_id = p_cle_id
3642   --AND    mtl.id1 = item.object1_id1
3643   AND    mtl.inventory_item_id = item.object1_id1
3644   AND    mtl.organization_id = p_org_id;
3645 
3646 
3647 CURSOR l_usage_csr (p_cle_id IN NUMBER) IS
3648   SELECT  usage_type                   Usage_Type,
3649           usage_period                 Usage_period,
3650           prorate                      Prorate,
3651           locked_price_list_id         locked_price_list_id,
3652           locked_price_list_line_id    locked_price_list_line_id
3653   FROM    OKS_K_LINES_B
3654   WHERE   cle_id = p_cle_id ;
3655 
3656 Cursor qty_uom_csr_sub(p_cle_id  Number) Is
3657    SELECT  okc.Number_of_items
3658             ,tl.Unit_of_measure uom_code
3659      FROM   okc_k_items okc
3660            ,mtl_units_of_measure_tl tl
3661      WHERE  okc.cle_id = p_cle_id
3662      AND    tl.uom_code = okc.uom_code
3663      AND    tl.language = USERENV('LANG');
3664 
3665   /*
3666   SELECT  Number_of_items
3667          ,OKX.Unit_of_measure uom_code
3668   FROM   OKC_K_ITEMS OKC
3669         ,OKX_UNITS_OF_MEASURE_V OKX
3670   WHERE  cle_id = P_cle_id
3671   AND    Okx.uom_code = OKC.uom_code ;
3672   */
3673 
3674 Cursor bsl_price_csr(p_bcl_id IN NUMBER, p_prv  IN   NUMBER) is
3675   SELECT bsl.id bsl_id, bsl.average average, bsd.unit_of_measure uom_code,
3676          bsl.date_billed_from ,bsl.date_billed_to,
3677          bsl.cle_id, rline.prorate,
3678          rline.locked_price_list_id,
3679          rline.locked_price_list_line_id,
3680          rline.dnz_chr_id
3681   FROM
3682         oks_k_lines_b           rline,
3683         oks_bill_sub_lines      bsl,
3684         oks_bill_sub_line_dtls  bsd
3685   WHERE bsl.bcl_id = p_bcl_id
3686   AND   bsl.id     = bsd.bsl_id
3687   AND   rline.cle_id = bsl.cle_id
3688   AND   p_prv      = 1
3689   UNION
3690   SELECT bsl.id bsl_id, bsl.average average, bsd.unit_of_measure uom_code,
3691          bsl.date_billed_from ,bsl.date_billed_to,
3692          bsl.cle_id , rline.prorate,
3693          rline.LOCKED_PRICE_LIST_ID,
3694          rline.locked_price_list_line_id,
3695          rline.dnz_chr_id
3696   FROM
3697         oks_k_lines_b   rline,
3698         oks_bsl_pr      bsl,
3699         oks_bsd_pr      bsd
3700   WHERE bsl.bcl_id = p_bcl_id
3701   AND   bsl.id     = bsd.bsl_id
3702   AND   rline.cle_id = bsl.cle_id
3703   AND   p_prv      = 2;
3704 
3705 
3706 CURSOR l_subline_Csr(p_cle_id  Number) Is
3707    SELECT
3708       sub_line.id                                        id
3709      ,sub_line.cle_id                                    cle_id
3710      ,sub_line.dnz_chr_id                                dnz_chr_id
3711      ,sub_line.price_negotiated                          price_negotiated
3712      ,sub_line.start_date                                start_date
3713      ,sub_line.end_date                                  end_date
3714      ,sub_line.date_terminated                           date_terminated
3715      ,sub_line.line_number                               line_number
3716      ,rul.fixed_quantity                                 fixed_qty
3717      ,rul.minimum_quantity                               minimum_qty
3718      ,rul.default_quantity                               default_qty
3719      ,rul.amcv_flag                                      amcv_flag
3720      ,rul.usage_period                                   usage_period
3721      ,rul.usage_duration                                 usage_duration
3722      ,rul.level_yn                                       level_yn
3723      ,rul.base_reading                                   base_reading
3724      ,rul.usage_type                                     usage_Type
3725      ,rul.usage_est_yn                                   usage_est_yn
3726      ,rul.usage_est_method                               usage_est_method
3727      ,rul.usage_est_start_date                           usage_est_start_date
3728    FROM   OKC_K_LINES_B sub_line ,
3729           OKS_K_LINES_B rul
3730    WHERE  sub_line.cle_id = p_cle_id
3731    AND    sub_line.date_cancelled is NULL               --[llc]
3732    AND    sub_line.id = rul.cle_id
3733    AND    sub_line.lse_id in (8,7,9,10,11,13,25,35);
3734    /*AND    not  exists ( select 1 from okc_k_rel_objs rel
3735                         WHERE rel.cle_id = sub_line.id ); Commented for 16039680 */
3736 
3737 
3738 /*FOR BILLING REPORT*/
3739 
3740 Cursor subline_count(p_cle_id  Number) Is
3741         SELECT count(sub_line.id)
3742         FROM   OKC_K_LINES_B sub_line
3743         WHERE  sub_line.cle_id = p_cle_id
3744         AND    sub_line.lse_id in (8,7,9,10,11,13,25,35)
3745         AND    sub_line.date_cancelled is NULL ;              --[llc]
3746         /*AND    not  exists ( select 1 from okc_k_rel_objs rel
3747                              where rel.cle_id = sub_line.id ); Commented for 16039680*/
3748 
3749 
3750 Cursor get_counter_qty(p_cle_id Number, p_lock_read number) IS
3751         select value_timestamp, counter_id
3752         from cs_counter_values, okc_k_items
3753         where cle_id = p_cle_id
3754         and   to_char(counter_id) = object1_id1
3755         and   counter_reading = p_lock_read;
3756 
3757 Cursor get_counter_vrt(p_cle_id Number) IS
3758         select to_number(object1_id1)
3759         from okc_k_items
3760         where cle_id = p_cle_id;
3761 
3762 
3763 --23-DEC-2005 mchoudha fix for bug#4915367
3764 Cursor bill_amount_npr (p_id IN NUMBER,p_hdr_id IN NUMBER,p_date_start IN DATE,p_date_end IN DATE) IS
3765 SELECT lvl.amount
3766 FROM   oks_level_elements lvl
3767 WHERE  lvl.cle_id = p_id
3768 And    lvl.dnz_chr_id = p_hdr_id
3769 And    lvl.date_start = p_date_start
3770 And    lvl.date_end = p_date_end;
3771 
3772 
3773 l_item_rec         l_inv_item_csr%ROWTYPE;
3774 l_qty_uom_sub_rec  qty_uom_csr_sub%ROWTYPE;
3775 l_subline_id       NUMBER;
3776 l_status_text     varchar2(200);  --added for bug 9927490
3777 
3778 usage_exception EXCEPTION;
3779 
3780 BEGIN
3781   If l_write_log then
3782      FND_FILE.PUT_LINE(FND_FILE.LOG,'***Processing Usage Item ***');
3783      FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Id:  ' || p_top_line_id);
3784      FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Start Date: ' || p_top_line_start_date);
3785      FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Termination Date/End date: ' || nvl(p_top_line_term_date,p_top_line_end_date));
3786   End If;
3787 
3788 
3789   p_return_status := 'S';
3790   l_prorate  := '';
3791   l_locked_price_list_id:= '';
3792   l_locked_price_list_line_id:= '';
3793 
3794   --Start mchoudha Bug#3537100 22-APR-04
3795   --For Billing Report
3796   OPEN  subline_count(p_top_line_id);
3797   FETCH subline_count into l_subline_count;
3798   CLOSE subline_count;
3799   --End  mchoudha Bug#3537100
3800 
3801 
3802   OPEN  l_inv_item_csr(p_top_line_id,p_inv_organization_id);
3803   FETCH l_inv_item_csr into l_item_rec;
3804   CLOSE l_inv_item_csr;
3805 
3806   OPEN  l_usage_csr(p_top_line_id);
3807   FETCH l_usage_csr into l_usage_type, l_usage_period , l_prorate ,
3808         l_locked_price_list_id, l_locked_price_list_line_id;
3809   CLOSE l_usage_csr;
3810 
3811   l_processed_lines_tbl(l_pr_tbl_idx).record_type  := 'Usage' ;
3812   level_elements_tab.delete;
3813 
3814   OKS_BILL_UTIL_PUB.get_next_level_element(
3815         P_API_VERSION        => l_api_version,
3816         P_ID                 => p_top_line_id,
3817         P_COVD_FLAG          => 'N',     ---- flag to indicate Top line
3818         P_DATE               => p_date,
3819         P_INIT_MSG_LIST      => l_init_msg_list,
3820         X_RETURN_STATUS      => l_return_status,
3821         X_MSG_COUNT          => l_msg_count,
3822         X_MSG_DATA           => l_msg_data,
3823         X_NEXT_LEVEL_ELEMENT => level_elements_tab );
3824 
3825   IF (l_return_status <> 'S')  THEN
3826     oks_bill_rec_pub.get_message(
3827                 l_msg_cnt  => l_msg_count,
3828                 l_msg_data => l_msg_data);
3829     l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
3830     l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3831 
3832     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in getting next level ');
3833 
3834     /*Needs to determine or revisited */
3835     --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
3836     Raise USAGE_EXCEPTION;
3837    END IF;
3838 
3839    IF (level_elements_tab.count < 1)  THEN
3840      l_processed_lines_tbl.DELETE(l_pr_tbl_idx) ;
3841    END IF;
3842 
3843    e_ptr := 1;
3844    no_of_cycles := level_elements_tab.count;
3845    l_tsub_id := l_prs_tbl_idx;
3846 
3847    WHILE (e_ptr <= no_of_cycles)
3848    LOOP
3849      l_line_total      := l_line_total + level_elements_tab(e_ptr).bill_amount ;
3850 
3851      l_inv_date        := level_elements_tab(e_ptr).date_to_interface;
3852      l_ar_inv_date     := level_elements_tab(e_ptr).date_transaction;
3853      l_bill_start_date := level_elements_tab(e_ptr).bill_from_date;
3854      l_bill_end_date   := level_elements_tab(e_ptr).bill_to_date;
3855      -------------------------------------------------------------------------
3856      -- Begin partial period computation logic
3857      -- Developer Mani Choudhary
3858      -- Date 11-JUN-2005
3859      -- get the rul_id for oks_level_elements
3860      -------------------------------------------------------------------------
3861      IF p_period_type IS NOT NULL AND
3862         p_period_start IS NOT NULL
3863      THEN
3864        l_rule_id         := level_elements_tab(e_ptr).rule_id;
3865        OPEN l_billing_uom_csr(l_rule_id);
3866        FETCH l_billing_uom_csr INTO l_uom_code;
3867        CLOSE l_billing_uom_csr;
3868      END IF;
3869      --------------------------------------------------------------------------
3870      /* Date_billed_to of top line should be manipulated if
3871         termination_date lies between start_date and end_date
3872         of billing period
3873      */
3874 
3875      IF ( ( p_top_line_term_date  >= l_bill_start_date) AND
3876           ( p_top_line_term_date <= l_bill_end_date)  ) THEN
3877        l_bill_end_date := p_top_line_term_date - 1 ;
3878      END IF;
3879 
3880      If l_write_log then
3881         FND_FILE.PUT_LINE( FND_FILE.LOG,'Line Interface Date :' ||l_inv_date );
3882         FND_FILE.PUT_LINE( FND_FILE.LOG,'Billing Period Start_date: ' || l_bill_start_date||' To '||l_bill_end_date);
3883      End If;
3884 
3885      l_ptr       := 0;
3886      l_total     := 0;
3887      l_final_qty := 0;
3888 
3889      l_cov_tbl.delete;
3890 
3891      IF (trunc(l_inv_date) <= trunc(p_date)) THEN
3892 
3893 /*******
3894      create bank account is no longer needed as part of R12 Bank account
3895     consolidation project
3896 
3897        OKS_BILL_REC_PUB.create_bank_Account(
3898                     p_dnz_chr_id      => p_dnz_chr_id,
3899                     p_bill_start_date => p_top_line_start_date,
3900                     p_currency_code   => p_currency_code,
3901                     x_status          => l_return_status,
3902                     l_msg_count       => l_msg_count,
3903                     l_msg_data        => l_msg_data
3904                     );
3905 
3906        IF (l_return_status <> 'S') THEN
3907          OKS_BILL_REC_PUB.get_message
3908                    (l_msg_cnt  => l_msg_count,
3909                     l_msg_data => l_msg_data);
3910          l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N';
3911          l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3912 
3913          FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in creating account');
3914 
3915 
3916 
3917          --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION') ;
3918          Raise USAGE_EXCEPTION;
3919        END IF;
3920 
3921 *******/
3922 
3923        FOR l_covlvl_rec in l_subline_csr(p_top_line_id)
3924        LOOP
3925 
3926          IF ( ((l_covlvl_rec.date_terminated is not null) and
3927                 (l_covlvl_rec.date_terminated > l_bill_start_date)) --l_inv_date))
3928                 OR
3929                 (l_covlvl_rec.date_terminated is  null))THEN
3930            IF  ((l_ar_inv_date is not null)
3931                  And (trunc(l_ar_inv_date) < trunc(sysdate)))  THEN
3932              l_ar_inv_date := sysdate;
3933            END IF;
3934 
3935               /*FOR BILLING REPORT*/
3936               l_subline_id := l_covlvl_rec.id;
3937 
3938            OKS_BILL_REC_PUB.Insert_bcl
3939                (P_CALLEDFROM        => l_called_from,
3940                 X_RETURN_STAT       => l_return_status,
3941                 P_CLE_ID            => p_top_line_id,
3942                 P_DATE_BILLED_FROM  => l_bill_start_date,
3943                 P_DATE_BILLED_TO    => l_bill_end_date,
3944                 P_DATE_NEXT_INVOICE => l_ar_inv_date,
3945                 P_BILL_ACTION       => 'RI',
3946                 P_OKL_FLAG          => p_okl_flag,
3947                 P_PRV               => p_prv,
3948                 P_MSG_COUNT         => l_msg_count,
3949                 P_MSG_DATA          => l_msg_data,
3950                 X_BCL_ID            => l_bcl_id);
3951 
3952            IF (l_return_status <> 'S')  THEN
3953              oks_bill_rec_pub.get_message
3954                    (l_msg_cnt  => l_msg_count,
3955                     l_msg_data => l_msg_data);
3956              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
3957              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3958              FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in insert bcl');
3959 
3960              --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
3961              Raise USAGE_EXCEPTION;
3962            END IF;
3963 
3964            IF (p_prv <> 2) THEN
3965              UPDATE oks_level_elements
3966              SET date_completed = l_bill_end_date
3967              WHERE id =  level_elements_tab(e_ptr).id;
3968            END IF;
3969 
3970            l_ptr := l_ptr + 1;
3971            level_coverage.delete;
3972 
3973            OKS_BILL_UTIL_PUB.get_next_level_element(
3974                P_API_VERSION        => l_api_version,
3975                P_ID                 => l_covlvl_rec.id,
3976                P_COVD_FLAG          => 'Y', -- flag to indicate Covered level
3977                P_DATE               => l_inv_date ,      --l_bill_end_date,
3978                P_INIT_MSG_LIST      => l_init_msg_list,
3979                X_RETURN_STATUS      => l_return_status,
3980                X_MSG_COUNT          => l_msg_count,
3981                X_MSG_DATA           => l_msg_data,
3982                X_NEXT_LEVEL_ELEMENT => level_coverage );
3983 
3984            IF ((l_return_status <> 'S')
3985                    OR (level_coverage.count = 0)) THEN
3986              OKS_BILL_REC_PUB.get_message
3987                  (l_msg_cnt  => l_msg_count,
3988                   l_msg_data => l_msg_data);
3989              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
3990              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3991              l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN := 'N' ;
3992              l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
3993              FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in get next level of coverage ');
3994              --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
3995              Raise USAGE_EXCEPTION;
3996            END IF;
3997 
3998            /*Update date completed in coverage line */
3999            IF (P_PRV <> 2) THEN
4000              UPDATE oks_level_elements
4001              SET date_completed = l_bill_end_date
4002              WHERE id = level_coverage(1).id;
4003            END IF;
4004 
4005            l_amount                := nvl(level_coverage(1).bill_amount,0);
4006            l_calc_rec.l_calc_sdate := level_coverage(1).bill_from_date;
4007            l_calc_rec.l_calc_edate := level_coverage(1).bill_to_date;
4008 
4009            IF (l_write_log) THEN
4010              FND_FILE.PUT_LINE( FND_FILE.LOG,' Coverage amount    : '||l_amount);
4011              FND_FILE.PUT_LINE( FND_FILE.LOG,' Coverage start_date: '||l_calc_rec.l_calc_sdate);
4012              FND_FILE.PUT_LINE( FND_FILE.LOG,' Coverage end_date  : '||l_calc_rec.l_calc_edate);
4013            END IF;
4014 
4015            IF (  l_covlvl_rec.date_terminated is not null)  AND
4016                ( trunc(l_calc_rec.l_calc_edate) >=
4017                               trunc(l_covlvl_rec.date_terminated)) THEN
4018              l_calc_rec.l_calc_edate := l_covlvl_rec.date_terminated - 1;
4019            END IF;
4020 
4021            l_cov_tbl(l_ptr).flag              := Null;
4022            l_cov_tbl(l_ptr).id                := l_covlvl_rec.id ;
4023            l_cov_tbl(l_ptr).bcl_id            := l_bcl_id;
4024            l_cov_tbl(l_ptr).date_billed_from  := l_calc_rec.l_calc_sdate;
4025            l_cov_tbl(l_ptr).date_billed_to    := l_calc_rec.l_calc_edate;
4026 
4027            IF (p_prv = 2) THEN  -- FIX for BUG# 2998682
4028              l_cov_tbl(l_ptr).date_billed_from
4029                                := level_elements_tab(e_ptr).bill_from_date;
4030              l_cov_tbl(l_ptr).date_billed_to
4031                                := level_elements_tab(e_ptr).bill_to_date;
4032 
4033              ----for bug 4455174
4034              l_calc_rec.l_calc_sdate :=level_elements_tab(e_ptr).bill_from_date;
4035              l_calc_rec.l_calc_edate :=level_elements_tab(e_ptr).bill_to_date;
4036 
4037 	     --23-DEC-2005 mchoudha  Fix for bug#4915367
4038              --fetching amount in case of negotiated usage type
4039              IF l_usage_type = 'NPR' THEN
4040                Open bill_amount_npr(l_covlvl_rec.id,l_covlvl_rec.dnz_chr_id,l_cov_tbl(l_ptr).date_billed_from,
4041 	                             l_cov_tbl(l_ptr).date_billed_to);
4042                Fetch bill_amount_npr into l_amount;
4043                Close bill_amount_npr;
4044              END IF;
4045 
4046            END IF;
4047 
4048            l_cov_tbl(l_ptr).amount            := 0;
4049            l_cov_tbl(l_ptr).average           := 0;
4050            l_cov_tbl(l_ptr).unit_of_measure   := p_uom_code;
4051            l_cov_tbl(l_ptr).fixed             := 0;
4052            l_cov_tbl(l_ptr).actual            := null;
4053            l_cov_tbl(l_ptr).default_default   := 0;
4054            l_cov_tbl(l_ptr).amcv_yn      := NVL(l_covlvl_rec.amcv_flag,'N');
4055            l_cov_tbl(l_ptr).adjustment_level  := 0 ;
4056            l_cov_tbl(l_ptr).adjustment_minimum:= 0 ;
4057            l_cov_tbl(l_ptr).result            := 1 ;--0 ; --check it out
4058            l_cov_tbl(l_ptr).x_stat            := Null ;
4059            l_cov_tbl(l_ptr).amount            := l_amount;
4060            l_cov_tbl(l_ptr).bcl_amount        :=nvl(l_calc_rec.l_bcl_amount,0);
4061            l_cov_tbl(l_ptr).date_to_interface := sysdate;
4062 
4063            IF  (l_usage_type = 'NPR') THEN
4064              IF (l_write_log) THEN
4065                FND_FILE.PUT_LINE( FND_FILE.LOG, 'USAGE_TYPE of subline = NPR' );
4066              END IF;
4067 
4068              OPEN  qty_uom_csr_sub(l_covlvl_rec.id);
4069              FETCH qty_uom_csr_sub into l_qty_uom_sub_rec;
4070              CLOSE qty_uom_csr_sub;
4071 
4072              l_cov_tbl(l_ptr).result             := 0; --l_qty_uom_sub_rec.number_of_items;
4073              l_cov_tbl(l_ptr).actual             := 0;
4074              l_cov_tbl(l_ptr).estimated_quantity := 0;
4075              l_cov_tbl(l_ptr).x_stat             := null;
4076              l_cov_tbl(l_ptr).unit_of_measure    := l_qty_uom_sub_rec.uom_code;
4077              l_cov_tbl(l_ptr).amount             := l_amount;
4078 
4079 
4080            ELSIF (l_usage_type = 'FRT')  THEN
4081              IF (l_write_log) THEN
4082                FND_FILE.PUT_LINE( FND_FILE.LOG, 'USAGE_TYPE of subline = FRT');
4083              END IF;
4084 
4085              l_qty := l_covlvl_rec.fixed_qty;
4086 
4087              IF (nvl(l_qty,0) <> 0) THEN
4088                -------------------------------------------------------------------------
4089                -- Begin partial period computation logic
4090                -- Developer Mani Choudhary
4091                -- Date 11-JUN-2005
4092                -- call oks_bill_rec_pub.Get_prorated_Usage_Qty to get the prorated usage
4093                -------------------------------------------------------------------------
4094                IF p_period_type IS NOT NULL AND
4095                   p_period_start IS NOT NULL
4096                THEN
4097 
4098                  l_qty := OKS_BILL_REC_PUB.Get_Prorated_Usage_Qty
4099                        (
4100                        p_start_date  => l_calc_rec.l_calc_sdate,
4101                        p_end_date    => l_calc_rec.l_calc_edate,
4102                        p_qty         => l_qty,
4103                        p_usage_uom   => l_usage_period,
4104                        p_billing_uom => l_uom_code,
4105                        p_period_type => p_period_type
4106                        );
4107                  IF (Nvl(l_qty,0) = 0)  THEN
4108                    l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN := 'N' ;
4109                    l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero ';
4110                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
4111                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero';
4112                    FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error Get_Prorated_Usage_Qty returns l_qty as '||l_qty);
4113 
4114                   --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4115                    Raise USAGE_EXCEPTION;
4116                  END IF;
4117 		 /* Commented for Bug#15897052 */
4118                  --l_qty := Round(l_qty,0);
4119                ELSE
4120                  --Existing logic
4121                  l_temp := OKS_TIME_MEASURES_PUB.GET_TARGET_QTY
4122                             (p_start_date  => l_calc_rec.l_calc_sdate,
4123                              p_source_qty  => 1,
4124                              p_source_uom  => l_usage_period,
4125                              p_target_uom  => p_time_uom_code,
4126                              p_round_dec   => 0
4127                              );
4128 
4129                  IF (Nvl(l_temp,0) = 0)  THEN
4130                    l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN := 'N' ;
4131                    l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero ';
4132                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
4133                    l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Target Quantity is zero';
4134                    FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error Get_target_qty returns Zero');
4135 
4136                   --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4137                    Raise USAGE_EXCEPTION;
4138                  END IF;
4139                  /* Modifed for Bug#15897052 */
4140                  l_qty := ((l_qty * (l_calc_rec.l_calc_edate -
4141                                 l_calc_rec.l_calc_sdate + 1))/l_temp) ;
4142 
4143                END IF; --p_period_type IS NOT NULL
4144              END IF;   --IF (nvl(l_qty,0) <> 0)
4145              l_cov_tbl(l_ptr).unit_of_measure    := p_uom_code;
4146              l_cov_tbl(l_ptr).fixed              := l_qty;
4147              l_cov_tbl(l_ptr).result             := l_qty;
4148              l_cov_tbl(l_ptr).actual             := 0;
4149              l_cov_tbl(l_ptr).estimated_quantity := 0;
4150              l_cov_tbl(l_ptr).sign               := 1;
4151              l_cov_tbl(l_ptr).average            := l_qty;
4152              l_cov_tbl(l_ptr).unit_of_measure    :=l_item_rec.primary_uom_code;
4153 
4154            ELSIF (l_usage_type in ('VRT','QTY')) THEN
4155              -------------------------------------------------------------------------
4156              -- Begin partial period computation logic
4157              -- Developer Mani Choudhary
4158              -- Date 11-JUN-2005
4159              -- Added additional period_type, period start parameters
4160              -------------------------------------------------------------------------
4161              OKS_BILL_REC_PUB.Usage_qty_to_bill
4162                 (
4163                 P_calledfrom            => p_prv, --1 for normal ,2 for preview,
4164                 P_cle_id                => l_covlvl_rec.id,
4165                 P_Usage_type            => l_usage_type,
4166                 P_estimation_flag       => l_covlvl_rec.usage_est_yn,
4167                 P_estimation_method     => l_covlvl_rec.usage_est_method,
4168                 p_default_qty           => l_covlvl_rec.Default_qty,
4169                 P_cov_start_date        => l_covlvl_rec.start_date,
4170                 P_cov_end_date          => l_covlvl_rec.end_date,
4171                 P_cov_prd_start_date    => l_calc_rec.l_calc_sdate,
4172                 P_cov_prd_end_date      => l_calc_rec.l_calc_edate,
4173                 p_usage_period          => l_usage_period,
4174                 p_time_uom_code         => p_time_uom_code,
4175                 p_settle_interval       => p_settlement_interval,
4176                 p_minimum_quantity      => l_covlvl_rec.minimum_qty,
4177                 p_usg_est_start_date    => l_covlvl_rec.usage_est_start_date,
4178                 p_period_type           => p_period_type, --period type
4179                 p_period_start          => p_period_start, --period start
4180                 X_qty                   => l_qty,
4181                 X_Uom_Code              => l_counter_uom_code,
4182                 X_flag                  => l_flag,
4183                 X_end_reading           => l_final_value,
4184                 X_start_reading         => l_init_value,
4185                 X_base_reading          => l_base_reading,
4186                 X_estimated_qty         => l_estimated_qty,
4187                 X_actual_qty            => l_actual_qty,
4188                 X_counter_value_id      => l_counter_value_id,
4189                 X_counter_group_id      => l_counter_grp_id,
4190                 X_return_status         => l_return_status
4191                   );
4192 
4193 
4194              IF (l_return_status <> 'S') THEN
4195                oks_bill_rec_pub.get_message
4196                        (l_msg_cnt  => l_msg_count,
4197                         l_msg_data => l_msg_data);
4198                l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN := 'N' ;
4199                l_processed_lines_tbl(l_pr_tbl_idx).Error_Message:= 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4200                l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN := 'N' ;
4201                l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message:= 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4202 
4203                Raise USAGE_EXCEPTION;
4204              END IF;
4205 
4206 
4207             IF (l_write_log) THEN
4208                FND_FILE.PUT_LINE( FND_FILE.LOG, 'After counter values X_value'||' '||l_qty);
4209             END IF;
4210 
4211             l_cov_tbl(l_ptr).result             :=nvl(l_qty, 0);
4212             l_cov_tbl(l_ptr).actual             :=l_actual_qty ;
4213             l_cov_tbl(l_ptr).unit_of_measure    :=l_item_rec.primary_uom_code;
4214             l_cov_tbl(l_ptr).start_reading      :=l_init_value;
4215             l_cov_tbl(l_ptr).end_reading        :=l_final_value;
4216             l_cov_tbl(l_ptr).base_reading       :=l_base_reading;
4217             l_cov_tbl(l_ptr).ccr_id             :=l_counter_value_id;
4218             l_cov_tbl(l_ptr).cgr_id             :=l_counter_grp_id;
4219             l_cov_tbl(l_ptr).flag               :=l_flag;
4220             l_cov_tbl(l_ptr).estimated_quantity :=l_estimated_qty;
4221 
4222 /******
4223      code changes for R12 project IB Counters Uptake.
4224      The below code is to lock the counter for Actual Per Period and Actual By Qty
4225 *****/
4226 
4227           if p_prv = 1 Then
4228             IF nvl(l_actual_qty,0) > 0 Then   ---- reading captured for the billed period
4229                 open get_counter_qty(l_covlvl_rec.id,l_final_value);
4230 	        fetch get_counter_qty into l_lock_date, l_counter_id;
4231 	        close get_counter_qty;
4232 
4233                IF (l_write_log) THEN
4234                    FND_FILE.PUT_LINE( FND_FILE.LOG, 'Cll IB Lock '||l_lock_date||', Counter id '||l_counter_id);
4235                END IF;
4236 
4237                l_counter_reading_lock_rec.reading_lock_date := l_lock_date;
4238                l_counter_reading_lock_rec.counter_id := l_counter_id;
4239                l_counter_reading_lock_rec.source_line_ref_id := l_covlvl_rec.id;
4240                l_counter_reading_lock_rec.source_line_ref := 'CONTRACT_LINE';
4241 
4242                Csi_Counter_Pub.create_reading_lock
4243                (
4244                     p_api_version          => 1.0,
4245                     p_commit               => 'F',
4246                     p_init_msg_list        => 'T',
4247                     p_validation_level     => 100,
4248                     p_ctr_reading_lock_rec => l_counter_reading_lock_rec,
4249                     x_return_status       => l_return_status,
4250                     x_msg_count           => l_msg_count,
4251                     x_msg_data            => l_msg_data,
4252                     x_reading_lock_id     => l_lock_id
4253 		);
4254 
4255             End If; --- for actual qty check
4256           End if;
4257 
4258 
4259          END IF;  -- l_usage_type = NPR
4260 
4261          IF (l_covlvl_rec.level_yn = 'Y') THEN
4262              l_final_qty := nvl(l_final_qty,0) + nvl(l_qty,0);
4263              l_total := nvl(l_total,0) + 1;
4264            END IF;
4265 
4266            l_cov_tbl(l_ptr).average := nvl(l_qty, 0);
4267 
4268          END IF;
4269          l_tsub_id := l_tsub_id +1;
4270        END LOOP;  --Covered level for loop
4271 
4272        IF (l_cov_tbl.count > 0) THEN
4273          IF (l_usage_type in ('VRT','QTY')) THEN
4274            IF (( nvl(l_total,0) <> 0) and (nvl(l_final_qty,0) <> 0) ) THEN
4275              l_level_qty := Round(l_final_qty/l_total);
4276            END IF;
4277 
4278            -------------------------------------------------------------------------
4279            -- Begin partial period computation logic
4280            -- Developer Mani Choudhary
4281            -- Date 12-JUN-2005
4282            -- Added two parameters p_period_start and p_period_type
4283            -------------------------------------------------------------------------
4284            level
4285              (
4286               P_LEVEL_QTY     => l_level_qty,
4287               P_COV_TBL       => l_cov_tbl,
4288               P_QTY           => l_qty,
4289               --P_LINE_TBL      => l_line_tbl,
4290               P_USAGE_PERIOD  => l_usage_period,
4291               P_TIME_UOM_CODE => p_time_uom_code,
4292               P_UOM_CODE      => l_uom_code,
4293               P_PERIOD_TYPE   => P_PERIOD_TYPE,
4294               P_PERIOD_START  => P_PERIOD_START,
4295               X_RETURN_STATUS => l_return_status
4296               );
4297 
4298            IF (l_write_log) THEN
4299               FND_FILE.PUT_LINE( FND_FILE.LOG, 'Level '||'  '||l_return_status);
4300            END IF;
4301 
4302            IF (l_return_status <> 'S') THEN
4303              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
4304              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message:= 'Error: '|| sqlerrm||'. Error Message:' ;
4305 
4306              FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error in LEVEL ') ;
4307              --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4308              Raise USAGE_EXCEPTION;
4309            END IF;
4310          END IF; -- l_usage_type in 'VRT','QTY'
4311 
4312          p_ar_feeder_ctr := 1;
4313          l_sign := l_cov_tbl(l_ptr).sign;
4314 
4315          OKS_BILL_REC_PUB.Insert_all_subline
4316            (
4317             P_CALLEDFROM     => l_called_from,
4318             X_RETURN_STAT    => l_return_status,
4319             P_COVERED_TBL    => l_cov_tbl,
4320             P_CURRENCY_CODE  => p_currency_code,
4321             P_DNZ_CHR_ID     => p_dnz_chr_id,
4322             P_PRV            => p_prv,
4323             P_MSG_COUNT      => l_msg_count,
4324             P_MSG_DATA       => l_msg_data
4325             );
4326 
4327          IF (l_usage_type <> 'NPR') THEN
4328             l_sub_id := l_prs_tbl_idx;
4329 
4330             FOR bsl_price_rec in bsl_price_csr(l_bcl_id,p_prv)
4331             LOOP
4332               l_price_break_details.delete;
4333 
4334               l_line_rec.line_id          := p_top_line_id;
4335               l_line_rec.intent           := 'USG';
4336               l_line_rec.usage_qty        := bsl_price_rec.average; -- qty
4337               l_line_rec.usage_uom_code   := bsl_price_rec.uom_code;
4338               l_line_rec.bsl_id           := bsl_price_rec.bsl_id;
4339               l_line_rec.subline_id       := bsl_price_rec.cle_id;
4340 
4341               IF ( nvl(bsl_price_rec.prorate,l_prorate) = 'ALL') THEN
4342                 l_line_rec.bill_from_date := bsl_price_rec.date_billed_from;
4343                 l_line_rec.bill_to_date   := bsl_price_rec.date_billed_to;
4344 
4345 
4346                 OKS_TIME_MEASURES_PUB.get_duration_uom
4347                    ( P_START_DATE    => bsl_price_rec.date_billed_from,
4348                      P_END_DATE      => bsl_price_rec.date_billed_to,
4349                      X_DURATION      => l_quantity_ordered,
4350                      X_TIMEUNIT      => l_break_uom_code,
4351                      X_RETURN_STATUS => l_return_status
4352                    );
4353 
4354                 l_line_rec.break_uom_code   := l_break_uom_code;
4355 
4356               ELSE
4357                 l_line_rec.bill_from_date := '';
4358                 l_line_rec.bill_to_date   := '';
4359 		--mchoudha bug#4128070 22-JAN-2005
4360                 l_line_rec.break_uom_code   := NULL;
4361               END IF;
4362 
4363 
4364               l_line_rec.price_list
4365                :=nvl(bsl_price_rec.LOCKED_PRICE_LIST_ID,l_locked_price_list_id);
4366               l_line_rec.price_list_line_id
4367                :=nvl(bsl_price_rec.locked_price_list_line_id,l_locked_price_list_line_id);
4368 
4369 /*Ceredian ER 13105205 */
4370 If (l_line_rec.usage_qty <>0 OR ( l_line_rec.usage_qty=0 AND nvl(FND_PROFILE.VALUE('OKS_USAGE_SKIP_QP_CALL_ZERO_QTY'),'N') = 'N')) THEN
4371               /*Pricing API to calculate amount */
4372               OKS_QP_PKG.CALC_PRICE
4373                 (
4374                  P_DETAIL_REC          => l_line_rec,
4375                  X_PRICE_DETAILS       => l_price_rec,
4376                  X_MODIFIER_DETAILS    => l_modifier_details,
4377                  X_PRICE_BREAK_DETAILS => l_price_break_details,
4378                  X_RETURN_STATUS       => l_return_status,
4379                  X_MSG_COUNT           => l_msg_count,
4380                  X_MSG_DATA            => l_msg_data
4381                 );
4382 
4383 
4384               IF (l_write_log) THEN
4385                 FND_FILE.PUT_LINE( FND_FILE.LOG, 'Price Calculated:  '||l_price_rec.PROD_EXT_AMOUNT);
4386               END IF;
4387 
4388      /*FOR BILLING REPORT*/
4389                  l_exception_amount := l_price_rec.PROD_EXT_AMOUNT;
4390 
4391 
4392 /*Added for bug 9927490*/
4393  IF (l_return_status = 'S') THEN
4394     IF l_price_rec.status_code = 'OKS_DUPLICATE_PRICE_LIST_LINES' THEN
4395            l_status_text := l_price_rec.status_text;
4396               FND_FILE.PUT_LINE( FND_FILE.LOG, 'Price Breaks are not available. Following message is returned by Pricing Engine'||'  '||l_status_text);
4397               Raise USAGE_EXCEPTION;
4398 
4399     END IF;
4400 ELSE
4401         oks_bill_rec_pub.get_message
4402                    (l_msg_cnt  => l_msg_count,
4403                     l_msg_data => l_msg_data);
4404 
4405                 FND_FILE.PUT_LINE( FND_FILE.LOG, 'Calculate Price Error'||'  '||l_return_status);
4406 
4407                 Raise USAGE_EXCEPTION;
4408 
4409          --OKC_FORMS_UTIL.Display_Errors(P_Stat => l_return_status);
4410          --RAISE FORM_TRIGGER_FAILURE;
4411 END IF;
4412    /*Added for bug 9927490*/
4413 
4414 
4415 l_price_rec.PROD_EXT_AMOUNT:=l_price_rec.PROD_EXT_AMOUNT*l_sign;
4416 
4417 else
4418 
4419 If l_write_log then --added by ansraj for bug 14016663
4420 FND_FILE.PUT_LINE( FND_FILE.LOG, 'Skipping the zero quantity line  for bsl_id '||bsl_price_rec.bsl_id);
4421 End If;
4422 
4423 l_exception_amount := 0;
4424 l_price_rec.PROD_EXT_AMOUNT:=0;
4425 
4426 end if; -- Ceredian Bug ER
4427 
4428 
4429 
4430               OKS_BILL_REC_PUB.update_bsl
4431                   (
4432                    X_RET_STAT     => l_return_status,
4433                    P_DNZ_CHR_ID   => p_dnz_chr_id,
4434                    P_BSL_ID       => bsl_price_rec.bsl_id,
4435                    P_BCL_ID       => l_bcl_id,
4436                    P_AMOUNT       => l_price_rec.PROD_EXT_AMOUNT,
4437                    P_CURRENCY_CODE=> p_currency_code,
4438                    P_PRV          => p_prv
4439                    );
4440 
4441               IF (l_return_status <> 'S') THEN
4442                 oks_bill_rec_pub.get_message
4443                    (l_msg_cnt  => l_msg_count,
4444                     l_msg_data => l_msg_data);
4445 
4446                 FND_FILE.PUT_LINE( FND_FILE.LOG, 'Error update bsl'||'  '||l_return_status);
4447                 --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4448                 Raise USAGE_EXCEPTION;
4449               END IF;
4450 
4451               l_break_amount := 0;
4452               /* Populate Price Break Record here and Insert Price Breaks
4453                  Details
4454               */
4455               --FOR i in l_price_break_details.first..l_price_break_details.last
4456               IF (l_price_break_details.COUNT)  > 0 THEN
4457                 i := l_price_break_details.FIRST;
4458                 LOOP
4459 
4460                   l_pbr_rec_in.bcl_id     := l_bcl_id;
4461                   l_pbr_rec_in.bsl_id     := bsl_price_rec.bsl_id;
4462                   l_pbr_rec_in.cle_id     := bsl_price_rec.cle_id;
4463                   l_pbr_rec_in.chr_id     := bsl_price_rec.dnz_chr_id;
4464                   l_pbr_rec_in.unit_price := l_price_break_details(i).unit_price;
4465                   l_pbr_rec_in.amount     := l_price_break_details(i).amount;
4466 
4467 
4468                   l_pbr_rec_in.amount  :=
4469                     OKS_EXTWAR_UTIL_PVT.round_currency_amt(l_price_break_details(i).amount, p_currency_code);
4470 
4471                   l_pbr_rec_in.quantity_from
4472                            := l_price_break_details(i).quantity_from;
4473                            --:= l_price_break_details(i).pricing_attr_value_from;
4474                   l_pbr_rec_in.quantity_to
4475                            := l_price_break_details(i).quantity_to;
4476                   l_pbr_rec_in.quantity
4477                            := l_price_break_details(i).quantity;
4478                   l_pbr_rec_in.prorate := nvl(bsl_price_rec.prorate,l_prorate);
4479                   --l_pbr_rec_in.lock_flag
4480                   --           := l_price_break_details(i).lock_flag;
4481                   --l_pbr_rec_in.locked_price_list_id
4482                   --           := l_price_break_details(i).locked_price_list_id;
4483                   --l_pbr_rec_in.locked_price_list_line_id
4484                   --          := l_price_break_details(i).locked_price_list_line_id;
4485                   --l_pbr_rec_in.price_list_id
4486                   --          := l_price_break_details(i).price_list_id;
4487                   --l_pbr_rec_in.price_list_line_id
4488                   --           := l_price_break_details(i).price_list_line_id;
4489 
4490 
4491                   l_break_amount := nvl(l_break_amount,0) + nvl(l_pbr_rec_in.amount,0) ;
4492 
4493                   IF ( nvl(l_pbr_rec_in.quantity,0)  > 0) THEN
4494                     OKS_PBR_PVT.insert_row(
4495                        P_API_VERSION       => 1,
4496                        P_INIT_MSG_LIST     => l_init_msg_list,
4497                        X_RETURN_STATUS     => l_return_status,
4498                        X_MSG_COUNT         => l_msg_count,
4499                        X_MSG_DATA          => l_msg_data,
4500                        P_PBRV_REC          => l_pbr_rec_in,
4501                        X_PBRV_REC          => l_pbr_rec_out) ;
4502 
4503                   END IF;
4504                   EXIT WHEN i = l_price_break_details.LAST;
4505                   i := l_price_break_details.NEXT(i);
4506                 END LOOP;
4507               END IF; --  l_price_break_details.COUNT > 0
4508 
4509           /*Modified for bug:9900133*/
4510             IF ((l_break_amount <> 0 ) and ( l_break_amount <> abs(l_price_rec.PROD_EXT_AMOUNT))) THEN
4511                 OKS_BILL_REC_PUB.prorate_price_breaks (
4512                        P_BSL_ID        =>      bsl_price_rec.bsl_id,
4513                        P_BREAK_AMOUNT  =>      l_break_amount,
4514                        P_TOT_AMOUNT    =>      l_price_rec.PROD_EXT_AMOUNT   ,
4515                        X_RETURN_STATUS =>      l_return_status) ;
4516               END IF;
4517 
4518 
4519               l_sub_id := l_sub_id + 1;
4520             END LOOP; --FOR bsl_price_rec in bsl_price_csr(l_bcl_id)
4521 
4522          END IF;   -- (l_usage_type <> 'NPR')
4523 
4524        END IF;
4525 
4526      END IF;  -- l_inv_date <= p_date
4527 
4528 
4529      e_ptr  :=  e_ptr  + 1;
4530      l_tsub_id := l_prs_tbl_idx;
4531 
4532    END LOOP;  --While eptr < no_of_cycles
4533 
4534 
4535 
4536 
4537 EXCEPTION
4538   WHEN USAGE_EXCEPTION THEN
4539   /*FOR BILLING REPORT*/
4540   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
4541   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_amount,0) + nvl(l_exception_amount,0) ;
4542   /*FOR ERROR REPORT*/
4543   p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
4544   p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
4545   p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 12;
4546   p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=  l_subline_id ;
4547   p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4548 
4549   p_return_status := 'E';
4550   WHEN OTHERS THEN
4551   /*FOR BILLING REPORT*/
4552   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
4553   p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_amount,0) + nvl(l_exception_amount,0) ;
4554   /*FOR ERROR REPORT*/
4555   p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
4556   p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
4557   p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 12;
4558   p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=  l_subline_id ;
4559   p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4560 
4561 
4562   p_return_status := 'E';
4563 END  Bill_usage_item;
4564 
4565 Procedure Bill_Service_Item (
4566                              p_dnz_chr_id              IN            NUMBER,
4567                              p_contract_number         IN            VARCHAR2,
4568                              p_con_num_modifier        IN            VARCHAR2,
4569                              p_line_number             IN            VARCHAR2,
4570                              p_lse_id                  IN            NUMBER,
4571                              p_inv_org_id              IN            NUMBER,
4572                              p_top_line_id             IN            NUMBER,
4573                              p_top_line_start_date     IN            DATE,
4574                              p_top_line_term_date      IN            DATE,
4575                              p_top_line_end_date       IN            DATE,
4576                              p_currency_code           IN            VARCHAR2,
4577                              p_object1_id1             IN            VARCHAR2,
4578                              p_object1_id2             IN            VARCHAR2,
4579                              p_okl_flag                IN            NUMBER,
4580                              p_prv                     IN            NUMBER,
4581                              p_date                    IN            DATE,
4582                              p_summary_yn              IN            VARCHAR2,
4583                              p_ar_feeder_ctr           IN OUT NOCOPY NUMBER,
4584                              p_billrep_tbl             IN OUT NOCOPY OKS_BILL_REC_PUB.bill_report_tbl_type,
4585                              p_billrep_tbl_idx         IN            NUMBER,
4586                              p_billrep_err_tbl         IN OUT NOCOPY OKS_BILL_REC_PUB.billrep_error_tbl_type,
4587                              p_billrep_err_tbl_idx     IN OUT NOCOPY NUMBER,
4588                              p_return_status           IN OUT NOCOPY VARCHAR2
4589                              )
4590 IS
4591 
4592 
4593 /* -- This cursor gives all the covered lines of service or usage lines */
4594 CURSOR l_subline_csr(p_cle_id  Number) Is
4595         SELECT sub_line.id                id
4596               ,sub_line.cle_id            cle_id
4597               ,sub_line.price_negotiated  price_negotiated
4598               ,sub_line.start_date        start_date
4599               ,sub_line.end_date          end_date
4600               ,sub_line.date_terminated   date_terminated
4601               ,sub_line.line_number       line_number /* Report */
4602         FROM   OKC_K_LINES_B sub_line
4603         WHERE  sub_line.cle_id = p_cle_id
4604         AND    sub_line.date_cancelled is NULL          -- [llc]
4605         AND    sub_line.lse_id in (8,7,9,10,11,13,25,35);
4606         /*AND    not  exists ( select 1 from okc_k_rel_objs rel
4607                              where rel.cle_id = sub_line.id );  Commented for 16039680*/
4608 
4609 Cursor qty_uom_csr(p_cle_id  Number) Is
4610     SELECT  okc.Number_of_items
4611             ,tl.Unit_of_measure uom_code
4612      FROM   okc_k_items okc
4613            ,mtl_units_of_measure_tl tl
4614      WHERE  okc.cle_id = p_cle_id
4615      AND    tl.uom_code = okc.uom_code
4616      AND    tl.language = USERENV('LANG');
4617 
4618     /*
4619      Select  Number_of_items
4620             ,OKX.Unit_of_measure uom_code
4621      From   OKC_K_ITEMS OKC
4622             ,OKX_UNITS_OF_MEASURE_V OKX
4623      Where  cle_id = P_cle_id
4624      And    Okx.uom_code = OKC.uom_code ;
4625      */
4626 
4627 /*FOR BILLING REPORT*/
4628 Cursor subline_count(p_cle_id  Number) Is
4629         SELECT count(sub_line.id)
4630         FROM   OKC_K_LINES_B sub_line
4631         WHERE  sub_line.cle_id = p_cle_id
4632         AND    sub_line.date_cancelled is NULL          -- [llc]
4633         AND    sub_line.lse_id in (8,7,9,10,11,13,25,35);
4634         /*AND    not  exists ( select 1 from okc_k_rel_objs rel
4635                              where rel.cle_id = sub_line.id ); Commented for 16039680 */
4636 /*FOR BILLING REPORT*/
4637 Cursor top_line_amount(p_cle_id NUMBER) Is
4638     Select sum(AMOUNT)
4639     FROM oks_level_elements
4640     where CLE_ID= p_cle_id
4641     AND DATE_TO_INTERFACE <= p_date
4642     AND DATE_COMPLETED IS NULL;
4643 
4644 
4645 
4646 l_ptr                    NUMBER;
4647 e_ptr                    NUMBER;
4648 no_of_cycles             NUMBER;
4649 l_sub_line_total         NUMBER;
4650 l_line_total             NUMBER;
4651 l_level_elements_count   NUMBER;
4652 l_amount                 NUMBER;
4653 l_bcl_id                 NUMBER;
4654 l_inv_date               DATE;
4655 l_ar_inv_date            DATE;
4656 
4657 l_summary_yn             VARCHAR2(1);
4658 l_subline_count          NUMBER := 0;
4659 l_subline_id             NUMBER;
4660 l_errep_amount           NUMBER;
4661 
4662 /* Variable for calling std API*/
4663 l_api_version      CONSTANT NUMBER      := 1.0;
4664 l_called_from      CONSTANT NUMBER      := 1;
4665 l_init_msg_list    CONSTANT VARCHAR2(1) := 'F';
4666 l_msg_count                 NUMBER;
4667 l_msg_data                  VARCHAR2(2000);
4668 l_return_status             VARCHAR2(1);
4669 qty_uom_rec                 QTY_UOM_CSR%rowtype;
4670 
4671 service_exception           EXCEPTION;
4672 sub_service_exception       EXCEPTION;
4673 BEGIN
4674   IF (l_write_log) THEN
4675      FND_FILE.PUT_LINE(FND_FILE.LOG,'***Processing Service/Ext Warranty Item Starts***');
4676      FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Top Line Id:  ' || p_top_line_id);
4677      FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Top Line Start Date: ' || p_top_line_start_date);
4678      FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Top Line Termination Date/End date: ' || nvl(p_top_line_term_date,p_top_line_end_date));
4679   END IF;
4680 
4681   p_return_status        := 'S';
4682   l_level_elements_count := 0;
4683   l_line_total           := 0;
4684 
4685   --Start mchoudha Bug#3537100 17-APR-04
4686   --For Billing Report
4687   OPEN  subline_count(p_top_line_id);
4688   FETCH subline_count into l_subline_count;
4689   CLOSE subline_count;
4690 
4691   IF (p_summary_yn = 'Y') THEN
4692     l_summary_yn := 'Y';
4693   ELSE
4694     IF ( FND_PROFILE.VALUE('OKS_AR_TRANSACTIONS_SUBMIT_SUMMARY_YN') = 'YES') THEN
4695       l_summary_yn := 'Y';
4696     ELSE
4697       l_summary_yn := 'N';
4698     END IF;
4699   END IF;
4700 
4701   --End mchoudha Bug#3537100
4702   IF (l_write_log) THEN
4703     FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Going to process all sublines for top line '||p_top_line_id);
4704   END IF;
4705 
4706   FOR l_covlvl_rec in l_subline_csr(p_top_line_id )
4707   LOOP
4708   BEGIN
4709 
4710     /*FOR BILLING REPORT*/
4711     l_subline_id := l_covlvl_rec.id;
4712     IF (l_write_log)  THEN
4713        FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => inside FOR l_covlvl_rec Processing Coverage Id: '||l_covlvl_rec.id);
4714     END IF;
4715 
4716     level_elements_tab.delete;
4717 
4718     OKS_BILL_UTIL_PUB.get_next_level_element(
4719         P_API_VERSION        => l_api_version,
4720         P_ID                 => l_covlvl_rec.id,
4721         P_COVD_FLAG          => 'Y',     ---- flag to indicate covered level
4722         P_DATE               => p_date,
4723         P_INIT_MSG_LIST      => l_init_msg_list,
4724         X_RETURN_STATUS      => l_return_status,
4725         X_MSG_COUNT          => l_msg_count,
4726         X_MSG_DATA           => l_msg_data,
4727         X_NEXT_LEVEL_ELEMENT => level_elements_tab );
4728 
4729     IF (l_write_log) THEN
4730        FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => After calling OKS_BILL_UTIL_PUB.get_next_level_element l_return_status '||l_return_status);
4731     END IF;
4732 
4733     IF (l_return_status <> 'S') THEN
4734       oks_bill_rec_pub.get_message
4735           (l_msg_cnt  => l_msg_count,
4736            l_msg_data  => l_msg_data);
4737 
4738       l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
4739       l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4740       l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
4741       l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4742 
4743       FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item =>   Failed in Creation of get_next_level_element  For coverage Id: '||l_covlvl_rec.id );
4744       FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item =>  Rolling Back the Whole Service With Top Line ID: '||p_top_line_id );
4745 
4746       --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4747 
4748       RAISE sub_service_exception;
4749     END IF;
4750 
4751     IF (level_elements_tab.count < 1)  THEN
4752       l_processed_sub_lines_tbl.DELETE(l_prs_tbl_idx) ;
4753     END IF;
4754 
4755     e_ptr := 1;
4756     no_of_cycles := level_elements_tab.count;
4757 
4758     l_sub_line_total := 0;
4759 
4760     l_level_elements_count := l_level_elements_count + level_elements_tab.count;
4761 
4762     IF (l_write_log)  THEN
4763       FND_FILE.PUT_LINE(FND_FILE.LOG,'No of Period for coverage: ' || no_of_cycles);
4764     END IF;
4765 
4766     OPEN  qty_uom_csr(l_covlvl_rec.id);
4767     FETCH qty_uom_csr into qty_uom_rec;
4768     CLOSE qty_uom_csr;
4769 
4770     IF (l_write_log) THEN
4771       FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Going inside  WHILE (e_ptr <= no_of_cycles) ');
4772     END IF;
4773 
4774     WHILE (e_ptr <= no_of_cycles)
4775     LOOP
4776 
4777       l_cov_tbl.delete;
4778       l_sub_line_total        :=nvl(l_sub_line_total,0)
4779                                     + level_elements_tab(e_ptr).bill_amount ;
4780       l_line_total            := nvl(l_line_total,0) +
4781                                     + level_elements_tab(e_ptr).bill_amount ;
4782       l_inv_date              := level_elements_tab(e_ptr).date_to_interface;
4783       l_ar_inv_date           := level_elements_tab(e_ptr).date_transaction;
4784       l_amount                := level_elements_tab(e_ptr).bill_amount;
4785       l_calc_rec.l_calc_sdate := level_elements_tab(e_ptr).bill_from_date ;
4786       l_calc_rec.l_calc_edate := level_elements_tab(e_ptr).bill_to_date;
4787 
4788       IF (  l_covlvl_rec.date_terminated is not null)  AND
4789          ( trunc(l_calc_rec.l_calc_edate) >=
4790                                    trunc(l_covlvl_rec.date_terminated)) THEN
4791         l_calc_rec.l_calc_edate := l_covlvl_rec.date_terminated - 1;
4792       END IF;
4793 
4794       IF (l_write_log)  THEN
4795         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Coverage Interface Date: '||l_inv_date);
4796         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Coverage Amount        : ' || l_amount);
4797         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Coverage Start Date    : '||l_calc_rec.l_calc_sdate);
4798         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => Coverage End Date      : '||l_calc_rec.l_calc_edate);
4799       END IF;
4800 
4801       IF (trunc(l_inv_date)  <= trunc(p_date)) THEN
4802 
4803         IF ((l_ar_inv_date is not null) And
4804             (l_ar_inv_date < sysdate))  THEN
4805           l_ar_inv_date := sysdate;
4806         END IF;
4807 
4808         IF (l_write_log)  THEN
4809           FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => l_ar_inv_date '||l_ar_inv_date);
4810         END IF;
4811 
4812         l_ptr :=  1;
4813 
4814 /*******
4815      create bank account is no longer needed as part of R12 Bank account
4816     consolidation project
4817 
4818         OKS_BILL_REC_PUB.create_bank_Account(
4819              P_DNZ_CHR_ID      => p_dnz_chr_id,
4820              P_BILL_START_DATE => p_top_line_start_date,
4821              P_CURRENCY_CODE   => p_currency_code,
4822              X_STATUS          => l_return_status,
4823              L_MSG_COUNT       => l_msg_count,
4824              L_MSG_DATA        => l_msg_data
4825              );
4826 
4827         IF (l_write_log) THEN
4828           FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => After calling OKS_BILL_REC_PUB.create_bank_Account l_return_status '||l_return_status);
4829         END IF;
4830 
4831         IF (l_return_status <> 'S') THEN
4832           oks_bill_rec_pub.get_message
4833                 (l_msg_cnt  => l_msg_count,
4834                  l_msg_data  => l_msg_data);
4835 
4836           l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
4837           l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4838           l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
4839           l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4840 
4841           FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item =>   Failed in Creation of bank account For coverage Id: '||l_covlvl_rec.id );
4842           FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item =>  Rolling Back the Whole Service With Top Line ID: '||p_top_line_id );
4843 
4844           --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4845 
4846           RAISE sub_service_exception;
4847         END IF;
4848 *****/
4849 
4850         OKS_BILL_REC_PUB.Insert_bcl
4851              (
4852               P_CALLEDFROM        => l_called_from,
4853               X_RETURN_STAT       => l_return_status,
4854               P_CLE_ID            => p_top_line_id,
4855               P_DATE_BILLED_FROM  => l_calc_rec.l_calc_sdate,
4856               P_DATE_BILLED_TO    => l_calc_rec.l_calc_edate,
4857               P_DATE_NEXT_INVOICE => l_ar_inv_date,
4858               P_BILL_ACTION       => 'RI',
4859               P_OKL_FLAG          => p_okl_flag,
4860               P_PRV               => p_prv,
4861               P_MSG_COUNT         => l_msg_count,
4862               P_MSG_DATA          => l_msg_data,
4863               X_BCL_ID            => l_bcl_id
4864              );
4865 
4866         IF (l_write_log)  THEN
4867           FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => After calling OKS_BILL_REC_PUB.Insert_bcl l_return_status '||l_return_status);
4868         END IF;
4869 
4870         IF (l_return_status <> 'S') THEN
4871           oks_bill_rec_pub.get_message(
4872                l_msg_cnt  => l_msg_count,
4873                l_msg_data  => l_msg_data);
4874           l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
4875           l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4876           l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
4877           l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4878 
4879           FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item => Failed in Insert BCL For coverage Id: ' ||l_covlvl_rec.id );
4880           FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item => Rolling Back the Whole Service With Top Line ID: '||p_top_line_id );
4881 
4882           RAISE sub_service_exception;
4883         END IF;
4884 
4885         IF (p_prv <> 2) THEN
4886 
4887           UPDATE oks_level_elements
4888           SET date_Completed = l_calc_rec.l_calc_edate
4889           WHERE  id = level_elements_tab(e_ptr).id;
4890 
4891         END IF;
4892 
4893         l_cov_tbl(l_ptr).id                 := l_covlvl_rec.id;
4894         l_cov_tbl(l_ptr).bcl_id             := l_bcl_id;
4895         l_cov_tbl(l_ptr).date_billed_from   := l_calc_rec.l_calc_sdate;
4896         l_cov_tbl(l_ptr).date_billed_to     := l_calc_rec.l_calc_edate;
4897         l_cov_tbl(l_ptr).average            := 0;
4898         l_cov_tbl(l_ptr).unit_of_measure    := qty_uom_rec.uom_code;
4899         l_cov_tbl(l_ptr).fixed              := 0 ;
4900         l_cov_tbl(l_ptr).actual             := null;
4901         l_cov_tbl(l_ptr).default_default    := 0;
4902         l_cov_tbl(l_ptr).amcv_yn            := 'N';
4903         l_cov_tbl(l_ptr).adjustment_level   := 0 ;
4904         l_cov_tbl(l_ptr).result             := qty_uom_rec.number_of_items ;
4905         l_cov_tbl(l_ptr).x_stat             := null;
4906         l_cov_tbl(l_ptr).amount             := l_amount;
4907         l_cov_tbl(l_ptr).bcl_amount         := nvl(l_calc_rec.l_bcl_amount,0);
4908         l_cov_tbl(l_ptr).date_to_interface  := sysdate;
4909 
4910       END IF; -- (trunc(l_inv_date)  <= trunc(p_date))
4911 
4912       IF ( l_write_log) THEN
4913         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => l_cov_tbl.count '||l_cov_tbl.count);
4914       END IF;
4915 
4916       IF (l_cov_tbl.count > 0) THEN
4917         p_ar_feeder_ctr := 1;
4918         OKS_BILL_REC_PUB.Insert_all_subline
4919              (
4920               P_CALLEDFROM     => l_called_from,
4921               X_RETURN_STAT    => l_return_status,
4922               P_COVERED_TBL    => l_cov_tbl,
4923               P_CURRENCY_CODE  => p_currency_code,
4924               P_DNZ_CHR_ID     => p_dnz_chr_id,
4925               P_PRV            => p_prv,
4926               P_MSG_COUNT      => l_msg_count,
4927               P_MSG_DATA       => l_msg_data
4928               );
4929 
4930       END IF;
4931 
4932       IF (l_write_log) THEN
4933         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => After calling OKS_BILL_REC_PUB.Insert_all_subline l_return_status '||l_return_status);
4934       END IF;
4935 
4936       IF (l_return_status <> 'S')  THEN
4937         oks_bill_rec_pub.get_message(
4938                l_msg_cnt  => l_msg_count,
4939                l_msg_data => l_msg_data);
4940         l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
4941         l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4942         l_processed_sub_lines_tbl(l_prs_tbl_idx).Billed_YN     := 'N' ;
4943         l_processed_sub_lines_tbl(l_prs_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4944 
4945         FND_FILE.PUT_LINE( FND_FILE.LOG, 'Bill_Service_Item => Insert into sublines table failed Contract line id :'||p_top_line_id);
4946         FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item =>  Rolling Back the Whole Service With Top Line ID: '||p_top_line_id );
4947         --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
4948         RAISE sub_service_exception;
4949       END IF;
4950 
4951       /* Following code is to update the date_completed field of top line  */
4952 
4953       IF (p_prv <> 2) THEN
4954         UPDATE oks_level_elements
4955         SET date_completed = l_calc_rec.l_calc_edate
4956         WHERE cle_id = p_top_line_id
4957         AND   date_completed is null
4958         AND   date_start <= l_calc_rec.l_calc_sdate;
4959       END IF;
4960 
4961       IF (l_write_log) THEN
4962         FND_FILE.PUT_LINE(FND_FILE.LOG,'Bill_Service_Item => After updating oks_level_elements ');
4963       END IF;
4964 
4965       e_ptr := e_ptr + 1;
4966 
4967     END LOOP; -- While eptr loop
4968 
4969     l_processed_sub_lines_tbl(l_prs_tbl_idx).Bill_Amount  := l_sub_line_total;
4970 
4971 
4972 
4973 
4974   EXCEPTION
4975     WHEN sub_service_exception THEN
4976       p_return_status := 'E';
4977 
4978       /* FOR BILLING REPORT */
4979       Open top_line_amount(p_top_line_id);
4980       Fetch top_line_amount into l_errep_amount;
4981       Close top_line_amount;
4982       IF (l_summary_yn = 'N') THEN
4983         p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
4984         p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value
4985                                                                                                        + nvl(l_errep_amount,0);
4986 
4987         /*FOR ERROR REPORT*/
4988         p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
4989         p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
4990         p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 1;
4991         p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=l_subline_id ;
4992         p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
4993 
4994 
4995       ELSE
4996         /*FOR ERROR REPORT*/
4997         p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines + 1;
4998         p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value
4999                                                                                                        + nvl(l_errep_amount,0);
5000 
5001         p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
5002         p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
5003         p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 1;
5004         p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=NULL;
5005        p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5006 
5007       END IF;
5008 
5009       FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item => Failed- sub_service_exception exception raised for coverage:  '||l_covlvl_rec.id||' With Error: '||sqlerrm );
5010       EXIT;
5011     WHEN OTHERS THEN
5012       --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5013       /* FOR BILLING REPORT */
5014       Open top_line_amount(p_top_line_id);
5015       Fetch top_line_amount into l_errep_amount;
5016       Close top_line_amount;
5017       IF (l_summary_yn = 'N') THEN
5018         p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines + l_subline_count;
5019         p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_SubLines_Value + nvl(l_errep_amount,0);
5020 
5021         /*FOR ERROR REPORT*/
5022         p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
5023         p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
5024         p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 1;
5025         p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=l_subline_id ;
5026         p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5027 
5028 
5029       ELSE
5030         /*FOR ERROR REPORT*/
5031         p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
5032         p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
5033         p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 1;
5034         p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id :=NULL;
5035         p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5036 
5037       END IF;
5038       p_return_status := 'E';
5039       FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item => Failed- when others  exception raised for coverage '||l_covlvl_rec.id||' With Error: '||sqlerrm );
5040       EXIT;
5041   END;
5042   END LOOP;  -- FOR loop for covered level
5043 
5044   --l_processed_lines_tbl(l_pr_tbl_idx).Bill_Amount       := l_line_total ;
5045 
5046   /* FOR BILLING REPORT */
5047  -- IF (l_summary_yn = 'Y' AND p_return_status <> 'E') THEN
5048  --   p_billrep_tbl(p_billrep_tbl_idx).Successful_Lines := p_billrep_tbl(p_billrep_tbl_idx).Successful_Lines + 1;
5049  --   p_billrep_tbl(p_billrep_tbl_idx).Successful_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Successful_Lines_Value + nvl(l_line_total,0);
5050  -- END IF;
5051 
5052   IF (l_summary_yn = 'Y' AND p_return_status = 'E') THEN
5053     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines + 1;
5054     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value + nvl(l_line_total,0);
5055   END IF;
5056 
5057 
5058 
5059   /* ** Delete the record from billing report table if no subline is billed***/
5060 
5061   IF (l_level_elements_count <= 0)  THEN
5062     l_processed_lines_tbl.DELETE(l_pr_tbl_idx) ;
5063   END IF;
5064 
5065   IF (l_write_log) THEN
5066     FND_FILE.PUT_LINE(FND_FILE.LOG,'***Processing Service/Ext Warranty Item Ends ***');
5067   END IF;
5068 
5069 
5070 EXCEPTION
5071  WHEN SERVICE_EXCEPTION THEN
5072    p_return_status := 'E';
5073   /* FOR BILLING REPORT */
5074   IF (l_summary_yn = 'Y') THEN
5075     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines + 1;
5076     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value + nvl(l_line_total,0);
5077   END IF;
5078   FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item => Failed- when SERVICE_EXCEPTION  exception raised '||sqlerrm );
5079  WHEN OTHERS THEN
5080    p_return_status := 'E';
5081   /* FOR BILLING REPORT */
5082   IF (l_summary_yn = 'Y') THEN
5083     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines + 1;
5084     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value + nvl(l_line_total,0);
5085   END IF;
5086   FND_FILE.PUT_LINE( FND_FILE.LOG,'Bill_Service_Item => Failed-outside  when OTHERS  exception raised '||sqlerrm );
5087 END Bill_Service_Item;
5088 
5089 
5090 Procedure Bill_Subscription_item(
5091                      p_dnz_chr_id          IN            NUMBER,
5092                      p_top_line_id         IN            NUMBER,
5093                      p_top_line_start_date IN            DATE,
5094                      p_top_line_term_date  IN            DATE,
5095                      p_top_line_end_date   IN            DATE,
5096                      p_currency_code       IN            VARCHAR2,
5097                      p_okl_flag            IN            NUMBER,
5098                      p_nos_of_items        IN            NUMBER,
5099                      p_uom_code            IN            VARCHAR2,
5100                      p_prv                 IN            NUMBER,
5101                      p_date                IN            DATE,
5102                      p_billrep_tbl         IN OUT NOCOPY OKS_BILL_REC_PUB.bill_report_tbl_type,
5103                      p_billrep_tbl_idx     IN            NUMBER,
5104                                  p_billrep_err_tbl     IN OUT NOCOPY OKS_BILL_REC_PUB.billrep_error_tbl_type,
5105                                  p_billrep_err_tbl_idx IN OUT NOCOPY NUMBER,
5106                      p_ar_feeder_ctr       IN OUT NOCOPY NUMBER,
5107                                  p_return_status       IN OUT NOCOPY VARCHAR2)
5108 IS
5109 l_ptr                       NUMBER    := 0;
5110 e_ptr                       NUMBER;
5111 no_of_elements              NUMBER;
5112 l_amount                    NUMBER;
5113 l_bcl_id                    NUMBER;
5114 l_line_total                NUMBER;
5115 l_inv_date                  DATE;
5116 l_ar_inv_date               DATE;
5117 l_bill_start_date           DATE;
5118 l_bill_end_date             DATE;
5119 
5120 
5121 /* Variable for calling std API*/
5122 l_api_version      CONSTANT NUMBER      := 1.0;
5123 l_called_from      CONSTANT NUMBER      := 1;
5124 l_init_msg_list    CONSTANT VARCHAR2(1) := 'F';
5125 l_msg_count                 NUMBER;
5126 l_msg_data                  VARCHAR2(2000);
5127 l_return_status             VARCHAR2(1);
5128 
5129 /*Exception Definition */
5130 SUBSRIPTION_EXCEPTION       EXCEPTION;
5131 
5132 BEGIN
5133   p_return_status  :=  'S';
5134   level_elements_tab.delete;
5135 
5136   IF (l_write_log) THEN
5137     FND_FILE.PUT_LINE(FND_FILE.LOG,'***Processing Subscription Item ***');
5138     FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Id:  ' || p_top_line_id);
5139     FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Start Date: ' || p_top_line_start_date);
5140     FND_FILE.PUT_LINE(FND_FILE.LOG,' Top Line Termination Date/End date: ' || nvl(p_top_line_term_date,p_top_line_end_date));
5141   END IF;
5142 
5143   oks_bill_util_pub.get_next_level_element(
5144            p_api_version        => l_api_version,
5145            p_id                 => p_top_line_id,
5146            p_covd_flag          => 'N',     ---- flag to indicate Top line
5147            p_date               => p_date,
5148            p_init_msg_list      => l_init_msg_list,
5149            x_return_status      => l_return_status,
5150            x_msg_count          => l_msg_count,
5151            x_msg_data           => l_msg_data,
5152            x_next_level_element => level_elements_tab );
5153 
5154   IF (l_return_status <> 'S') Then
5155     oks_bill_rec_pub.get_message(
5156                l_msg_cnt  => l_msg_count,
5157                l_msg_data => l_msg_data);
5158     l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
5159     l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '||
5160 sqlerrm||'. Error Message: '||l_msg_data ;
5161 
5162     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in getting next level ');
5163 
5164     Raise SUBSRIPTION_EXCEPTION;
5165   END IF;
5166 
5167   e_ptr           := 1;
5168   no_of_elements  := level_elements_tab.count;
5169   l_line_total    := 0;
5170 
5171   WHILE (e_ptr <= no_of_elements)
5172   LOOP
5173     l_inv_date          := level_elements_tab(e_ptr).date_to_interface;
5174     l_ar_inv_date       := level_elements_tab(e_ptr).date_transaction;
5175     l_amount            := level_elements_tab(e_ptr).bill_amount;
5176     l_bill_start_date   := level_elements_tab(e_ptr).bill_from_date;
5177     l_bill_end_date     := level_elements_tab(e_ptr).bill_to_date;
5178     l_line_total        := l_line_total+level_elements_tab(e_ptr).bill_amount;
5179 
5180     l_ptr := 1;
5181     l_cov_tbl.delete;
5182 
5183 
5184     IF (trunc(l_inv_date)  <= trunc(p_date)) THEN
5185       IF ((l_ar_inv_date is not null) AND
5186             (l_ar_inv_date < sysdate))  THEN
5187         l_ar_inv_date := sysdate;
5188       END IF;
5189 
5190 /*******
5191      create bank account is no longer needed as part of R12 Bank account
5192     consolidation project
5193 
5194       OKS_BILL_REC_PUB.create_bank_Account(
5195              P_DNZ_CHR_ID      => p_dnz_chr_id,
5196              P_BILL_START_DATE => p_top_line_start_date,
5197              P_CURRENCY_CODE   => p_currency_code,
5198              X_STATUS          => l_return_status,
5199              L_MSG_COUNT       => l_msg_count,
5200              L_MSG_DATA        => l_msg_data
5201              );
5202 
5203       IF (l_return_status <> 'S') THEN
5204         oks_bill_rec_pub.get_message(
5205                    l_msg_cnt  => l_msg_count,
5206                    l_msg_data => l_msg_data);
5207         l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
5208         l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5209 
5210         --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5211         FND_FILE.PUT_LINE( FND_FILE.LOG,' Failed in Creation of bank account');
5212         FND_FILE.PUT_LINE( FND_FILE.LOG,' Rolling Back the Whole Service '||p_top_line_id );
5213 
5214         RAISE SUBSRIPTION_EXCEPTION;
5215       END IF;
5216 ***/
5217 
5218        /*This procedure insert the into bill_con_lines,
5219          if the record is not already present for the same period.
5220          Since the out table returns the row_id of the inserted row, get_bcl_id
5221          which was present in earliar version is now  removed*/
5222       OKS_BILL_REC_PUB.Insert_bcl
5223              (
5224              P_CALLEDFROM        => l_called_from,
5225              X_RETURN_STAT       => l_return_status,
5226              P_CLE_ID            => p_top_line_id,
5227              P_DATE_BILLED_FROM  => l_bill_start_date,
5228              P_DATE_BILLED_TO    => l_bill_end_date,
5229              P_DATE_NEXT_INVOICE => l_ar_inv_date,
5230              P_BILL_ACTION       => 'RI',
5231              P_OKL_FLAG          => p_okl_flag,
5232              P_PRV               => p_prv,
5233              P_MSG_COUNT         => l_msg_count,
5234              P_MSG_DATA          => l_msg_data,
5235              X_BCL_ID            => l_bcl_id
5236              );
5237 
5238        IF (l_return_status <> 'S')  THEN
5239          oks_bill_rec_pub.get_message(
5240                    l_msg_cnt  => l_msg_count,
5241                    l_msg_data => l_msg_data);
5242          l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
5243          l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5244 
5245          FND_FILE.PUT_LINE( FND_FILE.LOG, 'Failed in insert bcl ');
5246          Raise SUBSRIPTION_EXCEPTION;
5247        END IF;
5248 
5249        IF (p_prv <> 2)  THEN
5250 
5251          UPDATE oks_level_elements
5252           SET date_completed = l_bill_end_date
5253           WHERE id = level_elements_tab(e_ptr).id;
5254 
5255        END IF;
5256 
5257        l_cov_tbl(l_ptr).flag               := Null;
5258        l_cov_tbl(l_ptr).id                 := p_top_line_id ;
5259        l_cov_tbl(l_ptr).bcl_id             := l_bcl_id;
5260        l_cov_tbl(l_ptr).date_billed_from   := l_bill_start_date;
5261        l_cov_tbl(l_ptr).date_billed_to     := l_bill_end_date;
5262        l_cov_tbl(l_ptr).amount             := l_amount;
5263        l_cov_tbl(l_ptr).average            := 0;
5264        l_cov_tbl(l_ptr).unit_of_measure    := p_uom_code;
5265        l_cov_tbl(l_ptr).fixed              := 0;
5266        l_cov_tbl(l_ptr).actual             := null;
5267        l_cov_tbl(l_ptr).default_default    := 0;
5268        l_cov_tbl(l_ptr).amcv_yn            := 'N';
5269        l_cov_tbl(l_ptr).adjustment_level   := 0 ;
5270        l_cov_tbl(l_ptr).adjustment_minimum := 0 ;
5271        l_cov_tbl(l_ptr).result             := 1 ;
5272        l_cov_tbl(l_ptr).x_stat             := Null ;
5273        l_cov_tbl(l_ptr).bcl_amount         := 0;--nvl(l_calc_rec.l_bcl_amount,0);
5274        l_cov_tbl(l_ptr).date_to_interface  := sysdate;
5275 
5276        IF (l_cov_tbl.count > 0) THEN
5277           /* check if this is to be passed back to main api */
5278          p_ar_feeder_ctr := 1;
5279          OKS_BILL_REC_PUB.Insert_all_subline
5280                 (
5281                 P_CALLEDFROM     => l_called_from,
5282                 X_RETURN_STAT    => l_return_status,
5283                 P_COVERED_TBL    => l_cov_tbl,
5284                 P_CURRENCY_CODE  => p_currency_code,
5285                 P_DNZ_CHR_ID     => p_dnz_chr_id,
5286                 P_PRV            => p_prv,
5287                 P_MSG_COUNT      => l_msg_count,
5288                 P_MSG_DATA       => l_msg_data
5289                 );
5290 
5291          IF (l_write_log) THEN
5292            FND_FILE.PUT_LINE( FND_FILE.LOG, 'Status after insert into sublines '||l_return_status );
5293          END IF;
5294 
5295          IF (l_return_status <> 'S') THEN
5296            oks_bill_rec_pub.get_message(
5297                    l_msg_cnt  => l_msg_count,
5298                    l_msg_data => l_msg_data);
5299            l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N ' ;
5300            l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5301            FND_FILE.PUT_LINE( FND_FILE.LOG, 'Insert into sublines table failed  Contract line id : '||p_top_line_id);
5302            --DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION ');
5303            Raise SUBSRIPTION_EXCEPTION;
5304          END IF;
5305 
5306        END IF; -- l_cov_tbl.count > 0
5307      END IF;  -- l_inv_date <= p_date
5308      e_ptr := e_ptr + 1 ;
5309 
5310   END LOOP;
5311 
5312 
5313 
5314 EXCEPTION
5315  WHEN SUBSRIPTION_EXCEPTION THEN
5316    /*FOR BILLING REPORT*/
5317     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines + 1;
5318     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value + nvl(l_line_total,0);
5319     /*FOR ERROR REPORT*/
5320     p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
5321     p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
5322     p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 46;
5323     p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id := NULL;
5324     p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5325     p_return_status := 'E';
5326  WHEN OTHERS THEN
5327     /*FOR BILLING REPORT*/
5328     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines + 1;
5329     p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value := p_billrep_tbl(p_billrep_tbl_idx).Rejected_Lines_Value + nvl(l_line_total,0);
5330     /*FOR ERROR REPORT*/
5331     p_billrep_err_tbl_idx := p_billrep_err_tbl_idx + 1;
5332     p_billrep_err_tbl(p_billrep_err_tbl_idx).Top_Line_id := p_top_line_id;
5333     p_billrep_err_tbl(p_billrep_err_tbl_idx).Lse_Id := 46;
5334     p_billrep_err_tbl(p_billrep_err_tbl_idx).Sub_line_id := NULL;
5335     p_billrep_err_tbl(p_billrep_err_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5336    p_return_status := 'E';
5337 END Bill_Subscription_item;
5338 
5339 
5340 
5341  Procedure Calculate_bill
5342  (
5343   ERRBUF                     OUT  NOCOPY VARCHAR2
5344  ,RETCODE                    OUT  NOCOPY NUMBER
5345  ,P_calledfrom                IN         NUMBER
5346  ,P_flag                      IN         NUMBER
5347  ,P_date                      IN         DATE
5348  ,P_process_from              IN         NUMBER
5349  ,P_process_to                IN         NUMBER
5350  ,P_Prv                       IN         NUMBER
5351  )
5352 
5353 
5354  Is
5355  Cursor billing_process (p_line_from     IN     NUMBER,
5356                          p_line_to       IN     NUMBER) IS
5357  SELECT chr_id,cle_id,line_no
5358    FROM oks_process_billing
5359    WHERE line_no between p_line_from and p_line_to;
5360 
5361  -------------------------------------------------------------------------
5362  -- Begin partial period computation logic
5363  -- Developer Mani Choudhary
5364  -- Date 11-JUN-2005
5365  -- Added period_start,period_type and price_uom in the select clause
5366  -- This is done to avoid calling oks_renew_util_pub.get_period_defaults
5367  -- so avoind hitting the database once more
5368  -------------------------------------------------------------------------
5369  Cursor l_bill_line_csr(p_hdr_id  IN NUMBER,
5370                         p_line_id IN NUMBER) IS
5371         SELECT line.id
5372               ,Hdr.Contract_number
5373               ,Hdr.Contract_number_modifier
5374               ,Hdr.Currency_code
5375               ,Hdr.Inv_organization_id
5376               ,Hdr.authoring_org_id
5377               ,Hdr.org_id
5378               ,line.dnz_chr_id
5379               ,line.cle_id
5380               ,line.lse_id
5381               ,line.start_date
5382               ,line.end_date
5383               ,line.price_negotiated
5384               ,line.date_terminated
5385               ,okp.object1_id1
5386               ,okp.object1_id2
5387               ,line.line_number
5388               ,rul.ar_interface_yn
5389               ,rul.period_start
5390               ,rul.period_type
5391               ,rul.price_uom
5392               ,nvl(rul.summary_trx_yn,'N') summary_yn
5393               ,rline.settlement_interval
5394        FROM
5395                OKC_K_PARTY_ROLES_B  okp
5396               ,OKC_K_LINES_B  line
5397               ,OKS_K_LINES_B  rline
5398               ,OKC_K_HEADERS_B Hdr
5399               ,OKS_K_HEADERS_B rul
5400         WHERE  Hdr.id          = p_hdr_id
5401         AND    line.id         = p_line_id
5402         AND    rline.cle_id    = line.id
5403         AND    rul.chr_id      = Hdr.id
5404         AND    line.dnz_chr_id = Hdr.id
5405         AND    line.lse_id in (1,12,19,46)
5406         AND    okp.dnz_chr_id  =  hdr.id
5407         AND    okp.rle_code    in ( 'CUSTOMER','SUBSCRIBER');
5408 
5409 
5410 
5411  Cursor l_inv_item_csr(p_cle_id Number,p_org_id Number) Is
5412      SELECT item.Object1_id1
5413         ,mtl.usage_item_flag
5414         ,mtl.service_item_flag
5415         ,mtl.primary_uom_code
5416   FROM   Okc_K_items Item
5417         ,mtl_system_items_b   mtl  --Okx_system_items_v mtl
5418   WHERE  item.cle_id = p_cle_id
5419   --AND    mtl.id1 = item.object1_id1
5420   AND    mtl.inventory_item_id = item.object1_id1
5421   AND    mtl.organization_id = p_org_id;
5422 
5423 Cursor qty_uom_csr(p_cle_id  Number) Is
5424      SELECT  okc.Number_of_items
5425             ,tl.Unit_of_measure uom_code
5426      FROM   okc_k_items okc
5427            ,mtl_units_of_measure_tl tl
5428      WHERE  okc.cle_id = p_cle_id
5429      AND    tl.uom_code = okc.uom_code
5430      AND    tl.language = USERENV('LANG');
5431 
5432      /*
5433      SELECT  Number_of_items
5434             ,OKX.Unit_of_measure uom_code
5435      FROM   OKC_K_ITEMS OKC
5436             ,OKX_UNITS_OF_MEASURE_V OKX
5437      WHERE  cle_id = P_cle_id
5438      AND    Okx.uom_code = OKC.uom_code ;
5439      */
5440 
5441 Cursor l_uom_csr Is
5442       SELECT uom_code
5443       FROM   Okc_time_code_units_v
5444       WHERE  tce_code = 'DAY'
5445       AND    quantity = 1
5446       AND    active_flag = 'Y';
5447 
5448 
5449 Cursor l_okl_contract_csr(p_chr_id IN NUMBER) is
5450   SELECT 1 from okc_k_rel_objs
5451   WHERE  rty_code in ('OKLSRV','OKLUBB')
5452   AND    jtot_object1_code = 'OKL_SERVICE'
5453   AND    object1_id1 = to_char(p_chr_id);
5454 
5455 
5456 Cursor l_contract_update_date(p_chr_id IN NUMBER) is
5457   SELECT last_update_date from okc_k_headers_b
5458   WHERE id = p_chr_id;
5459 
5460 
5461 
5462 
5463  X_return_status    Varchar2(1); -- was a parameter until subrequest impl.
5464  l_cvmv_rec         OKC_CVM_PVT.cvmv_rec_type ;
5465  l_cvmv_out_rec     OKC_CVM_PVT.cvmv_rec_type ;
5466  l_chrv_rec         OKC_CONTRACT_PUB.chrv_rec_type;
5467  l_chrv_out_rec     OKC_CONTRACT_PUB.chrv_rec_type;
5468  qty_uom_rec        QTY_UOM_CSR%rowtype;
5469  l_bill_rec         L_BILL_LINE_CSR%rowtype;
5470  l_item_rec         L_INV_ITEM_CSR%rowtype;
5471 
5472  l_return_status               VARCHAR2(1);
5473  l_msg_count                   NUMBER;
5474  l_msg_data                    VARCHAR2(2000);
5475  l_okl_flag                    NUMBER := 0;
5476  l_msg_cnt                     NUMBER;
5477  l_api_version      CONSTANT   NUMBER      := 1.0;
5478  l_init_msg_list    CONSTANT   VARCHAR2(1) := 'F';
5479  l_uom_code                    VARCHAR2(25);
5480  l_select_counter              NUMBER   := 0;
5481  l_reject_counter              NUMBER   := 0;
5482  l_process_counter             NUMBER   := 0;
5483  l_ar_feeder_ctr               NUMBER   := 0;
5484  l_con_update_date             DATE  ;
5485 
5486  sub_line_exception            EXCEPTION ;
5487  Main_line_exception           EXCEPTION ;
5488 
5489 SUBTYPE l_bclv_tbl_type_in  is OKS_bcl_PVT.bclv_tbl_type;
5490 
5491  l_bclv_tbl_in   l_bclv_tbl_type_in;
5492  l_bclv_tbl_out   l_bclv_tbl_type_in;
5493 
5494 Type l_num_tbl is table of NUMBER index  by BINARY_INTEGER ;
5495 chr_id              l_num_tbl;
5496 cle_id              l_num_tbl;
5497 l_line_no           l_num_tbl;
5498 
5499   l_sign                     Number;
5500   l_line_total               Number := 0;
5501   l_level_elements_count     Number := 0;
5502   l_sub_line_total           Number := 0;
5503   l_sub_line_total_tmp       Number := 0;
5504   l_g_ptr                    Number := 0 ;
5505   l_g_tbl_count              Number := 0 ;
5506 
5507 
5508   --Start mchoudha Bug#3537100 17-APR-04
5509   --For Billing Report
5510 
5511   l_billrep_tbl            OKS_BILL_REC_PUB.bill_report_tbl_type;
5512   l_billrep_tbl_idx        NUMBER;
5513   l_billrep_found          BOOLEAN;
5514   j                        NUMBER;
5515   l_billrep_err_tbl        OKS_BILL_REC_PUB.billrep_error_tbl_type;
5516   l_billrep_errtbl_idx     NUMBER;
5517 
5518   --End mchoudha Bug#3537100
5519 
5520 --Bug#5378184
5521 l_err_code varchar2(10);
5522 
5523 --Ceredian ER
5524 l_bulk_usage VARCHAR2(10);
5525 
5526  BEGIN
5527 
5528    RETCODE := 0;
5529    X_return_status := 'S';
5530 
5531    --mchoudha Fix for bug#4198616
5532    --initializing the variables in case of parallel workers
5533    l_yes_no :=  Fnd_profile.value('OKS_BILLING_REPORT_AND_LOG');
5534    FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => OKS: Billing Report And Log is set to '||l_yes_no);
5535 
5536 --Ceredian ER
5537    l_bulk_usage := FND_PROFILE.VALUE('OKS_USAGE_BILL_QP_BULK_CALL');
5538 
5539    If l_write_log then
5540      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill processing starts ');
5541      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => OKS_USAGE_BILL_QP_BULK_CALL is set to '||l_bulk_usage);
5542    End If;
5543 
5544    If l_yes_no = 'YES' then
5545       l_write_log       := TRUE;
5546       l_write_report    := TRUE;
5547    Else
5548       l_write_log       := FALSE;
5549       l_write_report    := FALSE;
5550    End If;
5551 
5552 
5553    OPEN  l_uom_csr;
5554    FETCH l_uom_csr into l_uom_code;
5555    CLOSE l_uom_csr;
5556 
5557    IF l_uom_code Is Null Then
5558      FND_FILE.PUT_LINE( FND_FILE.LOG, 'Time Units Of measure not set for DAY');
5559      Raise G_EXCEPTION_HALT_VALIDATION;
5560    END IF;
5561 
5562    --/*Set The p_date which is used to control the program*/
5563    --p_date := nvl(P_Default_Date,sysdate);
5564 
5565    --Start by mchoudha Bug#3537100 17-APR-04
5566    --For Billing Report
5567    /*
5568    l_pr_tbl_idx      := 0 ;
5569    l_prs_tbl_idx     := 0 ;
5570    */
5571 
5572    l_billrep_tbl_idx    := -1 ;
5573    l_billrep_errtbl_idx := -1 ;
5574    --End mchoudha Bug#3537100
5575 
5576    If l_write_log then
5577      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => Opening billing_process cursor from '||p_process_from||' to '||p_process_to);
5578    End If;
5579 
5580 
5581 
5582 
5583    OPEN billing_process(p_process_from , p_process_to) ;
5584    LOOP
5585    FETCH billing_process bulk collect
5586                    INTO chr_id, cle_id,l_line_no LIMIT 10000;
5587 
5588      If l_write_log then
5589        FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After Fetch billing_process cursor count of line ids fetched '||cle_id.count);
5590      End If;
5591 
5592      IF cle_id.COUNT > 0 THEN          --chk for count
5593 
5594 
5595        FOR i in  cle_id.FIRST..cle_id.LAST
5596        LOOP
5597 
5598        BEGIN
5599 
5600          DBMS_TRANSACTION.SAVEPOINT('BEFORE_TRANSACTION');
5601 
5602             IF l_write_log THEN
5603            FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 opening cursor l_bill_line_csr line id '||cle_id(i)||' header ID '||chr_id(i)||' line number '||l_line_no(i));
5604          END IF;
5605 
5606          /*****
5607          The policy context is set to multiple for Bug# 6158988
5608          This is because context is set for a particular org
5609          down the code and need to reset it back
5610          *****/
5611          mo_global.set_policy_context('M', Null);
5612 
5613 
5614          OPEN  l_bill_line_csr (chr_id(i),cle_id(i));
5615          FETCH l_bill_line_csr into l_bill_rec  ;
5616          IF (l_bill_line_csr%notfound) THEN
5617            FND_FILE.PUT_LINE(FND_FILE.LOG,'not found l_bill_line_csr for line id '||cle_id(i)||' for contract id '||chr_id(i));
5618            CLOSE l_bill_line_csr;
5619            RAISE MAIN_LINE_EXCEPTION;
5620          END IF;
5621          CLOSE l_bill_line_csr;
5622 
5623 
5624          l_select_counter := l_select_counter + 1;
5625          l_ar_Feeder_ctr  := 0;
5626 
5627          IF l_write_log THEN
5628             FND_FILE.PUT_LINE(FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Contract# : '||l_bill_rec.Contract_number);
5629             FND_FILE.PUT_LINE(FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Modifier: '||l_bill_rec.Contract_number_modifier);
5630             FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Parameter Default Date ' || P_date);
5631             FND_FILE.PUT_LINE(FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Period Start# : '||l_bill_rec.period_start);
5632             FND_FILE.PUT_LINE(FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill =>  Period Type: '||l_bill_rec.period_type);
5633             FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Price_uom ' ||l_bill_rec.price_uom);
5634          END IF;
5635 
5636          -- Commented as part of R12. Authoring org id changed to org_id (MOAC)
5637          -- okc_context.set_okc_org_context(l_bill_Rec.authoring_org_id, Null);
5638          okc_context.set_okc_org_context(l_bill_Rec.org_id, Null);
5639 
5640             IF l_write_log THEN
5641            FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After setting okc_context.set_okc_org_context for org '||l_bill_Rec.org_id);
5642          END IF;
5643 
5644 
5645          l_okl_flag := 0; --- check for OKL contract
5646 
5647          OPEN  l_okl_contract_csr (l_bill_rec.dnz_chr_id);
5648          FETCH l_okl_contract_csr into l_okl_flag;
5649          CLOSE l_okl_contract_csr;
5650 
5651             If l_write_log then
5652            FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 opening cursor l_bill_line_csr l_okl_flag '||l_okl_flag);
5653          End If;
5654 
5655          /*Invoices are to be generated only for contracts whose
5656          AR_interface_flag = 'Y'
5657          */
5658             If l_write_log then
5659            FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => l_bill_rec.ar_interface_yn '||Nvl(l_bill_rec.ar_interface_yn,'Y'));
5660          End If;
5661 
5662          IF Nvl(l_bill_rec.ar_interface_yn,'Y') = 'Y'   THEN -- {
5663 
5664          --Start mchoudha Bug#3537100 17-APR-04
5665          --For Billing Report
5666 
5667          /* *** Insert the lines to a PL/SQL table   ** */
5668           -- l_pr_tbl_idx      := l_pr_tbl_idx + 1;
5669 
5670 
5671 
5672          If l_write_log then
5673              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 initializing Billing Report ');
5674            End If;
5675 
5676               l_billrep_found          := FALSE;
5677 
5678            IF (l_billrep_tbl.count > 0) THEN
5679              j := l_billrep_tbl.FIRST;
5680              LOOP
5681                   IF(l_billrep_tbl(j).Currency_code = l_bill_rec.Currency_code) THEN
5682                        l_billrep_found := TRUE;
5683                  l_billrep_tbl_idx := j;         --point to the index containing the currency code
5684                  EXIT;
5685                END IF;
5686                EXIT WHEN j = l_billrep_tbl.LAST;
5687                j := l_billrep_tbl.NEXT(j);
5688              END LOOP;
5689            END IF;
5690 
5691 
5692            IF (l_billrep_found = FALSE) THEN
5693           l_billrep_tbl_idx      := l_billrep_tbl_idx + 1;
5694              l_billrep_tbl(l_billrep_tbl_idx).Currency_code := l_bill_rec.Currency_code;
5695              l_billrep_tbl(l_billrep_tbl_idx).Successful_Lines := 0;
5696              l_billrep_tbl(l_billrep_tbl_idx).Rejected_Lines := 0;
5697              l_billrep_tbl(l_billrep_tbl_idx).Successful_SubLines := 0;
5698              l_billrep_tbl(l_billrep_tbl_idx).Rejected_SubLines := 0;
5699           l_billrep_tbl(l_billrep_tbl_idx).Successful_Lines_Value := 0;
5700           l_billrep_tbl(l_billrep_tbl_idx).Rejected_Lines_Value := 0;
5701              l_billrep_tbl(l_billrep_tbl_idx).Successful_SubLines_Value := 0;
5702              l_billrep_tbl(l_billrep_tbl_idx).Rejected_SubLines_Value := 0;
5703            END IF;
5704 
5705            If l_write_log then
5706              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After initializing Billing Report ');
5707            End If;
5708 
5709            --End mchoudha Bug#3537100
5710 
5711            OPEN  qty_uom_csr(l_bill_rec.id);
5712            FETCH qty_uom_csr into qty_uom_rec;
5713            CLOSE qty_uom_csr;
5714 
5715          If l_write_log then
5716              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => After opening qty_uom_csr uom_code '||qty_uom_rec.uom_code);
5717            End If;
5718 
5719 
5720            IF (l_bill_rec.lse_id = 46) THEN
5721       -----------------------------------------------------------------
5722            If l_write_log then
5723                FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 calling Bill_Subscription_item for '||l_bill_rec.id);
5724              End If;
5725 
5726              Bill_Subscription_item(
5727                                  l_bill_rec.dnz_chr_id,
5728                                  l_bill_rec.id,
5729                                  l_bill_rec.start_date,
5730                                  l_bill_rec.date_terminated,
5731                                  l_bill_rec.end_date,
5732                                  l_bill_rec.currency_code,
5733                                  l_okl_flag,
5734                                  qty_uom_rec.number_of_items,
5735                                  qty_uom_rec.uom_code,
5736                                  p_prv,
5737                                  p_date,
5738                                  l_billrep_tbl,
5739                                  l_billrep_tbl_idx,
5740                                              l_billrep_err_tbl,
5741                                              l_billrep_errtbl_idx,
5742                                  l_ar_feeder_ctr,
5743                                  l_return_status);
5744 
5745 
5746              IF (l_return_status <> 'S') THEN
5747                ---DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5748                RAISE MAIN_LINE_EXCEPTION;
5749              END IF;
5750       -----------------------------------------------------------------
5751            ELSIF (l_bill_rec.lse_id in (1,19)) Then
5752              --Process_service_items
5753       -----------------------------------------------------------------
5754              If l_write_log then
5755                FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 calling Bill_Service_item for '||l_bill_rec.id);
5756              End If;
5757 
5758              Bill_Service_item(
5759                             l_bill_rec.dnz_chr_id,
5760                             l_bill_rec.contract_number,
5761                             l_bill_rec.Contract_number_modifier   ,
5762                             l_bill_rec.line_number,
5763                             l_bill_rec.lse_id   ,
5764                             l_bill_rec.inv_organization_id,
5765                             l_bill_rec.id,
5766                             l_bill_rec.start_date,
5767                             l_bill_rec.date_terminated,
5768                             l_bill_rec.end_date,
5769                             l_bill_rec.currency_code,
5770                             l_bill_rec.object1_id1,
5771                             l_bill_rec.object1_id2,
5772                             l_okl_flag,
5773                             --qty_uom_rec.number_of_items,
5774                             --qty_uom_rec.uom_code,
5775                             p_prv,
5776                             p_date,
5777                             l_bill_rec.summary_yn,
5778                             l_ar_feeder_ctr,
5779                             l_billrep_tbl,
5780                             l_billrep_tbl_idx,
5781                             l_billrep_err_tbl,
5782                                      l_billrep_errtbl_idx,
5783                             l_return_status
5784                             );
5785 
5786              IF (l_return_status <> 'S') THEN
5787                ----DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5788                RAISE MAIN_LINE_EXCEPTION;
5789              END IF;
5790       -----------------------------------------------------------------
5791 
5792            ELSIF (l_bill_rec.lse_id = 12) THEN
5793 
5794            If Nvl(l_bulk_usage,'N') = 'Y'    THEN
5795 
5796              -- Process_usage_items
5797              If l_write_log then
5798                FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 calling Bill_Usage_Item_bulk for '||l_bill_rec.id);
5799              End If;
5800              -------------------------------------------------------------------------
5801              -- Begin partial period computation logic
5802              -- Developer Mani Choudhary
5803              -- Date 12-JUN-2005
5804              -- added period type and period start as two parameters
5805              -------------------------------------------------------------------------
5806              --Ceredian ER
5807              Bill_Usage_Item_bulk(
5808                         l_bill_rec.dnz_chr_id,
5809                         l_bill_rec.contract_number,
5810                         l_bill_rec.Contract_number_modifier  ,
5811                         l_bill_rec.line_number,
5812                         l_bill_rec.lse_id   ,
5813                         l_bill_rec.object1_id1,
5814                         l_bill_rec.object1_id2,
5815                         l_bill_rec.id,
5816                         l_bill_rec.start_date,
5817                         l_bill_rec.date_terminated,
5818                         l_bill_rec.end_date,
5819                         l_bill_rec.inv_organization_id,
5820                         l_bill_rec.currency_code,
5821                         l_bill_rec.settlement_interval,
5822                         qty_uom_rec.uom_code,
5823                         l_uom_code,
5824                         l_okl_flag,
5825                         p_prv,
5826                         p_date,
5827                         l_billrep_tbl,
5828                         l_billrep_tbl_idx,
5829                         l_billrep_err_tbl,
5830                         l_billrep_errtbl_idx,
5831                         l_ar_feeder_ctr,
5832                         l_bill_rec.period_type,
5833                         l_bill_rec.period_start,
5834                         l_return_status
5835                         );
5836 
5837             Else
5838 
5839                  -- Process_usage_items
5840              If l_write_log then
5841                FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 calling Bill_Usage_Item for '||l_bill_rec.id);
5842              End If;
5843              -------------------------------------------------------------------------
5844              -- Begin partial period computation logic
5845              -- Developer Mani Choudhary
5846              -- Date 12-JUN-2005
5847              -- added period type and period start as two parameters
5848              -------------------------------------------------------------------------
5849 
5850              Bill_Usage_Item(
5851                         l_bill_rec.dnz_chr_id,
5852                         l_bill_rec.contract_number,
5853                         l_bill_rec.Contract_number_modifier  ,
5854                         l_bill_rec.line_number,
5855                         l_bill_rec.lse_id   ,
5856                         l_bill_rec.object1_id1,
5857                         l_bill_rec.object1_id2,
5858                         l_bill_rec.id,
5859                         l_bill_rec.start_date,
5860                         l_bill_rec.date_terminated,
5861                         l_bill_rec.end_date,
5862                         l_bill_rec.inv_organization_id,
5863                         l_bill_rec.currency_code,
5864                         l_bill_rec.settlement_interval,
5865                         qty_uom_rec.uom_code,
5866                         l_uom_code,
5867                         l_okl_flag,
5868                         p_prv,
5869                         p_date,
5870                         l_billrep_tbl,
5871                         l_billrep_tbl_idx,
5872                         l_billrep_err_tbl,
5873                         l_billrep_errtbl_idx,
5874                         l_ar_feeder_ctr,
5875                         l_bill_rec.period_type,
5876                         l_bill_rec.period_start,
5877                         l_return_status
5878                         );
5879 
5880             End if; --l_bulk_usage
5881 
5882              IF (l_return_status <> 'S') THEN
5883                ----DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5884                RAISE MAIN_LINE_EXCEPTION;
5885              END IF;
5886 
5887         --------------------------------------------------------
5888            END IF; --lse_id if stmt
5889 
5890          END IF; -- }  end if for Bill Yes / No
5891 
5892     /* skuchima Ceredian ER Added condition to stop calling AR for usage lines*/
5893          IF ( (l_ar_feeder_ctr = 1 AND Nvl(l_bulk_usage,'N') = 'N') OR (l_ar_feeder_ctr =1 and l_bill_rec.lse_id <> 12 ) ) THEN
5894            If l_write_log then
5895              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => B4 calling OKS_ARFEEDER_PUB.Get_REC_FEEDER for '||l_bill_rec.id);
5896            End If;
5897 
5898            OKS_ARFEEDER_PUB.Get_REC_FEEDER
5899                         (
5900                          X_RETURN_STATUS            => l_return_status,
5901                          X_MSG_COUNT                => l_msg_cnt,
5902                          X_MSG_DATA                 => l_msg_data,
5903                          P_FLAG                     => p_flag,  -- checkout
5904                          P_CALLED_FROM              => p_calledfrom,
5905                          P_DATE                     => p_date,
5906                          P_CLE_ID                   => l_bill_Rec.id,
5907                          P_PRV                      => p_prv,
5908                          P_BILLREP_TBL              => l_billrep_tbl,
5909                          P_BILLREP_TBL_IDX          => l_billrep_tbl_idx,
5910                       P_BILLREP_ERR_TBL          => l_billrep_err_tbl,
5911                       P_BILLREP_ERR_TBL_IDX      => l_billrep_errtbl_idx
5912                         );
5913 
5914            IF (l_return_status   <>  OKC_API.G_RET_STS_SUCCESS) Then
5915                 oks_bill_rec_pub.get_message (
5916                   l_msg_cnt  => l_msg_count,
5917                      l_msg_data => l_msg_data);
5918              l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
5919              l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5920 
5921                 oks_bill_Rec_pub.Set_sub_line(
5922                    P_PROCESSED_LINES_TBL      => l_processed_lines_tbl,
5923                    P_PROCESSED_SUB_LINES_TBL  => l_processed_sub_lines_tbl,
5924                    P_ERROR_MESSAGE => l_processed_lines_tbl(l_pr_tbl_idx).Error_Message,
5925                    P_TOP_LINE                 => l_bill_rec.id) ;
5926 
5927              FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => Failed in AR FEEDER :'||'  '||l_bill_rec.id);
5928 
5929              ---DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5930              Raise Main_Line_Exception;
5931            END IF;
5932 
5933 
5934 	    /*
5935 	     Contract version updates is done for OKI.
5936 	     OKI pulls data depending upon minor version change.
5937 		Bug# 5637820 - This procedure is made as an autonomous transaction
5938 	   */
5939 
5940 		 update_version(p_dnz_chr_id => l_bill_rec.dnz_chr_id);
5941 
5942 
5943       END IF;  -- l_ar_Feeder = 1
5944 
5945 
5946        --skuchima Ceredian ER
5947      if Nvl(l_bulk_usage,'N') = 'N' or l_bill_rec.lse_id <> 12 THEN
5948       l_process_counter := l_process_counter + 1;
5949      END IF;
5950 
5951       EXCEPTION
5952          WHEN MAIN_LINE_EXCEPTION THEN
5953          --Added by pmallara  begin exception block to fix bug#3961046
5954             BEGIN
5955            l_reject_counter := l_reject_counter + 1;
5956            DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5957            FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => MAIN LINE EXCEPTION RAISE'||'        '||sqlerrm);
5958                  RETCODE := 1;
5959             EXCEPTION
5960              WHEN  OTHERS THEN
5961            FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Failed- when trying to rollback inside MAIN_LINE_EXCEPTION  '||sqlerrm );
5962            exit;
5963             END;
5964 
5965          WHEN OTHERS THEN
5966          --Added by pmallara  begin exception block to fix bug#3961046
5967             BEGIN
5968            l_processed_lines_tbl(l_pr_tbl_idx).Billed_YN     := 'N' ;
5969            l_processed_lines_tbl(l_pr_tbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||' Main Loop - When others ' ;
5970 
5971            /*FOR ERROR REPORT*/
5972             l_billrep_errtbl_idx := l_billrep_errtbl_idx + 1;
5973             l_billrep_err_tbl(l_billrep_errtbl_idx).Top_Line_id := l_bill_rec.id;
5974             l_billrep_err_tbl(l_billrep_errtbl_idx).Lse_Id :=l_bill_rec.lse_id ;
5975             l_billrep_err_tbl(l_billrep_errtbl_idx).Sub_line_id := NULL;
5976             l_billrep_err_tbl(l_billrep_errtbl_idx).Error_Message := 'Error: '|| sqlerrm||'. Error Message: '||l_msg_data ;
5977 
5978             l_reject_counter := l_reject_counter + 1;
5979             DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
5980             FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Failed- when others  exception raised in Mainline loop '||sqlerrm );
5981                   RETCODE := 1;
5982 
5983 	    --Bug#5378184
5984 	     l_err_code := substr(sqlerrm,instr(sqlerrm,'-')+1,5);
5985 	     if (l_err_code = '01555') then
5986 		raise;
5987 	     end if;
5988 	    --End Bug#5378184
5989 
5990          EXCEPTION
5991               WHEN OTHERS THEN
5992            FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => Failed- when trying to rollback inside WHEN OTHERS exception'||sqlerrm );
5993               exit;
5994          END;
5995        END;
5996      END LOOP;            --end of loop for cle_id tbl
5997 
5998 if Nvl(l_bulk_usage,'N') = 'Y'THEN
5999 
6000 /*skuchima Ceredian ER*/
6001    BEGIN
6002 
6003      ---  After fetching all the lines...process the QP call in bulk mode for usage lines billing
6004      Usg_billing_bulk_qp_call_prc (l_process_counter,
6005                           l_reject_counter ,
6006                           l_billrep_tbl,
6007                           l_billrep_err_tbl,
6008                           l_billrep_errtbl_idx,
6009                           P_calledfrom,
6010                           p_flag,
6011                           p_date,
6012                           p_prv ,
6013                           RETCODE
6014                           );
6015 
6016    END;
6017 end if;
6018      --Added to clear pl/sql tables after processing records
6019      cle_id.delete;
6020      chr_id.delete;
6021      l_line_no.delete;
6022    END IF;              ----end of count for cle_id tbl
6023 
6024      EXIT WHEN billing_process%NOTFOUND ;
6025  END LOOP;   --MAIN LOOP END for billing_process cursor
6026 
6027    /*  *** Create the output file for Billing program.  ***  */
6028 
6029    If l_write_report then
6030       OKS_BILL_UTIL_PUB.CREATE_REPORT
6031          ( p_billrep_table      => l_billrep_tbl
6032           ,p_billrep_err_tbl    => l_billrep_err_tbl
6033           ,p_line_from          => P_process_from
6034           ,p_line_to            => P_process_to
6035           ,x_return_status      => l_return_status);
6036 
6037       IF (l_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
6038          FND_FILE.PUT_LINE(FND_FILE.LOG,'OKS_BILLING_PUB.Calculate_bill => *** Failed to create Billing Report ***' );
6039       END IF;
6040    End If;
6041 
6042    If l_write_log then
6043      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill processing Ends ');
6044    End If;
6045 
6046    ---- Added if clause to issue warning for any data related issue
6047    IF (RETCODE <> 1) THEN
6048         RETCODE := 0;
6049    End if;
6050 
6051  EXCEPTION
6052 
6053    WHEN  G_EXCEPTION_HALT_VALIDATION THEN
6054      x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
6055      RETCODE := 2;
6056      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => when g_exception_rollback  raised'||sqlerrm);
6057      DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
6058    WHEN G_EXCEPTION_ROLLBACK THEN
6059      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => when g_exception_rollback  raised'||sqlerrm);
6060      DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
6061 
6062    WHEN  OTHERS THEN
6063      x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
6064      RETCODE := 2;
6065      FND_FILE.PUT_LINE( FND_FILE.LOG, 'OKS_BILLING_PUB.Calculate_bill => when others raised'||sqlerrm);
6066      OKC_API.set_message(G_APP_NAME, G_UNEXPECTED_ERROR,
6067                          G_SQLCODE_TOKEN,SQLCODE,G_SQLERRM_TOKEN,SQLERRM);
6068      DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
6069 
6070  END Calculate_bill;
6071 
6072 /*----------------------------------------------------------------------
6073 Concurrent Program Wrapper for Regular Service and Usage Billing Program
6074 ------------------------------------------------------------------------*/
6075 
6076 
6077 PROCEDURE  Billing_Main
6078 (
6079 ERRBUF            OUT      NOCOPY VARCHAR2,
6080 RETCODE           OUT      NOCOPY NUMBER,
6081 P_CONTRACT_HDR_ID IN              NUMBER,
6082 -- nechatur 29-Nov-2005 bug#4459229 changing type of P_DEFAULT_TYPE to VARCHAR2
6083 --P_DEFAULT_DATE    IN              DATE,
6084 P_DEFAULT_DATE    IN             VARCHAR2,
6085 --end bug#4459229
6086 P_ORG_ID          IN              NUMBER,
6087 P_CUSTOMER_ID     IN              NUMBER,
6088 P_CATEGORY        IN              VARCHAR2,
6089 P_GRP_ID          IN              NUMBER,
6090 P_PROCESS         IN              VARCHAR2   --No for Normal processing,Yes for Preview Processing
6091 )
6092 IS
6093 
6094 
6095 CONC_STATUS             BOOLEAN;
6096 l_ret                   INTEGER;
6097 l_subrequests           INTEGER;
6098 l_errbuf                VARCHAR2(240);
6099 l_msg_data              VARCHAR2(2000);
6100 l_return_status         VARCHAR2(1);
6101 v_truncstring           VARCHAR2(500);
6102 l_view_by_org           VARCHAR2(10);
6103 l_dummy                 VARCHAR2(1);
6104 l_statement             VARCHAR2(30000);
6105 p_date                  DATE;
6106 l_line_no               NUMBER;
6107 l_max_boundary          NUMBER;
6108 l_min_boundary          NUMBER;
6109 l_slot_size             NUMBER;
6110 l_retcode               NUMBER;
6111 l_msg_count             NUMBER;
6112 p_prv                   NUMBER;
6113 l_org_id                NUMBER;
6114 l_flag                  NUMBER  := 0;
6115 v_cursor                NUMBER;
6116 
6117 l_billrep_tbl           OKS_BILL_REC_PUB.bill_report_tbl_type;
6118 l_billrep_tbl_idx       NUMBER;
6119 l_billrep_err_tbl       OKS_BILL_REC_PUB.billrep_error_tbl_type;
6120 l_billrep_errtbl_idx    NUMBER;
6121 /*added for bug7668259*/
6122 l_hook                  NUMBER;
6123 l_date_interface_start  DATE;
6124 l_hint                  VARCHAR2(50);
6125 p_access_mode          VARCHAR2(1);       /*Added for bug:10191601*/
6126 l_original_org_id NUMBER; /*skuchima*/
6127 
6128 BEGIN
6129 
6130   FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Billing_Main  Starts');
6131 
6132    l_yes_no :=  Fnd_profile.value('OKS_BILLING_REPORT_AND_LOG');
6133 
6134   FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Billing_Main => OKS: Billing Report And Log is set to '||l_yes_no);
6135 
6136    If l_yes_no = 'YES' then
6137       l_write_log       := TRUE;
6138       l_write_report    := TRUE;
6139    Else
6140       l_write_log       := FALSE;
6141       l_write_report    := FALSE;
6142    End If;
6143 
6144   l_org_id := p_org_id;
6145 
6146   --mchoudha fixed bug#4729936
6147   --IF (nvl(fnd_profile.value('OKC_VIEW_K_BY_ORG'),'N') = 'Y' ) THEN
6148   --  l_org_id := fnd_profile.value('ORG_ID');
6149   If l_write_log then
6150      FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => parameter Org ID is '||l_org_id);
6151   End If;
6152  -- END IF;
6153 
6154   If l_write_log then
6155      FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Preview Y/N ='||P_process);
6156   End If;
6157    /*Added for bug:10191601*/
6158    p_access_mode := mo_global.get_access_mode;
6159  /*p_access_mode    - specifies the operating unit access. 'S' for Single, 'M' for Multiple */
6160 
6161 /*skuchima bug 16452991 */
6162    l_original_org_id       := mo_global.get_current_org_id;
6163 
6164   /* Set p_prv flag, which is used to in calls to AR Feeder.
6165      p_prv = 2  -- preview billing
6166   */
6167   IF (P_PROCESS = 'Y') then
6168    P_PRV := 2;
6169   ELSE
6170    P_PRV := 1;
6171   END IF;
6172 
6173   user_id    := FND_GLOBAL.USER_ID;
6174   If l_write_log then
6175      FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => User_Id ='||to_char(user_id));
6176   End If;
6177 
6178 --nechatur 29-Nov-2005 for bug#4459229
6179 --p_date := nvl(trunc(p_default_date),trunc(sysdate));
6180 ----p_date := nvl(trunc(TO_DATE(p_default_date, 'yyyy/mm/dd hh24:mi:ss')),trunc(sysdate));
6181 -- end bug#4459229
6182 
6183 ----Hari bug# 5704211
6184     p_date := nvl(fnd_date.canonical_to_date(p_default_date), trunc(sysdate));
6185 
6186   --Added this If condition so that the table does not get
6187   --truncated during the restart of the parent
6188   If(FND_CONC_GLOBAL.request_data is null) THEN
6189 
6190     If l_write_log then
6191       FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Truncating oks_process_billing');
6192     End If;
6193 
6194     v_cursor := DBMS_SQL.OPEN_CURSOR;
6195     /*Following line is required to avoid GSCC errors at ARU creation.
6196       Concatination of string is required to avoid run time error.
6197       Ampersand 1 is taking value from un_oks param in dbdrv command line.*/
6198     --v_truncstring := 'Truncate Table oks';
6199     --v_truncstring := v_truncstring||'.oks_process_billing';
6200     v_truncstring := 'Truncate Table OKS'||'.oks_process_billing';
6201     DBMS_SQL.PARSE(v_cursor,v_truncstring,DBMS_SQL.V7);
6202     DBMS_SQL.CLOSE_CURSOR(v_cursor);
6203   END IF;
6204 
6205 
6206   /* This call to AR Feeder is done to process any termination records.
6207      It is kept in the begining of the code with purpose. In case of parallel
6208      run of billing program , this api may not get executed if placed at the
6209      end of api. This is because there is return statement in parallel worker
6210      code. This is fix for  bug # 2963174
6211   */
6212   IF (FND_CONC_GLOBAL.request_data is null) THEN -- not a restart of parent
6213 
6214   If l_write_log then
6215     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Call to OKS_ARFEEDER_PUB.Get_REC_FEEDER to interface termination records');
6216   End If;
6217 
6218     OKS_ARFEEDER_PUB.Get_REC_FEEDER
6219      (
6220        x_return_status             => l_return_status,
6221        x_msg_count                 => l_msg_count,
6222        x_msg_data                  => l_msg_data,
6223        p_flag                      => l_flag,
6224        p_called_from               => 1,
6225        p_date                      => p_date,
6226        p_cle_id                    => NULL,
6227        p_prv                       => 3,   --to interface termination records and any stray records
6228        p_billrep_tbl               => l_billrep_tbl,
6229        p_billrep_tbl_idx           => l_billrep_tbl_idx,
6230        p_billrep_err_tbl          => l_billrep_err_tbl,
6231        p_billrep_err_tbl_idx      => l_billrep_errtbl_idx
6232      ) ;
6233 
6234   If l_write_log then
6235     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => After Call to OKS_ARFEEDER_PUB.Get_REC_FEEDER to interface termination records l_return_status '||l_return_status);
6236     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Access_Mode after AR call - '||mo_global.get_access_mode);
6237     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Org Context after AR call - '||okc_context.get_okc_org_id);
6238     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Original Access Mode - '||p_Access_Mode);
6239     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Original Org Context  - '||l_original_org_id);
6240   End If;
6241 
6242 /*Set the org context again after ar call skuchima bug16452991 */
6243    mo_global.set_policy_context(p_access_mode,l_original_org_id);
6244 
6245   -- We need to see if we should spawn sub-requests;
6246   -- i.e., the number of contract lines that qualify is > MAX_SINGLE_REQUEST.
6247 
6248     DBMS_TRANSACTION.SAVEPOINT('BEFORE_MAIN_BILLING');
6249 
6250 
6251     l_line_no   := 0;
6252     /*Code hook to get interface start_date for bug7668259*/
6253    oks_code_hook.billing_interface_st_date(l_hook,l_date_interface_start,l_hint);
6254 
6255     IF (p_grp_id is not null) or (p_customer_id is not null) or
6256        (p_category is not null) or (l_org_id is not null)    or
6257        (p_contract_hdr_id is not null)  Then
6258       If l_write_log then
6259         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameters Passed => Contract Id '||p_contract_hdr_id);
6260         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Customer '||P_customer_id|| ' Category '||p_category);
6261         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Org '||l_org_id|| ' Group '||p_grp_id);
6262       End If;
6263 
6264     End If;
6265 
6266 
6267     IF (p_grp_id is null) and (p_customer_id is null) and
6268        (p_category is null) and (l_org_id is null)    and
6269        (p_contract_hdr_id is null)  Then
6270 
6271 If l_write_log then --added by ansraj for 14016663
6272         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Blind Query ' || ': with date '||p_date);
6273 End If;
6274 
6275         /*code hook is used as part of bug7668259*/
6276    IF l_hook = 1 AND l_date_interface_start IS NOT NULL THEN
6277 
6278 If l_write_log then --added by ansraj for 14016663
6279        FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Serial plan as l_hook value is 1 with
6280        date_interface_start as: '|| l_date_interface_start );
6281 End If;
6282 
6283 	  INSERT /*+ append */ into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6284            SELECT /*+ leading(lvl,line,as1,hdr,sts)
6285  	            use_nl(line,hdr) use_hash(as1,sts) swap_join_inputs(as1)
6286  	            swap_join_inputs(sts) */
6287              hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6288                 from   (
6289                           Select distinct lvl.parent_cle_id
6290                           from oks_level_elements lvl
6291  	                   where lvl.date_completed is null
6292  	                   and   (lvl.date_to_interface > trunc(l_date_interface_start) -1 and lvl.date_to_interface <  trunc(p_date)+1)
6293  	                   )  lvl,
6294  	                   okc_k_lines_b   line,
6295  	                   (
6296  	                   Select  distinct scs_code,sts_code
6297  	                   from okc_assents a
6298  	                   where a.opn_code = 'INVOICE'
6299  	                   and a.allowed_yn = 'Y'
6300  	                   ) as1,
6301  	                   okc_k_headers_b hdr,
6302  	                   (
6303  	                   Select  distinct code
6304  	                   from okc_statuses_b osb
6305  	                   where osb.ste_code <> 'HOLD'
6306  	                   ) sts
6307  	            WHERE Hdr.id = line.dnz_chr_id
6308  	            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6309  	            AND   Hdr.Template_yn = 'N'
6310  	            AND   line.id = lvl.parent_cle_id
6311  	            AND   line.lse_id     in (1,12,19,46)
6312  	            AND   line.sts_code = as1.sts_code
6313  	            AND   as1.scs_code =  Hdr.scs_code
6314  	            AND   sts.code =   Hdr.sts_code;
6315  	            /*AND   line.id not in ( Select   rel.cle_id
6316  	                                    From okc_k_rel_objs rel
6317  	                                    Where rel.cle_id is not null
6318  	                                 );*/ ---Commented for ER 16039680
6319  	         /*added for bug7668259*/
6320  	         ELSIF l_hint = 'FULL' THEN /*full parallel processing of data*/
6321 
6322 	          If l_write_log then -- by ansraj for bug 14016663
6323  	           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using FULL Parallel plan as l_hint value is FULL');
6324 	         End if;
6325 
6326                    /*Added for bug:10191601*/
6327  	     /*p_access_mode = 'M' for multi-org, 'S' for Single org.
6328               If p_access_mode = 'M' then make a direct join of  okc_k_headers_all_b with
6329                mo_glob_org_access_tmp. This is as per the appsperf team suggestion*/
6330 
6331                 IF Nvl(p_access_mode,'X') = 'M' THEN
6332                  /*removed the parallel hint and added NO_PUSH_PRED(lvl) as per appsperf team suggestion*/
6333                   /*added  nl_aj  hint as per appsperf team suggestion*/
6334  	      INSERT /*+ append */ into oks_process_billing
6335                    (chr_id,cle_id,line_no,currency_code)
6336                  SELECT /*+ leading(lvl,line,as1,hdr,as1)
6337                       use_nl(line,hdr) use_hash(as1,sts,oa) swap_join_inputs(as1) swap_join_inputs(oa)
6338                         swap_join_inputs(sts)
6339                        NO_PUSH_PRED(lvl)       */
6340                     hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6341                   from   (
6342                    Select  /*+ parallel(lvl) no_merge */ distinct
6343                   lvl.parent_cle_id
6344                   from oks_level_elements lvl
6345                   where lvl.date_completed is null
6346                   and   lvl.date_to_interface <  trunc(p_date) + 1
6347                   )  lvl,
6348                   okc_k_lines_b   line,
6349                   (
6350                   Select distinct scs_code,sts_code
6351                   from okc_assents a
6352                   where a.opn_code = 'INVOICE'
6353                   and a.allowed_yn = 'Y'
6354                   ) as1,
6355                   okc_k_headers_all_b hdr,
6356                   mo_glob_org_access_tmp oa,
6357                   (
6358                   Select distinct code
6359                   from okc_statuses_b osb
6360                   where osb.ste_code <> 'HOLD'
6361                   ) sts
6362            WHERE Hdr.id = line.dnz_chr_id
6363            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6364            AND   Hdr.Template_yn = 'N'
6365            AND   line.id = lvl.parent_cle_id
6366            AND   line.lse_id     in (1,12,19,46)
6367            AND   oa.organization_id = Hdr.authoring_org_id
6368            AND   line.sts_code = as1.sts_code
6369            AND   as1.scs_code =  Hdr.scs_code
6370            AND   sts.code =   Hdr.sts_code;
6371            /*AND   line.id not in ( Select /*+ nl_aj   rel.cle_id
6372                                    From okc_k_rel_objs rel
6373                                    Where rel.cle_id is not null
6374                                 );*/   ---Commented for ER 16039680
6375      ELSE
6376              INSERT /*+ append */ into oks_process_billing
6377              (chr_id,cle_id,line_no,currency_code)
6378               SELECT /*+ leading(lvl,line,as1,hdr,as1)
6379                  use_nl(line,hdr) use_hash(as1,sts) swap_join_inputs(as1)
6380                 swap_join_inputs(sts)
6381                  NO_PUSH_PRED(lvl)
6382               */
6383                 hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6384                  from   (
6385                         Select  /*+ parallel(lvl) no_merge */ distinct
6386                lvl.parent_cle_id
6387                   from oks_level_elements lvl
6388                   where lvl.date_completed is null
6389                   and   lvl.date_to_interface <  trunc(p_date) + 1
6390                   )  lvl,
6391                   okc_k_lines_b   line,
6392                   (
6393                   Select distinct scs_code,sts_code
6394                   from okc_assents a
6395                   where a.opn_code = 'INVOICE'
6396                   and a.allowed_yn = 'Y'
6397                   ) as1,
6398                   okc_k_headers_b hdr,
6399                   (
6400                   Select distinct code
6401                   from okc_statuses_b osb
6402                   where osb.ste_code <> 'HOLD'
6403                   ) sts
6404            WHERE Hdr.id = line.dnz_chr_id
6405            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6406            AND   Hdr.Template_yn = 'N'
6407            AND   line.id = lvl.parent_cle_id
6408            AND   line.lse_id     in (1,12,19,46)
6409            AND   line.sts_code = as1.sts_code
6410            AND   as1.scs_code =  Hdr.scs_code
6411            AND   sts.code =   Hdr.sts_code;
6412            /*AND   line.id not in ( Select /*+ nl_aj  rel.cle_id
6413                                    From okc_k_rel_objs rel
6414                                    Where rel.cle_id is not null
6415                                 );*/   ---Commented for ER 16039680
6416    END IF;
6417          /*modified for bug7668259*/
6418  	         ELSE    /*Semi parallel processing of data */
6419 	      If l_write_log then -- by ansraj for bug 14016663
6420  	         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Semi Parallel plan as l_hook value is 0');
6421 	      End if;
6422 
6423  	         INSERT /*+ append */ into oks_process_billing(chr_id,cle_id,line_no,currency_code)
6424  	         SELECT /*+ leading(lvl,line,as1,hdr,sts) use_nl(line,hdr) use_hash(as1,sts) swap_join_inputs(as1) swap_join_inputs(sts) */
6425  	           hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6426  	            from   (Select  /*+ parallel(lvl) no_merge */ distinct lvl.parent_cle_id
6427  	                   from oks_level_elements lvl
6428  	                   where lvl.date_completed is null
6429  	                   and   lvl.date_to_interface <  trunc(p_date) + 1
6430  	                   )  lvl,
6431  	                   okc_k_lines_b   line,
6432  	                   (
6433  	                   Select  distinct scs_code,sts_code
6434  	                   from okc_assents a
6435  	                   where a.opn_code = 'INVOICE'
6436  	                   and a.allowed_yn = 'Y'
6437  	                   ) as1,
6438  	                   okc_k_headers_b hdr,
6439  	                   (
6440  	                   Select  distinct code
6441  	                   from okc_statuses_b osb
6442  	                   where osb.ste_code <> 'HOLD'
6443  	                   ) sts
6444  	            WHERE Hdr.id = line.dnz_chr_id
6445  	            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6446  	            AND   Hdr.Template_yn = 'N'
6447  	            AND   line.id = lvl.parent_cle_id
6448  	            AND   line.lse_id     in (1,12,19,46)
6449  	            AND   line.sts_code = as1.sts_code
6450  	            AND   as1.scs_code =  Hdr.scs_code
6451  	            AND   sts.code =   Hdr.sts_code;
6452  	            /*AND   line.id not in ( Select   rel.cle_id
6453  	                                    From okc_k_rel_objs rel
6454  	                                    Where rel.cle_id is not null
6455  	                                 ); */   ---Commented for ER 16039680
6456  	         END IF;
6457     Elsif
6458        (p_grp_id is null) and (p_customer_id is null) and
6459        (p_category is null) and (l_org_id is not null)  and
6460        (p_contract_hdr_id is null)  Then
6461 If l_write_log then -- by ansraj for bug 14016663
6462         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Query for Org id');
6463 End if;
6464           /*modified for bug7668259*/
6465  	         IF l_hook = 1 AND l_date_interface_start IS NOT NULL THEN
6466 
6467 	          If l_write_log then -- by ansraj for bug 14016663
6468  	           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Serial plan as l_hook value is 1 with date_interface_start as: '||l_date_interface_start);
6469 	          End if;
6470 
6471  	           INSERT into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6472  	            SELECT hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6473  	            from   (
6474  	                   Select distinct lvl.parent_cle_id
6475  	                   from oks_level_elements lvl
6476  	                   where lvl.date_completed is null
6477  	                   and   (lvl.date_to_interface > TRUNC(l_date_interface_start) -1 and lvl.date_to_interface < trunc(p_date)+1)
6478  	                   )  lvl,
6479  	                   okc_k_lines_b   line,
6480  	                   (
6481  	                   Select  distinct scs_code,sts_code
6482  	                   from okc_assents a
6483  	                   where a.opn_code = 'INVOICE'
6484  	                   and a.allowed_yn = 'Y'
6485  	                   ) as1,
6486  	                   okc_k_headers_b hdr,
6487  	                   (
6488  	                   Select  distinct code
6489  	                   from okc_statuses_b osb
6490  	                   where osb.ste_code <> 'HOLD'
6491  	                   ) sts
6492  	            WHERE Hdr.id = line.dnz_chr_id
6493  	            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6494  	            AND   Hdr.Authoring_Org_Id = l_org_id
6495  	            AND   Hdr.Template_yn = 'N'
6496  	            AND   line.id = lvl.parent_cle_id
6497  	            AND   line.lse_id     in (1,12,19,46)
6498  	            AND   line.sts_code = as1.sts_code
6499  	            AND   as1.scs_code =  Hdr.scs_code
6500  	            AND   sts.code =   Hdr.sts_code;
6501  	            /*AND   line.id not in ( Select  rel.cle_id
6502  	                                    From okc_k_rel_objs rel
6503  	                                    Where rel.cle_id is not null
6504  	                                 );*/   ---Commented for ER 16039680
6505  	         /*modified for bug7668259*/
6506  	         ELSE   /*l_hook = 0, so parallel processing of data*/
6507 
6508 	         If l_write_log then -- by ansraj for bug 14016663
6509  	           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Parallel plan as l_hook value is 0') ;
6510                                    End if;
6511 
6512 	  INSERT  into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6513            SELECT hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6514            from   /*(
6515                   Select  /*+ parallel(lvl) distinct lvl.parent_cle_id
6516                   from oks_level_elements lvl
6517                   where lvl.date_completed is null
6518                   and   lvl.date_to_interface <  trunc(p_date) + 1
6519                   )  lvl,*/  /*commented for bug 13932146 */
6520                   okc_k_lines_b   line,
6521                   (
6522                   Select  distinct scs_code,sts_code
6523                   from okc_assents a
6524                   where a.opn_code = 'INVOICE'
6525                   and a.allowed_yn = 'Y'
6526                   ) as1,
6527                   okc_k_headers_b hdr,
6528                   (
6529                   Select distinct code
6530                   from okc_statuses_b osb
6531                   where osb.ste_code <> 'HOLD'
6532                   ) sts
6533            WHERE Hdr.id = line.dnz_chr_id
6534            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6535            AND   Hdr.Authoring_Org_Id = l_org_id
6536            AND   Hdr.Template_yn = 'N'
6537            --AND   line.id = lvl.parent_cle_id    /*commented for bug 13932146 */
6538            AND   line.lse_id     in (1,12,19,46)
6539            AND   line.sts_code = as1.sts_code
6540            AND   as1.scs_code =  Hdr.scs_code
6541            AND   sts.code =   Hdr.sts_code
6542            /*AND   line.id not in ( Select rel.cle_id
6543                                    From okc_k_rel_objs rel
6544                                    Where rel.cle_id is not null
6545                                 ) */  ---Commented for ER 16039680
6546             /*Added for bug 13932146 */
6547           AND EXISTS (
6548               SELECT /*+ no_unnest push_subq */
6549                      'x'
6550                 FROM oks_level_elements lvl
6551                WHERE lvl.date_completed IS NULL
6552                  AND lvl.date_to_interface < TRUNC (TO_DATE (p_date)) + 1
6553                  AND line.ID = lvl.parent_cle_id);
6554           /*Added for bug 13932146 */
6555      END IF;
6556     Elsif
6557        (p_contract_hdr_id is not null)  Then
6558 
6559        If l_write_log then -- by ansraj for bug 14016663
6560           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Query for Contract id');
6561        End if;
6562 
6563 	  INSERT into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6564 
6565         SELECT  hdr.id hdr_id,line.id line_id,rownum,hdr.currency_code
6566 		 from   okc_k_headers_b hdr, okc_k_lines_b   line
6567         WHERE Hdr.id = line.dnz_chr_id
6568         AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6569         AND   Hdr.Template_yn = 'N'
6570         AND   Hdr.id = p_contract_hdr_id
6571         AND   line.id IN (Select  lvl.parent_cle_id
6572 				          from oks_level_elements lvl
6573                               where lvl.date_completed is null
6574                               and   lvl.date_to_interface <  trunc(p_date) + 1 )
6575         AND exists (Select  1 from okc_statuses_b osb
6576                                   where osb.ste_code <> 'HOLD'
6577                                   and   osb.code =   Hdr.sts_code )
6578         AND exists ( SELECT 1 from okc_assents a
6579                                    where line.sts_code = a.sts_code
6580                                    and a.scs_code =  Hdr.scs_code
6581                                    and a.opn_code = 'INVOICE'
6582                                    and a.allowed_yn = 'Y' )
6583         AND    line.lse_id     in (1,12,19,46);
6584 		/* AND    line.id not in ( Select  rel.cle_id
6585 		                         From okc_k_rel_objs rel
6586                                    Where rel.cle_id is not null );*/  ---Commented for ER 16039680
6587 
6588     Elsif
6589        (p_grp_id is not null) and (p_customer_id is null) and
6590        (p_category is null) and (l_org_id is not null)  and
6591        (p_contract_hdr_id is null)  Then
6592        if l_write_log then -- by ansraj for bug 14016663
6593            FND_FILE.PUT_LINE(FND_FILE.LOG, 'Query for contract group and org id');
6594        End if;
6595          /*modified for bug7668259*/
6596  	         IF l_hook = 1 AND l_date_interface_start IS NOT NULL THEN
6597 	           if l_write_log then -- by ansraj for bug 14016663
6598  	                FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Serial plan as l_hook value is 1 with date_interface_start as: '||l_date_interface_start);
6599 	           End if;
6600 
6601  	         INSERT /*+ append */ into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6602  	            SELECT  /*+ leading(lvl) ORDERED USE_HASH(line hdr sts as1 cgp)
6603  	                        swap_join_inputs(hdr) swap_join_inputs(sts) swap_join_inputs(cgp) */
6604  	                       hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6605  	            from   (
6606  	                   Select  distinct lvl.parent_cle_id
6607  	                   from oks_level_elements lvl
6608  	                   where lvl.date_completed is null
6609  	                   and   (lvl.date_to_interface > TRUNC(l_date_interface_start) -1 AND lvl.date_to_interface <  trunc(p_date) +1)
6610  	                   )  lvl,
6611  	                   okc_k_lines_b   line,
6612  	                   (
6613  	                   Select  /*+ FULL (a) no_merge */ distinct scs_code,sts_code
6614  	                   from okc_assents a
6615  	                   where a.opn_code = 'INVOICE'
6616  	                   and a.allowed_yn = 'Y'
6617  	                   ) as1,
6618  	                   okc_k_headers_b hdr,
6619  	                   (
6620  	                   Select  /*+ FULL (osb) no_merge */ distinct code
6621  	                   from okc_statuses_b osb
6622  	                   where osb.ste_code <> 'HOLD'
6623  	                   ) sts,
6624  	                   (
6625  	                   Select  /*+ FULL (grp) no_merge */ distinct included_chr_id
6626  	                   from OKC_K_GRPINGS grp
6627  	                            where grp.cgp_parent_id = p_grp_id
6628  	                         ) cgp
6629  	            WHERE Hdr.id = line.dnz_chr_id
6630  	            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6631  	            AND   Hdr.Template_yn = 'N'
6632  	            AND   Hdr.Authoring_Org_Id = l_org_id
6633  	            AND   line.id = lvl.parent_cle_id
6634  	            AND   line.lse_id     in (1,12,19,46)
6635  	            AND   line.sts_code = as1.sts_code
6636  	            AND   as1.scs_code =  Hdr.scs_code
6637  	            AND   sts.code =   Hdr.sts_code
6638  	                  AND   cgp.included_chr_id = Hdr.id;
6639  	           /* AND   line.id not in ( Select  /*+ index_ffs (rel) HASH_AJ   rel.cle_id
6640  	                                    From okc_k_rel_objs rel
6641  	                                    Where rel.cle_id is not null
6642  	                                 ); */   ---Commented for ER 16039680
6643  	         /*modified for bug7668259*/
6644  	         ELSE /*l_hook = 0, so normal processing of data*/
6645 
6646 	         If l_write_log then -- by ansraj for bug 14016663
6647  	             FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Normal Plan as l_hook value is 0');
6648 	         End if;
6649 	  INSERT /*+ append */ into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6650            SELECT  /*+ leading(lvl) ORDERED USE_HASH(line hdr sts as1 cgp)
6651                        swap_join_inputs(hdr) swap_join_inputs(sts) swap_join_inputs(cgp) */
6652                       hdr.id hdr_id, line.id line_id, rownum, hdr.currency_code
6653            from   (
6654                   Select  /*+ FULL (lvl) no_merge */ distinct lvl.parent_cle_id
6655                   from oks_level_elements lvl
6656                   where lvl.date_completed is null
6657                   and   (lvl.date_to_interface) <  trunc(p_date)+1
6658                   )  lvl,
6659                   okc_k_lines_b   line,
6660                   (
6661                   Select  /*+ FULL (a) no_merge */ distinct scs_code,sts_code
6662                   from okc_assents a
6663                   where a.opn_code = 'INVOICE'
6664                   and a.allowed_yn = 'Y'
6665                   ) as1,
6666                   okc_k_headers_b hdr,
6667                   (
6668                   Select  /*+ FULL (osb) no_merge */ distinct code
6669                   from okc_statuses_b osb
6670                   where osb.ste_code <> 'HOLD'
6671                   ) sts,
6672                   (
6673                   Select  /*+ FULL (grp) no_merge */ distinct included_chr_id
6674                   from OKC_K_GRPINGS grp
6675 			   where grp.cgp_parent_id = p_grp_id
6676 		        ) cgp
6677            WHERE Hdr.id = line.dnz_chr_id
6678            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6679            AND   Hdr.Template_yn = 'N'
6680            AND   Hdr.Authoring_Org_Id = l_org_id
6681            AND   line.id = lvl.parent_cle_id
6682            AND   line.lse_id     in (1,12,19,46)
6683            AND   line.sts_code = as1.sts_code
6684            AND   as1.scs_code =  Hdr.scs_code
6685            AND   sts.code =   Hdr.sts_code
6686 		 AND   cgp.included_chr_id = Hdr.id;
6687            /*AND   line.id not in ( Select  /*+ index_ffs (rel) HASH_AJ   rel.cle_id
6688                                    From okc_k_rel_objs rel
6689                                    Where rel.cle_id is not null
6690                                 );*/   ---Commented for ER 16039680
6691         END IF;
6692     ELSIF
6693  	        (p_grp_id is null) and (p_customer_id is null) and
6694  	        (p_category is not null) and (l_org_id is not null)  and
6695  	        (p_contract_hdr_id is null)  Then
6696 
6697                 If l_write_log then -- by ansraj for bug 14016663
6698                     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Query for category and org id');
6699                  End if;
6700                  /*modified for bug7668259*/
6701  	         IF l_hook = 1 AND l_date_interface_start IS NOT NULL THEN
6702 	           If l_write_log then -- by ansraj for bug 14016663
6703  	               FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Serial plan as l_hook value is 1 with date_interface_start as: '||l_date_interface_start);
6704 	           End if;
6705 
6706                   INSERT into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6707  	            SELECT  hdr.id hdr_id,line.id line_id,rownum,hdr.currency_code
6708  	            from   okc_k_headers_b hdr, okc_k_lines_b   line
6709  	            WHERE Hdr.id = line.dnz_chr_id
6710  	            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6711  	            AND   Hdr.Template_yn = 'N'
6712  	            AND   Hdr.Authoring_Org_Id = l_org_id
6713  	            AND   Hdr.Scs_code = p_category
6714  	            AND   line.id IN (Select lvl.parent_cle_id
6715  	                               from oks_level_elements lvl
6716  	                               where lvl.date_completed is null
6717  	                                and   (lvl.date_to_interface > TRUNC(l_date_interface_start) -1 AND
6718                                         lvl.date_to_interface <  trunc(p_date) +1))
6719  	            AND exists (Select  1 from okc_statuses_b osb
6720  	                                   where osb.ste_code <> 'HOLD'
6721  	                                   and   osb.code =   Hdr.sts_code )
6722  	            AND exists ( SELECT 1 from okc_assents a
6723  	                                    where line.sts_code = a.sts_code
6724  	                                    and a.scs_code =  Hdr.scs_code
6725  	                                    and a.opn_code = 'INVOICE'
6726  	                                    and a.allowed_yn = 'Y' )
6727  	            AND    line.lse_id     in (1,12,19,46);
6728  	             /* AND    line.id not in ( Select  rel.cle_id
6729  	                                     From okc_k_rel_objs rel
6730  	                                    Where rel.cle_id is not null );*/   ---Commented for ER 16039680
6731 
6732                 /*modified for bug7668259*/
6733  	         ELSE /*l_hook = 0, so normal processing of data*/
6734 	        If l_write_log then -- by ansraj for bug 14016663
6735   	           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Using Normal plan as l_hook value is 0');
6736 	        End if;
6737 
6738  	           INSERT into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6739  	            SELECT  hdr.id hdr_id,line.id line_id,rownum,hdr.currency_code
6740  	                  from   okc_k_headers_b hdr, okc_k_lines_b   line
6741  	            WHERE Hdr.id = line.dnz_chr_id
6742  	            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6743  	            AND   Hdr.Template_yn = 'N'
6744  	            AND   Hdr.Authoring_Org_Id = l_org_id
6745  	            AND   Hdr.Scs_code = p_category
6746  	            AND   line.id IN (Select lvl.parent_cle_id
6747  	                                           from oks_level_elements lvl
6748  	                               where lvl.date_completed is null
6749  	                               and   lvl.date_to_interface <  trunc(p_date) +1)
6750  	            AND exists (Select  1 from okc_statuses_b osb
6751  	                                   where osb.ste_code <> 'HOLD'
6752  	                                   and   osb.code =   Hdr.sts_code )
6753  	            AND exists ( SELECT 1 from okc_assents a
6754  	                                    where line.sts_code = a.sts_code
6755  	                                    and a.scs_code =  Hdr.scs_code
6756  	                                    and a.opn_code = 'INVOICE'
6757  	                                    and a.allowed_yn = 'Y' )
6758  	            AND    line.lse_id     in (1,12,19,46);
6759  	                  /*AND    line.id not in ( Select  rel.cle_id
6760  	                                          From okc_k_rel_objs rel
6761  	                                    Where rel.cle_id is not null ); */    ---Commented for ER 16039680
6762  	         END IF;
6763     Else
6764       If l_write_log then -- by ansraj for bug 14016663
6765         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Query for rest of the parameters');
6766       End if;
6767 
6768 	  INSERT into oks_process_billing (chr_id,cle_id,line_no,currency_code)
6769 
6770            SELECT  hdr.id hdr_id,line.id line_id,rownum,hdr.currency_code
6771 		 from   okc_k_headers_b hdr, okc_k_lines_b   line
6772            WHERE Hdr.id = line.dnz_chr_id
6773            AND   Hdr.scs_code in ('SERVICE','WARRANTY','SUBSCRIPTION')
6774            AND   Hdr.Template_yn = 'N'
6775            AND   Hdr.Authoring_Org_Id = nvl(l_org_id, hdr.authoring_org_id)
6776            AND   Hdr.Scs_code = nvl(p_category, hdr.scs_code)
6777 		 AND  exists
6778 		       (select 1 from OKC_K_PARTY_ROLES_B okp
6779 			   where okp.dnz_chr_id  =  hdr.id
6780 			   and   okp.rle_code    in ('CUSTOMER','SUBSCRIBER')
6781 			   and   okp.object1_id1 = nvl(P_customer_id, okp.object1_id1) )
6782 		 AND  exists
6783 		       (select 1 from OKC_K_GRPINGS okg
6784 			   where okg.included_chr_id  =  hdr.id
6785 			   and   okg.cgp_parent_id = nvl(p_grp_id, okg.cgp_parent_id) )
6786            AND   line.id IN (Select  lvl.parent_cle_id
6787 				          from oks_level_elements lvl
6788                               where lvl.date_completed is null
6789                               and   lvl.date_to_interface <  trunc(p_date) +1 ) /*13105205*/
6790            AND exists (Select  1 from okc_statuses_b osb
6791                                   where osb.ste_code <> 'HOLD'
6792                                   and   osb.code =   Hdr.sts_code )
6793            AND exists ( SELECT 1 from okc_assents a
6794                                    where line.sts_code = a.sts_code
6795                                    and a.scs_code =  Hdr.scs_code
6796                                    and a.opn_code = 'INVOICE'
6797                                    and a.allowed_yn = 'Y' )
6798            AND    line.lse_id     in (1,12,19,46);
6799 		 /*AND    line.id not in ( Select  rel.cle_id
6800 		                         From okc_k_rel_objs rel
6801                                    Where rel.cle_id is not null ); */   ---Commented for ER 16039680
6802 
6803     End if;   --   End if clause for null parameters check
6804 
6805     ---this commit is required for the oks_process_billing table. should not be commented:
6806     commit;
6807     select count(*) into l_line_no from oks_process_billing;
6808 
6809   If l_write_log then
6810     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Number of records in oks_process_billing is '||l_line_no);
6811   End If;
6812 
6813 
6814   END IF;
6815 
6816    /* As part of bug13105205 removed the hardcoded value to l_subrequests and assigning the value from profile skuchima*/
6817   l_subrequests := nvl(FND_PROFILE.VALUE('OKS_NO_CHILD_REQUESTS_MAIN_BILLING'),30);
6818 
6819   If l_write_log then
6820     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Profile option  OKS: Number of Child Requests for Service Contracts Main Billing '||l_subrequests);
6821   End If;
6822 
6823 
6824   IF (p_contract_hdr_id is null) AND -- not a specific contract
6825      (FND_CONC_GLOBAL.request_data is null) AND -- not a restart of parent
6826      (nvl(FND_PROFILE.VALUE('OKS_PARALLEL_WORKER'),'NO') = 'YES') THEN
6827 
6828     -- l_line_no represent total records to be processed here
6829     If l_write_log then
6830       FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Profile option  OKS: Parallel Worker is set to YES');
6831     End If;
6832 
6833     IF (l_line_no > MAX_SINGLE_REQUEST )  THEN
6834       -- populate lo,hi varrays
6835 
6836      /* l_subrequests := 30; Bug 13105205*/  --  hard coded.
6837       l_slot_size :=  ceil(l_line_no / l_subrequests);
6838 
6839       --SELECT ceil(count(*)/10) into l_slot_size  from oks_process_billing;
6840       l_min_boundary  := 1;
6841       l_max_boundary  := l_slot_size;
6842       FOR idx in 1..l_subrequests
6843       LOOP
6844         l_ret := FND_REQUEST.submit_request
6845                       ('OKS','OKS_BILLING_SUB',
6846                                  to_char(idx), -- UI job display
6847                                  null, TRUE, -- TRUE means isSubRequest
6848                                  1, l_flag, p_date,
6849                                  l_min_boundary, l_max_boundary,
6850                         p_prv);
6851 
6852 
6853 
6854 
6855 
6856         IF (l_ret = 0) THEN
6857           errbuf := fnd_message.get;
6858        retcode := 2;
6859           FND_FILE.PUT_LINE (FND_FILE.LOG,'Sub-request failed to submit: '
6860                                                                      || errbuf);
6861           return;
6862         ELSE
6863         If l_write_log then -- by ansraj for bug 14016663
6864           FND_FILE.PUT_LINE (FND_FILE.LOG,'Sub-request '||to_char(l_ret)||
6865                              ' submitted for line numbers '||l_min_boundary||' to '||l_max_boundary);
6866          End if;
6867         END IF;
6868 
6869         IF (l_max_boundary >= l_line_no) THEN
6870           EXIT;
6871         END IF;
6872 
6873         l_min_boundary  := l_max_boundary + 1;
6874         l_max_boundary  := l_max_boundary + l_slot_size;
6875       END LOOP;
6876         -- after submitting sub-requests, set the parent status to PAUSED
6877         -- and set the request_data to a non-null value to detect restart
6878       FND_CONC_GLOBAL.set_req_globals
6879                        (conc_status => 'PAUSED',
6880                                  request_data => to_char(l_subrequests));
6881       errbuf := to_char(l_subrequests) || ' sub-requests submitted';
6882       retcode := 0;
6883       return; -- parent exits and waits for children to finish before restart
6884     END IF; -- l_agg_rec.total
6885 
6886   ELSIF ((FND_CONC_GLOBAL.request_data is not null ) AND
6887         (nvl(FND_PROFILE.VALUE('OKS_PARALLEL_WORKER'),'NO') = 'YES')) THEN
6888     -- restart detected (sub-requests finished)...cleanup and exit.
6889     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => Commiting here');
6890     COMMIT;
6891 
6892     v_cursor := DBMS_SQL.OPEN_CURSOR;
6893     /* Following line is required to avoid GSCC errors at ARU creation.
6894        Concatination of string is required to avoid run time error         */
6895     -- v_truncstring := 'Truncate Table oks';
6896     -- v_truncstring := v_truncstring||'.oks_process_billing';
6897     v_truncstring := 'Truncate Table OKS'||'.oks_process_billing';
6898     DBMS_SQL.PARSE(v_cursor,v_truncstring,DBMS_SQL.V7);
6899     DBMS_SQL.CLOSE_CURSOR(v_cursor);
6900 
6901 
6902     retcode := 0;
6903     return;
6904   END IF; -- parent test
6905 
6906   If l_write_log then
6907     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => B4 Calling OKS_BILLING_PUB.CALCULATE_BILL for sequential run');
6908   End If;
6909 
6910   OKS_BILLING_PUB.CALCULATE_BILL
6911             (l_errbuf, l_retcode, 1, l_flag,
6912              p_date,1 ,l_line_no,
6913              p_prv);
6914 
6915   If l_write_log then
6916     FND_FILE.PUT_LINE(FND_FILE.LOG, 'OKS_BILLING_PUB.Billing_Main => After Calling OKS_BILLING_PUB.CALCULATE_BILL for sequential run');
6917   End If;
6918 
6919   IF (l_retcode = 0)  THEN
6920     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Billing Main is successfully completed');
6921     conc_ret_code := SUCCESS;
6922     RETCODE := 0;
6923   ELSIF (l_retcode = 1)  THEN
6924     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Billing Main is successfully completed with warnings');
6925     conc_ret_code := WARNING;
6926     RETCODE := 1;
6927   ELSE
6928     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Billing Main completed with errors');
6929      conc_ret_code := ERROR;
6930      RETCODE := 2;
6931      DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_MAIN_BILLING');
6932   END IF;
6933 
6934 
6935   COMMIT;
6936 
6937    v_cursor := DBMS_SQL.OPEN_CURSOR;
6938   /* Following line is required to avoid GSCC errors at ARU creation.
6939      Concatination of string is required to avoid run time error     */
6940   --v_truncstring := 'Truncate Table oks';
6941   --v_truncstring := v_truncstring||'.oks_process_billing';
6942   v_truncstring := 'Truncate Table OKS'||'.oks_process_billing';
6943   DBMS_SQL.PARSE(v_cursor,v_truncstring,DBMS_SQL.V7);
6944   DBMS_SQL.CLOSE_CURSOR(v_cursor);
6945 
6946   FND_FILE.PUT_LINE( FND_FILE.LOG,'OKS_BILLING_PUB.Billing_Main  Ends');
6947 
6948 EXCEPTION
6949   WHEN UTL_FILE.INVALID_PATH THEN
6950     FND_FILE.PUT_LINE (FND_FILE.LOG, 'FILE LOCATION OR NAME WAS INVALID');
6951   WHEN UTL_FILE.INVALID_MODE THEN
6952     FND_FILE.PUT_LINE (FND_FILE.LOG, 'FILE OPEN MODE STRING WAS INVALID');
6953   WHEN UTL_FILE.INVALID_FILEHANDLE THEN
6954     FND_FILE.PUT_LINE (FND_FILE.LOG, 'FILE HANDLE WAS INVALID');
6955   WHEN UTL_FILE.INVALID_OPERATION THEN
6956     FND_FILE.PUT_LINE (FND_FILE.LOG, 'FILE IS NOT OPEN FOR WRITTING');
6957   WHEN UTL_FILE.WRITE_ERROR THEN
6958     FND_FILE.PUT_LINE (FND_FILE.LOG,'OS ERROR OCCURRED DURING WRITE OPERATION');
6959 
6960 END Billing_Main;
6961 
6962 
6963 PROCEDURE  Process_Suppress_Credits
6964  (
6965  ERRBUF            OUT NOCOPY VARCHAR2,
6966  RETCODE           OUT NOCOPY NUMBER,
6967  P_CONTRACT_HDR_ID IN         NUMBER,
6968  P_ORG_ID          IN         NUMBER,
6969  P_CATEGORY        IN         VARCHAR2
6970  )
6971  IS
6972 
6973 
6974  l_bclv_tbl_in                        OKS_bcl_PVT.bclv_tbl_type;
6975  l_bclv_tbl_out                       OKS_bcl_PVT.bclv_tbl_type;
6976  l_return_status                      VARCHAR2(10);
6977  l_msg_cnt                            NUMBER;
6978  l_msg_data                           VARCHAR2(2000);
6979 
6980  l_org_id                             NUMBER;
6981  l_retcode               NUMBER;
6982 
6983 --Bug # 4928184	19-JAN-2006	maanand
6984 /* Commenting code as this is giving perf. issue for condition
6985 	 AND   hdr.id = nvl(p_contract_hdr_id,hdr.id)
6986    Hence, breaking this cursor into two cursors depeding on condition
6987    process_cur into process_cur_hdr_id and process_cur
6988 */
6989 
6990 /*
6991 CURSOR process_cur(p_contract_hdr_id IN NUMBER,
6992                    p_category        IN VARCHAR2,
6993                    p_org_id          IN NUMBER)   is
6994   SELECT bcl.cle_id       bcl_cle_id,
6995          bsl.cle_id       bsl_cle_id,
6996          abs(bsl.amount)  bsl_amount,
6997          line.lse_id      bcl_lse_id
6998   FROM okc_k_headers_b      hdr,
6999        oks_bill_sub_lines   bsl,
7000        oks_bill_cont_lines  bcl,
7001        okc_k_lines_b        line
7002    WHERE line.id = bcl.cle_id
7003    AND   hdr.id = line.dnz_chr_id
7004    AND   hdr.id = nvl(p_contract_hdr_id,hdr.id) --Full Table Scan due to nvl condition
7005    AND   hdr.scs_code = nvl(p_category,hdr.scs_code)
7006    --AND   hdr.authoring_org_id = nvl(p_org_id,hdr.authoring_org_id)
7007    AND   hdr.org_id = nvl(p_org_id,hdr.org_id)
7008    AND   bcl.cle_id = line.id
7009    AND   bsl.bcl_id = bcl.id
7010    AND   bcl.bill_action = 'TR'
7011    AND   bcl.btn_id      = -44;
7012 */
7013 
7014 --Cursor to consider when p_contract_hdr_id is not null
7015 
7016 CURSOR process_cur_hdr_id (p_contract_hdr_id IN NUMBER,
7017                            p_category        IN VARCHAR2,
7018                            p_org_id          IN NUMBER)   is
7019 
7020   SELECT bcl.cle_id       bcl_cle_id,
7021          bsl.cle_id       bsl_cle_id,
7022          abs(bsl.amount)  bsl_amount,
7023          line.lse_id      bcl_lse_id
7024   FROM okc_k_headers_b      hdr,
7025        oks_bill_sub_lines   bsl,
7026        oks_bill_cont_lines  bcl,
7027        okc_k_lines_b        line
7028    WHERE line.id = bcl.cle_id
7029    AND   hdr.id = line.dnz_chr_id
7030    AND   hdr.id = p_contract_hdr_id
7031    AND   hdr.scs_code = nvl(p_category,hdr.scs_code)
7032    AND   hdr.org_id = nvl(p_org_id,hdr.org_id)
7033    AND   bcl.cle_id = line.id
7034    AND   bsl.bcl_id = bcl.id
7035    AND   bcl.bill_action = 'TR'
7036    AND   bcl.btn_id      = -44;
7037 
7038 
7039 --Cursor to consider when p_contract_hdr_id is NULL
7040 
7041 CURSOR process_cur  (p_category        IN VARCHAR2,
7042                      p_org_id          IN NUMBER)   is
7043 
7044   SELECT bcl.cle_id       bcl_cle_id,
7045          bsl.cle_id       bsl_cle_id,
7046          abs(bsl.amount)  bsl_amount,
7047          line.lse_id      bcl_lse_id
7048   FROM okc_k_headers_b      hdr,
7049        oks_bill_sub_lines   bsl,
7050        oks_bill_cont_lines  bcl,
7051        okc_k_lines_b        line
7052    WHERE line.id = bcl.cle_id
7053    AND   hdr.id = line.dnz_chr_id
7054    AND   hdr.scs_code = nvl(p_category,hdr.scs_code)
7055    AND   hdr.org_id = nvl(p_org_id,hdr.org_id)
7056    AND   bcl.cle_id = line.id
7057    AND   bsl.bcl_id = bcl.id
7058    AND   bcl.bill_action = 'TR'
7059    AND   bcl.btn_id      = -44;
7060 
7061 
7062 
7063 l_billrep_tbl           OKS_BILL_REC_PUB.bill_report_tbl_type;
7064 l_billrep_tbl_idx       NUMBER;
7065 l_billrep_err_tbl       OKS_BILL_REC_PUB.billrep_error_tbl_type;
7066 l_billrep_errtbl_idx    NUMBER;
7067 
7068 
7069 BEGIN
7070 
7071     l_retcode := 0;
7072 
7073     ----DBMS_TRANSACTION.SAVEPOINT('BEFORE_TRANSACTION');
7074 
7075     l_org_id := p_org_id;
7076 
7077     --mchoudha fixed bug#4729936
7078     --IF (nvl(fnd_profile.value('OKC_VIEW_K_BY_ORG'),'N') = 'Y' ) THEN
7079     --  l_org_id := fnd_profile.value('ORG_ID');
7080     --END IF;
7081 
7082 --Bug # 4928184	19-JAN-2006	maanand
7083 
7084 IF (p_contract_hdr_id is not null) THEN
7085 
7086     FOR cur in process_cur_hdr_id(p_contract_hdr_id ,
7087                                   p_category        ,
7088                                   l_org_id          )
7089     LOOP
7090 
7091       /*Update subline info*/
7092       IF (cur.bcl_lse_id <> 46) THEN
7093         UPDATE oks_k_lines_b
7094         SET credit_amount = nvl(credit_amount,0) +  nvl(cur.bsl_amount,0) ,
7095           suppressed_credit = nvl(suppressed_credit,0) - nvl(cur.bsl_amount,0)
7096         WHERE cle_id = cur.bsl_cle_id;
7097       END IF;
7098 
7099       /*Update topline info*/
7100       UPDATE oks_k_lines_b
7101       SET credit_amount = nvl(credit_amount,0) + nvl(cur.bsl_amount,0) ,
7102           suppressed_credit = nvl(suppressed_credit,0) - nvl(cur.bsl_amount,0)
7103       WHERE cle_id = cur.bcl_cle_id;
7104 
7105     END LOOP;
7106 
7107     /*
7108 	BTN_ID is updated to null for Each record which qualifies the user inputs.
7109 	Order management orginated line can have btn_id = -44.
7110 	To avoid process these records bill_action = 'TR' condition is added
7111 	in below where clause
7112     */
7113 
7114     UPDATE oks_bill_cont_lines bcl
7115     SET    bcl.btn_id = NULL
7116     WHERE  bcl.btn_id = -44
7117     AND    bcl.bill_Action = 'TR'
7118     AND    EXISTS
7119         (SELECT 1 from okc_k_headers_b hdr,
7120                     okc_k_lines_b   line
7121          WHERE line.id = bcl.cle_id
7122 		 AND   hdr.id = line.dnz_chr_id
7123          AND   hdr.id = p_contract_hdr_id
7124          AND   hdr.scs_code = nvl(p_category,hdr.scs_code)
7125          AND   hdr.org_id = nvl(l_org_id,hdr.org_id));
7126 
7127 
7128  ELSE --p_contract_hdr_id is NULL
7129 
7130 	 FOR cur in process_cur(p_category ,
7131                                 l_org_id          )
7132      LOOP
7133 
7134       /*Update subline info*/
7135       IF (cur.bcl_lse_id <> 46) THEN
7136         UPDATE oks_k_lines_b
7137         SET credit_amount = nvl(credit_amount,0) +  nvl(cur.bsl_amount,0) ,
7138           suppressed_credit = nvl(suppressed_credit,0) - nvl(cur.bsl_amount,0)
7139         WHERE cle_id = cur.bsl_cle_id;
7140       END IF;
7141 
7142       /*Update topline info*/
7143       UPDATE oks_k_lines_b
7144       SET credit_amount = nvl(credit_amount,0) + nvl(cur.bsl_amount,0) ,
7145           suppressed_credit = nvl(suppressed_credit,0) - nvl(cur.bsl_amount,0)
7146       WHERE cle_id = cur.bcl_cle_id;
7147 
7148     END LOOP;
7149 
7150     /*
7151 	BTN_ID is updated to null for Each record which qualifies the user inputs.
7152 	Order management orginated line can have btn_id = -44.
7153 	To avoid process these records bill_action = 'TR' condition is added
7154 	in below where clause
7155     */
7156 
7157 	UPDATE oks_bill_cont_lines bcl
7158     SET    bcl.btn_id = NULL
7159     WHERE  bcl.btn_id = -44
7160     AND    bcl.bill_Action = 'TR'
7161     AND    EXISTS
7162         (SELECT 1 from okc_k_headers_b hdr,
7163                     okc_k_lines_b   line
7164          WHERE line.id = bcl.cle_id
7165 		 AND   hdr.id = line.dnz_chr_id
7166          AND   hdr.scs_code = nvl(p_category,hdr.scs_code)
7167          AND   hdr.org_id = nvl(l_org_id,hdr.org_id));
7168 
7169 END IF; --p_contract_hdr_id is not null
7170 
7171 
7172 	--Bug # 4928184	19-JAN-2006	maanand
7173 	--Commented this code
7174     /*
7175     --BTN_ID is updated to null for Each record which qualifies the user inputs.
7176     --Order management orginated line can have btn_id = -44.
7177     --To avoid process these records bill_action = 'TR' condition is added
7178     --in below where clause
7179 
7180 
7181     UPDATE oks_bill_cont_lines bcl
7182     SET    bcl.btn_id = NULL
7183     WHERE  bcl.btn_id = -44
7184     AND    bcl.bill_Action = 'TR'
7185     AND    EXISTS
7186         (SELECT 1 from okc_k_headers_b hdr,
7187                     okc_k_lines_b   line
7188          WHERE line.id = bcl.cle_id
7189       AND   hdr.id = line.dnz_chr_id
7190          AND   hdr.id = nvl(p_contract_hdr_id,hdr.id)
7191          AND   hdr.scs_code = nvl(p_category,hdr.scs_code)
7192          --AND   hdr.authoring_org_id = nvl(l_org_id,hdr.authoring_org_id));
7193          AND   hdr.org_id = nvl(l_org_id,hdr.org_id));
7194 
7195 
7196 
7197       --Once Btn_id is update as null. Calling AR Feeder to process termination
7198       --records. These records are now processed as normal termination records
7199       --in AR Feeder. Calling AR Feeder with P_Prv =3 to process remaing
7200       --termination records
7201    */
7202 
7203 --END Bug # 4928184	19-JAN-2006	maanand
7204 
7205     OKS_ARFEEDER_PUB.Get_REC_FEEDER
7206        (
7207             x_return_status             => l_return_status,
7208             x_msg_count                 => l_msg_cnt,
7209             x_msg_data                  => l_msg_data,
7210             p_flag                      => 2,
7211             p_called_from               => 1,
7212             p_date                      => trunc(sysdate),
7213             p_cle_id                    => NULL,
7214             p_prv                       => 3, -- to interface termination records
7215          p_billrep_tbl               => l_billrep_tbl,
7216          p_billrep_tbl_idx           => l_billrep_tbl_idx,
7217          p_billrep_err_tbl           => l_billrep_err_tbl,
7218          p_billrep_err_tbl_idx       => l_billrep_errtbl_idx
7219        ) ;
7220 
7221     IF (l_return_status <> 'S') THEN
7222       OKS_BILL_REC_PUB.GET_MESSAGE(
7223              l_msg_cnt  => l_msg_cnt,
7224              l_msg_data => l_msg_data);
7225       FND_FILE.PUT_LINE(FND_FILE.LOG,'Error: Failed in AR FEEDER');
7226       ---DBMS_TRANSACTION.ROLLBACK_SAVEPOINT('BEFORE_TRANSACTION');
7227       l_retcode := 1;
7228     END IF;
7229 
7230   IF (l_retcode = 0)  THEN
7231     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Supress credit is successfully completed');
7232     conc_ret_code := SUCCESS;
7233     RETCODE := 0;
7234   END IF;
7235 
7236   COMMIT;
7237 
7238 EXCEPTION
7239  WHEN OTHERS THEN
7240     FND_FILE.PUT_LINE( FND_FILE.LOG, 'Supress credit completed with Errors');
7241     conc_ret_code := ERROR;
7242     RETCODE := 2;
7243     OKC_API.set_message(G_APP_NAME, G_UNEXPECTED_ERROR,
7244                         G_SQLCODE_TOKEN,SQLCODE,G_SQLERRM_TOKEN,SQLERRM);
7245 End  Process_Suppress_Credits;
7246 
7247 End OKS_BILLING_PUB;