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