1 PACKAGE BODY JAI_AR_RCTLA_TRIGGER_PKG AS
2 /* $Header: jai_ar_rctla_t.plb 120.22.12010000.5 2008/11/18 08:52:39 jmeena ship $ */
3 /*
4 REM +======================================================================+
5 REM NAME ARD_T1
6 REM
7 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
8 REM
9 RE NOTES Refers to old trigger JAI_AR_RCTLA_ARD_T3
10 REM
11 REM +======================================================================*/
12 /**************************************************************************************
13 Change History
14
15 S.No. Description
16
17 1 07/12/2005 Hjujjuru for the bug 4866533 File version 120.1
18 added the who columns in the insert of JAI_CMN_ERRORS_T
19 Dependencies Due to this bug:-
20 None
21
22 2 24/04/1005 cbabu for bug#6012570 (5876390) Version: 120.11
23 Projects Billing Enh.
24 forward ported from R11i to R12
25
26 3 26/04/2007 CSahoo for bug#5989740 File Version 120.12
27 Forward porting of 11i BUG#5907436
28 ENH: Handling Secondary and Higher Education Cess
29 Added the new cess types jai_constants.tax_type_sh_exc_edu_cess, jai_constants.tax_type_sh_cvd_edu_cess
30
31 4. 27/04/2007 CSahoo for bug#5879769, File Version 120.12
32 Forward porting of 11i bug#5694855
33 Added a function get_service_type to get the service_type_code
34 added the cursor c_get_address_details to get the customer_id and Customer_site_id
35
36
37
38 5. 14/05/2007 bduvarag for bug 5879769 File Version 120.14
39 Removed the Project Billing Code
40
41 6. 04/07/2007 brathod, File Version 120.17, bug#6012570 (5876390)
42 Reintroduced the project billing related changes.
43
44 7. 11-10-07 JMEENA for bug# 6493501 File Version 120.7.12000000.5
45 Issue: AUTOINVOICE PROGRAM GOING IN ERROR
46 Reason: IL doesn't processes the data which is being imported into Receivables,
47 if interface_line_context is any of the following :-
48 ('PROJECTS INVOICES', 'OKS CONTRACTS','LEGACY', 'Property-Projects','CLAIM').
49 Fix: Trigger jai_ractl_ariud_trg:-
50 IL sucessfully processes the data which is being imported into Receivables,
51 if interface_line_context is any of the following:-
52 ('ORDER ENTRY', 'SUPPLEMENT CM', 'SUPPLEMENT DM', 'SUPPLEMENT INVOICE',
53 'TCS Debit Memo', 'TCS Credit Memo' )
54 and interface_header_context is any of the following
55 ('PROJECTS INVOICES', 'PA INVOICES') --'PA INTERNAL INVOICES'
56 (jai_ractl_trg_pkg) Function is_this_projects_context:-
57 Commented 'PA INTERNAL INVOICES'
58 It can be used to support interproject or intercompany billing in future
59
60 8 06-nov-08 vkaranam for bug#7539258, File Version 120.7.12000000.6
61 forwardported the changes done in 115 bug#7536069
62 ----------------------------------------------------------------------------------------
63
64
65
66 Future Dependencies For the release Of this Object:-
67 (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/
68 A datamodel change )
69 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
70 Current Version Current Bug Dependent Files Version Author Date Remarks
71 Of File On Bug/Patchset Dependent On
72
73
74 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
75
76
77 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
78 */
79 PROCEDURE ARD_T1 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
80
81 v_excise Number := 0;
82 v_additional Number := 0;
83 v_other Number := 0;
84 v_old_tax_tot Number := 0;
85 v_old_line_amount Number := 0;
86 v_customer_trx_line_id Number; -- := pr_old.CUSTOMER_TRX_LINE_ID; --Ramananda for File.Sql.35
87 v_customer_trx_id Number; -- := pr_old.CUSTOMER_TRX_ID; --Ramananda for File.Sql.35
88 v_once_completed_flag Varchar2(1);
89
90 CURSOR excise_cal_cur IS
91 SELECT A.tax_id, A.tax_rate, A.tax_amount tax_amt,b.tax_type t_type
92 FROM JAI_AR_TRX_TAX_LINES A , JAI_CMN_TAXES_ALL B
93 WHERE link_to_cust_trx_line_id = v_customer_trx_line_id
94 and A.tax_id = B.tax_id
95 order by 1;
96
97 CURSOR old_line_amount_cur IS
98 SELECT line_amount ,tax_amount --added tax_amount for bug#7539258
99 FROM JAI_AR_TRX_LINES
100 WHERE CUSTOMER_TRX_ID = v_customer_trx_id AND
101 CUSTOMER_TRX_LINE_ID = v_customer_trx_line_id;
102
103 CURSOR ONCE_COMPLETE_FLAG_CUR IS
104 SELECT once_completed_flag
105 FROM JAI_AR_TRXS
106 WHERE customer_trx_id = v_customer_trx_id;
107
108 -- following segment uncommented by sriram - bug # 2618503
109 v_trans_type Varchar2(30);
110
111 /*Cursor transaction_type_cur IS
112 Select a.type
113 From RA_CUST_TRX_TYPES_ALL a, RA_CUSTOMER_TRX_ALL b
114 Where a.cust_trx_type_id = b.cust_trx_type_id
115 And b.customer_trx_id = v_customer_trx_id
116 And NVL(a.org_id,0) = NVL(pr_old.org_id,0);
117 */
118
119 -- the above cursor commented and using the following instead.
120
121 Cursor transaction_type_cur IS
122 Select a.type
123 From RA_CUST_TRX_TYPES_ALL a
124 Where cust_trx_type_id
125 in
126 (
127 SELECT cust_trx_type_id
128 FROM RA_CUSTOMER_TRX_ALL
129 WHERE CUSTOMER_TRX_ID = v_customer_trx_id
130 AND org_id = pr_old.ORG_ID /* Modified by Ramananda for removal of SQL LITERALs */
131 --AND org_id = NVL(pr_old.ORG_ID,0)
132 )
133 AND ORG_ID = pr_old.ORG_ID ; /* Modified by Ramananda for removal of SQL LITERALs */
134 -- AND ORG_ID = NVL(pr_old.ORG_ID,0);
135
136 -- ends here uncommented code by sriram - bug # 2618503
137
138 -- code added by sriram to check up if the line created corresponds to an so line or a return line
139
140 cursor c_check_so_line is
141 select 1
142 from JAI_OM_OE_SO_LINES
143 where line_id = to_number(pr_old.interface_line_attribute6);
144
145 cursor c_check_rma_line is
146 select 1
147 from JAI_OM_OE_RMA_LINES
148 where rma_line_id = to_number(pr_old.interface_line_attribute6);
149
150 v_so_line_check Number :=0;
151 v_rma_line_check Number :=0;
152
153
154 /**************************************************************************************
155 Change History
156
157 S.No. Description
158
159 1 Sriram - Bug # 2590650 - Added delete statements to delete from the
160 JAI_AR_TRX_INS_LINES_T for customer trx id and trx line id and also the
161 JAI_AR_TRXS table
162
163 2 Sriram - Bug # 2618503
164 If the line being deleted corresponds to a return order or a sales order then
165 delete the lines related to localization ar tables.
166
167 3. 29-nov-2004 ssumaith - bug# 4037690 - File version 115.1
168 Check whether india localization is being used was done using a INR check in every trigger.
169 This check has now been moved into a new package and calls made to this package from this trigger
170 If the function jai_cmn_utils_pkg.check_jai_exists returns true it means INR is the set of books currency ,
171 Hence if this function returns FALSE , control should return
172
173 4. 08-Jun-2005 This Object is Modified to refer to New DB Entity names in place of Old
174 DB Entity as required for CASE COMPLAINCE. Version 116.1
175
176 5. 13-Jun-2005 File Version: 116.2
177 Ramananda for bug#4428980. Removal of SQL LITERALs is done
178
179 6. 16-Jan-06 rallamse Bug#4926736 , Version # 120.2
180 Removed cursor location_cur in ARI_T2 as it is not being used
181
182 7. 17-feb-2007 sacsethi for bug#5228046 , version 120.8
183 for tax precedence
184 8. 27/02/2007 bduvarag for the bug#4694650 File version 120.9
185 Forward porting the changes done in 11i bug#4644152
186 9. 18/04/2007 bduvarag for the Bug#4881426, file version 120.10
187 Forward porting the changes done in 11i bug#4862976
188 10. 20/04/2007 bduvarag for the Bug#5684363, file version 120.10
189 Forward porting the changes done in 11i bug#5682531
190 Future Dependencies For the release Of this Object:-
191 (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/
192 A datamodel change )
193 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
194 Current Version Current Bug Dependent Files Version Author Date Remarks
195 Of File On Bug/Patchset Dependent On
196
197 ja_in_ar_lines_delete_trg.sql
198 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
199 115.1 4037690 IN60105D2 ja_in_util_pkg_s.sql 115.0 ssumaith 29-Nov-2004 Call to this function.
200 ja_in_util_pkg_s.sql 115.0 ssumaith
201
202 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
203
204 BEGIN
205 pv_return_code := jai_constants.successful ;
206 v_customer_trx_line_id := pr_old.CUSTOMER_TRX_LINE_ID; --Ramananda for File.Sql.35
207 v_customer_trx_id := pr_old.CUSTOMER_TRX_ID; --Ramananda for File.Sql.35
208
209 --If jai_cmn_utils_pkg.check_jai_exists(P_CALLING_OBJECT => 'JA_IN_AR_LINES_DELETE_TRG', P_ORG_ID => pr_old.ORG_ID) = false then
210 -- return;
211 --end if;
212
213
214 FOR excise_cal_rec in excise_cal_cur LOOP
215 IF excise_cal_rec.t_type IN ('Excise') THEN
216 v_excise := nvl(v_excise,0) + nvl(excise_cal_rec.tax_amt,0);
217 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
218 v_additional := nvl(v_additional,0) + nvl(excise_cal_rec.tax_amt,0);
219 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
220 v_other := nvl(v_other,0) + nvl(excise_cal_rec.tax_amt,0);
221 END IF;
222 END LOOP;
223 v_old_tax_tot := nvl(v_excise,0) + nvl(v_other,0) + nvl(v_additional,0);
224
225 OPEN old_line_amount_cur;
226 FETCH old_line_amount_cur INTO v_old_line_amount,v_old_tax_tot;--added v_old_tax_tot for bug#7539258
227 CLOSE old_line_amount_cur;
228
229
230 --start additions for bug#7539258
231 UPDATE JAI_AR_TRXS
232 SET line_amount = nvl(line_amount,0) - nvl(v_old_line_amount,0),
233 tax_amount = nvl(tax_amount,0) - nvl(v_old_tax_tot,0),
234 total_amount = nvl(total_amount,0) - (nvl(v_old_line_amount,0) + nvl(v_old_tax_tot,0))
235 WHERE customer_trx_id = v_customer_trx_id;
236
237 --end additions for bug#7539258
238
239 DELETE FROM
240 JAI_AR_TRXS trx
241 WHERE customer_trx_id = v_customer_trx_id
242 AND EXISTS
243 (SELECT 1
244 FROM ra_interface_lines_all il
245 WHERE il.customer_trx_id = v_customer_trx_id
246 AND NVL(il.interface_status , '~') <> 'P'
247 );
248
249 DELETE JAI_AR_TRX_TAX_LINES
250 WHERE LINK_TO_CUST_TRX_LINE_ID = v_customer_trx_line_id;
251
252 -- the followining delete from temp_lines_insert added by sriram bug # 2590650
253
254 DELETE JAI_AR_TRX_INS_LINES_T
255 WHERE CUSTOMER_TRX_ID = v_customer_trx_id
256 AND
257 LINK_TO_CUST_TRX_LINE_ID = v_customer_trx_line_id;
258
259
260 DELETE JAI_AR_TRX_LINES
261 WHERE CUSTOMER_TRX_ID = v_customer_trx_id AND
262 CUSTOMER_TRX_LINE_ID = v_customer_trx_line_id;
263 /* Added an exception block by Ramananda for bug#4570303 */
264 EXCEPTION
265 WHEN OTHERS THEN
266 Pv_return_code := jai_constants.unexpected_error;
267 Pv_return_message := 'Encountered an error in JAI_AR_RCTLA_TRIGGER_PKG.ARD_T1 ' || substr(sqlerrm,1,1900);
268 END ARD_T1 ;
269
270 /*
271 REM +======================================================================+
272 REM NAME ARI_T1
273 REM
274 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
275 REM
276 REM NOTES Refers to old trigger JAI_AR_RCTLA_ARI_T1
277 REM
278 REM +======================================================================+
279 */
280 PROCEDURE ARI_T1 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
281 v_trans_type Varchar2(30);
282
283 /* --Ramananda for File.Sql.35, START */
284 v_header_id Number; -- := pr_new.customer_trx_id;
285 v_inventory_item_id Number; -- := pr_new.inventory_item_id;
286 v_line_amount number; -- := nvl(NVL(pr_new.quantity_credited,pr_new.quantity_invoiced) * pr_new.unit_selling_price,0);
287 v_customer_trx_line_id Number; -- := pr_new.customer_trx_line_id;
288 v_line_type Varchar2(10); -- := pr_new.line_type;
289 v_prev_customer_trx_line_id Number; -- := pr_new.previous_customer_trx_line_id;
290 v_link_to_cust_id Number; -- := pr_new.link_to_cust_trx_line_id;
291 /* --Ramananda for File.Sql.35, end */
292
293 v_gl_date Date ;
294 v_tax_category_id Number ;
295 v_price_list Number ;
296 c_from_currency_code Varchar2(15);
297 c_conversion_type Varchar2(30);
298 c_conversion_date Date;
299 c_conversion_rate Number := 0;
300 v_converted_rate Number := 1;
301 v_books_id Number;
302
303 /* --Ramananda for File.Sql.35, start */
304 v_last_update_date Date; -- := pr_new.last_update_date;
305 v_last_updated_by Number; -- := pr_new.last_updated_by;
306 v_creation_date Date; -- := pr_new.creation_date;
307 v_created_by Number; -- := pr_new.created_by;
308 v_last_update_login Number; -- := pr_new.last_update_login;
309 v_operating_id number; -- :=pr_new.ORG_ID;
310 /* --Ramananda for File.Sql.35, end */
311
312 v_created_from Varchar2(30);
313 v_organization_id Number ;
314
315 v_gl_set_of_bks_id gl_sets_of_books.set_of_books_id%type;
316 v_currency_code gl_sets_of_books.currency_code%type;
317
318 lv_service_type_code VARCHAR2(30); --added by csahoo for bug#5879769
319
320
321 Cursor transaction_type_cur IS
322 Select a.type
323 From RA_CUST_TRX_TYPES_ALL a, RA_CUSTOMER_TRX_ALL b
324 Where a.cust_trx_type_id = b.cust_trx_type_id
325 And b.customer_trx_id = v_header_id
326 And NVL(a.org_id,0) = NVL(pr_new.org_id,0);
327
328 CURSOR gl_date_cur IS
329 SELECT DISTINCT gl_date
330 FROM RA_CUST_TRX_LINE_GL_DIST_ALL
331 WHERE CUSTOMER_TRX_LINE_ID = v_prev_customer_trx_line_id;
332
333 Cursor localization_line_info IS
334 Select assessable_value, tax_category_id, service_type_code --service_type_code added by csahoo for bug#5879769
335 From JAI_AR_TRX_LINES
336 Where customer_trx_line_id = v_prev_customer_trx_line_id;
337
338
339 -- Date 23/02/2006 by sacsethi for bug 5228046
340 -- precedence 6 to 10
341 CURSOR localization_tax_info IS
342 SELECT a.tax_id, a.tax_line_no lno,
343 a.precedence_1 p_1, a.precedence_2 p_2, a.precedence_3 p_3,
344 a.precedence_4 p_4, a.precedence_5 p_5,
345 a.precedence_6 p_6, a.precedence_7 p_7, a.precedence_8 p_8,
346 a.precedence_9 p_9, a.precedence_10 p_10,
347 a.tax_rate, a.tax_amount, a.uom uom_code, a.qty_rate,
348 decode(upper(b.tax_type),'EXCISE', 1, 'ADDL. EXCISE', 1, 'OTHER EXCISE', 1, 'CVD',1, 'TDS', 2, 0) tax_type_val,
349 b.tax_type
350 FROM JAI_AR_TRX_TAX_LINES a, JAI_CMN_TAXES_ALL b
351 WHERE a.customer_trx_line_id = v_prev_customer_trx_line_id
352 AND a.tax_id = b.tax_id;
353
354
355 Cursor header_info_cur IS
356 SELECT created_from, set_of_books_id, invoice_currency_code, exchange_rate_type, nvl(exchange_date,trx_date), exchange_rate
357 FROM RA_CUSTOMER_TRX_ALL
358 WHERE customer_trx_id = v_header_id;
359
360 Cursor localization_header_info_cur IS
361 SELECT organization_id
362 FROM JAI_AR_TRXS
363 WHERE customer_trx_id = v_header_id;
364
365 /* Bug 5243532. Added by Lakshmi Gopalsami
366 Removed the cursors Fetch_Book_Id_cur and set_of_books_cur
367 which is referening to org_organization_definitions as we
368 can get the SOB from the value assigned in the trigger
369
370 Removed the cursor sob_cur also.
371 */
372 BEGIN
373 pv_return_code := jai_constants.successful ;
374 /*------------------------------------------------------------------------------------------
375 FILENAME: JA_IN_AR_CM_LINES_INSERT_TRG.sql
376
377 CHANGE HISTORY:
378 S.No Date Author and Details
379 1. 2001/07/14 Anuradha Parthasarathy
380 Check added to ensure non firing of trigger for Non Indian OU.
381
382 2. 2004/10/18 ssumaith - bug# 3957682- File version 115.1
383 when a manual credit memo is created , taxes are not getting defaulted.
384 The reason this was happening is because this trigger has code to copy the
385 taxes from the invoice against which the credit memo is applied.
386
387 Added code to return control when a manual credit memo without reference is created.
388 Manual Credit memo with reference to invoice has ra_customer_trx_all.created_from as ARXTWCMI
389 Manual Credit memo without reference to invoice has ra_customer_trx_all.created_from as ARXTWMAI
390 3. 08-Jun-2005 This Object is Modified to refer to New DB Entity names in place of Old
391 DB Entity as required for CASE COMPLAINCE. Version 116.1
392
393 4. 10-Jun-2005 File Version: 116.2
394 Removal of SQL LITERALs is done
395 --------------------------------------------------------------------------------------------*/
396
397 /* --Ramananda for File.Sql.35, start */
398 v_header_id := pr_new.customer_trx_id;
399 v_inventory_item_id := pr_new.inventory_item_id;
400 v_line_amount := nvl(NVL(pr_new.quantity_credited,pr_new.quantity_invoiced) * pr_new.unit_selling_price,0);
401 v_customer_trx_line_id := pr_new.customer_trx_line_id;
402 v_line_type := pr_new.line_type;
403 v_prev_customer_trx_line_id := pr_new.previous_customer_trx_line_id;
404 v_link_to_cust_id := pr_new.link_to_cust_trx_line_id;
405 v_last_update_date := pr_new.last_update_date;
406 v_last_updated_by := pr_new.last_updated_by;
407 v_creation_date := pr_new.creation_date;
408 v_created_by := pr_new.created_by;
409 v_last_update_login := pr_new.last_update_login;
410 v_operating_id :=pr_new.ORG_ID;
411 /* --Ramananda for File.Sql.35, end */
412 /* Bug 5243532. Added by Lakshmi Gopalsami
413 Removed the cursor and assigned the value from the
414 table value assigned in the trigger
415
416 OPEN Fetch_Book_Id_Cur ;
417 FETCH Fetch_Book_Id_Cur INTO v_gl_set_of_bks_id;
418 CLOSE Fetch_Book_Id_Cur;
419 */
420
421
422
423 v_gl_set_of_bks_id := pr_new.set_of_books_id;
424
425 /* IF pr_new.org_id IS NOT NULL THEN
426
427 OPEN Sob_cur;
428 FETCH Sob_cur INTO v_currency_code;
429 CLOSE Sob_cur;
430 IF v_currency_code <> 'INR' THEN
431 RETURN;
432 END IF;
433 END IF; */
434
435
436 OPEN transaction_type_cur;
437 FETCH transaction_type_cur INTO v_trans_type;
438 CLOSE transaction_type_cur;
439
440 IF NVL(v_trans_type,'N') NOT IN ('DM','CM') THEN -- Modified on 19/9
441 Return;
442 END IF;
443
444 OPEN HEADER_INFO_CUR;
445 FETCH HEADER_INFO_CUR INTO v_created_from, v_books_id, c_from_currency_code, c_conversion_type, c_conversion_date, c_conversion_rate ;
446 CLOSE HEADER_INFO_CUR;
447 IF v_created_from NOT IN ('ARXTWCMI','ARXTWMAI') THEN -- Modified on 19/9
448 Return;
449 END IF;
450
451 /*
452 following code added by ssumaith - bug# 3957682
453 Ensured that for a manual credit memo tax defaultation does not take place from this trigger and it instead takes
454 place from the trigger ja_in_ar_lines_insert_trg.
455 */
456 if v_created_from = 'ARXTWMAI' and v_trans_type = 'CM' then
457 return;
458 end if;
459 /*
460 code added by ssumaith - bug# 3957682 - ends here
461 */
462
463 IF v_books_id IS NULL THEN
464 OPEN localization_header_info_cur;
465 FETCH localization_header_info_cur INTO v_organization_id;
466 CLOSE localization_header_info_cur;
467 /* Bug 5243532. Added by Lakshmi Gopalsami
468 Removed the reference to cursor set_of_books_cur.
469 */
470 END IF;
471
472 v_converted_rate := jai_cmn_utils_pkg.currency_conversion (v_books_id ,c_from_currency_code ,
473 c_conversion_date ,c_conversion_type, c_conversion_rate);
474
475 IF v_line_type = 'LINE' THEN
476 Open Gl_Date_Cur;
477 Fetch Gl_Date_Cur Into v_gl_date;
478 Close Gl_Date_Cur;
479
480 Open localization_line_info;
481 Fetch localization_line_info into v_tax_category_id, v_price_list, lv_service_type_code; -- lv_service_type_code added by csahoo for bug#5879769
482 Close localization_line_info;
483
484 INSERT INTO JAI_AR_TRX_LINES
485 (customer_trx_line_id,
486 line_number,
487 customer_trx_id,
488 description,
489 inventory_item_id,
490 unit_code,
491 quantity,
492 tax_category_id,
493 auto_invoice_flag ,
494 unit_selling_price,
495 line_amount,
496 gl_date,
497 tax_amount,
498 total_amount,
499 assessable_value,
500 creation_date,
501 created_by,
502 last_update_date,
503 last_updated_by,
504 last_update_login,
505 service_type_code -- added by csahoo for bug#5879769
506 )
507 VALUES(
508 v_customer_trx_line_id,
509 pr_new.line_number,
510 v_header_id,
511 pr_new.description,
512 v_inventory_item_id,
513 pr_new.uom_code,
514 NVL(NVL(pr_new.quantity_credited,pr_new.quantity_invoiced) ,0)
515 , v_tax_category_id,
516 'N',
517 pr_new.unit_selling_price,
518 v_line_amount,
519 v_gl_date,
520 0,
521 v_line_amount,
522 v_price_list,
523 v_creation_date,
524 v_created_by,
525 v_last_update_date,
526 v_last_updated_by,
527 v_last_update_login,
528 lv_service_type_code -- added by csahoo for bug#5879769
529 );
530 Update JAI_AR_TRXS
531 Set line_amount = nvl(line_amount,0) + nvl(v_line_amount,0)
532 Where Customer_Trx_Id = v_header_id;
533
534 ELSIF v_line_type in ('FREIGHT','TAX') THEN
535 FOR rec in localization_tax_info
536 LOOP
537 -- Date 23/02/2006 by sacsethi for bug 5228046
538 -- precedence 6 to 10
539 INSERT INTO JAI_AR_TRX_TAX_LINES
540 (customer_trx_line_id,
541 link_to_cust_trx_line_id,
542 tax_line_no,
543 precedence_1,
544 precedence_2,
545 precedence_3,
546 precedence_4,
547 precedence_5,
548 precedence_6,
549 precedence_7,
550 precedence_8,
551 precedence_9,
552 precedence_10,
553 tax_id,
554 tax_rate,
555 qty_rate,
556 uom,
557 tax_amount,
558 base_tax_amount,
559 func_tax_amount,
560 creation_date,
561 created_by,
562 last_update_date,
563 last_updated_by,
564 last_update_login
565 )
566 VALUES
567 (v_customer_trx_line_id,
568 v_link_to_cust_id,
569 rec.lno,
570 rec.p_1,
571 rec.p_2,
572 rec.p_3,
573 rec.p_4,
574 rec.p_5,
575 rec.p_6,
576 rec.p_7,
577 rec.p_8,
578 rec.p_9,
579 rec.p_10,
580 rec.tax_id,
581 rec.tax_rate,
582 rec.qty_rate,
583 rec.uom_code,
584 pr_new.extended_amount,
585 pr_new.extended_amount,
586 pr_new.extended_amount * v_converted_rate,
587 v_creation_date,
588 v_created_by,
589 v_last_update_date,
590 v_last_updated_by,
591 v_last_update_login
592 );
593
594 IF rec.tax_type in ('Excise','Addl. Excise','Other Excise') THEN
595 Update JAI_AR_TRXS
596 Set total_amount = nvl(total_amount,0) + nvl(pr_new.extended_amount,0),
597 tax_amount = nvl(tax_amount,0) + nvl(pr_new.extended_amount,0)
598 Where Customer_Trx_Id = v_header_id;
599 END IF;
600 Update JAI_AR_TRX_LINES
601 Set total_amount = nvl(total_amount,0) + nvl(pr_new.extended_amount,0),
602 tax_amount = nvl(tax_amount,0) + nvl(pr_new.extended_amount,0)
603 Where Customer_Trx_Id = v_header_id
604 and Customer_Trx_Line_Id = v_link_to_cust_id;
605 END LOOP;
606 END IF;
607 /* Added an exception block by Ramananda for bug#4570303 */
608 EXCEPTION
609 WHEN OTHERS THEN
610 Pv_return_code := jai_constants.unexpected_error;
611 Pv_return_message := 'Encountered an error in JAI_AR_RCTLA_TRIGGER_PKG.ARI_T1 ' || substr(sqlerrm,1,1900);
612 END ARI_T1 ;
613
614 /*
615 REM +======================================================================+
616 REM NAME ARI_T2
617 REM
618 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
619 REM
620 REM NOTES Refers to old trigger JAI_AR_RCTLA_ARI_T7
621 REM
622 REM +======================================================================+
623 */
624 PROCEDURE ARI_T2 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
625 --2001/05/03 Gadde,Jagdish6
626 v_currency_code gl_sets_of_books.currency_code%TYPE;
627 v_gl_set_of_bks_id NUMBER;
628 --2001/05/03 Gadde,Jagdish
629
630 v_created_from VARCHAR2(30);
631
632 /* --Ramananda for File.Sql.35, start */
633 v_org_id NUMBER; --:=pr_new.org_id;
634 v_last_update_date DATE; -- := pr_new.last_update_date;
635 v_last_updated_by NUMBER; -- := pr_new.last_updated_by;
636 v_creation_date DATE; -- := pr_new.creation_date;
637 v_created_by NUMBER; -- := pr_new.created_by;
638 v_last_update_login NUMBER; -- := pr_new.last_update_login;
639 v_interface_line_attribute3 VARCHAR2(30); -- := pr_new.interface_line_attribute3;
640 v_interface_line_attribute6 VARCHAR2(30); -- := pr_new.interface_line_attribute6;
641 v_customer_trx_line_id NUMBER; -- := pr_new.customer_trx_line_id;
642 v_header_id NUMBER; -- := pr_new.customer_trx_id;
643 v_line_amount NUMBER; -- := nvl(pr_new.quantity_invoiced * pr_new.unit_selling_price,0);
644 /* --Ramananda for File.Sql.35, end */
645
646 x NUMBER;
647 v_organization_id NUMBER;
648 v_location_id NUMBER;
649 v_once_completed_flag VARCHAR2(1);
650 v_excise_amount NUMBER; --File.Sql.35 Cbabu := 0;
651 v_trx_number VARCHAR2(20);
652 v_tax_category_id NUMBER;
653 v_payment_register VARCHAR2(15);
654 v_excise_invoice_no VARCHAR2(200);
655 v_excise_invoice_date DATE;
656 v_tax_amount NUMBER; --File.Sql.35 Cbabu := 0;
657 v_excise_diff NUMBER; --File.Sql.35 Cbabu := 0;
658 v_assessable_value NUMBER; --File.Sql.35 Cbabu := 0;
659 v_basic_excise_duty_amount NUMBER; --File.Sql.35 Cbabu := 0;
660 v_add_excise_duty_amount NUMBER; --File.Sql.35 Cbabu := 0;
661 v_oth_excise_duty_amount NUMBER; --File.Sql.35 Cbabu := 0;
662
663 v_exist_flag NUMBER;--File.Sql.35 Cbabu := 0;
664 v_batch_source_id NUMBER ;
665 v_preprinted_excise_inv_no VARCHAR2(50);
666 v_books_id NUMBER;
667 v_salesrep_id NUMBER;
668 c_from_currency_code VARCHAR2(15);
669 c_conversion_type VARCHAR2(30);
670 c_conversion_date DATE;
671 c_conversion_rate NUMBER;
672 v_tax_line_no NUMBER;
673 v_tax_catg_id NUMBER;
674 v_excise_exempt_type VARCHAR2(60);
675 v_excise_exempt_refno VARCHAR2(30);
676 v_excise_exempt_date DATE;
677 v_exchange_rate NUMBER;
678 v_bill_to_customer_id NUMBER;
679 v_ship_to_site_use_id NUMBER;
680 v_receipt_id NUMBER;
681 v_so_tax_amount NUMBER;
682 vsqlerrm VARCHAR2(240);
683 v_qty NUMBER; -- added by sriram
684 -- added, Harshita for bug#4245062
685 lv_vat_exemption_flag JAI_AR_TRX_LINES.vat_exemption_flag%TYPE ;
686 lv_vat_exemption_type JAI_AR_TRX_LINES.vat_exemption_type%TYPE ;
687 lv_vat_exemption_date JAI_AR_TRX_LINES.vat_exemption_date%TYPE ;
688 lv_vat_exemption_refno JAI_AR_TRX_LINES.vat_exemption_refno%TYPE ;
689 ln_vat_assessable_value JAI_AR_TRX_LINES.vat_assessable_value%TYPE ;
690 ln_vat_invoice_no JAI_AR_TRXS.vat_invoice_no %TYPE ;
691 ln_vat_invoice_date JAI_AR_TRXS.vat_invoice_date%TYPE;
692 -- ended, Harshita for bug#4245062
693
694 lv_appl_src JAI_CMN_ERRORS_T.APPLICATION_SOURCE%type;
695 lv_err_msg JAI_CMN_ERRORS_T.error_message%type;
696
697 ln_legal_entity_id NUMBER ; /* rallamse bug#4510143 */
698
699 v_service_type VARCHAR2(30); -- added by csahoo for bug#5879769
700
701 -- Date 26-feb-2006 added by sacsethi for bug 5631784
702 -- for TCS enhancement
703 -- start 5631784
704 ln_threshold_tax_cat_id jai_ap_tds_thhold_taxes.tax_category_id%type;
705 -- start 5631784
706 ----------------------
707
708 -------------- cursor for st forms tracking -------------
709 CURSOR GET_HEADER_DETAILS IS
710 SELECT bill_to_customer_id,
711 bill_to_site_use_id,
712 trx_number,
713 batch_source_id
714 FROM RA_CUSTOMER_TRX_ALL
715 WHERE customer_trx_id = pr_new.customer_trx_id;
716 CURSOR GET_SITE(P_TRX_NUMBER VARCHAR2) IS
717 SELECT customer_site
718 FROM JAI_AR_SUP_HDRS_ALL
719 WHERE supplementary_num = TO_NUMBER(p_trx_number);
720 -------------- cursor for st forms tracking -------------
721 CURSOR GET_EXCHANGE_RATE IS
722 SELECT exchange_rate
723 FROM ra_customer_trx_all
724 WHERE customer_trx_id = pr_new.customer_trx_id;
725 CURSOR CREATED_FROM_CUR IS
726 SELECT created_from, trx_number, batch_source_id, set_of_books_id, primary_salesrep_id,
727 invoice_currency_code, exchange_rate_type, exchange_date, exchange_rate
728 FROM ra_customer_trx_all
729 WHERE customer_trx_id = v_header_id;
730
731 CURSOR SO_PICKING_HDR_INFO IS
732 SELECT A.organization_id, A.location_id
733 FROM JAI_OM_WSH_LINES_ALL A,WSH_NEW_DELIVERIES B
734 WHERE A.delivery_id = B.DELIVERY_ID AND
735 B.NAME = v_interface_line_attribute3 AND
736 A.order_line_id = TO_NUMBER(v_interface_line_attribute6);
737
738 /* Added by JMEENA for bug# 6498345 (FP 6492966) Starts */
739 CURSOR c_ato_order IS
740 SELECT
741 1
742 FROM
743 oe_order_lines_all
744 WHERE
745 item_type_code IN ('CONFIG', 'MODEL', 'OPTION', 'CLASS')
746 AND line_id = (SELECT ato_line_id
747 FROM oe_order_lines_all
748 WHERE line_id = v_interface_line_attribute6 );
749
750 /* Retrieve Org + Loc from ja_in_so_picking_lines from the Config (Start) Item */
751 CURSOR c_ato_hdr_info IS
752 SELECT
753 organization_id, location_id
754 FROM
755 JAI_OM_WSH_LINES_ALL
756 WHERE
757 order_line_id IN (SELECT line_id
758 FROM oe_order_lines_all oel2
759 WHERE oel2.item_type_code = 'CONFIG'
760 AND oel2.header_id = (
761 SELECT header_id
762 FROM oe_order_lines_all oel
763 WHERE oel.line_id = v_interface_line_attribute6)
764 AND oel2.ato_line_id = (SELECT ato_line_id
765 FROM oe_order_lines_all oel1
766 WHERE oel1.line_id = v_interface_line_attribute6))
767 AND organization_id is not null
768 AND location_id is not null
769 AND rownum = 1 ;
770
771 ln_order_ato NUMBER ;
772 /* Added by JMEENA for bug#6498345(FP 6492966) Ends */
773
774 CURSOR JA_IN_RA_CUSTOMER_TRX_INFO IS
775 SELECT organization_id,
776 Location_id
777 FROM JAI_AR_TRXS
778 WHERE customer_trx_id = TO_NUMBER(pr_new.interface_line_attribute4); -- Replaced pr_new.interface_line_attribute1 , Bug 4392001
779 CURSOR JA_IN_RA_CUSTOMER_TRX_INFOCNSL IS
780 SELECT A.organization_id,
781 A.Location_id
782 FROM JAI_AR_TRXS A,
783 JAI_AR_SUP_HDRS_ALL B,
784 RA_CUSTOMER_TRX_ALL C
785 WHERE pr_new.customer_trx_id = c.customer_trx_id
786 AND c.trx_number = TO_CHAR(B.SUPPLEMENTARY_NUM)
787 AND B.customer_trx_id = A.customer_trx_id;
788
789 CURSOR SO_PICKING_LINES_INFO IS --12-APR-02
790 SELECT tax_category_id,Quantity , -- Quantity Added By Sriram Bug # .. Base Bug 2335923
791 (tax_amount/quantity) tax_amount, --Added by Jagdish 30-Aug-01
792 assessable_value, (basic_excise_duty_amount/quantity) basic_excise_duty_amount,
793 (add_excise_duty_amount/quantity) add_excise_duty_amount,
794 (oth_excise_duty_amount/quantity) oth_excise_duty_amount,
795 register, excise_invoice_no,
796 preprinted_excise_inv_no, excise_invoice_date,
797 excise_exempt_type, excise_exempt_refno, excise_exempt_date
798 , ar3_form_no, ar3_form_date, -- Vijay Shankar for Bug # 3181892
799 vat_exemption_flag, vat_exemption_type, vat_exemption_date, vat_exemption_refno, vat_assessable_value, vat_invoice_no, vat_invoice_date -- added, Harshita for bug#4245062
800 FROM JAI_OM_WSH_LINES_ALL a,wsh_new_deliveries b
801 WHERE A.delivery_id = b.delivery_id AND
802 B.NAME = v_interface_line_attribute3 AND
803 A.order_line_id = TO_NUMBER(v_interface_line_attribute6);
804
805 CURSOR SUPPLEMENT_LINES_INFO IS
806 SELECT DISTINCT A.tax_category_id,
807 (NVL(A.excise_diff_amt,0)+NVL(A.other_diff_amt,0)) TAX_AMT,
808 NVL(A.excise_diff_amt,0) excise_diff,
809 A.new_assessable_value
810 FROM JAI_AR_SUP_LINES A,
811 ra_customer_trx_all b,
812 ra_cust_trx_types_all c
813 WHERE B.CUST_TRX_TYPE_ID = C.CUST_TRX_TYPE_ID
814 AND A.SUP_INV_TYPE = DECODE(C.TYPE,'DM','DB','CM','CR','INV','SI')
815 AND A.customer_trx_line_id = TO_NUMBER(pr_new.interface_line_attribute3)
816 AND pr_new.customer_trx_id = b.customer_trx_id;
817
818 CURSOR SUPPLEMENT_LINES_INFO_CNSLDT IS
819 SELECT SUM(NVL(A.excise_diff_amt,0))+SUM(NVL(A.other_diff_amt,0)) TAX_AMT,
820 NVL(A.excise_diff_amt,0) excise_diff,
821 A.new_assessable_value
822 FROM JAI_AR_SUP_LINES A,
823 JAI_AR_SUP_HDRS_ALL b,
824 ra_customer_trx_all c,
825 ra_cust_trx_types_all e
826 WHERE pr_new.customer_trx_id = c.customer_trx_id
827 AND c.trx_number = TO_CHAR( b.SUPPLEMENTARY_NUM)
828 AND B.customer_trx_id = A.customer_trx_id
829 AND C.cust_trx_type_id = e.cust_trx_type_id
830 AND b.supp_inv_type = DECODE(e.TYPE,'DM','DB','CM','CR','INV','SI')
831 AND A.description = pr_new.description
832 AND A.sup_inv_type = b.supp_inv_type
833 GROUP BY A.inventory_item_id ,
834 A.new_assessable_value,
835 b.supp_inv_type;
836
837 CURSOR SUPPLEMENT_LINES_INFO_Tax_catg IS
838 SELECT A.tax_category_id
839 FROM JAI_AR_SUP_LINES A,
840 JAI_AR_SUP_HDRS_ALL b,
841 ra_customer_trx_all c,
842 ra_cust_trx_types_all D
843 WHERE pr_new.customer_trx_id = c.customer_trx_id
844 AND c.trx_number =TO_CHAR( b.SUPPLEMENTARY_NUM)
845 AND B.customer_trx_id = A.customer_trx_id
846 AND A.sup_inv_type = b.supp_inv_type
847 AND C.cust_trx_type_id = D.cust_trx_type_id
848 AND b.supp_inv_type = DECODE(D.TYPE,'DM','DB','CM','CR','INV','SI');
849
850 -- Date 23/02/2006 by sacsethi for bug 5228046
851 -- precedence 6 to 10
852 CURSOR SO_PICKING_TAX_LINES_INFO IS
853 SELECT b.quantity , --Added by Jagdish 30-Aug-01
854 A.tax_line_no,
855 A.uom,
856 A.tax_id,
857 A.tax_rate,
858 A.qty_rate,
859 A.base_tax_amount,
860 A.tax_amount,
861 c.tax_type,
862 A.func_tax_amount,
863 A.precedence_1, A.precedence_2, A.precedence_3, A.precedence_4, A.precedence_5,
864 A.precedence_6, A.precedence_7, A.precedence_8, A.precedence_9, A.precedence_10,
865 b.vat_invoice_no,b.vat_invoice_date
866 FROM JAI_OM_WSH_LINE_TAXES A,JAI_OM_WSH_LINES_ALL b,
867 JAI_CMN_TAXES_ALL c, wsh_new_deliveries D
868 WHERE A.delivery_detail_id = b.delivery_detail_id
869 AND A.tax_id=c.tax_id
870 and c.tax_type <> 'Modvat Recovery'/*Bug 4881426 bduvarag*/
871 AND b.delivery_id = D.delivery_id
872 AND D.name = v_interface_line_attribute3
873 AND b.order_line_id = TO_NUMBER(v_interface_line_attribute6); --Added on 17-Apr-2002
874
875
876 CURSOR SO_PICKING_TAX_AMT(p_tax_id NUMBER) IS
877 SELECT SUM(A.base_tax_amount) base_tax_amount,
878 SUM(A.tax_amount) tax_amount,
879 SUM(A.func_tax_amount) func_tax_amount
880 FROM JAI_OM_WSH_LINE_TAXES A,JAI_OM_WSH_LINES_ALL b,WSH_NEW_DELIVERIES C
881 WHERE A.delivery_detail_id = b.delivery_detail_id
882 AND b.delivery_id = c.delivery_id
883 AND c.NAME = v_interface_line_attribute3
884 AND b.order_line_id = TO_NUMBER(v_interface_line_attribute6)
885 AND A.tax_id = p_tax_id
886 GROUP BY A.tax_id; --17-Apr-2002
887
888 v_base_tax_amount NUMBER;
889 v_tax_amt NUMBER;
890 v_func_tax_amount NUMBER;
891
892 ln_first_time NUMBER;
893
894
895 CURSOR SUPPLEMENT_TAX_LINES IS
896 SELECT DISTINCT A.tax_line_no,
897 A.new_uom,
898 A.new_tax_id,
899 A.new_rate,
900 A.new_qty_rate,
901 (NVL(A.new_base_tax_amt,0) - NVL(A.old_base_tax_amt,0)) BASE_TAX_AMT,
902 A.diff_amt,
903 A.diff_amt FUNC_TAX_AMT,
904 t.tax_type,
905 t.stform_type
906 FROM JAI_AR_SUP_TAXES A,
907 JAI_AR_SUP_LINES b,
908 ra_customer_trx_all C,
909 ra_cust_trx_types_all D,
910 JAI_CMN_TAXES_ALL t
911 WHERE A.link_to_cust_trx_line_id = b.customer_trx_line_id
912 AND A.sup_inv_type = b.sup_inv_type
913 AND b.customer_Trx_line_id = TO_NUMBER(pr_new.interface_line_attribute3)
914 AND pr_new.customer_trx_id = c.customer_trx_id
915 AND c.cust_trx_type_id = D.cust_trx_type_id
916 AND b.sup_inv_type = DECODE(D.TYPE,'DM','DB','CM','CR','INV','SI')
917 AND A.new_tax_id = t.tax_id
918 ORDER BY A.tax_line_no;
919
920 CURSOR SUPPLEMENT_TAX_LINES_CNSLDT IS
921 SELECT A.new_uom,
922 A.new_tax_id,
923 A.new_rate,
924 A.new_qty_rate,
925 SUM(NVL(A.new_base_Tax_amt,0) - NVL(A.old_base_tax_amt,0)) BASE_TAX_AMT,
926 SUM(A.diff_amt) DIFF_AMT,
927 SUM(A.diff_amt) FUNC_TAX_AMT,
928 t.tax_type,
929 t.stform_type
930 FROM JAI_AR_SUP_TAXES A,
931 JAI_AR_SUP_LINES b,
932 JAI_AR_SUP_HDRS_ALL c,
933 ra_customer_trx_all D,
934 ra_cust_trx_types_all e,
935 JAI_CMN_TAXES_ALL t
936 WHERE pr_new.customer_trx_id = D.customer_trx_id
937 AND D.trx_number = TO_CHAR(c.SUPPLEMENTARY_NUM)
938 AND c.customer_trx_id = b.customer_trx_id
939 AND b.customer_trx_line_id = A.link_to_cust_trx_line_id
940 AND b.sup_inv_type = A.sup_inv_type
941 AND b.description = pr_new.description
942 AND c.supp_inv_type = b.sup_inv_type
943 AND e.cust_trx_type_id = D.cust_trx_type_id
944 AND c.supp_inv_type = DECODE(e.TYPE,'DM','DB','CM','CR','INV','SI')
945 and t.tax_type <> lc_modvat_tax/*Bug 4881426 bduvarag*/
946 AND A.new_tax_id = t.tax_id
947 GROUP BY b.inventory_item_id,
948 A.new_tax_id,
949 A.new_uom,
950 A.new_qty_rate,
951 A.new_rate,
952 t.tax_type,
953 t.stform_type ;
954
955 CURSOR DUPLICATE_HDR_CUR IS
956 SELECT 1
957 FROM JAI_AR_TRXS
958 WHERE customer_trx_id = v_header_id;
959
960 CURSOR ONCE_COMPLETE_FLAG_CUR IS
961 SELECT once_completed_flag
962 FROM JAI_AR_TRXS
963 WHERE customer_trx_id = v_header_id;
964 /* Cursor To Check Whether Interfaced Record Exist in JAI_OM_WSH_LINES_ALL */
965
966 CURSOR SO_PICKING_RECORD_CHECK IS
967 SELECT 1
968 FROM JAI_OM_WSH_LINES_ALL A,WSH_NEW_DELIVERIES B
969 WHERE A.delivery_id = B.DELIVERY_ID AND
970 B.NAME = v_interface_line_attribute3
971 AND A.order_line_id = TO_NUMBER(v_interface_line_attribute6); --17-Apr-2002
972
973
974 CURSOR SUPPLEMENT_LINES_CHECK IS
975 SELECT 1
976 FROM JAI_AR_SUP_LINES
977 WHERE customer_trx_line_id = TO_NUMBER(pr_new.interface_line_attribute3);
978 CURSOR SUPPLEMENT_LINES_CHECK_CNSLDT IS
979 SELECT 1
980 FROM JAI_AR_SUP_LINES A,
981 JAI_AR_SUP_HDRS_ALL B,
982 RA_CUSTOMER_TRX_ALL C,
983 RA_CUST_TRX_TYPES_ALL D
984 WHERE pr_new.CUSTOMER_TRX_ID = C.customer_trx_id
985 AND c.cust_trx_type_id = D.cust_trx_type_id
986 AND c.trx_number = TO_CHAR(b.SUPPLEMENTARY_NUM)
987 AND b.supp_inv_type = DECODE(D.TYPE,'INV','SI','CM','CR','DM','DB')
988 AND b.supp_inv_type = A.sup_inv_type
989 AND A.customer_trx_id = b.customer_trx_id;
990
991 CURSOR SO_PICKING_TAX_RECORD_CHECK IS
992 SELECT DISTINCT 1
993 FROM JAI_OM_WSH_LINE_TAXES A, JAI_OM_WSH_LINES_ALL b, WSH_NEW_DELIVERIES C
994 WHERE A.delivery_detail_id = b.delivery_detail_id
995 AND b.delivery_id = C.DELIVERY_ID AND
996 c.NAME = v_interface_line_attribute3
997 AND b.order_line_id = TO_NUMBER(v_interface_line_attribute6); --17-Apr-2002
998
999 CURSOR SUPPLEMENT_TAX_LINES_CHECK IS
1000 SELECT 1
1001 FROM JAI_AR_SUP_TAXES A, JAI_AR_SUP_LINES b
1002 WHERE A.link_to_cust_trx_line_id = b.customer_trx_line_id
1003 AND b.customer_trx_line_id = v_customer_Trx_line_id;
1004
1005 CURSOR SUPPLEMENT_TAX_LINES_CHECK_CNS IS
1006 SELECT 1
1007 FROM JAI_AR_SUP_LINES A,
1008 JAI_AR_SUP_HDRS_ALL B,
1009 RA_CUSTOMER_TRX_ALL C,
1010 RA_CUST_TRX_TYPES_ALL D,
1011 JAI_AR_SUP_TAXES E
1012 WHERE pr_new.CUSTOMER_TRX_ID = C.customer_trx_id
1013 AND c.cust_trx_type_id = D.cust_trx_type_id
1014 AND c.trx_number = TO_CHAR(b.SUPPLEMENTARY_NUM)
1015 AND b.supp_inv_type = DECODE(D.TYPE,'INV','SI','CM','CR','DM','DB')
1016 AND b.supp_inv_type = A.sup_inv_type
1017 AND A.customer_trx_id = b.customer_trx_id
1018 AND E.link_to_cust_trx_line_id = A.customer_trx_line_id
1019 AND A.sup_inv_type = e.sup_inv_type;
1020
1021 CURSOR complete_flag_cur IS
1022 SELECT complete_flag
1023 FROM ra_customer_trx_all
1024 WHERE customer_trx_id = v_header_id;
1025 v_trans_type VARCHAR2(30);
1026
1027 CURSOR transaction_type_cur IS
1028 SELECT A.TYPE
1029 FROM RA_CUST_TRX_TYPES_ALL A, RA_CUSTOMER_TRX_ALL b
1030 WHERE A.cust_trx_type_id = b.cust_trx_type_id
1031 AND b.customer_trx_id = v_header_id
1032 AND NVL(A.org_id,0) = NVL(pr_new.org_id,0);
1033 /* Code Added For Service Module */
1034 v_item_type_code VARCHAR2(50);
1035 v_serviced_quantity NUMBER;
1036 v_return_reference_id NUMBER;
1037 v_original_line_reference VARCHAR2(50);
1038 v_customer_product_id NUMBER;
1039 v_warehouse_id NUMBER;
1040 v_order_header_id NUMBER;
1041
1042 CURSOR So_Lines_Info_Cur IS
1043 SELECT item_type_code, serviced_quantity, return_reference_id, original_system_line_reference, customer_product_id,
1044 warehouse_id, header_id
1045 FROM So_Lines_All
1046 WHERE line_id = TO_NUMBER(v_interface_line_attribute6);
1047
1048 CURSOR JA_SO_LINES_RECORD_CHECK IS
1049 SELECT 1
1050 FROM JAI_OM_OE_SO_LINES
1051 WHERE line_id = TO_NUMBER(v_interface_line_attribute6);
1052
1053 CURSOR JA_SO_LINES_TAX_RECORD_CHECK IS
1054 SELECT DISTINCT 1
1055 FROM JAI_OM_OE_SO_TAXES A, JAI_OM_OE_SO_LINES b
1056 WHERE A.line_id = TO_NUMBER(v_interface_line_attribute6)
1057 AND A.line_id = b.line_id;
1058
1059 -- Date 23/02/2006 by sacsethi for bug 5228046
1060 -- precedence 6 to 10
1061 CURSOR JA_SO_TAX_LINES_INFO IS
1062 SELECT A.tax_line_no, A.uom, A.tax_id, A.tax_rate, A.qty_rate, A.base_tax_amount,A.tax_amount,
1063 A.func_tax_amount,
1064 A.precedence_1, A.precedence_2, A.precedence_3, A.precedence_4, A.precedence_5,
1065 A.precedence_6, A.precedence_7, A.precedence_8, A.precedence_9, A.precedence_10,
1066 c.tax_type
1067 FROM JAI_OM_OE_SO_TAXES A, JAI_OM_OE_SO_LINES b, JAI_CMN_TAXES_ALL c
1068 WHERE A.line_id = b.line_id
1069 AND b.line_id = TO_NUMBER(v_interface_line_attribute6)
1070 AND A.tax_id = c.tax_id
1071 and c.tax_type <> lc_modvat_tax/*Bug 4881426 bduvarag*/
1072 ORDER BY A.tax_line_no;
1073
1074 CURSOR ja_so_lines_info IS
1075 SELECT tax_category_id, tax_amount, assessable_value, excise_exempt_type,excise_exempt_refno, excise_exempt_date,
1076 vat_exemption_flag, vat_exemption_type, vat_exemption_date, vat_exemption_refno, vat_assessable_value -- added, Harshita for bug#4245062
1077 FROM JAI_OM_OE_SO_LINES
1078 WHERE line_id = to_number(v_interface_line_attribute6);
1079 -- Bug 3357587
1080 CURSOR C_JA_SO_LINES_ASSESSABLE_VAL IS
1081 SELECT assessable_value, service_type_code -- service_type_code added by csahoo for bug#5879769
1082 from JAI_OM_OE_SO_LINES
1083 WHERE line_id = TO_NUMBER(v_interface_line_attribute6);
1084 /* bug 5243532. Added by Lakshmi Gopalsami
1085 Removed the reference to cursor set_of_books_cur
1086 as the SOB will never be null in base table.
1087 */
1088
1089 --ADDED TO CHECK DUPLICATE ENTRY FOR LINES 01-DEC-99 GAURAV.
1090 CURSOR DUPLICATE_LINES_CUR IS
1091 SELECT 1
1092 FROM JAI_AR_TRX_LINES
1093 WHERE customer_trx_LINE_id = v_customer_trx_line_id;
1094
1095 CURSOR OLD_CUSTOMER_TRX_ID_CUR IS
1096 SELECT Customer_Trx_Id
1097 FROM JAI_AR_TRX_LINES
1098 WHERE customer_trx_LINE_id = v_customer_trx_line_id;
1099 CURSOR DUPLICATE_TAX_LINES_CUR(v_tax_id NUMBER) IS
1100 SELECT 1
1101 FROM JAI_AR_TRX_TAX_LINES
1102 WHERE link_to_cust_trx_line_id = v_customer_trx_line_id
1103 AND tax_id = v_tax_id;
1104 v_line_count NUMBER;
1105 v_tax_line_count NUMBER;
1106 v_old_customer_trx_id NUMBER;
1107 --2001/04/11 JAGDISH BHOSLE
1108
1109 J_organization_id NUMBER;
1110 J_location_id NUMBER;
1111 J_batch_source_id NUMBER;
1112 v_register_code JAI_OM_OE_BOND_REG_HDRS.REGISTER_CODE%TYPE;
1113
1114 CURSOR get_header_info_cur IS
1115 SELECT A.organization_id,
1116 A.location_id,
1117 A.order_type_id
1118 FROM JAI_OM_WSH_LINES_ALL A,WSH_NEW_DELIVERIES B
1119 WHERE A.delivery_id = B.DELIVERY_ID AND
1120 B.NAME = v_interface_line_attribute3
1121 AND A.order_line_id = TO_NUMBER(v_interface_line_attribute6); --17-Apr-2002
1122
1123 CURSOR get_register_code_cur(p_organization_id NUMBER,
1124 p_location_id NUMBER,
1125 p_batch_source_id NUMBER) IS
1126 SELECT register_code
1127 FROM JAI_OM_OE_BOND_REG_HDRS
1128 WHERE organization_id = p_organization_id
1129 AND location_id = p_location_id
1130 AND register_id IN (SELECT register_id
1131 FROM JAI_OM_OE_BOND_REG_DTLS
1132 WHERE order_type_id = p_batch_source_id
1133 AND order_flag = 'Y');
1134
1135
1136 /*
1137 The following cursor definition has been modified for performance reasons.
1138 Using the nvl and the org_organization_definitions table was causing performance problems .
1139 The modified explain plan has been compared with the previous and the performance is much
1140 better with the modified one.
1141 Sriram - Bug # 2668342 - Organization_id column is the operating_unit in the table.
1142 */
1143
1144 /* Bug 5243532. Added by Lakshmi Gopalsami
1145 Removed the cursor Fetch_Book_Id_cur which is referening to
1146 org_organization_definitions as we can get the SOB from the
1147 value assigned in the trigger
1148
1149 Also removed the sob_cur as it is not used anywhere.
1150 */
1151
1152
1153 --2001/05/03 Gadde,Jagdish
1154 --2001/04/20 Anuradha Parthasarathy
1155
1156 CURSOR pref_cur(p_organization_id NUMBER, p_location_id NUMBER)IS
1157 SELECT pref_rg23a, pref_rg23c, pref_pla
1158 FROM JAI_CMN_INVENTORY_ORGS
1159 WHERE organization_id = p_organization_id
1160 AND location_id = p_location_id ;
1161
1162 v_pref_rg23a NUMBER;
1163 v_pref_rg23c NUMBER;
1164 v_pref_pla NUMBER;
1165 v_ssi_unit_flag VARCHAR2(1);
1166 v_raise_error_flag VARCHAR2(1);
1167 v_fin_year NUMBER;
1168 v_rg23a_balance NUMBER;
1169 v_rg23c_balance NUMBER;
1170 v_pla_balance NUMBER;
1171 v_reg_type VARCHAR2(10);
1172 v_calc_tax_amount NUMBER;
1173
1174 CURSOR fin_year_cur(p_org_id IN NUMBER) IS
1175 SELECT MAX(A.fin_year)
1176 FROM JAI_CMN_FIN_YEARS A
1177 WHERE organization_id = p_org_id AND fin_active_flag = 'Y';
1178
1179 CURSOR rg_bal_cur(p_organization_id NUMBER, p_location_id NUMBER)IS
1180 SELECT NVL(rg23a_balance,0) rg23a_balance ,NVL(rg23c_balance,0) rg23c_balance,NVL(pla_balance,0) pla_balance
1181 FROM JAI_CMN_RG_BALANCES
1182 WHERE organization_id = p_organization_id
1183 AND location_id = p_location_id ;
1184
1185 CURSOR ssi_unit_flag_cur(p_organization_id IN NUMBER, p_location_id IN NUMBER) IS
1186 SELECT ssi_unit_flag
1187 FROM JAI_CMN_INVENTORY_ORGS
1188 WHERE organization_id = p_organization_id AND
1189 location_id = p_location_id;
1190
1191 CURSOR register_code_cur(p_org_id IN NUMBER, p_loc_id IN NUMBER, p_batch_source_id IN NUMBER) IS
1192 SELECT register_code
1193 FROM JAI_OM_OE_BOND_REG_HDRS
1194 WHERE organization_id = p_org_id AND
1195 location_id = p_loc_id AND
1196 register_id IN (SELECT register_id FROM JAI_OM_OE_BOND_REG_DTLS
1197 WHERE order_type_id = p_batch_source_id AND order_flag ='N');
1198
1199 CURSOR Register_Code_Meaning_Cur(p_register_code IN VARCHAR2, cp_lookup_type So_lookups.lookup_type%TYPE ) IS
1200 SELECT meaning
1201 FROM So_lookups
1202 WHERE lookup_code = p_register_code
1203 AND lookup_type = cp_lookup_type; /* 'REGISTER_TYPE'; Ramananda for removal of SQL LITERALs */
1204
1205 v_meaning VARCHAR2(80);
1206
1207 CURSOR Batch_Source_Name_Cur(p_batch_source_id IN NUMBER) IS
1208 SELECT name
1209 FROM Ra_Batch_Sources_All
1210 WHERE batch_source_id = p_batch_source_id
1211 AND NVL(org_id,0) = NVL(pr_new.org_id,0);
1212
1213 v_order_invoice_type VARCHAR2(50);
1214
1215 CURSOR Def_Excise_Invoice_Cur(p_organization_id IN NUMBER, p_location_id IN NUMBER, p_fin_year IN NUMBER,
1216 p_batch_name IN VARCHAR2, p_register_code IN VARCHAR2) IS
1217 SELECT start_number, end_number, jump_by, prefix
1218 FROM JAI_CMN_RG_EXC_INV_NOS
1219 WHERE organization_id = p_organization_id
1220 AND location_id = p_location_id
1221 AND fin_year = p_fin_year
1222 AND transaction_type = 'I'
1223 AND order_invoice_type = p_batch_name
1224 AND register_code = p_register_code ;
1225 /* Modified by Ramananda for removal of SQL LITERALs */
1226 --AND NVL(order_invoice_type,'###') = p_batch_name
1227 --AND NVL(register_code,'###') = NVL(p_register_code,'***');
1228
1229 v_start_number NUMBER;
1230 v_end_number NUMBER;
1231 v_jump_by NUMBER;
1232 v_prefix VARCHAR2(50);
1233 v_exc_invoice_no VARCHAR2(200);
1234 v_reg_code VARCHAR2(30);
1235 CURSOR ec_code_cur(p_organization_id IN NUMBER, p_location_id IN NUMBER) IS
1236 SELECT A.Organization_Id, A.Location_Id
1237 FROM JAI_CMN_INVENTORY_ORGS A
1238 WHERE A.Ec_Code IN (SELECT B.Ec_Code
1239 FROM JAI_CMN_INVENTORY_ORGS B
1240 WHERE B.Organization_Id = p_organization_id
1241 AND B.Location_Id = p_location_id);
1242
1243 v_source_name VARCHAR2(100); --File.Sql.35 Cbabu := 'Receivables India';
1244 v_category_name VARCHAR2(100); --File.Sql.35 Cbabu := 'RG Register Data Entry';
1245
1246 v_rg23_part_ii_no NUMBER;
1247 v_rg23_part_i_no NUMBER;
1248 v_pla_register_no NUMBER;
1249 v_part_i_register_id NUMBER ;
1250
1251 CURSOR site_cur IS
1252 SELECT SHIP_TO_CUSTOMER_ID,SHIP_TO_SITE_USE_ID
1253 FROM ra_customer_trx_all
1254 WHERE customer_trx_id = pr_new.customer_trx_id
1255 AND org_id = pr_new.org_id;
1256
1257
1258
1259 v_ship_id NUMBER;
1260 v_ship_site_id NUMBER;
1261 v_bond_tax_amt NUMBER; -- cbabu for Bug# 2779990
1262
1263 --Start of bug 3328871
1264 /*
1265 Query modified by aiyer for the bug 3328871
1266 Nvl clause has been added to ascertain that a value of zero
1267 gets inserted even if where clause fails to retrieve a record.
1268 */
1269 -- bug # 3000550 sriram
1270 cursor c_cust_trx_tax_line_amt is
1271 select nvl(sum(tax_amount),0)
1272 from JAI_AR_TRX_TAX_LINES
1273 where link_to_cust_trx_line_id = v_customer_trx_line_id;
1274 -- bug # 3000550 sriram
1275 -- End of bug 3328871
1276
1277 --2001/04/20 Anuradha Parthasarathy
1278
1279 V_REGISTER_ID Number; -- bug # 3021588
1280
1281
1282 -- Added an internal procedure for processing ATO Orders Bug # 2806274 - Sriram
1283
1284 v_so_line_id Number;
1285 v_item_type oe_order_lines_all.item_type_code%type;
1286 v_ato_line_id Varchar2(30);
1287 v_config_line_id Number;
1288 v_ex_inv_no JAI_OM_WSH_LINES_ALL.excise_invoice_no%type;
1289 v_pmt_reg JAI_OM_WSH_LINES_ALL.register%type;
1290 v_pre_prnt_ex_no JAI_OM_WSH_LINES_ALL.preprinted_excise_inv_no%type;
1291 v_ato_line_amount Number;
1292 v_ato_tax_amount Number;
1293 v_ato_total_amount Number;
1294 -- v_ar3_form_no Number;
1295 v_ar3_form_no JAI_AR_TRX_LINES.ar3_form_no%TYPE; -- Vijay shankar for Bug # 3181892
1296 v_ar3_form_date Date;
1297
1298 /*
1299 start additions by sriram - bug# 3607101
1300 */
1301 cursor c_ont_source_code is
1302 select FND_PROFILE.VALUE('ONT_SOURCE_CODE')
1303 from dual;
1304 v_ont_source_code ra_interface_lines_all.interface_line_context%type;
1305 /*
1306 ends here additions by sriram -bug#3607101
1307 */
1308
1309 cursor c_bill_only_invoice(cp_customer_trx_line_id number, cp_process_name oe_wf_line_assign_v.process_name%type ) is
1310 select 1
1311 from oe_wf_order_assign_v o_wf_asg
1312 where order_type_name = pr_new.interface_line_attribute2
1313 and exists
1314 (
1315 select 1
1316 from oe_wf_line_assign_v l_wf_asg
1317 where assignment_id = o_wf_asg.assignment_id
1318 and process_name = cp_process_name /*'R_BILL_ONLY' Ramananda for removal of SQL LITERALs */
1319 and order_type_id = l_wf_asg.order_type_id
1320 )
1321 ;
1322
1323 ln_bill_only number; --File.Sql.35 Cbabu := 0;
1324
1325
1326 /* added rallamse bug#4448789 */
1327 FUNCTION get_legal_entity_id RETURN NUMBER IS
1328
1329 CURSOR cur_legal_entity_id IS
1330 SELECT legal_entity_id
1331 FROM RA_CUSTOMER_TRX_ALL
1332 WHERE customer_trx_id = pr_new.customer_trx_id ;
1333
1334 ln_legal_entity_id NUMBER ;
1335
1336 BEGIN
1337 pv_return_code := jai_constants.successful ;
1338
1339 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Function get_legal_entity_id');
1340
1341 OPEN cur_legal_entity_id ;
1342 FETCH cur_legal_entity_id INTO ln_legal_entity_id ;
1343 CLOSE cur_legal_entity_id ;
1344
1345 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Legal Entity Id: '|| ln_legal_entity_id);
1346
1347 RETURN ln_legal_entity_id ;
1348
1349 END get_legal_entity_id ;
1350 /* end bug#4448789 */
1351
1352 Procedure Process_Taxes_for_ATO_Order is
1353
1354 cursor c_item_type is
1355 select item_type_code
1356 from oe_order_lines_all
1357 where line_id = v_interface_line_attribute6;
1358
1359 Cursor c_om_taxes(v_so_config_line_id Number) is
1360 select *
1361 from JAI_OM_OE_SO_TAXES
1362 where line_id = v_so_config_line_id;
1363
1364 Cursor c_get_config_line_id(v_ato_line_id Varchar2, cp_item_code oe_order_lines_all.item_type_code%type) is
1365 Select line_id
1366 from oe_order_lines_all
1367 where ato_line_id = v_ato_line_id
1368 and item_type_code = cp_item_code; /*'CONFIG'; Ramananda for removal of SQL LITERALs */
1369
1370 CURSOR c_get_om_lines(v_ato_line_id Varchar2) is
1371 SELECT *
1372 FROM JAI_OM_OE_SO_LINES
1373 WHERE line_id = v_ato_line_id;
1374
1375 cursor c_so_picking_data (v_ato_line_id Varchar2) is
1376 SELECT excise_invoice_no , register , preprinted_excise_inv_no , ar3_form_no ,ar3_form_date
1377 FROM JAI_OM_WSH_LINES_ALL
1378 WHERE order_line_id = v_ato_line_id;
1379
1380 CURSOR so_ato_picking_hdr_info(v_ato_line_id Varchar2) IS
1381 SELECT a.organization_id, a.location_id
1382 FROM JAI_OM_WSH_LINES_ALL a,wsh_new_deliveries b
1383 WHERE a.delivery_id = b.delivery_id and
1384 B.NAME = v_interface_line_attribute3 AND
1385 A.order_line_id = TO_NUMBER(v_ato_line_id);
1386
1387 CURSOR c_get_tax_info(p_tax_id Number) is
1388 SELECT tax_type
1389 FROM JAI_CMN_TAXES_ALL
1390 WHERE tax_id = p_tax_id;
1391
1392 v_tax_type JAI_CMN_TAXES_ALL.tax_type%type;
1393 v_tax_amount Number; --File.Sql.35 Cbabu :=0;
1394
1395 ln_legal_entity_id NUMBER ; /* rallamse bug#4510143 */
1396
1397 BEGIN
1398 pv_return_code := jai_constants.successful ;
1399
1400 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Inside Procedure Process_Taxes_for_ATO_Order');
1401 FND_FILE.PUT_LINE(FND_FILE.LOG,'ATO: v_item_type: ' || v_item_type); -- Added for bug#6498345 by JMEENA
1402 v_tax_amount :=0;
1403
1404 open c_item_type;
1405 fetch c_item_type into v_item_type;
1406 close c_item_type;
1407
1408 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Item type'|| v_item_type);
1409
1410 if NVL(v_item_type,'$$$') = 'MODEL' then
1411 IF (NVL(pr_new.Interface_line_attribute11,'0') ='0'
1412 and nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - bug# 3607101
1413 ) /* following OR added by sriram - bug#3607101 */
1414 or
1415 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug# 3607101
1416 )
1417 then
1418 -- using the following cursor , we get the line_id
1419 -- of the 'config' item in oe_order_lines_all
1420 Open c_get_config_line_id(v_interface_line_attribute6, 'CONFIG'); /* Modified by Ramananda for removal of SQL LITERALs */
1421 Fetch c_get_config_line_id into v_config_line_id;
1422 Close c_get_config_line_id;
1423
1424 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Config line id ' || v_config_line_id);
1425
1426 -- the variable v_config_line_id holds the line_id of the
1427 -- config item corresponding to the 'Model' item being imported.
1428
1429 For so_taxes_rec in c_om_taxes(v_config_line_id)
1430 Loop
1431 Open c_get_tax_info(so_taxes_rec.tax_id);
1432 Fetch c_get_tax_info into v_tax_type;
1433 close c_get_tax_info;
1434
1435 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Tax Type: '|| v_tax_type);
1436
1437 IF V_REGISTER_CODE ='BOND_REG' THEN
1438
1439 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Inside BOND Register');
1440 /* jai_constants.tax_type_sh_exc_edu_cess, jai_constants.tax_type_sh_cvd_edu_cess added by CSahoo Bug#5989740*/
1441 IF v_tax_type NOT IN ('Excise','Other Excise','CVD_EDUCATION_CESS','EXCISE_EDUCATION_CESS',jai_constants.tax_type_sh_cvd_edu_cess, jai_constants.tax_type_sh_exc_edu_cess) THEN
1442 /* 'CVD_EDUCATION_CESS','EXCISE_EDUCATION_CESS' added by ssumaith - bug# 4136981*/
1443 -- Date 23/02/2006 by sacsethi for bug 5228046
1444 -- precedence 6 to 10
1445 INSERT INTO JAI_AR_TRX_TAX_LINES
1446 (
1447 tax_line_no ,
1448 customer_trx_line_id ,
1449 link_to_cust_trx_line_id ,
1450 precedence_1 ,
1451 precedence_2 ,
1452 precedence_3 ,
1453 precedence_4 ,
1454 precedence_5 ,
1455 precedence_6 ,
1456 precedence_7 ,
1457 precedence_8 ,
1458 precedence_9 ,
1459 precedence_10 ,
1460 tax_id ,
1461 tax_rate ,
1462 qty_rate ,
1463 uom ,
1464 tax_amount ,
1465 func_tax_amount ,
1466 base_tax_amount ,
1467 creation_date ,
1468 created_by ,
1469 last_update_date ,
1470 last_updated_by ,
1471 last_update_login
1472 )
1473 VALUES
1474 (so_taxes_rec.tax_line_no,
1475 ra_customer_trx_lines_s.nextval,
1476 v_customer_trx_line_id,
1477 so_taxes_rec.precedence_1,
1478 so_taxes_rec.precedence_2,
1479 so_taxes_rec.precedence_3,
1480 so_taxes_rec.precedence_4,
1481 so_taxes_rec.precedence_5,
1482 so_taxes_rec.precedence_6,
1483 so_taxes_rec.precedence_7,
1484 so_taxes_rec.precedence_8,
1485 so_taxes_rec.precedence_9,
1486 so_taxes_rec.precedence_10,
1487 so_taxes_rec.tax_id,
1488 so_taxes_rec.tax_rate,
1489 so_taxes_rec.qty_rate,
1490 so_taxes_rec.uom,
1491 so_taxes_rec.tax_amount,
1492 so_taxes_rec.base_tax_amount,
1493 so_taxes_rec.func_tax_amount,
1494 sysdate,
1495 so_taxes_rec.created_by,
1496 sysdate,
1497 so_taxes_rec.last_updated_by,
1498 so_taxes_rec.last_update_login
1499 );
1500
1501 FND_FILE.PUT_LINE(FND_FILE.LOG, ' After insert into JAI_AR_TRX_TAX_LINES');
1502
1503 v_tax_amount := NVL(v_tax_amount,0) + NVL(so_taxes_rec.tax_amount,0);
1504
1505 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax amount: '|| v_tax_amount);
1506
1507 end if; -- for 'tax type'
1508 else
1509
1510 -- handle for the case where the register code is not BOND_REG
1511 -- Date 23/02/2006 by sacsethi for bug 5228046
1512 -- precedence 6 to 10
1513 INSERT INTO JAI_AR_TRX_TAX_LINES
1514 (
1515 TAX_LINE_NO ,
1516 CUSTOMER_TRX_LINE_ID ,
1517 LINK_TO_CUST_TRX_LINE_ID ,
1518 PRECEDENCE_1 ,
1519 PRECEDENCE_2 ,
1520 PRECEDENCE_3 ,
1521 PRECEDENCE_4 ,
1522 PRECEDENCE_5 ,
1523 PRECEDENCE_6 ,
1524 PRECEDENCE_7 ,
1525 PRECEDENCE_8 ,
1526 PRECEDENCE_9 ,
1527 PRECEDENCE_10 ,
1528 TAX_ID ,
1529 TAX_RATE ,
1530 QTY_RATE ,
1531 UOM ,
1532 TAX_AMOUNT ,
1533 FUNC_TAX_AMOUNT ,
1534 BASE_TAX_AMOUNT ,
1535 CREATION_DATE ,
1536 CREATED_BY ,
1537 LAST_UPDATE_DATE ,
1538 LAST_UPDATED_BY ,
1539 LAST_UPDATE_LOGIN
1540 )
1541 values
1542 (so_taxes_rec.tax_line_no,
1543 ra_customer_trx_lines_s.nextval,
1544 v_customer_trx_line_id,
1545 so_taxes_rec.precedence_1,
1546 so_taxes_rec.precedence_2,
1547 so_taxes_rec.precedence_3,
1548 so_taxes_rec.precedence_4,
1549 so_taxes_rec.precedence_5,
1550 so_taxes_rec.precedence_6,
1551 so_taxes_rec.precedence_7,
1552 so_taxes_rec.precedence_8,
1553 so_taxes_rec.precedence_9,
1554 so_taxes_rec.precedence_10,
1555 so_taxes_rec.tax_id,
1556 so_taxes_rec.tax_rate,
1557 so_taxes_rec.qty_rate,
1558 so_taxes_rec.uom,
1559 so_taxes_rec.tax_amount,
1560 so_taxes_rec.base_tax_amount,
1561 so_taxes_rec.func_tax_amount,
1562 sysdate,
1563 so_taxes_rec.created_by,
1564 sysdate,
1565 so_taxes_rec.last_updated_by,
1566 so_taxes_rec.last_update_login
1567 );
1568 FND_FILE.PUT_LINE(FND_FILE.LOG,
1569 ' Else - After insert into JAI_AR_TRX_TAX_LINES');
1570 v_tax_amount := NVL(v_tax_amount,0) + NVL(so_taxes_rec.tax_amount,0);
1571 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Tax amount: '|| v_tax_amount);
1572
1573 end if; -- for 'BOND_REG'
1574 End Loop;
1575
1576 -- creation of item line equivalent.
1577
1578
1579 Open c_so_picking_data(v_config_line_id);
1580 fetch c_so_picking_data into v_ex_inv_no , v_pmt_reg , v_pre_prnt_ex_no , v_ar3_form_no , v_ar3_form_date;
1581 close c_so_picking_data;
1582
1583 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Excise invoice number: '|| v_ex_inv_no);
1584 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Pmt reg: ' ||v_pmt_reg);
1585 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Pre print ex. no : '|| v_pre_prnt_ex_no);
1586 FND_FILE.PUT_LINE(FND_FILE.LOG, ' AR3 form no.: '|| v_ar3_form_no);
1587 FND_FILE.PUT_LINE(FND_FILE.LOG, ' AR3 form date '||v_ar3_form_date);
1588
1589 /*added by csahoo for bug#5879769*/
1590 OPEN c_get_address_details(v_header_id);
1591 FETCH c_get_address_details into r_add;
1592 CLOSE c_get_address_details;
1593
1594 v_service_type:=get_service_type( NVL(r_add.SHIP_TO_CUSTOMER_ID ,r_add.BILL_TO_CUSTOMER_ID) ,
1595 NVL(r_add.SHIP_TO_SITE_USE_ID, r_add.BILL_TO_SITE_USE_ID),'C');
1596
1597 for so_line_rec in c_get_om_lines(v_config_line_id)
1598 Loop
1599 Insert into JAI_AR_TRX_LINES
1600 (
1601 customer_trx_line_id ,
1602 customer_trx_id ,
1603 line_number ,
1604 inventory_item_id ,
1605 description ,
1606 unit_code ,
1607 quantity ,
1608 unit_selling_price ,
1609 tax_category_id ,
1610 line_amount ,
1611 tax_amount ,
1612 total_amount ,
1613 auto_invoice_flag ,
1614 assessable_value ,
1615 creation_date ,
1616 created_by ,
1617 last_update_date ,
1618 last_updated_by ,
1619 last_update_login ,
1620 excise_exempt_type ,
1621 excise_exempt_refno ,
1622 excise_exempt_date ,
1623 excise_invoice_no ,
1624 payment_register ,
1625 preprinted_excise_inv_no ,
1626 ar3_form_no ,
1627 ar3_form_date ,
1628 vat_exemption_flag , -- added, harshita for bug#4245062
1629 vat_exemption_type ,
1630 vat_exemption_date ,
1631 vat_exemption_refno ,
1632 vat_assessable_value ,
1633 service_type_code --Added by csahoo for Bug#5879769
1634 )
1635 Values
1636 (
1637 v_customer_trx_line_id,
1638 v_header_id,
1639 pr_new.line_number,
1640 pr_new.inventory_item_id,
1641 pr_new.description,
1642 so_line_rec.unit_code,
1643 so_line_rec.quantity,
1644 so_line_rec.selling_price,
1645 so_line_rec.tax_category_id,
1646 so_line_rec.line_amount,
1647 v_tax_amount,
1648 so_line_rec.line_amount + v_tax_amount,
1649 'Y',
1650 so_line_rec.assessable_value,
1651 sysdate,
1652 so_line_rec.created_by,
1653 sysdate,
1654 so_line_rec.last_updated_by,
1655 so_line_rec.last_update_login,
1656 so_line_rec.excise_exempt_type,
1657 so_line_rec.excise_exempt_refno,
1658 so_line_rec.excise_exempt_date,
1659 v_ex_inv_no ,
1660 v_pmt_reg ,
1661 v_pre_prnt_ex_no,
1662 v_ar3_form_no ,
1663 v_ar3_form_date,
1664 so_line_rec.vat_exemption_flag, -- added, Harshita for bug#4245062
1665 so_line_rec.vat_exemption_type,
1666 so_line_rec.vat_exemption_date,
1667 so_line_rec.vat_exemption_refno,
1668 so_line_rec.vat_assessable_value,
1669 v_service_type --Added by csahoo for Bug#5879769
1670 );
1671
1672 FND_FILE.PUT_LINE(FND_FILE.LOG,' Cursor . c_get_om_lines ');
1673 FND_FILE.PUT_LINE(FND_FILE.LOG,
1674 ' Inserted jai_ar_trx_lines for TRX LINE ID: '||v_customer_trx_line_id);
1675 FND_FILE.PUT_LINE(FND_FILE.LOG,' Trx id: ' || v_header_id);
1676
1677 v_ato_line_amount := so_line_rec.line_amount;
1678 v_ato_tax_amount := NVL(v_ato_tax_amount,0) + NVL(v_tax_amount,0);
1679 v_ato_total_amount := NVL(v_ato_total_amount,0) + NVL(so_line_rec.line_amount,0) + NVL(v_ato_tax_amount,0);
1680 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Ato tax amount: '||v_ato_tax_amount);
1681 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Ato tot amount: '||v_ato_total_amount);
1682 end loop;
1683
1684
1685 -- creation of record in JAI_AR_TRXS
1686
1687 OPEN CREATED_FROM_CUR;
1688 FETCH CREATED_FROM_CUR INTO v_created_from, v_trx_number, v_batch_source_id, v_books_id,
1689 v_salesrep_id, c_from_currency_code, c_conversion_type,
1690 c_conversion_date, c_conversion_rate ;
1691 CLOSE CREATED_FROM_CUR;
1692
1693 FND_FILE.PUT_LINE(FND_FILE.LOG,' Created from: '|| v_created_from);
1694 FND_FILE.PUT_LINE(FND_FILE.LOG,' Trx number : ' ||v_trx_number);
1695 FND_FILE.PUT_LINE(FND_FILE.LOG,' Batch source id '|| v_batch_source_id);
1696 FND_FILE.PUT_LINE(FND_FILE.LOG,' SOB id : '|| v_books_id);
1697 FND_FILE.PUT_LINE(FND_FILE.LOG,' Salesrep. id '||v_salesrep_id);
1698 FND_FILE.PUT_LINE(FND_FILE.LOG,' From currency code '||c_from_currency_code);
1699 FND_FILE.PUT_LINE(FND_FILE.LOG,' conversion type: '||c_conversion_type);
1700 FND_FILE.PUT_LINE(FND_FILE.LOG,' conversion date: '||c_conversion_date);
1701 FND_FILE.PUT_LINE(FND_FILE.LOG,' conversion rate: '||c_conversion_rate);
1702
1703 OPEN SO_ATO_PICKING_HDR_INFO(v_config_line_id);
1704 Fetch SO_ATO_PICKING_HDR_INFO into v_organization_id , v_location_id;
1705 close SO_ATO_PICKING_HDR_INFO;
1706
1707 FND_FILE.PUT_LINE(FND_FILE.LOG,' Org id: '|| v_organization_id);
1708 FND_FILE.PUT_LINE(FND_FILE.LOG,' Loc id: '||v_location_id);
1709
1710 ln_legal_entity_id := get_legal_entity_id ;
1711
1712 Insert into JAI_AR_TRXS
1713 (
1714 CUSTOMER_TRX_ID ,
1715 ORGANIZATION_ID ,
1716 LOCATION_ID ,
1717 UPDATE_RG_FLAG ,
1718 ONCE_COMPLETED_FLAG ,
1719 TOTAL_AMOUNT ,
1720 LINE_AMOUNT ,
1721 TAX_AMOUNT ,
1722 TRX_NUMBER ,
1723 BATCH_SOURCE_ID ,
1724 CREATION_DATE ,
1725 CREATED_BY ,
1726 LAST_UPDATE_DATE ,
1727 LAST_UPDATED_BY ,
1728 LAST_UPDATE_LOGIN ,
1729 SET_OF_BOOKS_ID ,
1730 PRIMARY_SALESREP_ID ,
1731 INVOICE_CURRENCY_CODE ,
1732 EXCHANGE_RATE_TYPE ,
1733 EXCHANGE_DATE ,
1734 EXCHANGE_RATE ,
1735 CREATED_FROM ,
1736 UPDATE_RG23D_FLAG ,
1737 LEGAL_ENTITY_ID /* rallamse bug#4448789 */
1738 )
1739 Values
1740 (
1741 v_header_id,
1742 v_organization_id,
1743 v_location_id,
1744 'Y',
1745 'N',/*Bug 4694650 bduvarag*/
1746 v_ato_total_amount,
1747 v_ato_line_amount,
1748 v_ato_tax_amount,
1749 v_trx_number,
1750 v_batch_source_id,
1751 sysdate,
1752 uid,
1753 sysdate,
1754 uid,
1755 uid,
1756 v_books_id,
1757 v_salesrep_id,
1758 c_from_currency_code,
1759 c_conversion_type,
1760 c_conversion_date,
1761 c_conversion_rate,
1762 v_created_from,
1763 'Y',
1764 ln_legal_entity_id /* rallamse bug#4448789 */
1765 );
1766
1767 FND_FILE.PUT_LINE(FND_FILE.LOG,'After insert into JAI_AR_TRXS ');
1768 FND_FILE.PUT_LINE(FND_FILE.LOG,
1769 'End of Procedure Process_Taxes_for_ATO_Order');
1770
1771 end if; -- end if for IF NVL(pr_new.Interface_line_attribute11,'0') ='0'
1772 end if;
1773
1774
1775 End Process_Taxes_for_ATO_Order;
1776 -- Ends here additions by sriram
1777
1778 /*
1779 Start additions by ssumaith for bug# 4136981*/
1780 procedure process_bill_only_invoice is
1781 cursor c_check_hdr_exists is
1782 select 1
1783 from JAI_AR_TRXS
1784 where customer_trx_id = pr_new.customer_trx_id;
1785
1786
1787 cursor c_trx_cur is
1788 select trx_number ,
1789 batch_source_id ,
1790 set_of_books_id ,
1791 primary_salesrep_id ,
1792 invoice_currency_Code ,
1793 exchange_rate_type ,
1794 exchange_date ,
1795 exchange_rate ,
1796 created_from ,
1797 nvl(bill_to_customer_id,ship_to_customer_id) customer_id , -- Date 26-feb-2006 added by sacsethi for bug 5631784
1798 trx_date
1799 from ra_customer_trx_all
1800 where customer_trx_id = pr_new.customer_trx_id;
1801
1802 CURSOR JA_SO_LINES_INFO IS
1803 SELECT tax_category_id ,
1804 tax_amount ,
1805 assessable_value ,
1806 line_amount ,
1807 excise_exempt_type ,
1808 excise_exempt_refno ,
1809 excise_exempt_date ,
1810 vat_exemption_flag , -- added, Harshita for bug#4245062
1811 vat_exemption_type ,
1812 vat_exemption_date ,
1813 vat_exemption_refno ,
1814 vat_assessable_value,
1815 unit_code , -- Date 26-feb-2006 added by sacsethi for bug 5631784
1816 inventory_item_id , -- Date 26-feb-2006 added by sacsethi for bug 5631784
1817 quantity , -- Date 26-feb-2006 added by sacsethi for bug 5631784
1818 service_type_code -- Added by csahoo, Bug 5879769
1819 FROM JAI_OM_OE_SO_LINES
1820 WHERE line_id = TO_NUMBER(v_interface_line_attribute6);
1821
1822 cursor c_get_amounts is
1823 select sum(tax_amount) tax_amt , sum(line_amount) line_amt
1824 from JAI_AR_TRX_LINES
1825 where customer_trx_id = pr_new.customer_trx_id;
1826
1827 cursor c_default_location(CP_ORGANIZATION_ID number) is
1828 select DEFAULT_LOCATION_BILL_ONLY
1829 from JAI_CMN_INVENTORY_ORGS
1830 where organization_id = cp_organization_id
1831 and location_id = 0;
1832
1833 cursor c_oe_system_params is
1834 select master_organization_id
1835 from oe_system_parameters ;
1836
1837
1838 lr_trx_rec c_trx_cur%rowtype;
1839 ln_hdr_exists number; --File.Sql.35 Cbabu := 0;
1840 ln_line_amount number; --File.Sql.35 Cbabu :=0;
1841 ln_tax_amount number; --File.Sql.35 Cbabu :=0;
1842 rec_so_lines JA_SO_LINES_INFO%rowtype;
1843 ln_inv_orgn_id number ;
1844 ln_default_locn_id number;
1845
1846 lv_appl_src JAI_CMN_ERRORS_T.APPLICATION_SOURCE%type;
1847 lv_err_msg JAI_CMN_ERRORS_T.ERROR_MESSAGE%type;
1848 lv_addl_msg JAI_CMN_ERRORS_T.ADDITIONAL_ERROR_MESG%type;
1849
1850 ln_legal_entity_id NUMBER ; /* rallamse bug#4510143 */
1851 -- Date 26-feb-2006 added by sacsethi for bug 5631784
1852 --start 5631784
1853 ln_tcs_exists number;
1854 ln_tcs_regime_id JAI_RGM_DEFINITIONS.regime_id%type;
1855 ln_threshold_slab_id jai_ap_tds_thhold_slabs.threshold_slab_id%type;
1856 ln_last_line_no number;
1857 ln_base_line_no number;
1858 lv_process_flag VARCHAR2(2);
1859 lv_process_message VARCHAR2(1996);
1860 ln_reg_id number;
1861 cursor c_chk_rgm_tax_exists ( cp_regime_code JAI_RGM_DEFINITIONS.regime_code%type
1862 , cp_cust_trx_line_id ra_customer_trx_lines_all.customer_trx_line_id%type
1863 )
1864 is
1865 select count(1)
1866 from jai_regime_tax_types_v jrttv
1867 , JAI_AR_TRX_TAX_LINES jrctt
1868 , JAI_CMN_TAXES_ALL jtc
1869 where jtc.tax_id = jrctt.tax_id
1870 and jtc.tax_type = jrttv.tax_type
1871 and regime_code = cp_regime_code
1872 and jrctt.link_to_cust_trx_line_id = cp_cust_trx_line_id;
1873 cursor c_get_regime_id (cp_regime_code JAI_RGM_DEFINITIONS.regime_code%type)
1874 is
1875 select regime_id
1876 from JAI_RGM_DEFINITIONS
1877 where regime_code = cp_regime_code;
1878 --end 5631784
1879 /*added for bug#6498072*/
1880 Cursor get_ar_tax_amount
1881 is
1882 select sum(tax_amount)
1883 from JAI_AR_TRX_TAX_LINES
1884 Where link_to_cust_trx_line_id = v_customer_trx_line_id;
1885
1886 ln_ar_tax_amount JAI_AR_TRX_TAX_LINES.TAX_AMOUNT%type;
1887
1888 begin
1889 FND_FILE.PUT_LINE(FND_FILE.LOG,
1890 ' Inside Procedure process_bill_only_invoice');
1891
1892 ln_hdr_exists := 0;
1893 ln_line_amount :=0;
1894 ln_tax_amount :=0;
1895 /*
1896 writing code here to process a bill only invoice.
1897 Validations to handle
1898 ---------------------
1899 a) in case of discounts only one line should have taxes
1900 b) in case of bond register excise and excise cess taxes should not flow into AR
1901 c) only one record should be inserted in the JAI_AR_TRXS table.
1902 */
1903
1904 ln_hdr_exists := 0;
1905 open c_check_hdr_exists;
1906 fetch c_check_hdr_exists into ln_hdr_exists;
1907 close c_check_hdr_exists;
1908
1909 FND_FILE.PUT_LINE(FND_FILE.LOG,' Header exists '|| ln_hdr_exists);
1910
1911 if nvl(ln_hdr_exists,0) = 0 then
1912 /*
1913 no record exists in the JAI_AR_TRXS table for the customer trx id ,
1914 hence insert a record into the table.
1915 */
1916
1917 open c_trx_cur;
1918 fetch c_trx_cur into lr_trx_rec;
1919 close c_trx_cur;
1920
1921 if pr_new.warehouse_id is null then
1922 open c_oe_system_params;
1923 fetch c_oe_system_params into ln_inv_orgn_id;
1924 close c_oe_system_params;
1925 else
1926 ln_inv_orgn_id := pr_new.warehouse_id ;
1927 end if;
1928
1929 FND_FILE.PUT_LINE(FND_FILE.LOG,' Inv orgn id: '|| ln_inv_orgn_id);
1930
1931 open c_default_location(ln_inv_orgn_id);
1932 fetch c_default_location into ln_default_locn_id;
1933 close c_default_location;
1934
1935 FND_FILE.PUT_LINE(FND_FILE.LOG,' Default location id '|| ln_default_locn_id);
1936
1937 if ln_default_locn_id is null then
1938
1939 /*
1940 if the default location setup is not done , log this as a message in the JAI_CMN_ERRORS_T table
1941 do not stop the processing.
1942 We could still update the organization and location id in the JAI_AR_TRXS table later on (as a datafix)
1943 */
1944 lv_appl_src := 'JA_IN_OE_AR_LINES_INSERT_TRG' ;
1945 lv_err_msg := 'Default Location is not setup for Inventory Organization ' || pr_new.warehouse_id ;
1946 lv_addl_msg := 'Please setup the Default Location in Organization Additional Information Screen for Trx id : ' || pr_new.customer_trx_id ;
1947
1948 insert into JAI_CMN_ERRORS_T
1949 (
1950 APPLICATION_SOURCE ,
1951 ERROR_MESSAGE ,
1952 ADDITIONAL_ERROR_MESG ,
1953 CREATION_DATE ,
1954 CREATED_BY ,
1955 -- added, Harshita for Bug 4866533
1956 LAST_UPDATED_BY,
1957 LAST_UPDATE_DATE
1958 )
1959 values
1960 (
1961 lv_appl_src, /*'JA_IN_OE_AR_LINES_INSERT_TRG', Ramananda for removal of SQL LITERALs */
1962 lv_err_msg, /* 'Default Location is not setup for Inventory Organization ' || pr_new.warehouse_id , */
1963 lv_addl_msg, /* 'Please setup the Default Location in Organization Additional Information Screen for Trx id : ' || pr_new.customer_trx_id , */
1964 sysdate,
1965 fnd_global.user_id ,
1966 -- added, Harshita for Bug 4866533
1967 fnd_global.user_id,
1968 sysdate
1969 );
1970 end if;
1971
1972 ln_legal_entity_id := get_legal_entity_id ;
1973
1974 insert into JAI_AR_TRXS -- bill only invoice
1975 (
1976 CUSTOMER_TRX_ID ,
1977 ORGANIZATION_ID ,
1978 LOCATION_ID ,
1979 UPDATE_RG_FLAG ,
1980 ONCE_COMPLETED_FLAG ,
1981 TOTAL_AMOUNT ,
1982 LINE_AMOUNT ,
1983 TAX_AMOUNT ,
1984 TRX_NUMBER ,
1985 BATCH_SOURCE_ID ,
1986 CREATION_DATE ,
1987 CREATED_BY ,
1988 LAST_UPDATE_DATE ,
1989 LAST_UPDATED_BY ,
1990 LAST_UPDATE_LOGIN ,
1991 SET_OF_BOOKS_ID ,
1992 PRIMARY_SALESREP_ID ,
1993 INVOICE_CURRENCY_CODE ,
1994 EXCHANGE_RATE_TYPE ,
1995 EXCHANGE_DATE ,
1996 EXCHANGE_RATE ,
1997 CREATED_FROM ,
1998 UPDATE_RG23D_FLAG ,
1999 TAX_INVOICE_NO ,
2000 LEGAL_ENTITY_ID /* rallamse bug#4448789 */
2001 )
2002 values
2003 (
2004 pr_new.customer_trx_id ,
2005 ln_inv_orgn_id ,
2006 ln_default_locn_id ,
2007 'N' ,
2008 'N' ,/*Bug 4694650 bduvarag*/
2009 0 ,
2010 0 ,
2011 0 ,
2012 lr_trx_rec.trx_number ,
2013 lr_trx_rec.batch_source_id ,
2014 sysdate ,
2015 fnd_global.user_id ,
2016 sysdate ,
2017 fnd_global.user_id ,
2018 fnd_global.login_id ,
2019 lr_trx_rec.set_of_books_id ,
2020 lr_trx_rec.primary_salesrep_id ,
2021 lr_trx_rec.invoice_currency_code ,
2022 lr_trx_rec.exchange_rate_type ,
2023 lr_trx_rec.exchange_date ,
2024 lr_trx_rec.exchange_rate ,
2025 lr_trx_rec.created_from ,
2026 'N' ,
2027 NULL ,
2028 ln_legal_entity_id /* rallamse bug#4448789 */
2029 );
2030
2031 FND_FILE.PUT_LINE(FND_FILE.LOG,
2032 ' After insert into JAI_AR_TRXS - Bill only invoice');
2033 end if;
2034
2035 /*
2036 insert into the JAI_AR_TRX_TAX_LINES table and then insert into the JAI_AR_TRX_LINES table.
2037 pr_new.interface_line_attribute6 = order_line_id
2038 pr_new.interface_line_context = 'ORDER ENTRY'
2039 */
2040
2041 open c_ont_source_code;
2042 fetch c_ont_source_code into v_ont_source_code;
2043 close c_ont_source_code;
2044 FND_FILE.PUT_LINE(FND_FILE.LOG,' Ont source code: '|| v_ont_source_code);
2045
2046 v_ont_source_code := ltrim(rtrim(v_ont_source_code));
2047
2048 FND_FILE.PUT_LINE(FND_FILE.LOG,
2049 ' Ont source code- after trunc: '|| v_ont_source_code);
2050
2051 /*
2052 return if it is discount line
2053 */
2054 if nvl(pr_new.interface_line_attribute11,'0') <> '0' then
2055 FND_FILE.PUT_LINE(FND_FILE.LOG,
2056 ' Int. line att1: '||pr_new.interface_line_attribute11);
2057 return;
2058 end if;
2059
2060 for tax_rec in JA_SO_TAX_LINES_INFO
2061 Loop
2062 FND_FILE.PUT_LINE(FND_FILE.LOG,' cursor ja_so_tax_lines_info');
2063 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax type '|| tax_rec.tax_type);
2064
2065 if v_register_code = 'BOND_REG' then
2066 FND_FILE.PUT_LINE(FND_FILE.LOG,' Register code '|| v_register_code);
2067 if upper(tax_rec.tax_type) not in ('EXCISE','OTHER EXCISE','CVD_EDUCATION_CESS','EXCISE_EDUCATION_CESS', jai_constants.tax_type_sh_cvd_edu_cess, jai_constants.tax_type_sh_exc_edu_cess) then
2068 /* 'CVD_EDUCATION_CESS','EXCISE_EDUCATION_CESS' added by ssumaith - bug# 4136981*/
2069 /*jai_constants.tax_type_sh_exc_edu_cess, jai_constants.tax_type_sh_cvd_edu_cess added by CSahoo BUG#5989740*/
2070 /*
2071 This is not a discount line , so taxes can flow. In case it was discount , control would have never come here
2072 because of the return statement above.
2073 */
2074 /* Date 23/02/2006 by sacsethi for bug 5228046
2075 precedence 6 to 10 */
2076 INSERT INTO JAI_AR_TRX_TAX_LINES
2077 (
2078 tax_line_no ,
2079 customer_trx_line_id ,
2080 link_to_cust_trx_line_id ,
2081 precedence_1 ,
2082 precedence_2 ,
2083 precedence_3 ,
2084 precedence_4 ,
2085 precedence_5 ,
2086 precedence_6 ,
2087 precedence_7 ,
2088 precedence_8 ,
2089 precedence_9 ,
2090 precedence_10 ,
2091 tax_id ,
2092 tax_rate ,
2093 qty_rate ,
2094 uom ,
2095 tax_amount ,
2096 func_tax_amount ,
2097 base_tax_amount ,
2098 creation_date ,
2099 created_by ,
2100 last_update_date ,
2101 last_updated_by ,
2102 last_update_login
2103 )
2104 VALUES
2105 (
2106 tax_rec.tax_line_no ,
2107 ra_customer_trx_lines_s.nextval ,
2108 v_customer_trx_line_id ,
2109 tax_rec.precedence_1 ,
2110 tax_rec.precedence_2 ,
2111 tax_rec.precedence_3 ,
2112 tax_rec.precedence_4 ,
2113 tax_rec.precedence_5 ,
2114 tax_rec.precedence_6 ,
2115 tax_rec.precedence_7 ,
2116 tax_rec.precedence_8 ,
2117 tax_rec.precedence_9 ,
2118 tax_rec.precedence_10 ,
2119 tax_rec.tax_id ,
2120 tax_rec.tax_rate ,
2121 tax_rec.qty_rate ,
2122 tax_rec.uom ,
2123 round(tax_rec.tax_amount,2) ,
2124 round(tax_rec.func_tax_amount,2) ,
2125 round(tax_rec.base_tax_amount,2) ,
2126 sysdate ,
2127 fnd_global.user_id ,
2128 sysdate ,
2129 fnd_global.user_id ,
2130 fnd_global.login_id
2131 );
2132 end if; /* end if for tax type not in excise .... */
2133 else /* register association is not bond register , so all taxes can flow */
2134 /* Date 23/02/2006 by sacsethi for bug 5228046
2135 precedence 6 to 10 */
2136 INSERT INTO JAI_AR_TRX_TAX_LINES
2137 (
2138 tax_line_no ,
2139 customer_trx_line_id ,
2140 link_to_cust_trx_line_id ,
2141 precedence_1 ,
2142 precedence_2 ,
2143 precedence_3 ,
2144 precedence_4 ,
2145 precedence_5 ,
2146 precedence_6 ,
2147 precedence_7 ,
2148 precedence_8 ,
2149 precedence_9 ,
2150 precedence_10 ,
2151 tax_id ,
2152 tax_rate ,
2153 qty_rate ,
2154 uom ,
2155 tax_amount ,
2156 func_tax_amount ,
2157 base_tax_amount ,
2158 creation_date ,
2159 created_by ,
2160 last_update_date ,
2161 last_updated_by ,
2162 last_update_login
2163 )
2164 VALUES
2165 (
2166 tax_rec.tax_line_no ,
2167 ra_customer_trx_lines_s.nextval ,
2168 v_customer_trx_line_id ,
2169 tax_rec.precedence_1 ,
2170 tax_rec.precedence_2 ,
2171 tax_rec.precedence_3 ,
2172 tax_rec.precedence_4 ,
2173 tax_rec.precedence_5 ,
2174 tax_rec.precedence_6 ,
2175 tax_rec.precedence_7 ,
2176 tax_rec.precedence_8 ,
2177 tax_rec.precedence_9 ,
2178 tax_rec.precedence_10 ,
2179 tax_rec.tax_id ,
2180 tax_rec.tax_rate ,
2181 tax_rec.qty_rate ,
2182 tax_rec.uom ,
2183 round(tax_rec.tax_amount,2) ,
2184 round(tax_rec.func_tax_amount,2) ,
2185 round(tax_rec.base_tax_amount,2) ,
2186 sysdate ,
2187 fnd_global.user_id ,
2188 sysdate ,
2189 fnd_global.user_id ,
2190 fnd_global.login_id
2191 );
2192
2193 end if;
2194 end loop;
2195
2196
2197 open JA_SO_LINES_INFO;
2198 fetch JA_SO_LINES_INFO into rec_so_lines;
2199 close JA_SO_LINES_INFO;
2200
2201 --end 5631784
2202 ln_tcs_exists := null;
2203 open c_chk_rgm_tax_exists ( cp_regime_code => jai_constants.tcs_regime
2204 , cp_cust_trx_line_id => v_customer_trx_line_id
2205 );
2206 fetch c_chk_rgm_tax_exists into ln_tcs_exists;
2207 close c_chk_rgm_tax_exists ;
2208 -- if ln_tcs_exists is not null then/*Bug 5684363 bduvarag*/
2209 if ln_tcs_exists > 0 then
2210 /* TCS type of tax is present */
2211 open c_get_regime_id (cp_regime_code => jai_constants.tcs_regime);
2212 fetch c_get_regime_id into ln_tcs_regime_id;
2213 close c_get_regime_id;
2214 /* Find out what is the current slab */
2215 jai_rgm_thhold_proc_pkg.get_threshold_slab_id
2216 (
2217 p_regime_id => ln_tcs_regime_id
2218 , p_organization_id => ln_inv_orgn_id
2219 , p_party_type => jai_constants.party_type_customer
2220 , p_party_id => lr_trx_rec.customer_id
2221 , p_org_id => v_org_id
2222 , p_source_trx_date => lr_trx_rec.trx_date
2223 , p_threshold_slab_id => ln_threshold_slab_id
2224 , p_process_flag => lv_process_flag
2225 , p_process_message => lv_process_message
2226 );
2227
2228 if lv_process_flag <> jai_constants.successful then
2229 app_exception.raise_exception
2230 (exception_type => 'APP'
2231 ,exception_code => -20275
2232 ,exception_text => lv_process_message
2233 );
2234 end if;
2235 if ln_threshold_slab_id is not null then
2236 /* Threshold level is up. Surcharge needs to be defaulted , so find out the tax category based on the threshold slab */
2237 jai_rgm_thhold_proc_pkg.get_threshold_tax_cat_id
2238 (
2239 p_threshold_slab_id => ln_threshold_slab_id
2240 , p_org_id => v_org_id
2241 , p_threshold_tax_cat_id => ln_threshold_tax_cat_id
2242 , p_process_flag => lv_process_flag
2243 , p_process_message => lv_process_message
2244 );
2245 if lv_process_flag <> jai_constants.successful then
2246 app_exception.raise_exception
2247 (exception_type => 'APP'
2248 ,exception_code => -20275
2249 ,exception_text => lv_process_message
2250 );
2251 end if;
2252 /* Get line number after which threshold taxes needs to be defaulted */
2253 select max(tax_line_no)
2254 into ln_last_line_no
2255 from JAI_AR_TRX_TAX_LINES
2256 where link_to_cust_trx_line_id = v_customer_trx_line_id;
2257 /* Get line number of the base tax (tax_type=TCS) for calculating the surcharge basically to set a precedence */
2258 select max(tax_line_no)
2259 into ln_base_line_no
2260 from JAI_AR_TRX_TAX_LINES jrctt
2261 , JAI_CMN_TAXES_ALL jtc
2262 where jrctt.link_to_cust_trx_line_id = v_customer_trx_line_id
2263 and jrctt.tax_id = jtc.tax_id
2264 and jtc.tax_type = jai_constants.tax_type_tcs;
2265 /*
2266 ||Call the helper method to default surcharge taxes on top of the SO taxes using the tax category
2267 || The api jai_rgm_thhold_proc_pkg.default_thhold_taxes inserts lines as per the same specified in the TCS tax category
2268 || into the ja_in_so_picking_tax_lines table
2269 */
2270 jai_rgm_thhold_proc_pkg.default_thhold_taxes
2271 (
2272 p_source_trx_id => ''
2273 , p_source_trx_line_id => v_customer_trx_line_id
2274 , p_source_event => jai_constants.bill_only_invoice
2275 , p_action => jai_constants.default_taxes
2276 , p_threshold_tax_cat_id => ln_threshold_tax_cat_id
2277 , p_tax_base_line_number => ln_base_line_no
2278 , p_last_line_number => ln_last_line_no
2279 , p_currency_code => lr_trx_rec.invoice_currency_code
2280 , p_currency_conv_rate => lr_trx_rec.exchange_rate
2281 , p_quantity => nvl(rec_so_lines.quantity,0)
2282 , p_base_tax_amt => nvl(rec_so_lines.line_amount,0)
2283 , p_assessable_value => rec_so_lines.assessable_value * rec_so_lines.quantity --ADDED rec_so_lines.quantity FOR BUG#6498072
2284 , p_inventory_item_id => rec_so_lines.inventory_item_id
2285 , p_uom_code => rec_so_lines.unit_code
2286 , p_vat_assessable_value => rec_so_lines.vat_assessable_value
2287 , p_process_flag => lv_process_flag
2288 , p_process_message => lv_process_message
2289 );
2290
2291 if lv_process_flag <> jai_constants.successful then
2292 app_exception.raise_exception
2293 (exception_type => 'APP'
2294 ,exception_code => -20275
2295 ,exception_text => lv_process_message
2296 );
2297 end if;
2298 end if; /* ln_threshold_slab_id is not null then */
2299 end if; /** ln_tcs_exists is not null then */
2300
2301 /*added by csahoo for bug#6498072, start*/
2302
2303 open get_ar_tax_amount;
2304 FETCH get_ar_tax_amount INTO ln_ar_tax_amount;
2305 CLOSE get_ar_tax_amount;
2306 /*added by csahoo for bug#6498072, end*/
2307
2308 /*moved the following code here for bug# 6498072*/
2309
2310 INSERT INTO JAI_AR_TRX_LINES (
2311 customer_trx_line_id ,
2312 line_number ,
2313 customer_trx_id ,
2314 description ,
2315 payment_register ,
2316 excise_invoice_no ,
2317 preprinted_excise_inv_no ,
2318 excise_invoice_date ,
2319 inventory_item_id ,
2320 unit_code ,
2321 quantity ,
2322 tax_category_id ,
2323 auto_invoice_flag ,
2324 unit_selling_price ,
2325 line_amount ,
2326 tax_amount ,
2327 total_amount ,
2328 assessable_value ,
2329 creation_date ,
2330 created_by ,
2331 last_update_date ,
2332 last_updated_by ,
2333 last_update_login ,
2334 excise_exempt_type ,
2335 excise_exempt_refno ,
2336 excise_exempt_date ,
2337 ar3_form_no ,
2338 ar3_form_date ,
2339 vat_exemption_flag , -- added, Harshita for bug#4245062
2340 vat_exemption_type ,
2341 vat_exemption_date ,
2342 vat_exemption_refno ,
2343 vat_assessable_value ,
2344 service_type_code --Added by csahoo for Bug#5879769
2345 )
2346 VALUES (
2347 pr_new.customer_trx_line_id ,
2348 pr_new.line_number ,
2349 pr_new.customer_trx_id ,
2350 pr_new.description ,
2351 NULL ,
2352 NULL ,
2353 NULL ,
2354 NULL ,
2355 pr_new.inventory_item_id ,
2356 pr_new.uom_code ,
2357 pr_new.quantity_invoiced ,
2358 rec_so_lines.tax_category_id ,
2359 'Y' ,
2360 pr_new.unit_selling_price ,
2361 round(nvl(rec_so_lines.line_amount,0),2) ,
2362 round(nvl(ln_ar_tax_amount,0),2) ,
2363 round(nvl(rec_so_lines.line_amount,0) +
2364 nvl(ln_ar_tax_amount,0),2) ,
2365 rec_so_lines.assessable_value ,
2366 sysdate ,
2367 fnd_global.user_id ,
2368 sysdate ,
2369 fnd_global.user_id ,
2370 fnd_global.login_id ,
2371 rec_so_lines.excise_exempt_type ,
2372 rec_so_lines.excise_exempt_refno ,
2373 rec_so_lines.excise_exempt_date ,
2374 NULL ,
2375 NULL ,
2376 rec_so_lines.vat_exemption_flag , -- added, Harshita for bug#4245062
2377 rec_so_lines.vat_exemption_type ,
2378 rec_so_lines.vat_exemption_date ,
2379 rec_so_lines.vat_exemption_refno ,
2380 rec_so_lines.vat_assessable_value ,
2381 rec_so_lines.service_type_code --Added by csahoo for Bug#5879769
2382 );
2383
2384 open c_get_amounts;
2385 fetch c_get_amounts into ln_tax_amount, ln_line_amount ;
2386 close c_get_amounts;
2387
2388 FND_FILE.PUT_LINE(FND_FILE.LOG,' Cursor c_get_amounts');
2389 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax amount '|| ln_tax_amount);
2390 FND_FILE.PUT_LINE(FND_FILE.LOG,' Line amount '|| ln_line_amount);
2391
2392 update JAI_AR_TRXS
2393 set tax_amount = ln_tax_amount ,
2394 line_amount = ln_line_amount,
2395 total_amount = ln_line_amount + ln_tax_amount
2396 where customer_trx_id = pr_new.customer_trx_id;
2397 /*bug# 6498072, end*/
2398 /*
2399 -- End of bug 4742259
2400 */
2401 jai_ar_tcs_rep_pkg.ar_accounting
2402 ( p_ractl => pr_new
2403 , p_process_flag => lv_process_flag
2404 , p_process_message => lv_process_message
2405 );
2406 if lv_process_flag <> jai_constants.successful then
2407 app_exception.raise_exception
2408 (exception_type => 'APP'
2409 ,exception_code => -20275
2410 ,exception_text => lv_process_message
2411 );
2412 end if;
2413 end ;
2414 BEGIN
2415 pv_return_code := jai_constants.successful ;
2416 /*---------------------------------------------------------------------------------------------
2417 FILENAME: JA_IN_OE_AR_LINES_INSERT_TRG.sql CHANGE HISTORY:
2418 S.No Date Author and Details
2419 ---------------------------------------------------------------------------------------------
2420 1. 12/02/01 MANOHAR MISHRA
2421 Removed the Duplicate_hdr_cur from the commented zone.
2422 2. 2001/04/11 JAGDISH BHOSLE
2423 Added Bond register checking to avoid Excise duty to hit
2424 Accounting entries.
2425 3. 2001/04/20 Anuradha Parthasarathy
2426 Enhancement for RG entries for Supplementary Transactions.
2427 4. 2001/05/03 Gadde,Jagdish
2428 Check added to avoid firing of trigger for Non_Indian OU.
2429 5. 2001/06/05 Anuradha Parthasarathy
2430 Cursor added to take care of correct tax insertions
2431 into JAI_AR_TRX_TAX_LINES
2432 6. 2001/09/13 Vijay
2433 Added condition of interface_line_context to return
2434 for Project Accounting
2435 7. 2001/11/01 Anuradha Parthasarathy
2436 Condition added to ensure that Modvat Recovery types of Taxes
2437 should not be charged to the customer.
2438 8. 2002/04/17 RPK
2439 for BUG# 2327261.
2440 Code modified to prevent the erroring out of the autoinvoice import program
2441 when the manual delivery is made and when the delivery name is alphanumeric.
2442 When the order created is assigned to this delivery and the ship confimation is
2443 done ,then the autoinvoice import program is running into error because the
2444 the validation is failing for delivery_id and interface_line_attribute3
2445 9. 2002/04/22 SRIRAM For Bug # 2316589 . The JAI_AR_TRXS table was updated with
2446 wrong values . Instead a new update has been written using a different value to
2447 update tax amounts correctly.
2448 10 2002/06/26 SRIRAM For Bug # 2398198 . Tax Lines were inserted multiple times in the
2449 JAI_AR_TRX_TAX_LINES , JAI_AR_TRX_LINES tables when discounts
2450 exist and tax amounts were updated doubly in JAI_AR_TRXS table, which have been
2451 solved in this bug.
2452 11. 2002/08/17 SRIRAM .Fopr Bug # 2518534 . When there is a change in UOM in the
2453 Sales order screen , the taxes in the localization screen are not
2454 flowing correctly.
2455 12. 2002/11/19 SRIRAM - Bug # 2668342. Performance issue reported when using the
2456 org_organization_definitions table using nvl(operating_unit) in the where
2457 clause. This is causing couple of full table scans which was a performance
2458 bottle neck.A new cursor definition has been written which uses the
2459 HR_OPERATING_UNITS table and this is performance optimized.
2460 Organization_id column is the operating_unit in the table.
2461
2462 13. 2003/01/09 Sriram - Bug # 2742849 - Version is 615.3
2463 This problem is about tax lines being inserted for discount line also.
2464 The earlier fix assumed that the discount line follows the item line by line number,
2465 that is they are consecutive lines. But this assumption is not correct and it depends on setup.
2466
2467 Found out from base apps team that interface_line_attribute11 can be used to identify a discount line from the item line.
2468 For a Invoice line imported from OM , the interface_line_attribute11 will have a value 0 or Null ,
2469 whereas for a discount line , the interface_line_attribute11 will have a value which maps to the price_adjustment_id.
2470
2471 13. 2003/02/07 Vijay Shankar - Bug # 2779990 - Version is 615.4
2472 When bond transaction invoice is created, then tax_amounts populated in JAI_AR_TRXS and JAI_AR_TRX_LINES is wrong.
2473 this is rectified by writing a new cursor name c_tax_amount
2474
2475 14. 2003/03/17 Sriram LMW ATO Issue - Bug #2806274 Version 615.5
2476 Created an internal procedure Process_Taxes_for_ATO_Order to pull taxes from OM to Ar for ATO Orders.
2477 The idea was to import the taxes for the 'Model' Item based on the config item.
2478
2479 15. 2003/06/26 Sriram - Bug # 3000550 version 616.1
2480 Tax amounts were not calculated correctly , in the JAI_AR_TRXS and JAI_AR_TRX_LINES
2481 table.This was observed when there was a split done during shipment.
2482 Data was correct in the JAI_AR_TRX_TAX_LINES table , but incorrect in the JAI_AR_TRX_LINES
2483 and JAI_AR_TRXS table.
2484 This has been fixed in this bug
2485
2486 16. 2003/08/22 Sriram - Bug # 3021588 version 616.2
2487
2488 For Multiple Bond Register Enhancement,
2489 Instead of using the cursors for fetching the register associated with the invoice type , a call has been made to the procedures
2490 of the jai_cmn_bond_register_pkg package. There enhancement has created dependency because of the
2491 introduction of 3 new columns in the JAI_OM_OE_BOND_REG_HDRS table and also call to the new package jai_cmn_bond_register_pkg.
2492
2493 This fix has introduced huge dependency . All future changes in this object should have this bug as a prereq
2494
2495
2496 17 2003/09/16 SSUMAITH - Bug # 3134224 Version 616.3
2497 For a Supplementary invoice , if if the ST form Type is NULL , entries are going into the ST forms Tracking tables.
2498 This is causing the unique constraint violation error. This has been resolved by making a change to ensure that
2499 entries in the ST forms table needs to go only if the St form Type is not null and tax type is 'Sales Tax' or 'CST'.
2500
2501 18 2003/10/10 Vijay shankar - Bug # 3181892, Version 616.4
2502 AR3 form number and date values are not populated into JAI_AR_TRX_LINES table which is resolved with this fix
2503
2504 19 2003/12/30 Aiyer - Bug #3328871, Version 618.1
2505
2506 Issue: -
2507 Create an order such that it does not have any associated taxes.
2508 Ship this order and run the auto invoice program.
2509 It is found that no records are inserted in the table JAI_AR_TRX_LINES.
2510
2511 Solution: -
2512 This was happening because the code was assuming that a line cannot exist without any taxes.
2513 So in such a case the control was made to return back without inserting a line in JAI_AR_TRX_LINES
2514 table.
2515
2516 Fix Details:-
2517 Added a if clause in the code. Placed the return statement between the if clause.
2518 So the modified functionality is that is a line does not have any taxes in shpiing tables and also does not have
2519 any taxes in JAI_OM_OE_SO_TAXES table then check whether a line exists in JAI_OM_OE_SO_LINES table only.
2520 IF yes then do not retunr, if not found then return.
2521 Also added a nvl clause in the cursor c_cust_trx_tax_line_amt. so that a value of zero would be returned
2522 even if the where clause failed to fetch a record.
2523 This would take care that tax amount would be inserted as 0 and total amount would also be computed properly
2524 in table JAI_AR_TRX_LINES.
2525 This issue was reported thorugh the bug 3344492.
2526 Also indented the whole code and added additional comments wereever necessary.
2527 Removed the commented code wherever applicable.
2528
2529 Dependency Introduced Due To This Bug:-
2530 None
2531 20 2004/02/16 RBASKER - Bug 3357587, Version 618.2
2532 When SO UOM is different from that of the primary UOM,
2533 JAI_AR_TRX_LINES is updated with wrong assessable value
2534 Added a cursor C_JA_SO_LINES_ASSESSABLE_VAL to fetch the correct assessable_value
2535 from JAI_OM_OE_SO_LINES instead of JAI_OM_WSH_LINES_ALL table.
2536
2537 21. 2004/05/05 ssumaith - bug# 3607101 - Version 619.1
2538 When autoinvoice import program imports an invoice from customer software and if interface_line_attribute11
2539 field in the ra_customer_trx_lines_all table is not null then , localization taxes are not retreived
2540 into the AR invoice.
2541 This issue has been resolved by adding a context based check that interface_line_attribute11 field cannot be
2542 null for Order Entry as the source of the invoice for taxes to be imported , and other wise if the context is not
2543 Order Entry then the localisation taxes will be populated into the Invoice from shipment.
2544
2545 22. 2004/04/16 ssumaith - bug# 3532716 Version - 115.1
2546
2547 The variable v_tax_count was not re-initialised to zero , as a result code flow is not entering into an if condition
2548 because of the static value of 1 it has initially and hence all taxes are not flowing into the AR invoice.
2549
2550 23. 2004/11/03 Vijay Shankar for Bug# 3985561 (Porting of Bug#3651923), Version: 115.2
2551 commented a delete statement on JAI_AR_TRX_INS_LINES_T table which is redundant and causing deadlock problems
2552 This DELETE statement is executed in Concurrent process where in taxes are defaulted from OM to AR
2553 * HIGH DEPENDENCY for future bugs *
2554
2555 24. 29-nov-2004 ssumaith - bug# 4037690 - File version 115.4
2556 Check whether india localization is being used was done using a INR check in every trigger.
2557 This check has now been moved into a new package and calls made to this package from this trigger
2558 If the function jai_cmn_utils_pkg.check_jai_exists returns true it means INR is the set of books currency ,
2559 Hence if this function returns FALSE , control should return.
2560
2561 25. 06-JAn-2005 ssumaith - bug#4136981 File version 115.5
2562
2563 In case of Bond Register Setup , in addition to Excise, the Education Cess taxes should also not flow to
2564 Receivables Localization tables.
2565 This check has been done in the code at two places.
2566
2567 Also added code for ensuring that taxes flow into ar in case of bill only workflow scenario
2568
2569 This fix does not introduce dependency on this object , but this patch cannot be sent alone to the CT
2570 because it relies on the alter done and the new tables created as part of the education cess enhancement
2571 bug# 4146708 creates the objects
2572
2573 26. 17-Mar-2005 hjujjuru - bug #4245062 File version 115.6
2574 The columns vat_exemption_flag, vat_exemption_type, vat_exemption_date, vat_exemption_refno,
2575 and vat_assessable_value have been added in JAI_OM_OE_SO_LINES, JAI_OM_WSH_LINES_ALL
2576 and JAI_AR_TRX_LINES.
2577 Additional fields vat_invoice_no and vat_invoice_date have been added into JAI_OM_WSH_LINES_ALL
2578 and JAI_AR_TRXS.
2579 The trigger has been updated to ensure that any data flowing into JAI_AR_TRX_LINES and
2580 JAI_AR_TRXS also includes the Vat information that comes down from either JAI_OM_OE_SO_LINES
2581 or JAI_OM_WSH_LINES_ALL .
2582
2583 Base bug - #4245089
2584
2585 Trigger file name is renamed to JAI_AR_RCTLA_T7.SQL
2586 ---------------------------------------------------
2587 27. 25-MAY-2005 BRATHOD, Bug# 4392001, File Version 116.1
2588 Issue:-
2589 RA_INTERFACE_LINES DFF segments needs to be limited use only one segment
2590 Fix:-
2591 - Following four segments will be obsoleted
2592 1. SUPPLEMENT CM
2593 2. SUPPLEMENT DM
2594 3. SUPPLEMENT INVOICE
2595 4. TDS CREDIT
2596 - A new segment (INDIA INVOICES) will be created with following attributes
2597 1. INTERFACE_LINE_ATTRIBUTE1 - Invoice Type
2598 2. INTERFACE_LINE_ATTRIBUTE2 - Unique Identifier
2599 - As new dff uses the ATTRIBUTE1 field the existing values of ATTRIBUTE1 will be
2600 migrated to ATTRIBUTE4
2601 - Attribute context will be changed to INDIA INVOICES.
2602 - INTERFACE_LINE_ATTRIBUTE1 will identify the type of invoice the possible values
2603 for this field will be same as different segments used previously
2604 i.e SUPPLEMENT CM, SUPPLEMENT DM, SUPPLEMENT INVOICE, TDS CREDIT
2605
2606 28 08-Jun-2005 This Object is Modified to refer to New DB Entity names in place of Old
2607 DB Entity as required for CASE COMPLAINCE. Version 116.2
2608
2609 29 10-Jun-2005 File Version: 116.3
2610 Removal of SQL LITERALs is done
2611
2612 30 10-Jun-2005 rallamse bug#4448789 116.3
2613 Added legal_entity_id for table JAI_AR_TRXS in insert statement
2614
2615 06-Jul-2005 Ramananda for bug#4477004. File Version: 116.4
2616 GL Sources and GL Categories got changed. Refer bug for the details
2617
2618 31 14-Jul-2005 rchandan for bug#4487676. File Version: 117.2
2619 JAI_CMN_RG_23AC_I_TXNS_S is replaced by JAI_CMN_RG_23AC_I_TRXS_S
2620
2621 32 26-Jul-2005 rallamse for bug#4510143 File Version 120.2
2622 Changed the legal_entity_id to get from function get_legal_entity_id.
2623 Replaced legal_entity_id with ln_legal_entity_id( holds value of get_legal_entity_id )
2624 for table JAI_AR_TRXS in insert statement.
2625
2626 33. 24-Aug-2005 Ramananda for bug #4567935 (115 bug 4404898). File version 120.2
2627 Issue:-
2628 1. Trigger currently processes invoices with interface line context as LEGACY.This needs to be stopped
2629
2630 Fix:-
2631 1. Added the check to RETURN from the trigger if interface line context in ( 'LEGACY','PROJECTS INVOICES','OKS CONTRACTS')
2632 also did forward porting for the bugs 4395450,4426613.
2633
2634 Dependency due to this bug :-
2635 Functional dependency with jai_ar_rctla_ari_t8 trigger of jai_fin_t.sql (120.2)
2636
2637 34. 28-Jun-2007 CSahoo for bug#6155839, File Version 120.16
2638 replaced RG Register Data Entry by jai_constants.je_category_rg_entry
2639 35. 16-oCT-2007 CSahoo for bug#6498072, File Version 120.21
2640 Multipled p_quantity to the assesible value in the call to the procedure jai_rgm_thhold_proc_pkg.default_thhold_taxes
2641
2642 36. 18-OCT-2007 CSahoo for bug#6498072, File Version 120.22
2643 Added the cursor get_ar_tax_amount to get the total tax amount from JAI_AR_TRX_TAX_LINES table.
2644 Moved the code for Inserting into JAI_AR_TRX_LINES and updating the table JAI_AR_TRXS to the end in the procedure
2645 process_bill_only_invoice
2646
2647 37 11-Nov-2008 JMEENA for bug#6498345( FP 6492966 )
2648 Issue: AR Autoinvoice completes in Error: ORA-20130: ORGANIZATION CANNOT BE NULL
2649 Reason: OPTION items in the sales order have taxes attached (Excise + VAT) with zero tax amounts.
2650 For OPTION item, derivation of organization and location is not present in the code
2651 as the taxes are not expected to be in the option item.
2652 As the it has vat taxes, it checks for organization id and AI errors out.
2653 Fix: Added logic to extract organization and location for OPTION items
2654
2655 Future Dependencies For the release Of this Object:-
2656 (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/
2657 A datamodel change )
2658
2659 ----------------------------------------------------------------------------------------------------------------------------------------------------
2660 Current Version Current Bug Dependent Files Version Author Date Remarks
2661 Of File On Bug/Patchset Dependent On
2662 ja_in_oe_ar_lines_insert_trg.sql
2663 ----------------------------------------------------------------------------------------------------------------------------------------------------
2664 616.2 3021588 IN60104D1 + ssumaith 22/08/2003 Bond Register Enhancement
2665 2801751 +
2666 2769440
2667
2668 115.4 4037690 IN60105D2 ja_in_util_pkg_s.sql 115.0 ssumaith 29-Nov-2004 Call to this function.
2669 ja_in_util_pkg_s.sql 115.0 ssumaith
2670
2671 115.6 4245062 IN60106 + 4245089 hjujjuru 17/03/2005 VAT Implelentation
2672
2673 ----------------------------------------------------------------------------------------------------------------------------------------------------
2674
2675 ----------------------------------------------------------------------------------------------*/
2676
2677 /* --Ramananda for File.Sql.35, start */
2678 v_org_id :=pr_new.org_id;
2679 v_last_update_date := pr_new.last_update_date;
2680 v_last_updated_by := pr_new.last_updated_by;
2681 v_creation_date := pr_new.creation_date;
2682 v_created_by := pr_new.created_by;
2683 v_last_update_login := pr_new.last_update_login;
2684 v_customer_trx_line_id := pr_new.customer_trx_line_id;
2685 v_header_id := pr_new.customer_trx_id;
2686 v_line_amount := nvl(pr_new.quantity_invoiced * pr_new.unit_selling_price,0);
2687 v_interface_line_attribute3 := pr_new.interface_line_attribute3;
2688 v_interface_line_attribute6 := pr_new.interface_line_attribute6;
2689 v_excise_amount := 0;
2690 v_tax_amount := 0;
2691 v_excise_diff := 0;
2692 v_assessable_value := 0;
2693 v_basic_excise_duty_amount := 0;
2694 v_add_excise_duty_amount := 0;
2695 v_oth_excise_duty_amount := 0;
2696 v_exist_flag := 0;
2697 v_source_name := 'Receivables India';
2698 v_category_name := jai_constants.je_category_rg_entry ; -- 'RG Register Data Entry' modified by csahoo for bug#6155839
2699 /* --Ramananda for File.Sql.35, end */
2700
2701 ln_bill_only := 0;
2702 ln_legal_entity_id := get_legal_entity_id ;
2703
2704 --2001/05/03 Gadde,Jagdish
2705
2706 /****************************** Validation 1 ********************************/
2707 FND_FILE.PUT_LINE(FND_FILE.LOG,' Org id: '||v_org_id);
2708
2709 /* Bug 5243532. Added by Lakshmi Gopalsami
2710 Removed the reference to cursor Fetch_Book_Id_Cur
2711 and used the values assigned in trigger to get
2712 the value of SOB.
2713 */
2714 v_gl_set_of_bks_id := pr_new.set_of_books_id;
2715
2716 FND_FILE.PUT_LINE(FND_FILE.LOG,' SOB id '|| v_gl_set_of_bks_id);
2717
2718 --If jai_cmn_utils_pkg.check_jai_exists(P_CALLING_OBJECT => 'JA_IN_OE_AR_LINES_INSERT_TRG', P_ORG_ID => pr_new.org_id) = false then
2719 -- return;
2720 --end if;
2721
2722 /*The following code has been commented and added the above code instead - ssumaith - bug# 4037690*/
2723
2724 /*
2725 IF pr_new.org_id IS NOT NULL
2726 THEN
2727 OPEN Sob_cur;
2728 FETCH Sob_cur INTO v_currency_code;
2729 CLOSE Sob_cur;
2730 IF nvl(v_currency_code,'###') <> 'INR'
2731 THEN
2732 RETURN;
2733 END IF;
2734 END IF;
2735 */
2736
2737 -- End addition
2738 --added by vijay on 13-sep-01
2739
2740 /****************************** Validation 2 ********************************/
2741 /*
2742 || Added by Ramananda for bug# 4567935 (115 bug#4404898,4395450,4426613)
2743 || Added the check to RETURN from the trigger if interface line context = 'LEGACY'
2744 */
2745 IF pr_new.interface_line_context in ( 'PROJECTS INVOICES','OKS CONTRACTS', 'LEGACY') THEN
2746 RETURN;
2747 END IF;
2748 --end addition by vijay on 13-sep-01
2749
2750 /****************************** Validation 3 ********************************/
2751 OPEN get_header_info_cur;
2752 FETCH get_header_info_cur INTO j_organization_id ,
2753 j_location_id ,
2754 j_batch_source_id;
2755 CLOSE get_header_info_cur;
2756
2757 FND_FILE.PUT_LINE(FND_FILE.LOG, ' header info.' );
2758 FND_FILE.PUT_LINE(FND_FILE.LOG, ' org id: '|| j_organization_id);
2759 FND_FILE.PUT_LINE(FND_FILE.LOG, ' loc id: '|| j_location_id);
2760 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Batch source id: '|| j_batch_source_id);
2761
2762 /* The following code has been added by SRIRAM -- BUG # 3021588 CALL TO jai_cmn_bond_register_pkg INSTEAD */
2763
2764 jai_cmn_bond_register_pkg.get_register_id(
2765 j_organization_id ,
2766 j_location_id ,
2767 j_batch_source_id ,
2768 'Y' ,
2769 v_register_id ,
2770 v_register_code
2771 );
2772
2773 /****************************** Validation 4 ********************************/
2774 OPEN transaction_type_cur;
2775 FETCH transaction_type_cur INTO v_trans_type;
2776 CLOSE transaction_type_cur;
2777
2778 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Transaction type '|| v_trans_type);
2779 FND_FILE.PUT_LINE(FND_FILE.LOG,
2780 ' Interface line attribute1 '||pr_new.interface_line_attribute1);
2781 FND_FILE.PUT_LINE(FND_FILE.LOG,
2782 ' Interface line context '|| pr_new.interface_line_context);
2783
2784 IF ( v_trans_type = 'CM'
2785 AND pr_new.interface_line_attribute1 = 'SUPPLEMENT CM' -- pr_new.interface_line_context, Bug 4392001
2786 AND pr_new.interface_line_context='INDIA INVOICES' -- Added by Brathod, for Bug# 4392001
2787 )
2788 OR
2789 ( v_trans_type = 'DM'
2790 AND pr_new.interface_line_attribute1 = 'SUPPLEMENT DM' -- pr_new.interface_line_context, Bug 4392001
2791 AND pr_new.interface_line_context='INDIA INVOICES' -- Added by Brathod, for Bug# 4392001
2792 )
2793 OR
2794 (v_trans_type = 'INV')
2795 THEN
2796 null;
2797 ELSE
2798 return;
2799 END IF;
2800
2801 /****************************** Validation 5 ********************************/
2802 /*
2803 This is cursor that is commonly used at various places in the code
2804 */
2805 OPEN created_from_cur;
2806 FETCH created_from_cur INTO v_created_from ,
2807 v_trx_number ,
2808 v_batch_source_id ,
2809 v_books_id ,
2810 v_salesrep_id ,
2811 c_from_currency_code ,
2812 c_conversion_type ,
2813 c_conversion_date ,
2814 c_conversion_rate ;
2815 CLOSE created_from_cur;
2816
2817 IF v_created_from <> 'RAXTRX' THEN
2818 return;
2819 END IF;
2820
2821 /****************************** Validation 6 ********************************/
2822 OPEN once_complete_flag_cur;
2823 FETCH once_complete_flag_cur INTO v_once_completed_flag;
2824 CLOSE once_complete_flag_cur;
2825
2826 FND_FILE.PUT_LINE(FND_FILE.LOG,
2827 ' Once completed flag '|| v_once_completed_flag);
2828
2829
2830 IF NVL(v_once_completed_flag,'N') = 'Y' THEN
2831 RETURN;
2832 END IF;
2833
2834 /****************************** Validation 7 ********************************/
2835 /*
2836 Code for handling supplementary invoices
2837 */
2838 /* Modified from pr_new.interface_line_context, Bug# 4392001 */
2839 IF pr_new.interface_line_attribute1 IN ('SUPPLEMENT CM'
2840 ,'SUPPLEMENT DM'
2841 ,'SUPPLEMENT INVOICE'
2842 )
2843 AND pr_new.interface_line_context = 'INDIA INVOICES' -- Added by Brathod, Bug# 4392001
2844 THEN
2845
2846 OPEN get_exchange_rate;
2847 FETCH get_exchange_rate INTO v_exchange_rate;
2848 CLOSE get_exchange_rate;
2849
2850 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Exchange rate '|| v_exchange_rate);
2851
2852 OPEN duplicate_hdr_cur;
2853 FETCH duplicate_hdr_cur INTO x;
2854 CLOSE duplicate_hdr_cur;
2855
2856 -- IF pr_new.interface_line_attribute1 IS NULL THEN -- Commented By BRATHOD Bug 4392001
2857 IF pr_new.interface_line_attribute4 IS NULL THEN -- Added by BRATHOD, Big# 4392001
2858 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Interface line att4 is null');
2859
2860 OPEN supplement_lines_check_cnsldt;
2861 FETCH supplement_lines_check_cnsldt INTO v_exist_flag;
2862 CLOSE supplement_lines_check_cnsldt;
2863
2864 -- ELSIF pr_new.interface_line_attribute1 IS NOT NULL THEN -- Commented By BRATHOD Bug 4392001
2865 ELSIF pr_new.interface_line_attribute4 IS NOT NULL THEN -- Added By BRATHOD Bug 4392001
2866 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Interface line att4 is not null');
2867 OPEN supplement_lines_check;
2868 FETCH supplement_lines_check INTO v_exist_flag;
2869 CLOSE supplement_lines_check;
2870 END IF;
2871
2872 FND_FILE.PUT_LINE(FND_FILE.LOG,
2873 ' Supplement lines check exists flag'|| v_exist_flag);
2874 IF NVL(v_exist_flag,0) <> 1 THEN
2875 return;
2876 END IF;
2877
2878 IF NVL(x,0) <> 1 THEN
2879 IF pr_new.interface_line_attribute4 IS NULL THEN -- pr_new.interface_line_attribute1, Bug 4392001
2880 OPEN ja_in_ra_customer_trx_infocnsl;
2881 FETCH ja_in_ra_customer_trx_infocnsl INTO v_organization_id, v_location_id;
2882 CLOSE ja_in_ra_customer_trx_infocnsl;
2883 ELSIF pr_new.interface_line_attribute4 IS NOT NULL THEN -- pr_new.interface_line_attribute1, Bug 4392001
2884 OPEN ja_in_ra_customer_trx_info;
2885 FETCH ja_in_ra_customer_trx_info INTO v_organization_id, v_location_id;
2886 CLOSE ja_in_ra_customer_trx_info;
2887 END IF;
2888
2889 INSERT INTO JAI_AR_TRXS ( -- supplement
2890 customer_trx_id ,
2891 organization_id ,
2892 location_id ,
2893 trx_number ,
2894 update_rg_flag ,
2895 update_rg23d_flag ,
2896 once_completed_flag ,
2897 batch_source_id ,
2898 set_of_books_id ,
2899 primary_salesrep_id ,
2900 invoice_currency_code ,
2901 exchange_rate_type ,
2902 exchange_date ,
2903 exchange_rate ,
2904 creation_date ,
2905 created_by ,
2906 last_update_date ,
2907 last_updated_by ,
2908 last_update_login ,
2909 legal_entity_id /* rallamse bug#4448789 */
2910 )
2911 VALUES (
2912 v_header_id ,
2913 v_organization_id ,
2914 v_location_id ,
2915 v_trx_number ,
2916 'Y' ,
2917 'Y' ,
2918 'N' ,
2919 v_batch_source_id ,
2920 v_books_id ,
2921 v_salesrep_id ,
2922 c_from_currency_code ,
2923 c_conversion_type ,
2924 c_conversion_date ,
2925 c_conversion_rate ,
2926 v_creation_date ,
2927 v_created_by ,
2928 v_last_update_date ,
2929 v_last_updated_by ,
2930 v_last_update_login ,
2931 ln_legal_entity_id /* rallamse bug#4448789 */
2932 );
2933 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Inside x <> 1: After insert into JAI_AR_TRXS');
2934 END IF;
2935
2936 IF pr_new.interface_line_attribute4 IS NULL THEN -- pr_new.interface_line_attribute1, Bug# 4392001
2937 OPEN supplement_tax_lines_check_cns;
2938 FETCH supplement_tax_lines_check_cns INTO v_exist_flag;
2939 CLOSE supplement_tax_lines_check_cns;
2940
2941 ELSIF pr_new.INTERFACE_LINE_ATTRIBUTE4 IS NOT NULL THEN -- pr_new.interface_line_attribute1, Bug# 4392001
2942 OPEN supplement_tax_lines_check;
2943 FETCH supplement_tax_lines_check INTO v_exist_flag;
2944 CLOSE supplement_tax_lines_check;
2945 END IF;
2946
2947
2948 IF NVL(v_exist_flag,0) <> 1 THEN
2949 return;
2950 END IF;
2951
2952 v_tax_line_no := 0;
2953
2954 /**************** Start of If Loop pr_new.interface_line_attribute1 IS NULL **********/
2955 IF pr_new.interface_line_attribute4 IS NULL THEN -- pr_new.interface_line_attribute1, Bug# 4392001
2956 FOR tax_rec IN supplement_tax_lines_cnsldt LOOP
2957 v_tax_line_no := v_tax_line_no+1;
2958
2959 -- Date 23/02/2006 by sacsethi for bug 5228046
2960 -- precedence 6 to 10
2961 INSERT INTO JAI_AR_TRX_TAX_LINES(
2962 tax_line_no ,
2963 customer_trx_line_id ,
2964 link_to_cust_trx_line_id ,
2965 precedence_1 ,
2966 precedence_2 ,
2967 precedence_3 ,
2968 precedence_4 ,
2969 precedence_5 ,
2970 precedence_6 ,
2971 precedence_7 ,
2972 precedence_8 ,
2973 precedence_9 ,
2974 precedence_10 ,
2975 tax_id ,
2976 tax_rate ,
2977 qty_rate ,
2978 uom ,
2979 tax_amount ,
2980 func_tax_amount ,
2981 base_tax_amount ,
2982 creation_date ,
2983 created_by ,
2984 last_update_date ,
2985 last_updated_by ,
2986 last_update_login
2987 )
2988 VALUES(
2989 v_tax_line_no ,
2990 ra_customer_trx_lines_s.NEXTVAL ,
2991 v_customer_trx_line_id ,
2992 NULL ,
2993 NULL ,
2994 NULL ,
2995 NULL ,
2996 NULL ,
2997 NULL ,
2998 NULL ,
2999 NULL ,
3000 NULL ,
3001 NULL ,
3002 tax_rec.new_tax_id ,
3003 tax_rec.new_rate ,
3004 tax_rec.new_qty_rate ,
3005 tax_rec.new_uom ,
3006 tax_rec.diff_amt ,
3007 tax_rec.func_tax_amt*nvl(v_exchange_rate,1) ,
3008 tax_rec.base_tax_amt ,
3009 v_creation_date ,
3010 v_created_by ,
3011 v_last_update_date ,
3012 v_last_updated_by ,
3013 v_last_update_login
3014 );
3015
3016 OPEN get_header_details;
3017 FETCH get_header_details INTO v_bill_to_customer_id ,
3018 v_ship_to_site_use_id ,
3019 v_trx_number ,
3020 v_batch_source_id;
3021
3022 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Bill to cust id: '|| v_bill_to_customer_id);
3023 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Ship to site use: '|| v_ship_to_site_use_id);
3024 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Trx number: '|| v_trx_number);
3025 FND_FILE.PUT_LINE(FND_FILE.LOG, ' Batch source id: '|| v_batch_source_id);
3026
3027 CLOSE get_header_details;
3028 OPEN get_site(v_trx_number);
3029 FETCH get_site INTO v_ship_to_site_use_id;
3030 CLOSE get_site;
3031 END LOOP;
3032
3033 ELSIF pr_new.interface_line_attribute4 IS NOT NULL THEN -- pr_new.interface_line_attribute1, Bug# 4392001
3034 FOR Tax_Rec IN SUPPLEMENT_TAX_LINES LOOP
3035 v_tax_line_no := v_tax_line_no+1;
3036
3037 INSERT INTO JAI_AR_TRX_TAX_LINES(
3038 tax_line_no ,
3039 customer_trx_line_id ,
3040 link_to_cust_trx_line_id ,
3041 precedence_1 ,
3042 precedence_2 ,
3043 precedence_3 ,
3044 precedence_4 ,
3045 precedence_5 ,
3046 precedence_6 ,
3047 precedence_7 ,
3048 precedence_8 ,
3049 precedence_9 ,
3050 precedence_10 ,
3051 tax_id ,
3052 tax_rate ,
3053 qty_rate ,
3054 uom ,
3055 tax_amount ,
3056 func_tax_amount ,
3057 base_tax_amount ,
3058 creation_date ,
3059 created_by ,
3060 last_update_date ,
3061 last_updated_by ,
3062 last_update_login
3063 )
3064 VALUES (
3065 v_tax_line_no ,
3066 ra_customer_trx_lines_s.nextval ,
3067 v_customer_trx_line_id ,
3068 NULL ,
3069 NULL ,
3070 NULL ,
3071 NULL ,
3072 NULL ,
3073 NULL ,
3074 NULL ,
3075 NULL ,
3076 NULL ,
3077 NULL ,
3078 tax_rec.new_tax_id ,
3079 tax_rec.new_rate ,
3080 tax_rec.new_qty_rate ,
3081 tax_rec.new_uom ,
3082 tax_rec.diff_amt ,
3083 tax_rec.func_tax_amt*nvl(v_exchange_rate,1) ,
3084 tax_rec.base_tax_amt ,
3085 v_creation_date ,
3086 v_created_by ,
3087 v_last_update_date ,
3088 v_last_updated_by ,
3089 v_last_update_login
3090 );
3091
3092 OPEN get_header_details;
3093 FETCH get_header_details INTO v_bill_to_customer_id,
3094 v_ship_to_site_use_id,
3095 v_trx_number,
3096 v_batch_source_id;
3097 CLOSE get_header_details;
3098 OPEN get_site(v_trx_number);
3099 FETCH get_site INTO v_ship_to_site_use_id;
3100 CLOSE get_site;
3101 END LOOP;
3102
3103 END IF;
3104
3105 /**************** End of If Loop pr_new.interface_line_attribute1 IS NULL **********/
3106
3107 IF pr_new.interface_line_attribute4 IS NULL THEN -- new.interface_line_attribute1, Bug# 4392001
3108 FND_FILE.PUT_LINE(FND_FILE.LOG,' Int. line att4 is null');
3109
3110 OPEN supplement_lines_info_cnsldt;
3111 FETCH supplement_lines_info_cnsldt INTO v_tax_amount,
3112 v_excise_diff,
3113 v_assessable_value;
3114 CLOSE supplement_lines_info_cnsldt;
3115
3116 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax amount: '|| v_tax_amount);
3117 FND_FILE.PUT_LINE(FND_FILE.LOG,' Excise diff: '|| v_excise_diff);
3118 FND_FILE.PUT_LINE(FND_FILE.LOG,' Assessable Value: '||v_assessable_value);
3119
3120 OPEN supplement_lines_info_tax_catg;
3121 FETCH supplement_lines_info_tax_catg INTO v_tax_category_id;
3122 CLOSE supplement_lines_info_tax_catg;
3123
3124 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax category: '|| v_tax_category_id);
3125
3126 ELSIF pr_new.INTERFACE_LINE_ATTRIBUTE4 IS NOT NULL THEN -- pr_new.interface_line_attribute1, Bug# 4392001
3127 FND_FILE.PUT_LINE(FND_FILE.LOG,' Int. line att4 is not null');
3128 OPEN supplement_lines_info;
3129 FETCH supplement_lines_info INTO v_tax_category_id,
3130 v_tax_amount ,
3131 v_excise_diff ,
3132 v_assessable_value;
3133 CLOSE supplement_lines_info;
3134 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax category: '|| v_tax_category_id);
3135 FND_FILE.PUT_LINE(FND_FILE.LOG,' Tax amount: '|| v_tax_amount);
3136 FND_FILE.PUT_LINE(FND_FILE.LOG,' Excise diff: '|| v_excise_diff);
3137 FND_FILE.PUT_LINE(FND_FILE.LOG,' Assessable Value: '||v_assessable_value);
3138
3139 END IF;
3140
3141
3142 /*added by csahoo for bug#5879769*/
3143 OPEN c_get_address_details(v_header_id);
3144 FETCH c_get_address_details into r_add;
3145 CLOSE c_get_address_details;
3146
3147 v_service_type:=get_service_type( NVL(r_add.SHIP_TO_CUSTOMER_ID ,r_add.BILL_TO_CUSTOMER_ID) ,
3148 NVL(r_add.SHIP_TO_SITE_USE_ID, r_add.BILL_TO_SITE_USE_ID),'C');
3149
3150 INSERT INTO JAI_AR_TRX_LINES (
3151 customer_trx_line_id ,
3152 line_number ,
3153 customer_trx_id ,
3154 description ,
3155 inventory_item_id ,
3156 unit_code ,
3157 quantity ,
3158 tax_category_id ,
3159 auto_invoice_flag ,
3160 unit_selling_price ,
3161 line_amount ,
3162 tax_amount ,
3163 total_amount ,
3164 assessable_value ,
3165 creation_date ,
3166 created_by ,
3167 last_update_date ,
3168 last_updated_by ,
3169 last_update_login
3170 )
3171 VALUES(
3172 v_customer_trx_line_id ,
3173 pr_new.line_number ,
3174 v_header_id ,
3175 pr_new.description ,
3176 pr_new.inventory_item_id ,
3177 pr_new.uom_code ,
3178 NVL(pr_new.quantity_invoiced,0) ,
3179 v_tax_category_id ,
3180 'Y' ,
3181 NVL(pr_new.unit_selling_price,0) ,
3182 v_line_amount ,
3183 v_tax_amount ,
3184 (v_line_amount + v_tax_amount) ,
3185 v_assessable_value ,
3186 v_creation_date ,
3187 v_created_by ,
3188 v_last_update_date ,
3189 v_last_updated_by ,
3190 v_last_update_login
3191 );
3192
3193 UPDATE JAI_AR_TRXS
3194 SET
3195 line_amount = NVL(line_amount, 0 ) + NVL(v_line_amount,0),
3196 once_completed_flag = NVL(v_once_completed_flag,'N')
3197 WHERE
3198 customer_trx_id = v_header_id;
3199
3200 --2001/04/20 Anuradha Parthasarathy
3201 OPEN register_code_cur(v_organization_id, v_location_id,v_batch_source_id);
3202 FETCH register_code_cur INTO v_reg_code;
3203 CLOSE register_code_cur;
3204
3205 IF NVL(v_excise_diff ,0) > 0 THEN
3206
3207 IF NVL(v_reg_code,'N') IN ('DOMESTIC_EXCISE','EXPORT_EXCISE') THEN
3208
3209 FND_FILE.PUT_LINE(FND_FILE.LOG,' Register code: '||v_reg_code);
3210
3211
3212 OPEN pref_cur(v_organization_id, v_location_id);
3213 FETCH pref_cur INTO v_pref_rg23a, v_pref_rg23c, v_pref_pla;
3214 CLOSE pref_cur;
3215
3216 FND_FILE.PUT_LINE(FND_FILE.LOG,' Pref RG23A: '|| v_pref_rg23a);
3217 FND_FILE.PUT_LINE(FND_FILE.LOG,' Pref RG23c: '||v_pref_rg23c);
3218 FND_FILE.PUT_LINE(FND_FILE.LOG,' Pref. PLA: '||v_pref_pla);
3219
3220 OPEN rg_bal_cur(v_organization_id, v_location_id);
3221 FETCH rg_bal_cur INTO v_rg23a_balance, v_rg23c_balance, v_pla_balance;
3222 CLOSE rg_bal_cur;
3223
3224 FND_FILE.PUT_LINE(FND_FILE.LOG,' Balance: RG23A:'||v_rg23a_balance);
3225 FND_FILE.PUT_LINE(FND_FILE.LOG,' RG23c: '||v_rg23c_balance);
3226 FND_FILE.PUT_LINE(FND_FILE.LOG,' PLA: '|| v_pla_balance);
3227
3228
3229 OPEN ssi_unit_flag_cur(v_organization_id, v_location_id);
3230 FETCH ssi_unit_flag_cur INTO v_ssi_unit_flag;
3231 CLOSE ssi_unit_flag_cur;
3232
3233 FND_FILE.PUT_LINE(FND_FILE.LOG,' SSI unit flag'||v_ssi_unit_flag);
3234
3235 IF v_pref_rg23a = 1 THEN --5
3236 IF v_rg23a_balance >= NVL(v_excise_diff,0) THEN --6
3237 v_reg_type := 'RG23A';
3238
3239 ELSIF v_pref_rg23c = 2 THEN --6
3240
3241 IF v_rg23c_balance >= NVL(v_excise_diff,0) THEN --7
3242 v_reg_type := 'RG23C';
3243 ELSIF v_pla_balance >= NVL(v_excise_diff,0) THEN --7
3244 v_reg_type := 'PLA';
3245 ELSIF NVL(v_ssi_unit_flag,'N') = 'Y' THEN --7
3246 v_reg_type := 'PLA';
3247 ELSE --7
3248 v_raise_error_flag := 'Y';
3249 END IF; --7
3250
3251 ELSIF v_pla_balance >= NVL(v_excise_diff,0) THEN --6
3252 v_reg_type := 'PLA';
3253
3254 ELSIF NVL(v_ssi_unit_flag,'N') = 'Y' THEN --6
3255 v_reg_type := 'PLA';
3256
3257 ELSIF v_rg23c_balance >= NVL(v_excise_diff,0) THEN --6
3258 v_reg_type := 'RG23C';
3259
3260 ELSE --6
3261 v_raise_error_flag := 'Y';
3262 END IF; --6
3263
3264 ELSIF v_pref_rg23c = 1 THEN --5
3265
3266 IF v_rg23c_balance >= NVL(v_excise_diff,0) THEN --6
3267 v_reg_type := 'RG23C';
3268
3269 ELSIF v_pref_rg23a = 2 THEN --6
3270
3271 IF v_rg23a_balance >= NVL(v_excise_diff,0) THEN --7
3272 v_reg_type := 'RG23A';
3273 ELSIF v_pla_balance >= NVL(v_excise_diff,0) THEN --7
3274 v_reg_type := 'PLA';
3275 ELSIF NVL(v_ssi_unit_flag,'N') = 'Y' THEN --7
3276 v_reg_type := 'PLA';
3277 ELSE --7
3278 v_raise_error_flag := 'Y';
3279 END IF; --7
3280
3281 ELSIF v_pla_balance >= NVL(v_excise_diff,0) THEN --6
3282 v_reg_type := 'PLA';
3283 ELSIF NVL(v_ssi_unit_flag,'N') = 'Y' THEN --6
3284 v_reg_type := 'PLA';
3285 ELSIF v_rg23a_balance >= NVL(v_excise_diff,0) THEN --6
3286 v_reg_type := 'RG23A';
3287 ELSE --6
3288 v_raise_error_flag := 'Y';
3289 END IF; --6
3290
3291 ELSIF v_pla_balance >= NVL(v_excise_diff,0) THEN
3292 v_reg_type := 'PLA';
3293 ELSIF NVL(v_ssi_unit_flag,'N') = 'Y' THEN --6
3294 v_reg_type := 'PLA';
3295 ELSIF v_pref_rg23a = 2 THEN --6
3296 IF v_rg23a_balance >= NVL(v_excise_diff,0) THEN --7
3297 v_reg_type := 'RG23A';
3298 ELSIF v_rg23c_balance >= NVL(v_excise_diff,0) THEN --7
3299 v_reg_type := 'RG23C';
3300 ELSE
3301 v_raise_error_flag := 'Y';
3302 END IF;
3303
3304 ELSIF v_rg23c_balance >= NVL(v_excise_diff,0) THEN --7
3305 v_reg_type := 'RG23C';
3306 ELSIF v_rg23a_balance >= NVL(v_excise_diff,0) THEN --7
3307 v_reg_type := 'RG23A';
3308 ELSE
3309 v_raise_error_flag := 'Y';
3310 END IF; --5
3311
3312 IF NVL(v_raise_error_flag,'N') = 'Y' THEN
3313 /* RAISE_APPLICATION_ERROR(-20120, 'NONE OF the Register Have Balances Greater OR Equal TO the Excisable Amount ->' || TO_CHAR(v_excise_diff));
3314 */ pv_return_code := jai_constants.expected_error ; pv_return_message := 'NONE OF the Register Have Balances Greater OR Equal TO the Excisable Amount ->' || TO_CHAR(v_excise_diff) ; return ;
3315 END IF;
3316
3317 OPEN register_code_meaning_cur(v_reg_code, 'REGISTER_TYPE'); /* Modified by Ramananda for removal of SQL LITERALs */
3318 FETCH register_code_meaning_cur INTO v_meaning;
3319 CLOSE register_code_meaning_cur;
3320
3321 FND_FILE.PUT_LINE(FND_FILE.LOG,' Meaning'|| v_meaning);
3322
3323 OPEN fin_year_cur(v_organization_id);
3324 FETCH fin_year_cur INTO v_fin_year;
3325 CLOSE fin_year_cur;
3326
3327 FND_FILE.PUT_LINE(FND_FILE.LOG,' Fin year '|| v_fin_year);
3328
3329 OPEN Batch_Source_Name_Cur(v_batch_source_id);
3330 FETCH Batch_Source_Name_Cur INTO v_order_invoice_type;
3331 CLOSE Batch_Source_Name_Cur;
3332
3333 FND_FILE.PUT_LINE(FND_FILE.LOG,' Order invoice type: '|| v_order_invoice_type);
3334
3335 OPEN Def_Excise_Invoice_Cur(v_organization_id, v_location_id, v_fin_year, v_order_invoice_type, v_meaning);
3336 FETCH Def_Excise_Invoice_Cur INTO v_start_number, v_end_number, v_jump_by, v_prefix;
3337 CLOSE Def_Excise_Invoice_Cur;
3338
3339 FND_FILE.PUT_LINE(FND_FILE.LOG,' Start number'|| v_start_number);
3340 FND_FILE.PUT_LINE(FND_FILE.LOG,' End number:'|| v_end_number);
3341 FND_FILE.PUT_LINE(FND_FILE.LOG,' jump by: '|| v_jump_by);
3342 FND_FILE.PUT_LINE(FND_FILE.LOG,' prefix : '|| v_prefix);
3343
3344
3345 IF v_start_number IS NOT NULL THEN --2
3346 IF NVL(v_start_number,0) >= NVL(v_end_number,0) AND v_end_number IS NOT NULL THEN
3347 /* RAISE_APPLICATION_ERROR(-20120, 'Excise Invoice NUMBER has been exhausted. ' ||
3348 ' Increase END NUMBER OR enter fresh START NUMBER AND END NUMBER.'); */ pv_return_code := jai_constants.expected_error ; pv_return_message := 'Excise Invoice NUMBER has been exhausted. ' ||
3349 ' Increase END NUMBER OR enter fresh START NUMBER AND END NUMBER.' ; return ;
3350 END IF;
3351 v_exc_invoice_no := NVL(v_start_number,0);
3352 v_start_number := NVL(v_start_number,0) + NVL(v_jump_by,0);
3353 IF v_prefix IS NOT NULL THEN
3354 v_exc_invoice_no := v_prefix||'/'||v_exc_invoice_no;
3355 END IF;
3356 END IF; --2
3357
3358 IF v_exc_invoice_no IS NOT NULL THEN
3359 IF v_start_number IS NOT NULL THEN
3360 FOR master_org_rec IN ec_code_cur(v_organization_id, v_location_id) LOOP
3361 UPDATE
3362 JAI_CMN_RG_EXC_INV_NOS
3363 SET
3364 start_number = v_start_number,
3365 last_update_date = v_last_update_date,
3366 last_updated_by = v_last_updated_by,
3367 last_update_login = v_last_update_login
3368 WHERE
3369 organization_id = master_org_rec.organization_id AND
3370 location_id = master_org_rec.location_id AND
3371 fin_year = v_fin_year AND
3372 order_invoice_type = v_order_invoice_type AND
3373 register_code = v_meaning;
3374
3375 END LOOP;
3376 END IF;
3377 END IF;
3378
3379 UPDATE JAI_AR_TRX_LINES
3380 SET payment_register = v_reg_type,
3381 excise_invoice_no = v_exc_invoice_no,
3382 excise_invoice_date = trunc(sysdate)
3383 WHERE
3384 customer_trx_line_id = v_customer_trx_line_id AND
3385 inventory_item_id = pr_new.inventory_item_id AND
3386 customer_trx_id = v_header_id;
3387
3388 OPEN site_cur;
3389 FETCH site_cur INTO v_ship_id,v_ship_site_id;
3390 CLOSE site_cur;
3391
3392 IF v_reg_type IN ('RG23A','RG23C') THEN
3393 jai_om_rg_pkg.ja_in_rg23_part_I_entry(
3394 v_reg_type ,
3395 v_fin_year ,
3396 v_organization_id ,
3397 v_location_id ,
3398 pr_new.inventory_item_id ,
3399 33 ,
3400 sysdate ,
3401 'I' ,
3402 pr_new.quantity_invoiced ,
3403 pr_new.uom_code ,
3404 v_exc_invoice_no ,
3405 sysdate ,
3406 v_excise_diff ,
3407 0 ,
3408 0 ,
3409 v_ship_id ,
3410 v_ship_site_id ,
3411 v_header_id ,
3412 sysdate ,
3413 v_reg_code ,
3414 v_creation_date ,
3415 v_created_by ,
3416 v_last_update_date ,
3417 v_last_updated_by ,
3418 v_last_update_login
3419 );
3420
3421 SELECT JAI_CMN_RG_23AC_I_TRXS_S.currval INTO v_part_i_register_id FROM dual; /* txns changed to trxs by rchandan for bug#4487676 */
3422
3423 jai_om_rg_pkg.ja_in_rg23_part_II_entry(
3424 v_reg_code ,
3425 v_reg_type ,
3426 v_fin_year ,
3427 v_organization_id ,
3428 v_location_id ,
3429 pr_new.inventory_item_id ,
3430 33 ,
3431 sysdate ,
3432 v_part_i_register_id ,
3433 v_exc_invoice_no ,
3434 sysdate ,
3435 v_excise_diff ,
3436 0 ,
3437 0 ,
3438 v_ship_id ,
3439 v_ship_site_id ,
3440 v_source_name ,
3441 v_category_name ,
3442 v_creation_date ,
3443 v_created_by ,
3444 v_last_update_date ,
3445 v_last_updated_by ,
3446 v_last_update_login ,
3447 pr_new.customer_trx_line_id ,
3448 null ,
3449 null
3450 );
3451
3452 SELECT JAI_CMN_RG_23AC_I_TRXS_S.currval INTO v_rg23_part_i_no FROM dual; /* txns changed to trxs by rchandan for bug# bug#4487676 */
3453
3454 SELECT JAI_CMN_RG_23AC_II_TRXS_S.currval INTO v_rg23_part_ii_no FROM dual;
3455
3456 UPDATE JAI_CMN_RG_23AC_I_TRXS
3457 SET REGISTER_ID_PART_II = v_rg23_part_ii_no,
3458 charge_account_id = (
3459 SELECT
3460 charge_account_id
3461 FROM
3462 JAI_CMN_RG_23AC_II_TRXS
3463 WHERE
3464 register_id = v_rg23_part_ii_no
3465 )
3466 WHERE register_id = v_rg23_part_i_no;
3467
3468 ELSIF v_reg_type = 'PLA' THEN
3469 jai_om_rg_pkg.ja_in_pla_entry(
3470 v_organization_id ,
3471 v_location_id ,
3472 pr_new.inventory_item_id ,
3473 v_fin_year ,
3474 33 ,
3475 v_header_id ,
3476 SYSDATE ,
3477 v_exc_invoice_no ,
3478 SYSDATE ,
3479 v_excise_diff ,
3480 0 ,
3481 0 ,
3482 v_ship_id ,
3483 v_ship_site_id ,
3484 v_source_name ,
3485 v_category_name ,
3486 v_creation_date ,
3487 v_created_by ,
3488 v_last_update_date ,
3489 v_last_updated_by ,
3490 v_last_update_login
3491 );
3492
3493
3494 SELECT JAI_CMN_RG_PLA_TRXS_S1.currval INTO v_pla_register_no FROM dual;
3495 UPDATE JAI_CMN_RG_23AC_I_TRXS
3496 SET REGISTER_ID_PART_II = v_pla_register_no,
3497 charge_account_id = (SELECT charge_account_id FROM JAI_CMN_RG_PLA_TRXS
3498 WHERE register_id = v_pla_register_no)
3499 WHERE register_id = v_rg23_part_i_no;
3500 END IF;
3501
3502 END IF;
3503 END IF;
3504
3505 --2001/04/20 Anuradha Parthasarathy
3506
3507 /* ( */
3508 ELSE /* ELSIF OF pr_new.interface_line_context IN ('SUPPLEMENT CM','SUPPLEMENT DM','SUPPLEMENT INVOICE') */
3509 -------------------------------------------------------------------------------------------
3510 /*from here starts the actual coding with respect to what needs to be done for a normal imported invoice
3511 the code segment until now - is for supplementary transactions
3512 */
3513 -- Manohar Mishra 12/02/01
3514 OPEN duplicate_hdr_cur;
3515 FETCH duplicate_hdr_cur INTO x;
3516 CLOSE duplicate_hdr_cur;
3517
3518 OPEN So_picking_record_check;
3519 FETCH So_picking_record_check INTO v_exist_flag;
3520 CLOSE So_picking_record_check;
3521
3522 ln_first_time := 0;
3523 IF NVL(v_exist_flag,0) <> 1 THEN
3524
3525 /* Here checking whether the invoice line corresponds to a bill only workflow , and if is true , the control should
3526 not return because there would be no shipment process */
3527
3528 ln_bill_only := 0;
3529 open c_bill_only_invoice(pr_new.customer_trx_line_id, 'R_BILL_ONLY'); /* Modified by Ramananda for removal of SQL LITERALs */
3530 fetch c_bill_only_invoice into ln_bill_only;
3531 close c_bill_only_invoice;
3532
3533 if ln_bill_only = 1 then
3534 process_bill_only_invoice;
3535 return;
3536 end if;
3537 -- here code returns for an ato imported order because because
3538 -- records do not exist in JAI_OM_WSH_LINES_ALL table
3539 process_taxes_for_ato_order;
3540
3541
3542 END IF;
3543
3544 v_exist_flag := 0;
3545
3546 OPEN so_picking_hdr_info;
3547 FETCH so_picking_hdr_info INTO v_organization_id, v_location_id;
3548 CLOSE so_picking_hdr_info;
3549 FND_FILE.PUT_LINE(FND_FILE.LOG,'v_organization_id= '||v_organization_id||' v_location_id= ' || v_location_id );
3550 /* Added by JMEENA for bug#6498345 ( FP 6492966), Starts */
3551 IF v_organization_id IS NULL THEN
3552 ln_order_ato := NULL ;
3553 OPEN c_ato_order ;
3554 FETCH c_ato_order INTO ln_order_ato ;
3555 CLOSE c_ato_order ;
3556
3557 IF nvl(ln_order_ato,0) = 1 THEN
3558 open c_ato_hdr_info;
3559 fetch c_ato_hdr_info into v_organization_id, v_location_id;
3560 close c_ato_hdr_info;
3561 END IF ;
3562
3563 FND_FILE.PUT_LINE(FND_FILE.LOG,'ATO Header Info: v_organization_id= '||v_organization_id||' v_location_id= ' || v_location_id );
3564 END IF ;
3565 /* Added for bug#6498345( FP 6492966), Ends */
3566
3567
3568 /*( */
3569 IF NVL(x,0) <> 1 THEN
3570 /* Bug 5243532. Added by Lakshmi Gopalsami
3571 Removed the reference to cursor set_of_books_cur.
3572 END IF;
3573 */
3574 /* start additions by sriram - bug# 3607101
3575 */
3576 open c_ont_source_code;
3577 fetch c_ont_source_code into v_ont_source_code;
3578 close c_ont_source_code;
3579 v_ont_source_code := ltrim(rtrim(v_ont_source_code));
3580 -- The value retreived here should be ideally 'ORDER ENTRY' , not hard coding because it can be profile driven.
3581 /*
3582 ends here -- bug# 3607101
3583 */
3584
3585 INSERT INTO JAI_AR_TRXS
3586 (Customer_Trx_ID, Organization_ID, Location_ID, Trx_Number,
3587 Update_RG_Flag,UPDATE_RG23D_FLAG, Once_Completed_Flag, Batch_Source_ID, Set_Of_Books_ID,
3588 Primary_Salesrep_ID, Invoice_Currency_Code, Exchange_Rate_Type,
3589 Exchange_Date, Exchange_Rate,
3590 creation_date, created_by, last_update_date, last_updated_by, last_update_login,
3591 legal_entity_id /* rallamse bug#4448789 */
3592 )
3593 VALUES (
3594 v_header_id, v_organization_id, v_location_id, v_trx_number,
3595 'Y', 'Y','N', v_batch_source_id, v_books_id,
3596 v_salesrep_id, c_from_currency_code, c_conversion_type,
3597 c_conversion_date, c_conversion_rate,
3598 v_creation_date, v_created_by, v_last_update_date, v_last_updated_by, v_last_update_login,
3599 ln_legal_entity_id /* rallamse bug#4448789 */
3600 );
3601 END IF;
3602
3603 /* ) */
3604
3605 OPEN so_picking_tax_record_check;
3606 FETCH so_picking_tax_record_check INTO v_exist_flag;
3607 CLOSE so_picking_tax_record_check;
3608
3609 /*
3610 Check if taxes exist in JAI_OM_WSH_LINE_TAXES tables.
3611 IF yes then insert all the taxes into ja_in_ra_cust_trx_lines_all table
3612 IF no then check the same in ja_in_so_tax_lines_table.
3613
3614 (
3615 */
3616 IF NVL(v_exist_flag,0) = 1 THEN
3617 v_bond_tax_amt := 0; -- cbabu for Bug# 2779990
3618
3619 FOR tax_rec IN so_picking_tax_lines_info LOOP
3620 /*IF ln_first_time = 0 THEN
3621 ln_first_time := ln_first_time + 1;
3622 UPDATE JAI_AR_TRXS
3623 SET vat_invoice_no = tax_rec.vat_invoice_no,
3624 vat_invoice_date = tax_rec.vat_invoice_date
3625 WHERE customer_trx_id = pr_new.customer_trx_id;
3626 END IF;*/
3627 --2001/06/05 Anuradha Parthasarathy
3628
3629 -- ssumaith - 3532716.
3630 v_base_tax_amount :=0;
3631 v_tax_amt :=0;
3632 v_func_tax_amount :=0;
3633 -- ssumaith - 3532716.
3634 OPEN so_picking_tax_amt(Tax_Rec.tax_id);
3635 FETCH so_picking_tax_amt INTO v_base_tax_amount,v_tax_amt,v_func_tax_amount;
3636 CLOSE so_picking_tax_amt;
3637
3638 v_tax_line_count := 0; -- ssumaith - 3532716.
3639 OPEN duplicate_tax_lines_cur(tax_rec.tax_id);
3640 FETCH duplicate_tax_lines_cur INTO v_tax_line_count;
3641 CLOSE duplicate_tax_lines_cur;
3642
3643 IF NVL(v_tax_line_count,0) <> 1 THEN
3644 IF v_register_code ='BOND_REG' THEN
3645 IF tax_rec.tax_type NOT IN ('Excise','Other Excise','CVD_EDUCATION_CESS','EXCISE_EDUCATION_CESS',jai_constants.tax_type_sh_cvd_edu_cess, jai_constants.tax_type_sh_exc_edu_cess) THEN
3646 /*jai_constants.tax_type_sh_cvd_edu_cess,jai_constants.tax_type_sh_exc_edu_cess added by CSahoo BUG#5989740*/
3647 IF (NVL(pr_new.Interface_line_attribute11,'0') = '0'
3648 and nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context))
3649 )/* following OR added by sriram - bug#3607101 */
3650 or
3651 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug# 3607101
3652 )
3653 then
3654 -- Date 23/02/2006 by sacsethi for bug 5228046
3655 -- precedence 6 to 10
3656 INSERT INTO JAI_AR_TRX_TAX_LINES (
3657 tax_line_no ,
3658 customer_trx_line_id ,
3659 link_to_cust_trx_line_id ,
3660 precedence_1 ,
3661 precedence_2 ,
3662 precedence_3 ,
3663 precedence_4 ,
3664 precedence_5 ,
3665 precedence_6 ,
3666 precedence_7 ,
3667 precedence_8 ,
3668 precedence_9 ,
3669 precedence_10 ,
3670 tax_id ,
3671 tax_rate ,
3672 qty_rate ,
3673 uom ,
3674 tax_amount ,
3675 func_tax_amount ,
3676 base_tax_amount ,
3677 creation_date ,
3678 created_by ,
3679 last_update_date ,
3680 last_updated_by ,
3681 last_update_login
3682 )
3683 VALUES
3684 (
3685 tax_rec.tax_line_no ,
3686 ra_customer_trx_lines_s.nextval ,
3687 v_customer_trx_line_id ,
3688 tax_rec.precedence_1 ,
3689 tax_rec.precedence_2 ,
3690 tax_rec.precedence_3 ,
3691 tax_rec.precedence_4 ,
3692 tax_rec.precedence_5 ,
3693 tax_rec.precedence_6 ,
3694 tax_rec.precedence_7 ,
3695 tax_rec.precedence_8 ,
3696 tax_rec.precedence_9 ,
3697 tax_rec.precedence_10 ,
3698 tax_rec.tax_id ,
3699 tax_rec.tax_rate ,
3700 tax_rec.qty_rate ,
3701 tax_rec.uom ,
3702 round(v_tax_amt,2) ,
3703 round(v_func_tax_amount,2) ,
3704 round(v_base_tax_amount,2) ,
3705 v_creation_date ,
3706 v_created_by ,
3707 v_last_update_date ,
3708 v_last_updated_by ,
3709 v_last_update_login
3710 );
3711
3712 -- cbabu for Bug# 2779990
3713 IF tax_rec.tax_type <> 'TDS' THEN
3714 v_bond_tax_amt := v_bond_tax_amt + nvl(v_tax_amt,0);
3715 END IF;
3716 END IF; /* END IF FOR IF (NVL(pr_new.Interface_line_attribute11,'0') = '0' */
3717 END IF; /* END IF FOR IF tax_rec.tax_type NOT IN ('Excise','Other Excise')*/
3718
3719 ELSE /* ELSE OF IF v_register_code ='BOND_REG' */
3720 -- the following If Condition added by Sriram - 27/06/2002 - Bug # 2398198
3721 -- Here trying to conditionally update Ja_in_ra_customer_trx_table
3722 -- For the second line of the same order line in AR , the tax amounts should not be
3723 -- inserted.Hence conditionally executing the insert statement.
3724 IF (NVL(pr_new.Interface_line_attribute11,'0') ='0'
3725 and nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - bug# 3607101
3726 )/* following OR added by sriram - bug#3607101 */
3727 or
3728 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug# 3607101
3729 )
3730 then
3731 -- Date 23/02/2006 by sacsethi for bug 5228046
3732 -- precedence 6 to 10
3733 INSERT INTO JAI_AR_TRX_TAX_LINES(
3734 tax_line_no ,
3735 customer_trx_line_id ,
3736 link_to_cust_trx_line_id ,
3737 precedence_1 ,
3738 precedence_2 ,
3739 precedence_3 ,
3740 precedence_4 ,
3741 precedence_5 ,
3742 precedence_6 ,
3743 precedence_7 ,
3744 precedence_8 ,
3745 precedence_9 ,
3746 precedence_10 ,
3747 tax_id ,
3748 tax_rate ,
3749 qty_rate ,
3750 uom ,
3751 tax_amount ,
3752 func_tax_amount ,
3753 base_tax_amount ,
3754 creation_date ,
3755 created_by ,
3756 last_update_date ,
3757 last_updated_by ,
3758 last_update_login
3759 )
3760
3761 VALUES(
3762 tax_rec.tax_line_no ,
3763 ra_customer_trx_lines_s.nextval ,
3764 v_customer_trx_line_id ,
3765 tax_rec.precedence_1 ,
3766 tax_rec.precedence_2 ,
3767 tax_rec.precedence_3 ,
3768 tax_rec.precedence_4 ,
3769 tax_rec.precedence_5 ,
3770 tax_rec.precedence_6 ,
3771 tax_rec.precedence_7 ,
3772 tax_rec.precedence_8 ,
3773 tax_rec.precedence_9 ,
3774 tax_rec.precedence_10 ,
3775 tax_rec.tax_id ,
3776 tax_rec.tax_rate ,
3777 tax_rec.qty_rate ,
3778 tax_rec.uom ,
3779 round(v_tax_amt,2) ,
3780 round(v_func_tax_amount,2) ,
3781 round(v_base_tax_amount,2) ,
3782 v_creation_date ,
3783 v_created_by ,
3784 v_last_update_date ,
3785 v_last_updated_by ,
3786 v_last_update_login
3787 );
3788
3789 END IF;
3790 END IF; /* END IF OF IF v_register_code ='BOND_REG' */
3791 END IF; /* END IF OF IF NVL(v_tax_line_count,0) <> 1 */
3792 END LOOP;
3793 OPEN so_picking_lines_info;
3794 FETCH so_picking_lines_info INTO v_tax_category_id ,
3795 v_qty ,
3796 v_tax_amount ,
3797 v_assessable_value ,
3798 v_basic_excise_duty_amount ,
3799 v_add_excise_duty_amount ,
3800 v_oth_excise_duty_amount ,
3801 v_payment_register ,
3802 v_excise_invoice_no ,
3803 v_preprinted_excise_inv_no ,
3804 v_excise_invoice_date ,
3805 v_excise_exempt_type ,
3806 v_excise_exempt_refno ,
3807 v_excise_exempt_date ,
3808 v_ar3_form_no ,
3809 v_ar3_form_date , -- Vijay Shankar for Bug # 3181892
3810 lv_vat_exemption_flag , -- added, Harshita for bug#4245062
3811 lv_vat_exemption_type ,
3812 lv_vat_exemption_date ,
3813 lv_vat_exemption_refno ,
3814 ln_vat_assessable_value ,
3815 ln_vat_invoice_no ,
3816 ln_vat_invoice_date ;
3817 CLOSE so_picking_lines_info;
3818 -- cbabu for Bug# 2779990
3819 -- this overrides the v_tax_amount fetched from cursor SO_PICKING_LINES_INFO for bond reg transactions
3820 IF v_register_code = 'BOND_REG' THEN
3821 v_tax_amount := v_bond_tax_amt / v_qty;
3822 END IF;
3823 -- Bug 3357587
3824 -- To pick assessable_value from JAI_OM_OE_SO_LINES instead of JAI_OM_WSH_LINES_ALL
3825 OPEN C_JA_SO_LINES_ASSESSABLE_VAL;
3826 FETCH C_JA_SO_LINES_ASSESSABLE_VAL into v_assessable_value,v_service_type;/*5879769..csahoo*/
3827 CLOSE C_JA_SO_LINES_ASSESSABLE_VAL;
3828
3829
3830 ELSE /* ELSE OF IF NVL(v_exist_flag,0) = 1 */
3831 /*
3832 If records do not exist in JAI_OM_WSH_LINE_TAXES table then control comes to this portion of the code
3833 */
3834 OPEN ja_so_lines_tax_record_check ;
3835 FETCH ja_so_lines_tax_record_check INTO v_exist_flag;
3836 CLOSE ja_so_lines_tax_record_check;
3837 /*
3838 Check if a tax line exists in ja_in_so_tax_lines_table
3839 IF yes then insert all the taxes into JAI_AR_TRX_TAX_LINES table.
3840 */
3841 IF NVL(v_exist_flag,0) = 1 THEN
3842 FOR tax_rec IN ja_so_tax_lines_info LOOP
3843 -- Date 23/02/2006 by sacsethi for bug 5228046
3844 -- precedence 6 to 10
3845 INSERT INTO JAI_AR_TRX_TAX_LINES(
3846 tax_line_no ,
3847 customer_trx_line_id ,
3848 link_to_cust_trx_line_id ,
3849 precedence_1 ,
3850 precedence_2 ,
3851 precedence_3 ,
3852 precedence_4 ,
3853 precedence_5 ,
3854 precedence_6 ,
3855 precedence_7 ,
3856 precedence_8 ,
3857 precedence_9 ,
3858 precedence_10 ,
3859 tax_id ,
3860 tax_rate ,
3861 qty_rate ,
3862 uom ,
3863 tax_amount ,
3864 func_tax_amount ,
3865 base_tax_amount ,
3866 creation_date ,
3867 created_by ,
3868 last_update_date ,
3869 last_updated_by ,
3870 last_update_login
3871 )
3872 VALUES(
3873 tax_rec.tax_line_no ,
3874 ra_customer_trx_lines_s.nextval ,
3875 v_customer_trx_line_id ,
3876 tax_rec.precedence_1 ,
3877 tax_rec.precedence_2 ,
3878 tax_rec.precedence_3 ,
3879 tax_rec.precedence_4 ,
3880 tax_rec.precedence_5 ,
3881 tax_rec.precedence_6 ,
3882 tax_rec.precedence_7 ,
3883 tax_rec.precedence_8 ,
3884 tax_rec.precedence_9 ,
3885 tax_rec.precedence_10 ,
3886 tax_rec.tax_id ,
3887 tax_rec.tax_rate ,
3888 tax_rec.qty_rate ,
3889 tax_rec.uom ,
3890 round(tax_rec.tax_amount,2) ,
3891 round(tax_rec.func_tax_amount,2) ,
3892 round(tax_rec.base_tax_amount,2) ,
3893 v_creation_date ,
3894 v_created_by ,
3895 v_last_update_date ,
3896 v_last_updated_by ,
3897 v_last_update_login
3898 );
3899 END LOOP;
3900 OPEN ja_so_lines_info;
3901 FETCH ja_so_lines_info INTO v_tax_category_id ,
3902 v_tax_amount ,
3903 v_assessable_value ,
3904 v_excise_exempt_type ,
3905 v_excise_exempt_refno ,
3906 v_excise_exempt_date ,
3907 lv_vat_exemption_flag , -- added, Harshita for bug#4245062
3908 lv_vat_exemption_type ,
3909 lv_vat_exemption_date ,
3910 lv_vat_exemption_refno ,
3911 ln_vat_assessable_value ;
3912 CLOSE ja_so_lines_info;
3913
3914 ELSE /* ELSE FOR IF NVL(v_exist_flag,0) = 1 */
3915 /*
3916 Update done by aiyer for the bug #3328871
3917 If taxes do not exist in JAI_OM_WSH_LINE_TAXES and JAI_OM_OE_SO_TAXES then control
3918 would come here.
3919 Code should return only in case of an RMA i.e return only when a line does not exist in JAI_OM_OE_SO_LINES table
3920 for the given line_id.
3921 */
3922 DECLARE
3923 CURSOR c_so_lines_exists
3924 IS
3925 SELECT 1
3926 FROM JAI_OM_OE_SO_LINES
3927 WHERE line_id = pr_new.interface_line_attribute6;
3928 lv_exists VARCHAR2(1);
3929 BEGIN
3930 pv_return_code := jai_constants.successful ;
3931 OPEN c_so_lines_exists ;
3932 FETCH c_so_lines_exists INTO lv_exists;
3933 IF c_so_lines_exists%NOTFOUND THEN
3934 CLOSE c_so_lines_exists;
3935 fnd_file.put_line(FND_FILE.LOG,
3936 'no lines in jai_om_oe_so_lines -return');
3937 return;
3938 END IF;
3939 CLOSE c_so_lines_exists;
3940 END ;
3941 END IF; /* END IF FOR IF NVL(v_exist_flag,0) = 1 */
3942 END IF;
3943 OPEN duplicate_lines_cur;
3944 FETCH duplicate_lines_cur INTO v_line_count;
3945 CLOSE duplicate_lines_cur;
3946
3947 fnd_file.put_line(FND_FILE.LOG, ' Line cnt: '|| v_line_count);
3948
3949 IF NVL(v_line_count,0) <> 1 THEN
3950 -- the following If Condition added by Sriram - 27/06/2002 - Bug # 2398198
3951 -- Here trying to conditionally update Ja_in_ra_customer_trx_table
3952 -- For the second line of the same order line in AR , the tax amount should not be
3953 -- inserted.Hence Setting setting tax amount variable v_calc_tax_amount to 0.
3954 IF (NVL(pr_new.Interface_line_attribute11,'0') ='0'
3955 and nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - bug# 3607101
3956 )/* following OR added by sriram - bug#3607101 */
3957 or
3958 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug# 3607101
3959 )
3960 then
3961
3962 fnd_file.put_line(FND_FILE.LOG, ' int. line att1 = 0 ');
3963 v_calc_tax_amount := v_tax_amount * v_qty;
3964 OPEN c_cust_trx_tax_line_amt;
3965 FETCH c_cust_trx_tax_line_amt into v_calc_tax_amount;
3966 CLOSE c_cust_trx_tax_line_amt;
3967 ELSE
3968 v_calc_tax_amount := 0;
3969 END IF;
3970
3971 INSERT INTO JAI_AR_TRX_LINES (
3972 customer_trx_line_id ,
3973 line_number ,
3974 customer_trx_id ,
3975 description ,
3976 payment_register ,
3977 excise_invoice_no ,
3978 preprinted_excise_inv_no ,
3979 excise_invoice_date ,
3980 inventory_item_id ,
3981 unit_code ,
3982 quantity ,
3983 tax_category_id ,
3984 auto_invoice_flag ,
3985 unit_selling_price ,
3986 line_amount ,
3987 tax_amount ,
3988 total_amount ,
3989 assessable_value ,
3990 creation_date ,
3991 created_by ,
3992 last_update_date ,
3993 last_updated_by ,
3994 last_update_login ,
3995 excise_exempt_type ,
3996 excise_exempt_refno ,
3997 excise_exempt_date ,
3998 ar3_form_no ,
3999 ar3_form_date ,
4000 vat_exemption_flag , -- added, Harshita for bug#4245062
4001 vat_exemption_type ,
4002 vat_exemption_date ,
4003 vat_exemption_refno ,
4004 vat_assessable_value
4005 )
4006 VALUES (
4007 v_customer_trx_line_id ,
4008 pr_new.line_number ,
4009 v_header_id ,
4010 pr_new.description ,
4011 v_payment_register ,
4012 v_excise_invoice_no ,
4013 v_preprinted_excise_inv_no ,
4014 v_excise_invoice_date ,
4015 pr_new.inventory_item_id ,
4016 pr_new.uom_code ,
4017 pr_new.quantity_invoiced ,
4018 v_tax_category_id ,
4019 'Y' ,
4020 pr_new.unit_selling_price ,
4021 round(v_line_amount,2) ,
4022 round(v_calc_tax_amount,2) ,
4023 round((v_line_amount + v_calc_tax_amount),2) ,
4024 v_assessable_value ,
4025 v_creation_date ,
4026 v_created_by ,
4027 v_last_update_date ,
4028 v_last_updated_by ,
4029 v_last_update_login ,
4030 v_excise_exempt_type ,
4031 v_excise_exempt_refno ,
4032 v_excise_exempt_date ,
4033 v_ar3_form_no ,
4034 v_ar3_form_date ,
4035 lv_vat_exemption_flag , -- added, Harshita for bug#4245062
4036 lv_vat_exemption_type ,
4037 lv_vat_exemption_date ,
4038 lv_vat_exemption_refno ,
4039 ln_vat_assessable_value
4040 );
4041 ELSE /* ELSE OF IF NVL(v_line_count,0) <> 1*/
4042 OPEN old_customer_trx_id_cur;
4043 FETCH old_customer_trx_id_cur INTO v_old_customer_trx_id;
4044 CLOSE old_customer_trx_id_cur;
4045
4046 -- Vijay Shankar for Bug# 3985561
4047 -- commented the following delete statement as this is not required in this trigger.
4048 -- This statement is executed in Concurrent process to default taxes from OM to AR
4049 --DELETE JAI_AR_TRX_INS_LINES_T
4050 --WHERE customer_trx_line_id = v_customer_trx_line_id;
4051
4052 IF v_old_customer_trx_id <> v_header_id THEN
4053 UPDATE JAI_AR_TRX_LINES
4054 SET customer_trx_id = v_header_id
4055 WHERE customer_trx_line_id = v_customer_trx_line_id;
4056 DELETE JAI_AR_TRXS
4057 WHERE customer_trx_id = v_old_customer_trx_id;
4058 END IF;
4059 END IF; /* END IF OF IF NVL(v_line_count,0) <> 1 */
4060
4061 v_excise_amount := round(nvl(v_basic_excise_duty_amount,0) + nvl(v_add_excise_duty_amount,0) + nvl(v_oth_excise_duty_amount,0));
4062
4063 fnd_file.put_line(FND_FILE.LOG, ' Excise amount: '|| v_excise_amount);
4064
4065 OPEN complete_flag_cur;
4066 FETCH complete_flag_cur INTO v_once_completed_flag;
4067 CLOSE complete_flag_cur;
4068
4069 fnd_file.put_line(FND_FILE.LOG, ' Once complete flag'|| v_once_completed_flag);
4070
4071 v_so_tax_amount := v_tax_amount * v_qty ;
4072
4073 /*Bug # 2316589*/
4074 -- Instead the following update has been modified . It used a new variable
4075 -- called v_so_tax_amount to calculate the tax amount.
4076 -- the following If Condition added by Sriram - 27/06/2002 - Bug # 2398198
4077 -- Here trying to conditionally update Ja_in_ra_customer_trx_table
4078 -- For the second line of the same order line in AR , the tax amount should not be
4079 -- updated.
4080
4081 -- bug # 3000550 sriram
4082 OPEN c_cust_trx_tax_line_amt;
4083 FETCH c_cust_trx_tax_line_amt into v_so_tax_amount;
4084 CLOSE c_cust_trx_tax_line_amt;
4085
4086 fnd_file.put_line(FND_FILE.LOG, ' so tax amount: '|| v_so_tax_amount);
4087
4088 -- bug # 3000550 sriram
4089 IF (NVL(pr_new.Interface_line_attribute11,'0') ='0'
4090 and nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - bug# 3607101
4091 )/* following OR added by sriram - bug#3607101 */
4092 or
4093 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug# 3607101
4094 )
4095 then
4096 -- Above if condition added by sriram Bug # 2742849
4097 -- instead of the previous if condition because , it may fail in circumstances
4098 -- where line ordering rules are set up in autoinvoice options.
4099
4100 UPDATE JAI_AR_TRXS
4101 SET line_amount = round(NVL(line_amount,0) + NVL(v_line_amount,0),2),
4102 tax_amount = round(NVL(tax_amount,0) + NVL(v_so_tax_amount,0),2),
4103 total_amount = round(NVL(total_amount,0) + NVL(v_line_amount,0) + NVL(v_so_tax_amount,0),2),
4104 once_completed_flag = NVL(v_once_completed_flag,'N'),
4105 vat_invoice_no = ln_vat_invoice_no, vat_invoice_date = ln_vat_invoice_date -- added, Harshita for bug#4245062
4106 WHERE customer_trx_id = v_header_id;
4107 ELSE
4108 UPDATE JAI_AR_TRXS
4109 SET line_amount = round(NVL(line_amount, 0 ) + NVL(v_line_amount,0),2),
4110 total_amount = round(NVL(total_amount,0) + NVL(v_line_amount,0),2),
4111 once_completed_flag = NVL(v_once_completed_flag,'N'),
4112 vat_invoice_no = ln_vat_invoice_no, vat_invoice_date = ln_vat_invoice_date -- added, Harshita for bug#4245062
4113 WHERE customer_trx_id = v_header_id;
4114 END IF;
4115
4116 END IF;
4117 EXCEPTION
4118 WHEN OTHERS THEN
4119 vsqlerrm := SQLERRM;
4120
4121 /* Added an exception block by Ramananda for bug#4570303 */
4122 Pv_return_code := jai_constants.unexpected_error;
4123 Pv_return_message := 'Encountered an error in JAI_AR_RCTLA_TRIGGER_PKG.ARI_T2 ' || substr(sqlerrm,1,1900);
4124
4125 lv_appl_src := 'JA_IN_OE_AR_LINES_INSERT_TRG' ;
4126 lv_err_msg := 'EXCEPTION Occured' ;
4127
4128 INSERT INTO JAI_CMN_ERRORS_T
4129 (
4130 APPLICATION_SOURCE ,
4131 error_message ,
4132 additional_error_mesg ,
4133 creation_date ,
4134 created_by ,
4135 -- added, Harshita for Bug 4866533
4136 LAST_UPDATED_BY,
4137 LAST_UPDATE_DATE
4138 )
4139 VALUES
4140 (
4141 lv_appl_src, /*'JA_IN_OE_AR_LINES_INSERT_TRG' ,*/
4142 lv_err_msg , /* 'EXCEPTION Occured ' ,*/
4143 substr(vsqlerrm,1,200) ,
4144 sysdate ,
4145 user ,
4146 -- added, Harshita for Bug 4866533
4147 fnd_global.user_id,
4148 sysdate
4149 );
4150
4151 END ARI_T2 ;
4152
4153 /*REM +======================================================================+
4154 REM NAME ARI_T3
4155 REM
4156 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
4157 REM
4158 REM NOTES Refers to old trigger JAI_AR_RCTLA_ARI_T8
4159 REM Change History :-
4160 REM Slno Date Bug File Version Comments
4161 REM 1. 14-Jul-2006 5378650 120.7 Uncommented the assigned of values
4162 REM from record group to local variables
4163 REM +======================================================================+
4164 */
4165 PROCEDURE ARI_T3 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
4166 v_created_from VARCHAR2(30);
4167 /* --Ramananda for File.Sql.35, start */
4168 /*
4169 ||Modified by aiyer for the bug 5378650
4170 */
4171 v_last_update_date DATE := pr_new.last_update_date;
4172 v_last_updated_by NUMBER := pr_new.last_updated_by;
4173 v_creation_date DATE := pr_new.creation_date;
4174 v_created_by NUMBER := pr_new.created_by;
4175 v_last_update_login NUMBER := pr_new.last_update_login;
4176 v_customer_trx_line_id NUMBER := pr_new.customer_trx_line_id;
4177 v_header_id NUMBER := pr_new.customer_trx_id;
4178 v_line_amount NUMBER := NVL(pr_new.quantity_credited * pr_new.unit_selling_price,0);
4179 v_interface_line_attribute7 VARCHAR2(30) := pr_new.interface_line_attribute6;
4180 v_quantity_credited NUMBER := pr_new.quantity_credited;
4181 /* --Ramananda for File.Sql.35, end */
4182
4183 x NUMBER := 0;
4184 v_organization_id NUMBER;
4185 v_location_id NUMBER;
4186 v_once_completed_flag VARCHAR2(1);
4187 v_excise_amount NUMBER := 0;
4188 v_trx_number VARCHAR2(30);
4189 v_tax_category_id NUMBER;
4190 v_payment_register VARCHAR2(15);
4191 v_excise_invoice_no NUMBER;
4192 v_excise_invoice_date DATE;
4193 v_tax_amount NUMBER := 0;
4194 v_assessable_value NUMBER := 0;
4195 v_basic_excise_duty_amount NUMBER := 0;
4196 v_add_excise_duty_amount NUMBER := 0;
4197 v_oth_excise_duty_amount NUMBER := 0;
4198 v_exist_flag NUMBER := 0;
4199 v_quantity NUMBER := 0;
4200 v_func_tax_amount NUMBER := 0;
4201 v_batch_source_id NUMBER ;
4202 v_books_id NUMBER;
4203 v_salesrep_id NUMBER;
4204 c_from_currency_code VARCHAR2(15);
4205 c_conversion_type VARCHAR2(30);
4206 c_conversion_date DATE;
4207 c_conversion_rate NUMBER;
4208 v_old_customer_trx_id NUMBER;
4209 v_line_count NUMBER := 0; -- added on 14-jun-01 by subbu
4210 ln_legal_entity_id NUMBER ; /* rallamse bug#4448789 */
4211 v_service_type VARCHAR2(30); -- added by csahoo for bug#5879769
4212
4213 -- cusrsor added to check duplication in JAI_AR_TRX_LINES for avoiding
4214 -- unique constraint violation
4215
4216 CURSOR DUPLICATE_LINES_CUR IS
4217 SELECT 1
4218 FROM JAI_AR_TRX_LINES
4219 WHERE customer_trx_LINE_id = v_customer_trx_line_id;
4220
4221 CURSOR OLD_CUSTOMER_TRX_ID_CUR IS
4222 SELECT Customer_Trx_Id
4223 FROM JAI_AR_TRX_LINES
4224 WHERE customer_trx_LINE_id = v_customer_trx_line_id;
4225
4226 CURSOR CREATED_FROM_CUR IS
4227 SELECT created_from, trx_number, batch_source_id, set_of_books_id, primary_salesrep_id,
4228 invoice_currency_code, exchange_rate_type, exchange_date, exchange_rate,
4229 legal_entity_id /* rallamse bug#4448789 */
4230 FROM ra_customer_trx_all
4231 WHERE customer_trx_id = v_header_id;
4232
4233
4234 -- following cursor definition modified by sriram - bug # 2755890 - 18/01/2003
4235 CURSOR SO_RMA_HDR_INFO IS
4236 SELECT organization_id, location_id
4237 FROM JAI_OM_WSH_LINES_ALL
4238 WHERE order_line_id IN
4239 (SELECT reference_line_id
4240 FROM oe_order_lines_all
4241 WHERE to_char(line_id) = v_interface_line_attribute7
4242 );
4243
4244 -- following cursor added by sriram -- bug # 2755890 to pick up the
4245 -- organization and location id based on the subinventory name
4246
4247 Cursor c_get_location is
4248 SELECT organization_id , location_id FROM JAI_INV_SUBINV_DTLS
4249 WHERE organization_id = pr_new.interface_line_attribute10
4250 AND UPPER(sub_inventory_name) IN
4251 (SELECT UPPER(subinventory)
4252 FROM rcv_transactions
4253 WHERE
4254 organization_id = pr_new.interface_line_attribute10
4255 AND (oe_order_line_id) = v_interface_line_attribute7
4256 AND subinventory IS NOT NULL
4257 );
4258
4259 -- ends here -- additions by sriram -- bug # 2755890
4260
4261
4262 /*
4263 ||Start of bug 4567935
4264 ||Added by Ramananda for the bug 4567935 (115 bug4404898)
4265 */
4266 CURSOR SO_RMA_LINES_INFO IS
4267 SELECT tax_category_id, assessable_value, service_type_code -- service_type_code added by csahoo for bug#5879769
4268 FROM JAI_OM_OE_RMA_LINES
4269 WHERE rma_line_id = v_interface_line_attribute7;
4270 /*
4271 ||End of bug 4567935
4272 */
4273 -- Date 23/02/2006 by sacsethi for bug 5228046
4274 -- precedence 6 to 10
4275 CURSOR SO_RMA_TAX_LINES_INFO IS
4276 SELECT A.tax_line_no, A.uom, A.tax_id, A.tax_rate, A.qty_rate, A.base_tax_amount, A.tax_amount, b.tax_type,
4277 A.func_tax_amount,
4278 A.precedence_1, A.precedence_2, A.precedence_3, A.precedence_4, A.precedence_5 ,
4279 A.precedence_6, A.precedence_7, A.precedence_8, A.precedence_9, A.precedence_10
4280 FROM JAI_OM_OE_RMA_TAXES A, JAI_CMN_TAXES_ALL b
4281 WHERE A.rma_line_id = v_interface_line_attribute7
4282 AND A.tax_id = b.tax_id
4283 and b.tax_type <> lc_modvat_tax/*Bug 4881426 bduvarag*/
4284 ORDER BY tax_line_no;
4285
4286
4287 CURSOR DUPLICATE_HDR_CUR IS
4288 SELECT 1
4289 FROM JAI_AR_TRXS
4290 WHERE customer_trx_id = v_header_id;
4291
4292
4293 /* Cursor To Check Whether Interfaced Record Exist in JAI_OM_WSH_LINES_ALL */
4294 CURSOR SO_RMA_RECORD_CHECK IS
4295 SELECT 1
4296 FROM JAI_OM_OE_RMA_LINES
4297 WHERE rma_line_id = v_interface_line_attribute7;
4298
4299
4300 CURSOR SO_RMA_TAX_RECORD_CHECK IS
4301 SELECT 1
4302 FROM JAI_OM_OE_RMA_TAXES
4303 WHERE rma_line_id = v_interface_line_attribute7;
4304
4305
4306 v_trans_type VARCHAR2(30);
4307 CURSOR transaction_type_cur IS
4308 SELECT A.TYPE
4309 FROM RA_CUST_TRX_TYPES_ALL A, RA_CUSTOMER_TRX_ALL b
4310 WHERE A.cust_trx_type_id = b.cust_trx_type_id
4311 AND b.customer_trx_id = v_header_id
4312 AND NVL(A.org_id,0) = NVL(pr_new.org_id,0);
4313
4314
4315 CURSOR SO_RMA_QUANTITY_CHECK IS
4316 SELECT NVL(quantity,0)
4317 FROM JAI_OM_OE_RMA_LINES
4318 WHERE rma_line_id = v_interface_line_attribute7;
4319
4320 /* bug 5243532. Added by Lakshmi Gopalsami
4321 Removed the reference to cursor set_of_books_cur
4322 as the SOB will never be null in base table.
4323 */
4324
4325 /*
4326 start additions by sriram - bug#3680721
4327 */
4328 cursor c_ont_source_code is
4329 select FND_PROFILE.VALUE('ONT_SOURCE_CODE')
4330 from dual;
4331 v_ont_source_code ra_interface_lines_all.interface_line_context%type;
4332 /*
4333 ends here additions by sriram -bug#3680721
4334 */
4335
4336 /*
4337 ||Code added by Ramananda for the bug 4567935 (115 bug4404898)
4338 ||Get the batch_source_id for the invoice corresponding to the credit memo.
4339 */
4340 CURSOR cur_get_transaction_type_id
4341 IS
4342 SELECT
4343 ott.transaction_type_id
4344 FROM
4345 ra_customer_trx_all rct,
4346 oe_transaction_types_tl ott
4347 WHERE
4348 rct.customer_trx_id = pr_new.previous_customer_trx_id
4349 /* bug 4926865. Added by Lakshmi Gopalsami
4350 Removed the upper as the data getting inserted into
4351 interface_header_attribute2 will be same as name in
4352 oe_transaction_types_tl
4353 */
4354 AND rct.interface_header_attribute2 = ott.name ;
4355
4356 /*added by csahoo for bug#6407648, start*/
4357 CURSOR cur_get_cmline_tax_amt
4358 IS
4359 SELECT
4360 nvl(sum(tax_amount),0)
4361 FROM
4362 JAI_AR_TRX_TAX_LINES
4363 WHERE
4364 link_to_cust_trx_line_id = pr_new.customer_trx_line_id ;
4365 /*added by csahoo for bug#6407648, end*/
4366
4367 ln_transaction_type_id OE_TRANSACTION_TYPES_TL.TRANSACTION_TYPE_ID%TYPE;
4368 ln_register_id JAI_OM_OE_BOND_REG_HDRS.REGISTER_ID%TYPE;
4369 lv_register_code JAI_OM_OE_BOND_REG_HDRS.REGISTER_CODE%TYPE;
4370 /*
4371 || End of bug4567935 (115 bug4404898)
4372 */
4373 BEGIN
4374 pv_return_code := jai_constants.successful ;
4375 /*------------------------------------------------------------------------------------------
4376 FILENAME: JA_IN_RMA_AR_LINES_INSERT_TRG.sql
4377
4378 CHANGE HISTORY:
4379
4380 S.No Date Author and Details
4381 ================================================================================================
4382 1. 2001/06/14 Subbu Code added to avoid unique constraint violation.
4383
4384 2. 2002/06/07 Ashish Shukla 2398850 INR check included in the code.(changes as per GSR)
4385
4386 3. 2002/09/11 Sriram Bug # 2461542. Added an if condition to check the duplicate taxes.
4387 This was happening was because when a RMA was done against a sales order
4388 that had discounts,the taxes were flowing as many times extra as the number
4389 of discounts. If a line has 2 discounts , then the taxes were getting tripled.
4390
4391 4 2002/11/22 Bug # 2668342 - replaced cursor using org_organization_definitions
4392 with nvl(operating_unit,0) causing performance problem
4393 and used the hr_operating_units table instead.
4394
4395 5 . 2003/01/09 Sriram - Bug # 2742849 - Version is 615.2
4396 This problem is about tax lines being inserted for discount line also. The earlier fix assumed
4397 that the discount line follows the item line by line number, that is they are consecutive
4398 lines. But this assumption is not correct and it depends on setup.
4399 Found out from base apps team that interface_line_attribute11 can be used to identify a
4400 discount line from the item line. For a Invoice line imported from OM , the
4401 interface_line_attribute11 will have a value 0 or Null , whereas for a discount line , the
4402 interface_line_attribute11 will have a value which maps to the price_adjustment_id.
4403
4404 6. 2003/01/18 Sriram - Bug # 2755890 - File Version 615.3
4405 When a credit memo created in AR because of a RMA Transaction is queried
4406 in the localization AR screen , it was causing no reords to be retreived.
4407 It is because , organization id and location id are not getting populated
4408 in the JAI_AR_TRXS table. This was because a cursor fetch was done incorrectly. The
4409 cursor definition has been corrected .
4410
4411 For RMA without reference , organization and location has to be fetched based on the subinventory
4412 chosen in the receiving transaction in Purchasing responsibility. Hence a new cursor is written
4413 to fetch the organization id , location id based on the subinventory name from the JAI_INV_SUBINV_DTLS
4414 table based on the subinventory name in the rcv transactions table.
4415
4416 7. 2003/04/18 Sriram - Bug # 2905912 - File Version 615.4
4417 For a RMA Transaction , the tax amount and total amount columns in the JAI_AR_TRXS
4418 table were incorrect. This has been corrected in this fix.
4419
4420 8. 2004/06/09 ssumaith - bug# 3680721 File Version 115.1
4421
4422 When autoinvoice import program imports a crdit memo from custom software and if interface_line_attribute11
4423 field in the ra_customer_trx_lines_all table is not null then , localization taxes are not retreived
4424 into the AR invoice.
4425
4426 This issue has been resolved by adding a context based check that interface_line_attribute11 field cannot be
4427 null for Order Entry as the source of the invoice for taxes to be imported , and other wise if the context is not
4428 Order Entry then the localisation taxes will be populated into the credit memo based on rma order.
4429
4430 9. 29/Nov/2004 Aiyer for bug#4035566. Version#115.1
4431 Issue:-
4432 The trigger should not get fired when the non-INR based set of books is attached to the current operating unit
4433 where transaction is being done.
4434
4435 Fix:-
4436 Function jai_cmn_utils_pkg.check_jai_exists is being called which returns the TRUE if the currency is INR and FALSE if the currency is
4437 NON-INR
4438 Also removed the cursors Fetch_Book_Id_Cur and Sob_cur and the variables v_gl_set_of_bks_id and v_currency_code and v_operating_id
4439
4440 Dependency Due to this Bug:-
4441 The current trigger becomes dependent on the function jai_cmn_utils_pkg.check_jai_exists version 115.0. introduced through the bug 4033992
4442
4443 10. 08-Jun-2005 This Object is Modified to refer to New DB Entity names in place of Old
4444 DB Entity as required for CASE COMPLAINCE. Version 116.1
4445
4446 11. 10-Jun-2005 File Version: 116.2
4447 Removal of SQL LITERALs is done
4448
4449 12. 10-Jun-2005 rallamse bug#4448789 116.3
4450 Added legal_entity_id for table JAI_AR_TRXS in insert statement
4451
4452 13. 26-07-2005 rallamse bug#4510143 120.2
4453 The legal_entity_id is derived from CREATED_FROM_CUR cursor based on ra_customer_trx_all.
4454
4455 14. 24-Aug-2005 Ramananda for bug #4567935 (115 bug 4404898, 4395450). File version 120.2
4456 Issue:-
4457 1. The following type of taxes should not be inserted into JAI_AR_TRX_LINES when Order type is BOND register:-
4458 'EXCISE', 'OTHER EXCISE', 'CVD_EDUCATION_CESS', 'EXCISE_EDUCATION_CESS'
4459
4460 2. Trigger currently processing Credit memo invoices with interface line context as LEGACY.This needs to be stopped
4461
4462 Fix:-
4463 1. Before a insert in the table JAI_AR_TRX_LINES, added a IF statement to bypass the insert into JAI_AR_TRX_LINES if
4464 the register code is 'BOND_REG' and any of the above stated taxes are present.
4465 2. Added the check to RETURN from the trigger if interface line context = 'LEGACY'
4466
4467 Dependency due to this bug :-
4468 Functional dependency with jai_ar_rctla_ari_t7 trigger of jai_fin_t.sql (120.2)
4469
4470 15. 20-Sep-2007 CSahoo for bug#6407648, file version 120.20
4471 Added the Cursor cur_get_cmline_tax_amt to get the line tax amount.
4472
4473 Future Dependencies For the release Of this Object:-
4474 (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/
4475 A datamodel change )
4476 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4477 Current Version Current Bug Dependent Files Version Author Date Remarks
4478 Of File On Bug/Patchset Dependent On
4479 ja_in_rma_ar_lines_insert_trg
4480 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4481 115.1 4035566 IN60105D2 + ja_in_util_pkg_s.sql 115.0 Aiyer 29-Nov-2004 Call to this function.
4482 4033992 ja_in_util_pkg_b.sql 115.0
4483
4484 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
4485
4486 /*
4487 || Code added by aiyer for the bug 4035566
4488 || Call the function jai_cmn_utils_pkg.check_jai_exists to check the current set of books in INR/NON-INR based.
4489 */
4490 --IF jai_cmn_utils_pkg.check_jai_exists ( p_calling_object => 'JA_IN_RMA_AR_LINES_INSERT_TRG' ,
4491 -- p_set_of_books_id => pr_new.set_of_books_id
4492 -- ) = FALSE
4493 -- THEN
4494 /*
4495 || return as the current set of books is NON-INR based
4496 */
4497 -- RETURN;
4498 --END IF;
4499
4500 /*
4501 || Start of bug #4567935 (115 bug4404898, 4395450,4404898)
4502 || Code added by Ramananda
4503 */
4504 IF pr_new.interface_line_context IN ('PROJECTS INVOICES','OKS CONTRACTS','LEGACY') THEN
4505 RETURN;
4506 END IF;
4507
4508
4509 -------------------------------------------------------------------------------------------------------
4510 OPEN transaction_type_cur;
4511 FETCH transaction_type_cur INTO v_trans_type;
4512 CLOSE transaction_type_cur;
4513
4514 IF NVL(v_trans_type,'N') <> 'CM' THEN
4515 RETURN;
4516 END IF;
4517
4518 OPEN CREATED_FROM_CUR;
4519 FETCH CREATED_FROM_CUR INTO v_created_from, v_trx_number, v_batch_source_id, v_books_id,
4520 v_salesrep_id, c_from_currency_code, c_conversion_type,
4521 c_conversion_date, c_conversion_rate, ln_legal_entity_id ; /* rallamse bug#4448789 */
4522 CLOSE CREATED_FROM_CUR;
4523
4524 IF v_created_from <> 'RAXTRX' THEN
4525 RETURN;
4526 END IF;
4527
4528 OPEN DUPLICATE_HDR_CUR;
4529 FETCH DUPLICATE_HDR_CUR INTO x;
4530 CLOSE DUPLICATE_HDR_CUR;
4531
4532 OPEN SO_RMA_RECORD_CHECK;
4533 FETCH SO_RMA_RECORD_CHECK INTO v_exist_flag;
4534 CLOSE SO_RMA_RECORD_CHECK;
4535
4536 fnd_file.put_line(FND_FILE.LOG, ' RMA record chk:'|| v_exist_flag);
4537
4538 IF NVL(v_exist_flag,0) <> 1 THEN
4539 RETURN;
4540 END IF;
4541
4542 IF NVL(x,0) <> 1 THEN
4543 OPEN SO_RMA_HDR_INFO;
4544 FETCH SO_RMA_HDR_INFO INTO v_organization_id, v_location_id;
4545 CLOSE SO_RMA_HDR_INFO;
4546
4547 -- added by sriram -- bug # 2755890
4548 if v_location_id is null then
4549 Begin
4550 Open c_get_location;
4551 Fetch c_get_location into v_organization_id, v_location_id;
4552 Close c_get_location;
4553 Exception
4554 -- adding the exception section so that this should not cause control flow
4555 -- to halt.If it hits the exception , the maximum effect is that organization
4556 -- and location id will not get fetched .. that will happen only for
4557 -- rma without refernec .. but for rma with reference it will go thru fine.
4558 When others then
4559 Null;
4560 End;
4561 end if;
4562
4563 -- ends here additions by sriram - bug # 2755890
4564 /* Bug 5243532. Added by Lakshmi Gopalsami
4565 Removed the reference to cursor set_of_books_cur.
4566 */
4567
4568 IF NVL(pr_new.Interface_line_attribute11,'0') = '0'
4569 and (nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - bug#3680721
4570 ) /* following OR added by sriram - bug#3680721 */
4571 or
4572 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug#3680721
4573 )
4574 then
4575 INSERT INTO JAI_AR_TRXS
4576 (
4577 Customer_Trx_ID,
4578 Organization_ID,
4579 Location_ID,
4580 Trx_Number,
4581 Update_RG_Flag,
4582 Once_Completed_Flag,
4583 Batch_Source_ID,
4584 Set_Of_Books_ID,
4585 Primary_Salesrep_ID,
4586 Invoice_Currency_Code,
4587 Exchange_Rate_Type,
4588 Exchange_Date,
4589 Exchange_Rate,
4590 Created_From,
4591 creation_date,
4592 created_by,
4593 last_update_date,
4594 last_updated_by,
4595 last_update_login,
4596 legal_entity_id /* rallamse bug#4448789 */
4597 )
4598 VALUES
4599 (
4600 v_header_id,
4601 v_organization_id,
4602 v_location_id,
4603 v_trx_number,
4604 'Y',
4605 'Y',
4606 v_batch_source_id,
4607 v_books_id,
4608 v_salesrep_id,
4609 c_from_currency_code,
4610 c_conversion_type,
4611 c_conversion_date,
4612 c_conversion_rate,
4613 v_created_from,
4614 v_creation_date,
4615 v_created_by,
4616 v_last_update_date,
4617 v_last_updated_by,
4618 v_last_update_login,
4619 ln_legal_entity_id /* rallamse bug#4448789 */
4620 );
4621 END If;
4622 END IF;
4623
4624 OPEN SO_RMA_TAX_RECORD_CHECK;
4625 FETCH SO_RMA_TAX_RECORD_CHECK INTO v_exist_flag;
4626 CLOSE SO_RMA_TAX_RECORD_CHECK;
4627
4628
4629 IF NVL(v_exist_flag,0) <> 1 THEN
4630 RETURN;
4631 END IF;
4632
4633 OPEN SO_RMA_QUANTITY_CHECK;
4634 FETCH SO_RMA_QUANTITY_CHECK INTO v_quantity;
4635 CLOSE SO_RMA_QUANTITY_CHECK;
4636
4637 /*
4638 || Added by Ramananda for bug#4567935 (115 bug 4404898) , Start
4639 */
4640 OPEN cur_get_transaction_type_id ;
4641 FETCH cur_get_transaction_type_id INTO ln_transaction_type_id;
4642 CLOSE cur_get_transaction_type_id ;
4643
4644 jai_cmn_bond_register_pkg.get_register_id(
4645 v_organization_id ,
4646 v_location_id ,
4647 ln_transaction_type_id ,
4648 'Y' ,
4649 ln_register_id ,
4650 lv_register_code
4651 );
4652 /*
4653 || Added by Ramananda for bug#4567935 (115 bug 4404898) , End
4654 */
4655
4656 FOR Tax_Rec IN SO_RMA_TAX_LINES_INFO LOOP
4657 v_func_tax_amount := NVL((Tax_Rec.func_tax_amount * v_quantity_credited) / v_quantity,0);
4658
4659 IF NVL(pr_new.Interface_line_attribute11,'0') ='0'
4660 and (nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - --bug#3680721
4661 ) /* following OR added by sriram - bug#3680721 */
4662 or
4663 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug#3680721
4664 )
4665 then
4666 -- Date 23/02/2006 by sacsethi for bug 5228046
4667 -- precedence 6 to 10
4668 INSERT INTO JAI_AR_TRX_TAX_LINES
4669 (
4670 tax_line_no,
4671 customer_trx_line_id,
4672 link_to_cust_trx_line_id,
4673 precedence_1,
4674 precedence_2,
4675 precedence_3,
4676 precedence_4,
4677 precedence_5,
4678 precedence_6,
4679 precedence_7,
4680 precedence_8,
4681 precedence_9,
4682 precedence_10,
4683 tax_id,
4684 tax_rate,
4685 qty_rate,
4686 uom,
4687 tax_amount,
4688 func_tax_amount,
4689 base_tax_amount,
4690 creation_date,
4691 created_by,
4692 last_update_date,
4693 last_updated_by,
4694 last_update_login
4695 )
4696 VALUES(
4697 Tax_Rec.tax_line_no,
4698 ra_customer_trx_lines_s.NEXTVAL,
4699 v_customer_trx_line_id,
4700 Tax_Rec.precedence_1,
4701 Tax_Rec.precedence_2,
4702 Tax_Rec.precedence_3,
4703 Tax_Rec.precedence_4,
4704 Tax_Rec.precedence_5,
4705 Tax_Rec.precedence_6,
4706 Tax_Rec.precedence_7,
4707 Tax_Rec.precedence_8,
4708 Tax_Rec.precedence_9,
4709 Tax_Rec.precedence_10,
4710 Tax_Rec.tax_id,
4711 Tax_Rec.tax_rate,
4712 Tax_Rec.qty_rate,
4713 Tax_Rec.uom,
4714 NVL((Tax_Rec.tax_amount * v_quantity_credited) / v_quantity,0),
4715 v_func_tax_amount,
4716 NVL((Tax_Rec.base_tax_amount * v_quantity_credited) / v_quantity,0),
4717 v_creation_date,
4718 v_created_by,
4719 v_last_update_date,
4720 v_last_updated_by,
4721 v_last_update_login
4722 );
4723 end if;
4724
4725 v_excise_amount := NVL(v_excise_amount,0) + NVL(v_func_tax_amount,0);
4726 END LOOP;
4727
4728
4729 OPEN DUPLICATE_LINES_CUR;
4730 FETCH DUPLICATE_LINES_CUR INTO v_line_count;
4731 CLOSE DUPLICATE_LINES_CUR;
4732
4733
4734 IF NVL(v_line_count,0) <> 1 THEN
4735 OPEN SO_RMA_LINES_INFO;
4736 /*
4737 || Code modified by Ramananda for the bug 4567935 (115 bug4404898)
4738 || FETCH SO_RMA_LINES_INFO INTO v_tax_category_id, v_tax_amount, v_assessable_value;
4739 */
4740 FETCH SO_RMA_LINES_INFO INTO v_tax_category_id, v_assessable_value,v_service_type;/*5879769*/
4741 CLOSE SO_RMA_LINES_INFO;
4742
4743 /*added by csahoo for bug#6407648,start*/
4744 OPEN cur_get_cmline_tax_amt;
4745 FETCH cur_get_cmline_tax_amt INTO v_tax_amount;
4746 CLOSE cur_get_cmline_tax_amt ;
4747 /*added by csahoo for bug#6407648,end*/
4748
4749 IF NVL(pr_new.Interface_line_attribute11,'0') ='0'
4750 and (nvl(v_ont_source_code,'ORDER ENTRY') = ltrim(rtrim(pr_new.interface_line_context)) -- added by sriram - --bug#3680721
4751 ) /* following OR added by sriram - bug#3680721 */
4752 or
4753 (nvl(v_ont_source_code,'ORDER ENTRY') <> nvl(ltrim(rtrim(pr_new.interface_line_context)),'$$$') -- added by sriram - bug#3680721
4754 )
4755 then
4756 v_tax_amount := NVL((v_tax_amount * abs(v_quantity_credited)) / v_quantity,0); -- added abs(v_quantity_credited) for bug #6407648
4757 ELSE
4758 v_tax_amount :=0;
4759 END IF;
4760
4761
4762 INSERT INTO JAI_AR_TRX_LINES
4763 (customer_trx_line_id,
4764 line_number,
4765 customer_trx_id,
4766 description,
4767 inventory_item_id,
4768 unit_code,
4769 quantity,
4770 tax_category_id,
4771 auto_invoice_flag,
4772 unit_selling_price,
4773 line_amount,
4774 tax_amount,
4775 total_amount,
4776 assessable_value,
4777 creation_date,
4778 created_by,
4779 last_update_date,
4780 last_updated_by,
4781 last_update_login,
4782 service_type_code -- added by csahoo for bug#5879769
4783 )
4784 VALUES(
4785 v_customer_trx_line_id,
4786 pr_new.line_number,
4787 v_header_id,
4788 pr_new.description,
4789 pr_new.inventory_item_id,
4790 pr_new.uom_code,
4791 pr_new.quantity_credited,
4792 v_tax_category_id,
4793 'Y',
4794 pr_new.unit_selling_price,
4795 v_line_amount,
4796 v_tax_amount,
4797 (v_line_amount + v_tax_amount),
4798 v_assessable_value,
4799 v_creation_date,
4800 v_created_by,
4801 v_last_update_date,
4802 v_last_updated_by,
4803 v_last_update_login,
4804 v_service_type -- added by csahoo for bug#5879769
4805 );
4806 ELSE
4807 OPEN OLD_CUSTOMER_TRX_ID_CUR;
4808 FETCH OLD_CUSTOMER_TRX_ID_CUR INTO v_old_customer_trx_id;
4809 CLOSE OLD_CUSTOMER_TRX_ID_CUR;
4810
4811 DELETE JAI_AR_TRX_INS_LINES_T
4812 WHERE Customer_Trx_Line_Id = v_customer_trx_line_id;
4813
4814 IF v_old_customer_trx_id <> v_header_id THEN
4815 UPDATE JAI_AR_TRX_LINES
4816 SET Customer_Trx_Id = v_header_id
4817 WHERE Customer_Trx_Line_Id = v_customer_trx_line_id;
4818
4819 DELETE JAI_AR_TRXS
4820 WHERE customer_trx_id = v_old_customer_trx_id;
4821 END IF;
4822 END IF; -- end if for the modification by subbu on 14-jun-01
4823
4824 UPDATE JAI_AR_TRXS
4825 SET line_amount = NVL(line_amount, 0 ) + NVL(v_line_amount,0),
4826 tax_amount = NVL(tax_amount,0) + NVL(v_excise_amount,0),
4827 total_amount = NVL(total_amount,0) + NVL(v_line_amount,0) + NVL(v_excise_amount,0)
4828 WHERE customer_trx_id = v_header_id;
4829 /* Added an exception block by Ramananda for bug#4570303 */
4830 EXCEPTION
4831 WHEN OTHERS THEN
4832 Pv_return_code := jai_constants.unexpected_error;
4833 Pv_return_message := 'Encountered an error in JAI_AR_RCTLA_TRIGGER_PKG.ARI_T3 ' || substr(sqlerrm,1,1900);
4834 END ARI_T3 ;
4835
4836 /*
4837 REM +======================================================================+
4838 REM NAME ARIU_T1
4839 REM
4840 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
4841 REM
4842 REM NOTES Refers to old trigger JAI_AR_RCTLA_ARIU_T4
4843 REM
4844 REM +======================================================================+
4845 */
4846 PROCEDURE ARIU_T1 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
4847 v_customer_id Number ;
4848 v_address_id Number ;
4849 v_org_id Number := 0;
4850 v_header_id Number; -- := pr_new.customer_trx_id; --Ramananda for File.Sql.35
4851 v_ship_to_site_use_id Number := 0;
4852 v_inventory_item_id Number; -- := pr_new.inventory_item_id; --Ramananda for File.Sql.35
4853 v_tax_category_list varchar2(30);
4854 v_tax_category_id Number;
4855 v_item_class varchar2(30); -- := 'N'; --Ramananda for File.Sql.35
4856 v_line_amount number :=0 ;
4857 v_line_no Number;
4858 v_tax_id Number;
4859 v_tax_rate Number;
4860 v_tax_amount Number;
4861 v_line_tax_amount Number := 0;
4862 v_uom_code varchar2(3); -- := pr_new.uom_code; --Ramananda for File.Sql.35
4863 v_tax_tot Number := 0;
4864 v_tot_amt Number := 0;
4865 v_excise Number := 0;
4866 v_additional Number := 0;
4867 v_other Number := 0;
4868 v_hdr_tax_amount Number := 0;
4869 v_hdr_total_amount Number := 0;
4870 v_price_list Number := 0;
4871 v_price_list_val Number := 0;
4872 v_price_list_uom_code Varchar2(3);
4873 v_conversion_rate Number := 0;
4874 v_organization_id Number := -1;
4875 v_row_id Rowid;
4876 v_customer_trx_line_id Number; -- := pr_new.customer_trx_line_id; --Ramananda for File.Sql.35
4877 v_once_completed_flag Varchar2(1);
4878 v_old_line_amount Number := 0;
4879 v_old_tax_tot Number := 0;
4880 v_created_from Varchar2(30);
4881 c_from_currency_code Varchar2(15);
4882 c_conversion_type Varchar2(30);
4883 c_conversion_date Date;
4884 c_conversion_rate Number := 0;
4885 v_converted_rate Number := 1;
4886 v_books_id Number;
4887 v_gl_date Date;
4888 -- Date 26-feb-2006 added by sacsethi for bug 5631784
4889 ln_tcs_exists number;
4890 ln_tcs_regime_id JAI_RGM_DEFINITIONS.regime_id%type;
4891 ln_threshold_slab_id JAI_AP_TDS_THHOLD_SLABS.threshold_slab_id%type;
4892 ln_threshold_tax_cat_id JAI_AP_TDS_THHOLD_TAXES.tax_category_id%type;
4893 ld_gl_dist_date date;
4894 v_service_type VARCHAR2(30); -- added by csahoo for bug#5879769
4895
4896 cursor c_gl_dist_date ( cp_customer_trx_id ra_customer_trx_all.customer_trx_id%type)
4897 is
4898 select gl_date
4899 from ra_cust_trx_line_gl_dist_all
4900 where customer_trx_id = cp_customer_trx_id
4901 and account_class = jai_constants.account_class_rec
4902 and latest_rec_flag = jai_constants.yes;
4903
4904 CURSOR GC_GET_REGIME_ID (CP_REGIME_CODE JAI_RGM_DEFINITIONS.REGIME_CODE%TYPE)
4905 IS
4906 SELECT REGIME_ID
4907 FROM JAI_RGM_DEFINITIONS
4908 WHERE REGIME_CODE = CP_REGIME_CODE;
4909 CURSOR GC_CHK_RGM_TAX_EXISTS ( CP_REGIME_CODE JAI_RGM_DEFINITIONS.REGIME_CODE%TYPE
4910 , CP_RGM_TAX_TYPE JAI_CMN_TAXES_ALL.TAX_TYPE%TYPE
4911 , CP_TAX_CATEGORY_ID JAI_CMN_TAX_CTGS_ALL.TAX_CATEGORY_ID%TYPE
4912 )
4913 IS
4914 SELECT COUNT(1)
4915 FROM JAI_CMN_TAX_CTG_LINES CATL
4916 ,JAI_CMN_TAXES_ALL CODES
4917 ,JAI_REGIME_TAX_TYPES_V JRTTV
4918 WHERE CATL.TAX_CATEGORY_ID = CP_TAX_CATEGORY_ID
4919 AND CATL.TAX_ID = CODES.TAX_ID
4920 AND CODES.TAX_TYPE = JRTTV.TAX_TYPE
4921 AND JRTTV.REGIME_CODE = CP_REGIME_CODE;
4922 -- END 5631784
4923
4924
4925 /* --Ramananda for File.Sql.35, START */
4926 v_last_update_date Date; -- := pr_new.last_update_date;
4927 v_last_updated_by Number; -- := pr_new.last_updated_by;
4928 v_creation_date Date ; -- := pr_new.creation_date;
4929 v_created_by Number; -- := pr_new.created_by;
4930 v_last_update_login Number; -- := pr_new.last_update_login;
4931 /* --Ramananda for File.Sql.35, END */
4932
4933 v_trx_date Date;
4934 v_total_tax_amount Number :=0;
4935 v_line_type varchar2(20); -- := pr_new.LINE_TYPE; --Ramananda for File.Sql.35
4936 V_DEBUG_VAR VARCHAR2(1996);
4937 VAR_REC_CTR NUMBER :=0;
4938 VAR_SQLERRM VARCHAR2(240);
4939 v_trans_type Varchar2(30);
4940 v_quantity number; -- It holds the quantity_invoiced in case of 'INV' and quantity_credited in case of 'CM' -- added ssumaith - bug# 3957682
4941
4942 -- Date 26-feb-2006 added by sacsethi for bug 5631784
4943 lv_process_flag VARCHAR2(2);
4944 lv_process_message VARCHAR2(1996);
4945 -- date 5631784
4946 Cursor bind_cur IS
4947 SELECT A.org_id,
4948 A.ship_to_customer_id,
4949 NVL(A.ship_to_site_use_id,0)
4950 FROM RA_CUSTOMER_TRX_ALL A
4951 WHERE customer_trx_id = v_header_id;
4952
4953
4954 Cursor header_info_cur IS
4955 SELECT set_of_books_id,
4956 invoice_currency_code,
4957 exchange_rate_type,
4958 exchange_date,
4959 exchange_rate, trx_date
4960 FROM RA_CUSTOMER_TRX_ALL
4961 WHERE customer_trx_id = v_header_id;
4962
4963 Cursor address_cur(p_ship_to_site_use_id IN Number) IS
4964 SELECT cust_acct_site_id address_id
4965 FROM HZ_CUST_SITE_USES_ALL A /* Removed ra_site_uses_all for Bug# 4434287 */
4966 WHERE A.site_use_id = NVL(p_ship_to_site_use_id,0);
4967
4968 CURSOR excise_cal_cur IS
4969 SELECT A.tax_id, A.tax_rate, A.tax_amount tax_amt,b.tax_type t_type
4970 FROM JAI_AR_TRX_TAX_LINES A , JAI_CMN_TAXES_ALL B
4971 WHERE link_to_cust_trx_line_id = v_customer_trx_line_id
4972 AND A.tax_id = B.tax_id
4973 ORDER BY 1;
4974
4975
4976 /*
4977 || Commented, Ramananda for bug #4567935 (115 bug3671351)
4978 */
4979 /*
4980 CURSOR price_list_cur(p_customer_id IN Number,p_inventory_item_id IN Number,
4981 p_address_id IN Number DEFAULT 0,v_uom_code VARCHAR2, p_trx_date DATE) IS
4982 SELECT A.list_price, a.unit_code
4983 FROM so_price_list_lines A, JAI_CMN_CUS_ADDRESSES B
4984 WHERE A.price_list_id = B.price_list_id
4985 AND B.customer_id = p_customer_id
4986 AND B.address_id = p_address_id
4987 AND A.inventory_item_id = p_inventory_item_id
4988 AND a.unit_code = v_uom_code
4989 AND NVL(a.end_date_active,SYSDATE) >= p_trx_date;
4990 */
4991
4992
4993 CURSOR ORG_CUR IS
4994 SELECT organization_id
4995 FROM JAI_AR_TRX_APPS_RELS_T ;/*altered by rchandan for bug#4479131*/
4996
4997 CURSOR organization_cur IS
4998 SELECT A.organization_id
4999 FROM JAI_AR_TRXS A, RA_CUSTOMER_TRX_ALL B
5000 WHERE A.trx_number = B.recurred_from_trx_number AND B.customer_trx_id = v_header_id;
5001
5002 CURSOR CREATED_FROM_CUR IS
5003 SELECT created_from , trx_date
5004 FROM ra_customer_trx_all
5005 WHERE customer_trx_id = v_header_id;
5006
5007 ld_trx_date ra_customer_trx_all.trx_Date%type;
5008
5009 CURSOR ONCE_COMPLETE_FLAG_CUR IS
5010 SELECT once_completed_flag
5011 FROM JAI_AR_TRXS
5012 WHERE customer_trx_id = v_header_id;
5013
5014 CURSOR ROW_ID_CUR IS
5015 SELECT rowid
5016 FROM RA_CUSTOMER_TRX_ALL
5017 WHERE customer_trx_id = v_header_id;
5018
5019 CURSOR old_line_amount_cur IS
5020 SELECT line_amount
5021 FROM JAI_AR_TRX_LINES
5022 WHERE CUSTOMER_TRX_ID = pr_old.CUSTOMER_TRX_ID
5023 AND CUSTOMER_TRX_LINE_ID = pr_old.CUSTOMER_TRX_LINE_ID;
5024
5025 CURSOR gl_date_cur IS
5026 SELECT DISTINCT gl_date
5027 FROM RA_CUST_TRX_LINE_GL_DIST_ALL
5028 WHERE CUSTOMER_TRX_LINE_ID = v_customer_trx_line_id;
5029
5030
5031 Cursor transaction_type_cur IS
5032 Select a.type
5033 From RA_CUST_TRX_TYPES_ALL a, RA_CUSTOMER_TRX_ALL b
5034 Where a.cust_trx_type_id = b.cust_trx_type_id
5035 And b.customer_trx_id = v_header_id
5036 And NVL(a.org_id,0) = NVL(pr_new.org_id,0);
5037
5038 ln_vat_assessable_value JAI_AR_TRX_LINES.VAT_ASSESSABLE_VALUE%TYPE;
5039
5040 /* Added by Ramananda as a part of removal of SQL LITERALs , start */
5041 lv_appl_src JAI_CMN_ERRORS_T.APPLICATION_SOURCE%type ;
5042 lv_add_err JAI_CMN_ERRORS_T.additional_error_mesg%type ;
5043 BEGIN
5044 pv_return_code := jai_constants.successful ;
5045 /* This Trigger fires , when you insert a record in RA_CUSTOMER_TRX_LINES_ALL */
5046
5047 /*------------------------------------------------------------------------------------------
5048 FILENAME: JA_IN_AR_LINES_INSERT_TRG.sql
5049 CHANGE HISTORY:
5050
5051 S.No Date Author and Details
5052 --------------------------------------------------------------------------------------------
5053 1. 2001/06/22 Anuradha Parthasarathy
5054 Code commented and added to improve performance.
5055
5056 2. 2003/03/12 Sriram - Bug # 2846277 - File Version 615.1
5057
5058 In case where seup business group setup is done , inventory organization is a value 0.
5059 This was causing the trigger to return because of code comparison . Hence changed the
5060 comparison to a large value such as 999999
5061
5062 3. 2004/10/17 ssumaith - bug# 3957682 - file version 115.1
5063
5064 Tax defaultation was not happening for a manual credit memo created without reference to
5065 an invoice.
5066 Added code in the trigger to ensure that code does not return when the transaction type is
5067 either 'INV' or 'CM'. Earlier the check was for 'INV' only.
5068
5069 4. 29-nov-2004 ssumaith - bug# 4037690 - File version 115.2
5070 Check whether india localization is being used was done using a INR check in every trigger.
5071 This check has now been moved into a new package and calls made to this package from this trigger
5072 If the function jai_cmn_utils_pkg.check_jai_exists returns true it means INR is the set of books currency ,
5073 Hence if this function returns FALSE , control should return
5074
5075 5. 16/Mar/05 ssumaith - bug# 4245053 file version 115.3
5076
5077 uptake of the vat assessable value has been done in this trigger.
5078 A call to the jai_general_pkg.JA_IN_VAT_ASSESSABLE_VALUE has been made passing the parameters
5079 to get the vat assessable value to the tax calculation routines and update the vat assessable
5080 value in the JAI_OM_OE_SO_LINES table.
5081
5082 This vat assessable value is sent as an additional parameter to the various procedures
5083 such as jai_om_tax_pkg.recalculate_oe_taxes , jai_cmn_tax_defaultation_pkg.ja_in_calc_prec_taxes
5084
5085 Hence, its mandatory that with this object all the other objects in this patch as well as the base bug
5086 need to be sent.
5087
5088 VAt assessable value , vat exemption related columns (type , refno and date) have also been copied
5089 from the source line in the case of a copy order / split scenario.
5090
5091 Dependency due to this bug - Huge
5092 This patch should always be accompanied by the VAT consolidated patch - 4245089
5093
5094 6. 08-Jun-2005 File Version 116.1. This Object is Modified to refer to New DB Entity names in place of Old
5095 DB Entity as required for CASE COMPLAINCE.
5096
5097 7. 10-Jun-2005 File Version: 116.2
5098 Removal of SQL LITERALs is done
5099
5100 8. 8-Jul-2005 rchandan for bug#4479131. File Version: 116.3
5101 The object is modified to eliminate the paddr usage.
5102
5103 9. 23-Aug-2005 Ramananda for bug#4567935 (115 bug3671351). File version 120.2
5104
5105 Problem
5106 -------
5107 Excise taxes not getting calculated on assessable price in AR INVOICE.
5108
5109 Fix
5110 ---
5111 Commented the code to calculate the assessable price and added a call
5112 to the jai_om_utils_pkg.get_oe_assessable_value function to calculate the assessable price
5113 correctly through various levels of defaultation.
5114
5115 10. 12-Nov-2008 CSahoo for bug#6012465, File Version 120.7.12000000.8
5116 Issue: ASSESSABLE PRICE FOR ITEMS DOES NOT APPEAR IN AR
5117 Reason: While creation of Manual Invoices, attachment of Item / Tax category list is checked before the
5118 calculation of excise / vat assessable value. If any category list is not attached,
5119 assessable value is shown as zero.
5120 Fix: Tax Category check is moved after the calculation of excise and vat assessable value.
5121
5122 Future Dependencies For the release Of this Object:-
5123 (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/
5124 A datamodel change )
5125 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5126 Current Version Current Bug Dependent Files Version Author Date Remarks
5127 Of File On Bug/Patchset Dependent On
5128
5129 ja_in_ar_lines_insert_trg.sql
5130 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5131 115.2 4037690 IN60105D2 ja_in_util_pkg_s.sql 115.0 ssumaith 29-Nov-2004 Call to this function.
5132 ja_in_util_pkg_s.sql 115.0 ssumaith
5133
5134 115.3 4245053 IN60106 + ssumaith Service Tax and VAT Infrastructure are created
5135 4146708 + based on the bugs - 4146708 and 4545089 respectively.
5136 4245089
5137
5138 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
5139
5140 /* --Ramananda for File.Sql.35, start */
5141 v_header_id := pr_new.customer_trx_id;
5142 v_inventory_item_id := pr_new.inventory_item_id;
5143 v_item_class := 'N';
5144 v_uom_code := pr_new.uom_code;
5145 v_customer_trx_line_id := pr_new.customer_trx_line_id;
5146 v_last_update_date := pr_new.last_update_date;
5147 v_last_updated_by := pr_new.last_updated_by;
5148 v_creation_date := pr_new.creation_date;
5149 v_created_by := pr_new.created_by;
5150 v_last_update_login := pr_new.last_update_login;
5151 v_line_type := pr_new.LINE_TYPE;
5152 ------------------
5153 /* --Ramananda for File.Sql.35, end */
5154
5155 /*The following code has added - ssumaith - bug# 4037690*/
5156 --If jai_cmn_utils_pkg.check_jai_exists(P_CALLING_OBJECT => 'JA_IN_AR_LINES_INSERT_TRG', P_ORG_ID => pr_new.ORG_ID) = false then
5157 -- return;
5158 --end if;
5159
5160 OPEN transaction_type_cur;
5161 FETCH transaction_type_cur INTO v_trans_type;
5162 CLOSE transaction_type_cur;
5163
5164 IF NVL(v_trans_type,'N') Not in ( 'INV','CM') THEN -- 'CM' added ssumaith - bug# 3957682
5165 Return;
5166 END IF;
5167
5168
5169 IF NVL(v_trans_type,'N') = 'INV' then
5170 v_line_amount := nvl(pr_new.quantity_invoiced * pr_new.unit_selling_price,0);
5171 v_quantity := pr_new.quantity_invoiced; -- added ssumaith - bug# 3957682
5172 elsif NVL(v_trans_type,'N') = 'CM' then
5173 v_line_amount := nvl(pr_new.quantity_credited * pr_new.unit_selling_price,0);
5174 v_quantity := pr_new.quantity_credited; -- added ssumaith - bug# 3957682
5175 end if;
5176
5177 OPEN ONCE_COMPLETE_FLAG_CUR;
5178 FETCH ONCE_COMPLETE_FLAG_CUR INTO v_once_completed_flag;
5179 CLOSE ONCE_COMPLETE_FLAG_CUR;
5180 IF NVL(v_once_completed_flag,'N') = 'Y' THEN
5181 RETURN;
5182 END IF;
5183
5184 OPEN CREATED_FROM_CUR;
5185 FETCH CREATED_FROM_CUR INTO v_created_from , ld_trx_date;
5186 CLOSE CREATED_FROM_CUR;
5187 IF v_created_from in ('ARXREC','RAXTRX') THEN
5188 RETURN;
5189 END IF;
5190 IF v_created_from = 'ARXTWMAI' THEN
5191 OPEN ORG_CUR;
5192 FETCH ORG_CUR INTO v_organization_id;
5193 CLOSE ORG_CUR;
5194 IF NVL(v_organization_id,999999) = 999999 THEN -- made 0 to 999999 because in case of setup business group setup , inventory organization value is 0
5195 OPEN organization_cur; -- which was causing code to return .- bug # 2846277
5196 FETCH organization_cur INTO v_organization_id;
5197 CLOSE organization_cur;
5198 /*ELSE
5199 OPEN ROW_ID_CUR;
5200 FETCH ROW_ID_CUR INTO v_row_id;
5201 CLOSE ROW_ID_CUR;
5202 jai_cmn_utils_pkg.JA_IN_SET_LOCATOR('JAINARTX',v_row_id);*//*commented by rchandan for bug#4479131*/
5203 END IF;
5204 IF NVL(v_organization_id,999999) = 999999 THEN -- -- made 0 to 999999 because in case of setup business group setup , inventory organization value is 0
5205 RETURN;
5206 END IF;
5207 OPEN bind_cur;
5208 FETCH bind_cur INTO v_org_id, v_customer_id, v_ship_to_site_use_id ;
5209 CLOSE bind_cur;
5210 IF pr_new.inventory_item_id <> pr_old.inventory_item_id THEN
5211 FOR excise_cal_rec in excise_cal_cur
5212 LOOP
5213 IF excise_cal_rec.t_type IN ('Excise') THEN
5214 v_excise := nvl(v_excise,0) + nvl(excise_cal_rec.tax_amt,0);
5215 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
5216 v_additional := nvl(v_additional,0) + nvl(excise_cal_rec.tax_amt,0);
5217 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
5218 v_other := nvl(v_other,0) + nvl(excise_cal_rec.tax_amt,0);
5219 END IF;
5220 END LOOP;
5221 v_old_tax_tot := nvl(v_excise,0) + nvl(v_other,0) + nvl(v_additional,0);
5222 OPEN old_line_amount_cur;
5223 FETCH old_line_amount_cur INTO v_old_line_amount;
5224 CLOSE old_line_amount_cur;
5225 UPDATE JAI_AR_TRXS
5226 SET line_amount = nvl(line_amount,0) - nvl(v_old_line_amount,0),
5227 tax_amount = nvl(tax_amount,0) - nvl(v_old_tax_tot,0),
5228 total_amount = nvl(total_amount,0) - (nvl(v_old_line_amount,0) + nvl(v_old_tax_tot,0))
5229 WHERE customer_trx_id = pr_old.CUSTOMER_TRX_ID;
5230
5231 DELETE JAI_AR_TRX_TAX_LINES
5232 WHERE LINK_TO_CUST_TRX_LINE_ID = pr_old.CUSTOMER_TRX_LINE_ID;
5233
5234 DELETE JAI_AR_TRX_LINES
5235 WHERE CUSTOMER_TRX_ID = pr_old.CUSTOMER_TRX_ID
5236 AND CUSTOMER_TRX_LINE_ID = pr_old.CUSTOMER_TRX_LINE_ID;
5237 END IF;
5238
5239 OPEN HEADER_INFO_CUR;
5240 FETCH HEADER_INFO_CUR INTO v_books_id, c_from_currency_code, c_conversion_type, c_conversion_date,
5241 c_conversion_rate, v_trx_date;
5242 CLOSE HEADER_INFO_CUR;
5243
5244 OPEN address_cur(v_ship_to_site_use_id);
5245 FETCH address_cur INTO v_address_id;
5246 CLOSE address_cur;
5247
5248 IF v_customer_id IS NOT NULL AND v_address_id IS NOT NULL THEN
5249 jai_cmn_tax_defaultation_pkg.ja_in_cust_default_taxes(
5250 v_organization_id ,
5251 v_customer_id,
5252 v_ship_to_site_use_id ,
5253 v_inventory_item_id ,
5254 v_header_id ,
5255 v_customer_trx_line_id,
5256 v_tax_category_id
5257 );
5258 ELSE
5259 jai_cmn_tax_defaultation_pkg.ja_in_org_default_taxes(
5260 v_organization_id ,
5261 v_inventory_item_id ,
5262 v_tax_category_id
5263 );
5264 END IF;
5265 -- bug#6012465. Moved the following if statement after assessable_value calculations
5266 --IF v_tax_category_id IS NOT NULL THEN
5267
5268 /*
5269 ||Start of bug #4567935 (115 bug3671351)
5270 ||Code added, Ramananda for bug #4567935 (115 bug3671351), Start
5271 ||Instead of deriving the assessable valeu in this trigger,
5272 ||the same has been now shifted to the function jai_om_utils_pkg.get_oe_assessable_value
5273 ||The function gets the assessable value based on 5 level defaultation
5274 ||logic.Currently the assessable value was being fetched only from the so_price_list_lines
5275 */
5276
5277 v_price_list := jai_om_utils_pkg.get_oe_assessable_value
5278 (
5279 p_customer_id => v_customer_id,
5280 p_ship_to_site_use_id => v_ship_to_site_use_id,
5281 p_inventory_item_id => v_inventory_item_id,
5282 p_uom_code => v_uom_code,
5283 p_default_price => pr_new.unit_selling_price,
5284 p_ass_value_date => ld_trx_date,
5285 /* Bug 5096787. Added by Lakshmi Gopalsami */
5286 p_sob_id => v_books_id,
5287 p_curr_conv_code => c_conversion_type,
5288 p_conv_rate => c_conversion_rate
5289 /* Later need to derive for p_conv_rate using ja_curr_conv
5290 as part of forwarding 11i code bug 4446346 */
5291 );
5292 v_price_list_val := v_quantity * NVL(v_price_list,0);
5293 /*
5294 ||End of #4567935 (115 bug3671351)
5295 */
5296
5297
5298 /* added by ssumaith - bug#4245053 */
5299 ln_vat_assessable_value := jai_general_pkg.ja_in_vat_assessable_value
5300 (
5301 p_party_id => v_customer_id ,
5302 p_party_site_id => v_ship_to_site_use_id ,
5303 p_inventory_item_id => v_inventory_item_id ,
5304 p_uom_code => v_uom_code ,
5305 p_default_price => pr_new.unit_selling_price,
5306 p_ass_value_date => ld_trx_date ,
5307 p_party_type => 'C'
5308 );
5309 ln_vat_assessable_value := nvl(ln_vat_assessable_value,0) * v_quantity;
5310 /* ends here additions by ssumaith - bug# 4245053*/
5311
5312 IF v_tax_category_id IS NOT NULL THEN --added for bug#6012465
5313
5314 IF c_conversion_date is NULL THEN
5315 c_conversion_date := v_trx_date;
5316 END IF;
5317
5318 v_converted_rate := jai_cmn_utils_pkg.currency_conversion(
5319 v_books_id ,
5320 c_from_currency_code ,
5321 c_conversion_date ,
5322 c_conversion_type,
5323 c_conversion_rate
5324 );
5325 v_line_tax_amount := nvl(v_line_amount,0);
5326 -- Date 26-feb-2006 added by sacsethi for bug 5631784
5327 open gc_chk_rgm_tax_exists
5328 ( cp_regime_code => jai_constants.tcs_regime
5329 , cp_rgm_tax_type => jai_constants.tax_type_tcs
5330 , cp_tax_category_id => v_tax_category_id
5331 );
5332 fetch gc_chk_rgm_tax_exists into ln_tcs_exists;
5333 close gc_chk_rgm_tax_exists;
5334 if ln_tcs_exists > 0 then
5335 /** TCS type of tax(s) are present */
5336 open gc_get_regime_id ( cp_regime_code => jai_constants.tcs_regime);
5337 fetch gc_get_regime_id into ln_tcs_regime_id;
5338 close gc_get_regime_id;
5339
5340 jai_rgm_thhold_proc_pkg.get_threshold_slab_id
5341 ( p_regime_id => ln_tcs_regime_id
5342 , p_organization_id => v_organization_id
5343 , p_party_type => jai_constants.party_type_customer
5344 , p_party_id => v_customer_id
5345 , p_org_id => v_org_id
5346 , p_source_trx_date => ld_trx_date /* ssumaith - bug# 6109941*/
5347 , p_threshold_slab_id => ln_threshold_slab_id
5348 , p_process_flag => lv_process_flag
5349 , p_process_message => lv_process_message
5350 );
5351
5352 if lv_process_flag <> jai_constants.successful then
5353 app_exception.raise_exception
5354 (exception_type => 'APP'
5355 ,exception_code => -20275
5356 ,exception_text => lv_process_message
5357 );
5358 end if;
5359 if ln_threshold_slab_id is not null then
5360 /**
5361 Threshold is high and slab is available. Hence get tax_category defined for the salb to default additional taxes
5362 */
5363 jai_rgm_thhold_proc_pkg.get_threshold_tax_cat_id
5364 (
5365 p_threshold_slab_id => ln_threshold_slab_id
5366 , p_org_id => v_org_id
5367 , p_threshold_tax_cat_id => ln_threshold_tax_cat_id
5368 , p_process_flag => lv_process_flag
5369 , p_process_message => lv_process_message
5370 );
5371 if lv_process_flag <> jai_constants.successful then
5372 app_exception.raise_exception
5373 (exception_type => 'APP'
5374 ,exception_code => -20275
5375 ,exception_text => lv_process_message
5376 );
5377 end if;
5378 end if; /** ln_threshold_slab_id is not null */
5379 end if; /** ln_tcs_exists is not null */
5380 jai_cmn_tax_defaultation_pkg.ja_in_calc_prec_taxes(
5381 'AR_LINES' ,
5382 v_tax_category_id ,
5383 v_header_id,
5384 v_customer_trx_line_id,
5385 v_price_list_val ,
5386 v_line_tax_amount ,
5387 v_inventory_item_id ,
5388 nvl(v_quantity,0), -- added - bug# 3957682
5389 pr_new.uom_code ,
5390 NULL ,
5391 NULL ,
5392 v_converted_rate ,
5393 v_creation_date ,
5394 v_created_by ,
5395 v_last_update_date ,
5396 v_last_updated_by ,
5397 v_last_update_login,
5398 NULL,
5399 ln_vat_assessable_value, /* added by ssumaith - bug# 4245053*/
5400 p_thhold_cat_base_tax_typ => jai_constants.tax_type_tcs , -- Date 26-feb-2006 added by sacsethi for bug 5631784
5401 p_threshold_tax_cat_id => ln_threshold_tax_cat_id,-- Date 26-feb-2006 added by sacsethi for bug 5631784
5402 p_source_trx_type => null,-- Date 26-feb-2006 added by sacsethi for bug 5631784
5403 p_source_table_name => null,-- Date 26-feb-2006 added by sacsethi for bug 5631784
5404 p_action => jai_constants.default_taxes-- Date 26-feb-2006 added by sacsethi for bug 5631784
5405 );
5406 END IF;
5407 v_excise := 0;
5408 v_additional := 0;
5409 v_other := 0;
5410 v_total_tax_amount := 0;
5411 FOR excise_cal_rec in excise_cal_cur
5412 LOOP
5413 IF excise_cal_rec.t_type IN ('Excise') THEN
5414 v_excise := nvl(v_excise,0) + excise_cal_rec.tax_amt;
5415 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
5416 v_additional := nvl(v_additional,0) + excise_cal_rec.tax_amt;
5417 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
5418 v_other := nvl(v_other,0) + excise_cal_rec.tax_amt;
5419 END IF;
5420 v_total_tax_amount := nvl(v_total_tax_amount,0) + nvl(excise_cal_rec.tax_amt,0);
5421 END LOOP;
5422 v_tax_tot := nvl(v_excise,0) + nvl(v_other,0) + nvl(v_additional,0);
5423 v_tot_amt := nvl(v_line_amount,0) + nvl(v_total_tax_amount,0);
5424
5425 UPDATE JAI_AR_TRXS
5426 SET line_amount = NVL(line_amount,0) + NVL(v_line_amount,0),
5427 total_amount = NVL(total_amount,0)+ NVL(v_tot_amt,0) ,
5428 tax_amount = NVL(tax_amount,0) + NVL(v_total_tax_amount,0)
5429 WHERE JAI_AR_TRXS.customer_trx_id = v_header_id;
5430
5431 /*added by csahoo for bug#5879769*/
5432 OPEN c_get_address_details(v_header_id);
5433 FETCH c_get_address_details into r_add;
5434 CLOSE c_get_address_details;
5435
5436 v_service_type:=get_service_type( NVL(r_add.SHIP_TO_CUSTOMER_ID ,r_add.BILL_TO_CUSTOMER_ID) ,
5437 NVL(r_add.SHIP_TO_SITE_USE_ID, r_add.BILL_TO_SITE_USE_ID),'C');
5438
5439
5440 Open Gl_Date_Cur;
5441 Fetch Gl_Date_Cur Into v_gl_date;
5442 Close Gl_Date_Cur;
5443 INSERT INTO JAI_AR_TRX_LINES(
5444 customer_trx_line_id,
5445 line_number,
5446 customer_trx_id,
5447 description,
5448 inventory_item_id,
5449 unit_code,
5450 quantity,
5451 tax_category_id,
5452 auto_invoice_flag ,
5453 unit_selling_price,
5454 line_amount,
5455 gl_date,
5456 tax_amount,
5457 total_amount,
5458 assessable_value,
5459 creation_date,
5460 created_by,
5461 last_update_date,
5462 last_updated_by,
5463 last_update_login,
5464 vat_assessable_value, /* added by ssumaith - bug# 4245053*/
5465 service_type_code -- Added by csahoo for Bug#5879769
5466 )
5467 VALUES(
5468 v_customer_trx_line_id,
5469 pr_new.line_number,
5470 v_header_id,
5471 pr_new.description,
5472 pr_new.inventory_item_id,
5473 pr_new.uom_code,
5474 --NVL(pr_new.quantity_invoiced,0), -- commented - bug# 3957682
5475 nvl(v_quantity,0), -- added - bug# 3957682
5476 v_tax_category_id,
5477 'N',
5478 pr_new.unit_selling_price,
5479 v_line_amount,
5480 v_gl_date,
5481 v_line_tax_amount,
5482 (v_line_amount + v_line_tax_amount),
5483 v_price_list,
5484 v_creation_date,
5485 v_created_by,
5486 v_last_update_date,
5487 v_last_updated_by,
5488 v_last_update_login,
5489 ln_vat_assessable_value, /* added by ssumaith - bug# 4245053*/
5490 v_service_type -- Added by csahoo for Bug#5879769
5491 );
5492 END IF;
5493
5494
5495 EXCEPTION
5496 WHEN OTHERS THEN
5497 VAR_SQLERRM := 'EXCEPTION OCCURED - ' || SQLERRM;
5498 VAR_SQLERRM := SUBSTR(VAR_SQLERRM,1,235);
5499
5500 /* Added an exception block by Ramananda for bug#4570303 */
5501 Pv_return_code := jai_constants.unexpected_error;
5502 Pv_return_message := 'Encountered an error in JAI_AR_RCTLA_TRIGGER_PKG.ARIU_T1 ' || substr(sqlerrm,1,1900);
5503
5504 lv_appl_src := 'JA_IN_AR_LINES_INSERT_TRG';
5505 lv_add_err := 'CUSTOMER_TRX_ID = ' || TO_CHAR(pr_new.CUSTOMER_TRX_ID) || ' CUSTOMER_TRX_LINE_ID = ' || TO_CHAR(pr_new.CUSTOMER_TRX_LINE_ID) ;
5506
5507 INSERT INTO JAI_CMN_ERRORS_T
5508 ( APPLICATION_SOURCE,
5509 error_message,
5510 additional_error_mesg,
5511 creation_date,
5512 created_by ,
5513 -- added, Harshita for Bug 4866533
5514 LAST_UPDATED_BY,
5515 LAST_UPDATE_DATE
5516 )
5517 values
5518 (
5519 lv_appl_src, /*'JA_IN_AR_LINES_INSERT_TRG', Ramananda for removal of SQL LITERALs */
5520 VAR_SQLERRM,
5521 lv_add_err, /* 'CUSTOMER_TRX_ID = ' || TO_CHAR(pr_new.CUSTOMER_TRX_ID) || ' CUSTOMER_TRX_LINE_ID = ' || TO_CHAR(pr_new.CUSTOMER_TRX_LINE_ID) , */
5522 sysdate,
5523 user ,
5524 -- added, Harshita for Bug 4866533
5525 fnd_global.user_id,
5526 sysdate
5527 );
5528
5529 END ARIU_T1 ;
5530
5531 /*REM +======================================================================+
5532 REM NAME ARU_T1
5533 REM
5534 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
5535 REM
5536 REM NOTES Refers to old trigger JAI_AR_RCTLA_ARU_T2
5537 REM
5538 REM +======================================================================+
5539 */
5540 PROCEDURE ARU_T1 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
5541 v_customer_id Number ;
5542 v_address_id Number ;
5543 v_org_id Number := 0;
5544 v_ship_to_site_use_id Number := 0;
5545 v_tax_category_list varchar2(30);
5546 v_tax_category_id Number;
5547 v_line_no Number;
5548 v_tax_id Number;
5549 v_tax_rate Number;
5550 v_tax_amount Number;
5551 v_line_tax_amount Number := 0;
5552 v_tax_tot Number := 0;
5553 v_tot_amt Number := 0;
5554 v_excise Number := 0;
5555 v_additional Number := 0;
5556 v_other Number := 0;
5557 v_price_list Number := 0;
5558 v_price_list_val Number := 0;
5559 v_price_list_uom_code Varchar2(3);
5560 v_conversion_rate Number := 0;
5561 v_old_tax_tot Number := 0;
5562 v_organization_id Number := -1;
5563 v_created_from Varchar2(30);
5564 v_once_completed_flag Varchar2(1);
5565 c_from_currency_code Varchar2(15);
5566 c_conversion_type Varchar2(30);
5567 c_conversion_date Date;
5568 c_conversion_rate Number := 0;
5569 v_converted_rate Number := 0;
5570 v_books_id Number;
5571 v_row_id Rowid;
5572
5573 /* --Ramananda for File.Sql.35 */
5574 v_uom_code varchar2(3); -- := pr_new.uom_code;
5575 v_line_amount number; -- := nvl(nvl(pr_new.quantity_credited,pr_new.quantity_invoiced) * pr_new.unit_selling_price,0);
5576 v_old_amount Number; -- := nvl(nvl(pr_old.quantity_credited,pr_new.quantity_invoiced) * pr_old.unit_selling_price,0);
5577 v_item_class varchar2(30); -- :='N';
5578 v_inventory_item_id Number; -- := pr_new.inventory_item_id;
5579 v_header_id Number; -- := pr_old.customer_trx_id;
5580 v_customer_trx_line_id Number; -- := pr_old.customer_trx_line_id;
5581 v_last_update_date Date ; -- := pr_new.last_update_date;
5582 v_last_updated_by Number; -- := pr_new.last_updated_by;
5583 v_creation_date Date ; -- := pr_new.creation_date;
5584 v_created_by Number; -- := pr_new.created_by;
5585 v_last_update_login Number; -- := pr_new.last_update_login;
5586 v_trx_date Date;
5587 v_trans_type Varchar2(30);
5588 /* --Ramananda for File.Sql.35 */
5589
5590 Cursor bind_cur IS
5591 SELECT A.org_id,A.ship_to_customer_id,NVL(A.ship_to_site_use_id,0)
5592 FROM RA_CUSTOMER_TRX_ALL A
5593 WHERE customer_trx_id = v_header_id;
5594
5595 Cursor header_info_cur IS
5596 SELECT set_of_books_id , invoice_currency_code,
5597 exchange_rate_type, exchange_date,
5598 exchange_rate , trx_date
5599 FROM RA_CUSTOMER_TRX_ALL
5600 WHERE customer_trx_id = v_header_id;
5601
5602 CURSOR excise_cal_cur IS
5603 select A.tax_id, A.tax_rate, A.tax_amount tax_amt,b.tax_type t_type
5604 from JAI_AR_TRX_TAX_LINES A ,
5605 JAI_CMN_TAXES_ALL B
5606 where link_to_cust_trx_line_id = pr_old.customer_trx_line_id
5607 and A.tax_id = B.tax_id
5608 order by 1;
5609
5610 CURSOR ORG_CUR IS
5611 SELECT organization_id
5612 FROM JAI_AR_TRX_APPS_RELS_T;/*altered by rchandan for bug#4479131*/
5613
5614
5615 CURSOR organization_cur IS
5616 SELECT organization_id
5617 FROM JAI_AR_TRXS
5618 WHERE trx_number = (
5619 SELECT recurred_from_trx_number
5620 FROM RA_CUSTOMER_TRX_ALL
5621 WHERE customer_trx_id = v_header_id
5622 );
5623
5624 CURSOR CREATED_FROM_CUR IS
5625 SELECT created_from
5626 FROM ra_customer_trx_all
5627 WHERE customer_trx_id = v_header_id;
5628
5629 /*CURSOR ROW_ID_CUR IS
5630 SELECT rowid FROM RA_CUSTOMER_TRX_ALL
5631 WHERE customer_trx_id = v_header_id;*//*commented by rchandan for bug#4479131*/
5632
5633
5634 Cursor transaction_type_cur IS
5635 Select a.type
5636 From RA_CUST_TRX_TYPES_ALL a, RA_CUSTOMER_TRX_ALL b
5637 Where a.cust_trx_type_id = b.cust_trx_type_id
5638 And b.customer_trx_id = v_header_id
5639 And (a.org_id = pr_new.org_id
5640 OR
5641 (a.org_id is null and pr_new.org_id is null )) ; /* Modified by Ramananda for removal of SQL LITERALs */
5642 -- And NVL(a.org_id,0) = NVL(pr_new.org_id,0);
5643
5644 /* bug 5243532. Added by Lakshmi Gopalsami
5645 Removed the reference to cursor set_of_books_cur
5646 as the SOB will never be null in base table.
5647 */
5648 BEGIN
5649 pv_return_code := jai_constants.successful ;
5650 /*------------------------------------------------------------------------------------------
5651 FILENAME: JA_IN_AR_CM_LINES_UPDATE_TRG.sql
5652
5653 CHANGE HISTORY:
5654 S.No Date Author and Details
5655 1. 2001/06/22 Anuradha Parthasarathy
5656 Code commented and added to improve performance.
5657
5658 2. 2003/03/12 Sriram - Bug # 2846277 File Version - 615.1
5659 In case where setup business group setup is done , inventory organization is a value 0.
5660 This was causing the trigger to return because of code comparison . Hence changed the
5661 comparison to a large value such as 999999
5662
5663 3. 2004/10/21 ssumaith - bug# 3957682 File Version - 115.1
5664 Added code to return the control when the condition = 'ARXTWMAI' and transaction_Type = 'CM'
5665 because tax defaultation is already taken care of as part of the trigger ja_in_ar_lines_update_trg
5666
5667 4. 08-Jun-2005 This Object is Modified to refer to New DB Entity names in place of Old
5668 DB Entity as required for CASE COMPLAINCE. Version 116.1
5669
5670 5. 13-Jun-2005 File Version: 116.2
5671 Ramananda for bug#4428980. Removal of SQL LITERALs is done
5672
5673 6. 8-Jul-2005 File Version: 116.3
5674 rchandan for bug#4479131
5675 The object is modified to eliminate the paddr usage.
5676
5677
5678 --------------------------------------------------------------------------------------------*/
5679
5680 /* --Ramananda for File.Sql.35 */
5681 v_header_id := pr_old.customer_trx_id;
5682 v_inventory_item_id := pr_new.inventory_item_id;
5683 v_item_class :='N';
5684 v_uom_code := pr_new.uom_code;
5685 v_line_amount := nvl(nvl(pr_new.quantity_credited,pr_new.quantity_invoiced) * pr_new.unit_selling_price,0);
5686 v_old_amount := nvl(nvl(pr_old.quantity_credited,pr_new.quantity_invoiced) * pr_old.unit_selling_price,0);
5687 v_customer_trx_line_id := pr_old.customer_trx_line_id;
5688 v_last_update_date := pr_new.last_update_date;
5689 v_last_updated_by := pr_new.last_updated_by;
5690 v_creation_date := pr_new.creation_date;
5691 v_created_by := pr_new.created_by;
5692 v_last_update_login := pr_new.last_update_login;
5693 /* --Ramananda for File.Sql.35 */
5694
5695 OPEN transaction_type_cur;
5696 FETCH transaction_type_cur INTO v_trans_type;
5697 CLOSE transaction_type_cur;
5698
5699 IF NVL(v_trans_type,'N') not in ('CM','DM') THEN
5700 Return;
5701 END IF;
5702
5703 OPEN CREATED_FROM_CUR;
5704 FETCH CREATED_FROM_CUR INTO v_created_from;
5705 CLOSE CREATED_FROM_CUR;
5706
5707 /* added by ssumaith - bug# 3957682 */
5708
5709 if v_created_from = 'ARXTWMAI' and NVL(v_trans_type,'N') = 'CM' then
5710 return;
5711 end if;
5712
5713 /* ends here additions by ssumaith - bug# 3957682 */
5714
5715 IF v_created_from in('RAXTRX','ARXREC') THEN
5716 RETURN;
5717 END IF;
5718
5719 OPEN ORG_CUR;
5720 FETCH ORG_CUR INTO v_organization_id;
5721 CLOSE ORG_CUR;
5722 IF NVL(v_organization_id,999999) = 999999 THEN
5723 OPEN organization_cur;
5724 FETCH organization_cur INTO v_organization_id;
5725 CLOSE organization_cur;
5726 /* ELSE
5727 OPEN ROW_ID_CUR;
5728 FETCH ROW_ID_CUR INTO v_row_id;
5729 CLOSE ROW_ID_CUR;
5730 jai_cmn_utils_pkg.JA_IN_SET_LOCATOR(
5731 'JAINARTX',
5732 v_row_id
5733 );*//*commented by rchandan for bug#4479131*/
5734 END IF;
5735 IF NVL(v_organization_id,999999) = 999999 THEN
5736
5737 RETURN;
5738 END IF;
5739 FOR excise_cal_rec in excise_cal_cur
5740 LOOP
5741 IF excise_cal_rec.t_type IN ('Excise') THEN
5742 v_excise := nvl(v_excise,0) + nvl(excise_cal_rec.tax_amt,0);
5743 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
5744 v_additional := nvl(v_additional,0) + nvl(excise_cal_rec.tax_amt,0);
5745 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
5746 v_other := nvl(v_other,0) + nvl(excise_cal_rec.tax_amt,0);
5747 END IF;
5748 END LOOP;
5749
5750 v_old_tax_tot := nvl(v_excise,0) + nvl(v_other,0) + nvl(v_additional,0);
5751
5752 OPEN bind_cur;
5753 FETCH bind_cur INTO v_org_id, v_customer_id,v_ship_to_site_use_id ;
5754 CLOSE bind_cur;
5755
5756 /* Bug 5243532. Added by Lakshmi Gopalsami
5757 Removed the reference to cursor set_of_books_cur.
5758 */
5759 OPEN HEADER_INFO_CUR;
5760 FETCH HEADER_INFO_CUR INTO v_books_id , c_from_currency_code, c_conversion_type,
5761 c_conversion_date, c_conversion_rate, v_trx_date;
5762 CLOSE HEADER_INFO_CUR;
5763
5764 v_line_tax_amount := nvl(v_line_amount,0);
5765
5766 IF c_conversion_date is NULL THEN
5767 c_conversion_date := v_trx_date;
5768 END IF;
5769
5770 v_converted_rate := jai_cmn_utils_pkg.currency_conversion (
5771 v_books_id ,
5772 c_from_currency_code ,
5773 c_conversion_date ,
5774 c_conversion_type ,
5775 c_conversion_rate
5776 );
5777 v_price_list_val := v_line_tax_amount;
5778
5779 jai_ar_utils_pkg.recalculate_tax(
5780 'AR_LINES_UPDATE' ,
5781 null ,
5782 v_header_id ,
5783 v_customer_trx_line_id ,
5784 v_price_list_val ,
5785 v_line_tax_amount ,
5786 v_converted_rate ,
5787 v_inventory_item_id ,
5788 NVL(pr_new.quantity_credited,0) ,
5789 pr_new.uom_code ,
5790 NULL ,
5791 NULL ,
5792 v_creation_date ,
5793 v_created_by ,
5794 v_last_update_date ,
5795 v_last_updated_by ,
5796 v_last_update_login
5797 );
5798 v_excise := 0;
5799 v_additional := 0;
5800 v_other := 0;
5801
5802
5803 FOR excise_cal_rec in excise_cal_cur LOOP
5804 IF excise_cal_rec.t_type IN ('Excise') THEN
5805 v_excise := nvl(v_excise,0) + excise_cal_rec.tax_amt;
5806 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
5807 v_additional := nvl(v_additional,0) + excise_cal_rec.tax_amt;
5808 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
5809 v_other := nvl(v_other,0) + excise_cal_rec.tax_amt;
5810 END IF;
5811 END LOOP;
5812 v_tax_tot := v_excise + v_other + v_additional;
5813 v_tot_amt := v_line_amount + v_tax_tot;
5814
5815 UPDATE JAI_AR_TRXS
5816 SET line_amount = NVL(line_amount,0) + NVL(v_line_amount,0) - NVL(v_old_amount,0),
5817 total_amount = NVL(total_amount,0)+ NVL(v_tot_amt,0) - nvl(v_old_amount,0) - NVL(v_old_tax_tot,0),
5818 tax_amount = NVL(tax_amount,0) + NVL(v_tax_tot,0) - NVL(v_old_tax_tot,0),
5819 creation_date = v_creation_date,
5820 created_by = v_created_by,
5821 last_update_date = v_last_update_date,
5822 last_updated_by = v_last_updated_by,
5823 last_update_login = v_last_update_login
5824 WHERE customer_trx_id = v_header_id;
5825
5826 UPDATE JAI_AR_TRX_LINES
5827 SET description = pr_new.description,
5828 inventory_item_id = pr_new.inventory_item_id,
5829 unit_code = pr_new.uom_code,
5830 quantity = pr_new.quantity_credited,
5831 auto_invoice_flag = 'N',
5832 tax_category_id = v_tax_category_id,
5833 unit_selling_price = pr_new.unit_selling_price,
5834 line_amount = v_line_amount,
5835 tax_amount = v_line_tax_amount,
5836 total_amount = v_line_amount + v_line_tax_amount,
5837 creation_date = v_creation_date,
5838 created_by = v_created_by,
5839 last_update_date = v_last_update_date,
5840 last_updated_by = v_last_updated_by,
5841 last_update_login = v_last_update_login
5842 WHERE customer_trx_line_id = pr_old.customer_trx_line_id
5843 AND customer_trx_id = v_header_id;
5844
5845 END ARU_T1 ;
5846
5847 /*
5848 REM +======================================================================+
5849 REM NAME ARU_T2
5850 REM
5851 REM DESCRIPTION Called from trigger JAI_AR_RCTLA_ARIUD_T1
5852 REM
5853 REM NOTES Refers to old trigger JAI_AR_RCTLA_ARU_T5
5854 REM
5855 REM +======================================================================+
5856 */
5857 PROCEDURE ARU_T2 ( pr_old t_rec%type , pr_new t_rec%type , pv_action varchar2 , pv_return_code out nocopy varchar2 , pv_return_message out nocopy varchar2 ) IS
5858
5859 v_customer_id Number ;
5860 v_address_id Number ;
5861 v_org_id Number := 0;
5862 v_ship_to_site_use_id Number := 0;
5863 v_tax_category_list varchar2(30);
5864 v_tax_category_id Number;
5865 v_line_no Number;
5866 v_tax_id Number;
5867 v_tax_rate Number;
5868 v_tax_amount Number;
5869 v_line_tax_amount Number := 0;
5870 v_new_quantity number:=0;
5871 v_old_quantity number:=0;
5872 v_line_amount number := 0;
5873 v_old_amount Number := 0;
5874 v_tax_tot Number := 0;
5875 v_tot_amt Number := 0;
5876 v_excise Number := 0;
5877 v_additional Number := 0;
5878 v_other Number := 0;
5879 v_price_list Number := 0;
5880 v_price_list_val Number := 0;
5881 v_price_list_uom_code Varchar2(3);
5882 v_conversion_rate Number := 0;
5883 v_old_tax_tot Number := 0;
5884 v_organization_id Number := -1;
5885 v_created_from Varchar2(30);
5886 v_once_completed_flag Varchar2(1);
5887 c_from_currency_code Varchar2(15);
5888 c_conversion_type Varchar2(30);
5889 c_conversion_date Date;
5890 c_conversion_rate Number := 0;
5891 v_converted_rate Number := 0;
5892 v_books_id Number;
5893 v_row_id Rowid;
5894 v_trx_date Date;
5895 v_trans_type Varchar2(30);
5896
5897 /* --Ramananda for File.Sql.35 */
5898 v_uom_code varchar2(3); -- := pr_new.uom_code;
5899 v_item_class varchar2(30); -- :='N';
5900 v_inventory_item_id Number; -- := pr_new.inventory_item_id;
5901 v_header_id Number; -- := pr_old.customer_trx_id;
5902 v_customer_trx_line_id Number; -- := pr_old.customer_trx_line_id;
5903 v_last_update_date Date; -- := pr_new.last_update_date;
5904 v_last_updated_by Number; -- := pr_new.last_updated_by;
5905 v_creation_date Date ; -- := pr_new.creation_date;
5906 v_created_by Number; -- := pr_new.created_by;
5907 v_last_update_login Number; -- := pr_new.last_update_login;
5908 /* --Ramananda for File.Sql.35 */
5909
5910 /* Bind variables customer_id , org_id to be retrieved in the db trigger */
5911 Cursor bind_cur IS
5912 SELECT A.org_id,A.ship_to_customer_id,NVL(A.ship_to_site_use_id,0)
5913 FROM RA_CUSTOMER_TRX_ALL A
5914 WHERE customer_trx_id = v_header_id;
5915
5916 Cursor header_info_cur IS
5917 SELECT set_of_books_id, invoice_currency_code, exchange_rate_type, exchange_date,
5918 exchange_rate, trx_date
5919 FROM RA_CUSTOMER_TRX_ALL
5920 WHERE customer_trx_id = v_header_id;
5921
5922 Cursor tax_id_cur(p_tax_category_id IN Number) IS
5923 SELECT line_no
5924 FROM JAI_CMN_TAX_CTG_LINES A
5925 WHERE A.tax_category_id = p_tax_category_id
5926 ORDER BY line_no;
5927
5928 /* to get address_id */
5929 /* Removed ra_site_uses_all and used hz_cust_site_uses_all for Bug# 4434287*/
5930 Cursor address_cur(p_ship_to_site_use_id IN Number) IS
5931 SELECT cust_acct_site_id address_id
5932 FROM hz_cust_site_uses_all A
5933 WHERE A.site_use_id = p_ship_to_site_use_id; /* Modified by Ramananda for removal of SQL LITERALs */
5934 -- WHERE A.site_use_id = NVL(p_ship_to_site_use_id,0);
5935
5936 CURSOR excise_cal_cur IS
5937 select A.tax_id, A.tax_rate, A.tax_amount tax_amt,b.tax_type t_type
5938 from JAI_AR_TRX_TAX_LINES A , JAI_CMN_TAXES_ALL B
5939 where link_to_cust_trx_line_id = pr_old.customer_trx_line_id
5940 and A.tax_id = B.tax_id
5941 order by 1;
5942
5943 CURSOR ORG_CUR IS
5944 SELECT organization_id
5945 FROM JAI_AR_TRX_APPS_RELS_T;/*altered by rchandan for paddr limination*/
5946
5947 CURSOR organization_cur IS
5948 SELECT organization_id
5949 FROM JAI_AR_TRXS
5950 WHERE trx_number = (
5951 SELECT recurred_from_trx_number
5952 FROM RA_CUSTOMER_TRX_ALL
5953 WHERE customer_trx_id = v_header_id
5954 );
5955
5956 CURSOR CREATED_FROM_CUR IS
5957 SELECT created_from , trx_date
5958 FROM ra_customer_trx_all
5959 WHERE customer_trx_id = v_header_id;
5960
5961 /*CURSOR ROW_ID_CUR IS
5962 SELECT rowid FROM RA_CUSTOMER_TRX_ALL
5963 WHERE customer_trx_id = v_header_id;*//*commented by rchandan for bug#4479131*/
5964
5965 CURSOR ONCE_COMPLETE_FLAG_CUR IS
5966 SELECT once_completed_flag
5967 FROM JAI_AR_TRXS
5968 WHERE customer_trx_id = v_header_id;
5969
5970
5971 Cursor transaction_type_cur IS
5972 Select a.type
5973 From RA_CUST_TRX_TYPES_ALL a, RA_CUSTOMER_TRX_ALL b
5974 Where a.cust_trx_type_id = b.cust_trx_type_id
5975 And b.customer_trx_id = v_header_id
5976 And ( a.org_id = pr_new.org_id
5977 OR
5978 (a.org_id is NULL AND pr_new.org_id is NULL )); /* Modified by Ramananda for removal of SQL LITERALs */
5979 --And NVL(a.org_id,0) = NVL(pr_new.org_id,0);
5980
5981 /* bug 5243532. Added by Lakshmi Gopalsami
5982 Removed the reference to cursor set_of_books_cur
5983 as the SOB will never be null in base table.
5984 */
5985
5986 ln_vat_assessable_value JAI_AR_TRX_LINES.VAT_ASSESSABLE_VALUE%TYPE;
5987 ld_trx_date DATE;
5988
5989 BEGIN
5990 pv_return_code := jai_constants.successful ;
5991 /*------------------------------------------------------------------------------------------
5992 FILENAME: JA_IN_AR_LINES_UPDATE_TRG.sql
5993
5994 CHANGE HISTORY:
5995 S.No Date Author and Details
5996 ------------------------------------------------------------------------------------------
5997 1. 2001/06/22 Anuradha Parthasarathy
5998 Code commented and added to improve performance.
5999
6000 2. 2003/03/12 Sriram - Bug # 2846277 - File Version 615.1
6001
6002 If inventory organization is 0 , which is possible when setup business group
6003 is done , it was causing the trigger to return . Hence comparing the nvl against
6004 a large value such as 999999.
6005
6006 3. 2004/21/10 ssumaith - bug# 3957682 - file version 115.1
6007
6008 For a manual credit memo when quantity is changed, taxes are not getting recalculated.
6009 This was because this trigger was written to fire only for invoice quantity change.
6010
6011 Changes done:
6012 1) Added a new when clause to ensure that trigger fires for credit memo quantity change
6013 2) Added code to use the quantity_invoiced for an invoice and quantity_credited for a credit memo.
6014
6015 4. 29-nov-2004 ssumaith - bug# 4037690 - File version 115.2
6016 Check whether india localization is being used was done using a INR check in every trigger.
6017 This check has now been moved into a new package and calls made to this package from this trigger
6018 If the function jai_cmn_utils_pkg.check_jai_exists returns true it means INR is the set of books currency ,
6019 Hence if this function returns FALSE , control should return.
6020
6021 5. 17/03/2005 ssumaith - bug# 4245053 - File Version 115.3
6022
6023 uptake of the vat assessable value has been done in this trigger.
6024 A call to the jai_general_pkg.JA_IN_VAT_ASSESSABLE_VALUE has been made passing the parameters
6025 to get the vat assessable value to the tax calculation routines and update the vat assessable
6026 value in the JAI_OM_OE_SO_LINES table.
6027
6028 This vat assessable value is sent as an additional parameter to the various procedures
6029 such as jai_om_tax_pkg.recalculate_oe_taxes , jai_cmn_tax_defaultation_pkg.ja_in_calc_prec_taxes
6030
6031 Hence, its mandatory that with this object all the other objects in this patch as well as the base bug
6032 need to be sent.
6033
6034 VAt assessable value , vat exemption related columns (type , refno and date) have also been copied
6035 from the source line in the case of a copy order / split scenario.
6036
6037 Dependency due to this bug - Huge
6038 This patch should always be accompanied by the VAT consolidated patch - 4245089
6039
6040
6041 6. 08-Jun-2005 File Version 116.1. This Object is Modified to refer to New DB Entity names in place of Old
6042 DB Entity as required for CASE COMPLAINCE.
6043
6044 7. 13-Jun-2005 Ramananda for bug#4428980. File Version: 116.2
6045 Removal of SQL LITERALs is done
6046
6047 8. 8-Jul-2005 rchandan for bug#4479131. File Version: 116.3
6048 The object is modified to eliminate the paddr usage.
6049
6050 9. 23-Aug-2005 Ramananda for bug# 4567935 (115 bug3671351). File Version 120.2
6051 Problem:
6052 -------
6053 Excise taxes not getting calculated on assessable price in AR INVOICE.
6054
6055 Fix:
6056 ----
6057 Commented the code to calculate the assessable price and added a call
6058 to the jai_om_utils_pkg.get_oe_assessable_value function to calculate the assessable price
6059 correctly through various levels of defaultation
6060
6061 10. 2-FEB-2006 SACSETHI for bug 5631784 , forward porting bug
6062 for TCS Enchancement
6063
6064 11. 18-Nov-2008 JMEENA for bug#6414523
6065 Issue: When selling price is changed, Excise Assessable Value should be updated correctly
6066 Reason: Excise Assessable value is derived but not updated in the table ja_in_ra_customer_trx_lines
6067 Fix: Modifed procedure ARU_T2. Added column assessable_value in the update statement of table JAI_AR_TRX_LINES.
6068
6069 Future Dependencies For the release Of this Object:-
6070 (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/
6071 A datamodel change )
6072 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6073 Current Version Current Bug Dependent Files Version Author Date Remarks
6074 Of File On Bug/Patchset Dependent On
6075
6076 ja_in_ar_lines_update_trg.sql
6077 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6078 115.2 4037690 IN60105D2 ja_in_util_pkg_s.sql 115.0 ssumaith 29-Nov-2004 Call to this function.
6079 ja_in_util_pkg_s.sql 115.0 ssumaith
6080
6081 115.3 4245053 IN60106 + ssumaith Service Tax and VAT Infrastructure are created
6082 4146708 + based on the bugs - 4146708 and 4545089 respectively.
6083 4245089
6084
6085 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
6086
6087
6088 /* --Ramananda for File.Sql.35 */
6089 v_header_id := pr_old.customer_trx_id;
6090 v_inventory_item_id := pr_new.inventory_item_id;
6091 v_item_class := 'N';
6092 v_uom_code := pr_new.uom_code;
6093 v_customer_trx_line_id := pr_old.customer_trx_line_id;
6094 v_last_update_date := pr_new.last_update_date;
6095 v_last_updated_by := pr_new.last_updated_by;
6096 v_creation_date := pr_new.creation_date;
6097 v_created_by := pr_new.created_by;
6098 v_last_update_login := pr_new.last_update_login;
6099 /* --Ramananda for File.Sql.35 */
6100
6101 /*The following code has added - ssumaith - bug# 4037690*/
6102
6103 --If jai_cmn_utils_pkg.check_jai_exists(P_CALLING_OBJECT => 'JA_IN_AR_LINES_UPDATE_TRG', P_ORG_ID => pr_new.org_id) = false then
6104 -- return;
6105 --end if;
6106
6107 OPEN transaction_type_cur;
6108 FETCH transaction_type_cur INTO v_trans_type;
6109 CLOSE transaction_type_cur;
6110 IF NVL(v_trans_type,'N') not in ( 'INV','CM') THEN -- added the CM into the IN by ssumaith - bug# 3957682
6111 Return;
6112 END IF;
6113
6114 /* ssumaith - bug# 3957682 */
6115 if NVL(v_trans_type,'N') = 'INV' then
6116 v_new_quantity := pr_new.quantity_invoiced;
6117 v_old_quantity := pr_old.quantity_invoiced;
6118 elsif NVL(v_trans_type,'N') = 'CM' then
6119 v_new_quantity := pr_new.quantity_credited;
6120 v_old_quantity := pr_old.quantity_credited;
6121 end if;
6122 v_line_amount := nvl(v_new_quantity * pr_new.unit_selling_price,0);
6123 v_old_amount := nvl(v_old_quantity * pr_old.unit_selling_price,0);
6124
6125 /* ssumaith - bug# 3957682 */
6126
6127
6128 OPEN ONCE_COMPLETE_FLAG_CUR;
6129 FETCH ONCE_COMPLETE_FLAG_CUR INTO v_once_completed_flag;
6130 CLOSE ONCE_COMPLETE_FLAG_CUR;
6131 IF NVL(v_once_completed_flag,'N') = 'Y' THEN
6132 RETURN;
6133 END IF;
6134
6135 OPEN CREATED_FROM_CUR;
6136 FETCH CREATED_FROM_CUR INTO v_created_from, ld_trx_date;
6137 CLOSE CREATED_FROM_CUR;
6138 IF v_created_from in('RAXTRX','ARXREC') THEN
6139 RETURN;
6140 END IF;
6141
6142 OPEN ORG_CUR;
6143 FETCH ORG_CUR INTO v_organization_id;
6144 CLOSE ORG_CUR;
6145 IF NVL(v_organization_id,999999) = 999999 THEN
6146 OPEN organization_cur;
6147 FETCH organization_cur INTO v_organization_id;
6148 CLOSE organization_cur;
6149 /*ELSE
6150 OPEN ROW_ID_CUR;
6151 FETCH ROW_ID_CUR INTO v_row_id;
6152 CLOSE ROW_ID_CUR;
6153 jai_cmn_utils_pkg.JA_IN_SET_LOCATOR('JAINARTX',v_row_id);*//*commented by rchandan for bug#4479131*/
6154 END IF;
6155 IF NVL(v_organization_id,999999) = 999999 THEN
6156 RETURN;
6157 END IF;
6158 FOR excise_cal_rec in excise_cal_cur
6159 LOOP
6160 IF excise_cal_rec.t_type IN ('Excise') THEN
6161 v_excise := nvl(v_excise,0) + nvl(excise_cal_rec.tax_amt,0);
6162 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
6163 v_additional := nvl(v_additional,0) + nvl(excise_cal_rec.tax_amt,0);
6164 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
6165 v_other := nvl(v_other,0) + nvl(excise_cal_rec.tax_amt,0);
6166 END IF;
6167 END LOOP;
6168
6169 v_old_tax_tot := nvl(v_excise,0) + nvl(v_other,0) + nvl(v_additional,0);
6170
6171 OPEN bind_cur;
6172 FETCH bind_cur INTO v_org_id, v_customer_id,v_ship_to_site_use_id ;
6173 CLOSE bind_cur;
6174
6175 /* Bug 5243532. Added by Lakshmi Gopalsami
6176 Removed the reference to cursor set_of_books_cur.
6177 */
6178
6179 OPEN HEADER_INFO_CUR;
6180 FETCH HEADER_INFO_CUR INTO v_books_id , c_from_currency_code, c_conversion_type,
6181 c_conversion_date, c_conversion_rate , v_trx_date;
6182 CLOSE HEADER_INFO_CUR;
6183
6184 OPEN address_cur(v_ship_to_site_use_id);
6185 FETCH address_cur INTO v_address_id;
6186 CLOSE address_cur;
6187
6188 IF v_customer_id IS NOT NULL AND v_address_id IS NOT NULL THEN
6189 jai_cmn_tax_defaultation_pkg.ja_in_cust_default_taxes(
6190 v_organization_id ,
6191 v_customer_id ,
6192 v_ship_to_site_use_id ,
6193 v_inventory_item_id ,
6194 v_header_id ,
6195 v_customer_trx_line_id,
6196 v_tax_category_id
6197 );
6198 ELSE
6199 jai_cmn_tax_defaultation_pkg.ja_in_org_default_taxes(
6200 v_organization_id ,
6201 v_inventory_item_id ,
6202 v_tax_category_id
6203 );
6204 END IF;
6205 --IF v_tax_category_id IS NOT NULL THEN --commented for bug#6012465
6206
6207 /*
6208 ||Added by Ramananda for bug #4567935 (115 bug3671351) , Start
6209 ||Instead of deriving the assessable valeu in this trigger,
6210 ||the same has been now shifted to the function jai_om_utils_pkg.get_oe_assessable_value
6211 ||The function gets the assessable value based on 5 level defaultation
6212 ||logic.Currently the assessable value was being fetched only from the so_price_list_lines
6213 */
6214 v_price_list := jai_om_utils_pkg.get_oe_assessable_value
6215 (
6216 p_customer_id => v_customer_id,
6217 p_ship_to_site_use_id => v_ship_to_site_use_id,
6218 p_inventory_item_id => v_inventory_item_id,
6219 p_uom_code => v_uom_code,
6220 p_default_price => pr_new.unit_selling_price,
6221 p_ass_value_date => ld_trx_date,
6222 /* Bug 5096787. Added by Lakshmi Gopalsami */
6223 p_sob_id => v_books_id,
6224 p_curr_conv_code => c_conversion_type,
6225 p_conv_rate => c_conversion_rate
6226 /* Later need to derive for p_conv_rate using ja_curr_conv
6227 as part of forwarding 11i code bug 4446346 */
6228 );
6229 v_price_list_val := v_new_quantity * NVL(v_price_list,0);
6230 /*
6231 ||Added by Ramananda for bug #4567935 (115 bug3671351) , End
6232 */
6233
6234 /* Bug# 4245053 - following function call added by ssumaith */
6235 ln_vat_assessable_value := jai_general_pkg.ja_in_vat_assessable_value
6236 (
6237 p_party_id => v_customer_id ,
6238 p_party_site_id => v_ship_to_site_use_id ,
6239 p_inventory_item_id => v_inventory_item_id ,
6240 p_uom_code => v_uom_code ,
6241 p_default_price => pr_new.unit_selling_price,
6242 p_ass_value_date => ld_trx_date ,
6243 p_party_type => 'C'
6244 );
6245
6246 ln_vat_assessable_value := nvl(ln_vat_assessable_value,0) * v_new_quantity;
6247 /* ends here - additions by ssumaith - bug# 4245053*/
6248
6249 v_line_tax_amount := nvl(v_line_amount,0);
6250
6251 /* Bug# 4245053 - added a parameter and passing the value here */
6252 jai_ar_utils_pkg.recalculate_tax('AR_LINES_UPDATE' ,
6253 v_tax_category_id ,
6254 v_header_id,
6255 v_customer_trx_line_id,
6256 v_price_list_val ,
6257 v_line_tax_amount ,
6258 v_converted_rate,
6259 v_inventory_item_id ,
6260 NVL(v_new_quantity,0),
6261 pr_new.uom_code ,
6262 NULL ,
6263 NULL ,
6264 v_creation_date ,
6265 v_created_by ,
6266 v_last_update_date ,
6267 v_last_updated_by ,
6268 v_last_update_login,
6269 ln_vat_assessable_value /* added by ssumaith - bug# 4245053*/
6270 );
6271 --END IF; --commented for bug#6012465
6272 v_excise := 0;
6273 v_additional := 0;
6274 v_other := 0;
6275 /* Update The Localizaed Header Table with the Line amount, Tax amount, Total Amount */
6276
6277 FOR excise_cal_rec in excise_cal_cur
6278 LOOP
6279 IF excise_cal_rec.t_type IN ('Excise') THEN
6280 v_excise := nvl(v_excise,0) + excise_cal_rec.tax_amt;
6281 ELSIF excise_cal_rec.t_type IN ('Addl. Excise') THEN
6282 v_additional := nvl(v_additional,0) + excise_cal_rec.tax_amt;
6283 ELSIF excise_cal_rec.t_type IN ('Other Excise') THEN
6284 v_other := nvl(v_other,0) + excise_cal_rec.tax_amt;
6285 END IF;
6286 END LOOP;
6287
6288 v_tax_tot := v_excise + v_other + v_additional;
6289 v_tot_amt := v_line_amount + v_tax_tot;
6290
6291 UPDATE JAI_AR_TRXS
6292 SET line_amount = NVL(line_amount,0) + NVL(v_line_amount,0) - NVL(v_old_amount,0),
6293 total_amount = NVL(total_amount,0)+ NVL(v_tot_amt,0) - nvl(v_old_amount,0) - NVL(v_old_tax_tot,0),
6294 tax_amount = NVL(tax_amount,0) + NVL(v_tax_tot,0) - NVL(v_old_tax_tot,0),
6295 creation_date = v_creation_date,
6296 created_by = v_created_by,
6297 last_update_date = v_last_update_date,
6298 last_updated_by = v_last_updated_by,
6299 last_update_login = v_last_update_login
6300 WHERE customer_trx_id = v_header_id;
6301
6302 UPDATE JAI_AR_TRX_LINES
6303 SET description = pr_new.description,
6304 inventory_item_id = pr_new.inventory_item_id,
6305 unit_code = pr_new.uom_code,
6306 quantity = v_new_quantity,
6307 auto_invoice_flag = 'N',
6308 tax_category_id = v_tax_category_id,
6309 unit_selling_price = pr_new.unit_selling_price,
6310 line_amount = v_line_amount,
6311 tax_amount = v_line_tax_amount,
6312 total_amount = v_line_amount + v_line_tax_amount,
6313 creation_date = v_creation_date,
6314 created_by = v_created_by,
6315 last_update_date = v_last_update_date,
6316 last_updated_by = v_last_updated_by,
6317 last_update_login = v_last_update_login,
6318 assessable_value = v_price_list -- Added by JMEENA for Bug#6414523( FP 6318850)
6319 WHERE customer_trx_line_id = pr_old.customer_trx_line_id
6320 AND customer_trx_id = v_header_id;
6321 /* Added an exception block by Ramananda for bug#4570303 */
6322 EXCEPTION
6323 WHEN OTHERS THEN
6324 Pv_return_code := jai_constants.unexpected_error;
6325 Pv_return_message := 'Encountered an error in JAI_AR_RCTLA_TRIGGER_PKG.ARU_T2 ' || substr(sqlerrm,1,1900);
6326 END ARU_T2 ;
6327
6328 /* following procedure added by cbabu for bug#6012570 (5876390) */
6329 procedure import_projects_taxes
6330 ( r_new in ra_customer_trx_lines_all%rowtype
6331 , r_old in ra_customer_trx_lines_all%rowtype
6332 , pv_action in varchar2
6333 , pv_err_msg OUT NOCOPY varchar2
6334 , pv_err_flg OUT NOCOPY varchar2
6335 )
6336 is
6337
6338 cursor c_draft_inv_line_taxes( cpn_draft_invoice_line_id in number ) is
6339 select *
6340 from jai_cmn_document_taxes
6341 where source_doc_type = jai_pa_billing_pkg.gv_source_projects
6342 and source_doc_line_id = cpn_draft_invoice_line_id
6343 order by tax_line_no;
6344 -- 6369471
6345 -- cursor to get transaction type
6346 CURSOR c_transaction_type IS
6347 SELECT A.TYPE
6348 FROM RA_CUST_TRX_TYPES_ALL A, RA_CUSTOMER_TRX_ALL b
6349 WHERE A.cust_trx_type_id = b.cust_trx_type_id
6350 AND b.customer_trx_id = r_new.customer_trx_id
6351 AND NVL(A.org_id,0) = NVL(r_new.org_id,0);
6352
6353 r_trx_type c_transaction_type%rowtype; --Bug 6369471
6354 ln_quantity jai_ar_trx_lines.quantity%type; -- Bug 6369471
6355
6356
6357 cursor c_ra_customer_trx is
6358 select trx_number, trx_date, batch_source_id, set_of_books_id
6359 , primary_salesrep_id ,invoice_currency_code, exchange_rate_type
6360 , exchange_date, exchange_rate
6361 , legal_entity_id -- 6012570
6362 from ra_customer_trx_all
6363 where customer_trx_id = r_new.customer_trx_id;
6364 r_ra_customer_trx c_ra_customer_trx%rowtype;
6365
6366 cursor c_jai_ra_customer_trx is
6367 select customer_trx_id
6368 from jai_ar_trxs
6369 where customer_trx_id = r_new.customer_trx_id;
6370 r_jai_ra_customer_trx c_jai_ra_customer_trx%rowtype;
6371
6372 cursor c_jai_ra_customer_trx_line is
6373 select customer_trx_line_id
6374 from jai_ar_trx_lines
6375 where customer_trx_line_id = r_new.customer_trx_line_id;
6376 r_jai_ra_customer_trx_line c_jai_ra_customer_trx_line%rowtype;
6377
6378 cursor c_get_project_id(cp_project_code in varchar2) is
6379 select project_id
6380 from pa_projects_all
6381 where segment1 = cp_project_code;
6382
6383 cursor c_jai_pa_draft_invoice(cpn_project_id in number, cpn_draft_invoice_num in number) is
6384 select draft_invoice_id, organization_id, location_id
6385 , excise_register_type
6386 , excise_invoice_no
6387 , excise_invoice_date
6388 , vat_invoice_no
6389 , vat_invoice_date
6390 from jai_pa_draft_invoices
6391 where project_id = cpn_project_id
6392 and draft_invoice_num = cpn_draft_invoice_num;
6393
6394 r_jai_pa_draft_invoice c_jai_pa_draft_invoice%rowtype;
6395
6396 cursor c_jai_pa_draft_inv_line(
6397 cpn_draft_invoice_id in number,
6398 cpn_line_num in number
6399 ) is
6400 select
6401 draft_invoice_id
6402 , draft_invoice_line_id
6403 , tax_category_id
6404 , service_type_code
6405 from jai_pa_draft_invoice_lines
6406 where draft_invoice_id = cpn_draft_invoice_id
6407 and line_num = cpn_line_num;
6408
6409 r_jai_pa_draft_inv_line c_jai_pa_draft_inv_line%rowtype;
6410
6411
6412 ln_line_customer_trx_line_id ra_customer_trx_lines_all.customer_trx_line_id%type;
6413
6414 ln_project_id pa_draft_invoices_all.project_id%type;
6415 ln_draft_invoice_num pa_draft_invoices_all.draft_invoice_num%type;
6416 ln_line_num pa_draft_invoice_items.line_num%type;
6417 ln_line_amount number;
6418 ln_tax_amount number;
6419 ln_func_tax_amount number;
6420 ln_base_tax_amount number;
6421
6422 ln_line_tax_amt number;
6423
6424
6425 begin
6426 /* 6369471
6427 If transaction is Credit memo then quantity invoiced should be considered, otherwise Quantity Invoice is fine.
6428 */
6429 open c_transaction_type;
6430 fetch c_transaction_type into r_trx_type;
6431 close c_transaction_type;
6432
6433 if nvl(r_trx_type.type ,'N') = 'CM' then
6434 ln_quantity := r_new.quantity_credited;
6435 else
6436 ln_quantity := r_new.quantity_invoiced;
6437 end if;
6438 /* End 6369471 */
6439
6440 ln_line_customer_trx_line_id := r_new.customer_trx_line_id;
6441 ln_line_amount := round( nvl(ln_quantity * r_new.unit_selling_price, 0), 2); -- Bug 6369471
6442
6443 open c_get_project_id(r_new.interface_line_attribute1);
6444 fetch c_get_project_id into ln_project_id;
6445 close c_get_project_id;
6446
6447 ln_draft_invoice_num := to_number(r_new.interface_line_attribute2);
6448 ln_line_num := to_number(r_new.interface_line_attribute6);
6449
6450 open c_jai_pa_draft_invoice(ln_project_id, ln_draft_invoice_num);
6451 fetch c_jai_pa_draft_invoice into r_jai_pa_draft_invoice;
6452 close c_jai_pa_draft_invoice;
6453
6454 if r_jai_pa_draft_invoice.draft_invoice_id is null then
6455 /* no data exists in JAI_PA tables, so no need to Import taxes from PA to AR */
6456 return;
6457 end if;
6458
6459 open c_jai_pa_draft_inv_line(r_jai_pa_draft_invoice.draft_invoice_id, ln_line_num);
6460 fetch c_jai_pa_draft_inv_line into r_jai_pa_draft_inv_line;
6461 close c_jai_pa_draft_inv_line;
6462
6463 open c_ra_customer_trx;
6464 fetch c_ra_customer_trx into r_ra_customer_trx;
6465 close c_ra_customer_trx;
6466
6467 open c_jai_ra_customer_trx;
6468 fetch c_jai_ra_customer_trx into r_jai_ra_customer_trx;
6469 close c_jai_ra_customer_trx;
6470
6471 if r_jai_ra_customer_trx.customer_trx_id is null then
6472 /* insert into jai_ar_trxs */
6473 insert into jai_ar_trxs(
6474 customer_trx_id
6475 , organization_id
6476 , location_id
6477 , trx_number
6478 , update_rg_flag
6479 , update_rg23d_flag
6480 , once_completed_flag
6481 , batch_source_id
6482 , set_of_books_id
6483 , primary_salesrep_id
6484 , invoice_currency_code
6485 , exchange_rate_type
6486 , exchange_date
6487 , exchange_rate
6488 , creation_date
6489 , created_by
6490 , last_update_date
6491 , last_updated_by
6492 , last_update_login
6493 , vat_invoice_no
6494 , vat_invoice_date
6495 , legal_entity_id -- 6012570
6496 ) values (
6497 r_new.customer_trx_id
6498 , r_jai_pa_draft_invoice.organization_id
6499 , r_jai_pa_draft_invoice.location_id
6500 , r_ra_customer_trx.trx_number
6501 , 'Y'
6502 , 'Y'
6503 , 'N'
6504 , r_ra_customer_trx.batch_source_id
6505 , r_ra_customer_trx.set_of_books_id
6506 , r_ra_customer_trx.primary_salesrep_id
6507 , r_ra_customer_trx.invoice_currency_code
6508 , r_ra_customer_trx.exchange_rate_type
6509 , r_ra_customer_trx.exchange_date
6510 , r_ra_customer_trx.exchange_rate
6511 , sysdate
6512 , r_new.created_by
6513 , sysdate
6514 , r_new.last_updated_by
6515 , r_new.last_update_login
6516 , r_jai_pa_draft_invoice.vat_invoice_no
6517 , r_jai_pa_draft_invoice.vat_invoice_date
6518 , r_ra_customer_trx.legal_entity_id -- 6012570
6519 );
6520
6521 end if;
6522
6523 /* insert into ja_in_ra_cust_trx_tax_lines */
6524 for tax_rec in c_draft_inv_line_taxes(r_jai_pa_draft_inv_line.draft_invoice_line_id) loop
6525
6526 ln_tax_amount := round(tax_rec.tax_amt,2);
6527 ln_func_tax_amount := round(tax_rec.func_tax_amt,2);
6528 if tax_rec.tax_rate <> 0 then
6529 ln_base_tax_amount := tax_rec.tax_amt * 100/ tax_rec.tax_rate;
6530 else
6531 ln_base_tax_amount := ln_tax_amount;
6532 end if;
6533
6534 insert into jai_ar_trx_tax_lines(
6535 tax_line_no ,
6536 customer_trx_line_id ,
6537 link_to_cust_trx_line_id ,
6538 precedence_1 ,
6539 precedence_2 ,
6540 precedence_3 ,
6541 precedence_4 ,
6542 precedence_5 ,
6543 precedence_6 ,
6544 precedence_7 ,
6545 precedence_8 ,
6546 precedence_9 ,
6547 precedence_10 ,
6548 tax_id ,
6549 tax_rate ,
6550 qty_rate ,
6551 uom ,
6552 tax_amount ,
6553 func_tax_amount ,
6554 base_tax_amount ,
6555 creation_date ,
6556 created_by ,
6557 last_update_date ,
6558 last_updated_by ,
6559 last_update_login
6560 ) values(
6561 tax_rec.tax_line_no ,
6562 ra_customer_trx_lines_s.nextval ,
6563 ln_line_customer_trx_line_id ,
6564 tax_rec.precedence_1 ,
6565 tax_rec.precedence_2 ,
6566 tax_rec.precedence_3 ,
6567 tax_rec.precedence_4 ,
6568 tax_rec.precedence_5 ,
6569 tax_rec.precedence_6 ,
6570 tax_rec.precedence_7 ,
6571 tax_rec.precedence_8 ,
6572 tax_rec.precedence_9 ,
6573 tax_rec.precedence_10 ,
6574 tax_rec.tax_id ,
6575 tax_rec.tax_rate ,
6576 tax_rec.qty_rate ,
6577 tax_rec.uom ,
6578 ln_tax_amount ,
6579 ln_func_tax_amount ,
6580 ln_base_tax_amount, /* Complete this round(v_base_tax_amount,2) , */
6581 sysdate ,
6582 r_new.created_by,
6583 sysdate ,
6584 r_new.last_updated_by ,
6585 r_new.last_update_login
6586 );
6587
6588 ln_line_tax_amt := nvl(ln_line_tax_amt,0) + ln_tax_amount;
6589
6590 end loop;
6591
6592 /* insert into jai_ar_trx_lines */
6593 open c_jai_ra_customer_trx_line;
6594 fetch c_jai_ra_customer_trx_line into r_jai_ra_customer_trx_line;
6595 close c_jai_ra_customer_trx_line;
6596
6597 if r_jai_ra_customer_trx_line.customer_trx_line_id is null then
6598 INSERT INTO jai_ar_trx_lines (
6599 customer_trx_line_id ,
6600 line_number ,
6601 customer_trx_id ,
6602 description ,
6603 payment_register ,
6604 excise_invoice_no ,
6605 preprinted_excise_inv_no ,
6606 excise_invoice_date ,
6607 inventory_item_id ,
6608 unit_code ,
6609 quantity ,
6610 tax_category_id ,
6611 auto_invoice_flag ,
6612 unit_selling_price ,
6613 line_amount ,
6614 tax_amount ,
6615 total_amount ,
6616 assessable_value ,
6617 creation_date ,
6618 created_by ,
6619 last_update_date ,
6620 last_updated_by ,
6621 last_update_login ,
6622 excise_exempt_type ,
6623 excise_exempt_refno ,
6624 excise_exempt_date ,
6625 ar3_form_no ,
6626 ar3_form_date ,
6627 vat_exemption_flag ,
6628 vat_exemption_type ,
6629 vat_exemption_date ,
6630 vat_exemption_refno ,
6631 vat_assessable_value ,
6632 service_type_code
6633 ) VALUES (
6634 ln_line_customer_trx_line_id ,
6635 r_new.line_number ,
6636 r_new.customer_trx_id ,
6637 r_new.description ,
6638 r_jai_pa_draft_invoice.excise_register_type ,
6639 r_jai_pa_draft_invoice.excise_invoice_no ,
6640 null , -- v_preprinted_excise_inv_no ,
6641 r_jai_pa_draft_invoice.excise_invoice_date ,
6642 r_new.inventory_item_id ,
6643 r_new.uom_code ,
6644 ln_quantity , -- 6369471, using ln_quanity instead of r_new.quantity_inoviced
6645 r_jai_pa_draft_inv_line.tax_category_id ,
6646 'Y' ,
6647 r_new.unit_selling_price ,
6648 ln_line_amount ,
6649 ln_line_tax_amt ,
6650 (ln_line_amount + ln_line_tax_amt) ,
6651 null , -- v_assessable_value ,
6652 sysdate ,
6653 r_new.created_by ,
6654 sysdate ,
6655 r_new.last_updated_by ,
6656 r_new.last_update_login ,
6657 null , -- v_excise_exempt_type ,
6658 null , -- v_excise_exempt_refno ,
6659 null , -- v_excise_exempt_date ,
6660 null , -- v_ar3_form_no ,
6661 null , -- v_ar3_form_date ,
6662 null , -- lv_vat_exemption_flag ,
6663 null , -- lv_vat_exemption_type ,
6664 null , -- lv_vat_exemption_date ,
6665 null , -- lv_vat_exemption_refno ,
6666 null , -- ln_vat_assessable_value
6667 r_jai_pa_draft_inv_line.service_type_code
6668 );
6669
6670 update jai_ar_trxs
6671 set tax_amount = nvl(tax_amount,0) + round( nvl(ln_line_tax_amt,0), 2)
6672 , line_amount = nvl(line_amount,0) + round( nvl(ln_line_amount,0), 2)
6673 , total_amount = nvl(total_amount,0) + round(nvl(ln_line_amount,0) + nvl(ln_line_tax_amt,0), 2)
6674 , last_updated_by = r_new.last_updated_by
6675 , last_update_date = sysdate
6676 , last_update_login = r_new.last_update_login
6677 where customer_trx_id = r_new.customer_trx_id;
6678
6679 end if;
6680
6681 end import_projects_taxes;
6682
6683 /*following function added for Projects Billing Implementation. bug#6012570 (5876390) */
6684 function is_this_projects_context(
6685 pv_context IN varchar2
6686 ) return boolean is
6687
6688 lb_return_value boolean;
6689
6690 begin
6691
6692 if upper(pv_context) in ('PROJECTS INVOICES', 'PA INVOICES' ) then
6693 /* Commented the following for bug# 6493501
6694 To support interproject or intercompany billing in future
6695 -- 'PA INTERNAL INVOICES' */
6696 lb_return_value := true;
6697 else
6698 lb_return_value := false;
6699 end if;
6700
6701 return lb_return_value;
6702
6703 end is_this_projects_context;
6704
6705
6706
6707 /* Function to get the service_type
6708 added by csahoo for bug#5879769*/
6709
6710 FUNCTION get_service_type(pn_party_id NUMBER,
6711 pn_party_site_id NUMBER,
6712 pv_party_type VARCHAR2) return VARCHAR2
6713 IS
6714 v_service_type VARCHAR2(30);
6715 ln_address_id NUMBER;
6716
6717 CURSOR c_get_address IS
6718 SELECT hzcas.cust_acct_site_id
6719 FROM hz_cust_site_uses_all hzcsu ,
6720 hz_cust_acct_sites_all hzcas
6721 WHERE hzcas.cust_acct_site_id = hzcsu.cust_acct_site_id
6722 AND hzcsu.site_use_id = pn_party_site_id
6723 AND hzcas.cust_account_id = pn_party_id ;
6724
6725 CURSOR cur_get_ser_type_customer(pn_cust_id NUMBER,pn_address_id NUMBER) IS
6726 SELECT service_type_code
6727 FROM JAI_CMN_CUS_ADDRESSES
6728 WHERE customer_id = pn_cust_id
6729 AND address_id = pn_address_id;
6730
6731 CURSOR cur_get_ser_type_vendor(
6732 cp_vendor_id IN Po_Headers_All.vendor_id%type,
6733 cp_vendor_site_id IN Po_Headers_All.vendor_site_id%type
6734 )
6735 IS
6736 SELECT service_type_code
6737 FROM JAI_CMN_VENDOR_SITES
6738 WHERE vendor_id = cp_vendor_id
6739 AND vendor_site_id = cp_vendor_site_id;
6740
6741 /*
6742 ||This function is used to retreive the service type based on the customer id and address id
6743 ||passed as parameters.
6744 */
6745
6746 BEGIN
6747 IF pv_party_type = jai_constants.party_type_customer THEN
6748
6749 OPEN c_get_address;
6750 FETCH c_get_address INTO ln_address_id;
6751 CLOSE c_get_address;
6752
6753 OPEN cur_get_ser_type_customer(pn_party_id,ln_address_id);
6754 FETCH cur_get_ser_type_customer INTO v_service_type;
6755 CLOSE cur_get_ser_type_customer;
6756
6757 IF v_service_type is null THEN
6758
6759 OPEN cur_get_ser_type_customer(pn_party_id,0);
6760 FETCH cur_get_ser_type_customer INTO v_service_type;
6761 CLOSE cur_get_ser_type_customer;
6762
6763 END IF;
6764
6765 ELSIF pv_party_type = jai_constants.party_type_vendor THEN
6766
6767 OPEN cur_get_ser_type_vendor(pn_party_id, pn_party_site_id);
6768 FETCH cur_get_ser_type_vendor INTO v_service_type;
6769 CLOSE cur_get_ser_type_vendor;
6770
6771 IF v_service_type IS NULL THEN
6772 OPEN cur_get_ser_type_vendor(pn_party_id, 0);
6773 FETCH cur_get_ser_type_vendor INTO v_service_type;
6774 CLOSE cur_get_ser_type_vendor;
6775 END IF;
6776
6777 END IF;
6778
6779 return v_service_type;
6780
6781 END;
6782
6783 END JAI_AR_RCTLA_TRIGGER_PKG;