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