DBA Data[Home] [Help]

PACKAGE BODY: APPS.JAI_PO_TAX_PKG

Source


1 PACKAGE BODY jai_po_tax_pkg AS
2 /* $Header: jai_po_tax.plb 120.36.12010000.4 2009/02/06 10:04:29 nprashar ship $ */
3 
4  /* --------------------------------------------------------------------------------------
5 Filename:
6 
7 Change History:
8 
9 Date         Bug         Remarks
10 ---------    ----------  -------------------------------------------------------------
11 08-Jun-2005  Version 116.2 jai_po_tax -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    File Version: 116.3
15                Ramananda for bug#4428980. Removal of SQL LITERALs is done
16 
17 26-Jul-2005    Aiyer for the bug 4517919,File Version 120.2
18                 Removed the reference to dbms_support.start_trace and dbms_support.stop_trace and replaced it with
19     execute immediate alter session SET EVENTS ''10046 trace name context forever, level 4''';
20 
21 27-Jul-2005    Bug 4516508. Added by Lakshmi Gopalsami version 120.3
22                Wrong calculation of tax amount when values added tax is included
23                during tax defaultation in PO.
24                Issue in Procedure Ja_In_Po_Case2.
25                The calculation of vat assesseble value was wrong. The vat amount is
26                now multiplied with the quantity if the function
27                jai_general_pkg.ja_in_vat_assessable_value
28                returns a not null value. Else the line amount is assigned as
29                the VAT amount.
30 28-Jul-2005    Bug 4520049. Added by Lakshmi Gopalsami Version 120.4
31                Added nvl for v_temp_price while calling
32                jai_general_pkg.ja_in_vat_assessable_value
33                in procedure copy_agreement_Taxes
34 
35          Dependency Due to this bug :-
36          None
37 
38 31/10/2006   SACSETHI for bug 5228046, File version 120.7
39              1.  Forward porting the change in 11i bug 5365523 (Additional CVD Enhancement , Tax Precedence , BOE ).
40                  This bug has datamodel and spec changes.
41 
42              2.  Forward porting of bug 5219225
43 
44 13-April-2007   ssawant for bug 5989740 ,File version 120.11
45                 Forward porting Budget07-08 changes of handling secondary and
46 	        Higher Secondary Education Cess from 11.5( bug no 5907436) to R12 (bug no 5989740).
47 		Changes were done for following files
48 		ja_in_po_default_taxes_pkg.sql ;
49 		ja_in_po_calc_tax_p.sql;
50 
51  18-jun-2007    sacsethi for bug 6134628 , file version 120.14
52 
53 		TAXES ARE NOT DEFAULTING FROM BPO TO RELEASES
54 
55 		Solution - Cursor Fetch_Taxes_Cur is changed
56 24-Aug-2007  iProcurement forward porting bug #6066485
57 
58  11-Sep-2007    For Bug 6137011
59                  For UOM tax lines tax amount is recalculated when currency code
60                  is changed.  --pramasub
61 
62 18-Sep-2007  iProcurement : bug # 6066485
63                issue : Currency conversion is not happening for Receipt taxes
64                fix : Compare if the line currency and tax currency are different
65                      then apply the conversion.
66 
67 17-Dec-2007  Kevin Cheng   Update the logic for inclusive tax calculation
68 
69 15-Jan-2008  Kevin Cheng   Update for Retroactive Price Enhancement
70 22-Jan-2008  Eric Ma   Update pv_called_from,lv_tax_type,lv_third_party_flag
71 23-Jan-2008   rchandan for bug#6766561 . File Version 120.31
72  	               Issue : INCORRECT TAX CALCULATION ON BLANKET PO RELEASES
73  	                 Fix : When VAT assessable value is not defined then line amount should be used
74  	                       as VAt assessable during tax calculation for VAT type of taxes.
75  	                       This was not happening. So added the code for this.
76                               This change is made to merge the fix made in version 120.29 for bug#6685406
77 22-Jan-2008  Eric Ma    Update cursor of get_rcv_line_for_retro to fix a bug
78 15-Feb-2008  Kevin Cheng   Modify code for bug 6816062.
79                            reset non rate tax amount for ad hoc tax in the third calculation loop.
80 26-Feb-2008  Kevin Cheng   Modify code for bug 6838743.
81                            Change variable v_tax_amt and vamt definition.
82                            Remove precision restriction for these temp
83                            variable, so the final result precision will
84                            not be affected by them.
85 29-Feb-2008  Kevin Cheng   Modify code for bug 6849952.
86                            reset non rate tax amount for ad hoc tax in the third calculation loop.
87 
88 
89 10-Nov-2008  Bug 7436368  File version 120.36.12010000.3
90              Issue : Taxes are not defaulted from catalog quotation to PO even after running
91 	     the concurrent "India - Concurrent request for defaulting taxes in PO when linked
92 	     with Quotation".
93 	     Reason: In procedure copy_quot_taxes, the where clause of cursor tax_cur was
94 	     changed from "nvl(a.line_location_id,-999)=v_quot_line_loc_id" to
95 	     "a.line_location_id=v_quot_line_loc_id" for removing SQL literals. But in
96 	     case of quotations with no price breaks, the line_location_id would be null
97 	     and this condtion would fail. Because of this taxes will not get copied.
98 	     Fix   : The condition was modified as follows, to handle the case:
99 	     ((a.line_location_id IS NULL AND v_quot_line_loc_id=-999) OR (a.line_location_id = v_quot_line_loc_id))
100 
101 6-FEB-2009 Changes by nprashar for bug 7694945, changes in procedure Copy Agreement Taxes.
102 
103  --------------------------------------------------------------------------------------*/
104 
105 PROCEDURE calculate_tax(
106     p_type IN VARCHAR2,
107     p_header_id NUMBER,
108     P_line_id NUMBER,
109     p_line_loc_id IN NUMBER,
110     p_line_quantity IN NUMBER,
111     p_price IN NUMBER,
112     p_line_uom_code IN VARCHAR2,
113     p_tax_amount IN OUT NOCOPY NUMBER,
114     p_assessable_value IN NUMBER DEFAULT NULL,
115     p_vat_assess_value IN NUMBER,  -- Ravi for VAT
116     p_item_id IN NUMBER DEFAULT NULL,
117     p_conv_rate IN NUMBER DEFAULT NULL
118    ,pv_retroprice_changed IN VARCHAR2 DEFAULT 'N' --Added by Kevin Cheng for Retroactive Price 2008/01/10
119    ,pv_called_from         IN VARCHAR2 DEFAULT NULL--Added by Eric Ma for Retroactive Price 2008/01/11
120   ) IS
121 
122   --  Line Location_Id is passed instead of p_header_id; Src_Ship_Id is passed in p_line_loc_id
123   --  For Requisition from Blanket PO, Requisition Line Id is passed in place of p_header_id, Currency in place of UOM.
124 
125 
126 -- Date 02/11/2006 Bug 5228046 added by SACSETHI
127    --TYPE Num_Tab IS TABLE OF NUMBER(25,4) INDEX BY BINARY_INTEGER;
128    --TYPE Tax_Amt_Num_Tab IS TABLE OF NUMBER(25,4) INDEX BY BINARY_INTEGER;
129 
130     TYPE Num_Tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
131     TYPE Tax_Amt_Num_Tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
132 
133     TYPE currency_tab IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
134     TYPE adhoc_flag_tab IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER; -- added by subbu on 08-nov-01
135 
136     debug VARCHAR2(1); --File.Sql.35 Cbabu  := 'Y'; --debug statement added by cbabu
137     p1        num_tab;
138     p2        num_tab;
139     p3        num_tab;
140     p4        num_tab;
141     p5        num_tab;
142     -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
143     p6        num_tab;
144     p7        num_tab;
145     p8        num_tab;
146     p9        num_tab;
147     p10       num_tab;
148 
149     rnd_factor            NUM_TAB;
150     p_inventory_item_id   NUMBER;
151     tax_rate_tab          NUM_TAB;
152     tax_type_tab          NUM_TAB;
153     end_date_tab          NUM_TAB;
154     tax_amt_tab           TAX_AMT_NUM_TAB;
155     tax_target_tab        TAX_AMT_NUM_TAB;
156     curr_tab              CURRENCY_TAB;
157     adhoc_tab             ADHOC_FLAG_TAB; -- added by subbu on 08-nov-01
158     v_amt                 NUMBER;
159     bsln_amt              NUMBER; --File.Sql.35 Cbabu     := p_tax_amount;
160     row_count             NUMBER; --File.Sql.35 Cbabu     := 0;
161 
162 
163 -- Date 01/11/2006 Bug 5228046 added by SACSETHI
164     v_tax_amt     NUMBER  ;
165     vamt          NUMBER  ;
166     max_iter      NUMBER ; -- bug 5228046. Changed from 10 to 15
167     v_conversion_rate   NUMBER;
168     counter     NUMBER;
169     conv_rate     NUMBER;
170     v_rnd_factor          NUMBER;
171 
172     -- Only for Requisition_Blanket
173     v_curr  VARCHAR2(30); --File.Sql.35 Cbabu   :=  p_line_uom_code;
174     -- End.
175 
176     -- 6/05/02 cbabu bug2357371
177     v_line_uom_code VARCHAR2(30); --File.Sql.35 Cbabu     := p_line_uom_code;
178 
179     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
180     ----------------------------------------------------------
181     TYPE CHAR_TAB IS TABLE OF VARCHAR2(10)
182     INDEX BY BINARY_INTEGER;
183 
184     lt_adhoc_tax_tab             CHAR_TAB;
185     lt_inclu_tax_tab             CHAR_TAB;
186     lt_tax_rate_per_rupee        NUM_TAB;
187     lt_cumul_tax_rate_per_rupee  NUM_TAB;
188     lt_tax_rate_zero_tab         NUM_TAB;
189     lt_tax_amt_rate_tax_tab      TAX_AMT_NUM_TAB;
190     lt_tax_amt_non_rate_tab      TAX_AMT_NUM_TAB;
191     lt_base_tax_amt_tab          TAX_AMT_NUM_TAB;
192     lt_func_tax_amt_tab          TAX_AMT_NUM_TAB;
193     ln_exclusive_price           NUMBER;
194     ln_total_non_rate_tax        NUMBER := 0;
195     ln_total_inclusive_factor    NUMBER;
196     ln_bsln_amt_nr               NUMBER := 0;
197     ln_currency_conv_factor      NUMBER;
198     ln_tax_amt_nr                NUMBER(38,10) := 0;
199     ln_func_tax_amt              NUMBER(38,10) := 0;
200     ln_vamt_nr                   NUMBER(38,10) := 0;
201     ln_excise_jb                 NUMBER;
202     ln_total_tax_per_rupee       NUMBER;
203     ln_assessable_value          NUMBER;
204     ln_vat_assessable_value      NUMBER;
205     ----------------------------------------------------------
206 
207     --Add by Eric Ma for Retro Active Pricing Update on Jan 11, 2008 ,Begin
208     -----------------------------------------------------------------------
209     CURSOR get_rcv_line_for_retro ( pn_tax_id in NUMBER)--changed by erif on Feb 1,2008
210     IS
211     SELECT
212       tax_type
213     , third_party_flag
214     FROM
215       jai_rcv_line_taxes
216     WHERE  shipment_line_id = p_line_id  -- shipment line id
217       AND  tax_id           = pn_tax_id ; --added by erif on Feb 1,2008
218 
219     lv_tax_type           jai_rcv_line_taxes.tax_type%TYPE;
220     lv_third_party_flag   jai_rcv_line_taxes.third_party_flag%TYPE;
221     -----------------------------------------------------------------------
222     --Add by Eric Ma for Retro Active Pricing Update on Jan 11, 2008 ,End
223 
224     CURSOR Fetch_Item_Cur IS
225       SELECT Item_Id
226       FROM   Po_Lines_All
227       WHERE  Po_Line_Id = p_line_id;
228 
229     -- 6/05/02 cbabu. added to fetch UOM_code in case if it is null. if this is null then we will get problems during quantity rate tax.
230     -- 6/05/02 cbabu bug2357371
231     CURSOR Fetch_line_uom_code IS
232       SELECT Uom_Code
233       FROM  po_lines_all plines, mtl_units_of_measure units
234       WHERE plines.Po_Line_Id = p_line_id
235       AND units.Unit_Of_Measure = plines.unit_meas_lookup_code;
236 
237     CURSOR fetch_rcv_line_currency is
238     SELECT rt.currency_code
239       FROM rcv_transactions     rt,
240            rcv_shipment_lines   rcl
241      WHERE rcl.shipment_header_id = p_header_id
242        AND rcl.shipment_line_id = p_line_id
243        AND rt.shipment_header_id = rcl.shipment_header_id
244        AND rt.shipment_line_id = rcl.shipment_line_id
245        AND rt.transaction_type = 'RECEIVE' ;
246 
247     lv_currency_code    rcv_transactions.currency_code%TYPE;
248 
249     -- in PR to PO / BPO to Brelease
250     -- added B.adhoc_flag column in select statement
251     /* Addded by LGOPALSA. Bug 4210102.
252      * Added CVD and Excise education cess
253      * */
254   /* Bug 5094130. Added by Lakshmi Gopalsami
255      Removed the PO_TAX_CUR cursor and added the record type
256   */
257   TYPE PO_TAX_CUR IS RECORD(
258   LNo   JAI_PO_TAXES.TAX_LINE_NO%TYPE,
259   P_1   JAI_PO_TAXES.PRECEDENCE_1%TYPE,
260   P_2   JAI_PO_TAXES.PRECEDENCE_2%TYPE,
261   P_3   JAI_PO_TAXES.PRECEDENCE_3%TYPE,
262   P_4   JAI_PO_TAXES.PRECEDENCE_4%TYPE,
263   P_5   JAI_PO_TAXES.PRECEDENCE_5%TYPE,
264   /* bug 5094130. Added by Lakshmi Gopalsami
265    * Included precedences 6 to 10
266    */
267   P_6   JAI_PO_TAXES.PRECEDENCE_6%TYPE,
268   P_7   JAI_PO_TAXES.PRECEDENCE_7%TYPE,
269   P_8   JAI_PO_TAXES.PRECEDENCE_8%TYPE,
270   P_9   JAI_PO_TAXES.PRECEDENCE_9%TYPE,
271   P_10    JAI_PO_TAXES.PRECEDENCE_10%TYPE,
272   Tax_Id          JAI_PO_TAXES.TAX_ID%TYPE,
273   Tax_type_val    NUMBER,
274   Tax_rate        JAI_PO_TAXES.TAX_RATE%TYPE,
275   Qty_Rate        JAI_PO_TAXES.QTY_RATE%TYPE,
276   Uom_code        JAI_PO_TAXES.UOM%TYPE,
277   Tax_Amount      JAI_PO_TAXES.TAX_AMOUNT%TYPE,
278   Curr            JAI_PO_TAXES.CURRENCY%TYPE,
279   Valid_Date      JAI_CMN_TAXES_ALL.END_DATE%TYPE,
280   Rnd_factor      JAI_CMN_TAXES_ALL.ROUNDING_FACTOR%TYPE,
281   Adhoc_flag      JAI_CMN_TAXES_ALL.ADHOC_FLAG%TYPE
282   ,Inclusive_tax_flag    JAI_CMN_TAXES_ALL.Inclusive_Tax_Flag%TYPE --Add by Kevin Cheng for inclusive tax Dec 18, 2007
283   );
284 
285 
286     -- START, Vijay Shankar for Bug# 3190782
287     TYPE tax_cur_type IS REF CURSOR RETURN PO_TAX_CUR;
288     c_tax_cur TAX_CUR_TYPE;
289     rec     c_tax_cur%ROWTYPE;
290     -- END, Vijay Shankar for Bug# 3190782
291 
292 --Added by Kevin Cheng for Retroactive Price 2008/01/11
293 --=====================================================
294 TYPE PO_TAX_RETRO_CUR IS RECORD(
295   LNo   JAI_PO_TAXES.TAX_LINE_NO%TYPE,
296   P_1   JAI_PO_TAXES.PRECEDENCE_1%TYPE,
297   P_2   JAI_PO_TAXES.PRECEDENCE_2%TYPE,
298   P_3   JAI_PO_TAXES.PRECEDENCE_3%TYPE,
299   P_4   JAI_PO_TAXES.PRECEDENCE_4%TYPE,
300   P_5   JAI_PO_TAXES.PRECEDENCE_5%TYPE,
301   /* bug 5094130. Added by Lakshmi Gopalsami
302    * Included precedences 6 to 10
303    */
304   P_6   JAI_PO_TAXES.PRECEDENCE_6%TYPE,
305   P_7   JAI_PO_TAXES.PRECEDENCE_7%TYPE,
306   P_8   JAI_PO_TAXES.PRECEDENCE_8%TYPE,
307   P_9   JAI_PO_TAXES.PRECEDENCE_9%TYPE,
308   P_10    JAI_PO_TAXES.PRECEDENCE_10%TYPE,
309   Tax_Id          JAI_PO_TAXES.TAX_ID%TYPE,
310   Tax_type_val    NUMBER,
311   Tax_rate        JAI_PO_TAXES.TAX_RATE%TYPE,
312   Qty_Rate        JAI_PO_TAXES.QTY_RATE%TYPE,
313   Uom_code        JAI_PO_TAXES.UOM%TYPE,
314   Tax_Amount      JAI_PO_TAXES.TAX_AMOUNT%TYPE,
315   Curr            JAI_PO_TAXES.CURRENCY%TYPE,
316   Valid_Date      JAI_CMN_TAXES_ALL.END_DATE%TYPE,
317   Rnd_factor      JAI_CMN_TAXES_ALL.ROUNDING_FACTOR%TYPE,
318   Adhoc_flag      JAI_CMN_TAXES_ALL.ADHOC_FLAG%TYPE,
319   hdr_vendor_id   PO_HEADERS_ALL.Vendor_Id%TYPE,
320   tax_vendor_id   JAI_PO_TAXES.Vendor_Id%TYPE
321   );
322 
323 
324     -- START, Vijay Shankar for Bug# 3190782
325     TYPE tax_cur_retro_type IS REF CURSOR RETURN PO_TAX_RETRO_CUR;
326     c_tax_retro_cur tax_cur_retro_type;
327     rec_retro     c_tax_retro_cur%ROWTYPE;
328     -- END, Vijay Shankar for Bug# 3190782
329 
330 lv_tax_remain_flag        VARCHAR2(1);
331 lv_process_flag           VARCHAR2(10);
332 lv_process_message        VARCHAR2(2000);
333 --=====================================================
334 
335     Cursor req_adhoc_tax_amt(taxid number) is
336       select A.tax_amount from JAI_PO_REQ_LINE_TAXES A, JAI_CMN_TAXES_ALL B
337       where A.tax_id =  taxid
338       AND requisition_line_id in(select requisition_line_id
339         from po_req_distributions_all
340         where distribution_id in (select req_distribution_id
341           from po_distributions_all
342           where po_header_id = p_header_id
343           and po_line_id = p_line_id))
344       and A.Tax_id = B.Tax_id
345       and B.adhoc_flag = 'Y';
346 
347     v_adhoc_tax_amt number;
348     v_adhoc_flag varchar2(1);
349     v_qty_rate number;
350     -- end of cursor added by subbu on 8-nov-01
351     -- end of modifications by subbu on 7-nov-01 for considering adhoc taxes in PR to PO / BPO to Brelease
352 
353     CURSOR uom_class_cur(p_line_uom_code IN VARCHAR2, p_tax_line_uom_code IN VARCHAR2) IS
354       SELECT A.uom_class
355       FROM mtl_units_of_measure A, mtl_units_of_measure B
356       WHERE A.uom_code = p_line_uom_code
357       AND B.uom_code = p_tax_line_uom_code
358       AND A.uom_class = B.uom_class;
359 
360     CURSOR Fetch_Sum_Cur( linelocid IN NUMBER ) IS
361       SELECT SUM( NVL( Tax_Amount, 0 ) )
362       FROM   JAI_PO_TAXES
363       WHERE  Line_Location_Id = linelocid      -- For Blanket Rel Line Loc Id is passed in place of header id.
364       AND   Tax_Type <> jai_constants.tax_type_tds ; --'TDS'; /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
365 
366   lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.calculate_tax';
367   BEGIN
368 
369   /*------------------------------------------------------------------------------------------
370    FILENAME: ja_in_cal_tax_p.sql
371 
372    CHANGE HISTORY:
373   S.No      Date          Author and Details
374   ------------------------------------------------------------------------------------------
375   1.      23-Aug-02 Nagaraj.s for Bug2519359
376                       The Adhoc Amounts were being picked up from requisitions earlier.
377                       Hence, in case of an Standard PO created without an requisition
378                       the adhoc amounts were populated as Zero which has been taken care
379                       by, incorporating an if condition if p_type='REQUISITION' then
380                       adhoc amounts are picked up from Requisition, else it will be picked
381                       from the previous adhoc amounts entered in the Tax screen.
382 
383   2.      26-JUN-03 Vijay Shankar for Bug# 3026084, FileVersion: 616.1
384                        Tax amount is getting calculated as 0 if tax_rate is -1. the reason is that
385                        if tax_rate_tab contains -1, then it is treated as adhoc tax and will not calculate
386                        tax amount. fixed the issue by treating the adhoc tax if tax_rate_tab contains -99999
387 
388   3       10-OCT-03 Vijay Shankar for Bug# 3190782, FileVersion: 616.2
389                        Tax Calculation is not handled properly when P_TYPE='REQUISITION', which is made proper with this fix. Basically
390                        assigning values to plsql tables is handled properly with common code by accessing JAI_PO_REQ_LINE_TAXES and
391                        JAI_PO_TAXES through REF CURSOR. Code related to populating plsql tables during P_TYPE='REQUISITION'
392                        is removed and aligned with PO code.
393 
394   4.      12-OCT-05 Bug4210102. Added by LGOPALSA
395                       Added CVD and Excise education Cess
396 
397   5.     17/mar-2005  Rchandan for bug#4245365 Version 115.2
398                      Changes made to calculate VAT taxes taking the VAT assessable value as base
399                      New parameter is added for having vat assesable value.
400   6.     20/03/2005  rchandan Version 115.3
401                      Wrong template was used while checkin. So again checked out the file and now doing a check in with correct template
402   7. 17/04/2007      kunkumar for 5989740
403                     Forward porting file ja_in_cal_tax_p.sql; version  	115.8.6107.2
404   8. 09/03/2007    rchandan for bug#4281841 , File Version 115.10
405                    Issue :  NEW ENH: IL SUPPORT FOR IPROCUREMENT
406                    Fix :  Added rounding to the tax amount wherever it is getting calculated.
407                          Moreover if the rounding factor is NULL , then tax amount was getting populated as NULL. So added
408                          a nvl condition with 0 as default. v_conversion_rate is initialised to zero for UOM based taxes.
409   9.  06/02/2007  rchandan for bug#5852041 , File Version 115.8
410                    Issue : TAX CALCULATED INCORRECTLY WHEN REQUISITION QUANTITY IS MODIFIED
411                      Fix : The cursor c_reqn_curr is modified to query from po_requistion_headers_all instead of
412                            po_requistion_lines_all as it was mutating when called from triggers on po_requistion_lines_all.
413 
414   10. 01/15/2008  Kevin Cheng   Add a branch to deal with taxes recalculate for retroactive price update.
415 
416   11. 02/29/2008  Kevin Cheng   Modify code for bug 6849952.
417                                 reset non rate tax amount for ad hoc tax in the third calculation loop.
418 
419   ===============================================================================
420   Dependencies:
421 
422   Version   Author      Dependency        Comments
423 
424   115.1     LGOPALSA    IN60106 +         Implemented Cess tax code
425                         4146708
426 
427   115.2     RCHANDAN    4245089              VAT implementation
428 
429   -------------------------------------------------------------------------------------------- */
430   --Added by Kevin Cheng for Retroactive Price 2008/01/10
431   --=====================================================
432   IF pv_retroprice_changed = 'N'
433   THEN
434   --=====================================================
435     debug           :=  'Y';
436     bsln_amt        :=  p_tax_amount;
437     row_count       :=  0;
438     v_tax_amt       :=  0;
439     vamt            :=  0;
440     max_iter        :=  15; -- bug 5228046. Changed from 10 to 15
441     v_curr          :=  p_line_uom_code;
442     v_line_uom_code :=  p_line_uom_code;
443 
444   IF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO' ) THEN -- Vijay Shankar for Bug# 3190782
445 
446     IF p_item_id IS NULL THEN
447        OPEN  Fetch_Item_Cur;
448        FETCH Fetch_Item_Cur INTO p_inventory_item_id;
449        CLOSE Fetch_Item_Cur;
450     ELSE
451        p_inventory_item_id := p_item_id;
452     END IF;
453 
454   --start 6/05/02 cbabu bug2357371
455     IF p_line_uom_code IS NULL THEN
456        OPEN  Fetch_line_uom_code;
457        FETCH Fetch_line_uom_code INTO v_line_uom_code;
458        CLOSE Fetch_line_uom_code;
459     END IF;
460   --end 6/05/02 cbabu bug2357371
461 
462   END IF;   -- Vijay Shankar for Bug# 3190782
463 
464   IF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO' ) THEN
465 
466           /* Added by LGOPALSA. Bug 4210102.
467      * Added CVD and Excise Education Cess
468      * */
469      OPEN c_tax_cur FOR
470      SELECT A.Tax_Line_No LNo,
471             A.Precedence_1 P_1,
472       A.Precedence_2 P_2,
473             A.Precedence_3 P_3,
474       A.Precedence_4 P_4,
475       A.precedence_5 P_5,
476             A.Precedence_6 P_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
477       A.Precedence_7 P_7,
478             A.Precedence_8 P_8,
479       A.Precedence_9 P_9,
480       A.precedence_10 P_10,
481             A.Tax_Id,
482             DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
483                                                                'EXCISE', 1,
484                                                          'ADDL. EXCISE', 1,
485                                                          'OTHER EXCISE', 1,
486                                     --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
487                                     /*jai_constants.tax_type_exc_edu_cess, 1,
488                                     jai_constants.tax_type_sh_exc_edu_cess, 1,--Added by kunkumar for bugno5989740*/
489                                     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
490                                     ---------------------------------------------------
491                                     jai_constants.tax_type_exc_edu_cess, 6,
492                                     jai_constants.tax_type_cvd_edu_cess , 6,
493                                     jai_constants.tax_type_sh_exc_edu_cess, 6,
494                                     jai_constants.tax_type_sh_cvd_edu_cess, 6,
495                                     ---------------------------------------------------
496                                                                   'TDS', 2, 0)) tax_type_val,
497             A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
498             A.Tax_Amount, A.currency curr, B.End_Date Valid_Date,
499             B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
500             , B.inclusive_tax_flag --Add by Kevin Cheng for inclusive tax Dec 18, 2007
501       FROM JAI_PO_TAXES A, JAI_CMN_TAXES_ALL B,jai_regime_tax_types_v aa
502      WHERE Po_Line_Id = p_line_id
503        AND Line_Location_Id = p_line_loc_id
504        --AND NVL( Line_Location_Id, -999 ) = p_line_loc_id /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
505        AND A.Tax_Id = B.Tax_Id
506        AND aa.tax_type(+) = b.tax_type
507      ORDER BY 1;
508 
509      --- Cursor changed by ravi for getting the vat related taxes.
510 
511 
512   ELSIF p_type = 'REQUISITION' THEN
513 
514           /* added by LGOPALSA. Bug 4210102.
515      * Added Excise and CVD Education Cess */
516     OPEN c_tax_cur FOR
517     SELECT A.Tax_Line_No LNo,
518            A.Precedence_1 P_1,
519      A.Precedence_2 P_2,
520            A.Precedence_3 P_3,
521      A.Precedence_4 P_4,
522      A.precedence_5 P_5,
523            A.Precedence_6 P_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
524      A.Precedence_7 P_7,
525            A.Precedence_8 P_8,
526      A.Precedence_9 P_9,
527      A.precedence_10 P_10,
528            A.Tax_Id,
529            DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
530                                                               'EXCISE', 1,
531                                                         'ADDL. EXCISE', 1,
532                                                         'OTHER EXCISE', 1,
533                                    --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
534                                    /*jai_constants.tax_type_exc_edu_cess, 1,
535                                    jai_constants.tax_type_sh_exc_edu_cess, 1,--Added by kunkumar for bugno 5989740*/
536                                    --Add by Kevin Cheng for inclusive tax Dec 18, 2007
537                                    ---------------------------------------------------
538                                    jai_constants.tax_type_exc_edu_cess, 6,
539                                    jai_constants.tax_type_cvd_edu_cess , 6,
540                                    jai_constants.tax_type_sh_exc_edu_cess, 6,
541                                    jai_constants.tax_type_sh_cvd_edu_cess, 6,
542                                    ---------------------------------------------------
543    'TDS', 2, 0)) tax_type_val,
544            A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
545            A.Tax_Amount, A.currency curr, B.End_Date Valid_Date,
546            B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
547            , B.inclusive_tax_flag --Add by Kevin Cheng for inclusive tax Dec 18, 2007
548      FROM JAI_PO_REQ_LINE_TAXES A,
549           JAI_CMN_TAXES_ALL B,
550           jai_regime_tax_types_v aa
551     WHERE requisition_line_Id = p_line_id
552       AND A.Tax_Id = B.Tax_Id
553       AND aa.tax_type(+) = b.tax_type
554 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
555    ORDER BY 1;
556 
557    /* added by ssumaith for receipts tax recalculation .*/
558    ELSIF p_type = 'RECEIPTS' THEN
559 
560      OPEN c_tax_cur FOR
561      SELECT A.Tax_Line_No LNo,  A.Precedence_1 P_1, A.Precedence_2 P_2,
562               A.Precedence_3 P_3, A.Precedence_4 P_4, A.precedence_5 P_5,
563               A.Precedence_6 P_6, A.Precedence_7 P_7,
564               A.Precedence_8 P_8, A.Precedence_9 P_9, A.precedence_10 P_10,
565               A.Tax_Id,
566               DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
567                                                                  'EXCISE', 1,
568                                                            'ADDL. EXCISE', 1,
569                                                            'OTHER EXCISE', 1,
570                                                            --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
571                                                            /*'Excise_Education_cess', 1,*/
572                                                            --Add by Kevin Cheng for inclusive tax Dec 18, 2007
573                                                            ---------------------------------------------------
574                                                            jai_constants.tax_type_exc_edu_cess, 6,
575                                                            jai_constants.tax_type_cvd_edu_cess , 6,
576                                                            jai_constants.tax_type_sh_exc_edu_cess, 6,
577                                                            jai_constants.tax_type_sh_cvd_edu_cess, 6,
578                                                            ---------------------------------------------------
579                                                            'TDS', 2, 0)) tax_type_val,
580               A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
581               A.Tax_Amount, A.currency curr, B.End_Date Valid_Date,
582               B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
583               , B.inclusive_tax_flag --Add by Kevin Cheng for inclusive tax Dec 18, 2007
584         FROM jai_rcv_line_taxes A,
585              JAI_CMN_TAXES_ALL B,
586              jai_regime_tax_types_v aa
587        WHERE shipment_line_id = p_line_id /* shipment line id */
588          AND A.Tax_Id = B.Tax_Id
589          AND aa.tax_type(+) = b.tax_type
590      ORDER BY 1;
591 
592      OPEN fetch_rcv_line_currency;
593      FETCH fetch_rcv_line_currency INTO lv_currency_code;
594      CLOSE fetch_rcv_line_currency;
595 
596    ELSIF p_type = 'ASBN' Then
597 
598      OPEN c_tax_cur FOR
599      SELECT A.Tax_Line_No LNo,  A.Precedence_1 P_1, A.Precedence_2 P_2,
600               A.Precedence_3 P_3, A.Precedence_4 P_4, A.precedence_5 P_5,
601               A.Precedence_6 P_6, A.Precedence_7 P_7,
602               A.Precedence_8 P_8, A.Precedence_9 P_9, A.precedence_10 P_10,
603               A.Tax_Id,
604               DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
605                                                                  'EXCISE', 1,
606                                                            'ADDL. EXCISE', 1,
607                                                            'OTHER EXCISE', 1,
608                                                            --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
609                                                            /*'Excise_Education_cess', 1,*/
610                                                            --Add by Kevin Cheng for inclusive tax Dec 18, 2007
611                                                            ---------------------------------------------------
612                                                            jai_constants.tax_type_exc_edu_cess, 6,
613                                                            jai_constants.tax_type_cvd_edu_cess , 6,
614                                                            jai_constants.tax_type_sh_exc_edu_cess, 6,
615                                                            jai_constants.tax_type_sh_cvd_edu_cess, 6,
616                                                            ---------------------------------------------------
617                                                            'TDS', 2, 0)) tax_type_val,
618               A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
619               A.Tax_Amt tax_amount, A.currency_code curr, B.End_Date Valid_Date,
620               B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
621               , B.inclusive_tax_flag --Add by Kevin Cheng for inclusive tax Dec 18, 2007
622         FROM Jai_cmn_document_Taxes A,
623              JAI_CMN_TAXES_ALL B,
624              jai_regime_tax_types_v aa
625        WHERE source_doc_line_id = p_line_id /* source doc line id */
626          AND A.Tax_Id = B.Tax_Id
627          AND aa.tax_type(+) = b.tax_type
628      ORDER BY 1;
629 
630   END IF;
631 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
632   IF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO', 'REQUISITION', 'RECEIPTS' , 'ASBN'  ) THEN
633 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
634   LOOP
635 
636     FETCH c_tax_cur INTO rec;
637     EXIT WHEN c_tax_cur%NOTFOUND;
638 
639       P1(rec.lno) := nvl(rec.p_1,-1);
640       P2(rec.lno) := nvl(rec.p_2,-1);
641       P3(rec.lno) := nvl(rec.p_3,-1);
642       P4(rec.lno) := nvl(rec.p_4,-1);
643       P5(rec.lno) := nvl(rec.p_5,-1);
644       -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
645       -- start bug#5228046
646       P6(rec.lno) := nvl(rec.p_6,-1);
647       P7(rec.lno) := nvl(rec.p_7,-1);
648       P8(rec.lno) := nvl(rec.p_8,-1);
649       P9(rec.lno) := nvl(rec.p_9,-1);
650       P10(rec.lno) := nvl(rec.p_10,-1);
651       -- end bug#5228046
652 
653       rnd_factor(rec.lno) := nvl(rec.rnd_factor,0);
654       Tax_Rate_Tab(rec.lno) := nvl(rec.Tax_Rate,0);
655       Tax_Type_Tab(rec.lno) := rec.tax_type_val;
656       adhoc_tab(rec.lno) := nvl(rec.adhoc_flag,'N'); -- added by subbu on 08-nov-01
657 
658       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
659       ----------------------------------------------------
660       lt_tax_rate_per_rupee(rec.lno)   := NVL(rec.tax_rate,0)/100;
661       ln_total_tax_per_rupee           := 0;
662       lt_inclu_tax_tab(rec.lno)        := NVL(rec.inclusive_tax_flag,'N');
663 
664       IF rec.tax_rate is null THEN
665         lt_tax_rate_zero_tab(rec.lno)  := 0;
666       ELSIF rec.tax_rate = 0 THEN
667         lt_tax_rate_zero_tab(rec.lno)  := -9999;
668       ELSE
669         lt_tax_rate_zero_tab(rec.lno)  := rec.tax_rate;
670       END IF;
671 
672       tax_amt_tab(rec.lno)             := 0;
673       lt_tax_amt_rate_tax_tab(rec.lno) := 0;
674       lt_tax_amt_non_rate_tab(rec.lno) := 0;
675       lt_base_tax_amt_tab(rec.lno)     := 0;
676       ----------------------------------------------------
677       IF nvl(rec.tax_rate,0) = 0 AND nvl(rec.qty_rate,0) = 0 and nvl(rec.adhoc_flag,'N') = 'Y' THEN
678       --Changed by Nagaraj.s for Bug2519359.
679 
680          /*
681          IF p_type='REQUISITION' Then
682       OPEN req_adhoc_tax_amt(rec.tax_id);
683       FETCH req_adhoc_tax_amt into v_adhoc_tax_amt;
684       CLOSE req_adhoc_tax_amt;
685          ELSE
686         v_adhoc_tax_amt := rec.tax_amount;
687          END IF;
688          */
689       v_adhoc_tax_amt := rec.tax_amount;
690 
691        -- cbabu for Bug# 3026084
692        -- tax_rate_tab(rec.lno) :=  -1;
693        tax_rate_tab(rec.lno) :=  -99999;
694 
695          /*Tax_Amt_Tab(rec.lno)  := v_adhoc_tax_amt;*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
696          tax_target_tab(rec.lno) := v_adhoc_tax_amt;
697         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
698         ---------------------------------------------------
699         lt_tax_amt_non_rate_tab(rec.lno) := nvl(v_adhoc_tax_amt, 0);   -- tax inclusive
700         lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
701         ---------------------------------------------------
702       ELSIF nvl(rec.tax_rate,0) = 0 AND nvl(rec.qty_rate,0) = 0 THEN
703 
704        -- cbabu for Bug# 3026084
705        -- tax_rate_tab(rec.lno) :=  -1;
706        tax_rate_tab(rec.lno) :=  -99999;
707 
708          /*Tax_Amt_Tab(rec.lno)  := rec.tax_amount;*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
709          tax_target_tab(rec.lno) := rec.tax_amount;
710          --Add by Kevin Cheng for inclusive tax Dec 18, 2007
711          ---------------------------------------------------
712          lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.tax_amount, 0);   -- tax inclusive
713          lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
714          ---------------------------------------------------
715       ELSE
716          Tax_Amt_Tab(rec.lno)  := 0;
717       END IF;
718 
719       Curr_Tab(rec.lno) := NVL( rec.curr, v_curr );
720       IF rec.Valid_Date is NULL Or rec.Valid_Date >= Sysdate THEN
721       End_Date_Tab(rec.lno) := 1;
722       ELSE
723       End_Date_Tab(rec.lno) := 0;
724       tax_amt_tab(rec.lno)  := 0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
725       END IF;
726       row_count := row_count + 1;
727 
728       IF tax_rate_tab(rec.lno) = 0 THEN
729 
730          FOR uom_cls IN uom_class_cur( nvl(p_line_uom_code, v_line_uom_code) , rec.uom_code) LOOP  -- -- 6/05/02 cbabu bug2357371, added nvl statement
731         INV_CONVERT.inv_um_conversion(nvl(p_line_uom_code, v_line_uom_code), rec.uom_code, p_inventory_item_id, v_conversion_rate);  -- 15/03/2002 cbabu, added nvl statement
732         IF nvl(v_conversion_rate, 0) <= 0 THEN
733           INV_CONVERT.inv_um_conversion(nvl(p_line_uom_code, v_line_uom_code), rec.uom_code, 0, v_conversion_rate); -- 6/05/02 cbabu bug2357371, added nvl statement
734           IF nvl(v_conversion_rate, 0) <= 0  THEN
735              v_conversion_rate := 0;
736           END IF;
737        END IF;
738        --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
739        --tax_amt_tab(rec.lno) := ROUND( nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity, rnd_factor(rec.lno) );
740 
741          -- cbabu for Bug# 3026084
742          -- tax_rate_tab(rec.lno) :=  -1;
743          tax_rate_tab(rec.lno) :=  -99999;
744 
745            --tax_target_tab(rec.lno) := tax_amt_tab( rec.lno ); --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
746            -- tax_rate_tab(rec.lno) :=  TRUNC( nvl(rec.qty_rate * p_line_quantity, 0 ), 2 );
747           --Add by Kevin Cheng for inclusive tax Dec 18, 2007
748           ---------------------------------------------------
749           lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
750           lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno);
751           tax_target_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno);
752           ---------------------------------------------------
753         END LOOP;
754      END IF;
755   END LOOP;
756 
757   CLOSE c_tax_cur;  -- Vijay Shankar for Bug# 3190782
758 
759   END IF;
760 
761   --Add by Kevin Cheng for inclusive tax Dec 18, 2007
762   -----------------------------------------------------
763   IF p_vat_assess_value <> p_price THEN
764     ln_vat_assessable_value := p_vat_assess_value;
765   ELSE
766     ln_vat_assessable_value := 1;
767   END IF;
768 
769   if p_assessable_value <> p_price THEN
770     ln_assessable_value := p_assessable_value;
771   ELSE
772     ln_assessable_value := 1;
773   END IF;
774   -----------------------------------------------------
775     bsln_amt := p_price;
776 
777    FOR I in 1..row_count
778     LOOP
779       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
780       ---------------------------------------------------
781       IF end_date_tab(I) <> 0
782       THEN
783       ---------------------------------------------------
784       IF tax_type_tab(i) = 1 THEN
785         --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
786          --bsln_amt := NVL( p_assessable_value, p_price );
787         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
788         ---------------------------------------------------
789         IF ln_assessable_value = 1 THEN
790           bsln_amt := 1;
791           ln_bsln_amt_nr := 0;
792         ELSE
793           bsln_amt := 0;
794           ln_bsln_amt_nr := ln_assessable_value;
795         END IF;
796         ---------------------------------------------------
797       ELSIF tax_type_tab(i) = 4 THEN             -- Ravi for VAT
798         --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
799          --bsln_amt := NVL( p_vat_assess_value, p_price );
800       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
801       ---------------------------------------------------
802         IF ln_vat_assessable_value = 1 THEN
803           bsln_amt := 1;
804 		      ln_bsln_amt_nr := 0;
805         ELSE
806           bsln_amt := 0;
807           ln_bsln_amt_nr := ln_vat_assessable_value;
808         END IF;
809       ELSIF tax_type_tab(I) = 6 THEN  --IF tax_type_tab(I) = 1   THEN
810         bsln_amt := 0;
811         ln_bsln_amt_nr := 0;
812       ELSE --IF tax_type_tab(I) = 1   THEN
813         bsln_amt := 1;
814         ln_bsln_amt_nr := 0;
815       END IF; --IF tax_type_tab(I) = 1   THEN
816       ---------------------------------------------------
817       /*ELSE
818          bsln_amt := p_price;
819       END IF;*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
820 
821       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
822       ---------------------------------------------------
823       IF tax_rate_tab(I) <> 0
824       THEN
825       ---------------------------------------------------
826       IF p1(I) < I and p1(I) not in (-1,0) then
827          vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
828         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P1(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
829       ELSIF p1(I) = 0 then
830          vamt  := vamt + bsln_amt;
831 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
832       END IF;
833       IF p2(I) < I and p2(I) not in (-1,0) then
834          vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
835         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P2(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
836 
837       ELSIF p2(I) = 0 then
838          vamt  := vamt + bsln_amt;
839 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
840       END IF;
841       IF p3(I) < I and p3(I) not in (-1,0) then
842          vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
843         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P3(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
844 
845       ELSIF p3(I) = 0 then
846          vamt  := vamt + bsln_amt;
847 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
848       END IF;
849       IF p4(I) < I and p4(I) not in (-1,0) then
850          vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
851         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P4(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
852 
853       ELSIF p4(I) = 0 then
854          vamt  := vamt + bsln_amt;
855 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
856       END IF;
857       IF p5(I) < I and p5(I) not in (-1,0) then
858          vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
859         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P5(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
860       ELSIF p5(I) = 0 then
861          vamt  := vamt + bsln_amt;
862 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
863       END IF;
864 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
865 -- START BUG 5228046
866 
867       IF p6(I) < I and p6(I) not in (-1,0) then
868          vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
869         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P6(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
870       ELSIF p6(I) = 0 then
871          vamt  := vamt + bsln_amt;
872 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
873       END IF;
874       IF p7(I) < I and p7(I) not in (-1,0) then
875          vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
876         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P7(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
877       ELSIF p7(I) = 0 then
878          vamt  := vamt + bsln_amt;
879 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
880       END IF;
881       IF p8(I) < I and p8(I) not in (-1,0) then
882          vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
883         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P8(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
884       ELSIF p8(I) = 0 then
885          vamt  := vamt + bsln_amt;
886 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
887       END IF;
888       IF p9(I) < I and p9(I) not in (-1,0) then
889          vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
890         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P9(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
891       ELSIF p9(I) = 0 then
892          vamt  := vamt + bsln_amt;
893 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
894       END IF;
895       IF p10(I) < I and p10(I) not in (-1,0) then
896          vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
897         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P10(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
898       ELSIF p10(I) = 0 then
899          vamt  := vamt + bsln_amt;
900 		     ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
901       END IF;
902 -- END BUG 5228046
903 
904      -- cbabu for Bug# 3026084
905        -- IF tax_rate_tab(I) <> -1 THEN
906        IF tax_rate_tab(I) <> -99999 THEN
907          v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
908          IF END_date_tab(I) = 0 then
909             tax_amt_tab(I) := 0;
910          ELSIF END_date_tab(I) = 1 then
911             tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
912          END IF;
913        ELSE --added by subbu on 7-nov-01
914          tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + nvl(v_tax_amt,0);
915        END IF;
916       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
917       ---------------------------------------------------
918       ln_tax_amt_nr := ln_tax_amt_nr + (ln_vamt_nr * (tax_rate_tab(I)/100));
919       lt_base_tax_amt_tab(I) := vamt;
920       lt_tax_amt_non_rate_tab(I) := NVL(lt_tax_amt_non_rate_tab(I),0) + ln_tax_amt_nr; -- tax inclusive
921       lt_tax_amt_rate_tax_tab(i) := tax_amt_tab(I);
922 
923       ln_tax_amt_nr := 0;
924       ln_vamt_nr := 0;
925       ---------------------------------------------------
926 
927       vamt      := 0;
928       v_tax_amt := 0;
929     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
930     ---------------------------------------------------
931       END IF; --IF tax_rate_tab(I) <> 0 THEN
932     ELSE --IF end_date_tab(I) <> 0 THEN
933       tax_amt_tab(I) := 0;
934       lt_base_tax_amt_tab(I) := 0;
935     END IF; --IF end_date_tab(I) <> 0 THEN
936     ---------------------------------------------------
937      END LOOP;
938 
939     FOR I in 1..row_count
940     LOOP
941       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
942       ---------------------------------------------------
943       IF end_date_tab( I ) <> 0 THEN
944       IF tax_rate_tab(I) <> 0 THEN
945       ---------------------------------------------------
946       IF p1(I) > I then
947          vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
948 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P1(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
949       END IF;
950       IF p2(I) > I  then
951          vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
952 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P2(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
953       END IF;
954       IF p3(I) > I  then
955          vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
956 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P3(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
957       END IF;
958       IF p4(I) > I then
959          vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
960 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P4(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
961       END IF;
962       IF p5(I) > I then
963          vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
964 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P5(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
965       END IF;
966 
967 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
968 -- START BUG 5228046
969 
970       IF p6(I) > I then
971          vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
972 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P6(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
973       END IF;
974       IF p7(I) > I  then
975          vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
976 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P7(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
977       END IF;
978       IF p8(I) > I  then
979          vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
980 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P8(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
981       END IF;
982       IF p9(I) > I then
983          vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
984 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P9(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
985       END IF;
986       IF p10(I) > I then
987          vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
988 		     ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P10(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
989       END IF;
990 -- END BUG 5228046
991 
992        -- cbabu for Bug# 3026084
993        -- IF tax_rate_tab(I) <> -1 THEN
994        IF tax_rate_tab(I) <> -99999 THEN
995          v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
996          IF END_date_tab(I) = 0 then
997             tax_amt_tab(I) := 0;
998          ELSIF END_date_tab(I) = 1 then
999             tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + nvl(v_tax_amt,0);
1000          END IF;
1001        ELSE -- added by subbu on 07-nov-01
1002           tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + nvl(v_tax_amt,0);
1003        END IF;
1004 
1005       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1006       ---------------------------------------------------
1007       lt_base_tax_amt_tab(I) := vamt;
1008       ln_tax_amt_nr := ln_tax_amt_nr + (ln_vamt_nr * (tax_rate_tab(I)/100)); -- tax inclusive
1009       IF vamt <> 0 THEN
1010         lt_base_tax_amt_tab(I) := lt_base_tax_amt_tab(I) + vamt;
1011       END IF;
1012       lt_tax_amt_non_rate_tab(I) := NVL(lt_tax_amt_non_rate_tab(I),0) + ln_tax_amt_nr ; -- tax inclusive
1013       lt_tax_amt_rate_tax_tab(i) := tax_amt_tab(I);
1014       ln_vamt_nr := 0 ;
1015       ln_tax_amt_nr := 0 ;
1016       ---------------------------------------------------
1017 
1018       vamt      := 0;
1019       v_tax_amt := 0;
1020     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1021     ---------------------------------------------------
1022       END IF; --IF tax_rate_tab(I) <> 0 THEN
1023 
1024     ELSE --IF end_date_tab( I ) <> 0 THEN
1025       lt_base_tax_amt_tab(I) := vamt;
1026       tax_amt_tab(I) := 0;
1027     END IF; --IF end_date_tab( I ) <> 0 THEN
1028     ---------------------------------------------------
1029     END LOOP;
1030 
1031     FOR counter IN 1 .. max_iter LOOP
1032       vamt := 0;
1033       v_tax_amt := 0;
1034       ln_vamt_nr:= 0;   --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1035       ln_tax_amt_nr:=0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1036 
1037       FOR i IN 1 .. row_count LOOP
1038         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1039         IF ( tax_rate_tab( i ) <> 0 OR lt_tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
1040 
1041   /*      IF tax_rate_tab( i ) > 0 AND End_Date_Tab(I) <> 0 THEN  Commented by Satya / Subbu on 09-Oct-01    */
1042 
1043   /*  Added by Satya / subbu on 09-Oct-01 for calculating the Negative Tax */
1044 
1045         IF tax_rate_tab( i ) <> 0 AND End_Date_Tab(I) <> 0  AND adhoc_tab(i) <> 'Y' THEN
1046   -- added extra condition AND adhoc_tab(i) <> 'Y' by subbu on 8-nov-01 for adhoc taxes
1047             IF tax_type_tab( i ) = 1 THEN
1048                --v_amt := NVL( p_assessable_value, p_price );--Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
1049               --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1050               ------------------------------------------------
1051               IF ln_assessable_value =1
1052               THEN
1053                 v_amt:=1;
1054                 ln_bsln_amt_nr :=0;
1055               ELSE
1056                 v_amt :=0;
1057                 ln_bsln_amt_nr :=ln_assessable_value;
1058               END IF;
1059               ------------------------------------------------
1060             ELSIF tax_type_tab(i) = 4 THEN     -- Ravi for VAT
1061                --v_amt := NVL( p_vat_assess_value, p_price );--Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
1062             --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1063             ---------------------------------------------------
1064               IF ln_vat_assessable_value =1
1065               THEN
1066                 v_amt:=1;
1067                 ln_bsln_amt_nr :=0;
1068               ELSE
1069                 v_amt :=0;
1070                 ln_bsln_amt_nr :=ln_vat_assessable_value;
1071               END IF;
1072             ELSIF tax_type_tab(I) = 6 THEN
1073               v_amt:=0;
1074               ln_bsln_amt_nr :=0;
1075             ---------------------------------------------------
1076             ELSIF v_amt = 0 OR tax_type_tab(i) <> 1 THEN
1077                --v_amt := p_price;--Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
1078                --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1079                ---------------------------------------------------
1080                vamt := 1;
1081                ln_bsln_amt_nr := 0;
1082                ---------------------------------------------------
1083             END IF;
1084      IF p1( i ) <> -1 THEN
1085         IF p1( i ) <> 0 THEN
1086              vamt := vamt + tax_amt_tab( p1( I ) );
1087 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P1(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1088         ELSIF p1(i) = 0 THEN
1089            vamt := vamt + v_amt;
1090 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1091         END IF;
1092      END IF;
1093            IF p2( i ) <> -1 THEN
1094         IF p2( i ) <> 0 THEN
1095              vamt := vamt + tax_amt_tab( p2( I ) );
1096 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P2(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1097         ELSIF p2(i) = 0 THEN
1098            vamt := vamt + v_amt;
1099 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1100         END IF;
1101      END IF;
1102            IF p3( i ) <> -1 THEN
1103         IF p3( i ) <> 0 THEN
1104              vamt := vamt + tax_amt_tab( p3( I ) );
1105 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P3(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1106         ELSIF p3(i) = 0 THEN
1107            vamt := vamt + v_amt;
1108 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1109         END IF;
1110      END IF;
1111            IF p4( i ) <> -1 THEN
1112         IF p4( i ) <> 0 THEN
1113              vamt := vamt + tax_amt_tab( p4( i ) );
1114 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P4(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1115         ELSIF p4(i) = 0 THEN
1116            vamt := vamt + v_amt;
1117 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1118         END IF;
1119      END IF;
1120            IF p5( i ) <> -1 THEN
1121         IF p5( i ) <> 0 THEN
1122              vamt := vamt + tax_amt_tab( p5( i ) );
1123 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P5(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1124         ELSIF p5(i) = 0 THEN
1125            vamt := vamt + v_amt;
1126 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1127         END IF;
1128      END IF;
1129 
1130 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
1131 -- START BUG 5228046
1132        IF p6( i ) <> -1 THEN
1133         IF p6( i ) <> 0 THEN
1134              vamt := vamt + tax_amt_tab( p6( I ) );
1135 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P6(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1136         ELSIF p6(i) = 0 THEN
1137            vamt := vamt + v_amt;
1138 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1139         END IF;
1140      END IF;
1141 
1142     IF p7( i ) <> -1 THEN
1143         IF p7( i ) <> 0 THEN
1144              vamt := vamt + tax_amt_tab( p7( I ) );
1145 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P7(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1146         ELSIF p7(i) = 0 THEN
1147            vamt := vamt + v_amt;
1148 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1149         END IF;
1150      END IF;
1151 
1152      IF p8( i ) <> -1 THEN
1153         IF p8( i ) <> 0 THEN
1154              vamt := vamt + tax_amt_tab( p8( I ) );
1155 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P8(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1156         ELSIF p8(i) = 0 THEN
1157            vamt := vamt + v_amt;
1158 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1159         END IF;
1160      END IF;
1161 
1162      IF p9( i ) <> -1 THEN
1163         IF p9( i ) <> 0 THEN
1164              vamt := vamt + tax_amt_tab( p9( i ) );
1165 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P9(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1166         ELSIF p9(i) = 0 THEN
1167            vamt := vamt + v_amt;
1168 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1169         END IF;
1170      END IF;
1171 
1172      IF p10( i ) <> -1 THEN
1173         IF p10( i ) <> 0 THEN
1174              vamt := vamt + tax_amt_tab( p10( i ) );
1175 		         ln_vamt_nr:=ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P10(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1176         ELSIF p10(i) = 0 THEN
1177            vamt := vamt + v_amt;
1178 		       ln_vamt_nr:=ln_vamt_nr+ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1179         END IF;
1180      END IF;
1181 -- END BUG 5228046
1182 
1183   tax_target_tab(I) := vamt;
1184   --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1185   ---------------------------------------------------
1186   lt_base_tax_amt_tab(I) := vamt;
1187   ln_tax_amt_nr:=ln_tax_amt_nr+(ln_vamt_nr*(tax_rate_tab(i)/100));
1188   lt_func_tax_amt_tab(I) := v_tax_amt +  ( vamt * ( tax_rate_tab( i )/100));
1189   ---------------------------------------------------
1190         IF counter = max_iter THEN --AND tax_type_tab( I ) IN ( 1, 2 ) THEN
1191             -- cbabu for Bug# 3026084
1192             -- IF tax_rate_tab(I) <> -1 THEN    -- 5/3/2002 cbabu
1193             IF tax_rate_tab(I) <> -99999 THEN
1194               --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
1195               /*v_tax_amt := ROUND( v_tax_amt + ( vamt * ( tax_rate_tab( i )/100)), rnd_factor(I) );*/
1196               --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1197               v_tax_amt := v_tax_amt + ( vamt * ( tax_rate_tab( i )/100));
1198             ELSE
1199               --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
1200               /*v_tax_amt := ROUND( tax_amt_tab( I ), rnd_factor(I) ); --  5/3/2002 cbabu*/
1201               --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1202               v_tax_amt := tax_amt_tab( I ); --  5/3/2002 cbabu
1203             END IF;
1204           /*ELSIF counter = max_iter AND tax_type_tab( I ) NOT IN ( 1, 2 ) THEN
1205              v_tax_amt := ROUND( v_tax_amt + ( vamt * ( tax_rate_tab( i )/100)), 2 );
1206             */
1207         ELSE
1208             -- cbabu for Bug# 3026084
1209             -- IF tax_rate_tab(I) <> -1 THEN -- 5/3/2002 cbabu
1210             IF tax_rate_tab(I) <> -99999 THEN
1211               v_tax_amt := v_tax_amt + ( vamt * ( tax_rate_tab( i )/100));
1212             ELSE
1213               v_tax_amt := tax_amt_tab( I ); -- 5/3/2002 cbabu
1214             END IF;
1215         END IF;
1216         tax_amt_tab( I ) := NVL( v_tax_amt, 0 );
1217         --cbabu for Bug# 3026084
1218         ELSIF tax_rate_tab( i ) = -99999 AND End_Date_Tab(I) <> 0  THEN
1219           --NULL; --Comment out by Kevin Cheng for bug 6849952 Feb 29, 2008
1220           ln_tax_amt_nr:=lt_tax_amt_non_rate_tab(i);  --Add by Kevin Cheng for bug 6849952 Feb 29, 2008
1221         ELSE
1222           tax_amt_tab(I) := 0;
1223           tax_target_tab(I) := 0;
1224         END IF;
1225 
1226       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1227       ---------------------------------------------------
1228       ELSIF tax_rate_tab(I) = 0 THEN --IF ( tax_rate_tab( i ) <> 0 OR tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
1229         lt_base_tax_amt_tab(I) := tax_amt_tab(i);
1230         v_tax_amt := tax_amt_tab( i );
1231         ln_tax_amt_nr:=lt_tax_amt_non_rate_tab(i);
1232         tax_target_tab(I) := v_tax_amt;
1233       ELSIF end_date_tab( I ) = 0 THEN --IF ( tax_rate_tab( i ) <> 0 OR tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
1234         tax_amt_tab(I) := 0;
1235         lt_base_tax_amt_tab(I) := 0;
1236         tax_target_tab(I) := 0;
1237       END IF; --IF ( tax_rate_tab( i ) <> 0 OR tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
1238       lt_tax_amt_non_rate_tab(I):=ln_tax_amt_nr;
1239       ---------------------------------------------------
1240 
1241         IF counter = max_iter THEN
1242           IF END_date_tab(I) = 0 THEN
1243             tax_amt_tab(I) := 0;
1244             lt_func_tax_amt_tab(i) := 0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1245           END IF;
1246         END IF;
1247         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
1248         ---------------------------------------------------
1249         ln_func_tax_amt := 0;
1250         ln_vamt_nr :=0;
1251         ln_tax_amt_nr:=0;
1252         ---------------------------------------------------
1253         vamt := 0;
1254         v_amt := 0;
1255         v_tax_amt := 0;
1256 
1257       END LOOP;
1258     END LOOP;
1259 
1260     --Add by Kevin for inclusive tax Dec 18, 2007
1261     ---------------------------------------------------------------------------------------
1262     FOR I IN 1 .. ROW_COUNT --Compute Factor
1263     LOOP
1264       IF lt_inclu_tax_tab(I) = 'Y'
1265       THEN
1266         ln_total_tax_per_rupee := ln_total_tax_per_rupee + nvl(lt_tax_amt_rate_tax_tab(I),0) ;
1267 	      ln_total_non_rate_tax := ln_total_non_rate_tax + nvl(lt_tax_amt_non_rate_tab(I),0);
1268       END IF; --IF lt_inclu_tax_tab(I) = 'Y'
1269     END LOOP; --FOR I IN 1 .. ROW_COUNT --Compute Factor
1270 
1271     ln_total_tax_per_rupee := ln_total_tax_per_rupee + 1;
1272 
1273     IF ln_total_tax_per_rupee <> 0
1274     THEN
1275       ln_exclusive_price := (NVL(p_price,0)  -  ln_total_non_rate_tax ) / ln_total_tax_per_rupee;
1276     END IF; --IF ln_total_tax_per_rupee <> 0
1277 
1278     /*
1279      EXPLANATION :
1280      -------------
1281     this loop typically would have an insert /update in the tax tables to insert/update tax amounts
1282     */
1283 
1284     FOR i in 1 .. row_count  --Compute Tax Amount
1285     LOOP
1286        tax_amt_tab (i) := (lt_tax_amt_rate_tax_tab(I) * ln_exclusive_price ) + lt_tax_amt_non_rate_tab(I);
1287        tax_amt_tab(I) :=  round(tax_amt_tab(I)  ,rnd_factor(I));
1288     END LOOP; --FOR i in 1 .. row_count
1289     --------------------------------------------------------------------------------------------------------
1290   --Added by Kevin Cheng for Retroactive Price 2008/01/10
1291 --==========================================================================================================
1292   ELSIF pv_retroprice_changed = 'Y'
1293   THEN
1294     debug           :=  'Y';
1295     bsln_amt        :=  p_tax_amount;
1296     row_count       :=  0;
1297     v_tax_amt       :=  0;
1298     vamt            :=  0;
1299     max_iter        :=  15; -- bug 5228046. Changed from 10 to 15
1300     v_curr          :=  p_line_uom_code;
1301     v_line_uom_code :=  p_line_uom_code;
1302 
1303   IF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO' ) THEN -- Vijay Shankar for Bug# 3190782
1304 
1305     IF p_item_id IS NULL THEN
1306        OPEN  Fetch_Item_Cur;
1307        FETCH Fetch_Item_Cur INTO p_inventory_item_id;
1308        CLOSE Fetch_Item_Cur;
1309     ELSE
1310        p_inventory_item_id := p_item_id;
1311     END IF;
1312 
1313   --start 6/05/02 cbabu bug2357371
1314     IF p_line_uom_code IS NULL THEN
1315        OPEN  Fetch_line_uom_code;
1316        FETCH Fetch_line_uom_code INTO v_line_uom_code;
1317        CLOSE Fetch_line_uom_code;
1318     END IF;
1319   --end 6/05/02 cbabu bug2357371
1320 
1321   END IF;   -- Vijay Shankar for Bug# 3190782
1322 
1323   IF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO' ) THEN
1324 
1325           /* Added by LGOPALSA. Bug 4210102.
1326      * Added CVD and Excise Education Cess
1327      * */
1328      OPEN c_tax_retro_cur FOR
1329      SELECT A.Tax_Line_No LNo,
1330             A.Precedence_1 P_1,
1331       A.Precedence_2 P_2,
1332             A.Precedence_3 P_3,
1333       A.Precedence_4 P_4,
1334       A.precedence_5 P_5,
1335             A.Precedence_6 P_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
1336       A.Precedence_7 P_7,
1337             A.Precedence_8 P_8,
1338       A.Precedence_9 P_9,
1339       A.precedence_10 P_10,
1340             A.Tax_Id,
1341             DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
1342                                                                'EXCISE', 1,
1343                                                          'ADDL. EXCISE', 1,
1344                                                          'OTHER EXCISE', 1,
1345                                     jai_constants.tax_type_exc_edu_cess, 1,
1346                                     jai_constants.tax_type_sh_exc_edu_cess, 1,--Added by kunkumar for bugno5989740
1347                                                                   'TDS', 2, 0)) tax_type_val,
1348             A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
1349             A.Tax_Amount, A.currency curr, B.End_Date Valid_Date,
1350             B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
1351             , pha.vendor_id hdr_vendor_id, A.Vendor_Id tax_vendor_id --Added by Kevin Cheng
1352       FROM JAI_PO_TAXES A, JAI_CMN_TAXES_ALL B,jai_regime_tax_types_v aa
1353            , po_headers_all pha  --Added by Kevin Cheng
1354      WHERE Po_Line_Id = p_line_id
1355        AND Line_Location_Id = p_line_loc_id
1356        --AND NVL( Line_Location_Id, -999 ) = p_line_loc_id /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
1357        AND A.Tax_Id = B.Tax_Id
1358        AND pha.po_header_id = A.Po_Header_Id --Added by Kevin Cheng
1359        AND aa.tax_type(+) = b.tax_type
1360      ORDER BY 1;
1361 
1362      --- Cursor changed by ravi for getting the vat related taxes.
1363 
1364 --Comment by Kevin Cheng
1365   /*ELSIF p_type = 'REQUISITION' THEN
1366 
1367           \* added by LGOPALSA. Bug 4210102.
1368      * Added Excise and CVD Education Cess *\
1369     OPEN c_tax_retro_cur FOR
1370     SELECT A.Tax_Line_No LNo,
1371            A.Precedence_1 P_1,
1372      A.Precedence_2 P_2,
1373            A.Precedence_3 P_3,
1374      A.Precedence_4 P_4,
1375      A.precedence_5 P_5,
1376            A.Precedence_6 P_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
1377      A.Precedence_7 P_7,
1378            A.Precedence_8 P_8,
1379      A.Precedence_9 P_9,
1380      A.precedence_10 P_10,
1381            A.Tax_Id,
1382            DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
1383                                                               'EXCISE', 1,
1384                                                         'ADDL. EXCISE', 1,
1385                                                         'OTHER EXCISE', 1,
1386                                    jai_constants.tax_type_exc_edu_cess, 1,
1387                                    jai_constants.tax_type_sh_exc_edu_cess, 1,--Added by kunkumar for bugno 5989740
1388 
1389    'TDS', 2, 0)) tax_type_val,
1390            A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
1391            A.Tax_Amount, A.currency curr, B.End_Date Valid_Date,
1392            B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
1393      FROM JAI_PO_REQ_LINE_TAXES A,
1394           JAI_CMN_TAXES_ALL B,
1395           jai_regime_tax_types_v aa
1396     WHERE requisition_line_Id = p_line_id
1397       AND A.Tax_Id = B.Tax_Id
1398       AND aa.tax_type(+) = b.tax_type
1399 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
1400    ORDER BY 1;
1401 */
1402    /* added by ssumaith for receipts tax recalculation .*/
1403    ELSIF p_type = 'RECEIPTS' THEN
1404 
1405      OPEN c_tax_retro_cur FOR
1406      SELECT A.Tax_Line_No LNo,  A.Precedence_1 P_1, A.Precedence_2 P_2,
1407               A.Precedence_3 P_3, A.Precedence_4 P_4, A.precedence_5 P_5,
1408               A.Precedence_6 P_6, A.Precedence_7 P_7,
1409               A.Precedence_8 P_8, A.Precedence_9 P_9, A.precedence_10 P_10,
1410               A.Tax_Id,
1411               DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
1412                                                                  'EXCISE', 1,
1413                                                            'ADDL. EXCISE', 1,
1414                                                            'OTHER EXCISE', 1,
1415                                                            'Excise_Education_cess', 1,
1416                                                            'TDS', 2, 0)) tax_type_val,
1417               A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
1418               A.Tax_Amount, A.currency curr, B.End_Date Valid_Date,
1419               B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
1420               , rsh.vendor_id hdr_vendor_id, A.Vendor_Id tax_vendor_id --Added by Kevin Cheng
1421         FROM jai_rcv_line_taxes A,
1422              JAI_CMN_TAXES_ALL B,
1423              jai_regime_tax_types_v aa,
1424              RCV_SHIPMENT_HEADERS rsh --Added by Kevin Cheng
1425        WHERE shipment_line_id = p_line_id /* shipment line id */
1426          AND A.Tax_Id = B.Tax_Id
1427          AND rsh.shipment_header_id = A.SHIPMENT_HEADER_ID --Added by Kevin Cheng
1428          AND aa.tax_type(+) = b.tax_type
1429      ORDER BY 1;
1430 
1431      OPEN fetch_rcv_line_currency;
1432      FETCH fetch_rcv_line_currency INTO lv_currency_code;
1433      CLOSE fetch_rcv_line_currency;
1434 --Comment out by Kevin Cheng
1435    /*ELSIF p_type = 'ASBN' Then
1436 
1437      OPEN c_tax_retro_cur FOR
1438      SELECT A.Tax_Line_No LNo,  A.Precedence_1 P_1, A.Precedence_2 P_2,
1439               A.Precedence_3 P_3, A.Precedence_4 P_4, A.precedence_5 P_5,
1440               A.Precedence_6 P_6, A.Precedence_7 P_7,
1441               A.Precedence_8 P_8, A.Precedence_9 P_9, A.precedence_10 P_10,
1442               A.Tax_Id,
1443               DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
1444                                                                  'EXCISE', 1,
1445                                                            'ADDL. EXCISE', 1,
1446                                                            'OTHER EXCISE', 1,
1447                                                            'Excise_Education_cess', 1,
1448                                                            'TDS', 2, 0)) tax_type_val,
1449               A.Tax_Rate tax_rate, A.Qty_Rate Qty_Rate, A.uom uom_code,
1450               A.Tax_Amt tax_amount, A.currency_code curr, B.End_Date Valid_Date,
1451               B.rounding_factor rnd_factor, B.adhoc_flag adhoc_flag
1452         FROM Jai_cmn_document_Taxes A,
1453              JAI_CMN_TAXES_ALL B,
1454              jai_regime_tax_types_v aa
1455        WHERE source_doc_line_id = p_line_id \* source doc line id *\
1456          AND A.Tax_Id = B.Tax_Id
1457          AND aa.tax_type(+) = b.tax_type
1458      ORDER BY 1;
1459 */
1460   END IF;
1461 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
1462   IF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO', 'REQUISITION', 'RECEIPTS' , 'ASBN'  ) THEN
1463 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
1464   LOOP
1465 
1466     FETCH c_tax_retro_cur INTO rec_retro;
1467     EXIT WHEN c_tax_retro_cur%NOTFOUND;
1468 
1469       P1(rec_retro.lno) := nvl(rec_retro.p_1,-1);
1470       P2(rec_retro.lno) := nvl(rec_retro.p_2,-1);
1471       P3(rec_retro.lno) := nvl(rec_retro.p_3,-1);
1472       P4(rec_retro.lno) := nvl(rec_retro.p_4,-1);
1473       P5(rec_retro.lno) := nvl(rec_retro.p_5,-1);
1474       -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Prec_retroedence 6 to 10 )
1475       -- start bug#5228046
1476       P6(rec_retro.lno) := nvl(rec_retro.p_6,-1);
1477       P7(rec_retro.lno) := nvl(rec_retro.p_7,-1);
1478       P8(rec_retro.lno) := nvl(rec_retro.p_8,-1);
1479       P9(rec_retro.lno) := nvl(rec_retro.p_9,-1);
1480       P10(rec_retro.lno) := nvl(rec_retro.p_10,-1);
1481       -- end bug#5228046
1482 
1483       rnd_factor(rec_retro.lno) := nvl(rec_retro.rnd_factor,0);
1484       Tax_Rate_Tab(rec_retro.lno) := nvl(rec_retro.Tax_Rate,0);
1485       Tax_Type_Tab(rec_retro.lno) := rec_retro.tax_type_val;
1486       --Comment out by Kevin Cheng
1487       --adhoc_tab(rec_retro.lno) := nvl(rec_retro.adhoc_flag,'N'); -- added by subbu on 08-nov-01
1488 
1489       --Added by Kevin Cheng -- for remain unchanged taxes
1490   --1, Ad hoc taxes
1491   --2, UOM based taxes
1492   --3, Assessable value base taxes (Excise/VAT)
1493   --4, Third party taxes
1494   --=================================================================================
1495   IF NVL(rec_retro.adhoc_flag,'N') = 'Y' --Ad hoc
1496   THEN
1497     lv_tax_remain_flag := 'Y';
1498   ELSIF tax_rate_tab(rec_retro.lno) = 0 AND rec_retro.uom_code IS NOT NULL --UOM based
1499   THEN
1500     lv_tax_remain_flag := 'Y';
1501   ELSIF rec_retro.tax_type_val = 1 AND p_assessable_value <> p_price --Excise assessable value based
1502   THEN
1503      lv_tax_remain_flag := 'Y';
1504   ELSIF rec_retro.tax_type_val = 4 AND p_vat_assess_value <> p_price --VAT assessable value based
1505   THEN
1506     lv_tax_remain_flag := 'Y';
1507   ELSIF rec_retro.hdr_vendor_id <> rec_retro.tax_vendor_id --Third party
1508   THEN
1509     lv_tax_remain_flag := 'Y';
1510   ELSE
1511     lv_tax_remain_flag := 'N';
1512   END IF;
1513 
1514   IF lv_tax_remain_flag = 'Y'
1515   THEN
1516     IF pv_called_from = 'RETROACTIVE'
1517     THEN
1518       SELECT
1519         original_tax_amount
1520       INTO
1521         tax_amt_tab(rec_retro.lno)
1522       FROM
1523         Jai_Retro_Tax_Changes jrtc
1524       WHERE jrtc.tax_id = rec_retro.tax_id
1525         AND jrtc.line_change_id = (SELECT
1526                                      jrlc.line_change_id
1527                                    FROM
1528                                      Jai_Retro_Line_Changes jrlc
1529                                    WHERE jrlc.doc_header_id = p_header_id
1530                                      AND jrlc.doc_line_id = P_line_id
1531                                      AND jrlc.doc_type = 'RECEIPT'
1532                                      AND jrlc.doc_version_number = (SELECT
1533                                                                       MAX(jrlc1.doc_version_number)
1534                                                                     FROM
1535                                                                       Jai_Retro_Line_Changes jrlc1
1536                                                                     WHERE jrlc1.doc_header_id = p_header_id
1537                                                                       AND jrlc1.doc_line_id = P_line_id
1538                                                                       AND jrlc1.doc_type = 'RECEIPT'
1539                                                                    )
1540                                   );
1541     ELSE
1542       SELECT
1543         original_tax_amount
1544       INTO
1545         tax_amt_tab(rec_retro.lno)
1546       FROM
1547         Jai_Retro_Tax_Changes jrtc
1548       WHERE jrtc.tax_id = rec_retro.tax_id
1549         AND jrtc.line_change_id = (SELECT
1550                                      line_change_id
1551                                    FROM
1552                                      Jai_Retro_Line_Changes jrlc
1553                                    WHERE jrlc.line_location_id = p_line_loc_id
1554                                      AND jrlc.doc_line_id = p_line_id
1555                                      AND jrlc.doc_type IN ( 'RELEASE'
1556                                                           , 'STANDARD PO'
1557                                                           )
1558                                      AND jrlc.doc_version_number = (SELECT
1559                                                                       MAX(jrlc1.doc_version_number)
1560                                                                     FROM
1561                                                                       Jai_Retro_Line_Changes jrlc1
1562                                                                     WHERE jrlc1.line_location_id = p_line_loc_id
1563                                                                       AND jrlc1.doc_line_id = p_line_id
1564                                                                       AND jrlc1.doc_type IN ( 'RELEASE'
1565                                                                                             , 'STANDARD PO'
1566                                                                                             )
1567                                                                    )
1568                                   );
1569     END IF;
1570 
1571     tax_rate_tab(rec_retro.lno)      := -99999;
1572     tax_target_tab(rec_retro.lno)    := rec_retro.tax_amount;
1573     adhoc_tab(rec_retro.lno)    := 'Y';
1574 
1575   ELSIF lv_tax_remain_flag = 'N'
1576   THEN
1577     tax_amt_tab(rec_retro.lno)   := 0;
1578     adhoc_tab(rec_retro.lno):= nvl(rec_retro.adhoc_flag,'N'); -- added by subbu on 08-nov-01
1579   END IF;
1580 
1581   --Add by Eric Ma for Retro active Pricing Update Jan 11, 2008,Begin
1582   --------------------------------------------------------------------------
1583   IF (pv_called_from = 'RETROACTIVE' )
1584   THEN
1585     OPEN  get_rcv_line_for_retro ( pn_tax_id => rec_retro.tax_id);
1586     FETCH get_rcv_line_for_retro
1587     INTO
1588       lv_tax_type
1589     , lv_third_party_flag;
1590     CLOSE get_rcv_line_for_retro;
1591 
1592   	IF( lv_tax_type IN
1593         ( JAI_CONSTANTS.tax_type_customs
1594         , JAI_CONSTANTS.tax_type_customs_edu_cess
1595         , JAI_CONSTANTS.tax_type_sh_customs_edu_Cess
1596         , JAI_CONSTANTS.tax_type_cvd
1597         , JAI_CONSTANTS.tax_type_cvd_edu_cess
1598         , JAI_CONSTANTS.tax_type_sh_cvd_edu_cess
1599         )
1600        OR lv_third_party_flag = 'Y'
1601       )
1602     THEN
1603       tax_rate_tab(rec_retro.lno) :=  -99999;              --changed by eric on Feb 1,2008
1604       Tax_Amt_Tab(rec_retro.lno)  := rec_retro.tax_amount; --changed by eric on Feb 1,2008
1605       tax_target_tab(rec_retro.lno) := rec_retro.tax_amount; --changed by eric on Feb 1,2008
1606     END IF;
1607   END IF;--IF  (pv_called_from = 'RETROACTIVE' )
1608   --------------------------------------------------------------------------
1609   --Add by Eric Ma for Retro active Pricing Update Jan 11, 2008,End
1610   --=================================================================================
1611 
1612   --Comment out by Kevin Cheng
1613       /*IF nvl(rec_retro.tax_rate,0) = 0 AND nvl(rec_retro.qty_rate,0) = 0 and nvl(rec_retro.adhoc_flag,'N') = 'Y' THEN
1614       --Changed by Nagaraj.s for Bug2519359.
1615 
1616          \*
1617          IF p_type='REQUISITION' Then
1618       OPEN req_adhoc_tax_amt(rec_retro.tax_id);
1619       FETCH req_adhoc_tax_amt into v_adhoc_tax_amt;
1620       CLOSE req_adhoc_tax_amt;
1621          ELSE
1622         v_adhoc_tax_amt := rec_retro.tax_amount;
1623          END IF;
1624          *\
1625       v_adhoc_tax_amt := rec_retro.tax_amount;
1626 
1627        -- cbabu for Bug# 3026084
1628        -- tax_rate_tab(rec_retro.lno) :=  -1;
1629        tax_rate_tab(rec_retro.lno) :=  -99999;
1630 
1631          Tax_Amt_Tab(rec_retro.lno)  := v_adhoc_tax_amt;
1632          tax_target_tab(rec_retro.lno) := v_adhoc_tax_amt;
1633 
1634       ELSIF nvl(rec_retro.tax_rate,0) = 0 AND nvl(rec_retro.qty_rate,0) = 0 THEN
1635 
1636        -- cbabu for Bug# 3026084
1637        -- tax_rate_tab(rec_retro.lno) :=  -1;
1638        tax_rate_tab(rec_retro.lno) :=  -99999;
1639 
1640          Tax_Amt_Tab(rec_retro.lno)  := rec_retro.tax_amount;
1641          tax_target_tab(rec_retro.lno) := rec_retro.tax_amount;
1642       ELSE
1643          Tax_Amt_Tab(rec_retro.lno)  := 0;
1644       END IF;*/
1645 
1646       Curr_Tab(rec_retro.lno) := NVL( rec_retro.curr, v_curr );
1647       IF rec_retro.Valid_Date is NULL Or rec_retro.Valid_Date >= Sysdate THEN
1648       End_Date_Tab(rec_retro.lno) := 1;
1649       ELSE
1650       End_Date_Tab(rec_retro.lno) := 0;
1651       END IF;
1652       row_count := row_count + 1;
1653 --Comment out by Kevin Cheng
1654       /*IF tax_rate_tab(rec_retro.lno) = 0 THEN
1655 
1656          FOR uom_cls IN uom_class_cur( nvl(p_line_uom_code, v_line_uom_code) , rec_retro.uom_code) LOOP  -- -- 6/05/02 cbabu bug2357371, added nvl statement
1657         INV_CONVERT.inv_um_conversion(nvl(p_line_uom_code, v_line_uom_code), rec_retro.uom_code, p_inventory_item_id, v_conversion_rate);  -- 15/03/2002 cbabu, added nvl statement
1658         IF nvl(v_conversion_rate, 0) <= 0 THEN
1659           INV_CONVERT.inv_um_conversion(nvl(p_line_uom_code, v_line_uom_code), rec_retro.uom_code, 0, v_conversion_rate); -- 6/05/02 cbabu bug2357371, added nvl statement
1660           IF nvl(v_conversion_rate, 0) <= 0  THEN
1661              v_conversion_rate := 0;
1662           END IF;
1663        END IF;
1664        tax_amt_tab(rec_retro.lno) := ROUND( nvl(rec_retro.qty_rate * v_conversion_rate, 0) * p_line_quantity, rnd_factor(rec_retro.lno) );
1665 
1666          -- cbabu for Bug# 3026084
1667          -- tax_rate_tab(rec_retro.lno) :=  -1;
1668          tax_rate_tab(rec_retro.lno) :=  -99999;
1669 
1670            tax_target_tab(rec_retro.lno) := tax_amt_tab( rec_retro.lno );
1671            -- tax_rate_tab(rec_retro.lno) :=  TRUNC( nvl(rec_retro.qty_rate * p_line_quantity, 0 ), 2 );
1672 
1673         END LOOP;
1674      END IF;*/
1675 
1676   END LOOP;
1677 
1678   CLOSE c_tax_retro_cur;  -- Vijay Shankar for Bug# 3190782
1679 
1680   END IF;
1681 
1682     bsln_amt := p_price;
1683 
1684    FOR I in 1..row_count
1685     LOOP
1686       IF tax_type_tab(i) = 1 THEN
1687          bsln_amt := NVL( p_assessable_value, p_price );
1688       ELSIF tax_type_tab(i) = 4 THEN             -- Ravi for VAT
1689          bsln_amt := NVL( p_vat_assess_value, p_price );
1690       ELSE
1691          bsln_amt := p_price;
1692       END IF;
1693       IF p1(I) < I and p1(I) not in (-1,0) then
1694          vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
1695 
1696       ELSIF p1(I) = 0 then
1697          vamt  := vamt + bsln_amt;
1698       END IF;
1699       IF p2(I) < I and p2(I) not in (-1,0) then
1700          vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
1701 
1702       ELSIF p2(I) = 0 then
1703          vamt  := vamt + bsln_amt;
1704       END IF;
1705       IF p3(I) < I and p3(I) not in (-1,0) then
1706          vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
1707 
1708       ELSIF p3(I) = 0 then
1709          vamt  := vamt + bsln_amt;
1710       END IF;
1711       IF p4(I) < I and p4(I) not in (-1,0) then
1712          vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
1713 
1714       ELSIF p4(I) = 0 then
1715          vamt  := vamt + bsln_amt;
1716       END IF;
1717       IF p5(I) < I and p5(I) not in (-1,0) then
1718          vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
1719       ELSIF p5(I) = 0 then
1720          vamt  := vamt + bsln_amt;
1721       END IF;
1722 
1723 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
1724 -- START BUG 5228046
1725 
1726       IF p6(I) < I and p6(I) not in (-1,0) then
1727          vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
1728       ELSIF p6(I) = 0 then
1729          vamt  := vamt + bsln_amt;
1730       END IF;
1731 
1732       IF p7(I) < I and p7(I) not in (-1,0) then
1733          vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
1734       ELSIF p7(I) = 0 then
1735          vamt  := vamt + bsln_amt;
1736       END IF;
1737 
1738       IF p8(I) < I and p8(I) not in (-1,0) then
1739          vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
1740       ELSIF p8(I) = 0 then
1741          vamt  := vamt + bsln_amt;
1742       END IF;
1743 
1744       IF p9(I) < I and p9(I) not in (-1,0) then
1745          vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
1746       ELSIF p9(I) = 0 then
1747          vamt  := vamt + bsln_amt;
1748       END IF;
1749 
1750       IF p10(I) < I and p10(I) not in (-1,0) then
1751          vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
1752       ELSIF p10(I) = 0 then
1753          vamt  := vamt + bsln_amt;
1754       END IF;
1755 -- END BUG 5228046
1756 
1757      -- cbabu for Bug# 3026084
1758        -- IF tax_rate_tab(I) <> -1 THEN
1759        IF tax_rate_tab(I) <> -99999 THEN
1760          v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
1761          IF END_date_tab(I) = 0 then
1762             tax_amt_tab(I) := 0;
1763          ELSIF END_date_tab(I) = 1 then
1764             tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
1765          END IF;
1766        ELSE --added by subbu on 7-nov-01
1767          tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + nvl(v_tax_amt,0);
1768        END IF;
1769       vamt      := 0;
1770       v_tax_amt := 0;
1771 
1772      END LOOP;
1773 
1774     FOR I in 1..row_count
1775     LOOP
1776       IF p1(I) > I then
1777          vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
1778       END IF;
1779       IF p2(I) > I  then
1780          vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
1781       END IF;
1782       IF p3(I) > I  then
1783          vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
1784       END IF;
1785       IF p4(I) > I then
1786          vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
1787       END IF;
1788       IF p5(I) > I then
1789          vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
1790       END IF;
1791 
1792 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
1793 -- START BUG 5228046
1794 
1795       IF p6(I) > I then
1796          vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
1797       END IF;
1798       IF p7(I) > I  then
1799          vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
1800       END IF;
1801       IF p8(I) > I  then
1802          vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
1803       END IF;
1804       IF p9(I) > I then
1805          vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
1806       END IF;
1807       IF p10(I) > I then
1808          vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
1809       END IF;
1810 -- END BUG 5228046
1811 
1812        -- cbabu for Bug# 3026084
1813        -- IF tax_rate_tab(I) <> -1 THEN
1814        IF tax_rate_tab(I) <> -99999 THEN
1815          v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
1816          IF END_date_tab(I) = 0 then
1817             tax_amt_tab(I) := 0;
1818          ELSIF END_date_tab(I) = 1 then
1819             tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + nvl(v_tax_amt,0);
1820          END IF;
1821        ELSE -- added by subbu on 07-nov-01
1822           tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + nvl(v_tax_amt,0);
1823        END IF;
1824       vamt      := 0;
1825       v_tax_amt := 0;
1826 
1827     END LOOP;
1828 
1829     FOR counter IN 1 .. max_iter LOOP
1830       vamt := 0;
1831       v_tax_amt := 0;
1832       FOR i IN 1 .. row_count LOOP
1833 
1834   /*      IF tax_rate_tab( i ) > 0 AND End_Date_Tab(I) <> 0 THEN  Commented by Satya / Subbu on 09-Oct-01    */
1835 
1836   /*  Added by Satya / subbu on 09-Oct-01 for calculating the Negative Tax */
1837 
1838         IF tax_rate_tab( i ) <> 0 AND End_Date_Tab(I) <> 0  AND adhoc_tab(i) <> 'Y' THEN
1839   -- added extra condition AND adhoc_tab(i) <> 'Y' by subbu on 8-nov-01 for adhoc taxes
1840             IF tax_type_tab( i ) = 1 THEN
1841                v_amt := NVL( p_assessable_value, p_price );
1842             ELSIF tax_type_tab(i) = 4 THEN     -- Ravi for VAT
1843                v_amt := NVL( p_vat_assess_value, p_price );
1844             ELSIF v_amt = 0 OR tax_type_tab(i) <> 1 THEN
1845                v_amt := p_price;
1846             END IF;
1847      IF p1( i ) <> -1 THEN
1848         IF p1( i ) <> 0 THEN
1849              vamt := vamt + tax_amt_tab( p1( I ) );
1850         ELSIF p1(i) = 0 THEN
1851            vamt := vamt + v_amt;
1852         END IF;
1853      END IF;
1854            IF p2( i ) <> -1 THEN
1855         IF p2( i ) <> 0 THEN
1856              vamt := vamt + tax_amt_tab( p2( I ) );
1857         ELSIF p2(i) = 0 THEN
1858            vamt := vamt + v_amt;
1859         END IF;
1860      END IF;
1861            IF p3( i ) <> -1 THEN
1862         IF p3( i ) <> 0 THEN
1863              vamt := vamt + tax_amt_tab( p3( I ) );
1864         ELSIF p3(i) = 0 THEN
1865            vamt := vamt + v_amt;
1866         END IF;
1867      END IF;
1868            IF p4( i ) <> -1 THEN
1869         IF p4( i ) <> 0 THEN
1870              vamt := vamt + tax_amt_tab( p4( i ) );
1871         ELSIF p4(i) = 0 THEN
1872            vamt := vamt + v_amt;
1873         END IF;
1874      END IF;
1875            IF p5( i ) <> -1 THEN
1876         IF p5( i ) <> 0 THEN
1877              vamt := vamt + tax_amt_tab( p5( i ) );
1878         ELSIF p5(i) = 0 THEN
1879            vamt := vamt + v_amt;
1880         END IF;
1881      END IF;
1882 
1883 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
1884 -- START BUG 5228046
1885        IF p6( i ) <> -1 THEN
1886         IF p6( i ) <> 0 THEN
1887              vamt := vamt + tax_amt_tab( p6( I ) );
1888         ELSIF p6(i) = 0 THEN
1889            vamt := vamt + v_amt;
1890         END IF;
1891      END IF;
1892 
1893     IF p7( i ) <> -1 THEN
1894         IF p7( i ) <> 0 THEN
1895              vamt := vamt + tax_amt_tab( p7( I ) );
1896         ELSIF p7(i) = 0 THEN
1897            vamt := vamt + v_amt;
1898         END IF;
1899      END IF;
1900 
1901      IF p8( i ) <> -1 THEN
1902         IF p8( i ) <> 0 THEN
1903              vamt := vamt + tax_amt_tab( p8( I ) );
1904         ELSIF p8(i) = 0 THEN
1905            vamt := vamt + v_amt;
1906         END IF;
1907      END IF;
1908 
1909      IF p9( i ) <> -1 THEN
1910         IF p9( i ) <> 0 THEN
1911              vamt := vamt + tax_amt_tab( p9( i ) );
1912         ELSIF p9(i) = 0 THEN
1913            vamt := vamt + v_amt;
1914         END IF;
1915      END IF;
1916 
1917      IF p10( i ) <> -1 THEN
1918         IF p10( i ) <> 0 THEN
1919              vamt := vamt + tax_amt_tab( p10( i ) );
1920         ELSIF p10(i) = 0 THEN
1921            vamt := vamt + v_amt;
1922         END IF;
1923      END IF;
1924 
1925 -- END BUG 5228046
1926 
1927   tax_target_tab(I) := vamt;
1928         IF counter = max_iter THEN --AND tax_type_tab( I ) IN ( 1, 2 ) THEN
1929             -- cbabu for Bug# 3026084
1930             -- IF tax_rate_tab(I) <> -1 THEN    -- 5/3/2002 cbabu
1931             IF tax_rate_tab(I) <> -99999 THEN
1932               v_tax_amt := ROUND( v_tax_amt + ( vamt * ( tax_rate_tab( i )/100)), rnd_factor(I) );
1933             ELSE
1934               v_tax_amt := ROUND( tax_amt_tab( I ), rnd_factor(I) ); --  5/3/2002 cbabu
1935             END IF;
1936           /*ELSIF counter = max_iter AND tax_type_tab( I ) NOT IN ( 1, 2 ) THEN
1937              v_tax_amt := ROUND( v_tax_amt + ( vamt * ( tax_rate_tab( i )/100)), 2 );
1938             */
1939         ELSE
1940             -- cbabu for Bug# 3026084
1941             -- IF tax_rate_tab(I) <> -1 THEN -- 5/3/2002 cbabu
1942             IF tax_rate_tab(I) <> -99999 THEN
1943               v_tax_amt := v_tax_amt + ( vamt * ( tax_rate_tab( i )/100));
1944             ELSE
1945               v_tax_amt := tax_amt_tab( I ); -- 5/3/2002 cbabu
1946             END IF;
1947         END IF;
1948         tax_amt_tab( I ) := NVL( v_tax_amt, 0 );
1949         --cbabu for Bug# 3026084
1950         ELSIF tax_rate_tab( i ) = -99999 AND End_Date_Tab(I) <> 0  THEN
1951           NULL;
1952         ELSE
1953           tax_amt_tab(I) := 0;
1954           tax_target_tab(I) := 0;
1955         END IF;
1956 
1957         IF counter = max_iter THEN
1958           IF END_date_tab(I) = 0 THEN
1959             tax_amt_tab(I) := 0;
1960           END IF;
1961         END IF;
1962 
1963         vamt := 0;
1964         v_amt := 0;
1965         v_tax_amt := 0;
1966 
1967       END LOOP;
1968     END LOOP;
1969   END IF;
1970 --==========================================================================================================
1971 
1972     IF p_type = 'REQUISITION' THEN  /*********************************/
1973        FOR I in 1..row_count LOOP
1974          v_tax_amt := v_tax_amt + nvl(tax_amt_tab(I),0);
1975         IF tax_type_tab( i )  = 1 THEN
1976            bsln_amt := p_assessable_value;
1977         ELSIF tax_type_tab(i) = 4 THEN    -- Ravi for VAT
1978            bsln_amt := p_vat_assess_value;
1979         ELSE
1980            bsln_amt := p_price;
1981         END IF;
1982         UPDATE JAI_PO_REQ_LINE_TAXES
1983            SET Tax_Amount = nvl(tax_amt_tab(I),0),
1984                Tax_Target_Amount = NVL( tax_target_tab(I), 0 ) * ( 1/p_conv_rate )
1985          WHERE Requisition_Header_Id = p_header_id
1986             AND Requisition_Line_Id   = p_line_id
1987             AND Tax_Line_No    = I;
1988         END LOOP;
1989         P_TAX_AMOUNT := v_tax_amt;
1990 
1991 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
1992 ELSIF p_type = 'RECEIPTS' THEN  /*********************************/
1993           FOR I in 1..row_count
1994           LOOP
1995              if lv_currency_code <> Curr_Tab(I) and  adhoc_tab(i) <> 'Y' then
1996                  tax_amt_tab(I) := nvl(tax_amt_tab(I),0) * (1/nvl(p_conv_rate,1));
1997              end if;
1998 
1999              v_tax_amt := v_tax_amt + nvl(tax_amt_tab(I),0);
2000              IF tax_type_tab( i )  = 1 THEN
2001                 bsln_amt := p_assessable_value;
2002              ELSIF tax_type_tab(i) = 4 THEN
2003                 bsln_amt := p_vat_assess_value;
2004              ELSE
2005                 bsln_amt := p_price;
2006              END IF;
2007 
2008              UPDATE    jai_rcv_line_taxes
2009              SET       Tax_Amount             = nvl(tax_amt_tab(I),0),
2010                        Tax_Target_Amount      = NVL(tax_target_tab(I), 0 ) * ( 1/p_conv_rate )
2011              WHERE     shipment_Header_Id     = p_header_id
2012              AND       shipment_Line_Id       = p_line_id
2013              AND       Tax_Line_No            = I;
2014            END LOOP;
2015            P_TAX_AMOUNT := v_tax_amt;
2016 
2017        ELSIF p_type = 'ASBN' THEN  /*********************************/
2018             FOR I in 1..row_count
2019             LOOP
2020                v_tax_amt := v_tax_amt + nvl(tax_amt_tab(I),0);
2021                IF tax_type_tab( i )  = 1 THEN
2022                   bsln_amt := p_assessable_value;
2023                ELSIF tax_type_tab(i) = 4 THEN
2024                   bsln_amt := p_vat_assess_value;
2025                ELSE
2026                   bsln_amt := p_price;
2027                END IF;
2028 
2029                UPDATE    Jai_cmn_document_Taxes
2030                SET       Tax_Amt             = nvl(tax_amt_tab(I),0)
2031                WHERE     source_doc_id          = p_header_id
2032                AND       source_doc_Line_Id     = p_line_id
2033                AND       Tax_Line_No            = I;
2034              END LOOP;
2035            P_TAX_AMOUNT := v_tax_amt;
2036 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
2037 
2038     ELSIF p_type = 'REQUISITION_BLANKET' THEN /*********************************/
2039        FOR I in 1..row_count LOOP
2040          IF v_curr = Curr_Tab(I) THEN
2041             conv_rate := 1;
2042          ELSE
2043             conv_rate := 1;
2044          END IF;
2045          IF tax_type_tab( i )  = 1 THEN
2046             bsln_amt := p_assessable_value;
2047          ELSIF tax_type_tab(i) = 4 THEN    -- Ravi for VAT
2048             bsln_amt := p_vat_assess_value;
2049          ELSE
2050             bsln_amt := p_price;
2051          END IF;
2052          v_tax_amt := v_tax_amt + nvl(tax_amt_tab(I),0);
2053          UPDATE JAI_PO_REQ_LINE_TAXES
2054             SET Tax_Amount = nvl(tax_amt_tab(I),0),
2055                 Tax_Target_Amount = NVL( tax_target_tab(I), 0 ) * ( 1/p_conv_rate )
2056           WHERE Requisition_Line_Id = p_header_id
2057             AND Tax_Line_No    = I;
2058         END LOOP;
2059         P_TAX_AMOUNT := v_tax_amt;
2060     ELSIF p_type IN ( 'RELEASE', 'STANDARDPO' ) THEN /*********************************/
2061        FOR I IN 1 .. row_count LOOP
2062         IF tax_type_tab( i )  = 1 THEN
2063            bsln_amt := p_assessable_value;
2064         ELSIF tax_type_tab(i) = 4 THEN    -- Ravi for VAT
2065            bsln_amt := p_vat_assess_value;
2066         ELSE
2067            bsln_amt := p_price;
2068         END IF;
2069         IF p_type = 'RELEASE' THEN
2070 
2071            UPDATE JAI_PO_TAXES
2072               SET Tax_Amount = NVL( tax_amt_tab(I), 0 ),
2073                   Tax_Target_Amount = NVL( tax_target_tab(I), 0 ) * ( 1/p_conv_rate )
2074             WHERE Line_Location_Id = p_header_id
2075               AND Po_Line_Id = p_line_id
2076               AND Tax_Line_No = I;
2077           --Added by Kevin Cheng for Retroactive Price 2008/01/11
2078           --=====================================================
2079           IF pv_retroprice_changed = 'Y'
2080           THEN
2081             JAI_RETRO_PRC_PKG.Update_Price_Changes( pn_tax_amt         => NVL( tax_amt_tab(I), 0 )
2082                                                   , pn_line_no         => I
2083                                                   , pn_line_loc_id     => p_header_id
2084                                                   , pv_process_flag    => lv_process_flag
2085                                                   , pv_process_message => lv_process_message
2086                                                   );
2087 
2088             IF lv_process_flag IN ('EE', 'UE')
2089             THEN
2090               FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
2091               FND_MESSAGE.SET_TOKEN('JAI_PROCESS_MSG','JAI_PO_TAX_PKG.CALCULATE_TAX.Err:'||lv_process_message);
2092               app_exception.raise_exception;
2093             END IF;
2094           END IF;
2095           --=====================================================
2096         ELSIF p_type = 'STANDARDPO' THEN
2097            UPDATE JAI_PO_TAXES
2098               SET Tax_Amount = NVL( tax_amt_tab(I), 0 ),
2099                   Tax_Target_Amount = NVL( tax_target_tab(I), 0 ) * ( 1/p_conv_rate )
2100             WHERE Line_Location_Id = p_line_loc_id
2101               AND Po_Line_Id = p_line_id
2102               AND Tax_Line_No = I;
2103           --Added by Kevin Cheng for Retroactive Price 2008/01/11
2104           --=====================================================
2105           IF pv_retroprice_changed = 'Y'
2106           THEN
2107             JAI_RETRO_PRC_PKG.Update_Price_Changes( pn_tax_amt         => NVL( tax_amt_tab(I), 0 )
2108                                                   , pn_line_no         => I
2109                                                   , pn_line_loc_id     => p_line_loc_id
2110                                                   , pv_process_flag    => lv_process_flag
2111                                                   , pv_process_message => lv_process_message
2112                                                   );
2113 
2114             IF lv_process_flag IN ('EE', 'UE')
2115             THEN
2116               FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
2117               FND_MESSAGE.SET_TOKEN('JAI_PROCESS_MSG','JAI_PO_TAX_PKG.CALCULATE_TAX.Err:'||lv_process_message);
2118               app_exception.raise_exception;
2119             END IF;
2120           END IF;
2121           --=====================================================
2122         END IF;
2123        END LOOP;
2124        IF p_type = 'RELEASE' THEN
2125           OPEN  Fetch_Sum_Cur( p_header_id );
2126           FETCH Fetch_Sum_Cur INTO v_tax_amt;
2127           CLOSE Fetch_Sum_Cur;
2128 
2129           UPDATE JAI_PO_LINE_LOCATIONS
2130              SET Tax_Amount = NVL( v_tax_amt, 0 ),
2131                  Total_Amount = v_tax_amt + p_price
2132            WHERE Line_Location_Id = p_header_id
2133              AND Po_Line_Id = p_line_id;
2134       ELSIF p_type = 'STANDARDPO' THEN
2135           OPEN  Fetch_Sum_Cur( p_line_loc_id );
2136           FETCH Fetch_Sum_Cur INTO v_tax_amt;
2137           CLOSE Fetch_Sum_Cur;
2138 
2139           UPDATE  JAI_PO_LINE_LOCATIONS
2140           SET     Tax_Amount = NVL( v_tax_amt, 0 ),
2141               Total_Amount = v_tax_amt + p_price
2142           WHERE   Line_Location_Id = p_line_loc_id
2143            AND    Po_Line_Id = p_line_id;
2144       END IF;
2145     END IF;
2146 
2147   EXCEPTION
2148     WHEN OTHERS THEN
2149     p_tax_amount := null;
2150     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
2151     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
2152     app_exception.raise_exception;
2153 
2154   END calculate_tax;
2155 
2156 /* ----------------------------------------------------------------------------------------*/
2157 
2158 
2159 /* ----------------------------------------------------------------------------------------*/
2160 
2161   PROCEDURE batch_quot_taxes_copy
2162   (
2163     p_errbuf OUT NOCOPY VARCHAR2,
2164     p_retcode OUT NOCOPY VARCHAR2
2165   )
2166   IS
2167     v_errbuf                VARCHAR2(1996);
2168     v_retcode               VARCHAR2(1996);
2169 
2170     lv_app_name   fnd_application.application_short_name%type ;
2171     lv_conc_name  fnd_concurrent_programs.concurrent_program_name%type ;
2172 
2173     v_rowid                 ROWID;
2174     error_from_called_unit  EXCEPTION;
2175     v_error_mesg            VARCHAR2(1996);
2176     v_qty                   NUMBER;
2177     v_line_location_id      NUMBER;
2178 
2179     v_total NUMBER; --File.Sql.35 Cbabu  := 0;
2180     v_processed NUMBER; --File.Sql.35 Cbabu  := 0;
2181 
2182     CURSOR c_line_location_qty( p_line_location_id IN NUMBER) IS
2183       SELECT quantity
2184       FROM po_line_locations_all
2185       WHERE line_location_id = p_line_location_id;
2186 
2187     CURSOR c_enable_trace IS
2188       SELECT enable_trace
2189       FROM fnd_concurrent_programs a, fnd_application b
2190       WHERE b.application_short_name = lv_app_name --'PO'
2191       AND b.application_id = a.application_id
2192       AND a.concurrent_program_name = lv_conc_name;  --'JAINPOTD';/* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
2193 
2194     CURSOR get_audsid IS
2195       SELECT a.sid, a.serial#, b.spid FROM v$session a,v$process b
2196       WHERE audsid = userenv('SESSIONID')
2197       AND a.paddr = b.addr;
2198 
2199     CURSOR get_dbname IS
2200       SELECT name FROM v$database;
2201 
2202     v_enable_trace fnd_concurrent_programs.enable_trace%TYPE;
2203     audsid  NUMBER; --File.Sql.35 Cbabu  := userenv('SESSIONID');
2204     sid   V$SESSION.SID%TYPE;
2205     serial  V$SESSION.SERIAL#%TYPE;
2206     spid  V$PROCESS.SPID%TYPE;
2207     v_name1 V$DATABASE.NAME%TYPE;
2208 
2209 
2210    lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.batch_quot_taxes_copy';
2211   BEGIN
2212 
2213   /*------------------------------------------------------------------------------------------------------------------------
2214   S.No      DATE                Author AND Details
2215   ---------------------------------------------------------------------------------------------------------------------------
2216   1 19-SEP-2002   Vijay Shankar, Created this procedure. Bug#2541354 (enhancement for KOEL)
2217             This trigger was created to move the processing of shipment lines while PO gets generated
2218             ja_in_bulk_po_quot_taxes_pfrom Quotation (used from MRP also). the concurrent was getting submitted for every shipment
2219             ja_in_bulk_po_quot_taxes_pline of the PO, to default the tax lines. With this procedure all such shipment lines
2220             will be processed as 1 concurrent. The temporary table used here is being populated from the
2221             trigger ja_in_po_tax_insert_trg on PO_LINE_LOCATIONS_ALL. The main concepts
2222             used here are,
2223               - if an error occurs while processing a particular record, the program will skip processing
2224               all other shipment lines of the error PO(Purchase Order).
2225               - the program will continue to process other PO's.
2226               - the program will update the temporary table for the error record, with error flag time and error
2227               - if a particular line has error flag set to 'Y', this program will not pick up that record and
2228               also all other lines pertaining to such an error PO.
2229              The concurrent which is referring this procedure needs to be trace enabled( useful when there is some problem
2230             with the concurrent). In order to get the trace the DBA should query for JAINPOTD concurrent and check the
2231             'Trace Enabled' flag which is used in this concurrent to create level 4 trace.
2232   ------------------------------------------------------------------------------------------------------------------------ */
2233 
2234     v_total  := 0;
2235     v_processed  := 0;
2236     audsid  := userenv('SESSIONID');
2237 
2238     FND_FILE.put_line(FND_FILE.LOG, 'Start procedure - Ja_In_Bulk_PO_Tax_Insert');
2239     -- this cursor picks up the PO Shipment lines from the temporary table but does not pick up such shipment lines
2240     -- which have error_flag set to 'Y' for any of it's Shipment lines.
2241 
2242 /* Added by Ramananda for removal of SQL LITERALs */
2243     lv_app_name  :=  'PO';
2244     lv_conc_name := 'JAINPOTD';
2245     OPEN c_enable_trace;
2246     FETCH c_enable_trace INTO v_enable_trace;
2247     CLOSE c_enable_trace;
2248 
2249     IF nvl(v_enable_trace, 'N') = 'Y' THEN
2250       OPEN get_audsid;
2251       FETCH get_audsid INTO sid, serial, spid;
2252       CLOSE get_audsid;
2253 
2254       /* code commented by aiyer for the bug 4517919
2255       DBMS_SUPPORT.START_TRACE_IN_SESSION( sid, serial, waits => false, binds=>true);
2256       */
2257       /*
2258       ||Opened the existing cursor to get the database name
2259       || and called fnd_file.put_line to register the info
2260       || also changed the dbms_support.start and stop trace to execute immediate alter session code
2261       */
2262       OPEN get_dbname;
2263       FETCH get_dbname INTO v_name1;
2264       CLOSE get_dbname;
2265 
2266       FND_FILE.PUT_LINE( FND_FILE.log, 'TraceFile Name = '||lower(v_name1)||'_ora_'||spid||'.trc');
2267       EXECUTE IMMEDIATE 'ALTER SESSION SET EVENTS ''10046 trace name context forever, level 4''';
2268     END IF;
2269 
2270     FOR c_rec IN
2271     (
2272       SELECT
2273         ROWID,
2274         po_header_id,
2275         po_line_id,
2276         line_location_id,
2277         from_header_id,
2278         from_line_id,
2279         price_override,
2280         uom_code,
2281         assessable_value,
2282         creation_date,
2283         created_by,
2284         last_update_date,
2285         last_updated_by,
2286         last_update_login
2287       FROM JAI_PO_QUOT_LINES_T
2288       WHERE nvl(error_flag, 'N') <> 'Y'
2289       ORDER BY  po_header_id, po_line_id
2290     )
2291     LOOP
2292       v_line_location_id := c_rec.line_location_id;
2293       v_rowid := c_rec.ROWID;
2294       v_errbuf := NULL;
2295       v_retcode := NULL;
2296       v_error_mesg := NULL;
2297 
2298       BEGIN
2299 
2300         OPEN c_line_location_qty( v_line_location_id );
2301         FETCH c_line_location_qty INTO v_qty;
2302         CLOSE c_line_location_qty;
2303 
2304         -- Call the procedure which defaults the taxes from Quotation to PO and inserts shipment lines into
2305         -- JA tables
2306         jai_po_tax_pkg.copy_quot_taxes(
2307           errbuf      => v_errbuf,
2308           retcode     => v_retcode,
2309           p_line_loc_id   => v_line_location_id,
2310           p_po_hdr_id   => c_rec.po_header_id,
2311           p_po_line_id  => c_rec.po_line_id,
2312           p_qty       => v_qty,
2313           p_frm_hdr_id  => c_rec.from_header_id,
2314           p_frm_line_id => c_rec.from_line_id,
2315           p_price     => c_rec.price_override,
2316           p_unit_code   => c_rec.uom_code,
2317           p_assessable_value => c_rec.assessable_value,
2318           p_cre_dt    => nvl(c_rec.creation_date, SYSDATE),
2319           p_cre_by    => nvl(c_rec.created_by, FND_GLOBAL.USER_ID),
2320           p_last_upd_dt => nvl(c_rec.last_update_date, SYSDATE),
2321           p_last_upd_by => nvl(c_rec.last_updated_by, FND_GLOBAL.USER_ID),
2322           p_last_upd_login=> nvl(c_rec.last_update_login, FND_GLOBAL.LOGIN_ID)
2323         );
2324 
2325         -- check whether called procedure returned any error
2326         IF ( v_errbuf IS NOT NULL) THEN
2327           v_error_mesg := 'Error from called unit jai_po_tax_pkg.copy_quot_taxes -> '||v_errbuf;
2328           RAISE  error_from_called_unit;
2329         END IF;
2330 
2331         DELETE FROM JAI_PO_QUOT_LINES_T
2332           WHERE rowid = v_rowid;
2333 
2334         COMMIT;
2335 
2336         v_processed := v_processed + 1;
2337       EXCEPTION
2338 
2339         WHEN OTHERS THEN
2340           IF v_error_mesg IS NULL  THEN
2341             -- the exception condition is not because of returned error from jai_po_tax_pkg.copy_quot_taxes
2342             v_error_mesg := 'Error in main for loop. SQLERRM -> '|| SQLERRM;
2343           END IF;
2344 
2345           ROLLBACK;
2346 
2347         -- update the record for error
2348           UPDATE JAI_PO_QUOT_LINES_T
2349           SET error_flag = 'Y',
2350             processing_time = SYSDATE,
2351             error_message = v_error_mesg
2352           WHERE  ROWID = v_rowid;
2353 
2354           COMMIT;
2355 
2356         FND_FILE.put_line(FND_FILE.LOG, v_error_mesg || ' : FOR line_location_id = ' ||  v_line_location_id || ', Quantity = ' || v_qty);
2357       END;
2358 
2359       FND_FILE.put_line(FND_FILE.LOG, ' Processed line_location_id = ' || v_line_location_id);
2360 
2361       END LOOP;   -- CURSOR FOR
2362 
2363     FND_FILE.put_line(FND_FILE.LOG, 'Tax Defaultation is SUCCESSFUL. END PROCEDURE - JA_IN_BULK_PO_QUOT_TAXES - '||v_processed||'/'||v_total||' records processed.');
2364 
2365   EXCEPTION
2366     WHEN OTHERS THEN
2367     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
2368     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
2369     app_exception.raise_exception;
2370   END  batch_quot_taxes_copy;
2371 
2372 /*------------------------------------------------------------------------------------------*/
2373 
2374   PROCEDURE copy_reqn_taxes
2375   (
2376     p_Vendor_Id number,
2377     p_Vendor_Site_Id number,
2378     p_Po_Header_Id number,
2379     p_Po_Line_Id number, --added by Sriram on 22-Nov-2001
2380     p_line_location_id number, --added by Sriram on 22-Nov-2001
2381     p_Type_Lookup_Code varchar2,
2382     p_Quotation_Class_Code varchar2,
2383     p_Ship_To_Location_Id number,
2384     p_Org_Id number,
2385     p_Creation_Date date,
2386     p_Created_By number,
2387     p_Last_Update_Date date,
2388     p_Last_Updated_By number,
2389     p_Last_Update_Login number
2390     /* Brathod, For Bug# 4242351 */
2391     ,p_rate         PO_HEADERS_ALL.RATE%TYPE      DEFAULT NULL
2392     ,p_rate_type      PO_HEADERS_ALL.RATE_TYPE%TYPE DEFAULT NULL
2393     ,p_rate_date     PO_HEADERS_ALL.RATE_DATE%TYPE DEFAULT NULL
2394     ,p_currency_code PO_HEADERS_ALL.CURRENCY_CODE%TYPE DEFAULT NULL
2395     /* End of Bug# 4242351 */
2396     )
2397   IS
2398       v_vendor_id         NUMBER; --File.Sql.35 Cbabu          :=  NVL( p_Vendor_Id, 0 );
2399       v_vendor_site_id    NUMBER; --File.Sql.35 Cbabu           :=  NVL( p_Vendor_Site_Id, 0 );
2400       v_po_hdr_id         NUMBER; --File.Sql.35 Cbabu           :=  p_Po_Header_Id;
2401       v_type_lookup_code  VARCHAR2(30); --File.Sql.35 Cbabu     :=  p_Type_Lookup_Code;
2402       v_quot_class_code   VARCHAR2(30); --File.Sql.35 Cbabu     :=  p_Quotation_Class_Code;
2403       v_ship_loc_id       NUMBER; --File.Sql.35 Cbabu           :=  p_Ship_To_Location_Id;
2404       v_org_id            NUMBER ;
2405       v_po_org_id         NUMBER; --File.Sql.35 Cbabu           :=  NVL( p_Org_Id, -999 );
2406 
2407       v_rate      NUMBER;
2408       v_rate_type   VARCHAR2(100);
2409       v_rate_date   DATE ;
2410 
2411       v_ship_to_loc_id  NUMBER; --File.Sql.35 Cbabu       :=  p_Ship_To_Location_Id;
2412       v_next_val    NUMBER;
2413       line_loc_flag   BOOLEAN;
2414       v_assessable_value  NUMBER;
2415       ln_vat_assess_value NUMBER; -- added rallamse bug#4250072
2416       v_func_curr         VARCHAR2(15);
2417 
2418       v_curr              VARCHAR2(100); --added by Sriram on 22-Nov-2001
2419       v_conv_rate         NUMBER;
2420       flag      VARCHAR2(10);
2421       v_line_cnt    NUMBER;
2422       v_tax_flag    VARCHAR2(1);
2423       v_old_vendor_id NUMBER;
2424       v_item_id   NUMBER;
2425       v_qty     NUMBER;
2426       v_price     NUMBER;
2427       v_uom     VARCHAR2(25);
2428       v_line_uom    VARCHAR2(25);
2429       v_cre_dt    DATE; --File.Sql.35 Cbabu             :=  p_Creation_Date;
2430       v_cre_by    NUMBER; --File.Sql.35 Cbabu       :=  p_Created_By;
2431       v_last_upd_dt   DATE ; --File.Sql.35 Cbabu            :=  p_Last_Update_Date;
2432       v_last_upd_by   NUMBER; --File.Sql.35 Cbabu           :=  p_Last_Updated_By;
2433       v_last_upd_login  NUMBER; --File.Sql.35 Cbabu       :=  p_Last_Update_Login;
2434       v_po_line_id1       NUMBER; --File.Sql.35 Cbabu  := p_Po_Line_Id; --added by Sriram on 22-Nov-2001
2435       v_line_location_id  NUMBER; --File.Sql.35 Cbabu  := p_line_location_id; --added by Sriram on 22-Nov-2001
2436       v_error  VARCHAR2(20) ;
2437       v_service_type_code varchar2(30);
2438     ------------------------------  ------------------------------  ------------------------------  ------------------------------
2439 
2440     -- Get the Inventory Organization Id
2441 
2442       CURSOR Fetch_Org_Id_Cur IS SELECT Inventory_Organization_id
2443                      FROM   Hr_Locations
2444                      WHERE  Location_Id = v_ship_loc_id;
2445 
2446     ------------------------------  ------------------------------  ------------------------------  ------------------------------
2447 
2448     -- Get the Line Focus Id from the Sequence
2449 
2450       CURSOR Fetch_Focus_Id IS SELECT JAI_PO_LINE_LOCATIONS_S.NEXTVAL
2451                  FROM   Dual;
2452 
2453     ------------------------------  ------------------------------  ------------------------------  ------------------------------
2454 
2455       CURSOR Lines_Cur IS SELECT DISTINCT Po_Line_Id
2456               FROM   Po_Line_Locations_all
2457               WHERE  Po_Header_Id = v_po_hdr_id;
2458 
2459       CURSOR Fetch_Item_Cur( Lineid IN NUMBER ) IS SELECT Item_Id
2460                    FROM   Po_Lines_All
2461                    WHERE  Po_Line_Id = Lineid;
2462 
2463       CURSOR Line_Loc_Cur( lineid IN NUMBER ) IS SELECT Line_Location_Id
2464                            FROM   po_line_locations_all
2465                            WHERE  Po_Line_Id = lineid;
2466 
2467     ------------------------------  ------------------------------  ------------------------------  ------------------------------
2468 
2469       CURSOR Fetch_Dtls_Cur( lineid IN NUMBER ) IS SELECT Quantity, Unit_Price, Unit_Meas_Lookup_Code
2470                        FROM   Po_Lines_All
2471                          WHERE  Po_Line_Id = lineid;
2472 
2473       CURSOR Fetch_Dtls1_Cur( lineid IN NUMBER, linelocid IN NUMBER ) IS SELECT Quantity, Price_Override,
2474                                 Unit_Meas_Lookup_Code
2475                                  FROM   Po_Line_Locations_All
2476                                    WHERE  Po_Line_Id = lineid
2477                           AND   Line_Location_Id = linelocid;
2478     -- Get the Uom Code
2479 
2480       CURSOR Fetch_UOMCode_Cur IS SELECT Uom_Code
2481                   FROM   Mtl_Units_Of_Measure
2482                   WHERE  Unit_Of_Measure = v_uom;
2483 
2484       lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.copy_reqn_taxes';
2485   BEGIN
2486 
2487   /*--------------------------------------------------------------------------------------------------------------------------
2488   CHANGE HISTORY for FILENAME - jai_po_tax_pkg.copy_reqn_taxes.sql
2489   S.No  Date         Author and Details
2490   -------------------------------------------------------------------------------------------------------------------------
2491   1     22/11/2001   sriram bug# Version#115.1
2492 
2493   2.    14/03/2005   bug#4250072  rallamse Version# 115.2
2494                      Changes for VAT implementation
2495 
2496   3.    31/03/2005   Brathod, Bug#4242351, Version 115.3
2497                      Issue:-    Cursor get_po_hdr having a select statement on table po_headers_all
2498                                 was raising mutating error.
2499                      Solution:- Four new parameters are passed to the procedure
2500                                 to avoid select statement.
2501 4.                   Kunkumar Added v_service_type_code and its manipulations for forward porting to R12.
2502   ===============================================================================
2503 
2504   Dependencies
2505 
2506   Version   Author     Dependencies           Comments
2507   115.2     rallamse   IN60106+4245089        Changes for VAT implementation
2508 
2509   --------------------------------------------------------------------------------------------------------------------------*/
2510 
2511        --File.Sql.35 Cbabu
2512        v_vendor_id            :=  NVL( p_Vendor_Id, 0 );
2513       v_vendor_site_id        :=  NVL( p_Vendor_Site_Id, 0 );
2514       v_po_hdr_id             :=  p_Po_Header_Id;
2515       v_type_lookup_code      :=  p_Type_Lookup_Code;
2516       v_quot_class_code       :=  p_Quotation_Class_Code;
2517       v_ship_loc_id           :=  p_Ship_To_Location_Id;
2518       v_ship_to_loc_id        :=  p_Ship_To_Location_Id;
2519       v_cre_dt                :=  p_Creation_Date;
2520       v_cre_by                :=  p_Created_By;
2521       v_last_upd_dt           :=  p_Last_Update_Date;
2522       v_last_upd_by           :=  p_Last_Updated_By;
2523       v_last_upd_login        :=  p_Last_Update_Login;
2524       v_po_line_id1           := p_Po_Line_Id; --added by Sriram on 22-Nov-2001
2525       v_line_location_id      := p_line_location_id; --added by Sriram on 22-Nov-2001
2526 
2527        -- Get the Inventory Organization Id
2528 
2529         OPEN  Fetch_Org_Id_Cur;
2530         FETCH Fetch_Org_Id_Cur INTO v_org_id;
2531         CLOSE fetch_Org_Id_Cur;
2532 
2533         /* Commented/Added by brathod, For Bug# 4242351 */
2534         -- OPEN get_po_hdr(v_po_hdr_id);
2535         -- FETCH get_po_hdr into v_rate,v_rate_type,v_rate_date,v_curr;
2536         -- CLOSE get_po_hdr;
2537 
2538         v_rate       :=  p_rate          ;
2539         v_rate_type  :=  p_rate_type     ;
2540         v_rate_date  :=  p_rate_date     ;
2541         v_curr       :=  p_currency_code ;
2542 
2543         /* End of Bug#4242351 */
2544 
2545         IF NVL( v_Line_Location_Id, -999 ) = -999
2546         THEN
2547 
2548           OPEN  Fetch_Dtls_Cur( v_po_Line_Id1 );
2549           FETCH Fetch_Dtls_Cur INTO v_qty, v_price, v_uom;
2550           CLOSE Fetch_Dtls_Cur;
2551 
2552           v_line_uom := v_uom;
2553           line_loc_flag := FALSE;
2554         ELSE
2555 
2556           OPEN  Fetch_Dtls1_Cur( v_Po_Line_Id1, v_Line_Location_Id );
2557           FETCH Fetch_Dtls1_Cur INTO v_qty, v_price, v_uom;
2558           CLOSE Fetch_Dtls1_Cur;
2559 
2560           IF v_uom IS NULL
2561           THEN
2562             FOR uom_rec IN  Fetch_Dtls_Cur( v_Po_Line_Id1 )
2563             LOOP
2564               v_uom := uom_rec.unit_meas_lookup_code;
2565             END LOOP;
2566           END IF;
2567 
2568           line_loc_flag := TRUE;
2569         END IF;
2570 
2571         OPEN  Fetch_UOMCode_Cur;
2572         FETCH Fetch_UOMCode_Cur INTO v_uom;
2573         CLOSE Fetch_UOMCode_Cur;
2574 
2575         OPEN  Fetch_Item_Cur( v_Po_Line_Id1 );
2576         FETCH Fetch_Item_Cur INTO v_item_id;
2577         CLOSE Fetch_Item_Cur;
2578 
2579         v_assessable_value := jai_cmn_setup_pkg.get_po_assessable_value
2580                                                 ( v_vendor_id,
2581                                                   v_vendor_site_id,
2582                                                   v_item_id,
2583                                                   v_uom
2584                                                  );
2585 
2586         v_conv_rate := v_rate;
2587 
2588         jai_po_cmn_pkg.get_functional_curr
2589                               ( v_ship_to_loc_id, v_po_org_id, v_org_id,
2590                                 v_curr, v_assessable_value,
2591                                 v_conv_rate, v_rate_type, v_rate_date, v_func_curr
2592                                );
2593 
2594         IF NVL( v_assessable_value, 0 ) <= 0
2595         THEN
2596           v_assessable_value := v_price * v_qty;
2597         ELSE
2598           v_assessable_value := v_assessable_value * v_qty;
2599         END IF;
2600 
2601         /* Begin - Bug#4250072 - Added by rallamse for VAT */
2602 
2603         ln_vat_assess_value := jai_general_pkg.ja_in_vat_assessable_value (
2604                                                             p_party_id          => v_vendor_id,
2605                                                             p_party_site_id     => v_vendor_site_id,
2606                                                             p_inventory_item_id => v_item_id,
2607                                                             p_uom_code          => v_uom,
2608                                                             p_default_price     => v_price,
2609                                                             p_ass_value_date    => trunc(sysdate) ,
2610                                                             p_party_type        => 'V'
2611                                                           );
2612         v_conv_rate := v_rate;
2613 
2614         jai_po_cmn_pkg.get_functional_curr
2615                           ( v_ship_to_loc_id, v_po_org_id, v_org_id,
2616                             v_curr, ln_vat_assess_value,
2617                             v_conv_rate, v_rate_type, v_rate_date, v_func_curr
2618                            );
2619 
2620         ln_vat_assess_value := ln_vat_assess_value * v_qty ;
2621 
2622         /* End - Bug#4250072  - Added by rallamse for VAT */
2623 
2624         OPEN  Fetch_Focus_Id;
2625         FETCH Fetch_Focus_Id INTO v_next_val;
2626         CLOSE Fetch_Focus_Id;
2627 
2628 v_service_type_code :=jai_ar_rctla_trigger_pkg.get_service_type(v_vendor_id,v_vendor_site_id,'V');
2629 
2630 
2631         INSERT INTO JAI_PO_LINE_LOCATIONS( Line_Focus_Id, Line_Location_Id, Po_Line_Id, Po_Header_Id,
2632            Tax_Modified_Flag, Tax_Amount, Total_Amount,
2633            Creation_Date, Created_By, Last_Update_Date, Last_Updated_By,
2634            Last_Update_Login,Service_type_code )
2635         VALUES
2636           ( v_next_val, v_Line_Location_Id, v_po_line_id1, v_po_hdr_id,
2637            'N', 0, 0,
2638            v_cre_dt, v_cre_by, v_last_upd_dt, v_last_upd_by,
2639            v_last_upd_login,v_service_type_code );
2640 
2641         IF v_type_lookup_code = 'BLANKET' OR
2642              v_quot_class_code = 'CATALOG'
2643         THEN
2644         --Addition by Ramakrishna on 15/12/2000 to check taxes defaulting
2645          if v_line_location_id is null
2646              then
2647                flag := 'INSLINES';
2648              else
2649                flag := 'I';
2650              end if;
2651         --end of addition by Ramakrishna
2652           ELSE
2653             flag := 'I';
2654           END IF;
2655 
2656           jai_po_tax_pkg.Ja_In_Po_Case2( v_Type_Lookup_Code,
2657                                                  v_Quot_Class_Code,
2658                                                  v_Vendor_Id,
2659                                                  v_Vendor_Site_Id,
2660                                                --p_Currency_Code,
2661                                                  v_curr,
2662                                                  v_org_id,
2663                                                  v_Item_Id,
2664                                                  v_Line_Location_Id,
2665                                                  v_po_hdr_id,
2666                                                  v_Po_Line_Id1,
2667                                                  v_price,
2668                                                  v_qty,
2669                                                  v_cre_dt,
2670                                                  v_cre_by,
2671                                                  v_last_upd_dt,
2672                                                  v_last_upd_by,
2673                                                  v_last_upd_login,
2674                                                  v_uom,
2675                                                  flag,
2676                                                  NVL( v_assessable_value, -9999 ),
2677                                                  ln_vat_assess_value,
2678                                                  NVL( v_conv_rate, 1 ) );
2679 
2680        /**    jai_po_tax_pkg.calculate_tax( 'STANDARDPO', v_po_hdr_id , v_Po_Line_Id1, v_line_location_id,
2681                            v_qty, v_price*v_qty, v_uom, v_assessable_value,
2682                            NVL( v_assessable_value, v_price*v_qty ), NULL, nvl(v_conv_rate,1));
2683 
2684 
2685       END LOOP;
2686     END LOOP;**/ --commented by Sriram on 22-Nov-2001
2687 
2688   EXCEPTION
2689     WHEN OTHERS THEN
2690     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
2691     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
2692     app_exception.raise_exception;
2693   END copy_reqn_taxes;
2694 
2695 /* ------------------------------------------------------------------------------------------------------*/
2696 
2697   PROCEDURE calc_tax(
2698   -- Do not use this function to pass line_location_id in place of header_id, use relevant fields to pass
2699   -- the parameters
2700     p_type      IN  VARCHAR2,   -- Contains the type of document
2701     p_header_id   IN  NUMBER,     -- Contains the header_id of the document
2702     P_line_id   IN  NUMBER,     -- Contains the line_id of the document
2703     p_line_location_id  IN  NUMBER,   -- Shipment line_id of the PO Document
2704     p_line_focus_id IN  NUMBER,     -- unique key of JAI_PO_LINE_LOCATIONS table
2705     p_line_quantity IN  NUMBER,     -- quantity given in the line
2706     p_base_value  IN  NUMBER,     -- base value of the line i.e quantity * base price of item
2707     p_line_uom_code IN  VARCHAR2,   -- uom_code of the line item
2708     p_tax_amount  IN OUT NOCOPY  NUMBER,    -- total tax amount that should be returned to the calling procedure
2709     p_assessable_value  IN NUMBER DEFAULT NULL, -- assessable value of line on which excise duty is calculated i.e quantity * assessable_price
2710     p_vat_assess_value  IN NUMBER, -- vat assessable value /* rallamse bug#4250072 VAT */
2711     p_item_id     IN NUMBER DEFAULT NULL, -- inventory item given in the line
2712     p_conv_rate     IN NUMBER DEFAULT NULL, -- Convertion rate from Functional to PO currency
2713     p_po_curr   IN VARCHAR2 DEFAULT NULL, -- PO Header or Requisition line currency
2714     p_func_curr   IN VARCHAR2 DEFAULT NULL,  -- Functional currency of the organization or operating unit
2715     p_requisition_line_id   IN NUMBER   DEFAULT NULL    --Bgowrava for Bug#5877782
2716   , pv_retroprice_changed IN VARCHAR2 DEFAULT 'N' --Added by Kevin Cheng for Retroactive Price on 2008/01/09
2717   ) IS
2718 
2719   -- The parameter p_conv_rate should contain the value which tells the no of FUNCTIONAL currency units for one foreign currency unit
2720   -- i.e functional_curr_tax_amount := PO_curr_tax_amount(foreign currency) * p_conv_rate
2721   -- eg. Amount in INR(FUNCTIONAL) = 1USD(FOREIGN) * 50 (50 is the p_conv_rate)
2722 
2723   /*
2724     Bug#2097413 is fixed on 09-nov-01 by subbu. Bug is raised for adhoc tax amounts are not
2725     coming FROM Requisition to Purchase Order instead adhoc tax amount coming as zero.This bug
2726     solved this bug and also considered Excise type of tax with UOM rate. Earlier this procedure
2727     solved Negative tax amounts bug.
2728   */
2729     TYPE num_tab IS TABLE OF NUMBER/*(14,3)Modified by Kevin Cheng for inclusive tax Dec 17, 2007*/ INDEX BY BINARY_INTEGER;
2730     TYPE tax_amt_num_tab IS TABLE OF NUMBER/*(25,3)Modified by Kevin Cheng for inclusive tax Dec 17, 2007*/ INDEX BY BINARY_INTEGER;
2731     TYPE currency_tab IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
2732     TYPE adhoc_flag_tab IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER; -- added for Bug#2097413
2733     TYPE uom_code_tab IS TABLE OF VARCHAR2(3) INDEX BY BINARY_INTEGER; --pramasub for #6137011
2734 
2735     p1        NUM_TAB;
2736     p2        NUM_TAB;
2737     p3        NUM_TAB;
2738     p4        NUM_TAB;
2739     p5        NUM_TAB;
2740 
2741 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
2742 -- START BUG 5228046
2743 
2744     p6        NUM_TAB;
2745     p7        NUM_TAB;
2746     p8        NUM_TAB;
2747     p9        NUM_TAB;
2748     p10        NUM_TAB;
2749 
2750 -- END BUG 5228046
2751 
2752     rnd_factor                    NUM_TAB;
2753     p_inventory_item_id           NUMBER;
2754     tax_rate_tab                  NUM_TAB;
2755     tax_type_tab                  NUM_TAB;
2756     end_date_tab                  NUM_TAB;
2757     -- This is used mainly for adhoc taxes and not for taxes which has rates attached with them
2758     initial_tax_amt_t            TAX_AMT_NUM_TAB;
2759 
2760     tax_amt_tab                  TAX_AMT_NUM_TAB;
2761     tax_target_tab               TAX_AMT_NUM_TAB;
2762     curr_tab                     CURRENCY_TAB;
2763     adhoc_tab                    ADHOC_FLAG_TAB; -- added for Bug#2097413
2764     qty_tab                      NUM_TAB;
2765     uom_tab                      UOM_CODE_TAB; --pramasub for #6137011
2766 
2767     v_amt                        NUMBER;
2768     bsln_amt                     NUMBER; --File.Sql.35 Cbabu  := p_tax_amount;
2769     row_count                    NUMBER; --File.Sql.35 Cbabu  := 0;
2770     v_tax_amt                    NUMBER/*(25,3) Comment out by Kevin Cheng for bug 6838743 Feb 26, 2008*/; --File.Sql.35 Cbabu  := 0;
2771     vamt                         NUMBER/*(25,3) Comment out by Kevin Cheng for bug 6838743 Feb 26, 2008*/; --File.Sql.35 Cbabu  := 0;
2772     max_iter                     NUMBER  ;  -- Changed from 10 to 15 for bug 5228046
2773     v_conversion_rate            NUMBER;
2774     counter                      NUMBER;
2775     conv_rate                    NUMBER;
2776     v_rnd_factor                 NUMBER;
2777 
2778     v_curr                       VARCHAR2(30); --File.Sql.35 Cbabu   :=  p_line_uom_code;
2779     v_line_uom_code              VARCHAR2(30); --File.Sql.35 Cbabu  := p_line_uom_code;
2780     v_debug                      VARCHAR(1); --File.Sql.35 Cbabu  := 'N'; -- cbabu for Bug# 2659815
2781 
2782     v_adhoc_tax_amt              NUMBER;
2783     v_adhoc_flag                 VARCHAR2(1);
2784     v_qty_rate                   NUMBER;
2785 
2786 
2787     -- start, cbabu for Bug# cbabu for Bug# 2659815
2788     v_conv_rate                  NUMBER;
2789     v_po_curr                    VARCHAR2(30);
2790     v_func_curr                  VARCHAR2(30);
2791     v_sob                        NUMBER;
2792     v_org_id                     NUMBER;
2793 
2794     --Add by Kevin Cheng for inclusive tax Dec 17, 2007
2795     ---------------------------------------------------
2796     TYPE CHAR_TAB IS TABLE OF VARCHAR2(10)
2797     INDEX BY BINARY_INTEGER;
2798 
2799     lt_adhoc_tax_tab             CHAR_TAB;
2800     lt_inclu_tax_tab             CHAR_TAB;
2801     lt_tax_rate_per_rupee        NUM_TAB;
2802     lt_cumul_tax_rate_per_rupee  NUM_TAB;
2803     lt_tax_rate_zero_tab         NUM_TAB;
2804     lt_tax_amt_rate_tax_tab      TAX_AMT_NUM_TAB;
2805     lt_tax_amt_non_rate_tab      TAX_AMT_NUM_TAB;
2806     lt_base_tax_amt_tab          TAX_AMT_NUM_TAB;
2807     lt_func_tax_amt_tab          TAX_AMT_NUM_TAB;
2808     lv_uom_code                  VARCHAR2(10) := 'EA';
2809     lv_register_code             VARCHAR2(20);
2810     ln_exclusive_price           NUMBER;
2811     ln_total_non_rate_tax        NUMBER := 0;
2812     ln_total_inclusive_factor    NUMBER;
2813     ln_bsln_amt_nr               NUMBER :=0;
2814     ln_currency_conv_factor      NUMBER;
2815     ln_tax_amt_nr                NUMBER(38,10) := 0;
2816     ln_func_tax_amt              NUMBER(38,10) := 0;
2817     ln_vamt_nr                   NUMBER(38,10) := 0;
2818     ln_excise_jb                 NUMBER;
2819     ln_total_tax_per_rupee       NUMBER;
2820     ln_assessable_value          NUMBER;
2821     ln_vat_assessable_value      NUMBER;
2822     ---------------------------------------------------
2823     CURSOR c_po_hdr_curr(p_po_header_id IN NUMBER) IS
2824             SELECT currency_code, org_id
2825             FROM po_headers_all
2826             WHERE po_header_id = p_po_header_id;
2827 
2828 /*cursor modified to use headers instead of lines as it is mutating in reqn triggers
2829     for bug#5877782*/
2830     CURSOR c_reqn_curr(p_reqn_header_id IN NUMBER) IS
2831            SELECT  org_id
2832            FROM po_requisition_headers_all
2833            WHERE requisition_header_id = p_reqn_header_id;
2834 
2835 
2836     -- end Changes, cbabu for Bug# cbabu for Bug# 2659815
2837 
2838     /* Bug 5243532. Added by Lakshmi Gopalsami
2839      * Removed cursors c_sob and c_func_curr
2840      * and implemented caching logic.
2841      */
2842 
2843     CURSOR fetch_item_cur IS
2844       SELECT item_id
2845       FROM po_lines_all
2846       WHERE po_line_id = p_line_id;
2847           /* Added by LGOPALSA. Bug 4210102.
2848             Added CVD and Excise education cess
2849           */
2850 
2851     /* start rallamse Bug#4250072 VAT  */
2852     CURSOR c_reqn_line_taxes(p_requisition_line_id IN NUMBER) is
2853     SELECT a.tax_line_no lno,
2854            a.precedence_1 p_1,
2855            a.precedence_2 p_2,
2856            a.precedence_3 p_3,
2857            a.precedence_4 p_4,
2858            a.precedence_5 p_5,
2859            a.precedence_6 p_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
2860            a.precedence_7 p_7,
2861            a.precedence_8 p_8,
2862            a.precedence_9 p_9,
2863            a.precedence_10 p_10,
2864            a.tax_id,
2865            a.tax_rate,
2866            nvl(a.tax_amount, 0) tax_amt,
2867            b.end_date valid_date,
2868            b.rounding_factor rnd_factor,
2869            a.qty_rate,
2870            a.uom uom_code,
2871            a.currency curr,
2872            b.adhoc_flag,
2873            b.inclusive_tax_flag, -- Add by Kevin Cheng for inclusive tax Dec 17, 2007
2874            DECODE( aa.regime_code, 'VAT', 4 ,
2875            DECODE( UPPER( A.Tax_Type ),'EXCISE', 1, 'ADDL. EXCISE', 1, 'OTHER EXCISE', 1, --'CVD', 1,
2876            --'ADDITIONAL_CVD',1,  -- Added by Girish , w.r.t BUG#5143906
2877            --commented the CVD, ADDITIONAL_CVD and cvd_edu_cess for Bug#5219225 by Sanjikum
2878 	   /* added by ssawant for bug 5989740 */
2879            --Comment out by Kevin Cheng for inclusive tax Dec 17, 2007
2880            /*JAI_CONSTANTS.TAX_TYPE_SH_EXC_EDU_CESS,1,jai_constants.tax_type_exc_edu_cess, 1,*/ --,jai_constants.tax_type_cvd_edu_cess, 1,
2881            --Add by Kevin Cheng for inclusive tax Dec 17, 2007
2882            ---------------------------------------------------
2883            jai_constants.tax_type_exc_edu_cess, 6,
2884            jai_constants.tax_type_cvd_edu_cess , 6,
2885            jai_constants.tax_type_sh_exc_edu_cess, 6,
2886            jai_constants.tax_type_sh_cvd_edu_cess, 6,
2887            ---------------------------------------------------
2888            'TDS', 2, 0
2889                  )
2890                  ) tax_type_val
2891      FROM  JAI_PO_REQ_LINE_TAXES a, JAI_CMN_TAXES_ALL b, jai_regime_tax_types_v aa
2892      WHERE requisition_line_id = p_line_id
2893      AND   a.Tax_Id = b.Tax_Id
2894      AND   aa.tax_type(+) = b.tax_type
2895      order by 1/*2*/;--Modified by Kevin Cheng for inclusive tax Dec 17, 2007
2896 
2897     /* Added by LGOPALSA. Bug 4210102.
2898      * Added CVD and Excise education cess
2899      * */
2900 
2901     CURSOR c_po_line_location_taxes(p_po_line_id IN NUMBER, p_line_location_id IN NUMBER) is
2902     SELECT A.Tax_Line_No LNo,
2903            A.Precedence_1 P_1,
2904            A.Precedence_2 P_2,
2905            A.Precedence_3 P_3,
2906            A.Precedence_4 P_4,
2907            A.precedence_5 P_5,
2908            A.Precedence_6 P_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
2909            A.Precedence_7 P_7,
2910            A.Precedence_8 P_8,
2911            A.Precedence_9 P_9,
2912            A.precedence_10 P_10,
2913            A.Tax_Id,
2914            DECODE( aa.regime_code, 'VAT', 4 ,
2915            DECODE( UPPER( A.Tax_Type ),'EXCISE', 1, 'ADDL. EXCISE', 1, 'OTHER EXCISE', 1, --'CVD', 1,
2916            --'ADDITIONAL_CVD',1,  -- Added by Girish , w.r.t BUG#5143906
2917            --commented the CVD, ADDITIONAL_CVD and cvd_edu_cess for Bug#5219225 by Sanjikum
2918 	   /* added by ssawant for bug 5989740 */
2919            --Comment out by Kevin Cheng for inclusive tax Dec 17, 2007
2920            /*JAI_CONSTANTS.TAX_TYPE_SH_EXC_EDU_CESS,1,jai_constants.tax_type_exc_edu_cess, 1,*/ --jai_constants.tax_type_cvd_edu_cess, 1,
2921            --Add by Kevin Cheng for inclusive tax Dec 17, 2007
2922            ---------------------------------------------------
2923            jai_constants.tax_type_exc_edu_cess, 6,
2924            jai_constants.tax_type_cvd_edu_cess , 6,
2925            jai_constants.tax_type_sh_exc_edu_cess, 6,
2926            jai_constants.tax_type_sh_cvd_edu_cess, 6,
2927            ---------------------------------------------------
2928            'TDS', 2, 0
2929                )
2930                ) tax_type_val,
2931            A.Tax_Rate tax_rate,
2932            A.Qty_Rate Qty_Rate,
2933            A.uom uom_code,
2934            A.Tax_Amount,
2935            A.currency curr,
2936            B.End_Date Valid_Date,
2937            B.rounding_factor rnd_factor,
2938            B.adhoc_flag adhoc_flag
2939            ,b.inclusive_tax_flag --Add by Kevin for inclusive tax Dec 17, 2007
2940      FROM  JAI_PO_TAXES A, JAI_CMN_TAXES_ALL B, jai_regime_tax_types_v aa
2941      WHERE Po_Line_Id = p_po_line_id
2942      --AND   nvl(line_location_id,-999) = p_line_location_id
2943      AND   line_location_id = p_line_location_id /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
2944      AND   A.Tax_Id = B.Tax_Id
2945      AND   aa.tax_type(+) = b.tax_type
2946      order by 1/*2*/;--Modified by Kevin Cheng for inclusive tax Dec 17, 2007
2947      /* end rallamse Bug#4250072 VAT implementation */
2948 
2949     CURSOR uom_class_cur(p_line_uom_code IN VARCHAR2, p_tax_line_uom_code IN VARCHAR2) IS
2950       SELECT a.uom_class
2951       FROM mtl_units_of_measure a, mtl_units_of_measure b
2952       WHERE a.uom_code = p_line_uom_code
2953       AND b.uom_code = p_tax_line_uom_code
2954       AND a.uom_class = b.uom_class;
2955 
2956     CURSOR fetch_sum_cur( p_line_location_id IN NUMBER ) IS
2957       SELECT SUM( NVL( tax_amount, 0 ) )
2958       FROM JAI_PO_TAXES
2959       WHERE line_location_id = p_line_location_id   -- For Blanket Rel Line Loc Id is passed in place of header id.
2960       AND tax_type <> jai_constants.tax_type_tds;  --'TDS'; /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
2961 
2962     CURSOR fetch_line_uom_code IS
2963       SELECT uom_code
2964       FROM po_lines_all plines, mtl_units_of_measure units
2965       WHERE plines.po_line_id = p_line_id
2966       AND units.unit_of_measure = plines.unit_meas_lookup_code;
2967 
2968       lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.calc_tax';
2969 
2970       /* Bug 5243532. Added by Lakshmi Gopalsami
2971        * Defined variable for implementing caching logic.
2972        */
2973       l_func_curr_det jai_plsql_cache_pkg.func_curr_details;
2974       -- End for bug 5243532
2975 
2976       /*rchandan for 5961325*/
2977       CURSOR cur_asbn_taxes(cp_source_doc_id NUMBER, cp_source_doc_line_id NUMBER) -- pramasub added cp_source_doc_id for bug #6137011
2978       IS
2979       SELECT A.Tax_Line_No  LNo,
2980              A.Precedence_1 P_1,
2981              A.Precedence_2 P_2,
2982                A.Precedence_3 P_3,
2983                A.Precedence_4 P_4,
2984                A.precedence_5 P_5,
2985                A.Precedence_6 P_6,
2986                A.Precedence_7 P_7,
2987                A.Precedence_8 P_8,
2988                A.Precedence_9 P_9,
2989                A.precedence_10 P_10,
2990                A.Tax_Id,
2991                DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
2992                                                                             'EXCISE', 1,
2993                                                                             'ADDL. EXCISE', 1,
2994                                                                             'OTHER EXCISE', 1,
2995                                                                             --Comment out by Kevin Cheng for inclusive tax Dec 17, 2007
2996                                                                             /*'Excise_Education_cess', 1,
2997                                                                             jai_constants.tax_type_sh_exc_edu_cess,1,*/
2998                                                                             --Add by Kevin Cheng for inclusive tax Dec 17, 2007
2999                                                                             ---------------------------------------------------
3000                                                                             jai_constants.tax_type_exc_edu_cess, 6,
3001                                                                             jai_constants.tax_type_cvd_edu_cess , 6,
3002                                                                             jai_constants.tax_type_sh_exc_edu_cess, 6,
3003                                                                             jai_constants.tax_type_sh_cvd_edu_cess, 6,
3004                                                                             ----------------------------------------------------
3005                                                                             'TDS', 2,
3006                                                                           0)) tax_type_val,
3007                A.Tax_Rate        tax_rate,
3008                A.Qty_Rate        Qty_Rate,
3009                A.uom             uom_code,
3010                A.Tax_Amt         tax_amount,
3011                A.currency_code   curr,
3012                B.End_Date        Valid_Date,
3013                B.rounding_factor rnd_factor,
3014                B.adhoc_flag      adhoc_flag
3015                , b.inclusive_tax_flag --Add by Kevin Cheng for inclusive tax Dec 17, 2007
3016           FROM Jai_cmn_document_Taxes A,
3017                JAI_CMN_TAXES_ALL B,
3018                jai_regime_tax_types_v aa
3019          WHERE source_doc_line_id = cp_source_doc_line_id
3020            AND source_doc_id = cp_source_doc_id --pramasub added this condn for bug #6137011
3021            AND A.Tax_Id = B.Tax_Id
3022            AND aa.tax_type(+) = b.tax_type
3023       ORDER BY 1;
3024 
3025 --Added by Kevin Cheng for Retroactive Price 2008/01/10
3026 --==============================================================================================
3027     /* start rallamse Bug#4250072 VAT  */
3028     CURSOR c_reqn_line_taxes_retro(p_requisition_line_id IN NUMBER) is
3029     SELECT a.tax_line_no lno,
3030            a.precedence_1 p_1,
3031            a.precedence_2 p_2,
3032            a.precedence_3 p_3,
3033            a.precedence_4 p_4,
3034            a.precedence_5 p_5,
3035            a.precedence_6 p_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
3036            a.precedence_7 p_7,
3037            a.precedence_8 p_8,
3038            a.precedence_9 p_9,
3039            a.precedence_10 p_10,
3040            a.tax_id,
3041            a.tax_rate,
3042            nvl(a.tax_amount, 0) tax_amt,
3043            b.end_date valid_date,
3044            b.rounding_factor rnd_factor,
3045            a.qty_rate,
3046            a.uom uom_code,
3047            a.currency curr,
3048            b.adhoc_flag,
3049            DECODE( aa.regime_code, 'VAT', 4 ,
3050            DECODE( UPPER( A.Tax_Type ),'EXCISE', 1, 'ADDL. EXCISE', 1, 'OTHER EXCISE', 1, --'CVD', 1,
3051            --'ADDITIONAL_CVD',1,  -- Added by Girish , w.r.t BUG#5143906
3052            --commented the CVD, ADDITIONAL_CVD and cvd_edu_cess for Bug#5219225 by Sanjikum
3053 	   /* added by ssawant for bug 5989740 */
3054            JAI_CONSTANTS.TAX_TYPE_SH_EXC_EDU_CESS,1,jai_constants.tax_type_exc_edu_cess, 1, --,jai_constants.tax_type_cvd_edu_cess, 1,
3055            'TDS', 2, 0
3056                  )
3057                  ) tax_type_val
3058      FROM  JAI_PO_REQ_LINE_TAXES a, JAI_CMN_TAXES_ALL b, jai_regime_tax_types_v aa
3059      WHERE requisition_line_id = p_line_id
3060      AND   a.Tax_Id = b.Tax_Id
3061      AND   aa.tax_type(+) = b.tax_type
3062      order by 2;
3063 
3064     /* Added by LGOPALSA. Bug 4210102.
3065      * Added CVD and Excise education cess
3066      * */
3067 
3068     CURSOR c_po_line_location_taxes_retro(p_po_line_id IN NUMBER, p_line_location_id IN NUMBER) is
3069     SELECT A.Tax_Line_No LNo,
3070            A.Precedence_1 P_1,
3071            A.Precedence_2 P_2,
3072            A.Precedence_3 P_3,
3073            A.Precedence_4 P_4,
3074            A.precedence_5 P_5,
3075            A.Precedence_6 P_6, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
3076            A.Precedence_7 P_7,
3077            A.Precedence_8 P_8,
3078            A.Precedence_9 P_9,
3079            A.precedence_10 P_10,
3080            A.Tax_Id,
3081            DECODE( aa.regime_code, 'VAT', 4 ,
3082            DECODE( UPPER( A.Tax_Type ),'EXCISE', 1, 'ADDL. EXCISE', 1, 'OTHER EXCISE', 1, --'CVD', 1,
3083            --'ADDITIONAL_CVD',1,  -- Added by Girish , w.r.t BUG#5143906
3084            --commented the CVD, ADDITIONAL_CVD and cvd_edu_cess for Bug#5219225 by Sanjikum
3085 	   /* added by ssawant for bug 5989740 */
3086            JAI_CONSTANTS.TAX_TYPE_SH_EXC_EDU_CESS,1,jai_constants.tax_type_exc_edu_cess, 1, --jai_constants.tax_type_cvd_edu_cess, 1,
3087            'TDS', 2, 0
3088                )
3089                ) tax_type_val,
3090            A.Tax_Rate tax_rate,
3091            A.Qty_Rate Qty_Rate,
3092            A.uom uom_code,
3093            A.Tax_Amount,
3094            A.currency curr,
3095            B.End_Date Valid_Date,
3096            B.rounding_factor rnd_factor,
3097            B.adhoc_flag adhoc_flag
3098            , pha.vendor_id hdr_vendor_id, a.vendor_id tax_vendor_id --Added by Kevin Cheng
3099      FROM  JAI_PO_TAXES A, JAI_CMN_TAXES_ALL B, jai_regime_tax_types_v aa
3100            , po_headers_all pha --Added by Kevin Cheng
3101      WHERE Po_Line_Id = p_po_line_id
3102      --AND   nvl(line_location_id,-999) = p_line_location_id
3103      AND   line_location_id = p_line_location_id /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
3104      AND   A.Tax_Id = B.Tax_Id
3105      AND   pha.po_header_id = A.Po_Header_Id --Added by Kevin Cheng
3106      AND   aa.tax_type(+) = b.tax_type
3107      order by 2;
3108      /* end rallamse Bug#4250072 VAT implementation */
3109 
3110      /*rchandan for 5961325*/
3111       CURSOR cur_asbn_taxes_retro(cp_source_doc_id NUMBER, cp_source_doc_line_id NUMBER) -- pramasub added cp_source_doc_id for bug #6137011
3112       IS
3113       SELECT A.Tax_Line_No  LNo,
3114              A.Precedence_1 P_1,
3115              A.Precedence_2 P_2,
3116                A.Precedence_3 P_3,
3117                A.Precedence_4 P_4,
3118                A.precedence_5 P_5,
3119                A.Precedence_6 P_6,
3120                A.Precedence_7 P_7,
3121                A.Precedence_8 P_8,
3122                A.Precedence_9 P_9,
3123                A.precedence_10 P_10,
3124                A.Tax_Id,
3125                DECODE(aa.regime_code, 'VAT', 4, DECODE( UPPER( A.Tax_Type ),
3126                                                                             'EXCISE', 1,
3127                                                                             'ADDL. EXCISE', 1,
3128                                                                             'OTHER EXCISE', 1,
3129                                                                             'Excise_Education_cess', 1,
3130                                                                             jai_constants.tax_type_sh_exc_edu_cess,1,
3131                                                                             'TDS', 2,
3132                                                                           0)) tax_type_val,
3133                A.Tax_Rate        tax_rate,
3134                A.Qty_Rate        Qty_Rate,
3135                A.uom             uom_code,
3136                A.Tax_Amt         tax_amount,
3137                A.currency_code   curr,
3138                B.End_Date        Valid_Date,
3139                B.rounding_factor rnd_factor,
3140                B.adhoc_flag      adhoc_flag
3141           FROM Jai_cmn_document_Taxes A,
3142                JAI_CMN_TAXES_ALL B,
3143                jai_regime_tax_types_v aa
3144          WHERE source_doc_line_id = cp_source_doc_line_id
3145            AND source_doc_id = cp_source_doc_id --pramasub added this condn for bug #6137011
3146            AND A.Tax_Id = B.Tax_Id
3147            AND aa.tax_type(+) = b.tax_type
3148       ORDER BY 1;
3149 
3150   lv_tax_remain_flag          VARCHAR2(1);
3151   lv_process_flag             VARCHAR2(10);
3152   lv_process_message          VARCHAR2(2000);
3153 --==============================================================================================
3154   BEGIN
3155 
3156   /*--------------------------------------------------------------------------------------------------------------------------
3157   CHANGE HISTORY for FILENAME - ja_in_po_calc_tax_p.sql
3158   S.No  Date  Author and Details
3159   -------------------------------------------------
3160   1.  30/12/2002  cbabu for EnhancementBug# 2427465, FileVersion# 615.1
3161                   This procedure is created with this bug by getting the source from jai_po_tax_pkg.calculate_tax procedure with some modifications
3162                   commented with bug number. Basically two new parameters were added.
3163                   Initially all the plsql tables are filled with PO Currency data and finally when updating these into the database
3164                   they are converted back to the tax currency if there is any change in the currency.
3165 
3166   2.  17/12/2003  Vijay Shankar for Bug# 3324653 (3184673), FileVersion# 618.1
3167                    Cleanedup the code from Currency conversion handling perspective
3168 
3169   3.  12/03/2005  Bug 4210102. Added by LGOPALSA - Version 115.1
3170                   (1) Added check file syntax.
3171       (2) Added NOCOPY for IN OUT Parameters
3172       (3) Added CVD and Excise education cess
3173 
3174   4.  14/03/2005  Bug#4250072. rallamse - Version 115.2
3175                   Changed the cursor query for c_reqn_line_taxes , c_po_line_location_taxes.
3176                   Made changes for VAT implementation
3177 
3178 
3179   5.  04/07/2007  Bgowrava for bug#5877782 , File Version 120.16
3180 		                Issue : TAX CALCULATED INCORRECTLY WHEN REQUISITION QUANTITY IS MODIFIED
3181 		                  Fix : The cursor c_reqn_curr is modified to query from po_requistion_headers_all instead of
3182 		                        po_requistion_lines_all as it was mutating when called from triggers on po_requistion_lines_all.
3183 
3184 	6.  04/07/2007  Bgowrava for bug#5877782 , File Version 120.16
3185 		                Issue : TAX CALCULATED INCORRECTLY WHEN REQUISITION QUANTITY IS MODIFIED
3186 		                  Fix : Added a new parameter p_requisition_line_id to capture the requisition_line_id in case
3187 		                        of REQUISITION_BLANKET as p_line_id would have po_line_id in this case.
3188 		                        In case of requistion Blanket, v_po_curr is not populated at all. Added code to
3189 		                        populate it with p_po_currency.
3190 		                        Commented code to populate v_func_cur if p_func_curr is NULL
3191                         Added standard who columns in all update statements.
3192 
3193   7.  12/17/2007  Kevin Cheng   Update the logic for inclusive tax calculation
3194 
3195   8.  01/15/2008  Kevin Cheng   Add a branch to deal with taxes recalculate for retroactive price update
3196 
3197   9.  02/15/2008  Kevin Cheng   Modify code for bug 6816062.
3198                                 reset non rate tax amount for ad hoc tax in the third calculation loop.
3199 
3200   10. 02/26/2008  Kevin Cheng   Modify code for bug 6838743.
3201                                 Change variable v_tax_amt and vamt definition.
3202                                 Remove precision restriction for these temp
3203                                 variable, so the final result precision will
3204                                 not be affected by them.
3205   ===============================================================================
3206 
3207   Dependencies
3208 
3209   Version   Author     Dependencies    Comments
3210   115.1     LGOPALSA   IN60106 +        Added Cess tax dependency
3211                        4146708
3212 
3213   115.2     rallamse   IN60106 +        Changes for VAT implementation
3214                        4146708 +
3215                        4245089
3216   --------------------------------------------------------------------------------------------------------------------------*/
3217   --Added by Kevin Cheng for Retroactive price 2008/01/10
3218   -------------------------------------------------------
3219   IF pv_retroprice_changed = 'N'
3220   THEN
3221   -------------------------------------------------------
3222    --File.Sql.35 Cbabu
3223     bsln_amt           := p_tax_amount;
3224     row_count          := 0;
3225     v_tax_amt          := 0;
3226     vamt               := 0;
3227     max_iter           := 15;  -- Date 03/11/2006 Bug 5228046 added by SACSETHI
3228     v_curr             :=  p_line_uom_code;
3229     v_line_uom_code    := p_line_uom_code;
3230     v_debug            := jai_constants.no;
3231 
3232   IF v_debug = 'Y' THEN
3233     fnd_file.put_line(fnd_file.log, 'Entered into the procedure 2' );
3234     fnd_file.put_line(fnd_file.log,
3235     -- INSERT INTO mc_debug values ( mc_debug_s.nextval,
3236       ' p_type -> '||p_type|| ' p_header_id -> '||p_header_id||
3237       ' P_line_id -> '||P_line_id|| ' p_line_location_id -> '||p_line_location_id||
3238       ' p_line_focus_id -> '||p_line_focus_id||
3239       ' p_line_quantity -> '||p_line_quantity|| ' p_base_value -> '||p_base_value);
3240     fnd_file.put_line(fnd_file.log, ' p_line_uom_code -> '||p_line_uom_code|| ' p_tax_amount -> '||p_tax_amount||
3241       ' p_assessable_value -> '||p_assessable_value|| ' p_item_id -> '||p_item_id||
3242       ' p_conv_rate -> '||p_conv_rate||
3243       ' p_po_curr -> '||p_po_curr|| ' p_func_curr -> '||p_func_curr
3244     );
3245   END IF;
3246 
3247   v_conv_rate := nvl( p_conv_rate, 1);
3248 /*bgowrava for Bug#5877782*/
3249   IF p_type = 'REQUISITION' THEN
3250     OPEN c_reqn_curr(p_header_id);
3251     FETCH c_reqn_curr INTO  v_org_id;
3252     CLOSE c_reqn_curr;
3253     v_po_curr := p_po_curr; /*bgowrava for Bug#5877782*/
3254   ELSIF p_type in ('REQUISITION_BLANKET','ASBN') THEN
3255     v_po_curr := p_po_curr; /*bgowrava for Bug#5877782*/
3256   ELSE  -- means PO related shipments
3257     OPEN c_po_hdr_curr(p_header_id);
3258     FETCH c_po_hdr_curr INTO v_po_curr, v_org_id;
3259     CLOSE c_po_hdr_curr;
3260   END IF;
3261 
3262  /* IF p_func_curr IS NULL THEN
3263     Bug 5243532. Added by Lakshmi Gopalsami
3264      * Removed cursors c_sob and c_func_curr
3265      * and implemented caching logic.
3266 
3267    l_func_curr_det       := jai_plsql_cache_pkg.return_sob_curr
3268                             (p_org_id  => v_org_id );
3269    v_sob                 := l_func_curr_det.ledger_id;
3270    v_func_curr           := l_func_curr_det.currency_code;
3271   ELSE
3272     v_func_curr := p_func_curr;
3273   END IF;*/
3274 
3275   /*
3276 	||bgowrava for bug#5877782. Commented the above code and added the following line
3277 	||p_func_curr is nowhere being used so it is not required at all.
3278 	*/
3279   v_func_curr := p_func_curr;
3280 
3281   IF p_type = 'REQUISITION' THEN
3282 
3283     IF p_item_id IS NULL THEN
3284       OPEN  Fetch_Item_Cur;
3285       FETCH Fetch_Item_Cur INTO p_inventory_item_id;
3286       CLOSE Fetch_Item_Cur;
3287     ELSE
3288       p_inventory_item_id := p_item_id;
3289     END IF;
3290 
3291     IF p_line_uom_code IS NULL THEN
3292       OPEN  Fetch_line_uom_code;
3293       FETCH Fetch_line_uom_code INTO v_line_uom_code;
3294       CLOSE Fetch_line_uom_code;
3295     END IF;
3296 
3297     FOR rec in c_reqn_line_taxes(p_line_id) LOOP
3298 
3299       P1(rec.lno) := nvl(rec.p_1,-1);
3300       P2(rec.lno) := nvl(rec.p_2,-1);
3301       P3(rec.lno) := nvl(rec.p_3,-1);
3302       P4(rec.lno) := nvl(rec.p_4,-1);
3303       P5(rec.lno) := nvl(rec.p_5,-1);
3304 
3305       -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
3306       -- start bug#5228046
3307       P6(rec.lno) := nvl(rec.p_6,-1);
3308       P7(rec.lno) := nvl(rec.p_7,-1);
3309       P8(rec.lno) := nvl(rec.p_8,-1);
3310       P9(rec.lno) := nvl(rec.p_9,-1);
3311       P10(rec.lno) := nvl(rec.p_10,-1);
3312       -- end bug#5228046
3313 
3314       rnd_factor(rec.lno) := nvl(rec.rnd_factor,0);
3315       tax_rate_tab(rec.lno) := nvl(rec.tax_rate,0);
3316       curr_tab(rec.lno) := nvl(rec.curr, v_po_curr);
3317 
3318       -- if tax_type is based on tax_rate then variable should be initialized with 0,
3319       -- if tax_type is ADHOC or UNIT RATE then they are handled later in the loop
3320       tax_amt_tab(rec.lno)  := 0;   -- nvl(rec.tax_amt,0);
3321       tax_target_tab(rec.lno) := 0;
3322       initial_tax_amt_t(rec.lno) := 0;
3323       tax_type_tab(rec.lno) := rec.tax_type_val;
3324       adhoc_tab(rec.lno) := nvl(rec.adhoc_flag, 'N');
3325       qty_tab(rec.lno) := rec.qty_rate;
3326       uom_tab(rec.lno) := rec.uom_code; --pramasub for #6066485
3327 
3328       --Add by Kevin Cheng for inclusive tax Dec 17, 2007
3329       ---------------------------------------------------
3330       lt_tax_rate_per_rupee(rec.lno) := NVL(rec.tax_rate,0)/100;
3331       ln_total_tax_per_rupee         := 0;
3332       lt_inclu_tax_tab(rec.lno)      := NVL(rec.inclusive_tax_flag,'N');
3333 
3334       IF rec.tax_rate is null THEN
3335         lt_tax_rate_zero_tab(rec.lno) := 0;
3336       ELSIF rec.tax_rate = 0 THEN
3337         lt_tax_rate_zero_tab(rec.lno) := -9999;
3338       ELSE
3339         lt_tax_rate_zero_tab(rec.lno) := rec.tax_rate;
3340       END IF;
3341 
3342       lt_tax_amt_rate_tax_tab(rec.lno) := 0;
3343       lt_tax_amt_non_rate_tab(rec.lno) := 0; --tax inclusive
3344       lt_base_tax_amt_tab(rec.lno)     := 0;
3345       ---------------------------------------------------
3346 
3347       -- this condition will take care of the ADHOC taxes
3348       IF adhoc_tab(rec.lno) = 'Y' THEN
3349 
3350         tax_rate_tab(rec.lno) :=  -99999;
3351         /*tax_amt_tab(rec.lno)  := rec.tax_amt;*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3352         initial_tax_amt_t(rec.lno) := rec.tax_amt;
3353         tax_target_tab(rec.lno) := rec.tax_amt;
3354         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3355         ---------------------------------------------------
3356         lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.tax_amt, 0);   -- tax inclusive
3357         lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
3358         ---------------------------------------------------
3359 
3360       -- this condition will take care of the taxes that are UNIT RATE based , rec.qty_rate <> 0
3361       ELSIF adhoc_tab(rec.lno) = 'N' AND tax_rate_tab(rec.lno) = 0 THEN
3362         v_conversion_rate := 0;
3363         FOR uom_cls IN uom_class_cur(v_line_uom_code, rec.uom_code) LOOP
3364           INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, p_inventory_item_id, v_conversion_rate);
3365           IF nvl(v_conversion_rate, 0) <= 0 THEN
3366             INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, 0, v_conversion_rate);
3367             IF nvl(v_conversion_rate, 0) <= 0  THEN
3368                v_conversion_rate := 0;
3369             END IF;
3370           END IF;
3371         tax_rate_tab( rec.lno ) := -99999;
3372         --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3373         --tax_amt_tab(rec.lno) := round(nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity,nvl(rec.rnd_factor,0));/*4281841*/
3374         initial_tax_amt_t(rec.lno) := round(nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity,nvl(rec.rnd_factor,0));/*4281841*/
3375         --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3376         --tax_target_tab(rec.lno) := tax_amt_tab(rec.lno);
3377         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3378         ---------------------------------------------------
3379         lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;   -- tax inclusive
3380         lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
3381         tax_target_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno);
3382         ---------------------------------------------------
3383         END LOOP;
3384       END IF;
3385 
3386       -- here we have to convert the tax_currency (func currency in case of foreign PO) into PO currency, so that all the
3387       -- taxes will be calculated in PO currency initially, then later while modifying them in database, then change them
3388       -- back to the tax currency
3389       -- ex. IF FUNCTIONAL CURRENCY -> USD, PO CURRENCY -> INR, TAX CURRENCY -> USD, then the if condition is satisfied
3390       IF curr_tab(rec.lno) <> v_po_curr THEN
3391       -- the following two lines are commented as the tax_amt becomes zero after this code execution (For UOM based rax lines in Reqn) pramasub #6066485
3392        -- tax_amt_tab(rec.lno)  := tax_amt_tab(rec.lno) / v_conv_rate;
3393        -- tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
3394         tax_target_tab(rec.lno) := tax_target_tab(rec.lno) / v_conv_rate;
3395       END IF;
3396 
3397       IF rec.Valid_Date is NULL OR rec.Valid_Date >= Sysdate THEN
3398         End_Date_Tab(rec.lno) := 1;
3399       ELSE
3400         End_Date_Tab(rec.lno) := 0;
3401         tax_amt_tab(rec.lno)  := 0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3402       END IF;
3403 
3404       row_count := row_count + 1;
3405     END LOOP;
3406 
3407   ELSIF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO' ) THEN
3408 
3409     IF p_item_id IS NULL THEN
3410       OPEN  Fetch_Item_Cur;
3411       FETCH Fetch_Item_Cur INTO p_inventory_item_id;
3412       CLOSE Fetch_Item_Cur;
3413     ELSE
3414       p_inventory_item_id := p_item_id;
3415     END IF;
3416 
3417 
3418 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
3419     /*4281841 */
3420      IF p_line_uom_code IS NULL and p_type = 'REQUISITION_BLANKET' THEN
3421       /* OPEN  fetch_req_uom_code;
3422        FETCH fetch_req_uom_code INTO v_line_uom_code;
3423        CLOSE fetch_req_uom_code;*/null;
3424      END IF;
3425 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
3426 
3427     FOR rec in c_po_line_location_taxes(p_line_id, p_line_location_id) LOOP
3428 
3429       P1(rec.lno) := nvl(rec.p_1,-1);
3430       P2(rec.lno) := nvl(rec.p_2,-1);
3431       P3(rec.lno) := nvl(rec.p_3,-1);
3432       P4(rec.lno) := nvl(rec.p_4,-1);
3433       P5(rec.lno) := nvl(rec.p_5,-1);
3434 
3435 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
3436 -- START BUG 5228046
3437 
3438       P6(rec.lno) := nvl(rec.p_6,-1);
3439       P7(rec.lno) := nvl(rec.p_7,-1);
3440       P8(rec.lno) := nvl(rec.p_8,-1);
3441       P9(rec.lno) := nvl(rec.p_9,-1);
3442       P10(rec.lno) := nvl(rec.p_10,-1);
3443 
3444 -- END BUG 5228046
3445 
3446 
3447       rnd_factor(rec.lno) := nvl(rec.rnd_factor,0);
3448       tax_rate_tab(rec.lno) := nvl(rec.tax_rate,0);
3449       tax_type_tab(rec.lno) := rec.tax_type_val;
3450       adhoc_tab(rec.lno) := nvl(rec.adhoc_flag,'N'); -- added for bug#2097413
3451       qty_tab(rec.lno) := rec.qty_rate; -- added for bug#2097413
3452 
3453       curr_tab(rec.lno) := nvl( rec.curr, v_po_curr); -- p_po_curr);  -- v_curr );
3454       tax_amt_tab(rec.lno) := 0;
3455       initial_tax_amt_t(rec.lno) := 0;
3456       tax_target_tab(rec.lno) := 0;
3457 
3458       --Add by Kevin Cheng for inclusive tax Dec 17, 2007
3459       ---------------------------------------------------
3460       lt_tax_rate_per_rupee(rec.lno) := NVL(rec.tax_rate,0)/100;
3461       ln_total_tax_per_rupee         := 0;
3462       lt_inclu_tax_tab(rec.lno)      := NVL(rec.inclusive_tax_flag,'N');
3463 
3464       IF rec.tax_rate is null THEN
3465         lt_tax_rate_zero_tab(rec.lno) := 0;
3466       ELSIF rec.tax_rate = 0 THEN
3467         lt_tax_rate_zero_tab(rec.lno) := -9999;
3468       ELSE
3469         lt_tax_rate_zero_tab(rec.lno) := rec.tax_rate;
3470       END IF;
3471 
3472       lt_tax_amt_rate_tax_tab(rec.lno) := 0;
3473       lt_tax_amt_non_rate_tab(rec.lno) := 0; --tax inclusive
3474       lt_base_tax_amt_tab(rec.lno)     := 0;
3475       ---------------------------------------------------
3476 
3477       -- start of modifications for Bug#2097413
3478       -- IF nvl(rec.tax_rate,0) = 0 AND nvl(rec.qty_rate,0) = 0 and nvl(rec.adhoc_flag,'N') = 'Y' THEN
3479       IF adhoc_tab(rec.lno) = 'Y' THEN
3480 
3481         tax_rate_tab(rec.lno) :=  -99999;
3482         /*tax_amt_tab(rec.lno) := nvl(rec.tax_amount,0);*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3483         initial_tax_amt_t(rec.lno) := nvl(rec.tax_amount,0);
3484         tax_target_tab(rec.lno) := nvl(rec.tax_amount,0);
3485         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3486         ---------------------------------------------------
3487         lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.tax_amount, 0);   -- tax inclusive
3488         lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
3489         ---------------------------------------------------
3490 
3491      ELSIF adhoc_tab(rec.lno) = 'N' AND qty_tab(rec.lno) <> 0 THEN -- tax_rate_tab(rec.lno) = 0 THEN
3492 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
3493         v_conversion_rate := 0;
3494       FOR uom_cls IN uom_class_cur(v_line_uom_code, rec.uom_code) LOOP
3495         INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, p_inventory_item_id, v_conversion_rate);
3496         IF nvl(v_conversion_rate, 0) <= 0 THEN
3497           INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, 0, v_conversion_rate);
3498           IF nvl(v_conversion_rate, 0) <= 0  THEN
3499             v_conversion_rate := 0;
3500           END IF;
3501         END IF;
3502       END LOOP;
3503       tax_rate_tab( rec.lno ) := -99999;
3504       --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3505       /*tax_amt_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
3506       tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));\*4281841*\*/
3507       initial_tax_amt_t(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
3508       --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3509       --tax_target_tab(rec.lno) := tax_amt_tab( rec.lno );
3510       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3511       ---------------------------------------------------
3512       lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;   -- tax inclusive
3513       --lt_tax_amt_non_rate_tab(rec.lno) := round(lt_tax_amt_non_rate_tab(rec.lno),nvl(rec.rnd_factor,0));
3514       lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
3515       tax_target_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno);
3516       ---------------------------------------------------
3517     END IF;
3518 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
3519 
3520       -- THIS IS THE MAIN CHANGE FOR THE BUG# cbabu for Bug# 2659815
3521       -- here we have to convert the tax_currency (func currency in case of foreign PO) into PO currency, so that all the
3522       -- taxes will be calculated in PO currency initially, then later while modifying them in database, then change them
3523       -- back to the tax currency
3524       -- ex. FUNCTIONAL CURRENCY -> USD, PO CURRENCY -> INR, TAX CURRENCY -> USD, then the if condition is satisfied
3525 
3526       IF curr_tab(rec.lno) <> v_po_curr THEN
3527          --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3528          /*tax_amt_tab(rec.lno)  := tax_amt_tab(rec.lno) * v_conv_rate; -- YYYYYYYY
3529          tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));\*4281841*\*/
3530          --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3531          ---------------------------------------------------
3532          lt_tax_amt_non_rate_tab(rec.lno)  := lt_tax_amt_non_rate_tab(rec.lno) * v_conv_rate; -- YYYYYYYY
3533          --lt_tax_amt_non_rate_tab(rec.lno) := round(lt_tax_amt_non_rate_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
3534          ---------------------------------------------------
3535          tax_target_tab(rec.lno) := tax_target_tab(rec.lno) * v_conv_rate; -- YYYYYYY
3536       END IF;
3537       --end, cbabu for Bug# 2659815
3538 
3539       IF rec.Valid_Date is NULL Or rec.Valid_Date >= SYSDATE THEN
3540         end_date_tab(rec.lno) := 1;
3541       ELSE
3542         end_date_tab(rec.lno) := 0;
3543         tax_amt_tab(rec.lno)  := 0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3544       END IF;
3545 
3546       row_count := row_count + 1;
3547 
3548     END LOOP;
3549  ELSIF p_type IN  ( 'ASBN' ) THEN /*rchandan for 5961325*/
3550 
3551   FOR rec in cur_asbn_taxes( p_header_id, p_line_id ) LOOP -- pramasub added p_header_id for bug #6137011
3552 
3553     P1(rec.lno) := nvl(rec.p_1,-1);
3554     P2(rec.lno) := nvl(rec.p_2,-1);
3555     P3(rec.lno) := nvl(rec.p_3,-1);
3556     P4(rec.lno) := nvl(rec.p_4,-1);
3557     P5(rec.lno) := nvl(rec.p_5,-1);
3558     P6(rec.lno) := nvl(rec.p_6,-1);
3559     P7(rec.lno) := nvl(rec.p_7,-1);
3560     P8(rec.lno) := nvl(rec.p_8,-1);
3561     P9(rec.lno) := nvl(rec.p_9,-1);
3562     P10(rec.lno) := nvl(rec.p_10,-1);
3563 
3564     rnd_factor(rec.lno)   := nvl(rec.rnd_factor,0);
3565     tax_rate_tab(rec.lno) := nvl(rec.tax_rate,0);
3566     tax_type_tab(rec.lno) := rec.tax_type_val;
3567     adhoc_tab(rec.lno)    := nvl(rec.adhoc_flag,'N'); -- added for bug#2097413
3568     qty_tab(rec.lno)      := rec.qty_rate; -- added for bug#2097413
3569     uom_tab(rec.lno)      := rec.uom_code; --pramasub for #6137011
3570 
3571     curr_tab(rec.lno)          := nvl( rec.curr, v_po_curr); -- p_po_curr);  -- v_curr );
3572     tax_amt_tab(rec.lno)       := 0;
3573     initial_tax_amt_t(rec.lno) := 0;
3574     tax_target_tab(rec.lno)    := 0;
3575 
3576     --Add by Kevin Cheng for inclusive tax Dec 17, 2007
3577     ---------------------------------------------------
3578     lt_tax_rate_per_rupee(rec.lno) := NVL(rec.tax_rate,0)/100;
3579     ln_total_tax_per_rupee         := 0;
3580     lt_inclu_tax_tab(rec.lno)      := NVL(rec.inclusive_tax_flag,'N');
3581 
3582     IF rec.tax_rate is null THEN
3583       lt_tax_rate_zero_tab(rec.lno) := 0;
3584     ELSIF rec.tax_rate = 0 THEN
3585       lt_tax_rate_zero_tab(rec.lno) := -9999;
3586     ELSE
3587       lt_tax_rate_zero_tab(rec.lno) := rec.tax_rate;
3588     END IF;
3589 
3590     lt_tax_amt_rate_tax_tab(rec.lno) := 0;
3591     lt_tax_amt_non_rate_tab(rec.lno) := 0; --tax inclusive
3592     lt_base_tax_amt_tab(rec.lno)     := 0;
3593     ---------------------------------------------------
3594 
3595     IF adhoc_tab(rec.lno) = 'Y' THEN
3596 
3597       tax_rate_tab(rec.lno)      :=  -99999;
3598       /*tax_amt_tab(rec.lno)       := nvl(rec.tax_amount,0);*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3599       initial_tax_amt_t(rec.lno) := nvl(rec.tax_amount,0);
3600       tax_target_tab(rec.lno)    := nvl(rec.tax_amount,0);
3601       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3602       ---------------------------------------------------
3603       lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.tax_amount, 0);   -- tax inclusive
3604       lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
3605       ---------------------------------------------------
3606 
3607     ELSIF adhoc_tab(rec.lno) = 'N' AND qty_tab(rec.lno) <> 0 THEN
3608         v_conversion_rate := 0;
3609       FOR uom_cls IN uom_class_cur(v_line_uom_code, rec.uom_code) LOOP
3610         INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, p_inventory_item_id, v_conversion_rate);
3611         IF nvl(v_conversion_rate, 0) <= 0 THEN
3612           INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, 0, v_conversion_rate);
3613           IF nvl(v_conversion_rate, 0) <= 0  THEN
3614             v_conversion_rate := 0;
3615           END IF;
3616         END IF;
3617       END LOOP;
3618       tax_rate_tab( rec.lno ) := -99999;
3619       --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3620       /*tax_amt_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
3621       tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));\*4281841*\*/
3622       initial_tax_amt_t(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
3623       --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3624       --tax_target_tab(rec.lno) := tax_amt_tab( rec.lno );
3625       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3626       ---------------------------------------------------
3627       lt_tax_amt_non_rate_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;   -- tax inclusive
3628       --lt_tax_amt_non_rate_tab(rec.lno) := round(lt_tax_amt_non_rate_tab(rec.lno),nvl(rec.rnd_factor,0));
3629       lt_base_tax_amt_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno); -- tax inclusive
3630       tax_target_tab(rec.lno) := lt_tax_amt_non_rate_tab(rec.lno);
3631       ---------------------------------------------------
3632     END IF;
3633 
3634     IF curr_tab(rec.lno) <> v_po_curr THEN
3635       --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3636       /*tax_amt_tab(rec.lno)  := tax_amt_tab(rec.lno) * v_conv_rate; -- YYYYYYYY
3637       tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));\*4281841*\*/
3638       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3639       ---------------------------------------------------
3640       lt_tax_amt_non_rate_tab(rec.lno)  := lt_tax_amt_non_rate_tab(rec.lno) * v_conv_rate; -- YYYYYYYY
3641       --lt_tax_amt_non_rate_tab(rec.lno) := round(lt_tax_amt_non_rate_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
3642       ---------------------------------------------------
3643       tax_target_tab(rec.lno) := tax_target_tab(rec.lno) * v_conv_rate; -- YYYYYYY
3644     END IF;
3645     --end, cbabu for Bug# 2659815
3646 
3647     IF rec.Valid_Date is NULL Or rec.Valid_Date >= SYSDATE THEN
3648       end_date_tab(rec.lno) := 1;
3649     ELSE
3650       end_date_tab(rec.lno) := 0;
3651       tax_amt_tab(rec.lno)  := 0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3652     END IF;
3653 
3654     row_count := row_count + 1;
3655 
3656   END LOOP;
3657 
3658   END IF;
3659 
3660   bsln_amt := p_base_value;
3661 
3662   --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3663   ---------------------------------------------------
3664   IF p_vat_assess_value <> p_base_value THEN
3665     ln_vat_assessable_value := p_vat_assess_value;
3666   ELSE
3667     ln_vat_assessable_value := 1;
3668   END IF;
3669 
3670   IF p_assessable_value <> p_base_value THEN
3671     ln_assessable_value := p_assessable_value;
3672   ELSE
3673     ln_assessable_value := 1;
3674   END IF;
3675   ---------------------------------------------------
3676 
3677   FOR i in 1..row_count LOOP
3678     IF end_date_tab(I) <> 0 THEN--Add by Kevin Cheng for inclusive tax Dec 18, 2007
3679     --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3680     /*IF tax_type_tab(i) = 1 THEN
3681       bsln_amt := NVL( p_assessable_value, p_base_value );
3682      \* start rallamse bug#4250072 VAT *\
3683     ELSIF tax_type_tab(i) = 4 THEN
3684       bsln_amt := NVL( p_vat_assess_value, p_base_value );
3685     \* end rallamse Bug#4250072 VAT *\
3686     ELSE
3687       bsln_amt := p_base_value;
3688     END IF;*/
3689       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3690       ---------------------------------------------------
3691       IF tax_type_tab(I) = 1
3692       THEN
3693         IF ln_assessable_value = 1
3694         THEN
3695           bsln_amt := 1;
3696           ln_bsln_amt_nr := 0;
3697         ELSE
3698           bsln_amt := 0;
3699           ln_bsln_amt_nr := ln_assessable_value;
3700         END IF;
3701       ELSIF tax_type_tab(I) = 4
3702       THEN --IF tax_type_tab(I) = 1   THEN
3703         IF ln_vat_assessable_value = 1
3704         THEN
3705           bsln_amt := 1;
3706 		      ln_bsln_amt_nr := 0;
3707         ELSE
3708           bsln_amt := 0;
3709           ln_bsln_amt_nr := ln_vat_assessable_value;
3710         END IF;
3711       ELSIF tax_type_tab(I) = 6
3712       THEN  --IF tax_type_tab(I) = 1   THEN
3713         bsln_amt := 0;
3714         ln_bsln_amt_nr := 0;
3715       ELSE --IF tax_type_tab(I) = 1   THEN
3716         bsln_amt := 1;
3717         ln_bsln_amt_nr := 0;
3718       END IF; --IF tax_type_tab(I) = 1   THEN
3719       ---------------------------------------------------
3720 
3721       IF tax_rate_tab(I) <> 0 THEN --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3722 
3723     IF p1(I) < I and p1(I) not in (-1,0) then
3724       vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
3725       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P1(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3726     ELSIF p1(I) = 0 then
3727       vamt  := vamt + bsln_amt;
3728       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3729     END IF;
3730 
3731     IF p2(I) < I and p2(I) not in (-1,0) then
3732       vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
3733       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P2(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3734     ELSIF p2(I) = 0 then
3735       vamt  := vamt + bsln_amt;
3736       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3737     END IF;
3738 
3739     IF p3(I) < I and p3(I) not in (-1,0) then
3740       vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
3741       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P3(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3742     ELSIF p3(I) = 0 then
3743       vamt  := vamt + bsln_amt;
3744       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3745     END IF;
3746 
3747     IF p4(I) < I and p4(I) not in (-1,0) then
3748       vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
3749       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P4(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3750     ELSIF p4(I) = 0 then
3751       vamt  := vamt + bsln_amt;
3752       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3753     END IF;
3754 
3755     IF p5(I) < I and p5(I) not in (-1,0) then
3756       vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
3757       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P5(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3758     ELSIF p5(I) = 0 then
3759       vamt  := vamt + bsln_amt;
3760       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3761     END IF;
3762 
3763 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
3764 -- START BUG 5228046
3765 
3766     IF p6(I) < I and p6(I) not in (-1,0) then
3767       vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
3768       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P6(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3769     ELSIF p6(I) = 0 then
3770       vamt  := vamt + bsln_amt;
3771       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3772     END IF;
3773 
3774     IF p7(I) < I and p7(I) not in (-1,0) then
3775       vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
3776       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P7(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3777     ELSIF p7(I) = 0 then
3778       vamt  := vamt + bsln_amt;
3779       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3780     END IF;
3781 
3782     IF p8(I) < I and p8(I) not in (-1,0) then
3783       vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
3784       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P8(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3785     ELSIF p8(I) = 0 then
3786       vamt  := vamt + bsln_amt;
3787       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3788     END IF;
3789 
3790     IF p9(I) < I and p9(I) not in (-1,0) then
3791       vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
3792       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P9(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3793     ELSIF p9(I) = 0 then
3794       vamt  := vamt + bsln_amt;
3795       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3796     END IF;
3797 
3798     IF p10(I) < I and p10(I) not in (-1,0) then
3799       vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
3800       ln_vamt_nr  := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(P10(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3801     ELSIF p10(I) = 0 then
3802       vamt  := vamt + bsln_amt;
3803       ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3804     END IF;
3805 
3806 -- END BUG 5228046
3807 
3808     IF tax_rate_tab(I) <> -99999 THEN
3809       v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
3810       IF END_date_tab(I) = 0 then
3811         tax_amt_tab(I) := 0;
3812       ELSIF END_date_tab(I) = 1 then
3813         tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
3814       END IF;
3815     ELSE
3816       tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
3817     END IF;
3818     --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3819     --tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
3820     --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3821     /*vamt      := 0;
3822     v_tax_amt := 0;*/
3823     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3824     ---------------------------------------------------
3825         ln_tax_amt_nr := ln_tax_amt_nr + (ln_vamt_nr * (tax_rate_tab(I)/100));
3826         lt_base_tax_amt_tab(I) := vamt;
3827         lt_tax_amt_non_rate_tab(I) := NVL(lt_tax_amt_non_rate_tab(I),0) + ln_tax_amt_nr;
3828         lt_tax_amt_rate_tax_tab(i) := tax_amt_tab(I);
3829         vamt := 0;
3830         v_tax_amt := 0;
3831         ln_tax_amt_nr := 0;
3832         ln_vamt_nr := 0;
3833 
3834       END IF; --IF tax_rate_tab(I) <> 0 THEN
3835     ELSE --IF end_date_tab(I) <> 0 THEN
3836       tax_amt_tab(I) := 0;
3837       lt_base_tax_amt_tab(I) := 0;
3838     END IF; --IF end_date_tab(I) <> 0 THEN
3839     ---------------------------------------------------
3840   END LOOP;
3841   --i := null;
3842 
3843   FOR i in 1..row_count LOOP
3844     --i := v_taxid_tab(j);
3845     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3846     ---------------------------------------------------
3847     IF end_date_tab( I ) <> 0 THEN
3848       IF tax_rate_tab(I) <> 0 THEN
3849     ---------------------------------------------------
3850     IF p1(I) > I then
3851       vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
3852       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p1(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3853     END IF;
3854 
3855     IF p2(I) > I  then
3856       vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
3857       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p2(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3858     END IF;
3859 
3860     IF p3(I) > I  then
3861       vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
3862       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p3(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3863     END IF;
3864 
3865     IF p4(I) > I then
3866       vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
3867       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p4(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3868     END IF;
3869 
3870     IF p5(I) > I then
3871       vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
3872       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p5(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3873     END IF;
3874 
3875 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
3876 -- START BUG 5228046
3877 
3878     IF p6(I) > I then
3879       vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
3880       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p6(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3881     END IF;
3882 
3883     IF p7(I) > I  then
3884       vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
3885       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p7(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3886     END IF;
3887 
3888     IF p8(I) > I  then
3889       vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
3890       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p8(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3891     END IF;
3892 
3893     IF p9(I) > I then
3894       vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
3895       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p9(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3896     END IF;
3897 
3898     IF p10(I) > I then
3899       vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
3900       ln_vamt_nr := ln_vamt_nr + NVL(lt_tax_amt_non_rate_tab(p10(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3901     END IF;
3902 
3903 -- END BUG 5228046
3904 
3905     IF tax_rate_tab(I) <> -99999 THEN
3906       v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
3907       IF END_date_tab(I) = 0 then
3908         tax_amt_tab(I) := 0;
3909       ELSIF END_date_tab(I) = 1 then
3910         tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
3911       END IF;
3912     ELSE -- added for Bug#2097413
3913       tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
3914     END IF;
3915 
3916 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
3917     --tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3918 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
3919 
3920     --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3921     /*vamt      := 0;
3922     v_tax_amt := 0;*/
3923     --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3924     ---------------------------------------------------
3925         lt_base_tax_amt_tab(I) := vamt;
3926         ln_tax_amt_nr := ln_tax_amt_nr + (ln_vamt_nr * (tax_rate_tab(I)/100));
3927         IF vamt <> 0
3928         THEN
3929           lt_base_tax_amt_tab(I) := lt_base_tax_amt_tab(I) + vamt;
3930         END IF;
3931         lt_tax_amt_non_rate_tab(I) := NVL(lt_tax_amt_non_rate_tab(I),0) + ln_tax_amt_nr ;
3932         lt_tax_amt_rate_tax_tab(i) := tax_amt_tab(I);
3933         vamt := 0;
3934         ln_vamt_nr := 0;
3935         v_tax_amt := 0;
3936         ln_tax_amt_nr := 0;
3937       END IF; --IF tax_rate_tab(I) <> 0 THEN
3938 
3939     ELSE --IF end_date_tab( I ) <> 0 THEN
3940       lt_base_tax_amt_tab(I) := vamt;
3941       tax_amt_tab(I) := 0;
3942     END IF; --IF end_date_tab( I ) <> 0 THEN
3943     ---------------------------------------------------
3944   END LOOP;
3945   --i := null;
3946 
3947   FOR counter IN 1 .. max_iter LOOP
3948     vamt := 0;
3949     v_tax_amt := 0;
3950     ln_vamt_nr:= 0;   --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3951     ln_tax_amt_nr:=0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3952 
3953     FOR i in 1..row_count LOOP
3954       --i := v_taxid_tab(j);
3955 
3956       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3957       IF ( tax_rate_tab( i ) <> 0 OR lt_tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
3958       --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3959       /*IF tax_rate_tab( i ) <> 0 AND End_Date_Tab(I) <> 0
3960         AND adhoc_tab(i) <> 'Y' AND qty_tab(i) IS NULL
3961       THEN*/
3962       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3963       IF adhoc_tab(i) <> 'Y' AND qty_tab(i) IS NULL
3964       THEN
3965         -- added extra condition AND adhoc_tab(i) <> 'Y' , qty_tab(i) IS NULL for Bug#2097413
3966         IF tax_type_tab( i ) = 1 THEN
3967           --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3968           ------------------------------------------------
3969           IF ln_assessable_value = 1
3970           THEN
3971             v_amt:=1;
3972             ln_bsln_amt_nr :=0;
3973           ELSE --IF ln_assessable_value = 1
3974             v_amt :=0;
3975             ln_bsln_amt_nr :=ln_assessable_value;
3976           END IF;
3977           ------------------------------------------------
3978           /*v_amt := NVL( p_assessable_value, p_base_value );*/--Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3979         /* start rallamse Bug#4250072 VAT */
3980         ELSIF tax_type_tab(i) = 4 THEN
3981           --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3982           ------------------------------------------------
3983           IF ln_vat_assessable_value = 1
3984           THEN
3985             v_amt:=1;
3986             ln_bsln_amt_nr :=0;
3987           ELSE --IF ln_vat_assessable_value = 1
3988             v_amt :=0;
3989             ln_bsln_amt_nr :=ln_vat_assessable_value;
3990           END IF;
3991           ------------------------------------------------
3992           /*v_amt := NVL( p_vat_assess_value, p_base_value );*/--Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
3993         /* end rallamse Bug#4250072 VAT */
3994         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
3995         -------------------------------------
3996         ELSIF tax_type_tab(I) = 6 THEN
3997           v_amt:=0;
3998           ln_bsln_amt_nr :=0;
3999         -------------------------------------
4000         ELSIF v_amt = 0 OR tax_type_tab(i) <> 1 THEN
4001           /*v_amt := p_base_value;*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
4002           v_amt          := 1; --Added by Kevin Cheng for inclusive tax Dec 18, 2007
4003           ln_bsln_amt_nr := 0; --Added by Kevin Cheng for inclusive tax Dec 18, 2007
4004         END IF;
4005 
4006         IF p1( i ) <> -1 THEN
4007           IF p1( i ) <> 0 THEN
4008             vamt := vamt + tax_amt_tab( p1( I ) );
4009             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P1(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4010           ELSIF p1(i) = 0 THEN
4011             vamt := vamt + v_amt;
4012             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4013           END IF;
4014         END IF;
4015 
4016         IF p2( i ) <> -1 THEN
4017           IF p2( i ) <> 0 THEN
4018             vamt := vamt + tax_amt_tab( p2( I ) );
4019             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P2(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4020           ELSIF p2(i) = 0 THEN
4021             vamt := vamt + v_amt;
4022             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4023           END IF;
4024         END IF;
4025 
4026         IF p3( i ) <> -1 THEN
4027           IF p3( i ) <> 0 THEN
4028             vamt := vamt + tax_amt_tab( p3( I ) );
4029             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P3(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4030           ELSIF p3(i) = 0 THEN
4031             vamt := vamt + v_amt;
4032             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4033           END IF;
4034         END IF;
4035 
4036         IF p4( i ) <> -1 THEN
4037           IF p4( i ) <> 0 THEN
4038             vamt := vamt + tax_amt_tab( p4( i ) );
4039             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P4(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4040           ELSIF p4(i) = 0 THEN
4041             vamt := vamt + v_amt;
4042             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4043           END IF;
4044         END IF;
4045 
4046         IF p5( i ) <> -1 THEN
4047           IF p5( i ) <> 0 THEN
4048             vamt := vamt + tax_amt_tab( p5( i ) );
4049             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P5(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4050           ELSIF p5(i) = 0 THEN
4051             vamt := vamt + v_amt;
4052             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4053           END IF;
4054         END IF;
4055 
4056 
4057 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
4058 -- START BUG 5228046
4059 
4060   IF p6( i ) <> -1 THEN
4061           IF p6( i ) <> 0 THEN
4062             vamt := vamt + tax_amt_tab( p6( I ) );
4063             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P6(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4064           ELSIF p6(i) = 0 THEN
4065             vamt := vamt + v_amt;
4066             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4067           END IF;
4068         END IF;
4069 
4070         IF p7( i ) <> -1 THEN
4071           IF p7( i ) <> 0 THEN
4072             vamt := vamt + tax_amt_tab( p7( I ) );
4073             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P7(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4074           ELSIF p7(i) = 0 THEN
4075             vamt := vamt + v_amt;
4076             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4077           END IF;
4078         END IF;
4079 
4080         IF p8( i ) <> -1 THEN
4081           IF p8( i ) <> 0 THEN
4082             vamt := vamt + tax_amt_tab( p8( I ) );
4083             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P8(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4084           ELSIF p8(i) = 0 THEN
4085             vamt := vamt + v_amt;
4086             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4087           END IF;
4088         END IF;
4089 
4090         IF p9( i ) <> -1 THEN
4091           IF p9( i ) <> 0 THEN
4092             vamt := vamt + tax_amt_tab( p9( i ) );
4093             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P9(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4094           ELSIF p9(i) = 0 THEN
4095             vamt := vamt + v_amt;
4096             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4097           END IF;
4098         END IF;
4099 
4100         IF p10( i ) <> -1 THEN
4101           IF p10( i ) <> 0 THEN
4102             vamt := vamt + tax_amt_tab( p10( i ) );
4103             ln_vamt_nr := ln_vamt_nr+NVL(lt_tax_amt_non_rate_tab(P10(I)),0); --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4104           ELSIF p10(i) = 0 THEN
4105             vamt := vamt + v_amt;
4106             ln_vamt_nr := ln_vamt_nr + ln_bsln_amt_nr; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4107           END IF;
4108         END IF;
4109 
4110 -- END BUG 5228046
4111 
4112   tax_target_tab(I) := vamt;
4113         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4114         ---------------------------------------------------
4115         lt_base_tax_amt_tab(I) := vamt;
4116         ln_tax_amt_nr:=ln_tax_amt_nr+(ln_vamt_nr*(tax_rate_tab(i)/100));
4117         ln_func_tax_amt := v_tax_amt +  ( vamt * ( tax_rate_tab( i )/100));
4118         ---------------------------------------------------
4119 
4120         v_tax_amt := v_tax_amt + ( vamt * ( tax_rate_tab( i )/100));
4121         tax_amt_tab( I ) := NVL( v_tax_amt, 0 );
4122       -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4123       --tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/ --Comment out by Kevin Cheng for inclusive tax Dec 18, 2007
4124       -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4125       ELSIF tax_rate_tab( i ) = -99999 AND End_Date_Tab(I) <> 0  THEN
4126         --NULL; --Comment out by Kevin Cheng for bug 6816062 Feb 15, 2008
4127         ln_tax_amt_nr:=lt_tax_amt_non_rate_tab(i); --Add by Kevin Cheng for bug 6816062 Feb 15, 2008
4128 
4129       ELSE
4130         tax_amt_tab(I) := 0;
4131         tax_target_tab(I) := 0;
4132         --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4133         ---------------------------------------------------
4134         lt_base_tax_amt_tab(I) := 0;
4135         ln_func_tax_amt        := 0;
4136         ---------------------------------------------------
4137       END IF;
4138       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4139       ---------------------------------------------------
4140       ELSIF tax_rate_tab(I) = 0 THEN --IF ( tax_rate_tab( i ) <> 0 OR tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
4141         lt_base_tax_amt_tab(I) := tax_amt_tab(i);
4142         v_tax_amt := tax_amt_tab( i );
4143         ln_tax_amt_nr:=lt_tax_amt_non_rate_tab(i);
4144         tax_target_tab(I) := v_tax_amt;
4145       ELSIF end_date_tab( I ) = 0 THEN --IF ( tax_rate_tab( i ) <> 0 OR tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
4146         tax_amt_tab(I) := 0;
4147         lt_base_tax_amt_tab(I) := 0;
4148         tax_target_tab(I) := 0;
4149       END IF; --IF ( tax_rate_tab( i ) <> 0 OR tax_rate_zero_tab(I) = -9999) AND end_date_tab( I ) <> 0 THEN
4150       lt_tax_amt_non_rate_tab(I):=ln_tax_amt_nr;
4151       ---------------------------------------------------
4152 
4153       IF counter = max_iter THEN
4154         IF END_date_tab(I) = 0 THEN
4155           tax_amt_tab(I) := 0;
4156           lt_func_tax_amt_tab(i) := 0; --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4157         END IF;
4158       END IF;
4159 
4160       vamt := 0;
4161       v_amt := 0;
4162       v_tax_amt := 0;
4163       --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4164       ---------------------------------------------------
4165       ln_func_tax_amt := 0;
4166       ln_vamt_nr :=0;
4167       ln_tax_amt_nr:=0;
4168       ---------------------------------------------------
4169 
4170     END LOOP;
4171 
4172   END LOOP;
4173 
4174   --Add by Kevin Cheng for inclusive tax Dec 18, 2007
4175   ---------------------------------------------------------------------------------------
4176   FOR I IN 1 .. ROW_COUNT
4177   LOOP
4178     IF lt_inclu_tax_tab(I) = 'Y'
4179     THEN
4180       ln_total_tax_per_rupee := ln_total_tax_per_rupee + nvl(lt_tax_amt_rate_tax_tab(I),0) ;
4181       ln_total_non_rate_tax := ln_total_non_rate_tax + nvl(lt_tax_amt_non_rate_tab(I),0);
4182     END IF;
4183   END LOOP; --FOR I IN 1 .. ROW_COUNT
4184   ln_total_tax_per_rupee := ln_total_tax_per_rupee + 1;
4185 
4186   IF ln_total_tax_per_rupee <> 0
4187   THEN
4188      ln_exclusive_price := (NVL(p_base_value,0)  -  ln_total_non_rate_tax ) / ln_total_tax_per_rupee;
4189   END If;
4190 
4191   FOR i in 1 .. row_count
4192   LOOP
4193      tax_amt_tab (i) := (lt_tax_amt_rate_tax_tab(I) * ln_exclusive_price ) + lt_tax_amt_non_rate_tab(I);
4194      --tax_amt_tab(I) :=  round(tax_amt_tab(I)  ,rnd_factor(I));
4195 
4196   END LOOP; --FOR i in 1 .. row_count
4197   --------------------------------------------------------------------------------------------------------
4198 
4199   --Added by Kevin Cheng for Retroactive Price 2008/01/10
4200   --======================================================================================================
4201   ELSIF pv_retroprice_changed = 'Y'
4202   THEN
4203        --File.Sql.35 Cbabu
4204     bsln_amt           := p_tax_amount;
4205     row_count          := 0;
4206     v_tax_amt          := 0;
4207     vamt               := 0;
4208     max_iter           := 15;  -- Date 03/11/2006 Bug 5228046 added by SACSETHI
4209     v_curr             :=  p_line_uom_code;
4210     v_line_uom_code    := p_line_uom_code;
4211     v_debug            := jai_constants.no;
4212 
4213   IF v_debug = 'Y' THEN
4214     fnd_file.put_line(fnd_file.log, 'Entered into the procedure 2' );
4215     fnd_file.put_line(fnd_file.log,
4216     -- INSERT INTO mc_debug values ( mc_debug_s.nextval,
4217       ' p_type -> '||p_type|| ' p_header_id -> '||p_header_id||
4218       ' P_line_id -> '||P_line_id|| ' p_line_location_id -> '||p_line_location_id||
4219       ' p_line_focus_id -> '||p_line_focus_id||
4220       ' p_line_quantity -> '||p_line_quantity|| ' p_base_value -> '||p_base_value);
4221     fnd_file.put_line(fnd_file.log, ' p_line_uom_code -> '||p_line_uom_code|| ' p_tax_amount -> '||p_tax_amount||
4222       ' p_assessable_value -> '||p_assessable_value|| ' p_item_id -> '||p_item_id||
4223       ' p_conv_rate -> '||p_conv_rate||
4224       ' p_po_curr -> '||p_po_curr|| ' p_func_curr -> '||p_func_curr
4225     );
4226   END IF;
4227 
4228   v_conv_rate := nvl( p_conv_rate, 1);
4229 /*bgowrava for Bug#5877782*/
4230   IF p_type = 'REQUISITION' THEN
4231     OPEN c_reqn_curr(p_header_id);
4232     FETCH c_reqn_curr INTO  v_org_id;
4233     CLOSE c_reqn_curr;
4234     v_po_curr := p_po_curr; /*bgowrava for Bug#5877782*/
4235   ELSIF p_type in ('REQUISITION_BLANKET','ASBN') THEN
4236     v_po_curr := p_po_curr; /*bgowrava for Bug#5877782*/
4237   ELSE  -- means PO related shipments
4238     OPEN c_po_hdr_curr(p_header_id);
4239     FETCH c_po_hdr_curr INTO v_po_curr, v_org_id;
4240     CLOSE c_po_hdr_curr;
4241   END IF;
4242 
4243  /* IF p_func_curr IS NULL THEN
4244     Bug 5243532. Added by Lakshmi Gopalsami
4245      * Removed cursors c_sob and c_func_curr
4246      * and implemented caching logic.
4247 
4248    l_func_curr_det       := jai_plsql_cache_pkg.return_sob_curr
4249                             (p_org_id  => v_org_id );
4250    v_sob                 := l_func_curr_det.ledger_id;
4251    v_func_curr           := l_func_curr_det.currency_code;
4252   ELSE
4253     v_func_curr := p_func_curr;
4254   END IF;*/
4255 
4256   /*
4257 	||bgowrava for bug#5877782. Commented the above code and added the following line
4258 	||p_func_curr is nowhere being used so it is not required at all.
4259 	*/
4260   v_func_curr := p_func_curr;
4261 
4262   IF p_type = 'REQUISITION' THEN
4263 
4264     IF p_item_id IS NULL THEN
4265       OPEN  Fetch_Item_Cur;
4266       FETCH Fetch_Item_Cur INTO p_inventory_item_id;
4267       CLOSE Fetch_Item_Cur;
4268     ELSE
4269       p_inventory_item_id := p_item_id;
4270     END IF;
4271 
4272     IF p_line_uom_code IS NULL THEN
4273       OPEN  Fetch_line_uom_code;
4274       FETCH Fetch_line_uom_code INTO v_line_uom_code;
4275       CLOSE Fetch_line_uom_code;
4276     END IF;
4277 
4278     FOR rec in c_reqn_line_taxes_retro(p_line_id) LOOP
4279 
4280       P1(rec.lno) := nvl(rec.p_1,-1);
4281       P2(rec.lno) := nvl(rec.p_2,-1);
4282       P3(rec.lno) := nvl(rec.p_3,-1);
4283       P4(rec.lno) := nvl(rec.p_4,-1);
4284       P5(rec.lno) := nvl(rec.p_5,-1);
4285 
4286       -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
4287       -- start bug#5228046
4288       P6(rec.lno) := nvl(rec.p_6,-1);
4289       P7(rec.lno) := nvl(rec.p_7,-1);
4290       P8(rec.lno) := nvl(rec.p_8,-1);
4291       P9(rec.lno) := nvl(rec.p_9,-1);
4292       P10(rec.lno) := nvl(rec.p_10,-1);
4293       -- end bug#5228046
4294 
4295       rnd_factor(rec.lno) := nvl(rec.rnd_factor,0);
4296       tax_rate_tab(rec.lno) := nvl(rec.tax_rate,0);
4297       curr_tab(rec.lno) := nvl(rec.curr, v_po_curr);
4298 
4299       -- if tax_type is based on tax_rate then variable should be initialized with 0,
4300       -- if tax_type is ADHOC or UNIT RATE then they are handled later in the loop
4301       tax_amt_tab(rec.lno)  := 0;   -- nvl(rec.tax_amt,0);
4302       tax_target_tab(rec.lno) := 0;
4303       initial_tax_amt_t(rec.lno) := 0;
4304       tax_type_tab(rec.lno) := rec.tax_type_val;
4305       adhoc_tab(rec.lno) := nvl(rec.adhoc_flag, 'N');
4306       qty_tab(rec.lno) := rec.qty_rate;
4307       uom_tab(rec.lno) := rec.uom_code; --pramasub for #6066485
4308 
4309       -- this condition will take care of the ADHOC taxes
4310       IF adhoc_tab(rec.lno) = 'Y' THEN
4311 
4312         tax_rate_tab(rec.lno) :=  -99999;
4313         tax_amt_tab(rec.lno)  := rec.tax_amt;
4314         initial_tax_amt_t(rec.lno) := rec.tax_amt;
4315         tax_target_tab(rec.lno) := rec.tax_amt;
4316 
4317       -- this condition will take care of the taxes that are UNIT RATE based , rec.qty_rate <> 0
4318       ELSIF adhoc_tab(rec.lno) = 'N' AND tax_rate_tab(rec.lno) = 0 THEN
4319         v_conversion_rate := 0;
4320         FOR uom_cls IN uom_class_cur(v_line_uom_code, rec.uom_code) LOOP
4321           INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, p_inventory_item_id, v_conversion_rate);
4322           IF nvl(v_conversion_rate, 0) <= 0 THEN
4323             INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, 0, v_conversion_rate);
4324             IF nvl(v_conversion_rate, 0) <= 0  THEN
4325                v_conversion_rate := 0;
4326             END IF;
4327           END IF;
4328         tax_rate_tab( rec.lno ) := -99999;
4329         tax_amt_tab(rec.lno) := round(nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity,nvl(rec.rnd_factor,0));/*4281841*/
4330         initial_tax_amt_t(rec.lno) := round(nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity,nvl(rec.rnd_factor,0));/*4281841*/
4331         tax_target_tab(rec.lno) := tax_amt_tab(rec.lno);
4332         END LOOP;
4333       END IF;
4334 
4335       -- here we have to convert the tax_currency (func currency in case of foreign PO) into PO currency, so that all the
4336       -- taxes will be calculated in PO currency initially, then later while modifying them in database, then change them
4337       -- back to the tax currency
4338       -- ex. IF FUNCTIONAL CURRENCY -> USD, PO CURRENCY -> INR, TAX CURRENCY -> USD, then the if condition is satisfied
4339       IF curr_tab(rec.lno) <> v_po_curr THEN
4340       -- the following two lines are commented as the tax_amt becomes zero after this code execution (For UOM based rax lines in Reqn) pramasub #6066485
4341        -- tax_amt_tab(rec.lno)  := tax_amt_tab(rec.lno) / v_conv_rate;
4342        -- tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
4343         tax_target_tab(rec.lno) := tax_target_tab(rec.lno) / v_conv_rate;
4344       END IF;
4345 
4346       IF rec.Valid_Date is NULL OR rec.Valid_Date >= Sysdate THEN
4347         End_Date_Tab(rec.lno) := 1;
4348       ELSE
4349         End_Date_Tab(rec.lno) := 0;
4350       END IF;
4351 
4352       row_count := row_count + 1;
4353     END LOOP;
4354 
4355   ELSIF p_type IN  ( 'RELEASE', 'REQUISITION_BLANKET', 'STANDARDPO' ) THEN
4356 
4357     IF p_item_id IS NULL THEN
4358       OPEN  Fetch_Item_Cur;
4359       FETCH Fetch_Item_Cur INTO p_inventory_item_id;
4360       CLOSE Fetch_Item_Cur;
4361     ELSE
4362       p_inventory_item_id := p_item_id;
4363     END IF;
4364 
4365 
4366 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4367     /*4281841 */
4368      IF p_line_uom_code IS NULL and p_type = 'REQUISITION_BLANKET' THEN
4369       /* OPEN  fetch_req_uom_code;
4370        FETCH fetch_req_uom_code INTO v_line_uom_code;
4371        CLOSE fetch_req_uom_code;*/null;
4372      END IF;
4373 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4374 
4375     FOR rec in c_po_line_location_taxes_retro(p_line_id, p_line_location_id) LOOP
4376 
4377       P1(rec.lno) := nvl(rec.p_1,-1);
4378       P2(rec.lno) := nvl(rec.p_2,-1);
4379       P3(rec.lno) := nvl(rec.p_3,-1);
4380       P4(rec.lno) := nvl(rec.p_4,-1);
4381       P5(rec.lno) := nvl(rec.p_5,-1);
4382 
4383 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
4384 -- START BUG 5228046
4385 
4386       P6(rec.lno) := nvl(rec.p_6,-1);
4387       P7(rec.lno) := nvl(rec.p_7,-1);
4388       P8(rec.lno) := nvl(rec.p_8,-1);
4389       P9(rec.lno) := nvl(rec.p_9,-1);
4390       P10(rec.lno) := nvl(rec.p_10,-1);
4391 
4392 -- END BUG 5228046
4393 
4394 
4395       rnd_factor(rec.lno) := nvl(rec.rnd_factor,0);
4396       tax_rate_tab(rec.lno) := nvl(rec.tax_rate,0);
4397       tax_type_tab(rec.lno) := rec.tax_type_val;
4398       adhoc_tab(rec.lno) := nvl(rec.adhoc_flag,'N'); -- added for bug#2097413
4399       qty_tab(rec.lno) := rec.qty_rate; -- added for bug#2097413
4400 
4401       curr_tab(rec.lno) := nvl( rec.curr, v_po_curr); -- p_po_curr);  -- v_curr );
4402       tax_amt_tab(rec.lno) := 0;
4403       initial_tax_amt_t(rec.lno) := 0;
4404       tax_target_tab(rec.lno) := 0;
4405 
4406   --Added by Kevin Cheng -- for remain unchanged taxes
4407   --1, Ad hoc taxes
4408   --2, UOM based taxes
4409   --3, Assessable value base taxes (Excise/VAT)
4410   --4, Third party taxes
4411   --=================================================================================
4412   IF NVL(rec.adhoc_flag,'N') = 'Y' --Ad hoc
4413   THEN
4414     lv_tax_remain_flag := 'Y';
4415   ELSIF NVL(rec.adhoc_flag,'N') = 'N' AND qty_tab(rec.lno) <> 0 --UOM based
4416   THEN
4417     lv_tax_remain_flag := 'Y';
4418   ELSIF rec.tax_type_val = 1 AND p_assessable_value <> p_base_value--Excise assessable value based
4419   THEN
4420      lv_tax_remain_flag := 'Y';
4421   ELSIF rec.tax_type_val = 4 AND p_vat_assess_value <> p_base_value --VAT assessable value based
4422   THEN
4423     lv_tax_remain_flag := 'Y';
4424   ELSIF rec.hdr_vendor_id <> rec.tax_vendor_id --Third party
4425   THEN
4426     lv_tax_remain_flag := 'Y';
4427   ELSE
4428     lv_tax_remain_flag := 'N';
4429   END IF;
4430 
4431   IF lv_tax_remain_flag = 'Y'
4432   THEN
4433     SELECT
4434       original_tax_amount
4435     INTO
4436       tax_amt_tab(rec.lno)
4437     FROM
4438       Jai_Retro_Tax_Changes jrtc
4439     WHERE jrtc.tax_id = rec.tax_id
4440       AND jrtc.line_change_id = (SELECT
4441                                    line_change_id
4442                                  FROM
4443                                    Jai_Retro_Line_Changes jrlc
4444                                  WHERE jrlc.line_location_id = p_line_location_id
4445                                    AND jrlc.doc_type IN ( 'RELEASE'
4446                                                         , 'RECEIPT'
4447                                                         , 'STANDARD PO'
4448                                                         )
4449                                    AND jrlc.doc_version_number = (SELECT
4450                                                                     MAX(jrlc1.doc_version_number)
4451                                                                   FROM
4452                                                                     Jai_Retro_Line_Changes jrlc1
4453                                                                   WHERE jrlc1.line_location_id = p_line_location_id
4454                                                                     AND jrlc1.doc_type IN ( 'RELEASE'
4455                                                                                           , 'RECEIPT'
4456                                                                                           , 'STANDARD PO'
4457                                                                                           )
4458                                                                  )
4459                                 );
4460     tax_rate_tab(rec.lno)      := -99999;
4461     tax_target_tab(rec.lno)    := nvl(rec.tax_amount,0);
4462     initial_tax_amt_t(rec.lno) := nvl(rec.tax_amount,0);
4463     adhoc_tab(rec.lno)         := 'Y';
4464 
4465   ELSIF lv_tax_remain_flag = 'N'
4466   THEN
4467     adhoc_tab(rec.lno):= nvl(rec.adhoc_flag,'N'); -- added by subbu on 08-nov-01
4468   END IF;
4469   --=================================================================================
4470 
4471       --Comment out by Kevin Cheng
4472       -- start of modifications for Bug#2097413
4473       -- IF nvl(rec.tax_rate,0) = 0 AND nvl(rec.qty_rate,0) = 0 and nvl(rec.adhoc_flag,'N') = 'Y' THEN
4474       /*IF adhoc_tab(rec.lno) = 'Y' THEN
4475 
4476         tax_rate_tab(rec.lno) :=  -99999;
4477         tax_amt_tab(rec.lno) := nvl(rec.tax_amount,0);
4478         initial_tax_amt_t(rec.lno) := nvl(rec.tax_amount,0);
4479         tax_target_tab(rec.lno) := nvl(rec.tax_amount,0);
4480 
4481 
4482      ELSIF adhoc_tab(rec.lno) = 'N' AND qty_tab(rec.lno) <> 0 THEN -- tax_rate_tab(rec.lno) = 0 THEN
4483 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4484         v_conversion_rate := 0;
4485       FOR uom_cls IN uom_class_cur(v_line_uom_code, rec.uom_code) LOOP
4486         INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, p_inventory_item_id, v_conversion_rate);
4487         IF nvl(v_conversion_rate, 0) <= 0 THEN
4488           INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, 0, v_conversion_rate);
4489           IF nvl(v_conversion_rate, 0) <= 0  THEN
4490             v_conversion_rate := 0;
4491           END IF;
4492         END IF;
4493       END LOOP;
4494       tax_rate_tab( rec.lno ) := -99999;
4495       tax_amt_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
4496       tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));\*4281841*\
4497       initial_tax_amt_t(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
4498       tax_target_tab(rec.lno) := tax_amt_tab( rec.lno );
4499     END IF;*/
4500 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4501 
4502       -- THIS IS THE MAIN CHANGE FOR THE BUG# cbabu for Bug# 2659815
4503       -- here we have to convert the tax_currency (func currency in case of foreign PO) into PO currency, so that all the
4504       -- taxes will be calculated in PO currency initially, then later while modifying them in database, then change them
4505       -- back to the tax currency
4506       -- ex. FUNCTIONAL CURRENCY -> USD, PO CURRENCY -> INR, TAX CURRENCY -> USD, then the if condition is satisfied
4507 
4508       IF curr_tab(rec.lno) <> v_po_curr THEN
4509          tax_amt_tab(rec.lno)  := tax_amt_tab(rec.lno) * v_conv_rate; -- YYYYYYYY
4510          tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
4511          tax_target_tab(rec.lno) := tax_target_tab(rec.lno) * v_conv_rate; -- YYYYYYY
4512       END IF;
4513       --end, cbabu for Bug# 2659815
4514 
4515       IF rec.Valid_Date is NULL Or rec.Valid_Date >= SYSDATE THEN
4516         end_date_tab(rec.lno) := 1;
4517       ELSE
4518         end_date_tab(rec.lno) := 0;
4519       END IF;
4520 
4521       row_count := row_count + 1;
4522 
4523     END LOOP;
4524  ELSIF p_type IN  ( 'ASBN' ) THEN /*rchandan for 5961325*/
4525 
4526   FOR rec in cur_asbn_taxes_retro( p_header_id, p_line_id ) LOOP -- pramasub added p_header_id for bug #6137011
4527 
4528     P1(rec.lno) := nvl(rec.p_1,-1);
4529     P2(rec.lno) := nvl(rec.p_2,-1);
4530     P3(rec.lno) := nvl(rec.p_3,-1);
4531     P4(rec.lno) := nvl(rec.p_4,-1);
4532     P5(rec.lno) := nvl(rec.p_5,-1);
4533     P6(rec.lno) := nvl(rec.p_6,-1);
4534     P7(rec.lno) := nvl(rec.p_7,-1);
4535     P8(rec.lno) := nvl(rec.p_8,-1);
4536     P9(rec.lno) := nvl(rec.p_9,-1);
4537     P10(rec.lno) := nvl(rec.p_10,-1);
4538 
4539     rnd_factor(rec.lno)   := nvl(rec.rnd_factor,0);
4540     tax_rate_tab(rec.lno) := nvl(rec.tax_rate,0);
4541     tax_type_tab(rec.lno) := rec.tax_type_val;
4542     adhoc_tab(rec.lno)    := nvl(rec.adhoc_flag,'N'); -- added for bug#2097413
4543     qty_tab(rec.lno)      := rec.qty_rate; -- added for bug#2097413
4544     uom_tab(rec.lno)      := rec.uom_code; --pramasub for #6137011
4545 
4546     curr_tab(rec.lno)          := nvl( rec.curr, v_po_curr); -- p_po_curr);  -- v_curr );
4547     tax_amt_tab(rec.lno)       := 0;
4548     initial_tax_amt_t(rec.lno) := 0;
4549     tax_target_tab(rec.lno)    := 0;
4550 
4551     IF adhoc_tab(rec.lno) = 'Y' THEN
4552 
4553       tax_rate_tab(rec.lno)      :=  -99999;
4554       tax_amt_tab(rec.lno)       := nvl(rec.tax_amount,0);
4555       initial_tax_amt_t(rec.lno) := nvl(rec.tax_amount,0);
4556       tax_target_tab(rec.lno)    := nvl(rec.tax_amount,0);
4557 
4558     ELSIF adhoc_tab(rec.lno) = 'N' AND qty_tab(rec.lno) <> 0 THEN
4559         v_conversion_rate := 0;
4560       FOR uom_cls IN uom_class_cur(v_line_uom_code, rec.uom_code) LOOP
4561         INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, p_inventory_item_id, v_conversion_rate);
4562         IF nvl(v_conversion_rate, 0) <= 0 THEN
4563           INV_CONVERT.inv_um_conversion(v_line_uom_code, rec.uom_code, 0, v_conversion_rate);
4564           IF nvl(v_conversion_rate, 0) <= 0  THEN
4565             v_conversion_rate := 0;
4566           END IF;
4567         END IF;
4568       END LOOP;
4569       tax_rate_tab( rec.lno ) := -99999;
4570       tax_amt_tab(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
4571       tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
4572       initial_tax_amt_t(rec.lno) := nvl(rec.qty_rate * v_conversion_rate, 0) * p_line_quantity;
4573       tax_target_tab(rec.lno) := tax_amt_tab( rec.lno );
4574     END IF;
4575 
4576     IF curr_tab(rec.lno) <> v_po_curr THEN
4577       tax_amt_tab(rec.lno)  := tax_amt_tab(rec.lno) * v_conv_rate; -- YYYYYYYY
4578       tax_amt_tab(rec.lno) := round(tax_amt_tab(rec.lno),nvl(rec.rnd_factor,0));/*4281841*/
4579       tax_target_tab(rec.lno) := tax_target_tab(rec.lno) * v_conv_rate; -- YYYYYYY
4580     END IF;
4581     --end, cbabu for Bug# 2659815
4582 
4583     IF rec.Valid_Date is NULL Or rec.Valid_Date >= SYSDATE THEN
4584       end_date_tab(rec.lno) := 1;
4585     ELSE
4586       end_date_tab(rec.lno) := 0;
4587     END IF;
4588 
4589     row_count := row_count + 1;
4590 
4591   END LOOP;
4592 
4593   END IF;
4594 
4595   bsln_amt := p_base_value;
4596 
4597   FOR i in 1..row_count LOOP
4598 
4599     IF tax_type_tab(i) = 1 THEN
4600       bsln_amt := NVL( p_assessable_value, p_base_value );
4601      /* start rallamse bug#4250072 VAT */
4602     ELSIF tax_type_tab(i) = 4 THEN
4603       bsln_amt := NVL( p_vat_assess_value, p_base_value );
4604     /* end rallamse Bug#4250072 VAT */
4605     ELSE
4606       bsln_amt := p_base_value;
4607     END IF;
4608 
4609     IF p1(I) < I and p1(I) not in (-1,0) then
4610       vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
4611     ELSIF p1(I) = 0 then
4612       vamt  := vamt + bsln_amt;
4613     END IF;
4614 
4615     IF p2(I) < I and p2(I) not in (-1,0) then
4616       vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
4617     ELSIF p2(I) = 0 then
4618       vamt  := vamt + bsln_amt;
4619     END IF;
4620 
4621     IF p3(I) < I and p3(I) not in (-1,0) then
4622       vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
4623     ELSIF p3(I) = 0 then
4624       vamt  := vamt + bsln_amt;
4625     END IF;
4626 
4627     IF p4(I) < I and p4(I) not in (-1,0) then
4628       vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
4629     ELSIF p4(I) = 0 then
4630       vamt  := vamt + bsln_amt;
4631     END IF;
4632 
4633     IF p5(I) < I and p5(I) not in (-1,0) then
4634       vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
4635     ELSIF p5(I) = 0 then
4636       vamt  := vamt + bsln_amt;
4637     END IF;
4638 
4639 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
4640 -- START BUG 5228046
4641 
4642     IF p6(I) < I and p6(I) not in (-1,0) then
4643       vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
4644     ELSIF p6(I) = 0 then
4645       vamt  := vamt + bsln_amt;
4646     END IF;
4647 
4648     IF p7(I) < I and p7(I) not in (-1,0) then
4649       vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
4650     ELSIF p7(I) = 0 then
4651       vamt  := vamt + bsln_amt;
4652     END IF;
4653 
4654     IF p8(I) < I and p8(I) not in (-1,0) then
4655       vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
4656     ELSIF p8(I) = 0 then
4657       vamt  := vamt + bsln_amt;
4658     END IF;
4659 
4660     IF p9(I) < I and p9(I) not in (-1,0) then
4661       vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
4662     ELSIF p9(I) = 0 then
4663       vamt  := vamt + bsln_amt;
4664     END IF;
4665 
4666     IF p10(I) < I and p10(I) not in (-1,0) then
4667       vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
4668     ELSIF p10(I) = 0 then
4669       vamt  := vamt + bsln_amt;
4670     END IF;
4671 
4672 -- END BUG 5228046
4673 
4674     IF tax_rate_tab(I) <> -99999 THEN
4675       v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
4676       IF END_date_tab(I) = 0 then
4677         tax_amt_tab(I) := 0;
4678       ELSIF END_date_tab(I) = 1 then
4679         tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
4680       END IF;
4681     ELSE
4682       tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
4683     END IF;
4684     tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
4685     vamt      := 0;
4686     v_tax_amt := 0;
4687 
4688   END LOOP;
4689   --i := null;
4690 
4691   FOR i in 1..row_count LOOP
4692     --i := v_taxid_tab(j);
4693 
4694     IF p1(I) > I then
4695       vamt  := vamt + nvl(tax_amt_tab(p1(I)),0);
4696     END IF;
4697 
4698     IF p2(I) > I  then
4699       vamt  := vamt + nvl(tax_amt_tab(p2(I)),0);
4700     END IF;
4701 
4702     IF p3(I) > I  then
4703       vamt  := vamt + nvl(tax_amt_tab(p3(I)),0);
4704     END IF;
4705 
4706     IF p4(I) > I then
4707       vamt  := vamt + nvl(tax_amt_tab(p4(I)),0);
4708     END IF;
4709 
4710     IF p5(I) > I then
4711       vamt  := vamt + nvl(tax_amt_tab(p5(I)),0);
4712     END IF;
4713 
4714 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
4715 -- START BUG 5228046
4716 
4717     IF p6(I) > I then
4718       vamt  := vamt + nvl(tax_amt_tab(p6(I)),0);
4719     END IF;
4720 
4721     IF p7(I) > I  then
4722       vamt  := vamt + nvl(tax_amt_tab(p7(I)),0);
4723     END IF;
4724 
4725     IF p8(I) > I  then
4726       vamt  := vamt + nvl(tax_amt_tab(p8(I)),0);
4727     END IF;
4728 
4729     IF p9(I) > I then
4730       vamt  := vamt + nvl(tax_amt_tab(p9(I)),0);
4731     END IF;
4732 
4733     IF p10(I) > I then
4734       vamt  := vamt + nvl(tax_amt_tab(p10(I)),0);
4735     END IF;
4736 
4737 -- END BUG 5228046
4738 
4739     IF tax_rate_tab(I) <> -99999 THEN
4740       v_tax_amt := v_tax_amt + (vamt * (tax_rate_tab(I)/100));
4741       IF END_date_tab(I) = 0 then
4742         tax_amt_tab(I) := 0;
4743       ELSIF END_date_tab(I) = 1 then
4744         tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
4745       END IF;
4746     ELSE -- added for Bug#2097413
4747       tax_amt_tab(I) := nvl(tax_amt_tab(I),0) + v_tax_amt;
4748     END IF;
4749 
4750 -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4751     tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
4752 -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4753 
4754     vamt      := 0;
4755     v_tax_amt := 0;
4756   END LOOP;
4757   --i := null;
4758 
4759   FOR counter IN 1 .. max_iter LOOP
4760     vamt := 0;
4761     v_tax_amt := 0;
4762 
4763     FOR i in 1..row_count LOOP
4764       --i := v_taxid_tab(j);
4765 
4766       IF tax_rate_tab( i ) <> 0 AND End_Date_Tab(I) <> 0
4767         AND adhoc_tab(i) <> 'Y' AND qty_tab(i) IS NULL
4768       THEN
4769         -- added extra condition AND adhoc_tab(i) <> 'Y' , qty_tab(i) IS NULL for Bug#2097413
4770         IF tax_type_tab( i ) = 1 THEN
4771           v_amt := NVL( p_assessable_value, p_base_value );
4772         /* start rallamse Bug#4250072 VAT */
4773         ELSIF tax_type_tab(i) = 4 THEN
4774           v_amt := NVL( p_vat_assess_value, p_base_value );
4775         /* end rallamse Bug#4250072 VAT */
4776         ELSIF v_amt = 0 OR tax_type_tab(i) <> 1 THEN
4777           v_amt := p_base_value;
4778         END IF;
4779 
4780         IF p1( i ) <> -1 THEN
4781           IF p1( i ) <> 0 THEN
4782             vamt := vamt + tax_amt_tab( p1( I ) );
4783           ELSIF p1(i) = 0 THEN
4784             vamt := vamt + v_amt;
4785           END IF;
4786         END IF;
4787 
4788         IF p2( i ) <> -1 THEN
4789           IF p2( i ) <> 0 THEN
4790             vamt := vamt + tax_amt_tab( p2( I ) );
4791           ELSIF p2(i) = 0 THEN
4792             vamt := vamt + v_amt;
4793           END IF;
4794         END IF;
4795 
4796         IF p3( i ) <> -1 THEN
4797           IF p3( i ) <> 0 THEN
4798             vamt := vamt + tax_amt_tab( p3( I ) );
4799           ELSIF p3(i) = 0 THEN
4800             vamt := vamt + v_amt;
4801           END IF;
4802         END IF;
4803 
4804         IF p4( i ) <> -1 THEN
4805           IF p4( i ) <> 0 THEN
4806             vamt := vamt + tax_amt_tab( p4( i ) );
4807           ELSIF p4(i) = 0 THEN
4808             vamt := vamt + v_amt;
4809           END IF;
4810         END IF;
4811 
4812         IF p5( i ) <> -1 THEN
4813           IF p5( i ) <> 0 THEN
4814             vamt := vamt + tax_amt_tab( p5( i ) );
4815           ELSIF p5(i) = 0 THEN
4816             vamt := vamt + v_amt;
4817           END IF;
4818         END IF;
4819 
4820 
4821 -- Date 01-NOV-2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
4822 -- START BUG 5228046
4823 
4824   IF p6( i ) <> -1 THEN
4825           IF p6( i ) <> 0 THEN
4826             vamt := vamt + tax_amt_tab( p6( I ) );
4827           ELSIF p6(i) = 0 THEN
4828             vamt := vamt + v_amt;
4829           END IF;
4830         END IF;
4831 
4832         IF p7( i ) <> -1 THEN
4833           IF p7( i ) <> 0 THEN
4834             vamt := vamt + tax_amt_tab( p7( I ) );
4835           ELSIF p7(i) = 0 THEN
4836             vamt := vamt + v_amt;
4837           END IF;
4838         END IF;
4839 
4840         IF p8( i ) <> -1 THEN
4841           IF p8( i ) <> 0 THEN
4842             vamt := vamt + tax_amt_tab( p8( I ) );
4843           ELSIF p8(i) = 0 THEN
4844             vamt := vamt + v_amt;
4845           END IF;
4846         END IF;
4847 
4848         IF p9( i ) <> -1 THEN
4849           IF p9( i ) <> 0 THEN
4850             vamt := vamt + tax_amt_tab( p9( i ) );
4851           ELSIF p9(i) = 0 THEN
4852             vamt := vamt + v_amt;
4853           END IF;
4854         END IF;
4855 
4856         IF p10( i ) <> -1 THEN
4857           IF p10( i ) <> 0 THEN
4858             vamt := vamt + tax_amt_tab( p10( i ) );
4859           ELSIF p10(i) = 0 THEN
4860             vamt := vamt + v_amt;
4861           END IF;
4862         END IF;
4863 
4864 -- END BUG 5228046
4865 
4866   tax_target_tab(I) := vamt;
4867 
4868         v_tax_amt := v_tax_amt + ( vamt * ( tax_rate_tab( i )/100));
4869         tax_amt_tab( I ) := NVL( v_tax_amt, 0 );
4870       -- START ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4871       tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
4872       -- END ILIPROCUREMENT FORWARD PORTING - KVAIDYAN
4873       ELSIF tax_rate_tab( i ) = -99999 AND End_Date_Tab(I) <> 0  THEN
4874         NULL;
4875 
4876       ELSE
4877         tax_amt_tab(I) := 0;
4878         tax_target_tab(I) := 0;
4879       END IF;
4880 
4881       IF counter = max_iter THEN
4882         IF END_date_tab(I) = 0 THEN
4883           tax_amt_tab(I) := 0;
4884         END IF;
4885       END IF;
4886 
4887       vamt := 0;
4888       v_amt := 0;
4889       v_tax_amt := 0;
4890 
4891     END LOOP;
4892 
4893   END LOOP;
4894   END IF;
4895   --======================================================================================================
4896 
4897   IF v_debug = 'Y' THEN
4898     fnd_file.put_line( fnd_file.log,' 1 After calculating the taxes -> '||row_count );
4899     FOR I in 1..row_count LOOP
4900       fnd_file.put_line(fnd_file.log, ' cur->'||curr_tab(i)||', tax_amt_tab('||i||') -> '||tax_amt_tab(i)||
4901         ', tax_target_tab -> '||tax_target_tab(i));
4902     END LOOP;
4903 
4904   END IF;
4905 
4906   IF p_type = 'REQUISITION' THEN
4907     FOR i in 1..row_count LOOP
4908       --i := v_taxid_tab(j);
4909 
4910       IF tax_type_tab( i ) <> 2 THEN
4911         v_tax_amt := v_tax_amt + round( nvl(tax_amt_tab(I),0), rnd_factor(I) );
4912       END IF;
4913 
4914       -- Currecy Conversion code by cbabu for Bug# cbabu for Bug# 2659815
4915       IF curr_tab(i) <> v_po_curr THEN
4916         IF tax_rate_tab(i) <> -99999 THEN
4917           tax_amt_tab(i)  := tax_amt_tab(i) * v_conv_rate;
4918         ELSE
4919           IF uom_tab(i) is not null then --pramasub start for #6066485
4920  	      tax_amt_tab(i)  := initial_tax_amt_t(i) * v_conv_rate;
4921           Else
4922               tax_amt_tab(i)  := initial_tax_amt_t(i);
4923           End If;  --pramasub end for #6066485
4924         END IF;
4925 	    tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
4926       END IF;
4927       --end, cbabu for Bug# 2659815
4928 
4929 
4930 --Bgowrava for Bug#5877782 Added standard Who columns
4931       UPDATE JAI_PO_REQ_LINE_TAXES
4932        SET    Tax_Amount = round( nvl(tax_amt_tab(I),0), nvl(rnd_factor(I),0) ),/*4281841*/
4933            Tax_Target_Amount = NVL( tax_target_tab(I), 0 ),
4934 					 last_update_date  = sysdate,
4935 					 last_updated_by   = fnd_global.user_id,
4936 					 last_update_login = fnd_global.login_id
4937     WHERE  Requisition_Header_Id = p_header_id
4938     AND    Requisition_Line_Id = p_line_id
4939     AND    Tax_Line_No = I;
4940     END LOOP;
4941 
4942     -- cbabu for Bug# 2659815
4943     --Bgowrava for Bug#5877782 Added standard Who columns
4944     UPDATE JAI_PO_REQ_LINES
4945     SET Tax_Amount = v_tax_amt,
4946       total_amount = p_base_value + v_tax_amt,
4947       last_update_date  = sysdate,
4948       last_updated_by   = fnd_global.user_id,
4949       last_update_login = fnd_global.login_id
4950     WHERE requisition_header_id = p_header_id
4951     AND requisition_line_id = p_line_id;
4952 
4953   ELSIF p_type = 'REQUISITION_BLANKET' THEN
4954 
4955     FOR i in 1..row_count LOOP
4956 
4957       IF tax_type_tab( i )  <> 2 THEN
4958         v_tax_amt := v_tax_amt + round( nvl(tax_amt_tab(I),0), rnd_factor(I) );
4959       END IF;
4960 
4961       -- Currecy Conversion code by cbabu for Bug# cbabu for Bug# 2659815
4962       IF curr_tab(i) <> v_po_curr THEN
4963         IF tax_rate_tab(i) <> -99999 THEN
4964           tax_amt_tab(i)  := tax_amt_tab(i) * v_conv_rate;
4965         ELSE
4966           tax_amt_tab(i)  := initial_tax_amt_t(i);
4967         END IF;
4968      END IF;
4969 	--ILIPROCUREMENT START
4970 	 IF tax_type_tab( i ) <> 2 THEN
4971          v_tax_amt := v_tax_amt + round( nvl(tax_amt_tab(I),0), rnd_factor(I) );
4972        END IF;
4973 	--ILIPROCUREMENT END
4974 
4975       --end, cbabu for Bug# 2659815
4976       --Bgowrava for Bug#5877782 Added standard Who columns
4977       UPDATE JAI_PO_REQ_LINE_TAXES
4978       SET Tax_Amount = round( nvl(tax_amt_tab(I),0), rnd_factor(I) ),
4979         Tax_Target_Amount = NVL( tax_target_tab(I), 0 ),
4980         last_update_date  = sysdate,
4981 				last_updated_by   = fnd_global.user_id,
4982 				last_update_login = fnd_global.login_id
4983       WHERE Requisition_Line_Id = p_requisition_line_id/*5877782..replaced p_line_id with p_requisition_line_id */
4984       AND Tax_Line_No = I;
4985     END LOOP;
4986 
4987 
4988   ELSIF p_type IN ( 'RELEASE', 'STANDARDPO' ) THEN
4989 
4990     IF v_debug = 'Y' THEN
4991       fnd_file.put_line( fnd_file.log, '3 Before Updating the table');
4992     END IF;
4993 
4994     FOR i in 1..row_count LOOP
4995 
4996       IF tax_type_tab( i ) <> 2 THEN
4997         v_tax_amt := v_tax_amt + round( nvl(tax_amt_tab(I),0), rnd_factor(I) );
4998       END IF;
4999 
5000       -- Currecy Conversion code by cbabu for Bug# cbabu for Bug# 2659815
5001       IF curr_tab(i) <> v_po_curr THEN
5002         IF tax_rate_tab(i) <> -99999 THEN
5003           tax_amt_tab(i)  := tax_amt_tab(i) * v_conv_rate;
5004         ELSE
5005           tax_amt_tab(i)  := initial_tax_amt_t(i);
5006         END IF;
5007 	--START ILIPROCUREMENT
5008 	tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
5009 	--END ILIPROCUREMENT
5010       END IF;
5011       --end, cbabu for Bug# 2659815
5012 
5013       IF v_debug = 'Y' THEN
5014         fnd_file.put_line( fnd_file.log,' cur->'||curr_tab(i)||', tax_amt_tab('||i||') -> '||tax_amt_tab(i)||
5015           ', tax_target_tab -> '||tax_target_tab(i));
5016       END IF;
5017 
5018 			--Bgowrava for Bug#5877782 Added standard Who columns
5019       UPDATE  JAI_PO_TAXES
5020       SET tax_amount = round( nvl( tax_amt_tab(i), 0 ), nvl(rnd_factor(I),0) ),
5021         tax_target_amount = nvl( tax_target_tab(i), 0 ),
5022         last_update_date  = sysdate,
5023 				last_updated_by   = fnd_global.user_id,
5024 		    last_update_login = fnd_global.login_id
5025       WHERE line_location_id = p_line_location_id
5026       AND po_line_id = p_line_id
5027       AND tax_line_no = i;
5028 
5029       --Added by Kevin Cheng for Retroactive Price 2008/01/11
5030       --=====================================================
5031       IF pv_retroprice_changed = 'Y'
5032       THEN
5033         JAI_RETRO_PRC_PKG.Update_Price_Changes( pn_tax_amt         => round( nvl( tax_amt_tab(i), 0 ), nvl(rnd_factor(I),0) )
5034                                               , pn_line_no         => i
5035                                               , pn_line_loc_id     => p_line_location_id
5036                                               , pv_process_flag    => lv_process_flag
5037                                               , pv_process_message => lv_process_message
5038                                               );
5039 
5040         IF lv_process_flag IN ('EE', 'UE')
5041         THEN
5042           FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5043           FND_MESSAGE.SET_TOKEN('JAI_PROCESS_MSG','JAI_PO_TAX_PKG.CALC_TAX.Err:'||lv_process_message);
5044           app_exception.raise_exception;
5045         END IF;
5046       END IF;
5047       --=====================================================
5048     END LOOP;
5049 
5050 		--Bgowrava for Bug#5877782 Added standard Who columns
5051     UPDATE JAI_PO_LINE_LOCATIONS
5052     SET Tax_Amount = NVL( v_tax_amt, 0 ),
5053       Total_Amount = v_tax_amt + p_base_value	,
5054       last_update_date  = sysdate,
5055 			last_updated_by   = fnd_global.user_id,
5056       last_update_login = fnd_global.login_id
5057     WHERE Line_Location_Id = p_line_location_id
5058     AND Po_Line_Id = p_line_id;
5059 
5060  ELSIF p_type in ( 'ASBN' ) THEN  /*rchandan for 5961325*/
5061 
5062   FOR i in 1..row_count LOOP
5063 
5064     IF tax_type_tab( i ) <> 2 THEN
5065       v_tax_amt := v_tax_amt + round( nvl(tax_amt_tab(I),0), rnd_factor(I) );
5066     END IF;
5067 
5068     -- Currecy Conversion code by cbabu for Bug# cbabu for Bug# 2659815
5069 
5070     IF curr_tab(i) <> v_po_curr THEN
5071       IF tax_rate_tab(i) <> -99999 THEN
5072         tax_amt_tab(i)  := tax_amt_tab(i) * 1/v_conv_rate;
5073       ELSE
5074         --tax_amt_tab(i)  := initial_tax_amt_t(i) ;
5075           IF uom_tab(i) is not null then --pramasub start for #6137011
5076               tax_amt_tab(i)  := initial_tax_amt_t(i) * 1/v_conv_rate;
5077           Else
5078               tax_amt_tab(i)  := initial_tax_amt_t(i);
5079           End If;  --pramasub end for #6137011
5080 
5081       END IF;
5082       tax_amt_tab(I) := round(tax_amt_tab(I),nvl(rnd_factor(I),0));/*4281841*/
5083     END IF;
5084     --end, cbabu for Bug# 2659815
5085 
5086     IF v_debug = 'Y' THEN
5087       FND_FILE.put_line(FND_FILE.LOG,' cur->'||curr_tab(i)||', tax_amt_tab('||i||') -> '||tax_amt_tab(i)||
5088                         ', tax_target_tab -> '||tax_target_tab(i));
5089     END IF;
5090 
5091     UPDATE jai_cmn_document_taxes
5092 		   SET Tax_Amt             = round( nvl( tax_amt_tab(i), 0 ), nvl(rnd_factor(I),0) ),
5093 		       last_update_date    = sysdate,
5094 					 last_updated_by     = fnd_global.user_id,
5095 				   last_update_login   = fnd_global.login_id
5096 		 WHERE source_doc_id       = p_header_id
5097 		   AND source_doc_Line_Id  = p_line_id
5098        AND Tax_Line_No         = I;
5099 
5100   END LOOP;
5101 
5102 END IF;
5103 
5104   p_tax_amount := v_tax_amt;
5105 
5106   EXCEPTION
5107     WHEN OTHERS THEN
5108     p_tax_amount := null;
5109     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5110     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5111     app_exception.raise_exception;
5112   END calc_tax;
5113 
5114 
5115 
5116 /*-----------------------------------------------------------------------------------------*/
5117 
5118   PROCEDURE copy_source_taxes (
5119     errbuf OUT NOCOPY VARCHAR2,
5120     retcode OUT NOCOPY VARCHAR2,
5121     p_type        VARCHAR2,
5122     p_po_hdr_id     NUMBER,
5123     p_po_line_id    NUMBER,
5124     p_po_line_loc_id  NUMBER,
5125     p_line_num      NUMBER,
5126     p_ship_num      NUMBER,
5127     p_item_id     NUMBER,
5128     p_from_hdr_id   NUMBER,
5129     p_from_type_lookup_code VARCHAR2,
5130     p_cre_dt      DATE,
5131     p_cre_by      NUMBER,
5132     p_last_upd_dt   DATE,
5133     p_last_upd_by   NUMBER,
5134     p_last_upd_login  NUMBER
5135   ) IS
5136 
5137     -- Copy Document for defaulting taxes in  Quotation to PO and PO to PO. It is executable
5138     -- FND CONCURRENT -> JAINCPDC
5139 
5140     v_seq_val     NUMBER;
5141     v_ln_loc_id   NUMBER;
5142 --Added by kunkumar for forward porting to R12 Start
5143 v_vendor_id number;
5144 v_vendor_site_id  number;
5145 v_service_type_code varchar2(30);
5146 
5147 
5148 cursor fetch_vendor_id_cur IS
5149 select vendor_id,vendor_site_id
5150 from po_headers_all
5151 where po_header_id=p_po_hdr_id;
5152 
5153 --Added by kunkumar End
5154 
5155     v_line_id          NUMBER;
5156 
5157     CURSOR Fetch_Focus_Id_Cur IS
5158       SELECT JAI_PO_LINE_LOCATIONS_S.nextval FROM Dual;
5159 
5160     --  Cursor definition for picking line_location_id from po_line_locations_all
5161 
5162     CURSOR Fetch_Line_Loc_Id_Cur IS
5163       SELECT jpll.Line_Location_Id
5164       FROM po_line_locations_all plla, JAI_PO_LINE_LOCATIONS jpll,
5165         po_lines_all pla, po_headers_all pha
5166       WHERE pha.po_header_id = pla.po_header_id
5167       AND jpll.line_location_id = plla.line_location_id
5168       AND pha.po_header_id = plla.po_header_id
5169       AND pla.po_line_id = plla.po_line_id
5170       AND pha.po_header_id = p_from_hdr_id
5171       AND pla.line_num = p_line_num
5172       AND pla.item_id = p_item_id
5173       AND plla.shipment_num = p_ship_num;
5174 
5175     --  Cursor definition for picking po_line_id from po_lines_all
5176     CURSOR fetch_line_id_cur IS
5177       SELECT pla.Po_Line_Id
5178       FROM po_lines_all pla, po_headers_all pha
5179       WHERE pha.Po_Header_Id = p_from_hdr_id
5180       AND pla.line_num = p_line_num   -- Vijay Shankar for Bug# 3466223
5181       AND pha.po_header_id =pla.po_header_id;
5182 
5183     -- Cursor definition for picking values from JAI_PO_LINE_LOCATIONS
5184     -- using line_location_id as where clause
5185     CURSOR Fetch_Ja_In_Po_Ln_Loc_Cur IS
5186       SELECT line_location_id, po_line_id, po_header_id, tax_modified_flag,
5187         tax_amount, total_amount, line_focus_id, creation_date,
5188         created_by, last_update_date, last_updated_by, last_update_login,
5189         tax_category_id       -- cbabu for EnhancementBug# 2427465
5190       FROM JAI_PO_LINE_LOCATIONS
5191       WHERE Line_Location_Id = v_ln_loc_id;
5192 
5193     -- Cursor definition for picking values from JAI_PO_TAXES
5194     -- using line_location_id as where clause
5195     CURSOR fetch_po_ln_loc_tax_cur IS
5196       SELECT line_location_id,
5197              tax_line_no,
5198        po_line_id,
5199        po_header_id,
5200              precedence_1,
5201        precedence_2,
5202        precedence_3,
5203        precedence_4,
5204              precedence_5,
5205              precedence_6,  -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5206        precedence_7,
5207        precedence_8,
5208        precedence_9,
5209              precedence_10,
5210        tax_id,
5211        currency,
5212        tax_rate,
5213              qty_rate,
5214        uom,
5215        tax_amount,
5216        tax_type,
5217              vendor_id,
5218        modvat_flag,
5219        tax_target_amount,
5220        line_focus_id,
5221              creation_date,
5222        created_by,
5223        last_update_date,
5224        last_updated_by,
5225        last_update_login,
5226              tax_category_id       -- cbabu for EnhancementBug# 2427465
5227       FROM JAI_PO_TAXES
5228       WHERE Line_Location_Id = v_ln_loc_id;
5229 
5230     -- Cursor definition for picking values from JAI_PO_LINE_LOCATIONS
5231     -- using po_line_id as where clause
5232     CURSOR fetch_jain_line_cur IS
5233       SELECT line_location_id, po_line_id, po_header_id, tax_modified_flag,
5234         tax_amount, total_amount, line_focus_id, creation_date,
5235         created_by, last_update_date, last_updated_by, last_update_login,
5236         tax_category_id     -- cbabu for EnhancementBug# 2427465
5237       FROM JAI_PO_LINE_LOCATIONS
5238       WHERE Po_Line_Id = v_line_id
5239       AND po_header_id = p_from_hdr_id
5240       AND ( line_location_id IS NULL
5241         OR line_location_id = 0 );  -- cbabu for EnhancementBug# 2427465
5242 
5243     -- Cursor definition for picking values from JAI_PO_TAXES
5244     -- using po_line_id as where clause
5245 
5246     CURSOR fetch_jain_line_tax_cur IS
5247       SELECT line_location_id,
5248              tax_line_no,
5249        po_line_id,
5250        po_header_id,
5251              precedence_1,
5252        precedence_2,
5253        precedence_3,
5254        precedence_4,
5255              precedence_5,
5256              precedence_6,  -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5257        precedence_7,
5258        precedence_8,
5259        precedence_9,
5260              precedence_10,
5261        tax_id,
5262        currency,
5263        tax_rate,
5264              qty_rate,
5265        uom,
5266        tax_amount,
5267        tax_type,
5268              vendor_id,
5269        modvat_flag,
5270        tax_target_amount,
5271        line_focus_id,
5272              creation_date,
5273        created_by,
5274        last_update_date,
5275        last_updated_by,
5276        last_update_login,
5277              tax_category_id       -- cbabu for EnhancementBug# 2427465
5278       FROM  JAI_PO_TAXES
5279       WHERE  Po_Line_Id = v_line_id
5280       AND po_header_id = p_from_hdr_id
5281       AND ( line_location_id IS NULL
5282         OR line_location_id = 0 );  -- cbabu for EnhancementBug# 2427465
5283 
5284     -- Cursor variable for Fetch_Po_Ln_Loc_Cur
5285     fetch_ja_in_po_ln_loc_rec   FETCH_JA_IN_PO_LN_LOC_CUR%ROWTYPE;
5286     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.copy_source_taxes';
5287   BEGIN
5288 
5289   /*-----------------------------------------------------------------------------------------------------------------------
5290   CHANGE HISTORY:   FILENAME: ja_in_po_copydoc_dflt_p.sql
5291   S.No   Date       Author and Details
5292   -------------------------------------------------------------------------------------------------------------------------
5293   1  06/12/2002   cbabu for EnhancementBug# 2427465, FileVersion# 615.1
5294                      tax_category_id column is populated into PO and SO localization tables, which will be used to
5295                     identify from which tax_category the taxes are defaulted. Also the tax_category_id populated into
5296                     the  tax table will be useful to identify whether the tax is a defaulted or a manual tax.
5297 
5298   2 14/04/2004  Vijay Shankar for Bug# 3466223, FileVersion# 619.1
5299            Cursor fetch_line_id_cur is not having line_num filter that is added in this fix.
5300            Otherwise it is not defaulting properly
5301   -------------------------------------------------------------------------------------------------------------------------*/
5302 
5303     IF p_type = 'L' THEN
5304       Update JAI_PO_COPYDOC_T
5305       Set po_header_id = p_po_hdr_id
5306       Where po_line_id = p_po_line_id;
5307       IF SQL%NOTFOUND
5308       THEN
5309         RETURN;
5310       END IF;
5311     ELSE
5312       Update JAI_PO_COPYDOC_T
5313       Set po_header_id = p_po_hdr_id
5314       Where line_location_id = p_po_line_loc_id;
5315       IF SQL%NOTFOUND
5316        THEN
5317          RETURN;
5318        END IF;
5319       END IF;
5320 
5321     OPEN Fetch_Line_Loc_Id_Cur;
5322     FETCH Fetch_Line_Loc_Id_Cur INTO v_ln_loc_id ;
5323     CLOSE Fetch_Line_Loc_Id_Cur;
5324 
5325     OPEN Fetch_Line_Id_Cur;
5326     FETCH Fetch_Line_Id_Cur INTO v_line_id;
5327     CLOSE Fetch_Line_Id_Cur;
5328 
5329     --       Line Level
5330 --Added by kunkumar for forward porting to R12
5331 open fetch_vendor_id_cur;
5332 fetch fetch_vendor_id_cur into v_vendor_id, v_vendor_site_id;
5333 close fetch_vendor_id_cur;
5334 
5335 v_service_type_code :=jai_ar_rctla_trigger_pkg.get_service_type(v_vendor_id,v_vendor_site_id,'V');
5336 --Added by kunkumar End;
5337     IF p_type = 'L' THEN
5338 
5339       IF v_seq_val IS NULL THEN
5340 
5341         OPEN  Fetch_Focus_Id_Cur;
5342         FETCH Fetch_Focus_Id_Cur INTO v_seq_val;
5343         CLOSE Fetch_Focus_Id_Cur;
5344 
5345         FND_FILE.put_line( FND_FILE.log, 'v_seq_val->'||v_seq_val);
5346 
5347         FOR rec1 in Fetch_Jain_Line_Cur LOOP
5348 
5349           INSERT INTO JAI_PO_LINE_LOCATIONS (
5350             line_location_id, po_line_id,  po_header_id,
5351             tax_modified_flag, tax_amount, total_amount,
5352             line_focus_id, creation_date, created_by,
5353             last_update_date, last_updated_by, last_update_login,
5354             tax_category_id     -- cbabu for EnhancementBug# 2427465
5355          ,service_type_code ) VALUES (
5356             p_po_line_loc_id, p_po_line_id, p_po_hdr_id,
5357             'Y', rec1.tax_amount, rec1.total_amount,
5358             v_seq_val, p_cre_dt, p_cre_by,
5359             p_last_upd_dt, p_last_upd_by, p_last_upd_login,
5360             rec1.tax_category_id    -- cbabu for EnhancementBug# 2427465
5361           ,v_service_type_code);
5362 
5363         END LOOP;
5364       END IF;
5365 
5366       FND_FILE.put_line( FND_FILE.log, 'bef taxes');
5367         FOR rec2 in Fetch_Jain_Line_Tax_Cur LOOP
5368         FND_FILE.put_line( FND_FILE.log, 'rec2.tax_id->'||rec2.tax_id);
5369 
5370 
5371        -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5372 
5373         INSERT INTO JAI_PO_TAXES (
5374           line_location_id, tax_line_no, po_line_id, po_header_id,
5375           precedence_1, precedence_2, precedence_3, precedence_4,precedence_5,
5376     precedence_6, precedence_7, precedence_8, precedence_9,
5377           precedence_10, tax_id, currency, tax_rate, qty_rate,
5378           uom, tax_amount, tax_type, vendor_id, modvat_flag,
5379           tax_target_amount, line_focus_id, creation_date, created_by,
5380           last_update_date, last_updated_by, last_update_login,
5381           tax_category_id     -- cbabu for EnhancementBug# 2427465
5382         ) VALUES (
5383           p_po_line_loc_id, rec2.tax_line_no, p_po_line_id, p_po_hdr_id,
5384           rec2.precedence_1, rec2.precedence_2, rec2.precedence_3, rec2.precedence_4,rec2.precedence_5,
5385     rec2.precedence_6, rec2.precedence_7, rec2.precedence_8, rec2.precedence_9, rec2.precedence_10 ,
5386     rec2.tax_id, rec2.currency, rec2.tax_rate, rec2.qty_rate,
5387           rec2.uom, rec2.tax_amount, rec2.tax_type, rec2.vendor_id, rec2.modvat_flag,
5388           rec2.tax_target_amount, v_seq_val, p_cre_dt, p_cre_by,
5389           p_last_upd_dt, p_last_upd_by, p_last_upd_login,
5390           rec2.tax_category_id    -- cbabu for EnhancementBug# 2427465
5391         );
5392 
5393          END LOOP;
5394 
5395      ELSE
5396 
5397       IF v_ln_loc_id IS NOT NULL THEN
5398 
5399         OPEN  Fetch_Focus_Id_Cur;
5400         FETCH Fetch_Focus_Id_Cur INTO v_seq_val;
5401         CLOSE Fetch_Focus_Id_Cur;
5402 
5403         OPEN Fetch_Ja_In_Po_Ln_Loc_Cur ;
5404         FETCH Fetch_Ja_In_Po_Ln_Loc_Cur INTO Fetch_Ja_In_Po_Ln_Loc_Rec;
5405 
5406         INSERT INTO JAI_PO_LINE_LOCATIONS (
5407           line_location_id, po_line_id,  po_header_id,
5408           tax_modified_flag, tax_amount, total_amount, line_focus_id,
5409           creation_date, created_by, last_update_date, last_updated_by, last_update_login,
5410           tax_category_id,service_type_code       -- cbabu for EnhancementBug# 2427465
5411         ) VALUES (
5412           p_po_line_loc_id, p_po_line_id, p_po_hdr_id,
5413           'Y', fetch_ja_in_po_ln_loc_rec.tax_amount, fetch_ja_in_po_ln_loc_rec.total_amount,
5414           v_seq_val, p_cre_dt, p_cre_by, p_last_upd_dt, p_last_upd_by, p_last_upd_login,
5415           fetch_ja_in_po_ln_loc_rec.tax_category_id     -- cbabu for EnhancementBug# 2427465
5416         ,v_service_type_code);
5417 
5418         CLOSE Fetch_Ja_In_Po_Ln_Loc_Cur;
5419 
5420        -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5421 
5422         FOR rec in Fetch_Po_Ln_Loc_Tax_Cur LOOP
5423         INSERT INTO JAI_PO_TAXES (
5424           line_location_id, tax_line_no, po_line_id, po_header_id,
5425           precedence_1, precedence_2, precedence_3, precedence_4, precedence_5,
5426     precedence_6, precedence_7, precedence_8, precedence_9, precedence_10,
5427     tax_id, currency, tax_rate, qty_rate,
5428           uom, tax_amount, tax_type,  vendor_id, modvat_flag,
5429           tax_target_amount, line_focus_id, creation_date, created_by,
5430           last_update_date, last_updated_by, last_update_login,
5431           tax_category_id       -- cbabu for EnhancementBug# 2427465
5432         ) VALUES (
5433           p_po_line_loc_id, rec.tax_line_no, p_po_line_id, p_po_hdr_id,
5434           rec.precedence_1, rec.precedence_2, rec.precedence_3, rec.precedence_4, rec.precedence_5,
5435     rec.precedence_6, rec.precedence_7, rec.precedence_8, rec.precedence_9, rec.precedence_10,
5436     rec.tax_id, rec.currency, rec.tax_rate, rec.qty_rate,
5437           rec.uom, rec.tax_amount, rec.tax_type, rec.vendor_id, rec.modvat_flag,
5438           rec.tax_target_amount, v_seq_val, p_cre_dt, p_cre_by,
5439           p_last_upd_dt, p_last_upd_by, p_last_upd_login,
5440           rec.tax_category_id     -- cbabu for EnhancementBug# 2427465
5441         );
5442         END LOOP;
5443 
5444       END IF;
5445     END IF;
5446 
5447      IF p_type = 'L' THEN
5448        Delete From JAI_PO_COPYDOC_T
5449         Where po_line_id = p_po_line_id
5450           AND line_location_id is null;
5451      ELSE
5452        Delete From JAI_PO_COPYDOC_T
5453         Where line_location_id = p_po_line_loc_id;
5454      END IF;
5455   EXCEPTION
5456     WHEN OTHERS THEN
5457     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5458     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5459     app_exception.raise_exception;
5460   END copy_source_taxes;
5461 
5462   /*----------------------------------------------------------------------------------------*/
5463 
5464   PROCEDURE copy_quot_taxes
5465   (
5466     errbuf OUT NOCOPY VARCHAR2,
5467     retcode OUT NOCOPY VARCHAR2,
5468     p_line_loc_id IN NUMBER,
5469     p_po_hdr_id IN NUMBER,
5470     p_po_line_id IN NUMBER,
5471     p_qty IN NUMBER,
5472     p_frm_hdr_id IN NUMBER,
5473     p_frm_line_id IN NUMBER,
5474     p_price IN NUMBER,
5475     p_unit_code IN VARCHAR2,
5476     p_assessable_value IN NUMBER,
5477     p_cre_dt IN DATE,
5478     p_cre_by IN NUMBER,
5479     p_last_upd_dt IN DATE,
5480     p_last_upd_by IN NUMBER,
5481     p_last_upd_login IN NUMBER
5482   )
5483   IS
5484 
5485     v_quot_line_loc_id            NUMBER;
5486     v_line_focus_id               NUMBER;
5487     v_unit_code                   VARCHAR2(25);
5488     v_tax_amt                     NUMBER;
5489     dummy                         NUMBER;
5490     ln_vat_assess_value           NUMBER;
5491 
5492     v_tax_category_id_holder JAI_PO_LINE_LOCATIONS.tax_category_id%TYPE;    -- cbabu for EnhancementBug# 2427465
5493     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.copy_quot_taxes';
5494     ------------------------------>
5495 
5496     CURSOR tax_cur IS
5497        SELECT a.Po_Line_Id, a.tax_line_no lno, a.tax_id,
5498               a.precedence_1 p_1,
5499               a.precedence_2 p_2,
5500               a.precedence_3 p_3,
5501               a.precedence_4 p_4,
5502               a.precedence_5 p_5,
5503               a.precedence_6 p_6,  -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5504               a.precedence_7 p_7,
5505               a.precedence_8 p_8,
5506               a.precedence_9 p_9,
5507               a.precedence_10 p_10,
5508               a.currency, a.tax_rate, a.qty_rate, a.uom, a.tax_amount, a.tax_type,
5509               a.vendor_id, a.modvat_flag,
5510               tax_category_id     -- cbabu for EnhancementBug# 2427465
5511       FROM   JAI_PO_TAXES a
5512       /*condition modified for bug 7436368*/
5513       WHERE  ((a.line_location_id IS NULL AND v_quot_line_loc_id=-999) OR (a.line_location_id = v_quot_line_loc_id))
5514       --a.line_location_id = v_quot_line_loc_id /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
5515     --WHERE  NVL( a.line_location_id, -999 ) = v_quot_line_loc_id
5516              AND  Po_Line_Id = p_frm_line_id
5517      ORDER BY  a.tax_line_no;
5518 
5519    CURSOR Fetch_Line_Focus_Id_Cur IS
5520       SELECT Line_Focus_Id
5521       FROM   JAI_PO_LINE_LOCATIONS
5522       WHERE  Po_Line_Id = p_po_line_id AND
5523              Line_Location_Id = p_line_loc_id;
5524 
5525     -- Start, added by Vijay Shankar for Bug# 3478460
5526     CURSOR c_line_tax_category_id_1(p_po_line_id IN NUMBER) IS
5527       SELECT tax_category_id
5528       FROM JAI_PO_LINE_LOCATIONS
5529       WHERE po_line_id = p_po_line_id
5530       AND line_location_id IS NULL;
5531 
5532     CURSOR c_line_tax_category_id_2(p_po_line_id IN NUMBER, p_line_location_id IN NUMBER) IS
5533       SELECT tax_category_id
5534       FROM JAI_PO_LINE_LOCATIONS
5535       WHERE po_line_id = p_po_line_id
5536       AND line_location_id = p_line_location_id;
5537     -- End, 3478460
5538 
5539   --Added by Nagaraj.s for Bug2953445..
5540   CURSOR c_check_adhoc_flag(p_tax_id number) IS
5541   select nvl(adhoc_flag,'N')
5542   from JAI_CMN_TAXES_ALL
5543   where tax_id = p_tax_id;
5544 
5545   --Added by Ravi for vat assessable vlue
5546   CURSOR cur_vendor
5547   IS
5548   SELECT vendor_id,vendor_site_id
5549     FROM po_headers_all
5550    WHERE po_header_id = p_po_hdr_id;
5551 
5552   CURSOR cur_item
5553   IS
5554   SELECT ITEM_ID
5555     FROM po_lines_all
5556    WHERE po_line_id = p_po_line_id;
5557 
5558   lv_item_id po_lines_all.item_id%type;
5559 
5560   vendor_rec  cur_vendor%ROWTYPE;
5561   v_check_adhoc_flag JAI_CMN_TAXES_ALL.adhoc_flag%type; --Nagaraj.s for Bug2953445.
5562   v_tax_amount       NUMBER;--Nagaraj.s for Bug2953445.
5563 
5564     ------------------------------>
5565 
5566   -- FND_EXECUTABLE -> JAINPOTD
5567   BEGIN
5568 
5569   /*-----------------------------------------------------------------------------------------------------------------------
5570   CHANGE HISTORY:   FILENAME: ja_in_po_quot_taxes_p.sql
5571   S.No   Date       Author and Details
5572   -------------------------------------------------------------------------------------------------------------------------
5573   1  06/12/2002   cbabu for EnhancementBug# 2427465, FileVersion# 615.1
5574                      tax_category_id column is populated into PO and SO localization tables, which will be used to
5575                     identify from which tax_category the taxes are defaulted. Also the tax_category_id populated into
5576                     the  tax table will be useful to identify whether the tax is a defaulted or a manual tax.
5577 
5578   2.   14/05/2003   Nagaraj.s for Bug#2953445. File Version : 616.1
5579                     In case of a Catalog Quotation, Adhoc Amounts Entered were defaulted as Zero, as previously Tax Amounts
5580                     were Zero irrespective of whether the Tax is an Adhoc Tax or not.
5581                     hence now a check has been incorporated, wherin if the Tax is of Adhoc Type, then The Tax Amounts
5582                     are populated as in the Quotation, else Tax Amounts are populated to Zero, so that Recalculation
5583                     of Taxes happen based upon precedences.
5584 
5585   3  09/03/2004   Vijay Shankar for Bug# 3478460, FileVersion# 618.1
5586                      Whenever the code doesn't fine a record for BPO Line in JAI_PO_LINE_LOCATIONS, then this procedure fails with either
5587                      no_data_found or duplicate_records found. Fixed this by taking tax category from tax lines otherwise fetching from
5588                      JAI_PO_LINE_LOCATIONS using the CURSORS c_line_tax_category_id_1 and c_line_tax_category_id_2
5589 
5590   4.   17/mar-2005     Rchandan for bug#4245365   Version#115.2. base bug#4245089
5591                        Changes made to calculate VAT assessable value . This vat assessable is passed
5592                        to the procedure that calculates the VAT related taxes
5593 
5594   -------------------------------------------------------------------------------------------------------------------------*/
5595 
5596       jai_po_cmn_pkg.locate_source_line
5597                        ( p_frm_hdr_id,
5598                          p_frm_line_id,
5599                          p_qty,
5600                          dummy,
5601                          v_quot_line_loc_id,
5602                          p_frm_line_id
5603                         );
5604 
5605        jai_po_cmn_pkg.insert_line
5606                     ( 'STANDARD',
5607                       p_line_loc_id,
5608                       p_po_hdr_id,
5609                       p_po_line_id,
5610                       p_cre_dt,
5611                       p_cre_by,
5612                       p_last_upd_dt,
5613                       p_last_upd_by,
5614                       p_last_upd_login,
5615                       'I'
5616                      );
5617 
5618        OPEN  Fetch_Line_Focus_Id_Cur;
5619        FETCH Fetch_Line_Focus_Id_Cur INTO v_line_focus_id;
5620        CLOSE Fetch_Line_Focus_Id_Cur;
5621 
5622        FOR rec in tax_cur LOOP
5623           --Added by Nagaraj.s to whether the Tax is an Adhoc One for Bug2953445.
5624       open c_check_adhoc_flag(rec.tax_id);
5625       fetch c_check_adhoc_flag into v_check_adhoc_flag;
5626       close c_check_adhoc_flag;
5627 
5628           --If this is an Adhoc Flag, then Tax Amount is to be the same Tax Amount as in Catalog Quotation
5629           --Else Tax Amount is Zero as before.
5630 
5631       if v_check_adhoc_flag ='Y' then
5632        v_tax_amount := rec.tax_amount;
5633       else
5634        v_tax_amount := 0;
5635       end if;
5636           --Ends here...
5637 
5638       INSERT INTO JAI_PO_TAXES(
5639                                   po_line_id,
5640                                   po_header_id,
5641                                   line_location_id,
5642                                   line_focus_id,
5643                                   tax_line_no,
5644                                   precedence_1,
5645                                   precedence_2,
5646                                   precedence_3,
5647                                   precedence_4,
5648                                   precedence_5,
5649                                   precedence_6,  -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5650                                   precedence_7,
5651                                   precedence_8,
5652                                   precedence_9,
5653                                   precedence_10,
5654                                   tax_id, tax_rate, qty_rate, uom, tax_amount, tax_target_amount,
5655                                   tax_type, modvat_flag, vendor_id, currency,
5656                                   creation_date, created_by, last_update_date,
5657                                   last_updated_by, last_update_login,
5658                                   tax_category_id     -- cbabu for EnhancementBug# 2427465
5659                              )
5660         VALUES (
5661                       p_po_line_id, p_po_hdr_id, p_line_loc_id, v_line_focus_id, rec.lno,
5662                       rec.p_1, rec.p_2, rec.p_3, rec.p_4, rec.p_5,rec.p_6, rec.p_7, rec.p_8, rec.p_9, rec.p_10,
5663                       rec.tax_id, rec.tax_rate, rec.qty_rate, rec.uom, v_tax_amount, 0, --Previously The Value of TaxAmount is 0 Which is now changed to v_tax_amount for Bug2953445
5664                       rec.tax_type, rec.modvat_flag, rec.vendor_id, rec.currency,
5665                       p_cre_dt, p_cre_by, p_last_upd_dt, p_last_upd_by, p_last_upd_login,
5666                       rec.tax_category_id     -- cbabu for EnhancementBug# 2427465
5667               );
5668 
5669       -- Vijay Shankar for Bug# 3478460
5670       v_tax_category_id_holder := nvl( rec.tax_category_id, v_tax_category_id_holder);
5671 
5672       v_check_adhoc_flag :=NULL;
5673       v_tax_amount       :=0;
5674     END LOOP;
5675 
5676     -- Start, if clause added by Vijay Shankar for Bug# 3478460
5677     If v_tax_category_id_holder IS NULL THEN
5678       IF v_quot_line_loc_id = -999 THEN
5679         OPEN c_line_tax_category_id_1(p_frm_line_id);
5680         FETCH c_line_tax_category_id_1 INTO v_tax_category_id_holder;
5681         CLOSE c_line_tax_category_id_1;
5682       ELSE
5683         OPEN c_line_tax_category_id_2(p_frm_line_id, v_quot_line_loc_id);
5684         FETCH c_line_tax_category_id_2 INTO v_tax_category_id_holder;
5685         CLOSE c_line_tax_category_id_2;
5686       END IF;
5687     end if;
5688 
5689     UPDATE JAI_PO_LINE_LOCATIONS
5690     SET tax_category_id = v_tax_category_id_holder
5691     WHERE line_focus_id = v_line_focus_id;
5692     -- End, 3478460
5693 
5694     /* following block is commented and replaced with the above UPDATE statement
5695     -- Start, cbabu for EnhancementBug# 2427465
5696     BEGIN
5697       IF v_quot_line_loc_id = -999 THEN
5698         SELECT tax_category_id INTO v_tax_category_id_holder
5699         FROM JAI_PO_LINE_LOCATIONS
5700         WHERE po_line_id = p_frm_line_id
5701         AND (line_location_id IS NULL OR line_location_id = 0);
5702       ELSE -- line_location_id is present in PO_LINE_LOCATIONS_ALL
5703         SELECT tax_category_id INTO v_tax_category_id_holder
5704         FROM JAI_PO_LINE_LOCATIONS
5705         WHERE po_line_id = p_frm_line_id
5706         AND line_location_id = v_quot_line_loc_id;
5707       END IF;
5708 
5709       UPDATE JAI_PO_LINE_LOCATIONS
5710       SET tax_category_id = v_tax_category_id_holder
5711       WHERE line_focus_id = v_line_focus_id;
5712     EXCEPTION
5713       WHEN OTHERS THEN
5714         RAISE_APPLICATION_ERROR( -20101, '1 Exception raised in jai_po_tax_pkg.copy_quot_taxes : '||SQLERRM, TRUE);
5715     END;
5716     -- End, cbabu for EnhancementBug# 2427465
5717     */
5718     OPEN cur_vendor;
5719     FETCH cur_vendor INTO vendor_rec;
5720     CLOSE cur_vendor;
5721 
5722     OPEN cur_item;
5723     FETCH cur_item INTO lv_item_id;
5724     CLOSE cur_item;
5725 
5726     ln_vat_assess_value := jai_general_pkg.ja_in_vat_assessable_value
5727              ( p_party_id => vendor_rec.vendor_id,
5728                p_party_site_id => vendor_rec.vendor_site_id,
5729                p_inventory_item_id => lv_item_id,
5730                p_uom_code => p_unit_code,
5731                p_default_price => p_price,
5732                p_ass_value_date => SYSDATE,
5733                p_party_type => 'V'
5734              ) ;   -- Ravi for VAT
5735 
5736 
5737     jai_po_tax_pkg.calculate_tax
5738           ( 'STANDARDPO', p_po_hdr_id , p_po_line_id, p_line_loc_id,
5739            p_qty, p_price*p_qty, p_unit_code, v_tax_amt, p_assessable_value, ln_vat_assess_value*p_qty, NULL );
5740             -- Ravi for VAT
5741 
5742   EXCEPTION
5743     WHEN OTHERS THEN
5744     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
5745     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
5746     app_exception.raise_exception;
5747   END copy_quot_taxes;
5748 
5749 /*------------------------------------------------------------------------------------------------------------*/
5750   PROCEDURE copy_agreement_taxes
5751   (
5752     errbuf OUT NOCOPY VARCHAR2,
5753     retcode OUT NOCOPY VARCHAR2,
5754     p_seq_val     IN  NUMBER,
5755     p_qty         IN  NUMBER,
5756     p_hdr_id      IN  NUMBER,
5757     p_line_id     IN  NUMBER,
5758     p_line_loc_id IN  NUMBER,
5759     p_ship_type   IN  VARCHAR2,
5760     p_cum_flag    IN  VARCHAR2,
5761     p_cre_dt      IN  DATE,
5762     p_cre_by      IN  NUMBER,
5763     p_last_cre_dt IN  DATE,
5764     p_last_cre_by IN  NUMBER,
5765     p_last_login  IN  NUMBER
5766   , pv_retroprice_changed IN VARCHAR2 --Added by Kevin Cheng for Retroactive Price 2008/01/10
5767   ) IS
5768 
5769     v_qty     NUMBER;   --File.Sql.35 Cbabu  := p_qty;
5770     v_old_qty     NUMBER;
5771     v_cum_qty     NUMBER;
5772     v_line_id     NUMBER;
5773     v_tax_amt     NUMBER;
5774     v_tax_amt1    NUMBER;
5775     v_total_amt   NUMBER;
5776     tax_amount    NUMBER;
5777     v_line_loc_id   NUMBER;
5778     i       NUMBER; --File.Sql.35 Cbabu  := 1;
5779     j       NUMBER;
5780     k       NUMBER;
5781     v_row     NUMBER;
5782     flag      BOOLEAN;  --File.Sql.35 Cbabu  :=  TRUE;
5783     v_temp_price    NUMBER;
5784     v_temp_qty1   NUMBER;
5785     v_temp_qty2   NUMBER;
5786     v_count     NUMBER;
5787     v_unit_price    NUMBER;
5788     v_uom     VARCHAR2(50);
5789     v_uom_code    VARCHAR2(50);
5790     v_po_hdr_id   NUMBER;
5791     v_po_line_id    NUMBER;
5792     v_vendor_id   NUMBER;
5793     v_vendor_site_id  NUMBER;
5794     v_assessable_value  NUMBER;
5795     ln_vat_assess_value     NUMBER;      -- Ravi for VAT
5796     v_doc_curr    VARCHAR2(100);
5797     v_item_id     NUMBER;
5798     v_curr_conv_factor    NUMBER;
5799     DUMMY                 NUMBER;   --File.Sql.35 Cbabu  := 1;
5800     v_tax_count       NUMBER;
5801     vQryOn      VARCHAR2(15);
5802 
5803     TYPE v_Llid_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
5804     Llid_tab v_Llid_tab;
5805 
5806     TYPE v_Qty_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
5807     Qty_tab v_Qty_Tab;
5808 
5809     TYPE v_Price_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
5810     price_tab v_Price_Tab;
5811 
5812     -- Vijay Shankar for Bug# 3191450
5813     -- following TYPE definition is modified to use VARCHAR2 instead of CHAR, because this is padding spaces to the
5814     -- values in the plsql tables if string length of value is less than 50
5815     -- TYPE Uom IS TABLE OF CHAR(50) INDEX BY BINARY_INTEGER;
5816     TYPE Uom IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
5817     uom_tab  uom;
5818 
5819     v_tax_category_id_holder JAI_PO_LINE_LOCATIONS.tax_category_id%TYPE;  -- cbabu for EnhancementBug# 2427465
5820 
5821 
5822 -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
5823 
5824     CURSOR Fetch_Taxes_Cur( lineid IN NUMBER, llid IN NUMBER ) IS
5825     SELECT Line_Location_Id, Tax_Line_No, Po_Line_Id, Po_Header_Id,
5826            Precedence_1, Precedence_2, Precedence_3, Precedence_4,Precedence_5,
5827      Precedence_6, Precedence_7, Precedence_8, Precedence_9,Precedence_10,
5828      Tax_Id, Currency, Tax_Rate, Qty_Rate, UOM, Tax_Amount, Tax_Type,
5829            Vendor_Id, Modvat_Flag, Tax_Target_Amount,
5830            tax_category_id    -- cbabu for EnhancementBug# 2427465
5831       FROM JAI_PO_TAXES
5832       WHERE NVL( Line_Location_Id, -999 ) = llid    /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980* -- NVL condition is added by SAcsethi for bug 6134628 */
5833        AND Po_Line_Id = lineid
5834      ORDER BY Tax_Line_No;
5835 
5836     CURSOR Fetch_Tax_Lines_Cur IS
5837     SELECT *
5838       FROM JAI_PO_REQUEST_T
5839      WHERE line_focus_id = p_seq_val  -- Modified By Sjha
5840      ORDER BY Tax_Line_No;
5841 
5842     v_junk_uom  MTL_UNITS_OF_MEASURE.unit_of_measure%TYPE;    -- Added by Vijay Shankar for Bug# 3205861
5843     CURSOR Fetch_Qty_Cur( llid IN NUMBER ) IS
5844     SELECT Quantity, Price_Override, Unit_Meas_Lookup_Code
5845       FROM Po_Line_Locations_All
5846      WHERE Line_Location_Id = llid;
5847 
5848     -- CURSOR Fetch_Cum_Qty_Cur IS
5849     CURSOR Fetch_Cum_Qty_Cur(pQryOn IN VARCHAR2, pShipToOrganizationId IN NUMBER, pShipToLocationId IN NUMBER, cp_shipment_type Po_Line_Locations_All.shipment_type%type) IS
5850     SELECT SUM( Quantity )
5851       FROM   Po_Line_Locations_All PLL
5852      WHERE  Po_Line_Id = p_line_id
5853           -- cbabu for Bug# 3102375
5854        AND shipment_type <> cp_shipment_type --'PRICE BREAK'
5855        AND ((pQryOn = 'ALL'  AND PLL.SHIP_TO_ORGANIZATION_ID = pShipToOrganizationId  AND PLL.SHIP_TO_LOCATION_ID = pShipToLocationId )
5856         OR (pQryOn = 'ORG'  AND PLL.SHIP_TO_ORGANIZATION_ID = pShipToOrganizationId  AND PLL.SHIP_TO_LOCATION_ID IS NULL )
5857         OR (pQryOn = 'NULL'  AND PLL.SHIP_TO_ORGANIZATION_ID IS NULL  AND PLL.SHIP_TO_LOCATION_ID IS NULL )
5858       );
5859 
5860     -- CURSOR Fetch_Count_Llid_Cur IS
5861     CURSOR Fetch_Count_Llid_Cur(pQryOn IN VARCHAR2, pShipToOrganizationId IN NUMBER, pShipToLocationId IN NUMBER, cp_shipment_type Po_Line_Locations_All.shipment_type%type) IS
5862     SELECT NVL( COUNT( Line_Location_Id ), 0 )
5863       FROM Po_Line_Locations_All PLL
5864      WHERE Po_Line_Id  = p_line_id
5865        AND Shipment_Type = cp_shipment_type --'PRICE BREAK'
5866           -- cbabu for Bug# 3102375
5867        AND ((pQryOn = 'ALL'  AND PLL.SHIP_TO_ORGANIZATION_ID = pShipToOrganizationId  AND PLL.SHIP_TO_LOCATION_ID = pShipToLocationId )
5868         OR (pQryOn = 'ORG'  AND PLL.SHIP_TO_ORGANIZATION_ID = pShipToOrganizationId  AND PLL.SHIP_TO_LOCATION_ID IS NULL )
5869         OR (pQryOn = 'NULL'  AND PLL.SHIP_TO_ORGANIZATION_ID IS NULL  AND PLL.SHIP_TO_LOCATION_ID IS NULL )
5870       )
5871        AND SYSDATE between nvl(start_date, SYSDATE) and nvl(end_date, SYSDATE);
5872 
5873     -- CURSOR Fetch_Locid_Cur IS
5874     CURSOR Fetch_Locid_Cur(pQryOn IN VARCHAR2, pShipToOrganizationId IN NUMBER, pShipToLocationId IN NUMBER, cp_shipment_type Po_Line_Locations_All.shipment_type%type) IS
5875     SELECT Line_Location_Id, Quantity, Price_Override, Unit_Meas_Lookup_Code
5876       FROM   Po_Line_Locations_All PLL
5877      WHERE  Po_Header_Id  = p_hdr_id
5878        AND    Po_Line_Id    = p_line_id
5879        AND    Shipment_Type = cp_shipment_type --'PRICE BREAK'
5880       -- cbabu for Bug# 3102375
5881        AND ((pQryOn = 'ALL'  AND PLL.SHIP_TO_ORGANIZATION_ID = pShipToOrganizationId  AND PLL.SHIP_TO_LOCATION_ID = pShipToLocationId )
5882         OR (pQryOn = 'ORG'  AND PLL.SHIP_TO_ORGANIZATION_ID = pShipToOrganizationId  AND PLL.SHIP_TO_LOCATION_ID IS NULL )
5883         OR (pQryOn = 'NULL'  AND PLL.SHIP_TO_ORGANIZATION_ID IS NULL AND PLL.SHIP_TO_LOCATION_ID IS NULL )
5884       )
5885        AND SYSDATE between nvl(start_date, SYSDATE) and nvl(end_date, SYSDATE)
5886      ORDER BY Quantity;
5887 
5888     -- added by cbabu for Bug# 3102375
5889     CURSOR cShipmentDetails(pLineLocationId IN NUMBER) IS
5890     SELECT ship_to_organization_id, ship_to_location_id
5891       FROM po_line_locations_all
5892      WHERE line_location_id = pLineLocationId;
5893     vShpDtl cShipmentDetails%ROWTYPE;
5894 
5895     ------------------------------Added by Nagaraj.s for Bug2461414>
5896     CURSOR Fetch_Price_cur IS
5897     SELECT Price_Override
5898       FROM Po_Line_Locations_All
5899      WHERE po_header_id = p_hdr_id
5900        AND po_line_id = p_line_id
5901        AND line_location_id=p_line_loc_id;
5902 
5903     CURSOR Fetch_Lineid_Cur IS
5904     SELECT Po_Line_Id, Unit_Price, Unit_Meas_Lookup_Code, Item_Id
5905       FROM   Po_Lines_All
5906      WHERE  Po_Line_Id = p_line_id;
5907 
5908     CURSOR Fetch_UOMCode_Cur( uom IN VARCHAR2 ) IS
5909     SELECT Uom_Code
5910       FROM   Mtl_Units_Of_Measure
5911      WHERE  Unit_Of_Measure = uom;
5912 
5913     CURSOR Fetch_Tot_Sum_Cur( llid IN NUMBER ) IS
5914     SELECT SUM( NVL( Tax_Amount, 0 ) )
5915       FROM   JAI_PO_TAXES
5916      WHERE  Line_Location_Id = llid
5917        AND   Tax_Type <> jai_constants.tax_type_tds; --'TDS';
5918 
5919     CURSOR Get_Assessable_Val_Cur IS
5920     SELECT Vendor_Id, Vendor_Site_Id, Currency_Code
5921       FROM   Po_Headers_All
5922      WHERE  Po_Header_Id = v_po_hdr_id;
5923 
5924     CURSOR Get_Item_Id_Cur IS
5925     SELECT Item_Id
5926       FROM   Po_Lines_All
5927      WHERE  Po_Line_Id = v_po_line_id;
5928 
5929     -- added by Vijay Shankar for Bug# 3487904
5930     CURSOR c_line_tax_category_id_1(p_po_line_id IN NUMBER) IS
5931     SELECT tax_category_id
5932       FROM JAI_PO_LINE_LOCATIONS
5933      WHERE po_line_id = p_po_line_id
5934        AND line_location_id IS NULL;
5935 
5936     CURSOR c_line_tax_category_id_2(p_po_line_id IN NUMBER, p_line_location_id IN NUMBER) IS
5937     SELECT tax_category_id
5938       FROM JAI_PO_LINE_LOCATIONS
5939      WHERE po_line_id = p_po_line_id
5940        AND line_location_id = p_line_location_id;
5941     -- End, 3487904
5942 
5943 
5944     /*  date 08-Aug-2007 by sacsethi for bug 6134628
5945         || Start 6134628
5946     */
5947 
5948     lv_override_flag JAI_CMN_VENDOR_SITES.override_flag%type ;
5949     lv_cre_dt    DATE;
5950     lv_cre_by    NUMBER;
5951     lv_last_upd_dt   DATE ;
5952     lv_last_upd_by   NUMBER;
5953     lv_last_upd_login  NUMBER;
5954     lv_price     NUMBER;
5955     lv_org_id            NUMBER ;
5956     lv_curr   PO_HEADERS_ALL.CURRENCY_CODE%TYPE ;
5957     lv_conv_rate number ;
5958     lv_type_lookup_code  VARCHAR2(30);
5959     lv_quot_class_code   VARCHAR2(30);
5960     lv_rate  PO_HEADERS_ALL.RATE%TYPE    ;
5961     lv_ship_to_location_id  PO_HEADERS_ALL.ship_to_location_id%type  ;
5962 
5963     lv_rate_type     PO_HEADERS_ALL.RATE_TYPE%TYPE DEFAULT NULL ;
5964     lv_rate_date     PO_HEADERS_ALL.RATE_DATE%TYPE DEFAULT NULL ;
5965     lv_func_curr         VARCHAR2(15);
5966 
5967     flag1     VARCHAR2(10);
5968 
5969     CURSOR tax_override_flag_cur(c_vendor_id NUMBER, c_vendor_site_id NUMBER) IS
5970     SELECT override_flag
5971     FROM JAI_CMN_VENDOR_SITES
5972     WHERE vendor_id = c_vendor_id
5973     AND vendor_site_id = nvl(c_vendor_site_id,0) ;
5974 
5975     cursor fetch_vendor_id_cur(p_po_hdr_id  po_headers_all.po_header_id%type )  IS
5976     select vendor_id,vendor_site_id , currency_code , rate ,RATE_TYPE , RATE_DATE  ,ship_to_location_id
5977     from po_headers_all
5978     where po_header_id=p_po_hdr_id;
5979 
5980     CURSOR Fetch_Dtls1_Cur( lineid IN NUMBER, linelocid IN NUMBER ) IS
5981     SELECT  Price_Override ,Unit_Meas_Lookup_Code
5982     FROM   Po_Line_Locations_All
5983     WHERE  Po_Line_Id = lineid
5984     AND   Line_Location_Id = linelocid;
5985 
5986     CURSOR Fetch_Org_Id_Cur IS
5987     SELECT Inventory_Organization_id
5988     FROM   Hr_Locations
5989     WHERE  Location_Id = lv_ship_to_location_id ;
5990 
5991     /*  end 6134628
5992     */
5993 
5994     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.copy_agreement_taxes';
5995   BEGIN
5996 
5997   /*-----------------------------------------------------------------------------------------------------------------------
5998   CHANGE HISTORY:   FILENAME: ja_in_po_conc_process_p.sql
5999   S.No   Date       Author and Details
6000   -------------------------------------------------------------------------------------------------------------------------
6001   1    01/08/2002   Nagaraj.s for Bug#2461414
6002                     The Unit Price in case of an Blanket release was being fetched from  po_line_locations_all where
6003                     shipment type ='PRICE BREAK' The Price is now calculated based upon the price as available in base
6004                     apps screen based upon which taxes are calculated properly.
6005 
6006   2  06/12/2002   cbabu for EnhancementBug# 2427465, FileVersion# 615.2
6007                     tax_category_id column is populated into PO and SO localization tables, which will be used to
6008                     identify from which tax_category the taxes are defaulted. Also the tax_category_id populated into
6009                     the  tax table will be useful to identify whether the tax is a defaulted or a manual tax.
6010 
6011   3  17/08/2003   Vijay Shankar for Bug# 3102375, FileVersion# 616.1
6012                      ship_to_location is not considered in the filter condition to fetch the PRICE BREAK information from the
6013                      cursors Fetch_Count_Llid_Cur and Fetch_Locid_Cur. The specified cursors are rectified, so that the cursors
6014                      fetch only records pertaining to the ship_to_location of the release shipment
6015 
6016   4  16/10/2003   Vijay Shankar for Bug# 3191450, FileVersion# 616.2
6017                      because UOM_CODE plsql table is defined as CHAR(50), all the values in plsql table is being padded with spaces.
6018                      this makes the cursor's to fail that are dependant on these values. So, modified the definition of UOM_CODE plsql
6019                      table to use VARCHAR2 instead of CHAR
6020 
6021   5  20/10/2003   Vijay Shankar for Bug# 3205861, FileVersion# 616.3
6022                      because UOM_CODE plsql table is defined as CHAR(50), all the values in plsql table is being padded with spaces.
6023 
6024   6  05/03/2004   Vijay Shankar for Bug# 3487904, FileVersion# 618.1
6025                      Whenever the code doesn't fine a record for BPO Line in JAI_PO_LINE_LOCATIONS, then this procedure fails with either
6026                      no_data_found or duplicate_records found. Fixed this by taking tax category from tax lines otherwise fetching from
6027                      JAI_PO_LINE_LOCATIONS using the CURSORS c_line_tax_category_id_1 and c_line_tax_category_id_2
6028 
6029   7.     17/mar-2005   Rchandan for bug#4245365   Version#115.2. base bug#4245089
6030                        Changes made to calculate VAT assessable value . This vat assessable is passed
6031                        to the procedure that calculates the VAT related taxes
6032 
6033   8.    08-Aug-2007    sacsethi for bug 6134628  , Version 120.19
6034 
6035                        Problem - R12RUP04-ST1: TAXES ARE NOT DEFAULTING FROM BPO TO RELEASES
6036 
6037 		       Solution Approach -
6038 
6039 		       Procedure copy_agreement_taxes , Code is added to check whether override_flag is Y or
6040 		       If Override_Flag ='Y' then
6041 		              Default Taxes by using tax defaultation Hirarchy
6042                        else
6043 		              Copy Taxes from Blanked PO
6044                        end if ;
6045 
6046 		       Changes Details
6047 		       -----------------
6048                          Object Type           Object Name                 Desc.
6049 			 -------------------------------------------------------
6050 			 Procedure             copy_agreement_taxes        Code is added related to Supplier Override flag
6051 			                                                   and Tax defaultation flag
6052 
6053 			 Procedure             Ja_In_Po_Case2              code is added for RELEASE type_lookup_code
6054 
6055   9.    01/15/2008  Kevin Cheng   Add a parameter to distinguish retroactive price update process
6056   -------------------------------------------------------------------------------------------------------------------------*/
6057 
6058     --File.Sql.35 Cbabu
6059     v_qty    := p_qty;
6060     i        := 1;
6061     flag     :=  TRUE;
6062     DUMMY    := 1;
6063 
6064 
6065     /*  Date 08-Aug-2007 by sacsethi for bug 6134628
6066         || Start 6134628
6067     */
6068    v_vendor_id := null ;
6069    v_vendor_site_id := null;
6070    lv_override_flag := 'N' ;
6071 
6072    open fetch_vendor_id_cur(p_hdr_id)  ;
6073    fetch fetch_vendor_id_cur into v_vendor_id , v_vendor_site_id  ,lv_curr   ,lv_rate ,lv_rate_type , lv_rate_date ,lv_ship_to_location_id;
6074    close fetch_vendor_id_cur ;
6075 
6076    open tax_override_flag_cur (v_vendor_id   , v_vendor_site_id  )  ;
6077    fetch tax_override_flag_cur into lv_override_flag ;
6078    close tax_override_flag_cur ;
6079 
6080    open Fetch_Org_Id_Cur ;
6081    fetch Fetch_Org_Id_Cur into lv_org_id;
6082    close Fetch_Org_Id_Cur ;
6083 
6084 
6085   IF lv_override_flag ='Y' THEN
6086       --  Override_flag ='Y'
6087       --  Cause Tax defaultation to happen
6088       --  from defaultation hirarchy
6089 
6090       lv_cre_dt          := p_cre_dt       ;
6091       lv_cre_by          := p_cre_by       ;
6092       lv_last_upd_dt     := p_last_cre_dt  ;
6093       lv_last_upd_by     := p_last_cre_by  ;
6094       lv_last_upd_login  := p_last_login   ;
6095       v_line_loc_id     := p_line_loc_id;
6096       v_po_line_id      := p_line_id;
6097       v_po_hdr_id       := p_hdr_id;
6098 
6099 
6100       lv_type_lookup_code   := 'RELEASE' ;
6101       lv_quot_class_code    := 'OTHERS';
6102 
6103       OPEN  Get_Item_Id_Cur;
6104       FETCH Get_Item_Id_Cur INTO v_item_id;
6105       CLOSE Get_Item_Id_Cur;
6106 
6107       OPEN  Fetch_Dtls1_Cur( v_po_line_id, v_line_loc_id );
6108       FETCH Fetch_Dtls1_Cur INTO lv_price , v_uom;
6109       CLOSE Fetch_Dtls1_Cur;
6110 
6111       OPEN  Fetch_UomCode_Cur( v_uom );
6112       FETCH Fetch_UomCode_Cur INTO v_uom_code;
6113       CLOSE Fetch_UomCode_Cur;
6114 
6115       OPEN  Fetch_Org_Id_Cur;
6116       FETCH Fetch_Org_Id_Cur INTO lv_org_id;
6117       CLOSE fetch_Org_Id_Cur;
6118 
6119 /*
6120       fnd_file.put_line(fnd_file.log,' v_type_lookup_code ' || v_type_lookup_code ||
6121                                      ' v_quot_class_code  ' || v_quot_class_code||
6122                                      'v_vendor_id ' || v_vendor_id||
6123                                      'v_vendor_site_id' ||v_vendor_site_id ||
6124                                      'v_curr  ' || v_curr||
6125                                      'v_org_id' ||v_org_id ||
6126                                      'v_Item_Id' ||v_Item_Id ||
6127                                      'v_line_loc_id ' ||v_line_loc_id ||
6128                                      'v_po_hdr_id ' ||v_po_hdr_id ||
6129                                      'v_po_line_id' || v_po_line_id||
6130                                      'v_price' || v_price||
6131                                      'v_qty         ' ||v_qty ||
6132                                      'v_cre_dt' || v_cre_dt||
6133                                      'v_cre_by' ||v_cre_by ||
6134                                      'v_last_upd_dt' || v_last_upd_dt||
6135                                      'v_last_upd_by' || v_last_upd_by||
6136                                      'v_last_upd_login' ||v_last_upd_login ||
6137                                      'v_uom_code' ||v_uom_code ||
6138                                      'flag1' ||flag1 ||
6139                                      'v_assessable_value ' ||v_assessable_value ||
6140                                      'ln_vat_assess_value ' || ln_vat_assess_value||
6141                                      'v_rate, 1 ) '  || v_rate  );
6142 */
6143 
6144       jai_po_tax_pkg.Ja_In_Po_Case2( lv_type_lookup_code  ,
6145                                      lv_quot_class_code  ,
6146                                      v_vendor_id,
6147                                      v_vendor_site_id,
6148                                      lv_curr,
6149                                      lv_org_id,
6150                                      v_Item_Id,
6151                                      v_line_loc_id,
6152                                      v_po_hdr_id     ,
6153                                      v_po_line_id     ,
6154                                      lv_price,
6155                                      v_qty         ,
6156                                      lv_cre_dt,
6157                                      lv_cre_by,
6158                                      lv_last_upd_dt,
6159                                      lv_last_upd_by,
6160                                      lv_last_upd_login,
6161                                      v_uom_code,
6162                                      'I',
6163                                      NVL( v_assessable_value, -9999 ),
6164                                      ln_vat_assess_value,
6165                                      NVL( lv_rate, 1 ) );
6166     /*
6167         End 6134628
6168     */
6169   ELSE  -- For Override filag = 'N'
6170 
6171   IF p_ship_type = 'SCHEDULED' THEN
6172 
6173     OPEN  Fetch_Qty_Cur( p_line_loc_id );
6174     FETCH Fetch_Qty_Cur INTO v_old_qty, v_temp_price, v_uom;
6175     CLOSE Fetch_Qty_Cur;
6176 
6177     FOR Tax_Rec IN Fetch_Tax_Lines_Cur LOOP
6178 
6179       v_tax_amt := ( NVL( Tax_Rec.Tax_Amount, 0 ) * NVL( v_qty, 0 ) ) / NVL( v_old_qty, 1 );
6180       --Incorporated by Nagaraj.s on 15/05/2002 for Bug#2373231
6181 
6182       BEGIN
6183         SELECT COUNT(1) INTO v_tax_count FROM
6184         JAI_PO_TAXES
6185         WHERE Line_Location_Id = Tax_Rec.Line_Location_Id AND
6186         TAX_ID = Tax_Rec.Tax_id;
6187       END;
6188 
6189       IF v_tax_count =0 THEN
6190 
6191 
6192          -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6193 
6194          INSERT INTO JAI_PO_TAXES(
6195           Line_Focus_Id,
6196           Line_Location_Id,  Tax_Line_No,
6197           Po_Line_Id, Po_Header_Id,
6198     Precedence_1, Precedence_2, Precedence_3, Precedence_4,Precedence_5,
6199     Precedence_6, Precedence_7, Precedence_8, Precedence_9,Precedence_10,
6200     Tax_Id, Currency,  Tax_Rate, Qty_Rate, UOM, Tax_Amount,
6201           Tax_Type, Modvat_Flag, Vendor_Id, Tax_Target_Amount,
6202           Creation_Date, Created_By,
6203           Last_Update_Date, Last_Updated_By, Last_Update_Login,
6204           tax_category_id   -- cbabu for EnhancementBug# 2427465
6205         ) VALUES (
6206           Tax_Rec.Line_Focus_Id, --p_seq_val, -- Modified By Sjha
6207           Tax_Rec.Line_Location_Id, Tax_Rec.Tax_Line_No,
6208           Tax_Rec.Po_Line_Id, Tax_Rec.Po_Header_Id,
6209     Tax_Rec.Precedence_1,Tax_Rec.Precedence_2, Tax_Rec.Precedence_3, Tax_Rec.Precedence_4, Tax_Rec.Precedence_5,
6210     Tax_Rec.Precedence_6,Tax_Rec.Precedence_7, Tax_Rec.Precedence_8, Tax_Rec.Precedence_9, Tax_Rec.Precedence_10,
6211     Tax_Rec.Tax_Id, Tax_Rec.Currency,
6212           Tax_Rec.Tax_Rate, Tax_Rec.Qty_Rate, Tax_Rec.UOM, v_tax_amt,
6213           Tax_Rec.Tax_Type, Tax_Rec.Modvat_Flag, Tax_Rec.Vendor_Id, Tax_Rec.Tax_Target_Amount,
6214           Tax_Rec.Creation_Date, Tax_Rec.Created_By,
6215           Tax_Rec.Last_Update_Date, Tax_Rec.Last_Updated_By, Tax_Rec.Last_Update_Login,
6216           tax_rec.tax_category_id   -- cbabu for EnhancementBug# 2427465
6217         );
6218       END IF;
6219       v_line_loc_id := Tax_Rec.Line_Location_Id;
6220       v_po_hdr_id := Tax_Rec.Po_Header_Id;
6221       v_po_line_id := Tax_Rec.Po_Line_Id;
6222 
6223     END LOOP;
6224 
6225        OPEN  Fetch_Qty_Cur( v_line_loc_id );
6226        FETCH Fetch_Qty_Cur INTO v_qty, v_temp_price
6227         -- Only PLANNED Shipment Type (Source line_location_id) will have UOM and Scheduled type of Shipments will not have value
6228         -- and this is the reason why excise taxes are not getting calculated on assessable value, bcos ass value is based on UOM
6229         -- Commented by Vijay Shankar for Bug# 3205861
6230         -- , v_uom
6231         , v_junk_uom
6232         ;
6233        CLOSE Fetch_Qty_Cur;
6234 
6235        OPEN  Fetch_UomCode_Cur( v_uom );
6236        FETCH Fetch_UomCode_Cur INTO v_uom_code;
6237        CLOSE Fetch_UomCode_Cur;
6238 
6239        OPEN  Get_Assessable_Val_Cur;
6240        FETCH Get_Assessable_Val_Cur INTO v_vendor_id, v_vendor_site_id, v_doc_curr;
6241        CLOSE Get_Assessable_Val_Cur;
6242 
6243        OPEN  Get_Item_Id_Cur;
6244        FETCH Get_Item_Id_Cur INTO v_item_id;
6245        CLOSE Get_Item_Id_Cur;
6246 
6247        v_assessable_value := jai_cmn_setup_pkg.get_po_assessable_value
6248                      ( v_vendor_id, v_vendor_site_id,
6249                        v_item_id, v_uom_code
6250                       );
6251 
6252        ln_vat_assess_value :=  jai_general_pkg.ja_in_vat_assessable_value
6253                                                 ( p_party_id => v_vendor_id,
6254                                                   p_party_site_id => v_vendor_site_id,
6255                                                   p_inventory_item_id => v_item_id,
6256                                                   p_uom_code => v_uom_code,
6257                                                   /* Bug 4520049. Added by Lakshmi Gopalsami*/
6258                                                   p_default_price => nvl(v_temp_price,v_unit_price),
6259                                                   p_ass_value_date => SYSDATE,
6260                                                   p_party_type => 'V'
6261                                                  ) ;    -- Ravi for VAT
6262 
6263        IF v_assessable_value IS NULL THEN
6264           v_assessable_value := v_temp_price * v_qty;
6265        ELSE
6266           v_assessable_value := v_assessable_value * v_qty;
6267           jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, v_assessable_value, v_doc_curr, v_curr_conv_factor ) ;
6268        END IF;
6269 
6270        ln_vat_assess_value := ln_vat_assess_value * v_qty;   -- Ravi for VAT
6271        IF ln_vat_assess_value <> ( v_temp_price * v_qty ) THEN     -- Ravi for VAT
6272 
6273          jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, ln_vat_assess_value, v_doc_curr, v_curr_conv_factor ) ;
6274 
6275        END IF;/*Ravi*/
6276 
6277 
6278        jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, DUMMY, v_doc_curr, v_curr_conv_factor ) ;
6279 
6280        jai_po_tax_pkg.calculate_tax
6281         ( 'STANDARDPO', v_po_hdr_id , v_po_line_id, v_line_loc_id,
6282           v_qty, v_qty*v_temp_price, v_uom_code,
6283           v_assessable_value, v_assessable_value, NULL, v_curr_conv_factor
6284          );
6285 
6286        OPEN  Fetch_Tot_Sum_Cur( v_line_loc_id );
6287        FETCH Fetch_Tot_Sum_Cur INTO v_tax_amt1;
6288        CLOSE Fetch_Tot_Sum_Cur;
6289 
6290        UPDATE JAI_PO_LINE_LOCATIONS
6291        SET    Tax_Amount   = v_tax_amt1,
6292             Total_Amount = NVL( v_qty * v_temp_price, 0 ) + v_tax_amt1 ,
6293       Last_Update_Date  = p_last_cre_dt,
6294       Last_Updated_By =   p_last_cre_by,
6295       Last_Update_Login = p_last_login
6296        WHERE  Line_Location_Id =  v_line_loc_id;
6297 
6298     ELSE  -- BLANKET
6299 
6300   --  pShipToOrganizationId IN NUMBER DEFAULT NULL
6301   --  pShipToLocationId IN NUMBER DEFAULT NULL
6302 
6303     -- cbabu for Bug# 3102375
6304     OPEN  cShipmentDetails(p_line_loc_id);
6305     FETCH cShipmentDetails INTO vShpDtl;
6306     CLOSE cShipmentDetails;
6307 
6308     IF vShpDtl.ship_to_organization_id IS NOT NULL AND vShpDtl.ship_to_location_id IS NOT NULL THEN
6309       vQryOn := 'ALL';
6310     ELSIF vShpDtl.ship_to_organization_id IS NOT NULL AND vShpDtl.ship_to_location_id IS NULL THEN
6311       vQryOn := 'ORG';
6312     ELSE
6313       vQryOn := 'NULL';
6314     END IF;
6315 
6316       -- OPEN  Fetch_Count_Llid_Cur;
6317       OPEN  Fetch_Count_Llid_Cur(vQryOn, vShpDtl.ship_to_organization_id, vShpDtl.ship_to_location_id, 'PRICE BREAK'); /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
6318       FETCH Fetch_Count_Llid_Cur INTO v_count;
6319       CLOSE Fetch_Count_Llid_Cur;
6320 
6321       OPEN  Fetch_Lineid_Cur;
6322       FETCH Fetch_Lineid_Cur INTO v_po_line_id, v_unit_price, v_uom, v_item_id;
6323       CLOSE Fetch_Lineid_Cur;
6324       v_qty := p_qty;
6325       IF v_count > 0 THEN
6326 
6327          IF p_cum_flag = 'CUMULATIVE' THEN
6328       -- OPEN  Fetch_Cum_Qty_Cur;
6329       OPEN  Fetch_Cum_Qty_Cur(vQryOn, vShpDtl.ship_to_organization_id, vShpDtl.ship_to_location_id, 'PRICE BREAK');    /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
6330       FETCH Fetch_Cum_Qty_Cur INTO v_qty;
6331       CLOSE Fetch_Cum_Qty_Cur;
6332          ELSE
6333       v_qty := p_qty;
6334          END IF;
6335          /*
6336              Check out for I line loc. id Qty. If p_qty < then consider the line.
6337        insert all the qty, price into PL/SQL table then do all the checking.
6338          */
6339          -- FOR Lines_Rec IN Fetch_Locid_Cur LOOP
6340          FOR Lines_Rec IN Fetch_Locid_Cur(vQryOn, vShpDtl.ship_to_organization_id, vShpDtl.ship_to_location_id, 'PRICE BREAK') LOOP /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
6341              Llid_tab( i ) := Lines_Rec.Line_Location_Id;
6342              Qty_Tab( i )  := Lines_Rec.Quantity;
6343          Price_Tab( i ) := Lines_Rec.Price_Override;
6344          Uom_Tab( i ) := Lines_Rec.Unit_Meas_Lookup_Code;
6345              i := i + 1;
6346          END LOOP;
6347          i := i - 1;
6348          IF ( Qty_Tab( 1 ) > v_qty ) THEN
6349              v_line_loc_id := -999;
6350        v_line_id := p_line_id;
6351        v_qty := p_qty;
6352          ELSE
6353           FOR j IN 1 .. i LOOP
6354              v_temp_qty1 := Qty_Tab( j );
6355              IF j < i - 1 THEN
6356           v_temp_qty2 := Qty_Tab( j+1  );
6357              ELSE
6358                 v_temp_qty2 := v_qty + j;
6359              END IF;
6360              IF v_qty >= v_temp_qty1 AND v_qty < v_temp_qty2 THEN
6361                 v_temp_price := Price_Tab( j );
6362                 /*FOR k IN 1 .. J LOOP
6363                     IF v_temp_price < Price_Tab( k ) THEN
6364                        v_temp_price := Price_Tab( k );
6365                        v_row := k;
6366                     ELSE
6367           v_row := j;
6368                     END IF;
6369                 END LOOP;*//*commented by rchandan for bug#3637364 and adde the following line*/ --pramasub FP
6370 			   v_row := j;
6371              END IF;
6372            END LOOP;
6373         /*   Commented by nprashar for bug 7694945
6374           v_line_loc_id := Llid_Tab( v_row );
6375            v_line_id     := p_line_id;
6376        v_qty := Qty_Tab( v_row );
6377              v_qty := p_qty;   -- Added by Abhay and Anand on 19-Jul-2000
6378        v_uom := Uom_Tab( v_row ); Ends here */
6379        --v_unit_price := Price_Tab( v_row );
6380 
6381      /*Code Added by nprashar for bug # 7694945*/
6382     If v_row is not null and v_row > 0 then /*Added by nprashar for bug 7694945 */
6383               v_line_loc_id := Llid_Tab( v_row );
6384               v_line_id     := p_line_id;
6385               v_qty := Qty_Tab( v_row );
6386               v_uom := Uom_Tab( v_row );
6387            Else
6388                 v_line_loc_id := -999;
6389                 v_line_id     :=  p_line_id;
6390            End If;
6391              v_qty := p_qty;   -- Added by Abhay and Anand on 19-Jul-2000 /*Addition Ends here */
6392 
6393   /*--Added by Nagaraj.s for Fetching Price....
6394        OPEN FETCH_PRICE_CUR;
6395        FETCH FETCH_PRICE_CUR INTO v_unit_price;
6396        CLOSE FETCH_PRICE_CUR;
6397        --Ends Here.........*/
6398         END IF;
6399 
6400     ELSIF v_count = 0 THEN
6401       v_line_loc_id := -999;
6402       v_line_id := p_line_id;
6403       v_qty := p_qty;
6404     END IF;
6405 	--pramasub FP start
6406 	  OPEN FETCH_PRICE_CUR;/*rchandan for bug#3637364*/
6407  	  FETCH FETCH_PRICE_CUR INTO v_unit_price;
6408  	  CLOSE FETCH_PRICE_CUR;
6409 	-- pramasub FP end
6410 
6411     OPEN  Fetch_UomCode_Cur( v_uom );
6412     FETCH Fetch_UomCode_Cur INTO v_uom_code;
6413     CLOSE Fetch_UomCode_Cur;
6414 
6415     FOR Tax_Rec IN Fetch_Taxes_Cur( v_line_id, v_line_loc_id ) LOOP
6416 
6417     -- v_tax_amt := Tax_Rec.Tax_Amount * v_qty / p_qty;
6418     --Incorporated by Nagaraj.s on 15/05/2002 for Bug#2373231
6419       BEGIN
6420         SELECT COUNT(1) INTO v_tax_count FROM
6421         JAI_PO_TAXES
6422         WHERE Line_Location_Id = p_line_Loc_Id AND
6423         TAX_ID = Tax_Rec.Tax_id;
6424       END;
6425 
6426      -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6427       IF v_tax_count =0 THEN
6428         INSERT INTO JAI_PO_TAXES(
6429           line_focus_id, line_location_id, tax_line_no,
6430           po_line_id, po_header_id,
6431     precedence_1, precedence_2, precedence_3, precedence_4, precedence_5,
6432     precedence_6, precedence_7, precedence_8, precedence_9, precedence_10 ,
6433           tax_id, currency, tax_rate,
6434           qty_rate, uom, tax_amount, tax_type,
6435           modvat_flag, vendor_id, tax_target_amount,
6436           creation_date, created_by, last_update_date, last_updated_by, last_update_login,
6437           tax_category_id   -- cbabu for EnhancementBug# 2427465
6438         ) VALUES (
6439           p_seq_val, p_line_Loc_Id, Tax_Rec.Tax_Line_No,
6440           p_Line_Id, p_hdr_id,
6441     Tax_Rec.Precedence_1,Tax_Rec.Precedence_2, Tax_Rec.Precedence_3, Tax_Rec.Precedence_4, Tax_Rec.Precedence_5,
6442       Tax_Rec.Precedence_6,Tax_Rec.Precedence_7, Tax_Rec.Precedence_8, Tax_Rec.Precedence_9, Tax_Rec.Precedence_10,
6443           Tax_Rec.Tax_Id, Tax_Rec.Currency, Tax_Rec.Tax_Rate,
6444           Tax_Rec.Qty_Rate, Tax_Rec.UOM, 0, Tax_Rec.Tax_Type,
6445           Tax_Rec.Modvat_Flag, Tax_Rec.Vendor_Id,   0,
6446           p_cre_dt, p_cre_by, p_last_cre_dt, p_last_cre_by, p_last_login,
6447           tax_rec.tax_category_id   -- cbabu for EnhancementBug# 2427465
6448         );
6449       END IF;
6450 
6451       -- Vijay Shankar for Bug# 3487904
6452       v_tax_category_id_holder := nvl( tax_rec.tax_category_id, v_tax_category_id_holder);
6453 
6454     END LOOP;
6455 
6456     -- if clause added by Vijay Shankar for Bug# 3487904
6457     If v_tax_category_id_holder IS NULL THEN
6458       IF v_line_loc_id = -999 THEN
6459         OPEN c_line_tax_category_id_1(v_po_line_id);
6460         FETCH c_line_tax_category_id_1 INTO v_tax_category_id_holder;
6461         CLOSE c_line_tax_category_id_1;
6462       ELSE
6463         OPEN c_line_tax_category_id_2(v_po_line_id, v_line_loc_id);
6464         FETCH c_line_tax_category_id_2 INTO v_tax_category_id_holder;
6465         CLOSE c_line_tax_category_id_2;
6466       END IF;
6467     end if;
6468 
6469     UPDATE JAI_PO_LINE_LOCATIONS
6470     SET tax_category_id = v_tax_category_id_holder
6471     WHERE line_focus_id = p_seq_val;
6472     -- End, 3487904
6473 
6474     /* following block is commented and replaced with the above UPDATE statement
6475     -- Start, cbabu for EnhancementBug# 2427465
6476     BEGIN
6477       IF v_line_loc_id = -999 THEN
6478         SELECT tax_category_id INTO v_tax_category_id_holder
6479         FROM JAI_PO_LINE_LOCATIONS
6480         WHERE po_line_id = v_po_line_id
6481         AND (line_location_id IS NULL OR line_location_id = 0);
6482       ELSE -- line_location_id is present in PO_LINE_LOCATIONS_ALL
6483         SELECT tax_category_id INTO v_tax_category_id_holder
6484         FROM JAI_PO_LINE_LOCATIONS
6485         WHERE po_line_id = v_po_line_id
6486         AND line_location_id = v_line_loc_id;
6487       END IF;
6488 
6489       UPDATE JAI_PO_LINE_LOCATIONS
6490       SET tax_category_id = v_tax_category_id_holder
6491       WHERE line_focus_id = p_seq_val;
6492     EXCEPTION
6493       WHEN OTHERS THEN
6494         RAISE_APPLICATION_ERROR( -20101, '1 Exception raised in jai_po_tax_pkg.copy_agreement_taxes: '||SQLERRM, TRUE);
6495     END;
6496     -- End, cbabu for EnhancementBug# 2427465
6497     */
6498 
6499         v_line_loc_id := p_line_loc_id;
6500         v_po_line_id := p_line_id;
6501         v_po_hdr_id := p_hdr_id;
6502         OPEN  Get_Assessable_Val_Cur;
6503         FETCH Get_Assessable_Val_Cur INTO v_vendor_id, v_vendor_site_id, v_doc_curr;
6504         CLOSE Get_Assessable_Val_Cur;
6505 
6506         OPEN  Get_Item_Id_Cur;
6507         FETCH Get_Item_Id_Cur INTO v_item_id;
6508         CLOSE Get_Item_Id_Cur;
6509 
6510         v_assessable_value := jai_cmn_setup_pkg.get_po_assessable_value
6511                       ( v_vendor_id, v_vendor_site_id,
6512                         v_item_id, v_uom_code
6513                        );
6514 
6515         IF v_assessable_value IS NULL THEN
6516            v_assessable_value := v_unit_price * v_qty;
6517         ELSE
6518            v_assessable_value := v_assessable_value * v_qty;
6519            jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, v_assessable_value, v_doc_curr, v_curr_conv_factor ) ;
6520         END IF;
6521 
6522         ln_vat_assess_value :=  jai_general_pkg.ja_in_vat_assessable_value    /*Ravi*/
6523                                                       ( p_party_id => v_vendor_id,
6524                                                         p_party_site_id => v_vendor_site_id,
6525                                                         p_inventory_item_id => v_item_id,
6526                                                         p_uom_code => v_uom_code,
6527                                                         p_default_price => v_temp_price,
6528                                                         p_ass_value_date => SYSDATE,
6529                                                         p_party_type => 'V'
6530                                                  ) ;    -- Ravi for VAT
6531 
6532         ln_vat_assess_value := ln_vat_assess_value * v_qty;   -- Ravi for VAT
6533         IF ln_vat_assess_value <> ( v_temp_price * v_qty ) THEN    -- Ravi for VAT
6534 
6535           jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, ln_vat_assess_value, v_doc_curr, v_curr_conv_factor ) ;
6536 
6537         END IF; -- Ravi for VAT
6538         IF nvl(ln_vat_assess_value,0) = 0 THEN /*rchandan for bug#6685406(6766561)*/
6539 
6540            ln_vat_assess_value := v_unit_price * v_qty;
6541 
6542         END IF;
6543 
6544         jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, DUMMY, v_doc_curr, v_curr_conv_factor ) ;
6545 
6546       -- Pass Line_Location_Id in place of Header_Id in procedure Cal_Tax.
6547         jai_po_tax_pkg.calculate_tax( 'RELEASE', p_line_loc_id, p_line_id, v_line_loc_id,
6548               p_qty, v_unit_price * p_qty, v_uom_code,
6549               Tax_Amount, v_assessable_value,ln_vat_assess_value, NULL, v_curr_conv_factor
6550               , pv_retroprice_changed --Added by Kevin Cheng for Retroactive Price 2008/01/10
6551               );  -- Ravi for VAT
6552       END IF;
6553 
6554       DELETE FROM JAI_PO_REQUEST_T WHERE line_focus_id = p_seq_val;
6555  END IF ;
6556   EXCEPTION
6557     WHEN OTHERS THEN
6558     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
6559     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
6560     app_exception.raise_exception;
6561   END copy_agreement_taxes;
6562 
6563   /*--------------------------------------------------------------------------------------------------------------------------
6564   CHANGE HISTORY for FILENAME - ja_in_po_default_taxes_pkg.sql
6565   S.No  Date  Author and Details
6566   -------------------------------------------------
6567   1 5/12/2002 Vijay Shankar for Bug# 2695844, FileVersion: 615.1
6568            when making a call to jai_po_tax_pkg.calculate_tax procedure, v_uom is going as NULL and so the procedure is making a call to po_lines_all
6569            table to fetch the uom and which is giving the mutating error.
6570            Created a new variable v_uom_code and passing the same to jai_po_tax_pkg.calculate_tax that will not make a query on po_lines_all
6571 
6572   2 6/12/2002 Vijay Shankar for EnhancementBug# 2427465, FileVersion# 615.2
6573           tax_category_id column is populated into PO and SO localization tables, which will be used to
6574           identify from which tax_category the taxes are defaulted. Also the tax_category_id populated into the
6575           tax table will be useful to identify whether the tax is a defaulted or a manual tax.
6576           New parameter is added in JA_IN_PO_INSERT procedure that is internally called from other procedure of this package
6577 
6578   3 14/04/2004  Vijay Shankar for Bug# 3466223, FileVersion# 619.1
6579            RAISE_APPLICATION_ERROR is removed, this is stopping tax defaultation if tax_category_id is not found for
6580            the Source Document line/shipment in Localization tables.
6581            For this purpose Cursors c_line_tax_category_id_1 and c_line_tax_category_id_2 are added
6582 
6583   4 12/03/2005  Bug 4210102. Added by LGOPALSA
6584                 (1) Added check file syntax
6585           (2) Added NOCOPY for OUT Parameters
6586           (3) Added CVD and Customs education cess
6587 
6588   5.17-Mar-2005  hjujjuru - bug #4245062  File version 115.2
6589                   The Assessable Value is calculated for the transaction. For this, a call is
6590                   made to the function ja_in_vat_assessable_value_f.sql with the parameters
6591                   relevant for the transaction. This assessable value is again passed to the
6592                   procedure that calucates the taxes.
6593 
6594                   Base bug - #4245089
6595 
6596   6. 22-Jun-2007  CSahoo for bug#6144740 File Version 120.15
6597   								added a new input parameter p_quantity to the procedure.
6598 
6599 
6600 
6601   ===============================================================================
6602   Dependencies
6603 
6604   Version  Author       Dependencies      Comments
6605   115.1    LGOPALSA      IN60106 +         Added cess related tax types
6606                          4146708
6607 
6608   115.2   hjujjuru       4245089         VAT Implelentation
6609   --------------------------------------------------------------------------------------------------------------------------*/
6610 
6611   PROCEDURE Ja_In_Po_Case1(
6612     v_type_lookup_code IN VARCHAR2,
6613     v_quot_class_code  IN VARCHAR2,
6614     vendor_id IN NUMBER,
6615     v_vendor_site_id IN NUMBER,
6616     currency IN VARCHAR2,
6617     v_org_id IN NUMBER,
6618     v_item_id IN NUMBER,
6619     v_uom_measure IN VARCHAR2,
6620     v_line_loc_id IN NUMBER,
6621     v_po_hdr_id IN NUMBER,
6622     v_po_line_id IN NUMBER,
6623     v_frm_po_line_id IN NUMBER,
6624     v_frm_line_loc_id IN NUMBER,
6625     v_price  IN NUMBER,
6626     v_qty IN NUMBER,
6627     v_cre_dt IN DATE,
6628     v_cre_by IN NUMBER,
6629     v_last_upd_dt IN DATE,
6630     v_last_upd_by IN NUMBER,
6631     v_last_upd_login IN NUMBER,
6632     flag IN VARCHAR2,
6633     success IN OUT NOCOPY NUMBER,       -- If success doesnt return 0, then Use Ja_In_Po_Case2
6634 		p_quantity   IN PO_LINE_LOCATIONS_ALL.quantity%TYPE  DEFAULT NULL   --added by csahoo for bug#6144740
6635   )
6636    IS
6637 
6638     v_seq_val       NUMBER;
6639     v_vendor_id       NUMBER; --File.Sql.35 Cbabu   :=  vendor_id;
6640     v_line_amt        NUMBER;
6641     v_reqn_entries          NUMBER;
6642     v_requisition_line_id   NUMBER;
6643     v_po_vendor_id      NUMBER;
6644     v_seq         NUMBER;
6645 
6646     v_curr          VARCHAR2(30);--File.Sql.35 Cbabu  := currency;
6647     v_tax_amt         NUMBER;
6648     v_total_amt       NUMBER;
6649     v_tax_line_no     NUMBER;
6650     v_prec1         NUMBER;
6651     v_prec2         NUMBER;
6652     v_prec3         NUMBER;
6653     v_prec4         NUMBER;
6654     v_prec5         NUMBER;
6655 -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6656 -- start Bug 5228046
6657     v_prec6         NUMBER;
6658     v_prec7         NUMBER;
6659     v_prec8         NUMBER;
6660     v_prec9         NUMBER;
6661     v_prec10         NUMBER;
6662 -- end Bug 5228046
6663     v_taxid         NUMBER;
6664     v_tax_rate        NUMBER;
6665     v_qty_rate        NUMBER;
6666     v_uom         VARCHAR2(100);
6667     v_tax_type        VARCHAR2(30);
6668     v_mod_flag        VARCHAR2(1);
6669     v_vendor2_id      NUMBER;
6670     v_mod_cr        NUMBER;
6671     v_vendor1_id      NUMBER;
6672     v_tax_target_amt    NUMBER;
6673 
6674     v_curr_conv_factor      NUMBER;
6675     v_assessable_value    NUMBER;
6676     ln_vat_assess_value   NUMBER;  -- added, Harshita for bug #4245062
6677 
6678     v_tax_category_id   JAI_PO_LINE_LOCATIONS.tax_category_id%TYPE; -- cbabu for EnhancementBug# 2427465
6679     v_tax_category_id_dflt  JAI_PO_LINE_LOCATIONS.tax_category_id%TYPE; -- cbabu for EnhancementBug# 2427465
6680 
6681     CURSOR Fetch_UOMCode_Cur IS
6682       SELECT Uom_Code
6683       FROM   Mtl_Units_Of_Measure
6684       WHERE  Unit_Of_Measure = v_uom_measure;
6685 
6686     CURSOR Fetch_Focus_Id_Cur IS
6687       SELECT Line_Focus_Id
6688       FROM   JAI_PO_LINE_LOCATIONS
6689       WHERE  Po_Line_Id = v_po_line_id
6690       AND   Line_Location_Id IS NULL;
6691 
6692     CURSOR Fetch_Focus1_Id_Cur IS
6693       SELECT Line_Focus_Id
6694       FROM   JAI_PO_LINE_LOCATIONS
6695       WHERE  Po_Line_Id = v_po_line_id
6696       AND   Line_Location_Id = v_line_loc_id;
6697 
6698  -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6699     CURSOR QFetch_Taxes_Cur IS
6700       SELECT Tax_Line_no,
6701         Precedence_1, Precedence_2, Precedence_3, Precedence_4, PRecedence_5,
6702         Precedence_6, Precedence_7, Precedence_8, Precedence_9, PRecedence_10,
6703   Tax_Id, Currency, Tax_Rate, Qty_Rate,
6704         UOM, Tax_Amount, Tax_Type, Modvat_Flag, Vendor_Id,
6705         tax_category_id -- cbabu for EnhancementBug# 2427465
6706       FROM   JAI_PO_TAXES
6707       WHERE  Po_Line_Id = v_frm_po_line_id
6708       AND   Line_Location_Id IS NULL
6709       ORDER BY Tax_Line_No;
6710 
6711 -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6712 
6713     CURSOR Q1Fetch_Taxes_Cur IS
6714       SELECT Tax_Line_no,
6715         Precedence_1,Precedence_2, Precedence_3, Precedence_4, PRecedence_5,
6716         Precedence_6,Precedence_7, Precedence_8, Precedence_9, PRecedence_10,
6717   Tax_Id, Currency, Tax_Rate, Qty_Rate,
6718         UOM, Tax_Amount, Tax_Type, Modvat_Flag, Vendor_Id,
6719         tax_category_id -- cbabu for EnhancementBug# 2427465
6720       FROM   JAI_PO_TAXES
6721       WHERE  Po_Line_Id = v_frm_po_line_id
6722       AND   Line_Location_Id = v_frm_line_loc_id
6723       ORDER BY Tax_Line_No;
6724 
6725     CURSOR Fetch_Mod_Cr_Cur( taxid IN NUMBER ) IS
6726       SELECT Tax_Type, Mod_Cr_Percentage, Vendor_Id,adhoc_flag   --kundan kumar for forward porting to R12
6727       FROM   JAI_CMN_TAXES_ALL
6728       WHERE  Tax_Id = taxid;
6729 
6730     CURSOR Fetch_Sum_Cur( Lfid IN NUMBER ) IS
6731       SELECT SUM( NVL( Tax_Amount, 0 ) )
6732       FROM   JAI_PO_TAXES
6733       WHERE  Line_Focus_Id = lfid;
6734 
6735     v_uom_code  VARCHAR2(4);  -- cbabu for Bug# 2695844
6736 
6737     -- Start, added by Vijay Shankar for Bug# 3466223
6738     CURSOR c_line_tax_category_id_1(p_po_line_id IN NUMBER) IS
6739       SELECT tax_category_id
6740       FROM JAI_PO_LINE_LOCATIONS
6741       WHERE po_line_id = p_po_line_id
6742       AND line_location_id IS NULL;
6743 
6744     CURSOR c_line_tax_category_id_2(p_po_line_id IN NUMBER, p_line_location_id IN NUMBER) IS
6745       SELECT tax_category_id
6746       FROM JAI_PO_LINE_LOCATIONS
6747       WHERE po_line_id = p_po_line_id
6748       AND line_location_id = p_line_location_id;
6749     -- End, Vijay Shankar for Bug# 3466223
6750 --Start,Added the following for forward porting to R12 kundan kumar
6751 
6752  CURSOR c_po_quantity_1(p_po_line_id IN NUMBER) IS
6753     SELECT quantity
6754     FROM po_line_locations_all
6755     WHERE po_line_id = p_po_line_id
6756                   AND line_location_id IS NULL ;
6757 
6758   CURSOR c_po_quantity_2(p_po_line_id IN NUMBER,p_po_line_location_id NUMBER ) IS
6759   SELECT quantity
6760     FROM po_line_locations_all
6761    WHERE po_line_id = p_po_line_id
6762            AND line_location_id = p_po_line_location_id ;
6763 
6764    lv_adhoc_flag VARCHAR2(1) ;
6765          ln_tax_id    NUMBER ;
6766          ln_quot_qty     NUMBER ;
6767 --End Added for Forward Porting kundan kumar
6768     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.ja_in_po_case1';
6769 
6770   BEGIN
6771 
6772     --File.Sql.35 Cbabu
6773     v_vendor_id       :=  vendor_id;
6774     v_curr           := currency;
6775 
6776   -- following IF modified to work for 'BLANKET' also by Vijay Shankar for Bug# 3466223
6777   IF v_type_lookup_Code IN ( 'QUOTATION') THEN
6778 
6779     IF v_line_loc_id IS NULL THEN
6780       OPEN  Fetch_Focus_Id_Cur;
6781       FETCH Fetch_Focus_Id_Cur INTO v_seq_val;
6782       CLOSE Fetch_Focus_Id_Cur;
6783     ELSE
6784       OPEN  Fetch_Focus1_Id_Cur;
6785       FETCH Fetch_Focus1_Id_Cur INTO v_seq_val;
6786       CLOSE Fetch_Focus1_Id_Cur;
6787     END IF;
6788 
6789     OPEN  Fetch_UOMCode_Cur;
6790     FETCH Fetch_UOMCode_Cur INTO v_uom;
6791     CLOSE Fetch_UOMCode_Cur;
6792 
6793     -- cbabu for Bug# 2695844
6794     v_uom_code := v_uom;
6795 
6796     v_assessable_value := jai_cmn_setup_pkg.get_po_assessable_value
6797                           ( vendor_id, v_vendor_site_id, v_item_id, v_uom );
6798 
6799     jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, v_assessable_value, v_curr, v_curr_conv_factor );
6800 
6801     --added, Harshita for bug #4245062
6802 
6803     ln_vat_assess_value :=
6804                     jai_general_pkg.ja_in_vat_assessable_value
6805                     ( p_party_id => vendor_id,
6806                       p_party_site_id => v_vendor_site_id,
6807                       p_inventory_item_id => v_item_id,
6808                       p_uom_code => v_uom,
6809                       p_default_price => v_price,
6810                       p_ass_value_date => trunc(SYSDATE),
6811                       p_party_type => 'V'
6812                     ) ;
6813 
6814     If nvl(ln_vat_assess_value,0) = 0 Then
6815      ln_vat_assess_value := v_line_amt ;
6816     Else
6817       ln_vat_assess_value := ln_vat_assess_value * v_qty;
6818       jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id,
6819                                          ln_vat_assess_value,
6820            v_curr,
6821            v_curr_conv_factor );
6822     End if;
6823      --ended, Harshita for bug #4245062
6824 
6825     IF v_frm_po_line_id IS NOT NULL OR v_frm_line_loc_id IS NOT NULL THEN
6826 
6827       success := 0;             -- Case 1 is successful !
6828 
6829       IF v_frm_line_loc_id IS NOT NULL AND v_frm_po_line_id IS NOT NULL THEN
6830 
6831         OPEN Q1Fetch_Taxes_Cur;
6832         LOOP
6833 
6834           FETCH Q1Fetch_Taxes_Cur
6835     INTO
6836       v_tax_line_no,
6837       v_prec1, v_prec2, v_prec3, v_prec4, v_prec5, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6838         v_prec6, v_prec7, v_prec8, v_prec9, v_prec10,
6839             v_taxid, v_curr, v_tax_rate, v_qty_rate, v_uom, v_tax_amt,
6840             v_tax_type, v_mod_flag, v_vendor2_id,
6841             v_tax_category_id;    -- cbabu for EnhancementBug# 2427465
6842 
6843           EXIT WHEN Q1Fetch_Taxes_Cur%NOTFOUND;
6844 
6845           OPEN Fetch_Mod_Cr_Cur( v_taxid );
6846           FETCH Fetch_Mod_Cr_Cur INTO v_tax_type, v_mod_cr, v_vendor1_id,lv_adhoc_flag;--Added adhoc flag by kundan kumar for forward porting to R12
6847           CLOSE Fetch_Mod_Cr_Cur;
6848 
6849           IF v_mod_flag IS NULL THEN
6850             v_mod_flag := v_mod_cr;
6851           END IF;
6852 
6853           /* Added by LGOPALSA. Bug 4210102
6854            * Added CVD and Customs Education Cess */
6855 
6856           IF upper(v_tax_type) IN ( 'CUSTOMS',
6857                                'CVD',
6858                                      jai_constants.tax_type_add_cvd ,        -- Date 31/10/2006 Bug 5228046 added by SACSETHI
6859                                      jai_constants.tax_type_customs_edu_cess,jai_constants.tax_type_sh_customs_edu_cess, /* added by ssawant for bug 5989740 */
6860                                      jai_constants.tax_type_cvd_edu_cess, jai_constants.tax_type_sh_cvd_edu_cess) /* added by ssawant for bug 5989740 */
6861           THEN
6862             v_vendor_id := NULL;
6863           ELSIF  v_tax_type = 'TDS' THEN
6864             v_vendor_id := v_vendor1_id;
6865           ELSE
6866             v_vendor_id := vendor_id;
6867           END IF;
6868   /* added by csahoo for bug# 6144740, start*/
6869 	IF nvl(p_quantity,0) <> 0 then
6870 			ln_quot_qty := p_quantity;
6871 	ELSE
6872 			ln_quot_qty := 1;
6873 	END IF;
6874 	/*bug # 6144740, end*/
6875 
6876 --start Added by kundan kumar for forward porting to R12
6877   IF nvl(lv_adhoc_flag,'N') = 'Y' THEN
6878   																		/*commented by csahoo for bug#6144740
6879                                         OPEN c_po_quantity_2(v_frm_po_line_id,v_frm_line_loc_id);
6880                                         FETCH c_po_quantity_2 INTO ln_quot_qty;
6881                                         CLOSE c_po_quantity_2;
6882                                   v_tax_amt := v_tax_amt * v_qty/ln_quot_qty ;*/
6883                                   v_tax_amt := v_tax_amt * v_qty/ln_quot_qty ;  --added by csahoo for bug#6144740
6884 
6885                                 ELSE
6886 
6887                                   v_tax_amt := NULL;
6888 
6889         END IF ;
6890 
6891 --End Added by kundan kumar for forward porting to R12
6892 
6893           jai_po_tax_pkg.Ja_In_Po_Insert( v_type_lookup_code, v_quot_class_code,
6894             v_seq_val, v_line_loc_id,
6895             v_tax_line_no, v_po_line_id,  v_po_hdr_id,
6896             v_prec1, v_prec2, v_prec3, v_prec4, v_prec5, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6897       v_prec6, v_prec7, v_prec8, v_prec9, v_prec10,
6898             v_taxid, v_price, v_qty, v_curr,
6899             v_tax_rate, v_qty_rate, v_uom,
6900             v_tax_amt, v_tax_type,  v_mod_flag,--NULL WAS REPLACED BY KUNDAN KUMAR FOR FORWARD PORTING TO R12
6901             v_vendor_id, NULL,
6902             v_cre_dt,  v_cre_by, v_last_upd_dt, v_last_upd_by,
6903             v_last_upd_login,
6904             v_tax_category_id     -- cbabu for EnhancementBug# 2427465
6905           );
6906 
6907           -- Vijay Shankar for Bug# 3466223
6908           v_tax_category_id_dflt := nvl(v_tax_category_id_dflt, v_tax_category_id);
6909 
6910         END LOOP;
6911         CLOSE Q1Fetch_Taxes_Cur;
6912 
6913       ELSIF v_frm_po_line_id IS NOT NULL AND v_frm_line_loc_id IS NULL THEN
6914 
6915         OPEN QFetch_Taxes_Cur;
6916         LOOP
6917           FETCH QFetch_Taxes_Cur INTO  v_tax_line_no,
6918       v_prec1, v_prec2, v_prec3, v_prec4, v_prec5, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6919       v_prec6, v_prec7, v_prec8, v_prec9, v_prec10,
6920             v_taxid, v_curr, v_tax_rate, v_qty_rate, v_uom, v_tax_amt,
6921             v_tax_type, v_mod_flag, v_vendor2_id,
6922             v_tax_category_id;  -- cbabu for EnhancementBug# 2427465
6923 
6924           EXIT WHEN QFetch_Taxes_Cur%NOTFOUND;
6925 
6926 
6927           OPEN Fetch_Mod_Cr_Cur( v_taxid );
6928           FETCH Fetch_Mod_Cr_Cur INTO v_tax_type, v_mod_cr, v_vendor1_id,lv_adhoc_flag;--Added by kundan kumar for forward porting
6929           CLOSE Fetch_Mod_Cr_Cur;
6930 
6931           IF v_mod_flag IS NULL THEN
6932             v_mod_flag := v_mod_cr;
6933           END IF;
6934 
6935           IF v_tax_type IN (    'Customs',
6936                                 'CVD',
6937          jai_constants.tax_type_add_cvd ,  -- Date 31/10/2006 Bug 5228046 added by SACSETHI
6938          jai_constants.tax_type_customs_edu_cess, jai_constants.tax_type_sh_customs_edu_cess, /* added by ssawant for bug 5989740 */
6939          jai_constants.tax_type_cvd_edu_cess, jai_constants.tax_type_sh_cvd_edu_cess /* added by ssawant for bug 5989740 */
6940                  ) THEN
6941             v_vendor_id := NULL;
6942           ELSIF  v_tax_type = 'TDS' THEN
6943             v_vendor_id := v_vendor1_id;
6944           ELSE
6945             v_vendor_id := vendor_id;
6946           END IF;
6947  --Start , added by rchandan for bug#4591242
6948         IF nvl(lv_adhoc_flag,'N') = 'Y' THEN
6949 
6950                                   OPEN c_po_quantity_1(v_frm_po_line_id);
6951                                         FETCH c_po_quantity_1 INTO ln_quot_qty;
6952                                         CLOSE c_po_quantity_1;
6953                                   v_tax_amt := v_tax_amt * v_qty/ln_quot_qty;
6954 
6955                                 ELSE
6956 
6957                                   v_tax_amt := NULL;
6958 
6959         END IF ;
6960         --End , added by rchandan for bug#4591242
6961   ---Added the above lines of code for forward porting to R12 ;kundan kumar
6962 
6963           jai_po_tax_pkg.Ja_In_Po_Insert( v_type_lookup_code, v_quot_class_code,
6964             v_seq_val, v_line_loc_id,
6965             v_tax_line_no, v_po_line_id,  v_po_hdr_id,
6966             v_prec1, v_prec2, v_prec3, v_prec4, v_prec5, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
6967             v_prec6, v_prec7, v_prec8, v_prec9, v_prec10,
6968             v_taxid, v_price, v_qty, v_curr,
6969             v_tax_rate, v_qty_rate, v_uom,
6970             v_tax_amt, v_tax_type,  v_mod_flag, --Added by kundan kumar for forward porting to R12
6971             v_vendor_id, NULL,
6972             v_cre_dt,  v_cre_by, v_last_upd_dt, v_last_upd_by,
6973             v_last_upd_login,
6974             v_tax_category_id
6975           );    -- cbabu for EnhancementBug# 2427465
6976 
6977           -- Vijay Shankar for Bug# 3466223
6978           v_tax_category_id_dflt := nvl(v_tax_category_id_dflt, v_tax_category_id);
6979 
6980         END LOOP;
6981         CLOSE QFetch_Taxes_Cur;
6982 
6983       END IF;
6984 
6985       -- Vijay Shankar for Bug# 3466223
6986       IF v_tax_category_id_dflt IS NULL THEN
6987         IF v_frm_line_loc_id IS NULL THEN
6988           OPEN c_line_tax_category_id_1(v_frm_po_line_id);
6989           FETCH c_line_tax_category_id_1 INTO v_tax_category_id_dflt;
6990           CLOSE c_line_tax_category_id_1;
6991         ELSE
6992           OPEN c_line_tax_category_id_2(v_frm_po_line_id, v_frm_line_loc_id);
6993           FETCH c_line_tax_category_id_2 INTO v_tax_category_id_dflt;
6994           CLOSE c_line_tax_category_id_2;
6995         END IF;
6996       END IF;
6997 
6998       UPDATE JAI_PO_LINE_LOCATIONS
6999       SET tax_category_id = v_tax_category_id_dflt
7000       WHERE line_focus_id = v_seq_val;
7001       -- End, Vijay Shankar for Bug# 3466223
7002 
7003       /* commented by Vijay Shankar for Bug# 3466223
7004       -- Start, cbabu for EnhancementBug# 2427465
7005       BEGIN
7006         IF v_frm_line_loc_id IS NOT NULL THEN
7007           SELECT tax_category_id INTO v_tax_category_id_dflt
7008           FROM JAI_PO_LINE_LOCATIONS
7009           WHERE line_location_id = v_frm_line_loc_id;
7010         ELSE
7011           SELECT tax_category_id INTO v_tax_category_id_dflt
7012           FROM JAI_PO_LINE_LOCATIONS
7013           WHERE po_line_id = v_frm_po_line_id
7014           AND (line_location_id IS NULL OR line_location_id = 0);
7015         END IF;
7016 
7017         UPDATE JAI_PO_LINE_LOCATIONS
7018         SET tax_category_id = v_tax_category_id_dflt
7019         WHERE line_focus_id = v_seq_val;
7020 
7021       EXCEPTION
7022         WHEN OTHERS THEN
7023           RAISE_APPLICATION_ERROR( -20101, '5 Exception raised in ja_in_po_default_taxes_pkg'||SQLERRM, TRUE);
7024       END;
7025       -- End, cbabu for EnhancementBug# 2427465
7026       */
7027      END IF;
7028 
7029     If ( ( v_type_lookup_code <> 'QUOTATION' AND v_quot_class_code <> 'CATALOG' )
7030       OR v_type_lookup_code <> 'BLANKET' )
7031     THEN
7032 
7033       jai_po_tax_pkg.calculate_tax( 'STANDARDPO', v_po_hdr_id , v_po_line_id, v_line_loc_id,
7034         -- v_qty, v_price*v_qty, v_uom, v_tax_amt, v_assessable_value, v_item_id ); -- cbabu for Bug# 2695844
7035         v_qty, v_price*v_qty, v_uom_code, v_tax_amt, v_assessable_value,ln_vat_assess_value,  -- added, Harshita for bug #4245062
7036         v_item_id );
7037 
7038     END IF;
7039 
7040     IF  ( v_quot_class_code <> 'CATALOG' OR v_type_lookup_code <> 'BLANKET' ) THEN
7041 
7042       OPEN  Fetch_Sum_Cur( v_seq_val );
7043       FETCH Fetch_Sum_Cur INTO v_tax_amt;
7044       CLOSE Fetch_Sum_Cur;
7045 
7046       UPDATE JAI_PO_LINE_LOCATIONS
7047       SET Tax_Amount = NVL( v_tax_amt, 0 ),
7048         Total_Amount = NVL( ( v_qty * v_price ), 0 ) + Tax_Amount,
7049         Last_Updated_By = v_last_upd_by,
7050         Last_Update_Date = v_last_upd_dt,
7051         Last_Update_Login = v_last_upd_login
7052       WHERE  Line_Focus_id = v_seq_val;
7053 
7054     ELSE
7055 
7056       UPDATE JAI_PO_LINE_LOCATIONS
7057       SET Tax_Amount = NULL,
7058         Total_Amount = NULL,
7059         Last_Updated_By = v_last_upd_by,
7060         Last_Update_Date = v_last_upd_dt,
7061         Last_Update_Login = v_last_upd_login
7062       WHERE  Line_Focus_Id = v_seq_val;
7063 
7064     END IF;
7065 
7066 
7067   ELSE
7068 
7069     success := 1;
7070 
7071   END IF;
7072 EXCEPTION
7073   WHEN OTHERS THEN
7074   success:= null;
7075   FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
7076   FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
7077   app_exception.raise_exception;
7078   END Ja_In_Po_Case1;
7079 
7080   -------------------------------------------------------------------------------------------------
7081   -------------------------------------------------------------------------------------------------
7082 
7083   PROCEDURE Ja_In_Po_Case2(
7084     v_type_lookup_code IN VARCHAR2,
7085     v_quot_class_code  IN VARCHAR2,
7086     vendor_id IN NUMBER,
7087     v_vendor_site_id IN NUMBER,
7088     currency IN VARCHAR2,
7089     v_org_id IN NUMBER,
7090     v_item_id IN NUMBER,
7091     v_line_loc_id IN NUMBER,
7092     v_po_hdr_id IN NUMBER,
7093     v_po_line_id IN NUMBER,
7094     v_price  IN NUMBER,
7095     v_qty IN NUMBER,
7096     v_cre_dt IN DATE,
7097     v_cre_by IN NUMBER,
7098     v_last_upd_dt IN DATE,
7099     v_last_upd_by IN NUMBER,
7100     v_last_upd_login IN NUMBER,
7101     v_uom_measure IN VARCHAR2,
7102     flag IN VARCHAR2,
7103     v_assessable_val IN NUMBER DEFAULT NULL,
7104     p_vat_assess_value IN NUMBER ,  -- added, Harshita for bug #4245062
7105     v_conv_rate IN NUMBER DEFAULT NULL,
7106     /* Bug 5096787. Added by Lakshmi Gopalsami  */
7107     v_rate IN NUMBER DEFAULT NULL,
7108     v_rate_date IN DATE DEFAULT NULL,
7109     v_rate_type IN VARCHAR2 DEFAULT NULL,
7110     p_tax_category_id IN NUMBER DEFAULT NULL
7111     ,pv_retroprice_changed IN VARCHAR2 DEFAULT 'N' --Added by Kevin Cheng for Retroactive Price 2008/01/13
7112   ) IS
7113 
7114     v_vendor_id       NUMBER; --File.Sql.35 Cbabu     :=  vendor_id;
7115     v_curr          VARCHAR2(30); --File.Sql.35 Cbabu   :=  currency;
7116     trans_name        VARCHAR2(200);
7117     v_seq_val       NUMBER;
7118 
7119     v_line_amt        NUMBER;
7120     v_assessable_value    NUMBER;
7121     ln_vat_assess_value   NUMBER;  -- added, Harshita for bug #4245062
7122     v_reqn_entries          NUMBER;
7123     v_requisition_line_id   NUMBER;
7124 
7125     v_item_class      VARCHAR2(4);
7126     v_tax_amt         NUMBER;
7127     v_total_amt       NUMBER;
7128     v_tax_ctg_id      NUMBER;
7129     v_uom_code        VARCHAR2(3);
7130     operation       VARCHAR2(2);
7131     operation_flag      NUMBER;
7132     dummy                   NUMBER; --File.Sql.35 Cbabu              :=    1;
7133     v_curr_conv_factor      NUMBER; -- This is used if v_conv_rate is NULL !
7134 
7135     CURSOR RFQ_Pref2_Cur( itemid IN NUMBER ) IS
7136       SELECT Item_Class
7137       FROM   JAI_INV_ITM_SETUPS
7138       WHERE  Inventory_Item_Id = itemid
7139       AND    Organization_id   = v_org_id;
7140 
7141     CURSOR Fetch_UOMCode_Cur IS
7142       SELECT Uom_Code
7143       FROM   Mtl_Units_Of_Measure
7144       WHERE  Unit_Of_Measure = v_uom_measure;
7145 
7146     CURSOR Fetch_Focus_Id IS
7147       SELECT Line_Focus_Id
7148       FROM   JAI_PO_LINE_LOCATIONS
7149       WHERE  Po_Line_Id = v_po_line_id
7150       AND   Po_Header_Id = v_po_hdr_id
7151       AND   Line_Location_Id IS NULL;
7152 
7153     CURSOR Fetch_Focus1_Id IS
7154       SELECT Line_Focus_Id
7155       FROM   JAI_PO_LINE_LOCATIONS
7156       WHERE  Po_Line_Id = v_po_line_id
7157       AND    Po_Header_Id = v_po_hdr_id
7158       AND    Line_Location_Id = v_line_loc_id;
7159 
7160     CURSOR Fetch_Sum_Cur IS
7161       SELECT SUM( NVL( Tax_Amount, 0 ) )
7162       FROM   JAI_PO_TAXES
7163       WHERE  Line_Location_Id = v_line_loc_id
7164       AND   Tax_Type <> jai_constants.tax_type_tds; -- 'TDS';     /* Modified by Ramananda for removal of SQL LITERALs :bug#4428980*/
7165 
7166    lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.ja_in_po_case2';
7167 
7168    BEGIN
7169 
7170     v_vendor_id    :=  vendor_id;
7171     v_curr         :=  currency;
7172     dummy          :=    1;
7173 
7174     OPEN RFQ_Pref2_Cur( v_item_id );
7175     FETCH RFQ_Pref2_Cur INTO v_item_class;
7176     CLOSE RFQ_Pref2_Cur;
7177 if p_tax_category_id is null then
7178     IF v_line_loc_id IS NULL THEN
7179 
7180       jai_cmn_tax_defaultation_pkg.Ja_In_Vendor_Default_Taxes(
7181         v_org_id,
7182         v_vendor_id,
7183         v_vendor_site_id,
7184         v_item_id,
7185         v_po_hdr_id,
7186         v_po_line_id,
7187         v_tax_ctg_id
7188       );
7189 
7190     ELSE
7191 
7192       jai_cmn_tax_defaultation_pkg.Ja_In_Vendor_Default_Taxes(
7193         v_org_id,
7194         v_vendor_id,
7195         v_vendor_site_id,
7196         v_item_id,
7197         v_po_hdr_id,
7198         v_line_loc_id,   -- Pass Line location ID instead of line id
7199         v_tax_ctg_id
7200       );
7201 
7202     END IF;
7203  ELSE
7204 
7205                 DELETE Jai_Po_Taxes
7206                  WHERE Po_Line_Id = v_po_line_id
7207                    AND NVL( Line_Location_Id, 0 ) = NVL( v_line_loc_id, 0 ); /* Replaced -999 with 0 - Bug 6012541 */
7208 
7209                 UPDATE Jai_Po_Line_Locations
7210                          SET Tax_Amount                     = NULL,
7211                                          Total_Amount                   = NULL,
7212                                          Last_Updated_By                = fnd_global.user_id,
7213                                          Last_Update_Date               = sysdate,
7214                                          Last_Update_Login              = fnd_global.login_id
7215                  WHERE Po_Line_Id                     = v_po_line_id
7216              AND NVL( Line_Location_Id, 0 ) = NVL( v_line_loc_id, 0 ); /* Replaced -999 with 0 - Bug 6012541 */
7217 
7218                  v_tax_ctg_id := p_tax_category_id;
7219 
7220   END IF;/*p_tax_category_id IS NULL*/
7221 
7222 
7223     IF v_tax_ctg_id IS NOT NULL THEN    -- 000a
7224 
7225       IF v_type_lookup_code NOT IN ( 'STANDARD', 'BLANKET', 'CONTRACT', 'PLANNED' ) THEN
7226         jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, dummy, v_curr, v_curr_conv_factor );
7227       END IF;
7228 
7229       OPEN Fetch_UOMCode_Cur;
7230       FETCH Fetch_UOMCode_Cur INTO v_uom_code;
7231       CLOSE Fetch_UOMCode_Cur;
7232 
7233       IF flag = 'INSLINES' THEN
7234         v_line_amt := -1;   -- Line Level Tax Defaulting.
7235         operation_flag := -1;
7236         --v_assessable_value := -1;
7237       ELSE
7238 
7239         operation_flag := 0;
7240         v_line_amt := v_qty*v_price; -- Shipment/Price Break Level Tax Defaulting.
7241 
7242         IF NVL( v_assessable_val, -9999 ) = -9999 THEN
7243           v_assessable_value := jai_cmn_setup_pkg.get_po_assessable_value(
7244                       v_vendor_id, v_vendor_site_id,
7245                       v_item_id, v_uom_code
7246                     );
7247 
7248           IF v_assessable_value IS NULL THEN
7249             v_assessable_value := v_line_amt;
7250           ELSE
7251             jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, v_assessable_value, v_curr, v_curr_conv_factor );
7252             v_assessable_value := v_assessable_value * v_qty;
7253           END IF;
7254 
7255         ELSE
7256           v_assessable_value := v_assessable_val;
7257         END IF;
7258 
7259         -- added, Harshita for bug #4245062
7260 
7261   /* Bug 4516508. Added by Lakshmi Gopalsami
7262      Assign the default value of the assessable value
7263   */
7264 
7265   ln_vat_assess_value := p_vat_assess_value;
7266 
7267         IF NVL( ln_vat_assess_value, -9999 ) = -9999 THEN
7268           ln_vat_assess_value :=
7269                     jai_general_pkg.ja_in_vat_assessable_value
7270                     ( p_party_id => v_vendor_id,
7271                       p_party_site_id => v_vendor_site_id,
7272                       p_inventory_item_id => v_item_id,
7273                       p_uom_code => v_uom_code,
7274                       p_default_price => 0,
7275                       p_ass_value_date => trunc(SYSDATE),
7276                       p_party_type => 'V'
7277                     ) ;
7278 
7279           IF NVL(ln_vat_assess_value,0) = 0 THEN
7280             ln_vat_assess_value := v_line_amt ;
7281           ELSE
7282             ln_vat_assess_value := ln_vat_assess_value * v_qty ;
7283             jai_po_cmn_pkg.Ja_In_Po_Func_Curr( v_po_hdr_id, ln_vat_assess_value, v_curr, v_curr_conv_factor );
7284           END IF ;
7285         END IF ;
7286 
7287         -- ended, Harshita for bug #4245062
7288 
7289       END IF;
7290 
7291       IF flag = 'U' THEN
7292         operation := '$U';  -- Updation
7293       ELSE
7294         operation := '$I';  -- Insert
7295       END IF;
7296 
7297       IF v_type_lookup_code IN ( 'RFQ', 'QUOTATION' ) AND v_quot_class_code = 'BID'  THEN
7298         trans_name := v_type_lookup_code || TO_CHAR( v_line_loc_id ) || operation;
7299 
7300       ELSIF ( v_type_lookup_code IN ( 'RFQ', 'QUOTATION' ) AND v_quot_class_code = 'CATALOG' )
7301         OR v_type_lookup_code = 'BLANKET'
7302       THEN
7303         /* Added 'OR' condition - Bug 6012541 */
7304         IF v_line_loc_id IS NULL OR v_line_loc_id = 0 THEN
7305           trans_name := v_type_lookup_code || operation;
7306         ELSE
7307           trans_name := v_type_lookup_code || TO_CHAR( v_line_loc_id ) || operation;
7308         END IF;
7309 -- Date 08-Aug-2007 by sacsethi for bug 6134628
7310 -- RELEASE look up type added
7311       ELSIF v_type_lookup_code IN ( 'STANDARD', 'PLANNED' , 'RELEASE' ) THEN
7312         trans_name := 'OTHERS' || TO_CHAR( v_line_loc_id ) || operation;
7313       ELSIF v_type_lookup_code = 'SCHEDULED' THEN
7314         trans_name := v_type_lookup_code || TO_CHAR( v_line_loc_id ) || operation;
7315       ELSIF v_type_lookup_code = 'BLANKET' THEN
7316         trans_name := v_type_lookup_code || TO_CHAR( v_line_loc_id ) || operation;
7317       END IF;
7318 
7319       jai_cmn_tax_defaultation_pkg.Ja_In_Calc_Prec_Taxes(
7320         LTRIM( RTRIM( trans_name ) ),
7321         v_tax_ctg_id,
7322         v_po_hdr_id,
7323         v_po_line_id,
7324         v_assessable_value,
7325         v_line_amt,
7326         v_item_id,
7327         v_qty,
7328         v_uom_code,
7329         v_vendor_id,
7330         v_curr,
7331         1/v_curr_conv_factor, --v_conv_rate,
7332         v_cre_dt,
7333         v_cre_by,
7334         v_last_upd_dt,
7335         v_last_upd_by,
7336         v_last_upd_login,
7337         operation_flag,
7338         ln_vat_assess_value  -- added, Harshita for bug #4245062
7339       , pv_retroprice_changed --Added by Kevin Cheng for Retroactive Price 2008/01/13
7340       );
7341 
7342       IF ( v_quot_class_code = 'CATALOG' ) OR  ( v_type_lookup_code = 'BLANKET' ) THEN
7343 
7344       /* Added 'AND' condition - Bug 6012541 */
7345         IF v_line_loc_id IS NOT NULL AND v_line_loc_id <> 0 THEN
7346           UPDATE JAI_PO_TAXES
7347           SET Tax_Amount = NULL,
7348             Tax_Target_Amount = NULL,
7349             Last_Updated_By = v_last_upd_by,
7350             Last_Update_Date = v_last_upd_dt,
7351             Last_Update_Login = v_last_upd_login
7352           WHERE  Po_Line_Id       = v_po_line_id
7353           AND   Line_Location_Id = v_line_loc_id;
7354 
7355           UPDATE JAI_PO_LINE_LOCATIONS
7356           SET Tax_Amount = NULL,
7357             Total_Amount = NULL,
7358             Last_Updated_By = v_last_upd_by,
7359             Last_Update_Date = v_last_upd_dt,
7360             Last_Update_Login = v_last_upd_login
7361           WHERE  Po_Line_Id = v_po_line_id
7362           AND   Line_Location_id = v_line_loc_id;
7363 
7364         ELSE
7365 
7366           UPDATE JAI_PO_TAXES
7367           SET Tax_Amount = NULL,
7368             Tax_Target_Amount = NULL,
7369             Last_Updated_By = v_last_upd_by,
7370             Last_Update_Date = v_last_upd_dt,
7371             Last_Update_Login = v_last_upd_login
7372           WHERE  Po_Line_Id = v_po_line_id
7373           AND Line_Location_Id IS NULL;
7374 
7375           UPDATE JAI_PO_LINE_LOCATIONS
7376           SET Tax_Amount = NULL,
7377             Total_Amount = NULL,
7378             Last_Updated_By = v_last_upd_by,
7379             Last_Update_Date = v_last_upd_dt,
7380             Last_Update_Login = v_last_upd_login
7381           WHERE  Po_Line_Id = v_po_line_id
7382           AND Line_Location_id IS NULL;
7383 
7384         END IF;
7385 
7386       END IF;
7387 
7388     END IF;   -- 000a
7389 
7390     --This Part of code is placed after END IF, to correct the tax_amount , Total_Amount
7391     --Entry into Localization tables , Ramakrishna on 21-may-2001
7392     IF v_quot_class_code <> 'CATALOG' OR v_type_lookup_code <> 'BLANKET' THEN
7393       OPEN  Fetch_Sum_Cur;
7394       FETCH Fetch_Sum_Cur INTO v_tax_amt;
7395       CLOSE Fetch_Sum_Cur;
7396 
7397       UPDATE JAI_PO_LINE_LOCATIONS
7398       SET Tax_Amount = nvl(v_tax_amt,0),
7399         Total_Amount = NVL( ( v_qty * v_price ), 0 ) + nvl(v_tax_amt,0),
7400         Last_Updated_By = v_last_upd_by,
7401         Last_Update_Date = v_last_upd_dt,
7402         Last_Update_Login = v_last_upd_login
7403       WHERE  Line_Location_id = v_line_loc_id
7404       AND Po_Line_Id = v_po_line_id;
7405     END IF;
7406 
7407   EXCEPTION
7408     WHEN OTHERS THEN
7409     FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
7410     FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
7411     app_exception.raise_exception;
7412   END Ja_In_Po_Case2;
7413 
7414   -------------------------------------------------------------------------------------------------
7415 
7416 
7417   PROCEDURE ja_in_po_insert(
7418     v_type_lookup_code IN VARCHAR2,
7419     v_quot_class_code IN VARCHAR2,
7420     v_seq_val IN NUMBER,
7421     v_line_loc_id IN NUMBER,
7422     v_tax_line_no IN NUMBER,
7423     v_po_line_id IN NUMBER,
7424     v_po_hdr_id IN NUMBER,
7425     v_prec1 IN NUMBER,
7426     v_prec2 IN NUMBER,
7427     v_prec3 IN NUMBER,
7428     v_prec4 IN NUMBER,
7429     v_prec5 IN NUMBER,
7430     v_prec6 IN NUMBER, -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
7431     v_prec7 IN NUMBER,
7432     v_prec8 IN NUMBER,
7433     v_prec9 IN NUMBER,
7434     v_prec10 IN NUMBER,
7435     v_taxid IN NUMBER,
7436     v_price IN NUMBER,
7437     v_qty IN NUMBER,
7438     v_curr IN VARCHAR2,
7439     v_tax_rate IN NUMBER,
7440     v_qty_rate IN NUMBER,
7441     v_uom IN VARCHAR2,
7442     v_tax_amt IN NUMBER ,
7443     v_tax_type VARCHAR2,
7444     v_mod_flag IN VARCHAR2,
7445     v_vendor_id IN NUMBER,
7446     v_tax_target_amt IN NUMBER,
7447     v_cre_dt IN DATE,
7448     v_cre_by IN NUMBER,
7449     v_last_upd_dt IN DATE,
7450     v_last_upd_by  IN NUMBER,
7451     v_last_upd_login IN NUMBER,
7452     v_tax_category_id IN NUMBER       -- cbabu for EnhancementBug# 2427465
7453   ) IS
7454 
7455     v_tax_amt1    NUMBER;   --File.Sql.35 Cbabu  := 0;
7456     v_tax     NUMBER;
7457     v_tax_target  NUMBER;
7458 --Start Added by  kundan kumar for forward porting to R12
7459 CURSOR cur_taxes_adhoc(cp_tax_id number) IS  --rchandan for bug#4591242
7460   SELECT adhoc_flag
7461     FROM JAI_CMN_TAXES_ALL
7462    WHERE tax_id = cp_tax_id;
7463 
7464          lv_adhoc_flag varchar2(1);   --rchandan for bug#4591242
7465 --End kundan kumar
7466     lv_object_name CONSTANT VARCHAR2 (61) := 'jai_po_tax_pkg.ja_in_po_insert';
7467   BEGIN
7468 --Added the following cursor opening for forward porting to R12
7469  OPEN cur_taxes_adhoc(v_taxid);     -- added rchandan for bug#4591242
7470         FETCH cur_taxes_adhoc INTO lv_adhoc_flag;
7471         CLOSE cur_taxes_adhoc;
7472 
7473     v_tax_amt1    := 0;
7474 
7475     IF v_type_lookup_code = 'BLANKET' OR v_quot_class_code = 'CATALOG' THEN
7476       v_tax := NULL;
7477       v_tax_target := NULL;
7478     ELSE
7479       v_tax := v_tax_amt;
7480       v_tax_target := v_tax_target_amt;
7481     END IF;
7482 
7483 -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
7484 
7485     INSERT INTO JAI_PO_TAXES(
7486       Line_Focus_Id, Line_Location_Id, Tax_Line_No,
7487       Po_Line_Id, Po_Header_Id,
7488       Precedence_1, Precedence_2, Precedence_3, Precedence_4, Precedence_5,
7489       Precedence_6, Precedence_7, Precedence_8, Precedence_9, Precedence_10,
7490       Tax_Id, Currency, Tax_Rate, Qty_Rate, UOM,
7491       Tax_Amount, Tax_Type, Modvat_Flag,
7492       Vendor_Id, Tax_Target_Amount,
7493       Creation_Date, Created_By, Last_Update_Date,
7494       Last_Updated_By, Last_Update_Login,
7495       tax_category_id       -- cbabu for EnhancementBug# 2427465
7496     ) VALUES  (
7497       v_seq_val, v_line_loc_id, v_tax_line_no,
7498       v_po_line_id, v_po_hdr_id,
7499       v_prec1, v_prec2, v_prec3, v_prec4, v_prec5,  -- Date 31/10/2006 Bug 5228046 added by SACSETHI  ( added column from Precedence 6 to 10 )
7500       v_prec6, v_prec7, v_prec8, v_prec9, v_prec10,
7501       v_taxid, v_curr, v_tax_rate, v_qty_rate,
7502       v_uom, v_tax, v_tax_type, v_mod_flag,
7503       v_vendor_id, v_tax_target,
7504       v_cre_dt, v_cre_by, v_last_upd_dt,
7505       v_last_upd_by, v_last_upd_login,
7506       v_tax_category_id   -- cbabu for EnhancementBug# 2427465
7507     );
7508 
7509   EXCEPTION
7510   WHEN OTHERS THEN
7511   FND_MESSAGE.SET_NAME ('JA','JAI_EXCEPTION_OCCURED');
7512   FND_MESSAGE.SET_TOKEN ('JAI_PROCESS_MSG',lv_object_name ||'.Err:'||sqlerrm);
7513   app_exception.raise_exception;
7514 
7515   END Ja_In_Po_Insert;
7516 END jai_po_tax_pkg;