DBA Data[Home] [Help]

PACKAGE BODY: APPS.JAI_RCV_EXCISE_PROCESSING_PKG

Source


1 PACKAGE BODY jai_rcv_excise_processing_pkg AS
2 /* $Header: jai_rcv_exc_prc.plb 120.38.12020000.4 2012/12/21 15:14:47 vkavulur ship $ */
3 
4 /* --------------------------------------------------------------------------------------
5 Filename:
6 
7 Change History:
8 
9 Date         Bug         Remarks
10 ---------    ----------  -------------------------------------------------------------
11 08-Jun-2005  Version 116.2 jai_rcv_exc_prc -Object is Modified to refer to New DB Entity names in place of Old DB Entity Names
12 		as required for CASE COMPLAINCE.
13 
14 13-Jun-2005  4428980     File Version: 116.3
15                          Ramananda for bug#4428980. Removal of SQL LITERALs is done
16 
17 27-Jul-2005  4516667     Added by Lakshmi Gopalsami Version 120.2
18                          (1) Removed CVD from additional amount. This is
19 			     accidentally added to additional excise. This is
20 			     done in PROCEDURE rg23_d_entry.
21                          (2) Rounded p_rate_per_unit to 4 decimal places in
22  			     jai_cmn_rg_23d_trxs_pkg.insert_row
23 
24 27-Jul-2005  4516678     Added by Lakshmi Gopalsami Version 120.3
25                          Issue :
26                           a.Whenever a user creates a receipt for a CGIN or
27 			    CGEX item, 50% cenvat is claimed. If he/she intends to
28 			    return the entire quantity in the receipt, he/she must
29 			    claim the remaining 50% cenvat first and then do the
30 			    RTV. Else, the system should throw an error.
31 
32                           b.After creating a receipt for a CGIN or CGEX item,
33 			    if the user does a partial RTV on that receipt,
34 			    the system should allow it although the remaining
35 			    50% CENVAT has not been claimed.
36 
37 			 Fix   :
38                           a. Added code to check this in Package jai_rcv_tax_pkg
39 			  (1) Created new procedure pick_register_type to get the
40 			  register_type depending on the item_class
41 			  (2)Created two new cursors  c_fetch_receive_quantity
42 			  and c_fetch_transaction_Quantity to get the
43 			  quantity received for the receipt and RTV transactions
44 			  (3) Added  nvl(cenvat_amount,0) in
45 			  cursor c_fetch_unclaim_cenvat
46 
47 			  Dependencies(Functional)
48 			  ------------------------
49 			  jai_rcv_tax.plb Version 120.2
50 
51                           b. The cenvat receivable accounts were not getting passed
52 			     in case of a CGIN/CGEX item.
53 			     Thus, the system is throwing an error.
54 			     Commented the generic assignment for cenvat
55 			     accounting entries and added the condition for
56 			     CGIN and CGEX item class in procedure
57 			     accounting_entries.
58 
59 
60 02-May-06    5176133   Added by rallamse version 120.4
61                        Issue : Object not getting compiled
62                        Fix:
63                        Modified the multi-line statement :
64                        r_diff_tax.basic_excise  := r_rtv_dtls.excise_basis_amt
65                        to a single line statement
66 17-Jul-2006  5378630 Aiyer, File Version 120.6
67                       Issue:-
68                         India Receiving transaction processor fails during validation phase for RMA
69                         type of transactions.
70 
71                       Fix:-
72                        During DFF elimination one elsif statment in the procedure validate_transaction got missed out
73                        due to which for RMA TYPE of either "PRODUCTION INPUT" or "GOODS RETURN" the code used to fail.
74                        To restrict this added back the if condition to check that the failure should happen only for PO receipt with FGIN or FGEX type
75                        of item class. The new IF condition now checks for source_document_type in PO or REQUISITION
76                        Also converted the reference of RMA TYPE "FG RETURN" into "GOODS RETURN" as FG return is not as per the abbreviation
77                        standard
78 
79 14-feb-2007  4704957,5841749  vkaranam,File version 120.11
80                               4704957-Forward porting the changes in 11i bug 4683156(return to vendor report shows 50% cenvat amount for partial rtv)
81                               5841749-Forward porting the changes in 11i bug 5647216(doing rtv for partial quantity, after claiming 50%, is giving error)
82 
83 
84 22-Feb-2007 5155138 srjayara, file version 120.12
85 			Forward port for 11i bug 5110511
86 			Issue: No accounting should be passed for Excise and Cess in case of RMA receipt for a Trading
87 			       organization.
88 			Fix: When call to accounting_entries is made for Trading organization a check is added so that
89 			     the call is made only if the attribute category is not India RMA Receipt.
90 16-APR-2007   Bug 5989740 Vkaranam for bug 5989740, File version 120.13
91               Forward porting the changes in 115 bug 5907436(Enh:Handling Secondary And Higher Education Cess)
92 
93 
94 17 14-may-07   kunkumar made changes for Budget and ST by IO and Build issues resolved	.
95 
96 04-Jun-2007  ssawant for bug#6084771,File Version 120.18
97                 Issue: UNABLE TO CLAIM CENVAT
98                   Fix: Added reference_id while jai_rcv_accounting_pkg.process_transaction to avoid
99                        the Duplicate accounting error.
100 
101 08-Jun-2007  CSahoo for bug#6078460, File Version 120.20
102 						 Issue:Excise Expense entry is getting generated for Excise and Education cess but
103 									 not for the SHE cess. The accounting entrty needs to be generated for the
104 									 same.
105 						 Fix: Added code for SH Education Cess Acccounting Entries in the procedure rtv_processing_for_ssi.
106 
107 9-Nov-2008  Bug 5752026 (FP for bug 5747435) File version 120.25
108              Issue : Total duty amount includes addl. CVD for the invoices flown from receipts.
109                      This is not consistent with what we have for manual entries.
110              Fix   : Excluded the addl. CVD when calculating the total duty amount in procedure
111                      rg23_d_entry.
112 23-jun-2009 vkaranam for bug#4767479
113             forwardported the changes done in 115 bug#4751114
114 	    Issue:  India Rg23 Part II report also picks autoclaimed entry for RTV against same Receipt exise invoice no instead of showing as a
115                   seperate record.
116                 Fix:
117                   The issue was coming as the excise invoice no generated for autoclaimed entry for RTV was same as that of the receipt.
118                   Changes are made in rg23_part_ii_entry procedure to append '/1' to the receipt's
119                   excise invoice no and assign it to the excise invoice no of autoclaimed entry for RTV
120 
121 14-aug-2009 vkaranam for bug#4750798
122 	    fwdported the changes done in 115 bug 4619176   /7229349
123 22-feb-2010  vkaranam for bug#9346733
124              Issue:
125              CENVAT CREDIT AMOUNT IS ROUNDING OFF TO THE NEAREST RUPEE WHILE DELIVERY OF MATErial
126              to non bonded subinvetory
127              fix details:
128              commented the call to do_Canvat_rounding in process_transaction procedure.
129 
130 17-mar-2010 vkaranam for bug#9478222
131             issue:
132             RMA CENVAT CLAIM CENVAT_RG_PKG.PROCESS_TRANSACTION->ORA-01722: INVALID NUMBER, S
133             Fix:
134             added to_char(p_transaction_id) in  CURSOR cur_rg1_register_id
135 21-jul-2010 vkaranam for bug#9854329
136                 ISSUE: ADDITIONAL CVD IS NOT HITTING ANY DUTY BOOK AT THE TIME OF MAKING RTV.
137                 FIX: added a new column CENVAT_CR_REVRSL_FLAG in the table ja_in_hr_organization_units.
138                      Depending on the value of this column, it would be decided to reverse the CVD, additional CVD, CVD cess and CVD SH cess
139                      type of taxes when we do a RTV. If the flag is 'Y', then the CVD, additional CVD, CVD cess and CVD SH cess type of taxes
140                      would get reversed. But if it is 'N', then these taxes neednot be reversed.
141                      Added the code for the above changes.
142 
143  22-Dec-2011  Bug 13514510
144                Issue - Cenvat claim is not supported for ISO receipt of FGIN/FGEX items.
145               Fix - Added 'REQ' to the list of source document types which are allowed for cenvat claim when item class is FGIN/FGEX.
146 
147  03-Oct-2012  Bug 13362352
148              Issue - EXCISE ACCOUNTING FOR OSP ITEMS RECEIPTS IS GETS REVERSED WHEN DELIVERED TO SHOP FLOOR.
149              Fix - The following if condition is added in process transaction before call to accounting_entries procedure
150                   If transaction type is DELIVER then destination type code should not be SHOP FLOOR OR
151                   If transaction type is RETURN TO RECEIVING then prent destination type code should not be SHOP FLOOR OR
152                   The transaction type can be MATCH, RECEIVE or 'RETURN TO VENDOR'.
153                   Call to update rg23 part ii register and accounting entries is made only if the above conditions are satisfied.
154 
155  21-Dec-2012  vkavulur for bug #14852106
156                  Issue : CENVAT CORRECTION ACCOUNTING NOT HAPPENING
157                  Fix : In the validate_transaction procedure there is a validations added to mark the cenvat rg status flag
158                  as 'X' if the transaction type is of deliver. Added few more conditions in the validation to allow cenvat
159                  processing if the current transaction type is 'CORRECT' and if excise taxes exist for the receipt.
160 
161 --------------------------------------------------------------------------------------*/
162 
163   FUNCTION get_apportioned_tax(
164     pr_tax      IN  TAX_BREAKUP,
165     p_factor    IN  NUMBER,
166     p_claim_type IN VARCHAR2     -- Date 30/10/2006 Bug 5228046 added by SACSETHI
167   ) RETURN TAX_BREAKUP IS
168 
169     r_tax   TAX_BREAKUP;
170     ln_factor     NUMBER;
171     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.get_apportioned_tax';
172 
173   BEGIN
174 
175     if p_factor IS NULL  THEN   /*Commented the condition  or p_factor = 0  the changes for  bug # 8644480 */
176       ln_factor := 1;
177     else
178       ln_factor := p_factor;
179     end if;
180 
181     r_tax.basic_excise     := pr_tax.basic_excise     * ln_factor;
182     r_tax.addl_excise      := pr_tax.addl_excise      * ln_factor;
183     r_tax.other_excise     := pr_tax.other_excise     * ln_factor;
184     r_tax.cvd              := pr_tax.cvd              * ln_factor;
185     r_tax.non_cenvat       := pr_tax.non_cenvat       * ln_factor;
186     r_tax.excise_edu_cess  := pr_tax.excise_edu_cess  * ln_factor;
187     r_tax.cvd_edu_cess     := pr_tax.cvd_edu_cess     * ln_factor;
188      /*added the following by vkaranam for budget 07 impact - bug#5989740*/
189     --start
190     r_tax.sh_exc_edu_cess  := pr_tax.sh_exc_edu_cess  * ln_factor;
191     r_tax.sh_cvd_edu_cess  := pr_tax.sh_cvd_edu_cess  * ln_factor;
192     --end
193 
194 
195      -- Date 30/10/2006 Bug 5228046 added by sacsethi
196     IF p_claim_type ='2ND CLAIM' THEN
197        r_tax.addl_cvd       := 0;
198     ELSE
199        r_tax.addl_cvd       := pr_tax.addl_cvd;
200     END IF;
201     RETURN r_tax;
202 
203   EXCEPTION
204     WHEN OTHERS THEN
205     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
206     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
207     app_exception.raise_exception;
208   END get_apportioned_tax;
209 
210 
211   -- Start, following procedures added by Vijay Shankar for Bug#3940588. RECEIPTS DEPLUG
212   PROCEDURE get_changed_vendor_dtls(
213     p_receive_trx_id      IN  NUMBER,
214     p_shipment_line_id    IN  NUMBER,
215     p_vendor_id OUT NOCOPY NUMBER,
216     p_vendor_site_id OUT NOCOPY NUMBER
217   ) IS
218 
219     CURSOR c_receipt_cenvat_dtl(cp_transaction_id IN NUMBER) IS
220       SELECT vendor_changed_flag, vendor_id, vendor_site_id
221       FROM JAI_RCV_CENVAT_CLAIMS
222       WHERE transaction_id = cp_transaction_id;
223 
224     r_receipt_cenvat_dtl  c_receipt_cenvat_dtl%ROWTYPE;
225     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.get_changed_vendor_dtls';
226 
227   BEGIN
228 
229     OPEN c_receipt_cenvat_dtl(p_receive_trx_id);
230     FETCH c_receipt_cenvat_dtl INTO r_receipt_cenvat_dtl;
231     CLOSE c_receipt_cenvat_dtl;
232 
233     IF r_receipt_cenvat_dtl.vendor_changed_flag = 'Y' THEN
234       p_vendor_id       := r_receipt_cenvat_dtl.vendor_id;
235       p_vendor_site_id  := r_receipt_cenvat_dtl.vendor_site_id;
236     END IF;
237   EXCEPTION
238     WHEN OTHERS THEN
239     p_vendor_id := null;
240     p_vendor_site_id := null;
241     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
242     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
243     app_exception.raise_exception;
244   END get_changed_vendor_dtls;
245 
246   /* Procedure Created by Vijay Shankar for Bug#3940588. RECEIPTS DEPLUG
247      POST PROCESSOR of CENVAT */
248   PROCEDURE post_cenvat_processor(
249     p_transaction_id            IN  NUMBER,
250     p_cenvat_claimed_ptg        IN  NUMBER,
251     p_cenvat_claimed_amt        IN  NUMBER,
252     p_other_cenvat_claimed_amt  IN  NUMBER
253   ) IS
254 
255     r_trx                         c_trx%ROWTYPE;
256     lv_transaction_type           JAI_RCV_TRANSACTIONS.transaction_type%TYPE;
257 
258      --start additions for bug#4750798
259 
260   CURSOR c_rtv_qty(cp_transaction_id  jai_rcv_transactions.transaction_id%TYPE)
261   IS
262   select quantity  from jai_rcv_transactions
263   WHERE   transaction_id = cp_transaction_id;
264 
265  cursor c_fetch_base_correct_qty(p_transaction_id number) is
266     select nvl(sum(quantity),0)
267     from   rcv_transactions
268     where  parent_transaction_id = p_transaction_id
269   and    transaction_type='CORRECT';
270 
271   v_rtv_qty                     jai_rcv_transactions.quantity%TYPE;
272   v_excise_rf                    NUMBER;
273   v_excise_edu_cess_rf          NUMBER;
274   v_excise_she_cess_rf          NUMBER;
275   v_base_correct_quantity       NUMBER;
276   v_changed_cenvat_quantity     NUMBER;
277 
278 
279 ---end additions for bug#4750798
280 
281 
282     ln_trx_qty_for_2nd_claim      NUMBER;
283     ln_trx_equivalent_of_receive  NUMBER;
284     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.post_cenvat_processor';
285 
286 
287 
288 
289   BEGIN
290 
291     OPEN c_trx(p_transaction_id);
292     FETCH c_trx INTO r_trx;
293     CLOSE c_trx;
294 
295     IF r_trx.transaction_type = 'CORRECT' THEN
296       lv_transaction_type := r_trx.parent_transaction_type;
297     ELSE
298       lv_transaction_type := r_trx.transaction_type;
299     END IF;
300 
301     -- update the quantity for 2nd claim only during the first claim of transaction line and that too only for CG Items only
302     IF p_cenvat_claimed_ptg = 50 AND r_trx.item_class IN ('CGIN','CGEX') THEN
303 
304       IF lv_transaction_type IN ('DELIVER','RETURN TO RECEIVING','RETURN TO VENDOR') THEN
305         ln_trx_equivalent_of_receive := jai_rcv_trx_processing_pkg.get_equivalent_qty_of_receive(r_trx.transaction_id);
306       ELSE
307         ln_trx_equivalent_of_receive := r_trx.quantity;
308       END IF;
309 
310       IF lv_transaction_type IN ('RECEIVE', 'MATCH')
311         -- non bonded RTR case i.e goods are returned to receiving from non bonded subinventory
312         or (lv_transaction_type = 'RETURN TO RECEIVING' and nvl(r_trx.loc_subinv_type, 'X') = 'N')
313       THEN
314         -- only during 1st Claim the quantity should be updated
315         ln_trx_qty_for_2nd_claim  := ln_trx_equivalent_of_receive;
316 
317       ELSIF lv_transaction_type = 'RETURN TO VENDOR'
318         -- non bonded delivery case. i.e goods are delivered to non bonded subinventory
319         or (lv_transaction_type = 'DELIVER' and nvl(r_trx.loc_subinv_type, 'X') = 'N')
320       THEN
321         ln_trx_qty_for_2nd_claim  := -1 * ln_trx_equivalent_of_receive;
322 
323       ELSE
324         ln_trx_qty_for_2nd_claim := 0;
325       END IF;
326 
327     ELSE
328     --start additions for bug#4750798
329              IF lv_transaction_type = 'RETURN TO VENDOR'
330         THEN
331             OPEN c_rtv_qty(r_trx.transaction_id);
332             FETCH c_rtv_qty INTO v_rtv_qty;
333             CLOSE c_rtv_qty;
334             ln_trx_qty_for_2nd_claim  := -1*v_rtv_qty;
335         ELSE
336              ln_trx_qty_for_2nd_claim := 0;
337         END IF;
338 	 --end additions for bug#4750798
339 
340     END IF;
341 
342     /* Start, Vijay Shankar for Bug#3940588 */
343     IF r_trx.transaction_type IN ('RECEIVE', 'MATCH') THEN
344       UPDATE JAI_RCV_CENVAT_CLAIMS
345       SET cenvat_claimed_ptg = p_cenvat_claimed_ptg,
346           cenvat_sequence = nvl(cenvat_sequence, 0) + 1,
347           cenvat_claimed_amt = nvl(cenvat_claimed_amt, 0) + p_cenvat_claimed_amt,
348           other_cenvat_claimed_amt = nvl(other_cenvat_claimed_amt,0) + p_other_cenvat_claimed_amt,
349           quantity_for_2nd_claim = nvl(quantity_for_2nd_claim,0) + nvl(ln_trx_qty_for_2nd_claim, 0),
350           last_update_date = sysdate,
351           last_updated_by = fnd_global.user_id,
352           last_update_login = fnd_global.login_id
353       WHERE transaction_id = p_transaction_id;
354 
355       -- this is to set the flag that is shown in JAINPORE, which signifies that the cenvat is claimed or not
356       update JAI_RCV_LINES
357       set claim_modvat_flag = 'Y',
358           last_update_date = sysdate,
359           last_updated_by = fnd_global.user_id,
360           last_update_login = fnd_global.login_id
361       where transaction_id = p_transaction_id;
362 
363     ELSE
364 
365       UPDATE JAI_RCV_CENVAT_CLAIMS
366       SET quantity_for_2nd_claim = nvl(quantity_for_2nd_claim,0) + ln_trx_qty_for_2nd_claim,
367           last_update_date = sysdate,
368           last_updated_by = fnd_global.user_id,
369           last_update_login = fnd_global.login_id
370       WHERE transaction_id = r_trx.tax_transaction_id;
371 
372     END IF;
373     /* End, Vijay Shankar for Bug#3940588 */
374 
375 
376       --start additions for bug#4750798
377                 get_excise_tax_rounding_factor(
378                    p_transaction_id => r_trx.tax_transaction_id,
379                    p_Excise_rf => v_excise_rf,
380                    p_Excise_edu_cess_rf => v_excise_edu_cess_rf,
381                    p_Excise_she_cess_rf => v_excise_she_cess_rf
382                 );
383 
384   FND_FILE.put_line(FND_FILE.log, '^CENVAT_RG_PKG.post_cenvat_processor. v_excise_rf->'||v_excise_rf||'-v_excise_edu_cess_rf->'||v_excise_edu_cess_rf||'-v_excise_she_cess_rf->'||v_excise_she_cess_rf);
385 
386    IF r_trx.transaction_type = 'RECEIVE' THEN
387    UPDATE  JAI_RCV_CENVAT_CLAIMS
388            SET   cenvat_amt_for_2nd_claim = ROUND((NVL(cenvat_amount,0))-(NVL(cenvat_claimed_amt,0)),v_excise_rf),
389            other_cenvat_amt_for_2nd_claim = ROUND((NVL(other_cenvat_amt,0))-(NVL(other_cenvat_claimed_amt,0)),v_excise_edu_cess_rf) ,
390          last_update_date  = sysdate,
391            last_updated_by   = fnd_global.user_id,
392            last_update_login = fnd_global.login_id
393            WHERE   transaction_id = r_trx.tax_transaction_id;
394   ELSE
395 
396                 ln_trx_equivalent_of_receive := jai_rcv_trx_processing_pkg .get_equivalent_qty_of_receive(r_trx.tax_transaction_id);
397 
398                 open  c_fetch_base_correct_qty(r_trx.tax_transaction_id);
399                  fetch c_fetch_base_correct_qty into v_base_correct_quantity;
400                 close c_fetch_base_correct_qty;
401 
402                         v_changed_cenvat_quantity := nvl(v_base_correct_quantity,0) + ln_trx_equivalent_of_receive;
403 
404                 FND_FILE.put_line(FND_FILE.log, '^CENVAT_RG_PKG.post_cenvat_processor.ln_trx_equivalent_of_receive->'||ln_trx_equivalent_of_receive);
405                 FND_FILE.put_line(FND_FILE.log, '^CENVAT_RG_PKG.post_cenvat_processor.v_changed_cenvat_quantity->'||v_changed_cenvat_quantity);
406 
407                 UPDATE JAI_RCV_CENVAT_CLAIMS
408                 SET cenvat_amt_for_2nd_claim = ROUND(nvl(v_changed_cenvat_quantity,   0) *nvl(cenvat_amount,   0) / nvl(ln_trx_equivalent_of_receive,   0),   v_excise_rf) -cenvat_claimed_amt,
409                   other_cenvat_amt_for_2nd_claim = ROUND(nvl(v_changed_cenvat_quantity,   0) *nvl(other_cenvat_amt,   0) / nvl(ln_trx_equivalent_of_receive,   0),   v_excise_edu_cess_rf) -other_cenvat_claimed_amt,
410                   last_update_date = sysdate,
411                   last_updated_by = fnd_global.user_id,
412                   last_update_login = fnd_global.login_id
413                 WHERE transaction_id = r_trx.tax_transaction_id;
414 
415   END IF;
416 --end additions for bug#4750798
417 
418   EXCEPTION
419     WHEN OTHERS THEN
420     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
421     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
422     app_exception.raise_exception;
423   END post_cenvat_processor;
424 
425   /* Start of bug 5365346. Created by Lakshmi Gopalsami */
426   PROCEDURE  update_RTV_Diff_value
427             (pr_base_trx            IN jai_rcv_excise_processing_pkg.c_base_trx%ROWTYPE,
428 	     pr_tax                 IN jai_rcv_excise_processing_pkg.c_trx%ROWTYPE,
429   	     pr_diff_tax            IN TAX_BREAKUP,
430 	     p_source_reg           IN VARCHAR2 ,
431 	     p_register_entry_type  IN VARCHAR2 ,
432              p_register_id          IN OUT NOCOPY NUMBER,
433 	     p_simulate_flag        IN  VARCHAR2,
434 	     p_codepath             IN OUT NOCOPY VARCHAR2,
435 	     p_process_status       OUT NOCOPY VARCHAR2,
436 	     p_process_message      OUT NOCOPY VARCHAR2
437 	    ) IS
438 
439     ln_tr_amount       NUMBER ;
440     ln_opening_balance NUMBER ;
441     ln_closing_balance NUMBER ;
442     ln_dr_basic        NUMBER ;
443     ln_dr_addl         NUMBER ;
444     ln_dr_other        NUMBER ;
445     ln_other_tax_debit NUMBER ;
446     ln_cr_basic        NUMBER ;
447     ln_cr_addl         NUMBER ;
448     ln_cr_other        NUMBER ;
449     ln_other_tax_credit  NUMBER ;
450     ln_transaction_id   NUMBER(10);
451     lv_transaction_type VARCHAR2(50);
452     ln_register_id      NUMBER ;
453     lv_remarks          JAI_CMN_RG_PLA_TRXS.REMARKS%TYPE;
454     lv_statement_id     VARCHAR2(5);
455     lv_process_status   VARCHAR2(2);
456     lv_process_message  VARCHAR2(2000);
457     lv_register_type    JAI_CMN_RG_23AC_II_TRXS.register_type%TYPE;
458     ln_reg_dr           NUMBER ;
459     ln_reg_cr           NUMBER ;
460     lv_upd_opening_bal_dr NUMBER ;
461     lv_upd_opening_bal_cr NUMBER ;
462     ln_ex_cess_diff     NUMBER ;
463     ln_cvd_cess_diff    NUMBER ;
464     ln_ex_sh_cess_diff     NUMBER ;
465     ln_cvd_sh_cess_diff    NUMBER ;
466 
467 
468   BEGIN
469 
470    p_codepath := jai_general_pkg.plot_codepath(1, p_codepath,
471    'jai_rcv_excise_processing_pkg.update_RTV_Diff_value', 'START');
472 
473 
474    lv_statement_id := '1';
475    p_codepath := jai_general_pkg.plot_codepath(1, p_codepath);
476 
477    fnd_file.put_line(FND_FILE.LOG, ' Inside Update RTV Diff value ->statement id '
478                                     || lv_statement_id);
479    fnd_file.put_line(FND_FILE.LOG, ' source register ' || p_source_reg);
480    /* If source register is PLA */
481    IF p_source_reg = 'PLA' THEN
482       IF pr_tax.transaction_type = 'CORRECT' THEN
483         lv_transaction_type := pr_tax.parent_transaction_type;
484       ELSE
485         lv_transaction_type := pr_tax.transaction_type;
486       END IF;
487       lv_statement_id := '2';
488       p_codepath := jai_general_pkg.plot_codepath(2, p_codepath);
489       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
490       jai_cmn_rg_pla_trxs_pkg.get_trxn_type_and_id(lv_transaction_type,
491                            pr_base_trx.source_document_code,
492 			   ln_transaction_id);
493       lv_statement_id := '3';
494       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath);
495       FOR c_get_register_id IN
496            (SELECT register_id ,
497 	           cr_basic_ed,
498 		   cr_additional_ed,
499 		   cr_other_ed,
500 		   dr_basic_ed,
501 		   dr_additional_ed,
502 		   dr_other_ed,
503 		   other_tax_credit,
504 		   other_tax_debit,
505 		   remarks
506             FROM jai_cmn_rg_pla_trxs
507 	    WHERE organization_id = pr_tax.organization_id
508 	      AND location_id = pr_tax.location_id
509 	      AND inventory_item_id = pr_tax.inventory_item_id
510 	      AND ref_document_id = pr_tax.transaction_id
511 	      AND transaction_source_num = ln_transaction_id
512 	    )
513       LOOP
514         lv_statement_id := '4';
515 	p_codepath := jai_general_pkg.plot_codepath(4, p_codepath);
516         fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
517         ln_register_id := c_get_register_id.register_id;
518 	ln_dr_basic    := c_get_register_id.dr_basic_ed;
519 	ln_dr_addl     := c_get_register_id.dr_additional_ed;
520 	ln_dr_other    := c_get_register_id.dr_other_ed;
521 	ln_other_tax_debit := c_get_register_id.other_tax_debit;
522 	ln_cr_basic    := c_get_register_id.cr_basic_ed;
523 	ln_cr_addl     := c_get_register_id.cr_additional_ed;
524 	ln_cr_other    := c_get_register_id.cr_other_ed;
525 	ln_other_tax_credit := c_get_register_id.other_tax_credit;
526 	lv_remarks     := c_get_register_id.remarks || 'RTV ADjustment';
527 	fnd_file.put_line(FND_FILE.LOG, ' RTV Adjustment values --> ');
528 	fnd_file.put_line(FND_FILE.LOG, ' Register id ' || ln_register_id);
529 	fnd_file.put_line(FND_FILE.LOG, 'CR: Basic--Addl--Other--cess'||
530                          ln_cr_basic||'--'||ln_cr_addl||'--'||
531 			 ln_cr_other||'--'||ln_other_tax_credit);
532 	fnd_file.put_line(FND_FILE.LOG, 'DR: Basic--Addl--Other--cess'||
533                          ln_dr_basic||'--'||ln_dr_addl||'--'||
534 			 ln_dr_other||'--'||ln_other_tax_debit);
535       END LOOP ;
536 
537       lv_statement_id := '5';
538       p_codepath := jai_general_pkg.plot_codepath(5, p_codepath);
539       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
540 
541       lv_statement_id := '6';
542       p_codepath := jai_general_pkg.plot_codepath(6, p_codepath);
543       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
544 
545       lv_statement_id := '7';
546       p_codepath := jai_general_pkg.plot_codepath(7, p_codepath);
547       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
548       /* Set the value of credit and debit basic, additional and other */
549 
550       IF p_register_entry_type = CENVAT_DEBIT THEN
551          lv_statement_id := '8';
552 	 p_codepath := jai_general_pkg.plot_codepath(8, p_codepath);
553          lv_upd_opening_bal_dr := ln_dr_basic + ln_dr_addl + ln_dr_other;
554          ln_dr_basic   := ln_dr_basic+ pr_diff_tax.basic_excise;
555          ln_dr_addl    := ln_dr_addl + pr_diff_tax.addl_excise + pr_diff_tax.cvd;
556          ln_dr_other   := ln_dr_other + pr_diff_tax.other_excise;
557          ln_other_tax_debit  := ln_other_tax_debit +
558 	                        pr_diff_tax.excise_edu_cess +
559 				pr_diff_tax.cvd_edu_cess + nvl(pr_diff_tax.sh_exc_edu_cess,0) +
560 				 nvl(pr_diff_tax.sh_cvd_edu_cess,0); --Bgowrava for Bug#6071509, added SH related cess
561 	 ln_reg_dr     := nvl(pr_diff_tax.basic_excise,0) +
562                           nvl(pr_diff_tax.addl_excise,0)+ nvl(pr_diff_tax.cvd,0) +
563 			  nvl(pr_diff_tax.other_excise,0);
564          fnd_file.put_line(FND_FILE.LOG, ' Reg. dr' || ln_reg_dr);
565       ELSE
566          lv_statement_id := '10';
567          lv_upd_opening_bal_cr := ln_cr_basic + ln_cr_addl + ln_cr_other;
568          fnd_file.put_line(FND_FILE.LOG, ' Reg. open cr' || lv_upd_opening_bal_cr);
569          ln_cr_basic   := ln_cr_basic + pr_diff_tax.basic_excise;
570          ln_cr_addl    := ln_cr_addl + pr_diff_tax.addl_excise + pr_diff_tax.cvd;
571          ln_cr_other   := ln_cr_other + pr_diff_tax.other_excise;
572          ln_other_tax_credit  := ln_other_tax_credit +
573 	                         pr_diff_tax.excise_edu_cess +
574 				 pr_diff_tax.cvd_edu_cess + nvl(pr_diff_tax.sh_exc_edu_cess,0) +
575 				 nvl(pr_diff_tax.sh_cvd_edu_cess,0); --Bgowrava for Bug#6071509, added SH related cess
576 	 ln_reg_cr     := nvl(pr_diff_tax.basic_excise,0) +
577                           nvl(pr_diff_tax.addl_excise,0)+ nvl(pr_diff_tax.cvd,0) +
578 			  nvl(pr_diff_tax.other_excise,0);
579          fnd_file.put_line(FND_FILE.LOG, ' Reg. cr' || ln_reg_cr);
580       END IF;
581 
582       /* Calculate the transaction amount difference to be updated */
583 
584       ln_tr_amount :=  nvl(ln_reg_cr,0) - nvl(ln_reg_dr,0);
585 
586       fnd_file.put_line(FND_FILE.LOG, ' Trx amt ' || ln_tr_amount);
587 
588             /*  Get the balance details */
589       jai_cmn_rg_balances_pkg.get_balance(
590          P_ORGANIZATION_ID   => pr_tax.organization_id,
591          P_LOCATION_ID       => pr_tax.location_id,
592          P_REGISTER_TYPE     => 'PLA',
593          P_OPENING_BALANCE   => ln_opening_balance,
594          P_PROCESS_STATUS    => lv_process_status,
595          P_PROCESS_MESSAGE   => lv_process_message
596        );
597       lv_statement_id := '9';
598       p_codepath := jai_general_pkg.plot_codepath(9, p_codepath);
599       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
600       ln_closing_balance := ln_opening_balance + ln_tr_amount;
601       ln_opening_balance := ln_opening_balance - (nvl(lv_upd_opening_bal_cr,0) - nvl(lv_upd_opening_bal_dr,0));
602 
603       fnd_file.put_line(FND_FILE.LOG, 'Opening balance to be updated ' || ln_opening_balance);
604 
605       lv_statement_id := '10';
606       p_codepath := jai_general_pkg.plot_codepath(10, p_codepath);
607       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
608 
609       /* Update PLA with the latest difference amount to the existing amount */
610       JAI_CMN_RG_PLA_TRXS_PKG.update_row(
611          P_REGISTER_ID         => ln_register_id,
612 	 P_CR_BASIC_ED         => ln_cr_basic,
613 	 P_CR_ADDITIONAL_ED    => ln_cr_addl,
614 	 P_CR_OTHER_ED         => ln_cr_other,
615 	 P_DR_BASIC_ED         => ln_dr_basic,
616 	 P_DR_ADDITIONAL_ED    => ln_dr_addl,
617 	 P_DR_OTHER_ED         => ln_dr_other,
618 	 P_REMARKS             => lv_remarks,
619 	 P_OPENING_BALANCE     => ln_opening_balance,
620 	 P_CLOSING_BALANCE     => ln_closing_balance,
621 	 P_OTHER_TAX_CREDIT    => ln_other_tax_credit,
622 	 P_OTHER_TAX_DEBIT     => ln_other_tax_debit
623          );
624       lv_statement_id := '11';
625       p_codepath := jai_general_pkg.plot_codepath(11, p_codepath);
626       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
627       /* Update the balances with the latest amount*/
628 
629       jai_cmn_rg_balances_pkg.update_row(
630         p_organization_id   => pr_tax.organization_id,
631         p_location_id       => pr_tax.location_id,
632         p_register_type     => 'PLA',
633 	p_amount_to_be_added=> ln_tr_amount,
634 	p_simulate_flag     => p_simulate_flag,
635 	p_process_status    => lv_process_status,
636 	p_process_message   => lv_process_message
637      );
638      p_register_id := ln_register_id;
639    /* If source register is RG23 part II */
640    ELSE
641       lv_register_type := jai_general_pkg.get_rg_register_type(pr_tax.item_class);
642       IF pr_tax.transaction_type = 'CORRECT' THEN
643         lv_transaction_type := pr_tax.parent_transaction_type;
644       ELSE
645         lv_transaction_type := pr_tax.transaction_type;
646       END IF;
647       lv_statement_id := '2';
648       p_codepath := jai_general_pkg.plot_codepath(2, p_codepath);
649       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
650       jai_cmn_rg_23ac_ii_pkg.get_trxn_type_and_id(lv_transaction_type,
651                            pr_base_trx.source_document_code,
652 			   ln_transaction_id);
653       lv_statement_id := '3';
654       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath);
655       FOR c_get_register_id IN
656            (SELECT register_id ,
657 	           cr_basic_ed,
658 		   cr_additional_ed,
659 		   cr_other_ed,
660 		   dr_basic_ed,
661 		   dr_additional_ed,
662 		   dr_other_ed,
663 		   other_tax_credit,
664 		   other_tax_debit,
665 		   remarks
666             FROM JAI_CMN_RG_23AC_II_TRXS
667 	    WHERE organization_id = pr_tax.organization_id
668 	      AND location_id = pr_tax.location_id
669 	      AND inventory_item_id = pr_tax.inventory_item_id
670 	      AND receipt_ref = pr_tax.transaction_id
671 	      AND transaction_source_num = ln_transaction_id
672 	    )
673       LOOP
674         lv_statement_id := '4';
675         fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
676         ln_register_id := c_get_register_id.register_id;
677 	ln_dr_basic    := c_get_register_id.dr_basic_ed;
678 	ln_dr_addl     := c_get_register_id.dr_additional_ed;
679 	ln_dr_other    := c_get_register_id.dr_other_ed;
680 	ln_other_tax_debit := c_get_register_id.other_tax_debit;
681 	ln_cr_basic    := c_get_register_id.cr_basic_ed;
682 	ln_cr_addl     := c_get_register_id.cr_additional_ed;
683 	ln_cr_other    := c_get_register_id.cr_other_ed;
684 	ln_other_tax_credit := c_get_register_id.other_tax_credit;
685 	lv_remarks     := c_get_register_id.remarks || 'RTV ADjustment';
686 	fnd_file.put_line(FND_FILE.LOG, ' RTV Adjustment values --> ');
687 	fnd_file.put_line(FND_FILE.LOG, ' Register id ' || ln_register_id);
688 	fnd_file.put_line(FND_FILE.LOG, 'CR: Basic--Addl--Other--cess'||
689                          ln_cr_basic||'--'||ln_cr_addl||'--'||
690 			 ln_cr_other||'--'||ln_other_tax_credit);
691 	fnd_file.put_line(FND_FILE.LOG, 'DR: Basic--Addl--Other--cess'||
692                          ln_dr_basic||'--'||ln_dr_addl||'--'||
693 			 ln_dr_other||'--'||ln_other_tax_debit);
694       END LOOP ;
695 
696       lv_statement_id := '5';
697       p_codepath := jai_general_pkg.plot_codepath(5, p_codepath);
698       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
699 
700 
701       lv_statement_id := '6';
702       p_codepath := jai_general_pkg.plot_codepath(6, p_codepath);
703       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
704       /* Set the value of credit and debit basic, additional and other */
705       IF p_register_entry_type = CENVAT_DEBIT THEN
706          lv_statement_id := '7';
707          lv_upd_opening_bal_dr := ln_dr_basic + ln_dr_addl + ln_dr_other;
708          ln_dr_basic   := ln_dr_basic+ pr_diff_tax.basic_excise;
709          ln_dr_addl    := ln_dr_addl + pr_diff_tax.addl_excise + pr_diff_tax.cvd;
710          ln_dr_other   := ln_dr_other + pr_diff_tax.other_excise;
711          ln_other_tax_debit  := ln_other_tax_debit +
712 	                        pr_diff_tax.excise_edu_cess +
713 				pr_diff_tax.cvd_edu_cess + nvl(pr_diff_tax.sh_exc_edu_cess,0) +
714 				 nvl(pr_diff_tax.sh_cvd_edu_cess,0); --Bgowrava for Bug#6071509, added SH related cess
715 	 ln_reg_dr     := nvl(pr_diff_tax.basic_excise,0) +
716                           nvl(pr_diff_tax.addl_excise,0)+ nvl(pr_diff_tax.cvd,0) +
717 			  nvl(pr_diff_tax.other_excise,0);
718       ELSE
719          lv_statement_id := '8';
720 	 p_codepath := jai_general_pkg.plot_codepath(8, p_codepath);
721 	 lv_upd_opening_bal_cr := ln_cr_basic + ln_cr_addl + ln_cr_other;
722          ln_cr_basic   := ln_cr_basic + pr_diff_tax.basic_excise;
723          ln_cr_addl    := ln_cr_addl + pr_diff_tax.addl_excise + pr_diff_tax.cvd;
724          ln_cr_other   := ln_cr_other + pr_diff_tax.other_excise;
725          ln_other_tax_credit  := ln_other_tax_credit +
726 	                         pr_diff_tax.excise_edu_cess +
727 				 pr_diff_tax.cvd_edu_cess+ nvl(pr_diff_tax.sh_exc_edu_cess,0) +
728 				 nvl(pr_diff_tax.sh_cvd_edu_cess,0); --Bgowrava for Bug#6071509, added SH related cess
729 	 ln_reg_cr     := nvl(pr_diff_tax.basic_excise,0) +
730                           nvl(pr_diff_tax.addl_excise,0)+ nvl(pr_diff_tax.cvd,0) +
731 			  nvl(pr_diff_tax.other_excise,0);
732       END IF;
733 
734        /* Calculate the transaction amount difference to be updated */
735 
736       ln_tr_amount :=  nvl(ln_reg_cr,0) - nvl(ln_reg_dr,0);
737 
738       lv_statement_id := '9';
739       p_codepath := jai_general_pkg.plot_codepath(9, p_codepath);
740       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
741 
742       /*  Get the balance details */
743       jai_cmn_rg_balances_pkg.get_balance(
744          P_ORGANIZATION_ID   => pr_tax.organization_id,
745          P_LOCATION_ID       => pr_tax.location_id,
746          P_REGISTER_TYPE     => lv_register_type,
747          P_OPENING_BALANCE   => ln_opening_balance,
748          P_PROCESS_STATUS    => lv_process_status,
749          P_PROCESS_MESSAGE   => lv_process_message
750        );
751       lv_statement_id := '10';
752       p_codepath := jai_general_pkg.plot_codepath(10, p_codepath);
753       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
754       ln_closing_balance := ln_opening_balance + ln_tr_amount;
755       ln_opening_balance := ln_opening_balance - (nvl(lv_upd_opening_bal_cr,0) - nvl(lv_upd_opening_bal_dr,0));
756       fnd_file.put_line(FND_FILE.LOG, 'Opening balance to be updated ' || ln_opening_balance);
757 
758       lv_statement_id := '11';
759       p_codepath := jai_general_pkg.plot_codepath(11, p_codepath);
760       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
761 
762       /* Update RG 23 Part II with the latest difference amount to the existing amount */
763       jai_cmn_rg_23ac_ii_pkg.update_row(
764          P_REGISTER_ID         => ln_register_id,
765 	 P_CR_BASIC_ED         => ln_cr_basic,
766 	 P_CR_ADDITIONAL_ED    => ln_cr_addl,
767 	 P_CR_OTHER_ED         => ln_cr_other,
768 	 P_DR_BASIC_ED         => ln_dr_basic,
769 	 P_DR_ADDITIONAL_ED    => ln_dr_addl,
770 	 P_DR_OTHER_ED         => ln_dr_other,
771 	 P_REMARKS             => lv_remarks,
772 	 P_OPENING_BALANCE     => ln_opening_balance,
773 	 P_CLOSING_BALANCE     => ln_closing_balance,
774 	 P_OTHER_TAX_CREDIT    => ln_other_tax_credit,
775 	 P_OTHER_TAX_DEBIT     => ln_other_tax_debit,
776 	 p_simulate_flag     => p_simulate_flag,
777 	 p_process_status    => lv_process_status,
778 	 p_process_message   => lv_process_message
779          );
780       lv_statement_id := '12';
781       p_codepath := jai_general_pkg.plot_codepath(12, p_codepath);
782       fnd_file.put_line(FND_FILE.LOG, ' Value of statement id ' || lv_statement_id);
783       /* Update the balances with the latest amount*/
784 
785       jai_cmn_rg_balances_pkg.update_row(
786         p_organization_id   => pr_tax.organization_id,
787         p_location_id       => pr_tax.location_id,
788         p_register_type     => lv_register_type,
789 	p_amount_to_be_added=> ln_tr_amount,
790 	p_simulate_flag     => p_simulate_flag,
791 	p_process_status    => lv_process_status,
792 	p_process_message   => lv_process_message
793      );
794      p_register_id := ln_register_id;
795    END IF ;
796 
797    /* Update CESS balances */
798    IF pr_diff_tax.excise_edu_cess <> 0 THEN
799       IF p_register_entry_type = CENVAT_DEBIT THEN
800         ln_other_tax_debit  := pr_diff_tax.excise_edu_cess;
801       ELSE
802         ln_other_tax_credit := pr_diff_tax.excise_edu_cess;
803       END IF;
804 
805       ln_ex_cess_diff := nvl(ln_other_tax_credit,0) -
806                          nvl(ln_other_tax_debit,0);
807 
808       UPDATE  JAI_CMN_RG_OTHERS
809          SET  credit = credit + ln_other_tax_credit,
810               debit  = debit + ln_other_tax_debit,
811   	      opening_balance = opening_balance,
812 	      closing_balance = closing_balance + ln_ex_cess_diff
813        WHERE  source_register = decode(p_source_reg,'PLA', jai_constants.reg_pla,
814                                   decode(lv_register_type,
815 				         jai_constants.register_type_a,
816 					 jai_constants.reg_rg23a_2,
817 					 jai_constants.reg_rg23c_2
818 					)
819 				   )
820         AND  source_register_id = p_register_id
821         AND  tax_type = jai_constants.tax_type_exc_edu_cess;
822    END IF; /* Excise cess*/
823 
824    p_codepath := jai_general_pkg.plot_codepath(7, p_codepath);
825 
826    IF pr_diff_tax.cvd_edu_cess <> 0 THEN
827      IF p_register_entry_type = CENVAT_DEBIT THEN
828         ln_other_tax_debit  := pr_diff_tax.cvd_edu_cess;
829      ELSE
830         ln_other_tax_credit := pr_diff_tax.cvd_edu_cess;
831      END IF;
832 
833      ln_cvd_cess_diff := nvl(ln_other_tax_credit,0) -
834                         nvl(ln_other_tax_debit,0);
835 
836      UPDATE  JAI_CMN_RG_OTHERS
837         SET  credit = credit + ln_other_tax_credit,
838              debit  = debit + ln_other_tax_debit,
839 	     opening_balance = opening_balance,
840 	     closing_balance = closing_balance + ln_cvd_cess_diff
841       WHERE  source_register = decode(p_source_reg,'PLA', jai_constants.reg_pla,
842                                   decode(lv_register_type,
843 				         jai_constants.register_type_a,
844 					 jai_constants.reg_rg23a_2,
845 					 jai_constants.reg_rg23c_2
846 					)
847 				   )
848         AND  source_register_id = p_register_id
849         AND  tax_type = jai_constants.tax_type_cvd_edu_cess;
850     END IF; /* CVD Cess */
851 
852     --For Excise SH Edu cess
853     IF pr_diff_tax.sh_exc_edu_cess <> 0 THEN
854 		      IF p_register_entry_type = CENVAT_DEBIT THEN
855 		        ln_other_tax_debit  := pr_diff_tax.sh_exc_edu_cess;
856 		      ELSE
857 		        ln_other_tax_credit := pr_diff_tax.sh_exc_edu_cess;
858 		      END IF;
859 
860 		      ln_ex_sh_cess_diff := nvl(ln_other_tax_credit,0) -
861 		                         nvl(ln_other_tax_debit,0);
862 
863 		      UPDATE  JAI_CMN_RG_OTHERS
864 		         SET  credit = credit + ln_other_tax_credit,
865 		              debit  = debit + ln_other_tax_debit,
866 		  	      opening_balance = opening_balance,
867 			      closing_balance = closing_balance + ln_ex_sh_cess_diff
868 		       WHERE  source_register = decode(p_source_reg,'PLA', jai_constants.reg_pla,
869 		                                  decode(lv_register_type,
870 						         jai_constants.register_type_a,
871 							 jai_constants.reg_rg23a_2,
872 							 jai_constants.reg_rg23c_2
873 							)
874 						   )
875 		        AND  source_register_id = p_register_id
876 		        AND  tax_type = jai_constants.tax_type_sh_exc_edu_cess;
877    END IF; /* Excise SH cess*/
878 
879    --For CVD SH cess
880    IF pr_diff_tax.sh_cvd_edu_cess <> 0 THEN
881 	      IF p_register_entry_type = CENVAT_DEBIT THEN
882 	         ln_other_tax_debit  := pr_diff_tax.sh_cvd_edu_cess;
883 	      ELSE
884 	         ln_other_tax_credit := pr_diff_tax.sh_cvd_edu_cess;
885 	      END IF;
886 
887 	      ln_cvd_sh_cess_diff := nvl(ln_other_tax_credit,0) -
888 	                         nvl(ln_other_tax_debit,0);
889 
890 	      UPDATE  JAI_CMN_RG_OTHERS
891 	         SET  credit = credit + ln_other_tax_credit,
892 	              debit  = debit + ln_other_tax_debit,
893 	 	     opening_balance = opening_balance,
894 	 	     closing_balance = closing_balance + ln_cvd_sh_cess_diff
895 	       WHERE  source_register = decode(p_source_reg,'PLA', jai_constants.reg_pla,
896 	                                   decode(lv_register_type,
897 	 				         jai_constants.register_type_a,
898 	 					 jai_constants.reg_rg23a_2,
899 	 					 jai_constants.reg_rg23c_2
900 	 					)
901 	 				   )
902 	         AND  source_register_id = p_register_id
903 	         AND  tax_type = jai_constants.tax_type_sh_cvd_edu_cess;
904     END IF; /* CVD SH Cess */
905 
906   EXCEPTION
907     WHEN OTHERS THEN
908       lv_process_status := 'E';
909       lv_process_message := 'EXC_PRC_PKG.update_RTV_Diff_value'||SQLERRM
910                             ||', StmtId->'||lv_statement_id;
911       FND_FILE.put_line( FND_FILE.log, 'Error in '||lv_process_message);
912       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
913   END update_RTV_Diff_value;
914 
915   -- End for bug 5365346
916 
917   PROCEDURE do_cenvat_rounding(
918     p_transaction_id  IN NUMBER,
919     pr_tax            IN OUT NOCOPY TAX_BREAKUP,
920     p_codepath        IN OUT NOCOPY VARCHAR2
921   ) IS
922 
923     ln_total_cenvat         NUMBER;
924     ln_total_cenvat_rounded NUMBER;
925     ln_rounded_amt          NUMBER;
926 
927     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.do_cenvat_rounding';
928   BEGIN
929 
930     FND_FILE.put_line(FND_FILE.log, '^CENVAT_RG_PKG.do_cenvat_rounding. Basic->'||pr_tax.basic_excise
931       ||', Additional->'||pr_tax.addl_excise
932       ||', Other->'|| pr_tax.other_excise||', CVD->'|| pr_tax.cvd
933     ||', Add CVD -> '|| pr_tax.addl_CVD
934     -- Date 30/10/2006 Bug 5228046 added by sacsethi
935     );
936 
937     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg_pkg.do_cenvat_rounding', 'START');
938 
939     ln_total_cenvat         := pr_tax.basic_excise +
940                                pr_tax.addl_excise +
941 			       pr_tax.other_excise +
942 			       pr_tax.cvd +
943   			       pr_tax.addl_cvd ; -- Date 30/10/2006 Bug 5228046 added by sacsethi
944 
945 
946     ln_total_cenvat_rounded := round(ln_total_cenvat, gn_cenvat_rnd);
947     ln_rounded_amt          := ln_total_cenvat - ln_total_cenvat_rounded;
948 
949     IF ln_rounded_amt <> 0 THEN
950 
951       p_codepath := jai_general_pkg.plot_codepath(2, p_codepath);
952 
953       IF pr_tax.cvd <> 0 THEN
954          pr_tax.cvd :=  pr_tax.cvd - ln_rounded_amt;
955       ELSIF pr_tax.other_excise <> 0 THEN
956          pr_tax.other_excise :=  pr_tax.other_excise - ln_rounded_amt;
957       ELSIF pr_tax.addl_excise <> 0 THEN
958         pr_tax.addl_excise := pr_tax.addl_excise - ln_rounded_amt;
959       -- Date 30/10/2006 Bug 5228046 added by sacsethi
960       -- START BUG 5228046
961       ELSIF pr_tax.addl_cvd <> 0 THEN
962         pr_tax.addl_cvd := pr_tax.addl_cvd - ln_rounded_amt;
963       -- END BUG 5228046
964       ELSE
965         pr_tax.basic_excise := pr_tax.basic_excise - ln_rounded_amt;
966       END IF;
967 
968       FND_FILE.put_line(FND_FILE.log, 'Rounded Amts. Basic->'||pr_tax.basic_excise||
969                                       ',Additional->'||pr_tax.addl_excise||
970 				      ', Other->'|| pr_tax.other_excise||
971 				      ', CVD->'|| pr_tax.cvd ||
972 				    ', Addl CVD-> ' || pr_tax.addl_cvd     -- Date 30/10/2006 Bug 5228046 added by sacsethi
973       );
974 
975     END IF;
976 
977     p_codepath := jai_general_pkg.plot_codepath(3, p_codepath, null, 'END');
978   EXCEPTION
979     WHEN OTHERS THEN
980     pr_tax := null;
981     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
982     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
983     app_exception.raise_exception;
984   END do_cenvat_rounding;
985 
986   PROCEDURE process_transaction(
987     p_transaction_id            IN        NUMBER,
988     p_cenvat_claimed_ptg        IN OUT NOCOPY VARCHAR2,
989     p_process_status OUT NOCOPY VARCHAR2,
990     p_process_message OUT NOCOPY VARCHAR2,
991     p_simulate_flag             IN        VARCHAR2,
992     p_codepath                  IN OUT NOCOPY VARCHAR2,
993     -- following parameters introduced for second claim of receive transaction
994     -- Vijay shankar for Bug#3940588. RECEIPTS DEPLUG
995     p_process_special_reason    IN        VARCHAR2    DEFAULT NULL,
996     p_process_special_qty       IN        NUMBER      DEFAULT NULL
997   ) IS
998 
999     lv_procedure_name             VARCHAR2(60); --File.Sql.35 Cbabu  := 'CENVAT_RG_PKG.process_transaction';
1000 
1001     r_trx                         c_trx%ROWTYPE;
1002     r_base_trx                    c_base_trx%ROWTYPE;
1003     r_orgn_info                   c_orgn_info%ROWTYPE;
1004     lv_transaction_type           RCV_TRANSACTIONS.transaction_type%TYPE;
1005     ln_trx_type_code              NUMBER(5);
1006 
1007     -- For RTV case
1008     ln_receive_trx_id             JAI_RCV_TRANSACTIONS.transaction_type%TYPE;
1009     ln_receive_basic              NUMBER;
1010     ln_receive_addl               NUMBER;
1011     ln_receive_other              NUMBER;
1012     ln_receive_cvd                NUMBER;
1013     ln_receipt_addl_cvd           NUMBER;     -- Date 30/10/2006 Bug 5228046 added by sacsethi
1014     ln_receive_non_cenvat         NUMBER;
1015     lv_receive_part_ii_type       VARCHAR2(10);
1016     ln_receive_part_ii_reg_id     NUMBER;
1017     ln_receive_charge_accnt       NUMBER;
1018 
1019     lv_cenvat_accounting_type     VARCHAR2(10);
1020     lv_register_entry_type        VARCHAR2(10);
1021     lv_cgin_code                  VARCHAR2(100);
1022 
1023     lv_reference_num              JAI_CMN_RG_23AC_II_TRXS.reference_num%TYPE;
1024 
1025     -- amount related variables
1026     ln_curr_conv_rate             NUMBER;
1027     ln_excise_amount              NUMBER;
1028 
1029     /* Vijay Shankar for Bug#3940588 */
1030     r_half_tax                    TAX_BREAKUP;/*uncommented by vkaranam for bug 4704957*/
1031     r_tax                         TAX_BREAKUP;
1032 
1033 
1034     ln_amount_factor              NUMBER;   --File.Sql.35 Cbabu  := 1;
1035     ln_apportion_factor           NUMBER;
1036 
1037     ln_charge_account_id          NUMBER;
1038     lv_part_i_register            VARCHAR2(20);
1039     ln_part_i_register_id         NUMBER;
1040     lv_part_ii_register           VARCHAR2(20);
1041     ln_part_ii_register_id        NUMBER;
1042     lv_register_type              VARCHAR(1);
1043 
1044     lv_excise_invoice_no          JAI_RCV_TRANSACTIONS.excise_invoice_no%TYPE;
1045     ld_excise_invoice_date        JAI_RCV_TRANSACTIONS.excise_invoice_date%TYPE;
1046     lv_tax_breakup_type           VARCHAR2(20);
1047     lb_process_iso                BOOLEAN;
1048 
1049     lv_message                    VARCHAR2(500);
1050     lv_err_message                VARCHAR2(500);
1051     lv_statement_id               VARCHAR2(5);
1052     lv_temp                       VARCHAR2(50);
1053 
1054     lv_cenvat_register_type       VARCHAR2(30);
1055     lv_edu_cess_register_type     VARCHAR2(30);
1056     r_cenvat                      TAX_BREAKUP;
1057     r_edu_cess                    TAX_BREAKUP;
1058 
1059     /*bgowrava for forward porting Bug#5756676 START*/
1060 
1061     CURSOR cur_rg1_register_id
1062 		  IS
1063 		  SELECT register_id
1064 		    FROM JAI_CMN_RG_I_TRXS
1065 		   WHERE TRANSACTION_SOURCE_NUM = 18
1066 		     AND register_id    > 0 /*This check excludes master org records*/
1067 		     AND ref_doc_no     = to_char(p_transaction_id);--added for bug#9478222
1068 
1069 		  CURSOR cur_rg23_1_register_id
1070 		  IS
1071 		  SELECT register_id
1072 		    FROM JAI_CMN_RG_23AC_I_TRXS
1073 		   WHERE TRANSACTION_SOURCE_NUM = 18
1074 		     AND register_id    > 0 /*This check excludes master org records*/
1075      AND RECEIPT_REF     = p_transaction_id;
1076 /*bgowrava for forward porting Bug#5756676 END*/
1077 
1078 
1079     /* Bug 6800251. Added by Lakshmi Gopalsami
1080      * Fetched the total amount of RTV of the receipt
1081      * for which we are claiming the 2nd 50%.
1082      * This cursor will be fetched only in case of 2nd 50% claim
1083      */
1084     CURSOR C_Get_Total_RTV (cp_shipment_header_id IN NUMBER,
1085                             cp_shipment_line_id IN NUMBER
1086                            ) IS
1087     SELECT SUM(nvl(quantity,0))
1088       FROM jai_rcv_transactions jrt
1089      WHERE
1090        -- jrt.transaction_id > p_transaction_id AND
1091        jrt.transaction_type = 'RETURN TO VENDOR'
1092        AND jrt.shipment_header_id = cp_shipment_header_id
1093        AND jrt.shipment_line_id = cp_shipment_line_id;
1094 
1095     ln_RTV_qty NUMBER;
1096     ln_special_qty NUMBER;
1097 
1098     /* Added for bug #13362352 *//*Start*/
1099   CURSOR cur_destination_type_code IS
1100    SELECT destination_type_code
1101 		 FROM jai_rcv_transactions
1102 		WHERE transaction_id = p_transaction_id;
1103 
1104   CURSOR cur_parent_trx( cp_prnt_trx_id NUMBER ) IS
1105 	 SELECT *
1106 	  FROM jai_rcv_transactions
1107 	 WHERE transaction_id = cp_prnt_trx_id;
1108 
1109 	parent_trx_rec           cur_parent_trx%ROWTYPE ;
1110 
1111   lv_destination_type_code jai_rcv_transactions.destination_type_code%type;
1112     /* Added for bug #13362352 *//*End*/
1113 
1114   BEGIN
1115 
1116   /*----------------------------------------------------------------------------------------------------------------------------
1117   CHANGE HISTORY for FILENAME: jai_rcv_excise_processing_pkg.sql
1118   S.No  dd/mm/yyyy   Author and Details
1119   ------------------------------------------------------------------------------------------------------------------------------
1120   1     26/07/2004   Vijay Shankar for Bug# 3496408, Version:115.0
1121                       This Package is coded for Corrections Enhancement to invoke CENVAT and RG related insert APIs for PO Functionality.
1122 
1123             - PROCESS_TRANSACTION
1124                This is the driving procedure that calls different internal API's which further calls CENVAT and RG APIs for data insertion
1125             - VALIDATE_TRANSACTION
1126                Validates whether CENVAT and RG entries needs to be passed for receipt transaction.
1127                Returns a value based on which the main procedure either proceeds or returns with a error message
1128             - DERIVE_CGIN_SCENARIO
1129                Returns a CGIN Scenario Code based on which Accounting and RG entry APIs are invoked
1130                valid values:  (1) 'REGULAR-FULL + REVERSAL-HALF' (2) 'REGULAR-HALF'
1131                               (3) 'REGULAR-FULL'                 (4) 'REGULAR-FULL + PARENT-REGULAR-HALF'
1132             - RG_I_ENTRY
1133                Has the RG1 Entry related data fetching logic. Invokes API to pass an RG1 Entry
1134             - RG23_PART_I_ENTRY
1135                Has the RG23 Part1 Entry related data fetching logic. Invokes API to pass RG23(A or C) Entry for quantity
1136             - RG23_D_ENTRY
1137                Has the RG23D Entry related data fetching logic. Invokes API to pass an RG23D Entry
1138             - RG23_PART_II_ENTRY
1139                Has the RG23 Part2 Entry related data fetching logic. Invokes API to pass RG23(A or C) Entry for Amount
1140             - PLA_ENTRY
1141                Has data fetching logic related to PLA Entry. Invokes API to pass a PLA Entry
1142             - ACCOUNTING_ENTRIES
1143                Determines the accounts that needs to be hit based on input params. Call Receipt Accounting API to pass accounting entries
1144             - GENERATE_EXCISE_INVOICE
1145                Invoices excise invoice no generation API and returns a value to caller
1146             Other Procedure and Functions are used for the processing of the transaction purpose
1147 
1148   2     26/10/2004   Vijay Shankar for Bug# 3927371, Version:115.1
1149                       IF Condition for Trading related transaction processing is corrected, which is previously wrong in PROCESS_TRANSACTION procedure
1150 
1151   3     03/01/2005   Vijay Shankar for Bug# 3940588, Version:115.2, 115.3
1152                       Following are the changes done as part of RECEIPTS DEPLUG and Education Cess Enhancement
1153                       - Added a RECORD Definition for tax breakup as TAX_BREAUP and modified to use this as a parameter in all the calls
1154                       that passes cenvat accounting and register entries. this change is made from an extensible perspective of breakup
1155                       - added the following procedures
1156                         - get_vendor_changed_dtls   : Retuns the changed excise vendor details as OUT Parameters
1157                         - post_cenvat_processor     : Updates JAI_RCV_CENVAT_CLAIMS, JAI_RCV_LINES tables with claim details
1158                         - other_cenvat_rg_recording : Inserts a record into JAI_CMN_RG_OTHERS table with the parameters passed to the call
1159                       - added the parameters p_process_special_reason and qty in PROCESS_TRANSACTION. These are used incase the accounting
1160                       and rg entries should consider these values for TAX_BREAUP instead of main transaction values.
1161                       These parameters are mainly added for RECEIPTS DEPLUG to support second Claim functionality of CGIN items
1162                       - COMMENTED the code related to AUTO Claim of 2nd 50% of RECEIVE transaction to the tune of RETURN TO VENDOR
1163                       that is being processed. this redundant as the 2nd 50% claim of RECEIVE will happen only to the tune of remaining
1164                       quantity of RECEIVE after RTV. Previous functionality is that, it claims whole of RECEIVE quantity for 2nd 50% also
1165                       Incase of CGIN items, CGIN_CODE returned from derive_cgin_code for RTV previously is 'REGULAR-FULL + PARENT-REGULAR-HALF'
1166                       and now it returns 'REGULAR-FULL + REVERSAL-HALF' incase the parent RECEIVE is only 50% claimed
1167                       - Call to get_vendor_changed_dtls is added in all RG Entries related procedures like rg23_part_i_entry etc. this
1168                       is used to insert RG Entries with a different Vendor other than excise if the user indicated the same through
1169                       Claim Cenvat Screen of India Localization
1170                       - Modified all RG Entries related procedures to make calls to other_cenvat_rg_recording incase EXCISE or CVD
1171                       EDUCATION_CESS are attached to receipt lines. the call inturn makes relevant CESS entries into RG tables
1172                       - Modified ACCOUTING_ENTRIES procedure to pass accounting for CESS Amounts to relevant CESS accounts of
1173                       Organization Additional information. this passes different accounting entries for EXCISE and CVD EUDCATION_CESS
1174                       incase they have different accounts defined in Organization Addl. Info Setup
1175                       - Modified get_tax_amount_breakup to break the amount for EXCISE_EDUCATION_CESS and CVD_EDUCATION_CESS also
1176 
1177   4.   16/02/2005 - bug#4187859  - File Version - 115.4
1178                    Even when RTV did not have cess, Validation to cess was done and an error was thrown to the uset that cess amount is
1179                    zero. This has been stopped by adding code not to call the ja_in_rg_others_pkg.insert_row procedure only if
1180                    the cess amount is not zero.
1181 
1182                    Dependency due to this bug:-
1183                     None
1184 
1185   5.   16/03/2005 - Vijay Shankar for Bug#4211045  - File Version - 115.5
1186                      Incase of RMA Accounting for CESS, we are hitting Cr. Excise Receivable A/C  and Dr. Cess RM A/C for Cess Amount.
1187                      this set of accounting for cess is wrong, instead it should be Cr. Cess Paid Payable Account and Dr. Cess RM A/C for Cess Amount
1188                      to fix this, changes are made in accounting_entries procedure and a call to jai_rcv_accounting_pkg.process_transaction
1189                      is made to pass an extra entry as Cr. Cess Paid Payable Accnt for Cess amt
1190 
1191   6.   15/04/2005    Sanjikum for Bug #4293421, File Version 116.0(115.7)
1192 
1193                      Problem
1194                      -------
1195                      During Cenvat Claim, while Inserting the Record into JAI_CMN_RG_23AC_II_TRXS, the Transaction date is inserted as Transaction Date of
1196                      the JAI_RCV_TRANSACTIONS.transaction_date. It should be the date on which claim is being made.
1197 
1198                      Fix
1199                      ---
1200                      In the Procedure rg23_part_ii_entry, while calling jai_cmn_rg_23ac_ii_pkg.insert_row, value of the parameter
1201                      p_transaction_date is changed to SYSDATE from r_trx.transaction_date
1202 
1203   7.   19/04/2005   Vijay Shankar for Bug #4103161, File Version 116.1(115.8)
1204                      Rounding of RTV Excise amounts to nearest rupee is removed as it will be done separately through RG Rounding
1205                      Concurrrent program
1206 
1207                    * Dependancy for later versions of this object *
1208 
1209   8   10/05/2005   Vijay Shankar for Bug#4346453. Version: 116.2
1210                    Code is modified due to the Impact of Receiving Transactions DFF Elimination
1211                    added a procedure rtv_processing_for_ssi that will be invoked for SSI processing
1212                 * High Dependancy for future Versions of this object *
1213 
1214 
1215  9   10-may-2007  bgowrava for forward porting Bug#5756676, 11i bug#5747013. File Version 120.15
1216 	                  Issue : QTY REGISTER SHOULD BE UPDATED ON RECEIVE DEPENDING ON SETUP
1217 	                    Fix : Changes are made to check if the Qty register is already hit. If it is then
1218 	                          the Qty register is updated with the amounts. Otherwise call to api is made
1219 	                          to insert into Qty register
1220 
1221 	                  Dependancy due to this bug : Yes
1222 
1223 10   10-may-2007  bgowrava for forward porting Bug#5756676, 11i bug#5747013. File Version 120.15
1224 	                  Issue : QTY REGISTER SHOULD BE UPDATED ON RECEIVE DEPENDING ON SETUP
1225 	                    Fix : The excise_invoice_no and excise_invoice_date should also be updated in Qty registers
1226                           in case of deferred claim also. So modified the update statement to update these columns also
1227 
1228 11.   04/06/2007  sacsethi for bug 6109941  file version #120.18
1229 
1230                   CODE REVIEW COMMENTS FOR ENHANCEMENTS
1231 
1232 		  Problem found for forward porting for Enhancement Additional cvd ( 5228046)  and budget 2007  ( 5989740)
1233 
1234 
1235   Dependancy:
1236   -----------
1237   IN60105D2 + 3496408
1238   IN60106   + 3940588 + 4146708/4239736 + 4103161 + 4346453
1239 
1240   /* IMPORTANT NOTE:
1241     For Receiving Transactions: In case of CGIN Claim a value needs to be passed for JAI_CMN_RG_23AC_II_TRXS.REFERENCE_NUM column
1242       that will be used for Duplicate Checking.
1243       Incase of RECEIVE transaction value passed for 1st 50% Claim is '1st Claim'. During 2nd 50% Claim '2nd Claim' is passed
1244       If 2nd Claim is happening from RTV transaction then TRANSACTION_ID of RECEIVE is passed as the value towards REFERENCE_NUM
1245       In all Other transactions value passed for REFERENCE_NUM column is NULL
1246 
1247 
1248   ----------------------------------------------------------------------------------------------------------------------------*/
1249 
1250     lv_procedure_name    := 'CENVAT_RG_PKG.process_transaction';
1251     ln_amount_factor     := 1;
1252 
1253     -- this is to identify the path in SQL TRACE file if any problem occured
1254     SELECT 'jai_rcv_excise_processing_pkg-'||p_transaction_id INTO lv_temp FROM DUAL;
1255 
1256     if lb_rg_debug then
1257       FND_FILE.put_line(FND_FILE.log,'*** Start jai_rcv_excise_processing_pkg.process_transaction');
1258       -- FND_FILE.put_line(FND_FILE.log,'*** Start jai_rcv_excise_processing_pkg.process_transaction');
1259     end if;
1260 
1261      /* Added for bug #13362352 */
1262      OPEN cur_destination_type_code;
1263 	   FETCH cur_destination_type_code INTO lv_destination_type_code;
1264 	   CLOSE cur_destination_type_code;
1265 
1266     lv_statement_id := '0';
1267     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.process_trx', 'START'); /* 1 */
1268     FND_FILE.put_line( FND_FILE.log, '***** Start of jai_rcv_excise_processing_pkg.process_transaction. Time:'||to_char(SYSDATE, 'dd/mm/yyyy hh24:mi:ss') );
1269 
1270     lv_statement_id := '1';
1271     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
1272     OPEN c_trx(p_transaction_id);
1273     FETCH c_trx INTO r_trx;
1274     CLOSE c_trx;
1275 
1276     /* Added for bug #13362352 */
1277     OPEN cur_parent_trx ( r_trx.parent_transaction_id );
1278 	  FETCH cur_parent_trx INTO parent_trx_rec;
1279 	  CLOSE cur_parent_trx;
1280 
1281     OPEN c_base_trx(p_transaction_id);
1282     FETCH c_base_trx INTO r_base_trx;
1283     CLOSE c_base_trx;
1284 
1285     IF r_trx.transaction_type = 'CORRECT' THEN
1286       lv_transaction_type := r_trx.parent_transaction_type;
1287     ELSE
1288       lv_transaction_type := r_trx.transaction_type;
1289     END IF;
1290 
1291     lv_statement_id := '2';
1292     p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
1293 
1294     validate_transaction(
1295       p_transaction_id    => p_transaction_id,
1296       p_validation_type   => 'COMMON',
1297       p_process_status    => p_process_status,
1298       p_process_message   => p_process_message,
1299       p_simulate_flag     => p_simulate_flag,
1300       p_codepath          => p_codepath
1301     );
1302 
1303     IF p_process_status IN ('X', 'E') THEN
1304       GOTO finish;
1305     END IF;
1306 
1307     lv_statement_id := '3';
1308     IF r_trx.organization_type = 'T' THEN
1309       lv_tax_breakup_type := 'RG23D';
1310     ELSE  -- manufacturing and others
1311       lv_tax_breakup_type := 'MODVAT';
1312     END IF;
1313 
1314     lv_statement_id := '4';
1315     p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
1316 
1317     -- ln_curr_conv_rate := r_trx.currency_conversion_rate;
1318     get_tax_amount_breakup(
1319         p_shipment_line_id  => r_trx.shipment_line_id,
1320         p_transaction_id    => r_trx.transaction_id,
1321         p_curr_conv_rate    => r_trx.currency_conversion_rate,
1322         pr_tax              => r_tax,
1323         p_breakup_type      => lv_tax_breakup_type,
1324         p_codepath          => p_codepath
1325     );
1326 
1327     -- Vijay Shankar for Bug#3940588. RECEIPTS DEPLUG
1328     -- following should be executed only incase of RECEIVE (or) MATCH transactions and that too for 2nd claim
1329     IF p_process_special_reason = jai_rcv_excise_processing_pkg.second_50ptg_claim THEN
1330       /* Bug 6800251. Added by Lakshmi Gopalsami
1331        * Get the total RTV qty and proportion it against the receipt qty.
1332        * The tax breakup should happen for the remaining quantity so that
1333        * half of the amount can be used for 2nd claim.
1334        * changed p_process_special_qty
1335        */
1336       OPEN C_Get_Total_RTV(r_trx.shipment_header_id, r_trx.shipment_line_id);
1337         FETCH C_Get_Total_RTV INTO ln_RTV_qty;
1338       CLOSE C_Get_Total_RTV;
1339       ln_special_qty := r_trx.quantity - nvl(ln_RTV_qty,0);
1340       /* Bug 6800251.
1341        * This is to check whether all the materials are returned.
1342        * case where RTV qty = Receipt Qty cannot happen before 2nd claim,
1343        * as 100% should be claimed before returning full goods.
1344        *
1345        */
1346       r_tax := get_apportioned_tax(r_tax, ln_special_qty/r_trx.quantity,'2ND CLAIM' );
1347        -- Date 01/11/2006 Bug 5228046 added by SACSETHI
1348     END IF;
1349 
1350     if lb_rg_debug then
1351       FND_FILE.put_line(FND_FILE.log,'*** Start jai_rcv_excise_processing_pkg.process_transaction');
1352       -- FND_FILE.put_line(FND_FILE.log,'*** Start jai_rcv_excise_processing_pkg.process_transaction');
1353     end if;
1354 
1355     -- Following is to calculate Tax Breakup Amount As Per Apportion Factor. This is calculated based on
1356     -- Transaction UOMs, Quantities of Parent RECEIVE and present trxn an
1357     lv_statement_id := '4a';
1358     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
1359 
1360     -- These variable are used for 2nd 50% Claim of RECEIVE Transaction of CGIN Items
1361 
1362      r_half_tax := get_apportioned_tax(r_tax, 0.5,null);/*uncommented by vkaranam  and passed null to the p_claim_type parameter for bug 4704957*/
1363 
1364     /* Call to Rounding of Excise Amounts */
1365     -- Rounding is done only for transaction types other than RECEIVE. Rounding of RECEIVE is handled at Excise invoice level seperately
1366     /* following is modified to include RETURN TO VENDOR as rounding of RTV will be done through a seperate process
1367     Vijay Shankar for Bug#4103161
1368     IF lv_transaction_type <> 'RECEIVE' THEN */
1369     /*commented by vkaranam for bug#9346733
1370     IF lv_transaction_type NOT IN ('RECEIVE','RETURN TO VENDOR') THEN
1371       do_cenvat_rounding(
1372         p_transaction_id  => r_trx.transaction_id,
1373         pr_tax            => r_tax,
1374         p_codepath        => p_codepath
1375       );
1376     END IF;
1377 
1378     if lb_rg_debug then
1379       --dbms_output.put_line('After Rounding. Basic:'||r_tax.basic_excise||', Addl:'||r_tax.addl_excise
1380       --  ||', Other:'||r_tax.other_excise||', cvd:'||r_tax.cvd ||', Addl. CVD:'||r_tax.addl_cvd);
1381       -- Date 30/10/2006 Bug 5228046 added by sacsethi
1382       FND_FILE.put_line(FND_FILE.log, 'After Rounding. Basic:'||r_tax.basic_excise||', Addl:'||r_tax.addl_excise
1383         ||', Other:'||r_tax.other_excise||', cvd:'||r_tax.cvd ||', Addl. CVD :'||r_tax.addl_cvd   );
1384     end if;
1385     */
1386 
1387     OPEN c_orgn_info(r_trx.organization_id, r_trx.location_id);
1388     FETCH c_orgn_info INTO r_orgn_info;
1389     CLOSE c_orgn_info;
1390 
1391     lv_register_type := jai_general_pkg.get_rg_register_type( p_item_class  => r_trx.item_class);
1392 
1393     lv_statement_id := '5';
1394     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
1395 
1396     /* Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh.
1397     -- Excise Invoce Generation for Return to Vendor Transactions
1398     IF lv_transaction_type = 'RETURN TO VENDOR' THEN
1399 
1400       generate_excise_invoice(
1401           p_transaction_id       => p_transaction_id,
1402           p_organization_id      => r_trx.organization_id,
1403           p_location_id          => r_trx.location_id,
1404           p_excise_invoice_no    => lv_excise_invoice_no,
1405           p_excise_invoice_date  => ld_excise_invoice_date,
1406           p_simulate_flag        => p_simulate_flag,
1407           p_errbuf               => lv_err_message,
1408           p_codepath             => p_codepath
1409       );
1410 
1411       if lb_rg_debug then
1412         --dbms_output.put_line('After ExciseInv Gen. ExInvNo:'||nvl(lv_excise_invoice_no,'NULL') );
1413         FND_FILE.put_line(FND_FILE.log, 'After ExciseInv Gen. ExInvNo:'||nvl(lv_excise_invoice_no, 'NULL') );
1414       end if;
1415 
1416       lv_statement_id := '6';
1417       p_codepath := jai_general_pkg.plot_codepath(8, p_codepath);
1418       IF lv_excise_invoice_no IS NOT NULL THEN
1419         INSERT INTO JAI_RCV_RTV_DTLS(
1420           transaction_id, parent_transaction_id, shipment_line_id,
1421           excise_invoice_no, excise_invoice_date, rg_register_part_i,
1422           creation_date, created_by, last_update_date, last_updated_by, last_update_login
1423         ) VALUES (
1424           p_transaction_id, r_trx.parent_transaction_id, r_trx.shipment_line_id,
1425           lv_excise_invoice_no, ld_excise_invoice_date, NULL,
1426           SYSDATE, FND_GLOBAL.user_id, SYSDATE, FND_GLOBAL.user_id, FND_GLOBAL.login_id
1427         );
1428 
1429         lv_statement_id := '7';
1430         p_codepath := jai_general_pkg.plot_codepath(9, p_codepath);
1431         jai_rcv_transactions_pkg.update_excise_invoice_no(
1432           p_transaction_id      => p_transaction_id,
1433           p_excise_invoice_no   => lv_excise_invoice_no,
1434           p_excise_invoice_date => ld_excise_invoice_date
1435         );
1436       ELSE
1437         lv_message := 'Cenvat Entries cannot be posted due to Excise Invoice cant be generated';
1438         GOTO finish;
1439       END IF;
1440 
1441     END IF;
1442     */
1443 
1444     -- to determine the way in which CGIN Items are Processed
1445     IF lv_register_type = 'C' THEN
1446       derive_cgin_scenario(
1447           p_transaction_id  => p_transaction_id,
1448           p_cgin_code       => lv_cgin_code,
1449           p_process_status  => p_process_status,
1450           p_process_message => p_process_message,
1451           p_codepath        => p_codepath
1452       );
1453 
1454       FND_FILE.put_line(FND_FILE.log, 'CGIN_CODE->'||lv_cgin_code);
1455       IF p_process_status IN ('E', 'X') THEN
1456         GOTO finish;
1457       END IF;
1458     END IF;
1459 
1460     -- Following is Very Important IF condition that determines whether the transaction should be debited or credited
1461     IF lv_transaction_type IN ('RECEIVE', 'RETURN TO RECEIVING') THEN
1462       lv_cenvat_accounting_type  := CENVAT_DEBIT;
1463       lv_register_entry_type     := CENVAT_CREDIT;
1464     ELSIF lv_transaction_type IN ('DELIVER', 'RETURN TO VENDOR') THEN
1465       lv_cenvat_accounting_type  := CENVAT_CREDIT;
1466       lv_register_entry_type     := CENVAT_DEBIT;
1467     END IF;
1468 
1469     if lb_rg_debug then
1470       FND_FILE.put_line(FND_FILE.log, 'AccntEntry Type:'||lv_cenvat_accounting_type||', RegEntryType:'|| lv_register_entry_type);
1471     end if;
1472 
1473     -- 90% of the cenvat entries entries happen only for RECEIVE and RTV entries (code=1)
1474     -- and cenvat entries happen for DELIVER and RTR (code=2)cases only if subinventory is nonbonded
1475     -- 1. RECEIVE and RTV.   We dont check for Subinventory for these transaction types
1476     -- 2. DELIVER and RTR. These were supported only if subinventory is non bonded or expense or non asset case
1477     lv_statement_id := '8';
1478     p_codepath := jai_general_pkg.plot_codepath(10, p_codepath); /* 10 */
1479     IF lv_transaction_type IN ('RECEIVE', 'RETURN TO RECEIVING', 'DELIVER', 'RETURN TO VENDOR') THEN
1480 
1481       IF r_trx.organization_type = jai_rcv_trx_processing_pkg.MFG_ORGN  THEN
1482 
1483         lv_statement_id := '9';
1484         p_codepath := jai_general_pkg.plot_codepath(11, p_codepath); /* 11 */
1485 
1486         IF (r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma  -- 'India RMA Receipt'
1487             AND r_trx.item_class IN ('FGIN', 'FGEX', 'CCIN', 'CCEX'))
1488 	  /*Added by nprashar for bug 6710747 The following condition is added to support register update for Inter Org Transfer*/
1489 	  OR ( r_base_trx.source_document_Code IN ('REQ','INVENTORY') AND lv_transaction_type <>'DELIVER' AND r_trx.item_class IN ('FGIN', 'FGEX', 'CCIN', 'CCEX')) --added 'REQ' for bug #13514510
1490         THEN
1491 
1492         /*bgowrava for forward porting Bug#5756676..start*/
1493 				        IF nvl(r_trx.quantity_register_flag,'N') = 'Y' THEN
1494 
1495 				          OPEN  cur_rg1_register_id;
1496 				          FETCH cur_rg1_register_id INTO ln_part_i_register_id;
1497 				          CLOSE cur_rg1_register_id;
1498 
1499 				          UPDATE JAI_CMN_RG_I_TRXS
1500 				             SET basic_ed              = r_tax.basic_excise,
1501 				                 additional_ed         = r_tax.addl_excise + r_tax.cvd,
1502 				                 other_ed              = r_tax.other_excise,
1503 				                 excise_duty_amount    = r_tax.basic_excise + r_tax.addl_excise + r_tax.cvd + r_tax.other_excise,
1504 				                 excise_invoice_number = r_trx.excise_invoice_no,
1505 				                 excise_invoice_date   = r_trx.excise_invoice_date
1506            WHERE register_id           = ln_part_i_register_id;
1507 
1508            ELSE
1509 
1510           rg_i_entry(
1511               p_transaction_id       => r_trx.transaction_id,
1512               pr_tax                 => r_tax,
1513               p_register_entry_type  => lv_register_entry_type,
1514               p_register_id          => ln_part_i_register_id,
1515               p_process_status       => p_process_status,
1516               p_process_message      => p_process_message,
1517               p_simulate_flag        => p_simulate_flag,
1518               p_codepath             => p_codepath
1519           );
1520 
1521           END IF;
1522           /*bgowrava for forward porting Bug#5756676..end*/
1523 
1524           IF ln_part_i_register_id IS NOT NULL THEN
1525             lv_part_i_register  := 'RG1';
1526           END IF;
1527 
1528         ELSIF r_trx.item_class IN ('RMIN', 'RMEX', 'CCIN', 'CCEX', 'CGIN', 'CGEX') THEN
1529 
1530           lv_statement_id := '10';
1531           p_codepath := jai_general_pkg.plot_codepath(12, p_codepath); /* 12 */
1532 
1533           -- RG23 Part I Entry is already made during first Claim, in case of CGIN Items
1534           -- So no need of another entry during Second 50% Claim of CENVAT
1535           IF nvl(lv_cgin_code, 'XXX') <> 'REGULAR-HALF' THEN
1536 
1537            /*bgowrava for forward porting Bug#5756676..start*/
1538 
1539 							IF nvl(r_trx.quantity_register_flag,'N') = 'Y' THEN
1540 
1541 							FND_FILE.put_line(FND_FILE.log, 'Quantity register is already hit. So updating amounts');
1542 
1543 								OPEN  cur_rg23_1_register_id;
1544 								FETCH cur_rg23_1_register_id INTO ln_part_i_register_id;
1545 								CLOSE cur_rg23_1_register_id;
1546 
1547 			  			  FND_FILE.put_line(FND_FILE.log, 'RG23 Part I Register Id:'||ln_part_i_register_id);
1548 
1549 								UPDATE JAI_CMN_RG_23AC_I_TRXS
1550 									 SET basic_ed            = r_tax.basic_excise,
1551 			  			         additional_ed       = r_tax.addl_excise + r_tax.cvd,
1552 			  			         additional_cvd      = r_tax.addl_cvd,
1553 			  			         other_ed            = r_tax.other_excise,
1554 			  			         EXCISE_INVOICE_NO   = r_trx.excise_invoice_no,
1555 			  			         excise_invoice_date = r_trx.excise_invoice_date
1556 								 WHERE register_id         = ln_part_i_register_id;
1557 
1558 							ELSE
1559 
1560 					     FND_FILE.put_line(FND_FILE.log, 'Quantity register is not hit. So calling rg23_part_i_entry');
1561                rg23_part_i_entry(
1562                 p_transaction_id       => r_trx.transaction_id,
1563                 pr_tax                 => r_tax,
1564                 p_register_entry_type  => lv_register_entry_type,
1565                 p_register_id          => ln_part_i_register_id,
1566                 p_process_status       => p_process_status,
1567                 p_process_message      => p_process_message,
1568                 p_simulate_flag        => p_simulate_flag,
1569                 p_codepath             => p_codepath
1570             );
1571 
1572             END IF;
1573           /*bgowrava for forward porting Bug#5756676..end*/
1574 
1575           ELSE
1576             FND_FILE.put_line( FND_FILE.log, 'No Call to RG23_PART_I_ENTRY');
1577           END IF;
1578 
1579           IF ln_part_i_register_id IS NOT NULL THEN
1580             lv_part_i_register  := 'RG23'||lv_register_type;
1581           END IF;
1582 
1583         ELSE
1584           lv_message := 'ItemClass Not Supported for Transaction';
1585           GOTO finish;
1586         END IF;
1587 
1588         IF p_process_status IN ('E', 'X') THEN
1589           GOTO finish;
1590         END IF;
1591 
1592         /*uncommneted by vkaranam for bug#4704957, start */--Commented by Vijay Shankar for Bug#3940588. RECEIPTS DEPLUG.
1593         -- Start PARENT Half Claim entry for RTV
1594         -- This is for RTV case when Parent RECEIVE is only 50% Claimed
1595         IF lv_transaction_type = 'RETURN TO VENDOR'
1596           AND lv_register_type = 'C'
1597           AND lv_cgin_code like '%PARENT-REGULAR-HALF%'
1598         THEN
1599 
1600           FND_FILE.put_line(FND_FILE.log, '<< Start 2nd 50% Claim of RECEIVE during RTV');
1601 
1602           lv_statement_id := '11';
1603           p_codepath := jai_general_pkg.plot_codepath(13, p_codepath);
1604           ln_receive_trx_id := r_trx.tax_transaction_id;
1605 
1606           -- Pass an RG23 PartII Entry against Parent RECEIVE line to the tune of 50% of RTV Quantity
1607           rg23_part_ii_entry(
1608               --p_transaction_id        => r_trx.transaction_id,
1609               p_transaction_id        => r_trx.tax_transaction_id,--added by vkaranam for bug 5841749
1610               pr_tax                  => r_half_tax,
1611               p_part_i_register_id    => NULL,
1612               p_register_entry_type   => CENVAT_CREDIT,
1613               p_reference_num         => r_trx.transaction_id,/*ln_receive_trx_id is replaced by r_trx.transaction_id by vkaranam for bug#4704957*/
1614               p_register_id           => ln_receive_part_ii_reg_id,
1615               p_process_status        => p_process_status,
1616               p_process_message       => p_process_message,
1617               p_simulate_flag         => p_simulate_flag,
1618               p_codepath              => p_codepath
1619           );
1620 
1621           IF p_process_status IN ('E', 'X') THEN
1622             GOTO finish;
1623           END IF;
1624 
1625           IF ln_receive_part_ii_reg_id IS NOT NULL THEN
1626             lv_receive_part_ii_type := 'RG23C';
1627 
1628             -- Vijay Shankar for Bug#3940588. The same is coded at the end of procedure
1629             -- this is to increase the cenvat_claimed_amt to the tune of second 50% that is claimed now on RECEIVE transaction
1630             UPDATE JAI_RCV_CENVAT_CLAIMS
1631               SET cenvat_claimed_amt = nvl(cenvat_claimed_amt,0)
1632                           + (r_half_tax.basic_excise +
1633 			     r_half_tax.addl_excise +
1634 			     r_half_tax.other_excise +
1635 			     r_half_tax.cvd +
1636 			     r_tax.addl_cvd     -- Date 30/10/2006 Bug 5228046 added by sacsethi
1637 			    ),
1638                         other_cenvat_claimed_amt = nvl(other_cenvat_claimed_amt,0)
1639                           + (r_half_tax.excise_edu_cess + r_half_tax.cvd_edu_cess+nvl(r_half_tax.sh_exc_edu_cess,0)
1640                           + nvl(r_half_tax.sh_cvd_edu_cess,0)),
1641                           /*added nvl(r_half_tax.sh_exc_edu_cess,0) + nvl(r_half_tax.sh_cvd_edu_cess,0) by vkaranam for budget 07 impact - bug#5989740*/
1642                   cenvat_sequence = cenvat_sequence + 1,
1643                   last_update_date = sysdate,
1644                   last_updated_by = fnd_global.user_id
1645             WHERE transaction_id = ln_receive_trx_id;
1646             -- CHK whether the above update is required or not. because there is another update at the end of procedure
1647 
1648           END IF;
1649 
1650           lv_statement_id := '11a';
1651           p_codepath := jai_general_pkg.plot_codepath(14, p_codepath);
1652           -- Pass accounting for the remaining 50% Claim against Parent RECEIVE line to the tune of RTV Quantity.
1653           -- Full amount is passed here but half amount will be passed in accounting_entries procedure
1654           accounting_entries(
1655               p_transaction_id          => r_trx.transaction_id,
1656               pr_tax                    => r_tax,
1657               p_cgin_code               => 'REGULAR-HALF',
1658               p_cenvat_accounting_type  => CENVAT_DEBIT,
1659               p_amount_register         => lv_receive_part_ii_type,
1660               p_cenvat_account_id       => ln_receive_charge_accnt,
1661               p_process_status          => p_process_status,
1662               p_process_message         => p_process_message,
1663               p_simulate_flag           => p_simulate_flag,
1664               p_codepath                => p_codepath
1665           );
1666 
1667           IF p_process_status IN ('E', 'X') THEN
1668             GOTO finish;
1669           END IF;
1670 
1671           jai_cmn_rg_23ac_ii_pkg.update_payment_details(
1672             p_register_id         => ln_receive_part_ii_reg_id,
1673             p_register_id_part_i  => NULL,
1674             p_charge_account_id   => ln_receive_charge_accnt
1675           );
1676 
1677           FND_FILE.put_line(FND_FILE.log, '>> END 2nd 50% Claim of RECEIVE during RTV');
1678 
1679         END IF;
1680         -- End PARENT Half Claim entry for RTV
1681         /*vkaranam for bug #4704957,end*/
1682 
1683         lv_statement_id := '11b';
1684         p_codepath := jai_general_pkg.plot_codepath(15, p_codepath); /* 15 */
1685         -- lv_cgin_code will have a value only in case of CGIN items wherein 1st 50% claim is 'REGULAR-FULL + REVERSAL-HALF'
1686         -- and 2nd 50% claim is done by 'REGULAR-HALF'
1687         IF lv_cgin_code IN ( 'REGULAR-FULL + REVERSAL-HALF', 'REGULAR-HALF') THEN
1688           ln_amount_factor := 0.5;
1689         ELSE
1690           ln_amount_factor := 1;
1691         END IF;
1692 
1693         lv_statement_id := '12';
1694 
1695         /* START - DUTY REGISTER HITTING LOGIC */
1696         -- following if condition modified by Vijay Shankar for RECEIPTS DEPLUG
1697         -- IF lv_transaction_type = 'RETURN TO VENDOR' AND r_orgn_info.pref_pla = 1 THEN
1698         IF lv_transaction_type = 'RETURN TO VENDOR' THEN
1699 
1700           p_codepath := jai_general_pkg.plot_codepath(16, p_codepath); /* 16 */
1701 
1702           derive_duty_registers(
1703             p_organization_id           => r_trx.organization_id,
1704             p_location_id               => r_trx.location_id,
1705             p_item_class                => r_trx.item_class,
1706             pr_tax                      => r_tax,
1707             p_cenvat_register_type      => lv_cenvat_register_type,
1708             -- p_edu_cess_register_type    => lv_edu_cess_register_type,
1709             p_process_flag              => p_process_status,
1710             p_process_message           => p_process_message,
1711             p_codepath                  => p_codepath,
1712             p_transaction_type          => lv_transaction_type --9854329
1713           );
1714 
1715           IF p_process_status = 'E' THEN
1716             GOTO finish;
1717           END IF;
1718 
1719         ELSE
1720           lv_cenvat_register_type   := NULL;
1721           lv_edu_cess_register_type := NULL;
1722         END IF;
1723 
1724         IF    (lv_cenvat_register_type IS NULL AND lv_edu_cess_register_type IS NULL)
1725             OR lv_cenvat_register_type IN (jai_constants.register_type_a, jai_constants.register_type_c)
1726         THEN
1727 
1728           lv_statement_id := '13';
1729           p_codepath := jai_general_pkg.plot_codepath(17, p_codepath);
1730 
1731           IF lv_transaction_type = 'RECEIVE' AND lv_cgin_code IS NOT NULL THEN
1732             -- 1st Claim
1733             IF nvl(p_cenvat_claimed_ptg, 0) = 0 THEN
1734               lv_reference_num := CGIN_FIRST_CLAIM;
1735             -- 2nd Claim onwards. -- Helpful to identify the duplicate entry in JAI_CMN_RG_23AC_II_TRXS. if the line is 100% Claimed, then we should not pass another entry
1736             ELSE    -- IF p_cenvat_claimed_ptg = 50 THEN
1737               lv_reference_num := CGIN_SECOND_CLAIM;
1738             END IF;
1739           ELSE
1740             lv_reference_num := NULL;
1741           END IF;
1742 
1743           lv_statement_id := '13.1';
1744 
1745       /* Added for bug #13362352 */
1746        IF ( lv_transaction_type = 'DELIVER' AND nvl(lv_destination_type_code,'xyz') <> 'SHOP FLOOR' ) OR
1747 			   ( lv_transaction_type = 'RETURN TO RECEIVING' AND parent_trx_rec.destination_type_code <> 'SHOP FLOOR' ) OR
1748 				 ( lv_transaction_type IN ( 'RECEIVE',  'RETURN TO VENDOR', 'MATCH' ) )
1749 			 THEN
1750 
1751           rg23_part_ii_entry(
1752               p_transaction_id        => r_trx.transaction_id,
1753               pr_tax                  => get_apportioned_tax(r_tax,
1754 	                                                     ln_amount_factor,
1755 							     UPPER(lv_reference_num)     -- Date 30/10/2006 Bug 5228046 added by sacsethi
1756 							    ),
1757               p_part_i_register_id    => ln_part_i_register_id,
1758               p_register_entry_type   => lv_register_entry_type,
1759               p_reference_num         => lv_reference_num,
1760               p_register_id           => ln_part_ii_register_id,
1761               p_process_status        => p_process_status,
1762               p_process_message       => p_process_message,
1763               p_simulate_flag         => p_simulate_flag,
1764               p_codepath              => p_codepath
1765           );
1766 
1767           IF p_process_status IN ('E', 'X') THEN
1768             GOTO finish;
1769           END IF;
1770 
1771           IF ln_part_ii_register_id IS NOT NULL THEN
1772             lv_part_ii_register  := 'RG23'||lv_register_type;
1773           END IF;
1774 
1775       END IF;
1776 
1777         ELSIF lv_cenvat_register_type = jai_constants.register_type_pla THEN
1778 
1779           lv_statement_id := '13.2';
1780           p_codepath := jai_general_pkg.plot_codepath(17.1, p_codepath);
1781           pla_entry(
1782               p_transaction_id      => p_transaction_id,
1783               pr_tax                => get_apportioned_tax(r_tax,
1784 	                                                   ln_amount_factor,
1785 							   UPPER(lv_reference_num)) ,    -- Date 30/10/2006 Bug 5228046 added by sacsethi
1786               p_register_entry_type => lv_register_entry_type,
1787               p_register_id         => ln_part_ii_register_id,
1788               p_process_status      => p_process_status,
1789               p_process_message     => p_process_message,
1790               p_simulate_flag       => p_simulate_flag,
1791               p_codepath            => p_codepath
1792           );
1793 
1794           IF p_process_status IN ('E', 'X') THEN
1795             GOTO finish;
1796           END IF;
1797 
1798           IF ln_part_ii_register_id IS NOT NULL THEN
1799             lv_part_ii_register  := 'PLA';
1800           END IF;
1801 
1802         ELSE
1803           lv_statement_id := '13.3';
1804           p_codepath := jai_general_pkg.plot_codepath(17.2, p_codepath);
1805           --p_process_status  := 'E';
1806           lv_message := 'Duty Register cannot be derived';
1807           GOTO finish;
1808         END IF;
1809 
1810         /* END - DUTY REGISTER HITTING LOGIC */
1811 
1812         /* START - ACCOUNTING LOGIC */
1813         lv_statement_id := '13a';
1814         p_codepath := jai_general_pkg.plot_codepath(18, p_codepath); /* 18 */
1815 
1816         fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb> --- 1');
1817 
1818      /* Added for bug #13362352 */
1819       IF ( lv_transaction_type = 'DELIVER' AND nvl(lv_destination_type_code,'xyz') <> 'SHOP FLOOR' ) OR
1820 			   ( lv_transaction_type = 'RETURN TO RECEIVING' AND parent_trx_rec.destination_type_code <> 'SHOP FLOOR' ) OR
1821 				 ( lv_transaction_type IN ( 'RECEIVE',  'RETURN TO VENDOR', 'MATCH' ) )
1822 			THEN
1823 
1824         accounting_entries(
1825             p_transaction_id          => r_trx.transaction_id,
1826             pr_tax                    => r_tax,
1827             p_cgin_code               => lv_cgin_code,
1828             p_cenvat_accounting_type  => lv_cenvat_accounting_type,
1829             p_amount_register         => lv_part_ii_register,
1830             p_cenvat_account_id       => ln_charge_account_id,
1831             p_process_status          => p_process_status,
1832             p_process_message         => p_process_message,
1833             p_simulate_flag           => p_simulate_flag,
1834             p_codepath                => p_codepath
1835         );
1836 
1837         IF p_process_status IN ('E', 'X') THEN
1838           GOTO finish;
1839         END IF;
1840 
1841         END IF ;
1842 
1843         /* END - ACCOUNTING LOGIC */
1844 
1845       ELSIF r_trx.organization_type = jai_rcv_trx_processing_pkg.TRADING_ORGN THEN
1846 
1847         -- In a Trading Organization all the ITEM CLASSes are supported
1848 
1849         lv_statement_id := '14';
1850         -- IF r_trx.item_class IN ('FGIN', 'FGEX') THEN
1851           -- right now i am assuming that we need not pass any accouting entries. however we need to pass rg23d entry
1852 
1853         lv_statement_id := '15';
1854         p_codepath := jai_general_pkg.plot_codepath(20, p_codepath); /* 20 */
1855         rg23_d_entry(
1856             p_transaction_id      => p_transaction_id,
1857             pr_tax                => r_tax,
1858             p_register_entry_type => lv_register_entry_type,
1859             p_register_id         => ln_part_i_register_id,
1860             p_process_status      => p_process_status,
1861             p_process_message     => p_process_message,
1862             p_simulate_flag       => p_simulate_flag,
1863             p_codepath            => p_codepath
1864         );
1865 
1866         IF ln_part_i_register_id IS NOT NULL THEN
1867           lv_part_i_register  := 'RG23D';
1868         END IF;
1869 
1870         IF p_process_status IN ('E', 'X') THEN
1871           GOTO finish;
1872         END IF;
1873 
1874         lv_statement_id := '16';
1875         p_codepath := jai_general_pkg.plot_codepath(21, p_codepath); /* 21 */
1876         -- there is no part II entry for TRADING transactions
1877         IF lv_transaction_type IN ('RECEIVE', 'RETURN TO VENDOR') AND r_trx.excise_in_trading = 'Y' THEN
1878 
1879           lb_process_iso := jai_rcv_trx_processing_pkg.process_iso_transaction(
1880                                 p_transaction_id    => r_trx.transaction_id,
1881                                 p_shipment_line_id  => r_trx.shipment_line_id
1882                             );
1883 
1884           -- No cenvat accounting in case of DELIVER/ RETURN TO RECEIVING.
1885           -- Also accounting happens only if Organization Setup for Excise in RG23D is checked
1886 
1887         -- Vijay Shankar for Bug#3927371, This needs modification after discussing with Yadu
1888           -- IF r_trx.organization_type = 'M' OR (r_trx.organization_type = 'T' AND lb_process_iso)
1889           IF ( r_base_trx.source_document_code <> 'REQ'
1890             OR (r_base_trx.source_document_code='REQ' AND lb_process_iso) )
1891             AND r_base_trx.source_document_code <> jai_rcv_trx_processing_pkg.source_rma /*srjayara for bug#5155138 - change done for base bug 5110511 + DFF Elimination*/
1892 
1893           THEN
1894 
1895             p_codepath := jai_general_pkg.plot_codepath(21.2, p_codepath);
1896             accounting_entries(
1897                 p_transaction_id          => r_trx.transaction_id,
1898                 pr_tax                    => r_tax,
1899                 p_cgin_code               => NULL, -- lv_cgin_code can be null as this is trading organization
1900                 p_cenvat_accounting_type  => lv_cenvat_accounting_type,
1901                 p_amount_register         => lv_part_ii_register,
1902                 p_cenvat_account_id       => ln_charge_account_id,
1903                 p_process_status          => p_process_status,
1904                 p_process_message         => p_process_message,
1905                 p_simulate_flag           => p_simulate_flag,
1906                 p_codepath                => p_codepath
1907             );
1908 
1909           ELSE
1910             FND_FILE.put_line( FND_FILE.log, '..No Accounting Required for Trading Orgn');
1911           END IF;
1912 
1913         END IF;
1914 
1915       ELSE
1916         p_codepath := jai_general_pkg.plot_codepath(21.5, p_codepath);
1917         lv_message := 'Organization Type Not supported';
1918         GOTO finish;
1919       END IF;
1920 
1921       IF p_process_status IN ('E', 'X') THEN
1922         GOTO finish;
1923       END IF;
1924 
1925     ELSE
1926       lv_statement_id := '18';
1927       p_codepath := jai_general_pkg.plot_codepath(22, p_codepath); /* 22 */
1928       lv_message := 'Transaction Type Not supported';
1929       GOTO finish;
1930     END IF;
1931 
1932     lv_statement_id := '19';
1933     p_codepath := jai_general_pkg.plot_codepath(23, p_codepath); /* 23 */
1934     -- Updation of RG Part1 Registers with Payment Register, Register_Id_Part_II, ChargeAccountId
1935     update_registers(
1936         p_quantity_register_id  => ln_part_i_register_id,
1937         p_quantity_register     => lv_part_i_register,
1938         p_payment_register_id   => ln_part_ii_register_id,
1939         p_payment_register      => lv_part_ii_register,
1940         p_charge_account_id     => ln_charge_account_id,
1941         p_process_status        => p_process_status,
1942         p_process_message       => p_process_message,
1943         p_simulate_flag         => p_simulate_flag,
1944         p_codepath              => p_codepath
1945     );
1946 
1947     IF lv_transaction_type = 'RETURN TO VENDOR' AND ln_part_i_register_id IS NOT NULL THEN
1948       lv_statement_id := '20';
1949       p_codepath := jai_general_pkg.plot_codepath(24, p_codepath); /* 24 */
1950       UPDATE JAI_RCV_RTV_DTLS
1951       SET rg_register_part_i = ln_part_i_register_id
1952       WHERE transaction_id = p_transaction_id;
1953     END IF;
1954 
1955     -- Assigning the Percentage value that has been claimed w.r.t transaction
1956     IF lv_register_type = 'C' THEN
1957       IF lv_transaction_type = 'RECEIVE' THEN
1958         IF lv_cgin_code = 'REGULAR-FULL' THEN
1959           p_cenvat_claimed_ptg := 100;
1960         ELSE      --IF lv_transaction_type = 'REGULAR-HALF' THEN
1961           p_cenvat_claimed_ptg := nvl(p_cenvat_claimed_ptg, 0) + 50;
1962         END IF;
1963       ELSE
1964         IF lv_cgin_code in ('REGULAR-FULL + REVERSAL-HALF', 'REGULAR-HALF') THEN
1965           p_cenvat_claimed_ptg := 50;
1966         ELSE
1967           p_cenvat_claimed_ptg := 100;
1968         END IF;
1969       END IF;
1970     ELSE
1971       p_cenvat_claimed_ptg := 100;
1972     END IF;
1973 
1974     -- CALL TO Post Processor updated claim related stuff in JAI_RCV_CENVAT_CLAIMS and JAI_RCV_LINES at RECEIVE trx level
1975     -- Vijay Shankar for Bug#3940588
1976     post_cenvat_processor(
1977       p_transaction_id            => p_transaction_id,
1978       p_cenvat_claimed_ptg        => p_cenvat_claimed_ptg,
1979       p_cenvat_claimed_amt        => (
1980                                         (  r_tax.basic_excise +
1981 					   r_tax.addl_excise +
1982 					   r_tax.other_excise +
1983 					   r_tax.cvd
1984 					)  * ln_amount_factor
1985 				     ) + r_tax.addl_cvd ,-- Date 30/10/2006 Bug 5228046 added by sacsethi
1986       p_other_cenvat_claimed_amt  => (r_tax.excise_edu_cess + r_tax.cvd_edu_cess+r_tax.sh_exc_edu_cess + r_tax.sh_cvd_edu_cess) * ln_amount_factor/*added r_tax.sh_exc_edu_cess + r_tax.sh_cvd_edu_cess
1987                                                                                                                                                    by vkaranam for budget 07 impact - bug#5989740*/
1988     );
1989 
1990     p_process_status := 'Y';
1991 
1992     <<finish>>
1993     IF lv_message IS NOT NULL THEN
1994       p_codepath := jai_general_pkg.plot_codepath(25, p_codepath); /* 25 */
1995 
1996       FND_FILE.put_line(FND_FILE.log, 'CENVAT_RG_PKG.process_trxn:'||lv_message||', StatementId:'||lv_statement_id);
1997       p_process_status := 'E';
1998       p_process_message := 'CENVAT_RG_PKG.process_trxn:'||lv_message||', StatementId:'||lv_statement_id;
1999     END IF;
2000 
2001     p_codepath := jai_general_pkg.plot_codepath(26, p_codepath, null, 'END'); /* 26 */
2002     FND_FILE.put_line( FND_FILE.log, '----- END, jai_rcv_excise_processing_pkg.process_transaction. Time:'||to_char(SYSDATE, 'dd/mm/yyyy hh24:mi:ss') );
2003 
2004   EXCEPTION
2005     WHEN OTHERS THEN
2006       p_process_status := 'E';
2007       p_process_message := 'CENVAT_RG_PKG.process_transaction->'||SQLERRM||', StmtId->'||lv_statement_id;
2008       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
2009       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
2010 
2011   END process_transaction;
2012 
2013   -- this procedure to be called only for RMA case of FGIN, FGEX, CCIN, CCEX
2014   PROCEDURE rg_i_entry(
2015     p_transaction_id      IN  NUMBER,
2016     pr_tax                IN  TAX_BREAKUP,
2017     p_register_entry_type IN  VARCHAR2,
2018     p_register_id OUT NOCOPY NUMBER,
2019     p_process_status OUT NOCOPY VARCHAR2,
2020     p_process_message OUT NOCOPY VARCHAR2,
2021     p_simulate_flag       IN  VARCHAR2,
2022     p_codepath            IN OUT NOCOPY VARCHAR2
2023   ) IS
2024 
2025     r_trx                     c_trx%ROWTYPE;
2026     r_base_trx                c_base_trx%ROWTYPE;
2027 
2028     ln_register_id            JAI_CMN_RG_I_TRXS.register_id%TYPE;
2029     lv_slno                   JAI_CMN_RG_I_TRXS.slno%TYPE;
2030     lv_range                  JAI_CMN_RG_I_TRXS.range_no%TYPE;
2031     lv_division               JAI_CMN_RG_I_TRXS.division_no%TYPE;
2032     ln_excise_duty_rate       JAI_CMN_RG_I_TRXS.excise_duty_rate%TYPE;
2033     lv_excise_invoice_no      JAI_CMN_RG_I_TRXS.excise_invoice_number%TYPE;
2034     ld_excise_invoice_date    JAI_CMN_RG_I_TRXS.excise_invoice_date%TYPE;
2035     ln_customer_id            RCV_TRANSACTIONS.customer_id%TYPE;
2036     ln_customer_site_id       RCV_TRANSACTIONS.customer_site_id%TYPE;
2037     r_parent_base_trx         c_base_trx%ROWTYPE;
2038 
2039     ln_entry_type             NUMBER;   --File.Sql.35 Cbabu  := 1;
2040     ln_basic_ed               NUMBER;
2041     ln_additional_ed          NUMBER;
2042     ln_other_ed               NUMBER;
2043     ln_excise_duty_amount     NUMBER;
2044 
2045 
2046     lv_transaction_type       JAI_CMN_RG_I_TRXS.transaction_type%TYPE;
2047 
2048     ln_quantity               NUMBER;
2049     ln_vendor_id              NUMBER(15);
2050     ln_vendor_site_id         NUMBER(15);
2051 
2052     lv_statement_id           VARCHAR2(5);
2053     ln_exc_edu_cess           NUMBER; /*vkaranam for bug 5989740*/
2054     ln_sh_exc_edu_cess        NUMBER; /*vkaranam for bug 5989740*/
2055 
2056 	  /* added, vumaasha for Bug 4689713   */
2057    Cursor c_excise_tax_rate(cp_shipment_header_id JAI_RCV_LINE_TAXES.shipment_header_id%TYPE,
2058                            cp_shipment_line_id JAI_RCV_LINE_TAXES.shipment_line_id%TYPE ) IS
2059     select nvl(sum(jrtl.tax_rate),0) , count(jrtl.tax_rate)
2060     from   JAI_RCV_LINE_TAXES  jrtl ,
2061            JAI_CMN_TAXES_ALL     jtc
2062     where  jrtl.tax_id   = jtc.tax_id
2063     and    jrtl.shipment_header_id = cp_shipment_header_id
2064     and    jrtl.shipment_line_id   = cp_shipment_line_id
2065     AND    UPPER(jtc.tax_type) = 'EXCISE'  ;
2066 
2067     ln_total_tax_rate  JAI_CMN_TAXES_ALL.tax_rate%TYPE;
2068     ln_number_of_Taxes NUMBER;
2069 
2070   /* ended, vumaasha for Bug 4689713 */
2071 
2072   BEGIN
2073 
2074     ln_entry_type := 1;
2075     if lb_rg_debug then
2076       FND_FILE.put_line(FND_FILE.log,'^ RG1 Entry. Basic:'||pr_tax.basic_excise
2077         ||', Addl:'||pr_tax.addl_excise||', Other:'||pr_tax.other_excise
2078         ||', CVD:'||pr_tax.cvd||', EntryType:'||p_register_entry_type ||', PrcSta:'||p_process_status
2079       );
2080     end if;
2081 
2082     lv_statement_id := '1';
2083     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.rg_i_entry', 'START'); /* 1 */
2084 
2085     OPEN c_trx(p_transaction_id);
2086     FETCH c_trx INTO r_trx;
2087     CLOSE c_trx;
2088 
2089     lv_statement_id := '2';
2090     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
2091     OPEN c_base_trx(p_transaction_id);
2092     FETCH c_base_trx INTO r_base_trx;
2093     CLOSE c_base_trx;
2094 
2095     ln_customer_id      := r_base_trx.customer_id;
2096     ln_customer_site_id := r_base_trx.customer_site_id;
2097 
2098     IF r_base_trx.source_document_code = 'REQ' THEN
2099       lv_statement_id := '4';
2100       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
2101       OPEN c_source_orgn_loc( r_base_trx.shipment_header_id, r_base_trx.requisition_line_id);
2102       FETCH c_source_orgn_loc INTO ln_vendor_id, ln_vendor_site_id;
2103       CLOSE c_source_orgn_loc;
2104 
2105       ln_vendor_id      := -ln_vendor_id;
2106       ln_vendor_site_id := -ln_vendor_site_id;
2107 
2108     ELSE
2109       lv_statement_id := '5';
2110       p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
2111 
2112       get_changed_vendor_dtls(
2113         p_receive_trx_id      => r_trx.tax_transaction_id,
2114         p_shipment_line_id    => r_trx.shipment_line_id,
2115         p_vendor_id           => ln_vendor_id,
2116         p_vendor_site_id      => ln_vendor_site_id
2117       );
2118 
2119       ln_vendor_id      := nvl(ln_vendor_id, r_base_trx.vendor_id);
2120       ln_vendor_site_id := nvl(ln_vendor_site_id, r_base_trx.vendor_site_id);
2121 
2122     END IF;
2123 
2124     IF r_base_trx.source_document_code = 'RMA' THEN
2125       IF ln_customer_site_id IS NULL THEN
2126         /*OPEN c_base_trx( jai_rcv_trx_processing_pkg.get_ancestor_id(
2127                             p_transaction_id     => r_trx.transaction_id,
2128                             p_shipment_line_id   => r_trx.shipment_line_id,
2129                             p_required_trx_type  => 'RECEIVE'
2130                          )
2131                        );*/
2132         OPEN c_base_trx(r_trx.tax_transaction_id);
2133         FETCH c_base_trx INTO r_parent_base_trx;
2134         CLOSE c_base_trx;
2135 
2136         ln_customer_site_id := r_parent_base_trx.customer_site_id;
2137       END IF;
2138     END IF;
2139 
2140     lv_statement_id := '61';
2141     p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
2142     jai_general_pkg.get_range_division(
2143         p_vendor_id       => ln_vendor_id,
2144         p_vendor_site_id  => ln_vendor_site_id,
2145         p_range_no        => lv_range,
2146         p_division_no     => lv_division
2147     );
2148 
2149     lv_excise_invoice_no    := r_trx.excise_invoice_no;
2150     ld_excise_invoice_date  := r_trx.excise_invoice_date;
2151 
2152     lv_statement_id := '7';
2153     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
2154     -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt' THEN
2155     IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then -- 'India RMA Receipt' THEN
2156       lv_transaction_type := 'CR';
2157     ELSE
2158       lv_transaction_type := 'R';
2159     END IF;
2160 
2161     IF p_register_entry_type = CENVAT_DEBIT THEN
2162       ln_entry_type := -1;
2163     END IF;
2164 
2165     lv_statement_id := '8';
2166     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
2167     ln_quantity           := r_trx.quantity * ln_entry_type;
2168     ln_basic_ed           := pr_tax.basic_excise * ln_entry_type;
2169     ln_additional_ed      := (pr_tax.addl_excise + pr_tax.cvd) * ln_entry_type;
2170     ln_other_ed           := pr_tax.other_excise * ln_entry_type;
2171     ln_excise_duty_amount := ln_basic_ed + ln_additional_ed + ln_other_ed;
2172     ln_exc_edu_cess       := pr_tax.excise_edu_cess * ln_entry_type;/*added by vkaranam for bug #5989740*/
2173     ln_sh_exc_edu_cess       := pr_tax.sh_exc_edu_cess * ln_entry_type;/*added by vkaranam for bug #5989740*/
2174     /* ln_excise_duty_rate := ln_excise_duty_amount/ln_quantity; commented, vumaasha for Bug 4689713 */
2175 
2176 	/* added, Vumaasha for Bug 4689713  */
2177 
2178     OPEN c_excise_tax_rate( r_trx.shipment_header_id, r_trx.shipment_line_id ) ;
2179     FETCH c_excise_tax_rate INTO ln_total_tax_rate , ln_number_of_Taxes ;
2180     CLOSE c_excise_tax_rate;
2181 
2182     if NVL(ln_number_of_Taxes,0) = 0 then
2183       ln_number_of_Taxes := 1;
2184     end if;
2185 
2186     ln_excise_duty_rate := ln_total_tax_rate / ln_number_of_Taxes;
2187 
2188    /* ended, Vumaasha for Bug 4689713   */
2189 
2190 
2191     if lb_rg_debug then
2192       FND_FILE.put_line(FND_FILE.log,'Before call to RG1. ExDutyAmt:'||ln_excise_duty_amount);
2193     end if;
2194 
2195     lv_statement_id := '9';
2196     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath); /* 8 */
2197     jai_cmn_rg_i_trxs_pkg.create_rg1_entry(
2198         p_register_id                  => p_register_id,
2199         p_register_id_part_ii          => null,
2200         p_fin_year                     => jai_general_pkg.get_fin_year(p_organization_id => r_trx.organization_id),
2201         p_slno                         => lv_slno,
2202         p_transaction_id               => null,
2203         p_organization_id              => r_trx.organization_id,
2204         p_location_id                  => r_trx.location_id,
2205         p_transaction_date             => r_trx.transaction_date,
2206         p_inventory_item_id            => r_trx.inventory_item_id,
2207         p_transaction_type             => lv_transaction_type,
2208         p_ref_doc_id                   => to_char(p_transaction_id),
2209         p_quantity                     => ln_quantity,
2210         p_transaction_uom_code         => r_trx.uom_code,
2211         p_issue_type                   => null,
2212         p_excise_duty_amount           => ln_excise_duty_amount,
2213         p_excise_invoice_number        => r_trx.excise_invoice_no,
2214         p_excise_invoice_date          => r_trx.excise_invoice_date,
2215         p_payment_register             => null,
2216         p_charge_account_id            => NULL,
2217         p_range_no                     => lv_range,
2218         p_division_no                  => lv_division,
2219         p_remarks                      => null,
2220         p_basic_ed                     => ln_basic_ed,
2221         p_additional_ed                => ln_additional_ed,
2222         p_other_ed                     => ln_other_ed,
2223         p_assessable_value             => null,
2224         p_excise_duty_rate             => ln_excise_duty_rate,
2225         p_vendor_id                    => ln_vendor_id,
2226         p_vendor_site_id               => ln_vendor_site_id,
2227         p_customer_id                  => ln_customer_id,
2228         p_customer_site_id             => ln_customer_site_id,
2229         p_creation_date                => SYSDATE,
2230         p_created_by                   => fnd_global.user_id,
2231         p_last_update_date             => SYSDATE,
2232         p_last_updated_by              => fnd_global.user_id,
2233         p_last_update_login            => fnd_global.login_id,
2234         p_called_from                  => 'RECEIPTS',
2235         p_cess_amount                  => ln_exc_edu_cess ,/*added by vkaranam for budget 07 impact - bug#5989740*/
2236 	p_sh_cess_amount               => ln_sh_exc_edu_cess --added by vkaranam for budget 07 impact - bug#5989740
2237      );
2238 
2239 
2240      /*bgowrava for forward porting Bug#5756676..start*/
2241 
2242 		 	UPDATE JAI_RCV_TRANSACTIONS
2243 		 		 SET quantity_register_flag  = 'Y',
2244 		 				 last_updated_by         = fnd_global.user_id,
2245 		 				 last_update_date        = sysdate,
2246 		 				 last_update_login       = fnd_global.login_id
2247 		 	 WHERE transaction_id          = p_transaction_id ;
2248 
2249 		   FND_FILE.put_line(FND_FILE.log, 'Updating quantity register flag to Y');
2250 
2251 		   /*bgowrava for forward porting Bug#5756676..end*/
2252 
2253 
2254     p_codepath := jai_general_pkg.plot_codepath(9, p_codepath, null, 'END'); /* 9 */
2255 
2256   EXCEPTION
2257     WHEN OTHERS THEN
2258       p_process_status := 'E';
2259       p_process_message := 'CENVAT_RG_PKG.rg_i_entry->'||SQLERRM||', StmtId->'||lv_statement_id;
2260       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
2261       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
2262 
2263   END rg_i_entry;
2264 
2265   PROCEDURE rg23_part_i_entry(
2266     p_transaction_id    IN NUMBER,
2267     pr_tax                IN  TAX_BREAKUP,
2268     p_register_entry_type IN VARCHAR2,
2269     p_register_id OUT NOCOPY NUMBER,
2270     p_process_status OUT NOCOPY VARCHAR2,
2271     p_process_message OUT NOCOPY VARCHAR2,
2272     p_simulate_flag     IN VARCHAR2,
2273     p_codepath          IN OUT NOCOPY VARCHAR2
2274   ) IS
2275 
2276     CURSOR c_po_header(cp_po_header_id IN NUMBER) IS
2277       SELECT po_header_id, creation_date
2278       FROM po_headers_all
2279       WHERE po_header_id = cp_po_header_id;
2280 
2281     r_trx                     c_trx%ROWTYPE;
2282     r_base_trx                c_base_trx%ROWTYPE;
2283     r_po_header               c_po_header%ROWTYPE;
2284 
2285     ln_register_id            JAI_CMN_RG_23AC_I_TRXS.register_id%TYPE;
2286     ln_vendor_id              RCV_TRANSACTIONS.vendor_id%TYPE;
2287     ln_vendor_site_id         RCV_TRANSACTIONS.vendor_site_id%TYPE;
2288     lv_excise_invoice_no      JAI_CMN_RG_23AC_I_TRXS.EXCISE_INVOICE_NO%TYPE;
2289     ld_excise_invoice_date    JAI_CMN_RG_23AC_I_TRXS.excise_invoice_date%TYPE;
2290     lv_transaction_type       RCV_TRANSACTIONS.transaction_type%TYPE;
2291     ln_customer_id            RCV_TRANSACTIONS.customer_id%TYPE;
2292     ln_customer_site_id       RCV_TRANSACTIONS.customer_site_id%TYPE;
2293     r_parent_base_trx         c_base_trx%ROWTYPE;
2294 
2295     ln_entry_type             NUMBER;   --File.Sql.35 Cbabu  := 1;
2296     ln_basic_ed               NUMBER;
2297     ln_additional_ed          NUMBER;
2298     ln_additional_cvd         NUMBER;     -- Date 30/10/2006 Bug 5228046 added by sacsethi
2299     ln_other_ed               NUMBER;
2300     ln_quantity               NUMBER;
2301       lv_cr_rvrsl_flag          jai_cmn_inventory_orgs.CENVAT_CR_REVRSL_FLAG%TYPE; --added for bug#9854329
2302 
2303       --start additions for bug#9854329
2304       cursor get_rev_flag(cp_organization_id in number,cp_location_id in number)
2305       is
2306       SELECT CENVAT_CR_REVRSL_FLAG FROM jai_cmn_inventory_orgs
2307   WHERE organization_id = cp_organization_id
2308     AND location_id =cp_location_id;
2309 
2310     lv_statement_id           VARCHAR2(5);
2311   BEGIN
2312 
2313     ln_entry_type    := 1;
2314     if lb_rg_debug then
2315      -- Date 30/10/2006 Bug 5228046 added by sacsethi
2316       FND_FILE.put_line(FND_FILE.log,'^ RG23_PART_I_Entry. Basic:'||pr_tax.basic_excise
2317         ||', Addl:'||pr_tax.addl_excise||', Other:'||pr_tax.other_excise
2318         ||', CVD:'||pr_tax.cvd ||', Addl. CVD: '|| pr_tax.addl_cvd||', EntryType:'||p_register_entry_type ||', PrcSta:'||p_process_status
2319       );
2320     end if;
2321 
2322     lv_statement_id := '1';
2323     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.23_part_i', 'START'); /* 1 */
2324     OPEN c_trx(p_transaction_id);
2325     FETCH c_trx INTO r_trx;
2326     CLOSE c_trx;
2327 
2328     --start additions for bug#9854329
2329     open get_rev_flag (r_trx.organization_id,r_trx.location_id);
2330     fetch get_rev_flag  INTO lv_cr_rvrsl_flag       ;
2331     close get_rev_flag;
2332     --end bug#9854329
2333 
2334 
2335     lv_statement_id := '2';
2336     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
2337 
2338     OPEN c_base_trx(p_transaction_id);
2339     FETCH c_base_trx INTO r_base_trx;
2340     CLOSE c_base_trx;
2341 
2342     ln_customer_id      := r_base_trx.customer_id;
2343     ln_customer_site_id := r_base_trx.customer_site_id;
2344 
2345     lv_statement_id := '3';
2346     p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
2347     IF r_base_trx.po_header_id IS NOT NULL THEN
2348       OPEN c_po_header(r_base_trx.po_header_id);
2349       FETCH c_po_header INTO r_po_header;
2350       CLOSE c_po_header;
2351     END IF;
2352 
2353     IF r_base_trx.source_document_code = 'REQ' THEN
2354       lv_statement_id := '4';
2355       p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
2356       OPEN c_source_orgn_loc( r_base_trx.shipment_header_id, r_base_trx.requisition_line_id);
2357       FETCH c_source_orgn_loc INTO ln_vendor_id, ln_vendor_site_id;
2358       CLOSE c_source_orgn_loc;
2359 
2360       ln_vendor_id      := -ln_vendor_id;
2361       ln_vendor_site_id := -ln_vendor_site_id;
2362 
2363     ELSE
2364       lv_statement_id := '5';
2365       p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
2366 
2367       -- Vijay Shankar for Bug#3940588
2368       get_changed_vendor_dtls(
2369         p_receive_trx_id      => r_trx.tax_transaction_id,
2370         p_shipment_line_id    => r_trx.shipment_line_id,
2371         p_vendor_id           => ln_vendor_id,
2372         p_vendor_site_id      => ln_vendor_site_id
2373       );
2374 
2375       ln_vendor_id      := nvl(ln_vendor_id, r_base_trx.vendor_id);
2376       ln_vendor_site_id := nvl(ln_vendor_site_id, r_base_trx.vendor_site_id);
2377     END IF;
2378 
2379     IF r_base_trx.source_document_code = 'RMA' THEN
2380 
2381       IF ln_customer_site_id IS NULL THEN
2382         /*OPEN c_base_trx( jai_rcv_trx_processing_pkg.get_ancestor_id(
2383                             p_transaction_id     => r_trx.transaction_id,
2384                             p_shipment_line_id   => r_trx.shipment_line_id,
2385                             p_required_trx_type  => 'RECEIVE'
2386                          )
2387                        );*/
2388         OPEN c_base_trx(r_trx.tax_transaction_id);
2389         FETCH c_base_trx INTO r_parent_base_trx;
2390         CLOSE c_base_trx;
2391 
2392         ln_customer_site_id := r_parent_base_trx.customer_site_id;
2393       END IF;
2394     END IF;
2395 
2396     IF r_trx.transaction_type = 'CORRECT' THEN
2397       lv_transaction_type := r_trx.parent_transaction_type;
2398     ELSE
2399       lv_transaction_type := r_trx.transaction_type;
2400     END IF;
2401 
2402     IF p_register_entry_type = CENVAT_DEBIT THEN
2403       ln_entry_type := -1;
2404     END IF;
2405 
2406     lv_excise_invoice_no    := r_trx.excise_invoice_no;
2407     ld_excise_invoice_date  := r_trx.excise_invoice_date;
2408 
2409     lv_statement_id := '6';
2410     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
2411     ln_quantity           := r_trx.quantity * ln_entry_type;
2412     ln_basic_ed           := pr_tax.basic_excise * ln_entry_type;
2413     --added for bug#9854329,start
2414   IF (r_base_trx.transaction_type = 'RETURN TO VENDOR' AND
2415       p_register_entry_type = CENVAT_DEBIT AND
2416       nvl(lv_cr_rvrsl_flag,'N') = 'N')
2417    THEN
2418       ln_additional_ed      := pr_tax.addl_excise * ln_entry_type;
2419       ln_additional_cvd     := 0;
2420   ELSE
2421       ln_additional_ed      := (pr_tax.addl_excise + pr_tax.cvd) * ln_entry_type;
2422       ln_additional_cvd     := pr_tax.addl_cvd * ln_entry_type;
2423   END IF;
2424   --added for bug#9854329,end
2425     ln_other_ed           := pr_tax.other_excise * ln_entry_type;
2426 
2427     if lb_rg_debug then
2428       FND_FILE.put_line(FND_FILE.log,'Before call to jai_cmn_rg_23ac_i_trxs_pkg.insert_row');
2429     end if;
2430 
2431     lv_statement_id := '7';
2432     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
2433     jai_cmn_rg_23ac_i_trxs_pkg.insert_row(
2434         p_register_id                   => p_register_id,
2435         p_inventory_item_id             => r_trx.inventory_item_id,
2436         p_organization_id               => r_trx.organization_id,
2437         p_quantity_received             => ln_quantity,
2438         p_receipt_id                    => r_trx.transaction_id,
2439         p_transaction_type              => lv_transaction_type,
2440         p_receipt_date                  => r_trx.transaction_date,      -- Why cant this be ShipmentHeader.Receipt_date
2441         p_po_header_id                  => r_base_trx.po_header_id,
2442         p_po_header_date                => r_po_header.creation_date,
2443         p_po_line_id                    => r_base_trx.po_line_id,
2444         p_po_line_location_id           => r_base_trx.po_line_location_id,
2445         p_vendor_id                     => ln_vendor_id,
2446         p_vendor_site_id                => ln_vendor_site_id,
2447         p_customer_id                   => ln_customer_id,
2448         p_customer_site_id              => ln_customer_site_id,
2449         p_goods_issue_id                => NULL,
2450         p_goods_issue_date              => NULL,
2451         p_goods_issue_quantity          => NULL,
2452         p_sales_invoice_id              => NULL,
2453         p_sales_invoice_date            => NULL,
2454         p_sales_invoice_quantity        => NULL,
2455         p_excise_invoice_id             => lv_excise_invoice_no,
2456         p_excise_invoice_date           => ld_excise_invoice_date,
2457         p_oth_receipt_quantity          => NULL,
2458         p_oth_receipt_id                => NULL,
2459         p_oth_receipt_date              => NULL,
2460         p_register_type                 => jai_general_pkg.get_rg_register_type(p_item_class => r_trx.item_class),
2461         p_identification_no             => NULL,
2462         p_identification_mark           => NULL,
2463         p_brand_name                    => NULL,
2464         p_date_of_verification          => NULL,
2465         p_date_of_installation          => NULL,
2466         p_date_of_commission            => NULL,
2467         p_regiser_id_part_ii            => NULL,
2468         p_place_of_install              => NULL,
2469         p_remarks                       => NULL,
2470         p_location_id                   => r_trx.location_id,
2471         p_transaction_uom_code          => r_trx.uom_code,
2472         p_transaction_date              => r_trx.transaction_date,
2473         p_basic_ed                      => ln_basic_ed,
2474         p_additional_ed                 => ln_additional_ed,
2475         p_additional_cvd                => ln_additional_cvd,     -- Date 30/10/2006 Bug 5228046 added by sacsethi
2476         p_other_ed                      => ln_other_ed,
2477         p_charge_account_id             => NULL,
2478         p_transaction_source            => r_base_trx.source_document_code,
2479         p_called_from                   => 'CENVAT_RG_PKG.rg23_part_i_entry',
2480         p_simulate_flag                 => p_simulate_flag,
2481         p_process_status                => p_process_status,
2482         p_process_message               => p_process_message
2483     );
2484 
2485     /*bgowrava for forward porting Bug#5756676..start*/
2486 
2487 			UPDATE JAI_RCV_TRANSACTIONS
2488 				 SET quantity_register_flag  = 'Y',
2489 						 last_updated_by         = fnd_global.user_id,
2490 						 last_update_date        = sysdate,
2491 						 last_update_login       = fnd_global.login_id
2492 			 WHERE transaction_id          = p_transaction_id ;
2493 
2494 		  FND_FILE.put_line(FND_FILE.log, 'Updating quantity register flag to Y');
2495 
2496   /*bgowrava for forward porting Bug#5756676..end*/
2497 
2498     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath, null, 'END'); /* 8 */
2499 
2500   EXCEPTION
2501     WHEN OTHERS THEN
2502       p_process_status := 'E';
2503       p_process_message := 'CENVAT_RG_PKG.rg23_part_i_entry->'||SQLERRM||', StmtId->'||lv_statement_id;
2504       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
2505       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
2506 
2507   END rg23_part_i_entry;
2508 
2509   PROCEDURE rg23_d_entry(
2510     p_transaction_id    IN NUMBER,
2511     pr_tax                IN  TAX_BREAKUP,
2512     p_register_entry_type       IN VARCHAR2,
2513     p_register_id OUT NOCOPY NUMBER,
2514     p_process_status OUT NOCOPY VARCHAR2,
2515     p_process_message OUT NOCOPY VARCHAR2,
2516     p_simulate_flag     IN VARCHAR2,
2517     p_codepath          IN OUT NOCOPY VARCHAR2
2518   ) IS
2519 
2520     CURSOR c_rma_tax_rate(cp_oe_order_line_id IN NUMBER) IS
2521       SELECT rel.excise_duty_rate
2522       FROM JAI_OM_OE_RMA_LINES rel
2523       WHERE rel.rma_line_id = cp_oe_order_line_id;
2524 
2525     CURSOR c_parent_register_id(cp_receipt_id IN NUMBER, cp_transaction_id IN NUMBER) IS
2526       SELECT register_id
2527       FROM JAI_CMN_RG_23D_TRXS
2528       WHERE receipt_ref = cp_receipt_id
2529       ANd transaction_source_num = cp_transaction_id;
2530 
2531     CURSOR c_tax_rate(cp_shipment_line_id IN NUMBER) IS
2532       SELECT tax_rate
2533       FROM JAI_RCV_LINE_TAXES
2534       WHERE shipment_line_id = cp_shipment_line_id
2535       AND tax_type IN (jai_constants.tax_type_excise,
2536                        jai_constants.tax_type_exc_additional,
2537                        jai_constants.tax_type_exc_other,
2538 		       jai_constants.tax_type_cvd,
2539 		       jai_constants.tax_type_add_cvd)
2540       --AND upper(tax_type) IN ('EXCISE', 'ADDL. EXCISE', 'OTHER EXCISE', 'CVD')
2541       -- we need not include the CESS here, because the rate should correspond to actual tax instead of cess
2542       ORDER BY tax_line_no;
2543 
2544     r_trx                     c_trx%ROWTYPE;
2545     r_base_trx                c_base_trx%ROWTYPE;
2546 
2547     ln_register_id            JAI_CMN_RG_23D_TRXS.register_id%TYPE;
2548     ln_vendor_id              RCV_TRANSACTIONS.vendor_id%TYPE;
2549     ln_vendor_site_id         RCV_TRANSACTIONS.vendor_site_id%TYPE;
2550     lv_excise_invoice_no      JAI_CMN_RG_23D_TRXS.comm_invoice_no%TYPE;
2551     ld_excise_invoice_date    JAI_CMN_RG_23D_TRXS.comm_invoice_date%TYPE;
2552     ln_excise_duty_rate       JAI_CMN_RG_23D_TRXS.excise_duty_rate%TYPE;
2553     lv_transaction_type       RCV_TRANSACTIONS.transaction_type%TYPE;
2554     lv_transaction_uom_code   MTL_UNITS_OF_MEASURE.uom_code%TYPE;
2555     ln_customer_id            RCV_TRANSACTIONS.customer_id%TYPE;
2556     ln_customer_site_id       RCV_TRANSACTIONS.customer_site_id%TYPE;
2557     r_parent_base_trx         c_base_trx%ROWTYPE;
2558 
2559     ln_entry_type             NUMBER;   --File.Sql.35 Cbabu  := 1;
2560     ln_basic_ed               NUMBER;
2561     ln_additional_ed          NUMBER;
2562     ln_other_ed               NUMBER;
2563     ln_additional_cvd         NUMBER;    -- Date 30/10/2006 Bug 5228046 added by sacsethi
2564     ln_cvd                    NUMBER;
2565     ln_duty_amount            NUMBER;
2566     ln_quantity_received      NUMBER;
2567     ln_qty_to_adjust          NUMBER;
2568 
2569     ln_ancestor_reg_id        JAI_CMN_RG_23D_TRXS.register_id%TYPE;
2570     ln_ancestor_trxn_id       RCV_TRANSACTIONS.transaction_id%TYPE;
2571 
2572     lv_statement_id           VARCHAR2(5);
2573 
2574     ln_other_tax_debit        NUMBER;
2575     ln_other_tax_credit       NUMBER;
2576 
2577   BEGIN
2578 
2579     ln_entry_type := 1;
2580 
2581     if lb_rg_debug then
2582 
2583     -- Date 30/10/2006 Bug 5228046 added by sacsethi
2584       FND_FILE.put_line(FND_FILE.log,'^ RG23_D_Entry. Basic:'||pr_tax.basic_excise
2585         ||', Addl:'||pr_tax.addl_excise||', Other:'||pr_tax.other_excise
2586         ||', CVD:'||pr_tax.cvd||', Addl. CVD:'||pr_tax.addl_cvd||', EntryType:'||p_register_entry_type ||', PrcSta:'||p_process_status
2587       );
2588     end if;
2589 
2590     lv_statement_id := '1';
2591     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.23_d', 'START'); /* 1 */
2592     OPEN c_trx(p_transaction_id);
2593     FETCH c_trx INTO r_trx;
2594     CLOSE c_trx;
2595 
2596     lv_statement_id := '2';
2597     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
2598     OPEN c_base_trx(p_transaction_id);
2599     FETCH c_base_trx INTO r_base_trx;
2600     CLOSE c_base_trx;
2601 
2602     ln_customer_id      := r_base_trx.customer_id;
2603     ln_customer_site_id := r_base_trx.customer_site_id;
2604 
2605     IF r_base_trx.source_document_code = 'REQ' THEN
2606       lv_statement_id := '3';
2607       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
2608       OPEN c_source_orgn_loc( r_base_trx.shipment_header_id, r_base_trx.requisition_line_id);
2609       FETCH c_source_orgn_loc INTO ln_vendor_id, ln_vendor_site_id;
2610       CLOSE c_source_orgn_loc;
2611 
2612       ln_vendor_id      := -ln_vendor_id;
2613       ln_vendor_site_id := -ln_vendor_site_id;
2614 
2615     ELSE
2616       ln_vendor_id      := r_base_trx.vendor_id;
2617       ln_vendor_site_id := r_base_trx.vendor_site_id;
2618     END IF;
2619 
2620     lv_excise_invoice_no    := r_trx.excise_invoice_no;
2621     ld_excise_invoice_date  := r_trx.excise_invoice_date;
2622 
2623     IF r_trx.transaction_type = 'CORRECT' THEN
2624       lv_transaction_type := r_trx.parent_transaction_type;
2625     ELSE
2626       lv_transaction_type := r_trx.transaction_type;
2627     END IF;
2628 
2629     IF r_base_trx.source_document_code = 'RMA' THEN
2630       lv_statement_id := '4';
2631       p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
2632       OPEN c_rma_tax_rate(r_base_trx.oe_order_line_id);
2633       FETCH c_rma_tax_rate INTO ln_excise_duty_rate;
2634       CLOSE c_rma_tax_rate;
2635 
2636       IF ln_customer_site_id IS NULL THEN
2637         /*OPEN c_base_trx( jai_rcv_trx_processing_pkg.get_ancestor_id
2638                               (p_transaction_id     => r_trx.transaction_id,
2639                                p_shipment_line_id   => r_trx.shipment_line_id,
2640                                p_required_trx_type  => 'RECEIVE')
2641                        );*/
2642         OPEN c_base_trx(r_trx.tax_transaction_id);
2643         FETCH c_base_trx INTO r_parent_base_trx;
2644         CLOSE c_base_trx;
2645 
2646         ln_customer_site_id := r_parent_base_trx.customer_site_id;
2647       END IF;
2648 
2649     ELSE
2650       lv_statement_id := '4.1';
2651       p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
2652       OPEN c_tax_rate(r_trx.shipment_line_id);
2653       FETCH c_tax_rate INTO ln_excise_duty_rate;
2654       CLOSE c_tax_rate;
2655     END IF;
2656 
2657     lv_statement_id := '5';
2658     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
2659     lv_transaction_uom_code := r_trx.uom_code;
2660 
2661     IF p_register_entry_type = CENVAT_DEBIT THEN
2662       ln_entry_type := -1;
2663       ln_other_tax_debit    := pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess+nvl(pr_tax.sh_exc_edu_cess,0)+ nvl(pr_tax.sh_cvd_edu_cess,0);/*added pr_tax.sh_exc_edu_cess + pr_tax.sh_cvd_edu_cess by vkaranam for budget 07 impact - bug#5989740*/
2664     ELSIF p_register_entry_type = CENVAT_CREDIT THEN
2665       ln_entry_type := 1;
2666       ln_other_tax_credit   := pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess+nvl(pr_tax.sh_exc_edu_cess,0)+ nvl(pr_tax.sh_cvd_edu_cess,0);/*added pr_tax.sh_exc_edu_cess + pr_tax.sh_cvd_edu_cess by vkaranam for budget 07 impact - bug#5989740*/
2667     END IF;
2668 
2669     ln_quantity_received  := r_trx.quantity * ln_entry_type;
2670     ln_qty_to_adjust      := ln_quantity_received;
2671 
2672     ln_basic_ed           := pr_tax.basic_excise * ln_entry_type;
2673 
2674     /* Bug 4516667. Added by Lakshmi.
2675      Removed CVD from additional amount. This is accidentally added to
2676      additional excise */
2677 
2678     ln_additional_ed      := pr_tax.addl_excise  * ln_entry_type;
2679     ln_other_ed           := pr_tax.other_excise * ln_entry_type;
2680     ln_cvd                := pr_tax.cvd * ln_entry_type;
2681 
2682     -- Date 30/10/2006 Bug 5228046 added by sacsethi
2683     -- START BUG 5228046
2684     ln_additional_cvd     := pr_tax.addl_cvd * ln_entry_type;
2685     ln_duty_amount        := ln_basic_ed + ln_additional_ed + ln_other_ed + ln_cvd; /*addl. CVD excluded for bug 5752026 (FP for bug 5747435)*/
2686     -- END BUG 5228046
2687 
2688     IF ln_qty_to_adjust < 0 OR lv_transaction_type = 'RETURN TO VENDOR' THEN
2689       ln_qty_to_adjust := 0;
2690     END IF;
2691 
2692     if lb_rg_debug then
2693       FND_FILE.put_line(FND_FILE.log,'Calling jai_cmn_rg_23d_trxs_pkg.insert_row');
2694     end if;
2695 
2696     lv_statement_id := '6';
2697     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
2698     jai_cmn_rg_23d_trxs_pkg.insert_row(
2699         p_register_id                   => p_register_id,
2700         p_organization_id               => r_trx.organization_id,
2701         p_location_id                   => r_trx.location_id,
2702         p_transaction_type              => lv_transaction_type,
2703         p_receipt_id                    => p_transaction_id,
2704         p_quantity_received             => ln_quantity_received,
2705         p_inventory_item_id             => r_trx.inventory_item_id,
2706         p_subinventory                  => r_base_trx.subinventory,
2707         p_reference_line_id             => r_trx.shipment_line_id,
2708         p_transaction_uom_code          => lv_transaction_uom_code,
2709         p_customer_id                   => ln_customer_id,
2710         p_bill_to_site_id               => NULL,
2711         p_ship_to_site_id               => ln_customer_site_id,
2712         p_quantity_issued               => NULL,
2713         p_register_code                 => NULL,
2714         p_released_date                 => NULL,
2715         p_comm_invoice_no               => lv_excise_invoice_no,
2716         p_comm_invoice_date             => ld_excise_invoice_date,
2717         p_receipt_boe_num               => jai_general_pkg.get_matched_boe_no(p_transaction_id),
2718         p_oth_receipt_id                => NULL,
2719         p_oth_receipt_date              => NULL,
2720         p_oth_receipt_quantity          => NULL,
2721         p_remarks                       => 'Live-Trx/PrntTrx:'||r_trx.transaction_id||'/'||r_trx.parent_transaction_id,
2722         p_qty_to_adjust                 => ln_qty_to_adjust,
2723         /* Bug 4516667.
2724          As per discussion with Vikram and Gadde rounding to 4 decimal places
2725 	 for rate per unit */
2726         p_rate_per_unit                 => round(ln_duty_amount/ln_quantity_received,4),
2727         p_excise_duty_rate              => ln_excise_duty_rate,
2728         p_charge_account_id             => NULL,    -- this will be updated later by calling update procedure
2729         p_duty_amount                   => ln_duty_amount,
2730         p_receipt_date                  => r_trx.transaction_date,
2731         p_goods_issue_id                => NULL,
2732         p_goods_issue_date              => NULL,
2733         p_goods_issue_quantity          => NULL,
2734         p_transaction_date              => r_trx.transaction_date,
2735         p_basic_ed                      => ln_basic_ed,
2736         p_additional_ed                 => ln_additional_ed,
2737         p_additional_cvd                => ln_additional_cvd,  -- Date 30/10/2006 Bug 5228046 added by sacsethi
2738         p_other_ed                      => ln_other_ed,
2739         p_cvd                           => ln_cvd,
2740         p_vendor_id                     => ln_vendor_id,
2741         p_vendor_site_id                => ln_vendor_site_id,
2742         p_receipt_num                   => r_trx.receipt_num,
2743         p_attribute1                    => NULL,
2744         p_attribute2                    => NULL,
2745         p_attribute3                    => NULL,
2746         p_attribute4                    => NULL,
2747         p_attribute5                    => NULL,
2748         p_consignee                     => NULL,
2749         p_manufacturer_name             => NULL,
2750         p_manufacturer_address          => NULL,
2751         p_manufacturer_rate_amt_per_un  => NULL,
2752         p_qty_received_from_manufactur  => NULL,
2753         p_tot_amt_paid_to_manufacturer  => NULL,
2754         p_other_tax_credit              => ln_other_tax_credit,
2755         p_other_tax_debit               => ln_other_tax_debit,
2756         p_transaction_source            => r_base_trx.source_document_code,
2757         p_called_from                   => 'CENVAT_RG_PKG.rg23_d_entry',
2758         p_simulate_flag                 => p_simulate_flag,
2759         p_process_status                => p_process_status,
2760         p_process_message               => p_process_message
2761     );
2762 
2763     p_codepath := jai_general_pkg.plot_codepath(7.1, p_codepath);
2764     lv_statement_id := '6.1';
2765     -- Vijay Shankar for Bug#3940588 EDUCATION CESS
2766     IF pr_tax.excise_edu_cess <> 0 THEN
2767       IF p_register_entry_type = CENVAT_DEBIT THEN
2768         ln_other_tax_debit  := pr_tax.excise_edu_cess;
2769       ELSE
2770         ln_other_tax_credit := pr_tax.excise_edu_cess;
2771       END IF;
2772       jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
2773           p_source_register     => jai_constants.reg_rg23d,
2774           p_source_register_id  => p_register_id,
2775           p_tax_type            => jai_constants.tax_type_exc_edu_cess,
2776           p_credit              => ln_other_tax_credit,
2777           p_debit               => ln_other_tax_debit,
2778           p_process_status      => p_process_status,
2779           p_process_message     => p_process_message
2780        );
2781     END IF;
2782 
2783     lv_statement_id := '6.2';
2784     p_codepath := jai_general_pkg.plot_codepath(7.2, p_codepath);
2785 
2786     IF pr_tax.cvd_edu_cess <> 0 THEN
2787       IF p_register_entry_type = CENVAT_DEBIT THEN
2788         ln_other_tax_debit  := pr_tax.cvd_edu_cess;
2789       ELSE
2790         ln_other_tax_credit := pr_tax.cvd_edu_cess;
2791       END IF;
2792       jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
2793           p_source_register     => jai_constants.reg_rg23d,
2794           p_source_register_id  => p_register_id,
2795           p_tax_type            => jai_constants.tax_type_cvd_edu_cess,
2796           p_credit              => ln_other_tax_credit,
2797           p_debit               => ln_other_tax_debit,
2798           p_process_status      => p_process_status,
2799           p_process_message     => p_process_message
2800        );
2801     END IF;
2802  /*added the following by vkaranam for budget 07 impact - bug#5989740*/
2803   --start
2804   lv_statement_id := '6.3';
2805 	p_codepath := jai_general_pkg.plot_codepath(7.3, p_codepath);
2806 
2807 	 IF pr_tax.sh_exc_edu_cess <> 0 THEN
2808 	    IF p_register_entry_type = CENVAT_DEBIT THEN
2809 	      ln_other_tax_debit  := pr_tax.sh_exc_edu_cess;
2810 	    ELSE
2811 	      ln_other_tax_credit := pr_tax.sh_exc_edu_cess;
2812 	    END IF;
2813 
2814 	    jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
2815 	        p_source_register     => jai_constants.reg_rg23d,
2816 	        p_source_register_id  => p_register_id,
2817 	        p_tax_type            => jai_constants.tax_type_sh_exc_edu_cess,
2818 	        p_credit              => ln_other_tax_credit,
2819 	        p_debit               => ln_other_tax_debit,
2820 	        p_process_status      => p_process_status,
2821 	        p_process_message     => p_process_message
2822 	     );
2823   END IF;
2824 
2825   lv_statement_id := '6.4';
2826 	p_codepath := jai_general_pkg.plot_codepath(7.4, p_codepath);
2827 
2828 	 IF pr_tax.sh_cvd_edu_cess <> 0 THEN
2829 			IF p_register_entry_type = CENVAT_DEBIT THEN
2830 				ln_other_tax_debit  := pr_tax.sh_cvd_edu_cess;
2831 			ELSE
2832 				ln_other_tax_credit := pr_tax.sh_cvd_edu_cess;
2833 			END IF;
2834 			  jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
2835 					p_source_register     => jai_constants.reg_rg23d,
2836 					p_source_register_id  => p_register_id,
2837 					p_tax_type            => jai_constants.tax_type_sh_cvd_edu_cess,
2838 					p_credit              => ln_other_tax_credit,
2839 					p_debit               => ln_other_tax_debit,
2840 					p_process_status      => p_process_status,
2841 					p_process_message     => p_process_message
2842  			 );
2843 	END IF;
2844 	--end bug#5989740
2845 
2846 
2847     lv_statement_id := '6.5';
2848     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath); /* 8 */
2849 
2850     -- following code to update parent RG23D entry with transaction qty
2851     IF lv_transaction_type = 'RETURN TO VENDOR' OR ln_quantity_received < 0 THEN
2852       FND_FILE.put_line(FND_FILE.log, 'To Update Qty_To_Adjust field of RG23D Table' );
2853 
2854       lv_statement_id := '7';
2855       p_codepath := jai_general_pkg.plot_codepath(9, p_codepath); /* 9 */
2856       ln_quantity_received  := nvl(r_base_trx.primary_quantity, r_base_trx.quantity);
2857 
2858       -- this is to reduce main RG23D entry of RECEIVE transaction incase of -ve RECEIVE Correction
2859       IF lv_transaction_type = 'RECEIVE' THEN
2860         ln_quantity_received := -ln_quantity_received;
2861       END IF;
2862 
2863       ln_ancestor_trxn_id   := jai_rcv_trx_processing_pkg.get_ancestor_id(
2864                                   p_transaction_id    => r_trx.transaction_id,
2865                                   p_shipment_line_id  => r_trx.shipment_line_id,
2866                                   p_required_trx_type => 'RECEIVE'
2867                                );
2868 
2869       lv_statement_id := '8';
2870       p_codepath := jai_general_pkg.plot_codepath(10, p_codepath); /* 10 */
2871       OPEN c_parent_register_id(ln_ancestor_trxn_id, 18);
2872       FETCH c_parent_register_id INTO ln_ancestor_reg_id;
2873       CLOSE c_parent_register_id;
2874 
2875       if lb_rg_debug then
2876         FND_FILE.put_line(FND_FILE.log,'Calling jai_cmn_rg_23d_trxs_pkg.update_qty_to_adjust');
2877       end if;
2878 
2879       lv_statement_id := '9';
2880       p_codepath := jai_general_pkg.plot_codepath(11, p_codepath); /* 11 */
2881       jai_cmn_rg_23d_trxs_pkg.update_qty_to_adjust(
2882           p_register_id     => ln_ancestor_reg_id,
2883           p_quantity        => ln_quantity_received ,
2884           p_simulate_flag   => p_simulate_flag,
2885           p_process_status  => p_process_status,
2886           p_process_message => p_process_message
2887       );
2888 
2889     END IF;
2890 
2891     p_codepath := jai_general_pkg.plot_codepath(12, p_codepath, null, 'END'); /* 12 */
2892 
2893   EXCEPTION
2894     WHEN OTHERS THEN
2895       p_process_status := 'E';
2896       p_process_message := 'CENVAT_RG_PKG.rg23_d_entry->'||SQLERRM||', StmtId->'||lv_statement_id;
2897       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
2898       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
2899 
2900   END rg23_d_entry;
2901 
2902   PROCEDURE rg23_part_ii_entry(
2903     p_transaction_id        IN        NUMBER,
2904     pr_tax                  IN        TAX_BREAKUP,
2905     p_part_i_register_id    IN        NUMBER,
2906     p_register_entry_type   IN        VARCHAR2,
2907     p_reference_num         IN        VARCHAR2,
2908     p_register_id OUT NOCOPY NUMBER,
2909     p_process_status OUT NOCOPY VARCHAR2,
2910     p_process_message OUT NOCOPY VARCHAR2,
2911     p_simulate_flag         IN        VARCHAR2,
2912     p_codepath              IN OUT NOCOPY VARCHAR2
2913   ) IS
2914 
2915     r_trx                     c_trx%ROWTYPE;
2916     r_base_trx                c_base_trx%ROWTYPE;
2917     r_parent_trx              c_trx%ROWTYPE;
2918 
2919    r_rtv_trx                 c_trx%ROWTYPE;/*vkaranam for bug#4767479*/
2920   ln_reference_num          NUMBER ;/*vkaranam for bug#4767479*/
2921   lv_exc_flag               VARCHAR2 (1);/*vkaranam for bug#4767479*/
2922 
2923     ln_register_id            JAI_CMN_RG_23AC_II_TRXS.register_id%TYPE;
2924     ln_vendor_id              RCV_TRANSACTIONS.vendor_id%TYPE;
2925     ln_vendor_site_id         RCV_TRANSACTIONS.vendor_site_id%TYPE;
2926     lv_transaction_type       RCV_TRANSACTIONS.transaction_type%TYPE;
2927     lv_excise_invoice_no      JAI_CMN_RG_23AC_II_TRXS.excise_invoice_no%TYPE;
2928     ld_excise_invoice_date    JAI_CMN_RG_23AC_II_TRXS.excise_invoice_date%TYPE;
2929     ln_customer_id            RCV_TRANSACTIONS.customer_id%TYPE;
2930     ln_customer_site_id       RCV_TRANSACTIONS.customer_site_id%TYPE;
2931     r_parent_base_trx         c_base_trx%ROWTYPE;
2932 
2933     ln_cr_basic               JAI_CMN_RG_23AC_II_TRXS.cr_basic_ed%TYPE;
2934     ln_cr_addl                JAI_CMN_RG_23AC_II_TRXS.cr_additional_ed%TYPE;
2935     ln_cr_other               JAI_CMN_RG_23AC_II_TRXS.cr_other_ed%TYPE;
2936     ln_dr_basic               JAI_CMN_RG_23AC_II_TRXS.dr_basic_ed%TYPE;
2937     ln_dr_addl                JAI_CMN_RG_23AC_II_TRXS.dr_additional_ed%TYPE;
2938     ln_dr_other               JAI_CMN_RG_23AC_II_TRXS.dr_other_ed%TYPE;
2939 
2940 -- Date 04/06/2007 by sacsethi for bug 5228046
2941     ln_cr_addl_cvd            JAI_CMN_RG_23AC_II_TRXS.cr_additional_cvd%TYPE;
2942     ln_dr_addl_cvd            JAI_CMN_RG_23AC_II_TRXS.dr_additional_cvd%TYPE;
2943 
2944 
2945     lv_statement_id           VARCHAR2(5);
2946     ln_other_tax_credit       NUMBER;
2947     ln_other_tax_debit        NUMBER;
2948     lv_register_type          JAI_CMN_RG_23AC_II_TRXS.register_type%TYPE;
2949     lv_source_register        JAI_CMN_RG_OTHERS.source_register%TYPE;
2950 
2951       --start additions for bug#9854329
2952     lv_cr_rvrsl_flag jai_cmn_inventory_orgs.CENVAT_CR_REVRSL_FLAG%TYPE;
2953   cursor get_rev_flag(cp_organization_id in number,cp_location_id in number)
2954       is
2955       SELECT CENVAT_CR_REVRSL_FLAG FROM jai_cmn_inventory_orgs
2956   WHERE organization_id = cp_organization_id
2957     AND location_id =cp_location_id;
2958 
2959     --end bug#9854329
2960 
2961   BEGIN
2962 
2963     if lb_rg_debug then
2964       FND_FILE.put_line(FND_FILE.log,'^ RG23_PART_II_Entry. Basic:'||pr_tax.basic_excise
2965         ||', Addl:'||pr_tax.addl_excise||', Other:'||pr_tax.other_excise
2966         ||', CVD:'||pr_tax.cvd||', ExCes:'||pr_tax.excise_edu_cess||', CvdCes:'||pr_tax.cvd_edu_cess
2967         ||', EntryType:'||p_register_entry_type ||', PrcSta:'||p_process_status
2968         ||', Part1Id:'||p_part_i_register_id||', RefNo:'||p_reference_num
2969       );
2970     end if;
2971 
2972     lv_statement_id := '1';
2973     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.23_part_ii', 'START'); /* 1 */
2974     OPEN c_trx(p_transaction_id);
2975     FETCH c_trx INTO r_trx;
2976     CLOSE c_trx;
2977 
2978     lv_statement_id := '2';
2979     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
2980     OPEN c_base_trx(p_transaction_id);
2981     FETCH c_base_trx INTO r_base_trx;
2982     CLOSE c_base_trx;
2983 
2984       --start additions for bug#9854329
2985     open get_rev_flag (r_trx.organization_id,r_trx.location_id);
2986     fetch get_rev_flag  INTO lv_cr_rvrsl_flag ;
2987     close get_rev_flag;
2988     --end bug#9854329
2989 
2990     ln_customer_id      := r_base_trx.customer_id;
2991     ln_customer_site_id := r_base_trx.customer_site_id;
2992 
2993     IF r_base_trx.source_document_code = 'REQ' THEN
2994       lv_statement_id := '3';
2995       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
2996       OPEN c_source_orgn_loc( r_base_trx.shipment_header_id, r_base_trx.requisition_line_id);
2997       FETCH c_source_orgn_loc INTO ln_vendor_id, ln_vendor_site_id;
2998       CLOSE c_source_orgn_loc;
2999 
3000       ln_vendor_id      := -ln_vendor_id;
3001       ln_vendor_site_id := -ln_vendor_site_id;
3002 
3003     ELSE
3004 
3005       -- Vijay Shankar for Bug#3940588
3006       get_changed_vendor_dtls(
3007         p_receive_trx_id      => r_trx.tax_transaction_id,
3008         p_shipment_line_id    => r_trx.shipment_line_id,
3009         p_vendor_id           => ln_vendor_id,
3010         p_vendor_site_id      => ln_vendor_site_id
3011       );
3012 
3013       ln_vendor_id      := nvl(ln_vendor_id, r_base_trx.vendor_id);
3014       ln_vendor_site_id := nvl(ln_vendor_site_id, r_base_trx.vendor_site_id);
3015 
3016     END IF;
3017 
3018     IF r_base_trx.source_document_code = 'RMA' THEN
3019       IF ln_customer_site_id IS NULL THEN
3020         /*OPEN c_base_trx( jai_rcv_trx_processing_pkg.get_ancestor_id
3021                               (p_transaction_id     => r_trx.transaction_id,
3022                                p_shipment_line_id   => r_trx.shipment_line_id,
3023                                p_required_trx_type  => 'RECEIVE')
3024                        );*/
3025         OPEN c_base_trx(r_trx.tax_transaction_id);
3026         FETCH c_base_trx INTO r_parent_base_trx;
3027         CLOSE c_base_trx;
3028 
3029         ln_customer_site_id := r_parent_base_trx.customer_site_id;
3030       END IF;
3031     END IF;
3032 
3033     IF r_trx.transaction_type = 'CORRECT' THEN
3034       lv_transaction_type := r_trx.parent_transaction_type;
3035     ELSE
3036       lv_transaction_type := r_trx.transaction_type;
3037     END IF;
3038 
3039     -- p_reference_num will contain parent RECEIVE trx_id incase of PARENT REGULAR 50% that is passed during RTV of CGIN item
3040     IF lv_transaction_type = 'RETURN TO VENDOR' AND p_reference_num IN (CGIN_FIRST_CLAIM, CGIN_SECOND_CLAIM) THEN
3041       OPEN c_trx(to_number(p_reference_num));
3042       FETCH c_trx INTO r_parent_trx;
3043       CLOSE c_trx;
3044       lv_excise_invoice_no    := r_parent_trx.excise_invoice_no;
3045       ld_excise_invoice_date  := r_parent_trx.excise_invoice_date;
3046  ELSIF lv_transaction_type = 'RECEIVE' AND p_reference_num IS NOT NULL THEN /*elsif added by vkaranam for bug#4767479*/
3047     /*p_reference_num would have the transaction id of Return to Vendor in case of Partial RTV auto claim record*/
3048 
3049     BEGIN
3050       ln_reference_num := to_number(p_reference_num);
3051       lv_exc_flag      := 'A'; /*A indiactes auto claim for RTV*/
3052       FND_FILE.put_line(FND_FILE.log,'p_reference_num:'||p_reference_num);
3053     EXCEPTION
3054       WHEN OTHERS THEN
3055         /*this exception would come if p_reference_num does not contain a number. It means p_reference_num is not having any transaction_id
3056          This means this transaction belongs to normal RECEIVE transaction*/
3057         lv_exc_flag      := 'C'; /*C indicates claim for Receipt transaction*/
3058         FND_FILE.put_line(FND_FILE.log,'Exception '||sqlerrm||' occurred and is handled');
3059         FND_FILE.put_line(FND_FILE.log,'p_reference_num:'||p_reference_num);
3060     END;
3061     IF lv_exc_flag = 'A' THEN
3062       OPEN c_trx(ln_reference_num);
3063       FETCH c_trx INTO r_rtv_trx;
3064       CLOSE c_trx;
3065       IF r_rtv_trx.transaction_type = 'RETURN TO VENDOR' THEN
3066         lv_excise_invoice_no    := r_trx.excise_invoice_no||'/1';
3067         ld_excise_invoice_date  := r_trx.excise_invoice_date;
3068       ELSE
3069         lv_excise_invoice_no    := r_trx.excise_invoice_no;
3070         ld_excise_invoice_date  := r_trx.excise_invoice_date;
3071       END IF ;
3072     ELSIF lv_exc_flag = 'C' THEN
3073       lv_excise_invoice_no    := r_trx.excise_invoice_no;
3074       ld_excise_invoice_date  := r_trx.excise_invoice_date;
3075     END IF ;
3076    --end additions for bug#4767479
3077     ELSE
3078       lv_excise_invoice_no    := r_trx.excise_invoice_no;
3079       ld_excise_invoice_date  := r_trx.excise_invoice_date;
3080     END IF;
3081 
3082     lv_statement_id := '4';
3083     p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
3084     IF p_register_entry_type = CENVAT_DEBIT THEN
3085       ln_dr_basic   := pr_tax.basic_excise;
3086    --   ln_dr_addl    := pr_tax.addl_excise + pr_tax.cvd; 9854329
3087       ln_dr_other   := pr_tax.other_excise;
3088     --added for bug#9854329,start
3089     IF (lv_transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3090       ln_dr_addl    := pr_tax.addl_excise;
3091       ln_dr_addl_cvd := 0;
3092       ln_other_tax_debit :=  nvl(pr_tax.excise_edu_cess ,0)
3093                              + nvl(pr_tax.sh_exc_edu_cess,0);
3094     ELSE
3095       ln_dr_addl    := nvl(pr_tax.addl_excise,0) + nvl(pr_tax.cvd,0);
3096       ln_dr_addl_cvd := nvl(pr_tax.addl_cvd,0);
3097       ln_other_tax_debit :=  nvl(pr_tax.excise_edu_cess,0) + nvl(pr_tax.cvd_edu_cess,0)
3098                              + nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0);
3099     END IF;
3100     --added for bug#9854329,end
3101     ELSE
3102       ln_cr_basic   := pr_tax.basic_excise;
3103       ln_cr_addl    := pr_tax.addl_excise + pr_tax.cvd;
3104       ln_cr_other   := pr_tax.other_excise;
3105       ln_cr_addl_cvd := pr_tax.addl_cvd; --Date 30/10/2006 Bug 5228046 added by sacsethi
3106       ln_other_tax_credit := pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess+ nvl(pr_tax.sh_exc_edu_cess,0)+ nvl(pr_tax.sh_cvd_edu_cess,0); --Bgowrava for Bug #6071509 ,Added SH related cess
3107     END IF;
3108 
3109     if lb_rg_debug then
3110       FND_FILE.put_line(FND_FILE.log,'Calling jai_cmn_rg_23ac_ii_pkg.insert_row');
3111     end if;
3112 
3113     lv_register_type := jai_general_pkg.get_rg_register_type(r_trx.item_class);
3114     if lv_register_type = jai_constants.register_type_a then
3115       lv_source_register := jai_constants.reg_rg23a_2;
3116     else
3117       lv_source_register := jai_constants.reg_rg23c_2;
3118     end if;
3119 
3120     lv_statement_id := '5';
3121     p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
3122     jai_cmn_rg_23ac_ii_pkg.insert_row(
3123         p_register_id                   => p_register_id,
3124         p_inventory_item_id             => r_trx.inventory_item_id,
3125         p_organization_id               => r_trx.organization_id,
3126         p_receipt_id                    => r_trx.transaction_id,
3127         p_receipt_date                  => r_trx.transaction_date,
3128         p_cr_basic_ed                   => ln_cr_basic,
3129         p_cr_additional_ed              => ln_cr_addl,
3130         p_cr_additional_cvd              => ln_cr_addl_cvd,  -- Date 30/10/2006 Bug 5228046 added by sacsethi
3131         p_cr_other_ed                   => ln_cr_other,
3132         p_dr_basic_ed                   => ln_dr_basic,
3133         p_dr_additional_ed              => ln_dr_addl,
3134         p_dr_additional_cvd              => ln_dr_addl_cvd, -- Date 30/10/2006 Bug 5228046 added by sacsethi
3135         p_dr_other_ed                   => ln_dr_other,
3136         p_excise_invoice_no             => lv_excise_invoice_no,
3137         p_excise_invoice_date           => ld_excise_invoice_date,
3138         p_register_type                 => lv_register_type,
3139         p_remarks                       => 'Live-Trx/PrntTrx:'||r_trx.transaction_id||'/'||r_trx.parent_transaction_id,
3140         p_vendor_id                     => ln_vendor_id,
3141         p_vendor_site_id                => ln_vendor_site_id,
3142         p_customer_id                   => ln_customer_id,
3143         p_customer_site_id              => ln_customer_site_id,
3144         p_location_id                   => r_trx.location_id,
3145         p_transaction_date              => SYSDATE, --r_trx.transaction_date, --Changed by Sanjikum for Bug #4293421
3146         p_charge_account_id             => NULL,
3147         p_register_id_part_i            => p_part_i_register_id,
3148         p_reference_num                 => p_reference_num,
3149         p_rounding_id                   => NULL,
3150         p_other_tax_credit              => ln_other_tax_credit,
3151         p_other_tax_debit               => ln_other_tax_debit,
3152         p_transaction_type              => lv_transaction_type,
3153         p_transaction_source            => r_base_trx.source_document_code,
3154         p_called_from                   => 'CENVAT_RG_PKG.rg23_part_ii_entry',
3155         p_simulate_flag                 => p_simulate_flag,
3156         p_process_status                => p_process_status,
3157         p_process_message               => p_process_message
3158     );
3159 
3160     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath);
3161 
3162     -- Vijay Shankar for Bug#3940588 EDUCATION CESS
3163     IF pr_tax.excise_edu_cess <> 0 THEN
3164       IF p_register_entry_type = CENVAT_DEBIT THEN
3165         ln_other_tax_debit  := pr_tax.excise_edu_cess;
3166       ELSE
3167         ln_other_tax_credit := pr_tax.excise_edu_cess;
3168       END IF;
3169       jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3170           p_source_register     => lv_source_register,
3171           p_source_register_id  => p_register_id,
3172           p_tax_type            => jai_constants.tax_type_exc_edu_cess,
3173           p_credit              => ln_other_tax_credit,
3174           p_debit               => ln_other_tax_debit,
3175           p_process_status      => p_process_status,
3176           p_process_message     => p_process_message
3177        );
3178     END IF;
3179 
3180     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath);
3181 
3182     IF pr_tax.cvd_edu_cess <> 0 THEN
3183       IF p_register_entry_type = CENVAT_DEBIT THEN
3184         --added for bug#9854329, start
3185       IF (lv_transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3186           ln_other_tax_debit  := 0; --pr_tax.cvd_edu_cess; --commented by Bgowrava for Bug#6530313
3187       ELSE
3188           ln_other_tax_debit  := nvl(pr_tax.cvd_edu_cess,0);
3189       END IF;
3190       --added for bug#9854329, end
3191       ELSE
3192         ln_other_tax_credit := pr_tax.cvd_edu_cess;
3193       END IF;
3194       jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3195           p_source_register     => lv_source_register,
3196           p_source_register_id  => p_register_id,
3197           p_tax_type            => jai_constants.tax_type_cvd_edu_cess,
3198           p_credit              => ln_other_tax_credit,
3199           p_debit               => ln_other_tax_debit,
3200           p_process_status      => p_process_status,
3201           p_process_message     => p_process_message
3202        );
3203     END IF;
3204 
3205     --For SH EDU CESS
3206     -- START,Bgowrava for Bug#6071509
3207     IF pr_tax.sh_exc_edu_cess <> 0 THEN
3208 		      IF p_register_entry_type = CENVAT_DEBIT THEN
3209 		        ln_other_tax_debit  := pr_tax.sh_exc_edu_cess;
3210 		      ELSE
3211 		        ln_other_tax_credit := pr_tax.sh_exc_edu_cess;
3212 		      END IF;
3213 		      jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3214 		          p_source_register     => lv_source_register,
3215 		          p_source_register_id  => p_register_id,
3216 		          p_tax_type            => jai_constants.tax_type_sh_exc_edu_cess,
3217 		          p_credit              => ln_other_tax_credit,
3218 		          p_debit               => ln_other_tax_debit,
3219 		          p_process_status      => p_process_status,
3220 		          p_process_message     => p_process_message
3221 		       );
3222 		    END IF;
3223 
3224 		    p_codepath := jai_general_pkg.plot_codepath(7, p_codepath);
3225 
3226 		    IF pr_tax.sh_cvd_edu_cess <> 0 THEN
3227 		      IF p_register_entry_type = CENVAT_DEBIT THEN
3228 		         --added for bug#9854329, start
3229           IF (lv_transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3230               ln_other_tax_debit  := 0;
3231           ELSE
3232               ln_other_tax_debit  := nvl(pr_tax.sh_cvd_edu_cess,0);
3233           END IF;
3234           --added for bug#9854329, end
3235 		      ELSE
3236 		        ln_other_tax_credit := pr_tax.sh_cvd_edu_cess;
3237 		      END IF;
3238 		      jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3239 		          p_source_register     => lv_source_register,
3240 		          p_source_register_id  => p_register_id,
3241 		          p_tax_type            => jai_constants.tax_type_sh_cvd_edu_cess,
3242 		          p_credit              => ln_other_tax_credit,
3243 		          p_debit               => ln_other_tax_debit,
3244 		          p_process_status      => p_process_status,
3245 		          p_process_message     => p_process_message
3246 		       );
3247     END IF;
3248 
3249      -- END,Bgowrava for Bug#6071509
3250 
3251     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath, null, 'END');
3252 
3253   EXCEPTION
3254     WHEN OTHERS THEN
3255       p_process_status := 'E';
3256       p_process_message := 'CENVAT_RG_PKG.rg23_part_ii_entry->'||SQLERRM||', StmtId->'||lv_statement_id;
3257       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
3258       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
3259 
3260   END rg23_part_ii_entry;
3261 
3262   PROCEDURE pla_entry(
3263     p_transaction_id        IN  NUMBER,
3264     pr_tax                  IN  TAX_BREAKUP,
3265     p_register_entry_type   IN  VARCHAR2,
3266     p_register_id OUT NOCOPY NUMBER,
3267     p_process_status OUT NOCOPY VARCHAR2,
3268     p_process_message OUT NOCOPY VARCHAR2,
3269     p_simulate_flag         IN  VARCHAR2,
3270     p_codepath              IN OUT NOCOPY VARCHAR2
3271   ) IS
3272 
3273     r_trx                     c_trx%ROWTYPE;
3274     r_base_trx                c_base_trx%ROWTYPE;
3275     r_orgn_info               c_orgn_info%ROWTYPE;
3276 
3277     ln_register_id            JAI_CMN_RG_PLA_TRXS.register_id%TYPE;
3278     ln_vendor_id              RCV_TRANSACTIONS.vendor_id%TYPE;
3279     ln_vendor_site_id         RCV_TRANSACTIONS.vendor_site_id%TYPE;
3280     lv_excise_invoice_no      JAI_CMN_RG_PLA_TRXS.DR_INVOICE_NO%TYPE;
3281     ld_excise_invoice_date    JAI_CMN_RG_PLA_TRXS.dr_invoice_date%TYPE;
3282     lv_transaction_type       RCV_TRANSACTIONS.transaction_type%TYPE;
3283 
3284     ln_cr_basic               JAI_CMN_RG_PLA_TRXS.cr_basic_ed%TYPE;
3285     ln_cr_addl                JAI_CMN_RG_PLA_TRXS.cr_additional_ed%TYPE;
3286     ln_cr_other               JAI_CMN_RG_PLA_TRXS.cr_other_ed%TYPE;
3287     ln_dr_basic               JAI_CMN_RG_PLA_TRXS.dr_basic_ed%TYPE;
3288     ln_dr_addl                JAI_CMN_RG_PLA_TRXS.dr_additional_ed%TYPE;
3289     ln_dr_other               JAI_CMN_RG_PLA_TRXS.dr_other_ed%TYPE;
3290 
3291     lv_statement_id           VARCHAR2(5);
3292     ln_other_tax_credit       NUMBER;
3293     ln_other_tax_debit        NUMBER;
3294       lv_cr_rvrsl_flag          jai_cmn_inventory_orgs.CENVAT_CR_REVRSL_FLAG%TYPE; --added for bug#9854329
3295      cursor get_rev_flag(cp_organization_id in number,cp_location_id in number)
3296       is
3297       SELECT CENVAT_CR_REVRSL_FLAG FROM jai_cmn_inventory_orgs
3298   WHERE organization_id = cp_organization_id
3299     AND location_id =cp_location_id;
3300 
3301   BEGIN
3302 
3303     if lb_rg_debug then
3304     FND_FILE.put_line(FND_FILE.log,'^ PLA_Entry. Basic:'||pr_tax.basic_excise
3305       ||', Addl:'||pr_tax.addl_excise||', Other:'||pr_tax.other_excise||', ExCes:'||pr_tax.excise_edu_cess||', CvdCes:'||pr_tax.cvd_edu_cess
3306       ||', SH_ExCes:'||pr_tax.sh_exc_edu_cess||', SH_CvdCes:'||pr_tax.sh_cvd_edu_cess /*added by vkaranam for bug #5989740*/
3307       ||', CVD:'||pr_tax.cvd
3308       ||', EntryType:'||p_register_entry_type ||', PrcSta:'||p_process_status
3309     );
3310    end if;
3311 
3312     if lb_rg_debug then
3313       FND_FILE.put_line(FND_FILE.log,'^ PLA_Entry');
3314     end if;
3315 
3316     lv_statement_id := '1';
3317     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.pla', 'START'); /* 1 */
3318     OPEN c_trx(p_transaction_id);
3319     FETCH c_trx INTO r_trx;
3320     CLOSE c_trx;
3321 
3322       --start additions for bug#9854329
3323     open get_rev_flag (r_trx.organization_id,r_trx.location_id);
3324     fetch get_rev_flag  INTO lv_cr_rvrsl_flag  ;
3325     close get_rev_flag;
3326     --end bug#9854329
3327 
3328     lv_statement_id := '2';
3329     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
3330     OPEN c_base_trx(p_transaction_id);
3331     FETCH c_base_trx INTO r_base_trx;
3332     CLOSE c_base_trx;
3333 
3334     IF r_base_trx.source_document_code = 'REQ' THEN
3335       lv_statement_id := '3';
3336       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
3337 
3338       OPEN c_source_orgn_loc( r_base_trx.shipment_header_id, r_base_trx.requisition_line_id);
3339       FETCH c_source_orgn_loc INTO ln_vendor_id, ln_vendor_site_id;
3340       CLOSE c_source_orgn_loc;
3341 
3342       ln_vendor_id      := -ln_vendor_id;
3343       ln_vendor_site_id := -ln_vendor_site_id;
3344 
3345     ELSE
3346 
3347       -- Vijay Shankar for Bug#3940588
3348       get_changed_vendor_dtls(
3349         p_receive_trx_id      => r_trx.tax_transaction_id,
3350         p_shipment_line_id    => r_trx.shipment_line_id,
3351         p_vendor_id           => ln_vendor_id,
3352         p_vendor_site_id      => ln_vendor_site_id
3353       );
3354 
3355       ln_vendor_id      := nvl(ln_vendor_id, r_base_trx.vendor_id);
3356       ln_vendor_site_id := nvl(ln_vendor_site_id, r_base_trx.vendor_site_id);
3357 
3358     END IF;
3359 
3360     IF r_trx.transaction_type = 'CORRECT' THEN
3361       lv_transaction_type := r_trx.parent_transaction_type;
3362     ELSE
3363       lv_transaction_type := r_trx.transaction_type;
3364     END IF;
3365 
3366     lv_excise_invoice_no    := r_trx.excise_invoice_no;
3367     ld_excise_invoice_date  := r_trx.excise_invoice_date;
3368 
3369     lv_statement_id := '4';
3370     p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
3371     IF p_register_entry_type = CENVAT_DEBIT THEN
3372       ln_dr_basic   := pr_tax.basic_excise;
3373      -- ln_dr_addl    := pr_tax.addl_excise + pr_tax.cvd; 9854329
3374       ln_dr_other   := pr_tax.other_excise;
3375    -- added by vkaranam for bug#9854329, start
3376     IF (        r_base_trx.transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3377       ln_dr_addl    := nvl(pr_tax.addl_excise,0);
3378       ln_other_tax_debit  := nvl(pr_tax.excise_edu_cess,0) + nvl(pr_tax.sh_exc_edu_cess,0);
3379     ELSE
3380       ln_dr_addl    := nvl(pr_tax.addl_excise,0) + nvl(pr_tax.cvd,0) + nvl(pr_tax.addl_cvd,0);
3381       ln_other_tax_debit  := nvl(pr_tax.excise_edu_cess,0) + nvl(pr_tax.cvd_edu_cess,0) + nvl(pr_tax.sh_exc_edu_cess,0)+ nvl(pr_tax.sh_cvd_edu_cess,0);
3382     END IF;
3383     -- added by vkaranam for bug#9854329, end
3384     ELSE
3385       ln_cr_basic   := pr_tax.basic_excise;
3386       ln_cr_addl    := pr_tax.addl_excise + pr_tax.cvd;
3387       ln_cr_other   := pr_tax.other_excise;
3388       ln_other_tax_credit  := pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess+nvl(pr_tax.sh_exc_edu_cess,0)+ nvl(pr_tax.sh_cvd_edu_cess,0);/*added pr_tax.sh_exc_edu_cess + pr_tax.sh_cvd_edu_cess by vkaranam for budget 07 impact - bug#5989740*/
3389     END IF;
3390 
3391     if lb_rg_debug then
3392       FND_FILE.put_line(FND_FILE.log,'Calling jai_cmn_rg_pla_trxs_pkg.insert_row');
3393     end if;
3394 
3395     lv_statement_id := '5';
3396     p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
3397     jai_cmn_rg_pla_trxs_pkg.insert_row(
3398         p_register_id                   => p_register_id,
3399         p_tr6_challan_no                => NULL,
3400         p_tr6_challan_date              => NULL,
3401         p_cr_basic_ed                   => ln_cr_basic,
3402         p_cr_additional_ed              => ln_cr_addl,
3403         p_cr_other_ed                   => ln_cr_other,
3404         p_ref_document_id               => r_trx.transaction_id,
3405         p_ref_document_date             => r_trx.transaction_date,
3406         p_dr_invoice_id                 => lv_excise_invoice_no,
3407         p_dr_invoice_date               => ld_excise_invoice_date,
3408         p_dr_basic_ed                   => ln_dr_basic,
3409         p_dr_additional_ed              => ln_dr_addl,
3410         p_dr_other_ed                   => ln_dr_other,
3411         p_organization_id               => r_trx.organization_id,
3412         p_location_id                   => r_trx.location_id,
3413         p_bank_branch_id                => NULL,
3414         p_entry_date                    => NULL,
3415         p_inventory_item_id             => r_trx.inventory_item_id,
3416         p_vendor_cust_flag              => 'V',
3417         p_vendor_id                     => ln_vendor_id,
3418         p_vendor_site_id                => ln_vendor_site_id,
3419         p_excise_invoice_no             => lv_excise_invoice_no,
3420         p_remarks                       => 'Live-Trx/PrntTrx:'||r_trx.transaction_id||'/'||r_trx.parent_transaction_id,
3421         p_transaction_date              => r_trx.transaction_date,
3422         p_charge_account_id             => NULL,
3423         p_other_tax_credit              => ln_other_tax_credit,
3424         p_other_tax_debit               => ln_other_tax_debit,
3425         p_transaction_type              => lv_transaction_type,
3426         p_transaction_source            => r_base_trx.source_document_code,
3427         p_called_from                   => 'cenvat_RG_PKG.pla_entry',
3428         p_simulate_flag                 => p_simulate_flag,
3429         p_process_status                => p_process_status,
3430         p_process_message               => p_process_message
3431     );
3432 
3433     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath);
3434 
3435     -- Vijay Shankar for Bug#3940588 EDUCATION CESS
3436     IF pr_tax.excise_edu_cess <> 0 THEN
3437       IF p_register_entry_type = CENVAT_DEBIT THEN
3438         ln_other_tax_debit  := pr_tax.excise_edu_cess;
3439       ELSE
3440         ln_other_tax_credit := pr_tax.excise_edu_cess;
3441       END IF;
3442       jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3443           p_source_register     => jai_constants.reg_pla,
3444           p_source_register_id  => p_register_id,
3445           p_tax_type            => jai_constants.tax_type_exc_edu_cess,
3446           p_credit              => ln_other_tax_credit,
3447           p_debit               => ln_other_tax_debit,
3448           p_process_status      => p_process_status,
3449           p_process_message     => p_process_message
3450        );
3451     END IF;
3452 
3453     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath);
3454 
3455     IF pr_tax.cvd_edu_cess <> 0 THEN
3456       IF p_register_entry_type = CENVAT_DEBIT THEN
3457          -- added by vkaranam for bug#9854329, start
3458       IF (      r_base_trx.transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3459         ln_other_tax_debit  := 0;
3460       ELSE
3461         ln_other_tax_debit  := pr_tax.cvd_edu_cess;
3462       END IF;
3463       -- added by vkaranam for bug#9854329, end
3464       ELSE
3465         ln_other_tax_credit := pr_tax.cvd_edu_cess;
3466       END IF;
3467       jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3468           p_source_register     => jai_constants.reg_pla,
3469           p_source_register_id  => p_register_id,
3470           p_tax_type            => jai_constants.tax_type_cvd_edu_cess,
3471           p_credit              => ln_other_tax_credit,
3472           p_debit               => ln_other_tax_debit,
3473           p_process_status      => p_process_status,
3474           p_process_message     => p_process_message
3475        );
3476     END IF;
3477 
3478   /*added the following by vkaranam for budget 07 impact - bug#5989740*/
3479   --start
3480   p_codepath := jai_general_pkg.plot_codepath(8, p_codepath);
3481    IF pr_tax.sh_exc_edu_cess <> 0 THEN
3482 	    IF p_register_entry_type = CENVAT_DEBIT THEN
3483 	      ln_other_tax_debit  := nvl(pr_tax.sh_exc_edu_cess,0);
3484 	    ELSE
3485 	      ln_other_tax_credit := nvl(pr_tax.sh_exc_edu_cess,0);
3486 	    END IF;
3487 
3488 	    jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3489 	        p_source_register     => jai_constants.reg_pla,
3490 	        p_source_register_id  => p_register_id,
3491 	        p_tax_type            => jai_constants.tax_type_sh_exc_edu_cess,
3492 	        p_credit              => ln_other_tax_credit,
3493 	        p_debit               => ln_other_tax_debit,
3494 	        p_process_status      => p_process_status,
3495 	        p_process_message     => p_process_message
3496 	     );
3497 	  END IF;
3498 
3499 	  p_codepath := jai_general_pkg.plot_codepath(9, p_codepath);
3500 
3501 	  IF pr_tax.sh_cvd_edu_cess <> 0 THEN
3502 	    IF p_register_entry_type = CENVAT_DEBIT THEN
3503 	       -- added by vkaranam for bug#9854329, start
3504         IF (    r_base_trx.transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3505           ln_other_tax_debit  := 0;
3506         ELSE
3507           ln_other_tax_debit  := nvl(pr_tax.sh_cvd_edu_cess,0);
3508         END IF;
3509         -- added by vkaranam for bug#9854329, end
3510 	    ELSE
3511 	      ln_other_tax_credit := nvl(pr_tax.sh_cvd_edu_cess,0);
3512 	    END IF;
3513 	    jai_rcv_excise_processing_pkg.other_cenvat_rg_recording(
3514 	        p_source_register     => jai_constants.reg_pla,
3515 	        p_source_register_id  => p_register_id,
3516 	        p_tax_type            => jai_constants.tax_type_sh_cvd_edu_cess,
3517 	        p_credit              => ln_other_tax_credit,
3518 	        p_debit               => ln_other_tax_debit,
3519 	        p_process_status      => p_process_status,
3520 	        p_process_message     => p_process_message
3521 	     );
3522 	  END IF;
3523 	  --end #5989740
3524 
3525 
3526 
3527     p_codepath := jai_general_pkg.plot_codepath(10, p_codepath, NULL, 'END'); /* 6 */
3528 
3529   EXCEPTION
3530     WHEN OTHERS THEN
3531       p_process_status := 'E';
3532       p_process_message := 'CENVAT_RG_PKG.pla_entry->'||SQLERRM||', StmtId->'||lv_statement_id;
3533       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
3534       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
3535 
3536   END pla_entry;
3537 
3538   /*~~~~~~~~~~~~~~~~~~~ ACCOUNTING_ENTRIES Main Procedure for Accounting ~~~~~~~~~~~~~~~~~~~~~*/
3539 
3540   PROCEDURE accounting_entries(
3541     p_transaction_id    IN NUMBER,
3542     pr_tax              IN  TAX_BREAKUP,
3543     p_cgin_code         IN VARCHAR2,
3544     p_cenvat_accounting_type IN VARCHAR2,
3545     p_amount_register   IN VARCHAR2,
3546     p_cenvat_account_id OUT NOCOPY NUMBER,
3547     p_process_status OUT NOCOPY VARCHAR2,
3548     p_process_message OUT NOCOPY VARCHAR2,
3549     p_simulate_flag     IN VARCHAR2,
3550     p_codepath          IN OUT NOCOPY VARCHAR2
3551   , pv_retro_reference          IN VARCHAR2 DEFAULT NULL --Added by rchandan on Jan 18,2008 for retro
3552 
3553   ) IS
3554 
3555     r_trx                           c_trx%ROWTYPE;
3556     r_base_trx                      c_base_trx%ROWTYPE;
3557     r_orgn_info                     c_orgn_info%ROWTYPE;
3558     r_rcv_params                    c_rcv_params%ROWTYPE;
3559 
3560     lv_register_type                VARCHAR2(1);
3561     lv_transaction_type             RCV_TRANSACTIONS.transaction_type%TYPE;
3562     ln_total_excise_amt             NUMBER;
3563     ln_cenvat_claimed_ptg           NUMBER;
3564 
3565     lv_accnt_type                   JAI_RCV_JOURNAL_ENTRIES.acct_type%TYPE;
3566     lv_accnt_nature                 JAI_RCV_JOURNAL_ENTRIES.acct_nature%TYPE;
3567 
3568     ln_cenvat_accnt_id              NUMBER;
3569     ln_cenvat_balancing_accnt_id    NUMBER;
3570     ln_receiving_accnt_id           NUMBER;
3571     ln_cenvat_rcvble_accnt_id       NUMBER;
3572     lv_cgin_case                    VARCHAR2(100);
3573 
3574     ln_debit                        NUMBER;
3575     ln_credit                       NUMBER;
3576     ln_balancing_debit              NUMBER;
3577     ln_balancing_credit             NUMBER;
3578 
3579     lv_accounting_date              DATE;   --File.Sql.35 Cbabu  := trunc(SYSDATE);
3580     lv_reference10                  VARCHAR2(240);
3581     lv_message                      VARCHAR2(200);
3582 
3583     lv_statement_id                 VARCHAR2(5);
3584 
3585     ln_exc_edu_cess_accnt           NUMBER(15);
3586     ln_exc_edu_cess_rcvble_accnt    NUMBER(15);
3587     ln_total_excise_edu_cess_amt    NUMBER;
3588     ln_edu_cess_debit               NUMBER;
3589     ln_edu_cess_credit              NUMBER;
3590     ln_bal_edu_cess_debit           NUMBER;
3591     ln_bal_edu_cess_credit          NUMBER;
3592 
3593     /* following variables added as part of Bug#4211045 */
3594     ln_cess_paid_payable_accnt_id   NUMBER;
3595     ln_edu_cess_balancing_debit     NUMBER;
3596     ln_edu_cess_balancing_credit    NUMBER;
3597     /*added the following variables by vkaranam for budget 07 impact - bug#5989740*/
3598     ln_sh_cess_paid_payable_accnt   NUMBER;
3599     ln_sh_exc_edu_cess_accnt        NUMBER;
3600     ln_sh_exc_edu_cess_rcvb_accnt   NUMBER;
3601     ln_sh_total_exc_edu_cess_amt    NUMBER;
3602     ln_sh_edu_cess_debit            NUMBER;
3603     ln_sh_edu_cess_credit           NUMBER;
3604     ln_sh_edu_cess_balancin_debit  NUMBER;
3605     ln_sh_edu_cess_balancin_credit NUMBER;
3606     ln_sh_bal_edu_cess_debit       NUMBER;
3607     ln_sh_bal_edu_cess_credit      NUMBER;
3608      lv_cr_rvrsl_flag          jai_cmn_inventory_orgs.CENVAT_CR_REVRSL_FLAG%TYPE; --added for bug#9854329
3609      cursor get_rev_flag(cp_organization_id in number,cp_location_id in number)
3610       is
3611       SELECT CENVAT_CR_REVRSL_FLAG FROM jai_cmn_inventory_orgs
3612   WHERE organization_id = cp_organization_id
3613     AND location_id =cp_location_id;
3614 
3615 
3616   BEGIN
3617 
3618     lv_accounting_date := trunc(SYSDATE);
3619 
3620     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb> --- 2');
3621 
3622     if lb_rg_debug then
3623       FND_FILE.put_line(FND_FILE.log,'^ Accounting Entries. CGIN Code->'||nvl(p_cgin_code, 'NULL')
3624       ||'. Basic:'||pr_tax.basic_excise ||', Addl:'||pr_tax.addl_excise||', Other:'||pr_tax.other_excise
3625       ||', ExCes:'||pr_tax.excise_edu_cess||', CvdCes:'||pr_tax.cvd_edu_cess
3626       --added by vkaranam fro bug #5989740
3627       ||', SH_ExCes:'||pr_tax.sh_exc_edu_cess||', SH_CvdCes:'||pr_tax.sh_cvd_edu_cess
3628       ||', CVD:'||pr_tax.cvd
3629       -- Bug 5143906. Added by Lakshmi Gopalsami
3630       ||', Addl CVD: '|| pr_tax.addl_cvd
3631       --Added by Wenqiong for the bug12645490 on 30/06/2011 begin.
3632       ||', Any other BOE 1: '|| pr_tax.any_other_boe_1
3633       ||', Any other BOE 2: '|| pr_tax.any_other_boe_2
3634       ||', Any other BOE 3: '|| pr_tax.any_other_boe_3
3635       ||', Any other BOE 4: '|| pr_tax.any_other_boe_4
3636       ||', Any other BOE 5: '|| pr_tax.any_other_boe_5
3637       --Added by Wenqiong for the bug12645490 on 30/06/2011 end.
3638       ||', AccntType:'||p_cenvat_accounting_type ||', PrcSta:'||p_process_status
3639       ||', AmtRegister:'||p_amount_register||', CGIN Code->'||nvl(p_cgin_code, 'NULL')
3640     );
3641     end if;
3642 
3643 
3644      fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 3');
3645 
3646     lv_statement_id := '1';
3647     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.accounting', 'START'); /* 1 */
3648     OPEN c_trx(p_transaction_id);
3649     FETCH c_trx INTO r_trx;
3650     CLOSE c_trx;
3651       --start additions for bug#9854329
3652     open get_rev_flag (r_trx.organization_id,r_trx.location_id);
3653     fetch get_rev_flag  INTO lv_cr_rvrsl_flag  ;
3654     close get_rev_flag;
3655     --end bug#9854329
3656 
3657     lv_statement_id := '2';
3658     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
3659 
3660     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 4');
3661 
3662     lv_reference10  := 'India Local Cenvat Entries for Receipt:' || r_trx.receipt_num ||'. Transaction Type '||r_trx.transaction_type;
3663     if r_trx.transaction_type = 'CORRECT' THEN
3664       lv_reference10 := lv_reference10 || ' of '||r_trx.parent_transaction_type;
3665     end if;
3666 
3667     lv_statement_id := '3';
3668     p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
3669     IF( NVL(r_trx.cenvat_claimed_ptg, 0) = 100 AND pv_retro_reference IS NULL ) THEN--Added by eric on Jan 18,2008 for retro
3670       p_process_status    := 'E';
3671       p_process_message := 'Cenvat was fully claimed already. No more claims can happen';
3672       GOTO end_of_accounting;
3673     END IF;
3674 
3675     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 5');
3676 
3677     OPEN c_base_trx(p_transaction_id);
3678     FETCH c_base_trx INTO r_base_trx;
3679     CLOSE c_base_trx;
3680 
3681     lv_statement_id := '4';
3682     p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
3683 
3684     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 6');
3685 
3686     IF r_trx.transaction_type = 'CORRECT' THEN
3687       lv_transaction_type := r_trx.parent_transaction_type;
3688     ELSE
3689       lv_transaction_type := r_trx.transaction_type;
3690     END IF;
3691 
3692     lv_register_type := jai_general_pkg.get_rg_register_type(r_trx.item_class);
3693 
3694     -- following cenvat_claimed_ptg corresponds to RECEIVE i.e parent of any other type of transaction
3695     -- ln_cenvat_claimed_ptg := get_receive_claimed_ptg(p_transaction_id, r_trx.shipment_line_id);
3696 
3697     lv_statement_id := '5';
3698     p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
3699     OPEN c_orgn_info(r_trx.organization_id, r_trx.location_id);
3700     FETCH c_orgn_info INTO r_orgn_info;
3701     CLOSE c_orgn_info;
3702 
3703     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 7');
3704 
3705     OPEN c_rcv_params(r_trx.organization_id);
3706     FETCH c_rcv_params INTO r_rcv_params;  -- this is the default accnt and will be overriden later based on transaction requirement
3707     CLOSE c_rcv_params;
3708     ln_receiving_accnt_id := r_rcv_params.receiving_account_id;
3709 
3710     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 8');
3711 
3712     lv_statement_id := '5a';
3713     p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
3714     IF r_trx.organization_type = 'M' THEN
3715       lv_statement_id := '6';
3716       p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
3717       lv_accnt_nature   := 'CENVAT';
3718       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt' THEN
3719       IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then
3720         ln_receiving_accnt_id := r_orgn_info.excise_rcvble_account;   /* In front end this is shown as excise Paid Payable Accnt */
3721 
3722         /* Vijay Shankar for Bug#4211045 */
3723         ln_cess_paid_payable_accnt_id := r_orgn_info.cess_paid_payable_account_id;
3724         ln_sh_cess_paid_payable_accnt :=r_orgn_info.sh_cess_paid_payable_acct_id ;--added by vkaranam for budget 07 impact - bug#5989740
3725       END IF;
3726 
3727       IF p_amount_register = 'PLA' THEN
3728         ln_cenvat_accnt_id        := r_orgn_info.modvat_pla_account_id;
3729         ln_exc_edu_cess_accnt     := r_orgn_info.modvat_pla_account_id;          -- CHK IMPORTANT
3730         ln_sh_exc_edu_cess_accnt     := r_orgn_info.modvat_pla_account_id;          -- by vkaranam,bug #5989740
3731       ELSIF p_amount_register = 'RG23A' THEN
3732         ln_cenvat_accnt_id        := r_orgn_info.modvat_rm_account_id;
3733         ln_exc_edu_cess_accnt     := r_orgn_info.excise_edu_cess_rm_account;
3734         ln_sh_exc_edu_cess_accnt  := r_orgn_info.sh_cess_rm_account;--added by vkaranam for budget 07 impact - bug#5989740
3735       ELSIF p_amount_register = 'RG23C' THEN
3736         ln_cenvat_accnt_id          := r_orgn_info.modvat_cg_account_id;
3737         ln_exc_edu_cess_accnt       := r_orgn_info.excise_edu_cess_cg_account;
3738         ln_sh_exc_edu_cess_accnt       := r_orgn_info.sh_cess_cg_account_id;--added by vkaranam for budget 07 impact - bug#5989740
3739 	-- Bug 4516678. Added by Lakshmi Gopalsami.
3740 	-- Commented the following assignments.
3741         --ln_cenvat_rcvble_accnt_id   := r_orgn_info.cenvat_rcvble_account;
3742         --ln_exc_edu_cess_rcvble_accnt := r_orgn_info.excise_edu_cess_rcvble_accnt;
3743       ELSE
3744         -- something wrong
3745         NULL;
3746       END IF;
3747 
3748       /* Bug 4516678. Added by Lakshmi Gopalsami
3749          Added the following conditions for CGIN and CGEX type of items
3750       */
3751 
3752       IF r_trx.item_class IN ('CGIN','CGEX') THEN
3753         ln_cenvat_rcvble_accnt_id   := r_orgn_info.cenvat_rcvble_account;
3754         ln_exc_edu_cess_rcvble_accnt := r_orgn_info.excise_edu_cess_rcvble_accnt;
3755         ln_sh_exc_edu_cess_rcvb_accnt := r_orgn_info.sh_cess_rcvble_acct_id;--added by vkaranam for budget 07 impact - bug#5989740
3756       END IF ;
3757 
3758     ELSIF r_trx.organization_type = 'T' THEN
3759       lv_accnt_nature   := 'TRADING';
3760       ln_cenvat_accnt_id    := r_orgn_info.excise_23d_account;
3761       ln_exc_edu_cess_accnt := r_orgn_info.excise_23d_account;    -- CHK IMPORTANT
3762       ln_sh_exc_edu_cess_accnt := r_orgn_info.excise_23d_account;    -- bug #5989740
3763       ln_cess_paid_payable_accnt_id := r_orgn_info.excise_23d_account; -- bug #5989740
3764     ELSE
3765       -- something wrong
3766       fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 9');
3767       NULL;
3768     END IF;
3769      fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 10');
3770 
3771    --added for bug#9854329,start
3772   IF (r_base_trx.transaction_type = 'RETURN TO VENDOR' AND nvl(lv_cr_rvrsl_flag,'N') = 'N') THEN
3773     ln_total_excise_amt :=  nvl(pr_tax.basic_excise,0) + nvl(pr_tax.addl_excise,0) +
3774                             nvl(pr_tax.other_excise,0) ;
3775 
3776     ln_total_excise_edu_cess_amt := nvl(pr_tax.excise_edu_cess,0);
3777     ln_sh_total_exc_edu_cess_amt := nvl(pr_tax.sh_exc_edu_cess,0);
3778   ELSE
3779     ln_total_excise_amt := nvl(pr_tax.basic_excise,0) + nvl(pr_tax.addl_excise,0) +
3780                            nvl(pr_tax.other_excise,0) + nvl(pr_tax.cvd,0) + nvl(pr_tax.addl_cvd,0) +
3781                            --Added by Wenqiong for the bug12645490 on 30/06/2011 begin.
3782                            nvl(pr_tax.any_other_boe_1,0) + nvl(pr_tax.any_other_boe_2,0) +
3783                            nvl(pr_tax.any_other_boe_3,0) + nvl(pr_tax.any_other_boe_4,0) +
3784                            nvl(pr_tax.any_other_boe_5,0);
3785                            --Added by Wenqiong for the bug12645490 on 30/06/2011 end.
3786     ln_total_excise_edu_cess_amt := nvl(pr_tax.excise_edu_cess,0) + nvl(pr_tax.cvd_edu_cess,0);
3787     ln_sh_total_exc_edu_cess_amt := nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0);
3788   END IF;
3789 
3790   --added for bug#9854329, end
3791 
3792     lv_statement_id := '7';
3793     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath); /* 8 */
3794     -- IF ln_cenvat_accnt_id IS NULL THEN
3795     IF ln_total_excise_amt <> 0 THEN
3796       IF ln_cenvat_accnt_id IS NULL THEN
3797         IF r_trx.organization_type = 'T' THEN
3798           lv_message := 'Excise RG23D Account was not defined in Organization Setup';
3799         ELSIF p_amount_register = 'PLA' THEN
3800           lv_message := 'Modvat PLA Account was not defined in Organization Setup';
3801         ELSIF lv_register_type = 'A' THEN
3802           lv_message := 'Modvat RM Account was not defined in Organization Setup';
3803         ELSIF lv_register_type = 'C' THEN
3804           lv_message := 'Modvat CG Account was not defined in Organization Setup';
3805         ELSE
3806           lv_message := 'Could not derive Cenvat Account';
3807         END IF;
3808 
3809       ELSIF p_cgin_code IN ('REGULAR-HALF', 'REGULAR-FULL + REVERSAL-HALF','REGULAR-FULL-RETRO') AND ln_cenvat_rcvble_accnt_id IS NULL THEN
3810         lv_message := 'Cenvat Receivable Account was not defined in Organization Setup';
3811       END IF;
3812     END IF;
3813 
3814     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 12');
3815 
3816     IF ln_receiving_accnt_id IS NULL THEN
3817       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt' THEN
3818       IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then
3819         lv_message := 'Excise Receivable Account was not defined in Organization Setup';
3820       ELSE
3821         lv_message := 'Receivable Account was not defined in RCV Parameters';
3822       END IF;
3823     END IF;
3824 
3825     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 13');
3826 
3827     /* following Added for EDUCATION CESS by Vijay Shankar*/
3828     IF ln_total_excise_edu_cess_amt <> 0 THEN
3829       /* Vijay Shankar for Bug#4211045 */
3830       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt'
3831       IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma
3832         AND ln_cess_paid_payable_accnt_id IS NULL
3833       THEN
3834         lv_message := 'Cess Paid/Payable Account was not defined in Organization Setup'; /* Cess meaning Excise Education Cess */
3835       END IF;
3836 
3837       IF ln_exc_edu_cess_accnt IS NULL THEN
3838         IF r_trx.organization_type = 'T' THEN
3839           lv_message := 'Excise RG23D Account was not defined in Organization Setup';
3840         ELSIF p_amount_register = 'PLA' THEN
3841           lv_message := 'Modvat PLA Account was not defined in Organization Setup';
3842         ELSIF lv_register_type = 'A' THEN
3843           lv_message := 'Excise Education Cess RM Account was not defined in Organization Setup';
3844         ELSIF lv_register_type = 'C' THEN
3845           lv_message := 'Excise Education Cess CG Account was not defined in Organization Setup';
3846         ELSE
3847           lv_message := 'Could not derive Cenvat Account';
3848         END IF;
3849 
3850       ELSIF p_cgin_code IN ('REGULAR-HALF', 'REGULAR-FULL + REVERSAL-HALF','REGULAR-FULL-RETRO') AND ln_cenvat_rcvble_accnt_id IS NULL THEN
3851         lv_message := 'Excise Education Cess Receivable Account was not defined in Organization Setup';
3852       END IF;
3853     END IF;
3854   /*added the following by vkaranam for budget 07 impact - bug#5989740*/
3855    --start
3856   IF ln_sh_total_exc_edu_cess_amt <> 0 THEN
3857 	     IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma
3858 	      AND ln_sh_cess_paid_payable_accnt IS NULL
3859 	    THEN
3860 	      lv_message := 'Secondary/Higher Cess Paid/Payable Account was not defined in Organization Setup';
3861 	    END IF;
3862 
3863 	    IF ln_sh_exc_edu_cess_accnt IS NULL THEN
3864 	      IF r_trx.organization_type = 'T' THEN
3865 	        lv_message := 'Excise RG23D Account was not defined in Organization Setup';
3866 	      ELSIF p_amount_register = 'PLA' THEN
3867 	        lv_message := 'Modvat PLA Account was not defined in Organization Setup';
3868 	      ELSIF lv_register_type = 'A' THEN
3869 	        lv_message := 'Secondary/Higher Excise Education Cess RM Account was not defined in Organization Setup';
3870 	      ELSIF lv_register_type = 'C' THEN
3871 	        lv_message := 'Secondary/Higher Excise Education Cess CG Account was not defined in Organization Setup';
3872 	      ELSE
3873 	        lv_message := 'Could not derive Cenvat Account';
3874 	      END IF;
3875 
3876 	    ELSIF p_cgin_code IN ('REGULAR-HALF', 'REGULAR-FULL + REVERSAL-HALF','REGULAR-FULL-RETRO') AND ln_cenvat_rcvble_accnt_id IS NULL THEN
3877 	      lv_message := 'Secondary/Higher Excise Education Cess Receivable Account was not defined in Organization Setup';
3878 	    END IF;
3879   END IF;
3880  --end bug #5989740
3881 
3882 
3883     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 14');
3884 
3885     lv_statement_id := '8';
3886     p_codepath := jai_general_pkg.plot_codepath(9, p_codepath); /* 9 */
3887     IF lv_message IS NOT NULL THEN
3888       p_process_status  := 'E';
3889       p_process_message := lv_message;
3890       RETURN;
3891     END IF;
3892 
3893 
3894     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 15');
3895 
3896     -- This will be used to update PART 1 and 2 Registers later
3897     p_cenvat_account_id := ln_cenvat_accnt_id;
3898 
3899     IF lv_transaction_type IN ('RECEIVE', 'RETURN TO RECEIVING') THEN
3900       lv_accnt_type   := 'REGULAR';
3901     ELSIF lv_transaction_type IN ('DELIVER', 'RETURN TO VENDOR') THEN
3902       lv_accnt_type   := 'REVERSAL';
3903     ELSE
3904       -- Sorry
3905       fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 16');
3906       NULL;
3907     END IF;
3908 
3909     lv_statement_id := '9';
3910     p_codepath := jai_general_pkg.plot_codepath(10, p_codepath); /* 10 */
3911     IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
3912       ln_debit            := ln_total_excise_amt;
3913       ln_balancing_credit := ln_total_excise_amt;
3914       ln_credit           := NULL;
3915       ln_balancing_debit  := NULL;
3916     ELSE
3917       ln_credit           := ln_total_excise_amt;
3918       ln_balancing_debit  := ln_total_excise_amt;
3919       ln_debit            := NULL;
3920       ln_balancing_credit := NULL;
3921     END IF;
3922 
3923     -- Vijay Shankar for Bug#3940588 ADDED for EDUCATION CESS
3924     -- If both accounts are same, then we can pass the accounting in one entry instead of two
3925     IF ln_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
3926       AND ln_exc_edu_cess_accnt = ln_cenvat_accnt_id
3927     THEN
3928       ln_edu_cess_debit   := null;
3929       ln_edu_cess_credit  := null;
3930       IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
3931         ln_debit  := ln_debit + ln_total_excise_edu_cess_amt;
3932       ELSE
3933         ln_credit := ln_credit + ln_total_excise_edu_cess_amt;
3934       END IF;
3935 
3936     /* if the execution comes here, it means different accounts are defined for edu cess. So, we need to pass
3937        seperate entry for cess */
3938     ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
3939 
3940       IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
3941         ln_edu_cess_debit := ln_total_excise_edu_cess_amt;
3942         ln_edu_cess_credit  := null;
3943       ELSE
3944         ln_edu_cess_credit := ln_total_excise_edu_cess_amt;
3945         ln_edu_cess_debit   := null;
3946       END IF;
3947 
3948     END IF;
3949     -- End Education Cess
3950     /*added the following by vkaranam for budget 07 impact - bug#5989740*/
3951    --start
3952   IF ln_sh_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
3953 	    AND ln_sh_exc_edu_cess_accnt = ln_cenvat_accnt_id
3954 	  THEN
3955 	    ln_sh_edu_cess_debit   := null;
3956 	    ln_sh_edu_cess_credit  := null;
3957 
3958 	    IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
3959 	      ln_debit  := ln_debit + ln_sh_total_exc_edu_cess_amt;
3960 	    ELSE
3961 	      ln_credit := ln_credit + ln_sh_total_exc_edu_cess_amt;
3962 	    END IF;
3963 
3964 	  /* if the execution comes here, it means different accounts are defined for edu cess. So, we need to pass
3965 	     seperate entry for cess */
3966 	  ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN
3967 
3968 	    IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
3969 	      ln_sh_edu_cess_debit := ln_sh_total_exc_edu_cess_amt;
3970 	      ln_sh_edu_cess_credit  := null;
3971 	    ELSE
3972 	      ln_sh_edu_cess_credit := ln_sh_total_exc_edu_cess_amt;
3973 	      ln_sh_edu_cess_debit   := null;
3974 	    END IF;
3975 
3976   END IF;
3977   --end bug#5989740
3978 
3979 
3980     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 17');
3981     /* setting values for balancing credit/debit variables */
3982     /* edu_cess_balancing part was coded as part of Bug#4211045 */
3983     IF ln_total_excise_edu_cess_amt <> 0 THEN
3984       ln_edu_cess_balancing_debit := null;
3985       ln_edu_cess_balancing_credit := null;
3986 
3987       IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
3988 
3989         /* ln_balancing_credit := ln_balancing_credit + ln_total_excise_edu_cess_amt; */
3990         /* If condition added by Vijay Shankar for Bug#4211045. Else is existing previously itself as above statement */
3991         -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt' THEN
3992         IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then
3993           ln_edu_cess_balancing_credit := ln_total_excise_edu_cess_amt;
3994         ELSE
3995           ln_balancing_credit := ln_balancing_credit + ln_total_excise_edu_cess_amt;
3996         END IF;
3997 
3998       ELSE
3999 
4000         /* ln_balancing_debit := ln_balancing_debit + ln_total_excise_edu_cess_amt; */
4001         /* If condition added by Vijay Shankar for Bug#4211045. Else is existing previously itself as above statement */
4002         -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt' THEN
4003         IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then
4004           ln_edu_cess_balancing_debit := ln_total_excise_edu_cess_amt;
4005         ELSE
4006           ln_balancing_debit := ln_balancing_debit + ln_total_excise_edu_cess_amt;
4007         END IF;
4008       END IF;
4009     END IF;
4010  /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4011 	 --start
4012 	IF ln_sh_total_exc_edu_cess_amt <> 0 THEN
4013 	    ln_sh_edu_cess_balancin_debit := null;
4014 	    ln_sh_edu_cess_balancin_credit := null;
4015 
4016 	    IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
4017 
4018 
4019 
4020 	      IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then
4021 	        ln_sh_edu_cess_balancin_credit := ln_sh_total_exc_edu_cess_amt;
4022 	      ELSE
4023 	        ln_balancing_credit := ln_balancing_credit + ln_sh_total_exc_edu_cess_amt;
4024 	      END IF;
4025 
4026 	    ELSE
4027 
4028 
4029 	      IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma then
4030 	        ln_sh_edu_cess_balancin_debit := ln_sh_total_exc_edu_cess_amt;
4031 	      ELSE
4032 	        ln_balancing_debit := ln_balancing_debit + ln_sh_total_exc_edu_cess_amt;
4033 	      END IF;
4034 	    END IF;
4035 	  END IF;
4036   --end bug#5989740
4037 
4038 
4039     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 18');
4040 
4041     lv_statement_id := '10';
4042     p_codepath := jai_general_pkg.plot_codepath(11, p_codepath); /* 11 */
4043     IF p_cgin_code IS NULL OR (lv_register_type = 'C' AND p_cgin_code like 'REGULAR-FULL%') THEN
4044 
4045       if lb_rg_debug then
4046         FND_FILE.put_line(FND_FILE.log,'11_1 jai_rcv_accounting_pkg.process_transaction.'
4047           ||' Debit:'||ln_debit||', Credit:'||ln_credit||', CenvatAccntId:'||ln_cenvat_accnt_id);
4048       end if;
4049 
4050       lv_statement_id := '10a';
4051       p_codepath := jai_general_pkg.plot_codepath(12, p_codepath); /* 12 */
4052       -- Actual Entry-1: Cenvat Accounting ( This Includes Edu Cess also if different account is not specified for cess)
4053     -- bug 5581319. Added by Lakshmi Gopalsami
4054     IF NVL(ln_debit,0) <> 0 OR NVL(ln_credit,0) <> 0 THEN
4055       fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 19');
4056       jai_rcv_accounting_pkg.process_transaction(
4057           P_TRANSACTION_ID       => p_transaction_id,
4058           P_ACCT_TYPE            => lv_accnt_type,
4059           P_ACCT_NATURE          => lv_accnt_nature,
4060           P_SOURCE_NAME          => gv_source_name,
4061           P_CATEGORY_NAME        => gv_category_name,
4062           P_CODE_COMBINATION_ID  => ln_cenvat_accnt_id,
4063           P_ENTERED_DR           => ln_debit,
4064           P_ENTERED_CR           => ln_credit,
4065           P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4066           P_ACCOUNTING_DATE      => lv_accounting_date,
4067           P_REFERENCE_10         => lv_reference10,
4068           P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4069           P_REFERENCE_24         => 'rcv_transactions',
4070           P_REFERENCE_25         => 'transaction_id',
4071           P_REFERENCE_26         => to_char(p_transaction_id),
4072           P_DESTINATION          => 'G',
4073           P_SIMULATE_FLAG        => p_simulate_flag,
4074           P_CODEPATH             => p_codepath,
4075           P_PROCESS_STATUS       => p_process_status,
4076           P_PROCESS_MESSAGE      => p_process_message,
4077           p_reference_name       => pv_retro_reference /*added by rchandan*/
4078       );
4079 
4080       IF p_process_status IN ('E', 'X') THEN
4081         GOTO end_of_accounting;
4082       END IF;
4083      END IF;
4084      -- Bug 5581319
4085 
4086       -- Start, EDUCATION CESS ACCCOUNTING
4087       IF nvl(ln_edu_cess_debit,0)<>0 OR nvl(ln_edu_cess_credit,0)<>0 THEN
4088 
4089         if lb_rg_debug then
4090           FND_FILE.put_line(FND_FILE.log,'11_2 Cen Accounting -- '
4091             ||' Dr:'||ln_edu_cess_debit||', Cr:'||ln_edu_cess_credit||', EduCessAccnt:'||ln_cenvat_accnt_id);
4092         end if;
4093     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 20');
4094         lv_statement_id := '10a';
4095         p_codepath := jai_general_pkg.plot_codepath(12, p_codepath); /* 12 */
4096         -- Actual Entry-2: Cenvat Cess Accounting
4097         jai_rcv_accounting_pkg.process_transaction(
4098             P_TRANSACTION_ID       => p_transaction_id,
4099             P_ACCT_TYPE            => lv_accnt_type,
4100             P_ACCT_NATURE          => lv_accnt_nature,
4101             P_SOURCE_NAME          => gv_source_name,
4102             P_CATEGORY_NAME        => gv_category_name,
4103             P_CODE_COMBINATION_ID  => ln_exc_edu_cess_accnt,
4104             P_ENTERED_DR           => ln_edu_cess_debit,
4105             P_ENTERED_CR           => ln_edu_cess_credit,
4106             P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4107             P_ACCOUNTING_DATE      => lv_accounting_date,
4108             P_REFERENCE_10         => lv_reference10,
4109             P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4110             P_REFERENCE_24         => 'rcv_transactions',
4111             P_REFERENCE_25         => 'transaction_id',
4112             P_REFERENCE_26         => to_char(p_transaction_id),
4113             P_DESTINATION          => 'G',
4114             P_SIMULATE_FLAG        => p_simulate_flag,
4115             P_CODEPATH             => p_codepath,
4116             P_PROCESS_STATUS       => p_process_status,
4117             P_PROCESS_MESSAGE      => p_process_message,
4118             p_reference_name       => pv_retro_reference /*added by rchandan*/
4119         );
4120 
4121         IF p_process_status IN ('E', 'X') THEN
4122           GOTO end_of_accounting;
4123         END IF;
4124       END IF;
4125       -- End, EDUCATION CESS ACCCOUNTING
4126 /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4127   --start SH_excise_edu_cess accounting
4128     IF nvl(ln_sh_edu_cess_debit,0)<>0 OR nvl(ln_sh_edu_cess_credit,0)<>0 THEN
4129 
4130       if lb_rg_debug then
4131         FND_FILE.put_line(FND_FILE.log,'11_3 Cen Accounting -- '
4132           ||' SH_Dr:'||ln_sh_edu_cess_debit||', SH_Cr:'||ln_sh_edu_cess_credit||', SH_EduCessAccnt:'||ln_sh_exc_edu_cess_accnt);
4133       end if;
4134 
4135       lv_statement_id := '10b';
4136       p_codepath := jai_general_pkg.plot_codepath(13, p_codepath); /* 13 */
4137       -- Actual Entry-2: Cenvat Cess Accounting
4138       jai_rcv_accounting_pkg.process_transaction(
4139           P_TRANSACTION_ID       => p_transaction_id,
4140           P_ACCT_TYPE            => lv_accnt_type,
4141           P_ACCT_NATURE          => lv_accnt_nature,
4142           P_SOURCE_NAME          => gv_source_name,
4143           P_CATEGORY_NAME        => gv_category_name,
4144           P_CODE_COMBINATION_ID  => ln_sh_exc_edu_cess_accnt,
4145           P_ENTERED_DR           => ln_sh_edu_cess_debit,
4146           P_ENTERED_CR           => ln_sh_edu_cess_credit,
4147           P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4148           P_ACCOUNTING_DATE      => lv_accounting_date,
4149           P_REFERENCE_10         => lv_reference10,
4150           P_REFERENCE_23         => 'ja_in_receipt_cenvat_rg_pkg.accounting_entries',
4151           P_REFERENCE_24         => 'rcv_transactions',
4152           P_REFERENCE_25         => 'transaction_id',
4153           P_REFERENCE_26         => to_char(p_transaction_id),
4154           P_DESTINATION          => 'G',
4155           P_SIMULATE_FLAG        => p_simulate_flag,
4156           P_CODEPATH             => p_codepath,
4157           P_PROCESS_STATUS       => p_process_status,
4158           P_PROCESS_MESSAGE      => p_process_message,
4159           p_reference_name       => pv_retro_reference /*added by rchandan*/
4160           , p_reference_id         => 3
4161       );
4162 
4163       IF p_process_status IN ('E', 'X') THEN
4164         GOTO end_of_accounting;
4165       END IF;
4166     END IF;
4167     -- End 5989740
4168 
4169 
4170       if lb_rg_debug then
4171         FND_FILE.put_line(FND_FILE.log,'12 jai_rcv_accounting_pkg.process_transaction.'
4172           ||' Debit:'||ln_balancing_debit||', Credit:'||ln_balancing_credit||', RecvngAccntId:'||ln_receiving_accnt_id);
4173       end if;
4174 
4175       lv_statement_id := '10b';
4176       p_codepath := jai_general_pkg.plot_codepath(13, p_codepath); /* 13 */
4177       -- Balancing Entry: Receiving Accounting
4178      -- bug 5581319. Added by Lakshmi Gopalsami
4179      IF NVL(ln_balancing_debit,0) <> 0 OR NVL(ln_balancing_credit,0) <> 0 THEN
4180       fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 21');
4181 
4182       jai_rcv_accounting_pkg.process_transaction(
4183           P_TRANSACTION_ID       => p_transaction_id,
4184           P_ACCT_TYPE            => lv_accnt_type,
4185           P_ACCT_NATURE          => lv_accnt_nature,
4186           P_SOURCE_NAME          => gv_source_name,
4187           P_CATEGORY_NAME        => gv_category_name,
4188           P_CODE_COMBINATION_ID  => ln_receiving_accnt_id,
4189           P_ENTERED_DR           => ln_balancing_debit,
4190           P_ENTERED_CR           => ln_balancing_credit,
4191           P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4192           P_ACCOUNTING_DATE      => lv_accounting_date,
4193           P_REFERENCE_10         => lv_reference10,
4194           P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4195           P_REFERENCE_24         => 'rcv_transactions',
4196           P_REFERENCE_25         => 'transaction_id',
4197           P_REFERENCE_26         => to_char(p_transaction_id),
4198           P_DESTINATION          => 'G',
4199           P_SIMULATE_FLAG        => p_simulate_flag,
4200           P_CODEPATH             => p_codepath,
4201           P_PROCESS_STATUS       => p_process_status,
4202           P_PROCESS_MESSAGE      => p_process_message,
4203           p_reference_name       => pv_retro_reference ,/*added by rchandan*/
4204            p_reference_id         => 5--replaced 3 with 5 by vkaranam fro bug#5989740
4205       );
4206 
4207       IF p_process_status IN ('E', 'X') THEN
4208         GOTO end_of_accounting;
4209       END IF;
4210      END IF;
4211      -- Bug 5581319
4212 
4213 
4214       /* following entry (CESS BALANCING ENTRY for RMA Production Input and GOODS RETURN cases)
4215        added by Vijay Shankar for Bug#4211045 */
4216       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt'
4217       IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma
4218         AND nvl(ln_edu_cess_balancing_debit, ln_edu_cess_balancing_credit) <> 0
4219       THEN
4220 
4221         lv_statement_id := '10b';
4222         p_codepath := jai_general_pkg.plot_codepath(13.1, p_codepath);
4223         -- Balancing Entry: Receiving Accounting
4224     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 22');
4225         jai_rcv_accounting_pkg.process_transaction(
4226             P_TRANSACTION_ID       => p_transaction_id,
4227             P_ACCT_TYPE            => lv_accnt_type,
4228             P_ACCT_NATURE          => lv_accnt_nature,
4229             P_SOURCE_NAME          => gv_source_name,
4230             P_CATEGORY_NAME        => gv_category_name,
4231             P_CODE_COMBINATION_ID  => ln_cess_paid_payable_accnt_id,
4232             P_ENTERED_DR           => ln_edu_cess_balancing_debit,
4233             P_ENTERED_CR           => ln_edu_cess_balancing_credit,
4234             P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4235             P_ACCOUNTING_DATE      => lv_accounting_date,
4236             P_REFERENCE_10         => lv_reference10,
4237             P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4238             P_REFERENCE_24         => 'rcv_transactions',
4239             P_REFERENCE_25         => 'transaction_id',
4240             P_REFERENCE_26         => to_char(p_transaction_id),
4241             P_DESTINATION          => 'G',
4242             P_SIMULATE_FLAG        => p_simulate_flag,
4243             P_CODEPATH             => p_codepath,
4244             P_PROCESS_STATUS       => p_process_status,
4245             P_PROCESS_MESSAGE      => p_process_message,
4246             p_reference_name       => pv_retro_reference, /*added by rchandan*/
4247              p_reference_id         => 6 --replaced 4 with 6 by vkaranam fro bug#5989740
4248         );
4249 
4250         IF p_process_status IN ('E', 'X') THEN
4251           GOTO end_of_accounting;
4252         END IF;
4253 
4254       END IF;
4255  /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4256  	   --start
4257  	   if lb_rg_debug then
4258  	 	      FND_FILE.put_line(FND_FILE.log,'15 JA_IN_RECEIPT_ACCOUNTING_PKG.process_transaction.'
4259  	 	        ||' SH_Debit:'||ln_sh_edu_cess_balancin_debit||', SH_Credit:'||ln_sh_edu_cess_balancin_credit
4260  	 	        ||', ln_sh_cess_paid_payable_accnt:'||ln_sh_cess_paid_payable_accnt);
4261  	   end if;
4262 
4263  	   IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma
4264  	 	      AND nvl(ln_sh_edu_cess_balancin_debit, ln_sh_edu_cess_balancin_credit) <> 0
4265  	 	    THEN
4266 
4267  	 	      lv_statement_id := '10d';
4268  	 	      p_codepath := jai_general_pkg.plot_codepath(15.1, p_codepath);
4269  	 	      -- Balancing Entry: Receiving Accounting
4270  	 	      jai_rcv_accounting_pkg.process_transaction(
4271  	 	          P_TRANSACTION_ID       => p_transaction_id,
4272  	 	          P_ACCT_TYPE            => lv_accnt_type,
4273  	 	          P_ACCT_NATURE          => lv_accnt_nature,
4274  	 	          P_SOURCE_NAME          => gv_source_name,
4275  	 	          P_CATEGORY_NAME        => gv_category_name,
4276  	 	          P_CODE_COMBINATION_ID  => ln_sh_cess_paid_payable_accnt,--replaced ln_cess_paid_payable_accnt_id with ln_sh_cess_paid_payable_accnt for bug #5989740
4277  	 	          P_ENTERED_DR           => ln_sh_edu_cess_balancin_debit,
4278  	 	          P_ENTERED_CR           => ln_sh_edu_cess_balancin_credit,
4279  	 	          P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4280  	 	          P_ACCOUNTING_DATE      => lv_accounting_date,
4281  	 	          P_REFERENCE_10         => lv_reference10,
4282  	 	          P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4283  	 	          P_REFERENCE_24         => 'rcv_transactions',
4284  	 	          P_REFERENCE_25         => 'transaction_id',
4285  	 	          P_REFERENCE_26         => to_char(p_transaction_id),
4286  	 	          P_DESTINATION          => 'G',
4287  	 	          P_SIMULATE_FLAG        => p_simulate_flag,
4288  	 	          P_CODEPATH             => p_codepath,
4289  	 	          P_PROCESS_STATUS       => p_process_status,
4290  	 	          P_PROCESS_MESSAGE      => p_process_message,
4291  	 	          p_reference_name       => pv_retro_reference /*added by rchandan*/
4292  	 	          , p_reference_id         => 4
4293  	 	      );
4294 
4295  	 	      IF p_process_status IN ('E', 'X') THEN
4296  	 	        GOTO end_of_accounting;
4297  	 	      END IF;
4298 
4299  	  END IF;
4300 
4301  	  --end 5989740
4302 
4303 
4304     END IF;
4305 
4306     /*~~~~~~~~~ Reversal/Regular Entry of 50% for CGIN Items from MainCG/RcvbleCG account to RcvbleCG/MainCG account ~~~~~~~~~~~~~~~*/
4307 
4308     lv_statement_id := '11';
4309     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb> --- 23a - cgin code ' || p_cgin_code );
4310 
4311     IF nvl(p_cgin_code,'AA') IN ('REGULAR-HALF', 'REGULAR-FULL + REVERSAL-HALF') THEN
4312     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 23');
4313       lv_statement_id := '12';
4314       p_codepath := jai_general_pkg.plot_codepath(15, p_codepath); /* 15 */
4315 
4316       -- this can happen only for RECEIVE type of transaction and that too for 2nd 50% Claim
4317       IF p_cgin_code = 'REGULAR-HALF' THEN
4318         lv_accnt_nature     := 'CENVAT-REG-50%';
4319         ln_debit            := ln_total_excise_amt/2;
4320         ln_balancing_credit := ln_total_excise_amt/2;
4321         ln_credit           := NULL;
4322         ln_balancing_debit  := NULL;
4323 
4324         -- Vijay Shankar for Bug#3940588 ADDED for EDUCATION CESS
4325         IF ln_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
4326           AND ln_exc_edu_cess_accnt = ln_cenvat_accnt_id
4327         THEN
4328           ln_debit            := ln_debit + ln_total_excise_edu_cess_amt/2;
4329           ln_edu_cess_debit   := null;
4330         -- if different account is specified for Cess, then we pass separate entry for cess and balance the amount with balance entry
4331         ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
4332           ln_edu_cess_debit   := ln_total_excise_edu_cess_amt/2;
4333         END IF;
4334         ln_edu_cess_credit  := null;
4335 
4336         -- this is required in case Excise Rcvble and Edu Cess Rcvble are same, so that no separate accnt entry for Cess Rcvble Amount
4337         IF ln_exc_edu_cess_rcvble_accnt IS NOT NULL AND ln_cenvat_rcvble_accnt_id IS NOT NULL
4338           AND ln_cenvat_rcvble_accnt_id = ln_exc_edu_cess_rcvble_accnt
4339         THEN
4340           ln_balancing_credit := ln_balancing_credit + ln_total_excise_edu_cess_amt/2;
4341         ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
4342           ln_bal_edu_cess_credit := ln_total_excise_edu_cess_amt/2;
4343           ln_bal_edu_cess_debit := null;
4344         END IF;
4345         -- End, Vijay Shankar for Bug#3940588
4346    /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4347 		  --start
4348 	    IF ln_sh_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
4349 					AND ln_sh_exc_edu_cess_accnt = ln_cenvat_accnt_id
4350 				THEN
4351 					ln_debit            := ln_debit + ln_sh_total_exc_edu_cess_amt/2;
4352 					ln_sh_edu_cess_debit   := null;
4353 				-- if different account is specified for Cess, then we pass separate entry for cess and balance the amount with balance entry
4354 				ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN
4355 					ln_sh_edu_cess_debit   := ln_sh_total_exc_edu_cess_amt/2;
4356 				END IF;
4357 				ln_sh_edu_cess_credit  := null;
4358 
4359 				-- this is required in case Excise Rcvble and SH Edu Cess Rcvble are same, so that no separate accnt entry for Cess Rcvble Amount
4360 				IF ln_sh_exc_edu_cess_rcvb_accnt IS NOT NULL AND ln_cenvat_rcvble_accnt_id IS NOT NULL
4361 					AND ln_cenvat_rcvble_accnt_id = ln_sh_exc_edu_cess_rcvb_accnt
4362 				THEN
4363 					ln_balancing_credit := ln_balancing_credit + ln_sh_total_exc_edu_cess_amt/2;
4364 				ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN -- Date 04/06/2007 by sacsethi for bug 6109941
4365 					ln_sh_bal_edu_cess_credit := ln_sh_total_exc_edu_cess_amt/2;
4366 					ln_sh_bal_edu_cess_debit := null;
4367 	    END IF;
4368      -- End bug#5989740
4369 
4370 
4371       ELSIF p_cgin_code = 'REGULAR-FULL + REVERSAL-HALF' THEN
4372 
4373         lv_accnt_nature   := 'CENVAT-REV-50%';
4374         IF p_cenvat_accounting_type = CENVAT_DEBIT THEN
4375           -- because this is reversal transaction, opposite of regular acocunting should be passed
4376           -- this happens in case of DELIVER Trxn
4377         /*ln_credit           := ln_total_excise_amt/2;
4378           ln_balancing_debit  := ln_total_excise_amt/2;
4379 		  commented the above and added the below by vumaasha for 7716044
4380 		  as ln_total_excise_amt is including the additional CVD, which shouldn't be reversed */
4381 		  ln_credit           := (ln_total_excise_amt - nvl(pr_tax.addl_cvd,0))/2;
4382 		  ln_balancing_debit  := (ln_total_excise_amt - nvl(pr_tax.addl_cvd,0))/2;
4383           ln_debit            := NULL;
4384           ln_balancing_credit := NULL;
4385 
4386           -- Vijay Shankar for Bug#3940588 ADDED for EDUCATION CESS
4387           IF ln_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
4388             AND ln_exc_edu_cess_accnt = ln_cenvat_accnt_id
4389           THEN
4390             ln_credit           := ln_credit + ln_total_excise_edu_cess_amt/2;
4391             ln_edu_cess_credit  := null;
4392           -- if different account is specified for Cess, then we pass separate entry for cess and balance the amount with balance entry
4393           ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
4394             ln_edu_cess_credit   := ln_total_excise_edu_cess_amt/2;
4395           END IF;
4396           ln_edu_cess_debit  := null;
4397 
4398           -- this is required in case Excise Rcvble and Edu Cess Rcvble are same, so that no separate accnt entry for Cess Rcvble Amount
4399           IF ln_exc_edu_cess_rcvble_accnt IS NOT NULL AND ln_cenvat_rcvble_accnt_id IS NOT NULL
4400             AND ln_cenvat_rcvble_accnt_id = ln_exc_edu_cess_rcvble_accnt
4401           THEN
4402             ln_balancing_debit := ln_balancing_debit + ln_total_excise_edu_cess_amt/2;
4403             ln_bal_edu_cess_debit  := null;
4404             ln_bal_edu_cess_credit := null;
4405           ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
4406             ln_bal_edu_cess_debit := ln_total_excise_edu_cess_amt/2;
4407             ln_bal_edu_cess_credit := null;
4408           END IF;
4409           -- End, Vijay Shankar for Bug#3940588
4410   /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4411 	IF ln_sh_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
4412 	  AND ln_sh_exc_edu_cess_accnt = ln_cenvat_accnt_id
4413 	THEN
4414 	  ln_credit           := ln_credit + ln_sh_total_exc_edu_cess_amt/2;
4415 	  ln_sh_edu_cess_credit  := null;
4416 	-- if different account is specified for Cess, then we pass separate entry for cess and balance the amount with balance entry
4417 	ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN
4418 	  ln_sh_edu_cess_credit   := ln_sh_total_exc_edu_cess_amt/2;
4419 	END IF;
4420 	ln_sh_edu_cess_debit  := null;
4421 
4422 	-- this is required in case Excise Rcvble and Edu Cess Rcvble are same, so that no separate accnt entry for Cess Rcvble Amount
4423 	IF ln_sh_exc_edu_cess_rcvb_accnt IS NOT NULL AND ln_cenvat_rcvble_accnt_id IS NOT NULL
4424 	  AND ln_cenvat_rcvble_accnt_id = ln_sh_exc_edu_cess_rcvb_accnt
4425 	THEN
4426 
4427 	  ln_balancing_debit := ln_balancing_debit + ln_sh_total_exc_edu_cess_amt/2;
4428 	  ln_sh_bal_edu_cess_debit  := null;
4429 	  ln_sh_bal_edu_cess_credit := null;
4430 	ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN
4431 	  ln_sh_bal_edu_cess_debit := ln_sh_total_exc_edu_cess_amt/2;
4432 	  ln_sh_bal_edu_cess_credit := null;
4433 	END IF;
4434      -- End bug 5989740
4435 
4436 
4437         ELSE
4438 
4439           /* ln_debit            := ln_total_excise_amt/2;
4440           ln_balancing_credit := ln_total_excise_amt/2;
4441 		  commented the above and added the below by vumaasha for 7716044.
4442 		  as ln_total_excise_amt is including the additional CVD, which shouldn't be reversed */
4443 		  ln_debit            := (ln_total_excise_amt - nvl(pr_tax.addl_cvd,0))/2;
4444 		  ln_balancing_credit := (ln_total_excise_amt - nvl(pr_tax.addl_cvd,0))/2;
4445           ln_credit           := NULL;
4446           ln_balancing_debit  := NULL;
4447 
4448           -- Vijay Shankar for Bug#3940588 ADDED for EDUCATION CESS
4449           IF ln_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
4450             AND ln_exc_edu_cess_accnt = ln_cenvat_accnt_id
4451           THEN
4452             ln_debit            := ln_debit + ln_total_excise_edu_cess_amt/2;
4453             ln_edu_cess_debit   := null;
4454           -- if different account is specified for Cess, then we pass separate entry for cess and balance the amount with balance entry
4455           ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
4456             ln_edu_cess_debit   := ln_total_excise_edu_cess_amt/2;
4457           END IF;
4458           ln_edu_cess_credit  := null;
4459 
4460           -- this is required in case Excise Rcvble and Edu Cess Rcvble are same, so that no separate accnt entry for Cess Rcvble Amount
4461           IF ln_exc_edu_cess_rcvble_accnt IS NOT NULL AND ln_cenvat_rcvble_accnt_id IS NOT NULL
4462             AND ln_cenvat_rcvble_accnt_id = ln_exc_edu_cess_rcvble_accnt
4463           THEN
4464             ln_balancing_credit := ln_balancing_credit + ln_total_excise_edu_cess_amt/2;
4465             ln_bal_edu_cess_debit  := null;
4466             ln_bal_edu_cess_credit := null;
4467           ELSIF ln_total_excise_edu_cess_amt <> 0 THEN
4468             ln_bal_edu_cess_credit := ln_total_excise_edu_cess_amt/2;
4469             ln_bal_edu_cess_debit := null;
4470           END IF;
4471           -- End, Vijay Shankar for Bug#3940588
4472    /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4473 	IF ln_sh_exc_edu_cess_accnt IS NOT NULL AND ln_cenvat_accnt_id IS NOT NULL
4474 	  AND ln_sh_exc_edu_cess_accnt = ln_cenvat_accnt_id
4475 	THEN
4476 	  ln_debit            := ln_debit + ln_sh_total_exc_edu_cess_amt/2;
4477 	  ln_sh_edu_cess_debit   := null;
4478 	-- if different account is specified for Cess, then we pass separate entry for cess and balance the amount with balance entry
4479 	ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN
4480 	  ln_sh_edu_cess_debit   := ln_sh_total_exc_edu_cess_amt/2;
4481 	END IF;
4482 	ln_sh_edu_cess_credit  := null;
4483 
4484 	-- this is required in case Excise Rcvble and Edu Cess Rcvble are same, so that no separate accnt entry for Cess Rcvble Amount
4485 	IF ln_sh_exc_edu_cess_rcvb_accnt IS NOT NULL AND ln_cenvat_rcvble_accnt_id IS NOT NULL
4486 	  AND ln_cenvat_rcvble_accnt_id = ln_sh_exc_edu_cess_rcvb_accnt
4487 	THEN
4488 	  ln_balancing_credit := ln_balancing_credit + ln_sh_total_exc_edu_cess_amt/2;
4489 	  ln_sh_bal_edu_cess_debit  := null;
4490 	  ln_sh_bal_edu_cess_credit := null;
4491 	ELSIF ln_sh_total_exc_edu_cess_amt <> 0 THEN
4492 	  ln_sh_bal_edu_cess_credit := ln_sh_total_exc_edu_cess_amt/2;
4493 	  ln_sh_bal_edu_cess_debit := null;
4494 	END IF;
4495    -- End bug 5989740
4496 
4497         END IF;
4498 
4499       ELSE
4500         FND_FILE.put_line(FND_FILE.log, '**** CGIN_CODE Not Handled ****');
4501 
4502         p_process_message   := 'CGIN_CODE Not Handled';
4503         GOTO end_of_accounting;
4504       END IF;
4505 
4506       lv_statement_id := '13';
4507       p_codepath := jai_general_pkg.plot_codepath(16, p_codepath); /* 16 */
4508       if lb_rg_debug then
4509         FND_FILE.put_line(FND_FILE.log,'21 jai_rcv_accounting_pkg.process_transaction'
4510           ||' Debit:'||ln_debit||', Credit:'||ln_credit||', CenvatAccntId:'||ln_cenvat_accnt_id);
4511       end if;
4512 
4513       lv_statement_id := '13a';
4514       p_codepath := jai_general_pkg.plot_codepath(17, p_codepath); /* 17 */
4515       -- SecondSet First Entry_1: Cenvat Accounting
4516       -- bug 5581319. Added by Lakshmi Gopalsami
4517      IF NVL(ln_balancing_debit,0) <> 0 OR NVL(ln_balancing_credit,0) <> 0 THEN
4518 
4519       fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 24');
4520       jai_rcv_accounting_pkg.process_transaction(
4521           P_TRANSACTION_ID       => p_transaction_id,
4522           P_ACCT_TYPE            => lv_accnt_type,
4523           P_ACCT_NATURE          => lv_accnt_nature,
4524           P_SOURCE_NAME          => gv_source_name,
4525           P_CATEGORY_NAME        => gv_category_name,
4526           P_CODE_COMBINATION_ID  => ln_cenvat_accnt_id,
4527           P_ENTERED_DR           => ln_debit,
4528           P_ENTERED_CR           => ln_credit,
4529           P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4530           P_ACCOUNTING_DATE      => lv_accounting_date,
4531           P_REFERENCE_10         => lv_reference10,
4532           P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4533           P_REFERENCE_24         => 'rcv_transactions',
4534           P_REFERENCE_25         => 'transaction_id',
4535           P_REFERENCE_26         => to_char(p_transaction_id),
4536           P_DESTINATION          => 'G',
4537           P_SIMULATE_FLAG        => p_simulate_flag,
4538           P_CODEPATH             => p_codepath,
4539           P_PROCESS_STATUS       => p_process_status,
4540           P_PROCESS_MESSAGE      => p_process_message,
4541           p_reference_name       => pv_retro_reference, /*added by rchandan*/
4542 	  p_reference_id         => 7 /*added by ssawant for bug 6084771*/
4543       );
4544 
4545       IF p_process_status IN ('E', 'X') THEN
4546         GOTO end_of_accounting;
4547       END IF;
4548     END IF;
4549     -- bug 5581319
4550 
4551       -- Vijay Shankar for Bug#3940588 EDUCATION CESS Accoounting
4552       IF nvl(ln_edu_cess_debit,0)<>0 OR nvl(ln_edu_cess_credit,0)<>0 THEN
4553 
4554         if lb_rg_debug then
4555           FND_FILE.put_line(FND_FILE.log,'21_1 Cess Accnt - '
4556             ||' Dr:'||ln_edu_cess_debit||', Cr:'||ln_edu_cess_credit||', Cess Accnt:'||ln_exc_edu_cess_accnt);
4557         end if;
4558         -- SecondSet First Entry_2: Education Cess Accounting
4559         lv_statement_id := '13z';
4560         p_codepath := jai_general_pkg.plot_codepath(17, p_codepath); /* 17 */
4561         -- SecondSet First Entry: cenvat Accounting
4562     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 25');
4563         jai_rcv_accounting_pkg.process_transaction(
4564             P_TRANSACTION_ID       => p_transaction_id,
4565             P_ACCT_TYPE            => lv_accnt_type,
4566             P_ACCT_NATURE          => lv_accnt_nature,
4567             P_SOURCE_NAME          => gv_source_name,
4568             P_CATEGORY_NAME        => gv_category_name,
4569             P_CODE_COMBINATION_ID  => ln_exc_edu_cess_accnt,
4570             P_ENTERED_DR           => ln_edu_cess_debit,
4571             P_ENTERED_CR           => ln_edu_cess_credit,
4572             P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4573             P_ACCOUNTING_DATE      => lv_accounting_date,
4574             P_REFERENCE_10         => lv_reference10,
4575             P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4576             P_REFERENCE_24         => 'rcv_transactions',
4577             P_REFERENCE_25         => 'transaction_id',
4578             P_REFERENCE_26         => to_char(p_transaction_id),
4579             P_DESTINATION          => 'G',
4580             P_SIMULATE_FLAG        => p_simulate_flag,
4581             P_CODEPATH             => p_codepath,
4582             P_PROCESS_STATUS       => p_process_status,
4583             P_PROCESS_MESSAGE      => p_process_message,
4584             p_reference_name       => pv_retro_reference, /*added by rchandan*/
4585 	    p_reference_id         => 8 /*added by ssawant for bug 6084771*/
4586         );
4587 
4588         IF p_process_status IN ('E', 'X') THEN
4589           GOTO end_of_accounting;
4590         END IF;
4591 
4592       END IF;
4593  /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4594     --start
4595     IF nvl(ln_sh_edu_cess_debit,0)<>0 OR nvl(ln_sh_edu_cess_credit,0)<>0 THEN
4596 
4597 	    if lb_rg_debug then
4598 	    FND_FILE.put_line(FND_FILE.log,'21_2 Cess Accnt - '
4599 	      ||' Dr:'||ln_sh_edu_cess_debit||', Cr:'||ln_sh_edu_cess_credit||', SH Cess Accnt:'||ln_sh_exc_edu_cess_accnt);
4600 	  end if;
4601 	  -- SecondSet First Entry_2: SH Education Cess Accounting
4602 	  lv_statement_id := '13x';
4603 	  p_codepath := jai_general_pkg.plot_codepath(20, p_codepath);
4604 	  -- SecondSet First Entry: cenvat Accounting
4605 	  jai_rcv_accounting_pkg.process_transaction(
4606 	      P_TRANSACTION_ID       => p_transaction_id,
4607 	      P_ACCT_TYPE            => lv_accnt_type,
4608 	      P_ACCT_NATURE          => lv_accnt_nature,
4609 	      P_SOURCE_NAME          => gv_source_name,
4610 	      P_CATEGORY_NAME        => gv_category_name,
4611 	      P_CODE_COMBINATION_ID  => ln_sh_exc_edu_cess_accnt,
4612 	      P_ENTERED_DR           => ln_sh_edu_cess_debit,
4613 	      P_ENTERED_CR           => ln_sh_edu_cess_credit,
4614 	      P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4615 	      P_ACCOUNTING_DATE      => lv_accounting_date,
4616 	      P_REFERENCE_10         => lv_reference10,
4617 	      P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4618 	      P_REFERENCE_24         => 'rcv_transactions',
4619 	      P_REFERENCE_25         => 'transaction_id',
4620 	      P_REFERENCE_26         => to_char(p_transaction_id),
4621 	      P_DESTINATION          => 'G',
4622 	      P_SIMULATE_FLAG        => p_simulate_flag,
4623 	      P_CODEPATH             => p_codepath,
4624 	      P_PROCESS_STATUS       => p_process_status,
4625 	      P_PROCESS_MESSAGE      => p_process_message,
4626 	      p_reference_name       => pv_retro_reference, /*added by rchandan*/
4627               p_reference_id         => 9  /*added by ssawant for bug 6084771*/
4628 	  );
4629 
4630 	  IF p_process_status IN ('E', 'X') THEN
4631 	    GOTO end_of_accounting;
4632 	  END IF;
4633 
4634     END IF;
4635     --end 5989740
4636 
4637 
4638       FND_FILE.put_line( FND_FILE.log, 'Codepath->'||p_codepath);
4639       if lb_rg_debug then
4640         FND_FILE.put_line(FND_FILE.log,'22 jai_rcv_accounting_pkg.process_transaction'
4641           ||' Debit:'||ln_balancing_debit||', Credit:'||ln_balancing_credit||', CenRcvbleAccntId:'||ln_cenvat_rcvble_accnt_id);
4642       end if;
4643 
4644       lv_statement_id := '13b';
4645       p_codepath := jai_general_pkg.plot_codepath(18, p_codepath); /* 18 */
4646       -- SecondSet Balancing Entry: Cenvat Receivable Accounting
4647       -- bug 5581319. Added by Lakshmi Gopalsami
4648       IF NVL(ln_balancing_debit,0) <> 0 OR NVL(ln_balancing_credit,0) <> 0 THEN
4649 
4650       fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 26');
4651       jai_rcv_accounting_pkg.process_transaction(
4652           P_TRANSACTION_ID       => p_transaction_id,
4653           P_ACCT_TYPE            => lv_accnt_type,
4654           P_ACCT_NATURE          => lv_accnt_nature,
4655           P_SOURCE_NAME          => gv_source_name,
4656           P_CATEGORY_NAME        => gv_category_name,
4657           P_CODE_COMBINATION_ID  => ln_cenvat_rcvble_accnt_id,
4658           P_ENTERED_DR           => ln_balancing_debit,
4659           P_ENTERED_CR           => ln_balancing_credit,
4660           P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4661           P_ACCOUNTING_DATE      => lv_accounting_date,
4662           P_REFERENCE_10         => lv_reference10,
4663           P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4664           P_REFERENCE_24         => 'rcv_transactions',
4665           P_REFERENCE_25         => 'transaction_id',
4666           P_REFERENCE_26         => to_char(p_transaction_id),
4667           P_DESTINATION          => 'G',
4668           P_SIMULATE_FLAG        => p_simulate_flag,
4669           P_CODEPATH             => p_codepath,
4670           P_PROCESS_STATUS       => p_process_status,
4671           P_PROCESS_MESSAGE      => p_process_message,
4672           p_reference_name       => pv_retro_reference, /*added by rchandan*/
4673 	  p_reference_id         => 10 /*added by ssawant for bug 6084771*/
4674       );
4675 
4676       IF p_process_status IN ('E', 'X') THEN
4677         GOTO end_of_accounting;
4678       END IF;
4679      END IF;
4680      -- Bug 5581319
4681 
4682       -- Vijay Shankar for Bug#3940588 EDUCATION CESS ACCOUNTING
4683       IF nvl(ln_bal_edu_cess_debit,0)<>0 OR nvl(ln_bal_edu_cess_credit,0)<>0  THEN
4684 
4685         if lb_rg_debug then
4686           FND_FILE.put_line(FND_FILE.log,'22_2 Cess Rcvble accnt'
4687             ||' Dr:'||ln_bal_edu_cess_debit||', Cr:'||ln_bal_edu_cess_credit||', CessRcvbleAccnt:'||ln_cenvat_rcvble_accnt_id);
4688         end if;
4689 
4690         lv_statement_id := '13b';
4691         p_codepath := jai_general_pkg.plot_codepath(18, p_codepath); /* 18 */
4692         -- SecondSet Balancing Entry: Cenvat Receivable Accounting
4693     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 27');
4694         jai_rcv_accounting_pkg.process_transaction(
4695             P_TRANSACTION_ID       => p_transaction_id,
4696             P_ACCT_TYPE            => lv_accnt_type,
4697             P_ACCT_NATURE          => lv_accnt_nature,
4698             P_SOURCE_NAME          => gv_source_name,
4699             P_CATEGORY_NAME        => gv_category_name,
4700             P_CODE_COMBINATION_ID  => ln_exc_edu_cess_rcvble_accnt,
4701             P_ENTERED_DR           => ln_bal_edu_cess_debit,
4702             P_ENTERED_CR           => ln_bal_edu_cess_credit,
4703             P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4704             P_ACCOUNTING_DATE      => lv_accounting_date,
4705             P_REFERENCE_10         => lv_reference10,
4706             P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4707             P_REFERENCE_24         => 'rcv_transactions',
4708             P_REFERENCE_25         => 'transaction_id',
4709             P_REFERENCE_26         => to_char(p_transaction_id),
4710             P_DESTINATION          => 'G',
4711             P_SIMULATE_FLAG        => p_simulate_flag,
4712             P_CODEPATH             => p_codepath,
4713             P_PROCESS_STATUS       => p_process_status,
4714             P_PROCESS_MESSAGE      => p_process_message,
4715             p_reference_name       => pv_retro_reference, /*added by rchandan*/
4716 	    p_reference_id         => 11 /*added by ssawant for bug 6084771*/
4717         );
4718 
4719         IF p_process_status IN ('E', 'X') THEN
4720           GOTO end_of_accounting;
4721         END IF;
4722 
4723       END IF;
4724       -- END EDUCATION CESS ACCOUNTING
4725 /*added the following by vkaranam for budget 07 impact - bug#5989740*/
4726     --start
4727     IF nvl(ln_sh_bal_edu_cess_debit,0)<>0 OR nvl(ln_sh_bal_edu_cess_credit,0)<>0  THEN
4728 
4729 	      if lb_rg_debug then
4730 	        FND_FILE.put_line(FND_FILE.log,'22_3 Cess Rcvble accnt'
4731 	          ||' Dr:'||ln_sh_bal_edu_cess_debit||', Cr:'||ln_sh_bal_edu_cess_credit||', SH CessRcvbleAccnt:'||ln_cenvat_rcvble_accnt_id);
4732 	      end if;
4733 
4734 	      lv_statement_id := '13d';
4735 	      p_codepath := jai_general_pkg.plot_codepath(20, p_codepath); /* 18 */
4736 	      -- SecondSet Balancing Entry: Cenvat Receivable Accounting
4737 	     jai_rcv_accounting_pkg.process_transaction(
4738 	          P_TRANSACTION_ID       => p_transaction_id,
4739 	          P_ACCT_TYPE            => lv_accnt_type,
4740 	          P_ACCT_NATURE          => lv_accnt_nature,
4741 	          P_SOURCE_NAME          => gv_source_name,
4742 	          P_CATEGORY_NAME        => gv_category_name,
4743 	          P_CODE_COMBINATION_ID  => ln_sh_exc_edu_cess_rcvb_accnt,
4744 	          P_ENTERED_DR           => ln_sh_bal_edu_cess_debit,
4745 	          P_ENTERED_CR           => ln_sh_bal_edu_cess_credit,
4746 	          P_CURRENCY_CODE        => jai_rcv_trx_processing_pkg.gv_func_curr,
4747 	          P_ACCOUNTING_DATE      => lv_accounting_date,
4748 	          P_REFERENCE_10         => lv_reference10,
4749 	          P_REFERENCE_23         => 'jai_rcv_excise_processing_pkg.accounting_entries',
4750 	          P_REFERENCE_24         => 'rcv_transactions',
4751 	          P_REFERENCE_25         => 'transaction_id',
4752 	          P_REFERENCE_26         => to_char(p_transaction_id),
4753 	          P_DESTINATION          => 'G',
4754 	          P_SIMULATE_FLAG        => p_simulate_flag,
4755 	          P_CODEPATH             => p_codepath,
4756 	          P_PROCESS_STATUS       => p_process_status,
4757 	          P_PROCESS_MESSAGE      => p_process_message,
4758 	          p_reference_name       => pv_retro_reference, /*added by rchandan*/
4759 		  p_reference_id         => 12 /*added by ssawant for bug 6084771*/
4760 	      );
4761 
4762 	      IF p_process_status IN ('E', 'X') THEN
4763 	        GOTO end_of_accounting;
4764 	      END IF;
4765 
4766 	END IF;
4767 	-- END bug 5989740
4768 
4769 
4770 
4771     END IF;
4772 
4773     <<end_of_accounting>>
4774     NULL;
4775 
4776     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 28a');
4777     p_codepath := jai_general_pkg.plot_codepath(19, p_codepath, null, 'END'); /* 19 */
4778     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- 28');
4779   EXCEPTION
4780     WHEN OTHERS THEN
4781       p_process_status := 'E';
4782     fnd_file.put_line(FND_FILE.LOG, ' <jai_rcv_exc_prc.plb --- ERR 29');
4783       p_process_message := 'CENVAT_RG_PKG.accounting_entries->'||SQLERRM||', StmtId->'||lv_statement_id;
4784       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
4785       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
4786 
4787   END accounting_entries;
4788 
4789 
4790   PROCEDURE update_registers(
4791     p_quantity_register_id  IN  NUMBER,
4792     p_quantity_register     IN  VARCHAR2,
4793     p_payment_register_id   IN  NUMBER,
4794     p_payment_register      IN  VARCHAR2,
4795     p_charge_account_id     IN  NUMBER,
4796     p_process_status OUT NOCOPY VARCHAR2,
4797     p_process_message OUT NOCOPY VARCHAR2,
4798     p_simulate_flag         IN  VARCHAR2,
4799     p_codepath              IN OUT NOCOPY VARCHAR2
4800   ) IS
4801 
4802     lv_statement_id   VARCHAR2(5);
4803   BEGIN
4804 
4805     lv_statement_id := '1';
4806     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.update_reg' , 'START'); /* 1 */
4807     if lb_rg_debug then
4808       /*dbms_output.put_line('^ Upd_Regs. Payid:'||p_payment_register_id
4809         ||', PayReg:'||p_payment_register
4810         ||', Qtyid:'||p_quantity_register_id
4811         ||', QtyReg:'||p_quantity_register
4812         ||', ChrgAccnt:'||p_charge_account_id); */
4813       fnd_file.put_line(fnd_file.log, '^ Upd_Regs. Payid:'||p_payment_register_id
4814         ||', PayReg:'||p_payment_register
4815         ||', Qtyid:'||p_quantity_register_id
4816         ||', QtyReg:'||p_quantity_register
4817         ||', ChrgAccnt:'||p_charge_account_id);
4818     end if;
4819 
4820     IF p_quantity_register IN ('RG23A', 'RG23C') THEN
4821       lv_statement_id := '2';
4822       p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
4823       jai_cmn_rg_23ac_i_trxs_pkg.update_payment_details(
4824         p_register_id         => p_quantity_register_id,
4825         p_register_id_part_ii => p_payment_register_id,
4826         p_charge_account_id   => p_charge_account_id
4827       );
4828 
4829     ELSIF p_quantity_register = 'RG23D' THEN
4830       lv_statement_id := '3';
4831       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
4832       jai_cmn_rg_23d_trxs_pkg.update_payment_details(
4833         p_register_id         => p_quantity_register_id,
4834         p_charge_account_id   => p_charge_account_id
4835       );
4836 
4837     ELSIF p_quantity_register = 'RG1' THEN
4838       lv_statement_id := '4';
4839       p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
4840       UPDATE JAI_CMN_RG_I_TRXS
4841       SET
4842         register_id_part_ii = p_payment_register_id,
4843         charge_account_id   = p_charge_account_id,
4844         payment_register    = p_payment_register
4845       WHERE register_id = p_quantity_register_id;
4846 
4847     ELSE
4848       FND_FILE.put_line( FND_FILE.log, 'JA_IN_RECEIPT_MODVAT_RG_PKG.update_registers: No Quantity Register Updated');
4849     END IF;
4850 
4851     IF p_payment_register IN ('RG23A', 'RG23C') THEN
4852       lv_statement_id := '5';
4853       p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
4854       jai_cmn_rg_23ac_ii_pkg.update_payment_details(
4855         p_register_id         => p_payment_register_id,
4856         p_register_id_part_i  => p_quantity_register_id,
4857         p_charge_account_id   => p_charge_account_id
4858       );
4859 
4860     ELSIF p_payment_register = 'PLA' THEN
4861       lv_statement_id := '6';
4862       p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
4863       jai_cmn_rg_pla_trxs_pkg.update_payment_details(
4864         p_register_id         => p_payment_register_id,
4865         p_charge_account_id   => p_charge_account_id
4866       );
4867 
4868     ELSE
4869       p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
4870       FND_FILE.put_line( FND_FILE.log, 'JA_IN_RECEIPT_MODVAT_RG_PKG.update_registers: No Payment Register Updated');
4871     END IF;
4872 
4873     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath, NULL, 'END'); /* 8 */
4874 
4875   EXCEPTION
4876     WHEN OTHERS THEN
4877       p_process_status := 'E';
4878       p_process_message := 'CENVAT_RG_PKG.update_registers->'||SQLERRM||', StmtId->'||lv_statement_id;
4879       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
4880       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
4881 
4882   END update_registers;
4883 
4884   -- If this function returns a message, then it means there is some problem and processing should be stopped
4885   PROCEDURE validate_transaction(
4886     p_transaction_id    IN NUMBER,
4887     p_validation_type   IN VARCHAR2,
4888     p_process_status OUT NOCOPY VARCHAR2,
4889     p_process_message OUT NOCOPY VARCHAR2,
4890     p_simulate_flag     IN VARCHAR2,
4891     p_codepath          IN OUT NOCOPY VARCHAR2
4892   ) IS
4893 
4894     r_trx                   c_trx%ROWTYPE;
4895     r_base_trx              c_base_trx%ROWTYPE;
4896     lv_validation_message   VARCHAR2(100);
4897     lv_transaction_type     RCV_TRANSACTIONS.transaction_type%TYPE;
4898 
4899     lv_include_cenvat_in_cost   VARCHAR2(5);
4900 
4901     CURSOR c_rg23_part_ii_chk(cp_transaction_id IN NUMBER) IS
4902       SELECT count(1)
4903       FROM JAI_CMN_RG_23AC_II_TRXS;
4904 
4905     lv_statement_id     VARCHAR2(5);
4906 
4907     r_jai_receipt_line    c_jai_receipt_line%ROWTYPE;   -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh.
4908     lv_source_req         CONSTANT VARCHAR2(3)   := 'REQ';
4909 
4910      --Added for bug #14852106
4911     CURSOR c_taxes(cp_shipment_line_id JAI_RCV_TRANSACTIONS.shipment_line_id%type) is /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
4912     SELECT  count(1) total_cnt,
4913         sum( decode(upper(tax_type), 'EXCISE', 1,
4914                                'ADDL. EXCISE', 1,
4915                                'OTHER EXCISE', 1,
4916              'CVD', 1,
4917              jai_constants.tax_type_add_cvd,1,
4918              jai_constants.tax_type_exc_edu_cess,1,
4919              jai_constants.tax_type_cvd_edu_cess,1,jai_constants.tax_type_sh_exc_edu_cess,1,
4920              jai_constants.tax_type_sh_cvd_edu_cess,1, 0)  --kunkumar for bugno5989740   -- Vijay Shankar for Bug#3940588 EDU CESS
4921            ) excise_cnt
4922     FROM   JAI_RCV_LINE_TAXES
4923     WHERE  shipment_line_id = cp_shipment_line_id
4924     AND    tax_type not in (jai_constants.tax_type_tds, jai_constants.tax_type_modvat_recovery);
4925 
4926     r_taxes                 c_taxes%ROWTYPE;
4927 
4928   BEGIN
4929 
4930     if lb_rg_debug then
4931       FND_FILE.put_line(FND_FILE.log,'^ Validate');
4932     end if;
4933 
4934     lv_statement_id := '1';
4935     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.validate', 'START'); /* 1 */
4936     OPEN c_trx(p_transaction_id);
4937     FETCH c_trx INTO r_trx;
4938     CLOSE c_trx;
4939 
4940     lv_statement_id := '2';
4941     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
4942     OPEN c_base_trx(p_transaction_id);
4943     FETCH c_base_trx INTO r_base_trx;
4944     CLOSE c_base_trx;
4945 
4946     IF r_trx.transaction_type = 'CORRECT' THEN
4947       lv_transaction_type := r_trx.parent_transaction_type;
4948     ELSE
4949       lv_transaction_type := r_trx.transaction_type;
4950     END IF;
4951 
4952     OPEN c_jai_receipt_line(r_trx.shipment_line_id);
4953     FETCH c_jai_receipt_line INTO r_jai_receipt_line;
4954     CLOSE c_jai_receipt_line;
4955 
4956     --Added for bug #14852106
4957     OPEN   c_taxes(r_trx.shipment_line_id);
4958     FETCH  c_taxes into r_taxes;
4959     CLOSE  c_taxes;
4960 
4961     IF p_validation_type = 'COMMON' THEN
4962 
4963       lv_statement_id := '5';
4964       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
4965       --upper added by narao.
4966       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. IF r_base_trx.attr_cat = 'India RMA Receipt' AND upper(r_base_trx.rma_type) NOT IN ('PRODUCTION INPUT', 'GOODS RETURN') THEN
4967        /*
4968        ||Start of bug 5378630
4969        ||Modified the below if statement condition such that the RMA_type 'GOODS RETURN' was changed into GOODS RETURN
4970        */
4971       IF r_base_trx.source_document_code = jai_rcv_trx_processing_pkg.source_rma
4972         AND upper(r_jai_receipt_line.rma_type) NOT IN ('PRODUCTION INPUT', 'GOODS RETURN')
4973       THEN
4974         /* End of bug 5378630 */
4975         lv_validation_message := 'RMA Type Not supported';
4976 
4977       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. ELSIF r_base_trx.attr_cat = 'India Receipt'  THEN
4978       ELSIF r_base_trx.source_document_code IN ( jai_constants.source_po,lv_source_req ) THEN /* added by aiyer for the bug 5378630 */
4979         IF r_trx.organization_type = 'M' AND r_trx.item_class IN ('FGIN', 'FGEX')
4980 	   and r_base_trx.source_document_code NOT IN ('REQ','INVENTORY')  THEN /* 6030615 - interorg  */ --added 'REQ' for bug #13514510
4981           lv_validation_message := 'Item Class not supported for Manufacturing Transactions';
4982 
4983         --ELSIF r_trx.organization_type = 'T' AND r_trx.item_class = jai_rcv_trx_processing_pkg.NO_SETUP THEN
4984         --
4985         ELSE
4986           lv_statement_id := '5.1';
4987         END IF;
4988 
4989       -- Vijay Shankar for Bug#4346453. RCV DFF Elim. Enh. ELSE
4990       --  lv_statement_id := '5.2';
4991 
4992       END IF;
4993 
4994       IF lv_transaction_type = 'RECEIVE' THEN
4995         lv_statement_id := '6';
4996         p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
4997         IF r_trx.organization_type = 'M' THEN
4998           IF r_trx.item_cenvatable <> 'Y' THEN
4999             lv_validation_message := 'Item is not a Cenvatable one';
5000           END IF;
5001 
5002         ELSIF r_trx.organization_type = 'T' THEN
5003           IF r_trx.item_trading_flag <> 'Y' THEN
5004             lv_validation_message := 'Item is not a Tradable one';
5005           --ELSIF r_trx.excise_in_trading <> 'Y' THEN
5006           --  lv_validation_message := 'Oraganization Setup for Excise in Trading is not checked';
5007           ELSIF r_trx.item_excisable <> 'Y' THEN
5008             lv_validation_message := 'Trading Item is not excisable';
5009           END IF;
5010         ELSE
5011           lv_validation_message := 'No Setup for Organization';
5012         END IF;
5013 
5014       ELSIF lv_transaction_type IN ('DELIVER', 'RETURN TO RECEIVING') THEN
5015 
5016         lv_statement_id := '7';
5017         p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
5018         IF r_trx.organization_type = 'T' THEN
5019           lv_validation_message := 'No Cenvat/RG Entries are passed for '||lv_transaction_type;
5020           GOTO end_of_validation;
5021         END IF;
5022 
5023         lv_statement_id := '7.1';
5024         p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
5025         lv_include_cenvat_in_cost := jai_rcv_deliver_rtr_pkg.include_cenvat_in_costing(
5026                                         p_transaction_id    => p_transaction_id,
5027                                         p_process_message   => p_process_message,
5028                                         p_process_status    => p_process_status,
5029                                         p_codepath          => p_codepath
5030                                      );
5031 
5032         IF p_process_status IN ('E', 'X') THEN
5033           RETURN;
5034         END IF;
5035 
5036         -- if the following condition is satisfied, then we need not pass any CENVAT entries during DELIVER or RTR transactions
5037         IF lv_include_cenvat_in_cost = 'N' AND r_trx.transaction_type <> 'CORRECT' AND r_trx.item_cenvatable = 'Y' AND r_taxes.excise_cnt > 0 --Added for bug #14852106
5038         THEN
5039           lv_validation_message := 'Cenvat Entries are not required for Transaction';
5040           GOTO end_of_validation;
5041         END IF;
5042 
5043       ELSIF lv_transaction_type = 'RETURN TO VENDOR' THEN
5044 
5045         lv_statement_id := '8';
5046         p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
5047         IF r_trx.organization_type = 'T' THEN
5048           IF r_trx.item_trading_flag <> 'Y' THEN
5049             lv_validation_message := 'Item is not a Tradable one';
5050           --ELSIF r_trx.excise_in_trading <> 'Y' THEN
5051           --  lv_validation_message := 'Organization Setup for Excise In RG23D is not done';
5052           ELSIF r_trx.item_excisable <> 'Y' THEN
5053             lv_validation_message := 'Trading Item is not excisable';
5054 
5055           END IF;
5056         END IF;
5057 
5058       END IF;
5059 
5060     ELSIF p_validation_type IN ('RECEIVE', 'RETURN TO VENDOR') THEN
5061       -- lv_validation_message := 'Item Class not supported';
5062       NULL;
5063     ELSIF p_validation_type IN ('DELIVER', 'RETURN TO RECEIVING') THEN
5064       NULL;
5065     ELSE
5066       NULL;
5067     END IF;
5068 
5069     <<end_of_validation>>
5070 
5071     lv_statement_id := '9';
5072     p_codepath := jai_general_pkg.plot_codepath(8, p_codepath); /* 8 */
5073     IF lv_validation_message IS NOT NULL THEN
5074       p_process_status  := 'X';
5075       p_process_message := lv_validation_message;
5076     END IF;
5077 
5078     p_codepath := jai_general_pkg.plot_codepath(9, p_codepath, NULL, 'END'); /* 9 */
5079 
5080   EXCEPTION
5081     WHEN OTHERS THEN
5082       p_process_status := 'E';
5083       p_process_message := 'CENVAT_RG_PKG.validate_transaction->'||SQLERRM||', StmtId->'||lv_statement_id;
5084       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_process_message);
5085       p_codepath := jai_general_pkg.plot_codepath(999, p_codepath, null, 'END');
5086 
5087   END validate_transaction;
5088 
5089   -- This procedure assumes that this is called only at the time of RTV
5090   PROCEDURE generate_excise_invoice(
5091     p_transaction_id          IN  NUMBER,
5092     p_organization_id         IN  NUMBER,
5093     p_location_id             IN  NUMBER,
5094     p_excise_invoice_no OUT NOCOPY VARCHAR2,
5095     p_excise_invoice_date OUT NOCOPY DATE,
5096     p_simulate_flag           IN VARCHAR2,
5097     p_errbuf OUT NOCOPY VARCHAR2,
5098     p_codepath                IN OUT NOCOPY VARCHAR2
5099   ) IS
5100 
5101     CURSOR c_rtv_excise_inv_no(cp_transaction_id IN NUMBER) IS
5102       SELECT excise_invoice_no, excise_invoice_date
5103       FROM JAI_RCV_RTV_DTLS
5104       WHERE transaction_id = cp_transaction_id;
5105 
5106     r_trx       c_trx%ROWTYPE;
5107     lv_statement_id   VARCHAR2(5);
5108   BEGIN
5109 
5110     if lb_rg_debug then
5111       FND_FILE.put_line(FND_FILE.log,'^ Gen_Exc_inv');
5112     end if;
5113 
5114     lv_statement_id := '1';
5115     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.generate_exc_inv', 'START'); /* 1 */
5116     OPEN c_trx(p_transaction_id);
5117     FETCH c_trx INTO r_trx;
5118     CLOSE c_trx;
5119 
5120     IF r_trx.transaction_type = 'CORRECT' THEN
5121       lv_statement_id := '2';
5122       p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
5123 
5124       OPEN c_rtv_excise_inv_no(r_trx.parent_transaction_id);
5125       FETCH c_rtv_excise_inv_no INTO p_excise_invoice_no, p_excise_invoice_date;
5126       CLOSE c_rtv_excise_inv_no;
5127     ELSE
5128       lv_statement_id := '3';
5129       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
5130       jai_cmn_setup_pkg.generate_excise_invoice_no(
5131           p_organization_id       => p_organization_id,
5132           p_location_id           => p_location_id,
5133           p_called_from           => 'P',         -- Required for excise generation during RTV
5134           p_order_invoice_type_id => NULL,
5135           p_fin_year              => jai_general_pkg.get_fin_year(p_organization_id),
5136           p_excise_inv_no         => p_excise_invoice_no,
5137           p_errbuf                => p_errbuf
5138       );
5139 
5140       IF p_excise_invoice_no IS NOT NULL THEN
5141         p_excise_invoice_date := trunc(SYSDATE);
5142       END IF;
5143     END IF;
5144 
5145     p_codepath := jai_general_pkg.plot_codepath(4, p_codepath, NULL, 'END'); /* 4 */
5146 
5147   EXCEPTION
5148     WHEN OTHERS THEN
5149       p_errbuf := 'CENVAT_RG_PKG.generate_excise_invoice->'||SQLERRM||', StmtId->'||lv_statement_id;
5150       FND_FILE.put_line( FND_FILE.log, 'Error in '||p_errbuf);
5151       p_codepath := jai_general_pkg.plot_codepath(999, p_errbuf, null, 'END');
5152       RAISE;
5153 
5154   END generate_excise_invoice;
5155 
5156   FUNCTION get_receive_claimed_ptg(
5157     p_transaction_id     IN  NUMBER,
5158     p_shipment_line_id  IN  NUMBER,
5159     p_codepath        IN OUT NOCOPY VARCHAR2
5160   ) RETURN NUMBER IS
5161 
5162     CURSOR c_cenvat_claimed_ptg(cp_shipment_line_id IN NUMBER) IS
5163       SELECT nvl(cenvat_claimed_ptg,0)
5164       FROM JAI_RCV_CENVAT_CLAIMS
5165       WHERE shipment_line_id = cp_shipment_line_id;
5166 
5167     ln_cenvat_claimed_ptg         NUMBER;
5168     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.get_receive_claimed_ptg';
5169 
5170     --ln_ancestor_receive_trxn_id   JAI_RCV_TRANSACTIONS.transaction_id%TYPE;
5171 
5172   BEGIN
5173 
5174   /*
5175     Ancestor should be a RECEIVE type of transaction, because CENVAT is claimed only for RECEIVE transaction and all other
5176     transactions follow this
5177     This is the function that should be changed if all Receipt Queries should be based on TRANSACTION_ID instead of SHIPMENT_LINE_ID
5178   */
5179     --ln_ancestor_receive_trxn_id :=
5180     --    jai_rcv_trx_processing_pkg.get_ancestor_id(p_transaction_id, p_shipment_line_id, 'RECEIVE');
5181 
5182     -- commented as pert of review and modified  p_shipment_line_id -> p_transaction_id
5183     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.get_receive_claimed_ptg', 'START'); /* 1 */
5184     OPEN c_cenvat_claimed_ptg(p_shipment_line_id);
5185     FETCH c_cenvat_claimed_ptg INTO ln_cenvat_claimed_ptg;
5186     CLOSE c_cenvat_claimed_ptg;
5187 
5188     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath, NULL, 'END'); /* 2 */
5189 
5190     RETURN ln_cenvat_claimed_ptg;
5191   EXCEPTION
5192     WHEN OTHERS THEN
5193     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5194     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5195     app_exception.raise_exception;
5196   END get_receive_claimed_ptg;
5197 
5198   /*~~~~~~~~~~~~~~~~~~~~~~~~~ TAX BREAUP ~~~~~~~~~~~~~~~~~~~~~~~~~~*/
5199 
5200   PROCEDURE get_tax_amount_breakup(
5201     p_shipment_line_id  IN      NUMBER,
5202     p_transaction_id    IN      NUMBER,
5203     p_curr_conv_rate    IN      NUMBER,
5204     pr_tax              OUT NOCOPY TAX_BREAKUP,
5205     p_breakup_type      IN      VARCHAR2,
5206     p_codepath          IN OUT NOCOPY VARCHAR2
5207   ) IS
5208 
5209     ln_curr_conv            NUMBER;
5210     ln_mod_problem_amt      NUMBER;
5211     ln_nonmod_problem_amt   NUMBER;
5212     ln_apportion_factor     NUMBER;
5213     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.get_tax_amount_breakup';
5214 
5215   BEGIN
5216     /* This procedure returns excise amounts as per transaction quantity
5217     If p_breakup_type is RG23D, then total tax amount should be added to excise amount instead of taking
5218     mod_cr_percentage into consideration
5219     */
5220 
5221     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.tax_breakup','START'); /* 1 */
5222     if lb_rg_debug then
5223       FND_FILE.put_line(FND_FILE.log,'^ tax_breakup');
5224     end if;
5225 
5226     ln_mod_problem_amt      := 0;
5227     ln_nonmod_problem_amt   := 0;
5228 
5229     ln_apportion_factor   := jai_rcv_trx_processing_pkg.get_apportion_factor(p_transaction_id);
5230 
5231     FOR tax_rec IN (SELECT  rtl.tax_type                                                                      ,
5232                             nvl(rtl.tax_amount, 0)                                              tax_amount    ,
5233                             nvl(rtl.modvat_flag, 'N')                                           modvat_flag   ,
5234                             nvl(rtl.currency, jai_rcv_trx_processing_pkg.gv_func_curr)      currency      ,
5235                             nvl(decode(p_breakup_type, 'RG23D', 100, jtc.mod_cr_percentage), 0) mod_cr_percentage,
5236                             nvl(jtc.rounding_factor, 0)                                         rnd,
5237                             nvl(jtc.inclusive_tax_flag,'N')   INCLUSIVE_TAX_FLAG --12817175
5238                     FROM JAI_RCV_LINE_TAXES rtl, JAI_CMN_TAXES_ALL jtc
5239                     WHERE rtl.shipment_line_id = p_shipment_line_id
5240                     AND jtc.tax_id = rtl.tax_id)
5241     LOOP
5242 
5243       p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
5244 
5245 
5246       IF tax_rec.currency <> jai_rcv_trx_processing_pkg.gv_func_curr THEN
5247         ln_curr_conv := NVL(p_curr_conv_rate, 1);
5248       ELSE
5249         ln_curr_conv := 1;
5250       END IF;
5251 
5252       IF p_breakup_type = 'RG23D' AND tax_rec.modvat_flag='Y'  THEN    -- trading case --11901294
5253         p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
5254         IF upper(tax_rec.tax_type) = 'EXCISE' THEN
5255           p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
5256           pr_tax.basic_excise   := pr_tax.basic_excise + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5257 
5258         ELSIF upper(tax_rec.tax_type) = 'ADDL. EXCISE' THEN
5259           p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
5260           pr_tax.addl_excise    := pr_tax.addl_excise + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5261 
5262         ELSIF upper(tax_rec.tax_type) = 'OTHER EXCISE' THEN
5263           p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
5264           pr_tax.other_excise   := pr_tax.other_excise + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5265 
5266         ELSIF tax_rec.tax_type = 'CVD' THEN
5267           p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
5268           pr_tax.cvd      := pr_tax.cvd + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5269 
5270         -- Start, Vijay Shankar for Bug#3940588
5271         ELSIF tax_rec.tax_type = jai_constants.tax_type_exc_edu_cess THEN
5272           pr_tax.excise_edu_cess   := pr_tax.excise_edu_cess + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5273 
5274         ELSIF tax_rec.tax_type = jai_constants.tax_type_cvd_edu_cess THEN
5275           pr_tax.cvd_edu_cess   := pr_tax.cvd_edu_cess + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5276         -- End, Vijay Shankar for Bug#3940588
5277       /*added the following by vkaranam for budget 07 impact - bug#5989740*/
5278       --start
5279       ELSIF tax_rec.tax_type = jai_constants.tax_type_sh_cvd_edu_cess THEN
5280          pr_tax.sh_cvd_edu_cess  := nvl(pr_tax.sh_cvd_edu_cess,0) + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5281 
5282       ELSIF tax_rec.tax_type = jai_constants.tax_type_sh_exc_edu_cess THEN
5283 			   pr_tax.sh_exc_edu_cess  := nvl(pr_tax.sh_exc_edu_cess,0) + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5284 
5285       --end bug #5989740*/
5286 
5287         ELSIF tax_rec.tax_type = jai_constants.tax_type_add_cvd THEN
5288           p_codepath := jai_general_pkg.plot_codepath(7.1, p_codepath); /* 7.1 */
5289           pr_tax.addl_cvd  := pr_tax.addl_cvd + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5290         --Added by Wenqiong for the bug12645490 on 22/06/2011 begin.
5291         ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other1 THEN
5292           pr_tax.any_other_boe_1  := pr_tax.any_other_boe_1 + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5293         ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other2 THEN
5294           pr_tax.any_other_boe_2  := pr_tax.any_other_boe_2 + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5295         ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other3 THEN
5296           pr_tax.any_other_boe_3  := pr_tax.any_other_boe_3 + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5297         ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other4 THEN
5298           pr_tax.any_other_boe_4  := pr_tax.any_other_boe_4 + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5299         ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other5 THEN
5300           pr_tax.any_other_boe_5  := pr_tax.any_other_boe_5 + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5301          --Added by Wenqiong for the bug12645490 on 22/06/2011 End.
5302         ELSE
5303           p_codepath := jai_general_pkg.plot_codepath(8, p_codepath); /* 8 */
5304           pr_tax.non_cenvat  := pr_tax.non_cenvat + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5305         END IF;
5306 
5307       ELSE  -- manufacturing case
5308         p_codepath := jai_general_pkg.plot_codepath(9, p_codepath); /* 9 */
5309 
5310          IF tax_rec.modvat_flag = 'Y' AND
5311          upper(tax_rec.tax_type) IN ('EXCISE', 'ADDL. EXCISE',
5312                                'OTHER EXCISE', 'CVD',
5313              -- Bug 5143906. Added by Lakshmi Gopalsami
5314              -- Included Addl. CVD
5315              'ADDITIONAL_CVD',
5316              jai_constants.tax_type_exc_edu_cess,
5317              jai_constants.tax_type_cvd_edu_cess,
5318              /*added the following by vkaranam for budget 07 impact - bug#5989740*/
5319              jai_constants.tax_type_sh_cvd_edu_cess,
5320              jai_constants.tax_type_sh_exc_edu_cess,
5321              --Added by Wenqiong for the bug12645490 on 22/06/2011 Begin.
5322              jai_constants.tax_type_boe_other1,
5323              jai_constants.tax_type_boe_other2,
5324              jai_constants.tax_type_boe_other3,
5325              jai_constants.tax_type_boe_other4,
5326              jai_constants.tax_type_boe_other5
5327              --Added by Wenqiong for the bug12645490 on 22/06/2011 End.
5328              )
5329      THEN
5330 
5331           p_codepath := jai_general_pkg.plot_codepath(10, p_codepath); /* 10 */
5332           IF upper(tax_rec.tax_type) = 'EXCISE' THEN
5333             p_codepath := jai_general_pkg.plot_codepath(11, p_codepath); /* 11 */
5334             pr_tax.basic_excise := pr_tax.basic_excise
5335               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5336           --12817175
5337 If  TAX_REC.inclusive_tax_flag='Y'
5338 then
5339      pr_tax.non_cenvat := pr_tax.non_cenvat
5340               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5341 
5342 else
5343             pr_tax.non_cenvat := pr_tax.non_cenvat
5344               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5345 end if;
5346 
5347 
5348 
5349           ELSIF upper(tax_rec.tax_type) = 'ADDL. EXCISE' THEN
5350             p_codepath := jai_general_pkg.plot_codepath(12, p_codepath); /* 12 */
5351             pr_tax.addl_excise := pr_tax.addl_excise
5352               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5353           --12817175
5354 If  TAX_REC.inclusive_tax_flag='Y'
5355 then
5356      pr_tax.non_cenvat := pr_tax.non_cenvat
5357               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5358 
5359 else
5360             pr_tax.non_cenvat := pr_tax.non_cenvat
5361               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5362 end if;
5363 
5364 
5365           ELSIF upper(tax_rec.tax_type) = 'OTHER EXCISE' THEN
5366             p_codepath := jai_general_pkg.plot_codepath(13, p_codepath); /* 13 */
5367             pr_tax.other_excise := pr_tax.other_excise
5368               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5369         --12817175
5370 If  TAX_REC.inclusive_tax_flag='Y'
5371 then
5372      pr_tax.non_cenvat := pr_tax.non_cenvat
5373               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5374 
5375 else
5376             pr_tax.non_cenvat := pr_tax.non_cenvat
5377               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5378 end if;
5379 
5380 
5381 
5382           ELSIF tax_rec.tax_type IN ('CVD') THEN
5383             p_codepath := jai_general_pkg.plot_codepath(14, p_codepath); /* 14 */
5384             pr_tax.cvd := pr_tax.cvd
5385               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5386           --12817175
5387 If  TAX_REC.inclusive_tax_flag='Y'
5388 then
5389      pr_tax.non_cenvat := pr_tax.non_cenvat
5390               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5391 
5392 else
5393             pr_tax.non_cenvat := pr_tax.non_cenvat
5394               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5395 end if;
5396 
5397 
5398 -- Date 04/06/2007 by sacsethi for bug 6109941
5399 -- Code review from bug 5228046
5400           ELSIF tax_rec.tax_type IN ( jai_constants.tax_type_add_cvd) THEN
5401             p_codepath := jai_general_pkg.plot_codepath(14, p_codepath); /* 14 */
5402             pr_tax.addl_cvd := pr_tax.addl_cvd
5403               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5404          --12817175
5405 If  TAX_REC.inclusive_tax_flag='Y'
5406 then
5407      pr_tax.non_cenvat := pr_tax.non_cenvat
5408               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5409 
5410 else
5411             pr_tax.non_cenvat := pr_tax.non_cenvat
5412               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5413 end if;
5414 
5415 
5416 -------------------------------------------------
5417           -- Start, Vijay Shankar for Bug#3940588
5418           ELSIF tax_rec.tax_type = jai_constants.tax_type_exc_edu_cess THEN
5419             pr_tax.excise_edu_cess   := pr_tax.excise_edu_cess +
5420                 + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5421            --12817175
5422 If  TAX_REC.inclusive_tax_flag='Y'
5423 then
5424      pr_tax.non_cenvat := pr_tax.non_cenvat
5425               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5426 
5427 else
5428             pr_tax.non_cenvat := pr_tax.non_cenvat
5429               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5430 end if;
5431 
5432 
5433           ELSIF tax_rec.tax_type = jai_constants.tax_type_cvd_edu_cess THEN
5434             pr_tax.cvd_edu_cess   := pr_tax.cvd_edu_cess
5435                 + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5436            --12817175
5437 If  TAX_REC.inclusive_tax_flag='Y'
5438 then
5439      pr_tax.non_cenvat := pr_tax.non_cenvat
5440               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5441 
5442 else
5443             pr_tax.non_cenvat := pr_tax.non_cenvat
5444               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5445 end if;
5446 
5447 
5448           -- End, Vijay Shankar for Bug#3940588
5449          /*added the following by vkaranam for budget 07 impact - bug#5989740*/
5450         --start
5451         ELSIF tax_rec.tax_type = jai_constants.tax_type_sh_exc_edu_cess THEN
5452 
5453           pr_tax.sh_exc_edu_cess   := nvl(pr_tax.sh_exc_edu_cess,0)+
5454 					              + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5455 				--12817175
5456 If  TAX_REC.inclusive_tax_flag='Y'
5457 then
5458      pr_tax.non_cenvat := pr_tax.non_cenvat
5459               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5460 
5461 else
5462             pr_tax.non_cenvat := pr_tax.non_cenvat
5463               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5464 end if;
5465 
5466 
5467 			  ELSIF tax_rec.tax_type = jai_constants.tax_type_sh_cvd_edu_cess THEN
5468 
5469 				  pr_tax.sh_cvd_edu_cess   := nvl(pr_tax.sh_cvd_edu_cess,0)+
5470 											+ round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5471 				 --12817175
5472 If  TAX_REC.inclusive_tax_flag='Y'
5473 then
5474      pr_tax.non_cenvat := pr_tax.non_cenvat
5475               + round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd)*-1;
5476 
5477 else
5478             pr_tax.non_cenvat := pr_tax.non_cenvat
5479               + round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5480 end if;
5481 
5482 
5483 	--end ,for bug #5989740
5484          --Added by Wenqiong for the bug12645490 on 22/06/2011 Begin.
5485 			  ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other1 THEN
5486 
5487 				  pr_tax.any_other_boe_1   := nvl(pr_tax.any_other_boe_1,0)+
5488 											+ round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5489 				  pr_tax.non_cenvat := pr_tax.non_cenvat
5490 										+ round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5491 			  ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other2 THEN
5492 
5493 				  pr_tax.any_other_boe_2   := nvl(pr_tax.any_other_boe_2,0)+
5494 											+ round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5495 				  pr_tax.non_cenvat := pr_tax.non_cenvat
5496 										+ round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5497 			  ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other3 THEN
5498 
5499 				  pr_tax.any_other_boe_3   := nvl(pr_tax.any_other_boe_3,0)+
5500 											+ round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5501 				  pr_tax.non_cenvat := pr_tax.non_cenvat
5502 										+ round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5503 			  ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other4 THEN
5504 
5505 				  pr_tax.any_other_boe_4   := nvl(pr_tax.any_other_boe_4,0)+
5506 											+ round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5507 				  pr_tax.non_cenvat := pr_tax.non_cenvat
5508 										+ round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5509 			  ELSIF tax_rec.tax_type = jai_constants.tax_type_boe_other5 THEN
5510 
5511 				  pr_tax.any_other_boe_5   := nvl(pr_tax.any_other_boe_5,0)+
5512 											+ round(tax_rec.tax_amount * (tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5513 				  pr_tax.non_cenvat := pr_tax.non_cenvat
5514 										+ round(tax_rec.tax_amount * (1 - tax_rec.mod_cr_percentage/100) * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5515 
5516          --Added by Wenqiong for the bug12645490 on 22/06/2011 End.
5517           ELSE
5518             p_codepath := jai_general_pkg.plot_codepath(15, p_codepath); /* 15 */
5519             ln_mod_problem_amt := ln_mod_problem_amt
5520               + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5521           END IF;
5522 
5523         ELSIF tax_rec.modvat_flag = 'N' and tax_rec.tax_type NOT IN ('TDS', 'Modvat Recovery') THEN
5524           p_codepath := jai_general_pkg.plot_codepath(16, p_codepath); /* 16 */
5525           pr_tax.non_cenvat := pr_tax.non_cenvat
5526             + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5527 
5528         ELSE
5529           p_codepath := jai_general_pkg.plot_codepath(17, p_codepath); /* 17 */
5530           ln_nonmod_problem_amt := ln_nonmod_problem_amt
5531             + round(tax_rec.tax_amount * ln_curr_conv * ln_apportion_factor, tax_rec.rnd);
5532         END IF;
5533 
5534       END IF;
5535 
5536     END LOOP;
5537 
5538     if lb_rg_debug then
5539       /*dbms_output.put_line('$tax_breakup. Basic:'||pr_tax.basic_excise||', Addl:'||pr_tax.addl_excise
5540         ||', Other:'||pr_tax.other_excise||', cvd:'||pr_tax.cvd||', Addl. CVD:'|| pr_tax.addl_cvd||', exc_ces:'||pr_tax.excise_edu_cess||', cvd_ces:'||pr_tax.cvd_edu_cess );
5541 
5542         */
5543       FND_FILE.put_line(FND_FILE.log, '$tax_breakup. Basic:'||pr_tax.basic_excise||', Addl:'||pr_tax.addl_excise
5544         ||', Other:'||pr_tax.other_excise||', cvd:'||pr_tax.cvd||', Addl. CVD:'|| pr_tax.addl_cvd||', exc_ces:'||pr_tax.excise_edu_cess||', cvd_ces:'||pr_tax.cvd_edu_cess );
5545     end if;
5546 
5547     p_codepath := jai_general_pkg.plot_codepath(18, p_codepath, NULL, 'END'); /* 18 */
5548 
5549   EXCEPTION
5550     WHEN OTHERS THEN
5551     pr_tax := null;
5552     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5553     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5554     app_exception.raise_exception;
5555   END get_tax_amount_breakup;
5556 
5557   PROCEDURE other_cenvat_rg_recording(
5558     p_source_register     IN  VARCHAR2,
5559     p_source_register_id  IN  NUMBER,
5560     p_tax_type            IN  VARCHAR2,
5561     p_credit              IN  NUMBER,
5562     p_debit               IN  NUMBER,
5563     p_process_status OUT NOCOPY VARCHAR2,
5564     p_process_message OUT NOCOPY VARCHAR2
5565   ) IS
5566     ln_source_type    NUMBER(2);
5567     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_rcv_excise_processing_pkg.other_cenvat_rg_recording';
5568   BEGIN
5569 
5570     IF p_source_register IN (jai_constants.reg_rg23a_2, jai_constants.reg_rg23c_2) THEN
5571       ln_source_type := jai_constants.reg_rg23_2_code;
5572     ELSIF p_source_register = jai_constants.reg_rg23d THEN
5573       ln_source_type := jai_constants.reg_rg23d_code;
5574     ELSIF p_source_register = jai_constants.reg_pla THEN
5575       ln_source_type := jai_constants.reg_pla_code;
5576     ELSIF p_source_register = jai_constants.reg_receipt_cenvat THEN
5577       ln_source_type := jai_constants.reg_receipt_cenvat_code;
5578     END IF;
5579 
5580     INSERT INTO JAI_CMN_RG_OTHERS(
5581       rg_other_id, source_type, source_register,
5582       source_register_id, tax_type, credit, debit,
5583       created_by, creation_date, last_updated_by, last_update_date
5584     ) VALUES (
5585       JAI_CMN_RG_OTHERS_S.nextval, ln_source_type, p_source_register,
5586       p_source_register_id, p_tax_type, p_credit, p_debit,
5587       fnd_global.user_id, sysdate, fnd_global.user_id, sysdate
5588     );
5589    EXCEPTION
5590      WHEN OTHERS THEN
5591      FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5592      FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5593      app_exception.raise_exception;
5594   END other_cenvat_rg_recording;
5595 
5596   /*~~~~~~~~~~~~~~~~~~~~~~ DERIVING CGIN Scenario ~~~~~~~~~~~~~~~~~~~~~~~~~*/
5597 
5598   PROCEDURE derive_cgin_scenario(
5599     p_transaction_id      IN  NUMBER,
5600     p_cgin_code OUT NOCOPY VARCHAR2,
5601     p_process_status OUT NOCOPY VARCHAR2,
5602     p_process_message OUT NOCOPY VARCHAR2,
5603     p_codepath            IN OUT NOCOPY VARCHAR2
5604   ) IS
5605 
5606     r_trx                   c_trx%ROWTYPE;
5607 
5608     lv_transaction_type     JAI_RCV_TRANSACTIONS.transaction_type%TYPE;
5609     ln_receive_claimed_ptg  NUMBER;
5610     lv_message              VARCHAR2(200);
5611     lv_object_name varchar2(200) := 'jai_rcv_excise_processing_pkg.dervice_cgin_scenario';
5612 
5613 BEGIN
5614 
5615     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'cenvat_rg.cgin_scenario' , 'START'); /* 1 */
5616     if lb_rg_debug then
5617       -- dbms_output.put_line('^ Drv_CGIN_Scnrio');
5618       FND_FILE.put_line(FND_FILE.log,'^ Drv_CGIN_Scnrio');
5619     end if;
5620 
5621 
5622   /*
5623     In 50% claim case there will be another set of entries that needs to be passed in some scenarios and in some scenario it is
5624     REGULAR key word that appear in p_cgin_code is linked with transaction accounting entries that will happen if there is no concept of 50% Claim
5625 
5626     ____________________________________________________________________________________________________________________________
5627     | Transaction Type  |Claim No| Accounting Entries                           |  Comments
5628     | ----------------  |--------| ------------------------------               |  -------------------
5629     | RECEIVE           |      1 | X   - Dr. Modvat CG, Cr. Inventory Receiving |
5630     |                   |        | X/2 - Dr. Cenvat Receivable, Cr. Modvat CG   |  Code = 'REGULAR-FULL + REVERSAL-HALF'
5631     |                   |        |                                              |
5632     |                   |      2 | X/2 - Dr. Modvat RG, Cr. Cenvat Receivable   |  There cant be no Claim in case of Delivery
5633     |                   |        |                                              |  Code = 'REGULAR-HALF'
5634     |                   |        |                                              |  to NonBonded Subinventory
5635     |                   |        |                                              |
5636     | DELIVER           |        | X   - Dr. Inventory Receiving, Dr. Modvat CG |  Code = 'REGULAR-FULL + REVERSAL-HALF'
5637     |  (NonBondedSubinv)|        | X/2 - Dr. Modvat CG, Cr. Cenvat Receivable   |
5638     |                   |        |                                              |
5639     | RTR               |        | X   - Dr. Modvat CG, Dr. Inventory Receiving |  Code = 'REGULAR-FULL + REVERSAL-HALF'
5640     |  (NonBondedSubinv)|        | X/2 - Dr. Cenvat Receivable, Cr. Modvat CG   |
5641     |                   |        |                                              |
5642     | RTV               |        |Case 1: Parent Receive was 50% Claimed        |
5643     |                   |        | X/2 - Dr. Cenvat Receivable, Cr. Modvat CG   |  X/2 Amount is to 50% Claim of Parent Trxn
5644     |                   |        | X   - Dr. Inventory Receiving, Cr. Modvat RG |  This is Regular Entry that happens during RTV
5645     |                   |        |                                              |  Code = 'REGULAR-FULL + PARENT-REGULAR-HALF'
5646     |                   |        |                                              |
5647     |                   |        |Case 2: Parent Receive was 100% Claimed       |
5648     |                   |        | X   - Dr. Inventory Receiving, Cr. Modvat RG |  Parent is fully claimed. no need of passing X/2 entry
5649     |                   |        |                                              |  Code = 'REGULAR-FULL'
5650     ____________________________________________________________________________________________________________________________
5651 
5652     NOTE: If Parent Receive is Claimed 100% then Code returned is
5653               - REGULAR Full for DELIVER/RTR and related CORRECT transactions
5654               - REGUALR FULL/REGULAR HALF  for RECEIVE CORRECTion if CORRECT is not yet Claimed/50% claimed
5655 
5656     X is the Full Cenvat Amount of RECEIVE Line
5657 
5658     Possible Values of RETURN Codes
5659       1) 'REGULAR-FULL + REVERSAL-HALF'
5660       2) 'REGULAR-HALF'
5661       3) 'REGULAR-FULL'
5662       4) 'REGULAR-FULL + PARENT-REGULAR-HALF'
5663   */
5664 
5665     p_codepath := jai_general_pkg.plot_codepath(2, p_codepath); /* 2 */
5666     OPEN c_trx(p_transaction_id);
5667     FETCH c_trx INTO r_trx;
5668     CLOSE c_trx;
5669 
5670     IF r_trx.cenvat_claimed_ptg = 100 THEN
5671       p_codepath := jai_general_pkg.plot_codepath(3, p_codepath); /* 3 */
5672       lv_message := 'Transaction is already full claimed';
5673       GOTO end_of_call;
5674     END IF;
5675 
5676     ln_receive_claimed_ptg    := get_receive_claimed_ptg(p_transaction_id, r_trx.shipment_line_id, p_codepath);
5677     p_codepath := jai_general_pkg.plot_codepath(4, p_codepath); /* 4 */
5678 
5679     IF r_trx.transaction_type = 'CORRECT' THEN
5680       p_codepath := jai_general_pkg.plot_codepath(5, p_codepath); /* 5 */
5681       lv_transaction_type := r_trx.parent_transaction_type;
5682     ELSE
5683       p_codepath := jai_general_pkg.plot_codepath(6, p_codepath); /* 6 */
5684       lv_transaction_type := r_trx.transaction_type;
5685     END IF;
5686 
5687     --following if block only for RECEIVE transactions
5688     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath); /* 7 */
5689     IF r_trx.transaction_type = 'RECEIVE' THEN        --, 'DELIVER', 'RETURN TO RECEIVING') THEN
5690       p_codepath := jai_general_pkg.plot_codepath(8, p_codepath); /* 8 */
5691 
5692       IF r_trx.cenvat_claimed_ptg = 0 THEN
5693         p_codepath := jai_general_pkg.plot_codepath(9, p_codepath); /* 9 */
5694         p_cgin_code := 'REGULAR-FULL + REVERSAL-HALF';
5695 
5696       -- RECEIVE is 50% claimed case
5697       ELSIF r_trx.cenvat_claimed_ptg < 100 THEN
5698         p_codepath := jai_general_pkg.plot_codepath(10, p_codepath); /* 10 */
5699         p_cgin_code := 'REGULAR-HALF';
5700 
5701       -- RECEIVE is 100% claimed case
5702       ELSIF r_trx.cenvat_claimed_ptg = 100 THEN
5703         p_codepath := jai_general_pkg.plot_codepath(11, p_codepath); /* 11 */
5704         lv_message := 'Transaction is Fully Claimed';
5705         GOTO end_of_call;
5706       END IF;
5707 
5708     -- this elsif for DELIVER, RETURN TO RECEIVING, CORRECT of RECEIVE, DELIVER and RETURN TO RECEIVING
5709     ELSIF lv_transaction_type IN ('RECEIVE', 'DELIVER', 'RETURN TO RECEIVING') THEN
5710       p_codepath := jai_general_pkg.plot_codepath(12, p_codepath); /* 12 */
5711 
5712       IF ln_receive_claimed_ptg = 0 THEN
5713 
5714         p_codepath := jai_general_pkg.plot_codepath(13, p_codepath); /* 13 */
5715         lv_message := 'Parent Receive Transaction is not Claimed';
5716         GOTO end_of_call;
5717 
5718       -- RECEIVE is 50% claimed case
5719       ELSIF ln_receive_claimed_ptg < 100 THEN
5720 
5721         p_codepath := jai_general_pkg.plot_codepath(14, p_codepath); /* 14 */
5722         IF r_trx.cenvat_claimed_ptg = 0 THEN
5723           p_codepath := jai_general_pkg.plot_codepath(15, p_codepath); /* 15 */
5724           p_cgin_code := 'REGULAR-FULL + REVERSAL-HALF';
5725         ELSIF r_trx.cenvat_claimed_ptg = 50 THEN
5726           p_codepath := jai_general_pkg.plot_codepath(16, p_codepath); /* 16 */
5727           lv_message := 'Second Claim did not happen for Parent transaction';
5728           GOTO end_of_call;
5729         END IF;
5730 
5731       -- RECEIVE is 100% claimed case
5732       ELSIF ln_receive_claimed_ptg = 100 THEN
5733         p_codepath := jai_general_pkg.plot_codepath(17, p_codepath); /* 17 */
5734         IF r_trx.cenvat_claimed_ptg = 0 THEN
5735           p_codepath := jai_general_pkg.plot_codepath(18, p_codepath); /* 18 */
5736           p_cgin_code := 'REGULAR-FULL';
5737         ELSIF r_trx.cenvat_claimed_ptg < 100 THEN
5738           p_codepath := jai_general_pkg.plot_codepath(19, p_codepath); /* 19 */
5739           p_cgin_code := 'REGULAR-HALF';
5740         END IF;
5741       END IF;
5742 
5743     ELSIF lv_transaction_type = 'RETURN TO VENDOR' THEN
5744 
5745       p_codepath := jai_general_pkg.plot_codepath(20, p_codepath); /* 20 */
5746       -- Need to implement this. Very Complicated One
5747       IF ln_receive_claimed_ptg = 0 THEN
5748         p_codepath := jai_general_pkg.plot_codepath(21, p_codepath); /* 21 */
5749         lv_message := 'Parent Receive Transaction is not Claimed';
5750         GOTO end_of_call;
5751 
5752       -- RECEIVE is 50% claimed case
5753       ELSIF ln_receive_claimed_ptg < 100 THEN
5754         p_codepath := jai_general_pkg.plot_codepath(22, p_codepath); /* 22 */
5755         -- following modified by Vijay Shankar for Bug#3940588
5756          p_cgin_code := 'REGULAR-FULL + PARENT-REGULAR-HALF';/*uncommented by vkaranam fro bug #4704957*/
5757         --p_cgin_code := 'REGULAR-FULL + REVERSAL-HALF';/*commented by vkaranam fro bug #4704957*/
5758 
5759       -- RECEIVE is 100% claimed case
5760       ELSIF ln_receive_claimed_ptg = 100 THEN
5761         p_codepath := jai_general_pkg.plot_codepath(23, p_codepath); /* 23 */
5762         p_cgin_code := 'REGULAR-FULL';
5763 
5764       END IF;
5765       p_codepath := jai_general_pkg.plot_codepath(24, p_codepath); /* 24 */
5766 
5767     END IF;
5768 
5769     <<end_of_call>>
5770     p_codepath := jai_general_pkg.plot_codepath(25, p_codepath); /* 25 */
5771 
5772     IF lv_message IS NOT NULL THEN
5773       p_process_status  := 'E';
5774       p_process_message := lv_message;
5775       RETURN;
5776     END IF;
5777     p_codepath := jai_general_pkg.plot_codepath(26, p_codepath, NULL, 'END'); /* 26 */
5778   EXCEPTION
5779     WHEN OTHERS THEN
5780     p_cgin_code := null;
5781     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5782     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5783     app_exception.raise_exception;
5784   END derive_cgin_scenario;
5785 
5786   PROCEDURE derive_duty_registers(
5787     p_organization_id           IN      NUMBER,
5788     p_location_id               IN      NUMBER,
5789     p_item_class                IN      VARCHAR2,
5790     pr_tax                      IN      TAX_BREAKUP,
5791     p_cenvat_register_type OUT NOCOPY VARCHAR2,
5792     -- p_edu_cess_register_type        OUT VARCHAR2,
5793     p_process_flag OUT NOCOPY VARCHAR2,
5794     p_process_message OUT NOCOPY VARCHAR2,
5795     p_codepath                  IN OUT NOCOPY VARCHAR2,
5796       p_transaction_type          IN      VARCHAR2  --added for bug#9854329
5797   ) IS
5798 
5799     r_orgn_info               c_orgn_info%ROWTYPE;
5800         ln_trx_amount             NUMBER;  --added for bug#9854329
5801 
5802     lv_process_flag           JAI_RCV_TRANSACTIONS.PROCESS_STATUS%TYPE;
5803     lv_process_message        JAI_RCV_TRANSACTIONS.process_message%TYPE;
5804 
5805     lv_pref1_register         VARCHAR2(30);
5806     lv_pref2_register         VARCHAR2(30);
5807 
5808     lv_cess_pref1_register    VARCHAR2(30);
5809     lv_cess_pref2_register    VARCHAR2(30);
5810 
5811     /*
5812     (x) If PREF_PLA = 1 then directly check balances in PLA
5813         a) if ssi_unit_flag='Y' then no need of checking balances, return cenvat_register as PLA
5814         b) elsif ssi_unit_flag='N' then
5815           i) check balances in PLA
5816           ii) check balances in respective registers  based on ITEM CLASS
5817 
5818     (y) If PREF_PLA <> 1, then
5819         a) check balances in respective register based on ITEM CLASS
5820         b) if (a) fails then check (a), b(i) of (x)
5821     */
5822 
5823   BEGIN
5824 
5825     FND_FILE.put_line( fnd_file.log, '^derive_duty_registers');
5826     p_codepath := jai_general_pkg.plot_codepath(1, p_codepath, 'CENVAT_RG_PKG.DRV_DUTY_REG' , 'START');
5827 
5828     OPEN c_orgn_info(p_organization_id, p_location_id);
5829     FETCH c_orgn_info INTO r_orgn_info;
5830     CLOSE c_orgn_info;
5831 
5832     IF r_orgn_info.pref_pla = 1 THEN
5833       lv_pref1_register         := jai_constants.register_type_pla;
5834       lv_cess_pref1_register    := jai_constants.reg_pla;
5835 
5836       IF p_item_class IN ('CGIN','CGEX') THEN
5837         p_codepath := jai_general_pkg.plot_codepath(2, p_codepath);
5838         lv_pref2_register       := jai_constants.register_type_c;
5839         lv_cess_pref2_register  := jai_constants.reg_rg23c;
5840       ELSE
5841         p_codepath := jai_general_pkg.plot_codepath(3, p_codepath);
5842         lv_pref2_register       := jai_constants.register_type_a;
5843         lv_cess_pref2_register  := jai_constants.reg_rg23a;
5844       END IF;
5845 
5846     ELSE  -- IF r_orgn_info.pref_rg23a = 1 THEN
5847 
5848       IF p_item_class IN ('CGIN','CGEX') THEN
5849         p_codepath := jai_general_pkg.plot_codepath(4, p_codepath);
5850         lv_pref1_register       := jai_constants.register_type_c;
5851         lv_cess_pref1_register  := jai_constants.reg_rg23c;
5852       ELSE
5853         p_codepath := jai_general_pkg.plot_codepath(5, p_codepath);
5854         lv_pref1_register       := jai_constants.register_type_a;
5855         lv_cess_pref1_register  := jai_constants.reg_rg23a;
5856       END IF;
5857 
5858       lv_pref2_register         := jai_constants.register_type_pla;
5859       lv_cess_pref2_register    := jai_constants.reg_pla;
5860 
5861     END IF;
5862 
5863     IF lb_rg_debug THEN
5864       FND_FILE.put_line( fnd_file.log, 'Org PlaPref:'||r_orgn_info.pref_pla||', 23aPref:'||r_orgn_info.pref_rg23a
5865         ||', 23cPref:'||r_orgn_info.pref_rg23c||', pref1_reg:'||lv_pref1_register||', pref2_reg:'||lv_pref2_register
5866         ||', AllowNegative:'||r_orgn_info.allow_negative_pla
5867       );
5868       /*dbms_output.put_line( 'Org PlaPref:'||r_orgn_info.pref_pla||', 23aPref:'||r_orgn_info.pref_rg23a
5869         ||', 23cPref:'||r_orgn_info.pref_rg23c||', pref1_reg:'||lv_pref1_register||', pref2_reg:'||lv_pref2_register
5870         ||', AllowNegative:'||r_orgn_info.allow_negative_pla);
5871         */
5872     END IF;
5873 
5874     IF    lv_pref1_register = jai_constants.register_type_pla
5875       AND r_orgn_info.allow_negative_pla = jai_constants.yes
5876     THEN
5877       p_codepath := jai_general_pkg.plot_codepath(6, p_codepath);
5878       p_cenvat_register_type    := jai_constants.register_type_pla;
5879       GOTO end_of_procedure;
5880     END IF;
5881 --added for bug#9854329, start
5882   IF (p_transaction_type = 'RETURN TO VENDOR' AND nvl(r_orgn_info.CENVAT_CR_REVRSL_FLAG,'N') = 'N') THEN
5883     ln_trx_amount :=  nvl( pr_tax.basic_excise,0) + nvl(pr_tax.addl_excise,0) +
5884                       nvl(pr_tax.other_excise,0) ;
5885   ELSE
5886     ln_trx_amount := nvl( pr_tax.basic_excise,0) + nvl(pr_tax.addl_excise,0) +
5887                       nvl(pr_tax.other_excise,0) + nvl(pr_tax.cvd,0) + nvl(pr_tax.addl_cvd,0);
5888   END IF;
5889   --added for bug#9854329, end
5890     /* BALANCES CHECKING */
5891     p_codepath := jai_general_pkg.plot_codepath(7, p_codepath);
5892     check_cenvat_balances(
5893       p_organization_id       => p_organization_id,
5894       p_location_id           => p_location_id,
5895     /*  p_transaction_amount    => pr_tax.basic_excise +
5896                                  pr_tax.addl_excise +
5897 				 pr_tax.other_excise +
5898 				 pr_tax.cvd +
5899 				 pr_tax.addl_cvd ,    -- Date 30/10/2006 Bug 5228046 added by sacsethi*/
5900            p_transaction_amount    => ln_trx_amount,    --added for bug#9854329
5901       p_register_type         => lv_pref1_register,
5902       p_process_flag          => lv_process_flag,
5903       p_process_message       => lv_process_message
5904     );
5905 
5906     IF lv_process_flag = jai_constants.unexpected_error THEN
5907       p_codepath := jai_general_pkg.plot_codepath(8, p_codepath);
5908       p_process_flag    := 'E';
5909       p_process_message :=  lv_process_message;
5910       GOTO end_of_procedure;
5911 
5912     ELSIF lv_process_flag = jai_constants.expected_error THEN
5913       p_codepath := jai_general_pkg.plot_codepath(9, p_codepath);
5914 
5915     ELSIF lv_process_flag = jai_constants.successful THEN
5916 
5917       p_codepath := jai_general_pkg.plot_codepath(11, p_codepath);
5918       IF pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess <> 0 THEN /* This if condition and its else added by ssumaith - bug# 4187859*/
5919 
5920             --added for bug#9854329, start
5921           IF (p_transaction_type = 'RETURN TO VENDOR' AND nvl(r_orgn_info.CENVAT_CR_REVRSL_FLAG,'N') = 'N') THEN
5922             ln_trx_amount :=  nvl(pr_tax.excise_edu_cess,0);
5923           ELSE
5924             ln_trx_amount := nvl(pr_tax.excise_edu_cess,0) + nvl(pr_tax.cvd_edu_cess,0);
5925           END IF;
5926           --added for bug#9854329, end
5927           jai_cmn_rg_others_pkg.check_balances(
5928             p_organization_id   => p_organization_id ,
5929             p_location_id       => p_location_id,
5930             p_register_type     => lv_cess_pref1_register,
5931              --  p_trx_amount        => pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess,
5932            p_trx_amount        => ln_trx_amount, --added for bug#9854329
5933             p_process_flag      => lv_process_flag,
5934             p_process_message   => lv_process_message
5935           );
5936 
5937           IF lv_process_flag = jai_constants.unexpected_error THEN
5938             p_codepath := jai_general_pkg.plot_codepath(12, p_codepath);
5939             p_process_flag    := 'E';
5940             p_process_message :=  lv_process_message;
5941             GOTO end_of_procedure;
5942 
5943           ELSIF lv_process_flag = jai_constants.expected_error THEN
5944             p_codepath := jai_general_pkg.plot_codepath(13, p_codepath);
5945           ELSIF lv_process_flag = jai_constants.successful THEN
5946             p_codepath := jai_general_pkg.plot_codepath(14, p_codepath);
5947             p_cenvat_register_type  := lv_pref1_register;
5948             GOTO end_of_procedure;
5949           END IF;
5950    /*added the following by vkaranam for budget 07 impact - bug#5989740*/
5951     --start
5952     ELSIF nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0) <> 0 THEN
5953   --added for bug#9854329, start
5954               IF (p_transaction_type = 'RETURN TO VENDOR' AND nvl(r_orgn_info.CENVAT_CR_REVRSL_FLAG,'N') = 'N') THEN
5955                 ln_trx_amount := nvl(pr_tax.sh_exc_edu_cess,0);
5956               ELSE
5957                 ln_trx_amount := nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0);
5958               END IF;
5959               --added for bug#9854329, end
5960 		          jai_cmn_rg_others_pkg.check_sh_balances(
5961 		          p_organization_id   => p_organization_id ,
5962 		          p_location_id       => p_location_id,
5963 		          p_register_type     => lv_cess_pref1_register,
5964 		          --  p_trx_amount        => nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0),
5965               p_trx_amount        => ln_trx_amount, --added for bug#9854329
5966 		          p_process_flag      => lv_process_flag,
5967 		          p_process_message   => lv_process_message
5968 		        );
5969 
5970 		        IF lv_process_flag = jai_constants.unexpected_error THEN
5971 		          p_codepath := jai_general_pkg.plot_codepath(14.1, p_codepath);
5972 		          p_process_flag    := 'E';
5973 		          p_process_message :=  lv_process_message;
5974 		          GOTO end_of_procedure;
5975 
5976 		        ELSIF lv_process_flag = jai_constants.expected_error THEN
5977 		          p_codepath := jai_general_pkg.plot_codepath(14.2, p_codepath);
5978 		        ELSIF lv_process_flag = jai_constants.successful THEN
5979 		          p_codepath := jai_general_pkg.plot_codepath(14.3, p_codepath);
5980 		          p_cenvat_register_type  := lv_pref1_register;
5981 		          GOTO end_of_procedure;
5982            END IF;
5983     --end bug #5989740
5984 
5985       ELSE
5986          lv_process_flag    := jai_constants.successful;
5987            p_cenvat_register_type  := lv_pref1_register; --added for bug#9854329
5988          lv_process_message := NULL;
5989          goto end_of_procedure;
5990       END IF;
5991     END IF;
5992 
5993     IF lv_pref2_register = jai_constants.register_type_pla
5994       AND r_orgn_info.allow_negative_pla = jai_constants.yes
5995     THEN
5996       p_codepath := jai_general_pkg.plot_codepath(15, p_codepath);
5997       p_cenvat_register_type  := lv_pref2_register;
5998       GOTO end_of_procedure;
5999     END IF;
6000     --added for bug#9854329, start
6001   IF (p_transaction_type = 'RETURN TO VENDOR' AND nvl(r_orgn_info.CENVAT_CR_REVRSL_FLAG,'N') = 'N') THEN
6002     ln_trx_amount :=  nvl( pr_tax.basic_excise,0) + nvl(pr_tax.addl_excise,0) +
6003                       nvl(pr_tax.other_excise,0);
6004   ELSE
6005     ln_trx_amount := nvl( pr_tax.basic_excise,0) + nvl(pr_tax.addl_excise,0) +
6006                       nvl(pr_tax.other_excise,0) + nvl(pr_tax.cvd,0) + nvl(pr_tax.addl_cvd,0);
6007   END IF;
6008   --added for bug#9854329, end
6009     p_codepath := jai_general_pkg.plot_codepath(16, p_codepath);
6010     check_cenvat_balances(
6011       p_organization_id       => p_organization_id,
6012       p_location_id           => p_location_id,
6013       /*   p_transaction_amount    => pr_tax.basic_excise +
6014                                  pr_tax.addl_excise +
6015 				 pr_tax.other_excise +
6016 				 pr_tax.cvd +
6017 				 pr_tax.addl_cvd,  -- Date 04/06/2007 by sacsethi for bug 6109941 */
6018          p_transaction_amount    => ln_trx_amount,  --added for bug#9854329
6019       p_register_type         => lv_pref2_register,
6020       p_process_flag          => lv_process_flag,
6021       p_process_message       => lv_process_message
6022     );
6023 
6024     IF lv_process_flag = jai_constants.unexpected_error THEN
6025       p_codepath := jai_general_pkg.plot_codepath(17, p_codepath);
6026       p_process_flag    := 'E';
6027       p_process_message :=  lv_process_message;
6028       GOTO end_of_procedure;
6029 
6030     ELSIF lv_process_flag = jai_constants.expected_error THEN
6031       p_codepath := jai_general_pkg.plot_codepath(18, p_codepath);
6032       p_process_flag    := 'E';
6033       p_process_message :=  'Sufficient Balances are not available in both '||lv_pref1_register||' and '||lv_pref2_register||' registers';
6034       GOTO end_of_procedure;
6035 
6036     ELSIF lv_process_flag = jai_constants.successful THEN
6037 
6038       p_codepath := jai_general_pkg.plot_codepath(19, p_codepath);
6039 
6040       IF pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess <> 0 THEN /* This if condition and its else added by ssumaith - bug# 4187859*/
6041             --added for bug#9854329, start
6042         IF (p_transaction_type = 'RETURN TO VENDOR' AND nvl(r_orgn_info.CENVAT_CR_REVRSL_FLAG,'N') = 'N') THEN
6043           ln_trx_amount :=  nvl(pr_tax.excise_edu_cess,0);
6044         ELSE
6045           ln_trx_amount := nvl(pr_tax.excise_edu_cess,0) + nvl(pr_tax.cvd_edu_cess,0);
6046         END IF;
6047         --added for bug#9854329, end
6048           jai_cmn_rg_others_pkg.check_balances(
6049             p_organization_id   => p_organization_id ,
6050             p_location_id       => p_location_id,
6051             p_register_type     => lv_cess_pref2_register,
6052              -- p_trx_amount        => pr_tax.excise_edu_cess + pr_tax.cvd_edu_cess,
6053            p_trx_amount        => ln_trx_amount, --added for bug#9854329
6054             p_process_flag      => lv_process_flag,
6055             p_process_message   => lv_process_message
6056           );
6057           IF lv_process_flag = jai_constants.unexpected_error THEN
6058             p_codepath := jai_general_pkg.plot_codepath(20, p_codepath);
6059             p_process_flag    := 'E';
6060             p_process_message :=  lv_process_message;
6061             GOTO end_of_procedure;
6062 
6063           ELSIF lv_process_flag = jai_constants.expected_error THEN
6064             p_codepath := jai_general_pkg.plot_codepath(21, p_codepath);
6065             p_process_flag    := 'E';
6066             p_process_message :=  'Sufficient Balances are not available in both '||lv_pref1_register||' and '||lv_pref2_register||' registers';
6067             GOTO end_of_procedure;
6068 
6069           ELSIF lv_process_flag = jai_constants.successful THEN
6070             p_codepath := jai_general_pkg.plot_codepath(22, p_codepath);
6071             p_cenvat_register_type  := lv_pref2_register;
6072             GOTO end_of_procedure;
6073           END IF;
6074 /*added the following by vkaranam for budget 07 impact - bug#5989740*/
6075      --start
6076      ELSIF nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0) <> 0 THEN
6077  --added for bug#9854329, start
6078               IF (p_transaction_type = 'RETURN TO VENDOR' AND nvl(r_orgn_info.CENVAT_CR_REVRSL_FLAG,'N') = 'N') THEN
6079                 ln_trx_amount := nvl(pr_tax.sh_exc_edu_cess,0);
6080               ELSE
6081                 ln_trx_amount := nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0);
6082               END IF;
6083               --added for bug#9854329, end
6084  	  jai_cmn_rg_others_pkg.check_sh_balances(
6085  	  p_organization_id   => p_organization_id ,
6086  	  p_location_id       => p_location_id,
6087  	  p_register_type     => lv_cess_pref2_register,
6088  		 -- p_trx_amount        => nvl(pr_tax.sh_exc_edu_cess,0) + nvl(pr_tax.sh_cvd_edu_cess,0),
6089     p_trx_amount        => ln_trx_amount,  --added for bug#9854329
6090  	  p_process_flag      => lv_process_flag,
6091  	  p_process_message   => lv_process_message
6092  	);
6093 
6094  	IF lv_process_flag = jai_constants.unexpected_error THEN
6095  	  p_codepath := jai_general_pkg.plot_codepath(22.1, p_codepath);
6096  	  p_process_flag    := 'E';
6097  	  p_process_message :=  lv_process_message;
6098  	  GOTO end_of_procedure;
6099 
6100  	ELSIF lv_process_flag = jai_constants.expected_error THEN
6101 	   p_codepath := jai_general_pkg.plot_codepath(22.2, p_codepath);
6102 	   p_process_flag    := 'E';
6103 	   p_process_message :=  'Sufficient Balances are not available in both '||lv_pref1_register||' and '||lv_pref2_register||' registers';
6104 	   GOTO end_of_procedure;
6105 
6106         ELSIF lv_process_flag = jai_constants.successful THEN
6107 	   p_codepath := jai_general_pkg.plot_codepath(22.3, p_codepath);
6108 	   p_cenvat_register_type  := lv_pref2_register;
6109 	   GOTO end_of_procedure;
6110         END IF;
6111 
6112      --end bug #5989740
6113 
6114 
6115       ELSE
6116           lv_process_flag    := jai_constants.successful;
6117           p_cenvat_register_type  := lv_pref2_register;  -- added for bug#9854329
6118           lv_process_message := NULL;
6119           goto end_of_procedure;
6120       END IF;
6121     END IF;
6122 
6123     <<end_of_procedure>>
6124 
6125     p_codepath := jai_general_pkg.plot_codepath(25, p_codepath, 'CENVAT_RG_PKG.DRV_DUTY_REG' , 'END');
6126     FND_FILE.put_line( fnd_file.log, '$derive_duty_registers. Register Type:'||p_cenvat_register_type);
6127     -- dbms_output.put_line( '$derive_duty_registers. Register Type:'||p_cenvat_register_type);
6128 
6129   EXCEPTION
6130     WHEN OTHERS THEN
6131       p_process_flag    := 'E';
6132       p_process_message := 'DERIVE_DUTY_REGISTERS: Error:'||SQLERRM;
6133       p_codepath := jai_general_pkg.plot_codepath(-999, p_codepath, 'CENVAT_RG_PKG.DRV_DUTY_REG' , 'END');
6134 
6135   END derive_duty_registers;
6136 
6137   PROCEDURE check_cenvat_balances(
6138     p_organization_id           IN      NUMBER,
6139     p_location_id               IN      NUMBER,
6140     p_transaction_amount        IN      NUMBER,
6141     p_register_type             IN      VARCHAR2,
6142     p_process_flag OUT NOCOPY VARCHAR2,
6143     p_process_message OUT NOCOPY VARCHAR2
6144   ) IS
6145 
6146     CURSOR c_orgn_balances(cp_organization_id IN NUMBER, cp_location_id IN NUMBER, cp_register_type IN VARCHAR2) IS
6147       SELECT  decode( cp_register_type,
6148                       jai_constants.register_type_pla, pla_balance,
6149                       jai_constants.register_type_a, rg23a_balance,
6150                       jai_constants.register_type_c, rg23c_balance
6151                     )
6152       FROM JAI_CMN_RG_BALANCES
6153       WHERE organization_id = cp_organization_id
6154       AND location_id = cp_location_id;
6155 
6156     ln_current_balance  NUMBER;
6157 
6158   BEGIN
6159 
6160     OPEN c_orgn_balances(p_organization_id, p_location_id, p_register_type);
6161     FETCH c_orgn_balances INTO ln_current_balance;
6162     CLOSE c_orgn_balances;
6163 
6164     IF ( nvl(ln_current_balance,0) - nvl(p_transaction_amount,0)) < 0 THEN
6165       p_process_flag    := jai_constants.expected_error;
6166       p_process_message := 'Sufficient Balances are not available in '''||p_register_type||''' register';
6167     ELSE
6168       p_process_flag    := jai_constants.successful;
6169     END IF;
6170 
6171   END check_cenvat_balances;
6172 
6173   procedure rtv_processing_for_ssi(
6174     pn_transaction_id                 NUMBER,
6175     pv_codepath         in out nocopy varchar2,
6176     pv_process_status   out nocopy    varchar2,
6177     pv_process_message  out nocopy    varchar2
6178   ) is
6179 
6180     cursor c_rtv_dtls(cp_transaction_id in number) is
6181       select receipt_excise_rate, rtv_excise_rate, excise_basis_amt
6182       from jai_rcv_rtv_batch_trxs
6183       where transaction_id = cp_transaction_id;
6184 
6185     lv_stform_type JAI_CMN_TAXES_ALL.stform_type%type ;
6186 
6187     cursor c_excise_cess_rate(cp_shipment_line_id in number) is
6188       select a.tax_rate, b.tax_account_id, a.tax_id
6189       from JAI_RCV_LINE_TAXES a, JAI_CMN_TAXES_ALL b
6190       where a.shipment_line_id = cp_shipment_line_id
6191       and a.tax_id = b.tax_id
6192       and ( a.tax_type = jai_constants.tax_type_exc_edu_cess
6193             -- following is to take care of Initial solution(Year2004) for Excise Cess func.
6194 	    or (a.tax_type = jai_constants.tax_type_other and b.stform_type =  lv_stform_type) --'EXCISE - CESS') /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
6195             --or (a.tax_type = 'Other' and b.stform_type = 'EXCISE - CESS')
6196           );
6197 
6198 		--added by csahoo for bug#6078460
6199 		cursor c_excise_sh_cess_rate(cp_shipment_line_id in number) is
6200 					select a.tax_rate, b.tax_account_id, a.tax_id
6201 					from JAI_RCV_LINE_TAXES a, JAI_CMN_TAXES_ALL b
6202 					where a.shipment_line_id = cp_shipment_line_id
6203 					and a.tax_id = b.tax_id
6204 					and ( a.tax_type = jai_constants.tax_type_sh_exc_edu_cess
6205 								-- following is to take care of Initial solution(Year2004) for Excise sh Cess func.
6206 					or (a.tax_type = jai_constants.tax_type_other and b.stform_type =  lv_stform_type)
6207 				 );
6208 
6209     cursor c_po_dist_accrual_accnt_id(cp_transaction_id in number) is
6210       select accrual_account_id
6211       from po_distributions_all a,
6212           ( select po_line_location_id
6213             from rcv_transactions
6214             where transaction_id = cp_transaction_id) b
6215       where a.line_location_id = b.po_line_location_id;
6216 
6217     cursor c_mtl_ap_accrual_accnt_id(cp_organization_id in number) is
6218       select ap_accrual_account
6219       from mtl_parameters
6220       where organization_id = cp_organization_id;
6221 
6222     r_trx                     c_trx%ROWTYPE;
6223     r_orgn_info               c_orgn_info%ROWTYPE;
6224 
6225     lv_reference10            gl_interface.reference10%TYPE;
6226     lv_reference23            gl_interface.reference23%TYPE;
6227     lv_reference24            gl_interface.reference24%TYPE;
6228     lv_reference25            gl_interface.reference26%TYPE;
6229     lv_reference26            gl_interface.reference25%TYPE;
6230     lv_reference_name         JAI_RCV_JOURNAL_ENTRIES.reference_name%TYPE;
6231     ln_reference_id           JAI_RCV_JOURNAL_ENTRIES.reference_id%TYPE;
6232 
6233     lv_accounting_date        DATE;
6234     lv_acct_nature            JAI_RCV_JOURNAL_ENTRIES.acct_nature%TYPE;
6235     lv_acct_type              JAI_RCV_JOURNAL_ENTRIES.acct_type%TYPE;
6236 
6237     r_diff_tax                jai_rcv_excise_processing_pkg.TAX_BREAKUP;
6238     r_rtv_dtls                c_rtv_dtls%ROWTYPE;
6239 
6240     ln_excise_cess_tax_id     JAI_CMN_TAXES_ALL.tax_id%TYPE;
6241     ln_excise_cess_rate       NUMBER;
6242     ln_excise_cess_accnt_id   gl_code_combinations.code_combination_id%TYPE;
6243     --added by csahoo for bug#6078460, start
6244     ln_excise_sh_cess_tax_id     JAI_CMN_TAXES_ALL.tax_id%TYPE;
6245 		ln_excise_sh_cess_rate       NUMBER;
6246     ln_excise_sh_cess_accnt_id   gl_code_combinations.code_combination_id%TYPE;
6247     --added by csahoo for bug#6078460, end
6248     lv_cenvat_register_type   VARCHAR2(30);
6249     lv_reference_num          JAI_CMN_RG_23AC_II_TRXS.reference_num%TYPE;
6250     lv_simulate_flag          VARCHAR2(1);
6251 
6252     ln_part_ii_register_id    NUMBER(15);
6253     lv_register_entry_type    VARCHAR2(15);
6254 
6255     ln_ccid                   gl_code_combinations.code_combination_id%TYPE;
6256     ln_credit_amt             number;
6257     ln_debit_amt              number;
6258 
6259     ln_balancing_ccid         gl_code_combinations.code_combination_id%TYPE;
6260     ln_balancing_credit_amt   number;
6261     ln_balancing_debit_amt    number;
6262 
6263     lv_statement_id           VARCHAR2(4);
6264 
6265     -- Bug 5365346. Added by Lakshmi Gopalsami
6266     r_base_trx                c_base_trx%ROWTYPE;
6267   begin
6268 
6269     lv_statement_id := '1';
6270     pv_codepath := jai_general_pkg.plot_codepath(1, pv_codepath, 'jai_rcv_excise_processing_pkg.rtv_processing_for_ssi', 'START');
6271     lv_simulate_flag        := jai_constants.no;
6272     lv_register_entry_type  := jai_rcv_excise_processing_pkg.cenvat_debit;
6273 
6274     open c_trx(pn_transaction_id);
6275     fetch c_trx into r_trx;
6276     close c_trx;
6277 
6278     -- bug 5365346. Added by Lakshmi Gopalsami
6279     OPEN  c_base_trx(pn_transaction_id);
6280      FETCH  c_base_trx INTO  r_base_trx;
6281     CLOSE  c_base_trx;
6282 
6283     open c_rtv_dtls(pn_transaction_id);
6284     fetch c_rtv_dtls into r_rtv_dtls;
6285     close c_rtv_dtls;
6286     r_diff_tax.basic_excise  := r_rtv_dtls.excise_basis_amt * (r_rtv_dtls.rtv_excise_rate - r_rtv_dtls.receipt_excise_rate) / 100;
6287 
6288      lv_statement_id := '2';
6289     if nvl(r_diff_tax.basic_excise, 0) <> 0 then
6290      lv_stform_type := 'EXCISE - CESS' ;
6291       open c_excise_cess_rate(r_trx.shipment_line_id);
6292       fetch c_excise_cess_rate into ln_excise_cess_rate, ln_excise_cess_accnt_id, ln_excise_cess_tax_id;
6293       close c_excise_cess_rate;
6294       r_diff_tax.excise_edu_cess := nvl(ln_excise_cess_rate, 0) * r_diff_tax.basic_excise/100;
6295     else
6296       GOTO end_of_procedure;
6297     end if;
6298 
6299     if r_diff_tax.excise_edu_cess <> 0 and ln_excise_cess_accnt_id is null then
6300       lv_statement_id := '2.1';
6301       pv_codepath := jai_general_pkg.plot_codepath(2.1, pv_codepath);
6302       pv_process_status := 'E';
6303       pv_process_message := 'Excise Education cess account is not defined in the tax. (TaxId:'||ln_excise_cess_tax_id||')';
6304       GOTO end_of_procedure;
6305     end if;
6306 
6307     --added by csahoo for bug#6078460, start
6308 		if nvl(r_diff_tax.basic_excise, 0) <> 0 then
6309 		 lv_stform_type := 'EXCISE - SH - CESS' ;
6310 			open c_excise_sh_cess_rate(r_trx.shipment_line_id);
6311 			fetch c_excise_sh_cess_rate into ln_excise_sh_cess_rate, ln_excise_sh_cess_accnt_id, ln_excise_sh_cess_tax_id;
6312 			close c_excise_sh_cess_rate;
6313 			r_diff_tax.sh_exc_edu_cess := nvl(ln_excise_sh_cess_rate, 0) * r_diff_tax.basic_excise/100;
6314 		else
6315 			GOTO end_of_procedure;
6316 		end if;
6317 
6318 		if r_diff_tax.sh_exc_edu_cess <> 0 and ln_excise_sh_cess_accnt_id is null then
6319 			lv_statement_id := '2.1';
6320 			pv_codepath := jai_general_pkg.plot_codepath(2.1, pv_codepath);
6321 			pv_process_status := 'E';
6322 			pv_process_message := 'Excise SH Education cess account is not defined in the tax. (TaxId:'||ln_excise_sh_cess_tax_id||')';
6323 			GOTO end_of_procedure;
6324     end if;
6325     --added by csahoo for bug#6078460, end
6326 
6327     lv_statement_id := '3';
6328     /* Start Register Entry */
6329     jai_rcv_excise_processing_pkg.derive_duty_registers(
6330       p_organization_id           => r_trx.organization_id,
6331       p_location_id               => r_trx.location_id,
6332       p_item_class                => r_trx.item_class,
6333       pr_tax                      => r_diff_tax,
6334       p_cenvat_register_type      => lv_cenvat_register_type,
6335       p_process_flag              => pv_process_status,
6336       p_process_message           => pv_process_message,
6337       p_codepath                  => pv_codepath,
6338       p_transaction_type   => r_trx.transaction_type --bug#9854329
6339     );
6340 
6341     lv_statement_id := '4';
6342     if pv_process_status = 'E' then
6343       GOTO end_of_procedure;
6344     end if;
6345 
6346     if lv_cenvat_register_type IN (jai_constants.register_type_a, jai_constants.register_type_c) then
6347 
6348       lv_statement_id := '5';
6349       pv_codepath := jai_general_pkg.plot_codepath(17, pv_codepath);
6350 
6351       lv_reference_num := 'CENVAT-SSI';
6352       /*
6353       jai_rcv_excise_processing_pkg.rg23_part_ii_entry(
6354           p_transaction_id        => r_trx.transaction_id,
6355 	  pr_tax                  => r_diff_tax,
6356           p_part_i_register_id    => null,
6357           p_register_entry_type   => lv_register_entry_type,
6358           p_reference_num         => lv_reference_num,
6359           p_register_id           => ln_part_ii_register_id,
6360           p_process_status        => pv_process_status,
6361           p_process_message       => pv_process_message,
6362           p_simulate_flag         => lv_simulate_flag,
6363           p_codepath              => pv_codepath
6364       );
6365       */
6366       BEGIN
6367 	      update_RTV_Diff_value
6368 	      ( pr_base_trx          => r_base_trx,
6369 		pr_tax               => r_trx,
6370 		pr_diff_tax          => r_diff_tax,
6371 		p_source_reg         => 'RG23II',
6372 		p_register_entry_type => lv_register_entry_type,
6373 		p_register_id         => ln_part_ii_register_id,
6374 		p_simulate_flag       => lv_simulate_flag,
6375 		p_codepath            => pv_codepath,
6376 		p_process_status      => pv_process_status,
6377 		p_process_message     => pv_process_message
6378 	      );
6379       EXCEPTION
6380         WHEN OTHERS THEN
6381 	  fnd_file.put_line(FND_FILE.LOG, ' exception ' || SQLERRM);
6382       END ;
6383       lv_statement_id := '6';
6384       IF pv_process_status IN ('E', 'X') THEN
6385         GOTO end_of_procedure;
6386       END IF;
6387       lv_reference_name := 'JAI_CMN_RG_23AC_II_TRXS';
6388       ln_reference_id   := ln_part_ii_register_id;
6389     elsif lv_cenvat_register_type = jai_constants.register_type_pla THEN
6390       lv_statement_id := '7';
6391       pv_codepath := jai_general_pkg.plot_codepath(17.1, pv_codepath);
6392       /* Bug 5365346. Added by Lakshmi Gopalsami
6393          Commented the call to pla entry and added
6394       jai_rcv_excise_processing_pkg.pla_entry(
6395           p_transaction_id      => r_trx.transaction_id,
6396           pr_tax                => r_diff_tax,
6397           p_register_entry_type => lv_register_entry_type,
6398           p_register_id         => ln_part_ii_register_id,
6399           p_process_status      => pv_process_status,
6400           p_process_message     => pv_process_message,
6401           p_simulate_flag       => lv_simulate_flag,
6402           p_codepath            => pv_codepath
6403       );
6404       */
6405       Begin
6406 	      update_RTV_Diff_value
6407 	      ( pr_base_trx          => r_base_trx,
6408 		pr_tax               => r_trx,
6409 		pr_diff_tax          => r_diff_tax,
6410 		p_source_reg         => 'PLA',
6411 		p_register_entry_type => lv_register_entry_type,
6412 		p_register_id         => ln_part_ii_register_id,
6413 		p_simulate_flag       => lv_simulate_flag,
6414 		p_codepath            => pv_codepath,
6415 		p_process_status      => pv_process_status,
6416 		p_process_message     => pv_process_message
6417 	      );
6418       Exception
6419         WHEN OTHERS THEN
6420 	  fnd_file.put_line(FND_FILE.LOG, ' exception ' || SQLERRM);
6421       END ;
6422       lv_statement_id := '8';
6423       IF pv_process_status IN ('E', 'X') THEN
6424         GOTO end_of_procedure;
6425       END IF;
6426       lv_reference_name := 'JAI_CMN_RG_PLA_TRXS';
6427       ln_reference_id   := ln_part_ii_register_id;
6428     else
6429       lv_statement_id := '9';
6430       pv_codepath := jai_general_pkg.plot_codepath(17.2, pv_codepath);
6431       pv_process_status := 'E';
6432       pv_process_message := 'Duty Register cannot be derived';
6433       GOTO end_of_procedure;
6434     end if;
6435     /* End Register Entry */
6436 
6437     lv_statement_id := '10';
6438     open c_orgn_info(r_trx.organization_id, r_trx.location_id);
6439     fetch c_orgn_info into r_orgn_info;
6440     close c_orgn_info;
6441 
6442     if lv_cenvat_register_type = jai_constants.register_type_a then
6443       lv_statement_id := '11';
6444       ln_ccid := r_orgn_info.modvat_rm_account_id;
6445     elsif lv_cenvat_register_type = jai_constants.register_type_c then
6446       lv_statement_id := '12';
6447       ln_ccid := r_orgn_info.modvat_cg_account_id;
6448     elsif lv_cenvat_register_type = jai_constants.register_type_pla then
6449       lv_statement_id := '13';
6450       ln_ccid := r_orgn_info.modvat_pla_account_id;
6451     end if;
6452 
6453     if ln_ccid is null then
6454       lv_statement_id := '14';
6455       pv_process_status    := 'E';
6456       pv_process_message := 'Modvat '||lv_cenvat_register_type||' account in Organization Setup doesnot exist';
6457       GOTO end_of_procedure;
6458     end if;
6459 
6460     if r_orgn_info.rtv_account_flag = jai_constants.yes then
6461       ln_balancing_ccid := r_orgn_info.rtv_expense_account_id;
6462       if ln_balancing_ccid is null then
6463         null;
6464       end if;
6465     elsif r_orgn_info.rtv_account_flag = jai_constants.no then
6466 
6467       open c_po_dist_accrual_accnt_id(r_trx.transaction_id);
6468       fetch c_po_dist_accrual_accnt_id into ln_balancing_ccid;
6469       close  c_po_dist_accrual_accnt_id;
6470 
6471       if ln_balancing_ccid is null then
6472         open c_po_dist_accrual_accnt_id(r_trx.transaction_id);
6473         fetch c_po_dist_accrual_accnt_id into ln_balancing_ccid;
6474         close  c_po_dist_accrual_accnt_id;
6475       end if;
6476 
6477     end if;
6478 
6479     lv_statement_id := '15';
6480     if ln_balancing_ccid is null then
6481       pv_process_status  := 'E';
6482       pv_process_message := 'No value for po and mtl accrual account';
6483       GOTO end_of_procedure;
6484     end if;
6485 
6486     lv_acct_type        := 'REVERSAL';
6487     lv_acct_nature      := 'CENVAT-SSI';
6488     lv_accounting_date  := trunc(sysdate);
6489 
6490     lv_reference23      := 'JAINRTVN';
6491     lv_reference24      := 'rcv_transactions';
6492     lv_reference25      := 'transaction_id';
6493     lv_reference26      := to_char(r_trx.transaction_id);
6494 
6495     lv_statement_id := '16';
6496     lv_reference10      := 'India Local RTV Entry for the Receipt Number ' || r_trx.receipt_num;
6497     if r_trx.transaction_type = 'CORRECT' THEN
6498       lv_reference10 := lv_reference10 || ' of '||r_trx.parent_transaction_type;
6499     end if;
6500 
6501     if lv_register_entry_type = jai_rcv_excise_processing_pkg.CENVAT_DEBIT then
6502       ln_debit_amt  := null;
6503       ln_credit_amt := r_diff_tax.basic_excise;
6504       ln_balancing_debit_amt  := r_diff_tax.basic_excise;
6505       ln_balancing_credit_amt := null;
6506     else
6507       ln_debit_amt  := r_diff_tax.basic_excise;
6508       ln_credit_amt := null;
6509       ln_balancing_debit_amt  := null;
6510       ln_balancing_credit_amt := r_diff_tax.basic_excise;
6511     end if;
6512 
6513     lv_statement_id := '20';
6514     /* Primary Accounting Entry - 1 */
6515     jai_rcv_accounting_pkg.process_transaction(
6516         p_transaction_id       => r_trx.transaction_id,
6517         p_acct_type            => lv_acct_type,
6518         p_acct_nature          => lv_acct_nature,
6519         p_source_name          => jai_rcv_excise_processing_pkg.gv_source_name,
6520         p_category_name        => jai_rcv_excise_processing_pkg.gv_category_name,
6521 
6522         p_code_combination_id  => ln_ccid,
6523         p_entered_dr           => ln_debit_amt,
6524         p_entered_cr           => ln_credit_amt,
6525 
6526         p_currency_code        => jai_rcv_trx_processing_pkg.gv_func_curr,
6527         p_accounting_date      => lv_accounting_date,
6528         p_reference_10         => lv_reference10,
6529         p_reference_23         => lv_reference23, --'jai_rcv_excise_processing_pkg.accounting_entries',
6530         p_reference_24         => lv_reference24, --'rcv_transactions',
6531         p_reference_25         => lv_reference25, --'transaction_id',
6532         p_reference_26         => lv_reference26, -- <transaction_id_value>
6533         p_destination          => 'G',
6534         p_simulate_flag        => lv_simulate_flag,
6535         p_codepath             => pv_codepath,
6536         p_process_status       => pv_process_status,
6537         p_process_message      => pv_process_message
6538         ,p_reference_name     => lv_reference_name,
6539         p_reference_id        => ln_reference_id
6540     );
6541 
6542     lv_statement_id := '21';
6543     if pv_process_status = 'E' then
6544       goto end_of_procedure;
6545     end if;
6546 
6547     lv_statement_id := '22';
6548     /* Balacing Accounting Entry - 1  */
6549     jai_rcv_accounting_pkg.process_transaction(
6550         p_transaction_id       => r_trx.transaction_id,
6551         p_acct_type            => lv_acct_type,
6552         p_acct_nature          => lv_acct_nature,
6553         p_source_name          => jai_rcv_excise_processing_pkg.gv_source_name,
6554         p_category_name        => jai_rcv_excise_processing_pkg.gv_category_name,
6555 
6556         p_code_combination_id  => ln_balancing_ccid,
6557         p_entered_dr           => ln_balancing_debit_amt,
6558         p_entered_cr           => ln_balancing_credit_amt,
6559 
6560         p_currency_code        => jai_rcv_trx_processing_pkg.gv_func_curr,
6561         p_accounting_date      => lv_accounting_date,
6562         p_reference_10         => lv_reference10,
6563         p_reference_23         => lv_reference23, --'jai_rcv_excise_processing_pkg.accounting_entries',
6564         p_reference_24         => lv_reference24, --'rcv_transactions',
6565         p_reference_25         => lv_reference25, --'transaction_id',
6566         p_reference_26         => lv_reference26, -- <transaction_id_value>
6567         p_destination          => 'G',
6568         p_simulate_flag        => lv_simulate_flag,
6569         p_codepath             => pv_codepath,
6570         p_process_status       => pv_process_status,
6571         p_process_message      => pv_process_message
6572         ,p_reference_name     => lv_reference_name,
6573         p_reference_id        => ln_reference_id
6574     );
6575 
6576     lv_statement_id := '23';
6577     if pv_process_status = 'E' then
6578       goto end_of_procedure;
6579     end if;
6580 
6581     /* Education Cess Acccounting Entries */
6582     if r_diff_tax.excise_edu_cess <> 0 then
6583 
6584       lv_statement_id := '24';
6585       lv_acct_nature  := 'CENVAT-EDUCESS-SSI';
6586       ln_ccid         := ln_excise_cess_accnt_id;
6587 
6588       if lv_register_entry_type = jai_rcv_excise_processing_pkg.CENVAT_DEBIT then
6589         ln_debit_amt  := null;
6590         ln_credit_amt := r_diff_tax.excise_edu_cess;
6591         ln_balancing_debit_amt  := r_diff_tax.excise_edu_cess;
6592         ln_balancing_credit_amt := null;
6593       else
6594         ln_debit_amt  := r_diff_tax.excise_edu_cess;
6595         ln_credit_amt := null;
6596         ln_balancing_debit_amt  := null;
6597         ln_balancing_credit_amt := r_diff_tax.excise_edu_cess;
6598       end if;
6599 
6600       lv_statement_id := '25';
6601       /* Primary Accounting Entry - 2 */
6602       jai_rcv_accounting_pkg.process_transaction(
6603           p_transaction_id       => r_trx.transaction_id,
6604           p_acct_type            => lv_acct_type,
6605           p_acct_nature          => lv_acct_nature,
6606           p_source_name          => jai_rcv_excise_processing_pkg.gv_source_name,
6607           p_category_name        => jai_rcv_excise_processing_pkg.gv_category_name,
6608 
6609           p_code_combination_id  => ln_ccid,
6610           p_entered_dr           => ln_debit_amt,
6611           p_entered_cr           => ln_credit_amt,
6612 
6613           p_currency_code        => jai_rcv_trx_processing_pkg.gv_func_curr,
6614           p_accounting_date      => lv_accounting_date,
6615           p_reference_10         => lv_reference10,
6616           p_reference_23         => lv_reference23, --'jai_rcv_excise_processing_pkg.accounting_entries',
6617           p_reference_24         => lv_reference24, --'rcv_transactions',
6618           p_reference_25         => lv_reference25, --'transaction_id',
6619           p_reference_26         => lv_reference26, -- <transaction_id_value>
6620           p_destination          => 'G',
6621           p_simulate_flag        => lv_simulate_flag,
6622           p_codepath             => pv_codepath,
6623           p_process_status       => pv_process_status,
6624           p_process_message      => pv_process_message
6625           ,p_reference_name     => lv_reference_name,
6626           p_reference_id        => ln_reference_id
6627       );
6628 
6629       lv_statement_id := '26';
6630       if pv_process_status = 'E' then
6631         goto end_of_procedure;
6632       end if;
6633 
6634       lv_statement_id := '27';
6635       /* Balacing Accounting Entry - 2  */
6636       jai_rcv_accounting_pkg.process_transaction(
6637           p_transaction_id       => r_trx.transaction_id,
6638           p_acct_type            => lv_acct_type,
6639           p_acct_nature          => lv_acct_nature,
6640           p_source_name          => jai_rcv_excise_processing_pkg.gv_source_name,
6641           p_category_name        => jai_rcv_excise_processing_pkg.gv_category_name,
6642 
6643           p_code_combination_id  => ln_balancing_ccid,
6644           p_entered_dr           => ln_balancing_debit_amt,
6645           p_entered_cr           => ln_balancing_credit_amt,
6646 
6647           p_currency_code        => jai_rcv_trx_processing_pkg.gv_func_curr,
6648           p_accounting_date      => lv_accounting_date,
6649           p_reference_10         => lv_reference10,
6650           p_reference_23         => lv_reference23, --'jai_rcv_excise_processing_pkg.accounting_entries',
6651           p_reference_24         => lv_reference24, --'rcv_transactions',
6652           p_reference_25         => lv_reference25, --'transaction_id',
6653           p_reference_26         => lv_reference26, -- <transaction_id_value>
6654           p_destination          => 'G',
6655           p_simulate_flag        => lv_simulate_flag,
6656           p_codepath             => pv_codepath,
6657           p_process_status       => pv_process_status,
6658           p_process_message      => pv_process_message
6659           ,p_reference_name     => lv_reference_name,
6660           p_reference_id        => ln_reference_id
6661       );
6662 
6663       lv_statement_id := '28';
6664       if pv_process_status = 'E' then
6665         goto end_of_procedure;
6666       end if;
6667 
6668     end if;
6669 
6670     -- added by csahoo for bug#6078460, start
6671 		/* SH Education Cess Acccounting Entries */
6672 		 if r_diff_tax.excise_edu_cess <> 0 then
6673 
6674 			 lv_statement_id := '29';
6675 			 lv_acct_nature  := 'CENVAT-SH-EDUCESS-SSI';
6676 			 ln_ccid         := ln_excise_sh_cess_accnt_id;
6677 
6678 			 if lv_register_entry_type = jai_rcv_excise_processing_pkg.CENVAT_DEBIT then
6679 				 ln_debit_amt  := null;
6680 				 ln_credit_amt := r_diff_tax.sh_exc_edu_cess;
6681 				 ln_balancing_debit_amt  := r_diff_tax.sh_exc_edu_cess;
6682 				 ln_balancing_credit_amt := null;
6683 			 else
6684 				 ln_debit_amt  := r_diff_tax.sh_exc_edu_cess;
6685 				 ln_credit_amt := null;
6686 				 ln_balancing_debit_amt  := null;
6687 				 ln_balancing_credit_amt := r_diff_tax.sh_exc_edu_cess;
6688 			 end if;
6689 
6690 			 lv_statement_id := '30';
6691 			 /* Primary Accounting Entry - 2 */
6692 			 jai_rcv_accounting_pkg.process_transaction(
6693 					 p_transaction_id       => r_trx.transaction_id,
6694 					 p_acct_type            => lv_acct_type,
6695 					 p_acct_nature          => lv_acct_nature,
6696 					 p_source_name          => jai_rcv_excise_processing_pkg.gv_source_name,
6697 					 p_category_name        => jai_rcv_excise_processing_pkg.gv_category_name,
6698 
6699 					 p_code_combination_id  => ln_ccid,
6700 					 p_entered_dr           => ln_debit_amt,
6701 					 p_entered_cr           => ln_credit_amt,
6702 
6703 					 p_currency_code        => jai_rcv_trx_processing_pkg.gv_func_curr,
6704 					 p_accounting_date      => lv_accounting_date,
6705 					 p_reference_10         => lv_reference10,
6706 					 p_reference_23         => lv_reference23, --'jai_rcv_excise_processing_pkg.accounting_entries',
6707 					 p_reference_24         => lv_reference24, --'rcv_transactions',
6708 					 p_reference_25         => lv_reference25, --'transaction_id',
6709 					 p_reference_26         => lv_reference26, -- <transaction_id_value>
6710 					 p_destination          => 'G',
6711 					 p_simulate_flag        => lv_simulate_flag,
6712 					 p_codepath             => pv_codepath,
6713 					 p_process_status       => pv_process_status,
6714 					 p_process_message      => pv_process_message
6715 					 ,p_reference_name     => lv_reference_name,
6716 					 p_reference_id        => ln_reference_id
6717 			 );
6718 			fnd_file.put_line(FND_FILE.LOG, ' lv_statement_id ' || lv_statement_id);
6719 			 lv_statement_id := '31';
6720 			 if pv_process_status = 'E' then
6721 				 goto end_of_procedure;
6722 			 end if;
6723 
6724 			 lv_statement_id := '32';
6725 			 /* Balacing Accounting Entry - 2  */
6726 			 jai_rcv_accounting_pkg.process_transaction(
6727 					 p_transaction_id       => r_trx.transaction_id,
6728 					 p_acct_type            => lv_acct_type,
6729 					 p_acct_nature          => lv_acct_nature,
6730 					 p_source_name          => jai_rcv_excise_processing_pkg.gv_source_name,
6731 					 p_category_name        => jai_rcv_excise_processing_pkg.gv_category_name,
6732 
6733 					 p_code_combination_id  => ln_balancing_ccid,
6734 					 p_entered_dr           => ln_balancing_debit_amt,
6735 					 p_entered_cr           => ln_balancing_credit_amt,
6736 
6737 					 p_currency_code        => jai_rcv_trx_processing_pkg.gv_func_curr,
6738 					 p_accounting_date      => lv_accounting_date,
6739 					 p_reference_10         => lv_reference10,
6740 					 p_reference_23         => lv_reference23, --'jai_rcv_excise_processing_pkg.accounting_entries',
6741 					 p_reference_24         => lv_reference24, --'rcv_transactions',
6742 					 p_reference_25         => lv_reference25, --'transaction_id',
6743 					 p_reference_26         => lv_reference26, -- <transaction_id_value>
6744 					 p_destination          => 'G',
6745 					 p_simulate_flag        => lv_simulate_flag,
6746 					 p_codepath             => pv_codepath,
6747 					 p_process_status       => pv_process_status,
6748 					 p_process_message      => pv_process_message
6749 					 ,p_reference_name     => lv_reference_name,
6750 					 p_reference_id        => ln_reference_id
6751 			 );
6752 			fnd_file.put_line(FND_FILE.LOG, ' lv_statement_id ' || lv_statement_id);
6753 			 lv_statement_id := '28';
6754 			 if pv_process_status = 'E' then
6755 				 goto end_of_procedure;
6756 			 end if;
6757 
6758 
6759     end if;
6760 
6761     -- added by csahoo for bug#6078460, end
6762 
6763     lv_statement_id := '29';
6764     pv_process_status := jai_constants.yes;
6765     <<end_of_procedure>>
6766     pv_codepath := jai_general_pkg.plot_codepath(75, pv_codepath, 'jai_rcv_excise_processing_pkg.rtv_processing_for_ssi', 'END');
6767 
6768   exception
6769     when others then
6770       pv_process_status := 'E';
6771       pv_process_message := 'Unexpected error in jai_rcv_excise_processing_pkg.rtv_processing_for_ssi(StmtId:'
6772                             ||lv_statement_id||'). ErrMsg:'||SQLERRM;
6773       pv_codepath := jai_general_pkg.plot_codepath(999, pv_codepath, 'jai_rcv_excise_processing_pkg.rtv_processing_for_ssi', 'END');
6774 
6775   end rtv_processing_for_ssi;
6776   --start additions for bug#4750798
6777   PROCEDURE get_excise_tax_rounding_factor(
6778    p_transaction_id IN NUMBER,
6779    p_Excise_rf OUT NOCOPY NUMBER,
6780    p_Excise_edu_cess_rf OUT NOCOPY NUMBER,
6781    p_Excise_she_cess_rf OUT NOCOPY NUMBER
6782    )
6783    IS
6784    CURSOR c_get_tax_rounding_factor(cp_transaction_id NUMBER) IS
6785         SELECT jt.tax_id,jt.tax_name,nvl(jt.ROUNDING_FACTOR,0) rf,jt.tax_type
6786         FROM jai_rcv_line_taxes jrt,rcv_transactions rt,
6787           jai_cmn_taxes_all jt
6788         WHERE jrt.shipment_line_id = rt.shipment_line_id
6789          AND jrt.shipment_header_id = rt.shipment_header_id
6790          AND jt.tax_id = jrt.tax_id
6791          AND rt.transaction_id=cp_transaction_id;
6792    BEGIN
6793 
6794     FOR tax_rf in  c_get_tax_rounding_factor(p_transaction_id)
6795     LOOP
6796 
6797      IF tax_rf.tax_type='Excise' THEN
6798        p_Excise_rf:=tax_rf.rf;
6799      ELSIF tax_rf.tax_type='EXCISE_EDUCATION_CESS' THEN
6800         p_Excise_edu_cess_rf:=tax_rf.rf;
6801      ELSIF tax_rf.tax_type='EXCISE_SH_EDU_CESS' THEN
6802         p_Excise_she_cess_rf:=tax_rf.rf;
6803      END IF;
6804 
6805     END LOOP;
6806 
6807 
6808    END get_excise_tax_rounding_factor;
6809 
6810  --end additions for bug#4750798
6811 
6812 
6813 END jai_rcv_excise_processing_pkg;