DBA Data[Home] [Help]

PACKAGE BODY: APPS.JAI_AP_TDS_ETDS_PKG

Source


1 PACKAGE BODY jai_ap_tds_etds_pkg AS
2 /* $Header: jai_ap_tds_etds.plb 120.74.12020000.18 2013/06/04 04:54:58 cholei ship $ */
3 
4 /*---------------------------------------------------------------------------------------------------------
5 change history for jai_ap_tds_etds_pkg.sql
6 
7 SlNo.  DD/MM/YYYY       Author and Details of Modifications
8 ----------------------------------------------------------------------------------------------------------
9 1      22/03/2004       Vijay Shankar for Bug# 3463974, Version: 619.1
10                           This Package is created for enhancement to capture all the eTDS format, data Requirements in different procedures
11 
12 2      13/04/2004       Vijay Shankar for Bug# 3603545 (also fixed 3567864), Version: 619.2
13                           TDS and Base Taxable amounts are not populated correctly in
14                           JAI_AP_ETDS_T table for Vendor Prepayment Invoices
15                           TDS Amount is wrongly populated as tds_tax_rate is used instead of
16                           tds_tax_rate/100 to calculated tds amount of prepayment applied amount.
17                           Base amount is not at all reduced to the extent of prepayment applied which is resolved with this bug.
18 
19                           Previous Bug# 3463974 is Obsoleted with this bug
20 
21 3.     21/06/2004       Aparajita for bug#3708878. Version#115.1
22                           Section was not getting printed properly for deductee details. Call to getSectionCode was missing  for deductee section.
23 
24 4.     24/05/2005       Ramananda for bug# 4388958 File Version: 116.1
25                           Changed AP Lookup code from 'TDS' to 'INDIA TDS'
26 
27 5.     08-Jun-2005      File Version 116.3. Object is Modified to refer to New DB Entity names in place of Old DB Entity Names
28                           as required for CASE COMPLAINCE.
29 
30 6.     14-Jun-2005      rchandan for bug#4428980, Version 116.4
31                           Modified the object to remove literals from DML statements and CURSORS.
32                           This activity is done as a part of R12 initiatives.
33 
34 7.     14-Jun-2205      Brathod for Bug# 4428712, Version 116.5
35                         Issue:
36                           Impact of Bank Account Project on IL Objects
37                         Solution:
38                           In R12 Bank Account Project will eliminate the redudant information maintained
39                           by each diffrent applications and improve the information sharing.
40                           As per the documentation AP_BANK_ACCOUNTS and AP_BANK_BRANCHES tables will
44                           model as part of R12 Initiative.
41                           hold information only for external bank accounts.  For internal bank accounts
42                           as per the new model HZ_PARTIES and CE_BANK_ACCOUNT, CE_BANK_ACCT_USES_ALL
43                           will be used.  The code in this procedure is modfied to refer to this new
45 
46 8.     29-Jun-2005      ssumaith - bug#4448789 - removal of hr_operating_units.legal_entity_id from this trigger.
47 
48 9.     17-Aug-2005      Ramananda for bug#4555466 during R12 Sanity Testing. File Version 120.2
49                         Instead of fnd_common_lookups table, ja_lookups table is being referred
50 
51 10     07/12/2005   Hjujjuru for the bug 4866533 File version 120.3
52                     added the who columns in the insert into tables JAI_AP_ETDS_REQUESTS and JAI_AP_ETDS_T.
53                     Dependencies Due to this bug:-
54                     None
55 
56 11    23/12/2005   Hjujjuru for Bug 4889272, File Version 120.4
57                    Removed the legal_entity_id parameter in the
58                    procedures populate_details and generate_flat_file.
59                    Removed the profile_org_id from the generate_flat_file procedure.
60                    Modified the code to eliminate references to the
61                    legal_entity_id and Operating Unit id.
62                    Changed the position of the parameter p_organization_id in the
63                    generate_flat_file procedure.
64 
65 12   27/03/2006    Hjujjuru for Bug 5096787 , File Version 120.5
66                    Spec changes have been made in this file as a part og Bug 5096787.
67                    Now, the r12 Procedure/Function specs is in this file are in
68                    sync with their corrsponding 11i counterparts
69 
70 
71 
72 13   11/05/2007    sacsethi for bug 5647248  + 5658040
73 
74     The following changes are done to make use of the same package for 26Q and 27Q
75                 Modified the populate_details procedure:
76                 1.added two parameters p_include_list,p_exclude_list in the call to populate_details,quarterly_returns
77                 and generate_etds_returns.
78                 2.Declared lv_list which is of varray type
79                 3.added populate_include_exclude_list procedure in populate_details.
80                 4.declared cursor c_prg_name which will fetch the concurrent program name in quarterly_returns procedure.
81                 Based on this concurrent program name form_number is changed.
82 
83                 Report has been modified to generate Form 27A along with eTDS Quarterly Returns.
84                 Added a call to the Concurrent JAINTDSA in the quarterly_returns procedure.
85 
86 
87                 Added the update clause to modify the taxabale_amount of JAI_AP_ETDS_T
88                 based on the taxable_amount of jai_ap_tds_thhold_trxs table.
89                 In case of threshold transition and rollback transactions, the
90                 taxable amount should be 0 for the differential invoice that has been created.
91                 Hence, implemented this change.
92 
93 14.  28-jun-2007  CSahoo for bug#6158875
94                   modified the num of input parameters to yearly_returns procedure.
95                   added the call to the function Fnd_date.canoncical_to_date.
96 
97 15.  02-Jul-2007  CSahoo for bug#6158875, file version 120.10
98                   modified the num of input parameters to querterly_returns procedure.
99                   added the call to the function Fnd_date.canoncical_to_date.
100 
101 
102 16.  03/07/2007   CSAHOO FOR BUG#6158875, File Version 120.11
103                   modified the following cursors c_tds_payment_check_id,c_base_payment_check_id,c_check_dtls.
104 
105 17.  27/08/2007   CSahoo for bug#5975168, File Version 120.12
106                   Added a check for status_lookup_code in cursor c_check_dtls
107 
108 18.  27/08/2007   Csahoo for bug#6070014, File version 120.13
109                   Changed the format mask from hardcoded value to
110                   assigned value. This is done in procedure
111                   create_quart_deductee_dtl
112 
113 19.  13/02/2008   Lakshmi Gopalsami for bug# 6796765  File Version 120.5.12000000.4
114      1. Changed the function getSectionCode. Replaced the hardcoded value with p_string.
115      2. Changed in procedure create_challan_detail. Added upper for both p_challan_section and Sec.().
116      3. Changed in procedure create_deductee_detail. Added upper for both p_deductee_section and Sec.().
117      4. Changed in procedure create_quart_challan_dtl.
118       a)  Added input parameter p_form_name to print the section code depending on the section.
119       b)  Declared variables to select the section truncation depending on the form name.
120       c)  Added logic to get the section code as 194C, 194D, 195 etc. from SEC. 194(C) and then check whether it can be converted to a
121           number. If so, the value will be printed in flat file else extract the value from 2nd character in flat file.
122           hardcoded the values of 194BB, 194EE, 194LA as per the details provided in NSDL as separate logic cannot be derived.
123       d)  Changed the UTL_FILE.PUT_LINE parameter from getsectioncode to lv_output_string.
124 
125 20.  15/02/2008  JMEENA for bug#6647362 File Version 120.5.12000000.4
126         Added 5000 UTL_FILE buffer size for bug#6647362
127 
128 21.  20/02/2008  JMEENA for bug#4600778 File Version 120.5.12000000.5
129              Removed the cursor c_bank_branch_code and added column bsr_code in the cursor c_tds_payment_check_id and fetched the value in v_bank_branch_code.
130 
131 22     08-Oct-2008        Bgowrava for Bug#6195027, File Version 120.5.12000000.5
132                                          Added sh_cess_rate in cursor c_tax_rates and defined related variables. Included ln_sh_cess_amt in ln_cess_amt.
133 
134 23.     24-Oct-2008     Bgowrava for bug#7485031, File version 115.14.6017.12
138 24.     06-Aug-2007     Forward Port Bug 6329774
135                                      Added code to use the include_flag and exclude_flag while determining the sections which need to be considered to be
136            inserted into the table JAI_AP_ETDS_T for the current execution. Also included code changes for bug 6281440
137 
139                         Changed the challan date to base_invoice_date while printing deductee details.
140 
141 25.    18-Oct-2008       Bgowrava for bug#6030953, File version 120.15.12010000.7, 120.21
142                                         Mandatory details to be printed in Form 27 A which is called from eTDS Quaterly.   Following parameters are included in respective procedures
143                        p_RespPers_flat_no
144                        p_RespPers_prem_bldg
145                        p_RespPers_rd_st_lane
146                         p_RespPers_area_loc
147                        p_RespPers_tn_cty_dt
148                        p_RespPers_tel_no
149                        p_RespPers_email
150                 and parameter p_RespPersAddress is removed.
151            Affected procedures are :
152                      create_quarterly_fh
153                       validate_batch_header
154                       quarterly_returns
155                      generate_etds_returns
156             Also passed the parameters while submitting the request  for Form 27A. Included p_deductor_status
157 
158 26.     28-May-2009     Bug 8505050 - Lines with amount as 0 for TDS is also displayed in the e-TDS flat file which causes issue during upload
159                         Added the having clause to prevent entries in e-TDS file with 0 Tax amount
160 
161 27.     15-Sep-2009     Changes for eTDS/eTCS File Validation Utility Changes - Bug 8880543
162 
163 28. 09-OCT-2009  Added by Bgowrava for Bug#9005248
164                  Replace the literal 'PANNOTREQD' to 'PANNOTAVBL' according to the latest notification.
165 
166 29.  06-Jan-2010   Xiao Lv for Bug#7662155
167         Added New cursor c_get_tds_inv_det in the populate_details procedure to calculate the surcharge amount at threshold
168         transition when surcharge gets applicable.
169 
170 30.  08-apr-2010    Bgowrava for Bug#9494515
171                                  Modified the query of the cursor c_pan_number and included the view jai_rgm_org_regns_v instead of the three table names.
172                                  This would fetch the correct PAN number for the organization.
173 
174 31. 25-Oct-2010     Bug 10020606
175                     Description: All TDS reports must be based on GL Date or date on which TCS Liability is booked
176                     and not Invoice Date
177                     Fix: Fetched data based on GL Date of Base Invoice
178 
179 32. 23-Nov-2010    amandali for bug 10315928
180                                   Description:R12 : ETDS FVU CHANGES AS NOTIFIED ON 09-OCT-2010 WRT NEW VERSION OF VALIDATION
181                                   Fix:Added responsible person and deductor contact details in regime and displayed them in batch header.
182                                         Also made few changes for the transporters.
183 
184 33. 05-Jan-2011   amandali for bug 10188600
185                   Description:INDIA LOCALIZATION : TDS RETURN SHOWS DATE ON AMOUNT PAID/CREDITED INCORRECT
186                   Fix:Amount paid/credited is showing the invoice date of the supplier.Changed it to the gl date.
187                       Modified the payment date parameter to dd.tds_invoice_date from dd.base_invoice_date  in a call to create_deductee_detail.
188 34. 17-Feb-2011   amandali for bug 11781966
189                   Description:  ETDS OUTPUT FAILS  NSDL VALIDATION FOR UNMATCHED CHALLAN COUNT
190                   Fix:Commented v_bh_unmatch_challan_cnt := 'NA' as no value needs to be passed for v_bh_unmatch_challan_count.
191 
192 35. 17-Jun-2011   amandali for bug 12624907
193                   Description:INDIA - PROGRAM TO GENERATE ETDS QUARTERLY CERTIFICATES 26Q ENDING WITH ERROR
194                   Fix: The state attribute code contains the name of the state and not the state code.
195                   Modified the datatype of v_state_name and also added the cursor c_get_state_code to print the state code in flat file.
196 
197 36. 5-Aug-2011    amandali for bug 12691784
198                   Description: ETDS Form 27A erroring out when 26Q run for multiple OUs
199           Fix: 1.Added a parameter p_deductor_addr_org_id in call to JAINTDSA
200                2.In Populate_details procedure, added a condition wrt organization id.
201              3. Challan details are populated irrespective of check number.Duplication of data exists. Added a check for check_number while updating records.
202 
203 37.  5-Sep-2011    amandali for Bug: 12927114
204                    Description:ETDS FLAT FILE VALIDATION  ERRORS "Invalid Deductor / Collector Address2"
205                    Fix: Concatenated the Deductor address2 and Address3 to 25 characters.
206 
207 38. 07-Sep-2011  mmurtuza for bug 12943133
208      Description: ERROR "T-FV-3043 INVALID SECTION / COLLECTION CODE" WHILE VALIDATING FLAT FILE
209      Fix: Bypassed the truncation logic in create_quart_challan_dtl procedure if the section code is already as per flat file requirement
210       Modified getsectioncode function to accomodate sections with E and C
211 
212 39.  14-Oct-2011  amandali for bug 13070779
213           Description:Payment amount  in ETDS flat file is showing the wrong amount incase of prepayment application on validated standard invoice.
214       Fix:For RTN invoices, the base_taxabale_amount should be -ve but is updated to positive and hence the amount is summed up instead of subtraction.
215           Commented the multiplication of tds_amount/invoice_to_tds_authority_Amt in updation for base_taxabale_amount.
216 
217 40.  29-NOV-11  mmurtuza for Bug 13439411
218     Description:   WHILE VALIDATING E-TDS FILE FVU SOFTWARE IS GIVING ERROR
219     Fix: Added trim clause in getsectioncode function to remove the space
220 
221 41.  08-Jan-2011 amandali for bug 13323753
222        Description:FVU validation errors.
226        +Fixed error "T-FV-2097 Count of Challan/Transfer voucher Records in Batch Header not
223      Fixed:+Responsible address when given more than 25 characters, concurrent 26Q  is errored out
224            +Same challan with different checks is shown in different challan records .It is now fixed to show in one challan record.
225        +Mismatch in the number of deductee records and the count of deductee records in challan record.
227        matches with actual no. of Challan/Transfer Voucher No. "
228 
229 42. 06-Mar-2012    amandali for bug 13702172
230                     Description:FVU 3.3 uptake
231                     Fix:Added parameter p_fh_consFileHash to the procedure create_quarterly_file_header and populating it with null in the flat file.
232 
233 43. 05-Apr-2012 ER 13514846
234                 Description: Invoices attracting Zero Rate TDS not displayed in eTDS Flat file
235                 Fix: Modified populate_details procedure to fetch Invoices which have Zero Rate Tax ID attached
236 
237 44.  24-SEP-2012 amandali for bug 14330534
238                  Description: ETDS flat file erroring "T-FV-4012 Valid employee / party name must be provided"
239                  Fix: Added validation to the length of supplier name in procedure validate_deductee_detail.
240 
241 45.  10-Dec-2012  amandali for ER 15840480
242                   Description:FVU3.6 Uptake
243 ---------------------------------------------------------------------------------------------------------*/
244   G_PKG_NAME          CONSTANT VARCHAR2(30) := 'JAI_AP_TDS_ETDS_PKG';
245   G_MSG_UERROR        CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR;
246   G_MSG_ERROR         CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_ERROR;
247   G_MSG_SUCCESS       CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_SUCCESS;
248   G_MSG_HIGH          CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH;
249   G_MSG_MEDIUM        CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM;
250   G_MSG_LOW           CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW;
251 
252   G_CURRENT_RUNTIME_LEVEL CONSTANT NUMBER       := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
253   G_LEVEL_UNEXPECTED      CONSTANT NUMBER       := FND_LOG.LEVEL_UNEXPECTED;
254   G_LEVEL_ERROR           CONSTANT NUMBER       := FND_LOG.LEVEL_ERROR;
255   G_LEVEL_EXCEPTION       CONSTANT NUMBER       := FND_LOG.LEVEL_EXCEPTION;
256   G_LEVEL_EVENT           CONSTANT NUMBER       := FND_LOG.LEVEL_EVENT;
257   G_LEVEL_PROCEDURE       CONSTANT NUMBER       := FND_LOG.LEVEL_PROCEDURE;
258   G_LEVEL_STATEMENT       CONSTANT NUMBER       := FND_LOG.LEVEL_STATEMENT;
259   G_MODULE_NAME           CONSTANT VARCHAR2(40) := 'JAI.PLSQL.JAI_AP_TDS_ETDS_PKG.';
260   G_INVOICE_VALIDATE      CONSTANT VARCHAR2(40) := 'INVOICE VALIDATE';
261   G_PREPAYMENT_APPLICATION CONSTANT VARCHAR2(40) := 'PREPAYMENT APPLICATION';
262   G_PREPAYMENT_UNAPPLICATION CONSTANT VARCHAR2(40) := 'PREPAYMENT UNAPPLICATION';
263   G_THRESHOLD_TRANSITION  CONSTANT VARCHAR2(40) := 'THRESHOLD TRANSITION';
264   G_THRESHOLD_ROLLBACK    CONSTANT VARCHAR2(40) := 'THRESHOLD ROLLBACK';
265   G_SURCHARGE_CALCULATE   CONSTANT VARCHAR2(40) := 'SURCHARGE_CALCULATE';
266   G_SURCHARGE_ROLLBACK    CONSTANT VARCHAR2(40) := 'SURCHARGE_ROLLBACK';
267   G_JAI_INDIA_TAX_REGIMES CONSTANT VARCHAR2(40) := 'JAI_INDIA_TAX_REGIMES';
268   G_TDS                   CONSTANT VARCHAR2(3)  := 'TDS';
269   G_TDS_SURCHARGE         CONSTANT VARCHAR2(20) := 'TDS_SURCHARGE';
270   G_TDS_SECTION           CONSTANT VARCHAR2(20) := 'TDS_SECTION';
271   G_WCT_SECTION           CONSTANT VARCHAR2(20) := 'WCT_SECTION';
272   G_ESSI_SECTION          CONSTANT VARCHAR2(20) := 'ESSI_SECTION';
273   G_Y                     CONSTANT VARCHAR2(1)  := 'Y';
274   G_N                     CONSTANT VARCHAR2(1)  := 'N';
275 
276   /*Bug 8880543 - Changes for eTDS/eTCS FVU Changes - Start*/
277 
278   FUNCTION VALIDATE_ALPHA_NUMERIC(p_str VARCHAR2, p_length NUMBER) RETURN VARCHAR2 IS
279   lv_resp     VARCHAR2(10);
280   BEGIN
281    FOR i in
282        (SELECT TRANSLATE(UPPER(substr(p_str, 1, 5)),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','AAAAAAAAAAAAAAAAAAAAAAAAAA') src_str1,
283                   TRANSLATE(substr(p_str, 6, 4),'0123456789','0000000000') src_str2,
284                   TRANSLATE(UPPER(substr(p_str, 10, 1)),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','AAAAAAAAAAAAAAAAAAAAAAAAAA') src_str3,
285                   'AAAAA0000A' dest_str
286       FROM    dual) LOOP
287 
288      IF (i.src_str1 || i.src_str2 || i.src_str3) = i.dest_str or p_str in ('PANNOTAVBL', 'PANAPPLIED') then/*ETDS FVU3.1 Bug 11896260*/
289        lv_resp := 'VALID';
290      ELSE
291        lv_resp := 'INVALID';
292      END IF;
293 
294      EXIT;
295    END LOOP;
296 
297     RETURN lv_resp;
298   END;
299 
300   PROCEDURE chk_err (p_err IN VARCHAR2,
301                        p_message IN VARCHAR2) IS
302   BEGIN
303     IF (p_err = 'E') THEN
304         FND_FILE.put_line(FND_FILE.log, p_message);
305         RAISE_APPLICATION_ERROR(-20099, p_message, true);
306     ELSIF  (p_err in ('N', 'S')) THEN
307         FND_FILE.put_line(FND_FILE.log, p_message);
308     END IF;
309   END chk_err;
310 
311   PROCEDURE get_attr_value (p_org_id IN NUMBER,
312                             p_attr_code IN VARCHAR2,
313                             p_attr_val OUT NOCOPY VARCHAR2,
314                             p_err OUT NOCOPY VARCHAR2,
315                             p_return_message OUT NOCOPY VARCHAR2
316                             ) IS
317 
318   CURSOR c_org_exists (p_org_id NUMBER)
319   IS
320   select '1'
321   from jai_rgm_definitions jrd,
322        jai_rgm_parties jrp
323   where jrd.regime_code = 'TDS'
324   and   jrd.regime_id = jrp.regime_id
325   and   jrp.organization_id = p_org_id;
326 
327   CURSOR c_party_setup (p_attr_code VARCHAR2, p_org_id NUMBER)
328   IS
329   select jrpr.attribute_value
330   from jai_rgm_parties jrp,
331        jai_rgm_definitions jrd,
332        jai_rgm_party_regns jrpr,
333        jai_rgm_registrations jrr
337   and jrr.attribute_code = p_attr_code
334   where jrd.regime_code = 'TDS'
335   and jrd.regime_id = jrp.regime_id
336   and jrp.regime_org_id = jrpr.regime_org_id
338   and jrp.organization_id = p_org_id
339   and jrr.registration_id = jrpr.registration_id;
340 
341   CURSOR c_regime_setup (p_attr_code VARCHAR2)
342   IS
343   select jrr.attribute_value
344   from jai_rgm_definitions jrd,
345        jai_rgm_registrations jrr
346   where jrd.regime_code = 'TDS'
347   and jrd.regime_id = jrr.regime_id
348   and jrr.attribute_code = p_attr_code;
349 
350   l_org_exists NUMBER;
351   l_attr_val   VARCHAR2(240);
352 
353   BEGIN
354 
355     l_org_exists := 0;
356     l_attr_val := NULL;
357 
358     OPEN c_org_exists (p_org_id);
359     FETCH c_org_exists INTO l_org_exists;
360     CLOSE c_org_exists;
361 
362     IF (l_org_exists = 0) THEN
363         p_return_message := 'Regime Registration Setup does not exist for the current Organization';
364         p_err := 'E';
365         p_attr_val := NULL;
366         return;
367     END IF;
368 
369     OPEN c_party_setup (p_attr_code, p_org_id);
370     FETCH c_party_setup INTO l_attr_val;
371     CLOSE c_party_setup;
372 
373     IF (l_attr_val IS NULL) THEN
374         OPEN c_regime_setup (p_attr_code);
375         FETCH c_regime_setup INTO l_attr_val;
376         CLOSE c_regime_setup;
377     END IF;
378 
379     IF (l_attr_val IS NULL) THEN
380         p_return_message := 'Attribute ' || p_attr_code || ' is not defined';
381         p_err := 'N';
382         p_attr_val := NULL;
383         return;
384     ELSE
385         p_attr_val := l_attr_val;
386         p_return_message := 'Attribute ' || p_attr_code || ' = ' || p_attr_val;
387         p_err := 'S';
388     END IF;
389 
390   END get_attr_value;
391 
392   /*Bug 8880543 - Changes for eTDS/eTCS FVU Changes - End*/
393 
394 
395   FUNCTION formatAmount( p_amount IN NUMBER) RETURN VARCHAR2 IS
396   BEGIN
397 
398     -- return (replace(to_char(ROUND(nvl(p_amount,0), 2), '999999999999D99'),'.'));
399     return ( to_char(ROUND(nvl(p_amount,0), 2)*100 ) );
400   END formatAmount;
401 
402   FUNCTION getSectionCode( p_section IN VARCHAR2,  p_string IN VARCHAR2 DEFAULT NULL ) RETURN VARCHAR2 IS
403   BEGIN
404 
405     IF p_section IS NOT NULL THEN
406       -- Bug 6796765. Added by Lakshmi Gopalsami
407       -- Changed to p_string instead of hardcoded value
408       --return replace(translate(p_section, p_string, ' '), ' '); commneted and added below by mmurtuza for bug12943133 to accomodate sections with E and C
409   --return replace(translate(p_section, p_string, ' '), 'SEC', ' '); commneted and added below by mmurtuza for bug13439411
410   return trim(replace(translate(p_section, p_string, ' '), 'SEC', ' '));
411     ELSE
412       return ' ';
413     END IF;
414 
415   END getSectionCode;
416 
417   PROCEDURE openFile(
418     p_directory IN VARCHAR2,
419     p_filename IN VARCHAR2
420   ) IS
421 
422   BEGIN
423 
424     v_filehandle := UTL_FILE.fopen(p_directory, p_filename, 'W', 5000); --Added 5000 buffer size for bug#6647362
425 
426     v_utl_file_dir  := p_directory;
427     v_utl_file_name := p_filename;
428 
429   END openFile;
430 
431   PROCEDURE closeFile IS
432   BEGIN
433     UTL_FILE.fclose(v_filehandle);
434   END closeFile;
435 
436 /* Commented by Chong for eTDS ER bug#16414088 Start
437   PROCEDURE populate_details(
438     p_batch_id IN NUMBER,
439    -- p_legal_entity_id IN NUMBER, -- Harshita for Bug 4889272
440     p_org_tan_num IN VARCHAR2,
441     p_tds_vendor_id IN NUMBER,
442     p_tds_vendor_site_id IN NUMBER,
443     p_tds_inv_from_date IN DATE,
444     p_tds_inv_to_date IN DATE,
445     p_etds_yearly_returns VARCHAR2,
446     p_include_list  IN  VARCHAR2,      --Date 11-05-2007 by Sacsethi for bug 5647248
447     p_exclude_list  IN  VARCHAR2,
448     p_organization_id IN NUMBER \* Bug#10315928 *\
449   )
450   IS
451     v_tds_check_id    NUMBER(15);
452     v_prepay_inv_id_of_tds  NUMBER(15);
453     v_bank_account_id NUMBER(15);
454     v_bank_account_name VARCHAR2(50);  -- added by csahoo for BUG#6158875
455 
456     v_temp_challan_num  VARCHAR2(50);
457     v_temp_challan_date DATE;
458     v_temp_bank     NUMBER(15);
459     v_temp_bank_acc_name VARCHAR2(50);  -- added by csahoo for BUG#6158875
460 
461     v_statement_id    VARCHAR2(3);
462     v_debug_base_invid    NUMBER(15);
463     v_debug_tds_invid   NUMBER(15);
464 
465     v_base_check_date DATE;
466     v_tds_check_date  DATE;
467     v_challan_num   VARCHAR2(50);
468     v_challan_date    DATE;
469     v_bank_branch_code  HZ_ORGANIZATION_PROFILES.BANK_OR_BRANCH_NUMBER%TYPE;
470 
471     v_challan_err   VARCHAR2(100);
472     v_deductee_err    VARCHAR2(100);
473 
474     v_base_invoice_check_id NUMBER(15);
475     v_prepay_inv_id_of_base NUMBER(15);
476 
477     v_payment_id NUMBER;
478     v_prepay_invoice_id NUMBER;
479     v_prepayment_amount_applied NUMBER;
480 
481     \* Bug 4353842. Added by Lakshmi Gopalsami *\
482     ln_check_number        ap_checks_all.check_number%TYPE;
483     ln_tax_rate            JAI_CMN_TAXES_ALL.tax_rate%TYPE;
484     ln_tds_rate            JAI_CMN_TAXES_ALL.tax_rate%TYPE;
485     ln_surcharge_rate      JAI_CMN_TAXES_ALL.surcharge_rate%TYPE;
486     ln_cess_rate           JAI_CMN_TAXES_ALL.cess_rate%TYPE;
487     ln_inv_amt             ap_invoices_all.invoice_amount%TYPE;
488 
489     -- added, Harshita for Bug 4525089
490 
491     lv_cert_issue_date    DATE ;
495                   -- ended, Harshita for Bug 4525089
492     ln_tds_amt             JAI_AP_ETDS_T.amt_of_tds%TYPE;
493     ln_surcharge_amt       JAI_AP_ETDS_T.amt_of_surcharge%TYPE;
494     ln_cess_amt            JAI_AP_ETDS_T.amt_of_cess%TYPE;
496 
497 --Date 11-05-2007 by Sacsethi for bug 5647248
498 -- start 5647248
499     lv_include_flag VARCHAR2(1);
500     lv_exclude_flag VARCHAR2(1);
501     TYPE lv_list IS VARRAY(10) OF VARCHAR2(30);
502     lv_include lv_list :=lv_list();
503     lv_exclude lv_list :=lv_list();
504 -- end 5647248
505 \*Bug 11896260 - Start*\
506                   CURSOR c_get_pp_apply_amt (p_invoice_id IN NUMBER)
507                   IS
508                   SELECT SUM(application_amount)
509                   FROM jai_ap_tds_prepayments jatp
510                   WHERE invoice_id = p_invoice_id
511                   AND (SELECT accounting_date
512                        FROM ap_invoice_distributions_all
513                        WHERE invoice_distribution_id = jatp.invoice_distribution_id)
514                        <=
515                       (SELECT accounting_date
516                        FROM ap_invoice_distributions_all
517                        WHERE invoice_distribution_id IN (SELECT prepay_distribution_id
518                                                          FROM ap_invoice_distributions_all
519                                                          WHERE invoice_distribution_id = jatp.invoice_distribution_id_prepay
520                                                         )
521                        );
522                   CURSOR c_get_applied_amt (p_invoice_id IN NUMBER)
523                   IS
524                   SELECT SUM(application_amount)
525                   FROM jai_ap_tds_prepayments jatp
526                   WHERE invoice_id IN (SELECT invoice_id
527                                        FROM ap_invoice_distributions_all
528                                        WHERE prepay_distribution_id IN (SELECT invoice_distribution_id
529                                                                         FROM ap_invoice_distributions_all
530                                                                         WHERE invoice_id = p_invoice_id
531                                                                        )
532                                       )
533                   AND (SELECT accounting_date
534                        FROM ap_invoice_distributions_all
535                        WHERE invoice_distribution_id = jatp.invoice_distribution_id)
536                        >
537                       (SELECT accounting_date
538                        FROM ap_invoice_distributions_all
539                        WHERE invoice_distribution_id IN (SELECT prepay_distribution_id
540                                                          FROM ap_invoice_distributions_all
541                                                          WHERE invoice_distribution_id = jatp.invoice_distribution_id_prepay
542                                                         )
543                        );
544                   CURSOR c_get_remaining_amt (p_invoice_id IN NUMBER)
545                   IS
546                   SELECT sum(prepay_amount_remaining)
547                   FROM ap_invoice_distributions_all
548                   WHERE invoice_id = p_invoice_id;
549                   CURSOR c_threshold_tran_inv (p_threshold_grp_id IN NUMBER)
550                   IS
551                   SELECT tds_invoice_id, tds_check_id, tds_tax_id, tds_amount
552                   FROM jai_ap_etds_t
553                   WHERE tds_invoice_id = (SELECT MAX(invoice_to_tds_authority_id)
554                                          FROM jai_ap_tds_thhold_trxs
555                                          WHERE threshold_grp_id = p_threshold_grp_id
556                                          AND tds_event LIKE 'THRESHOLD TRANSITION%'
557                                         );
558                   CURSOR c_gl_date(p_tds_invoice_id IN NUMBER)
559                   IS
560                   SELECT gl_date
561                   FROM ap_invoices_all
562                   WHERE invoice_id = p_tds_invoice_id;
563                   CURSOR c_chk_threshold_rollback(p_threshold_grp_id IN NUMBER)
564                   IS
565                   SELECT invoice_to_tds_authority_id
566                   FROM jai_ap_tds_thhold_trxs
567                   WHERE tds_event LIKE 'THRESHOLD ROLLBACK%'
568                   AND threshold_grp_id = p_threshold_grp_id
569                   AND invoice_to_tds_authority_id > (SELECT MAX(invoice_to_tds_authority_id)
570                                                      FROM jai_ap_tds_thhold_trxs
571                                                      WHERE threshold_grp_id = p_threshold_grp_id
572                                                      AND tds_event LIKE 'THRESHOLD TRANSITION%'
573                                                     );
574                   ln_calculated_inv_amt     NUMBER;
575                   ln_pp_apply_amt           NUMBER;
576                   ln_remain_amt             NUMBER;
577                   r_threshold_tran_inv      c_threshold_tran_inv%ROWTYPE;
578                   r_chk_threshold_rollback  c_chk_threshold_rollback%ROWTYPE;
579                   lv_bank_branch_code       AP_BANK_BRANCHES.bank_num%TYPE;
580                   ln_surcharge_amount       NUMBER;
581                   ln_sh_cess_amount         NUMBER;
582                   ln_cess_amount            NUMBER;
583                   ln_tds_amount             NUMBER;
584                   ld_gl_date                DATE;
585                   \*Bug 11896260 - End*\
586 
587     v_legalEntityTan VARCHAR2(50);
588     lv_voided        CONSTANT VARCHAR2(30) := 'VOIDED';          --rchandan for bug#4428980
589     lv_stop_init      CONSTANT VARCHAR2(30) := 'STOP INITIATED';--rchandan for bug#4428980
590     lv_india_tds_source CONSTANT VARCHAR2(30) := 'INDIA TDS';--rchandan for bug#4428980
591     lv_source_attribute VARCHAR2(30);--rchandan for bug#4428980
592 
596       FROM hr_all_organization_units
593     -- to get TAN of an organization
594     CURSOR c_tan_number(p_organization_id IN NUMBER) IS
595       SELECT attribute1
597       WHERE organization_id = p_organization_id;
598 
599     \*added by csahoo for bug # 6158875, START*\
600     \*Modified the cursor c_tds_payment_check_id by JMEENA for bug#4600778 to select the bsr_code from JAI_AP_TDS_PAYMENTS table *\
601     CURSOR c_tds_payment_check_id(p_invoice_id IN NUMBER) IS
602     SELECT pay.check_id, apc.bank_account_name, JATP.Challan_no challan_num,
603       JATP.check_deposit_date challan_date, JATP.bsr_code   branch_code, apc.check_number check_number \*Bug 7688789 - Added Check Number*\
604     FROM ap_invoice_payments_all PAY, ap_checks_all APC \* renamed the table from ap_checks_v to ap_checks_All for bug 12691784*\, JAI_AP_TDS_PAYMENTS JATP
605     WHERE PAY.invoice_id = p_invoice_id
606     AND PAY.check_id = APC.check_id
607     AND APC.check_id = JATP.check_id
608     AND APC.status_lookup_code NOT IN (lv_voided,lv_stop_init);
609 
610     \*Bug 12415388 - Get Payment details based on CHECK_ID instead of TDS_INVOICE_ID as a single TDS Invoice may be paid with multiple checks*\
611     CURSOR c_tds_payment_details(p_check_id IN NUMBER) IS
612     SELECT pay.check_id, apc.bank_account_name, JATP.Challan_no challan_num,
613       JATP.check_deposit_date challan_date, JATP.bsr_code   branch_code, apc.check_number check_number \*Bug 7688789 - Added Check Number*\
614     FROM ap_invoice_payments_all PAY, ap_checks_all APC\*renamed the table from ap_checks_v to ap_checks_All for Bug 12691784*\, JAI_AP_TDS_PAYMENTS JATP
615     WHERE PAY.check_id = p_check_id
616     AND PAY.check_id = APC.check_id
617     AND APC.check_id = JATP.check_id
618     AND APC.status_lookup_code NOT IN (lv_voided,lv_stop_init);
619 
620     CURSOR c_base_payment_check_id(p_invoice_id IN NUMBER) IS
621           SELECT pay.check_id, apc.current_bank_account_name, check_date
622           FROM ap_invoice_payments_all PAY, ap_checks_v APC
623           WHERE PAY.invoice_id = p_invoice_id
624           AND PAY.check_id = APC.check_id
625         AND APC.status_lookup_code NOT IN (lv_voided, lv_stop_init);
626 
627     \*added by csahoo for bug # 6158875, END*\
628 
629     CURSOR c_prepay_invoice_id(p_tds_invoice_id IN NUMBER) IS
630       SELECT b.invoice_id prepay_invoice_id
631       FROM ap_invoice_distributions_all a, ap_invoice_distributions_all b
632       WHERE a.invoice_id = p_tds_invoice_id
633       AND a.prepay_distribution_id IS NOT NULL
634       AND (a.reversal_flag IS NULL OR a.reversal_flag = 'N')  --rchandan for bug#4428980
635       AND b.invoice_distribution_id = a.prepay_distribution_id;
636 
637     CURSOR c_cert_issue_date(p_tds_invoice_id IN NUMBER) IS
638       SELECT a.issue_date
639       FROM JAI_AP_TDS_F16_HDRS_ALL a, JAI_AP_TDS_INV_PAYMENTS b -- Bug#4517720 ja_in_ap_form16_dtl b
640       WHERE a.certificate_num = b.certificate_num
641       AND a.org_tan_num = b.org_tan_num
642       AND a.fin_yr = b.fin_year
643       AND b.invoice_id = p_tds_invoice_id;
644 
645     CURSOR c_check_date(p_check_id IN NUMBER) IS
646       SELECT nvl(jatp.check_date, jatp.check_date) check_date
647       FROM JAI_AP_TDS_INV_PAYMENTS jatp
648       WHERE
649     check_id = p_check_id;
650     lv_tds_check_date DATE ;
651 
652     --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, begin
653     CURSOR c_get_tds_inv_det(cp_invoice_id NUMBER)
654     IS
655     SELECT threshold_trx_id,
656            tax_amount,
657            taxable_amount,
658            tds_event
659     FROM jai_ap_tds_thhold_trxs jatt
660     WHERE jatt.invoice_to_tds_authority_id = cp_invoice_id
661     AND tds_event like 'SURCHARGE_CALCULATE';
662 
663   r_get_tds_inv c_get_tds_inv_det%rowtype;
664 
665     --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, end
666 
667     CURSOR c_tax_rates(p_tax_id JAI_CMN_TAXES_ALL.tax_id%TYPE)
668     IS
669     SELECT
670         NVL(tax_rate,0) tax_rate,
671         (NVL(tax_rate,0) - (NVL(surcharge_rate,0) + NVL(cess_rate,0) + NVL(sh_cess_rate,0))) tds_rate,  -- added NVL, Harshita for Bug 4639067  --Added sh_cess_rate by Bgowrava for bug #6195027
672         NVL(surcharge_rate,0) surcharge_rate,
673         NVL(cess_rate,0) cess_rate,
674       NVL(sh_cess_rate,0) sh_cess_rate --Added by Bgowrava for Bug#6195027
675     FROM
676         JAI_CMN_TAXES_ALL jtc
677     WHERE
678         tax_id = p_tax_id  ;
679     \*Bug 11896260 - Start*\
680 
681     r_tax_rates               c_tax_rates%ROWTYPE;
682     r_tds_payment_check_id    c_tds_payment_check_id%ROWTYPE;
683     r_tds_payment_details     c_tds_payment_details%ROWTYPE; \*12415388*\
684     \*Bug 11896260 - End*\
685 
686     -- Bug 5975168. Added by csahoo, start
690 
687     ln_con_for_challan  NUMBER ;
688   ln_con_for_deductee NUMBER ;
689   -- Bug 5975168. end
691   \*START, Bgowrava for Bug#6195027*\
692   ln_sh_cess_rate NUMBER ;
693     ln_sh_cess_amt NUMBER ;
694   \*END, Bgowrava for Bug#6195027*\
695 
696   PROCEDURE populate_include_exclude_list(
697         p_include_exclude_list IN VARCHAR2,
698         p_include_exclude_arr OUT NOCOPY lv_list)
699     IS
700           ln_pos          NUMBER;
701           ln_initial_pos  NUMBER;
702           ln_length       NUMBER;
703           lv_char         VARCHAR2(1);
704         BEGIN
705           p_include_exclude_arr:=lv_list();
706           lv_char := ',';
707           ln_initial_pos := 1;
708           p_include_exclude_arr.extend(10);
709           FOR lv_count in 1..10
710             LOOP
711               p_include_exclude_arr(lv_count) := NULL;
712             END LOOP;
713           IF p_include_exclude_list IS NOT NULL THEN
714             FOR lv_count in 1..10
715             LOOP
716               ln_pos := instr (p_include_exclude_list, lv_char, 1, lv_count);
717               IF ln_pos <> 0 THEN
718                 ln_length   := ln_pos - ln_initial_pos ;
719                 p_include_exclude_arr(lv_count) := substr (p_include_exclude_list, ln_initial_pos , ln_length);
720                 ln_initial_pos := ln_pos + 1 ;
721               ELSE
722                 p_include_exclude_arr(lv_count) := substr (p_include_exclude_list, ln_initial_pos);
723 
724                 FOR i in lv_count+1..10
725                 LOOP
726                   p_include_exclude_arr(i) :=   p_include_exclude_arr(lv_count) ;
727                 END LOOP ;
728                 EXIT;
729               END IF;
730             END LOOP;
731           END IF;
732   -- end 5647248
733 
734        END populate_include_exclude_list;
735 
736   BEGIN
737 
738     v_statement_id := '1';
739 
740     v_statement_id := '2';
741     lv_source_attribute := 'ATTRIBUTE1';  --rchandan for bug#4428980
742 
743     lv_include.extend(10);
744     lv_exclude.extend(10);
745 
746     --Date 11-05-2007 by Sacsethi for bug 5647248
747 
748     IF p_include_list IS NOT NULL THEN
749       lv_include_flag := 'Y';
750       populate_include_exclude_list(p_include_list, lv_include);
751     ElSE
752       lv_include_flag := 'N';
753     END IF;
754 
755     IF p_exclude_list IS NOT NULL THEN
756       lv_exclude_flag := 'Y';
757       populate_include_exclude_list(p_exclude_list, lv_exclude);
758      ElSE
759       lv_exclude_flag := 'N';
760      END IF;
761     -- end 5647248
762 
763     INSERT INTO JAI_AP_ETDS_T (
764       batch_id,
765       base_invoice_id,
766       tds_invoice_id,
767       tds_invoice_num,
768       tds_invoice_date,
769       tds_section,
770       tds_tax_id,
771       tds_tax_rate,
772       tds_amount,
773       consider_for_challan,
774       consider_for_deductee,
775       tds_check_id,
776       base_invoice_date ,
777       created_by,
778       creation_date,
779       last_updated_by,
780       last_update_date
781     ) SELECT p_batch_id,
782       base_invoices.invoice_id,  -- base_invoice_id
783       tds_invoices.invoice_id,   -- tds_invoice_id
784       tds_invoices.invoice_num,  -- tds_invoice_num
785       tds_invoices.invoice_date, -- tds_invoice_date
786       a.tds_section,
787       a.tds_tax_id,
788       a.tds_tax_rate,
789       a.tax_amount,
790       1,
791       1,
792       a.check_id,
793       base_invoices.invoice_date,
794       fnd_global.user_id,
795       sysdate,
796       fnd_global.user_id,
797       sysdate
798       from  JAI_AP_TDS_INV_PAYMENTS a, ap_invoices_all base_invoices, ap_invoices_all tds_invoices
799                               where a.parent_invoice_id = base_invoices.invoice_id
800                               and   a.invoice_id = tds_invoices.invoice_id
801                               \*Bug 10020606 - All TDS reports must be based on GL Date or date on which TCS Liability is booked*\
802                               and   base_invoices.gl_date between p_tds_inv_from_date and p_tds_inv_to_date
803                               and   a.tax_authority_id = p_tds_vendor_id
804                               and   (p_tds_vendor_site_id is null or a.tax_authority_site_id = p_tds_vendor_site_id)
805                               and   a.payment_amount <> 0
806                 and   base_invoices.org_id = p_organization_id \* Added the condition for Bug 12691784 *\
807                               and   a.org_tan_num = p_org_tan_num
808                   and
809                               ( lv_include_flag = 'N' or ( lv_include_flag = 'Y'
810                     and upper(a.tds_section) in ( lv_include(1),lv_include(2),lv_include(3),lv_include(4),lv_include(5),lv_include(6),lv_include(7),lv_include(8),lv_include(9),lv_include(10) )  ))
811                               and
812                               ( lv_exclude_flag = 'N' or ( lv_exclude_flag = 'Y'
813                     and upper(a.tds_section) not in ( lv_exclude(1),lv_exclude(2),lv_exclude(3),lv_exclude(4),lv_exclude(5),lv_exclude(6),lv_exclude(7),lv_exclude(8),lv_exclude(9),lv_exclude(10)) ) );
814                                 --Added above two conditions by  Bgowrava for bug#7485031
815   \* ER: 13514846 - Zero tax rate lower rate records *\
816   INSERT INTO JAI_AP_ETDS_T (
817                                 batch_id,
818                                 base_invoice_id,
819                                 tds_invoice_id,
820                                 tds_invoice_num,
821                                 tds_invoice_date,
822                                 tds_section,
826                                 consider_for_challan,
823                                 tds_tax_id,
824                                 tds_tax_rate,
825                                 tds_amount,
827                                 consider_for_deductee,
828                                 tds_check_id,
829                                 base_invoice_date,
830                                 base_vendor_id,
831                                 base_vendor_site_id,
832                                 base_invoice_type_lookup_code,
833                                 challan_num,
834                                 challan_date,
835                                 check_number,
836                                 bank_branch_code,
837                                 challan_error,
838                                 deductee_error,
839                                 amt_of_tds,
840                                 amt_of_surcharge,
841                                 amt_of_cess,
842                                 certificate_issue_date,
843                                 tds_check_date,
844                                 base_taxabale_amount,
845                                 tds_vendor_classification,
846                                 created_by,
847                                 creation_date,
848                                 last_updated_by,
849                                 last_update_date
850                             )
851                             select
852                                 p_batch_id,
853                                 jatit.invoice_id,
854                                 -9997,
855                                 NULL,
856                                 max(aia.invoice_date),
857                                 nvl(jatit.actual_section_code, jatit.default_section_code),
858                                 nvl(jatit.actual_tax_id, jatit.default_tax_id),
859                                 max(jitc.tax_rate),
860                                 sum(jatit.tax_amount),
861                                 1,
862                                 1,
863                                 -9999,
864                                 max(aia.invoice_date),
865                                 max(aia.vendor_id),
866                                 max(aia.vendor_site_id),
867                                 max(aia.invoice_type_lookup_code),
868                                 NULL,
869                                 NULL,
870                                 NULL,
871                                 NULL,
872                                 NULL,
873                                 NULL,
874                                 0,
875                                 0,
876                                 0,
877                                 NULL,
878                                 NULL,
879                                 max(aia.invoice_amount),
880                                 max(jte.tds_vendor_classification),
881                                 fnd_global.user_id,
882                                 sysdate,
883                                 fnd_global.user_id,
884                                 sysdate
885                             FROM ap_invoices_all aia,
886                                  ap_invoice_distributions_all aida,
887                                  jai_ap_tds_inv_taxes jatit,
888                                  JAI_AP_TDS_VENDOR_HDRS jte,
889                                  JAI_CMN_TAXES_ALL jitc
890                             WHERE aia.invoice_id = jatit.invoice_id
891                             AND jatit.threshold_grp_id IS NOT NULL
892                             AND aia.cancelled_date IS NULL
893                             AND nvl(jatit.actual_tax_id, jatit.default_tax_id) = jitc.tax_id
894                             AND aia.vendor_id = jte.vendor_id
895                             AND aia.vendor_site_id = jte.vendor_site_id
896                             AND aia.invoice_id = aida.invoice_id
897                             and aida.accounting_Date between p_tds_inv_from_date and p_tds_inv_to_date
898                             AND aida.match_status_flag in ('A','T')
899                             AND aia.invoice_type_lookup_code IN ('STANDARD','PREPAYMENT')
900                             AND aia.org_id = p_organization_id
901                             and not exists (select 1 from jai_ap_tds_thhold_trxs where invoice_id = jatit.invoice_id)
902                             and jitc.tax_rate = 0
903                             and jitc.vendor_id = p_tds_vendor_id
904                             and (p_tds_vendor_site_id is null or jitc.vendor_site_id = p_tds_vendor_site_id)
905                             and upper(jitc.section_code) in (select lookup_code
906                                                              from fnd_lookup_values_vl
907                                                              where lookup_type in ('JAI_TDS_SECTION_ZERO_RATE_197', 'JAI_TDS_SECTION_ZERO_RATE_197A'))
908                             group by jatit.invoice_id, nvl(jatit.actual_section_code, jatit.default_section_code), nvl(jatit.actual_tax_id, jatit.default_tax_id);
909     \* ER : 13514846 -end*\
910     \* Bug#10315928 - Start *\
911     INSERT INTO JAI_AP_ETDS_T (
912                                 batch_id,
913                                 base_invoice_id,
914                                 tds_invoice_id,
915                                 tds_invoice_num,
916                                 tds_invoice_date,
917                                 tds_section,
918                                 tds_tax_id,
919                                 tds_tax_rate,
920                                 tds_amount,
921                                 consider_for_challan,
922                                 consider_for_deductee,
923                                 tds_check_id,
924                                 base_invoice_date,
925                                 base_vendor_id,
926                                 base_vendor_site_id,
930                                 check_number,
927                                 base_invoice_type_lookup_code,
928                                 challan_num,
929                                 challan_date,
931                                 bank_branch_code,
932                                 challan_error,
933                                 deductee_error,
934                                 amt_of_tds,
935                                 amt_of_surcharge,
936                                 amt_of_cess,
937                                 certificate_issue_date,
938                                 tds_check_date,
939                                 base_taxabale_amount,
940                         tds_vendor_classification,
941                         created_by,
942                           creation_date,
943                           last_updated_by,
944                           last_update_date
945                         ) select distinct
946                                 p_batch_id,
947                                 base_invoices.invoice_id,
948                                 -9999,
949                                 NULL,
950                                 base_invoices.invoice_date,
951                                 --'SEC. 194(C)',
952                                 decode(jte.tds_vendor_classification,'Transporter','SEC. 194(C)','Software', decode(povs.country, 'IN','SEC. 194(J)','SEC. 195')),
953                                 \*Added above decode by Avanija for FVU3.6*\
954                                 a.tax_id,
955                                 0,
956                                 0,
957                                 1,
958                                 1,
959                                 -9999,
960                                 base_invoices.invoice_date,
961                                 base_invoices.vendor_id,
962                                 base_invoices.vendor_site_id,
963                                 base_invoices.invoice_type_lookup_code,
964                                 NULL,
965                                 NULL,
966                                 NULL,
967                                 NULL,
968                                 NULL,
969                                 NULL,
970                                 0,
971                                 0,
972                                 0,
973                                 NULL,
974                                 NULL,
975                                 base_invoices.invoice_amount,
976                         jte.tds_vendor_classification,
977                         fnd_global.user_id,
978                           sysdate,
979                           fnd_global.user_id,
980                           sysdate
981                         from  jai_cmn_taxes_all a, ap_invoices_all base_invoices, po_vendor_sites_all povs, \* Added by Avanija for FVU3.6 *\
982                               ap_invoice_distributions_all aida, jai_ap_tds_vendor_hdrs jte
983                         where jte.vendor_id = base_invoices.vendor_id
984                         \*  FVU3.6 -start *\
985                         and povs.vendor_id = jte.vendor_id
986                         and povs.vendor_site_id = jte.vendor_site_id
987                         and base_invoices.cancelled_Date is null
988                         and a.tax_rate = 0
989                         \*  FVU3.6 -end *\
990                         and   a.tax_id = aida.global_attribute1
991                         and   jte.vendor_site_id = base_invoices.vendor_site_id--Added by Zhhou for bug#15962641 20121205
992                         --Changed by Zhiwei for Bug#15840480 FVU3.6 begin
993                         -----------------------------------------------------
994                         --and   jte.tds_vendor_classification = 'Transporter'
995                         and   jte.tds_vendor_classification in ('Transporter','Software')
996                         -----------------------------------------------------
997                         --Changed by Zhiwei for Bug#15840480  FVU3.6 end
998                         and   aida.global_attribute_category = 'JA.IN.APXINWKB.DISTRIBUTIONS'
999                         and   aida.invoice_id = base_invoices.invoice_id
1000                         and   aida.match_status_flag in ('A','T') \*10408793 - Unvalidated Invoices must not be picked*\
1001                         and   base_invoices.org_id = p_organization_id
1002                         and   base_invoices.invoice_type_lookup_code IN ('STANDARD','PREPAYMENT')
1003                         and   not exists (select '1' from jai_ap_tds_thhold_trxs jattt where jattt.invoice_id = base_invoices.invoice_id) \*Bug 10408793 - TDS should not be deducted*\
1004                         and not exists (select '1' from jai_ap_etds_t where base_invoice_id=base_invoices.invoice_id and batch_id=p_batch_id) \* Added by Avanija for FVU3.6 *\
1005                         --and   base_invoices.gl_date between p_tds_inv_from_date and p_tds_inv_to_date
1006                         and aida.accounting_date between p_tds_inv_from_date and p_tds_inv_to_date \* Changed by Avanija for FVU3.6 *\
1007                         and
1008                          ( lv_include_flag = 'N' or ( lv_include_flag = 'Y'
1009                                                       and upper(a.section_code) in ( lv_include(1),lv_include(2),
1010                                                       lv_include(3),lv_include(4),lv_include(5),lv_include(6),
1011                                                       lv_include(7),lv_include(8),lv_include(9),lv_include(10) )  ))
1012                         and
1013                          ( lv_exclude_flag = 'N' or ( lv_exclude_flag = 'Y'
1014                                                       and upper(a.section_code) not in ( lv_exclude(1),lv_exclude(2),
1015                                                       lv_exclude(3),lv_exclude(4),lv_exclude(5),lv_exclude(6),
1016                                                       lv_exclude(7),lv_exclude(8),lv_exclude(9),lv_exclude(10)) ) )
1017                         union all
1018                         select distinct
1022                                 NULL,
1019                                 p_batch_id,
1020                                 base_invoices.invoice_id,
1021                                 -9999,
1023                                 base_invoices.invoice_date,
1024                                 --'SEC. 194(C)',
1025                                 decode(jte.tds_vendor_classification,'Transporter','SEC. 194(C)','Software', decode(povs.country, 'IN','SEC. 194(J)','SEC. 195')),
1026                                 \* Added above decode by Avanija for FVU3.6*\
1027                                 -99,
1028                                 0,
1029                                 0,
1030                                 1,
1031                                 1,
1032                                 -9999,
1033                                 base_invoices.invoice_date,
1034                                 base_invoices.vendor_id,
1035                                 base_invoices.vendor_site_id,
1036                                 base_invoices.invoice_type_lookup_code,
1037                                 NULL,
1038                                 NULL,
1039                                 NULL,
1040                                 NULL,
1041                                 NULL,
1042                                 NULL,
1043                                 0,
1044                                 0,
1045                                 0,
1046                                 NULL,
1047                                 NULL,
1048                                 base_invoices.invoice_amount,
1049                                 jte.tds_vendor_classification,
1050                                 fnd_global.user_id,
1051                                 sysdate,
1052                                 fnd_global.user_id,
1053                                 sysdate
1054                         from  ap_invoices_all base_invoices,
1055                               ap_invoice_distributions_all aida, jai_ap_tds_vendor_hdrs jte, po_vendor_sites_all povs
1056                         where jte.vendor_id = base_invoices.vendor_id
1057                         and   jte.vendor_site_id = base_invoices.vendor_site_id--Added by Zhhou for bug#15962641 20121205
1058                         --Changed by Zhiwei for  Bug#15840480 FVU3.6 begin
1059                         -----------------------------------------------------
1060                         --and   jte.tds_vendor_classification = 'Transporter'
1061                         and   jte.tds_vendor_classification in ('Transporter','Software')
1062                         -----------------------------------------------------
1063                         --Changed by Zhiwei for  Bug#15840480 FVU3.6 end
1064                         and   aida.global_attribute1 is NULL
1065                         \*  FVU3.6 -start *\
1066                         and povs.vendor_id = jte.vendor_id
1067                         and povs.vendor_site_id = jte.vendor_site_id
1068                         and base_invoices.cancelled_Date is null
1069                         \*  FVU3.6 -end *\
1070                         and   (aida.global_attribute_category = 'JA.IN.APXINWKB.DISTRIBUTIONS' or aida.global_attribute_category is NULL)
1071                         and   aida.match_status_flag in ('A','T') \*10408793 - Unvalidated Invoices must not be picked*\
1072                         and   aida.invoice_id = base_invoices.invoice_id
1073                         and   base_invoices.org_id = p_organization_id
1074                         and   base_invoices.invoice_type_lookup_code IN ('STANDARD','PREPAYMENT')
1075                         and   not exists (select '1' from jai_ap_tds_thhold_trxs jattt where jattt.invoice_id = base_invoices.invoice_id) \*Bug 10408793 - TDS should not be deducted*\
1076                         and not exists (select '1' from jai_ap_etds_t where base_invoice_id=base_invoices.invoice_id and batch_id=p_batch_id) \* Added by Avanija for FVU3.6 *\
1077                         --and   base_invoices.gl_date between p_tds_inv_from_date and p_tds_inv_to_date
1078                         and aida.accounting_date between p_tds_inv_from_date and p_tds_inv_to_date \* Changed by Avanija for FVU3.6 *\
1079                         and   lv_exclude_flag = 'Y'
1080                         ;
1081 
1082                         \* Bug#10315928 - End *\
1083 
1084 
1085     v_statement_id := '3';
1086     \* -------- following fields of JAI_AP_ETDS_T needs to be populated now
1087       Invoice Distributions - prepayment_amount_applied
1088       Payment Details - tds_check_id, challan_num, challan_date, bank_branch_code
1089     --------------------------------- *\
1090   \*11896260 - Changes for FVU 3.1 - Start*\
1091                     \*Need to pick Invoices created before Threshold was breached and Prepayment not applied*\
1092                     FOR c_get_threshold_grp IN (SELECT threshold_grp_id
1093                                                 FROM jai_ap_tds_inv_taxes
1094                                                 WHERE invoice_id IN (SELECT base_invoice_id
1095                                                                      FROM jai_ap_etds_t
1096                                                                      WHERE batch_id = p_batch_id
1097                                                                      AND EXISTS (SELECT 1
1098                                                                                  FROM jai_ap_tds_thhold_trxs jatit_1
1099                                                                                  WHERE jatit_1.invoice_to_tds_authority_id = tds_invoice_id
1100                                                                                  AND jatit_1.tds_event LIKE 'THRESHOLD TRANSITION%'
1101                                                                                 )
1102                                                                     )
1103                                                )
1104                     LOOP
1105 
1106                         \*Check if Threshold Rollback has occured post Threshold Transition*\
1107                         OPEN c_chk_threshold_rollback(c_get_threshold_grp.threshold_grp_id);
1111                         EXIT WHEN r_chk_threshold_rollback.invoice_to_tds_authority_id IS NOT NULL;
1108                         FETCH c_chk_threshold_rollback INTO r_chk_threshold_rollback;
1109                         CLOSE c_chk_threshold_rollback;
1110 
1112                         INSERT INTO JAI_AP_ETDS_T (
1113                                 batch_id,
1114                                 base_invoice_id,
1115                                 tds_invoice_id,
1116                                 tds_invoice_num,
1117                                 tds_invoice_date,
1118                                 tds_section,
1119                                 tds_tax_id,
1120                                 tds_tax_rate,
1121                                 tds_amount,
1122                                 consider_for_challan,
1123                                 consider_for_deductee,
1124                                 tds_check_id,
1125                                 base_invoice_date,
1126                                 base_vendor_id,
1127                                 base_vendor_site_id,
1128                                 base_invoice_type_lookup_code,
1129                                 challan_num,
1130                                 challan_date,
1131                                 check_number,
1132                                 bank_branch_code,
1133                                 challan_error,
1134                                 deductee_error,
1135                                 amt_of_tds,
1136                                 amt_of_surcharge,
1137                                 amt_of_cess,
1138                                 certificate_issue_date,
1139                                 tds_check_date,
1140                                 base_taxabale_amount,
1141                                 tds_vendor_classification,
1142                                 created_by,
1143                                 creation_date,
1144                                 last_updated_by,
1145                                 last_update_date
1146                             )
1147                             select
1148                                 p_batch_id,
1149                                 jatit.invoice_id,
1150                                 -9999,
1151                                 NULL,
1152                                 aia.invoice_date,
1153                                 nvl(jatit.actual_section_code, jatit.default_section_code),
1154                                 nvl(jatit.actual_tax_id, jatit.default_tax_id),
1155                                 jitc.tax_rate,
1156                                 jatit.tax_amount,
1157                                 1,
1158                                 1,
1159                                 -9999,
1160                                 aia.invoice_date,
1161                                 aia.vendor_id,
1162                                 aia.vendor_site_id,
1163                                 aia.invoice_type_lookup_code,
1164                                 NULL,
1165                                 NULL,
1166                                 NULL,
1167                                 NULL,
1168                                 NULL,
1169                                 NULL,
1170                                 0,
1171                                 0,
1172                                 0,
1173                                 NULL,
1174                                 NULL,
1175                                 aia.invoice_amount,
1176                                 jte.tds_vendor_classification,
1177                                 fnd_global.user_id,
1178                                 sysdate,
1179                                 fnd_global.user_id,
1180                                 sysdate
1181                             FROM ap_invoices_all aia,
1182                                  ap_invoice_distributions_all aida,
1183                                  jai_ap_tds_inv_taxes jatit,
1184                                  JAI_AP_TDS_VENDOR_HDRS jte,
1185                                  JAI_CMN_TAXES_ALL jitc
1186                             WHERE aia.invoice_id = jatit.invoice_id
1187                             AND jatit.threshold_grp_id IS NOT NULL
1188                             AND jatit.threshold_grp_id = c_get_threshold_grp.threshold_grp_id
1189                             AND aia.cancelled_date IS NULL
1190                             AND NOT EXISTS (SELECT 1
1191                                             FROM jai_ap_tds_prepayments
1192                                             WHERE invoice_id = jatit.invoice_id)
1193                             AND nvl(jatit.actual_tax_id, jatit.default_tax_id) = jitc.tax_id
1194                             AND aia.vendor_id = jte.vendor_id
1195                             AND aia.vendor_site_id = jte.vendor_site_id
1196                             AND aia.invoice_id = aida.invoice_id
1197                             AND aida.match_status_flag in ('A','T')
1198                             AND aida.prepay_amount_remaining IS NULL
1199                             AND aia.invoice_type_lookup_code IN ('STANDARD','PREPAYMENT')
1200                             AND aia.org_id = p_organization_id
1201                             AND NOT EXISTS (SELECT 1
1202                                             FROM JAI_AP_ETDS_T
1203                                             WHERE base_invoice_id = jatit.invoice_id
1204                                             AND batch_id = p_batch_id
1205                                            )
1206                             AND ( lv_include_flag = 'N' or ( lv_include_flag = 'Y' and upper(nvl(jatit.actual_section_code, jatit.default_section_code))
1207                             in ( lv_include(1),lv_include(2),lv_include(3),lv_include(4),lv_include(5),lv_include(6),lv_include(7),lv_include(8),lv_include(9),lv_include(10))))
1208                             AND ( lv_exclude_flag = 'N' or ( lv_exclude_flag = 'Y' and upper(nvl(jatit.actual_section_code, jatit.default_section_code))
1212                         INSERT INTO JAI_AP_ETDS_T (
1209                             not in ( lv_exclude(1),lv_exclude(2),lv_exclude(3),lv_exclude(4),lv_exclude(5),lv_exclude(6),lv_exclude(7),lv_exclude(8),lv_exclude(9),lv_exclude(10), '94F')));
1210 
1211                         \*Need to pick Invoices created before Threshold was breached and Prepayment applied*\
1213                                 batch_id,
1214                                 base_invoice_id,
1215                                 tds_invoice_id,
1216                                 tds_invoice_num,
1217                                 tds_invoice_date,
1218                                 tds_section,
1219                                 tds_tax_id,
1220                                 tds_tax_rate,
1221                                 tds_amount,
1222                                 consider_for_challan,
1223                                 consider_for_deductee,
1224                                 tds_check_id,
1225                                 base_invoice_date,
1226                                 base_vendor_id,
1227                                 base_vendor_site_id,
1228                                 base_invoice_type_lookup_code,
1229                                 challan_num,
1230                                 challan_date,
1231                                 check_number,
1232                                 bank_branch_code,
1233                                 challan_error,
1234                                 deductee_error,
1235                                 amt_of_tds,
1236                                 amt_of_surcharge,
1237                                 amt_of_cess,
1238                                 certificate_issue_date,
1239                                 tds_check_date,
1240                                 base_taxabale_amount,
1241                                 tds_vendor_classification,
1242                                 created_by,
1243                                 creation_date,
1244                                 last_updated_by,
1245                                 last_update_date
1246                             )
1247                             select
1248                                 p_batch_id,
1249                                 jatit.invoice_id,
1250                                 -9998,
1251                                 NULL,
1252                                 aia.invoice_date,
1253                                 nvl(jatit.actual_section_code, jatit.default_section_code),
1254                                 nvl(jatit.actual_tax_id, jatit.default_tax_id),
1255                                 jitc.tax_rate,
1256                                 jatit.tax_amount,
1257                                 1,
1258                                 1,
1259                                 -9999,
1260                                 aia.invoice_date,
1261                                 aia.vendor_id,
1262                                 aia.vendor_site_id,
1263                                 aia.invoice_type_lookup_code,
1264                                 NULL,
1265                                 NULL,
1266                                 NULL,
1267                                 NULL,
1268                                 NULL,
1269                                 NULL,
1270                                 0,
1271                                 0,
1272                                 0,
1273                                 NULL,
1274                                 NULL,
1275                                 aia.invoice_amount,
1276                                 jte.tds_vendor_classification,
1277                                 fnd_global.user_id,
1278                                 sysdate,
1279                                 fnd_global.user_id,
1280                                 sysdate
1281                             FROM ap_invoices_all aia,
1282                                  ap_invoice_distributions_all aida,
1283                                  jai_ap_tds_inv_taxes jatit,
1284                                  JAI_AP_TDS_VENDOR_HDRS jte,
1285                                  JAI_CMN_TAXES_ALL jitc
1286                             WHERE aia.invoice_id = jatit.invoice_id
1287                             AND jatit.threshold_grp_id IS NOT NULL
1288                             AND jatit.threshold_grp_id = c_get_threshold_grp.threshold_grp_id
1289                             AND aia.cancelled_date IS NULL
1290                             AND (EXISTS (SELECT 1
1291                                             FROM jai_ap_tds_prepayments
1292                                             WHERE invoice_id = jatit.invoice_id)
1293                                  OR aida.prepay_amount_remaining IS NOT NULL)
1294                             AND nvl(jatit.actual_tax_id, jatit.default_tax_id) = jitc.tax_id
1295                             AND aia.vendor_id = jte.vendor_id
1296                             AND aia.vendor_site_id = jte.vendor_site_id
1297                             AND aia.invoice_id = aida.invoice_id
1298                             AND aida.match_status_flag in ('A','T')
1299                             AND aia.invoice_type_lookup_code IN ('STANDARD','PREPAYMENT')
1300                             AND aia.org_id = p_organization_id
1301                             AND NOT EXISTS (SELECT 1
1302                                             FROM JAI_AP_ETDS_T
1303                                             WHERE base_invoice_id = jatit.invoice_id
1304                                             AND batch_id = p_batch_id
1305                                            )
1306                             AND ( lv_include_flag = 'N' or ( lv_include_flag = 'Y' and upper(nvl(jatit.actual_section_code, jatit.default_section_code))
1307                             in ( lv_include(1),lv_include(2),lv_include(3),lv_include(4),lv_include(5),lv_include(6),lv_include(7),lv_include(8),lv_include(9),lv_include(10))))
1308                             AND ( lv_exclude_flag = 'N' or ( lv_exclude_flag = 'Y' and upper(nvl(jatit.actual_section_code, jatit.default_section_code))
1312                         ln_sh_cess_amount := 0;
1309                             not in ( lv_exclude(1),lv_exclude(2),lv_exclude(3),lv_exclude(4),lv_exclude(5),lv_exclude(6),lv_exclude(7),lv_exclude(8),lv_exclude(9),lv_exclude(10),'94F')));
1310 
1311                         ln_surcharge_amount := 0;
1313                         ln_cess_amount := 0;
1314                         ln_tds_amount := 0;
1315                         r_threshold_tran_inv := NULL;
1316                         r_tds_payment_check_id := NULL;
1317                         lv_bank_branch_code := NULL;
1318                         r_tax_rates := NULL;
1319                         \*Fetch TDS Invoice details of the Threshold Transition Invoice*\
1320                         OPEN c_threshold_tran_inv(c_get_threshold_grp.threshold_grp_id);
1321                         FETCH c_threshold_tran_inv INTO r_threshold_tran_inv;
1322                         CLOSE c_threshold_tran_inv;
1323 
1324                         OPEN c_gl_date(r_threshold_tran_inv.tds_invoice_id);
1325                         FETCH c_gl_date INTO ld_gl_date;
1326                         CLOSE c_gl_date;
1327 
1328                         OPEN c_tds_payment_check_id(r_threshold_tran_inv.tds_invoice_id);
1329                         FETCH c_tds_payment_check_id INTO r_tds_payment_check_id;
1330                         CLOSE c_tds_payment_check_id;
1331 
1332                         OPEN c_tax_rates(r_threshold_tran_inv.tds_tax_id);
1333                         FETCH c_tax_rates INTO r_tax_rates;
1334                         CLOSE c_tax_rates;
1335                         \*Split the TDS Amount into appropriate components*\
1336                         ln_surcharge_amount   := round((r_threshold_tran_inv.tds_amount * r_tax_rates.surcharge_rate/r_tax_rates.tax_rate),2) ;
1337                         ln_sh_cess_amount     := round((r_threshold_tran_inv.tds_amount * r_tax_rates.sh_cess_rate/r_tax_rates.tax_rate),2);
1338                         ln_cess_amount        := round((r_threshold_tran_inv.tds_amount * r_tax_rates.cess_rate/r_tax_rates.tax_rate),2) + ln_sh_cess_amount;
1339                         ln_tds_amount         := r_threshold_tran_inv.tds_amount - NVL(ln_surcharge_amount,0) - NVL(ln_cess_amount,0) ;
1340                         \*Prorate TDS Amount of Threshold Transition invoice among the Invoices prior to Threshold*\
1341                         UPDATE jai_ap_etds_t
1342                         SET tds_check_id = r_threshold_tran_inv.tds_check_id,
1343                         challan_num = r_tds_payment_check_id.challan_num,
1344                         challan_date = r_tds_payment_check_id.challan_date,
1345                         check_number = r_tds_payment_check_id.check_number,
1346                         bank_branch_code = r_tds_payment_check_id.branch_code,
1347                         amt_of_tds = ((tds_amount*ln_tds_amount)/r_threshold_tran_inv.tds_amount),
1348                         amt_of_surcharge = ((tds_amount*ln_surcharge_amount)/r_threshold_tran_inv.tds_amount),
1349                         amt_of_cess = ((tds_amount*ln_cess_amount)/r_threshold_tran_inv.tds_amount),
1350                         tds_invoice_date = ld_gl_date \*GL Date and Invoice Date are same for TDS Invoices*\
1351                         WHERE tds_check_id = -9999
1352                         AND tds_invoice_id IN (-9998, -9999)
1353                         AND (tds_vendor_classification IS NULL
1354                         --OR tds_vendor_classification <> 'Transporter'--Commented by Zhiwei for Bug#15840480 FVU3.6
1355                         --Added by Zhiwei for  Bug#15840480 FVU3.6 begin
1356                         ------------------------------------------------
1357                         --OR tds_vendor_classification <> 'Software'
1358                         OR tds_vendor_classification not in ('Transporter','Software')
1359                         ------------------------------------------------
1360                         --Added by Zhiwei for  Bug#15840480 FVU3.6 end
1361                         );
1362 
1363                         DELETE jai_ap_etds_t
1364                         WHERE batch_id = p_batch_id
1365                         AND EXISTS (SELECT 1
1366                                     FROM jai_ap_tds_thhold_trxs
1367                                     WHERE invoice_to_tds_authority_id = tds_invoice_id
1368                                     AND tds_event LIKE 'THRESHOLD TRANSITION%'
1369                                     AND threshold_grp_id = c_get_threshold_grp.threshold_grp_id
1370                                     );
1371                     END LOOP;\*FOR c_get_threshold_grp*\
1372                     \*If a Prepayment is applied on a Standard Invoice
1373                     + Base Taxable amount of Standard Invoice must be equal the amount unpaid + amount paid by Prepayament if GL Date of
1374                       Prepayment is greater than Standard Invoice
1375                     + Base Taxable amount of Standard Invoice must be equal the amount unpaid if GL Date of Prepayment is less than Standard Invoice
1376                     + Similar logic applies to Prepayment too*\
1377                     FOR c_update_amount IN (SELECT jaet.rowid row_id, jaet.*
1378                                             FROM JAI_AP_ETDS_T jaet
1379                                             WHERE tds_invoice_id = -9998
1380                                             AND batch_id = p_batch_id)
1381                     LOOP
1382                         ln_calculated_inv_amt := 0;
1383                         ln_pp_apply_amt := 0;
1384                         ln_remain_amt := 0;
1385                         SELECT invoice_amount - NVL(amount_paid, 0) INTO ln_calculated_inv_amt
1386                         FROM ap_invoices_all
1387                         WHERE invoice_id = c_update_amount.base_invoice_id;
1388                         fnd_file.put_line(FND_FILE.LOG, 'c_update_amount.base_invoice_id: ' || c_update_amount.base_invoice_id);
1389                         fnd_file.put_line(FND_FILE.LOG, 'ln_calculated_inv_amt: ' || ln_calculated_inv_amt);
1390                         IF c_update_amount.base_invoice_type_lookup_code = 'STANDARD' THEN
1391                             OPEN c_get_pp_apply_amt(c_update_amount.base_invoice_id);
1395                             ln_calculated_inv_amt := ln_calculated_inv_amt + nvl(ln_pp_apply_amt, 0);
1392                             FETCH c_get_pp_apply_amt INTO ln_pp_apply_amt;
1393                             CLOSE c_get_pp_apply_amt;
1394                             fnd_file.put_line(FND_FILE.LOG, 'STD ln_pp_apply_amt: ' || ln_pp_apply_amt);
1396                         ELSIF c_update_amount.base_invoice_type_lookup_code = 'PREPAYMENT' THEN
1397                             OPEN c_get_applied_amt(c_update_amount.base_invoice_id);
1398                             FETCH c_get_applied_amt INTO ln_pp_apply_amt;
1399                             CLOSE c_get_applied_amt;
1400                             fnd_file.put_line(FND_FILE.LOG, 'PP ln_pp_apply_amt: ' || ln_pp_apply_amt);
1401                             ln_calculated_inv_amt := ln_calculated_inv_amt + nvl(ln_pp_apply_amt, 0);
1402                             OPEN c_get_remaining_amt(c_update_amount.base_invoice_id);
1403                             FETCH c_get_remaining_amt INTO ln_remain_amt;
1404                             CLOSE c_get_remaining_amt;
1405                             fnd_file.put_line(FND_FILE.LOG, 'PP ln_remain_amt: ' || ln_remain_amt);
1406                             ln_calculated_inv_amt := ln_calculated_inv_amt + nvl(ln_remain_amt, 0);
1407                         END IF; \*IF c_update_amount.base_invoice_type_lookup_code = 'STANDARD' THEN*\
1408                         fnd_file.put_line(FND_FILE.LOG, 'ln_calculated_inv_amt: ' || ln_calculated_inv_amt);
1409                         UPDATE JAI_AP_ETDS_T
1410                         SET base_taxabale_amount = ln_calculated_inv_amt,
1411                         tds_invoice_id = -9999,
1412                         amt_of_tds = ((amt_of_tds*ln_calculated_inv_amt)/base_taxabale_amount),
1413                         amt_of_surcharge = ((amt_of_surcharge*ln_calculated_inv_amt)/base_taxabale_amount),
1414                         amt_of_cess = ((amt_of_cess*ln_calculated_inv_amt)/base_taxabale_amount)
1415                         WHERE base_invoice_id = c_update_amount.base_invoice_id
1416                         AND rowid = c_update_amount.row_id;
1417                     END LOOP; \*FOR c_update_amount*\
1418                     \*11896260 - Changes for FVU 3.1 - End*\
1419 
1420     FOR dtl IN (select a.rowid row_id, a.*,
1421             b.vendor_id vendor_id, b.vendor_site_id vendor_site_id, b.invoice_type_lookup_code inv_type
1422           from JAI_AP_ETDS_T a, ap_invoices_all b
1423           where a.batch_id = p_batch_id and a.base_invoice_id = b.invoice_id
1424       and a.tds_invoice_id not in ( -9999, -9997) ) \* Added Condition for Bug#10315928 *\ \* ER: 13514846 *\
1425     LOOP
1426 
1427       --added by csahoo for bug#5975168, start
1428     ln_con_for_challan  := 1;
1429     ln_con_for_deductee := 1;
1430     --bug#5975168, end
1431 
1432       ln_tax_rate       :=  NULL;
1433       ln_tds_rate       :=  NULL;
1434       ln_surcharge_rate :=  NULL;
1435       ln_cess_rate      :=  NULL;
1436       ln_tds_amt        := 0 ;
1437       ln_surcharge_amt  := 0 ;
1438       ln_cess_amt       := 0 ;
1439 
1440     \*START, Bgowrava for Bug#6195027*\
1441     ln_sh_cess_rate := NULL;
1442     ln_sh_cess_amt := 0;
1443     \*END, Bgowrava for Bug#6195027*\
1444 
1445       OPEN c_cert_issue_date(dtl.tds_invoice_id);
1446       FETCH c_cert_issue_date INTO lv_cert_issue_date;
1447       CLOSE c_cert_issue_date;
1448 
1449       OPEN c_check_date(dtl.tds_check_id);
1450       FETCH c_check_date INTO lv_tds_check_date;
1451       CLOSE c_check_date;
1452 
1453       OPEN c_tax_rates(dtl.tds_tax_id) ;
1454       FETCH c_tax_rates INTO ln_tax_rate, ln_tds_rate, ln_surcharge_rate, ln_cess_rate, ln_sh_cess_rate ;  --Added ln_sh_cess_rate by Bgowrava for bug#6195027
1455       CLOSE c_tax_rates ;
1456 
1457 
1458       v_challan_err := null;
1459       v_deductee_err := null;
1460       v_tds_check_id := null;
1461       v_base_invoice_check_id := null;
1462       v_challan_num := null;
1463       v_challan_date := null;
1464       v_bank_account_id := null;
1465       v_bank_account_name  := null;  --added by csahoo for BUG#6158875
1466       v_bank_branch_code := null;
1467       v_prepay_inv_id_of_base := null;
1468       v_prepay_inv_id_of_tds := null;
1469       v_prepayment_amount_applied := null;
1470       v_tds_check_date := null;
1471       v_base_check_date := null;
1472 
1473       v_temp_bank := null;
1474       v_temp_bank_acc_name := null; --added by csahoo for BUG#6158875
1475       v_temp_challan_num := null;
1476       v_temp_challan_date := null;
1477 
1478       v_debug_tds_invid := dtl.tds_invoice_id;
1479       v_debug_base_invid := dtl.base_invoice_id;
1480 
1481       ln_check_number := null;
1482 
1483       v_statement_id := '3a';
1484      \* Modified by JMEENA for bug# 4600778 to fetch the bsr_code in v_bank_branch_code *\
1485      \*Bug 12415388 - Commented c_tds_payment_check_id and added c_tds_payment_details as Check Details must be fetched based on CHECK_ID*\
1486       --OPEN c_tds_payment_check_id(dtl.tds_invoice_id);
1487       --FETCH c_tds_payment_check_id INTO v_tds_check_id, v_bank_account_name, v_challan_num, v_challan_date, v_bank_branch_code, ln_check_number;
1488       \*Bug 7688789 - Fetched Check Number also*\
1489       --CLOSE c_tds_payment_check_id;
1490 
1491       \*Bug 12415388 - TDS Invoice may be paid with multiple checks. Hence fetch details based on CHECK_ID instead of TDS Invoice ID*\
1492       OPEN c_tds_payment_details(dtl.tds_check_id);
1493       FETCH c_tds_payment_details INTO v_tds_check_id, v_bank_account_name, v_challan_num, v_challan_date, v_bank_branch_code, ln_check_number;
1494       CLOSE c_tds_payment_details;
1495 
1496    \*Bug 7688789 - Removed the else clause. The details fetched by c_check_dtls is already fetched by c_tds_payment_check_id*\
1497      IF v_tds_check_id IS NULL THEN
1498        v_statement_id := '3b';
1499        OPEN c_prepay_invoice_id(dtl.tds_invoice_id);
1500        FETCH c_prepay_invoice_id INTO v_prepay_inv_id_of_tds;
1504        \* Modified by JMEENA for bug# 4600778 to fetch the bsr_code in v_bank_branch_code *\
1501        CLOSE c_prepay_invoice_id;
1502 
1503        v_statement_id := '3b';
1505        OPEN c_tds_payment_check_id(v_prepay_inv_id_of_tds);
1506        FETCH c_tds_payment_check_id INTO v_tds_check_id, v_bank_account_name, v_challan_num, v_challan_date, v_bank_branch_code, ln_check_number;
1507        \*Bug 7688789 - Added check number to handle TDS Payment via Prepayment*\
1508        CLOSE c_tds_payment_check_id;
1509      END IF;
1510 
1511    IF ln_check_number IS NULL  THEN
1512       ln_con_for_challan := 0;
1513     fnd_file.put_line(FND_FILE.LOG, ' consider for challan '|| ln_con_for_challan);
1514     GOTO update_now;
1515    END IF ;
1516 
1517      IF v_tds_check_id IS NULL THEN
1518        v_challan_err := 'Payment Information not available for TDS Inv';
1519        GOTO update_now;
1520      END IF;
1521 
1522      IF v_bank_branch_code IS NULL THEN
1523        v_challan_err := 'Bank Branch Code is not found for TDS Inv';
1524      ELSIF v_challan_num IS NULL THEN
1525        v_challan_err := 'Challan Number is not found for TDS Inv';
1526      ELSIF v_challan_date IS NULL THEN
1527        v_challan_err := 'Challan Date is not found for TDS Inv';
1528      END IF;
1529 
1530      v_statement_id := '3d';
1531      OPEN c_base_payment_check_id(dtl.base_invoice_id);
1532      FETCH c_base_payment_check_id INTO v_base_invoice_check_id, v_temp_bank_acc_name, v_base_check_date;
1533      CLOSE c_base_payment_check_id;
1534 
1535      IF v_base_invoice_check_id IS NULL THEN
1536        v_statement_id := '3e';
1537        OPEN c_prepay_invoice_id(dtl.base_invoice_id);
1538        FETCH c_prepay_invoice_id INTO v_prepay_inv_id_of_base;
1539        CLOSE c_prepay_invoice_id;
1540 
1541        v_statement_id := '3f';
1542        OPEN c_base_payment_check_id(v_prepay_inv_id_of_base);
1543        FETCH c_base_payment_check_id INTO v_base_invoice_check_id, v_temp_bank_acc_name, v_base_check_date;
1544        CLOSE c_base_payment_check_id;
1545      END IF;
1546 
1547      IF v_base_invoice_check_id IS NULL THEN
1548        v_deductee_err := 'Payment Information not available for Base Invoice';
1549      END IF;
1550 
1551      <<update_now>>
1552 
1553      IF dtl.inv_type = 'PREPAYMENT' THEN
1554        v_statement_id := '3g';
1555        select sum(amount) - sum( nvl(prepay_amount_remaining, amount)) INTO v_prepayment_amount_applied
1556        from   ap_invoice_distributions_all
1557        where  invoice_id = dtl.base_invoice_id
1558        and    attribute1 = dtl.tds_tax_id;
1559      END IF;
1560 
1561      v_prepayment_amount_applied := nvl(v_prepayment_amount_applied,0);
1562 
1563      IF v_generate_headers THEN
1564        IF NVL(lv_action,'X') <> 'V' THEN
1565         FND_FILE.put_line(FND_FILE.log, 'lengths - inv_type:'||length(dtl.inv_type)
1566           ||', ch_num:'||length(v_challan_num) ||', bank_brCode:'||length(v_bank_branch_code) ||', ch_err:'
1567           ||', ded_err:'||length(v_deductee_err)
1568         );
1569        END IF ;
1570      END IF;
1571 
1572      v_challan_num := substr(v_challan_num, 1,25);
1573 
1574      v_statement_id := '3h';
1575      \* following lines of UPDATE commented by Vijay Shankar for Bug# 3567864 and modified as below UPDATE st
1576      UPDATE JAI_AP_ETDS_T
1577      SET tds_amount = round(tds_amount - v_prepayment_amount_applied*dtl.tds_tax_rate/100, 2),
1578      *\
1579   --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, begin
1580 
1581     OPEN c_get_tds_inv_det(dtl.tds_invoice_id);
1582     FETCH c_get_tds_inv_det INTO r_get_tds_inv;
1583     CLOSE c_get_tds_inv_det;
1584 
1585     IF r_get_tds_inv.threshold_trx_id IS NOT NULL
1586     THEN
1587         ln_surcharge_amt := r_get_tds_inv.tax_amount;
1588         ln_cess_amt := 0;
1589         ln_tds_amt := 0;
1590     ELSE
1591 
1592   --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, end
1593 
1594        -- added, Harshita for Bug 4525089
1595        ln_surcharge_amt   := round((dtl.tds_amount * ln_surcharge_rate /ln_tax_rate),2) ;
1596        ln_sh_cess_amt     := round((dtl.tds_amount * ln_sh_cess_rate/ln_tax_rate),2); --Added by Bgowrava for Bug#
1597        ln_cess_amt        := round((dtl.tds_amount * ln_cess_rate/ln_tax_rate),2) + ln_sh_cess_amt ; --Added ln_sh_cess_amt by bgowrava for bug#6195027
1598        ln_tds_amt         := dtl.tds_amount - NVL(ln_surcharge_amt,0) - NVL(ln_cess_amt,0) ;  -- added NVL, Harshita
1599        -- ended, Harshita for Bug 4525089
1600      END IF; --r_get_tds_inv.threshold_trx_id IS NOT NULL --add by Xiao Lv for bug#7662155
1601 
1602     UPDATE JAI_AP_ETDS_T
1603     SET tds_amount = round(tds_amount - v_prepayment_amount_applied*dtl.tds_tax_rate/100, 2),
1604       base_taxabale_amount = base_taxabale_amount - v_prepayment_amount_applied,
1605       base_vendor_id = dtl.vendor_id,
1606       base_vendor_site_id = dtl.vendor_site_id,
1607       base_invoice_type_lookup_code = dtl.inv_type,
1608       tds_check_id = v_tds_check_id,
1609       challan_num = v_challan_num,
1610       challan_date = v_challan_date,
1611       check_number = ln_check_number,
1612       bank_branch_code = v_bank_branch_code,
1613       base_invoice_check_id = v_base_invoice_check_id,
1614       prepayment_amount_applied = v_prepayment_amount_applied,
1615       challan_error =  v_challan_err,
1616       deductee_error =  v_deductee_err,
1617       amt_of_tds = ln_tds_amt,
1618       amt_of_surcharge = ln_surcharge_amt,
1619       amt_of_cess = ln_cess_amt,
1620       certificate_issue_date = lv_cert_issue_date,
1621       tds_check_date = lv_tds_check_date,
1622       -- Bug 5975168. Added by csahoo
1623       consider_for_challan = ln_con_for_challan,
1624       consider_for_deductee = decode(ln_con_for_challan,0,0,ln_con_for_deductee)
1625     WHERE rowid = dtl.row_id;
1626 
1627     END LOOP;
1628 
1629 --Modified by Xiao Lv for bug#7662155, begin
1633     update jai_ap_etds_t a
1630 \*
1631 --Date 11-05-2007 by Sacsethi for bug 5647248
1632 -- start 5647248
1634     set base_taxabale_amount =
1635        ( select nvl(taxable_amount,0)
1636          from JAI_AP_TDS_THHOLD_TRXS b
1637          where b.invoice_to_tds_authority_id = a.tds_invoice_id )
1638     where a.batch_id = p_batch_id
1639   and   a.tds_invoice_id <> -9999 --Bug 10315928
1640     and exists
1641          ( select 1
1642            from JAI_AP_TDS_THHOLD_TRXS c
1643            where c.invoice_to_tds_authority_id = a.tds_invoice_id
1644            and c.tds_event like '%THRESHOLD%'
1645          ) ;
1646  -- end 5647248
1647 *\
1648   \* Bug 5721614. Code migration by Xiao Lv from jai_ap_tds_etds_pkg.sql with version 115.26.6307.8
1649     * Commented the above and added the below.
1650    * Updates records which are available in
1651    * jai_ap_tds_thhold_trxs *\
1652 
1653     \*Bug 12415388 - Update Base Taxable amount to the portion of Check amount*\
1654     UPDATE jai_ap_etds_t a
1655        SET base_taxabale_amount =
1656             ( SELECT decode(b.tds_event,
1657                            'SURCHARGE_CALCULATE',
1658                            0,
1659                            \* nvl(taxable_amount,0) * sign(invoice_to_tds_authority_amt) * (tds_amount/abs(invoice_to_tds_authority_amt))) *\ --Added DECODE by Xiao Lv for Bug#7662155
1660                nvl(taxable_amount,0) * sign(invoice_to_tds_authority_amt)) \*commented above and added nvl(taxable_amount,0) * sign(invoice_to_tds_authority_amt) for bug 13070779*\
1661                 FROM jai_ap_tds_thhold_trxs b
1662                WHERE b.invoice_to_tds_authority_id = a.tds_invoice_id )
1663      WHERE a.batch_id = p_batch_id
1664      and   a.tds_invoice_id not in ( -9999, -9997 ); --Bug 10315928          \* ER: 13514846 *\
1665 
1666 
1667   \* This update is used to update invoices which
1668    * are not available in jai_ap_tds_thhold_trxs
1669    * but considered for calculating taxable_basis
1670    * for threshold transition or rollback.
1671    *\
1672 
1673   UPDATE jai_ap_etds_t a
1674   SET base_taxabale_amount = 0
1675   WHERE a.batch_id = p_batch_id
1676   AND base_taxabale_amount IS NULL;
1677 
1678 --Modified by Xiao Lv for bug#7662155, end
1679 
1680 
1681    EXCEPTION
1682      WHEN OTHERS THEN
1683        FND_FILE.put_line(FND_FILE.log, 'Err->'||SQLERRM);
1684        FND_FILE.put_line(FND_FILE.log, 'statement->'||v_statement_id
1685          ||', tds_invid->'||v_debug_tds_invid||', base_invid->'||v_debug_base_invid);
1686        RAISE;
1687    END populate_details;
1688 */ --Commented by Chong for eTDS ER bug#16414088 End
1689 --Added by Chong for eTDS ER bug#16414088 Start
1690   PROCEDURE populate_details(
1691     p_batch_id IN NUMBER,
1692     p_org_tan_num IN VARCHAR2,
1693     p_tds_vendor_id IN NUMBER,
1694     p_tds_vendor_site_id IN NUMBER,
1695     p_tds_inv_from_date IN DATE,
1696     p_tds_inv_to_date IN DATE,
1697     p_include_list  IN  VARCHAR2,
1698     p_exclude_list  IN  VARCHAR2,
1699     p_organization_id IN NUMBER
1700   )
1701   IS
1702     v_tds_check_id    NUMBER(15);
1703     v_prepay_inv_id_of_tds  NUMBER(15);
1704     v_bank_account_id NUMBER(15);
1705     v_bank_account_name VARCHAR2(80);/* Bug 16815165 -Modified size from 50 to 80 */
1706 
1707     v_temp_challan_num  VARCHAR2(50);
1708     v_temp_challan_date DATE;
1709     v_temp_bank     NUMBER(15);
1710     v_temp_bank_acc_name VARCHAR2(100);/* Bug 16815165 -Modified size from 50 to 80 */
1711 
1712     v_statement_id    VARCHAR2(3);
1713     v_debug_base_invid    NUMBER(15);
1714     v_debug_tds_invid   NUMBER(15);
1715 
1716     v_base_check_date DATE;
1717     v_tds_check_date  DATE;
1718     v_challan_num   VARCHAR2(50);
1719     v_challan_date    DATE;
1720     v_bank_branch_code  HZ_ORGANIZATION_PROFILES.BANK_OR_BRANCH_NUMBER%TYPE;
1721 
1722     v_challan_err   VARCHAR2(100);
1723     v_deductee_err    VARCHAR2(100);
1724 
1725     v_base_invoice_check_id NUMBER(15);
1726     v_prepay_inv_id_of_base NUMBER(15);
1727 
1728     v_payment_id NUMBER;
1729     v_prepay_invoice_id NUMBER;
1730     v_prepayment_amount_applied NUMBER;
1731 
1732     /* Bug 4353842. Added by Lakshmi Gopalsami */
1733     ln_check_number        ap_checks_all.check_number%TYPE;
1734     ln_tax_rate            JAI_CMN_TAXES_ALL.tax_rate%TYPE;
1735     ln_tds_rate            JAI_CMN_TAXES_ALL.tax_rate%TYPE;
1736     ln_surcharge_rate      JAI_CMN_TAXES_ALL.surcharge_rate%TYPE;
1737     ln_cess_rate           JAI_CMN_TAXES_ALL.cess_rate%TYPE;
1738     ln_inv_amt             ap_invoices_all.invoice_amount%TYPE;
1739 
1740     -- added, Harshita for Bug 4525089
1741 
1742     lv_cert_issue_date    DATE ;
1743     ln_tds_amt             JAI_AP_ETDS_T.amt_of_tds%TYPE;
1744     ln_surcharge_amt       JAI_AP_ETDS_T.amt_of_surcharge%TYPE;
1745     ln_cess_amt            JAI_AP_ETDS_T.amt_of_cess%TYPE;
1746                   -- ended, Harshita for Bug 4525089
1747 
1748 --Date 11-05-2007 by Sacsethi for bug 5647248
1749 -- start 5647248
1750     lv_include_flag VARCHAR2(1);
1751     lv_exclude_flag VARCHAR2(1);
1752     TYPE lv_list IS VARRAY(10) OF VARCHAR2(30);
1753     lv_include lv_list :=lv_list();
1754     lv_exclude lv_list :=lv_list();
1755 -- end 5647248
1756 /*Bug 11896260 - Start*/
1757                   CURSOR c_get_pp_apply_amt (p_invoice_id IN NUMBER)
1758                   IS
1759                   SELECT SUM(application_amount)
1760                   FROM jai_ap_tds_prepayments jatp
1761                   WHERE invoice_id = p_invoice_id
1762                   AND (SELECT accounting_date
1763                        FROM ap_invoice_distributions_all
1767                        FROM ap_invoice_distributions_all
1764                        WHERE invoice_distribution_id = jatp.invoice_distribution_id)
1765                        <=
1766                       (SELECT accounting_date
1768                        WHERE invoice_distribution_id IN (SELECT prepay_distribution_id
1769                                                          FROM ap_invoice_distributions_all
1770                                                          WHERE invoice_distribution_id = jatp.invoice_distribution_id_prepay
1771                                                         )
1772                        );
1773                   CURSOR c_get_applied_amt (p_invoice_id IN NUMBER)
1774                   IS
1775                   SELECT SUM(application_amount)
1776                   FROM jai_ap_tds_prepayments jatp
1777                   WHERE invoice_id IN (SELECT invoice_id
1778                                        FROM ap_invoice_distributions_all
1779                                        WHERE prepay_distribution_id IN (SELECT invoice_distribution_id
1780                                                                         FROM ap_invoice_distributions_all
1781                                                                         WHERE invoice_id = p_invoice_id
1782                                                                        )
1783                                       )
1784                   AND (SELECT accounting_date
1785                        FROM ap_invoice_distributions_all
1786                        WHERE invoice_distribution_id = jatp.invoice_distribution_id)
1787                        >
1788                       (SELECT accounting_date
1789                        FROM ap_invoice_distributions_all
1790                        WHERE invoice_distribution_id IN (SELECT prepay_distribution_id
1791                                                          FROM ap_invoice_distributions_all
1792                                                          WHERE invoice_distribution_id = jatp.invoice_distribution_id_prepay
1793                                                         )
1794                        );
1795                   CURSOR c_get_remaining_amt (p_invoice_id IN NUMBER)
1796                   IS
1797                   SELECT sum(prepay_amount_remaining)
1798                   FROM ap_invoice_distributions_all
1799                   WHERE invoice_id = p_invoice_id;
1800                   CURSOR c_threshold_tran_inv (p_threshold_grp_id IN NUMBER)
1801                   IS
1802                   SELECT tds_invoice_id, tds_check_id, tds_tax_id, tds_amount
1803                   FROM jai_ap_etds_t
1804                   WHERE tds_invoice_id = (SELECT MAX(invoice_to_tds_authority_id)
1805                                          FROM jai_ap_tds_thhold_trxs
1806                                          WHERE threshold_grp_id = p_threshold_grp_id
1807                                          AND tds_event LIKE 'THRESHOLD TRANSITION%'
1808                                         );
1809                   CURSOR c_gl_date(p_tds_invoice_id IN NUMBER)
1810                   IS
1811                   SELECT gl_date
1812                   FROM ap_invoices_all
1813                   WHERE invoice_id = p_tds_invoice_id;
1814                   CURSOR c_chk_threshold_rollback(p_threshold_grp_id IN NUMBER)
1815                   IS
1816                   SELECT invoice_to_tds_authority_id
1817                   FROM jai_ap_tds_thhold_trxs
1818                   WHERE tds_event LIKE 'THRESHOLD ROLLBACK%'
1819                   AND threshold_grp_id = p_threshold_grp_id
1820                   AND invoice_to_tds_authority_id > (SELECT MAX(invoice_to_tds_authority_id)
1821                                                      FROM jai_ap_tds_thhold_trxs
1822                                                      WHERE threshold_grp_id = p_threshold_grp_id
1823                                                      AND tds_event LIKE 'THRESHOLD TRANSITION%'
1824                                                     );
1825                   ln_calculated_inv_amt     NUMBER;
1826                   ln_pp_apply_amt           NUMBER;
1827                   ln_remain_amt             NUMBER;
1828                   r_threshold_tran_inv      c_threshold_tran_inv%ROWTYPE;
1829                   r_chk_threshold_rollback  c_chk_threshold_rollback%ROWTYPE;
1830                   lv_bank_branch_code       AP_BANK_BRANCHES.bank_num%TYPE;
1831                   ln_surcharge_amount       NUMBER;
1832                   ln_sh_cess_amount         NUMBER;
1833                   ln_cess_amount            NUMBER;
1834                   ln_tds_amount             NUMBER;
1835                   ld_gl_date                DATE;
1836                   /*Bug 11896260 - End*/
1837 
1838     v_legalEntityTan VARCHAR2(50);
1839     lv_voided        CONSTANT VARCHAR2(30) := 'VOIDED';          --rchandan for bug#4428980
1840     lv_stop_init      CONSTANT VARCHAR2(30) := 'STOP INITIATED';--rchandan for bug#4428980
1841     lv_india_tds_source CONSTANT VARCHAR2(30) := 'INDIA TDS';--rchandan for bug#4428980
1842 
1843 
1844     -- to get TAN of an organization
1845     CURSOR c_tan_number(p_organization_id IN NUMBER) IS
1846       SELECT attribute1
1847       FROM hr_all_organization_units
1848       WHERE organization_id = p_organization_id;
1849 
1850     /*added by csahoo for bug # 6158875, START*/
1851     /*Modified the cursor c_tds_payment_check_id by JMEENA for bug#4600778 to select the bsr_code from JAI_AP_TDS_PAYMENTS table */
1852     CURSOR c_tds_payment_check_id(p_invoice_id IN NUMBER) IS
1853     SELECT pay.check_id, apc.bank_account_name, JATP.Challan_no challan_num,
1854       JATP.check_deposit_date challan_date, JATP.bsr_code   branch_code, apc.check_number check_number /*Bug 7688789 - Added Check Number*/
1855     FROM ap_invoice_payments_all PAY, ap_checks_all APC /* renamed the table from ap_checks_v to ap_checks_All for bug 12691784*/, JAI_AP_TDS_PAYMENTS JATP
1859     AND APC.status_lookup_code NOT IN (lv_voided,lv_stop_init);
1856     WHERE PAY.invoice_id = p_invoice_id
1857     AND PAY.check_id = APC.check_id
1858     AND APC.check_id = JATP.check_id
1860 
1861     /*Bug 12415388 - Get Payment details based on CHECK_ID instead of TDS_INVOICE_ID as a single TDS Invoice may be paid with multiple checks*/
1862     CURSOR c_tds_payment_details(p_check_id IN NUMBER) IS
1863     SELECT pay.check_id, apc.bank_account_name, JATP.Challan_no challan_num,
1864       JATP.check_deposit_date challan_date, JATP.bsr_code   branch_code, apc.check_number check_number /*Bug 7688789 - Added Check Number*/
1865     FROM ap_invoice_payments_all PAY, ap_checks_all APC/*renamed the table from ap_checks_v to ap_checks_All for Bug 12691784*/, JAI_AP_TDS_PAYMENTS JATP
1866     WHERE PAY.check_id = p_check_id
1867     AND PAY.check_id = APC.check_id
1868     AND APC.check_id = JATP.check_id
1869     AND APC.status_lookup_code NOT IN (lv_voided,lv_stop_init);
1870 
1871     CURSOR c_base_payment_check_id(p_invoice_id IN NUMBER) IS
1872           SELECT pay.check_id, apc.current_bank_account_name, check_date
1873           FROM ap_invoice_payments_all PAY, ap_checks_v APC
1874           WHERE PAY.invoice_id = p_invoice_id
1875           AND PAY.check_id = APC.check_id
1876         AND APC.status_lookup_code NOT IN (lv_voided, lv_stop_init);
1877 
1878     /*added by csahoo for bug # 6158875, END*/
1879 
1880     CURSOR c_prepay_invoice_id(p_tds_invoice_id IN NUMBER) IS
1881       SELECT b.invoice_id prepay_invoice_id
1882       FROM ap_invoice_distributions_all a, ap_invoice_distributions_all b
1883       WHERE a.invoice_id = p_tds_invoice_id
1884       AND a.prepay_distribution_id IS NOT NULL
1885       AND (a.reversal_flag IS NULL OR a.reversal_flag = 'N')  --rchandan for bug#4428980
1886       AND b.invoice_distribution_id = a.prepay_distribution_id;
1887 
1888     CURSOR c_cert_issue_date(p_tds_invoice_id IN NUMBER) IS
1889       SELECT a.issue_date
1890       FROM JAI_AP_TDS_F16_HDRS_ALL a, JAI_AP_TDS_INV_PAYMENTS b -- Bug#4517720 ja_in_ap_form16_dtl b
1891       WHERE a.certificate_num = b.certificate_num
1892       AND a.org_tan_num = b.org_tan_num
1893       AND a.fin_yr = b.fin_year
1894       AND b.invoice_id = p_tds_invoice_id;
1895 
1896     CURSOR c_check_date(p_check_id IN NUMBER) IS
1897       SELECT nvl(jatp.check_date, jatp.check_date) check_date
1898       FROM JAI_AP_TDS_INV_PAYMENTS jatp
1899       WHERE
1900     check_id = p_check_id;
1901     lv_tds_check_date DATE ;
1902 
1903     --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, begin
1904     CURSOR c_get_tds_inv_det(cp_invoice_id NUMBER)
1905     IS
1906     SELECT threshold_trx_id,
1907            tax_amount,
1908            taxable_amount,
1909            tds_event
1910     FROM jai_ap_tds_thhold_trxs jatt
1911     WHERE jatt.invoice_to_tds_authority_id = cp_invoice_id
1912     AND tds_event like 'SURCHARGE_CALCULATE';
1913 
1914     --Get regime definition information
1915     CURSOR c_get_tds_regime_info IS
1916     SELECT jl.meaning     MEANING
1917           ,jl.lookup_code LOOKUP_CODE
1918           ,jrd.regime_id  REGIME_ID
1919       FROM ja_lookups          jl
1920           ,jai_rgm_definitions jrd
1921      WHERE jl.lookup_code = jrd.regime_code
1922        AND jl.lookup_type = G_JAI_INDIA_TAX_REGIMES
1923        AND jl.lookup_code = G_TDS
1924     ;
1925 
1926   r_get_tds_inv c_get_tds_inv_det%rowtype;
1927   r_get_tds_regime_info        c_get_tds_regime_info%rowtype;
1928 
1929     --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, end
1930 
1931     r_tds_payment_check_id    c_tds_payment_check_id%ROWTYPE;
1932     r_tds_payment_details     c_tds_payment_details%ROWTYPE; /*12415388*/
1933     /*Bug 11896260 - End*/
1934 
1935     -- Bug 5975168. Added by csahoo, start
1936     ln_con_for_challan  NUMBER ;
1937     ln_con_for_deductee NUMBER ;
1938     -- Bug 5975168. end
1939 
1940     /*START, Bgowrava for Bug#6195027*/
1941     ln_sh_cess_rate NUMBER ;
1942     ln_sh_cess_amt NUMBER ;
1943     /*END, Bgowrava for Bug#6195027*/
1944 
1945     l_api_name                     CONSTANT  VARCHAR2(50) := 'populate_details()';
1946 
1947     PROCEDURE populate_include_exclude_list(
1948           p_include_exclude_list IN VARCHAR2,
1949           p_include_exclude_arr OUT NOCOPY lv_list)
1950       IS
1951             ln_pos          NUMBER;
1952             ln_initial_pos  NUMBER;
1953             ln_length       NUMBER;
1954             lv_char         VARCHAR2(1);
1955           BEGIN
1956             p_include_exclude_arr:=lv_list();
1957             lv_char := ',';
1958             ln_initial_pos := 1;
1959             p_include_exclude_arr.extend(10);
1960             FOR lv_count in 1..10
1961               LOOP
1962                 p_include_exclude_arr(lv_count) := NULL;
1963               END LOOP;
1964             IF p_include_exclude_list IS NOT NULL THEN
1965               FOR lv_count in 1..10
1966               LOOP
1967                 ln_pos := instr (p_include_exclude_list, lv_char, 1, lv_count);
1968                 IF ln_pos <> 0 THEN
1969                   ln_length   := ln_pos - ln_initial_pos ;
1970                   p_include_exclude_arr(lv_count) := substr (p_include_exclude_list, ln_initial_pos , ln_length);
1971                   ln_initial_pos := ln_pos + 1 ;
1972                 ELSE
1973                   p_include_exclude_arr(lv_count) := substr (p_include_exclude_list, ln_initial_pos);
1974 
1975                   FOR i in lv_count+1..10
1976                   LOOP
1977                     p_include_exclude_arr(i) :=   p_include_exclude_arr(lv_count) ;
1978                   END LOOP ;
1979                   EXIT;
1980                 END IF;
1981               END LOOP;
1982             END IF;
1983     -- end 5647248
1987     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.BEGIN', G_PKG_NAME || ': '||l_api_name||'()+');
1984     END populate_include_exclude_list;
1985 
1986   BEGIN
1988     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_batch_id: '||p_batch_id);
1989     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_org_tan_num: '||p_org_tan_num);
1990     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_tds_vendor_id: '||p_tds_vendor_id);
1991     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_tds_vendor_site_id: '||p_tds_vendor_site_id);
1992     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_tds_inv_from_date: '||p_tds_inv_from_date);
1993     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_tds_inv_to_date: '||p_tds_inv_to_date);
1994     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_include_list: '||p_include_list);
1995     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_exclude_list: '||p_exclude_list);
1996     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.Parameters', 'p_organization_id: '|| p_organization_id);
1997 
1998     lv_include.extend(10);
1999     lv_exclude.extend(10);
2000     --Date 11-05-2007 by Sacsethi for bug 5647248
2001 
2002     IF p_include_list IS NOT NULL THEN
2003       lv_include_flag := 'Y';
2004       populate_include_exclude_list(p_include_list, lv_include);
2005     ElSE
2006       lv_include_flag := 'N';
2007     END IF;
2008 
2009     IF p_exclude_list IS NOT NULL THEN
2010       lv_exclude_flag := 'Y';
2011       populate_include_exclude_list(p_exclude_list, lv_exclude);
2012     ElSE
2013       lv_exclude_flag := 'N';
2014     END IF;
2015     -- end 5647248
2016 
2017     --Derive tds regime ID and code from regime setup
2018     OPEN c_get_tds_regime_info;
2019     FETCH c_get_tds_regime_info INTO r_get_tds_regime_info;
2020     CLOSE c_get_tds_regime_info;
2021 
2022     --1).Invoices attracting TDS and paid to Tax Authority
2023     INSERT INTO JAI_AP_ETDS_T (
2024       batch_id,
2025       base_invoice_id,
2026       tds_invoice_id,
2027       tds_invoice_num,
2028       tds_invoice_date,
2029       tds_section,
2030       tds_tax_id,
2031       tds_tax_rate,
2032       tds_amount,
2033       consider_for_challan,
2034       consider_for_deductee,
2035       tds_check_id,
2036       base_invoice_date ,
2037       -- Added for bug16889298 Start
2038       tds_vendor_classification,
2039       base_vendor_id,
2040       base_vendor_site_id,
2041       base_invoice_type_lookup_code,
2042       amt_of_tds,
2043       amt_of_cess,
2044       amt_of_surcharge,
2045       base_taxabale_amount,
2046       -- Added for bug16889298 End
2047       created_by,
2048       creation_date,
2049       last_updated_by,
2050       last_update_date
2051     )
2052     SELECT p_batch_id,
2053       base_invoices.invoice_id,  -- base_invoice_id
2054       NVL(a.invoice_id,-9999),    -- -9999 for prior threshold case           --tds_invoices.invoice_id,   -- tds_invoice_id
2055       tds_invoices.invoice_num,  -- tds_invoice_num
2056       NVL(tds_invoices.invoice_date, base_invoices.invoice_date), -- tds_invoice_date
2057       a.section_code,
2058       a.tax_category_id,         --for new TDS, populate tax_category_id instead of tax_id
2059       NVL(a.tax_rate,0),          --effective tds rate
2060       NVL(tds_invoices.invoice_amount,0),
2061       1,
2062       1,
2063       aipa.check_id,
2064       base_invoices.invoice_date,
2065       -- Added for bug16889298 Start
2066       jte.tds_vendor_classification,
2067       base_invoices.vendor_id,
2068       base_invoices.vendor_site_id,
2069       base_invoices.invoice_type_lookup_code,
2070       0,
2071       0,
2072       0,
2073       base_invoices.invoice_amount,
2074       -- Added for bug16889298 End
2075       fnd_global.user_id,
2076       sysdate,
2077       fnd_global.user_id,
2078       sysdate
2079       from  jai_ap_tds_repository     a
2080            ,ap_invoices_all           base_invoices
2081            ,ap_invoices_all           tds_invoices
2082            ,ap_invoice_payments_all   aipa
2083            ,JAI_AP_TDS_VENDOR_HDRS    jte  -- Added for bug16889298
2084       where a.source_invoice_id = base_invoices.invoice_id
2085       and   a.invoice_id = tds_invoices.invoice_id(+)  -- Added outer join for bug16889298
2086       and   a.invoice_id = aipa.invoice_id(+)  -- Added outer join for bug16889298
2087       --Added for bug16889298 start
2088       and   base_invoices.vendor_id = jte.vendor_id
2089       and   base_invoices.vendor_site_id = jte.vendor_site_id
2090       --Added for bug16889298 end
2091       /*Bug 10020606 - All TDS reports must be based on GL Date or date on which TCS Liability is booked*/
2092       and   base_invoices.gl_date between p_tds_inv_from_date and p_tds_inv_to_date
2093       and  ((a.tds_authority_id = p_tds_vendor_id
2094              and   (p_tds_vendor_site_id is null or a.tds_authority_site_id = p_tds_vendor_site_id)
2095              and   a.challan_number is not null
2096             ) or (
2097              a.invoice_id in(-9999, -9997) or a.invoice_id IS NULL
2098             )
2099             )
2100       and   NVL(a.Invoice_deleted,'N') = 'N'
2101       and   NVL(a.Source_invoice_deleted, 'N') = 'N'
2102    --   and   NVL(a.prior_threshold,'N') = 'N'     --removed for bug16889298
2103       and   NVL(a.required_for_etds,'N') = 'Y'
2104    -- and   a.challan_number is not null        --removed for bug16889298
2105       and   base_invoices.org_id = p_organization_id /* Added the condition for Bug 12691784 */
2109               and upper(a.section_code) in ( lv_include(1),lv_include(2),lv_include(3),lv_include(4),lv_include(5)
2106       and   a.org_tan_number = p_org_tan_num
2107       and   a.section_type = G_TDS_SECTION        --Only show TDS setcion in eTDS file
2108       and   ( lv_include_flag = 'N' or ( lv_include_flag = 'Y'
2110               ,lv_include(6),lv_include(7),lv_include(8),lv_include(9),lv_include(10) )))
2111       and   ( lv_exclude_flag = 'N' or ( lv_exclude_flag = 'Y'
2112               and upper(a.section_code) not in ( lv_exclude(1),lv_exclude(2),lv_exclude(3),lv_exclude(4),lv_exclude(5)
2113               ,lv_exclude(6),lv_exclude(7),lv_exclude(8),lv_exclude(9),lv_exclude(10))))
2114       ;
2115 
2116       jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME || l_api_name, 'After insert into JAI_AP_ETDS_T batch_id:' || p_batch_id);
2117     --2). Update payments infomation for paid TDS transactions (inserted from setp 1)
2118     --Update payment status and tds cess, sh tds cess, surcharge amount for paid transacations
2119     FOR dtl IN (select a.rowid row_id
2120                       ,a.*
2121                       ,b.vendor_id vendor_id
2122                       ,b.vendor_site_id vendor_site_id
2123                       ,b.invoice_type_lookup_code inv_type
2124                 from  JAI_AP_ETDS_T a
2125                      ,ap_invoices_all b
2126                 where a.batch_id = p_batch_id
2127                 and   a.base_invoice_id = b.invoice_id
2128                 and   a.tds_invoice_id not in ( -9999, -9997) )
2129     LOOP
2130 
2131       jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME || l_api_name, 'in Loop for TDS invoice: ' || dtl.tds_invoice_id);
2132       jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME || l_api_name, 'in Loop for TDS tds_check_id: ' || dtl.tds_check_id);
2133 
2134       --added by csahoo for bug#5975168, start
2135       ln_con_for_challan  := 1;
2136       ln_con_for_deductee := 1;
2137       --bug#5975168, end
2138 
2139       ln_tax_rate       :=  NULL;
2140       ln_tds_rate       :=  NULL;
2141       ln_surcharge_rate :=  NULL;
2142       ln_cess_rate      :=  NULL;
2143       ln_tds_amt        := 0 ;
2144       ln_surcharge_amt  := 0 ;
2145       ln_cess_amt       := 0 ;
2146 
2147       /*START, Bgowrava for Bug#6195027*/
2148       ln_sh_cess_rate := NULL;
2149       ln_sh_cess_amt := 0;
2150       /*END, Bgowrava for Bug#6195027*/
2151 
2152       OPEN c_cert_issue_date(dtl.tds_invoice_id);
2153       FETCH c_cert_issue_date INTO lv_cert_issue_date;
2154       CLOSE c_cert_issue_date;
2155 
2156       OPEN c_check_date(dtl.tds_check_id);
2157       FETCH c_check_date INTO lv_tds_check_date;
2158       CLOSE c_check_date;
2159 
2160       v_challan_err := null;
2161       v_deductee_err := null;
2162       v_tds_check_id := null;
2163       v_base_invoice_check_id := null;
2164       v_challan_num := null;
2165       v_challan_date := null;
2166       v_bank_account_id := null;
2167       v_bank_account_name  := null;  --added by csahoo for BUG#6158875
2168       v_bank_branch_code := null;
2169       v_prepay_inv_id_of_base := null;
2170       v_prepay_inv_id_of_tds := null;
2171       v_prepayment_amount_applied := null;
2172       v_tds_check_date := null;
2173       v_base_check_date := null;
2174 
2175       v_temp_bank := null;
2176       v_temp_bank_acc_name := null; --added by csahoo for BUG#6158875
2177       v_temp_challan_num := null;
2178       v_temp_challan_date := null;
2179 
2180       v_debug_tds_invid := dtl.tds_invoice_id;
2181       v_debug_base_invid := dtl.base_invoice_id;
2182 
2183       ln_check_number := null;
2184 
2185       v_statement_id := '3a';
2186      /* Modified by JMEENA for bug# 4600778 to fetch the bsr_code in v_bank_branch_code */
2187      /*Bug 12415388 - Commented c_tds_payment_check_id and added c_tds_payment_details as Check Details must be fetched based on CHECK_ID*/
2188       --OPEN c_tds_payment_check_id(dtl.tds_invoice_id);
2189       --FETCH c_tds_payment_check_id INTO v_tds_check_id, v_bank_account_name, v_challan_num, v_challan_date, v_bank_branch_code, ln_check_number;
2190       /*Bug 7688789 - Fetched Check Number also*/
2191       --CLOSE c_tds_payment_check_id;
2192 
2193       /*Bug 12415388 - TDS Invoice may be paid with multiple checks. Hence fetch details based on CHECK_ID instead of TDS Invoice ID*/
2194       OPEN c_tds_payment_details(dtl.tds_check_id);
2195       FETCH c_tds_payment_details INTO v_tds_check_id, v_bank_account_name, v_challan_num, v_challan_date, v_bank_branch_code, ln_check_number;
2196       CLOSE c_tds_payment_details;
2197 
2198       /*Bug 7688789 - Removed the else clause. The details fetched by c_check_dtls is already fetched by c_tds_payment_check_id*/
2199       IF v_tds_check_id IS NULL THEN
2200        v_statement_id := '3b';
2201        OPEN c_prepay_invoice_id(dtl.tds_invoice_id);
2202        FETCH c_prepay_invoice_id INTO v_prepay_inv_id_of_tds;
2203        CLOSE c_prepay_invoice_id;
2204 
2205        v_statement_id := '3b';
2206        /* Modified by JMEENA for bug# 4600778 to fetch the bsr_code in v_bank_branch_code */
2207        OPEN c_tds_payment_check_id(v_prepay_inv_id_of_tds);
2208        FETCH c_tds_payment_check_id INTO v_tds_check_id, v_bank_account_name, v_challan_num, v_challan_date, v_bank_branch_code, ln_check_number;
2209        /*Bug 7688789 - Added check number to handle TDS Payment via Prepayment*/
2210        CLOSE c_tds_payment_check_id;
2211       END IF;
2212 
2213       IF ln_check_number IS NULL  THEN
2214         ln_con_for_challan := 0;
2215         fnd_file.put_line(FND_FILE.LOG, ' consider for challan '|| ln_con_for_challan);
2216         jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME||l_api_name,' consider for challan '|| ln_con_for_challan);
2217         GOTO update_now;
2218       END IF ;
2219 
2223        GOTO update_now;
2220      IF v_tds_check_id IS NULL THEN
2221        v_challan_err := 'Payment Information not available for TDS Inv';
2222        jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME||l_api_name,v_challan_err);
2224      END IF;
2225 
2226      IF v_bank_branch_code IS NULL THEN
2227        v_challan_err := 'Bank Branch Code is not found for TDS Inv';
2228      ELSIF v_challan_num IS NULL THEN
2229        v_challan_err := 'Challan Number is not found for TDS Inv';
2230      ELSIF v_challan_date IS NULL THEN
2231        v_challan_err := 'Challan Date is not found for TDS Inv';
2232      END IF;
2233      jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME||l_api_name,'v_challan_err: ' || v_challan_err);
2234 
2235      v_statement_id := '3d';
2236      OPEN c_base_payment_check_id(dtl.base_invoice_id);
2237      FETCH c_base_payment_check_id INTO v_base_invoice_check_id, v_temp_bank_acc_name, v_base_check_date;
2238      CLOSE c_base_payment_check_id;
2239 
2240      IF v_base_invoice_check_id IS NULL THEN
2241        v_statement_id := '3e';
2242        OPEN c_prepay_invoice_id(dtl.base_invoice_id);
2243        FETCH c_prepay_invoice_id INTO v_prepay_inv_id_of_base;
2244        CLOSE c_prepay_invoice_id;
2245 
2246        v_statement_id := '3f';
2247        OPEN c_base_payment_check_id(v_prepay_inv_id_of_base);
2248        FETCH c_base_payment_check_id INTO v_base_invoice_check_id, v_temp_bank_acc_name, v_base_check_date;
2249        CLOSE c_base_payment_check_id;
2250      END IF;
2251 
2252      IF v_base_invoice_check_id IS NULL THEN
2253        v_deductee_err := 'Payment Information not available for Base Invoice';
2254      END IF;
2255 
2256      <<update_now>>
2257 
2258      IF dtl.inv_type = 'PREPAYMENT' THEN
2259        v_statement_id := '3g';
2260        select sum(amount) - sum( nvl(prepay_amount_remaining, amount)) INTO v_prepayment_amount_applied
2261        from   ap_invoice_distributions_all
2262        where  invoice_id = dtl.base_invoice_id
2263        and    attribute1 = dtl.tds_tax_id;
2264      END IF;
2265 
2266      v_prepayment_amount_applied := nvl(v_prepayment_amount_applied,0);
2267 
2268      IF v_generate_headers THEN
2269        IF NVL(lv_action,'X') <> 'V' THEN
2270          FND_FILE.put_line(FND_FILE.log, 'lengths - inv_type:'||length(dtl.inv_type)
2271           ||', ch_num:'||length(v_challan_num) ||', bank_brCode:'||length(v_bank_branch_code) ||', ch_err:'
2272           ||', ded_err:'||length(v_deductee_err)
2273          );
2274          jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_STATEMENT, G_MODULE_NAME||l_api_name, 'lengths - inv_type:' || length(dtl.inv_type)
2275           ||', ch_num:'||length(v_challan_num) ||', bank_brCode:'||length(v_bank_branch_code) ||', ch_err:'
2276           ||', ded_err:'||length(v_deductee_err));
2277        END IF ;
2278      END IF;
2279 
2280      v_challan_num := substr(v_challan_num, 1,25);
2281 
2282      v_statement_id := '3h';
2283      /* following lines of UPDATE commented by Vijay Shankar for Bug# 3567864 and modified as below UPDATE st
2284      UPDATE JAI_AP_ETDS_T
2285      SET tds_amount = round(tds_amount - v_prepayment_amount_applied*dtl.tds_tax_rate/100, 2),
2286      */
2287     --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, begin
2288     OPEN c_get_tds_inv_det(dtl.tds_invoice_id);
2289     FETCH c_get_tds_inv_det INTO r_get_tds_inv;
2290     CLOSE c_get_tds_inv_det;
2291 
2292     IF r_get_tds_inv.threshold_trx_id IS NOT NULL
2293     THEN
2294         ln_surcharge_amt := r_get_tds_inv.tax_amount;
2295         ln_cess_amt := 0;
2296         ln_tds_amt := 0;
2297     ELSE
2298     --Added by Xiao Lv for bug#7662155 on 06-Jan-2010, end
2299         /*Split the TDS Amount into appropriate components*/
2300         For rec_repository_lines in ( select jatrl.tax_id
2301                                             ,jatrl.tax_type
2302                                             ,jatrl.tax_amount
2303                                        From  jai_ap_tds_repo_lines jatrl
2304                                        Where jatrl.invoice_id = dtl.tds_invoice_id
2305                                        And    jatrl.surcharge_rollback is null
2306                                      )
2307         LOOP
2308             IF rec_repository_lines.tax_type = 'TDS' THEN
2309                 ln_tds_amt := rec_repository_lines.tax_amount;
2310             ELSIF rec_repository_lines.tax_type = 'TDS_EDUCATION_CESS' THEN
2311                 ln_cess_amt := rec_repository_lines.tax_amount;
2312             ELSIF rec_repository_lines.tax_type = 'TDS_SH_EDU_CESS' THEN
2313                 ln_sh_cess_amt := rec_repository_lines.tax_amount;
2314             ELSIF rec_repository_lines.tax_type = 'TDS_SURCHARGE' THEN
2315                 ln_surcharge_amt := rec_repository_lines.tax_amount;
2316             END IF;
2317         END LOOP;
2318     END IF; --r_get_tds_inv.threshold_trx_id IS NOT NULL --add by Xiao Lv for bug#7662155
2319 
2320     UPDATE JAI_AP_ETDS_T
2321     SET --tds_amount = round(tds_amount - v_prepayment_amount_applied*dtl.tds_tax_rate/100, 2),  --Updated for bug16898321, Sum surcharge amount into tds_amount 20130602
2322       tds_amount = round(ln_tds_amt + ln_cess_amt + ln_sh_cess_amt + ln_surcharge_amt - v_prepayment_amount_applied*dtl.tds_tax_rate/100, 2),
2323       base_taxabale_amount = base_taxabale_amount - v_prepayment_amount_applied,
2324       base_vendor_id = dtl.vendor_id,
2325       base_vendor_site_id = dtl.vendor_site_id,
2326       base_invoice_type_lookup_code = dtl.inv_type,
2327       tds_check_id = v_tds_check_id,
2328       challan_num = v_challan_num,
2329       challan_date = v_challan_date,
2330       check_number = ln_check_number,
2331       bank_branch_code = v_bank_branch_code,
2332       base_invoice_check_id = v_base_invoice_check_id,
2336       amt_of_tds = ln_tds_amt,
2333       prepayment_amount_applied = v_prepayment_amount_applied,
2334       challan_error =  v_challan_err,
2335       deductee_error =  v_deductee_err,
2337       amt_of_surcharge = ln_surcharge_amt,
2338       amt_of_cess = ln_cess_amt + ln_sh_cess_amt,  --Added sh_cess_amount by bug#16864998, sum cess and shcess together
2339       certificate_issue_date = lv_cert_issue_date,
2340       tds_check_date = lv_tds_check_date,
2341       -- Bug 5975168. Added by csahoo
2342       consider_for_challan = ln_con_for_challan,
2343       consider_for_deductee = decode(ln_con_for_challan,0,0,ln_con_for_deductee)
2344     WHERE rowid = dtl.row_id;
2345 
2346     END LOOP;
2347 
2348 --Modified by Xiao Lv for bug#7662155, begin
2349 /*
2350 --Date 11-05-2007 by Sacsethi for bug 5647248
2351 -- start 5647248
2352     update jai_ap_etds_t a
2353     set base_taxabale_amount =
2354        ( select nvl(taxable_amount,0)
2355          from JAI_AP_TDS_THHOLD_TRXS b
2356          where b.invoice_to_tds_authority_id = a.tds_invoice_id )
2357     where a.batch_id = p_batch_id
2358   and   a.tds_invoice_id <> -9999 --Bug 10315928
2359     and exists
2360          ( select 1
2361            from JAI_AP_TDS_THHOLD_TRXS c
2362            where c.invoice_to_tds_authority_id = a.tds_invoice_id
2363            and c.tds_event like '%THRESHOLD%'
2364          ) ;
2365  -- end 5647248
2366 */
2367   /* Bug 5721614. Code migration by Xiao Lv from jai_ap_tds_etds_pkg.sql with version 115.26.6307.8
2368     * Commented the above and added the below.
2369    * Updates records which are available in
2370    * jai_ap_tds_thhold_trxs */
2371 
2372     /*Bug 12415388 - Update Base Taxable amount to the portion of Check amount*/
2373     UPDATE jai_ap_etds_t a
2374        SET base_taxabale_amount =
2375             ( SELECT decode(b.tds_event,
2376                            'SURCHARGE_CALCULATE',
2377                            0,
2378                            /* nvl(taxable_amount,0) * sign(invoice_to_tds_authority_amt) * (tds_amount/abs(invoice_to_tds_authority_amt))) */ --Added DECODE by Xiao Lv for Bug#7662155
2379                nvl(taxable_amount,0) * sign(invoice_to_tds_authority_amt)) /*commented above and added nvl(taxable_amount,0) * sign(invoice_to_tds_authority_amt) for bug 13070779*/
2380                 FROM jai_ap_tds_thhold_trxs b
2381                WHERE b.invoice_to_tds_authority_id = a.tds_invoice_id )
2382      WHERE a.batch_id = p_batch_id
2383      and   a.tds_invoice_id not in ( -9999, -9997 ); --Bug 10315928          /* ER: 13514846 */
2384 
2385 
2386     /* This update is used to update invoices which
2387      * are not available in jai_ap_tds_thhold_trxs
2388      * but considered for calculating taxable_basis
2389      * for threshold transition or rollback.
2390      */
2391     UPDATE jai_ap_etds_t a
2392     SET base_taxabale_amount = 0
2393     WHERE a.batch_id = p_batch_id
2394     AND base_taxabale_amount IS NULL;
2395 
2396     --Modified by Xiao Lv for bug#7662155, end
2397 
2398     jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE, G_MODULE_NAME||l_api_name||'.END', G_PKG_NAME || ': '||l_api_name||'()-');
2399   EXCEPTION
2400     WHEN OTHERS THEN
2401       jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE
2402                                      ,G_MODULE_NAME||l_api_name||'. Other_Exception'
2403                                      ,SQLCODE || ':' || SQLERRM);
2404       jai_cmn_utils_pkg.WRITE_FND_LOG(G_LEVEL_PROCEDURE
2405                                      ,G_MODULE_NAME||l_api_name||'. Other_Exception'
2406                                      ,'statement->'||v_statement_id
2407                                       ||', tds_invid->'||v_debug_tds_invid||', base_invid->'||v_debug_base_invid);
2408        FND_FILE.put_line(FND_FILE.log, 'Err->'||SQLERRM);
2409        FND_FILE.put_line(FND_FILE.log, 'statement->'||v_statement_id
2410          ||', tds_invid->'||v_debug_tds_invid||', base_invid->'||v_debug_base_invid);
2411        RAISE;
2412    END populate_details;
2413 --Added by Chong for eTDS ER bug#16414088 End
2414 
2415   PROCEDURE create_file_header(
2416     p_line_number IN NUMBER,
2417     p_record_type IN VARCHAR2,
2418     p_file_type IN VARCHAR2,
2419     p_upload_type IN VARCHAR2,
2420     p_file_creation_date IN DATE,
2421     p_file_sequence_number IN NUMBER,
2422     p_deductor_tan IN VARCHAR2,
2423     p_number_of_batches IN NUMBER
2424   ) IS
2425 
2426   BEGIN
2427 
2428     UTL_FILE.PUT_LINE(v_filehandle,
2429         LPAD(p_line_number, s_line_number, v_pad_number)
2430      ||v_debug_pad_char||RPAD(p_record_type, s_record_type, v_pad_char)
2431      ||v_debug_pad_char||RPAD(p_file_type, s_file_type, v_pad_char)
2432      ||v_debug_pad_char||RPAD(p_upload_type, s_upload_type, v_pad_char)
2433      ||v_debug_pad_char||LPAD(to_char(p_file_creation_date, 'ddmmyyyy'), s_date, v_pad_date)
2434      ||v_debug_pad_char||LPAD(p_file_sequence_number, s_file_sequence_number, v_pad_number)
2435      ||v_debug_pad_char||RPAD(nvl(p_deductor_tan,' '), s_deductor_tan, v_pad_char)
2436      ||v_debug_pad_char||LPAD(nvl(p_number_of_batches,0), s_number_of_batches, v_pad_number)
2437     );
2438 
2439   END create_file_header;
2440 
2441   PROCEDURE create_batch_header(
2442     p_line_number IN NUMBER,  -- 6
2443     p_record_type IN VARCHAR2,  -- 2
2444     p_batch_number IN NUMBER, -- 4
2445     p_challan_count IN NUMBER,  -- 5
2446     p_deductee_count IN NUMBER, -- 5
2447     p_form_number IN CHAR,    -- 4
2448     p_rrr_number IN NUMBER,   -- 10
2449     p_rrr_date IN DATE,     -- 8
2450     p_deductor_tan IN VARCHAR2, -- 10
2451     p_pan_of_tan IN VARCHAR2, -- 10
2452     p_assessment_year IN NUMBER,-- 6
2453     p_financial_year IN NUMBER, -- 6
2454     p_deductor_name IN VARCHAR2,-- 75
2455     p_tan_address1 IN VARCHAR2, -- 25
2459     p_tan_address5 IN VARCHAR2, -- 25
2456     p_tan_address2 IN VARCHAR2, -- 25
2457     p_tan_address3 IN VARCHAR2, -- 25
2458     p_tan_address4 IN VARCHAR2, -- 25
2460     p_tan_state IN NUMBER,    -- 2
2461     p_tan_pin IN NUMBER,    -- 6
2462     p_chng_addr_since_last_return IN VARCHAR2,  -- 1    tells you whether address of deductor is changed since last return
2463     p_type_of_deductor IN VARCHAR2, -- 1        'C' for Central Govt/ 'O' for others /*Bug 8880543 - Modified Dedutory Status to Deductor Type*/
2464     p_quart_year_return IN VARCHAR, -- 2
2465     p_pers_resp_for_deduction IN VARCHAR2,  -- 75
2466     p_pers_designation IN VARCHAR2, -- 20
2467     p_tot_tax_dedected_challan IN NUMBER, -- 14, DECIMAL
2468     p_tot_tax_dedected_deductee IN NUMBER, -- 14, DECIMAL
2469     -- added. Harshita for Bug 5096787
2470     p_filler1    IN DATE DEFAULT NULL,
2471     p_filler2  IN NUMBER DEFAULT NULL,
2472     p_filler3  IN VARCHAR2 DEFAULT NULL,
2473     p_ack_num_tan_app IN NUMBER DEFAULT NULL,
2474     p_pro_rcpt_num_org_ret IN NUMBER  DEFAULT NULL
2475     -- ended. Harshita for Bug 5096787
2476   ) IS
2477 
2478   BEGIN
2479 
2480     UTL_FILE.PUT_LINE(v_filehandle,
2481        LPAD(p_line_number, s_line_number, v_pad_number)
2482      ||v_debug_pad_char||RPAD(p_record_type, s_record_type, v_pad_char)
2483      ||v_debug_pad_char||LPAD(p_batch_number, s_batch_number, v_pad_number)
2484      ||v_debug_pad_char||LPAD(p_challan_count, s_challan_count, v_pad_number)
2485      ||v_debug_pad_char||LPAD(p_deductee_count, s_deductee_count, v_pad_number)
2486      ||v_debug_pad_char||RPAD(p_form_number, s_form_number, v_pad_char)
2487      ||v_debug_pad_char||LPAD(nvl(p_rrr_number,0), s_rrr_number, v_pad_number)
2488      ||v_debug_pad_char||LPAD(nvl(to_char(p_rrr_date, 'ddmmyyyy'),' '), s_date, v_pad_date)
2489      ||v_debug_pad_char||RPAD(nvl(p_deductor_tan,' '), s_deductor_tan, v_pad_char)
2490      ||v_debug_pad_char||RPAD(nvl(p_pan_of_tan,' '), s_pan_of_tan, v_pad_char)
2491      ||v_debug_pad_char||LPAD(nvl(p_assessment_year,0), s_assessment_year, v_pad_number)
2492      ||v_debug_pad_char||LPAD(nvl(p_financial_year,0), s_financial_year, v_pad_number)
2493      ||v_debug_pad_char||RPAD(nvl(p_deductor_name,' '), s_deductor_name, v_pad_char)
2494      ||v_debug_pad_char||RPAD(nvl(p_tan_address1,' '), s_tan_address1, v_pad_char)
2495      ||v_debug_pad_char||RPAD(nvl(p_tan_address2,' '), s_tan_address2, v_pad_char)
2496      ||v_debug_pad_char||RPAD(nvl(p_tan_address3,' '), s_tan_address3, v_pad_char)
2497      ||v_debug_pad_char||RPAD(nvl(p_tan_address4,' '), s_tan_address4, v_pad_char)
2498      ||v_debug_pad_char||RPAD(nvl(p_tan_address5,' '), s_tan_address5, v_pad_char)
2499      ||v_debug_pad_char||LPAD(nvl(p_tan_state,0), s_tan_state, v_pad_number)
2500      ||v_debug_pad_char||LPAD(nvl(p_tan_pin,0), s_tan_pin, v_pad_number)
2501      ||v_debug_pad_char||RPAD(nvl(p_chng_addr_since_last_return,' '), s_chng_addr_since_last_return, v_pad_char)
2502      ||v_debug_pad_char||RPAD(nvl(p_type_of_deductor,' '), s_status_of_deductor, v_pad_char) /*Bug 8880543 - Modified Deductory Status to Deductor Type*/
2503      ||v_debug_pad_char||RPAD(nvl(p_quart_year_return,' '), s_quart_year_return, v_pad_char)
2504      ||v_debug_pad_char||RPAD(nvl(p_pers_resp_for_deduction,' '), s_pers_resp_for_deduction, v_pad_char)
2505      ||v_debug_pad_char||RPAD(nvl(p_pers_designation,' '), s_pers_designation, v_pad_char)
2506      ||v_debug_pad_char||LPAD(formatAmount(p_tot_tax_dedected_challan), s_tot_tax_dedected_challan, v_pad_number)
2507      ||v_debug_pad_char||LPAD(formatAmount(p_tot_tax_dedected_deductee), s_tot_tax_dedected_deductee, v_pad_number)
2508     );
2509 
2510   END create_batch_header;
2511 
2512   PROCEDURE create_challan_detail(
2513     p_line_number IN NUMBER,  -- 6
2514     p_record_type IN VARCHAR2,  -- 2
2515     p_batch_number IN NUMBER, -- 4
2516     p_challan_slno IN NUMBER, -- 5
2517     p_challan_section IN VARCHAR2,    -- 5
2518     p_amount_deducted IN NUMBER,  -- 14, DECIMAL
2519     p_challan_num IN VARCHAR2,    -- 9
2520     p_challan_date IN DATE,     -- 8
2521     p_bank_branch_code IN VARCHAR2,  -- 7,
2522     -- added. Harshita for Bug 5096787
2523     p_amount_of_tds       IN NUMBER DEFAULT NULL,
2524     p_amount_of_surcharge IN NUMBER DEFAULT NULL,
2525     p_amount_of_cess      IN NUMBER DEFAULT NULL,
2526     p_amount_of_int       IN NUMBER DEFAULT NULL,
2527     p_amount_of_oth       IN NUMBER DEFAULT NULL,
2528     p_check_number        IN NUMBER DEFAULT NULL,
2529     p_tds_dep_by_book     IN VARCHAR2 DEFAULT NULL,
2530     p_filler4             IN VARCHAR2 DEFAULT NULL
2531     -- added. Harshita for Bug 5096787
2532   ) IS
2533 
2534   BEGIN
2535      -- Bug 6796765. Added by Lakshmi Gopalsami
2536      -- Added upper for both p_challan_section and Sec.()
2537     UTL_FILE.PUT_LINE(v_filehandle,
2538         LPAD(p_line_number, s_line_number, v_pad_number)
2539       ||v_debug_pad_char||RPAD(p_record_type, s_record_type, v_pad_char)
2540       ||v_debug_pad_char||LPAD(p_batch_number, s_batch_number, v_pad_number)
2541       ||v_debug_pad_char||LPAD(nvl(p_challan_slno,0), s_challan_slno, v_pad_number)
2542       ||v_debug_pad_char||RPAD(getSectionCode(upper(p_challan_section), upper('Sec.()')), s_challan_section, v_pad_char)
2543       ||v_debug_pad_char||LPAD(formatAmount(p_amount_deducted), s_amount_deducted, v_pad_number)
2544       ||v_debug_pad_char||RPAD(nvl(p_challan_num,' '), s_challan_num, v_pad_char)
2545       ||v_debug_pad_char||LPAD(nvl(to_char(p_challan_date, 'ddmmyyyy'),' '), s_date, v_pad_date)
2546       ||v_debug_pad_char||RPAD(nvl(p_bank_branch_code,' '), s_bank_branch_code, v_pad_char)
2547     );
2548 
2549   END create_challan_detail;
2550 
2551  PROCEDURE create_deductee_detail(
2552      p_line_number IN NUMBER,        -- 9
2553      p_record_type IN VARCHAR2,      -- 2
2554      p_batch_number IN NUMBER,       -- 9
2555      p_deductee_slno IN NUMBER,      -- 5
2559      p_deductee_name IN VARCHAR2,    -- 75
2556      p_deductee_section IN VARCHAR2, -- 5
2557      p_deductee_code IN VARCHAR2,    -- 2            01 for Companies and 02 for other than companies
2558      p_deductee_pan IN VARCHAR2,     -- 10
2560      p_deductee_address1 IN VARCHAR2,        -- 25
2561      p_deductee_address2 IN VARCHAR2,        -- 25
2562      p_deductee_address3 IN VARCHAR2,        -- 25
2563      p_deductee_address4 IN VARCHAR2,        -- 25
2564      p_deductee_address5 IN VARCHAR2,        -- 25
2565      p_deductee_state IN VARCHAR2,   -- 2
2566      p_deductee_pin IN VARCHAR2,       -- 6 /*Changed to VARCHAR2 - Bug 7494473*/
2567      p_filler5 IN NUMBER,            -- 14 Added for bug#4353842
2568      p_payment_amount IN NUMBER,     -- 14 (12+2), DECIMAL
2569      p_payment_date IN DATE,         -- 8
2570      p_book_ent_oth IN VARCHAR2,     -- 1  Added for bug#4353842
2571      p_tax_rate IN NUMBER,           -- 4(2+2), DECIMAL
2572      p_filler6  IN VARCHAR2,         -- 1 Added for bug#4353842
2573      --p_grossing_up_factor IN VARCHAR2,     -- 1  -- Obsoleted via bug # 4353842
2574      p_tax_deducted IN NUMBER,       -- 14(12+2), DECIMAL
2575      p_tax_deducted_date IN DATE, -- 8
2576      p_tax_payment_date IN DATE,     -- 8
2577      p_bank_branch_code IN VARCHAR2, -- 7
2578      p_challan_no IN VARCHAR2,               -- 9
2579      p_tds_certificate_date IN DATE, -- 8
2580      p_reason_for_nDeduction IN VARCHAR2,    -- 1
2581      p_filler7 IN NUMBER                             -- 14, DECIMAL
2582          ) IS
2583 
2584 
2585   BEGIN
2586 
2587     -- Bug 6796765. Added by Lakshmi Gopalsami
2588     -- Added upper for both p_deductee_section and Sec.()
2589 
2590     UTL_FILE.PUT_LINE(v_filehandle,
2591           LPAD(p_line_number, s_line_number, v_pad_number)
2592         ||v_debug_pad_char||RPAD(p_record_type, s_record_type, v_pad_char)
2593         ||v_debug_pad_char||LPAD(p_batch_number, s_batch_number, v_pad_number)
2594         ||v_debug_pad_char||LPAD(nvl(p_deductee_slno,0), s_deductee_slno, v_pad_number)
2595   ||v_debug_pad_char||RPAD(getSectionCode(upper(p_deductee_section),upper('Sec.()')), s_deductee_section, v_pad_char)-- bug#3708878
2596         ||v_debug_pad_char||RPAD(nvl(p_deductee_code,' '), s_deductee_code, v_pad_char)
2597         ||v_debug_pad_char||RPAD(nvl(p_deductee_pan,' '), s_deductee_pan, v_pad_char)
2598         ||v_debug_pad_char||RPAD(nvl(p_deductee_name,' '), s_deductee_name, v_pad_char)
2599         ||v_debug_pad_char||RPAD(nvl(p_deductee_address1,' '), s_deductee_address1, v_pad_char)
2600         ||v_debug_pad_char||RPAD(nvl(p_deductee_address2,' '), s_deductee_address2, v_pad_char)
2601         ||v_debug_pad_char||RPAD(nvl(p_deductee_address3,' '), s_deductee_address3, v_pad_char)
2602         ||v_debug_pad_char||RPAD(nvl(p_deductee_address4,' '), s_deductee_address4, v_pad_char)
2603         ||v_debug_pad_char||RPAD(nvl(p_deductee_address5,' '), s_deductee_address5, v_pad_char)
2604         ||v_debug_pad_char||LPAD(nvl(p_deductee_state,'0'), s_deductee_state, v_pad_number)
2605         ||v_debug_pad_char||LPAD(nvl(p_deductee_pin,0), s_deductee_pin, v_pad_number)
2606         ||v_debug_pad_char||LPAD(formatAmount(p_filler5), s_filler, v_pad_number)
2607         ||v_debug_pad_char||LPAD(formatAmount(p_payment_amount), s_payment_amount, v_pad_number)
2608         ||v_debug_pad_char||LPAD(nvl(to_char(p_payment_date, 'ddmmyyyy'),' '), s_date, v_pad_date)
2609         ||v_debug_pad_char||RPAD(p_book_ent_oth , s_book_ent_oth, v_pad_char)
2610         ||v_debug_pad_char||LPAD(formatAmount(p_tax_rate), s_tax_rate, v_pad_number)
2611         ||v_debug_pad_char||RPAD(nvl(p_filler6,' '), s_filler6, v_pad_char)
2612         ||v_debug_pad_char||LPAD(formatAmount(p_tax_deducted), s_tax_deducted, v_pad_number)
2613         ||v_debug_pad_char||LPAD(nvl(to_char(p_tax_deducted_date, 'ddmmyyyy'),' '), s_date, v_pad_date)
2614         ||v_debug_pad_char||RPAD(nvl(p_bank_branch_code,' '), s_bank_branch_code, v_pad_char)
2615         ||v_debug_pad_char||LPAD(nvl(to_char(p_tax_payment_date, 'ddmmyyyy'),' '), s_date, v_pad_date)
2616         ||v_debug_pad_char||RPAD(nvl(p_challan_no,' '), s_challan_no, v_pad_char)
2617         ||v_debug_pad_char||LPAD(nvl(to_char(p_tds_certificate_date, 'ddmmyyyy'),' '), s_date, v_pad_date)
2618         ||v_debug_pad_char||RPAD(nvl(p_reason_for_nDeduction,' '), s_reason_for_nDeduction, v_pad_char)
2619         ||v_debug_pad_char||LPAD(formatAmount(p_filler7), s_filler, v_pad_number) || v_chr13
2620       );
2621   END create_deductee_detail;
2622 
2623   PROCEDURE create_fh(p_batch_id IN NUMBER) IS
2624     v_req JAI_AP_ETDS_REQUESTS%rowtype;
2625   BEGIN
2626 
2627     -- File Header
2628     SELECT * INTO v_req FROM JAI_AP_ETDS_REQUESTS WHERE batch_id = p_batch_id;
2629 
2630     UTL_FILE.PUT_LINE(v_filehandle, 'Input Parameters to this Request:');
2631     UTL_FILE.PUT_LINE(v_filehandle, '-------------------------------------------------');
2632     UTL_FILE.PUT_LINE(v_filehandle,
2633         '  batch_id                   ->'||v_req.batch_id||fnd_global.local_chr(10)
2634       ||'  request_id                 ->'||v_req.request_id||fnd_global.local_chr(10)
2635       ||'  legal_entity_id            ->'||v_req.legal_entity_id||fnd_global.local_chr(10)
2636       ||'  operating_unit_id          ->'||v_req.operating_unit_id||fnd_global.local_chr(10)
2637       ||'  org_tan_number             ->'||v_req.org_tan_number||fnd_global.local_chr(10)
2638       ||'  financial_year             ->'||v_req.financial_year||fnd_global.local_chr(10)
2639       ||'  tax_authority_id           ->'||v_req.tax_authority_id||fnd_global.local_chr(10)
2640       ||'  tax_authority_site_id      ->'||v_req.tax_authority_site_id||fnd_global.local_chr(10)
2641       ||'  organization_id            ->'||v_req.organization_id||fnd_global.local_chr(10)
2642       ||'  deductor_name              ->'||v_req.deductor_name||fnd_global.local_chr(10)
2643       ||'  deductor_state             ->'||v_req.deductor_state||fnd_global.local_chr(10)
2644       ||'  addr_changed_since_last_ret->'||v_req.addr_changed_since_last_ret||fnd_global.local_chr(10)
2648       ||'  challan_start_date         ->'||v_req.challan_start_date||fnd_global.local_chr(10)
2645       ||'  deductor_status            ->'||v_req.deductor_status||fnd_global.local_chr(10)
2646       ||'  person_resp_for_deduction  ->'||v_req.person_resp_for_deduction||fnd_global.local_chr(10)
2647       ||'  designation_of_pers_resp   ->'||v_req.designation_of_pers_resp||fnd_global.local_chr(10)
2649       ||'  challan_end_date           ->'||v_req.challan_end_date||fnd_global.local_chr(10)
2650       ||'  file_path                  ->'||v_req.file_path||fnd_global.local_chr(10)
2651       ||'  filename                   ->'||v_req.filename||fnd_global.local_chr(10)
2652     );
2653 
2654 
2655     UTL_FILE.PUT_LINE(v_filehandle,
2656         LPAD('LineNo', s_line_number, v_pad_char)
2657       ||v_pad_char||RPAD('RT', s_record_type, v_pad_char)
2658       ||v_pad_char||RPAD('FT', s_file_type, v_pad_char)
2659       ||v_pad_char||RPAD('UT', s_upload_type, v_pad_char)
2660       ||v_pad_char||LPAD('FileDate', s_date, v_pad_char)
2661       ||v_pad_char||LPAD('FSeqNo', s_file_sequence_number, v_pad_char)
2662       ||v_pad_char||RPAD('Org Tan', s_deductor_tan, v_pad_char)
2663       ||v_pad_char||LPAD('NoOfBatches', s_number_of_batches, v_pad_char)
2664     );
2665     UTL_FILE.PUT_LINE(v_filehandle,
2666         LPAD(v_underline_char, s_line_number, v_underline_char)
2667       ||v_pad_char||RPAD(v_underline_char, s_record_type, v_underline_char)
2668       ||v_pad_char||RPAD(v_underline_char, s_file_type, v_underline_char)
2669       ||v_pad_char||RPAD(v_underline_char, s_upload_type, v_underline_char)
2670       ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
2671       ||v_pad_char||LPAD(v_underline_char, s_file_sequence_number, v_underline_char)
2672       ||v_pad_char||RPAD(v_underline_char, s_deductor_tan, v_underline_char)
2673       ||v_pad_char||LPAD(v_underline_char, s_number_of_batches, v_underline_char)
2674     );
2675   END create_fh;
2676 
2677   PROCEDURE create_quarterly_fh
2678             ( p_batch_id IN NUMBER,
2679               p_period   IN VARCHAR2,
2680               p_RespPers_flat_no IN VARCHAR2 , -- Bug 6030953
2681             p_RespPers_prem_bldg IN VARCHAR2 , -- Bug 6030953
2682             p_RespPers_rd_st_lane IN VARCHAR2 , -- Bug 6030953
2683             p_RespPers_area_loc IN VARCHAR2 , -- Bug 6030953
2684             p_RespPers_tn_cty_dt IN VARCHAR2 , -- Bug 6030953
2685               p_RespPersState IN VARCHAR2,
2686               p_RespPersPin IN NUMBER,
2687         p_RespPers_tel_no IN VARCHAR2 , -- Bug 6030953
2688             p_RespPers_email IN VARCHAR2 , -- Bug 6030953
2689               p_RespPersAddrChange IN VARCHAR2
2690             )
2691           IS
2692             v_req   JAI_AP_ETDS_REQUESTS%rowtype;
2693           BEGIN
2694              SELECT * INTO v_req FROM JAI_AP_ETDS_REQUESTS WHERE batch_id = p_batch_id;
2695 
2696              UTL_FILE.PUT_LINE(v_filehandle, 'Input Parameters to this Request:');
2697              UTL_FILE.PUT_LINE(v_filehandle, '-------------------------------------------------');
2698              UTL_FILE.PUT_LINE(v_filehandle,
2699                        '  batch_id                   ->'||v_req.batch_id||fnd_global.local_chr(10)
2700                      ||'  request_id                 ->'||v_req.request_id||fnd_global.local_chr(10)
2701                      ||'  legal_entity_id            ->'||v_req.legal_entity_id||fnd_global.local_chr(10)
2702                      ||'  operating_unit_id          ->'||v_req.operating_unit_id||fnd_global.local_chr(10)
2703                      ||'  org_tan_number             ->'||v_req.org_tan_number||fnd_global.local_chr(10)
2704                      ||'  financial_year             ->'||v_req.financial_year||fnd_global.local_chr(10)
2705                      ||'  tax_authority_id           ->'||v_req.tax_authority_id||fnd_global.local_chr(10)
2706                      ||'  tax_authority_site_id      ->'||v_req.tax_authority_site_id||fnd_global.local_chr(10)
2707                      ||'  organization_id            ->'||v_req.organization_id||fnd_global.local_chr(10)
2708                      ||'  deductor_name              ->'||v_req.deductor_name||fnd_global.local_chr(10)
2709                      ||'  deductor_state             ->'||v_req.deductor_state||fnd_global.local_chr(10)
2710                      ||'  addr_changed_since_last_ret->'||v_req.addr_changed_since_last_ret||fnd_global.local_chr(10)
2711                      ||'  deductor_status            ->'||v_req.deductor_status||fnd_global.local_chr(10)
2712                      ||'  person_resp_for_deduction  ->'||v_req.person_resp_for_deduction||fnd_global.local_chr(10)
2713                      ||'  designation_of_pers_resp   ->'||v_req.designation_of_pers_resp||fnd_global.local_chr(10)
2714                      ||'  challan_start_date         ->'||v_req.challan_start_date||fnd_global.local_chr(10)
2715                      ||'  challan_end_date           ->'||v_req.challan_end_date||fnd_global.local_chr(10)
2716                      ||'  file_path                  ->'||v_req.file_path||fnd_global.local_chr(10)
2717                      ||'  filename                   ->'||v_req.filename||fnd_global.local_chr(10)
2718                      ||'  Period                     ->'||p_period||fnd_global.local_chr(10)
2719                      ||'  RespPerson''s Flat No      ->'||p_RespPers_Flat_no||fnd_global.local_chr(10)
2720                      ||'  RespPerson''s Premises/Bldg  ->'||p_RespPers_prem_bldg||fnd_global.local_chr(10)
2721                      ||'  RespPerson''s Rd/St/Lane   ->'||p_RespPers_rd_st_lane||fnd_global.local_chr(10)
2722                      ||'  RespPerson''s Area/Loc     ->'||p_RespPers_area_loc||fnd_global.local_chr(10)
2723                      ||'  RespPerson''s Tn/Cty/Dt    ->'||p_RespPers_tn_cty_dt||fnd_global.local_chr(10)
2724                      ||'  RespPerson''s State        ->'||p_RespPersState||fnd_global.local_chr(10)
2725                      ||'  RespPerson''s Pin          ->'||p_RespPersPin||fnd_global.local_chr(10)
2726            ||'  RespPerson''s Telephone no ->'||p_RespPers_tel_no||fnd_global.local_chr(10)
2730 
2727                      ||'  RespPerson''s Email        ->'||p_RespPers_email||fnd_global.local_chr(10)
2728                      ||'  RespPerson''s Addr Changed ->'||p_RespPersAddrChange||fnd_global.local_chr(10)
2729              );
2731 
2732              UTL_FILE.PUT_LINE(v_filehandle,
2733                  LPAD('Line No', sq_len_9, v_quart_pad) || v_pad_char ||
2734                  LPAD('RT', sq_len_2, v_quart_pad) || v_pad_char ||
2735                  LPAD('FT', sq_len_4, v_quart_pad) || v_pad_char ||
2736                  LPAD('UT', sq_len_2, v_quart_pad) || v_pad_char ||
2737                  LPAD('FileDate', sq_len_8, v_quart_pad) || v_pad_char ||
2738                  LPAD('SeqNo', sq_len_5, v_quart_pad) || v_pad_char ||
2739                  LPAD('U', sq_len_1, v_quart_pad) || v_pad_char ||
2740                  LPAD('TAN', sq_len_10, v_quart_pad) || v_pad_char ||
2741                  LPAD('Batch Cnt', sq_len_9, v_quart_pad) || v_pad_char ||
2742                  LPAD('Ret Prep util', sq_len_75, v_quart_pad) || v_pad_char ||  /*Bug 8880543 - Added Return Preperation Utility*/
2743                  LPAD('RH', sq_len_2, v_quart_pad) || v_pad_char ||
2744                  LPAD('FV', sq_len_2, v_quart_pad) || v_pad_char ||
2745                  LPAD('FH', sq_len_2, v_quart_pad) || v_pad_char ||
2746                  LPAD('SV', sq_len_2, v_quart_pad) || v_pad_char ||
2747                  LPAD('SH', sq_len_2, v_quart_pad) || v_pad_char ||
2748                  LPAD('SV', sq_len_2, v_quart_pad) || v_pad_char ||
2749                  LPAD('SH', sq_len_2, v_quart_pad) );
2750 
2751                   UTL_FILE.PUT_LINE(v_filehandle,
2752                   LPAD(v_underline_char, sq_len_9, v_underline_char) || v_pad_char ||
2753                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2754                   LPAD(v_underline_char, sq_len_4, v_underline_char) || v_pad_char ||
2755                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2756                   LPAD(v_underline_char, sq_len_8, v_underline_char) || v_pad_char ||
2757                   LPAD(v_underline_char, sq_len_5, v_underline_char) || v_pad_char ||
2758                   LPAD(v_underline_char, sq_len_1, v_underline_char) || v_pad_char ||
2759                   LPAD(v_underline_char, sq_len_10,v_underline_char) || v_pad_char ||
2760                   LPAD(v_underline_char, sq_len_9, v_underline_char) || v_pad_char ||
2761                   LPAD(v_underline_char, sq_len_75,v_underline_char) || v_pad_char || /*Bug 8880543 - Added Return Preperation Utility*/
2762                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2763                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2764                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2765                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2766                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2767                   LPAD(v_underline_char, sq_len_2, v_underline_char) || v_pad_char ||
2768                   LPAD(v_underline_char, sq_len_2, v_underline_char) );
2769 
2770         END create_quarterly_fh;
2771 
2772   PROCEDURE create_bh IS
2773   BEGIN
2774 
2775     -- Batch Header
2776     UTL_FILE.PUT_LINE(v_filehandle, fnd_global.local_chr(10) );
2777     UTL_FILE.PUT_LINE(v_filehandle,
2778         LPAD('LineNo', s_line_number, v_pad_char)
2779       ||v_pad_char||RPAD('RT', s_record_type, v_pad_char)
2780       ||v_pad_char||LPAD('BNo', s_batch_number, v_pad_char)
2781       ||v_pad_char||LPAD('Ch.Cnt', s_challan_count, v_pad_char)
2782       ||v_pad_char||LPAD('Dd.Cnt', s_deductee_count, v_pad_char)
2783       ||v_pad_char||RPAD('FNo.', s_form_number, v_pad_char)
2784       ||v_pad_char||LPAD('RRR No', s_rrr_number, v_pad_char)
2785       ||v_pad_char||LPAD('RRR Date', s_date, v_pad_char)
2786       ||v_pad_char||RPAD('Org Tan', s_deductor_tan, v_pad_char)
2787       ||v_pad_char||RPAD('Org Pan', s_pan_of_tan, v_pad_char)
2788       ||v_pad_char||LPAD('Ass.Year', s_assessment_year, v_pad_char)
2789       ||v_pad_char||LPAD('FinYr.', s_financial_year, v_pad_char)
2790       ||v_pad_char||RPAD('Org Name', s_deductor_name, v_pad_char)
2791       ||v_pad_char||RPAD('Tan Addr1', s_tan_address1, v_pad_char)
2792       ||v_pad_char||RPAD('Tan Addr2', s_tan_address2, v_pad_char)
2793       ||v_pad_char||RPAD('Tan Addr3', s_tan_address3, v_pad_char)
2794       ||v_pad_char||RPAD('Tan Addr4', s_tan_address4, v_pad_char)
2795       ||v_pad_char||RPAD('Tan Addr5', s_tan_address5, v_pad_char)
2796       ||v_pad_char||LPAD('State', s_tan_state, v_pad_char)
2797       ||v_pad_char||LPAD('TanPin', s_tan_pin, v_pad_char)
2798       ||v_pad_char||RPAD('ChangeOfAddr', s_chng_addr_since_last_return, v_pad_char)
2799       ||v_pad_char||RPAD('DS', s_status_of_deductor, v_pad_char)
2800       ||v_pad_char||RPAD('QY', s_quart_year_return, v_pad_char)
2801       ||v_pad_char||RPAD('PersonResponsibleForDeduction', s_pers_resp_for_deduction, v_pad_char)
2802       ||v_pad_char||RPAD('PersonDesignation', s_pers_designation, v_pad_char)
2803       ||v_pad_char||LPAD('TotChallanTax', s_tot_tax_dedected_challan, v_pad_char)
2804       ||v_pad_char||LPAD('TotDeducteeTax', s_tot_tax_dedected_deductee, v_pad_char)
2805     );
2806     UTL_FILE.PUT_LINE(v_filehandle,
2807         LPAD(v_underline_char, s_line_number, v_underline_char)
2808       ||v_pad_char||RPAD(v_underline_char, s_record_type, v_underline_char)
2809       ||v_pad_char||LPAD(v_underline_char, s_batch_number, v_underline_char)
2810       ||v_pad_char||LPAD(v_underline_char, s_challan_count, v_underline_char)
2811       ||v_pad_char||LPAD(v_underline_char, s_deductee_count, v_underline_char)
2812       ||v_pad_char||RPAD(v_underline_char, s_form_number, v_underline_char)
2813       ||v_pad_char||LPAD(v_underline_char, s_rrr_number, v_underline_char)
2814       ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
2815       ||v_pad_char||RPAD(v_underline_char, s_deductor_tan, v_underline_char)
2819       ||v_pad_char||RPAD(v_underline_char, s_deductor_name, v_underline_char)
2816       ||v_pad_char||RPAD(v_underline_char, s_pan_of_tan, v_underline_char)
2817       ||v_pad_char||LPAD(v_underline_char, s_assessment_year, v_underline_char)
2818       ||v_pad_char||LPAD(v_underline_char, s_financial_year, v_underline_char)
2820       ||v_pad_char||RPAD(v_underline_char, s_tan_address1, v_underline_char)
2821       ||v_pad_char||RPAD(v_underline_char, s_tan_address2, v_underline_char)
2822       ||v_pad_char||RPAD(v_underline_char, s_tan_address3, v_underline_char)
2823       ||v_pad_char||RPAD(v_underline_char, s_tan_address4, v_underline_char)
2824       ||v_pad_char||RPAD(v_underline_char, s_tan_address5, v_underline_char)
2825       ||v_pad_char||LPAD(v_underline_char, s_tan_state, v_underline_char)
2826       ||v_pad_char||LPAD(v_underline_char, s_tan_pin, v_underline_char)
2827       ||v_pad_char||RPAD(v_underline_char, s_chng_addr_since_last_return, v_underline_char)
2828       ||v_pad_char||RPAD(v_underline_char, s_status_of_deductor, v_underline_char)
2829       ||v_pad_char||RPAD(v_underline_char, s_quart_year_return, v_underline_char)
2830       ||v_pad_char||RPAD(v_underline_char, s_pers_resp_for_deduction, v_underline_char)
2831       ||v_pad_char||RPAD(v_underline_char, s_pers_designation, v_underline_char)
2832       ||v_pad_char||LPAD(v_underline_char, s_tot_tax_dedected_challan, v_underline_char)
2833       ||v_pad_char||LPAD(v_underline_char, s_tot_tax_dedected_deductee, v_underline_char)
2834     );
2835   END create_bh;
2836 
2837   PROCEDURE create_quarterly_bh IS
2838           BEGIN
2839             UTL_FILE.PUT_LINE(v_filehandle, ' ' ) ;
2840 
2841             UTL_FILE.PUT_LINE(v_filehandle,
2842             LPAD('Line No', sq_len_9, v_quart_pad) || v_pad_char ||
2843             LPAD('RT', sq_len_2, v_quart_pad) || v_pad_char ||
2844             LPAD('Batch No', sq_len_9, v_quart_pad) || v_pad_char ||
2845             LPAD('ChallCnt', sq_len_9, v_quart_pad) || v_pad_char ||
2846             LPAD('FN', sq_len_4, v_quart_pad) || v_pad_char ||
2847             LPAD('TT', sq_len_2, v_quart_pad) || v_pad_char ||
2848             LPAD('BI', sq_len_2, v_quart_pad) || v_pad_char ||
2849             LPAD('OR', sq_len_2, v_quart_pad) || v_pad_char ||
2850             LPAD('PR', sq_len_2, v_quart_pad) || v_pad_char ||
2851             LPAD('RN', sq_len_2, v_quart_pad) || v_pad_char ||
2852             LPAD('RD', sq_len_2, v_quart_pad) || v_pad_char ||
2853             LPAD('LT', sq_len_2, v_quart_pad) || v_pad_char ||
2854             LPAD('Ded TAN', sq_len_10, v_quart_pad) || v_pad_char ||
2855             LPAD('F1', sq_len_2, v_quart_pad) || v_pad_char ||
2856             LPAD('Ded PAN', sq_len_10, v_quart_pad) || v_pad_char ||
2857             LPAD('Ass.Yr', sq_len_6, v_quart_pad) || v_pad_char ||
2858             LPAD('Fin.Yr', sq_len_6, v_quart_pad) || v_pad_char ||
2859             LPAD('PD', sq_len_2, v_quart_pad) || v_pad_char ||
2860             LPAD('Deductor Name', sq_len_75, v_quart_pad) || v_pad_char ||
2861             LPAD('Deductor Branch', sq_len_75, v_quart_pad) || v_pad_char ||
2862             LPAD('Deductor Addr1', sq_len_25, v_quart_pad) || v_pad_char ||
2863             LPAD('Deductor Addr2', sq_len_25, v_quart_pad) || v_pad_char ||
2864             LPAD('Deductor Addr3', sq_len_25, v_quart_pad) || v_pad_char ||
2865             LPAD('Deductor Addr4', sq_len_25, v_quart_pad) || v_pad_char ||
2866             LPAD('Deductor Addr5', sq_len_25, v_quart_pad) || v_pad_char ||
2867             LPAD('DS', sq_len_2, v_quart_pad) || v_pad_char ||
2868             LPAD('DedPIN', sq_len_6, v_quart_pad) || v_pad_char ||
2869             LPAD('Deductor Email', sq_len_75, v_quart_pad) || v_pad_char ||
2870             LPAD('DedSTD', sq_len_5, v_quart_pad) || v_pad_char ||
2871             LPAD('Ded Phone', sq_len_10, v_quart_pad) || v_pad_char ||
2872             LPAD('C', sq_len_1, v_quart_pad) || v_pad_char ||
2873             LPAD('T', sq_len_1, v_quart_pad) || v_pad_char ||
2874             LPAD('RespPerson Name', sq_len_75, v_quart_pad) || v_pad_char ||
2875             LPAD('RespPerson Desg', sq_len_20, v_quart_pad) || v_pad_char ||
2876             LPAD('RespPerson Addr1', sq_len_25, v_quart_pad) || v_pad_char ||
2877             LPAD('RespPerson Addr2', sq_len_25, v_quart_pad) || v_pad_char ||
2878             LPAD('RespPerson Addr3', sq_len_25, v_quart_pad) || v_pad_char ||
2879             LPAD('RespPerson Addr4', sq_len_25, v_quart_pad) || v_pad_char ||
2880             LPAD('RespPerson Addr5', sq_len_25, v_quart_pad) || v_pad_char ||
2881             LPAD('RS', sq_len_2, v_quart_pad) || v_pad_char ||
2882             LPAD('ResPIN', sq_len_6, v_quart_pad) || v_pad_char ||
2883             LPAD('RespPerson Email', sq_len_75, v_quart_pad) || v_pad_char ||
2884             LPAD('Mobile No', sq_len_75, v_quart_pad) || v_pad_char ||
2885             LPAD('ResSTD', sq_len_5, v_quart_pad) || v_pad_char ||
2886             LPAD('ResPhone', sq_len_10, v_quart_pad) || v_pad_char ||
2887             LPAD('C', sq_len_1, v_quart_pad) || v_pad_char ||
2888             LPAD('TotChallanTax', sq_len_15, v_quart_pad) || v_pad_char ||
2889             LPAD('TC', sq_len_2, v_quart_pad) || v_pad_char ||
2890             LPAD('SC', sq_len_2, v_quart_pad) || v_pad_char ||
2891             LPAD('GT', sq_len_2, v_quart_pad) || v_pad_char ||
2892             LPAD('A', sq_len_1, v_quart_pad) || v_pad_char ||
2893             LPAD('AO Approval No', sq_len_15, v_quart_pad) || v_pad_char ||
2894             /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
2895             LPAD('L', sq_len_1, v_quart_pad)  || v_pad_char ||
2896             LPAD('SN', sq_len_2, v_quart_pad)  || v_pad_char ||
2897             LPAD('PAO Code', sq_len_20, v_quart_pad)  || v_pad_char ||
2898             LPAD('DDO Code', sq_len_20, v_quart_pad)  || v_pad_char ||
2899             LPAD('MN', sq_len_3, v_quart_pad)  || v_pad_char ||
2900             LPAD('Ministry Name Other', sq_len_150, v_quart_pad)  || v_pad_char ||
2901             LPAD('F2', sq_len_12, v_quart_pad)  || v_pad_char ||
2905             LPAD('RH', sq_len_2, v_quart_pad)
2902             LPAD('PAORgNo', sq_len_7, v_quart_pad)  || v_pad_char ||
2903             LPAD('DDORgNo', sq_len_10, v_quart_pad)  || v_pad_char ||
2904             /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
2906             );
2907 
2908            UTL_FILE.PUT_LINE(v_filehandle,
2909            LPAD(v_underline_char, sq_len_9,   v_underline_char) || v_pad_char ||
2910            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2911            LPAD(v_underline_char, sq_len_9,   v_underline_char) || v_pad_char ||
2912            LPAD(v_underline_char, sq_len_9,   v_underline_char) || v_pad_char ||
2913            LPAD(v_underline_char, sq_len_4,   v_underline_char) || v_pad_char ||
2914            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2915            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2916            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2917            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2918            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2919            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2920            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2921            LPAD(v_underline_char, sq_len_10,  v_underline_char) || v_pad_char ||
2922            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2923            LPAD(v_underline_char, sq_len_10,  v_underline_char) || v_pad_char ||
2924            LPAD(v_underline_char, sq_len_6,   v_underline_char) || v_pad_char ||
2925            LPAD(v_underline_char, sq_len_6,   v_underline_char) || v_pad_char ||
2926            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2927            LPAD(v_underline_char, sq_len_75,  v_underline_char) || v_pad_char ||
2928            LPAD(v_underline_char, sq_len_75,  v_underline_char) || v_pad_char ||
2929            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2930            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2931            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2932            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2933            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2934            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2935            LPAD(v_underline_char, sq_len_6,   v_underline_char) || v_pad_char ||
2936            LPAD(v_underline_char, sq_len_75,  v_underline_char) || v_pad_char ||
2937            LPAD(v_underline_char, sq_len_5,   v_underline_char) || v_pad_char ||
2938            LPAD(v_underline_char, sq_len_10,  v_underline_char) || v_pad_char ||
2939            LPAD(v_underline_char, sq_len_1,   v_underline_char) || v_pad_char ||
2940            LPAD(v_underline_char, sq_len_1,   v_underline_char) || v_pad_char ||
2941            LPAD(v_underline_char, sq_len_75,  v_underline_char) || v_pad_char ||
2942            LPAD(v_underline_char, sq_len_20,  v_underline_char) || v_pad_char ||
2943            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2944            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2945            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2946            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2947            LPAD(v_underline_char, sq_len_25,  v_underline_char) || v_pad_char ||
2948            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2949            LPAD(v_underline_char, sq_len_6,   v_underline_char) || v_pad_char ||
2950            LPAD(v_underline_char, sq_len_75,  v_underline_char) || v_pad_char ||
2951            LPAD(v_underline_char, sq_len_75,  v_underline_char) || v_pad_char ||
2952            LPAD(v_underline_char, sq_len_5,   v_underline_char) || v_pad_char ||
2953            LPAD(v_underline_char, sq_len_10,  v_underline_char) || v_pad_char ||
2954            LPAD(v_underline_char, sq_len_1,   v_underline_char) || v_pad_char ||
2955            LPAD(v_underline_char, sq_len_15,  v_underline_char) || v_pad_char ||
2956            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2957            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2958            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2959            LPAD(v_underline_char, sq_len_1,   v_underline_char) || v_pad_char ||
2960            LPAD(v_underline_char, sq_len_15,  v_underline_char) || v_pad_char ||
2961            /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
2962            LPAD(v_underline_char, sq_len_1,   v_underline_char) || v_pad_char ||
2963            LPAD(v_underline_char, sq_len_2,   v_underline_char) || v_pad_char ||
2964            LPAD(v_underline_char, sq_len_20,   v_underline_char) || v_pad_char ||
2965            LPAD(v_underline_char, sq_len_20,   v_underline_char) || v_pad_char ||
2966            LPAD(v_underline_char, sq_len_3,   v_underline_char) || v_pad_char ||
2967            LPAD(v_underline_char, sq_len_150,   v_underline_char) || v_pad_char ||
2968            LPAD(v_underline_char, sq_len_12,   v_underline_char) || v_pad_char ||
2969            LPAD(v_underline_char, sq_len_7,   v_underline_char) || v_pad_char ||
2970            LPAD(v_underline_char, sq_len_10,   v_underline_char) || v_pad_char ||
2971            /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
2972            LPAD(v_underline_char, sq_len_2,   v_underline_char)
2973            );
2974 
2975         END create_quarterly_bh;
2976 
2977         PROCEDURE create_quarterly_cd IS
2978                 BEGIN
2979                   UTL_FILE.PUT_LINE(v_filehandle, ' ' ) ;
2980                   UTL_FILE.PUT_LINE(v_filehandle,
2981                   LPAD('Line No', sq_len_9  , v_quart_pad) || v_pad_char ||
2982                   LPAD('RT', sq_len_2  , v_quart_pad) || v_pad_char ||
2986                   LPAD('I', sq_len_1  , v_quart_pad) || v_pad_char ||
2983                   LPAD('Batch No', sq_len_9  , v_quart_pad) || v_pad_char ||
2984                   LPAD('Chall No', sq_len_9  , v_quart_pad) || v_pad_char ||
2985                   LPAD('DeductCnt', sq_len_9  , v_quart_pad) || v_pad_char ||
2987                   LPAD('U', sq_len_2  , v_quart_pad) || v_pad_char ||
2988                   LPAD('F2', sq_len_2  , v_quart_pad) || v_pad_char ||
2989                   LPAD('F3', sq_len_2  , v_quart_pad) || v_pad_char ||
2990                   LPAD('F4', sq_len_2  , v_quart_pad) || v_pad_char ||
2991                   LPAD('LC', sq_len_2  , v_quart_pad) || v_pad_char ||
2992                   LPAD('Ch', sq_len_5  , v_quart_pad) || v_pad_char ||
2993                   LPAD('LV', sq_len_2  , v_quart_pad) || v_pad_char ||
2994                   LPAD('TrnsVouch', sq_len_9  , v_quart_pad) || v_pad_char ||
2995                   LPAD('LB', sq_len_2  , v_quart_pad) || v_pad_char ||
2996                   LPAD('Bank Br', sq_len_7  , v_quart_pad) || v_pad_char ||
2997                   LPAD('LD', sq_len_2  , v_quart_pad) || v_pad_char ||
2998                   LPAD('CH. Date', sq_len_8  , v_quart_pad) || v_pad_char ||
2999                   LPAD('F5', sq_len_2  , v_quart_pad) || v_pad_char ||
3000                   LPAD('F6', sq_len_2  , v_quart_pad) || v_pad_char ||
3001                   LPAD('Sec', sq_len_3  , v_quart_pad) || v_pad_char ||
3002                   LPAD('Oltas Tax', sq_len_15  , v_quart_pad) || v_pad_char ||
3003                   LPAD('Oltas Sur', sq_len_15  , v_quart_pad) || v_pad_char ||
3004                   LPAD('Oltas Cess', sq_len_15  , v_quart_pad) || v_pad_char ||
3005                   LPAD('Oltas Interest', sq_len_15  , v_quart_pad) || v_pad_char ||
3006                   LPAD('Oltas OtherAmt', sq_len_15  , v_quart_pad) || v_pad_char ||
3007                   LPAD('Total Deposit', sq_len_15  , v_quart_pad) || v_pad_char ||
3008                   LPAD('LD', sq_len_2  , v_quart_pad) || v_pad_char ||
3009                   LPAD('TotTax Deposit', sq_len_15  , v_quart_pad) || v_pad_char ||
3010                   LPAD('TDS Income Tax', sq_len_15  , v_quart_pad) || v_pad_char ||
3011                   LPAD('TDS Surcharge', sq_len_15  , v_quart_pad) || v_pad_char ||
3012                   LPAD('TDS Cess', sq_len_15  , v_quart_pad) || v_pad_char ||
3013                   LPAD('Total TDS ', sq_len_15  , v_quart_pad) || v_pad_char ||
3014                   LPAD('TDS Interest', sq_len_15  , v_quart_pad) || v_pad_char ||
3015                   LPAD('TDS OtherAmt', sq_len_15  , v_quart_pad) || v_pad_char ||
3016                   LPAD('Cheque/DD', sq_len_15  , v_quart_pad) || v_pad_char ||
3017                   LPAD('B', sq_len_1  , v_quart_pad) || v_pad_char ||
3018                   LPAD('Remarks', sq_len_14  , v_quart_pad) || v_pad_char ||
3019                   LPAD('RH', sq_len_2  , v_quart_pad)
3020                   );
3021 
3022                  UTL_FILE.PUT_LINE(v_filehandle,
3023                  LPAD(v_underline_char , sq_len_9   , v_underline_char) || v_pad_char ||
3024                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3025                  LPAD(v_underline_char , sq_len_9   , v_underline_char) || v_pad_char ||
3026                  LPAD(v_underline_char , sq_len_9   , v_underline_char) || v_pad_char ||
3027                  LPAD(v_underline_char , sq_len_9   , v_underline_char) || v_pad_char ||
3028                  LPAD(v_underline_char , sq_len_1   , v_underline_char) || v_pad_char ||
3029                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3030                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3031                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3032                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3033                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3034                  LPAD(v_underline_char , sq_len_5   , v_underline_char) || v_pad_char ||
3035                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3036                  LPAD(v_underline_char , sq_len_9   , v_underline_char) || v_pad_char ||
3037                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3038                  LPAD(v_underline_char , sq_len_7   , v_underline_char) || v_pad_char ||
3039                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3040                  LPAD(v_underline_char , sq_len_8   , v_underline_char) || v_pad_char ||
3041                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3042                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3043                  LPAD(v_underline_char , sq_len_3   , v_underline_char) || v_pad_char ||
3044                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3045                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3046                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3047                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3048                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3049                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3050                  LPAD(v_underline_char , sq_len_2   , v_underline_char) || v_pad_char ||
3051                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3052                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3053                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3054                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3055                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3056                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3060                  LPAD(v_underline_char , sq_len_14  , v_underline_char) || v_pad_char ||
3057                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3058                  LPAD(v_underline_char , sq_len_15  , v_underline_char) || v_pad_char ||
3059                  LPAD(v_underline_char , sq_len_1   , v_underline_char) || v_pad_char ||
3061                  LPAD(v_underline_char , sq_len_2   , v_underline_char)
3062                  );
3063 
3064         END create_quarterly_cd;
3065 
3066         PROCEDURE create_quarterly_dd IS
3067                 BEGIN
3068                    UTL_FILE.PUT_LINE(v_filehandle, ' ' ) ;
3069                    UTL_FILE.PUT_LINE(v_filehandle,
3070                    LPAD('Line No', sq_len_9, v_quart_pad)  || v_pad_char ||
3071                    LPAD('RT', sq_len_2, v_quart_pad)  || v_pad_char ||
3072                    LPAD('Batch No', sq_len_9, v_quart_pad)  || v_pad_char ||
3073                    LPAD('ChallNo', sq_len_9, v_quart_pad)  || v_pad_char ||
3074                    LPAD('DedRecNo', sq_len_9, v_quart_pad)  || v_pad_char ||
3075                    LPAD('M', sq_len_1, v_quart_pad)  || v_pad_char ||
3076                    LPAD('EN', sq_len_2, v_quart_pad)  || v_pad_char ||
3077                    LPAD('C', sq_len_1, v_quart_pad)  || v_pad_char ||
3078                    LPAD('LP', sq_len_2, v_quart_pad)  || v_pad_char ||
3079                    LPAD('Emp Pan', sq_len_10, v_quart_pad)  || v_pad_char ||
3080                    LPAD('LP', sq_len_2, v_quart_pad)  || v_pad_char ||
3081                    LPAD('PAN Ref No', sq_len_10, v_quart_pad)  || v_pad_char ||
3082                    LPAD('Employee Name', sq_len_75, v_quart_pad)  || v_pad_char ||
3083                    LPAD('TDS Income Tax ', sq_len_15, v_quart_pad)  || v_pad_char ||
3084                    LPAD('TDS Surcharge', sq_len_15, v_quart_pad)  || v_pad_char ||
3085                    LPAD('TDS Cess', sq_len_15, v_quart_pad)  || v_pad_char ||
3086                    LPAD('TDS Total', sq_len_15, v_quart_pad)  || v_pad_char ||
3087                    LPAD('LT', sq_len_2, v_quart_pad)  || v_pad_char ||
3088                    LPAD('TotTax Deposit', sq_len_15, v_quart_pad)  || v_pad_char ||
3089                    LPAD('LT', sq_len_2, v_quart_pad)  || v_pad_char ||
3090                    LPAD('TP', sq_len_2, v_quart_pad)  || v_pad_char ||
3091                    LPAD('Payment Amt', sq_len_15, v_quart_pad)  || v_pad_char ||
3092                    LPAD('Pay Dt', sq_len_8, v_quart_pad)  || v_pad_char ||
3093                    LPAD('TaxDedDt', sq_len_8, v_quart_pad)  || v_pad_char ||
3094                    LPAD('DD', sq_len_2, v_quart_pad)  || v_pad_char ||
3095                    LPAD('Tax Rt', sq_len_7, v_quart_pad)  || v_pad_char ||
3096                    LPAD('GI', sq_len_2, v_quart_pad)  || v_pad_char ||
3097                    LPAD('B', sq_len_1, v_quart_pad)  || v_pad_char ||
3098                    LPAD('TD', sq_len_2, v_quart_pad)  || v_pad_char ||
3099                    LPAD('R', sq_len_1, v_quart_pad)  || v_pad_char ||
3100                    LPAD('Remarks 2', sq_len_75, v_quart_pad)  || v_pad_char ||
3101                    LPAD('Remarks 3', sq_len_14, v_quart_pad)  || v_pad_char ||
3102                    LPAD('RH', sq_len_2, v_quart_pad)
3103                    );
3104 
3105                    UTL_FILE.PUT_LINE(v_filehandle,
3106                    LPAD(v_underline_char  , sq_len_9  , v_underline_char)  || v_pad_char ||
3107                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3108                    LPAD(v_underline_char  , sq_len_9  , v_underline_char)  || v_pad_char ||
3109                    LPAD(v_underline_char  , sq_len_9  , v_underline_char)  || v_pad_char ||
3110                    LPAD(v_underline_char  , sq_len_9  , v_underline_char)  || v_pad_char ||
3111                    LPAD(v_underline_char  , sq_len_1  , v_underline_char)  || v_pad_char ||
3112                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3113                    LPAD(v_underline_char  , sq_len_1  , v_underline_char)  || v_pad_char ||
3114                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3115                    LPAD(v_underline_char  , sq_len_10 , v_underline_char)  || v_pad_char ||
3116                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3117                    LPAD(v_underline_char  , sq_len_10 , v_underline_char)  || v_pad_char ||
3118                    LPAD(v_underline_char  , sq_len_75 , v_underline_char)  || v_pad_char ||
3119                    LPAD(v_underline_char  , sq_len_15 , v_underline_char)  || v_pad_char ||
3120                    LPAD(v_underline_char  , sq_len_15 , v_underline_char)  || v_pad_char ||
3121                    LPAD(v_underline_char  , sq_len_15 , v_underline_char)  || v_pad_char ||
3122                    LPAD(v_underline_char  , sq_len_15 , v_underline_char)  || v_pad_char ||
3123                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3124                    LPAD(v_underline_char  , sq_len_15 , v_underline_char)  || v_pad_char ||
3125                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3126                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3127                    LPAD(v_underline_char  , sq_len_15 , v_underline_char)  || v_pad_char ||
3128                    LPAD(v_underline_char  , sq_len_8  , v_underline_char)  || v_pad_char ||
3129                    LPAD(v_underline_char  , sq_len_8  , v_underline_char)  || v_pad_char ||
3130                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3131                    LPAD(v_underline_char  , sq_len_7  , v_underline_char)  || v_pad_char ||
3132                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3133                    LPAD(v_underline_char  , sq_len_1  , v_underline_char)  || v_pad_char ||
3134                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)  || v_pad_char ||
3138                    LPAD(v_underline_char  , sq_len_2  , v_underline_char)
3135                    LPAD(v_underline_char  , sq_len_1  , v_underline_char)  || v_pad_char ||
3136                    LPAD(v_underline_char  , sq_len_75 , v_underline_char)  || v_pad_char ||
3137                    LPAD(v_underline_char  , sq_len_14 , v_underline_char)  || v_pad_char ||
3139                    );
3140 
3141                 END create_quarterly_dd;
3142 
3143 
3144   PROCEDURE create_cd IS
3145   BEGIN
3146 
3147     -- Challan Detail
3148     UTL_FILE.PUT_LINE(v_filehandle, fnd_global.local_chr(10) );
3149     UTL_FILE.PUT_LINE(v_filehandle,
3150         LPAD('LineNo', s_line_number, v_pad_char)
3151       ||v_pad_char||RPAD('RT', s_record_type, v_pad_char)
3152       ||v_pad_char||LPAD('B.No', s_batch_number, v_pad_char)
3153       ||v_pad_char||LPAD('CSlNo', s_challan_slno, v_pad_char)
3154       ||v_pad_char||RPAD('Secn.', s_challan_section, v_pad_char)
3155       ||v_pad_char||LPAD('AmtDeducted', s_amount_deducted, v_pad_char)
3156       ||v_pad_char||RPAD('Ch.Num.', s_challan_num, v_pad_char)
3157       ||v_pad_char||LPAD('Ch.Date', s_date, v_pad_char)
3158       ||v_pad_char||RPAD('BankBrCode', s_bank_branch_code, v_pad_char)
3159     );
3160     UTL_FILE.PUT_LINE(v_filehandle,
3161         LPAD(v_underline_char, s_line_number, v_underline_char)
3162       ||v_pad_char||RPAD(v_underline_char, s_record_type, v_underline_char)
3163       ||v_pad_char||LPAD(v_underline_char, s_batch_number, v_underline_char)
3164       ||v_pad_char||LPAD(v_underline_char, s_challan_slno, v_underline_char)
3165       ||v_pad_char||RPAD(v_underline_char, s_challan_section, v_underline_char)
3166       ||v_pad_char||LPAD(v_underline_char, s_amount_deducted, v_underline_char)
3167       ||v_pad_char||RPAD(v_underline_char, s_challan_num, v_underline_char)
3168       ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
3169       ||v_pad_char||RPAD(v_underline_char, s_bank_branch_code, v_underline_char)
3170     );
3171   END create_cd;
3172 
3173 PROCEDURE create_dd IS
3174 BEGIN
3175 
3176 /* Bug 4353842. Added by Lakshmi Gopalsami
3177    p_grossing_up_factor Obsoleted via bug # 4353842
3178 */
3179 
3180 -- Deductee Detail
3181 UTL_FILE.PUT_LINE(v_filehandle, v_chr10 );
3182 UTL_FILE.PUT_LINE(v_filehandle,
3183           LPAD('LineNo', s_line_number, v_pad_char)
3184         ||v_pad_char||RPAD('RT', s_record_type, v_pad_char)
3185         ||v_pad_char||LPAD('B.No.', s_batch_number, v_pad_char)
3186         ||v_pad_char||LPAD('DSlNo', s_deductee_slno, v_pad_char)
3187         ||v_pad_char||RPAD('Secn.', s_deductee_section, v_pad_char)
3188         ||v_pad_char||RPAD('DCode', s_deductee_code, v_pad_char)
3189         ||v_pad_char||RPAD('DteePan', s_deductee_pan, v_pad_char)
3190         ||v_pad_char||RPAD('Deductee Name', s_deductee_name, v_pad_char)
3191         ||v_pad_char||RPAD('Deductee Addr1', s_deductee_address1, v_pad_char)
3192         ||v_pad_char||RPAD('Deductee Addr2', s_deductee_address2, v_pad_char)
3193         ||v_pad_char||RPAD('Deductee Addr3', s_deductee_address3, v_pad_char)
3194         ||v_pad_char||RPAD('Deductee Addr4', s_deductee_address4, v_pad_char)
3195         ||v_pad_char||RPAD('Deductee Addr5', s_deductee_address5, v_pad_char)
3196         ||v_pad_char||LPAD('DState', s_deductee_state, v_pad_char)
3197         ||v_pad_char||LPAD('DtePin', s_deductee_pin, v_pad_char)
3198         ||v_pad_char||LPAD('Filler5', s_filler, v_pad_char)
3199         ||v_pad_char||LPAD('Pay. Amount', s_payment_amount, v_pad_char)
3200         ||v_pad_char||LPAD('Pay. Date', s_date, v_pad_char)
3201         ||v_pad_char||LPAD('PBE', s_book_ent_oth , v_pad_char)
3202         ||v_pad_char||LPAD('TxRt', s_tax_rate, v_pad_char)
3203         --||v_pad_char||RPAD('Gf', s_grossing_up_factor, v_pad_char)
3204         ||v_pad_char||LPAD('Filler6', s_filler6, v_pad_char)
3205         ||v_pad_char||LPAD('TxDeducted', s_tax_deducted, v_pad_char)
3206         ||v_pad_char||LPAD('TxDed.Dt', s_date, v_pad_date)
3207         ||v_pad_char||RPAD('BBRCode', s_bank_branch_code, v_pad_char)
3208         ||v_pad_char||LPAD('TxPay.Dt', s_date, v_pad_date)
3209         ||v_pad_char||RPAD('ChlnNo', s_challan_no, v_pad_char)
3210         ||v_pad_char||LPAD('TdsCrtDt', s_date, v_pad_char)
3211         ||v_pad_char||RPAD('R', s_reason_for_nDeduction, v_pad_char)
3212         ||v_pad_char||LPAD('Filler7', s_filler, v_pad_char)
3213 );
3214 
3215 /* Bug 4353842. Added by Lakshmi Gopalsami
3216    p_grossing_up_factor Obsoleted via bug # 4353842
3217 */
3218 
3219 UTL_FILE.PUT_LINE(v_filehandle,
3220           LPAD(v_underline_char, s_line_number, v_underline_char)
3221         ||v_pad_char||RPAD(v_underline_char, s_record_type, v_underline_char)
3222         ||v_pad_char||LPAD(v_underline_char, s_batch_number, v_underline_char)
3223         ||v_pad_char||LPAD(v_underline_char, s_deductee_slno, v_underline_char)
3224         ||v_pad_char||RPAD(v_underline_char, s_deductee_section, v_underline_char)
3225         ||v_pad_char||RPAD(v_underline_char, s_deductee_code, v_underline_char)
3226         ||v_pad_char||RPAD(v_underline_char, s_deductee_pan, v_underline_char)
3227         ||v_pad_char||RPAD(v_underline_char, s_deductee_name, v_underline_char)
3228         ||v_pad_char||RPAD(v_underline_char, s_deductee_address1, v_underline_char)
3229         ||v_pad_char||RPAD(v_underline_char, s_deductee_address2, v_underline_char)
3230         ||v_pad_char||RPAD(v_underline_char, s_deductee_address3, v_underline_char)
3231         ||v_pad_char||RPAD(v_underline_char, s_deductee_address4, v_underline_char)
3232         ||v_pad_char||RPAD(v_underline_char, s_deductee_address5, v_underline_char)
3233         ||v_pad_char||LPAD(v_underline_char, s_deductee_state, v_underline_char)
3234         ||v_pad_char||LPAD(v_underline_char, s_deductee_pin, v_underline_char)
3235         ||v_pad_char||LPAD(v_underline_char, s_filler, v_underline_char)
3236         ||v_pad_char||LPAD(v_underline_char, s_payment_amount, v_underline_char)
3237         ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
3241         --||v_pad_char||RPAD(v_underline_char, s_grossing_up_factor, v_underline_char)
3238         ||v_pad_char||LPAD(v_underline_char, s_book_ent_oth , v_underline_char)
3239         ||v_pad_char||LPAD(v_underline_char, s_tax_rate, v_underline_char)
3240         ||v_pad_char||LPAD(v_underline_char, s_filler6, v_underline_char)
3242         ||v_pad_char||LPAD(v_underline_char, s_tax_deducted, v_underline_char)
3243         ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
3244         ||v_pad_char||RPAD(v_underline_char, s_bank_branch_code, v_underline_char)
3245         ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
3246         ||v_pad_char||RPAD(v_underline_char, s_challan_no, v_underline_char)
3247         ||v_pad_char||LPAD(v_underline_char, s_date, v_underline_char)
3248         ||v_pad_char||RPAD(v_underline_char, s_reason_for_nDeduction, v_underline_char)
3249         ||v_pad_char||LPAD(v_underline_char, s_filler, v_underline_char)
3250 );
3251 
3252 END create_dd;
3253 
3254 
3255 -- added, Harshita for Bug 5096787
3256 
3257       -- eTDS Quarterly Data Generation Procedues
3258 
3259 PROCEDURE create_quarterly_file_header(
3260   p_line_number IN NUMBER,
3261   p_record_type IN VARCHAR2,
3262   p_file_type IN VARCHAR2,
3263   p_upload_type IN VARCHAR2,
3264   p_file_creation_date IN DATE,
3265   p_file_sequence_number IN NUMBER,
3266   p_uploader_type  IN VARCHAR2,
3267   p_deductor_tan IN VARCHAR2,
3268   p_number_of_batches IN NUMBER,
3269   p_return_prep_util IN VARCHAR2, /*Bug 8880543 - Added Return Preperation Utility*/
3270   p_fh_recordHash IN VARCHAR2,
3271   p_fh_fvuVersion IN VARCHAR2,
3272   p_fh_fileHash   IN VARCHAR2,
3273   p_fh_samVersion IN VARCHAR2,
3274   p_fh_samHash    IN VARCHAR2,
3275   p_fh_scmVersion IN VARCHAR2,
3276   p_fh_scmHash    IN VARCHAR2,
3277   p_fh_consFileHash IN VARCHAR2, /* ETDS FVU3.3 -Bug 13702172 */
3278   p_generate_headers IN VARCHAR2
3279 )
3280 IS
3281 BEGIN
3282  IF p_generate_headers = 'N' THEN
3283 
3284    UTL_FILE.PUT_LINE(v_filehandle,
3285    p_line_number             ||  v_delimeter||
3286    p_record_type             ||  v_delimeter||
3287    p_file_type               ||  v_delimeter||
3288    p_upload_type             ||  v_delimeter||
3289    to_char(p_file_creation_date,'ddmmyyyy') ||  v_delimeter||
3290    p_file_sequence_number    ||  v_delimeter||
3291    p_uploader_type           ||  v_delimeter||
3292    upper(p_deductor_tan)     ||  v_delimeter||
3293    p_number_of_batches       ||  v_delimeter||
3294    p_return_prep_util        ||  v_delimeter|| /*Bug 8880543 - Added Return Preperation Utility*/
3295    p_fh_recordHash           ||  v_delimeter||
3296    p_fh_fvuVersion           ||  v_delimeter||
3297    p_fh_fileHash             ||  v_delimeter||
3298    p_fh_samVersion           ||  v_delimeter||
3299    p_fh_samHash              ||  v_delimeter||
3300    p_fh_scmVersion           ||  v_delimeter||
3301    p_fh_scmHash              ||  v_delimeter||
3302    p_fh_consFileHash);/* ETDS FVU3.3 -Bug 13702172 */
3303  ELSE
3304    UTL_FILE.PUT_LINE(v_filehandle,
3305    LPAD(p_line_number , sq_len_9, v_quart_pad) || v_pad_char ||
3306    LPAD(p_record_type , sq_len_2, v_quart_pad) || v_pad_char ||
3307    LPAD(p_file_type , sq_len_4, v_quart_pad) || v_pad_char ||
3308    LPAD(p_upload_type , sq_len_2, v_quart_pad) || v_pad_char ||
3309    LPAD(p_file_creation_date , sq_len_8, v_quart_pad) || v_pad_char ||
3310    LPAD(p_file_sequence_number , sq_len_5, v_quart_pad) || v_pad_char ||
3311    LPAD(p_uploader_type , sq_len_1, v_quart_pad) || v_pad_char ||
3312    LPAD(upper(p_deductor_tan) , sq_len_10, v_quart_pad) || v_pad_char ||
3313    LPAD(p_number_of_batches , sq_len_9, v_quart_pad) || v_pad_char ||
3314    LPAD(p_return_prep_util , sq_len_75, v_quart_pad) || v_pad_char || /*Bug 8880543 - Added Return Preperation Utility*/
3315    LPAD(NVL(p_fh_recordHash,v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3316    LPAD(NVL(p_fh_fvuVersion, v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3317    LPAD(NVL(p_fh_fileHash, v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3318    LPAD(NVL(p_fh_samVersion, v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3319    LPAD(NVL(p_fh_samHash, v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3320    LPAD(NVL(p_fh_scmVersion, v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3321    LPAD(NVL(p_fh_scmHash, v_q_noval_filler) , sq_len_2, v_quart_pad) || v_pad_char ||
3322    LPAD(NVL(p_fh_consFileHash, v_q_noval_filler) , sq_len_2, v_quart_pad) /* ETDS FVU3.3 -Bug 13702172 */
3323    ) ;
3324 
3325  END IF ;
3326 
3327 END create_quarterly_file_header;
3328 
3329 
3330 PROCEDURE create_quarterly_batch_header(
3331   p_line_number IN NUMBER,
3332   p_record_type IN VARCHAR2,
3333   p_batch_number IN NUMBER,
3334   p_challan_count IN NUMBER,
3335   p_form_number IN CHAR,
3336   p_trn_type IN VARCHAR2,
3337   p_batchUpd IN VARCHAR2,
3338   /* Bug# - Start */
3339   p_bh_orig_token IN VARCHAR2,
3340   p_bh_prev_token IN VARCHAR2,
3341   p_bh_token_number IN VARCHAR2,
3342   p_bh_token_date IN VARCHAR2,
3343   /* Bug#10315928 - End */
3344   p_deductor_last_tan  IN VARCHAR2,
3345   p_deductor_tan       IN VARCHAR2,
3346   p_bh_receipt_no      IN VARCHAR2, /* Bug#10315928 */
3347   p_deductor_pan       IN VARCHAR2,
3348   p_assessment_year    IN NUMBER,
3349   p_financial_year     IN NUMBER,
3350   p_period             IN VARCHAR2,
3351   p_deductor_name      IN VARCHAR2,
3352   p_deductor_branch    IN VARCHAR2,
3353   p_tan_address1       IN VARCHAR2,
3354   p_tan_address2       IN VARCHAR2,
3355   p_tan_address3       IN VARCHAR2,
3356   p_tan_address4       IN VARCHAR2,
3357   p_tan_address5       IN VARCHAR2,
3358   p_tan_state_code     IN NUMBER,
3359   p_tan_pin            IN NUMBER,
3363   p_addrChangedSinceLastReturn IN VARCHAR2,
3360   p_deductor_email     IN VARCHAR2,
3361   p_deductor_stdCode   IN NUMBER,
3362   p_deductor_phoneNo   IN NUMBER,
3364   p_type_of_deductor   IN VARCHAR2, /*Bug 8880543 - Modified Deductor Status to Deductor Type*/
3365   p_pers_resp_for_deduction IN VARCHAR2,
3366   p_PespPerson_designation  IN VARCHAR2,
3367   p_RespPerson_address1     IN VARCHAR2,
3368   p_RespPerson_address2     IN VARCHAR2,
3369   p_RespPerson_address3     IN VARCHAR2,
3370   p_RespPerson_address4     IN VARCHAR2,
3371   p_RespPerson_address5     IN VARCHAR2,
3372   p_RespPerson_state        IN VARCHAR2,
3373   p_RespPerson_pin          IN NUMBER,
3374   p_RespPerson_email        IN VARCHAR2,
3375   p_RespPerson_mobile       IN VARCHAR2, /* Bug#10315928 */
3376   p_RespPerson_stdCode      IN NUMBER,
3377   p_RespPerson_phoneNo      IN NUMBER,
3378   p_RespPerson_addressChange IN VARCHAR2,
3379   p_totTaxDeductedAsPerChallan IN NUMBER,
3380   p_bh_unmatch_challan_cnt  IN VARCHAR2, /* Bug#10315928 */
3381   p_salaryRecords_count     IN VARCHAR2,
3382   p_gross_total             IN VARCHAR2,
3383   p_ao_approval             IN VARCHAR2,
3384   p_ao_approval_number      IN VARCHAR2,
3385   /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
3386   p_last_deductor_type      IN  VARCHAR2,
3387   p_state_name              IN  VARCHAR2,
3388   p_pao_code                IN  VARCHAR2,
3389   p_ddo_code                IN  VARCHAR2,
3390   p_ministry_name           IN  VARCHAR2,
3391   p_ministry_name_other     IN  VARCHAR2,
3392   p_filler2                 IN  VARCHAR2,
3393   p_pao_registration_no     IN  NUMBER,
3394   p_ddo_registration_no     IN  VARCHAR2,
3395   /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
3396   p_recHash                 IN VARCHAR2,
3397   p_generate_headers        IN VARCHAR2
3398 )
3399 IS
3400 BEGIN
3401   IF p_generate_headers = 'N' THEN
3402     UTL_FILE.PUT_LINE( v_filehandle,  p_line_number          ||  v_delimeter||
3403     p_record_type            ||  v_delimeter||
3404     p_batch_number           ||  v_delimeter||
3405     p_challan_count          ||  v_delimeter||
3406     p_form_number            ||  v_delimeter||
3407     p_trn_type               ||  v_delimeter||
3408     p_batchUpd               ||  v_delimeter||
3409    /* Bug#10315928 - Start */
3410     p_bh_orig_token          ||  v_delimeter||
3411     p_bh_prev_token          ||  v_delimeter||
3412     p_bh_token_number        ||  v_delimeter||
3413     p_bh_token_date          ||  v_delimeter||
3414     /* Bug#10315928 - End */
3415     p_deductor_last_tan      ||  v_delimeter||
3416     upper(p_deductor_tan)    ||  v_delimeter||
3417     p_bh_receipt_no          ||  v_delimeter|| /* Bug#10315928 */
3418     p_deductor_pan           ||  v_delimeter||
3419     p_assessment_year        ||  v_delimeter||
3420     p_financial_year         ||  v_delimeter||
3421     p_period                 ||  v_delimeter||
3422     p_deductor_name          ||  v_delimeter||
3423     p_deductor_branch        ||  v_delimeter||
3424     p_tan_address1           ||  v_delimeter||
3425     p_tan_address2           ||  v_delimeter||
3426     p_tan_address3           ||  v_delimeter||
3427     p_tan_address4           ||  v_delimeter||
3428     p_tan_address5           ||  v_delimeter||
3429     p_tan_state_code         ||  v_delimeter||
3430     p_tan_pin                ||  v_delimeter||
3431     p_deductor_email         ||  v_delimeter||
3432     p_deductor_stdCode       ||  v_delimeter||
3433     p_deductor_phoneNo       ||  v_delimeter||
3434     p_addrChangedSinceLastReturn ||  v_delimeter||
3435     p_type_of_deductor       ||  v_delimeter|| /*Bug 8880543 - Modified Status of Deductor to type of Deductor*/
3436     p_pers_resp_for_deduction   ||  v_delimeter||
3437     p_PespPerson_designation    ||  v_delimeter||
3438     p_RespPerson_address1       ||  v_delimeter||
3439     p_RespPerson_address2       ||  v_delimeter||
3440     p_RespPerson_address3       ||  v_delimeter||
3441     p_RespPerson_address4       ||  v_delimeter||
3442     p_RespPerson_address5       ||  v_delimeter||
3443     p_RespPerson_state          ||  v_delimeter||
3444     p_RespPerson_pin            ||  v_delimeter||
3445     p_RespPerson_email          ||  v_delimeter||
3446     p_RespPerson_mobile         ||  v_delimeter|| /* Bug#10315928 */
3447     p_RespPerson_stdCode        ||  v_delimeter||
3448     p_RespPerson_phoneNo        ||  v_delimeter||
3449     p_RespPerson_addressChange  ||  v_delimeter||
3450     to_char(p_totTaxDeductedAsPerChallan,v_format_amount) ||  v_delimeter||
3451     p_bh_unmatch_challan_cnt    ||  v_delimeter|| /* Bug#10315928 */
3452     p_salaryRecords_count       ||  v_delimeter||
3453     p_gross_total               ||  v_delimeter||
3454     p_ao_approval               ||  v_delimeter||
3455     p_ao_approval_number        ||  v_delimeter||
3456     /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
3457     p_last_deductor_type        ||  v_delimeter||
3458     p_state_name                ||  v_delimeter||
3459     p_pao_code                  ||  v_delimeter||
3460     p_ddo_code                  ||  v_delimeter||
3461     p_ministry_name             ||  v_delimeter||
3462     p_ministry_name_other       ||  v_delimeter||
3463     p_filler2                   ||  v_delimeter||
3464     to_char(p_pao_registration_no)       ||  v_delimeter||
3465     p_ddo_registration_no       ||  v_delimeter||
3466     /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
3467     p_recHash                             ) ;
3468 
3469 
3470   ELSE
3471     UTL_FILE.PUT_LINE( v_filehandle,
3472     LPAD(p_line_number, sq_len_9  , v_quart_pad) || v_pad_char ||
3473     LPAD(p_record_type , sq_len_2  , v_quart_pad) || v_pad_char ||
3474     LPAD(p_batch_number, sq_len_9  , v_quart_pad) || v_pad_char ||
3475     LPAD(p_challan_count, sq_len_9  , v_quart_pad) || v_pad_char ||
3476     LPAD(p_form_number, sq_len_4  , v_quart_pad) || v_pad_char ||
3480      LPAD(NVL(p_bh_prev_token,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3477     LPAD(NVL(p_trn_type,v_q_noval_filler ), sq_len_2  , v_quart_pad) || v_pad_char ||
3478     LPAD(NVL(p_batchUpd,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3479      LPAD(NVL(p_bh_orig_token,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3481      LPAD(NVL(p_bh_token_number,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3482      LPAD(NVL(p_bh_token_date,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3483      LPAD(NVL(p_deductor_last_tan,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3484     LPAD(upper(p_deductor_tan), sq_len_10  , v_quart_pad) || v_pad_char ||
3485     LPAD(NVL(p_bh_receipt_no,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3486     LPAD(NVL(p_deductor_pan,v_q_null_filler ) , sq_len_10  , v_quart_pad) || v_pad_char ||
3487     LPAD(p_assessment_year , sq_len_6  , v_quart_pad) || v_pad_char ||
3488     LPAD(p_financial_year  , sq_len_6  , v_quart_pad) || v_pad_char ||
3489     LPAD(p_period , sq_len_2  , v_quart_pad) || v_pad_char ||
3490     LPAD(p_deductor_name, sq_len_75  , v_quart_pad) || v_pad_char ||
3491     LPAD(NVL(p_deductor_branch ,v_q_null_filler ), sq_len_75  , v_quart_pad) || v_pad_char ||
3492     LPAD(p_tan_address1, sq_len_25  , v_quart_pad) || v_pad_char ||
3493     LPAD(NVL(p_tan_address2,v_q_null_filler )   , sq_len_25  , v_quart_pad) || v_pad_char ||
3494     LPAD(NVL(p_tan_address3,v_q_null_filler )     , sq_len_25  , v_quart_pad) || v_pad_char ||
3495     LPAD(NVL(p_tan_address4,v_q_null_filler ) , sq_len_25  , v_quart_pad) || v_pad_char ||
3496     LPAD(NVL(p_tan_address5,v_q_null_filler )   , sq_len_25  , v_quart_pad) || v_pad_char ||
3497     LPAD(p_tan_state_code, sq_len_2  , v_quart_pad) || v_pad_char ||
3498     LPAD(p_tan_pin, sq_len_6  , v_quart_pad) || v_pad_char ||
3499     LPAD(NVL(p_deductor_email,v_q_null_filler ) , sq_len_75  , v_quart_pad) || v_pad_char ||
3500     LPAD(NVL(p_deductor_stdCode,v_quart_numfill ) , sq_len_5  , v_quart_pad) || v_pad_char ||
3501     LPAD(NVL(p_deductor_phoneNo,v_quart_numfill )    , sq_len_10  , v_quart_pad) || v_pad_char ||
3502     LPAD(p_addrChangedSinceLastReturn, sq_len_1  , v_quart_pad) || v_pad_char ||
3503     LPAD(p_type_of_deductor, sq_len_1  , v_quart_pad) || v_pad_char ||
3504     LPAD(p_pers_resp_for_deduction, sq_len_75  , v_quart_pad) || v_pad_char ||
3505     LPAD(p_PespPerson_designation, sq_len_20  , v_quart_pad) || v_pad_char ||
3506     LPAD(p_RespPerson_address1, sq_len_25  , v_quart_pad) || v_pad_char ||
3507     LPAD(NVL(p_RespPerson_address2,v_q_null_filler ) , sq_len_25  , v_quart_pad) || v_pad_char ||
3508     LPAD(NVL(p_RespPerson_address3,v_q_null_filler ) , sq_len_25  , v_quart_pad) || v_pad_char ||
3509     LPAD(NVL(p_RespPerson_address4,v_q_null_filler ) , sq_len_25  , v_quart_pad) || v_pad_char ||
3510     LPAD(NVL(p_RespPerson_address5,v_q_null_filler ) , sq_len_25  , v_quart_pad) || v_pad_char ||
3511     LPAD(p_RespPerson_state, sq_len_2  , v_quart_pad) || v_pad_char ||
3512     LPAD(p_RespPerson_pin, sq_len_6  , v_quart_pad) || v_pad_char ||
3513     LPAD(NVL(p_RespPerson_email,v_q_null_filler ) , sq_len_75  , v_quart_pad) || v_pad_char ||
3514     LPAD(NVL(p_RespPerson_mobile,v_q_null_filler ) , sq_len_75  , v_quart_pad) || v_pad_char ||
3515     LPAD(NVL(p_RespPerson_stdCode,v_quart_numfill ) , sq_len_5  , v_quart_pad) || v_pad_char ||
3516     LPAD(NVL(p_RespPerson_phoneNo,v_quart_numfill )   , sq_len_10  , v_quart_pad) || v_pad_char ||
3517     LPAD(p_RespPerson_addressChange, sq_len_1  , v_quart_pad) || v_pad_char ||
3518     LPAD(to_char(p_totTaxDeductedAsPerChallan,v_format_amount), sq_len_15  , v_quart_pad) || v_pad_char ||
3519     LPAD(NVL(p_bh_unmatch_challan_cnt,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3520     LPAD(NVL(p_salaryRecords_count,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3521     LPAD(NVL(p_gross_total,v_q_noval_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3522     LPAD(p_ao_approval, sq_len_1  , v_quart_pad) || v_pad_char ||
3523     LPAD(NVL(p_ao_approval_number,v_q_noval_filler ) , sq_len_15  , v_quart_pad) || v_pad_char ||
3524     /*Bug 8880543 - Modified for eTDS/eTCS FVU changes - Start*/
3525     LPAD(NVL(p_last_deductor_type, v_q_null_filler ) , sq_len_1  , v_quart_pad) || v_pad_char ||
3526     LPAD(NVL(p_state_name, v_q_null_filler ) , sq_len_2  , v_quart_pad) || v_pad_char ||
3527     LPAD(NVL(p_pao_code, v_q_null_filler ) , sq_len_20  , v_quart_pad) || v_pad_char ||
3528     LPAD(NVL(p_ddo_code, v_q_null_filler ) , sq_len_20  , v_quart_pad) || v_pad_char ||
3529     LPAD(NVL(p_ministry_name, v_q_null_filler ) , sq_len_3  , v_quart_pad) || v_pad_char ||
3530     LPAD(NVL(p_ministry_name_other, v_q_null_filler ) , sq_len_150  , v_quart_pad) || v_pad_char ||
3531     LPAD(NVL(p_filler2, v_q_null_filler ) , sq_len_12  , v_quart_pad) || v_pad_char ||
3532     LPAD(NVL(to_char(p_pao_registration_no), v_q_null_filler ) , sq_len_7  , v_quart_pad) || v_pad_char ||
3533     LPAD(NVL(p_ddo_registration_no, v_q_null_filler ) , sq_len_10  , v_quart_pad) || v_pad_char ||
3534     /*Bug 8880543 - Modified for eTDS/eTCS FVU changes - End*/
3535     LPAD(NVL(p_recHash,v_q_noval_filler ) , sq_len_2  , v_quart_pad)
3536     );
3537 
3538   END IF ;
3539 END create_quarterly_batch_header;
3540 
3541 
3542 PROCEDURE create_quart_challan_dtl(
3543   p_line_number IN NUMBER ,
3544   p_record_type IN VARCHAR2 ,
3545   p_batch_number IN NUMBER ,
3546   p_challan_dtl_slno IN NUMBER ,
3547   p_deductee_cnt IN NUMBER ,
3548   p_nil_challan_indicator IN VARCHAR2 ,
3549   p_ch_updIndicator IN VARCHAR2 ,
3550   p_filler2 IN VARCHAR2 ,
3551   p_filler3 IN VARCHAR2 ,
3552   p_filler4 IN VARCHAR2 ,
3553   p_last_bank_challan_no IN VARCHAR2 ,
3554   p_bank_challan_no IN VARCHAR2 ,
3555   p_last_transfer_voucher_no IN VARCHAR2 ,
3556   p_transfer_voucher_no IN NUMBER ,
3557   p_last_bank_branch_code IN VARCHAR2 ,
3558   p_bank_branch_code IN VARCHAR2 ,
3559   p_challan_lastDate IN VARCHAR2 ,
3560   p_challan_Date IN DATE ,
3561   p_filler5 IN VARCHAR2 ,
3562   p_filler6 IN VARCHAR2 ,
3563   p_tds_section IN VARCHAR2 ,
3564   p_amt_of_tds IN NUMBER ,
3565   p_amt_of_surcharge IN NUMBER ,
3566   p_amt_of_cess IN NUMBER ,
3567   p_amt_of_int IN NUMBER ,
3568   p_amt_of_oth IN NUMBER ,
3569   p_tds_amount IN NUMBER ,
3570   p_last_total_depositAmt IN NUMBER ,
3571   p_total_deposit IN NUMBER ,
3572   p_tds_income_tax IN NUMBER ,
3573   p_tds_surcharge IN NUMBER ,
3574   p_tds_cess IN NUMBER ,
3575   p_total_income_tds IN NUMBER ,
3576   p_tds_interest_amt IN NUMBER ,
3577   p_tds_other_amt IN NUMBER ,
3578   p_check_number IN NUMBER ,
3579   p_book_entry IN VARCHAR2 ,
3580   p_remarks IN VARCHAR2 ,
3581   p_ch_recHash IN VARCHAR2,
3582   p_generate_headers IN VARCHAR2,
3583   /* Bug 6796765. Added by Lakshmi Gopalsami
3584    * Added p_form_name as this is required to print the
3585    * section code depending on the section
3586    */
3587   p_form_name IN VARCHAR2
3588   ) IS
3589   /* Bug 6796765. Added by Lakshmi Gopalsami
3590    * Declared variable to select the section truncation depending on
3591    * the form name
3592    */
3593   lv_sec_string  VARCHAR2(50);
3594   lv_output_string VARCHAR2 (100);
3595   ln_tds_section NUMBER;
3596 
3597 BEGIN
3598 
3599   /* Bug 6796765. Added by Lakshmi Gopalsami
3600    * Hardcoding the value of tds_section to be printed in flat file
3601    * for following values 194BB, 194EE, 194LA
3602    * as per the details provided in NSDL as separate logic cannot be
3603    *  derived.
3604    * Logic here is to get the section code as 194C, 194D, 195 etc.
3605    * from SEC. 194(C) and then check whether it can be converted to a
3606    * number. If so, the value will be printed in flat file else
3607    * extract the value from 2nd character in flat file except for the
3608    * above hardcoded sections
3609    */
3610 
3611 /* Commentted out by Chong for eTDS ER bug#16414088 20130330 Start
3612    --27Q out put setion code mapping should define in UI.
3613 
3614   --lv_sec_string := 'SEC. ()'; commenetd and added below line by mmurtuza for bug12943133 to accomodate sections with E and C
3615   lv_sec_string := '. ()';
3616   lv_output_string := getSectionCode(upper(p_tds_section), lv_sec_string);
3617 
3618   IF lv_output_string in ('194BB', '194EE','194LB','194LC') THEN \* Added '194LC' and '194LB' in if condition for FVU3.6 *\
3619     lv_output_string := substr(lv_output_string,3,length(lv_output_string));
3620   ELSIF lv_output_string = '194LA' THEN
3621     lv_output_string := '94L';
3622 
3623   --Added by Zhhou for Bug#15840480 begin
3624   -------------------------------------------------------
3625  \* ELSIF lv_output_string = '194LB' then
3626     lv_output_string := '4LB';
3627   ELSIF lv_output_string = '194LC' then
3628     lv_output_string := '4LC'; *\ \* Commented by Avanija for FVU3.6 *\
3629   -------------------------------------------------------
3630   --Added by Zhhou for Bug#15840480 end
3631 
3632   \*'SEC. ()' which is passed as parameter to getSectionCode already has C which is translated to ' '
3633   So only 194 is returned by getSectionCode instead of 194C. Hence harcoded the Section for 194(C) as 94C*\
3634 
3635 \*commented by mmurtuza for bug12943133
3636   ELSIF lv_output_string = '194' AND upper(p_tds_section) = 'SEC. 194(C)' THEN
3637     lv_output_string := '94C';*\
3638   ELSE
3639      BEGIN
3640        ln_tds_section := to_number(lv_output_string);
3641      EXCEPTION
3642        WHEN OTHERS THEN
3646     )) THEN --added if caluse by mmurtua for bug 12943133
3643          IF SQLCODE = -6502 THEN
3644     IF(lv_output_string NOT IN ('94A','94B','4BB','94C','94D','4EE','94F','94G','94H','94I','94J','94L','94E','96A','96B','96C','96D'
3645        ,'4LB','4LC'--Added by Zhhou for Bug#15840480
3647        lv_output_string := substr(lv_output_string,2,length(lv_output_string));
3648     END IF;
3649          END IF;
3650      END;
3651   END IF;
3652 */
3653 --Commentted out by Chong for eTDS ER bug#16414088 20130330 End
3654 --Added out by Chong for eTDS ER bug#16414088 20130330 Start
3655 --------------------------------------------------------------------
3656    BEGIN
3657      SELECT jatsm.section_code_revised  INTO  lv_output_string
3658       FROM   jai_ap_tds_sec_map jatsm
3659             ,ja_lookups          jl
3660             ,jai_rgm_definitions jrd
3661       WHERE jl.lookup_code = jrd.regime_code
3662         AND jl.lookup_type = G_JAI_INDIA_TAX_REGIMES
3663         AND jl.lookup_code = G_TDS
3664         AND jatsm.section_code = p_tds_section
3665 --      AND   jatsm.form_type = 1
3666       AND   jatsm.form_type = decode(p_form_name,'27Q',1,2)   --Updated by Chong for bug#16824926
3667       AND   jatsm.regime_id = jrd.regime_id
3668       AND   jatsm.from_date <= p_challan_date
3669       AND   (jatsm.to_date IS NULL
3670              OR jatsm.to_date >= p_challan_date
3671             )
3672      ;
3673    EXCEPTION
3674      WHEN OTHERS THEN
3675        lv_output_string := p_tds_section;
3676    END;
3677 --------------------------------------------------------------------
3678 --Added out by Chong for eTDS ER bug#16414088 20130330 End
3679 
3680 
3681   -- End for bug 6796765.
3682 
3683   -- fnd_file.put_line(FND_FILE.LOG,' tds section ' || p_tds_section);
3684   -- fnd_file.put_line(FND_FILE.LOG,'SEction code with header '||
3685   -- LPAD(getSectionCode(upper(p_tds_section),upper(lv_sec_string)), sq_len_3, v_quart_pad));
3686   -- fnd_file.put_line(FND_FILE.LOG,'SEction code with header '|| getSectionCode(upper(p_tds_section),
3687   -- upper(lv_sec_string)) );
3688 
3689   IF p_generate_headers = 'N' THEN
3690 
3691     -- Bug 6796765. Added by Lakshmi Gopalsami
3692     -- Changed from getsectioncode to lv_output_string
3693 
3694     UTL_FILE.PUT_LINE(
3695     v_filehandle,p_line_number                  ||  v_delimeter||
3696     p_record_type                               ||  v_delimeter||
3697     p_batch_number                              ||  v_delimeter||
3698     p_challan_dtl_slno                          ||  v_delimeter||
3699     p_deductee_cnt                              ||  v_delimeter||
3700     p_nil_challan_indicator                     ||  v_delimeter||
3701     p_ch_updIndicator                           ||  v_delimeter||
3702     p_filler2                                   ||  v_delimeter||
3703     p_filler3                                   ||  v_delimeter||
3704     p_filler4                                   ||  v_delimeter||
3705     p_last_bank_challan_no                      ||  v_delimeter||
3706     substr(p_bank_challan_no, 1,5)              ||  v_delimeter||
3707     p_last_transfer_voucher_no                  ||  v_delimeter||
3708     p_transfer_voucher_no                       ||  v_delimeter||
3709     p_last_bank_branch_code                     ||  v_delimeter||
3710     p_bank_branch_code                          ||  v_delimeter||
3711     p_challan_lastDate                          ||  v_delimeter||
3712     to_char(p_challan_Date,'ddmmyyyy')          ||  v_delimeter||
3713     p_filler5                                   ||  v_delimeter||
3714     p_filler6                                   ||  v_delimeter||
3715     -- Bug 6796765. Added by Lakshmi Gopalsami
3716     lv_output_string   ||  v_delimeter||
3717     to_char(p_amt_of_tds,v_format_amount)       ||  v_delimeter||
3718     to_char(p_amt_of_surcharge,v_format_amount) ||  v_delimeter||
3719     to_char(p_amt_of_cess,v_format_amount)      ||  v_delimeter||
3720     to_char(p_amt_of_int,v_format_amount)       ||  v_delimeter||
3721     to_char(p_amt_of_oth,v_format_amount)       ||  v_delimeter||
3722     to_char(p_tds_amount,v_format_amount)       ||  v_delimeter||
3723     p_last_total_depositAmt                     ||  v_delimeter||
3724     to_char(p_total_deposit,v_format_amount)    ||  v_delimeter||
3725     to_char(p_tds_income_tax,v_format_amount)   ||  v_delimeter||
3726     to_char(p_tds_surcharge,v_format_amount)    ||  v_delimeter||
3727     to_char(p_tds_cess,v_format_amount)         ||  v_delimeter||
3728     to_char(p_total_income_tds,v_format_amount) ||  v_delimeter||
3729     to_char(p_tds_interest_amt,v_format_amount) ||  v_delimeter||
3730     to_char(p_tds_other_amt, v_format_amount)   ||  v_delimeter||
3731     p_check_number                              ||  v_delimeter||
3732     p_book_entry                                ||  v_delimeter||
3733     p_remarks                                   ||  v_delimeter||
3734     p_ch_recHash ) ;
3735   ELSE
3736     -- Bug 6796765. Added by Lakshmi Gopalsami
3737     -- Changed from getsectioncode to lv_output_string
3738 
3739     UTL_FILE.PUT_LINE( v_filehandle,
3740     LPAD(p_line_number     , sq_len_9, v_quart_pad) || v_pad_char ||
3741     LPAD(p_record_type     , sq_len_2, v_quart_pad) || v_pad_char ||
3742     LPAD(p_batch_number       , sq_len_9, v_quart_pad) || v_pad_char ||
3743     LPAD(p_challan_dtl_slno       , sq_len_9, v_quart_pad) || v_pad_char ||
3744     LPAD(p_deductee_cnt      , sq_len_9, v_quart_pad) || v_pad_char ||
3745     LPAD(p_nil_challan_indicator  , sq_len_1, v_quart_pad) || v_pad_char ||
3746     LPAD(NVL(p_ch_updIndicator,v_q_noval_filler),   sq_len_2, v_quart_pad) || v_pad_char ||
3747     LPAD(NVL(p_filler2,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3748     LPAD(NVL(p_filler3,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3749     LPAD(NVL(p_filler4,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3750     LPAD(NVL(p_last_bank_challan_no,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3751     LPAD(NVL(p_bank_challan_no,v_q_null_filler )       , sq_len_5, v_quart_pad) || v_pad_char ||
3752     LPAD(NVL(p_last_transfer_voucher_no,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3753     LPAD(NVL(p_transfer_voucher_no,v_quart_numfill )       , sq_len_9, v_quart_pad) || v_pad_char ||
3754     LPAD(NVL(p_last_bank_branch_code,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3755     LPAD(NVL(p_bank_branch_code,v_q_null_filler )       , sq_len_7, v_quart_pad) || v_pad_char ||
3756     LPAD(NVL(p_challan_lastDate,v_q_noval_filler ) , sq_len_2, v_quart_pad) || v_pad_char ||
3757     LPAD(to_char(p_challan_Date,'ddmmyyyy') , sq_len_8, v_quart_pad) || v_pad_char ||
3758     LPAD(NVL(p_filler5,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3759     LPAD(NVL(p_filler6,v_q_noval_filler )       , sq_len_2, v_quart_pad) || v_pad_char ||
3760     -- Bug 6796765. Added by Lakshmi Gopalsami
3761     LPAD(lv_output_string, sq_len_3, v_quart_pad) || v_pad_char ||
3762     LPAD(to_char(p_amt_of_tds , v_format_amount)   , sq_len_15, v_quart_pad) || v_pad_char ||
3763     LPAD(to_char( p_amt_of_surcharge, v_format_amount)  , sq_len_15, v_quart_pad) || v_pad_char ||
3764     LPAD(to_char( p_amt_of_cess, v_format_amount)  , sq_len_15, v_quart_pad) || v_pad_char ||
3765     LPAD(to_char( p_amt_of_int, v_format_amount)   , sq_len_15, v_quart_pad) || v_pad_char ||
3766     LPAD(to_char( p_amt_of_oth, v_format_amount)   , sq_len_15, v_quart_pad) || v_pad_char ||
3767     LPAD(to_char( p_tds_amount, v_format_amount)   , sq_len_15, v_quart_pad) || v_pad_char ||
3768     LPAD(NVL(p_last_total_depositAmt, v_quart_numfill) , sq_len_2, v_quart_pad) || v_pad_char ||
3769     LPAD(to_char( p_total_deposit, v_format_amount)    , sq_len_15, v_quart_pad) || v_pad_char ||
3770     LPAD(to_char( p_tds_income_tax, v_format_amount)   , sq_len_15, v_quart_pad) || v_pad_char ||
3771     LPAD(to_char( p_tds_surcharge, v_format_amount)    , sq_len_15, v_quart_pad) || v_pad_char ||
3772     LPAD(to_char( p_tds_cess, v_format_amount)         , sq_len_15, v_quart_pad) || v_pad_char ||
3773     LPAD(to_char( p_total_income_tds, v_format_amount) , sq_len_15, v_quart_pad) || v_pad_char ||
3774     LPAD(to_char( p_tds_interest_amt, v_format_amount) , sq_len_15, v_quart_pad) || v_pad_char ||
3775     LPAD(to_char( p_tds_other_amt, v_format_amount)    , sq_len_15, v_quart_pad) || v_pad_char ||
3776     LPAD(NVL(p_check_number,v_quart_numfill ) , sq_len_15, v_quart_pad) || v_pad_char ||
3777     LPAD(NVL(p_book_entry,v_q_null_filler )   , sq_len_1, v_quart_pad) || v_pad_char ||
3778     LPAD(NVL(p_remarks,v_q_null_filler )     , sq_len_14, v_quart_pad) || v_pad_char ||
3779     LPAD(NVL(p_ch_recHash,v_q_noval_filler )  , sq_len_2, v_quart_pad)
3780     );
3781   END IF ;
3782 END create_quart_challan_dtl;
3783 
3784 
3785 PROCEDURE create_quart_deductee_dtl(
3786   p_line_number IN NUMBER,
3787   p_record_type IN VARCHAR2,
3788   p_batch_number IN NUMBER,
3789   p_dh_challan_recNo IN NUMBER,
3790   p_deductee_slno IN NUMBER,
3791   p_dh_mode IN VARCHAR2,
3792   p_emp_serial_no IN VARCHAR2,
3793   p_deductee_code IN VARCHAR2,
3794   p_last_emp_pan IN VARCHAR2,
3795   p_deductee_pan IN VARCHAR2,
3796   p_last_emp_pan_refno IN VARCHAR2,
3797   p_deductee_pan_refno IN VARCHAR2,
3798   p_vendor_name IN VARCHAR2,
3799   p_deductee_tds_income_tax IN NUMBER,
3800   p_deductee_tds_surcharge IN NUMBER,
3801   p_deductee_tds_cess IN NUMBER,
3802   p_deductee_total_tax_deducted IN NUMBER,
3803   p_last_total_tax_deducted IN VARCHAR2,
3804   p_deductee_total_tax_deposit IN NUMBER,
3805   p_last_total_tax_deposit IN VARCHAR2,
3806   p_total_purchase IN VARCHAR2,
3807   p_base_taxabale_amount IN NUMBER,
3808   p_gl_date IN DATE,
3809   p_tds_invoice_date IN DATE,
3810   p_deposit_date IN VARCHAR2,
3811   p_tds_tax_rate IN NUMBER,
3812   p_grossingUp_ind IN VARCHAR2,
3813   p_book_ent_oth IN VARCHAR2,
3814   p_certificate_issue_date IN VARCHAR2,
3815   p_remarks1 IN VARCHAR2,
3816   p_remarks2 IN VARCHAR2,
3817   p_remarks3 IN VARCHAR2,
3818   p_dh_recHash  IN VARCHAR2,
3819   p_generate_headers IN VARCHAR2
3823   IF p_generate_headers = 'N' THEN
3820 )
3821 IS
3822 BEGIN
3824     UTL_FILE.PUT_LINE( v_filehandle,
3825     p_line_number                                             || v_delimeter  ||
3826     p_record_type                                             || v_delimeter  ||
3827     p_batch_number                                            || v_delimeter  ||
3828     p_dh_challan_recNo                                        || v_delimeter  ||
3829     p_deductee_slno                                           || v_delimeter  ||
3830     p_dh_mode                                                 || v_delimeter  ||
3831     p_emp_serial_no                                           || v_delimeter  ||
3832     p_deductee_code                                           || v_delimeter  ||
3833     p_last_emp_pan                                            || v_delimeter  ||
3834     p_deductee_pan                                            || v_delimeter  ||
3835     p_last_emp_pan_refno                                      || v_delimeter  ||
3836     p_deductee_pan_refno                                      || v_delimeter  ||
3837     p_vendor_name                                             || v_delimeter  ||
3838     to_char( p_deductee_tds_income_tax, v_format_amount)      || v_delimeter  ||
3839     to_char( p_deductee_tds_surcharge, v_format_amount)       || v_delimeter  ||
3840     to_char( p_deductee_tds_cess, v_format_amount)            || v_delimeter  ||
3841     to_char( p_deductee_total_tax_deducted, v_format_amount)  || v_delimeter  ||
3842     p_last_total_tax_deducted                                 || v_delimeter  ||
3843     to_char( p_deductee_total_tax_deposit, v_format_amount)   || v_delimeter  ||
3844     p_last_total_tax_deposit                                  || v_delimeter  ||
3845     p_total_purchase                                          || v_delimeter  ||
3846     to_char( p_base_taxabale_amount, v_format_amount)         || v_delimeter  ||
3847     to_char(p_gl_date,'ddmmyyyy')                             || v_delimeter  ||
3848     to_char(p_tds_invoice_date,'ddmmyyyy')                    || v_delimeter  ||
3849     p_deposit_date                                            || v_delimeter  ||
3850     -- Bug 6070014. Added by csahoo.
3851     -- Changed the hardcoded value to assigned value.
3852     to_char(p_tds_tax_rate,v_format_rate)                       || v_delimeter  ||
3853     p_grossingUp_ind                                          || v_delimeter  ||
3854     p_book_ent_oth                                            || v_delimeter  ||
3855     p_certificate_issue_date                                  || v_delimeter  ||
3856     p_remarks1                                                || v_delimeter  ||
3857     p_remarks2                                                || v_delimeter  ||
3858     p_remarks3                                                || v_delimeter  ||
3859     p_dh_recHash
3860         );
3861   ELSE
3862     UTL_FILE.PUT_LINE( v_filehandle,
3863     LPAD(p_line_number  , sq_len_9, v_quart_pad) || v_pad_char ||
3864     LPAD(p_record_type  , sq_len_2, v_quart_pad) || v_pad_char ||
3865     LPAD(p_batch_number  , sq_len_9, v_quart_pad) || v_pad_char ||
3866     LPAD(p_dh_challan_recNo  , sq_len_9, v_quart_pad) || v_pad_char ||
3867     LPAD(p_deductee_slno  , sq_len_9, v_quart_pad) || v_pad_char ||
3868     LPAD(p_dh_mode  , sq_len_1, v_quart_pad) || v_pad_char ||
3869     LPAD(NVL(p_emp_serial_no,v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3870     LPAD(p_deductee_code  , sq_len_1, v_quart_pad) || v_pad_char ||
3871     LPAD(NVL(p_last_emp_pan, v_q_noval_filler), sq_len_2, v_quart_pad) || v_pad_char ||
3872     LPAD(p_deductee_pan  , sq_len_10, v_quart_pad) || v_pad_char ||
3873     LPAD(NVL(p_last_emp_pan_refno,v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3874     LPAD(NVL(p_deductee_pan_refno,v_q_null_filler)  , sq_len_10, v_quart_pad) || v_pad_char ||
3875     LPAD(NVL(p_vendor_name, v_q_null_filler) , sq_len_75, v_quart_pad) || v_pad_char ||
3876     LPAD(to_char( p_deductee_tds_income_tax, v_format_amount)    , sq_len_15, v_quart_pad) || v_pad_char ||
3877     LPAD(to_char( p_deductee_tds_surcharge, v_format_amount)  , sq_len_15, v_quart_pad) || v_pad_char ||
3878     LPAD(to_char( p_deductee_tds_cess, v_format_amount)  , sq_len_15, v_quart_pad) || v_pad_char ||
3879     LPAD(to_char( p_deductee_total_tax_deducted, v_format_amount)   , sq_len_15, v_quart_pad) || v_pad_char ||
3880     LPAD(NVL(p_last_total_tax_deducted, v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3881     LPAD(to_char( p_deductee_total_tax_deposit, v_format_amount) , sq_len_15, v_quart_pad) || v_pad_char ||
3882     LPAD(NVL(p_last_total_tax_deposit, v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3883     LPAD(NVL(p_total_purchase, v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3884     LPAD(to_char( p_base_taxabale_amount, v_format_amount) , sq_len_15, v_quart_pad) || v_pad_char ||
3885     LPAD(to_char(p_gl_date,'ddmmyyyy')  , sq_len_8, v_quart_pad) || v_pad_char ||
3886     LPAD(NVL(to_char(p_tds_invoice_date,'ddmmyyyy'),G_DATE_DUMMY) , sq_len_8, v_quart_pad) || v_pad_char ||  -- change later
3887     LPAD(NVL(p_deposit_date, v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3888     LPAD( to_char(p_tds_tax_rate,v_format_rate), sq_len_7, v_quart_pad) || v_pad_char ||
3889     LPAD(NVL(p_grossingUp_ind, v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3890     LPAD(p_book_ent_oth  , sq_len_1, v_quart_pad) || v_pad_char ||
3891     LPAD(NVL(p_certificate_issue_date,v_q_noval_filler)  , sq_len_2, v_quart_pad) || v_pad_char ||
3892     LPAD(NVL(p_remarks1,v_q_null_filler)  , sq_len_1, v_quart_pad) || v_pad_char ||
3893     LPAD(NVL(p_remarks2,v_q_noval_filler)  , sq_len_75, v_quart_pad) || v_pad_char ||
3894     LPAD(NVL(p_remarks3,v_q_noval_filler)  , sq_len_14, v_quart_pad) || v_pad_char ||
3895     LPAD(NVL(p_dh_recHash,v_q_noval_filler) , sq_len_2, v_quart_pad)
3896         );
3897   END IF ;
3898 END create_quart_deductee_dtl;
3899 
3900 -- Validation related Procedures.
3901 
3902 PROCEDURE validate_file_header
3903 ( p_line_number         IN NUMBER ,
3904   p_record_type         IN VARCHAR2,
3905   p_quartfile_type      IN VARCHAR2,
3909   p_uploader_type       IN VARCHAR2,
3906   p_upload_type         IN VARCHAR2,
3907   p_file_creation_date  IN DATE,
3908   p_file_sequence_number IN NUMBER,
3910   p_deductor_tan        IN VARCHAR2,
3911   p_number_of_batches   IN NUMBER,
3912   p_ret_prep_util       IN VARCHAR2, /*Bug 8880543 - Added Return Preperation Utility*/
3913   p_period              IN VARCHAR2,
3914   p_challan_start_date  IN DATE,
3915   p_challan_end_date    IN DATE,
3916   p_fin_year            IN NUMBER,
3917   p_return_code         OUT NOCOPY VARCHAR2,
3918   p_return_message      OUT NOCOPY VARCHAR2
3919 )
3920 IS
3921    lv_q1_start_date   VARCHAR2(11) ;
3922    lv_q1_end_date     VARCHAR2(11) ;
3923    lv_q2_start_date   VARCHAR2(11) ;
3924    lv_q2_end_date     VARCHAR2(11) ;
3925    lv_q3_start_date   VARCHAR2(11) ;
3926    lv_q3_end_date     VARCHAR2(11) ;
3927    lv_q4_start_date   VARCHAR2(11) ;
3928    lv_q4_end_date     VARCHAR2(11) ;
3929    ln_fin_year        NUMBER ;
3930    lv_date_format     VARCHAR2(11);
3931 BEGIN
3932 
3933      IF p_line_number IS NULL THEN
3934        p_return_message := p_return_message ||  ' Line Number should not be null. '   ;
3935        IF lv_action <> 'V' THEN
3936           goto  end_of_procedure  ;
3937        END IF ;
3938      END IF;
3939      IF p_record_type IS NULL THEN
3940        p_return_message := p_return_message ||  ' Record Type is null. '     ;
3941        IF lv_action <> 'V' THEN
3942           goto  end_of_procedure  ;
3943        END IF ;
3944      END IF;
3945      IF p_quartfile_type IS NULL THEN
3946        p_return_message := p_return_message ||  ' File Type is null. '   ;
3947        IF lv_action <> 'V' THEN
3948           goto  end_of_procedure  ;
3949        END IF ;
3950      END IF;
3951      IF p_upload_type IS NULL THEN
3952        p_return_message := p_return_message ||  ' Upload Type is null. '    ;
3953        IF lv_action <> 'V' THEN
3954           goto  end_of_procedure  ;
3955        END IF ;
3956      END IF;
3957      IF p_file_creation_date IS NULL THEN
3958        p_return_message := p_return_message ||  ' File Creation Date is null. '    ;
3959        IF lv_action <> 'V' THEN
3960           goto  end_of_procedure  ;
3961        END IF ;
3962      END IF;
3963      IF p_file_sequence_number IS NULL THEN
3964        p_return_message := p_return_message ||  ' File Sequence No is null. '  ;
3965        IF lv_action <> 'V' THEN
3966           goto  end_of_procedure  ;
3967        END IF ;
3968      END IF;
3969      IF p_uploader_type IS NULL THEN
3970        p_return_message := p_return_message ||  ' Upload Type is null. '   ;
3971        IF lv_action <> 'V' THEN
3972           goto  end_of_procedure  ;
3973        END IF ;
3974      END IF;
3975      IF p_deductor_tan IS NULL THEN
3976        p_return_message := p_return_message ||  ' Deductor TAN is null. '   ;
3977        IF lv_action <> 'V' THEN
3978           goto  end_of_procedure  ;
3979        END IF ;
3980      END IF;
3981      IF p_number_of_batches IS NULL THEN
3982        p_return_message := p_return_message ||  ' Batch Count is null. '   ;
3983        IF lv_action <> 'V' THEN
3984           goto  end_of_procedure  ;
3985        END IF ;
3986      END IF;
3987      /*Bug 8880543 - Added Return Preperation Utility*/
3988      IF p_ret_prep_util IS NULL THEN
3989        p_return_message := p_return_message ||  ' Return Preperation Utility is null. '   ;
3990        IF lv_action <> 'V' THEN
3991           goto  end_of_procedure  ;
3992        END IF ;
3993      END IF;
3994 
3995 
3996    IF p_period = 'Q1' THEN
3997       lv_q1_start_date := '01-APR-' || p_fin_year ;
3998       lv_q1_end_date   := '30-JUN-' || p_fin_year ;
3999       lv_date_format := 'DD-MON-YYYY' ;
4000 
4001       IF not ( p_challan_start_date >=  to_date(lv_q1_start_date,lv_date_format) and p_challan_end_date <=  to_date(lv_q1_end_date,lv_date_format) ) THEN
4002        p_return_message := ' The given Challan Start and end dates do not fall under the specified Quarter and Year. ' ;
4003        goto  end_of_procedure  ;
4004       END IF ;
4005     ELSIF p_period = 'Q2' THEN
4006       lv_q2_start_date := '01-JUL-' || p_fin_year;
4007       lv_q2_end_date   := '30-SEP-' || p_fin_year;
4008 
4009       IF not ( p_challan_start_date >=  to_date(lv_q2_start_date,lv_date_format)  and p_challan_end_date <=  to_date(lv_q2_end_date,lv_date_format) ) THEN
4010          p_return_message := ' The given Challan Start and end dates do not fall under the specified Quarter and Year. '  ;
4011          goto  end_of_procedure  ;
4012       END IF ;
4013     ELSIF p_period = 'Q3' THEN
4014       lv_q3_start_date := '01-OCT-' || p_fin_year;
4015       lv_q3_end_date   := '31-DEC-' || p_fin_year;
4016 
4017       IF not ( p_challan_start_date >=  to_date(lv_q3_start_date,lv_date_format) and p_challan_end_date  <=  to_date(lv_q3_end_date,lv_date_format) ) THEN
4018          p_return_message := ' The given Challan Start and end dates do not fall under the specified Quarter and Year. '  ;
4019          goto  end_of_procedure  ;
4020       END IF ;
4021     ELSIF p_period = 'Q4' THEN
4022       ln_fin_year := p_fin_year + 1 ;
4023       lv_q4_start_date := '01-JAN-' || ln_fin_year;
4024       lv_q4_end_date   := '31-MAR-' || ln_fin_year;
4025 
4026       IF not ( p_challan_start_date >=  to_date(lv_q4_start_date,lv_date_format) and p_challan_end_date <= to_date(lv_q4_end_date,lv_date_format)  ) THEN
4027          p_return_message := ' The given Challan Start and end dates do not fall under the specified Quarter and Year. '  ;
4028          goto  end_of_procedure  ;
4029     END IF ;
4030   END IF ;
4031 
4032     IF lv_action = 'V' THEN
4033       goto  end_of_procedure  ;
4034          END IF ;
4035 
4036    <<end_of_procedure>>
4037    if p_return_message is not null then
4038      p_return_code := 'E';
4042 END validate_file_header;
4039      p_return_message := 'File Header Error - ' || 'Line No : ' || p_line_number || '. ' ||  p_return_message ;
4040         end if;
4041 
4043 
4044 PROCEDURE validate_batch_header
4045  ( p_line_number                  IN  NUMBER,
4046    p_record_type                  IN  VARCHAR2,
4047    p_batch_number                 IN  NUMBER,
4048    p_challan_cnt                  IN  NUMBER,
4049    p_quart_form_number            IN  VARCHAR2,
4050    p_deductor_tan                 IN  VARCHAR2,
4051    p_assessment_year              IN  NUMBER,
4052    p_financial_year               IN  NUMBER,
4053    p_deductor_name                IN  VARCHAR2,
4054    p_deductor_pan                 IN  VARCHAR2, /*Bug 8880543 - Added for Validating PAN Number*/
4055    p_tan_address1                 IN  VARCHAR2,
4056    p_tan_state_code               IN  NUMBER,
4057    p_tan_pin                      IN  NUMBER,
4058    p_deductor_type                IN  VARCHAR2, /*Bug 8880543 - Modified Deductor Status to Deductor Type*/
4059    p_addrChangedSinceLastReturn   IN  VARCHAR2,
4060    p_personNameRespForDedection   IN  VARCHAR2,
4061    p_personDesgnRespForDedection  IN  VARCHAR2,
4062    p_RespPers_flat_no IN VARCHAR2 , -- Bug 6030953
4063    p_RespPers_prem_bldg IN VARCHAR2 , -- Bug 6030953
4064    p_RespPers_rd_st_lane IN VARCHAR2 , -- Bug 6030953
4065    p_RespPers_area_loc IN VARCHAR2 , -- Bug 6030953
4066    p_RespPers_tn_cty_dt IN VARCHAR2 , -- Bug 6030953
4067    p_RespPersState                IN  NUMBER,
4068    p_RespPersPin                  IN  NUMBER,
4069    p_RespPers_tel_no IN VARCHAR2 , -- Bug 6030953
4070    p_RespPers_email IN VARCHAR2 , -- Bug 6030953
4071    p_RespPersAddrChange           IN  VARCHAR2,
4072    p_totTaxDeductedAsPerDeductee  IN  NUMBER,
4073    p_ao_approval                  IN  VARCHAR2,
4074    /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
4075    p_state_name                   IN  VARCHAR2,
4076    p_pao_code                     IN  VARCHAR2,
4077    p_ddo_code                     IN  VARCHAR2,
4078    p_ministry_name                IN  VARCHAR2,
4079    p_pao_registration_no          IN  NUMBER,
4080    p_ddo_registration_no          IN  VARCHAR2,
4081    /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
4082    p_RespPerson_mobile     IN  VARCHAR2,
4083           p_deductor_phone_no       IN  VARCHAR2,
4084           p_resp_person_phone_no    IN  VARCHAR2,/*ETDS FVU3.1 Bug 11896260*/
4085    p_return_code                  OUT NOCOPY VARCHAR2,
4086    p_return_message               OUT NOCOPY VARCHAR2
4087  )
4088  IS
4089  BEGIN
4090 
4091     IF p_line_number   IS NULL THEN
4092      p_return_message := p_return_message ||  ' Line Number should not be null. ' ;
4093      IF lv_action <> 'V' THEN
4094        goto  end_of_procedure  ;
4095      END IF ;
4096     END IF ;
4097     IF p_record_type   IS NULL THEN
4098      p_return_message := p_return_message ||  ' Record Type is null. '  ;
4099      IF lv_action <> 'V' THEN
4100        goto  end_of_procedure  ;
4101      END IF ;
4102     END IF ;
4103     IF p_batch_number  IS NULL THEN
4104      p_return_message := p_return_message ||  ' Batch Number is null. ' ;
4105      IF lv_action <> 'V' THEN
4106        goto  end_of_procedure  ;
4107      END IF ;
4108     END IF ;
4109     IF p_challan_cnt IS NULL THEN
4110      p_return_message := p_return_message ||  ' Record Count is null. ' ;
4111      IF lv_action <> 'V' THEN
4112        goto  end_of_procedure  ;
4113      END IF ;
4114     END IF ;
4115     IF p_quart_form_number  IS NULL THEN
4116      p_return_message := p_return_message ||  ' Form Number is null. '  ;
4117      IF lv_action <> 'V' THEN
4118        goto  end_of_procedure  ;
4119      END IF ;
4120     END IF ;
4121     IF p_deductor_tan   IS NULL THEN
4122      p_return_message := p_return_message ||  ' Deductor TAN is null. ' ;
4123      IF lv_action <> 'V' THEN
4124        goto  end_of_procedure  ;
4125      END IF ;
4126     END IF ;
4127     IF p_assessment_year IS NULL THEN
4128      p_return_message := p_return_message ||  ' Assessment Year is null. '  ;
4129      IF lv_action <> 'V' THEN
4130        goto  end_of_procedure  ;
4131      END IF ;
4132     END IF ;
4133     IF p_financial_year IS NULL THEN
4134      p_return_message := p_return_message ||  ' Financial Year is null. ' ;
4135      IF lv_action <> 'V' THEN
4136        goto  end_of_procedure  ;
4137      END IF ;
4138     END IF ;
4139     IF p_deductor_name IS NULL THEN
4140      p_return_message := p_return_message ||  ' Deductor Name is null. '  ;
4141      IF lv_action <> 'V' THEN
4142        goto  end_of_procedure  ;
4143      END IF ;
4144     END IF ;
4145     /*Bug 8880543 - PAN Number Validation - Start*/
4146     IF p_deductor_pan IS NULL THEN
4147      p_return_message := p_return_message ||  ' Deductor PAN is null. '  ;
4148      IF lv_action <> 'V' THEN
4149        goto  end_of_procedure  ;
4150      END IF ;
4151     ELSE
4152      IF (validate_alpha_numeric(p_deductor_pan, length(p_deductor_pan)) = 'INVALID') THEN
4153          p_return_message := p_return_message ||  ' PAN format incorrect. The first five must be alphabets, followed by four numbers, and then followed by an alphabet.'  ;
4154          IF lv_action <> 'V' THEN
4155            goto  end_of_procedure  ;
4156          END IF ;
4157      END IF;
4158     END IF ;
4159     /*Bug 8880543 - PAN Number Validation - End*/
4160     IF p_tan_address1  IS NULL THEN
4161      p_return_message := p_return_message ||  ' Deductor Address is null. ' ;
4162      IF lv_action <> 'V' THEN
4163        goto  end_of_procedure  ;
4164      END IF ;
4165     END IF ;
4166     IF p_tan_state_code   IS NULL THEN
4167      p_return_message := p_return_message ||  ' Deductor State is null. '  ;
4168      IF lv_action <> 'V' THEN
4172     IF p_tan_pin    IS NULL THEN
4169        goto  end_of_procedure  ;
4170      END IF ;
4171     END IF ;
4173      p_return_message := p_return_message ||  ' Deductor Pin is null. '  ;
4174      IF lv_action <> 'V' THEN
4175        goto  end_of_procedure  ;
4176      END IF ;
4177     END IF ;
4178     IF p_deductor_type IS NULL THEN
4179      p_return_message := p_return_message ||  ' Deductor Type is null. '  ;
4180      IF lv_action <> 'V' THEN
4181        goto  end_of_procedure  ;
4182      END IF ;
4183     END IF ;
4184     IF p_addrChangedSinceLastReturn IS NULL THEN
4185      p_return_message := p_return_message ||  ' Field Deductor Addredd Changed Since last year is null. ' ;
4186      IF lv_action <> 'V' THEN
4187        goto  end_of_procedure  ;
4188      END IF ;
4189     END IF ;
4190     IF p_personNameRespForDedection IS NULL THEN
4191      p_return_message := p_return_message ||  ' Person Responsible For Deduction is null. '  ;
4192      IF lv_action <> 'V' THEN
4193        goto  end_of_procedure  ;
4194      END IF ;
4195     END IF ;
4196     IF p_personDesgnRespForDedection IS NULL THEN
4197      p_return_message := p_return_message ||  ' Designation of Responsible Person  is null. '  ;
4201     END IF ;
4198      IF lv_action <> 'V' THEN
4199        goto  end_of_procedure  ;
4200      END IF ;
4202       -- Bug 6030953. Added by Lakshmi Gopalsami
4203        IF p_RespPers_flat_no   IS NULL THEN
4204          p_return_message := p_return_message ||  ' Flat No. of Responsible Person is null. '  ;
4205          IF lv_action <> 'V' THEN
4206            goto  end_of_procedure  ;
4207          END IF ;
4208        END IF ;
4209 
4210        IF p_RespPers_prem_bldg   IS NULL THEN
4211          p_return_message := p_return_message ||  ' Name of the premises/bldg of Responsible Person is null. '  ;
4212          IF lv_action <> 'V' THEN
4213            goto  end_of_procedure  ;
4214          END IF ;
4215        END IF ;
4216 
4217        IF p_RespPers_rd_st_lane   IS NULL THEN
4218          p_return_message := p_return_message ||  ' Road/Street/Lane of Responsible Person is null. '  ;
4219          IF lv_action <> 'V' THEN
4220            goto  end_of_procedure  ;
4221          END IF ;
4222        END IF ;
4223 
4224        IF p_RespPers_area_loc   IS NULL THEN
4225          p_return_message := p_return_message ||  ' Area/Location of Responsible Person is null. '  ;
4226          IF lv_action <> 'V' THEN
4227            goto  end_of_procedure  ;
4228          END IF ;
4229        END IF ;
4230 
4231        IF p_RespPers_tn_cty_dt   IS NULL THEN
4232          p_return_message := p_return_message ||  ' Town/City/District of Responsible Person is null. '  ;
4233          IF lv_action <> 'V' THEN
4234            goto  end_of_procedure  ;
4235          END IF ;
4236        END IF ;
4237      -- End for bug 6030953
4238 
4239     IF p_RespPersState    IS NULL THEN
4240      p_return_message := p_return_message ||  ' State of Responsible Person is null. '  ;
4241      IF lv_action <> 'V' THEN
4242        goto  end_of_procedure  ;
4243      END IF ;
4244     END IF ;
4245     IF p_RespPersPin   IS NULL THEN
4246      p_return_message := p_return_message ||  ' Pin  of Responsible Person is null. '  ;
4247      IF lv_action <> 'V' THEN
4248        goto  end_of_procedure  ;
4249      END IF ;
4250     END IF ;
4251     IF p_RespPersAddrChange IS NULL THEN
4252      p_return_message := p_return_message ||  ' Field ''Address of Responsible Person has Changed'' is null. '  ;
4253      IF lv_action <> 'V' THEN
4254        goto  end_of_procedure  ;
4255      END IF ;
4256     END IF ;
4257     /*Bug 10408793 - It is no more required to validate that Challan amount is not NULL as for Transporters challan amount can be NULL*/
4258     /*
4259     IF p_totTaxDeductedAsPerDeductee IS NULL THEN
4260      p_return_message := p_return_message ||  ' Total Deposit Amount as per Challan is null. '  ;
4261      IF lv_action <> 'V' THEN
4262        goto  end_of_procedure  ;
4263      END IF ;
4264     END IF ;
4265     */
4266     IF p_ao_approval  IS NULL THEN
4267      p_return_message := p_return_message ||  ' AO Approval is null. '  ;
4268      IF lv_action <> 'V' THEN
4269        goto  end_of_procedure  ;
4270      END IF ;
4271     END IF ;
4272 
4273     /*Bug 8880543 - Validation for eTDs/eTCS FVU changes - Start*/
4274 
4275     IF p_deductor_type in ('S', 'E', 'H', 'N') THEN
4276         IF p_state_name IS NULL THEN
4277             p_return_message := p_return_message ||  ' State is required when Deductor Type is S/E/H/N. '  ;
4278             IF lv_action <> 'V' THEN
4279                 goto  end_of_procedure  ;
4283 
4280             END IF ;
4281         END IF ;
4282     END IF;
4284     IF p_deductor_type in ('A') THEN
4285         IF p_pao_code IS NULL THEN
4286             p_return_message := p_return_message ||  ' PAO Code is required when Deductor Type is A. '  ;
4287             IF lv_action <> 'V' THEN
4288                 goto  end_of_procedure  ;
4289             END IF ;
4290         END IF ;
4291         IF p_ddo_code IS NULL THEN
4292             p_return_message := p_return_message ||  ' DDO Code is required when Deductor Type is A. '  ;
4293             IF lv_action <> 'V' THEN
4294                 goto  end_of_procedure  ;
4295             END IF ;
4296         END IF ;
4297     END IF;
4298 
4299     IF p_deductor_type in ('A', 'D', 'G') THEN
4300         IF p_ministry_name IS NULL THEN
4301             p_return_message := p_return_message ||  ' Ministry Name is required when Deductor Type is A/D/G. '  ;
4302             IF lv_action <> 'V' THEN
4303                 goto  end_of_procedure  ;
4304             END IF ;
4305         END IF ;
4306     END IF;
4307 
4308 /*eTDS FVU3.1 Bug 11896260 - Start*/
4309   If p_deductor_type in ('K','M', 'P', 'T', 'J', 'B', 'Q', 'F') and p_RespPerson_mobile IS NULL then
4310      p_return_message := p_return_message ||'Responsible person Mobile No. must be provided for Deductor Type ' || p_deductor_type;
4311    IF lv_action <> 'V' THEN
4312         goto  end_of_procedure  ;
4313     END IF ;
4314        ELSIF p_RespPerson_mobile IS NULL AND
4315           p_deductor_phone_no IS NULL AND
4316           p_resp_person_phone_no IS NULL
4317        THEN
4318            p_return_message := p_return_message ||  ' Either mobile no. should be provided or Telephone no. and STD code of deductor or responsible person should be provided. ';
4319            IF lv_action <> 'V' THEN
4320                goto  end_of_procedure  ;
4321            END IF ;
4322        END IF;
4323        /*eTDS FVU3.1 Bug 11896260 - End*/
4324     IF lv_action = 'V' THEN
4325      goto  end_of_procedure  ;
4326     END IF ;
4327 
4328     <<end_of_procedure>>
4329     IF p_return_message IS NOT NULL THEN
4330       p_return_code := 'E';
4331       p_return_message := 'Batch Header Error - ' || 'Line No : ' || p_line_number || '. ' || p_return_message ;
4332     END IF;
4333 
4334  END validate_batch_header;
4335 
4336 PROCEDURE validate_challan_detail
4337 (p_line_number           IN  NUMBER ,
4338 p_record_type           IN  VARCHAR2,
4339 p_batch_number          IN  NUMBER,
4340 p_challan_dtl_slno      IN  NUMBER,
4341 p_deductee_cnt          IN  NUMBER,
4342 p_nil_challan_indicat   IN  VARCHAR2,
4343 p_tds_section           IN  VARCHAR2,
4344 p_amt_of_tds            IN  NUMBER,
4345 p_amt_of_surcharge      IN  NUMBER,
4346 p_amt_of_cess           IN  NUMBER,
4347 p_amt_of_oth            IN  NUMBER,
4348 p_tds_amount            IN  NUMBER,
4349 p_total_income_tds      IN  NUMBER,
4350 p_challan_num           IN  VARCHAR2,
4351 p_bank_branch_code      IN  VARCHAR2,
4352 p_challan_no            IN  VARCHAR2,
4353 p_challan_Date          IN  DATE,
4354 p_check_number          IN  NUMBER,
4355 p_tds_vendor_classification IN VARCHAR2,/*Bug 10315928*/
4356 p_return_code           OUT NOCOPY VARCHAR2,
4357 p_return_message        OUT NOCOPY VARCHAR2
4358 )
4359 IS
4360 BEGIN
4364            goto  end_of_procedure  ;
4361  IF p_line_number               IS NULL THEN
4362         p_return_message := p_return_message ||     ' Line number should not be null. '   ;
4363         IF lv_action <> 'V' THEN
4365          END IF ;
4366       END IF ;
4367       IF p_record_type               IS NULL THEN
4368         p_return_message := p_return_message ||     ' Record Type is null. '   ;
4369         IF lv_action <> 'V' THEN
4370            goto  end_of_procedure  ;
4371          END IF ;
4372       END IF ;
4373       IF p_batch_number              IS NULL THEN
4374         p_return_message := p_return_message ||     ' Batch Number is null. '   ;
4375         IF lv_action <> 'V' THEN
4376            goto  end_of_procedure  ;
4377          END IF ;
4378       END IF ;
4379       IF p_challan_dtl_slno          IS NULL THEN
4380         p_return_message := p_return_message ||     ' Challan Record Number is null. '   ;
4381         IF lv_action <> 'V' THEN
4382            goto  end_of_procedure  ;
4383          END IF ;
4384       END IF ;
4385       IF p_deductee_cnt              IS NULL THEN
4386         p_return_message := p_return_message ||     ' Deductee Count is null  . '   ;
4387         IF lv_action <> 'V' THEN
4388            goto  end_of_procedure  ;
4389          END IF ;
4390       END IF ;
4391       IF p_nil_challan_indicat       IS NULL THEN
4392         p_return_message := p_return_message ||     ' NIL Challan Indicator is null  . '   ;
4393         IF lv_action <> 'V' THEN
4394            goto  end_of_procedure  ;
4395          END IF ;
4396       END IF ;
4397       IF p_tds_section               IS NULL THEN
4398         p_return_message := p_return_message ||     ' TDS Section is null  . '   ;
4402       END IF ;
4399         IF lv_action <> 'V' THEN
4400            goto  end_of_procedure  ;
4401          END IF ;
4403  --IF(p_tds_vendor_classification is null and nvl(p_amt_of_tds ,1) > 0) THEN /* Bug 10315928*/ /* 13514846 */
4404    IF (nvl(p_nil_challan_indicat, 'N') <> 'Y' ) then
4405       IF p_amt_of_tds                IS NULL THEN
4406         p_return_message := p_return_message ||     ' TDS Amount is null  . '   ;
4407         IF lv_action <> 'V' THEN
4408            goto  end_of_procedure  ;
4409          END IF ;
4410       END IF ;
4411       IF p_amt_of_surcharge          IS NULL THEN
4412         p_return_message := p_return_message ||     ' TDS Surcharge Amount is null  . '   ;
4413         IF lv_action <> 'V' THEN
4414            goto  end_of_procedure  ;
4415          END IF ;
4416       END IF ;
4417       IF p_amt_of_cess IS NULL THEN
4418         p_return_message := p_return_message ||     ' TDS Cess Amount is null  . '   ;
4419         IF lv_action <> 'V' THEN
4420            goto  end_of_procedure  ;
4421          END IF ;
4422       END IF ;
4423       IF p_amt_of_oth                IS NULL THEN
4424         p_return_message := p_return_message ||     ' TDS Other Amount is null  . '   ;
4425         IF lv_action <> 'V' THEN
4426            goto  end_of_procedure  ;
4427          END IF ;
4428       END IF ;
4429       IF p_tds_amount                IS NULL THEN
4430         p_return_message := p_return_message ||     ' Total TDS Amount is null  . '   ;
4431         IF lv_action <> 'V' THEN
4432            goto  end_of_procedure  ;
4433          END IF ;
4434       END IF ;
4435       IF p_challan_no                IS NULL THEN
4436         p_return_message := p_return_message ||   ' CHallan No is null  . '   ;
4437         IF lv_action <> 'V' THEN
4438            goto  end_of_procedure  ;
4439          END IF ;
4440       END IF ;
4441       IF p_challan_Date                IS NULL THEN
4442         p_return_message := p_return_message ||   ' CHallan Date is null  . '   ;
4443         IF lv_action <> 'V' THEN
4444            goto  end_of_procedure  ;
4445          END IF ;
4446       END IF ;
4447     -- Harshita for Bug 4640996
4448       check_numeric(p_challan_num, 'Check Number : ' || p_check_number  || ' Challan Number is not a Numeric Value', lv_action);
4449       check_numeric(p_bank_branch_code, 'Check Number : ' || p_check_number  || ' Bank Branch Code is not a Numeric Value ', lv_action);
4450 
4451     IF p_total_income_tds          IS NULL THEN
4452         p_return_message := p_return_message ||   ' Total Tax Deposit Amount is null  . '   ;
4453         IF lv_action <> 'V' THEN
4454            goto  end_of_procedure  ;
4455         END IF ;
4456       END IF ;
4457     END IF; /*Bug 10315928*/
4458 
4459 
4460       IF lv_action = 'V' THEN
4461         goto  end_of_procedure  ;
4462       END IF ;
4463 
4464       <<end_of_procedure>>
4465       IF p_return_message IS NOT NULL THEN
4466         p_return_code := 'E';
4467         p_return_message := 'Challan Detail Error - ' || 'Check Number : ' || p_check_number || '. ' || p_return_message ;
4468       END IF;
4469 END validate_challan_detail;
4470 
4471 PROCEDURE validate_deductee_detail
4472 ( p_line_number                  IN  NUMBER ,
4473  p_record_type                  IN  VARCHAR2,
4474  p_batch_number                 IN  NUMBER,
4475  p_challan_line_num             IN  NUMBER,
4476  p_deductee_slno                IN  NUMBER,
4477  p_dh_mode                      IN  VARCHAR2,
4478  p_quart_deductee_code          IN  VARCHAR2,
4479  p_deductee_pan                 IN  VARCHAR2,
4480  p_vendor_name                  IN  VARCHAR2,
4481  p_amt_of_tds                   IN  NUMBER,
4482  p_amt_of_surcharge             IN  NUMBER ,
4483  p_amt_of_cess                  IN  NUMBER  ,
4484  p_deductee_total_tax_deducted  IN  NUMBER,
4485  p_base_taxabale_amount         IN  NUMBER,
4486  p_gl_date                      IN  DATE ,
4487  p_book_ent_oth                 IN  VARCHAR2,
4488  p_return_code                  OUT NOCOPY VARCHAR2,
4489  p_return_message               OUT NOCOPY VARCHAR2
4490 )
4491 IS
4492 BEGIN
4493  IF p_line_number  IS NULL THEN
4494        p_return_message := p_return_message ||     '  Line Number should not be null. '  ;
4495        IF lv_action <> 'V' THEN
4496          goto  end_of_procedure  ;
4497        END IF ;
4498       END IF ;
4499       IF p_record_type  IS NULL THEN
4500        p_return_message := p_return_message ||     '  Record Type is null. '  ;
4501        IF lv_action <> 'V' THEN
4502          goto  end_of_procedure  ;
4503        END IF ;
4504       END IF ;
4505       IF p_batch_number IS NULL THEN
4506        p_return_message := p_return_message ||   ' Batch Number is null. '   ;
4507        IF lv_action <> 'V' THEN
4508          goto  end_of_procedure  ;
4509        END IF ;
4510       END IF ;
4511       IF p_challan_line_num   IS NULL THEN
4512        p_return_message := p_return_message ||     '  Challan Record Number is null. '  ;
4513        IF lv_action <> 'V' THEN
4514          goto  end_of_procedure  ;
4515        END IF ;
4516       END IF ;
4520          goto  end_of_procedure  ;
4517       IF p_deductee_slno  IS NULL THEN
4518        p_return_message := p_return_message ||     '  Party Detail Record Number is null. '  ;
4519        IF lv_action <> 'V' THEN
4521        END IF ;
4522       END IF ;
4523       IF p_dh_mode  IS NULL THEN
4524        p_return_message := p_return_message ||     '  Mode is null. '  ;
4525        IF lv_action <> 'V' THEN
4526          goto  end_of_procedure  ;
4527        END IF ;
4528       END IF ;
4529       IF p_quart_deductee_code  IS NULL THEN
4530        p_return_message := p_return_message ||     '  Deductee Party Code is null. '  ;
4531        IF lv_action <> 'V' THEN
4532          goto  end_of_procedure  ;
4533        END IF ;
4534       END IF ;
4535       IF p_deductee_pan IS NULL THEN
4536        p_return_message := p_return_message ||     '  Deductee PAN is null. '  ;
4537        IF lv_action <> 'V' THEN
4538          goto  end_of_procedure  ;
4539        END IF ;
4540       /*Bug 8880543 - Added validation for PAN - Start*/
4541    ELSE
4542        IF (validate_alpha_numeric(p_deductee_pan, length(p_deductee_pan)) = 'INVALID') THEN
4543           p_return_message := p_return_message ||  ' PAN format incorrect. The first five must be alphabets, followed by four numbers, and then followed by an alphabet.'  ;
4544           IF lv_action <> 'V' THEN
4545              goto  end_of_procedure  ;
4546           END IF ;
4547        END IF;
4548       /*Bug 8880543 - Added validation for PAN - End*/
4549       END IF ;
4550       IF p_vendor_name  IS NULL THEN
4551        p_return_message := p_return_message ||     '  Party Name is null. '  ;
4552        IF lv_action <> 'V' THEN
4553          goto  end_of_procedure  ;
4554        END IF ;
4555       END IF ;
4556     /* start -Bug 14330534 */
4557     IF length(p_vendor_name) >75  THEN
4558        p_return_message := p_return_message ||     '  Party Name cannot be greater than 75 characters :' || p_vendor_name ;
4559        IF lv_action <> 'V' THEN
4560          goto  end_of_procedure  ;
4561        END IF ;
4562       END IF ;
4563     /* End -Bug 14330534 */
4564 
4565       IF p_amt_of_tds  IS NULL THEN
4566        p_return_message := p_return_message ||     '  TDS Income Tax for the Period is null. '  ;
4567        IF lv_action <> 'V' THEN
4568          goto  end_of_procedure  ;
4569        END IF ;
4570       END IF ;
4571       IF p_amt_of_surcharge   IS NULL THEN
4572        p_return_message := p_return_message ||     '  TDS Surcharge is null. '  ;
4573        IF lv_action <> 'V' THEN
4574          goto  end_of_procedure  ;
4575        END IF ;
4576       END IF ;
4577       IF p_amt_of_cess   IS NULL THEN
4578        p_return_message := p_return_message ||     '  TDS Cess is null. '  ;
4579        IF lv_action <> 'V' THEN
4580          goto  end_of_procedure  ;
4581        END IF ;
4582       END IF ;
4583       IF p_deductee_total_tax_deducted IS NULL THEN
4584        p_return_message := p_return_message ||     '  Total TDS  is null. '  ;
4585        IF lv_action <> 'V' THEN
4586          goto  end_of_procedure  ;
4587        END IF ;
4588       END IF ;
4589       IF p_base_taxabale_amount IS NULL THEN
4590        p_return_message := p_return_message ||     '  Payment Amount is null. '  ;
4591        IF lv_action <> 'V' THEN
4592          goto  end_of_procedure  ;
4593        END IF ;
4594       END IF ;
4595       IF p_gl_date IS NULL THEN
4596        p_return_message := p_return_message ||     '  Date on which Amount Credited is null. '  ;
4597        IF lv_action <> 'V' THEN
4598          goto  end_of_procedure  ;
4599        END IF ;
4600       END IF ;
4601       IF p_book_ent_oth  IS NULL THEN
4602        p_return_message := p_return_message ||     '  Book/Cash Entry is null. '  ;
4603        IF lv_action <> 'V' THEN
4604          goto  end_of_procedure  ;
4605        END IF ;
4606       END IF ;
4607 
4608        IF lv_action = 'V' THEN
4609          goto  end_of_procedure  ;
4610        END IF ;
4611 
4612       <<end_of_procedure>>
4613       if p_return_message is not null then
4614         p_return_code := 'E';
4615         p_return_message := 'Deductee Detail Error - ' ||  p_return_message ;
4616       end if;
4617 END validate_deductee_detail;
4618 
4619 PROCEDURE check_numeric
4620 (p_variable IN VARCHAR2 ,
4621 p_err      IN VARCHAR2 ,
4622 p_action   IN VARCHAR2
4623 )
4624 IS
4625 ln_check_number NUMBER ;
4626 BEGIN
4627    ln_check_number := to_number( p_variable ) ;
4628     EXCEPTION
4629      WHEN OTHERS THEN
4630       FND_FILE.put_line(FND_FILE.log, 'sql code : ' || SQLCODE );
4631       FND_FILE.put_line(FND_FILE.log, 'Challan Detail Error - ' || '.  ERROR : ' || p_err );
4632 
4633       -- Harshita for Bug 4640996
4634       IF p_action <> 'V' THEN
4635         raise_application_error(-20023, 'Challan Detail Error - ' || '.  ERROR : ' || p_err );
4636       END IF ;
4637 END check_numeric;
4638 
4639 /* Functional Related Procedures */
4640 
4644   --p_legal_entity_id   IN NUMBER,    --commented by csahoo for bug#6158875
4641 PROCEDURE quarterly_returns(
4642   p_err_buf OUT NOCOPY VARCHAR2,
4643   p_ret_code OUT NOCOPY NUMBER,
4645   --p_profile_org_id    IN NUMBER,    --commented by csahoo for bug#6158875
4646   p_tan_number      IN VARCHAR2,
4647   p_fin_year        IN NUMBER,
4648   p_period          IN VARCHAR2,
4649   p_tax_authority_id    IN NUMBER,
4650   p_tax_authority_site_id IN NUMBER,
4651   p_organization_id   IN NUMBER,
4652   p_deductor_addr_org_id IN NUMBER, /*ETDS FVU3.1 Bug 11896260  */
4653   p_deductor_name     IN VARCHAR2,
4654   --p_deductor_email    IN VARCHAR2, /* Bug#10315928 */
4655   --p_deductor_stdcode IN VARCHAR2, /* Bug#10315928 */
4656   --p_deductor_phno    IN VARCHAR2, /* Bug#10315928 */
4657   p_deductor_state    IN VARCHAR2,
4658   p_addrChangedSinceLastRet IN VARCHAR2,
4659   --p_deductor_status   IN VARCHAR2,  /*Bug 8880543 - Commented for eTDS/eTCS FVU Changes*/
4660   p_persRespForDeduction  IN VARCHAR2,
4661   p_desgOfPersResponsible IN VARCHAR2,
4662   p_RespPers_flat_no IN VARCHAR2 , -- Bug 6030953
4663   p_RespPers_prem_bldg IN VARCHAR2 , -- Bug 6030953
4664   p_RespPers_rd_st_lane IN VARCHAR2 , -- Bug 6030953
4665   p_RespPers_area_loc IN VARCHAR2 , -- Bug 6030953
4666   p_RespPers_tn_cty_dt IN VARCHAR2 , -- Bug 6030953
4667   p_RespPersState IN VARCHAR2 ,
4668   p_RespPersPin IN NUMBER ,
4669   --p_RespPersStdCode IN VARCHAR2, /* Bug#10315928 */
4670   --p_RespPers_tel_no IN VARCHAR2 , -- Bug 6030953
4671   --p_RespPersMobileNo IN VARCHAR2, /* Bug#10315928 */
4672   --p_RespPers_email IN VARCHAR2 , -- Bug 6030953
4673   p_RespPersAddrChange IN VARCHAR2,
4674   p_challan_Start_Date  IN VARCHAR2,
4675   p_challan_End_Date    IN VARCHAR2,
4676   p_pro_rcpt_num_org_ret IN NUMBER,
4680   p_include_list    IN VARCHAR2,
4677   p_file_path       IN VARCHAR2,
4678   p_filename        IN VARCHAR2,
4679   p_action          IN VARCHAR2 DEFAULT NULL,
4681   p_exclude_list    IN VARCHAR2 --Date 11-05-2007 by Sacsethi for bug 5647248
4682 )
4683 IS
4684 
4685 
4686 --Date 11-05-2007 by Sacsethi for bug 5647248
4687 -- start 5647248
4688 
4689 
4690   cursor c_prg_name(cp_conc_prg in number)
4691   is
4692   select concurrent_program_name
4693   from fnd_concurrent_programs_vl
4694   where concurrent_program_id= cp_conc_prg;
4695 
4696   l_prg_name varchar2(50);
4697   l_prg_id   number(15);
4698   l_form_number varchar2(5);
4699 
4700  /* lv_req_id   NUMBER;
4701   lv_result   BOOLEAN;
4702   lv_request_desc   VARCHAR2(200);*//*Added in generate_etds_returns-ETDS FVU3.1 Bug 11896260*/
4703 
4704   v_deductor_type VARCHAR2(1);
4705   v_resp_person_email     VARCHAR2(75);
4706   v_resp_person_phoneno   VARCHAR2(15) ;
4707   v_err           VARCHAR2(1);
4708   v_return_message VARCHAR2(240);
4709 
4710   /*
4711   Cursor c_get_state_desc
4712   is
4713   select
4714     description
4715   from FND_FLEX_VALUES_VL a
4716   where flex_value_set_id =
4717          ( select flex_value_set_id
4718            from fnd_flex_value_sets
4719            where flex_value_set_name ='JA_IN_INDIAN_STATES'
4720          )
4721   and flex_value = to_number(p_RespPersState) ;
4722 
4723   lv_state_desc fnd_flex_values_vl.description%TYPE ; */ /*ETDS FVU3.1 Bug 11896260*/
4724   ld_challan_start_date  DATE;  --added by csahoo for bug#6158875
4725   ld_challan_end_date     DATE;  --added by csahoo for bug#6158875
4726   /* Bug 13323753 -Start */
4727   l_RespPers_flat_no varchar2(25);
4728   l_RespPers_prem_bldg varchar2(25);
4729   l_RespPers_rd_st_lane varchar2(25);
4730   l_RespPers_area_loc varchar2(25);
4731   l_RespPers_tn_cty_dt varchar2(25);
4732   /* Bug 13323753 -End */
4733   BEGIN
4734 
4735      l_prg_id:=FND_GLOBAL.CONC_PROGRAM_ID;
4736      ld_challan_start_date  := fnd_date.canonical_to_date(p_challan_Start_Date);  --added by csahoo for bug#6158875
4737      ld_challan_end_date     := fnd_date.canonical_to_date(p_challan_End_Date);    --added by csahoo for bug#6158875
4738 
4739      open c_prg_name(l_prg_id);
4740      fetch c_prg_name into l_prg_name;
4741      close c_prg_name;
4742 
4743      if l_prg_name='JAINETDSQ' then
4744         l_form_number:='26Q';
4745      elsif l_prg_name='JAINE27Q' then
4746         l_form_number:='27Q';
4747     end if;
4748 /* Added substr conditions for bug 13323753 */
4749 l_RespPers_flat_no := substr(p_RespPers_flat_no,1,25);
4750 l_RespPers_prem_bldg := substr(p_RespPers_prem_bldg,1,25);
4751 l_RespPers_rd_st_lane := substr(p_RespPers_rd_st_lane,1,25);
4752 l_RespPers_area_loc := substr(p_RespPers_area_loc,1,25);
4753 l_RespPers_tn_cty_dt := substr(p_RespPers_tn_cty_dt,1,25);
4754 /* end -13323753 */
4755 
4756     generate_etds_returns
4757       (p_err_buf                 =>   p_err_buf                 ,
4761        p_period                   =>   p_period                  ,
4758        p_ret_code                 =>   p_ret_code                ,
4759        p_tan_number               =>   p_tan_number              ,
4760        p_fin_year                 =>   p_fin_year                ,
4762        p_tax_authority_id         =>   p_tax_authority_id        ,
4763        p_tax_authority_site_id    =>   p_tax_authority_site_id   ,
4764        p_organization_id          =>   p_organization_id         ,
4765      p_deductor_addr_org_id     => p_deductor_addr_org_id, /*ETDS FVU3.1 Bug 11896260*/
4766        p_deductor_name            =>   p_deductor_name           ,
4767       --p_deductor_email           =>   p_deductor_email          , /* Bug#10315928 */
4768        --p_deductor_stdcode         =>   p_deductor_stdcode        , /* Bug#10315928 */
4769        --p_deductor_phno            =>   p_deductor_phno           , /* Bug#10315928 */
4770        p_deductor_state           =>   p_deductor_state          ,
4771        p_addrChangedSinceLastRet  =>   p_addrChangedSinceLastRet ,
4772        --p_deductor_status          =>   p_deductor_status       , /*Bug 8880543 - Commented for eTDS/eTCS FVU Changes*/
4773        p_persRespForDeduction     =>   p_persRespForDeduction    ,
4774        p_desgOfPersResponsible    =>   p_desgOfPersResponsible   ,
4775        -- bug 6030953. Added by Lakshmi Gopalsami
4776        p_RespPers_flat_no         =>   l_RespPers_flat_no        ,
4777        p_RespPers_prem_bldg       =>   l_RespPers_prem_bldg      ,
4778        p_RespPers_rd_st_lane      =>   l_RespPers_rd_st_lane     ,
4779        p_RespPers_area_loc        =>   l_RespPers_area_loc       ,
4780        p_RespPers_tn_cty_dt       =>   l_RespPers_tn_cty_dt      ,
4781      -- end for bug 6030953
4782        p_RespPersState            =>   p_RespPersState           ,
4783        p_RespPersPin              =>   p_RespPersPin             ,
4784       --p_RespPersMobileNo         =>   p_RespPersMobileNo        , /* Bug#10315928 */
4785        --p_RespPersStdCode          =>   p_RespPersStdCode         , /* Bug#10315928 */
4786      -- bug 6030953. Added by Lakshmi Gopalsami
4787        -- p_RespPers_tel_no          =>   p_RespPers_tel_no         ,/* Bug#10315928 */
4788        --p_RespPers_email           =>   p_RespPers_email          ,/* Bug#10315928 */
4789       -- end for bug 6030953
4790        p_RespPersAddrChange       =>   p_RespPersAddrChange      ,
4791        pv_challan_Start_Date       =>   p_challan_Start_Date      ,
4792        pv_challan_End_Date         =>   p_challan_End_Date        ,
4793        p_pro_rcpt_num_org_ret     =>   p_pro_rcpt_num_org_ret    ,
4794        p_file_path                =>   p_file_path               ,
4795        p_filename                 =>   p_filename                ,
4796        p_action                   =>   p_action                  ,
4797        p_form_number              =>   l_form_number             ,
4798        p_include_list             =>   p_include_list            ,
4799        p_exclude_list             =>   p_exclude_list
4800       ) ;
4801 
4802 
4803      /* open c_get_state_desc ;
4804       fetch c_get_state_desc into lv_state_desc ;
4805       close c_get_state_desc ; */
4806       /*Bug 8880543 - Start*/
4807       /*get_attr_value (p_organization_id, 'DEDUCTOR_TYPE', v_deductor_type, v_err, v_return_message);
4808       chk_err(v_err, v_return_message);
4809       get_attr_value (p_organization_id, 'RESP_PERSON_EMAIL', v_resp_person_email, v_err, v_return_message);
4810       chk_err(v_err, v_return_message);
4811       get_attr_value (p_organization_id, 'RESP_PERSON_PHONE_NO', v_resp_person_phoneno, v_err, v_return_message);
4812       chk_err(v_err, v_return_message);
4813       --Bug 8880543 - End
4814       lv_request_desc := 'India - TDS Form 27A for Batch Id '|| ln_batch_id;
4815 
4816       lv_result := FND_REQUEST.set_mode(true);
4817       lv_req_id := FND_REQUEST.submit_request(
4821                       p_tan_number,              --Org Tan Num
4818                       'JA', 'JAINTDSA', lv_request_desc, '', FALSE,
4819                       --p_legal_entity_id,         --Legal Entity Id  --commented by csahoo for bug#6158875
4820                       --p_profile_org_id,          --Operating Unit  --commented by csahoo for bug#6158875
4822                       p_organization_id,         --Organization Id
4823                       p_fin_year,                --Fin Year
4824                       p_period,                  --Quarter
4825                       p_tax_authority_id,        --Tax Authority
4826                       p_tax_authority_site_id,   --Tax Authority Site
4827                       l_form_number,             --Form Number
4828                       p_pro_rcpt_num_org_ret,    --Previous Receipt Number
4829             -- Bug 6030953. Added by Lakshmi Gopalsami
4830                   v_deductor_type  ,         -- Type of deductor. --Bug 8880543 - Fetch deductor and pass the same as it is not a parameter
4831                       p_persRespForDeduction,    --Person Responsible
4832                       p_desgOfPersResponsible,   --Responsible person Designation
4833                        -- bug 6030953. Added by Lakshmi Gopalsami
4834                       p_RespPers_flat_no,         -- Responsible person Flat No.
4835                   p_RespPers_prem_bldg,       -- Name of premises/Bldg
4836                   p_RespPers_rd_st_lane,      -- Road/Street/Lane
4837                   p_RespPers_area_loc,        -- Area/Location
4838                   p_RespPers_tn_cty_dt,       -- Town/city/District
4839                       lv_state_desc,              -- Responsible person State
4840                       p_RespPersPin,              -- Responsible Person Pin
4841                    v_resp_person_phoneno,      -- Telephone number
4842                   v_resp_person_email,        -- Email
4843                  -- end for bug 6030953
4844                      p_challan_Start_Date,    --MODIFIED BY CSAHOO FOR BUG#6158875
4845                      p_challan_End_Date,      --MODIFIED BY CSAHOO FOR BUG#6158875
4846                       CHR(0), '', '', '', '', '', '',
4847                       '', '', '', '', '', '', '', '', '', '',
4848                       '', '', '', '', '', '', '', '', '', '',
4849                       '', '', '', '', '', '', '', '', '', '',
4850                       '', '', '', '', '', '', '', '', '', '',
4851                       '', '', '', '', '', '', '', '', '', '',
4852                       '', '', '', '', '', '', '', '', '', '',
4853                       '', '', '', '', '', '', '', ''
4854                   );
4855                   */
4856 
4857 
4858 
4859 END quarterly_returns;
4860 
4861 /* Comment out Yearly return program by Chong for eTDS ER bug#16414088
4862 PROCEDURE yearly_returns(
4863   p_err_buf OUT NOCOPY VARCHAR2,
4864   p_ret_code OUT NOCOPY NUMBER,
4865   --p_legal_entity_id   IN NUMBER,   --commented by csahoo for bug#6158875
4866   --p_profile_org_id    IN NUMBER,   --commented by csahoo for bug#6158875
4867   p_tan_number      IN VARCHAR2,
4868   p_fin_year        IN NUMBER,
4869   p_organization_id   IN NUMBER,
4870   p_tax_authority_id    IN NUMBER,
4871   p_tax_authority_site_id IN NUMBER,
4872   p_deductor_name     IN VARCHAR2,
4873   p_deductor_state    IN VARCHAR2,
4874   p_addrChangedSinceLastRet IN VARCHAR2,
4875   p_deductor_status   IN VARCHAR2,
4876   p_persRespForDeduction  IN VARCHAR2,
4880   --p_pro_rcpt_num_org_ret IN NUMBER, --commented by csahoo for bug#6158875
4877   p_desgOfPersResponsible IN VARCHAR2,
4878   p_challan_Start_Date  IN VARCHAR2,
4879   p_challan_End_Date    IN VARCHAR2,
4881   p_file_path       IN VARCHAR2,
4882   p_filename        IN VARCHAR2,
4883   p_generate_headers    IN VARCHAR2 DEFAULT NULL
4884 )
4885 IS
4886 ld_challan_start_date   DATE;
4887 ld_challan_end_date     DATE;
4888 BEGIN
4889 
4890 ld_challan_start_date  := fnd_date.canonical_to_date(p_challan_Start_Date);  --added by csahoo for bug#6158875
4891 ld_challan_end_date     := fnd_date.canonical_to_date(p_challan_End_Date);    --added by csahoo for bug#6158875
4892  generate_etds_returns
4893      (
4894        p_err_buf                  =>   p_err_buf                 ,
4895        p_ret_code                 =>   p_ret_code                ,
4896        p_tan_number               =>   p_tan_number              ,
4897        p_fin_year                 =>   p_fin_year                ,
4898        p_tax_authority_id         =>   p_tax_authority_id        ,
4899        p_tax_authority_site_id    =>   p_tax_authority_site_id   ,
4900        p_organization_id          =>   p_organization_id         ,
4901        p_deductor_name            =>   p_deductor_name           ,
4902        p_deductor_state           =>   p_deductor_state          ,
4903        p_addrChangedSinceLastRet  =>   p_addrChangedSinceLastRet ,
4904        --p_deductor_status          =>   p_deductor_status       , \*Bug 8880543 - Commented for eTDS/eTCS FVU Changes*\
4905        p_persRespForDeduction     =>   p_persRespForDeduction    ,
4906        p_desgOfPersResponsible    =>   p_desgOfPersResponsible   ,
4907        pv_challan_Start_Date       =>   p_challan_Start_Date      ,
4908        pv_challan_End_Date         =>   p_challan_End_Date        ,
4909        p_pro_rcpt_num_org_ret     =>   NULL    ,   --modified by csahoo for bug#6158875
4910        p_file_path                =>   p_file_path               ,
4911        p_filename                 =>   p_filename                ,
4912        p_generate_headers         =>   p_generate_headers
4913     ) ;
4914 
4915 
4916 END yearly_returns;
4917 -- ended, Harshita for Bug 4525089
4918 */
4919 
4920 
4921 
4922 PROCEDURE generate_etds_returns
4923 (
4924     p_err_buf OUT NOCOPY VARCHAR2,
4925     p_ret_code OUT NOCOPY NUMBER,
4926     p_tan_number      IN VARCHAR2,
4927     p_fin_year        IN NUMBER,
4928     p_organization_id   IN NUMBER, -- Harshita for Bug 4889272
4929   p_deductor_addr_org_id IN NUMBER DEFAULT NULL,/*ETDS FVU3.1 Bug 11896260  */
4930     p_tax_authority_id    IN NUMBER,
4931     p_tax_authority_site_id IN NUMBER,
4932     p_deductor_name     IN VARCHAR2,
4933      --p_deductor_email    IN VARCHAR2 DEFAULT NULL, /* Bug#10315928 */
4934     --p_deductor_stdcode IN VARCHAR2 DEFAULT NULL,  /* Bug#10315928 */
4935     --p_deductor_phno    IN VARCHAR2 DEFAULT NULL,  /* Bug#10315928 */
4936     p_deductor_state    IN VARCHAR2,
4937     p_addrChangedSinceLastRet IN VARCHAR2,
4938     --p_deductor_status   IN VARCHAR2, /*Bug 8880543 - Commented for eTDS/eTCS FVU Changes*/
4939     p_persRespForDeduction  IN VARCHAR2,
4940     p_desgOfPersResponsible IN VARCHAR2,
4941     pv_challan_Start_Date  IN VARCHAR2, /* rallamse for bu# 4334682 changed to varchar2 from date */
4942     pv_challan_End_Date    IN VARCHAR2, /* rallamse for bu# 4334682 changed to varchar2 from date */
4943     p_pro_rcpt_num_org_ret IN NUMBER,
4944     p_file_path       IN VARCHAR2,
4945     p_filename        IN VARCHAR2,
4946     p_generate_headers    IN VARCHAR2 DEFAULT NULL,
4947     p_period               IN VARCHAR2 DEFAULT NULL,
4948     p_RespPers_flat_no IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4949     p_RespPers_prem_bldg IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4950     p_RespPers_rd_st_lane IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4951     p_RespPers_area_loc IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4952     p_RespPers_tn_cty_dt IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4953     p_RespPersState        IN VARCHAR2 DEFAULT NULL,
4954     p_RespPersPin          IN NUMBER   DEFAULT NULL,
4955    --p_RespPersStdCode IN VARCHAR2 DEFAULT NULL, /* Bug#10315928 */
4956    -- p_RespPers_tel_no IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4957    --p_RespPersMobileNo IN VARCHAR2 DEFAULT NULL, /* Bug#10315928 */
4958     --p_RespPers_email IN VARCHAR2 DEFAULT NULL, -- Bug 6030953
4959     p_RespPersAddrChange   IN VARCHAR2 DEFAULT NULL,
4960     p_action               IN VARCHAR2 DEFAULT NULL,
4961     p_form_number          IN VARCHAR2 DEFAULT NULL,     --Date 11-05-2007 by Sacsethi for bug 5647248
4962     p_include_list         IN VARCHAR2 DEFAULT NULL,
4963     p_exclude_list         IN VARCHAR2 DEFAULT NULL
4964 
4965 )IS
4966 
4967     lv_object_name  VARCHAR2(61); -- := '<Package_name>.<procedure_name>'; /* Added by Ramananda for bug#4407165 */
4968     lv_oth_reg_type  CONSTANT VARCHAR2(30) := 'OTHERS';
4969     lv_prim_att_type CONSTANT VARCHAR2(30) := 'OTHERS' ; -- 'PRIMARY'; -- Harshita for Bug 4889272
4970     lv_pan_att_code  CONSTANT VARCHAR2(30) := 'PAN NO';
4971 
4972     /* rallamse for bug# 4336482 */
4973     p_challan_Start_Date  DATE; --File.Sql.35 Cbabu  DEFAULT fnd_date.canonical_to_date(pv_challan_Start_Date);
4974     p_challan_End_Date    DATE; --File.Sql.35 Cbabu  DEFAULT fnd_date.canonical_to_date(pv_challan_End_Date);
4975 
4976 /*Update to get fin year info from regime definition for eTDS bug#16414088
4977     -- to get financial and assessment years
4978     CURSOR c_fin_year(p_tan_number \*p_legal_entity_id*\ IN VARCHAR2, p_fin_year IN NUMBER, p_organization_id IN NUMBER ) IS
4979       SELECT start_date, end_date
4980       FROM JAI_AP_TDS_YEARS
4981       -- added, Harshita for Bug 4889272
4982       where TAN_NO = p_tan_number
4983       AND fin_year = p_fin_year
4984       and legal_entity_id = p_organization_id;
4985 */
4986     --Added by Chong for eDTC on 20130321 start
4990             ,p.end_date
4987     -------------------------------------------------------------------------------------------------
4988     CURSOR c_fin_year IS
4989       SELECT p.start_date
4991       from gl_period_sets ps
4992           ,gl_periods p
4993           ,JAI_RGM_REGISTRATIONS rr
4994           ,JAI_RGM_DEFINITIONS gd
4995       Where ps.period_set_id = to_number(rr.attribute_value)
4996       and   ps.period_set_name = p.period_set_name
4997       and   gd.regime_code = 'TDS'
4998       and   gd.regime_id = rr.regime_id
4999       and   rr.attribute_code = 'TDS_CALENDAR'
5000     ;
5001     -------------------------------------------------------------------------------------------------
5002     --Added by Chong for eDTC on 20130321 end
5003 
5004       -- commented, Harshita for Bug 4889272
5005       /*
5006       WHERE legal_entity_id = p_legal_entity_id
5007       AND fin_year = p_fin_year;
5008       */
5009 
5010     -- to get Organization related to TAN
5011     CURSOR c_organization_id(p_tan_number IN VARCHAR2, p_organization_id IN NUMBER DEFAULT NULL) IS
5012       SELECT organization_id
5013       FROM jai_ap_tds_org_tan_v        ---  JAI_AP_TDS_ORG_TANS is changed to view jai_ap_tds_org_tan_v  4323338
5014       WHERE org_tan_num = p_tan_number
5015       AND organization_id = nvl(p_organization_id, organization_id);
5016 /*ETDS FVU3.1 Bug 11896260   start*/
5017 --to get organisation_id from tan
5018     -- to get PAN related to TAN
5019 
5020 Cursor c_get_state_desc
5021   is
5022   select
5023     description
5024   from FND_FLEX_VALUES_VL a
5025   where flex_value_set_id =
5026          ( select flex_value_set_id
5027            from fnd_flex_value_sets
5028            where flex_value_set_name ='JA_IN_INDIAN_STATES'
5029          )
5030   and flex_value = to_number(p_RespPersState) ;
5031 
5032   lv_state_desc fnd_flex_values_vl.description%TYPE ;
5033   lv_request_desc   VARCHAR2(200);
5034   lv_req_id   NUMBER;
5035   lv_result   BOOLEAN;
5036 /*ETDS FVU3.1 Bug 11896260   END*/
5037     -- to get PAN related to TAN
5038     /*Modified the below cursor by Bgowrava for Bug#9494515*/
5039     CURSOR c_pan_number(p_organization_id IN NUMBER) IS  --Harshita for bug#4889272
5040     SELECT attribute_value ORG_TAN_NUM
5041     FROM jai_rgm_org_regns_v
5042     WHERE
5043       regime_code = 'TDS'
5044       AND organization_id     = p_organization_id
5045       AND registration_type   = lv_oth_reg_type
5046       AND attribute_type_code = lv_prim_att_type
5047       AND attribute_code      = lv_pan_att_code;
5048 
5049 
5050     -- Cursor to check whether the organization is an Operating Unit
5051     -- commented by ssumaith - bug# 4448789
5052     /*
5053       CURSOR c_ou_check(p_organization_id IN NUMBER) IS
5054       SELECT organization_id, to_number(legal_entity_id)
5055       FROM hr_operating_units
5056       WHERE organization_id = p_organization_id;
5057     */
5058     -- Cursor to check whether the organization is Legal Entity
5059     CURSOR c_le_check(p_organization_id IN NUMBER) IS
5060       SELECT 1
5061       FROM hr_legal_entities
5062       WHERE organization_id = p_organization_id;
5063 
5064     -- gives Location_id linked to Organization/*ETDS FVU3.1 Bug 11896260  -Modified the below query*/
5065     CURSOR c_location_linked_to_org(p_organization_id IN NUMBER,p_deductor_addr_org_id IN NUMBER) IS
5066       SELECT location_id
5067       FROM hr_all_organization_units
5068       WHERE organization_id = nvl(p_organization_id,p_deductor_addr_org_id);
5069 
5070     -- to get address details of location linked to given organization
5071     CURSOR c_address_details(p_location_id IN NUMBER) IS
5072     SELECT location_code, address_line_1, address_line_2, address_line_3, null, null,
5073            REPLACE(postal_code, ' ') postal_code
5074       FROM hr_locations_all
5075      WHERE location_id = p_location_id;
5076 
5077     -- gives the Deductee code based on Vendor Classification
5078     CURSOR c_deductee_dtls(p_vendor_id IN NUMBER) IS
5079     SELECT vendor_name,
5080            decode( UPPER(organization_type_lookup_code), 'COMPANY', '01', '02')
5081       FROM po_vendors
5082      WHERE vendor_id = p_vendor_id;
5083 
5084     -- gives the Deductee code based on Vendor Classification
5085     CURSOR c_deductee_site_dtls(p_vendor_id IN NUMBER, p_vendor_site_id IN NUMBER) IS
5086     SELECT address_line1 addr1, address_line2 addr2, address_line3 addr3, address_line4 addr4, city,
5087            UPPER(state) state, REPLACE(zip,' ') zip   --Removed to_number for Bug 6281440
5088       FROM po_vendor_sites_all
5089      WHERE vendor_id = p_vendor_id
5090        AND vendor_site_id = p_vendor_site_id;
5091 
5092     v_deductee_state_code NUMBER;
5093     CURSOR c_state_code(p_state_name IN VARCHAR2,p_state_type IN VARCHAR2) IS
5094     SELECT meaning
5095       FROM ja_lookups --fnd_common_lookups  /* Ramananda for bug#4555466 */
5096      WHERE lookup_type = p_state_type
5097        AND lookup_code = p_state_name;
5098 
5099     CURSOR c_deductee_pan(p_vendor_id IN NUMBER, p_vendor_site_id IN NUMBER) IS
5100     SELECT pan_no,confirm_pan_flag /*eTDS FVU3.1 Bug 11896260*/
5101       FROM JAI_AP_TDS_VENDOR_HDRS
5102      WHERE vendor_id = p_vendor_id
5103        AND vendor_site_id = p_vendor_site_id;
5104 
5105     CURSOR c_check_dtls(p_check_id IN NUMBER) IS
5106     SELECT check_date
5107       FROM ap_checks_all
5108      WHERE check_id = p_check_id;
5109 
5110    CURSOR c_cert_issue_date(p_tds_invoice_id IN NUMBER) IS
5111     SELECT a.issue_date
5112     FROM JAI_AP_TDS_F16_HDRS_ALL a, JAI_AP_TDS_F16_DTLS_ALL b
5113     WHERE a.CERTIFICATE_NUM = b.CERTIFICATE_NUM
5114     AND a.org_tan_num = b.org_tan_num
5115     AND a.fin_yr = b.fin_yr
5119     /* CURSOR c_challan_records(p_batch_id IN NUMBER) IS
5116     AND b.tds_invoice_id = p_tds_invoice_id;
5117 
5118 
5120       select *
5121       from JAI_AP_ETDS_T a
5122       where a.batch_id = p_batch_id
5123       and a.consider_for_challan=1
5124       FOR UPDATE OF challan_line_num;
5125 
5126       bug#3708878 above cursor definition replaced by the definition below
5127     */
5128 
5129     lv_dummy_date                DATE;
5130 
5131    /* CURSOR c_challan_records(p_batch_id IN NUMBER) IS
5132       SELECT tds_section, bank_branch_code, challan_num, challan_date, sum(tds_amount) tds_amount
5133       FROM   JAI_AP_ETDS_T a
5134       WHERE  a.batch_id = p_batch_id
5135       AND    a.consider_for_challan=1
5136       GROUP BY tds_section, bank_branch_code, challan_num, challan_date;*/
5137 
5138      /* CURSOR c_challan_records(p_batch_id IN NUMBER) IS
5139             select NVL(tds_section,'No Section') tds_section,
5140                    NVL(bank_branch_code,'No Bank Branch') bank_branch_code,
5141                    NVL(challan_num,'No Challan Number') challan_num,
5142                    NVL(challan_date,lv_dummy_date) challan_date,
5143                    check_number check_number,
5144                    sum(tds_amount) tds_amount,
5145                    sum(amt_of_tds) amt_of_tds,
5146                    sum(amt_of_surcharge) amt_of_surcharge,
5147                    sum(amt_of_cess) amt_of_cess
5148             from   JAI_AP_ETDS_T a
5149             where a.batch_id = p_batch_id
5150             and a.consider_for_challan=1
5151             and a.tds_invoice_id <> -9999 -- Bug#10315928
5152             group by NVL(tds_section,'No Section'), NVL(bank_branch_code,'No Bank Branch'),
5153                      NVL(challan_num,'No Challan Number'), NVL(challan_date,lv_dummy_date),
5154                      check_number;
5155     cd c_challan_records%ROWTYPE ;   */
5156   /*start 10315928 */
5157   CURSOR c_challan_records(p_batch_id IN NUMBER) IS
5158   select NVL(tds_section,'No Section') tds_section,
5159          NVL(bank_branch_code,'No Bank Branch') bank_branch_code,
5160          NVL(challan_num,'No Challan Number') challan_num,
5161          NVL(challan_date,lv_dummy_date) challan_date,
5162          --check_number check_number,/* Commented for Bug 13323753 */
5163          sum(tds_amount) tds_amount,
5164          sum(amt_of_tds) amt_of_tds,
5165          sum(amt_of_surcharge) amt_of_surcharge,
5166          sum(amt_of_cess) amt_of_cess,
5167          --Changed by Zhhou for bug#15962641 20121205 begin
5168          ------------------------------------------------------------
5169          tds_vendor_classification /* Uncommented by Avanija for FVU3.6 */
5170          --decode(tds_vendor_classification,NULL,NULL,'TRANS/SOFTW') tds_vendor_classification /* Avanija for FVU3.6 */
5171          ------------------------------------------------------------
5172          --Changed by Zhhou for bug#15962641 20121205 end
5173   from   jai_ap_etds_t a
5174   where a.batch_id = p_batch_id
5175   and a.consider_for_challan=1
5176   group by NVL(tds_section,'No Section'), NVL(bank_branch_code,'No Bank Branch'),
5177            NVL(challan_num,'No Challan Number'), NVL(challan_date,lv_dummy_date),
5178                   /* check_number, -commented for Bug 13323753 */
5179                   --Changed by Zhhou for bug#15962641 20121205 begin
5180                   ------------------------------------------------------------
5181                   tds_vendor_classification;  /* Uncommented by Avanija for FVU3.6 */
5182                  -- decode(tds_vendor_classification,NULL,NULL,'TRANS/SOFTW');/* Avanija for FVU3.6 */
5183                   ------------------------------------------------------------
5184                   --Changed by Zhhou for bug#15962641 20121205 end
5185 
5186 cd c_challan_records%ROWTYPE ;
5187 
5188 /*end 10315928 */
5189 
5190     /*CURSOR c_deductee_records(p_batch_id IN NUMBER) IS
5191       SELECT *
5192       FROM JAI_AP_ETDS_T a
5193       WHERE a.batch_id = p_batch_id
5194       AND a.consider_for_challan=1
5195       FOR UPDATE OF deductee_line_num;*/
5196 
5197     CURSOR c_deductee_records(p_batch_id IN NUMBER, p_challan_line_num IN NUMBER) IS
5198       select
5199           base_vendor_id,challan_line_num, base_vendor_site_id,tds_tax_id,
5200           NVL(tds_section,'No Section') tds_section,
5201           NVL(bank_branch_code,'No Bank Branch') bank_branch_code,
5202           NVL(challan_num,'No Challan Number') challan_num,
5203           NVL(challan_date,lv_dummy_date) challan_date,
5204           --check_number, /* Commented for Bug 13323753 */
5205           tds_tax_rate,
5206           max(certificate_issue_date) certificate_issue_date,
5207           max( base_invoice_date) base_invoice_date ,
5208           max(tds_check_date) tds_check_date,
5209           max(tds_invoice_date) tds_invoice_date,
5210           max(tds_invoice_id) tds_invoice_id,
5211           max(base_invoice_id) base_invoice_id,
5212           sum(amt_of_tds) amt_of_tds,
5213           sum(amt_of_surcharge) amt_of_surcharge,
5214           sum(amt_of_cess) amt_of_cess,
5215           sum(base_taxabale_amount) base_taxabale_amount,
5216           sum(tds_amount) tds_amount
5217       from JAI_AP_ETDS_T a
5218       where a.batch_id = p_batch_id
5219           and a.consider_for_challan=1
5220          and (a.tds_invoice_id <> -9999 /* Bug#10315928 */
5221               OR  (a.tds_invoice_id = -9999 and (a.tds_vendor_classification not in ( 'Transporter', 'Software') OR a.tds_vendor_classification IS NULL))) /*11896260*/
5222 			/* Added Software by Avanija for FVU3.6*/
5223           and challan_line_num = NVL(p_challan_line_num, challan_line_num)
5224       group by challan_line_num, base_vendor_id, base_vendor_site_id,tds_tax_id,
5225           NVL(tds_section,'No Section'), NVL(bank_branch_code,'No Bank Branch'),
5229     /* ER: 13514846 - Query to populate Zero Rate Records in Deductee*/
5226           NVL(challan_num,'No Challan Number'), NVL(challan_date,lv_dummy_date),
5227           /* check_number, -Commented for Bug 13323753 */tds_tax_rate, base_invoice_id
5228       having sum(amt_of_tds) > 0
5230     union
5231     select
5232           base_vendor_id,challan_line_num, base_vendor_site_id,tds_tax_id,
5233           NVL(tds_section,'No Section') tds_section,
5234           NVL(bank_branch_code,'No Bank Branch') bank_branch_code,
5235           NVL(challan_num,'No Challan Number') challan_num,
5236           NVL(challan_date,lv_dummy_date) challan_date,
5237           tds_tax_rate,
5238           max(certificate_issue_date) certificate_issue_date,
5239           max( base_invoice_date) base_invoice_date ,
5240           max(tds_check_date) tds_check_date,
5241           max(tds_invoice_date) tds_invoice_date,
5242           max(tds_invoice_id) tds_invoice_id,
5243           max(base_invoice_id) base_invoice_id,
5244           sum(amt_of_tds) amt_of_tds,
5245           sum(amt_of_surcharge) amt_of_surcharge,
5246           sum(amt_of_cess) amt_of_cess,
5247           sum(base_taxabale_amount) base_taxabale_amount,
5248           sum(tds_amount) tds_amount
5249       from JAI_AP_ETDS_T a
5250       where a.batch_id = p_batch_id
5251       and a.consider_for_challan=1
5252       and a.tds_invoice_id = -9997
5253       and challan_line_num = NVL(p_challan_line_num, challan_line_num)
5254       group by challan_line_num, base_vendor_id, base_vendor_site_id,tds_tax_id,
5255                NVL(tds_section,'No Section'), NVL(bank_branch_code,'No Bank Branch'),
5256                NVL(challan_num,'No Challan Number'), NVL(challan_date,lv_dummy_date),
5257                tds_tax_rate, base_invoice_id
5258     ;
5259       /*Bug 8505050 - Added the having clause to prevent entries in e-TDS file with 0 Tax amount*/
5260 
5261       dd c_deductee_records%ROWTYPE ;
5262   /*Bug 10315928 - Start*/
5263     cursor c_split_phone_no(p_phone_no IN VARCHAR2)
5264     IS
5265     select
5266     substr(p_phone_no,0,(select instr(p_phone_no,'-')from dual)-1),
5267     substr(p_phone_no,(select instr(p_phone_no,'-')from dual)+1)
5268     from dual;
5269 
5270       --Here merge cursor to support software Vendor.
5271       --Changed by Zhiwei for Bug#15840480 FVU3.6 begin
5272       ------------------------------------------------------------------------------------------------------
5273       --CURSOR c_deductee_records_trans(p_batch_id IN NUMBER, p_challan_line_num IN NUMBER)
5274       CURSOR c_deductee_records_trans(p_batch_id IN NUMBER, p_challan_line_num IN NUMBER, c_vendor_classification in varchar2
5275       )
5276       ------------------------------------------------------------------------------------------------------
5277       --Changed by Zhiwei for Bug#15840480 FVU3.6 end
5278       IS
5279       select
5280           base_vendor_id,challan_line_num, base_vendor_site_id,tds_tax_id,
5281           NVL(tds_section,'No Section') tds_section,
5282           NVL(bank_branch_code,'No Bank Branch') bank_branch_code,
5283           NVL(challan_num,'No Challan Number') challan_num,
5284           NVL(challan_date,lv_dummy_date) challan_date,
5285           /* NVL(check_number, -9999) check_number,- Commented for Bug 13323753 */
5286           tds_tax_rate,
5287           max(certificate_issue_date) certificate_issue_date,
5288           max(base_invoice_date) base_invoice_date ,
5289           max(tds_check_date) tds_check_date,
5290           max(tds_invoice_date) tds_invoice_date,
5291           max(tds_invoice_id) tds_invoice_id, --Added by Bgowrava for bug#9346767
5292           max(base_invoice_id) base_invoice_id, /* Added for Bug 10188600*/
5293           sum(amt_of_tds) amt_of_tds,
5294           sum(amt_of_surcharge) amt_of_surcharge,
5295           sum(amt_of_cess) amt_of_cess,
5296           sum(base_taxabale_amount) base_taxabale_amount,
5297           sum(tds_amount) tds_amount
5298       from jai_ap_etds_t a
5299       where a.batch_id = p_batch_id
5300           and a.consider_for_challan=1
5301           and a.tds_invoice_id = -9999
5302           and challan_line_num = NVL(p_challan_line_num, challan_line_num)
5303       --Changed by Zhiwei for Bug#15840480 FVU3.6 begin
5304       ---------------------------------------------------------
5305       --and a.tds_vendor_classification = 'Transporter' /*Bug 11896260 - Distinguish between Transporters and Invoices before Threshold*/
5306       and a.tds_vendor_classification = c_vendor_classification
5307       ---------------------------------------------------------
5308       --Changed by Zhiwei for Bug#15840480 FVU3.6 end
5309       group by challan_line_num, base_vendor_id, base_vendor_site_id, tds_tax_id,
5310           NVL(tds_section,'No Section'), NVL(bank_branch_code,'No Bank Branch'),
5311           NVL(challan_num,'No Challan Number'), NVL(challan_date,lv_dummy_date),
5312           /*NVL(check_number, -9999), - Commented for Bug 13323753 */ tds_tax_rate, base_invoice_id; /* Added base_invoice_id for bug 15996337 */
5313 
5314       dd_t c_deductee_records_trans%ROWTYPE ;
5315 
5316       /* Bug#10315928 - End */
5317 /*Bug 10188600-Start*/
5318     CURSOR get_gl_date(p_base_invoice_id IN NUMBER) IS
5319       SELECT gl_date
5320       FROM ap_invoices_all
5321       WHERE invoice_id = p_base_invoice_id;
5322  /*Bug 10188600-End*/
5323 
5324 
5325     CURSOR c_base_inv_gl_date(p_invoice_id IN NUMBER, p_tax_id IN NUMBER,p_line_type ap_invoice_distributions_all.line_type_lookup_code%type) IS
5326       SELECT accounting_date
5327       FROM ap_invoice_distributions_all
5328       WHERE invoice_id = p_invoice_id
5329       AND line_type_lookup_code = p_line_type
5330       AND global_attribute1 = to_char(p_tax_id);--rchandan for bug#4333488
5331 
5332     /*ER 13514846 - Derive Reason for Non Deduction Based on Section Code attached*/
5333     /* A - In case of lower deduction/no deduction on account of certificate under section 197
5334        B - In case of no deduction on account of declaration under section 197A */
5335     /*  --Commented out by Chong for eTDS ER bug#16414088 20130330 Start
5336     CURSOR c_reason_non_deduction(p_tax_id IN NUMBER) IS
5337     select 'A'
5338     from jai_cmn_taxes_all, fnd_lookup_values_vl
5339     where tax_id = p_tax_id
5340     and upper(section_code) = lookup_code
5341     and (stform_type is not null or tax_rate = 0)
5342     and lookup_type = 'JAI_TDS_SECTION_ZERO_RATE_197'
5343     UNION
5344     select 'B'
5345     from jai_cmn_taxes_all, fnd_lookup_values_vl
5346     where tax_id = p_tax_id
5347     and tax_rate = 0
5348     and upper(section_code) = lookup_code
5349     and lookup_type = 'JAI_TDS_SECTION_ZERO_RATE_197A';
5350     */ ----Commented out by Chong for eTDS ER bug#16414088 20130330 END
5351     --Added out by Chong for eTDS ER bug#16414088 20130330 Start
5352     --------------------------------------------------------------------
5353     CURSOR c_reason_non_deduction(p_section_code IN VARCHAR2) IS
5354     select 'A'
5355     from  fnd_lookup_values_vl
5356     where upper(p_section_code) = lookup_code
5357     and lookup_type = 'JAI_TDS_SECTION_ZERO_RATE_197'
5358     UNION
5359     select 'B'
5360     from fnd_lookup_values_vl
5361     where upper(p_section_code) = lookup_code
5362     and lookup_type = 'JAI_TDS_SECTION_ZERO_RATE_197A';
5363     --------------------------------------------------------------------
5364     --Added out by Chong for eTDS ER bug#16414088 20130330 End
5365    /*
5366     CURSOR c_deductee_cnt(p_batch_id IN NUMBER , p_check_number IN NUMBER ) IS
5367             select sum ( count(  base_vendor_id ) )  -- distinct removed the distinct
5368             from JAI_AP_ETDS_T
5369             WHERE  batch_id = p_batch_id
5370             and    nvl(tds_section, 'No Section') = nvl(cd.tds_section, 'No Section')
5371             and    nvl(challan_num,'No Challan Number') = nvl(cd.challan_num, 'No Challan Number')
5372             and    nvl(challan_date, lv_dummy_date) = nvl(cd.challan_date, lv_dummy_date )
5373             and    nvl(bank_branch_code, 'No Bank Branch') = nvl(cd.bank_branch_code, 'No Bank Branch')
5374             and    consider_for_challan=1
5375             and    check_number = p_check_number
5376         group  by  base_vendor_id, base_vendor_site_id,tds_tax_id ;
5377    */
5378 
5379    /*ADDED BY CSAHOO FOR BUG#6158875*/
5380    CURSOR c_deductee_cnt(p_batch_id IN NUMBER ,
5381                           /* p_check_number IN NUMBER, - Commented for Bug 13323753 */
5382                          p_tds_section IN VARCHAR2 ,
5383                          p_challan_num IN varchar2,
5384                          p_challan_date IN DATE,
5385                          p_bank_branch_code IN VARCHAR2) IS
5386         select sum ( count(  distinct base_invoice_id ) )
5387         from JAI_AP_ETDS_T
5388         WHERE  batch_id = p_batch_id
5389         and    nvl(tds_section, 'No Section') = nvl(p_tds_section, 'No Section')
5390         and    nvl(challan_num,'No Challan Number') = nvl(p_challan_num, 'No Challan Number')
5391         and    nvl(challan_date, lv_dummy_date) = nvl(p_challan_date, lv_dummy_date )
5392         and    nvl(bank_branch_code, 'No Bank Branch') = nvl(p_bank_branch_code, 'No Bank Branch')
5393         and    consider_for_challan=1
5394         and    tds_invoice_id not in ( -9999, -9997) /* Bug#10315928 */ /* ER 13514846 */
5395         /* and    check_number = p_check_number - Commented for Bug 13323753 */
5396         group  by  base_vendor_id, base_vendor_site_id,tds_tax_id, base_invoice_id
5397     having sum(amt_of_tds) >0 /* Added having clause for Bug 13323753 */
5398     /* ER: 13514846 */
5399     union
5400     select sum ( count(  distinct base_invoice_id ) )
5401         from JAI_AP_ETDS_T
5402         WHERE  batch_id = p_batch_id
5406         and    nvl(bank_branch_code, 'No Bank Branch') = nvl(p_bank_branch_code, 'No Bank Branch')
5403         and    nvl(tds_section, 'No Section') = nvl(p_tds_section, 'No Section')
5404         and    nvl(challan_num,'No Challan Number') = nvl(p_challan_num, 'No Challan Number')
5405         and    nvl(challan_date, lv_dummy_date) = nvl(p_challan_date, lv_dummy_date )
5407         and    consider_for_challan=1
5408         and    tds_invoice_id = -9997
5409         group  by  base_vendor_id, base_vendor_site_id,tds_tax_id, base_invoice_id
5410     ;
5411     /*Bug 11896260 - Start*/
5412       CURSOR c_deductee_cnt_bt(p_batch_id IN NUMBER/* p_check_number IN NUMBER - Commented for Bug 13323753 */ ) IS
5413         select sum ( count( distinct base_invoice_id ) )
5414         from JAI_AP_ETDS_T
5415         WHERE  batch_id = p_batch_id
5416         and    nvl(tds_section, 'No Section') = nvl(cd.tds_section, 'No Section')
5417         and    nvl(challan_num,'No Challan Number') = nvl(cd.challan_num, 'No Challan Number')
5418         and    nvl(challan_date, lv_dummy_date) = nvl(cd.challan_date, lv_dummy_date )
5419         and    nvl(bank_branch_code, 'No Bank Branch') = nvl(cd.bank_branch_code, 'No Bank Branch')
5420         and    consider_for_challan=1
5421         /* and    check_number = p_check_number - Commented for Bug 13323753 */
5422         and    tds_invoice_id = -9999
5423         and    (tds_vendor_classification not in ('Transporter','Software') OR tds_vendor_classification IS NULL) /* Avanija for FVU3.6 */
5424         group  by  base_vendor_id, base_vendor_site_id, tds_tax_id;
5425       /*Bug 11896260 - End*/
5426     /* Bug#10315928 - Start */
5427 
5428 
5429        --Here merge cursor to support Software vendor
5430        --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
5431        -----------------------------------------------------------------------------
5432        --CURSOR c_deductee_cnt_trans(p_batch_id IN NUMBER) IS
5433        CURSOR c_deductee_cnt_trans(
5434                 p_batch_id IN NUMBER,
5435                 pv_vendor_classification in varchar2) --Commented by Zhhou for bug#15962641 20121205
5436        -----------------------------------------------------------------------------
5437        --Changed by Zhiwei for Bug#15840480  FVU3.6 end
5438        --CURSOR c_deductee_cnt_trans(p_batch_id IN NUMBER)--Added by Zhhou for bug#15962641 20121205 /* Commented by Avanija for FVU3.6 */
5439         is
5440         select sum ( count( distinct base_vendor_id ) )
5441         from jai_ap_etds_t
5442         WHERE  batch_id = p_batch_id
5443        -- and    nvl(tds_section, 'No Section') = nvl('SEC. 194(C)', 'No Section')
5444 	   --and    nvl(tds_section, 'No Section') =decode(pv_vendor_classification, 'Transporter', 'SEC. 194(C)','SEC. 194(J)') /* Avanija for FVU3.6 */ /* Commented for bug 15996337 */
5445         and    consider_for_challan=1
5446         --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
5447         -----------------------------------------------------------------------------
5448         --and    tds_vendor_classification = 'Transporter' /*Bug 11896260*/
5449         and    tds_vendor_classification = pv_vendor_classification --Commented by Zhhou for bug#15962641 20121205 /*Uncommented by Avanija for FVU3.6*/
5450         -----------------------------------------------------------------------------
5451         --Changed by Zhiwei for Bug#15840480  FVU3.6 end
5452         --Added by Zhhou for bug#15962641 20121205 begin
5453         -----------------------------------------------------------------------------
5454         --and    tds_vendor_classification in ('Transporter','Software') /* Commented by Avanija for FVU3.6 */
5455         -----------------------------------------------------------------------------
5456         --Added by Zhhou for bug#15962641 20121205 end
5457         and    tds_invoice_id = -9999
5458         group  by  base_vendor_id, base_vendor_site_id, tds_tax_id, base_invoice_id; /* Added base_invoice_id for bug 16002763 */
5459 
5460      /* cursor c_trans_vendor(p_vendor_id IN NUMBER) IS
5461       SELECT 'T'
5462       FROM jai_ap_tds_vendor_hdrs
5463       WHERE vendor_id = p_vendor_id;*/
5464 
5465       /* Bug#10315928 - End */
5466      CURSOR c_get_tds_gl_date(cp_invoice_id ap_invoices_all.invoice_id%type) IS
5467      SELECT gl_date
5468      FROM ap_invoices_all
5469      WHERE invoice_id = cp_invoice_id;
5470 
5471      ld_tds_gl_date date;
5472 
5473     CURSOR c_get_errors(cp_batch_id JAI_AP_ETDS_T.batch_id%TYPE ) IS
5474            Select Error_Message from jai_ap_etds_errors_t
5475    where batch_id = cp_batch_id ;
5476 
5477     -- File Header Variables
5478     v_line_number NUMBER(6); --File.Sql.35 Cbabu  := 0;
5479     v_record_type VARCHAR2(2);
5480     v_file_type   VARCHAR2(3) ; --:= 'TDS'      File.Sql.35 by Brathod
5481     v_quartfile_type   CHAR(3);
5482     v_upload_type VARCHAR2(1) ; --:= 'R'        File.Sql.35 by Brathod
5483     v_file_creation_date  Date; -- := SYSDATE   File.Sql.35 by Brathod
5484     v_file_sequence_number  NUMBER(8);
5485     v_deductor_tan      VARCHAR2(20);
5486     v_number_of_batches   NUMBER(4);    --File.Sql.35 Cbabu  := 1;
5487     v_return_prep_util  VARCHAR2(75);   /*Bug 8880543*/
5488     v_check_number      NUMBER; /*Bug 8880543*/
5489 
5490     -- Batch Header Variables
5491     v_batch_number  NUMBER(4);
5492     v_challan_cnt NUMBER(5);    --File.Sql.35 Cbabu  := 0;
5493     v_deductee_cnt  NUMBER(5); --File.Sql.35 Cbabu  := 0;
5494     v_form_number CHAR(4);
5495     v_rrr_number  NUMBER(10);
5496     v_rrr_date    CHAR(8);
5497     v_deductor_pan  VARCHAR2(200);
5498 
5499     v_quart_form_number VARCHAR2(3) ;
5500     v_deductor_branch VARCHAR2(75);
5501     v_deductor_email    VARCHAR2(75);
5502     v_deductor_stdCode      NUMBER(5);
5503     v_deductor_phoneNo varchar2(15);
5504     v_RespPerson_address2  VARCHAR2(25);
5505     v_RespPerson_address3  VARCHAR2(25);
5506     v_RespPerson_address4  VARCHAR2(25);
5507     v_RespPerson_address5  VARCHAR2(25);
5508     v_RespPerson_email     VARCHAR2(75);
5509     v_RespPerson_mobile    VARCHAR2(75);
5510     v_RespPerson_stdCode   INTEGER(5)  ;
5511     v_RespPerson_phoneNo   VARCHAR2(15) ;
5512     v_RespPerson_addressChange   VARCHAR2(1);
5513     v_bh_trnType  VARCHAR2(1) ;
5514     /* Bug#10315928 - Start */
5515     v_bh_orig_token VARCHAR2(1);
5516     v_bh_prev_token VARCHAR2(1);
5517     v_bh_token_number VARCHAR2(1);
5518     v_bh_token_date VARCHAR2(1);
5519     v_bh_receipt_no VARCHAR2(8);
5520     v_bh_unmatch_challan_cnt VARCHAR2(9);
5521    -- v_RespPerson_Mobileno VARCHAR2(75);
5522     /* Bug#10315928 - End */
5523     v_bh_batchUpd  VARCHAR2(1)  ;
5524     v_bh_org_RRRno  VARCHAR2(1)  ;
5525     v_bh_prev_RRRno  VARCHAR2(1) ;
5526     v_bh_RRRno  VARCHAR2(1) ;
5527     v_bh_RRRdate                       VARCHAR2(1)  ;
5528     v_bh_deductor_last_tan             VARCHAR2(1)  ;
5529     v_bh_tds_circle                    VARCHAR2(1)  ;
5530     v_bh_salaryRecords_count           VARCHAR2(1)  ;
5531     v_bh_gross_total                   VARCHAR2(1)  ;
5532     v_ao_approval                      VARCHAR2(1)  ;
5533     v_ao_approval_number               VARCHAR2(15);
5534     /*Bug 8880543 - Start*/
5535     v_last_deductor_type               VARCHAR2(1)  ;
5536     v_state_name                       VARCHAR2(240) ;/*Bug 12624907 changed varchar2(2) to varchar2*/
5537   /*Bug 12624907-Start*/
5538   cursor c_get_state_code (p_state_name in varchar2) is
5539   select flex_value
5540   from FND_FLEX_VALUES_VL a
5541   where flex_value_set_id =
5542          ( select flex_value_set_id
5543            from fnd_flex_value_sets
5544            where flex_value_set_name ='JA_IN_INDIAN_STATES'
5545          )
5546          and description= p_state_name;
5547    v_state_code varchar2(2);
5548    /*Bug 12624907 -end*/
5549     v_pao_code                         VARCHAR2(20) ;
5550     v_ddo_code                         VARCHAR2(20) ;
5551     v_ministry_name                    VARCHAR2(3)  ;
5552     v_ministry_name_other              VARCHAR2(150);
5553     v_pao_registration_no              NUMBER(10)   ;
5554     v_ddo_registration_no              VARCHAR2(10) ;
5555     v_challan_number                   VARCHAR2(10) ;
5556     v_return_message                   VARCHAR2(240);
5557     v_err                              VARCHAR2(1)  ;
5558     /*Bug 8880543 - End*/
5559     v_bh_recHash                       VARCHAR2(1)  ;
5560 v_regime_override number :=0; /*ETDS FVU3.1 Bug 11896260  */    -- Input Variables
5561     v_tds_vendor_id NUMBER;
5562     v_organization_id NUMBER;
5563 
5564     v_fin_year VARCHAR2(4);
5565     v_address_organization_id NUMBER;
5566     v_deductor_name VARCHAR2(75);
5567   /* Bug#10315928 - Start */
5568      v_deductor_ph_no number(10);
5569      v_RespPerson_ph_no number(10);
5570     /* Bug#10315928 - End */
5571     v_tan_state_code NUMBER(2);
5572     v_addrChangedSinceLastReturn VARCHAR2(1);
5573     v_deductor_type VARCHAR2(1);      /*Bug 8880543 - Modified Deductor Status to Deductor Type*/
5574     v_personNameRespForDedection VARCHAR2(75);
5575     v_personDesgnRespForDedection VARCHAR2(20);
5576     v_challan_start_date DATE;
5577     v_challan_end_date DATE;
5578 
5579     -- Derived variables
5580     -- v_tan_org_id NUMBER;
5581     v_org_id  NUMBER;
5582     v_financial_year VARCHAR2(6);
5583     v_assessment_year VARCHAR2(6);
5584     --v_legal_entity_id NUMBER;  -- Harshita for Bug 4889272
5585     v_location_id NUMBER;
5586     v_tan_pin     NUMBER(6);
5587     v_quarterlyOrYearly VARCHAR2(2); -- := 'Y';   -- as given by Vikram File.Sql.35 by Brathod
5588 
5589     -- added location_code and modified the types of address variables to refer table column types by Vijay Shankar for Bug#4057192
5590     v_location_code   HR_LOCATIONS_ALL.location_code%TYPE;
5591     v_tan_address1    HR_LOCATIONS_ALL.address_line_1%TYPE;
5592     v_tan_address2    HR_LOCATIONS_ALL.address_line_2%TYPE;
5593     v_tan_address3    HR_LOCATIONS_ALL.address_line_3%TYPE;
5594     v_tan_address4    VARCHAR2(75);
5595     v_tan_address5    VARCHAR2(75);
5596     v_postal_code     HR_LOCATIONS_ALL.postal_code%TYPE;
5597     v_totTaxDeductedAsPerChallan NUMBER;
5598     v_totTaxDeductedAsPerDeductee NUMBER := 0; /*Bug 10315928 - Initialize the Batch Total of - Total of Deposit Amount as per Challan*/
5599 
5600     v_challan_dtl_slno NUMBER;  --File.Sql.35 Cbabu  := 0;
5601     v_bank_branch_code VARCHAR2(7) ;
5602 
5603     v_deductee_slno NUMBER; --File.Sql.35 Cbabu  := 0;
5604     v_deductee_code VARCHAR2(2);
5605     v_deductee_pan  VARCHAR2(20);
5606   v_confirm_pan_flag VARCHAR2(1);/*ETDS FVU3.1 Bug 11896260  */
5607     v_stform_name VARCHAR2(25);
5608     v_vendor_name PO_VENDORS.vendor_name%TYPE;
5609     v_base_gl_date ap_invoices_all.gl_date%TYPE;/*Bug 10188600*/
5610     v_site_dtls   c_deductee_site_dtls%ROWTYPE;
5611     v_base_inv_check_dtls c_check_dtls%ROWTYPE;
5615     v_reason_for_nDeduction VARCHAR2(1);
5612     v_tds_inv_check_dtls  c_check_dtls%ROWTYPE;
5613     v_cert_issue_date   DATE;
5614     v_grossing_up_factor  VARCHAR2(1);
5616     v_filler        NUMBER(14);
5617 
5618     v_gl_date DATE;
5619     v_batch_id  NUMBER;
5620 
5621     v_ch_updIndicator         VARCHAR2(1)   ;
5622     v_filler1                 VARCHAR2(1)   ;
5623     v_filler2                 VARCHAR2(1)   ;
5624     v_filler3                 VARCHAR2(1)   ;
5625     v_filler4                 VARCHAR2(1)   ;
5626     v_last_bank_challan_no    VARCHAR2(1)   ;
5627     v_bank_challan_no         NUMBER(5) ;
5628     v_last_transfer_voucher_no VARCHAR2(1)   ;
5629     v_transfer_voucher_no     NUMBER(9) ;
5630     v_last_bank_branch_code   VARCHAR2(1)   ;
5631     v_challan_lastDate        VARCHAR2(1)   ;
5632     v_challan_Date        DATE ;
5633     v_filler5                 VARCHAR2(1)   ;
5634     v_filler6                 VARCHAR2(1)   ;
5635     v_last_total_depositAmt   VARCHAR2(1)   ;
5636 
5637     v_total_deposit           NUMBER(15,2) ;
5638     v_book_entry              VARCHAR2(1) ;
5639     v_ch_recHash              VARCHAR2(1)   ;
5640     v_nil_challan_indicator   VARCHAR2(1)   ;
5641     v_remarks                 VARCHAR2(14) ;
5642     v_remarks2               VARCHAR2(75);
5643     v_remarks3               VARCHAR2(14);
5644 
5645 
5646     v_quart_deductee_code        VARCHAR2(1) ;
5647     v_deductee_pan_refno         VARCHAR2(10);/*ETDS FVU3.1 Bug 11896260*/
5648     v_dh_mode                    VARCHAR2(1) ;
5649     v_emp_serial_no              VARCHAR2(1)   ;
5650     v_last_emp_pan               VARCHAR2(1)   ;
5651     v_last_emp_pan_refno         VARCHAR2(1)   ;
5652     v_deductee_total_tax_deducted NUMBER(15,2) ;
5653     v_last_total_tax_deducted    VARCHAR2(1)   ;
5654     v_deductee_total_tax_deposit NUMBER(15);
5655     v_last_total_tax_deposit     VARCHAR2(1)   ;
5656     v_total_purchase             VARCHAR2(1)   ;
5657     v_deposit_date               VARCHAR2(1)   ;
5658     v_grossingUp_ind             VARCHAR2(1)   ;
5659     v_certificate_issue_date     VARCHAR2(1)   ;  -- another declaration exists.
5660     v_dh_recHash                 VARCHAR2(1)   ;
5661     lv_etds_yearly_returns       VARCHAR2(1) ;
5662     v_challan_line_num           NUMBER ;
5663     ln_amt_of_tds                NUMBER(15,2) ;
5664         --v_tds_tax_rate               NUMBER(7);
5665     -- ended, Harshita for Bug 4525089
5666 
5667     v_ack_num_tan_app NUMBER(14);
5668     v_pro_rcpt_num_org_ret NUMBER(14);
5669     v_book_ent_oth VARCHAR2(1);
5670     v_quart_book_ent_oth VARCHAR2(1); -- Harshita for Bug 4525089,
5671     ln_amt_of_oth number(14);
5672 
5673     -- used variables
5674     --v_vendor_name PO_VENDORS.vendor_name%TYPE;
5675     v_vendor_site_code  PO_VENDOR_SITES_ALL.vendor_site_code%TYPE;
5676     v_error_message VARCHAR2(100);
5677     v_conc_request_id NUMBER(15); -- := FND_PROFILE.value('CONC_REQUEST_ID'); File.Sql.35 by Brathod
5678     v_statement_id VARCHAR2(3) ; --:= '0';  File.Sql.35 by Brathod
5679 
5680     v_start_date DATE;
5681     v_end_date DATE;
5682 
5683     v_uploader_type CHAR(1)      ;
5684     p_return_code    VARCHAR2(1) ;
5685     p_return_message VARCHAR2(2000) ;
5686     lv_generate_headers VARCHAR2(1) ;
5687     ln_errors_exist    NUMBER  ;
5688     DUMMY            VARCHAR2(1) ;
5689     v_fh_recordHash  VARCHAR2(1) ;
5690     v_fh_fvuVersion  VARCHAR2(1) ;
5691     v_fh_fileHash    VARCHAR2(1) ;
5692     v_fh_samVersion  VARCHAR2(1) ;
5693     v_fh_samHash     VARCHAR2(1) ;
5694     v_fh_scmVersion  VARCHAR2(1) ;
5695     v_fh_scmHash     VARCHAR2(1) ;
5696     v_fh_consFileHash  VARCHAR2(1) ;  /* ETDS FVU3.3 -Bug 13702172 */
5697     v_q_deductee_cnt NUMBER(9) ;
5698 
5699     ld_tds_inv_date  DATE; /*ER 13514846*/
5700     /*Bug 11896260 - Start*/
5701     /*Derive Challan Date based on Financial Year and Quarter if Challan Date is NULL*/
5702     ld_challan_date DATE;
5703     ld_nil_challan_date DATE; /*ER 13514846*/
5704     ln_ded_tax_rate NUMBER;
5705     v_bt_deductee_cnt NUMBER;
5706 
5707     FUNCTION derive_challan_date RETURN VARCHAR2
5708     IS
5709     ln_year VARCHAR2(4);
5710     BEGIN
5711       /* Comment out by Chong for eTDS bug#16414088 20130321
5712         SELECT to_char(start_date, 'YYYY') INTO ln_year
5713         FROM jai_ap_tds_years
5714         WHERE legal_entity_id = p_organization_id
5715         AND fin_year = p_fin_year;
5716         */
5717         ln_year := p_fin_year - 1;  --to_char(p_fin_year, 'YYYY'); --Added out by Chong for eTDS bug#16414088 20130321
5718 
5719         IF (p_period = 'Q1') THEN
5720             return '30-JUN-' || ln_year;
5721         ELSIF (p_period = 'Q2') THEN
5722             return '30-SEP-' || ln_year;
5723         ELSIF (p_period = 'Q3') THEN
5724             return '31-DEC-' || ln_year;
5725         ELSIF (p_period = 'Q4') THEN
5726             return '31-MAR-' || to_char(to_number(ln_year) + 1);
5727         END IF;
5728     END derive_challan_date;
5729     /*Bug 11896260 - End*/
5730 
5731     PROCEDURE process_deductee_records
5732     IS
5733     BEGIN
5734       /*START, Bgowrava for Bug#7662155*/
5735       IF c_deductee_records%ISOPEN THEN
5736        CLOSE c_deductee_records ;
5737       END IF;
5738       /*END, Bgowrava for Bug#7662155*/
5739       OPEN c_deductee_records(v_batch_id, v_challan_line_num) ;
5740       LOOP
5741       FETCH c_deductee_records INTO dd ;
5742       EXIT WHEN
5743       c_deductee_records%NOTFOUND ;
5744     v_confirm_pan_flag := null;/*ETDS FVU3.1 Bug 11896260  */
5745 
5746       v_vendor_name := null;
5747       v_deductee_code := null;
5748       v_deductee_pan := null;
5749       v_site_dtls := null;
5750       --v_tds_inv_check_dtls := null;
5751       --v_base_inv_check_dtls := null;
5752       v_reason_for_nDeduction := null;
5753       v_filler := null;
5754       v_deductee_state_code := null;
5755       --v_gl_date := null;
5756       v_reason_for_nDeduction := null;
5757       v_stform_name :=null;
5758       --v_tds_tax_rate := null;
5759 
5760       v_line_number := v_line_number + 1;
5761       v_deductee_slno := v_deductee_slno + 1;
5762 
5763       OPEN c_deductee_dtls(dd.base_vendor_id);
5764       FETCH c_deductee_dtls INTO v_vendor_name, v_deductee_code;
5765       CLOSE c_deductee_dtls;
5766 
5767       OPEN c_deductee_pan(dd.base_vendor_id, dd.base_vendor_site_id);
5768       FETCH c_deductee_pan INTO v_deductee_pan,v_confirm_pan_flag;/*ETDS FVU3.1 Bug 11896260*/
5769       CLOSE c_deductee_pan;
5770 
5771       -- START code added for Bug#3841751 as PAN # was not printed, if it setup only at null site
5772       IF v_deductee_pan IS NULL THEN
5773        OPEN c_deductee_pan(dd.base_vendor_id, 0);
5774        FETCH c_deductee_pan INTO v_deductee_pan,v_confirm_pan_flag;/*ETDS FVU3.1 Bug 11896260*/
5775        CLOSE c_deductee_pan;
5776       END IF;
5777       -- END code added for Bug#3841751
5778 /*start- eTDS FVU3.1 Bug 11896260*/
5779       v_deductee_pan_refno := NULL;
5780          if (nvl(v_confirm_pan_flag,'N') = 'N' and v_deductee_pan is not null) then
5781      v_deductee_pan_refno := v_deductee_pan;
5782      v_deductee_pan := 'PANAPPLIED';
5783      end if;
5784      /*end- eTDS FVU3.1 Bug 11896260*/
5785       OPEN c_deductee_site_dtls(dd.base_vendor_id, dd.base_vendor_site_id);
5786       FETCH c_deductee_site_dtls INTO v_site_dtls;
5787       CLOSE c_deductee_site_dtls;
5788 
5789       OPEN c_state_code(v_site_dtls.state,'IN_STATE');
5790       FETCH c_state_code INTO v_deductee_state_code;
5791       CLOSE c_state_code;
5792 
5793       IF v_deductee_state_code IS NULL THEN
5794         v_deductee_state_code := 99;
5795       END IF;
5796 
5797       /*ER 13514846*/
5798       --OPEN c_reason_non_deduction(dd.tds_tax_id);   --Commented out by Chong for eTDS ER bug#16414088 20130330  As we save tax category ID in eTDS temp table.
5799       OPEN  c_reason_non_deduction(dd.tds_section);  --Commented out by Chong for eTDS ER bug#16414088 20130330   We should derive by section code.
5800       FETCH c_reason_non_deduction INTO v_reason_for_nDeduction;
5801       CLOSE c_reason_non_deduction;
5802 
5803       IF v_deductee_pan IN ('PANNOTAVBL', 'PANAPPLIED') THEN
5804         v_reason_for_nDeduction := 'C';
5805       END IF;
5806 
5807       /*Bug 11896260 - Start*/
5808       IF (dd.tds_invoice_id not in ( -9999, -9997)) THEN /* Er :13514846 */
5809         OPEN c_get_tds_gl_date(dd.tds_invoice_id);
5810         FETCH c_get_tds_gl_date INTO ld_tds_gl_date;
5811         CLOSE c_get_tds_gl_date;
5812       ELSIF dd.tds_invoice_id = -9999 then /* modifeid else to elsif :ER :13514846 */
5813         ld_tds_gl_date := dd.tds_invoice_date;
5814         v_reason_for_nDeduction := 'Y';
5815       END IF;
5816       /*Bug 11896260 - End*/
5817       v_book_ent_oth := 'C';
5818 
5819       IF lv_etds_yearly_returns = 'Y' THEN -- Harshita for Bug 4525089
5820        jai_ap_tds_etds_pkg.create_deductee_detail
5821        (
5822           p_line_number         =>   v_line_number,
5823           p_record_type         =>   v_record_type,
5824           p_batch_number        =>   v_batch_number,
5825           p_deductee_slno       =>   v_deductee_slno,
5826           p_deductee_section    =>   dd.tds_section,
5827           p_deductee_code       =>   v_deductee_code,
5828           p_deductee_pan        =>   v_deductee_pan,
5829           p_deductee_name       =>   v_vendor_name,
5830           p_deductee_address1   =>   v_site_dtls.addr1,
5831           p_deductee_address2   =>   v_site_dtls.addr2,
5832           p_deductee_address3   =>   v_site_dtls.addr3,
5833           p_deductee_address4   =>   v_site_dtls.addr4,
5834           p_deductee_address5   =>   v_site_dtls.city,
5835           p_deductee_state      =>   v_deductee_state_code,
5836           p_deductee_pin        =>   v_site_dtls.zip,
5837           p_filler5             =>   v_filler,
5838           p_payment_amount      =>   dd.base_taxabale_amount,
5839           p_payment_date        =>   dd.tds_invoice_date,--dd.base_invoice_date, /*Changed challan_date to base_invoice_date - Forward Port Bug 6329774*/
5840           /*Bug 10188600,commented the above line and modified*/
5841           p_book_ent_oth        =>   v_book_ent_oth,
5842           p_tax_rate            =>   dd.tds_tax_rate,
5843           p_filler6             =>   v_filler6,
5844           p_tax_deducted        =>   dd.tds_amount,
5845           p_tax_deducted_date   =>   dd.tds_invoice_date,
5846           p_tax_payment_date    =>   dd.tds_check_date,
5847           p_bank_branch_code    =>   dd.bank_branch_code,
5848           p_challan_no            =>   dd.challan_num,
5849           p_tds_certificate_date  =>   dd.certificate_issue_date,
5850           p_reason_for_nDeduction =>   v_reason_for_nDeduction,
5851           p_filler7               =>   v_filler
5852 
5853        );
5854       ELSE
5855        IF v_deductee_code = '01' THEN
5856          v_quart_deductee_code := '1' ;
5857        ELSIF v_deductee_code = '02' THEN
5858          v_quart_deductee_code := '2' ;
5859        END IF ;
5860 
5861        v_deductee_total_tax_deducted := dd.amt_of_tds + dd.amt_of_surcharge + dd.amt_of_cess ;
5862        v_quart_book_ent_oth := 'N' ;
5863 
5864       p_return_code    := null ;
5865       p_return_message := null ;
5866 
5867       jai_ap_tds_etds_pkg.validate_deductee_detail
5868        ( p_line_number                   => v_line_number  ,
5869          p_record_type                   => v_record_type  ,
5870          p_batch_number                  => v_batch_number ,
5871          p_challan_line_num              => dd.challan_line_num   ,
5872          p_deductee_slno                 => v_deductee_slno  ,
5873          p_dh_mode                       => v_dh_mode  ,
5874          p_quart_deductee_code           => v_quart_deductee_code  ,
5875          p_deductee_pan                  => v_deductee_pan ,
5876          p_vendor_name                   => v_vendor_name  ,
5877          p_amt_of_tds                    => dd.amt_of_tds  ,
5878          p_amt_of_surcharge              => dd.amt_of_surcharge   ,
5879          p_amt_of_cess                   => dd.amt_of_cess   ,
5880          p_deductee_total_tax_deducted   => v_deductee_total_tax_deducted,
5881          p_base_taxabale_amount          => dd.base_taxabale_amount ,
5882          p_gl_date                       => dd.tds_invoice_date, --dd.base_invoice_date  ,  /*Changed challan_date to base_invoice_date - Forward Port Bug 6329774*/
5883 /*Bug 10188600,commented the above line and modified*/
5884          p_book_ent_oth                  => v_book_ent_oth,
5885          p_return_code                   => p_return_code,
5886          p_return_message                => p_return_message
5887        );
5888       IF p_return_code = 'E' THEN
5889        IF lv_action = 'V' THEN
5890         insert into jai_ap_etds_errors_t
5891          (batch_id, record_type,  reference_id, error_message) values
5892         ( v_batch_id,'DD', v_line_number, p_return_message ) ; /*Bug 8880543 - Modified ln_batch_id to v_batch_id*/
5893        ELSE
5894         p_ret_code := jai_constants.request_error ;
5895         p_err_buf := p_return_message ;
5896         RETURN ;
5897        END IF ;
5898       END IF ;
5899     lv_generate_headers := null ;
5900       IF p_action <> 'V' THEN
5901        IF p_action = 'F' THEN
5902          lv_generate_headers := 'N' ;
5903        ELSIF p_action = 'H' THEN
5904          lv_generate_headers := 'Y' ;
5905        END IF ;
5906 
5907        /*Bug 11896260 - Tax Rate must be 0.0000 if Total Income Tax Deducted at Source is 0.00*/
5908        IF (v_deductee_total_tax_deducted IS NULL OR v_deductee_total_tax_deducted = 0) THEN
5909         ln_ded_tax_rate := 0;
5910        ELSE
5911         ln_ded_tax_rate := dd.tds_tax_rate;
5912        END IF;
5913        /*Bug 11896260 - End*/
5914        /*ER - 13514846 - TDS Invoice Date must be NULL if No Tax is deducted*/
5915        IF (v_deductee_total_tax_deducted = 0) THEN
5916         ld_tds_inv_date := NULL;
5917        ELSE
5918         ld_tds_inv_date := dd.tds_invoice_date;
5919        END IF;
5920        /*ER 13514846 - End*/
5921        jai_ap_tds_etds_pkg.create_quart_deductee_dtl
5922        (
5926          p_dh_challan_recNo              => v_challan_dtl_slno,
5923          p_line_number                   => v_line_number,
5924          p_record_type                   => v_record_type,
5925          p_batch_number                  => v_batch_number,
5927          p_deductee_slno                 => v_deductee_slno,
5928          p_dh_mode                       => v_dh_mode,
5929          p_emp_serial_no                 => v_emp_serial_no,
5930          p_deductee_code                 => v_quart_deductee_code,
5931          p_last_emp_pan                  => v_last_emp_pan,
5932          p_deductee_pan                  => v_deductee_pan,
5933          p_last_emp_pan_refno            => v_last_emp_pan_refno,
5934          p_deductee_pan_refno            => v_deductee_pan_refno,
5935          p_vendor_name                   => v_vendor_name,
5936          p_deductee_tds_income_tax       => dd.amt_of_tds ,
5937          p_deductee_tds_surcharge        => dd.amt_of_surcharge,
5938          p_deductee_tds_cess             => dd.amt_of_cess,
5939          p_deductee_total_tax_deducted   => v_deductee_total_tax_deducted,
5940          p_last_total_tax_deducted       => v_last_total_tax_deducted,
5941          p_deductee_total_tax_deposit    => v_deductee_total_tax_deducted,
5942          p_last_total_tax_deposit        => v_last_total_tax_deposit,
5943          p_total_purchase                => v_total_purchase,
5944          p_base_taxabale_amount          => dd.base_taxabale_amount,
5945          p_gl_date                       => dd.tds_invoice_date, --dd.base_invoice_date,   /*Changed challan_date to base_invoice_date - Forward Port Bug 6329774*/
5946 /*Bug 10188600,commented the above line and modified*/
5947          p_tds_invoice_date              => ld_tds_inv_date, /*ER 13514846*/
5948          p_deposit_date                  => v_deposit_date,
5949          p_tds_tax_rate                  => ln_ded_tax_rate, --v_tds_tax_rate, /*Bug 11896260*/
5950          p_grossingUp_ind                => v_grossingUp_ind,
5951          p_book_ent_oth                  => v_quart_book_ent_oth,
5952          p_certificate_issue_date        => v_certificate_issue_date,
5953          p_remarks1                      => v_reason_for_nDeduction, -- VIJAY REVIEW v_remarks1,
5954          p_remarks2                      => v_remarks2,
5955          p_remarks3                      => v_remarks3,
5956          p_dh_recHash                    => v_dh_recHash,
5957          p_generate_headers              => lv_generate_headers
5958         );
5959 
5960         END IF ;
5961 
5962       END IF ;
5963 
5964       UPDATE JAI_AP_ETDS_T
5965       SET deductee_line_num = v_line_number
5966       WHERE batch_id = v_batch_id
5967        and consider_for_challan=1
5968        and challan_line_num                          = dd.challan_line_num
5969        and base_vendor_id                            = dd.base_vendor_id
5970        and base_vendor_site_id                       = dd.base_vendor_site_id
5971        and tds_tax_id                                = dd.tds_tax_id
5972        and NVL(tds_section,'No Section')             = NVL(dd.tds_section,'No Section')
5973        and NVL(bank_branch_code,'No Bank Branch')    = NVL(dd.bank_branch_code,'No Bank Branch')
5974        and NVL(challan_num,'No Challan Number')      = NVL(dd.challan_num,'No Challan Number')
5975        and NVL(challan_date,lv_dummy_date)           = NVL(dd.challan_date,lv_dummy_date)
5976        /*and check_number                              = dd.check_number --commented for Bug 13323753 */
5977        and tds_tax_rate                              = dd.tds_tax_rate ;
5978 
5979         END LOOP;
5980 
5981         CLOSE c_deductee_records ;
5982       END process_deductee_records;
5983 
5984     /* Bug#10315928 - Start */
5985       --Change internal procedure here to support Software vendor.
5986       --Changed by Zhiwei for Bug#15840480 FVU3.6 end
5987       -------------------------------------------------------------------------------
5988       --PROCEDURE process_deductee_records_trans()
5989       PROCEDURE process_deductee_records_trans(pv_vendor_classification in varchar2)
5990       -------------------------------------------------------------------------------
5991       --Changed by Zhiwei for Bug#15840480 FVU3.6 end
5992 
5993       IS
5994       BEGIN
5995         IF c_deductee_records_trans%ISOPEN THEN
5996           CLOSE c_deductee_records_trans ;
5997         END IF ;
5998         --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
5999         -----------------------------------------------------------------------
6000 
6001         --OPEN c_deductee_records_trans(v_batch_id, v_challan_line_num) ;
6002         OPEN c_deductee_records_trans(
6003               v_batch_id,
6004               v_challan_line_num,
6005               pv_vendor_classification
6006               ) ;
6007         -----------------------------------------------------------------------
6008         --Changed by Zhiwei for Bug#15840480  FVU3.6 end
6009 
6010         LOOP
6011          FETCH c_deductee_records_trans INTO dd_t ;
6012          EXIT WHEN
6013           c_deductee_records_trans%NOTFOUND ;
6014           v_confirm_pan_flag := null;/*ETDS FVU3.1 Bug 11896260  */
6015           v_vendor_name := null;
6016           v_deductee_code := null;
6017           v_deductee_pan := null;
6018           v_site_dtls := null;
6019           v_reason_for_nDeduction := null;
6020           v_filler := null;
6021           v_deductee_state_code := null;
6022           v_reason_for_nDeduction := null;
6023           v_stform_name :=null;
6024           v_line_number := v_line_number + 1;
6025           v_deductee_slno := v_deductee_slno + 1;
6026 
6027           /*Start-Bug 10188600*/
6028           OPEN get_gl_date(dd_t.base_invoice_id);
6029           FETCH get_gl_date INTO v_base_gl_date;
6030           CLOSE get_gl_date;
6031           /*End-Bug 10188600*/
6032 
6033           OPEN c_deductee_dtls(dd_t.base_vendor_id);
6034           FETCH c_deductee_dtls INTO v_vendor_name, v_deductee_code;
6035           CLOSE c_deductee_dtls;
6036 
6037           OPEN c_deductee_pan(dd_t.base_vendor_id, dd_t.base_vendor_site_id);
6038           FETCH c_deductee_pan INTO v_deductee_pan, v_confirm_pan_flag;/*ETDS FVU3.1 Bug 11896260  */
6039           CLOSE c_deductee_pan;
6040 
6041           IF v_deductee_pan IS NULL THEN
6042             OPEN c_deductee_pan(dd_t.base_vendor_id, 0);
6043             FETCH c_deductee_pan INTO v_deductee_pan, v_confirm_pan_flag;/*ETDS FVU3.1 Bug 11896260  */
6044             CLOSE c_deductee_pan;
6045           END IF;
6046 /*start- eTDS FVU3.1 Bug 11896260*/
6047          v_deductee_pan_refno := NULL;
6048          if (nvl(v_confirm_pan_flag,'N') = 'N' and v_deductee_pan is not null) then
6049      v_deductee_pan_refno := v_deductee_pan;
6050      v_deductee_pan := 'PANAPPLIED';
6051      end if;
6052      /*end- eTDS FVU3.1 Bug 11896260*/
6053           OPEN c_deductee_site_dtls(dd_t.base_vendor_id, dd_t.base_vendor_site_id);
6054           FETCH c_deductee_site_dtls INTO v_site_dtls;
6055           CLOSE c_deductee_site_dtls;
6056 
6057           OPEN c_state_code(v_site_dtls.state, 'IN_STATE');
6058           FETCH c_state_code INTO v_deductee_state_code;
6059           CLOSE c_state_code;
6060 
6061           IF v_deductee_state_code IS NULL THEN
6062 
6063             v_deductee_state_code := 99;
6064 
6065           END IF;
6066 
6067           --Here is remark1 , display S for software
6068           --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
6069           ---------------------------------------------
6070           -- v_reason_for_nDeduction := 'T';
6071           IF pv_vendor_classification = 'Transporter' THEN
6072               v_reason_for_nDeduction := 'T';
6073           ELSIF pv_vendor_classification = 'Software' THEN
6074               v_reason_for_nDeduction := 'S';
6075           END IF;
6076           ---------------------------------------------
6077           --Changed by Zhiwei for Bug#15840480  FVU3.6 end
6078 
6079           v_book_ent_oth := 'C';
6080 
6081           IF lv_etds_yearly_returns = 'Y' THEN
6082             jai_ap_tds_etds_pkg.create_deductee_detail(v_line_number, v_record_type,
6083               v_batch_number, v_deductee_slno, dd_t.tds_section, v_deductee_code,
6084               v_deductee_pan, v_vendor_name, v_site_dtls.addr1, v_site_dtls.addr2,
6085               v_site_dtls.addr3, v_site_dtls.addr4, v_site_dtls.city,
6086               v_deductee_state_code, v_site_dtls.zip, v_filler,  dd_t.base_taxabale_amount,
6087               dd_t.base_invoice_date,
6088               v_book_ent_oth, dd_t.tds_tax_rate,  v_filler6,
6089               dd_t.tds_amount, dd_t.tds_invoice_date, dd_t.tds_check_date,
6090               dd_t.bank_branch_code, dd_t.challan_num, dd_t.certificate_issue_date, v_reason_for_nDeduction, v_filler
6091             );
6092           ELSE
6093             IF v_deductee_code = '01' THEN
6094               v_quart_deductee_code := '1' ;
6095             ELSIF v_deductee_code = '02' THEN
6096               v_quart_deductee_code := '2' ;
6097             END IF ;
6098 
6099             v_deductee_total_tax_deducted := dd_t.amt_of_tds + dd_t.amt_of_surcharge + dd_t.amt_of_cess ;
6100             v_quart_book_ent_oth := 'N' ;
6101 
6102             lv_generate_headers := null ;
6103             IF p_action <> 'V' THEN
6104               IF p_action = 'F' THEN
6105                 lv_generate_headers := 'N' ;
6106               ELSIF p_action = 'H' THEN
6107                 lv_generate_headers := 'Y' ;
6108               END IF ;
6109               /*Bug 11896260 - Tax Rate must be 0.0000 if Total Income Tax Deducted at Source is 0.00*/
6110               IF (v_deductee_total_tax_deducted IS NULL OR v_deductee_total_tax_deducted = 0) THEN
6111                ln_ded_tax_rate := 0;
6112               ELSE
6113                ln_ded_tax_rate := dd_t.tds_tax_rate;
6114               END IF;
6115               /*Bug 11896260 - End*/
6116               jai_ap_tds_etds_pkg.create_quart_deductee_dtl
6117               (
6118                 p_line_number                   => v_line_number,
6119                 p_record_type                   => v_record_type,
6120                 p_batch_number                  => v_batch_number,
6121                 p_dh_challan_recNo              => v_challan_dtl_slno,
6122                 p_deductee_slno                 => v_deductee_slno,
6123                 p_dh_mode                       => v_dh_mode,
6124                 p_emp_serial_no                 => v_emp_serial_no,
6125                 p_deductee_code                 => v_quart_deductee_code,
6126                 p_last_emp_pan                  => v_last_emp_pan,
6127                 p_deductee_pan                  => v_deductee_pan,
6128                 p_last_emp_pan_refno            => v_last_emp_pan_refno,
6129                 p_deductee_pan_refno            => v_deductee_pan_refno,
6130                 p_vendor_name                   => v_vendor_name,
6131                 p_deductee_tds_income_tax       => dd_t.amt_of_tds ,
6132                 p_deductee_tds_surcharge        => dd_t.amt_of_surcharge,
6133                 p_deductee_tds_cess             => dd_t.amt_of_cess,
6134                 p_deductee_total_tax_deducted   => v_deductee_total_tax_deducted,
6135                 p_last_total_tax_deducted       => v_last_total_tax_deducted,
6136                 p_deductee_total_tax_deposit    => v_deductee_total_tax_deducted,
6137                 p_last_total_tax_deposit        => v_last_total_tax_deposit,
6138                 p_total_purchase                => v_total_purchase,
6139                 p_base_taxabale_amount          => dd_t.base_taxabale_amount,
6140                 p_gl_date                       => v_base_gl_date,--dd_t.base_invoice_date,/*Bug 10188600*/
6141                 p_tds_invoice_date              => NULL,
6142                 p_deposit_date                  => v_deposit_date,
6143                 p_tds_tax_rate                  => ln_ded_tax_rate, /*Bug 11896260*/
6144                 p_grossingUp_ind                => v_grossingUp_ind,
6145                 p_book_ent_oth                  => v_quart_book_ent_oth,
6146                 p_certificate_issue_date        => v_certificate_issue_date,
6147                 p_remarks1                      => v_reason_for_nDeduction,
6148                 p_remarks2                      => v_remarks2,
6149                 p_remarks3                      => v_remarks3,
6150                 p_dh_recHash                    => v_dh_recHash,
6151                 p_generate_headers              => lv_generate_headers
6152                );
6153 
6154             END IF ;
6155 
6156           END IF ;
6157 
6158           UPDATE jai_ap_etds_t
6159           SET deductee_line_num = v_line_number
6160           WHERE batch_id = v_batch_id
6161             and consider_for_challan=1
6162             and tds_invoice_id                            = -9999
6163             and challan_line_num                          = dd_t.challan_line_num
6164             and base_vendor_id                            = dd_t.base_vendor_id
6165             and base_vendor_site_id                       = dd.base_vendor_site_id
6166             and tds_tax_id                                = dd_t.tds_tax_id
6167             and NVL(tds_section,'No Section')             = NVL(dd_t.tds_section,'No Section')
6168             and NVL(bank_branch_code,'No Bank Branch')    = NVL(dd_t.bank_branch_code,'No Bank Branch')
6169             and NVL(challan_num,'No Challan Number')      = NVL(dd_t.challan_num,'No Challan Number')
6170             and NVL(challan_date,lv_dummy_date)           = NVL(dd_t.challan_date,lv_dummy_date)
6171             /* and nvl(check_number,'No Check Number')       = nvl(dd_t.check_number,'No Check Number') --commnented for Bug 13323753 */
6172             and tds_tax_rate                              = dd_t.tds_tax_rate
6173             --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
6174             ---------------------------------------------------------------
6175             --and tds_vendor_classification = 'Transporter';
6176             and tds_vendor_classification = pv_vendor_classification;
6177             ---------------------------------------------------------------
6178             --Changed by Zhiwei for Bug#15840480  FVU3.6 end
6179 
6180 
6181         END LOOP;
6182 
6183         CLOSE c_deductee_records_trans ;
6184       END process_deductee_records_trans;
6185     /* Bug#10315928 - End*/
6186 
6187   BEGIN
6188 
6189   /*---------------------------------------------------------------------------------------------------------------------------------
6190   change history for ja_in_ap_generate_etds_p.sql
6191 
6192   SlNo.  DD/MM/YYYY       Author and Details of Modifications
6193   ---------------------------------------------------------------------------------------------------------------------------------
6194   1      22/03/2004  Vijay Shankar for Bug# 3463974, Version: 619.1
6195                       This procedure is created for enhancement to generate eTDS Flat file by making calls to jai_ap_tds_etds_pkg package
6196 
6197   2      13/04/2004  Vijay Shankar for Bug# 3603545 (also fixed 3567864), Version: 619.2
6198                       Fixed the issues
6199                         deductee state code - Using lookup codes in FND_COMMON_LOOKUPS with lookup_type = 'IN_STATE'
6200                         Deductee payment date - old date among GL_DATE of invoice and check_date
6201                         reason for non deduction - populating A if stform_type of tds tax is 197 and B if 197A and null if others
6202                       Also incorporated few error checks and raising errors with relevant message
6203 
6204   3      21/06/2004  Aparajita for bug#3708878. Version 115.1.
6205                       If more than one TDS invoice has been paid by the same challan, then the challan
6206                       details were getting repeated as many times as the number of invoices that has been
6207                       grouped for payment. Changed the code to group by challan number and date.
6208 
6209   4      02/09/2004  Sanjikum for bug#3841751. Version 115.2.
6210                       Issue:-
6211                         ETDS CONCURRENT DOES NOT SHOW PAN # IF THE SAME IS SETUP ONLY AT NULL SITE.
6212 
6213                       Reason:-
6214                         TDS Transactions can take place even if setup is maintained only at null
6215                         site level without setup at Site level. So for such transactions, no pan# is displayed
6216                       Fix:-
6217                         In the cursor - c_deductee_pan added the check that if there is no row returned,
6218                         then open the same cursor again for vendor_site_id = 0
6222                       rectified with this fix by showing proper message on Postal Code attached to Address Location
6219 
6220   5      12/12/2004  Vijay Shankar for Bug#4057192. Version 115.3
6221                       When postal Code is not a number or number with more that 6 digits, then the application is erroring. which is
6223 
6224 
6225   6.     2/05/2005   rchandan for bug#4323338. Version 116.1
6226                      India Org Info DFF is eliminated as a part of JA migration. A table by name ja_in_ap_tds_org_tan is dropped
6227                      and a view jai_ap_tds_org_tan_v is created to capture the PAN No,TAN NO and WARD NO. The code changes are done
6228                      to refer to the new view instead of the dropped table.
6229 
6230   7.    8/05/2005    rchandan for bug#4333488. Version 116.1
6231                      The Invoice Distribution DFF is eliminated and a new global DFF is used to
6232                      maintain the functionality. From now the TDS tax, WCT tax and ESSI will not
6233                      be populated in the attribute columns of ap_invoice_distributions_all table
6234                      instead these will be populated in the global attribute columns. So the code changes are
6235                      made accordingly.Both Payment and India distributions DFF elimintion is taken care of in
6236                      the same version.
6237 
6238  8.  19/05/2005     rallamse for Bug#4336482, Version 116.2
6239                     For SEED there is a change in concurrent to use FND_STANDARD_DATE with STANDARD_DATE format
6240                     Procedure  signature modified by converting DATE datatype
6241                     to varchar2 datatype. The varchar2 values are converted to DATE fromat
6242                     using fnd_date.canonical_to_date function.
6243 
6244  9.  13/07/2007     CSahoo for bug#6158875, File Version 120.12
6245                      replaced the AND with OR in the update statement.
6246 
6247 
6248 
6249 
6250 
6251   Future Dependencies For the release Of this Object:-
6252   (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/
6253   A datamodel change )
6254 
6255   ----------------------------------------------------------------------------------------------------------------------------------------------------
6256   Current Version       Current Bug    Dependent           Files              Version   Author   Date         Remarks
6257   Of File                              On Bug/Patchset    Dependent On
6258   jai_ap_rpt_apcr_pkg.compute_credit_balance.sql
6259   ----------------------------------------------------------------------------------------------------------------------------------------------------
6260   115.1                 3708878        IN60105D2+3603545  jai_ap_tds_etds_pkg.sql         Apdas    25/06/2004
6261 
6262   ---------------------------------------------------------------------------------------------------------------------------------------------------
6263 
6264   ---------------------------------------------------------------------------------------------------------------------------------*/
6265        DUMMY := null ;
6266        v_fh_recordHash := DUMMY ;
6267        v_fh_fvuVersion := DUMMY ;
6268        v_fh_fileHash   := DUMMY ;
6269        v_fh_samVersion := DUMMY ;
6270        v_fh_samHash    := DUMMY ;
6271        v_fh_scmVersion := DUMMY ;
6272        v_fh_scmHash    := DUMMY ;
6273      v_fh_consFileHash := DUMMY ; /* ETDS FVU3.3 - Bug 13702172 */
6274        v_bh_trnType  := DUMMY ;
6275        /* Bug#10315928 - Start */
6276        v_bh_orig_token := DUMMY;
6277        v_bh_prev_token := DUMMY;
6278        v_bh_token_number := DUMMY;
6279        v_bh_token_date := DUMMY;
6280        v_bh_receipt_no := DUMMY;
6281        v_bh_unmatch_challan_cnt := DUMMY;
6282        /* Bug#10315928 - End */
6283        v_bh_batchUpd   := DUMMY ;
6284        v_bh_org_RRRno   := DUMMY ;
6285        v_bh_prev_RRRno  := DUMMY ;
6286        v_bh_RRRno  := DUMMY ;
6287        v_bh_RRRdate                      := DUMMY ;
6288        v_bh_deductor_last_tan            := DUMMY ;
6289        v_bh_tds_circle                   := DUMMY ;
6290        v_bh_salaryRecords_count          := DUMMY ;
6291        v_bh_gross_total                  := DUMMY ;
6292        v_bh_recHash                      := DUMMY ;
6293        v_ch_updIndicator           := DUMMY ;
6294        v_filler1                   := DUMMY ;
6295        v_filler2                   := DUMMY ;
6296        v_filler3                   := DUMMY ;
6297        v_filler4                   := DUMMY ;
6298        v_last_bank_challan_no      := DUMMY ;
6299        v_last_transfer_voucher_no   := DUMMY ;
6300        v_last_bank_branch_code     := DUMMY ;
6301        v_challan_lastDate          := DUMMY ;
6302        v_filler5                   := DUMMY ;
6303        v_filler6                   := DUMMY ;
6304        v_last_total_depositAmt     := DUMMY ;
6305        v_ch_recHash                := DUMMY ;
6306        v_emp_serial_no                := DUMMY ;
6307        v_last_emp_pan                 := DUMMY ;
6308        v_last_emp_pan_refno           := DUMMY ;
6309        v_last_total_tax_deducted      := DUMMY ;
6310        v_last_total_tax_deposit       := DUMMY ;
6311        v_total_purchase               := DUMMY ;
6312        v_deposit_date                 := DUMMY ;
6313        v_grossingUp_ind               := DUMMY ;
6314        v_certificate_issue_date       := DUMMY ;
6315        v_dh_recHash                   := DUMMY ;
6316        lv_action                      := p_action   ;
6317 
6318     lv_object_name     := 'jai_ap_tds_etds_pkg.generate_flat_file'; /* Added by Ramananda for bug#4407165 */
6319 
6320 
6321     v_upload_type           := 'R'    ;
6322     v_file_creation_date    := SYSDATE  ;
6323     v_quarterlyOrYearly     :='Y';
6324     v_conc_request_id       := FND_PROFILE.value('CONC_REQUEST_ID') ;-- File.Sql.35 by Brathod
6325     p_challan_Start_Date    := fnd_date.canonical_to_date(pv_challan_Start_Date);
6329     v_challan_cnt           := 0;
6326     p_challan_End_Date      := fnd_date.canonical_to_date(pv_challan_End_Date);
6327     v_line_number           := 0;
6328     v_number_of_batches     := 1;
6330     v_deductee_cnt          := 0;
6331     v_challan_dtl_slno      := 0;
6332     v_deductee_slno         := 0;
6333 
6334     lv_dummy_date    := SYSDATE-1000;
6335     v_file_type    := 'NS3' ;
6336     v_quartfile_type   := 'NS1';
6337     v_upload_type  := 'R';
6338     v_uploader_type  := 'D';
6339 
6340     v_ao_approval     := 'N';
6341     v_nil_challan_indicator    := 'N' ;
6342     v_dh_mode                     := 'O' ;
6343     v_statement_id := '0';
6344 
6345     -- v_quart_form_number  := '26Q';
6346      v_quart_form_number  := p_form_number; --Date 11-05-2007 by Sacsethi for bug 5647248
6347 
6348     SELECT JAI_AP_ETDS_T_S.nextval INTO v_batch_id FROM DUAL;
6349 
6350     IF NVL(p_action,'X') <> 'V' THEN
6351       IF NVL(p_generate_headers,'X') = 'Y' or NVL(p_action,'X') = 'H' THEN
6352         jai_ap_tds_etds_pkg.v_debug_pad_char := ' ';
6353         jai_ap_tds_etds_pkg.v_generate_headers := TRUE;
6354       ELSE
6355         jai_ap_tds_etds_pkg.v_debug_pad_char := '';
6356         jai_ap_tds_etds_pkg.v_generate_headers := FALSE;
6357       END IF;
6358     END IF;
6359 
6360 
6361    IF NVL(p_period,'XX') = 'XX' THEN
6362      /*Commented out by Chong for eTDS, remove Yearly returns 20130330
6363      lv_etds_yearly_returns := 'Y' ;
6364      FND_FILE.put_line(FND_FILE.log, '~~~~Ver:619.1~~~~ Start of eTDS File Creation for Yearly Returns Batch_id->'||v_batch_id
6365      ||', Creation Date->'||to_char(SYSDATE,'dd-mon-yyyy hh24:mi:ss')||' ~~~~~~~~~~~~~~~~~~');
6366      */
6367      NULL;
6368    ELSE
6369      lv_etds_yearly_returns := 'N' ;
6370      FND_FILE.put_line(FND_FILE.log, '~~~~Ver:115.6~~~~ Start of eTDS File Creation for Quarterly returns
6371      Batch_id->'||v_batch_id || 'Period : ' || p_period
6372      ||', Creation Date->'||to_char(SYSDATE,'dd-mon-yyyy hh24:mi:ss')||' ~~~~~~~~~~~~~~~~~~');
6373    END IF ;
6374 
6375     IF length(p_tan_number) > 10 THEN
6376       FND_FILE.put_line(FND_FILE.log, 'Tan Number length is greater than 10 characters');
6377       RAISE_APPLICATION_ERROR(-20014, 'Tan Number length is greater than 10 characters', true);
6378     END IF;
6379 /*ETDS FVU3.1 Bug 11896260   Start*/
6380 if(p_organization_id is null and p_deductor_addr_org_id is null) then
6381 FND_FILE.put_line(FND_FILE.log, 'Deductor Address must be selected as the report is being submitted for TAN Number');
6382       RAISE_APPLICATION_ERROR(-20018, 'Deductor Address must be selected as the report is being submitted for TAN Number', true);
6383     END IF;
6384 
6385   if (p_organization_id is null) then
6386   select count(*) into v_regime_override
6387   from jai_rgm_parties jrp,
6388        jai_rgm_definitions jrd,
6389        jai_rgm_party_regns jrpr,
6390        jai_rgm_registrations jrr
6391   where jrd.regime_code = 'TDS'
6392   and jrd.regime_id = jrp.regime_id
6393   and jrp.regime_org_id = jrpr.regime_org_id
6394   and jrp.organization_id in (select distinct organization_id from jai_ap_tds_org_tan_v where org_tan_num = p_tan_number)
6395   and jrr.registration_id = jrpr.registration_id;
6396 
6397   if (v_regime_override > 0) then
6398   FND_FILE.put_line(FND_FILE.log, 'Regime setup is not same for all OUs for the provided TAN number');
6399       RAISE_APPLICATION_ERROR(-20014, 'For the selected TAN number attributes must be same across the OUs', true);
6400   end if;
6401   end if;
6402 
6403   /*ETDS FVU3.1 Bug 11896260   END*/
6404   /*ETDS FVU3.1 Bug 11896260   Start*/
6405   open c_organization_id(p_tan_number, p_organization_id);
6406 fetch c_organization_id into v_organization_id ;
6407 close c_organization_id;
6408 /*Bug 8880543 - Fetch Attribute values for eTDS/eTCS FVU Changes - Start*/
6409     get_attr_value (v_organization_id, 'DEDUCTOR_TYPE', v_deductor_type, v_err, v_return_message);
6410     chk_err(v_err, v_return_message);
6411     get_attr_value (v_organization_id, 'STATE', v_state_name, v_err, v_return_message);
6412     chk_err(v_err, v_return_message);
6413   /*Bug 12624907 -start*/
6414   OPEN c_get_state_code(v_state_name);
6415     FETCH c_get_state_code INTO v_state_code;
6416     CLOSE  c_get_state_code;
6417   /*Bug 12624907 -end*/
6418     get_attr_value (v_organization_id, 'MINISTRY_NAME', v_ministry_name, v_err, v_return_message);
6419     chk_err(v_err, v_return_message);
6420     get_attr_value (v_organization_id, 'PAO_CODE', v_pao_code, v_err, v_return_message);
6421     chk_err(v_err, v_return_message);
6422     get_attr_value (v_organization_id, 'DDO_CODE', v_ddo_code, v_err, v_return_message);
6423     chk_err(v_err, v_return_message);
6424     get_attr_value (v_organization_id, 'PAO_REGISTRATION_NO', v_pao_registration_no, v_err, v_return_message);
6425     chk_err(v_err, v_return_message);
6426     get_attr_value (v_organization_id, 'DDO_REGISTRATION_NO', v_ddo_registration_no, v_err, v_return_message);
6427     chk_err(v_err, v_return_message);
6428   /*Bug 10315928 - Start*/
6429     get_attr_value (v_organization_id, 'DEDUCTOR_EMAIL', v_deductor_email, v_err, v_return_message);
6430     chk_err(v_err, v_return_message);
6431     get_attr_value (v_organization_id, 'DEDUCTOR_PHONE_NO', v_deductor_phoneNo, v_err, v_return_message);
6432     chk_err(v_err, v_return_message);
6433     get_attr_value (v_organization_id, 'RESP_PERSON_EMAIL', v_RespPerson_email, v_err, v_return_message);
6434     chk_err(v_err, v_return_message);
6435     get_attr_value (v_organization_id, 'RESP_PERSON_PHONE_NO', v_RespPerson_phoneNo, v_err, v_return_message);
6436     chk_err(v_err, v_return_message);
6437     get_attr_value (v_organization_id, 'RESP_PERSON_MOBILE_NO', v_RespPerson_mobile, v_err, v_return_message);
6438     chk_err(v_err, v_return_message);
6442     OPEN c_split_phone_no(v_deductor_phoneNo);
6439 get_attr_value (v_organization_id, 'RETURN_PREP_UTILITY', v_return_prep_util, v_err, v_return_message);
6440     chk_err(v_err, v_return_message);
6441 
6443     FETCH c_split_phone_no INTO v_deductor_stdCode, v_deductor_ph_no;
6444     CLOSE c_split_phone_no;
6445 
6446     OPEN c_split_phone_no(v_RespPerson_phoneNo);
6447     FETCH c_split_phone_no INTO v_RespPerson_stdCode, v_RespPerson_ph_no;
6448     CLOSE c_split_phone_no;
6449     /*Bug 10315928 - End*/
6450   /*ETDS FVU3.1 Bug 11896260   END*/
6451     INSERT INTO JAI_AP_ETDS_REQUESTS(
6452       batch_id, request_id,/* legal_entity_id, operating_unit_id,*/ org_tan_number, financial_year,
6453       tax_authority_id, tax_authority_site_id, organization_id,
6454       deductor_name,
6455       deductor_state,
6456       addr_changed_since_last_ret,
6457       --deductor_status,  /*Bug 8880543 - Commented for eTDS/eTCS FVU Changes*/
6458       person_resp_for_deduction, designation_of_pers_resp,
6459       challan_start_date, challan_end_date, file_path, filename,
6460       program_application_id, program_id, program_login_id,
6461       -- added, Harshita for Bug 4866533
6462       created_by, creation_date, last_updated_by, last_update_date
6463     ) VALUES (
6464       v_batch_id, v_conc_request_id,/*p_legal_entity_id, p_profile_org_id,*/ p_tan_number, p_fin_year, -- Harshita for Bug 4889272
6465       p_tax_authority_id, p_tax_authority_site_id, p_organization_id,
6466       p_deductor_name,
6467       p_deductor_state,
6468       p_addrChangedSinceLastRet,
6469       --p_deductor_status,   /*Bug 8880543 - Commented for eTDS/eTCS FVU Changes*/
6470       p_persRespForDeduction, p_desgOfPersResponsible,
6471       p_challan_Start_Date, p_challan_End_Date, p_file_path, p_filename,
6472       fnd_profile.value('PROG_APPL_ID'), fnd_profile.value('CONC_PROGRAM_ID'), fnd_profile.value('CONC_LOGIN_ID'),
6473       -- added, Harshita for Bug 4866533
6474       fnd_global.user_id, sysdate, fnd_global.user_id, sysdate
6475     );
6476 
6477     FOR k IN c_organization_id(p_tan_number, p_organization_id) LOOP
6478 
6479       -- Fetching the Pan Number based on TAN
6480       OPEN c_pan_number(k.organization_id);
6481       FETCH c_pan_number INTO v_deductor_pan;
6482       CLOSE c_pan_number;
6483 
6484       EXIT WHEN v_deductor_pan IS NOT NULL;
6485 
6486     END LOOP;
6487 
6488     IF v_deductor_pan IS NULL THEN
6489       FND_FILE.put_line(FND_FILE.log, 'Pan Number cannot be retreived based on given TAN Number');
6490       RAISE_APPLICATION_ERROR(-20015, 'Pan Number cannot be retreived based on given TAN Number', true);
6491     END IF;
6492 
6493     v_financial_year        := p_fin_year;
6494     v_deductor_tan          := p_tan_number;
6495     v_tan_state_code        := to_number(p_deductor_state);
6496     v_deductor_name         := p_deductor_name;
6497     --v_deductor_type         := p_deductor_status; /*Commented for Bug 8880543 - Deductor Type is derived from Regime Setup*/
6498     v_addrChangedSinceLastReturn  := p_addrChangedSinceLastRet;
6499     v_personNameRespForDedection  := p_persRespForDeduction;
6500     v_personDesgnRespForDedection := p_desgOfPersResponsible;
6501     -- Fetching Start Date and End date of given Financial Year
6502   --OPEN  c_fin_year(v_deductor_tan, v_financial_year, v_organization_id); -- Harshita for Bug 4889272
6503     OPEN  c_fin_year;  --Change by Chong for eDTC on 20130321
6504     FETCH c_fin_year INTO v_start_date, v_end_date;
6505     CLOSE c_fin_year;
6506 
6507     IF v_start_date IS NULL OR v_end_date IS NULL THEN
6508       FND_FILE.put_line(FND_FILE.log, 'Cannot get values for Financial Year and Assessment Year');
6509       RAISE_APPLICATION_ERROR( -20016, 'Cannot get values for Financial Year and Assessment Year');
6510     END IF;
6511 
6512     -- Fetching Location linked to Input Organization from where address details are captured
6513     OPEN c_location_linked_to_org(p_organization_id,p_deductor_addr_org_id);/*ETDS FVU3.1 Bug 11896260  */
6514     FETCH c_location_linked_to_org INTO v_location_id;
6515     CLOSE c_location_linked_to_org;
6516 
6517     for org in  c_organization_id(p_tan_number, p_organization_id)
6518     loop
6519         jai_ap_tds_etds_pkg.populate_details(
6520           v_batch_id,
6521           p_tan_number,
6522           p_tax_authority_id,
6523           p_tax_authority_site_id,
6524           p_challan_Start_Date,
6525           p_challan_end_Date,
6526    --       lv_etds_yearly_returns,   --Commented by Chong for bug#16414088 20130307
6527           p_include_list,
6528           p_exclude_list,
6529           org.organization_id /*10201453*//*eTDS FVU3.1 Bug 11896260  */ /* Bug#10315928 */
6530     );
6531     end loop;
6532     -- Shall Populate the Address Details of Batch Header
6533     OPEN c_address_details(v_location_id);
6534     FETCH c_address_details INTO v_location_code, v_tan_address1, v_tan_address2, v_tan_address3, v_tan_address4,
6535       v_tan_address5, v_postal_code;
6536     CLOSE c_address_details;
6537   v_tan_address1 := substr(v_tan_address1,1,25);/*ETDS FVU3.1 Bug 11896260-truncating address to 25 characters*/
6538     /* Start-Bug 12927114 */
6539   v_tan_address2 := substr(v_tan_address2,1,25);
6540   v_tan_address3 := substr(v_tan_address3,1,25);
6541     /* End-Bug 12927114 */
6542     -- Start, Vijay Shankar for Bug#4057192
6543     -- checks for Pincode related to Address location
6544     IF length(v_postal_code) > 6 THEN
6545       RAISE_APPLICATION_ERROR(-20010, 'Postal Code of Location should not have more than 6 digit numbered value. Location Code (id):'||v_location_code||' ('||v_location_id||')');
6546     END IF;
6547 
6548     BEGIN
6549       v_tan_pin := to_number(v_postal_code);
6550     EXCEPTION
6551       WHEN VALUE_ERROR THEN     -- SQLCODE = '-6502', PL/SQL: numeric or value error: character to number conversion error
6552         RAISE_APPLICATION_ERROR(-20010, 'Postal Code of Location should be a 6 digit number. Location Code (id):'||v_location_code||' ('||v_location_id||')');
6556     BEGIN
6553     END;
6554     -- End, Vijay Shankar for Bug#4057192
6555 
6557       jai_ap_tds_etds_pkg.openFile(p_file_path, p_filename);
6558     EXCEPTION
6559       WHEN OTHERS THEN
6560         FND_FILE.put_line(FND_FILE.log, 'Error Occured during opening of file(1):'||SQLERRM);
6561         RAISE_APPLICATION_ERROR(-20016, 'Error Occured(1):'||SQLERRM, true);
6562     END;
6563 
6564     IF p_action <> 'V' THEN
6565     FND_FILE.put_line(FND_FILE.log, 'Start File Header');
6566     END IF ;
6567 
6568     -- File Header (42 Chars)
6569     v_line_number := v_line_number + 1;
6570     v_record_type := 'FH';
6571     v_file_sequence_number := 1;
6572 
6573 
6574 
6575     IF lv_etds_yearly_returns = 'Y' THEN
6576      IF p_generate_headers = 'Y' THEN
6577       jai_ap_tds_etds_pkg.create_fh(v_batch_id);
6578      END IF;
6579 
6580     jai_ap_tds_etds_pkg.create_file_header(v_line_number, v_record_type, v_file_type, v_upload_type,
6581       v_file_creation_date, v_file_sequence_number, v_deductor_tan, v_number_of_batches);
6582     ELSE
6583      IF p_action = 'H' THEN
6584          jai_ap_tds_etds_pkg.create_quarterly_fh
6585      (v_batch_id,
6586      p_period,
6587      p_RespPers_flat_no, p_RespPers_prem_bldg,  -- Bug 6030953
6588        p_RespPers_rd_st_lane, p_RespPers_area_loc, -- Bug 6030953
6589        p_RespPers_tn_cty_dt, -- Bug 6030953
6590      p_RespPersState, p_RespPersPin,
6591      v_RespPerson_phoneNo, v_RespPerson_email, -- Bug 6030953
6592      p_RespPersAddrChange );
6593      END IF;
6594 
6595       p_return_code    := null ;
6596       p_return_message := null ;
6597 
6598       jai_ap_tds_etds_pkg.validate_file_header
6599       ( p_line_number          => v_line_number ,
6600         p_record_type          => v_record_type ,
6601         p_quartfile_type       => v_quartfile_type,
6602         p_upload_type          => v_upload_type,
6603         p_file_creation_date   => v_file_creation_date,
6604         p_file_sequence_number => v_file_sequence_number,
6605         p_uploader_type        => v_uploader_type ,
6606         p_deductor_tan         => v_deductor_tan ,
6607         p_number_of_batches    => v_number_of_batches,
6608         p_ret_prep_util        => v_return_prep_util,         /*Bug 8880543 - Added Return Preperation Utility*/
6609         p_period               => p_period,
6610         p_challan_start_date   => p_challan_Start_Date,
6611         p_challan_end_date     => p_challan_End_Date,
6612         p_fin_year             => to_char(v_start_date,'YYYY'),/*(p_fin_year has been replaced with to_char(v_start_date,'YYYY')
6613                                                                 by rchandan for bug#4640996*/
6614         p_return_code          => p_return_code,
6615         p_return_message       => p_return_message
6616       );
6617 
6618          IF p_return_code = 'E' THEN
6619            IF lv_action = 'V' THEN
6620             insert into jai_ap_etds_errors_t
6621               (batch_id, record_type,  error_message) values
6622             ( v_batch_id, 'FH',  p_return_message ) ; /*Bug 8880543 - Modified ln_batch_id to v_batch_id*/
6623            ELSE
6624             p_ret_code := jai_constants.request_error ;
6625             p_err_buf := p_return_message ;
6626             RETURN ;
6627            END IF ;
6628          END IF ;
6629 
6630       lv_generate_headers := null ;
6631       IF p_action <> 'V' THEN
6632        IF p_action = 'F' THEN
6633          lv_generate_headers := 'N' ;
6634        ELSIF p_action = 'H' THEN
6635          lv_generate_headers := 'Y' ;
6636        END IF ;
6637 
6638        jai_ap_tds_etds_pkg.create_quarterly_file_header
6639          (
6640            p_line_number              =>  v_line_number,
6641            p_record_type              =>  v_record_type,
6642            p_file_type                =>  v_quartfile_type,
6643            p_upload_type              =>  v_upload_type,
6644            p_file_creation_date       =>  v_file_creation_date,
6645            p_file_sequence_number     =>  v_file_sequence_number,
6646            p_uploader_type            =>  v_uploader_type,
6647            p_deductor_tan             =>  v_deductor_tan,
6648            p_number_of_batches        =>  v_number_of_batches,
6649            p_return_prep_util         =>  v_return_prep_util,
6650            p_fh_recordHash            =>  v_fh_recordHash,
6651            p_fh_fvuVersion            =>  v_fh_fvuVersion,
6652            p_fh_fileHash              =>  v_fh_fileHash,
6653            p_fh_samVersion            =>  v_fh_samVersion,
6654            p_fh_samHash               =>  v_fh_samHash,
6655            p_fh_scmVersion            =>  v_fh_scmVersion,
6656            p_fh_scmHash               =>  v_fh_scmHash,
6657        p_fh_consFileHash          =>  v_fh_consFileHash,/* ETDS FVU3.3 -Bug 13702172 */
6658            p_generate_headers         =>  lv_generate_headers
6659          ) ;
6660       END IF ;
6661     END IF ;
6662 
6663     -- Batch Header (411 Chars)
6664     v_line_number := v_line_number + 1;
6665     v_record_type := 'BH';
6666     v_batch_number := 1;
6667     v_form_number := 26;    -- as per Vikrams update
6668     v_financial_year := to_char(v_start_date, 'YYYY')||to_char(v_end_date, 'YY');
6669     v_assessment_year := to_char(add_months(v_start_date,12), 'YYYY')||to_char(add_months(v_end_date,12), 'YY');
6670 
6671     /*SELECT count(1), sum(tds_amount)
6672     FROM JAI_AP_ETDS_T
6673     WHERE batch_id = v_batch_id AND consider_for_challan=1;*/
6674 
6675     -- bug#3708878. Above select was changed to the select below.
6676     select count(1), sum(tds_amt)
6677     INTO v_challan_cnt, v_totTaxDeductedAsPerChallan
6678     from
6679     (
6683     group by tds_section, bank_branch_code, challan_num, challan_date
6680     select tds_section, bank_branch_code, challan_num, challan_date, sum(tds_amount) tds_amt
6681     from   JAI_AP_ETDS_T
6682     WHERE  batch_id = v_batch_id AND consider_for_challan=1
6684     );
6685 
6686     SELECT count(1), sum(tds_amount) INTO v_deductee_cnt, v_totTaxDeductedAsPerDeductee
6687     FROM JAI_AP_ETDS_T
6688     WHERE batch_id = v_batch_id AND consider_for_deductee=1
6689   AND ((tds_invoice_id not in ( -9999, -9997)) /* Bug#10315928 */ /* ER :13514846 */
6690          OR (tds_invoice_id = -9999 AND (tds_vendor_classification IS NULL
6691          --Changed by Zhhou for bug#15962641 20121205 begin
6692          ---------------------------------------------------------------
6693          OR tds_vendor_classification not in ('Transporter','Software')
6694          --OR tds_vendor_classification <> 'Transporter'
6695          ---------------------------------------------------------------
6696          --Changed by Zhhou for bug#15962641 20121205 end
6697          ))); /*Bug 11896260*/
6698 
6699 
6700     IF p_action <> 'V' THEN
6701     FND_FILE.put_line(FND_FILE.log, 'Batch Header');
6702     END IF ;
6703 
6704     v_ack_num_tan_app := NULL;
6705     v_pro_rcpt_num_org_ret := nvl(p_pro_rcpt_num_org_ret,0);
6706 
6707 
6708 
6709     IF v_ministry_name = '99' THEN
6710        select meaning into v_ministry_name_other
6711        from ja_lookups lkup
6712        where lkup.lookup_type = 'JAI_MIN_NAME_VALUES'
6713        and lkup.lookup_code = '99';
6714     else
6715        v_ministry_name_other := NULL;
6716     END IF;
6717 
6718     IF lv_etds_yearly_returns = 'Y' THEN
6719 
6720       IF p_generate_headers = 'Y' THEN
6721         jai_ap_tds_etds_pkg.create_bh;
6722       END IF;
6723 
6724     jai_ap_tds_etds_pkg.create_batch_header(v_line_number, v_record_type, v_batch_number,
6725       v_challan_cnt, v_deductee_cnt, v_form_number, v_rrr_number, v_rrr_date,
6726       v_deductor_tan, v_deductor_pan, v_assessment_year, v_financial_year, v_deductor_name,
6727       v_tan_address1, v_tan_address2, v_tan_address3, v_tan_address4, v_tan_address5,
6728       v_tan_state_code, v_tan_pin, v_addrChangedSinceLastReturn, v_deductor_type, /*Bug 8880543 - Modified Deductor Status to Deductor Type*/
6729       v_quarterlyOrYearly, v_personNameRespForDedection, v_personDesgnRespForDedection,
6730       v_totTaxDeductedAsPerChallan, v_totTaxDeductedAsPerDeductee
6731     );
6732 
6733     ELSE
6734       IF p_action = 'H' THEN
6735             jai_ap_tds_etds_pkg.create_quarterly_bh;
6736       END IF;
6737 
6738     p_return_code    := null ;
6739     p_return_message := null ;
6740 
6741 
6742     jai_ap_tds_etds_pkg.validate_batch_header
6743     ( p_line_number                  => v_line_number   ,
6744       p_record_type                  => v_record_type   ,
6745       p_batch_number                 => v_batch_number  ,
6746       p_challan_cnt                  => v_challan_cnt ,
6747       p_quart_form_number            => v_quart_form_number  ,
6748       p_deductor_tan                 => v_deductor_tan   ,
6749       p_assessment_year              => v_assessment_year,
6750       p_financial_year               => v_financial_year ,
6751       p_deductor_name                => v_deductor_name ,
6752       p_deductor_pan                 => v_deductor_pan ,
6753       p_tan_address1                 => v_tan_address1  ,
6754       p_tan_state_code               => v_tan_state_code   ,
6755       p_tan_pin                      => v_tan_pin    ,
6756       p_deductor_type                => v_deductor_type , /*Bug 8880543 - Modified Deductor Status to Deductor Type*/
6757       p_addrChangedSinceLastReturn   => v_addrChangedSinceLastReturn,
6758       p_personNameRespForDedection   => v_personNameRespForDedection,
6759       p_personDesgnRespForDedection  => v_personDesgnRespForDedection,
6760       -- bug 6030953. Added by Lakshmi Gopalsami
6761     p_RespPers_flat_no         =>   p_RespPers_flat_no        ,
6762     p_RespPers_prem_bldg       =>   p_RespPers_prem_bldg      ,
6763     p_RespPers_rd_st_lane      =>   p_RespPers_rd_st_lane     ,
6764     p_RespPers_area_loc        =>   p_RespPers_area_loc       ,
6765     p_RespPers_tn_cty_dt       =>   p_RespPers_tn_cty_dt      ,
6766     -- end for bug 6030953
6767       p_RespPersState                => p_RespPersState    ,
6768       p_RespPersPin                  => p_RespPersPin   ,
6769     -- bug 6030953. Added by Lakshmi Gopalsami
6770     p_RespPers_tel_no          =>   v_RespPerson_phoneNo         ,
6771     p_RespPers_email           =>   v_RespPerson_email          ,
6772     -- end for bug 6030953
6773       p_RespPersAddrChange           => p_RespPersAddrChange ,
6774       p_totTaxDeductedAsPerDeductee  => v_totTaxDeductedAsPerDeductee,
6775       p_ao_approval                  => v_ao_approval,
6776       /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
6777       p_state_name                   => v_state_code, /*Bug 12624907 Modified from v_state_name to v_state_code*/
6778       p_pao_code                     => v_pao_code,
6779       p_ddo_code                     => v_ddo_code,
6780       p_ministry_name                => v_ministry_name,
6781       p_pao_registration_no          => v_pao_registration_no,
6782       p_ddo_registration_no          => v_ddo_registration_no,
6783       /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
6784 p_RespPerson_mobile         => v_RespPerson_mobile,
6785               p_deductor_phone_no         => v_deductor_phoneNo,
6786               p_resp_person_phone_no      => v_RespPerson_phoneNo,/*eTDS FVU3.1 Bug 11896260*/
6787       p_return_code                  => p_return_code,
6788       p_return_message               => p_return_message
6789     );
6790 
6791       IF p_return_code = 'E' THEN
6792         IF lv_action = 'V' THEN
6793          insert into jai_ap_etds_errors_t(batch_id, record_type, error_message) values
6794          ( v_batch_id, 'BH', p_return_message ) ; /*Bug 8880543 - Modified ln_batch_id to v_batch_id*/
6795         ELSE
6796          p_ret_code := jai_constants.request_error ;
6797          p_err_buf := p_return_message ;
6798 
6799          RETURN ;
6800         END IF ;
6801       END IF ;
6802 
6803 
6804     lv_generate_headers := null ;
6805     IF p_action <> 'V' THEN
6806      IF p_action = 'F' THEN
6807        lv_generate_headers := 'N' ;
6808      ELSIF p_action = 'H' THEN
6809        lv_generate_headers := 'Y' ;
6810     END IF ;
6811     --v_bh_unmatch_challan_cnt := 'NA';/*Bug-11781966*/
6812      jai_ap_tds_etds_pkg.create_quarterly_batch_header
6813      (
6814        p_line_number                => v_line_number,
6815        p_record_type                => v_record_type,
6816        p_batch_number               => v_batch_number,
6817        p_challan_count              => v_challan_cnt,
6818        p_form_number                => v_quart_form_number,
6819        p_trn_type                   => v_bh_trnType,
6820        /* Bug#10315928 - Start */
6821        p_bh_orig_token              => v_bh_orig_token,
6822        p_bh_prev_token              => v_bh_prev_token,
6823        p_bh_token_number            => v_bh_token_number,
6824        p_bh_token_date              => v_bh_token_date,
6825        /* Bug#10315928 - End */
6826        p_batchUpd                   => v_bh_batchUpd,
6827        p_deductor_last_tan          => v_bh_deductor_last_tan,
6828        p_deductor_tan               => v_deductor_tan,
6829        p_bh_receipt_no              => v_bh_receipt_no, /* Bug#10315928 */
6830        p_deductor_pan               => v_deductor_pan,
6831        p_assessment_year            => v_assessment_year,
6832        p_financial_year             => v_financial_year,
6833        p_period                     => p_period,
6834        p_deductor_name              => v_deductor_name,
6835        p_deductor_branch            => v_deductor_branch,
6836        p_tan_address1               => v_tan_address1,
6837        p_tan_address2               => v_tan_address2,
6838        p_tan_address3               => v_tan_address3,
6839        p_tan_address4               => v_tan_address4,
6840        p_tan_address5               => v_tan_address5,
6841        p_tan_state_code             => v_tan_state_code,
6842        p_tan_pin                    => v_tan_pin,
6843        p_deductor_email             => v_deductor_email,
6844        p_deductor_stdCode           => v_deductor_stdCode,
6845        p_deductor_phoneNo           => v_deductor_ph_no,
6846        p_addrChangedSinceLastReturn => v_addrChangedSinceLastReturn,
6847        p_type_of_deductor           => v_deductor_type, /*Bug 8880543 - Modified Deductor Status to Deductor Type*/
6848        p_pers_resp_for_deduction    => v_personNameRespForDedection,
6849        p_PespPerson_designation     => v_personDesgnRespForDedection,
6850        p_RespPerson_address1        => p_RespPers_flat_no,  -- bug 6030953
6851        p_RespPerson_address2        => p_RespPers_prem_bldg,  -- bug 6030953
6852        p_RespPerson_address3        => p_RespPers_rd_st_lane,  -- bug 6030953
6853        p_RespPerson_address4        => p_RespPers_area_loc,  -- bug 6030953
6854        p_RespPerson_address5        => p_RespPers_tn_cty_dt,  -- bug 6030953
6855        p_RespPerson_state           => p_RespPersState,
6856        p_RespPerson_pin             => p_RespPersPin,
6857        p_RespPerson_email           => v_RespPerson_email,   -- bug 6030953/* Bug#10315928 */
6858        p_respPerson_mobile          => v_RespPerson_mobile, /* Bug#10315928 */
6859        p_RespPerson_stdCode         => v_RespPerson_stdCode,
6860        p_RespPerson_phoneNo         => v_RespPerson_ph_no,   -- bug 6030953 /* Bug#10315928 */
6861        p_RespPerson_addressChange   => p_RespPersAddrChange,
6862        p_totTaxDeductedAsPerChallan => round(nvl(v_totTaxDeductedAsPerDeductee, 0.00)),   /* Bug#10315928 */
6863        p_bh_unmatch_challan_cnt     => v_bh_unmatch_challan_cnt, /* Bug#10315928 */
6864        p_salaryRecords_count        => v_bh_salaryRecords_count,
6865        p_gross_total                => v_bh_gross_total,
6866        p_ao_approval                => v_ao_approval     ,
6867        p_ao_approval_number         => v_ao_approval_number,
6871        p_pao_code                   => v_pao_code,
6868        /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - Start*/
6869        p_last_deductor_type         => v_last_deductor_type,
6870        p_state_name                 => v_state_code,/*Bug 12624907 -Modified from v_state_name to v_state_code */
6872        p_ddo_code                   => v_ddo_code,
6873        p_ministry_name              => v_ministry_name,
6874        p_ministry_name_other        => v_ministry_name_other,
6875        p_filler2                    => v_filler2,
6876        p_pao_registration_no        => v_pao_registration_no,
6877        p_ddo_registration_no        => v_ddo_registration_no,
6878        /*Bug 8880543 - Added for eTDS/eTCS FVU Changes - End*/
6879        p_recHash                    => v_bh_recHash,
6880        p_generate_headers           => lv_generate_headers
6881        ) ;
6882       END IF ;
6883     END IF ;
6884 
6885     IF p_action <> 'V' THEN
6886     FND_FILE.put_line(FND_FILE.log, 'Challan Detail');
6887     END IF ;
6888 
6889     -- Challan Details (60 Chars)
6890     v_record_type := 'CD';
6891     IF lv_etds_yearly_returns = 'Y' THEN
6892       IF p_generate_headers = 'Y' THEN
6893         jai_ap_tds_etds_pkg.create_cd;
6894       END IF;
6895     END IF;
6896 
6897     v_challan_dtl_slno := 0;
6898     FOR cd IN c_challan_records(v_batch_id)
6899     LOOP
6900       v_line_number := v_line_number + 1;
6901       v_challan_dtl_slno := v_challan_dtl_slno + 1;
6902       ln_amt_of_oth := 0;
6903       v_record_type := 'CD';
6904 
6905     IF cd.challan_date = lv_dummy_date THEN
6906          cd.challan_date := to_date(null) ;
6907        END IF ;
6908 
6909     IF cd.tds_vendor_classification is null THEN  /*Bug 10315928 */
6910      v_check_number := 0;--cd.check_number;/* modified from cd.check_number to 0 for Bug 13323753 */
6911      v_nil_challan_indicator    := 'N' ; /*10408793 - Nil Challan indicator is N is tax is present*/
6912      IF lv_etds_yearly_returns = 'Y' THEN -- Harshita for Bug 4525089
6913         jai_ap_tds_etds_pkg.create_challan_detail(v_line_number, v_record_type, v_batch_number, v_challan_dtl_slno,
6914         cd.tds_section, cd.tds_amount, cd.challan_num, cd.challan_date, cd.bank_branch_code
6915         );
6916       ELSE
6917         IF cd.challan_num = 'No Challan Number' THEN
6918            cd.challan_num := null ;
6919         END IF ;
6920 
6921       FND_FILE.put_line(FND_FILE.log, 'cd.tds_section: '||cd.tds_section||' cd.challan_num: '||cd.challan_num||
6922         ' cd.challan_date :' || cd.challan_date || 'cd.bank_branch_code' || cd.bank_branch_code /*|| 'cd.check_number' || cd.check_number- Bug 13323753*/);
6923 
6924 
6925       --MODIFIED BY CSAHOO FOR BUG#6158875
6926 
6927       v_bt_deductee_cnt := 0;
6928       OPEN c_deductee_cnt(v_batch_id, /* cd.check_number, --commented for bug 13323753 */ cd.tds_section,
6929                           cd.challan_num, cd.challan_date,cd.bank_branch_code);
6930       FETCH c_deductee_cnt INTO v_q_deductee_cnt ;
6931       CLOSE c_deductee_cnt ;
6932 
6933       OPEN c_deductee_cnt_bt(v_batch_id /* cd.check_number --commented for bug 13323753 */);
6934       FETCH c_deductee_cnt_bt INTO v_bt_deductee_cnt ;
6935       CLOSE c_deductee_cnt_bt ;
6936 
6937       v_q_deductee_cnt := nvl(v_q_deductee_cnt,0) + nvl(v_bt_deductee_cnt, 0);
6938 
6939       FND_FILE.put_line(FND_FILE.log, 'v_batch_id: '||v_batch_id||' v_q_deductee_cnt: '||v_q_deductee_cnt);
6940 
6941         IF p_action = 'H'  THEN
6942         jai_ap_tds_etds_pkg.create_quarterly_cd;
6943       END IF ;
6944 
6945       v_total_deposit    := nvl(cd.amt_of_tds, 0) + nvl(cd.amt_of_surcharge, 0) + nvl(cd.amt_of_cess, 0);/*ETDS FVU3.1 Bug 11896260*/
6946       /* ER : 13514846 - Nil Challan Indicator to be marked 'Y' for Zero Rate Invoices
6947       Challan Date should be Last date of the quarter in case Nil Challan Indicator is 'Y'*/
6948       if v_total_deposit = 0 then
6949         v_nil_challan_indicator    := 'Y' ;
6950         v_check_number := null;
6951         ld_nil_challan_date := derive_challan_date;
6952       end if;
6953       IF cd.challan_num = 'No Challan Number' THEN
6954         cd.challan_num := null ;
6955       END IF ;
6956       /* ER : 13514846 - end */
6957       IF cd.challan_num IS NULL THEN
6958        v_bank_branch_code := null ;
6959       ELSE
6960        v_bank_branch_code := substr(cd.bank_branch_code,1,7);
6961       END IF ;
6962 
6963       p_return_code    := null ;
6964       p_return_message := null ;
6968       (
6965 
6966 
6967       jai_ap_tds_etds_pkg.validate_challan_detail
6969         p_line_number               => v_line_number  ,
6970         p_record_type               => v_record_type  ,
6971         p_batch_number              => v_batch_number ,
6972         p_challan_dtl_slno          => v_challan_dtl_slno   ,
6973         p_deductee_cnt              => v_q_deductee_cnt ,
6974         p_nil_challan_indicat       => v_nil_challan_indicator,
6975         p_tds_section               => cd.tds_section   ,
6976         p_amt_of_tds                => cd.amt_of_tds    ,
6977         p_amt_of_surcharge          => cd.amt_of_surcharge  ,
6978         p_amt_of_cess               => cd.amt_of_cess  ,
6979         p_amt_of_oth                => ln_amt_of_oth   ,
6980         p_tds_amount                => cd.tds_amount   ,
6981         p_total_income_tds          => v_total_deposit ,
6982         p_challan_num               => cd.challan_num,
6983         p_bank_branch_code          => cd.bank_branch_code,
6984         p_challan_no                => cd.challan_num,
6985         p_challan_Date              => cd.challan_date,
6986         p_check_number              => 0, /*cd.check_number,--modified for bug 13323753 */
6987     p_tds_vendor_classification => cd.tds_vendor_classification,
6988         p_return_code               => p_return_code,
6989         p_return_message            => p_return_message
6990       );
6991       IF p_return_code = 'E' THEN
6992         IF lv_action = 'V' THEN
6993          insert into jai_ap_etds_errors_t
6994            (batch_id, record_type, reference_id, error_message) values
6995            ( v_batch_id, 'CD', v_line_number, p_return_message ) ; /*Bug 8880543 - Modified ln_batch_id to v_batch_id*/
6996         ELSE
6997          p_ret_code := jai_constants.request_error ;
6998          p_err_buf := p_return_message ;
6999 
7000          RETURN ;
7001         END IF ;
7002       END IF ;
7003 
7004 
7005       lv_generate_headers := null ;
7006       IF p_action <> 'V' THEN
7007        IF p_action = 'F' THEN
7008          lv_generate_headers := 'N' ;
7009        ELSIF p_action = 'H' THEN
7010          lv_generate_headers := 'Y' ;
7011        END IF ;
7012 
7013       ln_amt_of_tds :=  cd.tds_amount - round(cd.amt_of_surcharge) - round(cd.amt_of_cess) - round(ln_amt_of_oth) - round(ln_amt_of_oth) ;
7014 
7015       /*Bug 8880543 - Challan Number to be used only if deductor type is not A or S - Start*/
7016       IF (v_deductor_type in ('A', 'S')) THEN
7017          v_transfer_voucher_no := to_number(cd.challan_num);
7018          v_challan_number := NULL;
7019          v_bank_branch_code := NULL;
7020          v_check_number := NULL;
7021          v_book_entry := 'Y';
7022       else
7023          v_challan_number := to_number(cd.challan_num);
7024          v_transfer_voucher_no := NULL;
7025          v_book_entry := 'N';
7026       END IF;
7027       /*Bug 8880543 - Challan Number to be used only if deductor type is not A or S - End*/
7028 
7029 
7030       jai_ap_tds_etds_pkg.create_quart_challan_dtl
7031       (
7032         p_line_number              => v_line_number,
7033         p_record_type              => v_record_type,
7034         p_batch_number             => v_batch_number,
7035         p_challan_dtl_slno         => v_challan_dtl_slno,
7036         p_deductee_cnt             => v_q_deductee_cnt,
7037         p_nil_challan_indicator    => v_nil_challan_indicator,
7038         p_ch_updIndicator          => v_ch_updIndicator,
7039         p_filler2                  => v_filler2,
7040         p_filler3                  => v_filler3,
7041         p_filler4                  => v_filler4,
7042         p_last_bank_challan_no     => v_last_bank_challan_no,
7043         p_bank_challan_no          => v_challan_number,
7044         /*Bug 8880543 - Challan Number to be used only if deductory type is not A or S*/
7045         p_last_transfer_voucher_no => v_last_transfer_voucher_no,
7046         p_transfer_voucher_no      => v_transfer_voucher_no,
7047         /*Bug 8880543 - Replaced v_transfer_voucher_no with Challan Number if Deductor Type is A or S*/
7048         p_last_bank_branch_code    => v_last_bank_branch_code,
7049         p_bank_branch_code         => v_bank_branch_code ,
7050         p_challan_lastDate         => v_challan_lastDate,
7051         p_challan_Date             => nvl(cd.challan_date, ld_nil_challan_date), /*ER 13514846*/
7052         p_filler5                  => v_filler5,
7053         p_filler6                  => v_filler6,
7054         p_tds_section              => cd.tds_section,
7055         p_amt_of_tds               => ln_amt_of_tds,
7056         p_amt_of_surcharge         => round(cd.amt_of_surcharge),
7057         p_amt_of_cess              => round(cd.amt_of_cess),
7058         p_amt_of_int               => round(ln_amt_of_oth),
7059         p_amt_of_oth               => round(ln_amt_of_oth),
7060         p_tds_amount               => cd.tds_amount,
7061         p_last_total_depositAmt    => v_last_total_depositAmt,
7062         p_total_deposit            => v_total_deposit,
7063         p_tds_income_tax           => cd.amt_of_tds,
7064         p_tds_surcharge            => cd.amt_of_surcharge,
7065         p_tds_cess                 => cd.amt_of_cess,
7066         p_total_income_tds         => v_total_deposit,
7067         p_tds_interest_amt         => 0,
7068         p_tds_other_amt            => 0,
7069         p_check_number             => v_check_number, /*Bug 8880543 - Validation required based on Deductor Type*/
7070         p_book_entry               => v_book_entry,
7071         p_remarks                  => v_remarks,
7072         p_ch_recHash               => v_ch_recHash,
7073         p_generate_headers         => lv_generate_headers,
7074   /* Bug 6796765. Added by Lakshmi Gopalsami
7075    * Added p_form_name as this is required to print the
7076    * section code depending on the section
7077    */
7081       END IF ;
7078   p_form_name    =>    v_quart_form_number
7079       ) ;
7080        END IF ;
7082 
7083 
7084 
7085       -- UPDATE JAI_AP_ETDS_T SET challan_line_num = v_line_number WHERE CURRENT OF c_challan_records;
7086       -- bug#3708878. update needed to be changed as for update of cannot be used with group by
7087       UPDATE JAI_AP_ETDS_T
7088       SET    challan_line_num = v_line_number
7089       WHERE  batch_id = v_batch_id
7090       and nvl(tds_section, 'No Section') = nvl(cd.tds_section, 'No Section')
7091     and nvl(challan_num, 'No Challan Number') = nvl(cd.challan_num, 'No Challan Number')
7092       and    nvl(challan_date, trunc(sysdate) ) = nvl(cd.challan_date, trunc(sysdate) )
7093       and nvl(bank_branch_code, 'No Bank Branch') = nvl(cd.bank_branch_code, 'No Bank Branch')
7094       and    consider_for_challan=1
7095 	  and tds_vendor_classification is null; /* Avanija for FVU3.6 */
7096 
7097       IF p_action <> 'V' THEN
7098         FND_FILE.put_line(FND_FILE.log, 'Challan Line:'||v_line_number
7102       END IF ;
7099           ||', tdsSec:' || cd.tds_section || ', ChlNum:' || cd.challan_num
7100           ||', ChlDate:'||cd.challan_date||', bankBr:'||cd.bank_branch_code
7101         );
7103 
7104       IF lv_etds_yearly_returns = 'N' THEN -- Harshita for Bug 4525089
7105 
7106         v_record_type := 'DD';
7107         v_challan_line_num := v_line_number ;
7108 
7109         IF p_action = 'H' THEN
7110           jai_ap_tds_etds_pkg.create_quarterly_dd;
7111         END IF;
7112 
7113         v_deductee_slno := 0 ;
7114         process_deductee_records ;  -- internal procedure call
7115         v_challan_line_num := null ;
7116 
7117       END IF ;
7118 
7119 
7120   --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
7121   --------------------------------------------------------
7122   --Elseif cd.tds_vendor_classification = 'Transporter' then
7123 
7124   --Changed by Zhhou for bug#15962641 20121205 begin
7125   ----------------------------------------------------------------------
7126   ELSIF cd.tds_vendor_classification in('Transporter','Software') THEN /* Avanija for FVU3.6 */
7127   --ELSIF cd.tds_vendor_classification in('TRANS/SOFTW') THEN /* Commented by Avanija for FVU3.6 */
7128 
7129   ----------------------------------------------------------------------
7130   --Changed by Zhhou for bug#15962641 20121205 end
7131 
7132   --FND_FILE.put_line(FND_FILE.log, 'Starting Transporter');
7133     FND_FILE.put_line(FND_FILE.log,'Starting '||cd.tds_vendor_classification||'s');
7134   ---------------------------------------------------------
7135   --Changed by Zhiwei for Bug#15840480  FVU3.6 end
7136 
7137      IF lv_etds_yearly_returns = 'Y' THEN
7138 
7139        jai_ap_tds_etds_pkg.create_challan_detail(v_line_number, v_record_type, v_batch_number, v_challan_dtl_slno,
7140         cd.tds_section, cd.tds_amount, cd.challan_num, cd.challan_date, cd.bank_branch_code
7141         );
7142 
7143      ELSE
7144         IF cd.challan_num = 'No Challan Number' THEN
7145            cd.challan_num := null ;
7146         END IF ;
7147 
7148 
7149         --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
7150         --------------------------------------------------------
7151         --OPEN c_deductee_cnt_trans(v_batch_id);
7152         OPEN c_deductee_cnt_trans(v_batch_id, cd.tds_vendor_classification) ;----Commented by Zhhou for bug#15962641 20121205 /* Uncommented by AVanija for FVU 3.6*/
7153         ---------------------------------------------------------
7154         --Changed by Zhiwei for Bug#15840480  FVU3.6 end
7155 
7156         --Added by Zhhou for bug#15962641 20121205 begin
7160         --Added by Zhhou for bug#15962641 20121205 end
7157         -------------------------------------------------------------
7158        -- OPEN c_deductee_cnt_trans(v_batch_id); /* commented by Avanija for FVU3.6 */
7159         -------------------------------------------------------------
7161         FETCH c_deductee_cnt_trans INTO v_q_deductee_cnt ;
7162         CLOSE c_deductee_cnt_trans ;
7163 
7164 
7165         IF p_action = 'H'  THEN
7166           jai_ap_tds_etds_pkg.create_quarterly_cd;
7167         END IF ;
7168 
7169          v_total_deposit    := nvl(cd.amt_of_tds, 0) + nvl(cd.amt_of_surcharge, 0) + nvl(cd.amt_of_cess, 0);/*ETDS FVU3.1 Bug 11896260*/
7170 
7171          IF cd.challan_num IS NULL THEN
7172            v_bank_branch_code := null ;
7173          ELSE
7174            v_bank_branch_code := substr(cd.bank_branch_code,1,7);
7175          END IF ;
7176          v_nil_challan_indicator    := 'Y' ;/*Bug 10315928*/
7177          p_return_code    := null ;
7178          p_return_message := null ;
7179      jai_ap_tds_etds_pkg.validate_challan_detail
7180       (
7181         p_line_number               => v_line_number  ,
7182         p_record_type               => v_record_type  ,
7183         p_batch_number              => v_batch_number ,
7184         p_challan_dtl_slno          => v_challan_dtl_slno   ,
7185         p_deductee_cnt              => v_q_deductee_cnt ,
7186         p_nil_challan_indicat       => v_nil_challan_indicator,
7187         p_tds_section               => cd.tds_section   ,
7188         p_amt_of_tds                => cd.amt_of_tds    ,
7189         p_amt_of_surcharge          => cd.amt_of_surcharge  ,
7190         p_amt_of_cess               => cd.amt_of_cess  ,
7191         p_amt_of_oth                => ln_amt_of_oth   ,
7192         p_tds_amount                => cd.tds_amount   ,
7193         p_total_income_tds          => v_total_deposit ,
7194         p_challan_num               => cd.challan_num,
7195         p_bank_branch_code          => cd.bank_branch_code,
7196         p_challan_no                => cd.challan_num,
7197         p_challan_Date              => cd.challan_date,
7198         p_check_number              => 0, /* cd.check_number, --modified for bug 13323753 */
7199     /*(p_RespPerson_mobile         => v_RespPerson_mobile,--Bug#10315928
7200         p_deductor_phone_no         => v_deductor_phoneNo,--Bug#10315928
7201         p_resp_person_phone_no      => v_RespPerson_phoneNo,*//*Bug#10315928*/
7202     p_tds_vendor_classification => cd.tds_vendor_classification,
7203         p_return_code               => p_return_code,
7204         p_return_message            => p_return_message
7205       );
7206 
7207          lv_generate_headers := null ;
7208          IF p_action <> 'V' THEN
7209            IF p_action = 'F' THEN
7210              lv_generate_headers := 'N' ;
7211            ELSIF p_action = 'H' THEN
7212              lv_generate_headers := 'Y' ;
7213            END IF ;
7214 
7215            ln_amt_of_tds :=  cd.tds_amount - round(nvl(cd.amt_of_surcharge, 0))
7216                              - round(nvl(cd.amt_of_cess, 0)) - round(nvl(ln_amt_of_oth, 0)) - round(nvl(ln_amt_of_oth, 0)) ;/*ETDS FVU3.1 Bug 11896260*/
7217 
7218            IF v_deductor_type in ('A', 'S') THEN
7219            v_transfer_voucher_no  := cd.challan_num;
7220            v_bank_branch_code := NULL;
7221            v_check_number := NULL;
7222            v_book_entry := 'Y';
7223            ELSE
7224            v_challan_number := cd.challan_num;
7225            v_check_number := 0; /*cd.check_number; --bug 13323753 */
7226              --Added by Zhhou for bug#15964430 20121205 begin
7227              -------------------------------------------------------------
7228              if(v_nil_challan_indicator = 'Y')then
7229                  v_check_number := NULL;
7230              end if;
7231              -------------------------------------------------------------
7232              --Added by Zhhou for bug#15964430 20121205 end
7233            v_book_entry := 'N';
7234            END IF;
7235              /*Bug 11896260 - Value should be equal to last date of respective quarter if the value in field 'NIL Challan Indicator' is 'Y'.*/
7236             IF (cd.challan_date IS NULL) THEN
7237                 ld_challan_date := derive_challan_date;
7238             ELSE
7239                 ld_challan_date := cd.challan_date;
7240             END IF;
7241             jai_ap_tds_etds_pkg.create_quart_challan_dtl
7242             (
7243                 p_line_number              => v_line_number,
7244                 p_record_type              => v_record_type,
7245                 p_batch_number             => v_batch_number,
7246                 p_challan_dtl_slno         => v_challan_dtl_slno,
7247                 p_deductee_cnt             => v_q_deductee_cnt,
7248                 p_nil_challan_indicator    => v_nil_challan_indicator,
7249                 p_ch_updIndicator          => v_ch_updIndicator,
7250                 p_filler2                  => v_filler2,
7251                 p_filler3                  => v_filler3,
7252                 p_filler4                  => v_filler4,
7253                 p_last_bank_challan_no     => v_last_bank_challan_no,
7254                 p_bank_challan_no          => v_challan_number,          -- Bgowrava for Bug#8894038
7255                 p_last_transfer_voucher_no => v_last_transfer_voucher_no,
7256                 p_transfer_voucher_no      => v_transfer_voucher_no,
7257                 p_last_bank_branch_code    => v_last_bank_branch_code,
7258                 p_bank_branch_code         => v_bank_branch_code ,
7259                 p_challan_lastDate         => v_challan_lastDate,
7260                 p_challan_Date             => ld_challan_date,
7261                 p_filler5                  => v_filler5,
7262                 p_filler6                  => v_filler6,
7263                 p_tds_section              => cd.tds_section,
7264                 p_amt_of_tds               => ROUND(ln_amt_of_tds),
7265                 p_amt_of_surcharge         => round(cd.amt_of_surcharge),
7269                 p_tds_amount               => ROUND(ln_amt_of_tds) + round(nvl(cd.amt_of_surcharge,0)) + round(nvl(cd.amt_of_cess,0)) + round(nvl(ln_amt_of_oth,0)),/*ETDS FVU3.1 Bug 11896260*/
7266                 p_amt_of_cess              => round(cd.amt_of_cess),
7267                 p_amt_of_int               => round(ln_amt_of_oth),
7268                 p_amt_of_oth               => round(ln_amt_of_oth),
7270                 p_last_total_depositAmt    => v_last_total_depositAmt,
7271                 p_total_deposit            => v_total_deposit,
7272                 p_tds_income_tax           => cd.amt_of_tds,
7273                 p_tds_surcharge            => cd.amt_of_surcharge,
7274                 p_tds_cess                 => cd.amt_of_cess,
7275                 p_total_income_tds         => v_total_deposit,
7276                 p_tds_interest_amt         => 0,
7277                 p_tds_other_amt            => 0,
7278                 p_check_number             => v_check_number,
7279                 p_book_entry               => v_book_entry,
7280                 p_remarks                  => v_remarks,
7281                 p_ch_recHash               => v_ch_recHash,
7282                 p_generate_headers         => lv_generate_headers,
7283                 p_form_name    =>    v_quart_form_number
7284              ) ;
7285          END IF ;
7286      END IF ;
7287 
7288       UPDATE jai_ap_etds_t
7289       SET    challan_line_num = v_line_number
7290       WHERE  batch_id = v_batch_id
7291       --and    nvl(tds_section, 'No Section') = decode(cd.tds_vendor_classification,'Transporter','SEC. 194(C)', 'SEC. 194(J)') /*Avanija for FVU3.6 */
7292 	  and   nvl(tds_section, 'No Section') = cd.tds_section /*Commented above and added the AND for tds section for bug 15996337  */
7293       and    consider_for_challan=1
7294       and    tds_invoice_id = -9999
7295       --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
7296       ------------------------------------------------------------------
7297       --and    tds_vendor_classification = 'Transporter';/*ETDS FVU3.1 Bug 11896260*/
7298       and    tds_vendor_classification = cd.tds_vendor_classification;--Commented by Zhhou for bug#15962641 20121205 /* Uncommented by Avanija for FVU3.6 */
7299       ------------------------------------------------------------------
7300       --Changed by Zhiwei for Bug#15840480  FVU3.6 end
7301       --Added by Zhhou for bug#15962641 20121205 begin
7302       -----------------------------------------------------------------------
7303       --and    tds_vendor_classification in ( 'Transporter','Software');/* commented by Avanija for FVU3.6 */
7304       -----------------------------------------------------------------------
7305       --Added by Zhhou for bug#15962641 20121205 end
7306       IF p_action <> 'V' THEN
7307         FND_FILE.put_line(FND_FILE.log, 'Challan Line Trans:'||v_line_number
7308           ||', tdsSec:' || cd.tds_section || ', ChlNum Trans:' || cd.challan_num
7309           ||', ChlDate:'||cd.challan_date||', bankBr Trans:'||cd.bank_branch_code
7310         );
7311       END IF ;
7312 
7313       IF lv_etds_yearly_returns = 'N' THEN -- Harshita for Bug 4525089
7314 
7315         v_record_type := 'DD';
7316         v_challan_line_num := v_line_number ;
7317 
7318         IF p_action = 'H' THEN
7319           jai_ap_tds_etds_pkg.create_quarterly_dd;
7320         END IF;
7321 
7322         v_deductee_slno := 0 ;
7323 
7324         --Changed by Zhiwei for Bug#15840480  FVU3.6 begin
7325         ---------------------------------------------------------
7326         --FND_FILE.put_line(FND_FILE.log, 'Calling process_deductee_records_trans');
7327         --FND_FILE.put_line(FND_FILE.log, 'Calling process_deductee_records_trans for '|| cd.tds_vendor_classification);--Commented by Zhhou for bug#15962641 20121205
7328         --process_deductee_records_trans ;  -- internal procedure call
7329         --process_deductee_records_trans(cd.tds_vendor_classification);--Commented by Zhhou for bug#15962641 20121205
7330         ---------------------------------------------------------
7331         --Changed by Zhiwei for Bug#15840480  FVU3.6 end
7332         --Added by Zhhou for bug#15962641 20121205  begin
7333         ---------------------------------------------------------
7334 
7335         FND_FILE.put_line(FND_FILE.log, 'Calling process_deductee_records_trans for Transporter');
7336         --process_deductee_records_trans('Transporter');/*Avanija for FVU3.6 */
7337         FND_FILE.put_line(FND_FILE.log, 'Calling process_deductee_records_trans for Software');
7338         --process_deductee_records_trans('Software'); /*Avanija for FVU3.6 */
7339 		process_deductee_records_trans(cd.tds_vendor_classification); /*Avanija for FVU3.6 */
7340         ---------------------------------------------------------
7341         --Added by Zhhou for bug#15962641 20121205  end
7342         v_challan_line_num := null ;
7343 
7344       END IF ;
7345 
7346     END IF;
7347     /*Bug 11896260 - End*/
7348 
7349     END LOOP;
7350 
7351     /* Bug#10315928 */
7352 
7353     IF lv_etds_yearly_returns= 'Y' THEN
7354       v_record_type := 'DD';
7355       IF p_action <> 'V' THEN
7356         FND_FILE.put_line(FND_FILE.log, 'Deductee Detail');
7357         -- Dedectee Details (338 Chars)
7358         v_record_type := 'DD';
7359         v_deductee_slno := 0;
7360       END IF;
7361 
7362       IF p_generate_headers = 'Y' THEN
7363         jai_ap_tds_etds_pkg.create_dd;
7364       END IF;
7365 
7366        v_challan_line_num := null ;
7367        process_deductee_records ;
7368    END IF ;
7369 
7370     IF p_action = 'V' THEN
7371 
7372       FND_FILE.put_line(FND_FILE.log,' LISTING THE ERRORS IN THIS BATCH ' );
7376 
7373       FND_FILE.put_line(FND_FILE.log,'-------------------------------------------------------------------- ' );
7374 
7375       ln_errors_exist := 0;
7377       FOR rec_get_errors IN c_get_errors(v_batch_id) /*Bug 8880543 - Modified ln_batch_id to v_batch_id*/
7378       LOOP
7379         ln_errors_exist := 1 ;
7380         FND_FILE.put_line(FND_FILE.log, rec_get_errors.Error_Message );
7381       END LOOP ;
7382 
7383       IF ln_errors_exist = 0 THEN
7384         FND_FILE.put_line(FND_FILE.log,' File Validation Successful. No Errors Found !! ' );
7385       END IF ;
7386 
7387       FND_FILE.put_line(FND_FILE.log,'-------------------------------------------------------------------- ' );
7388       FND_FILE.put_line(FND_FILE.log,' END OF ERRORS IN THIS BATCH ' );
7389 
7390     END IF ;
7391 
7392     jai_ap_tds_etds_pkg.closeFile;
7393 
7394     IF p_action <> 'V' THEN
7395       FND_FILE.put_line(FND_FILE.log, '~~~~~~~~~~~~~~~ End of eTDS File Creation ~~~~~~~~~~~~~~~~~~');
7396     END IF ;
7397 /*ETDS FVU3.1 Bug 11896260*/
7398 if (lv_etds_yearly_returns='N') then
7399   open c_get_state_desc ;
7400       fetch c_get_state_desc into lv_state_desc ;
7401       close c_get_state_desc ;
7402     lv_request_desc := 'India - TDS Form 27A for Batch Id '|| ln_batch_id; /*ln_batch_id*/
7403 
7404       lv_result := FND_REQUEST.set_mode(true);
7405       lv_req_id := FND_REQUEST.submit_request(
7406                       'JA', 'JAINTDSA', lv_request_desc, '', FALSE,
7407                       --p_legal_entity_id,         --Legal Entity Id  --commented by csahoo for bug#6158875
7408                       --p_profile_org_id,          --Operating Unit  --commented by csahoo for bug#6158875
7409                       p_tan_number,              --Org Tan Num
7410                       p_organization_id,         --Organization Id
7411                       p_deductor_addr_org_id, /*Bug 12691784*/
7412                       p_fin_year,                --Fin Year
7413                       p_period,                  --Quarter
7414                       p_tax_authority_id,        --Tax Authority
7415                       p_tax_authority_site_id,   --Tax Authority Site
7416                       p_form_number,             --Form Number
7417                       p_pro_rcpt_num_org_ret,    --Previous Receipt Number
7418             -- Bug 6030953. Added by Lakshmi Gopalsami
7419                   v_deductor_type  ,         -- Type of deductor. /*Bug 8880543 - Fetch deductor and pass the same as it is not a parameter*/
7420                       p_persRespForDeduction,    --Person Responsible
7421                       p_desgOfPersResponsible,   --Responsible person Designation
7422                        -- bug 6030953. Added by Lakshmi Gopalsami
7423                       p_RespPers_flat_no,         -- Responsible person Flat No.
7424                   p_RespPers_prem_bldg,       -- Name of premises/Bldg
7425                   p_RespPers_rd_st_lane,      -- Road/Street/Lane
7426                   p_RespPers_area_loc,        -- Area/Location
7427                   p_RespPers_tn_cty_dt,       -- Town/city/District
7428                       lv_state_desc,              -- Responsible person State
7429                       p_RespPersPin,              -- Responsible Person Pin
7430                    v_RespPerson_phoneNo,      -- Telephone number
7431                   v_RespPerson_email,        -- Email
7432                  -- end for bug 6030953
7433                      p_challan_Start_Date,    --MODIFIED BY CSAHOO FOR BUG#6158875
7434                      p_challan_End_Date,      --MODIFIED BY CSAHOO FOR BUG#6158875
7435                       CHR(0), '', '', '', '', '', '',
7436                       '', '', '', '', '', '', '', '', '', '',
7437                       '', '', '', '', '', '', '', '', '', '',
7438                       '', '', '', '', '', '', '', '', '', '',
7439                       '', '', '', '', '', '', '', '', '', '',
7440                       '', '', '', '', '', '', '', '', '', '',
7441                       '', '', '', '', '', '', '', '', '', '',
7442                       '', '', '', '', '', '', '', ''
7443                   );
7444           end if;
7445 /* Added by Ramananda for bug#4407165 */
7446  EXCEPTION
7447   WHEN OTHERS THEN
7448     p_err_buf  := null;
7449     p_ret_code := null;
7450     FND_MESSAGE.SET_NAME('JA','JAI_EXCEPTION_OCCURED');
7451     FND_MESSAGE.SET_TOKEN('JAI_PROCESS_MSG', lv_object_name ||'. Err:'||sqlerrm );
7452     app_exception.raise_exception;
7453 
7454 END generate_etds_returns;
7455 
7456 -- ended, Harshita for 5096787
7457 
7458 
7459 END jai_ap_tds_etds_pkg;