DBA Data[Home] [Help]

PACKAGE BODY: APPS.JAI_AR_TAX_LINES_PKG

Source


1 PACKAGE BODY JAI_AR_TAX_LINES_PKG AS
2 /* $Header: jai_ar_tax_lines.plb 120.0.12020000.2 2013/03/19 00:23:55 vkaranam noship $ */
3 
4   G_CURRENT_RUNTIME_LEVEL CONSTANT NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
5   G_LEVEL_UNEXPECTED      CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
6   G_LEVEL_ERROR           CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
7   G_LEVEL_EXCEPTION       CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
8   G_LEVEL_EVENT           CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
9   G_LEVEL_PROCEDURE       CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
10   G_LEVEL_STATEMENT       CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
11   G_MODULE_NAME           CONSTANT VARCHAR2(100) := 'JAI.PLSQL.JAI_AR_TAX_LINES_PKG.';
12 
13   /********************************************************************************************************
14    FILENAME      : jai_ar_tax_lines.plb
15 
16    Created By    : qimeng
17 
18    Created Date  : 10-July-2012
19 
20    Bug           : 14040855
21 
22    Purpose       : To replace trigger package jai_jar_tl_trigger_pkg for JAI trigger elimination.
23 
24    Called from   :
25 
26    --------------------------------------------------------------------------------------------------------
27    CHANGE HISTORY:
28    --------------------------------------------------------------------------------------------------------
29    S.No      Date          Author and Details
30    --------------------------------------------------------------------------------------------------------
31    14253668  12-Sep-2012   Qinglei
32                            Ported code change for bug#14253668 from file jai_jai_tl_t.plb 120.22.12010000.13.1201030.12
33 
34 
35 
36 
37 
38 
39 
40   *********************************************************************************************************/
41 
42  --Added by Wenqiong for Bug 14253668                Begin
43  ----------------------------------------------------------------------------
44   FUNCTION get_ar_trx_type(pn_customer_trx_line_id IN NUMBER)
45     RETURN VARCHAR2 IS
46 	PRAGMA AUTONOMOUS_TRANSACTION;
47   CURSOR check_trx_type IS
48      SELECT trx_types.type
49    FROM
50    ra_customer_trx_lines_all trxl
51  , ra_customer_trx_all       trx
52  , ra_cust_trx_types_all     trx_types
53    WHERE trxl.customer_trx_id = trx.customer_trx_id
54    AND trx_types.cust_trx_type_id  = trx.cust_trx_type_id
55    AND trxl.customer_trx_line_id = pn_customer_trx_line_id;
56 
57    lv_trx_type            ra_cust_trx_types_all.type%TYPE;
58   BEGIN
59     OPEN check_trx_type;
60     FETCH check_trx_type
61       INTO lv_trx_type;
62     CLOSE check_trx_type;
63     RETURN lv_trx_type;
64   END get_ar_trx_type;
65  ----------------------------------------------------------------------------
66  --Added by Wenqiong for Bug 14253668                End
67   PROCEDURE POPULATE_TAX_LINES_TEMP(pr_old            t_rec%type,
68                                     pr_new            t_rec%type,
69                                     pv_action         in varchar2,
70                                     pv_return_code    out nocopy varchar2,
71                                     pv_return_message out nocopy varchar2,
72                                     pn_tax_exists     out nocopy number) IS
73     lv_api_name CONSTANT VARCHAR2(200) := 'POPULATE_TAX_LINES_TEMP';
74     lv_debug_info VARCHAR2(4000);
75     le EXCEPTION;
76     l_tcs_sur_line_num     NUMBER := 0;
77     l_tcs_line_num         NUMBER := 0;
78     l_tot_tax_lines        NUMBER;
79     l_org_id               NUMBER;
80     v_line_amount          NUMBER := 0;
81     v_quantity             NUMBER;
82     v_trans_type           VARCHAR2(30);
83     v_line_tax_amount      NUMBER := 0;
84     l_bill_to_customer_id  NUMBER;
85     l_bill_to_site_use_id  NUMBER;
86     ln_organization_id     NUMBER;
87     ln_trx_date            DATE;
88     v_line_no              NUMBER := 0;
89     v_books_id             NUMBER := 1;
90     v_salesrep_id          NUMBER;
91     v_line_type            VARCHAR2(30);
92     v_vat_tax              NUMBER;
93     v_ccid                 NUMBER;
94     v_cust_trx_line_id     RA_CUSTOMER_TRX_LINES_ALL.customer_trx_line_id%TYPE;
95     v_customer_trx_line_id RA_CUSTOMER_TRX_LINES_ALL.customer_trx_line_id%TYPE;
96     v_customer_trx_id      RA_CUSTOMER_TRX_ALL.customer_trx_id%TYPE;
97 
98     v_created_from       VARCHAR2(30);
99     c_from_currency_code VARCHAR2(15);
100     c_conversion_type    VARCHAR2(30);
101     c_conversion_date    DATE;
102     c_conversion_rate    NUMBER := 0;
103     v_converted_rate     NUMBER := 1;
104     req_id               NUMBER;
105     result               BOOLEAN;
106     v_organization_id    NUMBER;
107     v_location_id        NUMBER;
108     v_batch_source_id    NUMBER;
109     v_register_code      VARCHAR2(50);
110     v_order_number       VARCHAR2(30);
111     v_order_type         ra_customer_trx_all.interface_header_attribute2%type;
112     v_org_id             NUMBER(15);
113     v_tax_exists         NUMBER := 0;
114 
115     ln_inv_curr_precision NUMBER;
116     lv_intf_hdr_ctx       ra_customer_trx_all.interface_header_context%type;
117 
118     ld_st_accrual_date DATE;
119     ld_trx_date        DATE;
120 
121     Cursor transaction_type_cur IS
122       Select a.type,
123              b.org_id,
124              b.bill_to_customer_id,
125              NVL(b.bill_to_site_use_id, 0),
126              b.trx_date
127         From RA_CUST_TRX_TYPES_ALL a, RA_CUSTOMER_TRX_ALL b
128        Where a.cust_trx_type_id = b.cust_trx_type_id
129          And b.customer_trx_id = v_customer_trx_id
130          And NVL(a.org_id, 0) = NVL(b.org_id, 0);
131 
132     CURSOR c_get_trx_date IS
133       SELECT gl_date
134         FROM ra_cust_trx_line_gl_dist_all
135        WHERE customer_trx_id = v_customer_trx_id
136          AND customer_trx_line_id = v_customer_trx_line_id
137          AND account_class = 'REV';
138 
139     CURSOR c_inv_curr_precision(cp_currency_code varchar2) IS
140       SELECT NVL(minimum_accountable_unit, NVL(precision, 2)) curr_precision
141         FROM fnd_currencies
142        WHERE currency_code = cp_currency_code;
143 
144     CURSOR tax_type_cur IS
145       SELECT a.tax_id               taxid,
146              a.tax_rate,
147              a.uom                  uom,
148              a.tax_amount           tax_amt,
149              b.tax_type             t_type,
150              a.customer_trx_line_id line_id,
151              a.tax_line_no          tax_line_no
152         FROM JAI_AR_TRX_TAX_LINES a, JAI_CMN_TAXES_ALL b
153        WHERE link_to_cust_trx_line_id = v_customer_trx_line_id
154          AND a.tax_id = b.tax_id
155          AND NVL(b.reverse_charge_flag,'N') = 'N' --Added by Qinglei for bug#14619984 SERVICE TAX REVERSE CHARGE TAX LINE IS GENERATED IN AR DISTRIBUTION FORM
156        ORDER BY 1;
157 
158     CURSOR HEADER_INFO_CUR IS
159       SELECT set_of_books_id,
160              primary_salesrep_id,
161              org_id,
162              invoice_currency_code,
163              exchange_rate_type,
164              exchange_date,
165              exchange_rate,
166              interface_header_context
167         FROM RA_CUSTOMER_TRX_ALL
168        WHERE customer_trx_id = v_customer_trx_id;
169 
170     CURSOR ORG_CUR IS
171       SELECT ORG_ID
172         FROM RA_CUSTOMER_TRX_ALL
173        WHERE CUSTOMER_TRX_ID = pr_new.customer_trx_id;
174 
175     lv_tax_regime_code      zx_rates_b.tax_regime_code%type;
176     ln_party_tax_profile_id zx_party_tax_profile.party_tax_profile_id%type;
177     ln_tax_rate_id          zx_rates_b.tax_rate_id%type;
178 
179     CURSOR TAX_CCID_CUR(p_tax_id IN NUMBER) IS
180       SELECT tax_account_id
181         FROM JAI_CMN_TAXES_ALL B
182        WHERE B.tax_id = p_tax_id;
183 
184     CURSOR CREATED_FROM_CUR IS
185       SELECT created_from,
186              interface_header_attribute1,
187              interface_header_attribute2
188         FROM ra_customer_trx_all
189        WHERE customer_trx_id = v_customer_trx_id;
190 
191     CURSOR SO_AR_HDR_INFO IS
192       SELECT organization_id, location_id, batch_source_id
193         FROM JAI_AR_TRXS
194        WHERE Customer_Trx_ID = v_customer_trx_id;
195 
196     CURSOR get_batch_src_id IS
197       SELECT batch_source_id
198         FROM JAI_AR_TRXS
199        WHERE Customer_Trx_ID = v_customer_trx_id;
200 
201     Cursor c_get_orgn is
202       select warehouse_id, interface_line_attribute6
203         from ra_interfacE_lines_all
204        where interfacE_line_context = 'ORDER ENTRY'
205          and line_type = 'LINE'
206          and interface_line_id = v_customer_trx_line_id;
207 
208     CURSOR c_get_orgn_project IS
209       SELECT a.organization_id, a.location_id
210         FROM jai_pa_draft_invoices  a,
211              ra_interface_lines_all b,
212              pa_projects_all        c
213        WHERE b.interface_line_context = 'PROJECTS INVOICES'
214          AND b.line_type = 'LINE'
215          AND b.interface_line_attribute1 = c.segment1
216          AND c.project_id = a.project_id
217          AND a.draft_invoice_num = b.interface_line_attribute2
218          AND interface_line_id = v_customer_trx_line_id;
219 
220     Cursor c_get_loc(cp_order_line_id varchar2) is
221       select location_id
222         from jai_om_wsh_lines_all
223        where order_line_id = cp_order_line_id;
224 
225     ln_order_line_id varchar2(30);
226 
227     CURSOR register_code_cur(p_org_id          IN NUMBER,
228                              p_loc_id          IN NUMBER,
229                              p_batch_source_id IN NUMBER) IS
230       SELECT register_code
231         FROM JAI_OM_OE_BOND_REG_HDRS
232        WHERE organization_id = p_org_id
233          AND location_id = p_loc_id
234          AND register_id IN (SELECT register_id
235                                FROM JAI_OM_OE_BOND_REG_DTLS
236                               WHERE order_type_id = p_batch_source_id
237                                 AND order_flag = 'N');
238 
239     CURSOR register_code_cur1(p_organization_id NUMBER,
240                               p_location_id     NUMBER,
241                               p_order_type      varchar2) IS
242       SELECT A.register_code
243         FROM JAI_OM_OE_BOND_REG_HDRS A,
244              JAI_OM_OE_BOND_REG_DTLS b,
245              oe_transaction_types_tl ott
246        WHERE A.organization_id = p_organization_id
247          AND A.location_id = p_location_id
248          AND A.register_id = b.register_id
249          AND b.order_flag = 'Y'
250          AND b.order_type_id = ott.transaction_type_id
251          AND ott.NAME = p_order_type;
252 
253     CURSOR trx_num(v_cust_trx_id NUMBER) IS
254       SELECT trx_number
255         FROM ra_customer_trx_all
256        WHERE customer_trx_id = v_cust_trx_id;
257 
258     CURSOR cur_chk_rgm(cp_tax_type JAI_CMN_TAXES_ALL.TAX_TYPE%TYPE) IS
259       SELECT regime_id, regime_code
260         FROM jai_regime_tax_types_v jrttv
261        WHERE upper(jrttv.tax_type) = upper(cp_tax_type);
262 
263     ln_regime_code JAI_RGM_DEFINITIONS.REGIME_CODE%TYPE;
264     lv_attr_value  JAI_RGM_REGISTRATIONS.ATTRIBUTE_VALUE%TYPE;
265 
266     ln_regime_id     JAI_RGM_DEFINITIONS.REGIME_ID%TYPE;
267     lv_error_flag    VARCHAR2(2);
268     lv_error_message VARCHAR2(4000);
269 
270     v_err_mesg VARCHAR2(250);
271     v_trx_num  ra_customer_trx_all.trx_number%TYPE;
272 
273     l_func_curr_det jai_plsql_cache_pkg.func_curr_details;
274 
275     CURSOR check_rma_credit_cur(pn_order_number  NUMBER,
276                                 pn_order_line_id NUMBER) IS
277       SELECT count(1)
278         FROM OE_ORDER_HEADERS_ALL    oh,
279              OE_ORDER_LINES_ALL      ol,
280              OE_TRANSACTION_TYPES_TL ot,
281              oe_workflow_assignments owf
282        WHERE oh.header_id = ol.header_id
283          AND oh.order_type_id = ot.transaction_type_id
284          AND oh.order_type_id = owf.order_type_id
285          AND ol.line_type_id = owf.line_type_id
286          AND oh.order_number = pn_order_number
287          AND ot.language = userenv('LANG')
288          AND ol.line_id = pn_order_line_id
289          AND owf.process_name IN
290              ('R_RMA_CREDIT_APP_HDR_INV',
291               'R_RMA_CREDIT_WO_SHIP_APPROVE',
292               'R_RMA_CREDIT_WO_SHIP_HDR_INV',
293               'R_RMA_FOR_CREDIT_WO_SHIPMENT',
294               'R_RMA_FOR_OTA_CREDIT');
295 
296     CURSOR check_shippable_item_cur(pn_order_line_id NUMBER) IS
297       SELECT COUNT(1)
298         FROM MTL_SYSTEM_ITEMS msi, JAI_OM_OE_RMA_LINES l
299        WHERE msi.inventory_item_id = pr_new.inventory_item_id
300          AND msi.inventory_item_id = l.inventory_item_id
301          AND l.rma_line_id = pn_order_line_id
302          AND msi.shippable_item_flag = 'N';
303 
304     ln_rma_flag         NUMBER;
305     ln_nonship_rma_flag NUMBER;
306 
307     v_counter           NUMBER := 0;
308     lb_is_accrual_basis BOOLEAN := FALSE;
309     CURSOR GC_GET_REGIME_ID(CP_REGIME_CODE JAI_RGM_DEFINITIONS.REGIME_CODE%TYPE) IS
310       SELECT REGIME_ID
311         FROM JAI_RGM_DEFINITIONS
312        WHERE REGIME_CODE = CP_REGIME_CODE;
313     ln_tcs_regime_id        JAI_RGM_DEFINITIONS.regime_id%type;
314     ln_threshold_slab_id    jai_ap_tds_thhold_slabs.threshold_slab_id%type;
315     ln_threshold_tax_cat_id jai_ap_tds_thhold_taxes.tax_category_id%type;
316     lv_process_flag         VARCHAR2(2);
317     lv_process_message      VARCHAR2(1996);
318     l_max_tax_line_no       NUMBER;
319     ln_tax_amount           NUMBER;
320 
321     lv_trx_type            ra_cust_trx_types_all.type%TYPE;  --Added by Wenqiong for Bug 14253668
322   BEGIN
323 
324     IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
325        lv_debug_info := 'JAI_AR_TAX_LINES_PKG.POPULATE_TAX_LINES_TEMP.BEGIN';
326        FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,lv_debug_info);
327     END IF;
328     pv_return_code := jai_constants.successful;
329     /*------------------------------------------------------------------------------------------
330      FILENAME: jai_ar_tax_lines.plb
331      CHANGE HISTORY:
332     S.No      Date          Author and Details
333     1.        07-Jun-2012 Qinglei
334               For jai trigger elimination
335 
336 
337     ==========================================================================================================================================================
338 
339     Future Dependencies For the release Of this Object:-
340     (Please add a row in the section below only if your bug introduces a dependency due to spec change/ A new call to a object/
341     A datamodel change )
342 
343     ----------------------------------------------------------------------------------------------------------------------------------------------------
344     Current Version       Current Bug    Dependent           Files                              Version     Author     Date         Remarks
345     Of File                              On Bug/Patchset    Dependent On
346     jai_ar_tax_lines.plb
347 
348     --------------------------------------------------------------------------------------------------------------------------------------------------------*/
349 
350     v_customer_trx_line_id := pr_new.customer_trx_line_id;
351     v_customer_trx_id      := pr_new.customer_trx_id;
352 
353     OPEN trx_num(pr_new.Customer_trx_id);
354     FETCH trx_num
355       INTO v_trx_num;
356     CLOSE trx_num;
357 
358     OPEN CREATED_FROM_CUR;
359     FETCH CREATED_FROM_CUR
360       INTO v_created_from, v_order_number, v_order_type;
361     CLOSE CREATED_FROM_CUR;
362     IF v_created_from IN ('ARXREC') THEN
363       RETURN;
364     END IF;
365 
366     OPEN HEADER_INFO_CUR;
367     FETCH HEADER_INFO_CUR
368       INTO v_books_id,
369            v_salesrep_id,
370            v_org_id,
371            c_from_currency_code,
372            c_conversion_type,
373            c_conversion_date,
374            c_conversion_rate,
375            lv_intf_hdr_ctx;
376     CLOSE HEADER_INFO_CUR;
377 
378     IF c_from_currency_code IS NOT NULL THEN
379       OPEN c_inv_Curr_precision(c_from_currency_code);
380       FETCH c_inv_curr_precision
381         INTO ln_inv_curr_precision;
382       CLOSE c_inv_curr_precision;
383     END IF;
384 
385     IF ln_inv_curr_precision is NULL THEN
386       ln_inv_curr_precision := 0;
387     END IF;
388 
389     OPEN ORG_CUR;
390     FETCH ORG_CUR
391       INTO V_ORG_ID;
392     CLOSE ORG_CUR;
393 
394     OPEN jai_ar_trx_pkg.c_tax_regime_code_cur(V_ORG_ID);
395     FETCH jai_ar_trx_pkg.c_tax_regime_code_cur
396       INTO lv_tax_regime_code;
397     CLOSE jai_ar_trx_pkg.c_tax_regime_code_cur;
398 
399     OPEN jai_ar_trx_pkg.c_max_tax_rate_id_cur(lv_tax_regime_code);
400     FETCH jai_ar_trx_pkg.c_max_tax_rate_id_cur
401       INTO ln_tax_rate_id;
402     CLOSE jai_ar_trx_pkg.c_max_tax_rate_id_cur;
403 
404     IF v_books_id IS NULL THEN
405       l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr(p_org_id => v_org_id);
406       v_books_id      := l_func_curr_det.ledger_id;
407     END IF;
408 
409     v_converted_rate := jai_cmn_utils_pkg.currency_conversion(v_books_id,
410                                                               c_from_currency_code,
411                                                               c_conversion_date,
412                                                               c_conversion_type,
413                                                               c_conversion_rate);
414 
415     open get_batch_src_id;
416     fetch get_batch_src_id
417       into v_batch_source_id;
418     close get_batch_src_id;
419 
420     open c_get_orgn;
421     fetch c_get_orgn
422       into v_organization_id, ln_order_line_id;
423     close c_get_orgn;
424 
425     if v_organization_id is null then
426       OPEN SO_AR_HDR_INFO;
427       FETCH SO_AR_HDR_INFO
428         INTO v_organization_id, v_location_id, v_batch_source_id;
429       CLOSE SO_AR_HDR_INFO;
430     end if;
431 
432     open c_get_loc(ln_order_line_id);
433     fetch c_get_loc
434       into v_location_id;
435     close c_get_loc;
436 
437     if JAI_AR_RCTLA_TRIGGER_PKG.is_this_projects_context(lv_intf_hdr_ctx) then
438       open c_get_orgn_project;
439       fetch c_get_orgn_project
440         into v_organization_id, v_location_id;
441       close c_get_orgn_project;
442     else
443 
444       fnd_file.put_line(FND_FILE.LOG,
445                         'organization id is ' || v_organization_id);
446       fnd_file.put_line(FND_FILE.LOG, 'location id is ' || v_location_id);
447 
448       if v_location_id is null then
449         OPEN SO_AR_HDR_INFO;
450         FETCH SO_AR_HDR_INFO
451           INTO v_organization_id, v_location_id, v_batch_source_id;
452         CLOSE SO_AR_HDR_INFO;
453       end if;
454 
455       fnd_file.put_line(FND_FILE.LOG,
456                         'organization id is ' || v_organization_id);
457       fnd_file.put_line(FND_FILE.LOG, 'location id is ' || v_location_id);
458 
459       IF v_created_from = 'RAXTRX' THEN
460 
461         OPEN register_code_cur1(v_organization_id,
462                                 v_location_id,
463                                 v_order_type);
464         FETCH register_code_cur1
465           INTO v_register_code;
466         CLOSE register_code_cur1;
467       ELSIF v_created_from = 'ARXTWMAI' THEN
468         OPEN register_code_cur(v_organization_id,
469                                v_location_id,
470                                v_batch_source_id);
471         FETCH register_code_cur
472           INTO v_register_code;
473         CLOSE register_code_cur;
474       END IF;
475 
476     end if;
477 
478     BEGIN
479       FOR TAX_TYPE_REC IN TAX_TYPE_CUR LOOP
480 
481         SELECT COUNT(*)
482           INTO v_counter
483           FROM JAI_AR_TRX_INS_LINES_T b
484          WHERE b.LINK_TO_CUST_TRX_LINE_ID = pr_new.Customer_Trx_Line_Id
485            AND b.customer_trx_line_id = Tax_Type_Rec.LINE_ID;
486 
487         IF tax_type_rec.t_type = 'Freight' THEN
488           v_line_type := 'FREIGHT';
489         ELSE
490           v_line_type := 'TAX';
491         END IF;
492 
493         ln_regime_id   := null;
494         ln_regime_code := null;
495 
496         OPEN cur_chk_rgm(cp_tax_type => tax_type_rec.t_type);
497         FETCH cur_chk_rgm
498           INTO ln_regime_id, ln_regime_code;
499         CLOSE cur_chk_rgm;
500 
501         IF (upper(Tax_Type_Rec.T_Type) = 'VAT REVERSAL') THEN
502           TAX_TYPE_REC.tax_amt := 0;
503         END IF;
504 
505         IF NVL(v_register_code, 'N') = 'BOND_REG' THEN
506 
507           IF upper(Tax_Type_Rec.T_Type) IN
508              ('EXCISE',
509               'ADDL. EXCISE',
510               'OTHER EXCISE',
511               'EXCISE_EDUCATION_CESS',
512               'CVD_EDUCATION_CESS',
513               jai_constants.tax_type_sh_exc_edu_cess,
514               jai_constants.tax_type_sh_cvd_edu_cess) THEN
515             TAX_TYPE_REC.tax_amt := 0;
516           END IF;
517         END IF;
518 
519         IF tax_type_rec.t_type = 'Freight' THEN
520           v_line_type := 'FREIGHT';
521         ELSE
522           v_line_type := 'TAX';
523         END IF;
524 
525         ln_regime_id   := null;
526         ln_regime_code := null;
527 
528         OPEN cur_chk_rgm(cp_tax_type => tax_type_rec.t_type);
529         FETCH cur_chk_rgm
530           INTO ln_regime_id, ln_regime_code;
531         CLOSE cur_chk_rgm;
532 
533         IF upper(tax_type_rec.t_type) =
534            upper(jai_constants.tax_type_service) OR
535            upper(tax_type_rec.t_type) =
536            upper(jai_constants.tax_type_service_edu_cess) OR
537            upper(tax_type_rec.t_type) =
538            upper(jai_constants.tax_type_sh_service_edu_cess) THEN
539 
540           jai_ar_rgm_processing_pkg.get_regime_info(p_regime_code   => jai_constants.service_regime,
541                                                     p_tax_type_code => tax_type_rec.t_type,
542                                                     p_regime_id     => ln_regime_id,
543                                                     p_error_flag    => lv_error_flag,
544                                                     p_error_message => lv_error_message);
545 
546           IF lv_error_flag <> jai_constants.successful THEN
547 
548             pv_return_code    := jai_constants.expected_error;
549             pv_return_message := lv_error_message;
550             return;
551           END IF;
552 
553           OPEN c_get_trx_date;
554           FETCH c_get_trx_date INTO ld_trx_date;
555           CLOSE c_get_trx_date;
556 
557           --Added by Wenqiong for Bug 14253668 begin
558           -------------------------------------------
559           lv_trx_type := get_ar_trx_type(v_customer_trx_line_id);
560 
561           IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
562                lv_debug_info := 'v_customer_trx_id = '|| v_customer_trx_id||
563                                 ', v_customer_trx_line_id = '|| v_customer_trx_line_id||
564                                 ', lv_trx_type = '|| lv_trx_type;
565                FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'v_customer_trx_id = ');
566           END IF;
567           -------------------------------------------
568         	--Added by Wenqiong for Bug 14253668 end
569           lb_is_accrual_basis := JAI_CMN_UTILS_PKG.IS_ACCRUAL_BASIS(ln_regime_id,
570                                                                     v_organization_id,
571                                                                     v_location_id,
572                                                                     ld_trx_date);
573           IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
574                lv_debug_info := 'v_customer_trx_id = '|| v_customer_trx_id||
575                                 ', v_customer_trx_line_id = '|| v_customer_trx_line_id||
576                                 ', ld';
577                FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'v_customer_trx_id = ');
578           END IF;
579 
580           IF lb_is_accrual_basis THEN
581             IF nvl(lv_trx_type,'#') <> jai_constants.ar_invoice_type_cm THEN--Added by Wenqiong for Bug 14253668
582               v_ccid := jai_cmn_rgm_recording_pkg.get_account(p_regime_id         => ln_regime_id,
583                                                               p_organization_type => jai_constants.service_tax_orgn_type,
584                                                               p_organization_id   => v_organization_id,
585                                                               p_location_id       => v_location_id,
586                                                               p_tax_type          => tax_type_rec.t_type,
587                                                               p_account_name      => jai_constants.liability);
588               IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
589                  FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'Get accrual basis account for service tax, liability account ccid is '|| v_ccid);
590               END IF;
591             --Added by Wenqiong for Bug 14253668 begin
592            ELSIF nvl(lv_trx_type,'#') = jai_constants.ar_invoice_type_cm THEN
593              v_ccid := jai_cmn_rgm_recording_pkg.get_account (
594                                                               p_regime_id             => ln_regime_id                              ,
595                                                               p_organization_type     => jai_constants.service_tax_orgn_type       ,
596                                                               p_organization_id       => v_organization_id                                  ,
597                                                               p_location_id           => v_location_id                             ,
598                                                               p_tax_type              => tax_type_rec.t_type                       ,
599                                                               p_account_name          => jai_constants.recovery
600                                                             );
601            END IF;
602            --Added by Wenqiong for Bug 14253668 end
603           ELSE
604             IF nvl(lv_trx_type,'#') <> jai_constants.ar_invoice_type_cm THEN --Added by Wenqiong for Bug 14253668
605               v_ccid := jai_cmn_rgm_recording_pkg.get_account(p_regime_id         => ln_regime_id,
606                                                               p_organization_type => jai_constants.service_tax_orgn_type,
607                                                               p_organization_id   => v_organization_id,
608                                                               p_location_id       => v_location_id,
609                                                               p_tax_type          => tax_type_rec.t_type,
610                                                               p_account_name      => jai_constants.liability_interim);
611               IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
612                  FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'Get cash basis account for service tax, liability interim account ccid is '|| v_ccid);
613               END IF;
614              --Added by Wenqiong for Bug 14253668 begin
615            ELSIF nvl(lv_trx_type,'#') = jai_constants.ar_invoice_type_cm THEN
616              v_ccid := jai_cmn_rgm_recording_pkg.get_account (
617                                                               p_regime_id             => ln_regime_id                              ,
618                                                               p_organization_type     => jai_constants.service_tax_orgn_type       ,
619                                                               p_organization_id       => v_organization_id                                  ,
620                                                               p_location_id           => v_location_id                             ,
621                                                               p_tax_type              => tax_type_rec.t_type                       ,
622                                                               p_account_name          => jai_constants.recovery_interim
623                                                             );
624           END IF;
625            --Added by Wenqiong for Bug 14253668 end
626           END IF;
627 
628           IF v_ccid IS NULL THEN
629             pv_return_code    := jai_constants.expected_error;
630             pv_return_message := 'Invalid Code combination ,please check the Service Tax - Tax Accounting Setup';
631             return;
632           END IF;
633 
634         ELSIF UPPER(nvl(ln_regime_code, '####')) = jai_constants.vat_regime THEN
635 
636           if pr_new.inventory_item_id is not null then
637             jai_inv_items_pkg.jai_get_attrib(p_regime_code       => ln_regime_code,
638                                              p_organization_id   => v_organization_id,
639                                              p_inventory_item_id => pr_new.inventory_item_id,
640                                              p_attribute_code    => jai_constants.rgm_attr_item_applicable,
641                                              p_attribute_value   => lv_attr_value,
642                                              p_process_flag      => lv_error_flag,
643                                              p_process_msg       => lv_error_message);
644             IF lv_error_flag <> jai_constants.successful THEN
645               pv_return_code    := jai_constants.expected_error;
646               pv_return_message := lv_error_message;
647               return;
648             END IF;
649           end if;
650           if pr_new.inventory_item_id is not null and
651              nvl(lv_attr_value, 'N') = 'N' THEN
652             pv_return_code    := jai_constants.expected_error;
653             pv_return_message := 'ITEM not vatable';
654             return;
655 
656           END IF;
657 
658           if NOT
659               (JAI_AR_RCTLA_TRIGGER_PKG.is_this_projects_context(lv_intf_hdr_ctx)) then
660 
661             OPEN check_rma_credit_cur(v_order_number, ln_order_line_id);
662             FETCH check_rma_credit_cur
663               INTO ln_rma_flag;
664             CLOSE check_rma_credit_cur;
665 
666             OPEN check_shippable_item_cur(ln_order_line_id);
667             FETCH check_shippable_item_cur
668               INTO ln_nonship_rma_flag;
669             CLOSE check_shippable_item_cur;
670 
671           end if;
672 
673           IF ln_rma_flag > 0 OR ln_nonship_rma_flag > 0 THEN
674             v_ccid := jai_cmn_rgm_recording_pkg.get_account(p_regime_id         => ln_regime_id,
675                                                             p_organization_type => jai_constants.orgn_type_io,
676                                                             p_organization_id   => v_organization_id,
677                                                             p_location_id       => v_location_id,
678                                                             p_tax_type          => tax_type_rec.t_type,
679                                                             p_account_name      => jai_constants.recovery);
680           ELSE
681 
682             v_ccid := jai_cmn_rgm_recording_pkg.get_account(p_regime_id         => ln_regime_id,
683                                                             p_organization_type => jai_constants.orgn_type_io,
684                                                             p_organization_id   => v_organization_id,
685                                                             p_location_id       => v_location_id,
686                                                             p_tax_type          => tax_type_rec.t_type,
687                                                             p_account_name      => jai_constants.liability_interim);
688 
689           End IF;
690           IF v_ccid IS NULL THEN
691 
692             pv_return_code    := jai_constants.expected_error;
693             pv_return_message := 'Invalid Code combination ,please check the VAT Tax - Tax Accounting Setup  ';
694             return;
695 
696           END IF;
697 
698         ELSIF UPPER(nvl(ln_regime_code, '####')) = jai_constants.tcs_regime THEN
699           v_ccid := jai_cmn_rgm_recording_pkg.get_account(p_regime_id         => ln_regime_id,
700                                                           p_organization_type => jai_constants.orgn_type_io,
701                                                           p_organization_id   => v_organization_id,
702                                                           p_location_id       => v_location_id,
703                                                           p_tax_type          => tax_type_rec.t_type,
704                                                           p_account_name      => jai_constants.liability_interim);
705           IF v_ccid IS NULL THEN
706 
707             raise_application_error(-20130,
708                                     'Invalid Code combination ,please check the TCS Tax - Tax Accounting Setup');
709 
710           END IF;
711 
712         ELSE
713           OPEN TAX_CCID_CUR(TAX_TYPE_REC.taxid);
714           FETCH TAX_CCID_CUR
715             INTO v_ccid;
716           CLOSE TAX_CCID_CUR;
717 
718         END IF;
719 
720         IF TAX_TYPE_REC.t_type = 'TDS' THEN
721           TAX_TYPE_REC.tax_amt := 0;
722         END IF;
723         IF NVL(v_counter, 0) = 0 THEN
724 
725           INSERT_TAX_LINES_TEMP(pn_extended_amount            => round(TAX_TYPE_REC.tax_amt,
726                                                                        ln_inv_curr_precision),
727                                 pn_customer_trx_line_id       => TAX_TYPE_REC.LINE_ID,
728                                 pn_customer_trx_id            => v_customer_trx_id,
729                                 pn_set_of_books_id            => v_books_id,
730                                 pn_link_to_cust_trx_line_id   => v_customer_trx_line_id,
731                                 pv_line_type                  => v_line_type,
732                                 pv_uom_code                   => TAX_TYPE_REC.uom,
733                                 pn_vat_tax_id                 => ln_tax_rate_id,
734                                 pn_acctd_amount               => v_converted_rate *
735                                                                  TAX_TYPE_REC.tax_amt,
736                                 pn_amount                     => round(TAX_TYPE_REC.tax_amt,
737                                                                        ln_inv_curr_precision),
738                                 pn_CODE_COMBINATION_ID        => v_ccid,
739                                 pn_cust_trx_line_sales_rep_id => v_salesrep_id,
740                                 pv_insert_update_flag         => 'U',
741                                 pd_last_update_date           => pr_new.last_update_date,
742                                 pn_last_updated_by            => pr_new.last_updated_by,
743                                 pd_creation_date              => pr_new.creation_date,
744                                 pn_created_by                 => pr_new.created_by,
745                                 pn_last_update_login          => pr_new.last_update_login,
746                                 pn_tax_rate                   => TAX_TYPE_REC.tax_rate,
747                                 pv_error_flag                 => 'P',
748                                 pv_source                     => v_created_from,
749                                 pn_org_id                     => v_org_id,
750                                 pn_line_number                => tax_type_rec.tax_line_no);
751 
752         ELSIF (v_counter > 0 AND pv_action = JAI_CONSTANTS.updating) THEN
753           UPDATE JAI_AR_TRX_INS_LINES_T
754              SET extended_amount    = TAX_TYPE_REC.tax_amt,
755                  set_of_books_id    = v_books_id,
756                  line_type          = v_line_type,
757                  uom_code           = TAX_TYPE_REC.uom,
758                  acctd_amount       = v_converted_rate *
759                                       TAX_TYPE_REC.tax_amt,
760                  amount             = TAX_TYPE_REC.tax_amt,
761                  insert_update_flag = 'U',
762                  tax_rate           = TAX_TYPE_REC.tax_rate
763            WHERE customer_trx_id = v_customer_trx_id
764              AND customer_trx_line_id = TAX_TYPE_REC.line_id;
765         END IF;
766 
767         v_tax_exists := 1;
768       END LOOP;
769 
770       pn_tax_exists := v_tax_exists;
771       --Added by Qinglei for JAI Trigger Elimination on 6-June-2012
772 
773     EXCEPTION
774       WHEN OTHERS THEN
775         v_err_mesg        := SQLERRM;
776         pv_return_code    := jai_constants.expected_error;
777         pv_return_message := 'error in processing the invoice ..' ||
778                              v_trx_num || v_err_mesg;
779         return;
780     END;
781 
782     --Commented by Qinglei for JAI Trigger Elimination 11-May-2012 begin
783     -- the following if added by Sriram / Pavan on 06-May-2002
784     /*IF v_created_from = 'ARXTWMAI' AND v_tax_exists = 1 THEN --added condition of v_tax_exists by mmurtuza for bug 13042890
785                result := fnd_request.set_mode(TRUE);
786         req_id := fnd_request.submit_request( 'JA', 'JAILINEGL', 'AR Tax and Freight Defaultation',
787              SYSDATE, FALSE,v_customer_trx_id, v_customer_trx_line_id );
788 
789 
790     END IF;*/
791     --Commented by Qinglei for JAI Trigger Elimination 11-May-2012 end
792     IF pv_action = JAI_CONSTANTS.updating THEN
793       IF v_created_from = 'ARXTWMAI' AND v_tax_exists = 1 THEN
794         BEGIN
795           SELECT max(jattl.tax_line_no)
796             INTO l_tcs_sur_line_num
797             FROM JAI_AR_TRX_TAX_LINES jattl, jai_cmn_taxes_all jcta
798            WHERE jattl.link_to_cust_trx_line_id =
799                  pr_new.customer_trx_line_id
800              AND jattl.tax_id = jcta.tax_id
801              AND jcta.tax_type = jai_constants.tax_type_tcs_surcharge
802            GROUP BY jcta.tax_type;
803         EXCEPTION
804           WHEN NO_DATA_FOUND THEN
805             l_tcs_sur_line_num := 0;
806         END;
807 
808         BEGIN
809           SELECT count(jattl.tax_line_no)
810             INTO l_tot_tax_lines
811             FROM JAI_AR_TRX_TAX_LINES jattl
812            WHERE jattl.link_to_cust_trx_line_id =
813                  pr_new.customer_trx_line_id;
814         EXCEPTION
815           WHEN NO_DATA_FOUND THEN
816             RETURN;
817         END;
818 
819         if (pr_new.tax_category_id is NULL and l_tcs_sur_line_num = 0) then
820           if (c_conversion_date is NULL) then
821             SELECT trx_date
822               INTO c_conversion_date
823               FROM ra_customer_trx_all
824              WHERE customer_trx_id = v_customer_trx_id;
825           end if;
826 
827           OPEN transaction_type_cur;
828           FETCH transaction_type_cur
829             INTO v_trans_type,
830                  l_org_id,
831                  l_bill_to_customer_id,
832                  l_bill_to_site_use_id,
833                  ln_trx_date;
834           CLOSE transaction_type_cur;
835 
836           IF NVL(v_trans_type, 'N') Not in ('INV', 'CM') THEN
837             Return;
838           END IF;
839 
840           v_line_amount := nvl(pr_new.quantity * pr_new.unit_selling_price,
841                                0);
842           v_quantity    := pr_new.quantity;
843 
844           v_line_tax_amount := nvl(v_line_amount, 0);
845 
846           BEGIN
847             SELECT max(jattl.tax_line_no)
848               INTO l_tcs_line_num
849               FROM JAI_AR_TRX_TAX_LINES jattl, jai_cmn_taxes_all jcta
850              WHERE jattl.link_to_cust_trx_line_id =
851                    pr_new.customer_trx_line_id
852                AND jattl.tax_id = jcta.tax_id
853                AND jcta.tax_type = jai_constants.tax_type_tcs
854              GROUP BY jcta.tax_type;
855           EXCEPTION
856             WHEN NO_DATA_FOUND THEN
857               RETURN;
858           END;
859 
860           IF (l_tcs_line_num > 0) then
861             open gc_get_regime_id(cp_regime_code => jai_constants.tcs_regime);
862             fetch gc_get_regime_id
863               into ln_tcs_regime_id;
864             close gc_get_regime_id;
865 
866             /* open bind_cur;
867             fetch bind_cur
868               into l_org_id,
869                    l_bill_to_customer_id,
870                    l_bill_to_site_use_id,
871                    ln_trx_date;
872             close bind_cur;*/
873 
874             SELECT organization_id
875               into ln_organization_id
876               FROM JAI_AR_TRXS
877              WHERE customer_trx_id = pr_new.customer_trx_id;
878 
879             jai_rgm_thhold_proc_pkg.get_threshold_slab_id(p_regime_id         => ln_tcs_regime_id,
880                                                           p_organization_id   => ln_organization_id,
881                                                           p_party_type        => jai_constants.party_type_customer,
882                                                           p_party_id          => l_bill_to_customer_id,
883                                                           p_org_id            => l_org_id,
884                                                           p_source_trx_date   => ln_trx_date,
885                                                           p_threshold_slab_id => ln_threshold_slab_id,
886                                                           p_process_flag      => lv_process_flag,
887                                                           p_process_message   => lv_process_message);
888 
889             if lv_process_flag <> jai_constants.successful then
890               app_exception.raise_exception(exception_type => 'APP',
891                                             exception_code => -20275,
892                                             exception_text => lv_process_message);
893             end if;
894             if ln_threshold_slab_id is not null then
895 
896               jai_rgm_thhold_proc_pkg.get_threshold_tax_cat_id(p_threshold_slab_id    => ln_threshold_slab_id,
897                                                                p_org_id               => l_org_id,
898                                                                p_threshold_tax_cat_id => ln_threshold_tax_cat_id,
899                                                                p_process_flag         => lv_process_flag,
900                                                                p_process_message      => lv_process_message);
901               if lv_process_flag <> jai_constants.successful then
902                 app_exception.raise_exception(exception_type => 'APP',
903                                               exception_code => -20275,
904                                               exception_text => lv_process_message);
905               end if;
906             end if;
907 
908             select max(jattl.tax_line_no)
909               into l_max_tax_line_no
910               from JAI_AR_TRX_TAX_LINES jattl
911              where jattl.link_to_cust_trx_line_id =
912                    pr_new.customer_trx_line_id;
913 
914             jai_cmn_tax_defaultation_pkg.ja_in_calc_prec_taxes(transaction_name          => 'AR_LINES',
915                                                                p_tax_category_id         => -1,
916                                                                p_header_id               => pr_new.customer_trx_id,
917                                                                p_line_id                 => pr_new.customer_trx_line_id,
918                                                                p_assessable_value        => pr_new.assessable_value *
919                                                                                             pr_new.quantity,
920                                                                p_tax_amount              => ln_tax_amount,
921                                                                p_inventory_item_id       => pr_new.inventory_item_id,
922                                                                p_line_quantity           => pr_new.quantity,
923                                                                p_uom_code                => pr_new.unit_code,
924                                                                p_vendor_id               => NULL,
925                                                                p_currency                => NULL,
926                                                                p_currency_conv_factor    => NVL(v_converted_rate,
927                                                                                                 1),
928                                                                p_creation_date           => sysdate,
929                                                                p_created_by              => FND_GLOBAL.user_id,
930                                                                p_last_update_date        => sysdate,
931                                                                p_last_updated_by         => FND_GLOBAL.user_id,
932                                                                p_last_update_login       => FND_GLOBAL.login_id,
933                                                                p_operation_flag          => NULL,
934                                                                p_vat_assessable_value    => pr_new.vat_assessable_value,
935                                                                p_thhold_cat_base_tax_typ => 'TCS',
936                                                                p_threshold_tax_cat_id    => ln_threshold_tax_cat_id,
937                                                                p_source_trx_type         => null,
938                                                                p_source_table_name       => null,
939                                                                p_action                  => 'DEFAULT_TAXES',
940                                                                p_max_tax_line            => l_max_tax_line_no,
941                                                                p_max_rgm_tax_line        => l_tcs_line_num);
942           end if;
943 
944         end if;
945       END IF;
946     END IF;
947     lv_debug_info := 'JAI_AR_TAX_LINES_PKG.POPULATE_TAX_LINES_TEMP.END';
948     IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
949        FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,lv_debug_info);
950     END IF;
951     EXCEPTION
952       WHEN OTHERS THEN
953           IF G_LEVEL_UNEXPECTED >= G_CURRENT_RUNTIME_LEVEL THEN
954             lv_debug_info := substr('Error occurred in JAI_AR_TAX_LINES_PKG.POPULATE_TAX_LINES_TEMP. '||sqlerrm,1,4000);
955             FND_LOG.STRING(G_LEVEL_UNEXPECTED,G_MODULE_NAME || lv_api_name,lv_debug_info);
956           END IF;
957           RAISE le;
958   END POPULATE_TAX_LINES_TEMP;
959 
960   PROCEDURE POPULATE_TAX_LINES_WRAPPER(pr_old            t_rec%type,
961                                        pr_new            t_rec%type,
962                                        pv_action         varchar2,
963                                        pv_return_code    out nocopy varchar2,
964                                        pv_return_message out nocopy varchar2) IS
965     req_id                NUMBER;
966   result                BOOLEAN;
967     lv_return_message       VARCHAR2(2000);
968     lv_return_code          VARCHAR2(100);
969     lv_errbuf               VARCHAR2(1500);
970     lv_retcode              VARCHAR2(10);
971     ln_customer_trx_id      NUMBER;
972     ln_customer_trx_line_id NUMBER;
973     lv_api_name CONSTANT VARCHAR2(200) := 'POPULATE_TAX_LINES_WRAPPER';
974     lv_debug_info VARCHAR2(4000);
975 
976     CURSOR CREATED_FROM_CUR IS
977       SELECT created_from
978         FROM ra_customer_trx_all
979        WHERE customer_trx_id = ln_customer_trx_id;
980 
981     lv_created_from VARCHAR2(30);
982     ln_tax_exists   NUMBER;
983     le EXCEPTION;
984   BEGIN
985     lv_debug_info := 'JAI_AR_TAX_LINES_PKG.POPULATE_TAX_LINES_WRAPPER.BEGIN';
986     IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
987        FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,lv_debug_info);
988     END IF;
989     JAI_AR_TAX_LINES_PKG.POPULATE_TAX_LINES_TEMP(pr_old,
990                                                  pr_new,
991                                                  pv_action,
992                                                  lv_return_code,
993                                                  lv_return_message,
994                                                  ln_tax_exists);
995     pv_return_code    := lv_return_code;
996     pv_return_message := lv_return_message;
997 
998     ln_customer_trx_id      := pr_new.customer_trx_id;
999     ln_customer_trx_line_id := pr_new.customer_trx_line_id;
1000 
1001     OPEN created_from_cur;
1002     FETCH created_from_cur INTO lv_created_from;
1003     CLOSE created_from_cur;
1004 
1005     lv_debug_info := substr('End calling POPULATE_TAX_LINES_TEMP. lv_return_code = '||
1006                      lv_return_code||', lv_return_message = '|| lv_return_message,1,4000);
1007     IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
1008        FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,lv_debug_info);
1009     END IF;
1010 
1011     IF lv_return_code = JAI_CONSTANTS.SUCCESSFUL AND
1012        lv_created_from = 'ARXTWMAI' AND ln_tax_exists = 1 THEN
1013       JAI_AR_MATCH_TAX_PKG.PROCESS_MANUAL_INVOICE(lv_errbuf,
1014                                                   lv_retcode,
1015                                                   ln_customer_trx_id,
1016                                                   ln_customer_trx_line_id);
1017     END IF;
1018 
1019     lv_debug_info := 'JAI_AR_TAX_LINES_PKG.POPULATE_TAX_LINES_WRAPPER.END';
1020     IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
1021        FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,lv_debug_info);
1022     END IF;
1023     EXCEPTION
1024         WHEN OTHERS THEN
1025           IF G_LEVEL_UNEXPECTED >= G_CURRENT_RUNTIME_LEVEL THEN
1026             lv_debug_info := substr('Error calling POPULATE_TAX_LINES_WRAPPER. '|| sqlerrm,1,4000);
1027             FND_LOG.STRING(G_LEVEL_UNEXPECTED,G_MODULE_NAME || lv_api_name,lv_debug_info);
1028           END IF;
1029           RAISE le;
1030   END POPULATE_TAX_LINES_WRAPPER;
1031 
1032   PROCEDURE INSERT_TAX_LINES_TEMP(pn_extended_amount            IN NUMBER,
1033                                   pn_customer_trx_line_id       IN NUMBER,
1034                                   pn_customer_trx_id            IN NUMBER,
1035                                   pn_set_of_books_id            IN NUMBER,
1036                                   pn_link_to_cust_trx_line_id   IN NUMBER,
1037                                   pv_line_type                  IN VARCHAR2,
1038                                   pv_uom_code                   IN VARCHAR2,
1039                                   pn_vat_tax_id                 IN NUMBER,
1040                                   pn_acctd_amount               IN NUMBER,
1041                                   pn_amount                     IN NUMBER,
1042                                   pn_code_combination_id        IN NUMBER,
1043                                   pn_cust_trx_line_sales_rep_id IN NUMBER,
1044                                   pv_insert_update_flag         IN VARCHAR2,
1045                                   pd_last_update_date           IN DATE,
1046                                   pn_last_updated_by            IN NUMBER,
1047                                   pd_creation_date              IN DATE,
1048                                   pn_created_by                 IN NUMBER,
1049                                   pn_last_update_login          IN NUMBER,
1050                                   pn_tax_rate                   IN NUMBER,
1051                                   pv_error_flag                 IN VARCHAR2,
1052                                   pv_source                     IN VARCHAR2,
1053                                   pn_org_id                     IN NUMBER,
1054                                   pn_line_number                IN NUMBER) IS
1055     lv_api_name CONSTANT VARCHAR2(100) := 'INSERT_TAX_LINES_TEMP';
1056     lv_debug_info VARCHAR2(4000);
1057     le EXCEPTION;
1058   BEGIN
1059     lv_debug_info := SUBSTR('pn_extended_amount = '            || pn_extended_amount ||
1060                             ';pn_customer_trx_line_id = '      || pn_customer_trx_line_id ||
1061                             ';pn_customer_trx_id =  '          || pn_customer_trx_id ||
1062                             ';pn_set_of_books_id = '           || pn_set_of_books_id ||
1063                             ';pn_link_to_cust_trx_line_id = '  || pn_link_to_cust_trx_line_id ||
1064                             ';pv_line_type = '                 || pv_line_type ||
1065                             ';pv_uom_code = '                  || pv_uom_code ||
1066                             ';pn_vat_tax_id = '                || pn_vat_tax_id ||
1067                             ';pn_acctd_amount = '              || pn_acctd_amount ||
1068                             ';pn_amount = '                    || pn_amount ||
1069                             ';pn_CODE_COMBINATION_ID = '       || pn_CODE_COMBINATION_ID ||
1070                             ';pn_cust_trx_line_sales_rep_id = '||pn_cust_trx_line_sales_rep_id ||
1071                             ';pv_insert_update_flag = '        || pv_insert_update_flag ||
1072                             ';pd_last_update_date = '          || pd_last_update_date ||
1073                             ';pn_last_updated_by = '           || pn_last_updated_by ||
1074                             ';pd_creation_date = '             ||pd_creation_date ||
1075                             ';pn_created_by = '                || pn_created_by ||
1076                             ';pn_last_update_login = '         || pn_last_update_login ||
1077                             ';pn_tax_rate = '                  || pn_tax_rate ||
1078                             ';pv_error_flag = '                || pv_error_flag ||
1079                             ';pv_source = '                    || pv_source ||
1080                             ';pn_org_id = '                    || pn_org_id ||
1081                             ';pn_line_number = '               || pn_line_number,
1082                             1,
1083                             4000);
1084 
1085     IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
1086       FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'JAI_AR_TAX_LINES_PKG.INSERT_TAX_LINES_TEMP.BEGIN');
1087       FND_LOG.STRING(G_LEVEL_PROCEDURE,
1088                      G_MODULE_NAME || lv_api_name,
1089                      lv_debug_info);
1090 
1091     END IF;
1092 
1093     INSERT INTO JAI_AR_TRX_INS_LINES_T
1094       (extended_amount,
1095        customer_trx_line_id,
1096        customer_trx_id,
1097        set_of_books_id,
1098        link_to_cust_trx_line_id,
1099        line_type,
1100        uom_code,
1101        vat_tax_id,
1102        acctd_amount,
1103        amount,
1104        CODE_COMBINATION_ID,
1105        cust_trx_line_sales_rep_id,
1106        insert_update_flag,
1107        last_update_date,
1108        last_updated_by,
1109        creation_date,
1110        created_by,
1111        last_update_login,
1112        tax_rate,
1113        error_flag,
1114        source,
1115        org_id,
1116        line_number)
1117     VALUES
1118       (pn_extended_amount,
1119        pn_customer_trx_line_id,
1120        pn_customer_trx_id,
1121        pn_set_of_books_id,
1122        pn_link_to_cust_trx_line_id,
1123        pv_line_type,
1124        pv_uom_code,
1125        pn_vat_tax_id,
1126        pn_acctd_amount,
1127        pn_amount,
1128        pn_code_combination_id,
1129        pn_cust_trx_line_sales_rep_id,
1130        pv_insert_update_flag,
1131        pd_last_update_date,
1132        pn_last_updated_by,
1133        pd_creation_date,
1134        pn_created_by,
1135        pn_last_update_login,
1136        pn_tax_rate,
1137        pv_error_flag,
1138        pv_source,
1139        pn_org_id,
1140        pn_line_number);
1141        IF (G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
1142           FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'1 record inserted into table JAI_AR_TRX_INS_LINES_T.');
1143           FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME || lv_api_name,'JAI_AR_TAX_LINES_PKG.INSERT_TAX_LINES_TEMP.END');
1144        END IF;
1145   EXCEPTION
1146     WHEN OTHERS THEN
1147       IF G_LEVEL_UNEXPECTED >= G_CURRENT_RUNTIME_LEVEL THEN
1148          FND_LOG.STRING(G_LEVEL_UNEXPECTED,
1149                      G_MODULE_NAME || lv_api_name,
1150                      substr('Error inserting table JAI_AR_TRX_INS_LINES_T. ' ||
1151                      sqlerrm,1,4000));
1152       END IF;
1153       RAISE le;
1154   END INSERT_TAX_LINES_TEMP;
1155 
1156 END JAI_AR_TAX_LINES_PKG;