DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_IN_24QC_ARCHIVE

Source


1 PACKAGE BODY pay_in_24qc_archive AS
2 /* $Header: pyin24qc.pkb 120.11.12010000.6 2009/11/09 07:05:25 mdubasi ship $ */
3 
4   --------------------------------------------------------------------------
5   --                                                                      --
6   -- Name           : TRACE_PL_SQL_TABLE_DATA                             --
7   -- Type           : PROCEDURE                                           --
8   -- Access         : Private                                             --
9   -- Description    : This procedure is used to display PL/SQL table      --
10   --                  data depending on value of BOOLEAN g_debug          --
11   -- Parameters     :                                                     --
12   --             IN : N/A                                                 --
13   --            OUT : N/A                                                 --
14   --                                                                      --
15   -- Change History :                                                     --
16   --------------------------------------------------------------------------
17   -- Rev#  Date           Userid    Description                           --
18   --------------------------------------------------------------------------
19   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
20   --------------------------------------------------------------------------
21   --
22   PROCEDURE trace_pl_sql_table_data
23   IS
24   l_procedure   VARCHAR2(250);
25   l_message     VARCHAR2(250);
26   BEGIN
27 
28       g_debug     := hr_utility.debug_enabled;
29       l_procedure := g_package || '.trace_pl_sql_table_data ';
30       pay_in_utils.set_location(g_debug,'Entering: '|| l_procedure,10);
31 
32       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
33       pay_in_utils.set_location(g_debug,'Displaying Data for Salary Records ',2);
34       pay_in_utils.set_location(g_debug,'========================================== ',3);
35       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON Starts........ ',3);
36       pay_in_utils.set_location(g_debug,'Number of assignment actions deleted : '|| g_count_sal_delete ,4);
37       FOR i IN 1..g_count_sal_delete -1
38       LOOP
39          pay_in_utils.trace('Last Action Context ID is : ', g_sal_data_rec_del(i).last_action_context_id );
40          pay_in_utils.trace('Assignment ID is          : ', g_sal_data_rec_del(i).assignment_id          );
41          pay_in_utils.trace('Source ID is       : ', g_sal_data_rec_del(i).source_id       );
42          pay_in_utils.trace('Salary Mode is          : ', g_sal_data_rec_del(i).salary_mode          );
43       END LOOP;
44       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON for deletion Ends........ ',5);
45       pay_in_utils.set_location(g_debug,'========================================== ',6);
46 
47       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON for Addition Starts........ ',7);
48       pay_in_utils.trace('Number of assignment actions added : ', g_count_sal_addition );
49       FOR i IN 1..g_count_sal_addition -1
50       LOOP
51          pay_in_utils.trace('Last Action Context ID is : ', g_sal_data_rec_add(i).last_action_context_id );
52          pay_in_utils.trace('Assignment ID is          : ', g_sal_data_rec_add(i).assignment_id          );
53          pay_in_utils.trace('Source ID is       : ', g_sal_data_rec_add(i).source_id       );
54          pay_in_utils.trace('Salary Mode is          : ', g_sal_data_rec_add(i).salary_mode          );
55       END LOOP;
56       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON for addition Ends........ ',9);
57 
58       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON for addition Ends........ ',5);
59       pay_in_utils.set_location(g_debug,'========================================== ',6);
60 
61       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON for Updation Starts........ ',7);
62       pay_in_utils.trace('Number of assignment actions updated : ', g_count_sal_update );
63       FOR i IN 1..g_count_sal_update -1
64       LOOP
65          pay_in_utils.trace('Last Action Context ID is : ', g_sal_data_rec_upd(i).last_action_context_id );
66          pay_in_utils.trace('Assignment ID is          : ', g_sal_data_rec_upd(i).assignment_id          );
67          pay_in_utils.trace('Source ID is       : ', g_sal_data_rec_upd(i).source_id       );
68          pay_in_utils.trace('Salary Mode is          : ', g_sal_data_rec_upd(i).salary_mode          );
69       END LOOP;
70       pay_in_utils.set_location(g_debug,'IN_24QC_PERSON for updation Ends........ ',9);
71       pay_in_utils.set_location(g_debug,'Data for Salary Records Ends ',2);
72       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
73 
74 
75       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
76       pay_in_utils.set_location(g_debug,'Displaying Data for Deductee Records ',2);
77       pay_in_utils.set_location(g_debug,'========================================== ',3);
78       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE Starts........ ',3);
79       pay_in_utils.set_location(g_debug,'Number of element entries deleted : '|| g_count_ee_delete ,4);
80       FOR i IN 1..g_count_ee_delete -1
81       LOOP
82          pay_in_utils.trace('Last Action Context ID is : ', g_ee_data_rec_del(i).last_action_context_id );
83          pay_in_utils.trace('Assignment ID is          : ', g_ee_data_rec_del(i).assignment_id          );
84          pay_in_utils.trace('Element Entry ID is       : ', g_ee_data_rec_del(i).element_entry_id       );
85          pay_in_utils.trace('Deductee Mode is          : ', g_ee_data_rec_del(i).deductee_mode          );
86       END LOOP;
87       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE for deletion Ends........ ',5);
88       pay_in_utils.set_location(g_debug,'========================================== ',6);
89 
90       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE for Addition Starts........ ',7);
91       pay_in_utils.trace('Number of element entries added : ', g_count_ee_addition );
92       FOR i IN 1..g_count_ee_addition -1
93       LOOP
94          pay_in_utils.trace('Last Action Context ID is : ', g_ee_data_rec_add(i).last_action_context_id );
95          pay_in_utils.trace('Assignment ID is          : ', g_ee_data_rec_add(i).assignment_id          );
96          pay_in_utils.trace('Element Entry ID is       : ', g_ee_data_rec_add(i).element_entry_id       );
97          pay_in_utils.trace('Deductee Mode is          : ', g_ee_data_rec_add(i).deductee_mode          );
98       END LOOP;
99       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE for addition Ends........ ',9);
100 
101       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE for addition Ends........ ',5);
102       pay_in_utils.set_location(g_debug,'========================================== ',6);
103 
104       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE for Updation Starts........ ',7);
105       pay_in_utils.trace('Number of element entries updated : ', g_count_ee_update );
106       FOR i IN 1..g_count_ee_update -1
107       LOOP
108          pay_in_utils.trace('Last Action Context ID is : ', g_ee_data_rec_upd(i).last_action_context_id );
109          pay_in_utils.trace('Assignment ID is          : ', g_ee_data_rec_upd(i).assignment_id          );
110          pay_in_utils.trace('Element Entry ID is       : ', g_ee_data_rec_upd(i).element_entry_id       );
111          pay_in_utils.trace('Deductee Mode is          : ', g_ee_data_rec_upd(i).deductee_mode          );
112       END LOOP;
113       pay_in_utils.set_location(g_debug,'IN_24QC_DEDUCTEE for updation Ends........ ',9);
114       pay_in_utils.set_location(g_debug,'Data for Deductee Records Ends ',2);
115       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
116 
117       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
118       pay_in_utils.set_location(g_debug,'Displaying Data for Organization ',2);
119       pay_in_utils.set_location(g_debug,'========================================== ',3);
120       pay_in_utils.set_location(g_debug,'IN_24QC_ORG Starts........ ',3);
121       pay_in_utils.trace('Value of g_count_org is : ', g_count_org);
122       FOR i IN 1..g_count_org -1
123       LOOP
124          pay_in_utils.trace('Gre ID is                  : ', g_org_data(i).gre_id                );
125          pay_in_utils.trace('Last Action Context ID is  : ', g_org_data(i).last_action_context_id);
126       END LOOP;
127       pay_in_utils.set_location(g_debug,'IN_24QC_ORG Ends........ ',3);
128       pay_in_utils.set_location(g_debug,'========================================== ',3);
129       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
130 
131       pay_in_utils.set_location(g_debug,'************************************************************ ',3);
132       pay_in_utils.set_location(g_debug,'IN_24QC_CHALLAN Starts............ ',3);
133       pay_in_utils.set_location(g_debug,'========================================== ',3);
134       pay_in_utils.trace('Number of added challans  is : ', g_count_challan_add);
135       FOR i IN 1..g_count_challan_add - 1
136       LOOP
137          pay_in_utils.trace('Transfer Voucher Number is :' , g_challan_data_add(i).transfer_voucher_number);
138          pay_in_utils.trace('Transfer Voucher Date is   :' , g_challan_data_add(i).transfer_voucher_date  );
139          pay_in_utils.trace('Amount is                  :' , g_challan_data_add(i).amount                 );
140          pay_in_utils.trace('Surcharge is               :' , g_challan_data_add(i).surcharge              );
141          pay_in_utils.trace('Education Cess is          :' , g_challan_data_add(i).education_cess         );
142          pay_in_utils.trace('Interest is                :' , g_challan_data_add(i).interest               );
143          pay_in_utils.trace('Other is                   :' , g_challan_data_add(i).other                  );
144          pay_in_utils.trace('Bank Branch Code is        :' , g_challan_data_add(i).bank_branch_code       );
145          pay_in_utils.trace('Cheque DD Number           :' , g_challan_data_add(i).cheque_dd_num          );
146          pay_in_utils.trace('Org Information ID is      :' , g_challan_data_add(i).org_information_id     );
147          pay_in_utils.trace('Mode is                    :' , g_challan_data_add(i).modes                  );
148          END LOOP;
149 
150       pay_in_utils.set_location(g_debug,'========================================== ',3);
151       pay_in_utils.trace('Number of updated challans  is : ', g_count_challan_upd);
152       FOR i IN 1..g_count_challan_upd - 1
153       LOOP
154          pay_in_utils.trace('Transfer Voucher Number is :' , g_challan_data_upd(i).transfer_voucher_number);
155          pay_in_utils.trace('Transfer Voucher Date is   :' , g_challan_data_upd(i).transfer_voucher_date  );
156          pay_in_utils.trace('Amount is                  :' , g_challan_data_upd(i).amount                 );
157          pay_in_utils.trace('Surcharge is               :' , g_challan_data_upd(i).surcharge              );
158          pay_in_utils.trace('Education Cess is          :' , g_challan_data_upd(i).education_cess         );
159          pay_in_utils.trace('Interest is                :' , g_challan_data_upd(i).interest               );
160          pay_in_utils.trace('Other is                   :' , g_challan_data_upd(i).other                  );
161          pay_in_utils.trace('Bank Branch Code is        :' , g_challan_data_upd(i).bank_branch_code       );
162          pay_in_utils.trace('Cheque DD Number           :' , g_challan_data_upd(i).cheque_dd_num          );
163          pay_in_utils.trace('Org Information ID is      :' , g_challan_data_upd(i).org_information_id     );
164          pay_in_utils.trace('Mode is                    :' , g_challan_data_upd(i).modes                  );
165          END LOOP;
166 
167       pay_in_utils.set_location(g_debug,'========================================== ',3);
168       pay_in_utils.trace('Number of no change challans  is : ', g_count_challan_noc);
169       FOR i IN 1..g_count_challan_noc - 1
170       LOOP
171          pay_in_utils.trace('Transfer Voucher Number is :' , g_challan_data_noc(i).transfer_voucher_number);
172          pay_in_utils.trace('Transfer Voucher Date is   :' , g_challan_data_noc(i).transfer_voucher_date  );
173          pay_in_utils.trace('Amount is                  :' , g_challan_data_noc(i).amount                 );
174          pay_in_utils.trace('Surcharge is               :' , g_challan_data_noc(i).surcharge              );
175          pay_in_utils.trace('Education Cess is          :' , g_challan_data_noc(i).education_cess         );
176          pay_in_utils.trace('Interest is                :' , g_challan_data_noc(i).interest               );
177          pay_in_utils.trace('Other is                   :' , g_challan_data_noc(i).other                  );
178          pay_in_utils.trace('Bank Branch Code is        :' , g_challan_data_noc(i).bank_branch_code       );
179          pay_in_utils.trace('Cheque DD Number           :' , g_challan_data_noc(i).cheque_dd_num          );
180          pay_in_utils.trace('Org Information ID is      :' , g_challan_data_noc(i).org_information_id     );
181          pay_in_utils.trace('Mode is                    :' , g_challan_data_noc(i).modes                  );
182          END LOOP;
183       pay_in_utils.set_location(g_debug,'Leaving :'|| g_package || '.trace_pl_sql_table_data ',1);
184 
185 
186   EXCEPTION
187     WHEN OTHERS THEN
188       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
189       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
190   END trace_pl_sql_table_data;
191 
192   --------------------------------------------------------------------------
193   --                                                                      --
194   -- Name           : REMOVE_CURR_FORMAT                                  --
195   -- Type           : FUNCTION                                            --
196   -- Access         : Private                                             --
197   -- Description    : This function is used to remove currency formatting --
198   --                                                                      --
199   -- Parameters     :                                                     --
200   --             IN : p_value                                             --
201   --            OUT : VARCHAR2                                            --
202   --                                                                      --
203   -- Change History :                                                     --
204   --------------------------------------------------------------------------
205   -- Rev#  Date           Userid    Description                           --
206   --------------------------------------------------------------------------
207   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
208   --------------------------------------------------------------------------
209   FUNCTION remove_curr_format (p_value    IN VARCHAR2)
210   RETURN VARCHAR2 IS
211      l_return_value VARCHAR2(240);
212      l_procedure    VARCHAR2(100);
213      l_message      VARCHAR2(250);
214   BEGIN
215 
216     l_procedure := g_package||'.remove_curr_format';
217     pay_in_utils.set_location(g_debug, 'Entering: ' || l_procedure, 10);
218 
219     IF g_debug THEN
220        pay_in_utils.trace('p_value',p_value);
221     END IF;
222 
223     l_return_value := REPLACE(REPLACE(NVL(p_value,'0'), ',', ''), '+', '');
224     pay_in_utils.set_location(g_debug,'Leaving : '|| l_procedure, 30);
225 
226     RETURN l_return_value;
227   EXCEPTION
228     WHEN OTHERS THEN
229       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
230       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
231   END remove_curr_format;
232 
233   --------------------------------------------------------------------------
234   --                                                                      --
235   -- Name           : CHECK_ARCHIVAL_STATUS                               --
236   -- Type           : FUNCTION                                            --
237   -- Access         : Private                                             --
238   -- Description    : This function determines the presence of current    --
239   --                  data in archival table for the current payroll act id-
240   -- Parameters     :                                                     --
241   --             IN : p_source_id          NUMBER                         --
242   --                  p_act_inf_category   VARCHAR2                       --
243   --                  p_act_information1   VARCHAR2                       --
244   --                  p_mode               VARCHAR2                       --
245   --            OUT : NUMBER                                              --
246   --                                                                      --
247   -- Change History :                                                     --
248   --------------------------------------------------------------------------
249   -- Rev#  Date           Userid    Description                           --
250   --------------------------------------------------------------------------
251   -- 115.0 13-Mar-20066     aaagarwa   Initial Version                      --
252   -- 115.1 07-Feb-2007      rpalli     Added check for IN_24QC_PERSON       --
253   --------------------------------------------------------------------------
254   FUNCTION check_archival_status(p_source_id         IN  NUMBER   DEFAULT NULL
255                                 ,p_act_inf_category  IN  VARCHAR2
256                                 ,p_act_information1  IN  VARCHAR2 DEFAULT NULL
257                                 ,p_mode              IN  VARCHAR2 DEFAULT NULL
258                                  )
259   RETURN NUMBER
260   IS
261 
262     CURSOR c_chk_person_data
263     IS
264        SELECT 1
265          FROM pay_action_information
266         WHERE action_information_category = 'IN_24QC_PERSON'
267           AND action_context_type         = 'AAP'
268           AND source_id                   = p_source_id
269           AND action_information10        = p_mode
270           AND action_context_id IN
271                                 (SELECT assignment_action_id
272                                    FROM pay_assignment_actions
273                                   WHERE payroll_action_id  = g_payroll_action_id
274                                 );
275 
276 
277     CURSOR c_chk_ded_data
278     IS
279        SELECT 1
280          FROM pay_action_information
281         WHERE action_information_category = 'IN_24QC_DEDUCTEE'
282           AND action_context_type         = 'AAP'
283           AND source_id                   = p_source_id
284           AND action_information15        = p_mode
285           AND action_context_id IN
286                                 (SELECT assignment_action_id
287                                    FROM pay_assignment_actions
288                                   WHERE payroll_action_id  = g_payroll_action_id
289                                 );
290 
291     CURSOR c_chk_org_data
292     IS
293        SELECT 1
294          FROM pay_action_information
295         WHERE action_information_category = 'IN_24QC_ORG'
296           AND action_context_type         = 'PA'
297           AND action_context_id           = g_payroll_action_id
298           AND action_information1         = g_gre_id;
299 
300     CURSOR c_chk_challan_data
301     IS
302        SELECT 1
303          FROM pay_action_information
304         WHERE action_information_category = 'IN_24QC_CHALLAN'
305           AND action_context_type         = 'PA'
306           AND action_context_id           = g_payroll_action_id
307           AND action_information1         = p_act_information1
308           AND action_information3         = g_gre_id;
309 
310   l_flag        NUMBER := 0;
311   l_procedure   VARCHAR2(250);
312   l_message     VARCHAR2(250);
313   BEGIN
314      g_debug     := hr_utility.debug_enabled;
315      l_procedure := g_package ||'.check_archival_status';
316      pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
317 
318      IF (p_act_inf_category = 'IN_24QC_DEDUCTEE')
319      THEN
320         OPEN  c_chk_ded_data;
321         FETCH c_chk_ded_data INTO l_flag;
322         CLOSE c_chk_ded_data;
323      ELSIF (p_act_inf_category = 'IN_24QC_ORG')
324      THEN
325         OPEN  c_chk_org_data;
326         FETCH c_chk_org_data INTO l_flag;
327         CLOSE c_chk_org_data;
328      ELSIF (p_act_inf_category = 'IN_24QC_PERSON')
329      THEN
330         OPEN  c_chk_person_data;
331         FETCH c_chk_person_data INTO l_flag;
332         CLOSE c_chk_person_data;
333      ELSE
334         OPEN  c_chk_challan_data;
335         FETCH c_chk_challan_data INTO l_flag;
336         CLOSE c_chk_challan_data;
337      END IF;
338 
339      pay_in_utils.set_location(g_debug,'Leaving : '|| g_package||'.check_archival_status',2);
340 
341      RETURN l_flag;
342   EXCEPTION
343     WHEN OTHERS THEN
344       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
345       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
346 END check_archival_status;
347 
348   --------------------------------------------------------------------------
349   --                                                                      --
350   -- Name           : GET_PARAMETERS                                      --
351   -- Type           : PROCEDURE                                           --
352   -- Access         : Private                                             --
353   -- Description    : This procedure determines the globals applicable    --
354   --                  through out the tenure of the process               --
355   -- Parameters     :                                                     --
356   --             IN : p_payroll_action_id  NUMBER                         --
357   --                  p_token_name         VARCHAR2                       --
358   --            OUT : p_token_value        VARCHAR2                       --
359   --                                                                      --
360   -- Change History :                                                     --
361   --------------------------------------------------------------------------
362   -- Rev#  Date           Userid    Description                           --
363   --------------------------------------------------------------------------
364   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
365   --------------------------------------------------------------------------
366 
367   PROCEDURE get_parameters(p_payroll_action_id IN  NUMBER,
368                            p_token_name        IN  VARCHAR2,
369                            p_token_value       OUT NOCOPY VARCHAR2
370                            )
371   IS
372 
373     CURSOR csr_parameter_info(p_pact_id NUMBER,
374                               p_token   CHAR) IS
375     SELECT SUBSTR(legislative_parameters,
376                    INSTR(legislative_parameters,p_token)+(LENGTH(p_token)+1),
377                     INSTR(legislative_parameters,' ',
378                            INSTR(legislative_parameters,p_token))
379                      - (INSTR(legislative_parameters,p_token)+LENGTH(p_token)))
380            ,business_group_id
381       FROM  pay_payroll_actions
382      WHERE  payroll_action_id = p_pact_id;
383 
384     l_token_value VARCHAR2(150);
385     l_bg_id       NUMBER;
386     l_procedure   VARCHAR2(100);
387     l_message     VARCHAR2(250);
388 
389   BEGIN
390     g_debug := hr_utility.debug_enabled;
391     l_procedure  := g_package||'.get_parameters';
392 
393     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
394 
395     OPEN csr_parameter_info(p_payroll_action_id,
396                             p_token_name);
397     FETCH csr_parameter_info INTO l_token_value,l_bg_id;
398     CLOSE csr_parameter_info;
399 
400     p_token_value := TRIM(l_token_value);
401 
402     IF (p_token_name = 'BG_ID') THEN
403         p_token_value := l_bg_id;
404     END IF;
405 
406     IF (p_token_value IS NULL) THEN
407          p_token_value := '%';
408     END IF;
409 
410     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,20);
411   EXCEPTION
412     WHEN OTHERS THEN
413       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
414       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
415   END get_parameters;
416 
417   --------------------------------------------------------------------------
418   --                                                                      --
419   -- Name           : INITIALIZATION_CODE                                 --
420   -- Type           : PROCEDURE                                           --
421   -- Access         : Public                                              --
422   -- Description    : This procedure is used to set global contexts.      --
423   -- Parameters     :                                                     --
424   --             IN : p_payroll_action_id    NUMBER                       --
425   --            OUT : N/A                                                 --
426   --                                                                      --
427   -- Change History :                                                     --
428   --------------------------------------------------------------------------
429   -- Rev#  Date           Userid    Description                           --
430   --------------------------------------------------------------------------
431   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
432   -- 115.1 07-Feb-2007    rpalli    Added code to initialize some dates   --
433   --------------------------------------------------------------------------
434   --
435   PROCEDURE initialization_code (p_payroll_action_id  IN NUMBER)
436   IS
437   --
438   CURSOR csr_arch_ref_no(p_payroll_action_id NUMBER)
439   IS
440    SELECT 1
441     FROM pay_action_information pai
442         ,pay_payroll_actions    ppa
443    WHERE pai.action_information_category = 'IN_24QC_ORG'
444      AND pai.action_context_type         = 'PA'
445      AND pai.action_information1         = g_gre_id
446      AND pai.action_information3         = g_year||g_quarter
447      AND pai.action_information30        = g_24qc_reference
448      AND pai.action_context_id           = ppa.payroll_action_id
449      AND ppa.action_type                 = 'X'
450      AND ppa.action_status               = 'C'
451      AND ppa.payroll_action_id  <> p_payroll_action_id;
452 
453   CURSOR c_prev_stmt_details(p_tan_number      VARCHAR2
454                             ,p_last_act_cxt_id NUMBER
455                                )
456      IS
457        SELECT DECODE(action_information_category,'IN_24Q_ORG',action_information21,action_information7)   deductor_type
458          FROM pay_action_information
459         WHERE action_information_category IN ('IN_24Q_ORG','IN_24QC_ORG')
460           AND action_context_id   = p_last_act_cxt_id
461           AND action_context_type = 'PA'
462           AND action_information1 = g_gre_id
463           AND action_information2 = p_tan_number
464           AND action_information3 = g_year||g_quarter
465         ORDER BY action_context_id DESC;
466 
467     l_procedure                   VARCHAR2(100);
468     l_assess_yr_start        DATE;
469     l_end_date               DATE;
470     i                        NUMBER;
471     l_token_name             pay_in_utils.char_tab_type;
472     l_token_value            pay_in_utils.char_tab_type;
473     l_arch_ref_no_check      NUMBER;
474     E_NON_UNIQUE_ARCH_REF_NO EXCEPTION;
475     E_EMPLR_CLASS_VALIDATE EXCEPTION;
476     l_deductor_type            hr_organization_information.org_information3%TYPE;
477     l_tan_number               hr_organization_information.org_information3%TYPE;
478     l_previous_deductor_type   hr_organization_information.org_information3%TYPE;
479   --
480   BEGIN
481   --
482     g_debug := hr_utility.debug_enabled;
483     l_procedure  := g_package || '.initialization_code';
484 
485     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
486 
487     g_payroll_action_id  := p_payroll_action_id;
488     get_parameters(p_payroll_action_id,'YR' ,g_year);
489     get_parameters(p_payroll_action_id,'GRE',g_gre_id);
490     get_parameters(p_payroll_action_id,'QR' ,g_quarter);
491     get_parameters(p_payroll_action_id,'CT' ,g_correction_mode);
492     get_parameters(p_payroll_action_id,'AR' ,g_24qc_reference);
493     get_parameters(p_payroll_action_id,'EC' ,g_24qc_empr_change);
494     get_parameters(p_payroll_action_id,'RC' ,g_24qc_rep_adr_chg);
495     get_parameters(p_payroll_action_id,'RN' ,g_cancel_ref_number);
496     get_parameters(p_payroll_action_id,'RFD',g_regular_file_date);
497 
498     IF g_regular_file_date < TO_DATE('01-10-09','DD-MM-YY')
499     THEN
500     g_old_format := 'Y';
501     ELSE
502     g_old_format := 'N';
503     END IF;
504 
505     i := TO_NUMBER(SUBSTR(g_quarter,2,1)) - 1;
506     l_assess_yr_start := fnd_date.string_to_date(('01/04/'|| SUBSTR(g_year,1,4)),'DD/MM/YYYY');
507     l_end_date   := fnd_date.string_to_date(('31/03/'|| SUBSTR(g_year,6)),'DD/MM/YYYY');
508 
509     g_qr_start_date  := ADD_MONTHS(l_assess_yr_start,(i*3)-12);
510     g_end_date       := ADD_MONTHS(g_qr_start_date,3) -1;
511 
512     pay_in_utils.set_location(g_debug,'Finding Globals : '||l_procedure,20);
513 
514     g_qr_end_date := ADD_MONTHS(g_qr_start_date,3) - 1;
515 
516     g_tax_year := TO_CHAR(TO_NUMBER(SUBSTR(g_year,1,4))-1)||'-'|| SUBSTR(g_year,1,4);
517 
518     g_fin_start_date := ADD_MONTHS(l_assess_yr_start,-12);
519     g_fin_end_date   := ADD_MONTHS(l_end_date,-12);
520 
521     IF g_quarter ='Q4' THEN
522       g_start_date := ADD_MONTHS(l_assess_yr_start,-12);
523     ELSE
524       g_start_date := g_qr_start_date;
525     END IF;
526 
527     l_arch_ref_no_check := 0;
528     OPEN csr_arch_ref_no(p_payroll_action_id);
529     FETCH csr_arch_ref_no INTO l_arch_ref_no_check;
530     CLOSE csr_arch_ref_no;
531 
532     IF l_arch_ref_no_check = 1 THEN
533        l_token_name(1)  := 'NUMBER_CATEGORY';
534        l_token_value(1) := hr_general.decode_lookup('IN_MESSAGE_TOKENS','ARCH_REF_NUM');--'Archive Reference Number';
535        RAISE E_NON_UNIQUE_ARCH_REF_NO;
536     END IF;
537 
538     SELECT  hoi.org_information1 ,hoi.org_information6 into l_tan_number,l_deductor_type
539       FROM hr_organization_information hoi
540           ,hr_organization_units       hou
541      WHERE hoi.organization_id         = g_gre_id
542        AND hoi.org_information_context = 'PER_IN_INCOME_TAX_DF'
543        AND hou.organization_id         = hoi.organization_id
544        AND hou.business_group_id       = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
545        AND g_qr_end_date BETWEEN hou.date_from AND NVL(hou.date_to,TO_DATE('31-12-4712','DD-MM-YYYY'));
546 
547       FOR i IN 1.. g_count_org - 1
548         LOOP
549                 IF (g_org_data(i).gre_id = g_gre_id)
550                 THEN
551                        pay_in_utils.set_location(g_debug,'Fetching previous statement details ',3);
552                        pay_in_utils.set_location(g_debug,'Last Payroll Action Id   : ' || g_org_data(i).last_action_context_id,6);
553                        OPEN  c_prev_stmt_details(l_tan_number,g_org_data(i).last_action_context_id);
554                        FETCH c_prev_stmt_details INTO l_previous_deductor_type;
555                        CLOSE c_prev_stmt_details;
556                 END IF;
557        END LOOP;
558            pay_in_utils.set_location(g_debug,'Old Deductor Type is    : ' || l_previous_deductor_type,9);
559            pay_in_utils.set_location(g_debug,'New Deductor Type is    : ' || l_deductor_type,9);
560 
561            IF (l_previous_deductor_type IN ('A','S') and l_deductor_type NOT IN ('A','S'))
562            THEN
563             l_token_name(1)  := 'EMPLR_TYPE';
564             l_token_value(1) := 'Government';
565             RAISE E_EMPLR_CLASS_VALIDATE;
566            ELSIF (l_previous_deductor_type NOT IN ('A','S') and l_deductor_type IN ('A','S'))
567            THEN
568             l_token_name(1)  := 'EMPLR_TYPE';
569             l_token_value(1) := 'Non-Government';
570             RAISE E_EMPLR_CLASS_VALIDATE;
571            END IF;
572 
573     pay_in_utils.set_location(g_debug,'Global1: '||g_year||' '||' '||g_quarter||' '||g_gre_id,30);
574     pay_in_utils.set_location(g_debug,'Global2: '||g_end_date||g_qr_start_date||g_qr_end_date,40);
575     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,50);
576 
577   --
578   EXCEPTION
579     WHEN E_NON_UNIQUE_ARCH_REF_NO THEN
580       pay_in_utils.raise_message(800, 'PER_IN_NON_UNIQUE_VALUE', l_token_name, l_token_value);
581       fnd_file.put_line(fnd_file.log,'Archive Reference Number '|| g_24qc_reference || 'is non-unique.');
582       RAISE;
583     WHEN E_EMPLR_CLASS_VALIDATE THEN
584       pay_in_utils.raise_message(800,'PER_IN_24Q_EMPLR_VALIDATE', l_token_name, l_token_value);
585       fnd_file.put_line(fnd_file.log,'Employer Classification '|| l_deductor_type || 'should be changed.');
586       RAISE;
587     WHEN OTHERS THEN
588       RAISE;
589   END initialization_code;
590 
591  --------------------------------------------------------------------------
592   --                                                                      --
593   -- Name           : ASSIGNMENT_END_DATE                                 --
594   -- Type           : FUNCTION                                            --
595   -- Access         : Private                                             --
596   -- Description    : This function determines the least of asg terminat- --
597   --                  -ion date and quarter end date.                     --
598   -- Parameters     :                                                     --
599   --             IN : p_assignment_id NUMBER                              --
600   --            OUT : DATE                                                --
601   --                                                                      --
602   -- Change History :                                                     --
603   --------------------------------------------------------------------------
604   -- Rev#  Date           Userid    Description                           --
605   --------------------------------------------------------------------------
606   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
607   --------------------------------------------------------------------------
608   FUNCTION assignment_end_date(p_assignment_id IN  NUMBER
609                               )
610   RETURN DATE
611   IS
612     CURSOR c_termination_check
613     IS
614     SELECT NVL(pos.actual_termination_date,(fnd_date.string_to_date('31-12-4712','DD-MM-YYYY')))
615       FROM   per_all_assignments_f  asg
616             ,per_periods_of_service pos
617      WHERE asg.person_id         = pos.person_id
618        AND asg.assignment_id     = p_assignment_id
619        AND asg.business_group_id = pos.business_group_id
620        AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
621        AND NVL(pos.actual_termination_date,(TO_DATE('31-12-4712','DD-MM-YYYY')))
622              BETWEEN asg.effective_start_date AND asg.effective_end_date
623      ORDER BY 1 DESC;
624 
625     l_date      DATE;
626     l_procedure VARCHAR2(250);
627     l_message   VARCHAR2(250);
628   BEGIN
629     g_debug     := hr_utility.debug_enabled;
630     l_procedure := g_package ||'.assignment_end_date';
631     pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
632     OPEN  c_termination_check;
633     FETCH c_termination_check INTO l_date;
634     CLOSE c_termination_check;
635     pay_in_utils.set_location(g_debug,'Date Found is: '|| l_date,2);
636     pay_in_utils.set_location(g_debug,'Leaving :'||g_package||'.assignment_end_date',3);
637     RETURN LEAST(l_date,g_qr_end_date);
638   EXCEPTION
639     WHEN OTHERS THEN
640       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
641       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
642 END assignment_end_date;
643 
644  --------------------------------------------------------------------------
645   --                                                                      --
646   -- Name           : RANGE_CODE                                          --
647   -- Type           : PROCEDURE                                           --
648   -- Access         : Public                                              --
649   -- Description    : This procedure returns a sql string to select a     --
650   --                  range of assignments eligible for archival.         --
651   --                                                                      --
652   -- Parameters     :                                                     --
653   --             IN : p_payroll_action_id    NUMBER                       --
654   --            OUT : p_sql                  VARCHAR2                     --
655   --                                                                      --
656   -- Change History :                                                     --
657   --------------------------------------------------------------------------
658   -- Rev#  Date           Userid    Description                           --
659   --------------------------------------------------------------------------
660   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
661   --------------------------------------------------------------------------
662   PROCEDURE range_code(p_payroll_action_id   IN  NUMBER
663                       ,p_sql                 OUT NOCOPY VARCHAR2
664                       )
665   IS
666   --
667     l_procedure  VARCHAR2(100);
668     l_message    VARCHAR2(250);
669   --
670   BEGIN
671   --
672     g_debug := hr_utility.debug_enabled;
673     l_procedure  := g_package || '.range_code';
674 
675     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
676 
677     -- Call core package to return SQL string to SELECT a range
678     -- of assignments eligible for archival
679     --
680     pay_core_payslip_utils.range_cursor(p_payroll_action_id
681                                        ,p_sql);
682 
683     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,20);
684   --
685   EXCEPTION
686     WHEN OTHERS THEN
687       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
688       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
689   --
690   END range_code;
691 
692   --------------------------------------------------------------------------
693   --                                                                      --
694   -- Name           : UPDATE_CHALLANS                                     --
695   -- Type           : FUNCTION                                            --
696   -- Access         : Private                                             --
697   -- Description    : This function returns the last statement detail     --
698   -- Parameters     :                                                     --
699   --             IN : p_challan_number   VARCHAR2                         --
700   --                                                                      --
701   --            OUT : VARCHAR2                                            --
702   --                                                                      --
703   -- Change History :                                                     --
704   --------------------------------------------------------------------------
705   -- Rev#  Date           Userid    Description                           --
706   --------------------------------------------------------------------------
707   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
708   --------------------------------------------------------------------------
709   FUNCTION update_challans(p_challan_number    IN VARCHAR2)
710   RETURN VARCHAR2
711   IS
712     CURSOR c_24q_ee_sum(p_challan_number       VARCHAR2
713                        ,p_24q_pay_action_id   NUMBER
714                        )
715     IS
716         SELECT SUM(NVL(pai.action_information9,0)) amount_deposited
717           FROM pay_action_information  pai
718               ,pay_assignment_actions  paa
719          WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
720            AND paa.assignment_action_id        = pai.action_context_id
721            AND pai.action_information1         = p_challan_number
722            AND paa.payroll_action_id           = p_24q_pay_action_id;
723 
724       l_action_info_id    NUMBER;
725       l_ovn               NUMBER;
726       l_last_sum          VARCHAR2(2500);
727       l_procedure         VARCHAR2(250);
728       l_message           VARCHAR2(250);
729   BEGIN
730      g_debug     := hr_utility.debug_enabled;
731      l_procedure := g_package ||'.update_challans';
732      pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
733      pay_in_utils.set_location(g_debug,'g_24q_payroll_act_id  ' || g_24q_payroll_act_id ,1);
734      pay_in_utils.set_location(g_debug,'g_24qc_payroll_act_id ' || g_24qc_payroll_act_id,1);
735 
736      l_last_sum := NULL;
737      pay_in_utils.set_location(g_debug,'Starting updation of action_information19 for Challans ' ,1);
738      IF (g_24qc_payroll_act_id IS NOT NULL)
739      THEN
740             pay_in_utils.set_location(g_debug,'Using 24Q Correction Data',2);
741             l_last_sum := pay_in_24qc_er_returns.get_24qc_tax_values(p_challan_number
742                                                                     ,g_gre_id
743                                                                     ,g_24qc_payroll_act_id
744                                                                     );
745             l_last_sum := SUBSTR(l_last_sum,1,INSTR(l_last_sum,'^')-1);
746       END IF;
747 
748       IF(TO_NUMBER(NVL(l_last_sum,0)) = 0)
749       THEN
750             pay_in_utils.set_location(g_debug,'Using 24Q Data',3);
751             OPEN  c_24q_ee_sum(p_challan_number,g_24q_payroll_act_id);
752             FETCH c_24q_ee_sum INTO l_last_sum;
753             CLOSE c_24q_ee_sum;
754             l_last_sum := pay_in_24q_er_returns.get_format_value(l_last_sum);
755      END IF;
756 
757      pay_in_utils.set_location(g_debug,'Leaving: '|| g_package||'.update_challans',1);
758      RETURN l_last_sum;
759   EXCEPTION
760     WHEN OTHERS THEN
761       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
762       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
763   END update_challans;
764 
765   --------------------------------------------------------------------------
766   --                                                                      --
767   -- Name           : CHECK_EE_IN_QC                                      --
768   -- Type           : PROCEDURE                                           --
769   -- Access         : Private                                             --
770   -- Description    : This determines cyclic change in Challan Number in  --
771   --                  an element entry                                    --
772   -- Parameters     :                                                     --
773   --             IN : p_element_entry_id                                  --
774   --            OUT : VARCHAR2                                            --
775   --                                                                      --
776   -- Change History :                                                     --
777   --------------------------------------------------------------------------
778   -- Rev#  Date           Userid    Description                           --
779   --------------------------------------------------------------------------
780   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
781   --------------------------------------------------------------------------
782   FUNCTION check_ee_in_qc(p_element_entry_id IN NUMBER)
783   RETURN VARCHAR2
784   IS
785   CURSOR check_ee
786   IS
787    SELECT pai.action_information1
788          ,MAX(pai.action_context_id)
789      FROM pay_action_information pai
790          ,pay_action_interlocks locks
791          ,pay_assignment_actions paa
792          ,pay_assignment_actions paa_24qc
793     WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
794       AND locks.locking_action_id         = pai.action_context_id
795       AND locks.locked_action_id          = paa.assignment_action_id
796       AND paa.payroll_action_id           = g_24q_payroll_act_id
797       AND paa.assignment_id               = pai.assignment_id
798       AND pai.action_information2         = g_year||g_quarter
799       AND paa_24qc.assignment_id          = pai.assignment_id
800       AND paa_24qc.assignment_action_id   = pai.action_context_id
801       AND pai.action_information15        = 'A'
802       AND pai.source_id                   = p_element_entry_id
803       AND paa_24qc.payroll_action_id IN(
804                                         SELECT org_information3
805                                           FROM hr_organization_information
806                                          WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
807                                            AND organization_id  = g_gre_id
808                                            AND org_information1 = g_year
809                                            AND org_information2 = g_quarter
810                                            AND org_information5 = 'A'
811                                            AND org_information6 = 'C'
812                                         )
813       GROUP BY pai.action_information1;
814 
815   l_challan_number         VARCHAR2(250);
816   l_action_info_id         NUMBER;
817   l_procedure              VARCHAR2(250);
818   l_message                VARCHAR2(250);
819 
820   BEGIN
821     l_procedure  :=  g_package || '.check_ee_in_qc';
822     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
823 
824     OPEN  check_ee;
825     FETCH check_ee INTO l_challan_number,l_action_info_id;
826     CLOSE check_ee;
827 
828     l_challan_number := NVL(l_challan_number,pay_in_utils.get_ee_value(p_element_entry_id,'Challan or Voucher Number'));
829 
830     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,20);
831     RETURN l_challan_number;
832   EXCEPTION
833     WHEN OTHERS THEN
834       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
835       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
836   END check_ee_in_qc;
837 
838   --------------------------------------------------------------------------
839   --                                                                      --
840   -- Name           : GENERATE_EMPLOYEE_DATA                              --
841   -- Type           : PROCEDURE                                           --
842   -- Access         : Private                                             --
843   -- Description    : This procedure populates global tables used in      --
844   --                  deductee detail record                              --
845   -- Parameters     :                                                     --
846   --             IN : p_payroll_action_id    NUMBER                       --
847   --            OUT : N/A                                                 --
848   --                                                                      --
849   -- Change History :                                                     --
850   --------------------------------------------------------------------------
851   -- Rev#  Date           Userid    Description                           --
852   --------------------------------------------------------------------------
853   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
854   --------------------------------------------------------------------------
855   --
856   PROCEDURE generate_employee_data(p_payroll_action_id   IN NUMBER
857                                   )
858   IS
859 
860     CURSOR c_delete_mode_entries(p_payroll_action_id        NUMBER)
861     IS
862        SELECT pai.source_id           element_entry_id
863              ,pai.assignment_id       assignment_id
864              ,pai.action_context_id   last_action_context_id
865          FROM pay_action_information pai
866              ,pay_assignment_actions paa
867         WHERE pai.action_information_category LIKE 'IN_24Q%_DEDUCTEE'
868           AND pai.action_context_id = paa.assignment_action_id
869           AND(
870                 paa.payroll_action_id IN (
871                                            SELECT org_information3
872                                              FROM hr_organization_information
873                                             WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
874                                               AND organization_id  = g_gre_id
875                                               AND org_information1 = g_year
876                                               AND org_information2 = g_quarter
877                                               AND org_information5 = 'A'
878                                           )
879              )
880           AND pai.action_information3 = g_gre_id
881           AND (
882                 pai.source_id NOT IN
883                        (SELECT entry.element_entry_id
884                           FROM pay_element_entries_f entry
885                               ,pay_element_types_f   types
886                          WHERE entry.assignment_id = pai.assignment_id
887                            AND entry.element_type_id = types.element_type_id
888                            AND types.element_name = 'Income Tax Challan Information'
889                            AND types.legislation_code = 'IN'
890                            AND entry.effective_start_date BETWEEN g_qr_start_date
891                            AND g_qr_end_date
892                         )
893                OR
894                pai.action_information1 <> pay_in_utils.get_ee_value(pai.source_id,'Challan or Voucher Number')
895              )
896          AND (
897                 pai.source_id NOT IN
898                       (SELECT pai.source_id
899                          FROM pay_action_information pai
900                              ,pay_action_interlocks locks
901                              ,pay_assignment_actions paa
902                              ,pay_assignment_actions masters
903                         WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
904                           AND pai.action_information15        = 'D'
905                           AND locks.locking_action_id         = pai.action_context_id
906                           AND locks.locked_action_id          = paa.assignment_action_id
907                           AND paa.payroll_action_id           = p_payroll_action_id
908                           AND paa.assignment_id               = pai.assignment_id
909                           AND masters.assignment_id            = pai.assignment_id
910                           AND masters.assignment_action_id     = pai.action_context_id
911                           AND masters.payroll_action_id IN(
912                                                            SELECT org_information3
913                                                              FROM hr_organization_information
914                                                             WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
915                                                               AND organization_id  = g_gre_id
916                                                               AND org_information1 = g_year
917                                                               AND org_information2 = g_quarter
918                                                               AND org_information5 = 'A'
919                                                               AND org_information6 = 'C'
920                                                      )
921                       )
922               OR
923               pay_in_utils.get_ee_value(pai.source_id,'Challan or Voucher Number') NOT IN
924               (
925                       (SELECT pai.action_information1
926                          FROM pay_action_information pai
927                              ,pay_action_interlocks locks
928                              ,pay_assignment_actions paa
929                              ,pay_assignment_actions masters
930                         WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
931                           AND pai.action_information15        = 'A'
932                           AND locks.locking_action_id         = pai.action_context_id
933                           AND locks.locked_action_id          = paa.assignment_action_id
934                           AND paa.payroll_action_id           = p_payroll_action_id
935                           AND paa.assignment_id               = pai.assignment_id
936                           AND masters.assignment_id            = pai.assignment_id
937                           AND masters.assignment_action_id     = pai.action_context_id
938                           AND masters.payroll_action_id IN(
939                                                             SELECT org_information3
940                                                               FROM hr_organization_information
941                                                              WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
942                                                                AND organization_id  = g_gre_id
943                                                                AND org_information1 = g_year
944                                                                AND org_information2 = g_quarter
945                                                                AND org_information5 = 'A'
946                                                                AND org_information6 = 'C'
947                                                      )
948                       )
949               )
950            )
951            ORDER BY 3 DESC;
952 
953     CURSOR c_addition_mode_entries(p_payroll_action_id        NUMBER)
954     IS
955       SELECT entry.element_entry_id  element_entry_id
956             ,entry.assignment_id     assignment_id
957             ,NULL                    last_action_context_id
958             ,pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number')
959         FROM pay_element_entries_f entry
960             ,pay_element_types_f   types
961        WHERE entry.element_type_id = types.element_type_id
962          AND types.element_name    = 'Income Tax Challan Information'
963          AND types.legislation_code = 'IN'
964          AND entry.effective_start_date BETWEEN g_qr_start_date AND g_qr_end_date
965          AND (
966                 entry.element_entry_id NOT IN
967                       (SELECT pai.source_id
968                          FROM pay_action_information pai
969                              ,pay_assignment_actions paa
970                         WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
971                           AND pai.action_context_id   = paa.assignment_action_id
972                           AND paa.payroll_action_id   = p_payroll_action_id
973                       )
974               OR
975               pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number') NOT IN
976                       (SELECT pai.action_information1
977                          FROM pay_action_information pai
978                              ,pay_assignment_actions paa
979                         WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
980                           AND pai.action_context_id   = paa.assignment_action_id
981                           AND paa.payroll_action_id   = p_payroll_action_id
982                           AND pai.source_id           = entry.element_entry_id
983                       )
984              )
985          AND (
986                  entry.element_entry_id NOT IN
987                       (SELECT pai.source_id
988                          FROM pay_action_information pai
989                              ,pay_action_interlocks locks
990                              ,pay_assignment_actions paa
991                              ,pay_assignment_actions paa_24qc
992                         WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
993                           AND locks.locking_action_id         = pai.action_context_id
994                           AND locks.locked_action_id          = paa.assignment_action_id
995                           AND paa.payroll_action_id           = p_payroll_action_id
996                           AND paa.assignment_id               = pai.assignment_id
997                           AND pai.action_information2         = g_year||g_quarter
998                           AND paa_24qc.assignment_id          = pai.assignment_id
999                           AND paa_24qc.assignment_action_id   = pai.action_context_id
1000                           AND paa_24qc.payroll_action_id IN(
1001                                                       SELECT org_information3
1002                                                         FROM hr_organization_information
1003                                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1004                                                          AND organization_id  = g_gre_id
1005                                                          AND org_information1 = g_year
1006                                                          AND org_information2 = g_quarter
1007                                                          AND org_information5 = 'A'
1008                                                          AND org_information6 = 'C'
1009                                                      )
1010                       )
1011               OR
1012               pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number') NOT IN
1013               (
1014                       (SELECT pai.action_information1
1015                          FROM pay_action_information pai
1016                              ,pay_action_interlocks locks
1017                              ,pay_assignment_actions paa
1018                              ,pay_assignment_actions paa_24qc
1019                         WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
1020                           AND locks.locking_action_id         = pai.action_context_id
1021                           AND locks.locked_action_id          = paa.assignment_action_id
1022                           AND paa.payroll_action_id           = p_payroll_action_id
1023                           AND paa.assignment_id               = pai.assignment_id
1024                           AND pai.action_information2         = g_year||g_quarter
1025                           AND paa_24qc.assignment_id          = pai.assignment_id
1026                           AND paa_24qc.assignment_action_id   = pai.action_context_id
1027                           AND pai.source_id                   = entry.element_entry_id
1028                           AND paa_24qc.payroll_action_id IN(
1029                                                       SELECT org_information3
1030                                                         FROM hr_organization_information
1031                                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1032                                                          AND organization_id  = g_gre_id
1033                                                          AND org_information1 = g_year
1034                                                          AND org_information2 = g_quarter
1035                                                          AND org_information5 = 'A'
1036                                                          AND org_information6 = 'C'
1037                                                      )
1038                       )
1039               )
1040             )
1041          AND pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number') IN
1042              	    (SELECT bank.org_information4||' - '||hoi.org_information3 ||' - ' ||to_char(fnd_date.canonical_to_date(hoi.org_information2),'DD-Mon-RRRR') org_information3
1043                                                            FROM hr_organization_units hou
1044                                                                ,hr_organization_information hoi
1045                                                                ,hr_organization_information bank
1046                                                           WHERE hoi.organization_id   = hou.organization_id
1047                                                             AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1048                                                             AND hoi.org_information_context = 'PER_IN_IT_CHALLAN_INFO'
1049                                                             AND hoi.org_information1 = g_tax_year
1050                                                             AND bank.org_information_context = 'PER_IN_CHALLAN_BANK'
1051                                                             and bank.organization_id = hoi.organization_id
1052                                                             AND hoi.org_information5 = bank.org_information_id
1053                                                             AND hoi.org_information13 = g_quarter
1054                                                             AND hoi.organization_id = g_gre_id
1055                                                          UNION
1056                                                         SELECT 'BOOK - '||hoi.org_information3 ||' - ' ||to_char(fnd_date.canonical_to_date(hoi.org_information2),'DD-Mon-RRRR') org_information3
1057                                                           FROM hr_organization_units hou
1058                                                               ,hr_organization_information hoi
1059                                                          WHERE hoi.organization_id   = hou.organization_id
1060                                                            AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1061                                                            AND hoi.org_information_context = 'PER_IN_IT_CHALLAN_INFO'
1062                                                            AND hoi.org_information1 = g_tax_year
1063                                                            AND hoi.org_information13 = g_quarter
1064                                                            AND hoi.org_information5 IS NULL
1065                                                            AND hoi.organization_id = g_gre_id
1066 			                                 )
1067          AND (
1068                 (
1069                     g_correction_mode IN ('%','C3')
1070                     AND
1071                     pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number') IN
1072                     (
1073                                        SELECT action_information1
1074                                          FROM pay_action_information
1075                                         WHERE action_information_category IN('IN_24QC_CHALLAN','IN_24Q_CHALLAN')
1076                                           AND (
1077                                                 action_information15 = p_payroll_action_id
1078                                                 AND action_information_category = 'IN_24QC_CHALLAN'
1079                                                 AND action_information2 = g_year||g_quarter
1080                                                 AND action_information15 IN
1081                                                                            (
1082                                                                             (SELECT bank.org_information4||' - '||hoi.org_information3 ||' - ' ||to_char(fnd_date.canonical_to_date(hoi.org_information2),'DD-Mon-RRRR') org_information3
1083                                                            FROM hr_organization_units hou
1084                                                                ,hr_organization_information hoi
1085                                                                ,hr_organization_information bank
1086                                                           WHERE hoi.organization_id   = hou.organization_id
1087                                                             AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1088                                                             AND hoi.org_information_context = 'PER_IN_IT_CHALLAN_INFO'
1089                                                             AND hoi.org_information1 = g_tax_year
1090                                                             AND bank.org_information_context = 'PER_IN_CHALLAN_BANK'
1091                                                             and bank.organization_id = hoi.organization_id
1092                                                             AND hoi.org_information5 = bank.org_information_id
1093                                                             AND hoi.org_information13 = g_quarter
1094                                                             AND hoi.organization_id = g_gre_id
1095                                                          UNION
1096                                                         SELECT 'BOOK - '||hoi.org_information3 ||' - ' ||to_char(fnd_date.canonical_to_date(hoi.org_information2),'DD-Mon-RRRR') org_information3
1097                                                           FROM hr_organization_units hou
1098                                                               ,hr_organization_information hoi
1099                                                          WHERE hoi.organization_id   = hou.organization_id
1100                                                            AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1101                                                            AND hoi.org_information_context = 'PER_IN_IT_CHALLAN_INFO'
1102                                                            AND hoi.org_information1 = g_tax_year
1103                                                            AND hoi.org_information13 = g_quarter
1104                                                            AND hoi.org_information5 IS NULL
1105                                                            AND hoi.organization_id = g_gre_id
1106 			                                 )
1107                                                                            )
1108                                                 )
1109                                                 OR
1110                                                 (
1111                                                 action_information_category = 'IN_24Q_CHALLAN'
1112                                                 AND action_context_id   = p_payroll_action_id
1113                                                 )
1114                     )
1115                 )
1116                 OR
1117                 (g_correction_mode IN ('%','C9')
1118                 AND
1119                 pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number') NOT IN
1120                        (
1121                                        SELECT action_information1
1122                                          FROM pay_action_information
1123                                         WHERE action_information_category IN('IN_24QC_CHALLAN','IN_24Q_CHALLAN')
1124                                           AND (
1125                                                 action_information15 = p_payroll_action_id
1126                                                 AND action_information_category = 'IN_24QC_CHALLAN'
1127                                                 AND action_information2 = g_year||g_quarter
1128                                                 AND action_information15 IN
1129 						(SELECT bank.org_information4||' - '||hoi.org_information3 ||' - ' ||to_char(fnd_date.canonical_to_date(hoi.org_information2),'DD-Mon-RRRR') org_information3
1130                                                            FROM hr_organization_units hou
1131                                                                ,hr_organization_information hoi
1132                                                                ,hr_organization_information bank
1133                                                           WHERE hoi.organization_id   = hou.organization_id
1134                                                             AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1135                                                             AND hoi.org_information_context = 'PER_IN_IT_CHALLAN_INFO'
1136                                                             AND hoi.org_information1 = g_tax_year
1137                                                             AND bank.org_information_context = 'PER_IN_CHALLAN_BANK'
1138                                                             and bank.organization_id = hoi.organization_id
1139                                                             AND hoi.org_information5 = bank.org_information_id
1140                                                             AND hoi.org_information13 = g_quarter
1141                                                             AND hoi.organization_id = g_gre_id
1142                                                          UNION
1143                                                         SELECT 'BOOK - '||hoi.org_information3 ||' - ' ||to_char(fnd_date.canonical_to_date(hoi.org_information2),'DD-Mon-RRRR') org_information3
1144                                                           FROM hr_organization_units hou
1145                                                               ,hr_organization_information hoi
1146                                                          WHERE hoi.organization_id   = hou.organization_id
1147                                                            AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1148                                                            AND hoi.org_information_context = 'PER_IN_IT_CHALLAN_INFO'
1149                                                            AND hoi.org_information1 = g_tax_year
1150                                                            AND hoi.org_information13 = g_quarter
1151                                                            AND hoi.org_information5 IS NULL
1152                                                            AND hoi.organization_id = g_gre_id
1153 			                                 )
1154                                                 )
1155                                                 OR
1156                                                 (
1157                                                 action_information_category = 'IN_24Q_CHALLAN'
1158                                                 AND action_context_id   = p_payroll_action_id
1159                                                 )
1160                         )
1161                 )
1162               )
1163               ORDER BY 4;
1164 
1165     CURSOR c_update_mode_entries(p_payroll_action_id        NUMBER
1166                                 )
1167     IS
1168        SELECT pai.source_id     element_entry_id
1169              ,pai.assignment_id assignment_id
1170              ,pai.action_context_id   last_action_context_id
1171              ,pep.effective_end_date
1172          FROM pay_action_information pai
1173              ,pay_assignment_actions  paa
1174              ,per_people_f            pep
1175              ,per_assignments_f       asg
1176         WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
1177           AND pai.action_context_id = paa.assignment_action_id
1178           AND pai.action_information3 = g_gre_id
1179           AND paa.payroll_action_id = p_payroll_action_id
1180           AND asg.assignment_id     = pai.assignment_id
1181           AND asg.person_id         = pep.person_id
1182           AND asg.business_group_id = pep.business_group_id
1183           AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1184           AND (
1185                 (
1186                   (NVL(pai.action_information13,'0') <> (SELECT  NVL(paei.aei_information2,'0')
1187                                                            FROM  per_assignment_extra_info paei
1188                                                                 ,per_assignments_f paa
1189                                                           WHERE  paei.information_type = 'PER_IN_TAX_EXEMPTION_DF'
1190                                                             AND  paei.aei_information_category = 'PER_IN_TAX_EXEMPTION_DF'
1191                                                             AND  paei.assignment_id = paa.assignment_id
1192                                                             AND  paa.assignment_id  = asg.assignment_id
1193                                                             AND  paei.aei_information1 = g_tax_year
1194                                                             AND  assignment_end_date(asg.assignment_id) BETWEEN paa.effective_start_date AND paa.effective_end_date
1195                                                             AND  ROWNUM = 1)
1196                  )
1197                OR
1198                   (TO_NUMBER(remove_curr_format(pai.action_information6))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Income Tax Deducted'))))
1199                OR
1200                   (TO_NUMBER(remove_curr_format(pai.action_information7))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Surcharge Deducted'))))
1201                OR
1202                   (TO_NUMBER(remove_curr_format(pai.action_information8))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Education Cess Deducted'))))
1203                OR
1204                   (TO_NUMBER(remove_curr_format(pai.action_information5))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Taxable Income'))))
1205                OR
1206                   (pai.action_information4  <> pay_in_utils.get_ee_value(pai.source_id,'Payment Date'))
1207                OR
1208                   (pai.action_information12 <> hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title))
1209                OR
1210                   (NVL(pai.action_information11,'0') <> NVL(pep.per_information14,'0'))
1211                OR(
1212                      (
1213                            g_correction_mode IN ('C5','%')
1214                        AND (pai.action_information10 NOT IN('APPLIEDFOR','PANNOTAVBL'))
1215                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))NOT IN('APPLIEDFOR','PANNOTAVBL'))
1216                        AND (pai.action_information10 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
1217                      )
1218                      OR
1219                      (
1220                        g_correction_mode NOT IN ('C5')
1221                        AND (pai.action_information10 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
1222                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))IN('APPLIEDFOR','PANNOTAVBL'))
1223                      )
1224                 )
1225                )
1226               AND pay_in_utils.get_ee_value(pai.source_id,'Challan or Voucher Number') = pai.action_information1
1227              )
1228           AND   assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
1229           AND   assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
1230           ORDER BY 4 DESC;
1231 
1232     CURSOR c_check_entries_in_24q_correct(p_24q_arc_action_context_id NUMBER
1233                                          ,p_assignment_id             NUMBER
1234                                          ,p_element_entry_id          NUMBER
1235                                          ,p_mode                      VARCHAR2
1236                                          )
1237     IS
1238        SELECT pai_locking.action_context_id  last_action_context_id
1239          FROM pay_action_information pai_locking
1240              ,pay_action_interlocks locks
1241              ,pay_assignment_actions paa
1242         WHERE pai_locking.action_information_category = 'IN_24QC_DEDUCTEE'
1243           AND pai_locking.action_information3  = g_gre_id
1244           AND pai_locking.action_information15 = p_mode
1245           AND pai_locking.action_context_id    = paa.assignment_action_id
1246           AND paa.payroll_action_id IN
1247                                     (
1248                                       SELECT org_information3
1249                                         FROM hr_organization_information
1250                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1251                                          AND organization_id  = g_gre_id
1252                                          AND org_information1 = g_year
1253                                          AND org_information2 = g_quarter
1254                                          AND org_information5 = 'A'
1255                                          AND org_information6 = 'C'
1256                                     )
1257           AND locks.locking_action_id          = pai_locking.action_context_id
1258           AND locks.locked_action_id           = p_24q_arc_action_context_id
1259           AND pai_locking.assignment_id        = p_assignment_id
1260           AND pai_locking.source_id            = p_element_entry_id
1261         ORDER BY pai_locking.action_context_id DESC;
1262 
1263     CURSOR c_24qc_upd_mode_entries(p_assignment_action_id        NUMBER
1264                                   ,p_element_entry_id            NUMBER
1265                                   )
1266     IS
1267        SELECT pai.action_context_id
1268          FROM pay_action_information pai
1269              ,per_people_f           pep
1270              ,per_assignments_f      asg
1271              ,pay_assignment_actions paa
1272         WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
1273           AND paa.assignment_action_id = pai.action_context_id
1274           AND pai.source_id     = p_element_entry_id
1275           AND paa.payroll_action_id IN
1276                            (
1277                              SELECT org_information3
1278                                FROM hr_organization_information
1279                               WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1280                                 AND organization_id  = g_gre_id
1281                                 AND org_information1 = g_year
1282                                 AND org_information2 = g_quarter
1283                                 AND org_information5 = 'A'
1284                                 AND org_information6 = 'C'
1285                           )
1286           AND pai.action_information3 = g_gre_id
1287           AND pai.action_context_id = p_assignment_action_id
1288           AND asg.assignment_id     = pai.assignment_id
1289           AND asg.person_id         = pep.person_id
1290           AND asg.business_group_id = pep.business_group_id
1291           AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1292           AND (
1293                   (NVL(pai.action_information18,'0') <> (SELECT  NVL(paei.aei_information2,'0')
1294                                                            FROM  per_assignment_extra_info paei
1295                                                                 ,per_assignments_f paa
1296                                                           WHERE  paei.information_type = 'PER_IN_TAX_EXEMPTION_DF'
1297                                                             AND  paei.aei_information_category = 'PER_IN_TAX_EXEMPTION_DF'
1298                                                             AND  paei.assignment_id = paa.assignment_id
1299                                                             AND  paa.assignment_id = asg.assignment_id
1300                                                             AND  paei.aei_information1 = g_tax_year
1301                                                             AND  assignment_end_date(asg.assignment_id) BETWEEN paa.effective_start_date AND paa.effective_end_date
1302                                                             AND  ROWNUM = 1)
1303                  )
1304                OR
1305                   (TO_NUMBER(remove_curr_format(pai.action_information6))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Income Tax Deducted'))))
1306                OR
1307                   (TO_NUMBER(remove_curr_format(pai.action_information7))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Surcharge Deducted'))))
1308                OR
1309                   (TO_NUMBER(remove_curr_format(pai.action_information8))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Education Cess Deducted'))))
1310                OR
1311                   (TO_NUMBER(remove_curr_format(pai.action_information5))  <> TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Taxable Income'))))
1312                OR
1313                   (pai.action_information4  <> pay_in_utils.get_ee_value(pai.source_id,'Payment Date'))
1314                OR
1315                   (pai.action_information10 <> hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title))
1316                OR(--Checking PAN Number
1317                     (
1318                            g_correction_mode IN ('C5','%')
1319                        AND (pai.action_information9 NOT IN('APPLIEDFOR','PANNOTAVBL'))
1320                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))NOT IN('APPLIEDFOR','PANNOTAVBL'))
1321                        AND (pai.action_information9 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
1322                      )
1323                      OR
1324                      (
1325                        g_correction_mode NOT IN ('C5')
1326                        AND (pai.action_information9 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
1327                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))IN('APPLIEDFOR','PANNOTAVBL'))
1328                      )
1329                 )
1330               OR -- Checking PAN reference Number
1331                   (NVL(pai.action_information11,'0') <> NVL(pep.per_information14,'0'))
1332               )
1333           AND  assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
1334           AND  assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
1335           AND NOT EXISTS
1336           (
1337        SELECT 1
1338          FROM pay_action_information pai
1339              ,per_people_f           pep
1340              ,per_assignments_f      asg
1341         WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
1342           AND pai.source_id            = p_element_entry_id
1343           AND pai.action_information3  = g_gre_id
1344           AND pai.action_context_id    = p_assignment_action_id
1345           AND asg.assignment_id        = pai.assignment_id
1346           AND asg.person_id            = pep.person_id
1347           AND asg.business_group_id    = pep.business_group_id
1348           AND asg.business_group_id    = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1349           AND (
1350                   (NVL(pai.action_information18,'0') = (SELECT  NVL(paei.aei_information2,'0')
1351                                                            FROM  per_assignment_extra_info paei
1352                                                                 ,per_assignments_f paa
1353                                                           WHERE  paei.information_type = 'PER_IN_TAX_EXEMPTION_DF'
1354                                                             AND  paei.aei_information_category = 'PER_IN_TAX_EXEMPTION_DF'
1355                                                             AND  paei.assignment_id = paa.assignment_id
1356                                                             AND  paa.assignment_id = asg.assignment_id
1357                                                             AND  paei.aei_information1 = g_tax_year
1358                                                             AND  assignment_end_date(asg.assignment_id) BETWEEN paa.effective_start_date AND paa.effective_end_date
1359                                                             AND  ROWNUM = 1)
1360                  )
1361                AND
1362                   (TO_NUMBER(remove_curr_format(pai.action_information6))  = TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Income Tax Deducted'))))
1363                AND
1364                   (TO_NUMBER(remove_curr_format(pai.action_information7))  = TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Surcharge Deducted'))))
1365                AND
1366                   (TO_NUMBER(remove_curr_format(pai.action_information8))  = TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Education Cess Deducted'))))
1367                AND
1368                   (TO_NUMBER(remove_curr_format(pai.action_information5))  = TO_NUMBER(remove_curr_format(pay_in_utils.get_ee_value(pai.source_id,'Taxable Income'))))
1369                AND
1370                   (pai.action_information4  = pay_in_utils.get_ee_value(pai.source_id,'Payment Date'))
1371                AND
1372                   (pai.action_information10 = hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title))
1373                AND(--Checking PAN Number
1374                      (
1375                            g_correction_mode IN ('C5','%')
1376                        AND (pai.action_information9 NOT IN('APPLIEDFOR','PANNOTAVBL'))
1377                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))NOT IN('APPLIEDFOR','PANNOTAVBL'))
1378                        AND (pai.action_information9 = (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
1379                      )
1380                      OR
1381                      (
1382                        g_correction_mode NOT IN ('C5')
1383                        AND (pai.action_information9 = (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
1384                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))IN('APPLIEDFOR','PANNOTAVBL'))
1385                      )
1386                 )
1387               AND -- Checking PAN reference Number
1388                   (NVL(pai.action_information11,'0') = NVL(pep.per_information14,'0'))
1389               )
1390           AND  assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
1391           AND  assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
1392          );
1393 
1394     CURSOR c_form_24qc_locking_id(p_mode           VARCHAR2
1395                                  ,p_flag           NUMBER
1396                                  )
1397     IS
1398       SELECT MAX(pai.action_context_id) last_action_context_id
1399             ,pai.source_id              element_entry_id
1400             ,pai.assignment_id          assignment_id
1401         FROM pay_action_information pai
1402             ,pay_assignment_actions paa
1403        WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
1404          AND pai.action_information3         = g_gre_id
1405          AND pai.action_information2         = g_year||g_quarter
1406          AND pai.action_information15        = p_mode
1407          AND pai.action_context_id           = paa.assignment_action_id
1408          AND paa.payroll_action_id IN
1409                               (
1410                                 SELECT org_information3
1411                                   FROM hr_organization_information
1412                                  WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1413                                    AND organization_id  = g_gre_id
1414                                    AND org_information1 = g_year
1415                                    AND org_information2 = g_quarter
1416                                    AND org_information5 = 'A'
1417                                    AND org_information6 = 'C'
1418                               )
1419         AND (
1420                 p_flag = 1
1421                 OR
1422                 (
1423                  pai.source_id NOT IN(
1424                                 SELECT pai.source_id
1425                                   FROM pay_action_information pai
1426                                       ,pay_assignment_actions paa
1427                                  WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
1428                                    AND pai.action_information3         = g_gre_id
1429                                    AND pai.action_information2         = g_year||g_quarter
1430                                    AND pai.action_information15        = 'D'
1431                                    AND pai.action_context_id           = paa.assignment_action_id
1432                                    AND paa.payroll_action_id IN
1433                                                         (
1434                                                               SELECT org_information3
1435                                                                 FROM hr_organization_information
1436                                                                WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1437                                                                  AND organization_id  = g_gre_id
1438                                                                  AND org_information1 = g_year
1439                                                                  AND org_information2 = g_quarter
1440                                                                  AND org_information5 = 'A'
1441                                                                  AND org_information6 = 'C'
1442                                                         )
1443                                    )
1444                 AND pai.source_id IN
1445                                      (SELECT entry.element_entry_id
1446                                         FROM pay_element_entries_f entry
1447                                             ,pay_element_types_f   types
1448                                        WHERE entry.assignment_id = pai.assignment_id
1449                                          AND entry.element_type_id = types.element_type_id
1450                                          AND types.element_name = 'Income Tax Challan Information'
1451                                          AND types.legislation_code = 'IN'
1452                                          AND entry.effective_start_date BETWEEN g_qr_start_date
1453                                          AND g_qr_end_date
1454                                         )
1455                 )
1456             )
1457         GROUP BY pai.source_id,pai.assignment_id;
1458 
1459     CURSOR c_live_ee
1460     IS
1461       SELECT entry.element_entry_id  element_entry_id
1462             ,entry.assignment_id     assignment_id
1463             ,pay_in_utils.get_ee_value(entry.element_entry_id,'Challan or Voucher Number') challan
1464         FROM pay_element_entries_f      entry
1465             ,pay_element_types_f        types
1466        WHERE entry.element_type_id   = types.element_type_id
1467          AND types.element_name      = 'Income Tax Challan Information'
1468          AND types.legislation_code  = 'IN'
1469          AND entry.effective_start_date BETWEEN g_qr_start_date AND g_qr_end_date;
1470 
1471     CURSOR c_bg_check(p_assignment_id   NUMBER)
1472     IS
1473       SELECT 1
1474         FROM per_assignments_f
1475        WHERE business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
1476          AND assignment_id     = p_assignment_id;
1477 
1478     l_procedure                 VARCHAR2(100);
1479     l_action_id                 NUMBER;
1480     l_dummy                     NUMBER;
1481     l_flag                      BOOLEAN;
1482     l_last_action_context_id    NUMBER;
1483     i                           NUMBER;
1484     l_message                   VARCHAR2(250);
1485     l_bg_check                  NUMBER;
1486 
1487   --
1488   BEGIN
1489   --
1490     g_debug := hr_utility.debug_enabled;
1491     l_procedure  :=  g_package || '.generate_employee_data';
1492 
1493     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
1494 
1495    --The below process finds those Challan Element Entries which have MODE as Deletion(D)
1496     pay_in_utils.set_location(g_debug,'Finding element entries deleted since last statement ',2);
1497    FOR c_rec IN c_delete_mode_entries(p_payroll_action_id)
1498    LOOP
1499           l_bg_check := 0;
1500           OPEN  c_bg_check(c_rec.assignment_id);
1501           FETCH c_bg_check INTO l_bg_check;
1502           CLOSE c_bg_check;
1503 
1504           IF (l_bg_check = 1)
1505           THEN
1506                g_ee_data_rec_del(g_count_ee_delete).last_action_context_id := c_rec.last_action_context_id;
1507                g_ee_data_rec_del(g_count_ee_delete).assignment_id          := c_rec.assignment_id;
1508                g_ee_data_rec_del(g_count_ee_delete).element_entry_id       := c_rec.element_entry_id;
1509                g_ee_data_rec_del(g_count_ee_delete).deductee_mode          := 'D';
1510                g_count_ee_delete := g_count_ee_delete + 1;
1511           END IF;
1512    END LOOP;
1513 
1514     pay_in_utils.set_location(g_debug,'Finding element entries added since last statement ',3);
1515 --The below process finds those Challan Element Entries which have MODE as Addition(A)
1516     FOR c_rec IN c_addition_mode_entries(p_payroll_action_id)
1517     LOOP
1518           l_bg_check := 0;
1519           OPEN  c_bg_check(c_rec.assignment_id);
1520           FETCH c_bg_check INTO l_bg_check;
1521           CLOSE c_bg_check;
1522 
1523           IF (l_bg_check = 1)
1524           THEN
1525                g_ee_data_rec_add(g_count_ee_addition).last_action_context_id := c_rec.last_action_context_id;
1526                g_ee_data_rec_add(g_count_ee_addition).assignment_id          := c_rec.assignment_id;
1527                g_ee_data_rec_add(g_count_ee_addition).element_entry_id       := c_rec.element_entry_id;
1528                g_ee_data_rec_add(g_count_ee_addition).deductee_mode          := 'A';
1529                g_count_ee_addition := g_count_ee_addition + 1;
1530           END IF;
1531     END LOOP;
1532 --The below cursor finds those Challan Element Entries that have cyclic challan number change
1533     FOR c_rec IN c_live_ee
1534     LOOP
1535        l_bg_check := 0;
1536        OPEN  c_bg_check(c_rec.assignment_id);
1537        FETCH c_bg_check INTO l_bg_check;
1538        CLOSE c_bg_check;
1539 
1540        IF (l_bg_check = 1)
1541        THEN
1542             IF (c_rec.challan <> check_ee_in_qc(c_rec.element_entry_id))
1543             THEN
1544                 pay_in_utils.set_location(g_debug,'Live Challan Value is: '|| c_rec.challan,1);
1545                 pay_in_utils.set_location(g_debug,'Old Challan Value is: '|| check_ee_in_qc(c_rec.element_entry_id),2);
1546                 g_ee_data_rec_add(g_count_ee_addition).last_action_context_id := NULL;
1547                 g_ee_data_rec_add(g_count_ee_addition).assignment_id          := c_rec.assignment_id;
1548                 g_ee_data_rec_add(g_count_ee_addition).element_entry_id       := c_rec.element_entry_id;
1549                 g_ee_data_rec_add(g_count_ee_addition).deductee_mode          := 'A';
1550                 g_count_ee_addition := g_count_ee_addition + 1;
1551             END IF;
1552        END IF;
1553     END LOOP;
1554 --The below process finds those Challan Element Entries which have MODE as Updation(U)
1555 -- This code checks U from Form 24Q Archival to Live Data
1556     pay_in_utils.set_location(g_debug,'Finding element entries updated since last statement ',4);
1557     pay_in_utils.set_location(g_debug,'Finding diff between live data and 24Q Archival ', 1);
1558 
1559     l_flag := TRUE;
1560     FOR csr_rec IN c_update_mode_entries(p_payroll_action_id)
1561     LOOP
1562         pay_in_utils.set_location(g_debug,'Diff between live data and 24Q Archival found', 1);
1563         pay_in_utils.set_location(g_debug,'p_payroll_action_id is '|| p_payroll_action_id,2);
1564         pay_in_utils.set_location(g_debug,'Finding diff between live data and 24Q Correction Archival ', 1);
1565         pay_in_utils.set_location(g_debug,'csr_rec.last_action_context_id '|| csr_rec.last_action_context_id,2);
1566         pay_in_utils.set_location(g_debug,'csr_rec.assignment_id          '|| csr_rec.assignment_id         ,2);
1567         pay_in_utils.set_location(g_debug,'csr_rec.element_entry_id       '|| csr_rec.element_entry_id      ,2);
1568 
1569         l_flag := TRUE;
1570 
1571         FOR c_rec IN c_check_entries_in_24q_correct(csr_rec.last_action_context_id
1572                                                    ,csr_rec.assignment_id
1573                                                    ,csr_rec.element_entry_id
1574                                                    ,'U'
1575                                                    )
1576         LOOP
1577            IF ((c_rec.last_action_context_id IS NOT NULL)AND l_flag)
1578            THEN
1579                   l_last_action_context_id := c_rec.last_action_context_id;
1580                   pay_in_utils.set_location(g_debug,'Record was reported in 24Q Correction',11);
1581                   pay_in_utils.set_location(g_debug,'with action context id as ' || l_last_action_context_id,1);
1582                   l_flag := FALSE;
1583            END IF;
1584         END LOOP;
1585 
1586         pay_in_utils.set_location(g_debug,'Mid way in finding updated element entries ', 5);
1587         IF (l_last_action_context_id IS NULL)
1588         THEN
1589            pay_in_utils.set_location(g_debug,'Record was not reported in 24Q Correction',1);
1590            pay_in_utils.set_location(g_debug,'Hence storing earlier values based on 24Q',1);
1591            g_ee_data_rec_upd(g_count_ee_update).last_action_context_id := csr_rec.last_action_context_id;
1592            g_ee_data_rec_upd(g_count_ee_update).assignment_id          := csr_rec.assignment_id;
1593            g_ee_data_rec_upd(g_count_ee_update).element_entry_id       := csr_rec.element_entry_id;
1594            g_ee_data_rec_upd(g_count_ee_update).deductee_mode          := 'U';
1595            g_count_ee_update := g_count_ee_update + 1;
1596         ELSE --Present then need to check the present values with the archived values under Form 24QCorrection
1597                 l_dummy := NULL;
1598                 pay_in_utils.set_location(g_debug,'Record was reported in 24Q Correction',1);
1599                 pay_in_utils.set_location(g_debug,'Need to compare the value from 24Q Correction now',1);
1600                 OPEN  c_24qc_upd_mode_entries(l_last_action_context_id,csr_rec.element_entry_id);
1601                 FETCH c_24qc_upd_mode_entries INTO l_dummy;
1602                 CLOSE c_24qc_upd_mode_entries;
1603 
1604                 IF (l_dummy IS NOT NULL) THEN
1605                      pay_in_utils.set_location(g_debug,'Difference from 24Q Correction Data',1);
1606                      pay_in_utils.set_location(g_debug,'l_dummy is '|| l_dummy,1);
1607                      pay_in_utils.set_location(g_debug,'csr_rec.element_entry_id'|| csr_rec.element_entry_id,2);
1608                      g_ee_data_rec_upd(g_count_ee_update).last_action_context_id := l_dummy;
1609                      g_ee_data_rec_upd(g_count_ee_update).assignment_id          := csr_rec.assignment_id;
1610                      g_ee_data_rec_upd(g_count_ee_update).element_entry_id       := csr_rec.element_entry_id;
1611                      g_ee_data_rec_upd(g_count_ee_update).deductee_mode          := 'U';
1612                      g_count_ee_update := g_count_ee_update + 1;
1613                      pay_in_utils.set_location(g_debug,'Stored data as 24Q Correction Data',1);
1614                 END IF;
1615         END IF;
1616     END LOOP;
1617         pay_in_utils.set_location(g_debug,'Additional Checking on updated element entries ', 6);
1618 --Similarly need to repeat the above structure for the case when data after submission to authorities
1619 --was updated, form 24qc generated again updated to original form and 24qc again generated
1620 --The following code checks U for Data under Form 24Q Correction.
1621 
1622 -- This cursor finds all those Form 24Q Corrections that are locking Form 24Q
1623     pay_in_utils.set_location(g_debug,'Now checking those element entries that have same data in live and 24QC ', 7);
1624     FOR c_rec IN c_form_24qc_locking_id('U',1)
1625     LOOP
1626 
1627        l_flag  := TRUE;
1628        l_dummy := NULL;
1629 
1630        pay_in_utils.set_location(g_debug,'Checking 24qc+ and Live Here',1);
1631        pay_in_utils.set_location(g_debug,'c_rec.last_action_context_id' || c_rec.last_action_context_id,1);
1632        pay_in_utils.set_location(g_debug,'c_rec.element_entry_id' || c_rec.element_entry_id,2);
1633 
1634        OPEN  c_24qc_upd_mode_entries(c_rec.last_action_context_id,c_rec.element_entry_id);
1635        FETCH c_24qc_upd_mode_entries INTO l_dummy;
1636        CLOSE c_24qc_upd_mode_entries;
1637 
1638        IF (l_dummy IS NOT NULL)
1639        THEN
1640             pay_in_utils.set_location(g_debug,'Diff found with the Live Data',3);
1641             FOR i IN 1.. g_count_ee_update - 1
1642             LOOP
1643                IF (
1644                   (g_ee_data_rec_upd(i).last_action_context_id = c_rec.last_action_context_id)
1645                   AND
1646                   (g_ee_data_rec_upd(i).assignment_id          = c_rec.assignment_id)
1647                   AND
1648                   (g_ee_data_rec_upd(i).element_entry_id       = c_rec.element_entry_id)
1649                   AND
1650                   (g_ee_data_rec_upd(i).deductee_mode          = 'U')
1651                   )
1652                THEN
1653                     l_flag := FALSE;
1654                END IF;
1655             END LOOP;
1656        ELSE
1657             pay_in_utils.set_location(g_debug,'No Diff found with the Live Data',3);
1658            l_flag  := FALSE;
1659        END IF;
1660 
1661        IF (l_flag)
1662        THEN
1663                g_ee_data_rec_upd(g_count_ee_update).last_action_context_id := c_rec.last_action_context_id;
1664                g_ee_data_rec_upd(g_count_ee_update).assignment_id          := c_rec.assignment_id;
1665                g_ee_data_rec_upd(g_count_ee_update).element_entry_id       := c_rec.element_entry_id;
1666                g_ee_data_rec_upd(g_count_ee_update).deductee_mode          := 'U';
1667                g_count_ee_update := g_count_ee_update + 1;
1668        END IF;
1669 
1670     END LOOP;
1671     --Now Searching for those updated element entries that were created after
1672     --form 24Q Correction generation
1673     pay_in_utils.set_location(g_debug,'Now Searching for those updated element entries that were 24QC+',1);
1674     FOR c_rec IN c_form_24qc_locking_id('A',2)
1675     LOOP
1676        l_dummy := NULL;
1677        pay_in_utils.set_location(g_debug,'c_rec.last_action_context_id '|| c_rec.last_action_context_id,1);
1678        pay_in_utils.set_location(g_debug,'c_rec.assignment_id          '|| c_rec.assignment_id         ,1);
1679        pay_in_utils.set_location(g_debug,'c_rec.element_entry_id       '|| c_rec.element_entry_id      ,1);
1680 
1681        OPEN  c_24qc_upd_mode_entries(c_rec.last_action_context_id,c_rec.element_entry_id);
1682        FETCH c_24qc_upd_mode_entries INTO l_dummy;
1683        CLOSE c_24qc_upd_mode_entries;
1684        pay_in_utils.set_location(g_debug,'l_dummy is '|| l_dummy,2);
1685        IF (l_dummy IS NOT NULL)
1686        THEN
1687                g_ee_data_rec_upd(g_count_ee_update).last_action_context_id := c_rec.last_action_context_id;
1688                g_ee_data_rec_upd(g_count_ee_update).assignment_id          := c_rec.assignment_id;
1689                g_ee_data_rec_upd(g_count_ee_update).element_entry_id       := c_rec.element_entry_id;
1690                g_ee_data_rec_upd(g_count_ee_update).deductee_mode          := 'U';
1691                g_count_ee_update := g_count_ee_update + 1;
1692        END IF;
1693     END LOOP;
1694     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,30);
1695   --
1696   EXCEPTION
1697     WHEN OTHERS THEN
1698       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
1699       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
1700   END generate_employee_data;
1701 
1702 
1703 --------------------------------------------------------------------------
1704 --                                                                      --
1705 -- Name           : GET_FORMAT_VALUE                                    --
1706 -- Type           : FUNCTION                                            --
1707 -- Access         : Public                                              --
1708 -- Description    : This function returns value with precision          --
1709 --                  of two decimal place                                --
1710 --                                                                      --
1711 -- Parameters     :                                                     --
1712 --             IN : p_value              VARCHAR2                       --
1713 --------------------------------------------------------------------------
1714 FUNCTION get_format_value(p_value IN VARCHAR2)
1715 RETURN VARCHAR2 IS
1716 
1717 l_value      VARCHAR2(20);
1718 l_procedure  VARCHAR2(100);
1719 
1720 BEGIN
1721  g_debug          := hr_utility.debug_enabled;
1722  l_procedure := g_package ||'.get_format_value';
1723  pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
1724  IF g_debug THEN
1725    pay_in_utils.trace('p_value',p_value);
1726  END IF;
1727 
1728  IF(NVL(p_value,0)=0) THEN
1729        RETURN '0.00';
1730  END IF;
1731 
1732 l_value := (p_value*100);
1733 
1734 l_value := SUBSTR(l_value,1,length(l_value)-2)||'.'||SUBSTR(l_value,length(l_value)-1,length(l_value));
1735 
1736 
1737 IF g_debug THEN
1738      pay_in_utils.trace('l_value',l_value);
1739 END IF;
1740 
1741 pay_in_utils.set_location(g_debug,'LEAVING: '||l_procedure,20);
1742 
1743 RETURN l_value;
1744 
1745 END get_format_value;
1746 
1747 --------------------------------------------------------------------------
1748 --                                                                      --
1749 -- Name           : GET_24Q_VALUES                                      --
1750 -- Type           : FUNCTION                                            --
1751 -- Access         : Public                                              --
1752 -- Description    : This function returns the values corresponding to   --
1753 --                  the F16 Balances                                    --
1754 -- Parameters     :                                                     --
1755 --             IN : p_category          VARCHAR2                        --
1756 --                  p_component_name    VARCHAR2                        --
1757 --                  p_context_id        NUMBER                          --
1758 --                  p_source_id         NUMBER                          --
1759 --                  p_segment_num       NUMBER                          --
1760 --------------------------------------------------------------------------
1761 FUNCTION get_24Q_values (p_category       IN VARCHAR2
1762                         ,p_component_name IN VARCHAR2
1763                         ,p_context_id     IN NUMBER
1764                         ,p_source_id      IN NUMBER
1765                         ,p_segment_num    IN NUMBER )
1766 RETURN VARCHAR2 IS
1767 
1768 CURSOR c_form24Q_values IS
1769   SELECT  NVL(action_information2,0)
1770     FROM  pay_action_information
1771    WHERE  action_information_category = p_category
1772      AND  action_information1 = p_component_name
1773      AND  action_context_id = p_context_id
1774      AND  source_id = p_source_id;
1775 
1776 l_value1 VARCHAR2(20);
1777 l_procedure varchar2(100);
1778 
1779 BEGIN
1780 g_debug          := hr_utility.debug_enabled;
1781 l_procedure := g_package ||'.get_24Q_values';
1782 pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
1783 
1784  IF g_debug THEN
1785         pay_in_utils.trace('**************************************************','********************');
1786         pay_in_utils.trace('p_category',p_category);
1787         pay_in_utils.trace('p_component_name',p_component_name);
1788         pay_in_utils.trace('p_context_id',TO_CHAR(p_context_id));
1789         pay_in_utils.trace('p_source_id',TO_CHAR(p_source_id));
1790         pay_in_utils.trace('p_segment_num',TO_CHAR(p_segment_num));
1791         pay_in_utils.trace('**************************************************','********************');
1792  END IF;
1793 
1794   OPEN c_form24Q_values;
1795   FETCH c_form24Q_values INTO l_value1;
1796   IF c_form24Q_values%NOTFOUND THEN
1797     CLOSE c_form24Q_values;
1798     RETURN '0.00';
1799   END IF;
1800   CLOSE c_form24Q_values;
1801 
1802   pay_in_utils.set_location(g_debug,'l_value1 = : '||l_value1,15);
1803 
1804   l_value1 := get_format_value(l_value1);
1805 
1806   pay_in_utils.set_location(g_debug,'l_value1 = : '||l_value1,20);
1807 
1808   pay_in_utils.set_location(g_debug,'LEAVING: '||l_procedure,40);
1809 
1810   IF(p_segment_num=1) THEN
1811        RETURN l_value1;
1812   END IF;
1813 
1814 END get_24Q_values;
1815 
1816   --------------------------------------------------------------------------
1817   --                                                                      --
1818   -- Name           : GENERATE_SALARY_DATA                                --
1819   -- Type           : PROCEDURE                                           --
1820   -- Access         : Private                                             --
1821   -- Description    : This procedure populates global tables used in      --
1822   --                  salary detail record                                --
1823   -- Parameters     :                                                     --
1824   --             IN : p_payroll_action_id    NUMBER                       --
1825   --            OUT : N/A                                                 --
1826   --                                                                      --
1827   -- Change History :                                                     --
1828   --------------------------------------------------------------------------
1829   -- Rev#  Date           Userid    Description                           --
1830   --------------------------------------------------------------------------
1831   -- 115.0 07-Feb-2007    rpalli    5754018 : 24QC Quarter4 Stat Update   --
1832   --------------------------------------------------------------------------
1833  PROCEDURE generate_salary_data(p_payroll_action_id   IN NUMBER
1834                                ,p_start_person        IN NUMBER
1835                                ,p_end_person          IN NUMBER)
1836   IS
1837 
1838     CURSOR c_delete_mode_entries(p_payroll_action_id        NUMBER)
1839     IS
1840        SELECT pai.source_id           source_id
1841              ,pai.assignment_id       assignment_id
1842              ,pai.action_context_id   last_action_context_id
1843          FROM pay_action_information pai
1844              ,pay_assignment_actions paa
1845         WHERE pai.action_information_category LIKE 'IN_24Q%_PERSON'
1846           AND fnd_number.canonical_to_number(pai.action_information1)
1847               BETWEEN p_start_person AND p_end_person
1848           AND pai.action_context_id = paa.assignment_action_id
1849           AND
1850            ( pai.action_information_category = 'IN_24Q_PERSON'
1851              OR
1852              (pai.action_information_category = 'IN_24QC_PERSON' AND pai.action_information10 IN ('A'))
1853             )
1854           AND(
1855                 paa.payroll_action_id IN (
1856                                            SELECT org_information3
1857                                              FROM hr_organization_information
1858                                             WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1859                                               AND organization_id  = g_gre_id
1860                                               AND org_information1 = g_year
1861                                               AND org_information2 = g_quarter
1862                                               AND org_information5 = 'A'
1863                                           )
1864              )
1865           AND pai.action_information3 = g_gre_id
1866           AND (
1867               pai.source_id  NOT IN
1868              (
1869              SELECT
1870                  paa.assignment_action_id run_asg_action_id
1871              FROM pay_assignment_actions paa
1872                  ,pay_payroll_actions ppa
1873                  ,per_assignments_f paf
1874              WHERE paf.assignment_id = paa.assignment_id
1875              AND paa.assignment_id = pai.assignment_id
1876              AND paa.tax_unit_id  = pai.action_information3
1877              AND paa.payroll_action_id = ppa.payroll_action_id
1878              AND ppa.action_type IN('R','Q','I','B')
1879              AND ppa.payroll_id    = paf.payroll_id
1880              AND ppa.action_status ='C'
1881              AND ppa.effective_date between g_start_date and g_end_date
1882              AND paa.source_action_id IS NULL
1883              AND (1 = DECODE(ppa.action_type,'I',1,0)
1884              OR EXISTS (SELECT ''
1885                         FROM pay_action_interlocks intk,
1886                              pay_assignment_actions paa1,
1887                              pay_payroll_actions ppa1
1888                         WHERE intk.locked_action_id = paa.assignment_Action_id
1889                         AND intk.locking_action_id =  paa1.assignment_action_id
1890                         AND paa1.payroll_action_id =ppa1.payroll_action_id
1891                         AND ppa1.action_type in('P','U')
1892                         AND ppa.action_type in('R','Q','B')
1893                         AND ppa1.action_status ='C'
1894                         AND ppa1.effective_date BETWEEN g_start_date and g_end_date
1895                         AND ROWNUM =1 ))
1896                       )
1897              )
1898          AND (
1899                 pai.source_id NOT IN
1900                       (SELECT pai.source_id
1901                          FROM pay_action_information pai
1902                              ,pay_action_interlocks locks
1903                              ,pay_assignment_actions paa
1904                              ,pay_assignment_actions masters
1905                         WHERE pai.action_information_category = 'IN_24QC_PERSON'
1906                           AND pai.action_information10        IN  ('D')
1907                           AND locks.locking_action_id         = pai.action_context_id
1908                           AND locks.locked_action_id          = paa.assignment_action_id
1909                           AND paa.payroll_action_id           = p_payroll_action_id
1910                           AND paa.assignment_id               = pai.assignment_id
1911                           AND masters.assignment_id            = pai.assignment_id
1912                           AND masters.assignment_action_id     = pai.action_context_id
1913                           AND masters.payroll_action_id IN(
1914                                                            SELECT org_information3
1915                                                              FROM hr_organization_information
1916                                                             WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1917                                                               AND organization_id  = g_gre_id
1918                                                               AND org_information1 = g_year
1919                                                               AND org_information2 = g_quarter
1920                                                               AND org_information5 = 'A'
1921                                                               AND org_information6 = 'C'
1922                                                      )
1923                       )
1924            )
1925            ORDER BY 2 DESC;
1926 
1927     CURSOR c_addition_mode_entries(p_payroll_action_id        NUMBER)
1928     IS
1929     SELECT a.source_id,a.assignment_id,a.last_action_context_id
1930      FROM
1931            (SELECT
1932               FND_NUMBER.CANONICAL_TO_NUMBER(SUBSTR(MAX(LPAD(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) source_id
1933               ,paf.assignment_id       assignment_id
1934               ,NULL    last_action_context_id
1935              FROM pay_assignment_actions paa
1936                  ,pay_payroll_actions ppa
1937                  ,per_assignments_f paf
1938              WHERE paf.person_id BETWEEN p_start_person AND p_end_person
1939              AND paf.assignment_id = paa.assignment_id
1940              AND paa.tax_unit_id  = g_gre_id
1941              AND paa.payroll_action_id = ppa.payroll_action_id
1942              AND ppa.action_type IN('R','Q','I','B')
1943              AND ppa.payroll_id    = paf.payroll_id
1944              AND ppa.action_status ='C'
1945              AND ppa.effective_date between g_start_date and g_end_date
1946              AND paa.source_action_id IS NULL
1947              AND (1 = DECODE(ppa.action_type,'I',1,0)
1948               OR EXISTS (SELECT ''
1949                         FROM pay_action_interlocks intk,
1950                              pay_assignment_actions paa1,
1951                              pay_payroll_actions ppa1
1952                         WHERE intk.locked_action_id = paa.assignment_Action_id
1953                         AND intk.locking_action_id =  paa1.assignment_action_id
1954                         AND paa1.payroll_action_id =ppa1.payroll_action_id
1955                         AND ppa1.action_type in('P','U')
1956                         AND ppa.action_type in('R','Q','B')
1957                         AND ppa1.action_status ='C'
1958                         AND ppa1.effective_date BETWEEN g_start_date and g_end_date
1959                         AND ROWNUM =1 ))
1960                        GROUP BY paf.assignment_id) a
1961            WHERE (
1962                   a.source_id NOT IN
1963                       (SELECT pai.source_id
1964                          FROM pay_action_information pai
1965                              ,pay_assignment_actions paa
1966                         WHERE pai.action_information_category = 'IN_24Q_PERSON'
1967                           AND pai.action_context_id   = paa.assignment_action_id
1968                           AND paa.payroll_action_id   = p_payroll_action_id
1969                       )
1970                 )
1971            AND (
1972                  a.source_id NOT IN
1973                       (SELECT pai.source_id
1974                          FROM pay_action_information pai
1975                              ,pay_action_interlocks locks
1976                              ,pay_assignment_actions paa
1977                              ,pay_assignment_actions paa_24qc
1978                         WHERE pai.action_information_category = 'IN_24QC_PERSON'
1979                           AND locks.locking_action_id         = pai.action_context_id
1980                           AND locks.locked_action_id          = paa.assignment_action_id
1981                           AND paa.payroll_action_id           = p_payroll_action_id
1982                           AND paa.assignment_id               = pai.assignment_id
1983                           AND pai.action_information2         = g_year||g_quarter
1984                           AND paa_24qc.assignment_id          = pai.assignment_id
1985                           AND paa_24qc.assignment_action_id   = pai.action_context_id
1986                           AND paa_24qc.payroll_action_id IN(
1987                                                       SELECT org_information3
1988                                                         FROM hr_organization_information
1989                                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
1990                                                          AND organization_id  = g_gre_id
1991                                                          AND org_information1 = g_year
1992                                                          AND org_information2 = g_quarter
1993                                                          AND org_information5 = 'A'
1994                                                          AND org_information6 = 'C'
1995                                                      )
1996                       )
1997                 )
1998            AND (
1999                  a.source_id NOT IN
2000                       (SELECT pai.source_id
2001                          FROM pay_action_information pai
2002                              ,pay_action_interlocks locks
2003                              ,pay_assignment_actions paa
2004                              ,pay_assignment_actions paa_24qc
2005                         WHERE pai.action_information_category = 'IN_24QC_PERSON'
2006                           AND locks.locking_action_id         = pai.action_context_id
2007                           AND locks.locked_action_id          = paa.assignment_action_id
2008                           AND paa.payroll_action_id           = p_payroll_action_id
2009                           AND paa.assignment_id               = pai.assignment_id
2010                           AND pai.action_information2         = g_year||g_quarter
2011                           AND paa_24qc.assignment_id          = pai.assignment_id
2012                           AND paa_24qc.assignment_action_id   = pai.action_context_id
2013                           AND paa_24qc.payroll_action_id IN(
2014                                                       SELECT org_information3
2015                                                         FROM hr_organization_information
2016                                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
2017                                                          AND organization_id  = g_gre_id
2018                                                          AND org_information1 = g_year
2019                                                          AND org_information2 = g_quarter
2020                                                          AND org_information5 = 'A'
2021                                                          AND org_information6 = 'C'
2022                                                      )
2023                       )
2024                 )
2025            AND (
2026                  a.source_id NOT IN
2027                       (SELECT pai.source_id
2028                          FROM pay_action_information pai
2029                              ,pay_assignment_actions paa_24qc
2030                         WHERE pai.action_information_category = 'IN_24QC_PERSON'
2031                           AND pai.action_information3         = g_gre_id
2032                           AND pai.action_information2         = g_year||g_quarter
2033                           AND paa_24qc.assignment_id          = pai.assignment_id
2034                           AND paa_24qc.assignment_action_id   = pai.action_context_id
2035                           AND paa_24qc.payroll_action_id IN(
2036                                                       SELECT org_information3
2037                                                         FROM hr_organization_information
2038                                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
2039                                                          AND organization_id  = g_gre_id
2040                                                          AND org_information1 = g_year
2041                                                          AND org_information2 = g_quarter
2042                                                          AND org_information5 = 'A'
2043                                                          AND org_information6 = 'C'
2044                                                      )
2045                       )
2046                 )
2047             ORDER BY 2 DESC;
2048 
2049 
2050    CURSOR c_update_mode_entries(p_payroll_action_id        NUMBER
2051                                 )
2052     IS
2053        SELECT DISTINCT
2054               pai.source_id     source_id
2055              ,pai.assignment_id assignment_id
2056              ,pai.action_context_id   last_action_context_id
2057              ,pep.effective_end_date
2058          FROM pay_action_information pai
2059              ,pay_assignment_actions  paa
2060              ,per_people_f            pep
2061              ,per_assignments_f       asg
2062         WHERE pai.action_information_category = 'IN_24Q_PERSON'
2063           AND fnd_number.canonical_to_number(pai.action_information1)
2064               BETWEEN p_start_person AND p_end_person
2065           AND pai.action_context_id = paa.assignment_action_id
2066           AND pai.action_information3 = g_gre_id
2067           AND paa.payroll_action_id = p_payroll_action_id
2068           AND asg.assignment_id     = pai.assignment_id
2069           AND asg.person_id         = pep.person_id
2070           AND asg.business_group_id = pep.business_group_id
2071           AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2072           AND pai.source_id  IN
2073              (
2074              SELECT
2075                  paa.assignment_action_id run_asg_action_id
2076              FROM pay_assignment_actions paa
2077                  ,pay_payroll_actions ppa
2078                  ,per_assignments_f paf
2079              WHERE paf.person_id BETWEEN p_start_person AND p_end_person
2080              AND paf.assignment_id = paa.assignment_id
2081              AND paa.assignment_id = pai.assignment_id
2082              AND paa.tax_unit_id  = pai.action_information3
2083              AND paa.payroll_action_id = ppa.payroll_action_id
2084              AND ppa.action_type IN('R','Q','I','B')
2085              AND ppa.payroll_id    = paf.payroll_id
2086              AND ppa.action_status ='C'
2087              AND ppa.effective_date between g_start_date and g_end_date
2088              AND paa.source_action_id IS NULL
2089              AND (1 = DECODE(ppa.action_type,'I',1,0)
2090              OR EXISTS (SELECT ''
2091                         FROM pay_action_interlocks intk,
2092                              pay_assignment_actions paa1,
2093                              pay_payroll_actions ppa1
2094                         WHERE intk.locked_action_id = paa.assignment_Action_id
2095                         AND intk.locking_action_id =  paa1.assignment_action_id
2096                         AND paa1.payroll_action_id =ppa1.payroll_action_id
2097                         AND ppa1.action_type in('P','U')
2098                         AND ppa.action_type in('R','Q','B')
2099                         AND ppa1.action_status ='C'
2100                         AND ppa1.effective_date BETWEEN g_start_date and g_end_date
2101                         AND ROWNUM =1 ))
2102                )
2103            AND (
2104                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Salary Under Section 17',pai.action_context_id,pai.source_id,1)))
2105                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Salary Under Section 17','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2106                OR
2107                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Profit in lieu of Salary',pai.action_context_id,pai.source_id,1)))
2108                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Profit in lieu of Salary','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2109                OR
2110                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Value of Perquisites',pai.action_context_id,pai.source_id,1)))
2111                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Value of Perquisites','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2112                OR
2113                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Gross Salary less Allowances',pai.action_context_id,pai.source_id,1)))
2114                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Gross Salary less Allowances','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2115                OR
2116                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Allowances Exempt',pai.action_context_id,pai.source_id,1)))
2117                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Allowances Exempt','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2118                OR
2119                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Deductions under Sec 16',pai.action_context_id,pai.source_id,1)))
2120                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Deductions under Sec 16','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2121                OR
2122                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Income Chargeable Under head Salaries',pai.action_context_id,pai.source_id,1)))
2123                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Income Chargeable Under head Salaries','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2124                OR
2125                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Other Income',pai.action_context_id,pai.source_id,1)))
2126                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Other Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2127                OR
2128                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Gross Total Income',pai.action_context_id,pai.source_id,1)))
2129                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Gross Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2130                OR
2131                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Total Income',pai.action_context_id,pai.source_id,1)))
2132                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2133                OR
2134                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Tax on Total Income',pai.action_context_id,pai.source_id,1)))
2135                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Tax on Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2136                OR
2137                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Marginal Relief',pai.action_context_id,pai.source_id,1)))
2138                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Marginal Relief','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2139                OR
2140                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Total Tax payable',pai.action_context_id,pai.source_id,1)))
2141                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Tax payable','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2142                OR
2143                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Relief under Sec 89',pai.action_context_id,pai.source_id,1)))
2144                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Relief under Sec 89','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2145                OR
2146                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Employment Tax',pai.action_context_id,pai.source_id,1)))
2147                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Employment Tax','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2148                OR
2149                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Entertainment Allowance',pai.action_context_id,pai.source_id,1)))
2150                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Entertainment Allowance','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2151                OR
2152                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Surcharge',pai.action_context_id,pai.source_id,1)))
2153                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Surcharge','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2154                OR
2155                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Education Cess',pai.action_context_id,pai.source_id,1)))
2156                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Education Cess','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2157                OR
2158                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 TDS',pai.action_context_id,pai.source_id,1)))
2159                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 TDS','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2160                OR
2161                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_SALARY','F16 Total Chapter VI A Deductions',pai.action_context_id,pai.source_id,1)))
2162                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Chapter VI A Deductions','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2163                OR
2164                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24Q_VIA','80CCE',pai.action_context_id,pai.source_id,1)))
2165                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Deductions Sec 80CCE','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2166                OR
2167                   (pai.action_information6 <> hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title))
2168                OR -- Checking PAN reference Number
2169                    (NVL(pai.action_information5,'0') <> NVL(pep.per_information14,'0'))
2170                OR ( --Checking PAN Number
2171                      (
2172                        g_correction_mode IN ('C5','%')
2173                        AND (pai.action_information4 NOT IN('APPLIEDFOR','PANNOTAVBL'))
2174                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))NOT IN('APPLIEDFOR','PANNOTAVBL'))
2175                        AND (pai.action_information4 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
2176                      )
2177                      OR
2178                      (
2179                        g_correction_mode NOT IN ('C5')
2180                        AND (pai.action_information4 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
2181                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))IN('APPLIEDFOR','PANNOTAVBL'))
2182                      )
2183                  )
2184               )
2185           AND   assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
2186           AND   assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
2187           ORDER BY 2,4 DESC;
2188 
2189 
2190     CURSOR c_check_entries_in_24q_correct(p_24q_arc_action_context_id NUMBER
2191                                          ,p_assignment_id             NUMBER
2192                                          ,p_source_id                 NUMBER
2193                                          )
2194     IS
2195        SELECT pai_locking.action_context_id  last_action_context_id
2196          FROM pay_action_information pai_locking
2197              ,pay_action_interlocks locks
2198              ,pay_assignment_actions paa
2199         WHERE pai_locking.action_information_category = 'IN_24QC_PERSON'
2200           AND fnd_number.canonical_to_number(pai_locking.action_information1)
2201               BETWEEN p_start_person AND p_end_person
2202           AND pai_locking.action_information3  = g_gre_id
2203           AND pai_locking.action_context_id    = paa.assignment_action_id
2204           AND paa.payroll_action_id IN
2205                                     (
2206                                       SELECT org_information3
2207                                         FROM hr_organization_information
2208                                        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
2209                                          AND organization_id  = g_gre_id
2210                                          AND org_information1 = g_year
2211                                          AND org_information2 = g_quarter
2212                                          AND org_information5 = 'A'
2213                                          AND org_information6 = 'C'
2214                                     )
2215           AND locks.locking_action_id          = pai_locking.action_context_id
2216           AND locks.locked_action_id           = p_24q_arc_action_context_id
2217           AND pai_locking.assignment_id        = p_assignment_id
2218           AND pai_locking.source_id            = p_source_id
2219         ORDER BY pai_locking.action_context_id DESC;
2220 
2221     CURSOR c_24qc_upd_mode_entries(p_assignment_action_id        NUMBER
2222                                   ,p_source_id                   NUMBER
2223                                   )
2224     IS
2225        SELECT pai.action_context_id
2226          FROM pay_action_information pai
2227              ,per_people_f           pep
2228              ,per_assignments_f      asg
2229              ,pay_assignment_actions paa
2230         WHERE pai.action_information_category = 'IN_24QC_PERSON'
2231           AND fnd_number.canonical_to_number(pai.action_information1)
2232               BETWEEN p_start_person AND p_end_person
2233           AND paa.assignment_action_id = pai.action_context_id
2234           AND pai.source_id     = p_source_id
2235           AND paa.payroll_action_id IN
2236                            (
2237                              SELECT org_information3
2238                                FROM hr_organization_information
2239                               WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
2240                                 AND organization_id  = g_gre_id
2241                                 AND org_information1 = g_year
2242                                 AND org_information2 = g_quarter
2243                                 AND org_information5 = 'A'
2244                                 AND org_information6 = 'C'
2245                           )
2246           AND pai.action_information3 = g_gre_id
2247           AND pai.action_context_id = p_assignment_action_id
2248           AND asg.assignment_id     = pai.assignment_id
2249           AND asg.person_id         = pep.person_id
2250           AND asg.business_group_id = pep.business_group_id
2251           AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2252           AND pai.source_id  IN
2253              (
2254              SELECT
2255                  paa.assignment_action_id run_asg_action_id
2256              FROM pay_assignment_actions paa
2257                  ,pay_payroll_actions ppa
2258                  ,per_assignments_f paf
2259              WHERE paf.person_id BETWEEN p_start_person AND p_end_person
2260              AND paf.assignment_id = paa.assignment_id
2261              AND paa.assignment_id = pai.assignment_id
2262              AND paa.tax_unit_id  = pai.action_information3
2263              AND paa.payroll_action_id = ppa.payroll_action_id
2264              AND ppa.action_type IN('R','Q','I','B')
2265              AND ppa.payroll_id    = paf.payroll_id
2266              AND ppa.action_status ='C'
2267              AND ppa.effective_date between g_start_date and g_end_date
2268              AND paa.source_action_id IS NULL
2269              AND (1 = DECODE(ppa.action_type,'I',1,0)
2270                   OR EXISTS (SELECT ''
2271                              FROM pay_action_interlocks intk,
2272                                   pay_assignment_actions paa1,
2273                                   pay_payroll_actions ppa1
2274                              WHERE intk.locked_action_id = paa.assignment_Action_id
2275                              AND intk.locking_action_id =  paa1.assignment_action_id
2276                              AND paa1.payroll_action_id =ppa1.payroll_action_id
2277                              AND ppa1.action_type in('P','U')
2278                              AND ppa.action_type in('R','Q','B')
2279                              AND ppa1.action_status ='C'
2280                              AND ppa1.effective_date BETWEEN g_start_date and g_end_date
2281                              AND ROWNUM =1 ))
2282                 )
2283           AND (
2284                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Salary Under Section 17',pai.action_context_id,pai.source_id,1)))
2285                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Salary Under Section 17','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2286                OR
2287                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Profit in lieu of Salary',pai.action_context_id,pai.source_id,1)))
2288                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Profit in lieu of Salary','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2289                OR
2290                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Value of Perquisites',pai.action_context_id,pai.source_id,1)))
2291                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Value of Perquisites','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2292                OR
2293                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Gross Salary less Allowances',pai.action_context_id,pai.source_id,1)))
2294                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Gross Salary less Allowances','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2295                OR
2296                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Allowances Exempt',pai.action_context_id,pai.source_id,1)))
2297                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Allowances Exempt','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2298                OR
2299                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Deductions under Sec 16',pai.action_context_id,pai.source_id,1)))
2300                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Deductions under Sec 16','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2301                OR
2302                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Income Chargeable Under head Salaries',pai.action_context_id,pai.source_id,1)))
2303                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Income Chargeable Under head Salaries','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2304                OR
2305                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Other Income',pai.action_context_id,pai.source_id,1)))
2306                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Other Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2307                OR
2308                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Gross Total Income',pai.action_context_id,pai.source_id,1)))
2309                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Gross Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2310                OR
2311                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Total Income',pai.action_context_id,pai.source_id,1)))
2312                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2313                OR
2314                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Tax on Total Income',pai.action_context_id,pai.source_id,1)))
2315                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Tax on Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2316                OR
2317                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Marginal Relief',pai.action_context_id,pai.source_id,1)))
2318                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Marginal Relief','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2319                OR
2320                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Total Tax payable',pai.action_context_id,pai.source_id,1)))
2321                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Tax payable','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2322                OR
2323                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Relief under Sec 89',pai.action_context_id,pai.source_id,1)))
2324                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Relief under Sec 89','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2325                OR
2326                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Employment Tax',pai.action_context_id,pai.source_id,1)))
2327                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Employment Tax','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2328                OR
2329                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Entertainment Allowance',pai.action_context_id,pai.source_id,1)))
2330                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Entertainment Allowance','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2331                OR
2332                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Surcharge',pai.action_context_id,pai.source_id,1)))
2333                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Surcharge','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2334                OR
2335                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Education Cess',pai.action_context_id,pai.source_id,1)))
2336                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Education Cess','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2337                OR
2338                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 TDS',pai.action_context_id,pai.source_id,1)))
2339                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 TDS','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2340                OR
2341                 (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Total Chapter VI A Deductions',pai.action_context_id,pai.source_id,1)))
2342                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Chapter VI A Deductions','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2343                OR
2344                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_VIA','80CCE',pai.action_context_id,pai.source_id,1)))
2345                    <> FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Deductions Sec 80CCE','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2346                OR
2347                   (pai.action_information6 <> hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title))
2348                OR
2349                    (NVL(pai.action_information5,'0') <> NVL(pep.per_information14,'0'))
2350                OR(
2351                      (
2352                        g_correction_mode IN ('C5','%')
2353                        AND (pai.action_information4 NOT IN('APPLIEDFOR','PANNOTAVBL'))
2354                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))NOT IN('APPLIEDFOR','PANNOTAVBL'))
2355                        AND (pai.action_information4 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
2356                      )
2357                      OR
2358                      (
2359                        g_correction_mode NOT IN ('C5')
2360                        AND (pai.action_information4 <> (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
2361                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))IN('APPLIEDFOR','PANNOTAVBL'))
2362                      )
2363                  )
2364               )
2365           AND  assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
2366           AND  assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
2367           AND NOT EXISTS
2368           (
2369        SELECT 1
2370          FROM pay_action_information pai
2371              ,per_people_f           pep
2372              ,per_assignments_f      asg
2373         WHERE pai.action_information_category = 'IN_24QC_PERSON'
2374           AND fnd_number.canonical_to_number(pai.action_information1)
2375               BETWEEN p_start_person AND p_end_person
2376           AND pai.source_id            = p_source_id
2377           AND pai.action_information3  = g_gre_id
2378           AND pai.action_context_id    = p_assignment_action_id
2379           AND asg.assignment_id        = pai.assignment_id
2380           AND asg.person_id            = pep.person_id
2381           AND asg.business_group_id    = pep.business_group_id
2382           AND asg.business_group_id    = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2383           AND (
2384                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Salary Under Section 17',pai.action_context_id,pai.source_id,1)))
2385                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Salary Under Section 17','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2386                AND
2387                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Profit in lieu of Salary',pai.action_context_id,pai.source_id,1)))
2388                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Profit in lieu of Salary','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2389                AND
2390                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Value of Perquisites',pai.action_context_id,pai.source_id,1)))
2391                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Value of Perquisites','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2392                AND
2393                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Gross Salary less Allowances',pai.action_context_id,pai.source_id,1)))
2394                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Gross Salary less Allowances','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2395                AND
2396                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Allowances Exempt',pai.action_context_id,pai.source_id,1)))
2397                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Allowances Exempt','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2398                AND
2399                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Deductions under Sec 16',pai.action_context_id,pai.source_id,1)))
2400                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Deductions under Sec 16','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2401                AND
2402                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Income Chargeable Under head Salaries',pai.action_context_id,pai.source_id,1)))
2403                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Income Chargeable Under head Salaries','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2404                AND
2405                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Other Income',pai.action_context_id,pai.source_id,1)))
2406                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Other Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2407                AND
2408                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Gross Total Income',pai.action_context_id,pai.source_id,1)))
2409                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Gross Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2410                AND
2411                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Total Income',pai.action_context_id,pai.source_id,1)))
2412                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2413                AND
2414                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Tax on Total Income',pai.action_context_id,pai.source_id,1)))
2415                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Tax on Total Income','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2416                AND
2417                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Marginal Relief',pai.action_context_id,pai.source_id,1)))
2418                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Marginal Relief','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2419                AND
2420                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Total Tax payable',pai.action_context_id,pai.source_id,1)))
2421                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Tax payable','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2422                AND
2423                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Relief under Sec 89',pai.action_context_id,pai.source_id,1)))
2424                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Relief under Sec 89','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2425                AND
2426                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Employment Tax',pai.action_context_id,pai.source_id,1)))
2427                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Employment Tax','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2428                AND
2429                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Entertainment Allowance',pai.action_context_id,pai.source_id,1)))
2430                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Entertainment Allowance','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2431                AND
2432                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Surcharge',pai.action_context_id,pai.source_id,1)))
2433                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Surcharge','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2434                AND
2435                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Education Cess',pai.action_context_id,pai.source_id,1)))
2436                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Education Cess','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2437                AND
2438                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 TDS',pai.action_context_id,pai.source_id,1)))
2439                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 TDS','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2440                AND
2441                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_SALARY','F16 Total Chapter VI A Deductions',pai.action_context_id,pai.source_id,1)))
2442                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Total Chapter VI A Deductions','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2443                AND
2444                  (FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values('IN_24QC_VIA','80CCE',pai.action_context_id,pai.source_id,1)))
2445                    = FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(pay_in_tax_utils.get_balance_value(pai.source_id,'F16 Deductions Sec 80CCE','_ASG_LE_PTD','TAX_UNIT_ID',g_gre_id))))
2446                AND
2447                   (pai.action_information6 = hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title))
2448                AND(--Checking PAN Number
2449                      (
2450                        g_correction_mode IN ('C5','%')
2451                        AND (pai.action_information4 NOT IN('APPLIEDFOR','PANNOTAVBL'))
2452                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))NOT IN('APPLIEDFOR','PANNOTAVBL'))
2453                        AND (pai.action_information4 = (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
2454                      )
2455                      OR
2456                      (
2457                        g_correction_mode NOT IN ('C5')
2458                        AND (pai.action_information4 = (DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4)))
2459                        AND ((DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4))IN('APPLIEDFOR','PANNOTAVBL'))
2460                      )
2461                 )
2462               AND -- Checking PAN reference Number
2463                   (NVL(pai.action_information5,'0') = NVL(pep.per_information14,'0'))
2464               )
2465           AND  assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
2466           AND  assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
2467          );
2468 
2469    CURSOR c_form_24qc_locking_id(p_mode           VARCHAR2
2470                                 ,p_flag           NUMBER
2471                                  )
2472     IS
2473       SELECT MAX(pai.action_context_id) last_action_context_id
2474             ,pai.source_id              source_id
2475             ,pai.assignment_id          assignment_id
2476         FROM pay_action_information pai
2477             ,pay_assignment_actions paa
2478        WHERE pai.action_information_category = 'IN_24QC_PERSON'
2479          AND fnd_number.canonical_to_number(pai.action_information1)
2480               BETWEEN p_start_person AND p_end_person
2481          AND pai.action_information3         = g_gre_id
2482          AND pai.action_information2         = g_year||g_quarter
2483          AND
2484           (    ((p_flag = 1) AND (pai.action_information10 IN ('A','NA')))
2485             OR ((p_flag = 2) AND (pai.action_information10 = p_mode))
2486           )
2487          AND pai.action_context_id           = paa.assignment_action_id
2488          AND paa.payroll_action_id IN
2489                               (
2490                                 SELECT org_information3
2491                                   FROM hr_organization_information
2492                                  WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
2493                                    AND organization_id  = g_gre_id
2494                                    AND org_information1 = g_year
2495                                    AND org_information2 = g_quarter
2496                                    AND org_information5 = 'A'
2497                                    AND org_information6 = 'C'
2498                               )
2499         AND (
2500                 p_flag = 1
2501                 OR
2502                 (
2503                  pai.source_id NOT IN(
2504                                 SELECT pai.source_id
2505                                   FROM pay_action_information pai
2506                                       ,pay_assignment_actions paa
2507                                  WHERE pai.action_information_category = 'IN_24QC_PERSON'
2508                                    AND fnd_number.canonical_to_number(pai.action_information1)
2509                                        BETWEEN p_start_person AND p_end_person
2510                                    AND pai.action_information3         = g_gre_id
2511                                    AND pai.action_information2         = g_year||g_quarter
2512                                    AND pai.action_information10        = 'D'
2513                                    AND pai.action_context_id           = paa.assignment_action_id
2514                                    AND paa.payroll_action_id IN
2515                                                         (
2516                                                               SELECT org_information3
2517                                                                 FROM hr_organization_information
2518                                                                WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
2519                                                                  AND organization_id  = g_gre_id
2520                                                                  AND org_information1 = g_year
2521                                                                  AND org_information2 = g_quarter
2522                                                                  AND org_information5 = 'A'
2523                                                                  AND org_information6 = 'C'
2524                                                         )
2525                                    )
2526                    AND pai.source_id IN
2527                             (SELECT a.source_id
2528                              FROM
2529                                  (SELECT
2530                                     FND_NUMBER.CANONICAL_TO_NUMBER(SUBSTR(MAX(LPAD(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) source_id
2531                                     ,paf.assignment_id       assignment_id
2532                                     ,NULL    last_action_context_id
2533                                    FROM pay_assignment_actions paa
2534                                        ,pay_payroll_actions ppa
2535                                        ,per_assignments_f paf
2536                                    WHERE paf.person_id BETWEEN p_start_person AND p_end_person
2537                                    AND paf.assignment_id = paa.assignment_id
2538                                    AND paa.tax_unit_id  = g_gre_id
2539                                    AND paa.payroll_action_id = ppa.payroll_action_id
2540                                    AND ppa.action_type IN('R','Q','I','B')
2541                                    AND ppa.payroll_id    = paf.payroll_id
2542                                    AND ppa.action_status ='C'
2543                                    AND ppa.effective_date between g_start_date and g_end_date
2544                                    AND paa.source_action_id IS NULL
2545                                    AND (1 = DECODE(ppa.action_type,'I',1,0)
2546                                     OR EXISTS (SELECT ''
2547                                               FROM pay_action_interlocks intk,
2548                                                    pay_assignment_actions paa1,
2549                                                    pay_payroll_actions ppa1
2550                                               WHERE intk.locked_action_id = paa.assignment_Action_id
2551                                               AND intk.locking_action_id =  paa1.assignment_action_id
2552                                               AND paa1.payroll_action_id =ppa1.payroll_action_id
2553                                               AND ppa1.action_type in('P','U')
2554                                               AND ppa.action_type in('R','Q','B')
2555                                               AND ppa1.action_status ='C'
2556                                               AND ppa1.effective_date BETWEEN g_start_date and g_end_date
2557                                               AND ROWNUM =1 ))
2558                                              GROUP BY paf.assignment_id) a
2559                                                  WHERE
2560                                        a.assignment_id  = pai.assignment_id)
2561                  )
2562             )
2563         GROUP BY pai.assignment_id,pai.source_id;
2564 
2565     CURSOR c_bg_check(p_assignment_id   NUMBER)
2566     IS
2567       SELECT 1
2568         FROM per_assignments_f
2569        WHERE business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2570          AND assignment_id     = p_assignment_id;
2571 
2572     l_procedure                 VARCHAR2(100);
2573     l_action_id                 NUMBER;
2574     l_dummy                     NUMBER;
2575     l_flag                      BOOLEAN;
2576     l_last_action_context_id    NUMBER;
2577     i                           NUMBER;
2578     l_message                   VARCHAR2(250);
2579     l_bg_check                  NUMBER;
2580 
2581   --
2582   BEGIN
2583   --
2584     g_debug := hr_utility.debug_enabled;
2585     l_procedure  :=  g_package || '.generate_salary_data';
2586 
2587     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
2588 
2589     pay_in_utils.trace('p_start_person in  generate_salary_data-> ',p_start_person);
2590     pay_in_utils.trace('p_end_person in  generate_salary_data-> ',p_end_person);
2591 
2592 
2593    --The below process finds those Assignment Actions which have MODE as Deletion(D)
2594     pay_in_utils.set_location(g_debug,'Finding Assignment Actions deleted since last statement ',2);
2595    FOR c_rec IN c_delete_mode_entries(p_payroll_action_id)
2596    LOOP
2597           l_bg_check := 0;
2598           OPEN  c_bg_check(c_rec.assignment_id);
2599           FETCH c_bg_check INTO l_bg_check;
2600           CLOSE c_bg_check;
2601 
2602           IF (l_bg_check = 1)
2603           THEN
2604                g_sal_data_rec_del(g_count_sal_delete).source_id              := c_rec.source_id;
2605                g_sal_data_rec_del(g_count_sal_delete).last_action_context_id := c_rec.last_action_context_id;
2606                g_sal_data_rec_del(g_count_sal_delete).assignment_id          := c_rec.assignment_id;
2607                g_sal_data_rec_del(g_count_sal_delete).salary_mode            := 'D';
2608                g_count_sal_delete := g_count_sal_delete + 1;
2609           END IF;
2610    END LOOP;
2611 
2612     pay_in_utils.set_location(g_debug,'Finding Assignment Actions added since last statement ',3);
2613 
2614 --The below process finds those Assignment Actions which have MODE as Addition(A)
2615     FOR c_rec IN c_addition_mode_entries(p_payroll_action_id)
2616     LOOP
2617           l_bg_check := 0;
2618           OPEN  c_bg_check(c_rec.assignment_id);
2619           FETCH c_bg_check INTO l_bg_check;
2620           CLOSE c_bg_check;
2621 
2622           IF (l_bg_check = 1)
2623           THEN
2624                g_sal_data_rec_add(g_count_sal_addition).source_id              := c_rec.source_id;
2625                g_sal_data_rec_add(g_count_sal_addition).last_action_context_id := c_rec.last_action_context_id;
2626                g_sal_data_rec_add(g_count_sal_addition).assignment_id          := c_rec.assignment_id;
2627                g_sal_data_rec_add(g_count_sal_addition).salary_mode            := 'A';
2628                g_count_sal_addition := g_count_sal_addition + 1;
2629           END IF;
2630     END LOOP;
2631   --
2632 
2633 --The below process finds those Assignment Actions which have been updated
2634 -- This code checks A from Form 24Q Archival to Live Data
2635     pay_in_utils.set_location(g_debug,'Finding Assignment Actions updated since last statement ',4);
2636     pay_in_utils.set_location(g_debug,'Finding diff between live data and 24Q Archival ', 1);
2637 
2638     l_flag := TRUE;
2639     FOR csr_rec IN c_update_mode_entries(p_payroll_action_id)
2640     LOOP
2641         pay_in_utils.set_location(g_debug,'Diff between live data and 24Q Archival found', 1);
2642         pay_in_utils.set_location(g_debug,'p_payroll_action_id is '|| p_payroll_action_id,1);
2643         pay_in_utils.set_location(g_debug,'csr_rec.last_action_context_id '|| csr_rec.last_action_context_id,1);
2644         pay_in_utils.set_location(g_debug,'csr_rec.assignment_id          '|| csr_rec.assignment_id         ,1);
2645         pay_in_utils.set_location(g_debug,'csr_rec.source_id              '|| csr_rec.source_id      ,1);
2646 
2647         pay_in_utils.set_location(g_debug,'Finding diff between live data and 24Q Correction Archival ', 1);
2648 
2649         l_flag := TRUE;
2650         l_last_action_context_id := NULL;
2651 
2652         FOR c_rec IN c_check_entries_in_24q_correct(csr_rec.last_action_context_id
2653                                                    ,csr_rec.assignment_id
2654                                                    ,csr_rec.source_id
2655                                                    )
2656         LOOP
2657            IF ((c_rec.last_action_context_id IS NOT NULL) AND l_flag)
2658            THEN
2659                   l_last_action_context_id := c_rec.last_action_context_id;
2660                   pay_in_utils.set_location(g_debug,'Record was reported in 24Q Correction',2);
2661                   pay_in_utils.set_location(g_debug,'with action context id as ' || l_last_action_context_id,2);
2662                   l_flag := FALSE;
2663            END IF;
2664         END LOOP;
2665 
2666         pay_in_utils.set_location(g_debug,'Mid way in finding updated assignment actions', 3);
2667         pay_in_utils.trace('l_last_action_context_id after  c_check_entries_in_24q_correct is -> ',l_last_action_context_id);
2668 
2669         IF (l_last_action_context_id IS NULL)
2670         THEN
2671            pay_in_utils.set_location(g_debug,'Record was not reported in 24Q Correction',4);
2672            pay_in_utils.set_location(g_debug,'Hence storing earlier values based on 24Q',4);
2673            g_sal_data_rec_upd(g_count_sal_update).last_action_context_id := csr_rec.last_action_context_id;
2674            g_sal_data_rec_upd(g_count_sal_update).assignment_id          := csr_rec.assignment_id;
2675            g_sal_data_rec_upd(g_count_sal_update).source_id              := csr_rec.source_id;
2676            g_sal_data_rec_upd(g_count_sal_update).salary_mode            := 'U';
2677            g_count_sal_update := g_count_sal_update + 1;
2678 
2679         ELSE --Present then need to check the present values with the archived values under Form 24QCorrection
2680                 l_dummy := NULL;
2681                 pay_in_utils.set_location(g_debug,'Record was reported in 24Q Correction',5);
2682                 pay_in_utils.set_location(g_debug,'Need to compare the value from 24Q Correction now',5);
2683                 OPEN  c_24qc_upd_mode_entries(l_last_action_context_id,csr_rec.source_id);
2684                 FETCH c_24qc_upd_mode_entries INTO l_dummy;
2685                 CLOSE c_24qc_upd_mode_entries;
2686 
2687                 IF (l_dummy IS NOT NULL) THEN
2688                      pay_in_utils.set_location(g_debug,'Difference from 24Q Correction Data',6);
2689                      pay_in_utils.set_location(g_debug,'l_dummy is '|| l_dummy,6);
2690                      pay_in_utils.set_location(g_debug,'csr_rec.source_id'|| csr_rec.source_id,6);
2691                      g_sal_data_rec_upd(g_count_sal_update).last_action_context_id := l_dummy;
2692                      g_sal_data_rec_upd(g_count_sal_update).assignment_id          := csr_rec.assignment_id;
2693                      g_sal_data_rec_upd(g_count_sal_update).source_id              := csr_rec.source_id;
2694                      g_sal_data_rec_upd(g_count_sal_update).salary_mode            := 'U';
2695                      g_count_sal_update := g_count_sal_update + 1;
2696 
2697                      pay_in_utils.set_location(g_debug,'Stored data as 24Q Correction Data',6);
2698                 END IF;
2699         END IF;
2700     END LOOP;
2701 
2702 
2703         pay_in_utils.set_location(g_debug,'Additional Checking on updated assignment actions ', 7);
2704 --Similarly need to repeat the above structure for the case when data after submission to authorities
2705 --was updated, form 24qc generated again updated to original form and 24qc again generated
2706 --The following code checks U for Data under Form 24Q Correction.
2707 
2708 -- This cursor finds all those Form 24Q Corrections that are locking Form 24Q
2709     pay_in_utils.set_location(g_debug,'Now checking those assignment actions that have same data in live and 24QC ', 7);
2710     FOR c_rec IN c_form_24qc_locking_id('A',1)
2711     LOOP
2712 
2713        l_flag  := TRUE;
2714        l_dummy := NULL;
2715 
2716        pay_in_utils.set_location(g_debug,'Checking 24qc+ and Live Here',7);
2717        pay_in_utils.set_location(g_debug,'c_rec.last_action_context_id' || c_rec.last_action_context_id,7);
2718        pay_in_utils.set_location(g_debug,'c_rec.source_id' || c_rec.source_id,7);
2719 
2720        OPEN  c_24qc_upd_mode_entries(c_rec.last_action_context_id,c_rec.source_id);
2721        FETCH c_24qc_upd_mode_entries INTO l_dummy;
2722        CLOSE c_24qc_upd_mode_entries;
2723 
2724        pay_in_utils.trace('l_dummy in c_form_24qc_locking_id 1',l_dummy);
2725 
2726        IF (l_dummy IS NOT NULL)
2727        THEN
2728             pay_in_utils.set_location(g_debug,'Diff found with the Live Data',7);
2729             FOR i IN 1.. g_count_sal_update - 1
2730             LOOP
2731                IF (
2732                   (g_sal_data_rec_upd(i).last_action_context_id = c_rec.last_action_context_id)
2733                   AND
2734                   (g_sal_data_rec_upd(i).assignment_id          = c_rec.assignment_id)
2735                   AND
2736                   (g_sal_data_rec_upd(i).source_id       = c_rec.source_id)
2737                   AND
2738                   (g_sal_data_rec_upd(i).salary_mode          = 'U')
2739                   )
2740                THEN
2741                     l_flag := FALSE;
2742                END IF;
2743             END LOOP;
2744        ELSE
2745             pay_in_utils.set_location(g_debug,'No Diff found with the Live Data',7);
2746            l_flag  := FALSE;
2747        END IF;
2748 
2749        IF (l_flag)
2750        THEN
2751                g_sal_data_rec_upd(g_count_sal_update).last_action_context_id := c_rec.last_action_context_id;
2752                g_sal_data_rec_upd(g_count_sal_update).assignment_id          := c_rec.assignment_id;
2753                g_sal_data_rec_upd(g_count_sal_update).source_id              := c_rec.source_id;
2754                g_sal_data_rec_upd(g_count_sal_update).salary_mode            := 'U';
2755                g_count_sal_update := g_count_sal_update + 1;
2756 
2757        END IF;
2758 
2759     END LOOP;
2760     --Now Searching for those updated assignment actions that were created after
2761     --form 24Q Correction generation
2762     pay_in_utils.set_location(g_debug,'Now Searching for those updated assignment actions that were 24QC+',8);
2763     FOR c_rec IN c_form_24qc_locking_id('A',2)
2764     LOOP
2765        l_dummy := NULL;
2766        pay_in_utils.set_location(g_debug,'c_rec.last_action_context_id '|| c_rec.last_action_context_id,8);
2767        pay_in_utils.set_location(g_debug,'c_rec.assignment_id          '|| c_rec.assignment_id         ,8);
2768        pay_in_utils.set_location(g_debug,'c_rec.source_id       '|| c_rec.source_id      ,8);
2769 
2770        OPEN  c_24qc_upd_mode_entries(c_rec.last_action_context_id,c_rec.source_id);
2771        FETCH c_24qc_upd_mode_entries INTO l_dummy;
2772        CLOSE c_24qc_upd_mode_entries;
2773        pay_in_utils.set_location(g_debug,'l_dummy is '|| l_dummy,8);
2774        IF (l_dummy IS NOT NULL)
2775        THEN
2776                g_sal_data_rec_upd(g_count_sal_update).last_action_context_id := c_rec.last_action_context_id;
2777                g_sal_data_rec_upd(g_count_sal_update).assignment_id          := c_rec.assignment_id;
2778                g_sal_data_rec_upd(g_count_sal_update).source_id              := c_rec.source_id;
2779                g_sal_data_rec_upd(g_count_sal_update).salary_mode            := 'U';
2780                g_count_sal_update := g_count_sal_update + 1;
2781 
2782        END IF;
2783     END LOOP;
2784 
2785     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,120);
2786   --
2787 
2788   EXCEPTION
2789     WHEN OTHERS THEN
2790       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
2791       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
2792   END generate_salary_data;
2793 
2794 
2795   --------------------------------------------------------------------------
2796   --                                                                      --
2797   -- Name           : GET_ORG_DETAILS                                     --
2798   -- Type           : PROCEDURE                                           --
2799   -- Access         : Public                                              --
2800   -- Description    : This procedure returns the live value for an org    --
2801   -- Parameters     :                                                     --
2802   --             IN : p_gre_id   NUMBER                                   --
2803   --            OUT :                                                     --
2804   --                                                                      --
2805   -- Change History :                                                     --
2806   --------------------------------------------------------------------------
2807   -- Rev#  Date           Userid    Description                           --
2808   --------------------------------------------------------------------------
2809   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
2810   -- 115.1 25-Sep-2007    rsaharay  Modified c_pos,c_rep_address          --
2811   --------------------------------------------------------------------------
2812   PROCEDURE get_org_details(p_gre_id                IN NUMBER
2813                            ,p_tan_number           OUT NOCOPY VARCHAR2
2814                            ,p_deductor_type        OUT NOCOPY VARCHAR2
2815                            ,p_branch_or_division   OUT NOCOPY VARCHAR2
2816                            ,p_org_location         OUT NOCOPY NUMBER
2817                            ,p_pan_number           OUT NOCOPY VARCHAR2
2818                            ,p_legal_name           OUT NOCOPY VARCHAR2
2819                            ,p_rep_name             OUT NOCOPY VARCHAR2
2820                            ,p_rep_position         OUT NOCOPY VARCHAR2
2821                            ,p_rep_location         OUT NOCOPY NUMBER
2822                            ,p_rep_email_id         OUT NOCOPY VARCHAR2
2823                            ,p_rep_work_phone       OUT NOCOPY VARCHAR2
2824                            ,p_rep_std_code         OUT NOCOPY VARCHAR2
2825 			   ,p_state                OUT NOCOPY VARCHAR2
2826 	                   ,p_pao_code             OUT NOCOPY VARCHAR2
2827 	                   ,p_ddo_code             OUT NOCOPY VARCHAR2
2828                    	   ,p_ministry_name        OUT NOCOPY VARCHAR2
2829                            ,p_other_ministry_name  OUT NOCOPY VARCHAR2
2830                            ,p_pao_reg_code         OUT NOCOPY NUMBER
2831                    	   ,p_ddo_reg_code         OUT NOCOPY VARCHAR2
2832                            )
2833   IS
2834     CURSOR c_org_inc_tax_df_details
2835     IS
2836     SELECT hoi.org_information1        tan
2837           ,hoi.org_information3        emplr_type
2838           ,hoi.org_information6        emplr_type_24Q
2839           ,hoi.org_information4        reg_org_id
2840           ,hoi.org_information7        division
2841           ,hou.location_id             location_id
2842           ,hoi.org_information9        state
2843           ,hoi.org_information10       pao_code
2844           ,hoi.org_information11       ddo_code
2845           ,hoi.org_information12       ministry_name
2846           ,hoi.org_information13       other_ministry_name
2847           ,hoi.org_information14       pao_reg_code
2848           ,hoi.org_information15       ddo_reg_code
2849       FROM hr_organization_information hoi
2850           ,hr_organization_units       hou
2851      WHERE hoi.organization_id         = p_gre_id
2852        AND hoi.org_information_context = 'PER_IN_INCOME_TAX_DF'
2853        AND hou.organization_id         = hoi.organization_id
2854        AND hou.business_group_id       = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2855        AND g_qr_end_date BETWEEN hou.date_from AND NVL(hou.date_to,TO_DATE('31-12-4712','DD-MM-YYYY'));
2856 
2857     CURSOR c_reg_org_details(p_reg_org_id        NUMBER)
2858     IS
2859     SELECT hoi.org_information3        pan
2860           ,hoi.org_information4        legal_name
2861       FROM hr_organization_information  hoi
2862           ,hr_organization_units        hou
2863      WHERE hoi.organization_id = p_reg_org_id
2864        AND hoi.org_information_context = 'PER_IN_COMPANY_DF'
2865        AND hou.organization_id = hoi.organization_id
2866        AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2867        AND g_qr_end_date BETWEEN hou.date_from AND NVL(hou.date_to,TO_DATE('31-12-4712','DD-MM-YYYY'));
2868 
2869    CURSOR c_pos(p_person_id        NUMBER)
2870    IS
2871    SELECT nvl(pos.name,job.name) name
2872    FROM   per_positions     pos
2873          ,per_assignments_f asg
2874          ,per_jobs          job
2875    WHERE  asg.position_id=pos.position_id(+)
2876    AND    asg.job_id=job.job_id(+)
2877    AND    asg.person_id = p_person_id
2878    AND    asg.primary_flag = 'Y'
2879    AND    asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2880    AND    g_qr_end_date BETWEEN pos.date_effective(+) AND NVL(pos.date_end(+),TO_DATE('31-12-4712','DD-MM-YYYY'))
2881    AND    g_qr_end_date BETWEEN job.date_from(+) AND NVL(job.date_to(+),TO_DATE('31-12-4712','DD-MM-YYYY'))
2882    AND    g_qr_end_date BETWEEN asg.effective_start_date AND asg.effective_end_date;
2883 
2884 
2885    CURSOR c_rep_address(p_person_id         NUMBER)
2886    IS
2887    SELECT hou.location_id rep_location
2888      FROM per_assignments_f   asg
2889          ,hr_organization_units hou
2890     WHERE asg.person_id = p_person_id
2891       AND asg.primary_flag = 'Y'
2892       AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2893       AND hou.organization_id = asg.organization_id
2894       AND hou.business_group_id = asg.business_group_id
2895       AND g_qr_end_date BETWEEN asg.effective_start_date AND asg.effective_end_date
2896       AND g_qr_end_date BETWEEN hou.date_from AND NVL(hou.date_to,TO_DATE('31-12-4712','DD-MM-YYYY'));
2897 
2898    CURSOR c_representative_id
2899    IS
2900    SELECT pep.person_id
2901          ,hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title) rep_name
2902          ,pep.email_address        email_id
2903      FROM hr_organization_information   hoi
2904          ,hr_organization_units         hou
2905          ,per_people_f              pep
2906     WHERE hoi.org_information_context = 'PER_IN_INCOME_TAX_REP_DF'
2907       AND hoi.organization_id = p_gre_id
2908       AND hou.organization_id = hoi.organization_id
2909       AND hou.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
2910       AND pep.person_id = hoi.org_information1
2911       AND pep.business_group_id = hou.business_group_id
2912       AND g_qr_end_date BETWEEN pep.effective_start_date AND pep.effective_end_date
2913       AND g_qr_end_date BETWEEN fnd_date.canonical_to_date(hoi.org_information2)
2914       AND NVL(fnd_date.canonical_to_date(hoi.org_information3),TO_DATE('31-12-4712','DD-MM-YYYY'))
2915       AND g_qr_end_date BETWEEN hou.date_from AND NVL(hou.date_to,TO_DATE('31-12-4712','DD-MM-YYYY'));
2916 
2917    CURSOR c_rep_phone(p_person_id         NUMBER)
2918    IS
2919    SELECT phone_number rep_phone_no
2920          ,SUBSTR(phone_number
2921          ,INSTR(phone_number,'-',1,1) + 1
2922          ,INSTR(phone_number,'-',1,2) - INSTR(phone_number,'-',1,1) -1
2923          )STD_CODE
2924      FROM per_phones
2925     WHERE parent_id = p_person_id
2926       AND phone_type =  'W1'
2927       AND g_qr_end_date BETWEEN date_from AND NVL(date_to,TO_DATE('31-12-4712','DD-MM-YYYY'));
2928 
2929 
2930    l_reg_org_id          hr_organization_information.org_information4%TYPE;
2931    l_rep_person_id       per_all_people_f.person_id%TYPE;
2932    l_emplr_type          hr_organization_information.org_information3%TYPE;
2933    l_emplr_type_24Q      hr_organization_information.org_information6%TYPE;
2934    l_procedure           VARCHAR2(250);
2935    l_message             VARCHAR2(250);
2936   BEGIN
2937     g_debug     := hr_utility.debug_enabled;
2938     l_procedure := g_package ||'.get_org_details';
2939     pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
2940     pay_in_utils.set_location(g_debug,'Fetching Live Details ',2);
2941     OPEN  c_org_inc_tax_df_details;
2942     FETCH c_org_inc_tax_df_details INTO p_tan_number,l_emplr_type,l_emplr_type_24Q,l_reg_org_id,p_branch_or_division,p_org_location
2943      ,p_state,p_pao_code,p_ddo_code,p_ministry_name,p_other_ministry_name,p_pao_reg_code,p_ddo_reg_code;
2944     CLOSE c_org_inc_tax_df_details;
2945 
2946     IF g_old_format = 'Y' THEN
2947     p_deductor_type := l_emplr_type;
2948     ELSE
2949     p_deductor_type := l_emplr_type_24Q;
2950     END IF;
2951 
2952     pay_in_utils.set_location(g_debug,'p_tan_number              : '|| p_tan_number        ,1);
2953     pay_in_utils.set_location(g_debug,'p_org_location            : '|| p_org_location      ,1);
2954     pay_in_utils.set_location(g_debug,'p_branch_or_division      : '|| p_branch_or_division,1);
2955     pay_in_utils.set_location(g_debug,'p_deductor_type           : '|| p_deductor_type     ,1);
2956     pay_in_utils.set_location(g_debug,'l_reg_org_id              : '|| l_reg_org_id        ,1);
2957     pay_in_utils.set_location(g_debug,'p_state                   : '|| p_state             ,1);
2958     pay_in_utils.set_location(g_debug,'p_pao_code                : '|| p_pao_code          ,1);
2959     pay_in_utils.set_location(g_debug,'p_ddo_code                : '|| p_ddo_code          ,1);
2960     pay_in_utils.set_location(g_debug,'p_ministry_name           : '|| p_ministry_name     ,1);
2961     pay_in_utils.set_location(g_debug,'p_other_ministry_name     : '|| p_other_ministry_name ,1);
2962     pay_in_utils.set_location(g_debug,'p_pao_reg_code            : '|| p_pao_reg_code        ,1);
2963     pay_in_utils.set_location(g_debug,'p_ddo_reg_code            : '|| p_ddo_reg_code        ,1);
2964 
2965     OPEN  c_reg_org_details(l_reg_org_id);
2966     FETCH c_reg_org_details INTO p_pan_number,p_legal_name;
2967     CLOSE c_reg_org_details;
2968 
2969     pay_in_utils.set_location(g_debug,'p_pan_number           : '|| p_pan_number     ,2);
2970     pay_in_utils.set_location(g_debug,'p_legal_name           : '|| p_legal_name     ,2);
2971 
2972     OPEN  c_representative_id;
2973     FETCH c_representative_id INTO l_rep_person_id,p_rep_name,p_rep_email_id;
2974     CLOSE c_representative_id;
2975 
2976     pay_in_utils.set_location(g_debug,'l_rep_person_id           : '|| l_rep_person_id      ,2);
2977     pay_in_utils.set_location(g_debug,'p_rep_name                : '|| p_rep_name           ,2);
2978     pay_in_utils.set_location(g_debug,'p_rep_email_id            : '|| p_rep_email_id       ,2);
2979 
2980     OPEN  c_pos(l_rep_person_id);
2981     FETCH c_pos INTO p_rep_position;
2982     CLOSE c_pos;
2983 
2984     pay_in_utils.set_location(g_debug,'p_rep_position            : '|| p_rep_position       ,2);
2985 
2986     OPEN  c_rep_address(l_rep_person_id);
2987     FETCH c_rep_address INTO p_rep_location;
2988     CLOSE c_rep_address;
2989 
2990     pay_in_utils.set_location(g_debug,'p_rep_location            : '|| p_rep_location       ,2);
2991 
2992     OPEN  c_rep_phone(l_rep_person_id);
2993     FETCH c_rep_phone INTO p_rep_work_phone,p_rep_std_code;
2994     CLOSE c_rep_phone;
2995 
2996     pay_in_utils.set_location(g_debug,'p_rep_work_phone           : '|| p_rep_work_phone      ,2);
2997     pay_in_utils.set_location(g_debug,'p_rep_std_code             : '|| p_rep_std_code           ,2);
2998 
2999     pay_in_utils.set_location(g_debug,'Leaving: '|| g_package||'.get_org_details ',1);
3000   EXCEPTION
3001     WHEN OTHERS THEN
3002       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
3003       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
3004   END get_org_details;
3005   --------------------------------------------------------------------------
3006   --                                                                      --
3007   -- Name           : GENERATE_ORGANIZATION_DATA                          --
3008   -- Type           : PROCEDURE                                           --
3009   -- Access         : Private                                             --
3010   -- Description    : This procedure populates global tables used in      --
3011   --                  organization detail record                          --
3012   -- Parameters     :                                                     --
3013   --             IN : p_payroll_action_id    NUMBER                       --
3014   --            OUT : N/A                                                 --
3015   --                                                                      --
3016   -- Change History :                                                     --
3017   --------------------------------------------------------------------------
3018   -- Rev#  Date           Userid    Description                           --
3019   --------------------------------------------------------------------------
3020   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
3021   --------------------------------------------------------------------------
3022   --
3023   PROCEDURE generate_organization_data(p_payroll_action_id   IN NUMBER
3024                                       ,p_gre_id              IN NUMBER
3025                                       )
3026   IS
3027   -- The below cursor finds the Form 24Q Correction locking the Form 24Q Archival
3028   -- for a particulatr GRE as passed in the p_payroll_action_id
3029     CURSOR c_locking_24qc_pa_data
3030     IS
3031        SELECT DISTINCT pai.action_context_id locking_id
3032              ,pai.action_information1        gre_id
3033          FROM pay_action_information pai
3034         WHERE pai.action_context_type = 'PA'
3035           AND pai.action_information_category = 'IN_24QC_ORG'
3036           AND pai.action_information1  = p_gre_id
3037           AND pai.action_information3 = g_year||g_quarter
3038           AND pai.source_id = p_payroll_action_id
3039           AND pai.action_context_id IN
3040                            (
3041                              SELECT org_information3
3042                                FROM hr_organization_information
3043                               WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
3044                                 AND organization_id  = g_gre_id
3045                                 AND org_information1 = g_year
3046                                 AND org_information2 = g_quarter
3047                                 AND org_information5 = 'A'
3048                                 AND org_information6 = 'C'
3049                           )
3050         ORDER BY pai.action_context_id DESC;
3051 
3052   -- This cursor fetches the GREs that were reported in Form 24Q Archival
3053     CURSOR c_chk_organization
3054     IS
3055        SELECT action_information1 gre_id
3056          FROM pay_action_information
3057         WHERE action_information_category = 'IN_24Q_ORG'
3058           AND action_context_type = 'PA'
3059           AND action_information1 = p_gre_id
3060           AND action_information3 = g_year||g_quarter
3061           AND action_context_id   = p_payroll_action_id;
3062 
3063   -- After fetching the above values, need to take a diff of their archived data
3064   -- and live data. Also, diff of live and 24Q Correction data.
3065   -- For doing so first find the live data values.
3066 
3067    CURSOR c_diff_with_24q_data(p_gre_id             NUMBER
3068                                ,p_tan_number         VARCHAR2
3069                                ,p_deductor_type      VARCHAR2
3070                                ,p_branch_or_division VARCHAR2
3071                                ,p_org_location       NUMBER
3072                                ,p_pan_number         VARCHAR2
3073                                ,p_legal_name         VARCHAR2
3074                                ,p_rep_name           VARCHAR2
3075                                ,p_rep_position       VARCHAR2
3076                                ,p_rep_location       NUMBER
3077                                ,p_rep_email_id       VARCHAR2
3078                                ,p_rep_work_phone     VARCHAR2
3079                                ,p_rep_std_code       VARCHAR2
3080                                ,p_act_inf_category   VARCHAR2
3081                                ,p_action_context_id  NUMBER
3082                                )
3083     IS
3084        SELECT pai.action_context_id     last_action_context_id
3085          FROM pay_action_information pai
3086         WHERE pai.action_information_category = p_act_inf_category
3087           AND pai.action_context_type   = 'PA'
3088           AND pai.action_context_id     = p_action_context_id
3089           AND pai.action_information1   = p_gre_id
3090           AND pai.action_information2   = p_tan_number
3091           AND pai.action_information3   = g_year||g_quarter
3092           AND(
3093                (pai.action_information4  <> p_pan_number)
3094               OR
3095                (pai.action_information5  <> p_legal_name)
3096               OR
3097                (pai.action_information6  <> p_org_location)
3098               OR
3099                (pai.action_information7  <> p_deductor_type)
3100               OR
3101                (pai.action_information8  <> p_branch_or_division)
3102               OR
3103                (pai.action_information9  <> p_rep_name)
3104               OR
3105                (pai.action_information10 <> p_rep_email_id)
3106               OR
3107                (pai.action_information11 <> p_rep_position)
3108               OR
3109                (pai.action_information12 <> p_rep_location)
3110               OR
3111                (pai.action_information13 <> p_rep_work_phone)
3112               OR
3113                (SUBSTR(pai.action_information13
3114                       ,INSTR(pai.action_information13,'-',1,1) + 1
3115                       ,INSTR(pai.action_information13,'-',1,2) - INSTR(pai.action_information13,'-',1,1) -1
3116                       )                  <> p_rep_std_code
3117                )
3118               OR
3119                (DECODE(p_act_inf_category,'IN_24Q_ORG',p_rep_std_code,pai.action_information14) <> p_rep_std_code)
3120               );
3121 
3122 CURSOR c_diff_with_24q_data_new(p_gre_id             NUMBER
3123                                ,p_tan_number         VARCHAR2
3124                                ,p_deductor_type      VARCHAR2
3125                                ,p_branch_or_division VARCHAR2
3126                                ,p_org_location       NUMBER
3127                                ,p_pan_number         VARCHAR2
3128                                ,p_legal_name         VARCHAR2
3129                                ,p_rep_name           VARCHAR2
3130                                ,p_rep_position       VARCHAR2
3131                                ,p_rep_location       NUMBER
3132                                ,p_rep_email_id       VARCHAR2
3133                                ,p_rep_work_phone     VARCHAR2
3134                                ,p_rep_std_code       VARCHAR2
3135                                ,p_act_inf_category   VARCHAR2
3136                                ,p_action_context_id  NUMBER
3137 			       ,p_state              VARCHAR2
3138                                ,p_pao_code           VARCHAR2
3139                                ,p_ddo_code           VARCHAR2
3140                                ,p_ministry_name      VARCHAR2
3141                                ,p_other_ministry_name VARCHAR2
3142                                ,p_pao_reg_code        NUMBER
3143                                ,p_ddo_reg_code        VARCHAR2
3144                                )
3145     IS
3146        SELECT pai.action_context_id     last_action_context_id
3147          FROM pay_action_information pai
3148         WHERE pai.action_information_category = p_act_inf_category
3149           AND pai.action_context_type   = 'PA'
3150           AND pai.action_context_id     = p_action_context_id
3151           AND pai.action_information1   = p_gre_id
3152           AND pai.action_information2   = p_tan_number
3153           AND pai.action_information3   = g_year||g_quarter
3154           AND(
3155                (pai.action_information4  <> p_pan_number)
3156               OR
3157                (pai.action_information5  <> p_legal_name)
3158               OR
3159                (pai.action_information6  <> p_org_location)
3160               OR
3161                (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information21,pai.action_information7) <> p_deductor_type)
3162               OR
3163                (pai.action_information8  <> p_branch_or_division)
3164               OR
3165                (pai.action_information9  <> p_rep_name)
3166               OR
3167                (pai.action_information10 <> p_rep_email_id)
3168               OR
3169                (pai.action_information11 <> p_rep_position)
3170               OR
3171                (pai.action_information12 <> p_rep_location)
3172               OR
3173                (pai.action_information13 <> p_rep_work_phone)
3174 	      OR
3175               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information14,pai.action_information20) <> p_state)
3176               OR
3177               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information15,pai.action_information21) <> p_pao_code)
3178               OR
3179               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information16,pai.action_information22) <> p_ddo_code)
3180               OR
3181               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information17,pai.action_information23) <> p_ministry_name)
3182               OR
3183               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information18,pai.action_information24) <> p_other_ministry_name)
3184               OR
3185               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information19,pai.action_information27) <> p_pao_reg_code)
3186               OR
3187               (DECODE(p_act_inf_category,'IN_24Q_ORG',pai.action_information20,pai.action_information28) <> p_ddo_reg_code)
3188               OR
3189                (SUBSTR(pai.action_information13
3190                       ,INSTR(pai.action_information13,'-',1,1) + 1
3191                       ,INSTR(pai.action_information13,'-',1,2) - INSTR(pai.action_information13,'-',1,1) -1
3192                       )                  <> p_rep_std_code
3193                )
3194               OR
3195                (DECODE(p_act_inf_category,'IN_24Q_ORG',p_rep_std_code,pai.action_information14) <> p_rep_std_code)
3196               );
3197 --
3198        l_last_action_context_id   NUMBER;
3199        l_dummy                    NUMBER;
3200        l_flag                     BOOLEAN;
3201        l_tan_number               hr_organization_information.org_information1%TYPE;
3202        l_deductor_type            hr_organization_information.org_information3%TYPE;
3203        l_branch_or_division       hr_organization_information.org_information7%TYPE;
3204        l_org_location             hr_organization_units.location_id%TYPE;
3205        l_pan_number               hr_organization_information.org_information3%TYPE;
3206        l_legal_name               hr_organization_information.org_information4%TYPE;
3207        l_state                    hr_organization_information.org_information9%TYPE;
3208        l_pao_code                 hr_organization_information.org_information10%TYPE;
3209        l_ddo_code                 hr_organization_information.org_information11%TYPE;
3210        l_ministry_name            hr_organization_information.org_information12%TYPE;
3211        l_other_ministry_name      hr_organization_information.org_information13%TYPE;
3212        l_pao_reg_code             hr_organization_information.org_information14%TYPE;
3213        l_ddo_reg_code             hr_organization_information.org_information15%TYPE;
3214        l_rep_name                 per_all_people_f.full_name%TYPE;
3215        l_rep_position             per_all_positions.name%TYPE;
3216        l_rep_location             hr_organization_units.location_id%TYPE;
3217        l_rep_email_id             per_all_people_f.email_address%TYPE;
3218        l_rep_work_phone           per_phones.phone_number%TYPE;
3219        l_rep_std_code             per_phones.phone_number%TYPE;
3220        l_procedure                VARCHAR2(250);
3221        l_message                  VARCHAR2(250);
3222   BEGIN
3223      g_debug     := hr_utility.debug_enabled;
3224      l_procedure := g_package ||'.generate_organization_data';
3225      pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
3226 
3227      FOR c_rec IN c_chk_organization
3228      LOOP
3229         pay_in_utils.set_location(g_debug,'Organization ID in Form 24Q Archival is '||c_rec.gre_id,2);
3230         pay_in_utils.set_location(g_debug,'Fetching Live GRE Details',2);
3231         get_org_details(c_rec.gre_id,
3232                         l_tan_number,
3233                         l_deductor_type,
3234                         l_branch_or_division,
3235                         l_org_location,
3236                         l_pan_number,
3237                         l_legal_name,
3238                         l_rep_name,
3239                         l_rep_position,
3240                         l_rep_location,
3241                         l_rep_email_id,
3242                         l_rep_work_phone,
3243                         l_rep_std_code,
3244 			l_state,
3245                         l_pao_code,
3246                         l_ddo_code,
3247                         l_ministry_name,
3248                         l_other_ministry_name,
3249                         l_pao_reg_code,
3250                         l_ddo_reg_code
3251                        );
3252 
3253         pay_in_utils.set_location(g_debug,'Fetched Live GRE Details ',3);
3254         pay_in_utils.set_location(g_debug,'Checking Diff with 24Q Archived Data',4);
3255 
3256 	IF g_old_format = 'Y' THEN
3257                 OPEN  c_diff_with_24q_data(c_rec.gre_id,
3258                                    l_tan_number,
3259                                    l_deductor_type,
3260                                    l_branch_or_division,
3261                                    l_org_location,
3262                                    l_pan_number,
3263                                    l_legal_name,
3264                                    l_rep_name,
3265                                    l_rep_position,
3266                                    l_rep_location,
3267                                    l_rep_email_id,
3268                                    l_rep_work_phone,
3269                                    l_rep_std_code,
3270                                    'IN_24Q_ORG',
3271                                    p_payroll_action_id
3272                                   );
3273                FETCH c_diff_with_24q_data INTO l_last_action_context_id;
3274                CLOSE c_diff_with_24q_data;
3275         ELSE
3276               OPEN  c_diff_with_24q_data_new(c_rec.gre_id,
3277                                    l_tan_number,
3278                                    l_deductor_type,
3279                                    l_branch_or_division,
3280                                    l_org_location,
3281                                    l_pan_number,
3282                                    l_legal_name,
3283                                    l_rep_name,
3284                                    l_rep_position,
3285                                    l_rep_location,
3286                                    l_rep_email_id,
3287                                    l_rep_work_phone,
3288                                    l_rep_std_code,
3289                                    'IN_24Q_ORG',
3290                                    p_payroll_action_id,
3291 				   l_state,
3292                                    l_pao_code,
3293                                    l_ddo_code,
3294                                    l_ministry_name,
3295                                    l_other_ministry_name,
3296                                    l_pao_reg_code,
3297                                    l_ddo_reg_code
3298                                   );
3299             FETCH c_diff_with_24q_data_new INTO l_last_action_context_id;
3300             CLOSE c_diff_with_24q_data_new;
3301 	END IF;
3302 
3303         pay_in_utils.set_location(g_debug,'Last Action Context ID in 24Q is :'|| l_last_action_context_id,5);
3304         IF (l_last_action_context_id IS NOT NULL)
3305         THEN
3306         -- This means that there is a diff from archived and present data.
3307         -- So need to check whether this diff was reported in any of the
3308         -- Form 24Q Corrections or not. For this find the Form 24Q Corrections
3309         -- on top of Form 24Q Archival and check if any of them has data as per
3310         -- present live data. If they too dont have any record, then need to
3311         -- insert this org data in a PL/SQL table.
3312            pay_in_utils.set_location(g_debug,'Diff with live and and 24Q Data found..',2);
3313               l_flag := TRUE;
3314 
3315               FOR csr_rec IN c_locking_24qc_pa_data
3316               LOOP
3317                      pay_in_utils.set_location(g_debug,'Checking Diff in 24Q Correction Data',6);
3318 
3319 	       IF g_old_format = 'Y' THEN
3320                      OPEN  c_diff_with_24q_data(c_rec.gre_id,
3321                                                 l_tan_number,
3322                                                 l_deductor_type,
3323                                                 l_branch_or_division,
3324                                                 l_org_location,
3325                                                 l_pan_number,
3326                                                 l_legal_name,
3327                                                 l_rep_name,
3328                                                 l_rep_position,
3329                                                 l_rep_location,
3330                                                 l_rep_email_id,
3331                                                 l_rep_work_phone,
3332                                                 l_rep_std_code,
3333                                                 'IN_24QC_ORG',
3334                                                 csr_rec.locking_id
3335                                                 );
3336                       FETCH c_diff_with_24q_data INTO l_dummy;
3337                       CLOSE c_diff_with_24q_data;
3338                 ELSE
3339                      OPEN  c_diff_with_24q_data_new(c_rec.gre_id,
3340                                                 l_tan_number,
3341                                                 l_deductor_type,
3342                                                 l_branch_or_division,
3343                                                 l_org_location,
3344                                                 l_pan_number,
3345                                                 l_legal_name,
3346                                                 l_rep_name,
3347                                                 l_rep_position,
3348                                                 l_rep_location,
3349                                                 l_rep_email_id,
3350                                                 l_rep_work_phone,
3351                                                 l_rep_std_code,
3352                                                 'IN_24QC_ORG',
3353                                                 csr_rec.locking_id,
3354 						l_state,
3355                                                 l_pao_code,
3356                                                 l_ddo_code,
3357                                                 l_ministry_name,
3358                                                 l_other_ministry_name,
3359                                                 l_pao_reg_code,
3360                                                 l_ddo_reg_code
3361                                                 );
3362                      FETCH c_diff_with_24q_data_new INTO l_dummy;
3363                      CLOSE c_diff_with_24q_data_new;
3364                   END IF;
3365                      IF ((l_dummy IS NULL)AND (l_flag))
3366                      THEN
3367                             pay_in_utils.set_location(g_debug,'Diff in 24Q Correction Data Found',6);
3368                            l_flag := FALSE;
3369                      END IF;
3370               END LOOP;
3371 
3372               IF (l_flag)
3373               THEN
3374                     g_org_data(g_count_org).gre_id                  := c_rec.gre_id;
3375                     g_org_data(g_count_org).last_action_context_id  := p_payroll_action_id;
3376                     g_count_org := g_count_org + 1;
3377               END IF;
3378         END IF;
3379      END LOOP;
3380 
3381      --The above logic found all those values of GRE that had a change from
3382      --24Q Archival to present state without getting reported in 24QC.
3383      --The following code finds those GREs that have undergone a change from
3384      --the last correction statement.
3385      FOR c_record IN c_locking_24qc_pa_data
3386      LOOP
3387         get_org_details(c_record.gre_id,
3388                         l_tan_number,
3389                         l_deductor_type,
3390                         l_branch_or_division,
3391                         l_org_location,
3392                         l_pan_number,
3393                         l_legal_name,
3394                         l_rep_name,
3395                         l_rep_position,
3396                         l_rep_location,
3397                         l_rep_email_id,
3398                         l_rep_work_phone,
3399                         l_rep_std_code,
3400 			l_state,
3401                         l_pao_code,
3402                         l_ddo_code,
3403                         l_ministry_name,
3404                         l_other_ministry_name,
3405                         l_pao_reg_code,
3406                         l_ddo_reg_code
3407                        );
3408      IF g_old_format = 'Y' THEN
3409          OPEN  c_diff_with_24q_data(c_record.gre_id,
3410                                   l_tan_number,
3411                                   l_deductor_type,
3412                                   l_branch_or_division,
3413                                   l_org_location,
3414                                   l_pan_number,
3415                                   l_legal_name,
3416                                   l_rep_name,
3417                                   l_rep_position,
3418                                   l_rep_location,
3419                                   l_rep_email_id,
3420                                   l_rep_work_phone,
3421                                   l_rep_std_code,
3422                                   'IN_24QC_ORG',
3423                                   c_record.locking_id
3424                                   );
3425           FETCH c_diff_with_24q_data INTO l_dummy;
3426           CLOSE c_diff_with_24q_data;
3427        ELSE
3428           OPEN  c_diff_with_24q_data_new(c_record.gre_id,
3429                                   l_tan_number,
3430                                   l_deductor_type,
3431                                   l_branch_or_division,
3432                                   l_org_location,
3433                                   l_pan_number,
3434                                   l_legal_name,
3435                                   l_rep_name,
3436                                   l_rep_position,
3437                                   l_rep_location,
3438                                   l_rep_email_id,
3439                                   l_rep_work_phone,
3440                                   l_rep_std_code,
3441                                   'IN_24QC_ORG',
3442                                   c_record.locking_id,
3443 				  l_state,
3444                                   l_pao_code,
3445                                   l_ddo_code,
3446                                   l_ministry_name,
3447                                   l_other_ministry_name,
3448                                   l_pao_reg_code,
3449                                   l_ddo_reg_code
3450                                   );
3451            FETCH c_diff_with_24q_data_new INTO l_dummy;
3452            CLOSE c_diff_with_24q_data_new;
3453        END IF;
3454         l_flag := TRUE;
3455 
3456         IF (l_dummy IS NOT NULL)
3457         THEN
3458         -- Then this means that there is a difference from this corrections
3459         -- statement to the present live data, hence need to store this GRE
3460         -- and last action context id, but need to check that this correction
3461         -- might have been superceded by another correction. So check in global
3462         -- PL/SQL table, if this GRE ID exists then dont insert a new record.
3463                 FOR i IN 1..g_count_org - 1
3464                 LOOP
3465                    IF ((g_org_data(i).gre_id = c_record.gre_id)AND(l_flag)AND(g_org_data(i).last_action_context_id < l_dummy))
3466                    THEN
3467                         l_flag := FALSE;
3468                         g_org_data(i).last_action_context_id := l_dummy;
3469                    END IF;
3470                 END LOOP;
3471 
3472                 IF (l_flag)
3473                 THEN
3474                     g_org_data(g_count_org).gre_id                  := c_record.gre_id;
3475                     g_org_data(g_count_org).last_action_context_id  := l_dummy;
3476                     g_count_org := g_count_org + 1;
3477                 END IF;
3478         END IF;
3479      END LOOP;
3480      pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.generate_organization_data ',5);
3481   EXCEPTION
3482     WHEN OTHERS THEN
3483       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
3484       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
3485   END generate_organization_data;
3486 
3487   --------------------------------------------------------------------------
3488   --                                                                      --
3489   -- Name           : GENERATE_CHALLAN_DATA                               --
3490   -- Type           : PROCEDURE                                           --
3491   -- Access         : Private                                             --
3492   -- Description    : This procedure populates PL/SQL table for challans  --
3493   -- Parameters     :                                                     --
3494   --             IN : p_payroll_action_id    NUMBER                       --
3495   --            OUT : N/A                                                 --
3496   --                                                                      --
3497   -- Change History :                                                     --
3498   --------------------------------------------------------------------------
3499   -- Rev#  Date           Userid    Description                           --
3500   --------------------------------------------------------------------------
3501   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
3502   --------------------------------------------------------------------------
3503   PROCEDURE generate_challan_data(p_payroll_action_id     IN NUMBER
3504                                  ,p_gre_id                IN NUMBER
3505                                  )
3506   IS
3507     CURSOR c_challan_live_data_master(p_tax_year       VARCHAR2
3508                                      ,p_challan_number VARCHAR2
3509                                      ,p_org_info_id    NUMBER
3510                                      )
3511     IS
3512       SELECT hoi.org_information3           challan_number,
3513              hoi.org_information2           transfer_voucher_date,
3514              hoi.org_information4           amount,
3515              hoi.org_information7           surcharge,
3516              hoi.org_information8           education_cess,
3517              hoi.org_information10          other,
3518              hoi.org_information9           interest,
3519              (SELECT hoi_bank.org_information4
3520                FROM hr_organization_information hoi_bank
3521               WHERE hoi_bank.organization_id = p_gre_id
3522                 AND hoi_bank.org_information_context = 'PER_IN_CHALLAN_BANK'
3523                 AND hoi_bank.org_information_id = hoi.org_information5
3524              )                              bank_branch_code,
3525              hoi.org_information11          cheque_dd_num,
3526              hoi.org_information_id         org_information_id
3527         FROM hr_organization_information hoi
3528        WHERE hoi.org_information_id IN
3529        (
3530             SELECT hoi.org_information_id
3531               FROM hr_organization_information hoi
3532                   ,hr_organization_units hou
3533              WHERE hoi.organization_id     = p_gre_id
3534                AND  hoi.organization_id    = hou.organization_id
3535                AND  hou.business_group_id  = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
3536                AND org_information_context = 'PER_IN_IT_CHALLAN_INFO'
3537        )
3538          AND hoi.org_information13 = g_quarter
3539          AND hoi.org_information1  = p_tax_year
3540          AND(
3541 	     hoi.org_information3 LIKE p_challan_number
3542              OR
3543              hoi.org_information_id  = p_org_info_id
3544             );
3545 
3546   --The below cursor gives the value of Challan Details as in the live Data.
3547   -- This cursor can return all the values as well as specific also based on
3548   -- p_challan_number and p_org_info_id
3549     CURSOR c_challan_live_data(p_tax_year       VARCHAR2
3550                               ,p_challan_number VARCHAR2
3551                               ,p_org_info_id    NUMBER
3552                               )
3553     IS
3554       SELECT hoi.org_information3           challan_number,
3555              hoi.org_information2           transfer_voucher_date,
3556              hoi.org_information4           amount,
3557              hoi.org_information7           surcharge,
3558              hoi.org_information8           education_cess,
3559              hoi.org_information10          other,
3560              hoi.org_information9           interest,
3561              (SELECT hoi_bank.org_information4
3562                FROM hr_organization_information hoi_bank
3563               WHERE hoi_bank.organization_id = p_gre_id
3564                 AND hoi_bank.org_information_context = 'PER_IN_CHALLAN_BANK'
3565                 AND hoi_bank.org_information_id = hoi.org_information5
3566              )                              bank_branch_code,
3567              hoi.org_information11          cheque_dd_num,
3568              hoi.org_information_id         org_information_id
3569         FROM hr_organization_information hoi
3570        WHERE hoi.org_information_id IN
3571        (
3572             SELECT hoi.org_information_id
3573               FROM hr_organization_information hoi
3574                   ,hr_organization_units hou
3575              WHERE hoi.organization_id     = p_gre_id
3576                AND  hoi.organization_id    = hou.organization_id
3577                AND  hou.business_group_id  = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
3578                AND org_information_context = 'PER_IN_IT_CHALLAN_INFO'
3579        )
3580          AND hoi.org_information13 = g_quarter
3581          AND hoi.org_information1  = p_tax_year
3582          AND(
3583              hoi.org_information3 LIKE SUBSTR(p_challan_number ,INSTR (p_challan_number, ' -',1,1)+3,(INSTR (p_challan_number, ' -',1,2)-(INSTR (p_challan_number, ' -',1,1)+3)))
3584              OR
3585              hoi.org_information_id  = p_org_info_id
3586             );
3587 
3588     CURSOR c_challan_24q_data_master(p_act_info_category     VARCHAR2
3589                                     ,p_voucher_number        VARCHAR2
3590                                     ,p_org_information_id    NUMBER
3591                                      )
3592     IS
3593       SELECT action_information_id,
3594              action_information1     transfer_voucher_number,
3595              action_information4     bank_branch_code,
3596              action_information5     transfer_voucher_date,
3597              action_information6     amount,
3598              action_information7     surcharge,
3599              action_information8     cess,
3600              action_information9     interest,
3601              action_information10    other,
3602              action_information11    cheque_dd_num,
3603              source_id               org_information_id
3604         FROM pay_action_information
3605        WHERE action_information2         = g_year||g_quarter
3606          AND action_information3         = p_gre_id
3607          AND action_information_category = p_act_info_category
3608          AND action_context_id IN
3609                                (
3610                                  SELECT org_information3
3611                                    FROM hr_organization_information
3612                                   WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
3613                                     AND organization_id  = g_gre_id
3614                                     AND org_information1 = g_year
3615                                     AND org_information2 = g_quarter
3616                                     AND org_information5 = 'A'
3617                               )
3618          AND DECODE(p_act_info_category
3619                    ,'IN_24Q_CHALLAN'
3620                    ,action_context_id
3621                    ,p_payroll_action_id
3622                    )                    = p_payroll_action_id
3623          AND (
3624               action_information1 LIKE p_voucher_number
3625              OR
3626               source_id         =  p_org_information_id
3627              )
3628          AND DECODE(p_act_info_category
3629                    ,'IN_24QC_CHALLAN'
3630                    ,action_information15
3631                    ,p_payroll_action_id
3632                    ) = p_payroll_action_id
3633       ORDER BY action_information_id DESC;
3634 
3635     -- The below cursor fetches data both from Form 24Q Archival
3636     -- and Form 24Q Corrections. This cursor can retrun data specific to
3637     -- challan number or org_information_id
3638     CURSOR c_challan_24q_data(p_act_info_category     VARCHAR2
3639                              ,p_voucher_number        VARCHAR2
3640                              ,p_org_information_id    NUMBER
3641                              )
3642     IS
3643       SELECT action_information_id,
3644              action_information1     transfer_voucher_number,
3645              action_information4     bank_branch_code,
3646              action_information5     transfer_voucher_date,
3647              action_information6     amount,
3648              action_information7     surcharge,
3649              action_information8     cess,
3650              action_information9     interest,
3651              action_information10    other,
3652              action_information11    cheque_dd_num,
3653              source_id               org_information_id
3654         FROM pay_action_information
3655        WHERE action_information2         = g_year||g_quarter
3656          AND action_information3         = p_gre_id
3657          AND action_information_category = p_act_info_category
3658          AND action_context_id IN
3659                                (
3660                                  SELECT org_information3
3661                                    FROM hr_organization_information
3662                                   WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
3663                                     AND organization_id  = g_gre_id
3664                                     AND org_information1 = g_year
3665                                     AND org_information2 = g_quarter
3666                                     AND org_information5 = 'A'
3667                               )
3668          AND DECODE(p_act_info_category
3669                    ,'IN_24Q_CHALLAN'
3670                    ,action_context_id
3671                    ,p_payroll_action_id
3672                    )                    = p_payroll_action_id
3673          AND (
3674               action_information1 LIKE p_voucher_number
3675              OR
3676               source_id         =  p_org_information_id
3677              )
3678          AND DECODE(p_act_info_category
3679                    ,'IN_24QC_CHALLAN'
3680                    ,action_information15
3681                    ,p_payroll_action_id
3682                    ) = p_payroll_action_id
3683       ORDER BY action_information_id DESC;
3684 
3685     l_transfer_voucher_number     hr_organization_information.org_information3%TYPE;
3686     l_transfer_voucher_date       hr_organization_information.org_information2%TYPE;
3687     l_amount                      hr_organization_information.org_information4%TYPE;
3688     l_surcharge                   hr_organization_information.org_information7%TYPE;
3689     l_education_cess              hr_organization_information.org_information8%TYPE;
3690     l_interest                    hr_organization_information.org_information9%TYPE;
3691     l_others                      hr_organization_information.org_information10%TYPE;
3692     l_bank_branch_code            hr_organization_information.org_information4%TYPE;
3693     l_cheque_dd_num               hr_organization_information.org_information11%TYPE;
3694     l_org_information_id          NUMBER;
3695     l_action_information_id       NUMBER;
3696 
3697     l_transfer_voucher_number_1   hr_organization_information.org_information3%TYPE;
3698     l_transfer_voucher_date_1     hr_organization_information.org_information2%TYPE;
3699     l_amount_1                    hr_organization_information.org_information4%TYPE;
3700     l_surcharge_1                 hr_organization_information.org_information7%TYPE;
3701     l_education_cess_1            hr_organization_information.org_information8%TYPE;
3702     l_interest_1                  hr_organization_information.org_information9%TYPE;
3703     l_others_1                    hr_organization_information.org_information10%TYPE;
3704     l_bank_branch_code_1          hr_organization_information.org_information4%TYPE;
3705     l_cheque_dd_num_1             hr_organization_information.org_information11%TYPE;
3706     l_org_information_id_1        NUMBER;
3707     l_dummy_boolean               BOOLEAN;
3708     l_dummy                       hr_organization_information.org_information3%TYPE;
3709     l_procedure                   VARCHAR2(250);
3710     l_message                     VARCHAR2(250);
3711   BEGIN
3712      g_debug     := hr_utility.debug_enabled;
3713      l_procedure := g_package ||'.generate_challan_data';
3714      pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
3715     -- First Search for those challans that have been added since Form 24Q
3716     -- Last generation but were not reported in Form 24Q Correction.
3717     -- For this check existence of Live Challan Number in 24Q Archival.
3718     -- If its not there, then check its existence in Form 24Q Corrections
3719     -- done on its top. If its not even there, then this shows addition of
3720     -- challans.
3721 
3722     FOR c_rec IN c_challan_live_data_master(g_tax_year,'%',NULL)
3723     LOOP
3724        pay_in_utils.set_location(g_debug,'Fetching Live Data ', 2);
3725        -- For the fetched live data checking its presence in 24Q Archived Data
3726        l_dummy_boolean  := TRUE;
3727        l_dummy          := NULL;
3728 
3729 
3730        FOR csr_record IN c_challan_24q_data('IN_24Q_CHALLAN',NVL(c_rec.bank_branch_code,'BOOK')||' - '||c_rec.challan_number||' - '||to_char(fnd_date.canonical_to_date(c_rec.transfer_voucher_date),'DD-Mon-RRRR') ,NULL)
3731        LOOP
3732 
3733                 IF (l_dummy_boolean)
3734                 THEN
3735                    pay_in_utils.set_location(g_debug,'Checking 24Q Archived Data',3);
3736                    l_dummy := csr_record.transfer_voucher_number;
3737                    l_dummy_boolean  := FALSE;
3738                 END IF;
3739        END LOOP;
3740 
3741 
3742        IF (l_dummy IS NULL)
3743        THEN
3744         -- This means that the present challan data was not reported in
3745         -- Form 24Q Archival. However this challan number might have been updated
3746         -- to a different challan number. So check in Form 24Q Archived Data for the
3747         -- presence of this record's org_information_id
3748            pay_in_utils.set_location(g_debug,'Again opened',1);
3749            l_dummy_boolean  := TRUE;
3750            FOR csr_record IN c_challan_24q_data('IN_24Q_CHALLAN',NULL,c_rec.org_information_id)
3751            LOOP
3752                  IF (l_dummy_boolean)
3753                 THEN
3754                         l_dummy := csr_record.transfer_voucher_number;
3755                         l_dummy_boolean  := FALSE;
3756                 END IF;
3757               pay_in_utils.set_location(g_debug,'Again opened',2);
3758            END LOOP;
3759 
3760            IF (l_dummy IS NULL)
3761            THEN
3762                 -- This means that in 24Q Archival this record was never present. So,
3763                 -- need to check in Form 24Q Correction, firstly on the basis of
3764                 -- Challan Number and then on basis of org_information_id
3765                 pay_in_utils.set_location(g_debug,'Again opened',3);
3766                 l_dummy_boolean  := TRUE;
3767                 FOR csr_record IN c_challan_24q_data('IN_24QC_CHALLAN',NVL(c_rec.bank_branch_code,'BOOK')||' - '||c_rec.challan_number||' - '||to_char(fnd_date.canonical_to_date(c_rec.transfer_voucher_date),'DD-Mon-RRRR') ,NULL)
3768                 LOOP
3769                 IF (l_dummy_boolean)
3770                 THEN
3771                         l_dummy := csr_record.transfer_voucher_number;
3772                         pay_in_utils.set_location(g_debug,'Again opened',4);
3773                         l_dummy_boolean  := FALSE;
3774                 END IF;
3775                 END LOOP;
3776 
3777                   pay_in_utils.set_location(g_debug,'Again opened',5);
3778                   IF (l_dummy IS NULL)
3779                   THEN
3780                         -- This means that in Form 24QC no record with c_rec.challan_number
3781                         -- was reported. However this may happen that challan number was
3782                         -- updated and hence got reported in Form 24Q Correction. So,
3783                         -- checking in correction data again using org_information_id.
3784                          pay_in_utils.set_location(g_debug,'Again opened',6);
3785                          l_dummy_boolean  := TRUE;
3786                         FOR csr_record IN c_challan_24q_data('IN_24QC_CHALLAN',NULL,c_rec.org_information_id)
3787                         LOOP
3788                              IF (l_dummy_boolean)
3789                              THEN
3790                                   l_dummy := csr_record.transfer_voucher_number;
3791                                   pay_in_utils.set_location(g_debug,'Again opened',7);
3792                                   l_dummy_boolean  := FALSE;
3793                              END IF;
3794                         END LOOP;
3795 
3796                         pay_in_utils.set_location(g_debug,'Again opened',8);
3797                         IF (l_dummy IS NULL)
3798                         THEN
3799                            --This means that in Form 24Q Correction, this record was never
3800                            -- present. So need to insert this record data in PL/SQL table.
3801                            g_challan_data_add(g_count_challan_add).transfer_voucher_number := NVL(c_rec.bank_branch_code,'BOOK')||' - '||c_rec.challan_number||' - '||to_char(fnd_date.canonical_to_date(c_rec.transfer_voucher_date),'DD-Mon-RRRR') ;
3802                            g_challan_data_add(g_count_challan_add).transfer_voucher_date   := c_rec.transfer_voucher_date;
3803                            g_challan_data_add(g_count_challan_add).amount                  := c_rec.amount;
3804                            g_challan_data_add(g_count_challan_add).surcharge               := c_rec.surcharge;
3805                            g_challan_data_add(g_count_challan_add).education_cess          := c_rec.education_cess;
3806                            g_challan_data_add(g_count_challan_add).interest                := c_rec.interest;
3807                            g_challan_data_add(g_count_challan_add).other                   := c_rec.other;
3808                            g_challan_data_add(g_count_challan_add).bank_branch_code        := c_rec.bank_branch_code;
3809                            g_challan_data_add(g_count_challan_add).cheque_dd_num           := c_rec.cheque_dd_num;
3810                            g_challan_data_add(g_count_challan_add).org_information_id      := c_rec.org_information_id;
3811                            g_challan_data_add(g_count_challan_add).modes                   := 'A';
3812                            g_count_challan_add := g_count_challan_add + 1;
3813                            pay_in_utils.set_location(g_debug,'Again opened',9);
3814                         END IF;
3815                   END IF;
3816            END IF;
3817        END IF;
3818     END LOOP;
3819 
3820        pay_in_utils.set_location(g_debug,'Starting Search for Updated Challans',1);
3821     -- Lastly search for those challans that have been updated since Form 24Q
3822     -- last generation but were not reported in Form 24Q Correction.
3823     FOR c_rec IN c_challan_24q_data_master('IN_24Q_CHALLAN','%',NULL)
3824     LOOP
3825        pay_in_utils.set_location(g_debug,'Fetching 24Q Data ' ,1);
3826        -- Now, on the basis of org_information_id check if there is any change
3827        -- in challan details in the live data.
3828 
3829        OPEN  c_challan_live_data(g_tax_year,NULL,c_rec.org_information_id);
3830        FETCH c_challan_live_data INTO l_transfer_voucher_number,
3831                                       l_transfer_voucher_date,
3832                                       l_amount,
3833                                       l_surcharge,
3834                                       l_education_cess,
3835                                       l_others,
3836                                       l_interest,
3837                                       l_bank_branch_code,
3838                                       l_cheque_dd_num,
3839                                       l_org_information_id;
3840        CLOSE c_challan_live_data;
3841        pay_in_utils.set_location(g_debug,'Fetching Live Data ' ,2);
3842 
3843 
3844        IF (--24Q Archival Data Here                 Live Data Here
3845            (c_rec.transfer_voucher_number <> NVL(l_bank_branch_code,'BOOK')||' - '||l_transfer_voucher_number||' - '||to_char(fnd_date.canonical_to_date(l_transfer_voucher_date),'DD-Mon-RRRR') ) OR
3846            (c_rec.bank_branch_code        <> l_bank_branch_code)        OR
3847            (c_rec.transfer_voucher_date   <> l_transfer_voucher_date)   OR
3848            (c_rec.amount                  <> l_amount)                  OR
3849            (c_rec.surcharge               <> l_surcharge)               OR
3850            (c_rec.cess                    <> l_education_cess)          OR
3851            (c_rec.interest                <> l_interest)                OR
3852            (c_rec.other                   <> l_others)                  OR
3853            (c_rec.cheque_dd_num           <> l_cheque_dd_num)
3854          )
3855       THEN
3856       -- This means that there are certain records that have same org_information_id
3857       -- as in Live Data and in Form 24Q but have undergone a change in their data
3858       -- Now, need to check whether these changes were reported in Form 24Q Correction
3859       -- or not.
3860                 pay_in_utils.set_location(g_debug,'Inside Check 1' ,1);
3861                 l_action_information_id  := NULL;
3862                 OPEN  c_challan_24q_data('IN_24QC_CHALLAN',NULL,c_rec.org_information_id);
3863                 FETCH c_challan_24q_data INTO l_action_information_id,
3864                                               l_transfer_voucher_number_1,
3865                                               l_bank_branch_code_1,
3866                                               l_transfer_voucher_date_1,
3867                                               l_amount_1,
3868                                               l_surcharge_1,
3869                                               l_education_cess_1,
3870                                               l_interest_1,
3871                                               l_others_1,
3872                                               l_cheque_dd_num_1,
3873                                               l_org_information_id_1;
3874                 CLOSE c_challan_24q_data;
3875                 -- What may happen is that the values were reported in Form 24Q Correction
3876                 -- but they might have still undergone another change. So need to check
3877                 -- whether any change was reported in Form 24Q Correction or not.
3878                 -- If yes(24QC), then are the values diff. If yes then store in PL/SQL on basis of 24QC, else reject
3879                 -- If not, then store in PL/SQL on the basis of 24Q Archival
3880                 IF (l_action_information_id IS NOT NULL)
3881                 THEN
3882                     IF (-- Live Data here             --24Q Correction Data here
3883                         (NVL(l_bank_branch_code,'BOOK')||' - '||l_transfer_voucher_number||' - '||to_char(fnd_date.canonical_to_date(l_transfer_voucher_date),'DD-Mon-RRRR')  <> l_transfer_voucher_number_1) OR
3884                         (l_bank_branch_code        <> l_bank_branch_code_1)        OR
3885                         (l_transfer_voucher_date   <> l_transfer_voucher_date_1)   OR
3886                         (l_amount                  <> l_amount_1)                  OR
3887                         (l_surcharge               <> l_surcharge_1)               OR
3888                         (l_education_cess          <> l_education_cess_1)          OR
3889                         (l_interest                <> l_interest_1)                OR
3890                         (l_others                  <> l_others_1)                  OR
3891                         (l_cheque_dd_num           <> l_cheque_dd_num_1)           OR
3892                         (l_org_information_id      <> l_org_information_id_1)
3893                       )
3894                    THEN
3895                            pay_in_utils.set_location(g_debug,'Inside Check 2' ,2);
3896                           --This means that in Form 24Q Correction, this record was present and now it has
3897                           -- been further modified. So need to insert this record data in PL/SQL table.
3898                           g_challan_data_upd(g_count_challan_upd).transfer_voucher_number := l_transfer_voucher_number_1;
3899                           g_challan_data_upd(g_count_challan_upd).transfer_voucher_date   := l_transfer_voucher_date_1;
3900                           g_challan_data_upd(g_count_challan_upd).amount                  := l_amount_1;
3901                           g_challan_data_upd(g_count_challan_upd).surcharge               := l_surcharge_1;
3902                           g_challan_data_upd(g_count_challan_upd).education_cess          := l_education_cess_1;
3903                           g_challan_data_upd(g_count_challan_upd).interest                := l_interest_1;
3904                           g_challan_data_upd(g_count_challan_upd).other                   := l_others_1;
3905                           g_challan_data_upd(g_count_challan_upd).bank_branch_code        := l_bank_branch_code_1;
3906                           g_challan_data_upd(g_count_challan_upd).cheque_dd_num           := l_cheque_dd_num_1;
3907                           g_challan_data_upd(g_count_challan_upd).org_information_id      := l_org_information_id_1;
3908                           g_challan_data_upd(g_count_challan_upd).modes                   := 'U';
3909                           g_count_challan_upd := g_count_challan_upd + 1;
3910                    END IF;
3911               ELSE
3912                           pay_in_utils.set_location(g_debug,'Inside Check 3' ,3);
3913                           --This means that in Form 24Q Correction, this record was  never present.
3914                           --So need to insert this record data in PL/SQL table on basis of form 24q archival
3915                           g_challan_data_upd(g_count_challan_upd).transfer_voucher_number := c_rec.transfer_voucher_number;
3916                           g_challan_data_upd(g_count_challan_upd).transfer_voucher_date   := c_rec.transfer_voucher_date;
3917                           g_challan_data_upd(g_count_challan_upd).amount                  := c_rec.amount;
3918                           g_challan_data_upd(g_count_challan_upd).surcharge               := c_rec.surcharge;
3919                           g_challan_data_upd(g_count_challan_upd).education_cess          := c_rec.cess;
3920                           g_challan_data_upd(g_count_challan_upd).interest                := c_rec.interest;
3921                           g_challan_data_upd(g_count_challan_upd).other                   := c_rec.other;
3922                           g_challan_data_upd(g_count_challan_upd).bank_branch_code        := c_rec.bank_branch_code;
3923                           g_challan_data_upd(g_count_challan_upd).cheque_dd_num           := c_rec.cheque_dd_num;
3924                           g_challan_data_upd(g_count_challan_upd).org_information_id      := c_rec.org_information_id;
3925                           g_challan_data_upd(g_count_challan_upd).modes                   := 'U';
3926                           g_count_challan_upd := g_count_challan_upd + 1;
3927               END IF;
3928       ELSE
3929          pay_in_utils.set_location(g_debug,'Inside Check 4' ,4);
3930       -- This means that the archived data and Live Data is identical. But there is a possibility that
3931       -- data was updated and reported in Form 24Q Correction and later again restored back to the data
3932       -- as in Form 24Q Archival. So need to check whether for c_rec.org_information_id any record is
3933       -- present in Form 24Q Correction or not. If its present, then check its status with Live Data.
3934       -- If there is a diff then mark that record, else reject it.
3935 
3936 
3937                 OPEN  c_challan_24q_data('IN_24QC_CHALLAN',NULL,c_rec.org_information_id);
3938                 FETCH c_challan_24q_data INTO l_action_information_id,
3939                                               l_transfer_voucher_number_1,
3940                                               l_bank_branch_code_1,
3941                                               l_transfer_voucher_date_1,
3942                                               l_amount_1,
3943                                               l_surcharge_1,
3944                                               l_education_cess_1,
3945                                               l_interest_1,
3946                                               l_others_1,
3947                                               l_cheque_dd_num_1,
3948                                               l_org_information_id_1;
3949                 CLOSE c_challan_24q_data;
3950 
3951 
3952                 IF (l_action_information_id IS NOT NULL)
3953                 THEN
3954                 -- This means that there is a reporting of this data in 24Q Correction. Now, need
3955                 -- to check the diff of the two records. If diff exists then store this record
3956                 -- on the basis of 24Q Correction else reject it.
3957                       IF (--Live Data                     24Q Correction Data
3958                           (NVL(l_bank_branch_code,'BOOK')||' - '||l_transfer_voucher_number||' - '||to_char(fnd_date.canonical_to_date(l_transfer_voucher_date),'DD-Mon-RRRR')  <> l_transfer_voucher_number_1) OR
3959                           (l_bank_branch_code        <> l_bank_branch_code_1)        OR
3960                           (l_transfer_voucher_date   <> l_transfer_voucher_date_1)   OR
3961                           (l_amount                  <> l_amount_1)                  OR
3962                           (l_surcharge               <> l_surcharge_1)               OR
3963                           (l_education_cess          <> l_education_cess_1)          OR
3964                           (l_interest                <> l_interest_1)                OR
3965                           (l_others                  <> l_others_1)                  OR
3966                           (l_cheque_dd_num           <> l_cheque_dd_num_1)           OR
3967                           (l_org_information_id      <> l_org_information_id_1)
3968                         )
3969                       THEN
3970                              pay_in_utils.set_location(g_debug,'Inside Check 5' ,5);
3971                             --This means that in Form 24Q Correction, this record was never
3972                             -- updated. So need to insert this record data in PL/SQL table.
3973                             g_challan_data_upd(g_count_challan_upd).transfer_voucher_number := l_transfer_voucher_number_1;
3974                             g_challan_data_upd(g_count_challan_upd).transfer_voucher_date   := l_transfer_voucher_date_1;
3975                             g_challan_data_upd(g_count_challan_upd).amount                  := l_amount_1;
3976                             g_challan_data_upd(g_count_challan_upd).surcharge               := l_surcharge_1;
3977                             g_challan_data_upd(g_count_challan_upd).education_cess          := l_education_cess_1;
3978                             g_challan_data_upd(g_count_challan_upd).interest                := l_interest_1;
3979                             g_challan_data_upd(g_count_challan_upd).other                   := l_others_1;
3980                             g_challan_data_upd(g_count_challan_upd).bank_branch_code        := l_bank_branch_code_1;
3981                             g_challan_data_upd(g_count_challan_upd).cheque_dd_num           := l_cheque_dd_num_1;
3982                             g_challan_data_upd(g_count_challan_upd).org_information_id      := l_org_information_id_1;
3983                             g_challan_data_upd(g_count_challan_upd).modes                   := 'U';
3984                             g_count_challan_upd := g_count_challan_upd + 1;
3985                       END IF;
3986                END IF;
3987       END IF;
3988     END LOOP;
3989        pay_in_utils.set_location(g_debug,'New Search Criteria Starting........' ,1);
3990     -- The above updation case handles only those cases when record was only updated
3991     -- and never re - created with the same Challan Number.
3992     FOR c_rec IN c_challan_24q_data_master('IN_24Q_CHALLAN','%',NULL)
3993     LOOP
3994        -- Now, on the basis of challan number check if there is any change
3995        -- in challan details in the live data.
3996        OPEN  c_challan_live_data(g_tax_year,c_rec.transfer_voucher_number,NULL);
3997        FETCH c_challan_live_data INTO l_transfer_voucher_number,
3998                                       l_transfer_voucher_date,
3999                                       l_amount,
4000                                       l_surcharge,
4001                                       l_education_cess,
4002                                       l_others,
4003                                       l_interest,
4004                                       l_bank_branch_code,
4005                                       l_cheque_dd_num,
4006                                       l_org_information_id;
4007        CLOSE c_challan_live_data;
4008 
4009        IF (c_rec.org_information_id <> l_org_information_id)
4010        THEN
4011        -- This means that there is a record which was deleted and recreated
4012        -- with the same challan number. Now, if rest of the details are same
4013        -- then no need to mark this record else mark it.
4014                IF (
4015                    (c_rec.bank_branch_code        <> l_bank_branch_code)        OR
4016                    (c_rec.transfer_voucher_date   <> l_transfer_voucher_date)   OR
4017                    (c_rec.amount                  <> l_amount)                  OR
4018                    (c_rec.surcharge               <> l_surcharge)               OR
4019                    (c_rec.cess                    <> l_education_cess)          OR
4020                    (c_rec.interest                <> l_interest)                OR
4021                    (c_rec.other                   <> l_others)                  OR
4022                    (c_rec.cheque_dd_num           <> l_cheque_dd_num)
4023                  )
4024               THEN
4025               -- This means that this record has same challan number and different
4026               -- details in terms of org_information_id and other details.
4027               -- So check as to whether this diff was reported in Form 24Q Correction
4028               -- or not.
4029                       OPEN  c_challan_24q_data('IN_24QC_CHALLAN',c_rec.transfer_voucher_number,NULL);
4030                       FETCH c_challan_24q_data INTO l_action_information_id,
4031                                                     l_transfer_voucher_number_1,
4032                                                     l_bank_branch_code_1,
4033                                                     l_transfer_voucher_date_1,
4034                                                     l_amount_1,
4035                                                     l_surcharge_1,
4036                                                     l_education_cess_1,
4037                                                     l_interest_1,
4038                                                     l_others_1,
4039                                                     l_cheque_dd_num_1,
4040                                                     l_org_information_id_1;
4041                       CLOSE c_challan_24q_data;
4042                       IF (l_action_information_id IS NOT NULL)
4043                       THEN
4044                       -- This means that record was present in Form 24Q Correction. If there is a diff in
4045                       -- data then store in PL/SQL table based on 24Q Correction, else reject it.
4046                              IF (--Live Data                   24Q Correction Data
4047                                  (l_bank_branch_code        <> l_bank_branch_code_1)        OR
4048                                  (l_transfer_voucher_date   <> l_transfer_voucher_date_1)   OR
4049                                  (l_amount                  <> l_amount_1)                  OR
4050                                  (l_surcharge               <> l_surcharge_1)               OR
4051                                  (l_education_cess          <> l_education_cess_1)          OR
4052                                  (l_interest                <> l_interest_1)                OR
4053                                  (l_others                  <> l_others_1)                  OR
4054                                  (l_cheque_dd_num           <> l_cheque_dd_num_1)
4055                                )
4056                             THEN
4057                                  -- This means that in Form 24Q Correction, this record was present and at present
4058                                  -- the data has undergone a change since then. So need to store this change based
4059                                  -- on 24Q Correction.
4060                                   g_challan_data_upd(g_count_challan_upd).transfer_voucher_number := l_transfer_voucher_number_1;
4061                                   g_challan_data_upd(g_count_challan_upd).transfer_voucher_date   := l_transfer_voucher_date_1;
4062                                   g_challan_data_upd(g_count_challan_upd).amount                  := l_amount_1;
4063                                   g_challan_data_upd(g_count_challan_upd).surcharge               := l_surcharge_1;
4064                                   g_challan_data_upd(g_count_challan_upd).education_cess          := l_education_cess_1;
4065                                   g_challan_data_upd(g_count_challan_upd).interest                := l_others_1;
4066                                   g_challan_data_upd(g_count_challan_upd).other                   := l_interest_1;
4067                                   g_challan_data_upd(g_count_challan_upd).bank_branch_code        := l_bank_branch_code_1;
4068                                   g_challan_data_upd(g_count_challan_upd).cheque_dd_num           := l_cheque_dd_num_1;
4069                                   g_challan_data_upd(g_count_challan_upd).org_information_id      := l_org_information_id_1;
4070                                   g_challan_data_upd(g_count_challan_upd).modes                   := 'U';
4071                                   g_count_challan_upd := g_count_challan_upd + 1;
4072                             ELSE
4073                                   --This means that in Form 24Q Correction, this record was never
4074                                   -- updated. So need to insert this record data in PL/SQL table based on 24Q Archival
4075                                   g_challan_data_upd(g_count_challan_upd).transfer_voucher_number := c_rec.transfer_voucher_number;
4076                                   g_challan_data_upd(g_count_challan_upd).transfer_voucher_date   := c_rec.transfer_voucher_date;
4077                                   g_challan_data_upd(g_count_challan_upd).amount                  := c_rec.amount;
4078                                   g_challan_data_upd(g_count_challan_upd).surcharge               := c_rec.surcharge;
4079                                   g_challan_data_upd(g_count_challan_upd).education_cess          := c_rec.cess;
4080                                   g_challan_data_upd(g_count_challan_upd).interest                := c_rec.interest;
4081                                   g_challan_data_upd(g_count_challan_upd).other                   := c_rec.other;
4082                                   g_challan_data_upd(g_count_challan_upd).bank_branch_code        := c_rec.bank_branch_code;
4083                                   g_challan_data_upd(g_count_challan_upd).cheque_dd_num           := c_rec.cheque_dd_num;
4084                                   g_challan_data_upd(g_count_challan_upd).org_information_id      := c_rec.org_information_id;
4085                                   g_challan_data_upd(g_count_challan_upd).modes                   := 'U';
4086                                   g_count_challan_upd := g_count_challan_upd + 1;
4087                             END IF;
4088                      END IF;
4089                END IF;
4090       END IF;
4091     END LOOP;
4092     pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.generate_challan_data', 1);
4093   EXCEPTION
4094     WHEN OTHERS THEN
4095       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
4096       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
4097   END generate_challan_data;
4098 
4099   --------------------------------------------------------------------------
4100   --                                                                      --
4101   -- Name           : GET_ELEMENT_ENTRY_VALUES                            --
4102   -- Type           : PROCEDURE                                           --
4103   -- Access         : Public                                              --
4104   -- Description    :                                                     --
4105   --                                                                      --
4106   -- Parameters     :                                                     --
4107   --             IN : p_element_entry_id     NUMBER                       --
4108   --                : p_action_context_id    NUMBER                       --
4109   --                : p_assignment_id        NUMBER                       --
4110   --            OUT : p_ee_live_rec          t_screen_entry_value_rec     --
4111   --                  p_ee_24qc_rec          t_screen_entry_value_rec     --
4112   --------------------------------------------------------------------------
4113   -- Rev#  Date           Userid    Description                           --
4114   --------------------------------------------------------------------------
4115   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
4116   --------------------------------------------------------------------------
4117   PROCEDURE get_element_entry_values
4118     (
4119       p_element_entry_id   IN  NUMBER  DEFAULT NULL
4120      ,p_action_context_id  IN  NUMBER  DEFAULT NULL
4121      ,p_assignment_id      IN  NUMBER
4122      ,p_ee_live_rec        OUT NOCOPY  t_screen_entry_value_rec
4123      ,p_ee_24qc_rec        OUT NOCOPY  t_screen_entry_value_rec
4124      ,p_person_live_data   OUT NOCOPY  t_person_data_rec
4125      ,p_person_24q_data    OUT NOCOPY  t_person_data_rec
4126     )
4127   IS
4128     CURSOR c_get_ee_from_live_data
4129     IS
4130        SELECT pay_in_utils.get_ee_value(p_element_entry_id,'Challan or Voucher Number')  Challan_or_Voucher_Number,
4131               pay_in_utils.get_ee_value(p_element_entry_id,'Payment Date')               Payment_Date,
4132               pay_in_utils.get_ee_value(p_element_entry_id,'Taxable Income')             Taxable_Income,
4133               pay_in_utils.get_ee_value(p_element_entry_id,'Income Tax Deducted')        Income_Tax_Deducted,
4134               pay_in_utils.get_ee_value(p_element_entry_id,'Surcharge Deducted')         Surcharge_Deducted,
4135               pay_in_utils.get_ee_value(p_element_entry_id,'Education Cess Deducted')    Education_Cess_Deducted,
4136               pay_in_utils.get_ee_value(p_element_entry_id,'Amount Deposited')           Amount_Deposited
4137          FROM dual;
4138 
4139     CURSOR c_get_ee_from_24q_data
4140     IS
4141        SELECT action_information1        Challan_or_Voucher_Number,
4142               action_information4        Payment_Date,
4143               action_information5        Taxable_Income,
4144               action_information6        Income_Tax_Deducted,
4145               action_information7        Surcharge_Deducted,
4146               action_information8        Education_Cess_Deducted,
4147               DECODE(action_information_category,'IN_24Q_DEDUCTEE'
4148                     ,action_information9,'IN_24QC_DEDUCTEE'
4149                     ,action_information16) Amount_Deposited
4150              ,action_information_id
4151          FROM pay_action_information pai
4152         WHERE pai.action_context_id           = p_action_context_id
4153           AND pai.action_information_category IN ('IN_24Q_DEDUCTEE','IN_24QC_DEDUCTEE')
4154           AND pai.assignment_id               = p_assignment_id
4155           AND pai.source_id                   = p_element_entry_id
4156           AND pai.action_information3         = g_gre_id
4157         ORDER BY action_information_id DESC;
4158 
4159     CURSOR c_get_person_data_from_24q
4160     IS
4161        SELECT action_information1   person_id
4162              ,action_information4   pan_number
4163              ,action_information5   pan_ref_number
4164              ,action_information6   full_name
4165              ,action_information_id
4166          FROM pay_action_information
4167         WHERE action_context_id           =     p_action_context_id
4168           AND action_context_type         =     'AAP'
4169           AND action_information_category =     'IN_24Q_PERSON'
4170           AND assignment_id               =     p_assignment_id
4171           AND action_information2         =     g_year||g_quarter
4172           AND action_information3         =     g_gre_id
4173          ORDER BY action_information_id DESC;
4174 
4175     CURSOR c_get_tax_rate_from_24q
4176     IS
4177        SELECT action_information13  tax_rate
4178          FROM pay_action_information
4179         WHERE action_context_id           =     p_action_context_id
4180           AND action_context_type         =     'AAP'
4181           AND action_information_category =     'IN_24Q_DEDUCTEE'
4182           AND assignment_id               =     p_assignment_id
4183           AND source_id                   =     p_element_entry_id
4184           AND action_information3         =     g_gre_id;
4185 
4186     CURSOR c_get_person_data_from_24qc
4187     IS
4188        SELECT action_information12  person_id
4189              ,action_information9   pan_number
4190              ,action_information11  pan_ref_number
4191              ,action_information18  tax_rate
4192              ,action_information10  full_name
4193              ,action_information_id
4194          FROM pay_action_information
4195         WHERE action_context_id           =     p_action_context_id
4196           AND action_context_type         =     'AAP'
4197           AND action_information_category =     'IN_24QC_DEDUCTEE'
4198           AND assignment_id               =     p_assignment_id
4199           AND action_information2         =     g_year||g_quarter
4200           AND action_information3         =     g_gre_id
4201         ORDER BY action_information_id DESC;
4202 
4203     CURSOR c_get_live_person_data
4204     IS
4205        SELECT asg.person_id         person_id
4206              ,DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4) pan
4207              ,pep.per_information14 pan_ref_number
4208              ,hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title) full_name
4209              ,pep.effective_end_date
4210        FROM   per_assignments_f  asg
4211              ,per_people_f       pep
4212        WHERE  asg.assignment_id     = p_assignment_id
4213          AND  pep.person_id         = asg.person_id
4214          AND  pep.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
4215          AND  asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
4216          AND  assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
4217          AND  assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date
4218         ORDER BY 5 DESC;
4219 
4220     CURSOR c_aei_tax_rate(p_person_id  NUMBER)
4221     IS
4222        SELECT  paei.aei_information2
4223          FROM  per_assignment_extra_info paei
4224               ,per_assignments_f paa
4225         WHERE  paei.information_type = 'PER_IN_TAX_EXEMPTION_DF'
4226           AND  paei.aei_information_category = 'PER_IN_TAX_EXEMPTION_DF'
4227           AND  paei.assignment_id = paa.assignment_id
4228           AND  paa.person_id = p_person_id
4229           AND  paei.aei_information1 = g_tax_year
4230           AND  assignment_end_date(paa.assignment_id) BETWEEN paa.effective_start_date AND paa.effective_end_date
4231           AND  ROWNUM = 1;
4232 
4233 
4234        l_person_id             per_all_people_f.person_id%TYPE;
4235        l_pan_number            per_all_people_f.per_information14%TYPE;
4236        l_pan_ref_number        per_all_people_f.per_information14%TYPE;
4237        l_full_name             per_all_people_f.full_name%TYPE;
4238        l_tax_rate              per_assignment_extra_info.aei_information2 %TYPE;
4239        l_end_date              DATE;
4240        l_old_tax_rate          per_assignment_extra_info.aei_information2 %TYPE;
4241        l_action_information_id NUMBER;
4242        l_procedure             VARCHAR2(250);
4243        l_message               VARCHAR2(250);
4244   BEGIN
4245         g_debug     := hr_utility.debug_enabled;
4246         l_procedure := g_package ||'.get_element_entry_values';
4247         pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
4248         pay_in_utils.set_location(g_debug,'Fetching Live Data ' ,2);
4249         OPEN  c_get_ee_from_live_data;
4250         FETCH c_get_ee_from_live_data INTO p_ee_live_rec.challan_number,
4251                                            p_ee_live_rec.payment_date,
4252                                            p_ee_live_rec.taxable_income,
4253                                            p_ee_live_rec.income_tax,
4254                                            p_ee_live_rec.surcharge,
4255                                            p_ee_live_rec.education_cess,
4256                                            p_ee_live_rec.amount_deposited;
4257         CLOSE c_get_ee_from_live_data;
4258 
4259         pay_in_utils.set_location(g_debug,'Fetched Live Data ' ,2);
4260         pay_in_utils.set_location(g_debug,'Fetching 24Q Archival Data ' ,2);
4261 
4262         pay_in_utils.set_location(g_debug,'p_element_entry_id   '|| p_element_entry_id  ,2);
4263         pay_in_utils.set_location(g_debug,'p_action_context_id  '|| p_action_context_id ,2);
4264         pay_in_utils.set_location(g_debug,'p_assignment_id      '|| p_assignment_id     ,2);
4265 
4266         OPEN  c_get_ee_from_24q_data;
4267         FETCH c_get_ee_from_24q_data INTO  p_ee_24qc_rec.challan_number,
4268                                            p_ee_24qc_rec.payment_date,
4269                                            p_ee_24qc_rec.taxable_income,
4270                                            p_ee_24qc_rec.income_tax,
4271                                            p_ee_24qc_rec.surcharge,
4272                                            p_ee_24qc_rec.education_cess,
4273                                            p_ee_24qc_rec.amount_deposited,
4274                                            l_action_information_id;
4275         CLOSE c_get_ee_from_24q_data;
4276         pay_in_utils.set_location(g_debug,'Fetched 24Q Archival Data ' ,2);
4277 
4278         pay_in_utils.set_location(g_debug,'Searching in 24Q Correction ' ,2);
4279         OPEN  c_get_person_data_from_24qc;
4280         FETCH c_get_person_data_from_24qc INTO l_person_id,l_pan_number,l_pan_ref_number,l_old_tax_rate,p_person_24q_data.full_name,l_action_information_id;
4281         CLOSE c_get_person_data_from_24qc;
4282         pay_in_utils.set_location(g_debug,'Found person id in 24Q Correction: '|| l_person_id ,2);
4283 
4284         IF (l_person_id IS NULL)
4285         THEN
4286                pay_in_utils.set_location(g_debug,'Person ID is NULL' ,2);
4287                pay_in_utils.set_location(g_debug,'Hence Searching in 24Q Archival ' ,2);
4288                OPEN  c_get_person_data_from_24q;
4289                FETCH c_get_person_data_from_24q INTO l_person_id,l_pan_number,l_pan_ref_number,p_person_24q_data.full_name,l_action_information_id;
4290                CLOSE c_get_person_data_from_24q;
4291 
4292                OPEN  c_get_tax_rate_from_24q;
4293                FETCH c_get_tax_rate_from_24q INTO l_old_tax_rate;
4294                CLOSE c_get_tax_rate_from_24q;
4295                pay_in_utils.set_location(g_debug,'Old Tax Rate was '|| l_old_tax_rate,2);
4296         END IF;
4297 
4298         p_person_24q_data.person_id      := l_person_id;
4299         p_person_24q_data.pan_number     := l_pan_number;
4300         p_person_24q_data.pan_ref_number := l_pan_ref_number;
4301         p_person_24q_data.tax_rate       := l_old_tax_rate;
4302 
4303         pay_in_utils.set_location(g_debug,'Fetching Person Data from Live Data' ,2);
4304         OPEN c_get_live_person_data;
4305         FETCH c_get_live_person_data INTO p_person_live_data.person_id
4306                                          ,p_person_live_data.pan_number
4307                                          ,p_person_live_data.pan_ref_number
4308                                          ,p_person_live_data.full_name
4309                                          ,l_end_date;
4310         CLOSE c_get_live_person_data;
4311         pay_in_utils.set_location(g_debug,'Fetched Person Data from Live Data' ,2);
4312 
4313         OPEN  c_aei_tax_rate(p_person_live_data.person_id);
4314         FETCH c_aei_tax_rate INTO p_person_live_data.tax_rate;
4315         CLOSE c_aei_tax_rate;
4316 
4317         p_ee_24qc_rec.taxable_income   := TO_NUMBER(remove_curr_format(p_ee_24qc_rec.taxable_income));
4318         p_ee_24qc_rec.income_tax       := TO_NUMBER(remove_curr_format(p_ee_24qc_rec.income_tax));
4319         p_ee_24qc_rec.surcharge        := TO_NUMBER(remove_curr_format(p_ee_24qc_rec.surcharge));
4320         p_ee_24qc_rec.education_cess   := TO_NUMBER(remove_curr_format(p_ee_24qc_rec.education_cess));
4321         p_ee_24qc_rec.amount_deposited := TO_NUMBER(remove_curr_format(p_ee_24qc_rec.amount_deposited));
4322 
4323 
4324         p_ee_live_rec.taxable_income   := TO_NUMBER(remove_curr_format(p_ee_live_rec.taxable_income));
4325         p_ee_live_rec.income_tax       := TO_NUMBER(remove_curr_format(p_ee_live_rec.income_tax));
4326         p_ee_live_rec.surcharge        := TO_NUMBER(remove_curr_format(p_ee_live_rec.surcharge));
4327         p_ee_live_rec.education_cess   := TO_NUMBER(remove_curr_format(p_ee_live_rec.education_cess));
4328         p_ee_live_rec.amount_deposited := TO_NUMBER(remove_curr_format(p_ee_live_rec.amount_deposited));
4329 
4330         pay_in_utils.set_location(g_debug,'Leaving : '|| g_package||'.get_element_entry_values ', 1);
4331   EXCEPTION
4332     WHEN OTHERS THEN
4333       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
4334       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
4335   END get_element_entry_values;
4336 
4337   --------------------------------------------------------------------------
4338   --                                                                      --
4339   -- Name           : GET_LIVE_BALANCES                                   --
4340   -- Type           : PROCEDURE                                           --
4341   -- Access         : Private                                             --
4342   -- Description    :                                                     --
4343   --                                                                      --
4344   -- Parameters     :                                                     --
4345   --             IN : p_run_asg_action_id    NUMBER                       --
4346   --                  p_gre_id               NUMBER                       --
4347   --            OUT : p_balances             t_balance_value_tab          --
4348   --------------------------------------------------------------------------
4349   -- Rev#  Date           Userid    Description                           --
4350   --------------------------------------------------------------------------
4351   -- 115.0 07-Feb-2007    rpalli    5754018 : 24QC Quarter4 Stat Update   --
4352   --------------------------------------------------------------------------
4353   PROCEDURE get_live_balances(p_run_asg_action_id     IN  NUMBER
4354                               ,p_gre_id               IN  NUMBER
4355                               ,p_balances             OUT NOCOPY t_balance_value_tab)
4356   IS
4357 
4358     CURSOR c_f16_le_balances
4359     IS
4360     SELECT pdb.defined_balance_id balance_id
4361           ,pbt.balance_name       balance_name
4362       FROM pay_balance_types pbt
4363           ,pay_balance_dimensions pbd
4364           ,pay_defined_balances pdb
4365      WHERE pbt.balance_name IN('F16 Salary Under Section 17'
4366                               ,'F16 Profit in lieu of Salary'
4367                               ,'F16 Value of Perquisites'
4368                               ,'F16 Gross Salary less Allowances'
4369                               ,'F16 Allowances Exempt'
4370                               ,'F16 Deductions under Sec 16'
4371                               ,'F16 Income Chargeable Under head Salaries'
4372                               ,'F16 Other Income'
4373                               ,'F16 Gross Total Income'
4374                               ,'F16 Total Income'
4375                               ,'F16 Tax on Total Income'
4376                               ,'F16 Marginal Relief'
4377                               ,'F16 Total Tax payable'
4378                               ,'F16 Relief under Sec 89'
4379                               ,'F16 Employment Tax'
4380                               ,'F16 Entertainment Allowance'
4381                               ,'F16 Surcharge'
4382                               ,'F16 Education Cess'
4383                               ,'F16 Sec and HE Cess'
4384                               ,'F16 TDS'
4385                              --Chapter VIA Balances
4386                               ,'F16 Total Chapter VI A Deductions'
4387                               ,'F16 Deductions Sec 80CCE'
4388                               )
4389        AND pbd.dimension_name   ='_ASG_LE_PTD'
4390        AND pbt.legislation_code = 'IN'
4391        AND pbd.legislation_code = 'IN'
4392        AND pdb.legislation_code = 'IN'
4393        AND pbt.balance_type_id = pdb.balance_type_id
4394        AND pbd.balance_dimension_id  = pdb.balance_dimension_id;
4395 
4396     g_bal_name_tab       t_bal_name_tab;
4397     g_context_table      pay_balance_pkg.t_context_tab;
4398     g_balance_value_tab  pay_balance_pkg.t_balance_value_tab;
4399     g_result_table       pay_balance_pkg.t_detailed_bal_out_tab;
4400 
4401     l_balance_value       NUMBER;
4402     i                     NUMBER;
4403     j                     NUMBER;
4404 
4405     l_proc                VARCHAR2(100);
4406     l_message             VARCHAR2(255);
4407 
4408     l_tot_via_qa         NUMBER;
4409     l_q4_80cce_total     NUMBER;
4410     l_q4_others_total    NUMBER;
4411     l_cess		 NUMBER;
4412 
4413   BEGIN
4414     g_debug := hr_utility.debug_enabled;
4415     l_proc  := g_package||'.get_live_balances';
4416 
4417     pay_in_utils.set_location(g_debug,'Entering : '||l_proc,10);
4418 
4419     if g_debug then
4420       pay_in_utils.trace('******************************','********************');
4421       pay_in_utils.trace('p_run_asg_action_id             : ',p_run_asg_action_id);
4422       pay_in_utils.trace('p_gre_id                        : ',p_gre_id);
4423       pay_in_utils.trace('******************************','********************');
4424    end if;
4425 
4426     i := 1;
4427     g_bal_name_tab.DELETE;
4428     g_balance_value_tab.DELETE;
4429     g_result_table.DELETE;
4430     g_context_table.DELETE;
4431     g_context_table(1).tax_unit_id := p_gre_id;
4432 
4433     --Step 1: Chapter VIA Balances - Initialise variables
4434     l_tot_via_qa := 0;
4435     l_q4_80cce_total := 0;
4436     l_q4_others_total := 0;
4437 
4438     l_cess:=0;
4439 
4440     --Step 2: Get F16 balances
4441 
4442     FOR c_rec IN c_f16_le_balances
4443     LOOP
4444       g_balance_value_tab(i).defined_balance_id := c_rec.balance_id;
4445       g_bal_name_tab(i).balance_name            := c_rec.balance_name;
4446       i := i + 1;
4447     END LOOP;
4448 
4449     pay_balance_pkg.get_value(p_assignment_action_id  =>     p_run_asg_action_id
4450                              ,p_defined_balance_lst   =>     g_balance_value_tab
4451                              ,p_context_lst           =>     g_context_table
4452                              ,p_output_table          =>     g_result_table
4453                              );
4454 
4455 
4456     FOR i IN 1..g_balance_value_tab.COUNT
4457     LOOP
4458       IF (g_result_table(i).balance_value <> 0)
4459       THEN
4460         IF (g_bal_name_tab(i).balance_name ='F16 Total Chapter VI A Deductions')
4461           THEN
4462             l_tot_via_qa := g_result_table(i).balance_value ;
4463         ELSIF (g_bal_name_tab(i).balance_name  = 'F16 Deductions Sec 80CCE')
4464           THEN
4465             l_q4_80cce_total := g_result_table(i).balance_value ;
4466         ELSIF (g_bal_name_tab(i).balance_name  = 'F16 Education Cess' OR g_bal_name_tab(i).balance_name  = 'F16 Sec and HE Cess')
4467           THEN
4468             l_cess := l_cess + g_result_table(i).balance_value ;
4469         END IF;
4470 
4471           if g_debug then
4472               pay_in_utils.trace('balance_name             : ',g_bal_name_tab(i).balance_name);
4473               pay_in_utils.trace('balance_value            : ',g_result_table(i).balance_value);
4474           end if;
4475       END IF;
4476     END LOOP;
4477 
4478     l_q4_others_total := l_tot_via_qa - l_q4_80cce_total;
4479 
4480     i:= g_balance_value_tab.COUNT + 1;
4481     g_bal_name_tab(i).balance_name  := '80CCE';
4482     g_result_table(i).balance_value := l_q4_80cce_total;
4483 
4484     i:= i + 1;
4485     g_bal_name_tab(i).balance_name  := 'Others';
4486     g_result_table(i).balance_value := l_q4_others_total;
4487 
4488     FOR r IN 1..g_bal_name_tab.COUNT
4489     LOOP
4490       IF g_bal_name_tab(r).balance_name='F16 Education Cess' THEN
4491         p_balances(r).balance_name  := g_bal_name_tab(r).balance_name;
4492         p_balances(r).balance_value := l_cess;
4493       ELSE
4494         p_balances(r).balance_name  := g_bal_name_tab(r).balance_name;
4495         p_balances(r).balance_value := g_result_table(r).balance_value;
4496       END IF ;
4497     END LOOP;
4498 
4499     --Step 3:Delete all PL/SQL tables
4500     g_bal_name_tab.DELETE;
4501     g_context_table.DELETE;
4502     g_balance_value_tab.DELETE;
4503     g_result_table.DELETE;
4504 
4505     pay_in_utils.set_location(g_debug,'Leaving: '||l_proc,30);
4506 
4507   EXCEPTION
4508     WHEN OTHERS THEN
4509       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_proc, 'SQLERRMC:'||sqlerrm);
4510       pay_in_utils.set_location(g_debug,'Leaving : '||l_proc, 150);
4511   END get_live_balances;
4512 
4513 
4514   --------------------------------------------------------------------------
4515   --                                                                      --
4516   -- Name           : GET_BALANCE_VALUES                                  --
4517   -- Type           : PROCEDURE                                           --
4518   -- Access         : Private                                             --
4519   -- Description    :                                                     --
4520   --                                                                      --
4521   -- Parameters     :                                                     --
4522   --             IN : p_source_id            NUMBER                       --
4523   --                : p_action_context_id    NUMBER                       --
4524   --                : p_assignment_id        NUMBER                       --
4525   --                : p_24qa_pay_act_id      NUMBER                       --
4526   --                : p_mode                 VARCHAR2                     --
4527   --            OUT : p_ba_live_rec          t_balance_value_rec          --
4528   --                  p_ba_24qc_rec          t_balance_value_rec          --
4529   --                : p_gre_count            NUMBER                       --
4530   --------------------------------------------------------------------------
4531   -- Rev#  Date           Userid    Description                           --
4532   --------------------------------------------------------------------------
4533   -- 115.0 07-Feb-2007    rpalli    5754018 : 24QC Quarter4 Stat Update   --
4534   --------------------------------------------------------------------------
4535   PROCEDURE get_balance_values
4536     (
4537       p_source_id          IN  NUMBER  DEFAULT NULL
4538      ,p_action_context_id  IN  NUMBER  DEFAULT NULL
4539      ,p_assignment_id      IN  NUMBER
4540      ,p_24qa_pay_act_id    IN  NUMBER
4541      ,p_mode               IN  VARCHAR2
4542      ,p_ba_live_rec        OUT NOCOPY  t_balance_value_tab
4543      ,p_ba_24qc_rec        OUT NOCOPY  t_balance_value_tab
4544      ,p_person_live_data   OUT NOCOPY  t_person_data_sal_rec
4545      ,p_person_24q_data    OUT NOCOPY  t_person_data_sal_rec
4546      ,p_gre_count          OUT NOCOPY  NUMBER
4547     )
4548   IS
4549 
4550     CURSOR c_get_bal_24q(p_action_context_id NUMBER, p_24q_source_id NUMBER, p_category VARCHAR2, p_balance_name VARCHAR2)
4551     IS
4552        SELECT DISTINCT
4553        FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values(p_category,p_balance_name,pai.action_context_id,pai.source_id,1)))
4554          FROM pay_action_information pai
4555         WHERE pai.action_context_id           = p_action_context_id
4556           AND pai.action_information_category = p_category
4557           AND pai.source_id                   = p_24q_source_id;
4558 
4559     CURSOR c_get_person_data_from_24q
4560     IS
4561        SELECT DISTINCT
4562               pai.action_information1   person_id
4563              ,pai.action_information4   pan_number
4564              ,pai.action_information5   pan_ref_number
4565              ,pai.action_information6   full_name
4566              ,fnd_date.canonical_to_date(pai.action_information9)   start_date
4567              ,fnd_date.canonical_to_date(pai.action_information10)  end_date
4568              ,pai.source_id
4569           FROM pay_action_information pai
4570               ,pay_assignment_actions paa
4571          WHERE pai.action_information_category IN('IN_24Q_PERSON')
4572            AND pai.action_information3         = g_gre_id
4573            AND pai.action_information2         = g_year||g_quarter
4574            AND pai.assignment_id               = p_assignment_id
4575            AND (
4576                   (pai.source_id  = p_source_id AND p_mode NOT IN ('A'))
4577                OR (p_mode IN ('A'))
4578                )
4579            AND pai.action_context_id           = paa.assignment_action_id
4580            AND paa.payroll_action_id           = p_24qa_pay_act_id
4581          ORDER BY pai.source_id DESC;
4582 
4583     CURSOR c_get_person_data_from_24qc
4584     IS
4585        SELECT DISTINCT
4586               pai.action_information1   person_id
4587              ,pai.action_information4   pan_number
4588              ,pai.action_information5   pan_ref_number
4589              ,pai.action_information6   full_name
4590              ,fnd_date.canonical_to_date(pai.action_information8)   start_date
4591              ,fnd_date.canonical_to_date(pai.action_information9)  end_date
4592              ,pai.source_id
4593          FROM pay_action_information pai
4594               ,pay_assignment_actions paa
4595               ,pay_action_interlocks  locks
4596               ,pay_assignment_actions paa_master
4597          WHERE pai.action_information_category = 'IN_24QC_PERSON'
4598            AND pai.assignment_id               = p_assignment_id
4599            AND pai.action_information3         = g_gre_id
4600            AND pai.action_information2         = g_year||g_quarter
4601            AND pai.action_information10        = 'NA'
4602            AND (
4603                   (pai.source_id  = p_source_id AND p_mode NOT IN ('A'))
4604                OR (p_mode IN ('A'))
4605                )
4606            AND locks.locking_action_id         = pai.action_context_id
4607            AND locks.locked_action_id          = paa.assignment_action_id
4608            AND paa.payroll_action_id           = p_24qa_pay_act_id
4609            AND paa_master.assignment_action_id = pai.action_context_id
4610            AND paa_master.payroll_action_id IN(
4611                                                   SELECT org_information3
4612                                                     FROM hr_organization_information
4613                                                    WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
4614                                                      AND organization_id         = g_gre_id
4615                                                      AND org_information1        = g_year
4616                                                      AND org_information2        = g_quarter
4617                                                      AND org_information5        = 'A'
4618                                                      AND org_information6        = 'C'
4619                                                  )
4620                                      ORDER BY pai.source_id DESC;
4621 
4622     CURSOR c_get_live_person_data
4623     IS
4624        SELECT asg.person_id         person_id
4625              ,DECODE(pep.per_information4,NULL,DECODE(pep.per_information5,'Yes','APPLIEDFOR','PANNOTAVBL'),pep.per_information4) pan
4626              ,pep.per_information14 pan_ref_number
4627              ,hr_in_utility.per_in_full_name(pep.first_name,pep.middle_names,pep.last_name,pep.title) full_name
4628        FROM   per_assignments_f  asg
4629              ,per_people_f       pep
4630        WHERE  asg.assignment_id     = p_assignment_id
4631          AND  pep.person_id         = asg.person_id
4632          AND  pep.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
4633          AND  asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
4634          AND  assignment_end_date(asg.assignment_id) BETWEEN asg.effective_start_date AND asg.effective_end_date
4635          AND  assignment_end_date(asg.assignment_id) BETWEEN pep.effective_start_date AND pep.effective_end_date;
4636 
4637   CURSOR c_24qc_source_id(p_action_context_id     NUMBER,
4638                           p_assignment_id         NUMBER
4639                          )
4640       IS
4641         SELECT pai.action_context_id, pai.source_id
4642           FROM pay_action_information pai
4643               ,pay_assignment_actions paa
4644               ,pay_action_interlocks  locks
4645               ,pay_assignment_actions paa_master
4646          WHERE pai.action_information_category = 'IN_24QC_PERSON'
4647            AND pai.assignment_id               = p_assignment_id
4648            AND pai.action_information3         = g_gre_id
4649            AND pai.action_information2         = g_year||g_quarter
4650            AND pai.action_information10        = 'A'
4651            AND (
4652                   (pai.source_id  = p_source_id AND p_mode NOT IN ('A'))
4653                OR (p_mode IN ('A'))
4654                )
4655            AND locks.locking_action_id         = pai.action_context_id
4656            AND locks.locked_action_id          = paa.assignment_action_id
4657            AND paa.payroll_action_id           = p_24qa_pay_act_id
4658            AND paa_master.assignment_action_id = pai.action_context_id
4659            AND paa_master.payroll_action_id IN(
4660                                                   SELECT org_information3
4661                                                     FROM hr_organization_information
4662                                                    WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
4663                                                      AND organization_id         = g_gre_id
4664                                                      AND org_information1        = g_year
4665                                                      AND org_information2        = g_quarter
4666                                                      AND org_information5        = 'A'
4667                                                      AND org_information6        = 'C'
4668                                                  )
4669                                                  ORDER BY pai.source_id DESC;
4670 
4671 
4672   CURSOR c_24qa_source_id(p_action_context_id     NUMBER,
4673                           p_assignment_id         NUMBER
4674                          )
4675   IS
4676        SELECT DISTINCT pai.action_context_id, pai.source_id
4677           FROM pay_action_information pai
4678               ,pay_assignment_actions paa
4679          WHERE pai.action_information_category IN('IN_24Q_PERSON')
4680            AND pai.action_information3         = g_gre_id
4681            AND pai.action_information2         = g_year||g_quarter
4682            AND pai.assignment_id               = p_assignment_id
4683            AND (
4684                   (pai.source_id  = p_source_id AND p_mode NOT IN ('A'))
4685                OR (p_mode IN ('A'))
4686                )
4687            AND pai.action_context_id           = paa.assignment_action_id
4688            AND paa.payroll_action_id           = p_24qa_pay_act_id
4689            ORDER BY pai.source_id DESC;
4690 
4691     CURSOR c_gre_records(p_assignment_id NUMBER)
4692     IS
4693     SELECT  GREATEST(asg.effective_start_date,g_fin_start_date) start_date
4694            ,LEAST(asg.effective_end_date,g_fin_end_date)        end_date
4695            ,scl.segment1
4696       FROM  per_assignments_f  asg
4697            ,hr_soft_coding_keyflex scl
4698            ,pay_assignment_actions paa
4699      WHERE  asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id
4700        AND  paa.assignment_action_id = p_action_context_id
4701        AND  asg.assignment_id = paa.assignment_id
4702        AND  paa.assignment_id = p_assignment_id
4703        AND  scl.segment1 LIKE g_gre_id
4704        AND  ( asg.effective_start_date BETWEEN g_fin_start_date  AND g_end_date
4705           OR  g_fin_start_date BETWEEN asg.effective_start_date  AND asg.effective_end_date
4706               )
4707        AND  asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
4708     ORDER BY 1 ;
4709 
4710     CURSOR get_eoy_archival_details(p_start_date        DATE
4711                                    ,p_end_date         DATE
4712                                    ,p_tax_unit_id      NUMBER
4713                                    ,p_assignment_id    NUMBER
4714                                    )
4715     IS
4716     SELECT FND_NUMBER.CANONICAL_TO_NUMBER(SUBSTR(MAX(LPAD(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) run_asg_action_id
4717       FROM pay_assignment_actions paa
4718           ,pay_payroll_actions ppa
4719           ,per_assignments_f paf
4720      WHERE paf.assignment_id = paa.assignment_id
4721        AND paf.assignment_id = p_assignment_id
4722        AND paa.tax_unit_id  = p_tax_unit_id
4723        AND paa.payroll_action_id = ppa.payroll_action_id
4724        AND ppa.action_type IN('R','Q','I','B')
4725        AND ppa.payroll_id    = paf.payroll_id
4726        AND ppa.action_status ='C'
4727        AND ppa.effective_date between p_start_date and p_end_date
4728        AND paa.source_action_id IS NULL
4729        AND (1 = DECODE(ppa.action_type,'I',1,0)
4730             OR EXISTS (SELECT ''
4731                      FROM pay_action_interlocks intk,
4732                           pay_assignment_actions paa1,
4733                           pay_payroll_actions ppa1
4734                     WHERE intk.locked_action_id = paa.assignment_Action_id
4735                       AND intk.locking_action_id =  paa1.assignment_action_id
4736                       AND paa1.payroll_action_id =ppa1.payroll_action_id
4737                       AND paa1.assignment_id = p_assignment_id
4738                       AND ppa1.action_type in('P','U')
4739                       AND ppa.action_type in('R','Q','B')
4740                       AND ppa1.action_status ='C'
4741                       AND ppa1.effective_date BETWEEN p_start_date and p_end_date
4742                       AND ROWNUM =1 ));
4743 
4744 
4745     CURSOR get_assignment_pact_id
4746     IS
4747     SELECT paa.assignment_id
4748           ,paa.payroll_action_id
4749           ,paf.person_id
4750       FROM pay_assignment_actions  paa
4751           ,per_all_assignments_f paf
4752      WHERE paa.assignment_action_id = p_action_context_id
4753        AND paa.assignment_id = paf.assignment_id
4754        AND ROWNUM =1;
4755 
4756     CURSOR c_termination_check(p_assignment_id NUMBER)
4757     IS
4758     SELECT NVL(pos.actual_termination_date,(fnd_date.string_to_date('31-12-4712','DD-MM-YYYY')))
4759       FROM   per_all_assignments_f  asg
4760             ,per_periods_of_service pos
4761      WHERE asg.person_id         = pos.person_id
4762        AND asg.assignment_id     = p_assignment_id
4763        AND asg.business_group_id = pos.business_group_id
4764        AND asg.business_group_id = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
4765        AND NVL(pos.actual_termination_date,(to_date('31-12-4712','DD-MM-YYYY')))
4766              BETWEEN asg.effective_start_date AND asg.effective_end_date
4767      ORDER BY 1 DESC;
4768 
4769 
4770        l_per_id                per_all_people_f.person_id%TYPE;
4771        l_person_id             per_all_people_f.person_id%TYPE;
4772        l_pan_number            per_all_people_f.per_information14%TYPE;
4773        l_pan_ref_number        per_all_people_f.per_information14%TYPE;
4774        l_full_name             per_all_people_f.full_name%TYPE;
4775 
4776        l_procedure             VARCHAR2(250);
4777        l_message               VARCHAR2(250);
4778 
4779        l_source_id             NUMBER;
4780        l_24qa_source_id        NUMBER;
4781        l_arc_pay_action_id               NUMBER;
4782 
4783        l_run_asg_action_id               NUMBER;
4784 
4785        i                     NUMBER;
4786        j                     NUMBER;
4787        l_count               NUMBER;
4788        l_balance_value       NUMBER;
4789 
4790        l_assignment_id       NUMBER;
4791        l_action_context_id   NUMBER;
4792        l_actual_term_date    DATE;
4793        l_effective_start_date DATE;
4794        l_effective_end_date   DATE;
4795 
4796        l_last_run_ind                    BOOLEAN;
4797 
4798        l_sal_category               VARCHAR2(250);
4799        l_via_category               VARCHAR2(250);
4800 
4801        t_balance_name t_bal_name_tab;
4802 
4803   BEGIN
4804 
4805         g_debug     := hr_utility.debug_enabled;
4806         l_procedure := g_package ||'.get_balance_values';
4807         pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
4808         pay_in_utils.set_location(g_debug,'Fetching Live Data ' ,2);
4809 
4810     --
4811       l_count := 1;
4812       i := 1;
4813       j := 1;
4814       g_asg_tab.DELETE;
4815 
4816       t_balance_name(1).balance_name  :=          'F16 Salary Under Section 17';
4817       t_balance_name(2).balance_name  :=          'F16 Profit in lieu of Salary';
4818       t_balance_name(3).balance_name  :=          'F16 Value of Perquisites';
4819       t_balance_name(4).balance_name  :=          'F16 Gross Salary less Allowances';
4820       t_balance_name(5).balance_name  :=          'F16 Allowances Exempt';
4821       t_balance_name(6).balance_name  :=          'F16 Deductions under Sec 16';
4822       t_balance_name(7).balance_name  :=          'F16 Income Chargeable Under head Salaries';
4823       t_balance_name(8).balance_name  :=          'F16 Other Income';
4824       t_balance_name(9).balance_name  :=          'F16 Gross Total Income';
4825       t_balance_name(10).balance_name :=          'F16 Total Income';
4826       t_balance_name(11).balance_name :=          'F16 Tax on Total Income';
4827       t_balance_name(12).balance_name :=          'F16 Marginal Relief';
4828       t_balance_name(13).balance_name :=          'F16 Total Tax payable';
4829       t_balance_name(14).balance_name :=          'F16 Relief under Sec 89';
4830       t_balance_name(15).balance_name :=          'F16 Employment Tax';
4831       t_balance_name(16).balance_name :=          'F16 Entertainment Allowance';
4832       t_balance_name(17).balance_name :=          'F16 Surcharge';
4833       t_balance_name(18).balance_name :=          'F16 Education Cess';
4834       t_balance_name(19).balance_name :=          'F16 TDS';
4835         --Chapter VIA Balances
4836       t_balance_name(20).balance_name :=          'F16 Total Chapter VI A Deductions';
4837       t_balance_name(21).balance_name :=          'F16 Deductions Sec 80CCE';
4838         --Chapter VIA Balances - Archive
4839       t_balance_name(22).balance_name :=          '80CCE';
4840       t_balance_name(23).balance_name :=          'Others';
4841 
4842     --
4843     OPEN  get_assignment_pact_id;
4844     FETCH get_assignment_pact_id INTO l_assignment_id ,l_arc_pay_action_id,l_per_id;
4845     CLOSE get_assignment_pact_id;
4846 
4847     OPEN  c_termination_check(l_assignment_id);
4848     FETCH c_termination_check INTO l_actual_term_date;
4849     CLOSE c_termination_check;
4850 
4851     if g_debug then
4852        pay_in_utils.trace('l_assignment_id          : ',l_assignment_id);
4853        pay_in_utils.trace('l_arc_pay_action_id      : ',l_arc_pay_action_id);
4854        pay_in_utils.trace('l_per_id                 : ',l_per_id);
4855        pay_in_utils.trace('l_actual_term_date       : ',l_actual_term_date);
4856     end if;
4857 
4858  -- Get all records from financial year start till current quarter end to find out
4859  -- previous GRE assignment_action_id and remaining pay periods
4860     pay_in_utils.set_location(g_debug,'Entering : '||l_assignment_id,12);
4861     FOR c_rec IN c_gre_records(l_assignment_id)
4862     LOOP
4863         IF ((l_count <>1)
4864               AND
4865             (g_asg_tab(l_count-1).gre_id =  c_rec.segment1)
4866              AND
4867             (g_asg_tab(l_count-1).end_date + 1 = c_rec.start_date)
4868           )
4869         THEN
4870            g_asg_tab(l_count-1).end_date     := c_rec.end_date;
4871            l_count := l_count -1;
4872         ELSE
4873            g_asg_tab(l_count).gre_id       := c_rec.segment1;
4874            g_asg_tab(l_count).start_date   := c_rec.start_date;
4875            g_asg_tab(l_count).end_date     := c_rec.end_date;
4876         END IF;
4877         l_count := l_count + 1;
4878     END LOOP;
4879 
4880     pay_in_utils.set_location(g_debug,'l_count : '||l_count,20);
4881 
4882     p_gre_count := l_count;
4883 
4884 /* g_asg_tab.start/end date will contain the actual start/end of asg in a GRE or the the financial year  .
4885    We need to change it to quarter date*/
4886 
4887     FOR i IN 1..l_count-1
4888     LOOP
4889        --Get Live Balances only if it is a candidate for reporting in the specified quarter
4890       IF (g_start_date <=  g_asg_tab(i).end_date AND
4891           g_end_date   >=  g_asg_tab(i).start_date) THEN
4892          pay_in_utils.set_location(g_debug,'l_assignment_id : '||l_assignment_id||' ' ||g_asg_tab(i).start_date||' ' ||g_asg_tab(i).end_date||' ' ||g_asg_tab(i).gre_id,30);
4893 
4894 
4895         -- Get assignment action id corresponding to the maximum action sequence record
4896          OPEN  get_eoy_archival_details(GREATEST(g_asg_tab(i).start_date,g_start_date)
4897                                        ,LEAST(g_asg_tab(i).end_date,g_end_date)
4898                                        ,g_asg_tab(i).gre_id
4899                                        ,l_assignment_id
4900                                        );
4901          FETCH get_eoy_archival_details INTO l_run_asg_action_id;
4902          CLOSE get_eoy_archival_details;
4903 
4904             pay_in_utils.trace('l_run_asg_action_id in LOOP: ', l_run_asg_action_id );
4905 
4906          IF l_run_asg_action_id IS NOT NULL THEN
4907 
4908            -- Get Person start date and end date
4909            IF g_asg_tab(i).start_date > LEAST(g_asg_tab(i).end_date,l_actual_term_date) THEN
4910              l_effective_end_date := g_end_date;
4911            ELSE
4912              l_effective_end_date := LEAST(g_end_date,g_asg_tab(i).end_date,l_actual_term_date);
4913            END IF;
4914 
4915            IF g_quarter = 'Q4' THEN
4916              l_effective_start_date := g_asg_tab(i).start_date;
4917            ELSE
4918              l_effective_start_date := GREATEST(g_qr_start_date,g_asg_tab(i).start_date);
4919            END IF;
4920 
4921             pay_in_utils.set_location(g_debug,'Fetching Live Balances Data  ' ,2);
4922             pay_in_utils.set_location(g_debug,'p_mode in Live Balances Data : '||p_mode ,2);
4923             pay_in_utils.set_location(g_debug,'p_source_id in Live Balances Data : '||p_source_id ,2);
4924             pay_in_utils.set_location(g_debug,'l_run_asg_action_id in Live Balances Data : '||l_run_asg_action_id ,2);
4925 
4926             IF (p_source_id = l_run_asg_action_id)
4927             THEN
4928 
4929               get_live_balances(p_run_asg_action_id     => l_run_asg_action_id
4930                                ,p_gre_id                => g_asg_tab(i).gre_id
4931                                ,p_balances              => p_ba_live_rec
4932                                );
4933               pay_in_utils.set_location(g_debug,'Fetched Live Balances Data ' ,2);
4934               EXIT;
4935             END IF;
4936             pay_in_utils.set_location(g_debug,'Fetching Live Balances Data  ' ,3);
4937 
4938             IF ((p_mode = 'D') AND (p_source_id < l_run_asg_action_id))
4939             THEN
4940 
4941               get_live_balances(p_run_asg_action_id     => l_run_asg_action_id
4942                                ,p_gre_id                => g_asg_tab(i).gre_id
4943                                ,p_balances              => p_ba_live_rec
4944                                );
4945               pay_in_utils.set_location(g_debug,'Fetched Live Balances Data ' ,3);
4946               EXIT;
4947             END IF;
4948 
4949          END IF; -- Run Assact is NOT NULL
4950       END IF; -- End of Get Live Balances
4951     END LOOP;
4952 
4953             pay_in_utils.set_location(g_debug,'Fetching 24Q Archival Balances Data ' ,3);
4954 
4955             pay_in_utils.set_location(g_debug,'Searching in 24Q Correction ' ,3);
4956             pay_in_utils.set_location(g_debug,'Fetching 24Q Archival Source ID ' ,3);
4957 
4958             pay_in_utils.set_location(g_debug,'p_action_context_id  : '|| p_action_context_id ,3);
4959             pay_in_utils.set_location(g_debug,'p_assignment_id      : '|| p_assignment_id     ,3);
4960             pay_in_utils.set_location(g_debug,'p_source_id          : '|| p_source_id     ,3);
4961 
4962             OPEN  c_24qc_source_id(p_action_context_id,p_assignment_id);
4963             FETCH c_24qc_source_id INTO l_action_context_id,l_24qa_source_id;
4964              l_sal_category := 'IN_24QC_SALARY';
4965              l_via_category := 'IN_24QC_VIA';
4966              pay_in_utils.set_location(g_debug,'l_24qa_source_id in c_24qc_source_id : '|| l_24qa_source_id ,3);
4967             CLOSE c_24qc_source_id;
4968 
4969             IF (l_24qa_source_id IS NULL)
4970             THEN
4971                pay_in_utils.set_location(g_debug,'Source ID is NULL' ,4);
4972                pay_in_utils.set_location(g_debug,'Hence Searching in 24Q Archival ' ,4);
4973                OPEN  c_24qa_source_id(p_action_context_id,p_assignment_id);
4974                FETCH c_24qa_source_id INTO l_action_context_id,l_24qa_source_id;
4975                 l_sal_category := 'IN_24Q_SALARY';
4976                 l_via_category := 'IN_24Q_VIA';
4977                 pay_in_utils.trace('l_24qa_source_id in c_24qa_source_id : ', l_24qa_source_id );
4978                CLOSE c_24qa_source_id;
4979             END IF;
4980 
4981             pay_in_utils.trace('l_24qa_source_id  : ', l_24qa_source_id );
4982             pay_in_utils.trace('l_sal_category  : ', l_sal_category );
4983             pay_in_utils.trace('l_via_category  : ', l_via_category );
4984 
4985             IF (l_24qa_source_id IS NOT NULL) THEN
4986                FOR j IN 1..t_balance_name.COUNT
4987                LOOP
4988                 IF (t_balance_name(j).balance_name IN ('80CCE','Others'))
4989                 THEN
4990                        OPEN  c_get_bal_24q(l_action_context_id,l_24qa_source_id,l_via_category,t_balance_name(j).balance_name);
4991                        FETCH c_get_bal_24q INTO l_balance_value;
4992                        CLOSE c_get_bal_24q;
4993                  ELSE
4994                        OPEN  c_get_bal_24q(l_action_context_id,l_24qa_source_id,l_sal_category,t_balance_name(j).balance_name);
4995                        FETCH c_get_bal_24q INTO l_balance_value;
4996                        CLOSE c_get_bal_24q;
4997                  END IF;
4998                  p_ba_24qc_rec(j).balance_name  := t_balance_name(j).balance_name;
4999                  p_ba_24qc_rec(j).balance_value := l_balance_value;
5000                END LOOP;
5001             END IF;
5002 
5003             pay_in_utils.set_location(g_debug,'Fetched 24Q Archival Balances Data ' ,4);
5004 
5005             pay_in_utils.set_location(g_debug,'Searching person data in 24Q Correction ' ,5);
5006             OPEN  c_get_person_data_from_24qc;
5007             FETCH c_get_person_data_from_24qc INTO l_person_id,l_pan_number,l_pan_ref_number,p_person_24q_data.full_name,
5008                     p_person_24q_data.start_date,p_person_24q_data.end_date,l_source_id;
5009             pay_in_utils.set_location(g_debug,'Value of person id found in 24Q Correction: '|| l_person_id ,5);
5010             CLOSE c_get_person_data_from_24qc;
5011 
5012 
5013             IF (l_person_id IS NULL)
5014             THEN
5015                    pay_in_utils.set_location(g_debug,'Person ID is NULL' ,5);
5016                    pay_in_utils.set_location(g_debug,'Hence Searching in 24Q Archival ' ,5);
5017                    OPEN  c_get_person_data_from_24q;
5018                    FETCH c_get_person_data_from_24q INTO l_person_id,l_pan_number,l_pan_ref_number,p_person_24q_data.full_name,
5019                             p_person_24q_data.start_date,p_person_24q_data.end_date,l_source_id;
5020                    CLOSE c_get_person_data_from_24q;
5021             pay_in_utils.set_location(g_debug,'Value of person id found in 24Q Archival: '|| l_person_id ,5);
5022             END IF;
5023 
5024             p_person_24q_data.person_id      := l_person_id;
5025             p_person_24q_data.pan_number     := l_pan_number;
5026             p_person_24q_data.pan_ref_number := l_pan_ref_number;
5027 
5028             pay_in_utils.set_location(g_debug,'Fetched Person Data from 24Q Archival Data' ,5);
5029 
5030             pay_in_utils.set_location(g_debug,'Fetching Person Data from Live Data' ,6);
5031             OPEN c_get_live_person_data;
5032             FETCH c_get_live_person_data INTO p_person_live_data.person_id
5033                                              ,p_person_live_data.pan_number
5034                                              ,p_person_live_data.pan_ref_number
5035                                              ,p_person_live_data.full_name;
5036             CLOSE c_get_live_person_data;
5037 
5038             p_person_live_data.start_date   := l_effective_start_date;
5039             p_person_live_data.end_date     := l_effective_end_date;
5040 
5041             pay_in_utils.set_location(g_debug,'Fetched Person Data from Live Data' ,6);
5042 
5043             pay_in_utils.set_location(g_debug,'---------------------------------------------' ,7);
5044             pay_in_utils.set_location(g_debug,'Removing format for Live Balances Data' ,7);
5045             FOR i IN 1..p_ba_live_rec.COUNT
5046             LOOP
5047               p_ba_live_rec(i).balance_value  := FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(p_ba_live_rec(i).balance_value));
5048             END LOOP;
5049 
5050             pay_in_utils.set_location(g_debug,'---------------------------------------------' ,7);
5051 
5052             pay_in_utils.set_location(g_debug,'---------------------------------------------' ,8);
5053             pay_in_utils.set_location(g_debug,'Removing format for 24Q Archive Balances Data' ,8);
5054             FOR i IN 1..p_ba_24qc_rec.COUNT
5055             LOOP
5056               p_ba_24qc_rec(i).balance_value  := FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(p_ba_24qc_rec(i).balance_value));
5057             END LOOP;
5058             pay_in_utils.set_location(g_debug,'---------------------------------------------' ,8);
5059 
5060     pay_in_utils.set_location(g_debug,'Leaving : '|| l_procedure, 120);
5061 
5062   EXCEPTION
5063     WHEN OTHERS THEN
5064       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
5065       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
5066   END get_balance_values;
5067 
5068 
5069   --------------------------------------------------------------------------
5070   --                                                                      --
5071   -- Name           : CHECK_C5_CHANGE_ONLY                                --
5072   -- Type           : FUNCTION                                            --
5073   -- Access         : Private                                             --
5074   -- Description    :                                                     --
5075   --                                                                      --
5076   -- Parameters     :                                                     --
5077   --             IN : p_element_entry_id     NUMBER                       --
5078   --                : p_action_context_id    NUMBER                       --
5079   --                : p_assignment_id        NUMBER                       --
5080   --            OUT : p_flag                 BOOLEAN                      --
5081   --------------------------------------------------------------------------
5082   -- Rev#  Date           Userid    Description                           --
5083   --------------------------------------------------------------------------
5084   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
5085   --------------------------------------------------------------------------
5086   FUNCTION check_c5_change_only
5087     (
5088       p_element_entry_id   IN  NUMBER
5089      ,p_action_context_id  IN  NUMBER
5090      ,p_assignment_id      IN  NUMBER
5091     )
5092   RETURN BOOLEAN
5093   IS
5094      t_ee_live_rec         t_screen_entry_value_rec;
5095      t_ee_24qc_rec         t_screen_entry_value_rec;
5096      t_person_live_data    t_person_data_rec;
5097      t_person_24q_data     t_person_data_rec;
5098      l_procedure           VARCHAR2(250);
5099      l_message             VARCHAR2(250);
5100   BEGIN
5101       g_debug     := hr_utility.debug_enabled;
5102       l_procedure := g_package ||'.check_c5_change_only';
5103       pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
5104       pay_in_utils.set_location(g_debug,'Fetching Live Data',2);
5105       get_element_entry_values
5106       (
5107         p_element_entry_id
5108        ,p_action_context_id
5109        ,p_assignment_id
5110        ,t_ee_live_rec
5111        ,t_ee_24qc_rec
5112        ,t_person_live_data
5113        ,t_person_24q_data
5114       );
5115       pay_in_utils.set_location(g_debug,'Fetched Live Data',3);
5116       pay_in_utils.set_location(g_debug,'Comparing Data',4);
5117 
5118       IF(t_ee_live_rec.challan_number <> t_ee_24qc_rec.challan_number)
5119       THEN
5120            pay_in_utils.set_location(g_debug,'t_ee_live_rec.challan_number'|| t_ee_live_rec.challan_number,1);
5121            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.challan_number'|| t_ee_24qc_rec.challan_number,1);
5122            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 1',1);
5123            RETURN FALSE;
5124       END IF;
5125 
5126       IF(t_ee_live_rec.payment_date <> t_ee_24qc_rec.payment_date)
5127       THEN
5128            pay_in_utils.set_location(g_debug,'t_ee_live_rec.payment_date'|| t_ee_live_rec.payment_date,2);
5129            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.payment_date'|| t_ee_24qc_rec.payment_date,2);
5130            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 2',2);
5131            RETURN FALSE;
5132       END IF;
5133 
5134       IF(t_ee_live_rec.amount_deposited <> t_ee_24qc_rec.amount_deposited)
5135       THEN
5136            pay_in_utils.set_location(g_debug,'t_ee_live_rec.amount_deposited'|| t_ee_live_rec.amount_deposited,3);
5137            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.amount_deposited'|| t_ee_24qc_rec.amount_deposited,3);
5138            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 3',3);
5139            RETURN FALSE;
5140       END IF;
5141 
5142       IF(t_ee_live_rec.surcharge <> t_ee_24qc_rec.surcharge)
5143       THEN
5144            pay_in_utils.set_location(g_debug,'t_ee_live_rec.surcharge'|| t_ee_live_rec.surcharge,4);
5145            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.surcharge'|| t_ee_24qc_rec.surcharge,4);
5146            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 4',4);
5147            RETURN FALSE;
5148       END IF;
5149 
5150       IF(t_ee_live_rec.education_cess <> t_ee_24qc_rec.education_cess)
5151       THEN
5152            pay_in_utils.set_location(g_debug,'t_ee_live_rec.education_cess'|| t_ee_live_rec.education_cess,5);
5153            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.education_cess'|| t_ee_24qc_rec.education_cess,5);
5154            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 5',5);
5155            RETURN FALSE;
5156       END IF;
5157 
5158       IF(t_ee_live_rec.income_tax <> t_ee_24qc_rec.income_tax)
5159       THEN
5160            pay_in_utils.set_location(g_debug,'t_ee_live_rec.income_tax'|| t_ee_live_rec.income_tax,6);
5161            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.income_tax'|| t_ee_24qc_rec.income_tax,6);
5162            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 6',6);
5163            RETURN FALSE;
5164       END IF;
5165 
5166       IF(t_ee_live_rec.taxable_income <> t_ee_24qc_rec.taxable_income)
5167       THEN
5168            pay_in_utils.set_location(g_debug,'t_ee_live_rec.taxable_income'|| t_ee_live_rec.taxable_income,7);
5169            pay_in_utils.set_location(g_debug,'t_ee_24qc_rec.taxable_income'|| t_ee_24qc_rec.taxable_income,7);
5170            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 7',7);
5171            RETURN FALSE;
5172       END IF;
5173 
5174       IF(t_person_live_data.full_name <> t_person_24q_data.full_name)
5175       THEN
5176            pay_in_utils.set_location(g_debug,'t_person_live_data.full_name'|| t_person_live_data.full_name,8);
5177            pay_in_utils.set_location(g_debug,'t_person_24q_data.full_name'|| t_person_24q_data.full_name,8);
5178            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 8',8);
5179            RETURN FALSE;
5180       END IF;
5181 
5182       IF(NVL(t_person_live_data.tax_rate,'NA') <> NVL(t_person_24q_data.tax_rate,'NA'))
5183       THEN
5184            pay_in_utils.set_location(g_debug,'t_person_live_data.tax_rate'|| t_person_live_data.tax_rate,9);
5185            pay_in_utils.set_location(g_debug,'t_person_24q_data.tax_rate'|| t_person_24q_data.tax_rate,9);
5186            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 9',9);
5187            RETURN FALSE;
5188       END IF;
5189 
5190       IF(NVL(t_person_live_data.pan_ref_number,'NA') <> NVL(t_person_24q_data.pan_ref_number,'NA'))
5191       THEN
5192            pay_in_utils.set_location(g_debug,'t_person_live_data.pan_ref_number'|| t_person_live_data.pan_ref_number,10);
5193            pay_in_utils.set_location(g_debug,'t_person_24q_data.pan_ref_number'|| t_person_24q_data.pan_ref_number,10);
5194            pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only Diff 10',10);
5195            RETURN FALSE;
5196       END IF;
5197 
5198       pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.check_c5_change_only No Diff',11);
5199       RETURN TRUE;
5200   EXCEPTION
5201     WHEN OTHERS THEN
5202       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
5203       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
5204   END check_c5_change_only;
5205 
5206 
5207   --------------------------------------------------------------------------
5208   --                                                                      --
5209   -- Name           : ARCHIVE_SALARY_DATA                                 --
5210   -- Type           : PROCEDURE                                           --
5211   -- Access         : Private                                             --
5212   -- Description    : Procedure to archive the salary data.               --
5213   -- Parameters     :                                                     --
5214   --             IN :                                                     --
5215   --                                                                      --
5216   --            OUT : N/A                                                 --
5217   --                                                                      --
5218   -- Change History :                                                     --
5219   --------------------------------------------------------------------------
5220   -- Rev#  Date           Userid    Description                           --
5221   --------------------------------------------------------------------------
5222   -- 115.0 07-Feb-2007    rpalli    5754018 : 24QC Quarter4 Stat Update   --
5223   --------------------------------------------------------------------------
5224   PROCEDURE archive_salary_data(p_payroll_action_id   NUMBER
5225                                ,p_24qa_pay_act_id     NUMBER
5226                                )
5227   IS
5228 
5229   CURSOR c_salary_number_24q(p_person_id      VARCHAR2
5230                             ,p_source_id      NUMBER
5231                              )
5232   IS
5233         SELECT MAX(FND_NUMBER.CANONICAL_TO_NUMBER(action_information11))
5234           FROM pay_action_information pai
5235               ,pay_assignment_actions paa
5236          WHERE pai.action_information_category = 'IN_24Q_PERSON'
5237            AND pai.action_information3         = g_gre_id
5238            AND pai.action_information2         = g_year||g_quarter
5239            AND pai.action_information1         = p_person_id
5240            AND pai.source_id                   = p_source_id
5241            AND pai.action_context_id           = paa.assignment_action_id
5242            AND paa.payroll_action_id           = p_24qa_pay_act_id
5243            AND paa.payroll_action_id IN(
5244                                         SELECT org_information3
5245                                           FROM hr_organization_information
5246                                          WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
5247                                            AND organization_id         = g_gre_id
5248                                            AND org_information1        = g_year
5249                                            AND org_information2        = g_quarter
5250                                            AND org_information5        = 'A'
5251                                            AND org_information6        = 'O'
5252                                        );
5253 
5254   CURSOR c_salary_number_24qc(p_person_id      VARCHAR2
5255                              ,p_source_id      NUMBER
5256                               )
5257       IS
5258        SELECT MAX(FND_NUMBER.CANONICAL_TO_NUMBER(action_information12))
5259           FROM pay_action_information pai
5260               ,pay_assignment_actions paa
5261               ,pay_action_interlocks  locks
5262               ,pay_assignment_actions paa_master
5263          WHERE pai.action_information_category = 'IN_24QC_PERSON'
5264            AND pai.action_information3         = g_gre_id
5265            AND pai.action_information2         = g_year||g_quarter
5266            AND pai.action_information1         = p_person_id
5267            AND pai.source_id                   = p_source_id
5268            AND locks.locking_action_id         = pai.action_context_id
5269            AND locks.locked_action_id          = paa.assignment_action_id
5270            AND paa.payroll_action_id           = p_24qa_pay_act_id
5271            AND paa_master.assignment_action_id = pai.action_context_id
5272            AND paa_master.payroll_action_id IN(
5273                                                   SELECT org_information3
5274                                                     FROM hr_organization_information
5275                                                    WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
5276                                                      AND organization_id         = g_gre_id
5277                                                      AND org_information1        = g_year
5278                                                      AND org_information2        = g_quarter
5279                                                      AND org_information5        = 'A'
5280                                                      AND org_information6        = 'C'
5281                                                  );
5282 
5283   CURSOR c_max_salary_number_24q
5284   IS
5285         SELECT MAX(FND_NUMBER.CANONICAL_TO_NUMBER(action_information11))
5286           FROM pay_action_information pai
5287               ,pay_assignment_actions paa
5288          WHERE pai.action_information_category = 'IN_24Q_PERSON'
5289            AND pai.action_information3         = g_gre_id
5290            AND pai.action_information2         = g_year||g_quarter
5291            AND pai.action_context_id           = paa.assignment_action_id
5292            AND paa.payroll_action_id           = p_24qa_pay_act_id
5293            AND paa.payroll_action_id IN(
5294                                         SELECT org_information3
5295                                           FROM hr_organization_information
5296                                          WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
5297                                            AND organization_id         = g_gre_id
5298                                            AND org_information1        = g_year
5299                                            AND org_information2        = g_quarter
5300                                            AND org_information5        = 'A'
5301                                            AND org_information6        = 'O'
5302                                        );
5303 
5304 
5305   CURSOR c_max_salary_number_24qc
5306       IS
5307        SELECT MAX(FND_NUMBER.CANONICAL_TO_NUMBER(action_information12))
5308           FROM pay_action_information pai
5309               ,pay_assignment_actions paa
5310               ,pay_action_interlocks  locks
5311               ,pay_assignment_actions paa_master
5312          WHERE pai.action_information_category = 'IN_24QC_PERSON'
5313            AND pai.action_information3         = g_gre_id
5314            AND pai.action_information2         = g_year||g_quarter
5315            AND locks.locking_action_id         = pai.action_context_id
5316            AND locks.locked_action_id          = paa.assignment_action_id
5317            AND paa.payroll_action_id           = p_24qa_pay_act_id
5318            AND paa_master.assignment_action_id = pai.action_context_id
5319            AND paa_master.payroll_action_id IN(
5320                                                   SELECT org_information3
5321                                                     FROM hr_organization_information
5322                                                    WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
5323                                                      AND organization_id         = g_gre_id
5324                                                      AND org_information1        = g_year
5325                                                      AND org_information2        = g_quarter
5326                                                      AND org_information5        = 'A'
5327                                                      AND org_information6        = 'C'
5328                                                  );
5329 
5330 
5331   CURSOR c_asg_act_id(p_payroll_action_id     NUMBER,
5332                       p_assignment_id         NUMBER
5333                      )
5334   IS
5335      SELECT assignment_action_id
5336        FROM pay_assignment_actions
5337       WHERE payroll_action_id = p_payroll_action_id
5338         AND assignment_id     = p_assignment_id;
5339 
5340   CURSOR c_max_pact(p_assignment_id NUMBER)
5341   IS
5342       SELECT
5343               FND_NUMBER.CANONICAL_TO_NUMBER(SUBSTR(MAX(LPAD(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) source_id
5344               ,paf.assignment_id       assignment_id
5345              FROM pay_assignment_actions paa
5346                  ,pay_payroll_actions ppa
5347                  ,per_assignments_f paf
5348              WHERE paf.assignment_id = paa.assignment_id
5349              AND paf.assignment_id =p_assignment_id
5350              AND paa.tax_unit_id  = g_gre_id
5351              AND paa.payroll_action_id = ppa.payroll_action_id
5352              AND ppa.action_type IN('R','Q','I','B')
5353              AND ppa.payroll_id    = paf.payroll_id
5354              AND ppa.action_status ='C'
5355              AND ppa.effective_date between g_start_date and g_end_date
5356              AND paa.source_action_id IS NULL
5357              AND (1 = DECODE(ppa.action_type,'I',1,0)
5358               OR EXISTS (SELECT ''
5359                         FROM pay_action_interlocks intk,
5360                              pay_assignment_actions paa1,
5361                              pay_payroll_actions ppa1
5362                         WHERE intk.locked_action_id = paa.assignment_Action_id
5363                         AND intk.locking_action_id =  paa1.assignment_action_id
5364                         AND paa1.payroll_action_id =ppa1.payroll_action_id
5365                         AND ppa1.action_type in('P','U')
5366                         AND ppa.action_type in('R','Q','B')
5367                         AND ppa1.action_status ='C'
5368                         AND ppa1.effective_date between g_start_date and g_end_date
5369                         AND ROWNUM =1 ))
5370                 GROUP BY paf.assignment_id;
5371 
5372   CURSOR c_prev_max_pact(p_assignment_id NUMBER, p_max_asact_id NUMBER)
5373   IS
5374       SELECT
5375               FND_NUMBER.CANONICAL_TO_NUMBER(SUBSTR(MAX(LPAD(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) source_id
5376               ,paf.assignment_id       assignment_id
5377              FROM pay_assignment_actions paa
5378                  ,pay_payroll_actions ppa
5379                  ,per_assignments_f paf
5380              WHERE paf.assignment_id = paa.assignment_id
5381              AND paf.assignment_id =p_assignment_id
5382              AND paa.tax_unit_id  = g_gre_id
5383              AND paa.payroll_action_id = ppa.payroll_action_id
5384              AND paa.assignment_action_id < p_max_asact_id
5385              AND ppa.action_type IN('R','Q','I','B')
5386              AND ppa.payroll_id    = paf.payroll_id
5387              AND ppa.action_status ='C'
5388              AND ppa.effective_date between g_start_date and g_end_date
5389              AND paa.source_action_id IS NULL
5390              AND (1 = DECODE(ppa.action_type,'I',1,0)
5391               OR EXISTS (SELECT ''
5392                         FROM pay_action_interlocks intk,
5393                              pay_assignment_actions paa1,
5394                              pay_payroll_actions ppa1
5395                         WHERE intk.locked_action_id = paa.assignment_Action_id
5396                         AND intk.locking_action_id =  paa1.assignment_action_id
5397                         AND paa1.payroll_action_id =ppa1.payroll_action_id
5398                         AND ppa1.action_type in('P','U')
5399                         AND ppa.action_type in('R','Q','B')
5400                         AND ppa1.action_status ='C'
5401                         AND ppa1.effective_date between g_start_date and g_end_date
5402                         AND ROWNUM =1 ))
5403                 GROUP BY paf.assignment_id;
5404 
5405   CURSOR c_24qc_source_id(p_action_context_id     NUMBER,
5406                           p_assignment_id         NUMBER
5407                          )
5408       IS
5409         SELECT DISTINCT pai.source_id,pai.action_context_id
5410           FROM pay_action_information pai
5411               ,pay_assignment_actions paa
5412               ,pay_action_interlocks  locks
5413               ,pay_assignment_actions paa_master
5414          WHERE pai.action_information_category = 'IN_24QC_PERSON'
5415            AND pai.assignment_id               = p_assignment_id
5416            AND pai.action_information3         = g_gre_id
5417            AND pai.action_information2         = g_year||g_quarter
5418            AND pai.action_information10        = 'A'
5419            AND locks.locking_action_id         = pai.action_context_id
5420            AND locks.locked_action_id          = paa.assignment_action_id
5421            AND paa.payroll_action_id           = p_24qa_pay_act_id
5422            AND paa_master.assignment_action_id = pai.action_context_id
5423            AND paa_master.payroll_action_id IN(
5424                                                   SELECT org_information3
5425                                                     FROM hr_organization_information
5426                                                    WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
5427                                                      AND organization_id         = g_gre_id
5428                                                      AND org_information1        = g_year
5429                                                      AND org_information2        = g_quarter
5430                                                      AND org_information5        = 'A'
5431                                                      AND org_information6        = 'C'
5432                                                  )
5433                                                  ORDER BY pai.source_id DESC;
5434 
5435   CURSOR c_24qa_source_id(p_action_context_id     NUMBER,
5436                           p_assignment_id         NUMBER
5437                          )
5438   IS
5439        SELECT DISTINCT pai.source_id,pai.action_context_id
5440           FROM pay_action_information pai
5441          WHERE pai.action_information_category IN('IN_24Q_PERSON')
5442            AND pai.action_information3         = g_gre_id
5443            AND pai.assignment_id               = p_assignment_id
5444            AND pai.action_context_id           = p_action_context_id
5445            ORDER BY pai.source_id DESC;
5446 
5447   CURSOR c_get_bal_24q(p_action_context_id NUMBER, p_24q_source_id NUMBER, p_category VARCHAR2, p_balance_name VARCHAR2)
5448   IS
5449        SELECT DISTINCT
5450        FND_NUMBER.CANONICAL_TO_NUMBER(remove_curr_format(get_24Q_values(p_category,p_balance_name,pai.action_context_id,pai.source_id,1)))
5451          FROM pay_action_information pai
5452         WHERE pai.action_context_id           = p_action_context_id
5453           AND pai.action_information_category = p_category
5454           AND pai.source_id                   = p_24q_source_id;
5455 
5456     tab_24q_ba_data  t_balance_value_tab;
5457     tab_liv_ba_data  t_balance_value_tab;
5458 
5459     tab_24q_pe_data  t_person_data_sal_rec;
5460     tab_liv_pe_data  t_person_data_sal_rec;
5461 
5462     l_action_information_category pay_action_information.action_information_category%TYPE;
5463     l_arch_asg_action_id          NUMBER;
5464     l_24qa_asg_action_id          NUMBER;
5465     l_24qa_source_id              NUMBER;
5466     l_prev_asg_action_id          NUMBER;
5467     l_prev_category               VARCHAR2(250);
5468 
5469     l_action_info_id              NUMBER;
5470     l_ovn                         NUMBER;
5471     j                             NUMBER;
5472     k                             NUMBER;
5473     l                             NUMBER;
5474     s                             NUMBER;
5475     l_dummy                       NUMBER  := -1;
5476     l_flag                        NUMBER  := -1;
5477     l_flag1                       NUMBER  := -1;
5478     l_flag2                       NUMBER  := -1;
5479 
5480     l_procedure                   VARCHAR2(250);
5481     l_message                     VARCHAR2(250);
5482     l_balance_value       NUMBER;
5483 
5484     l_c5_change_only              BOOLEAN;
5485     l_prev_c5                     BOOLEAN;
5486     l_c5_tot_income_flag          BOOLEAN;
5487 
5488     l_max_pact                NUMBER;
5489     l_prev_max_pact           NUMBER;
5490     l_count_delete            NUMBER;
5491     l_gre_count              NUMBER;
5492     l_assignment_id           NUMBER;
5493     l_future_pay              BOOLEAN;
5494     l_prev_pay                BOOLEAN;
5495 
5496   BEGIN
5497 
5498       g_debug     := hr_utility.debug_enabled;
5499       l_procedure := g_package ||'.archive_salary_data';
5500       pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
5501       pay_in_utils.set_location(g_debug,'Fetching Salary Data ', 1);
5502 
5503       s := 1;
5504       l_24qa_source_id := NULL;
5505       l_24qa_asg_action_id := NULL;
5506       IF (g_correction_mode IN('C4','C5','%'))
5507       THEN
5508              pay_in_utils.set_location(g_debug,'Value of g_count_sal_delete : '|| g_count_sal_delete, 1);
5509              FOR i IN 1..g_count_sal_delete - 1
5510              LOOP
5511 
5512                 pay_in_utils.set_location(g_debug,'Checking archived presence of this deleted assignment action',1);
5513                 l_flag := -1;
5514                 l_flag1 := -1;
5515                 l_flag2 := -1;
5516                 l_gre_count := 0;
5517 
5518                 l_flag  := check_archival_status(g_sal_data_rec_del(i).source_id,'IN_24QC_PERSON',NULL,'D');
5519                 l_flag1 := check_archival_status(g_sal_data_rec_del(i).source_id,'IN_24QC_PERSON',NULL,'NA');
5520 
5521                 pay_in_utils.trace('l_flag in g_count_sal_delete ',l_flag);
5522                 pay_in_utils.trace('l_flag1 in g_count_sal_delete ',l_flag1);
5523 
5524                 IF ((l_flag = 0) AND (l_flag1 = 0))
5525                 THEN
5526                       pay_in_utils.set_location(g_debug,'Deleted Salary Detail Record Not Archived. Hence doing '||g_sal_data_rec_del(i).source_id,1);
5527 
5528                        get_balance_values
5529                         (
5530                           g_sal_data_rec_del(i).source_id
5531                          ,g_sal_data_rec_del(i).last_action_context_id
5532                          ,g_sal_data_rec_del(i).assignment_id
5533                          ,p_24qa_pay_act_id
5534                          ,'D'
5535                          ,tab_liv_ba_data
5536                          ,tab_24q_ba_data
5537                          ,tab_liv_pe_data
5538                          ,tab_24q_pe_data
5539                          ,l_gre_count
5540                         );
5541 
5542                 --      if g_correction_mode = 'C5' and tab_24q_pe_data.pan_number IS VALID and
5543                 --       tab_liv_pe_data.pan_number is also valid and not equal 2 each other
5544                 --       then not only arhcive this assignment data, but also last organization PA data
5545 
5546                          pay_in_utils.trace('Delete Source ID            : ', g_sal_data_rec_del(i).source_id );
5547                          pay_in_utils.trace('tab_liv_pe_data.pan_number  : ', tab_liv_pe_data.pan_number );
5548                          pay_in_utils.trace('tab_24q_pe_data.pan_number  : ', tab_24q_pe_data.pan_number );
5549 
5550                          IF ((g_correction_mode IN('C4','C5','%'))
5551                               AND(tab_24q_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
5552                               AND(tab_liv_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
5553                               AND(tab_24q_pe_data.pan_number <> tab_liv_pe_data.pan_number)
5554                             )
5555                          THEN
5556                                  l_action_information_category := 'C4:C5';
5557                          ELSE
5558                                  l_action_information_category := 'C4';
5559                          END IF;
5560 
5561                          OPEN  c_asg_act_id(p_payroll_action_id,g_sal_data_rec_del(i).assignment_id);
5562                          FETCH c_asg_act_id INTO l_arch_asg_action_id;
5563                          CLOSE c_asg_act_id;
5564 
5565                          OPEN c_asg_act_id(p_24qa_pay_act_id,g_sal_data_rec_del(i).assignment_id);
5566                          FETCH c_asg_act_id INTO l_24qa_asg_action_id;
5567                          CLOSE c_asg_act_id;
5568 
5569                          OPEN  c_salary_number_24qc(tab_liv_pe_data.person_id,g_sal_data_rec_del(i).source_id);
5570                          FETCH c_salary_number_24qc INTO k;
5571                          CLOSE c_salary_number_24qc;
5572 
5573                          OPEN  c_salary_number_24q(tab_liv_pe_data.person_id,g_sal_data_rec_del(i).source_id);
5574                          FETCH c_salary_number_24q INTO j;
5575                          CLOSE c_salary_number_24q;
5576 
5577                           pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
5578                           pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
5579 
5580                        l_c5_change_only := TRUE;
5581                        pay_in_utils.trace('Count of live balances  : ', tab_liv_ba_data.COUNT );
5582                        pay_in_utils.trace('Count of 24q balances   : ', tab_24q_ba_data.COUNT );
5583 
5584                         FOR j IN 1..tab_liv_ba_data.COUNT
5585                         LOOP
5586                          FOR k IN 1..tab_24q_ba_data.COUNT
5587                          LOOP
5588                            IF (tab_liv_ba_data(j).balance_name = tab_24q_ba_data(k).balance_name)
5589                            THEN
5590 
5591                                IF ((tab_liv_ba_data(j).balance_value <> 0) AND
5592                                    (tab_liv_ba_data(j).balance_value <> tab_24q_ba_data(k).balance_value) AND
5593                                    (tab_liv_ba_data(j).balance_name NOT IN ('F16 Deductions Sec 80CCE'))
5594                                   )
5595                                THEN
5596                                    l_c5_change_only := FALSE;
5597                                END IF;
5598 
5599                            END IF;
5600                           END LOOP;
5601                         END LOOP;
5602 
5603                         IF (tab_liv_ba_data.COUNT = 0)
5604                         THEN
5605                            l_c5_change_only := FALSE;
5606                            tab_liv_pe_data.start_date := tab_24q_pe_data.start_date;
5607                            tab_liv_pe_data.end_date   := tab_24q_pe_data.end_date;
5608                         END IF;
5609 
5610 
5611                        IF (INSTR(l_action_information_category,'C4')<> 0) AND (g_correction_mode IN ('%','C4'))
5612                            AND ((l_c5_change_only = FALSE)) AND (g_quarter IN ('Q4') AND (l_flag = 0))
5613                        THEN
5614 
5615                                 pay_action_information_api.create_action_information
5616                                              (p_action_context_id              =>     l_arch_asg_action_id
5617                                              ,p_action_context_type            =>     'AAP'
5618                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
5619                                              ,p_source_id                      =>     g_sal_data_rec_del(i).source_id
5620                                              ,p_assignment_id                  =>     g_sal_data_rec_del(i).assignment_id
5621                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
5622                                              ,p_action_information2            =>     g_year||g_quarter
5623                                              ,p_action_information3            =>     g_gre_id
5624                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
5625                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
5626                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
5627                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
5628                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
5629                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
5630                                              ,p_action_information10           =>     'D'
5631                                              ,p_action_information11           =>     'C4'
5632                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0))
5633                                              ,p_action_information_id          =>     l_action_info_id
5634                                              ,p_object_version_number          =>     l_ovn
5635                                              );
5636 
5637 
5638                                          FOR l IN 1..tab_24q_ba_data.COUNT
5639                                          LOOP
5640 
5641                                             IF ((tab_24q_ba_data(l).balance_name IN ('F16 Gross Total Income')) AND
5642                                                 (tab_24q_ba_data(l).balance_value <> 0)
5643                                                )
5644                                              THEN
5645 
5646                                               pay_action_information_api.create_action_information
5647                                                             (p_action_context_id              =>     l_arch_asg_action_id
5648                                                             ,p_action_context_type            =>     'AAP'
5649                                                             ,p_action_information_category    =>     'IN_24QC_SALARY'
5650                                                             ,p_source_id                      =>     g_sal_data_rec_del(i).source_id
5651                                                             ,p_action_information1            =>     'Prev F16 Gross Total Income'
5652                                                             ,p_action_information2            =>     tab_24q_ba_data(l).balance_value
5653                                                             ,p_action_information_id          =>     l_action_info_id
5654                                                             ,p_object_version_number          =>     l_ovn
5655                                                             );
5656                                                END IF;
5657                                          END LOOP;
5658 
5659                               OPEN c_asg_act_id(p_24qa_pay_act_id,g_sal_data_rec_del(i).assignment_id);
5660                               FETCH c_asg_act_id INTO l_24qa_asg_action_id;
5661                               CLOSE c_asg_act_id;
5662 
5663 
5664                               OPEN  c_24qa_source_id(l_24qa_asg_action_id,g_sal_data_rec_del(i).assignment_id);
5665                               FETCH c_24qa_source_id INTO l_24qa_source_id,l_24qa_asg_action_id;
5666                               CLOSE c_24qa_source_id;
5667 
5668                               OPEN  c_get_bal_24q(l_24qa_asg_action_id,l_24qa_source_id,'IN_24Q_SALARY','F16 Gross Total Income');
5669                               FETCH c_get_bal_24q INTO l_balance_value;
5670                               CLOSE c_get_bal_24q;
5671 
5672                               IF ((l_24qa_source_id IS NOT NULL) AND (l_balance_value <> 0)) THEN
5673                                 pay_action_information_api.create_action_information
5674                                               (p_action_context_id              =>     l_arch_asg_action_id
5675                                               ,p_action_context_type            =>     'AAP'
5676                                               ,p_action_information_category    =>     'IN_24QC_SALARY'
5677                                               ,p_source_id                      =>     g_sal_data_rec_del(i).source_id
5678                                               ,p_action_information1            =>     'Form24Q F16 Gross Total Income'
5679                                               ,p_action_information2            =>     l_balance_value
5680                                               ,p_action_information_id          =>     l_action_info_id
5681                                               ,p_object_version_number          =>     l_ovn
5682                                               );
5683                               END IF;
5684 
5685                        END IF;
5686                  END IF;
5687 
5688                         l_prev_pay := FALSE;
5689                         IF (l_c5_change_only=FALSE)
5690                         THEN
5691                               OPEN  c_max_pact(g_sal_data_rec_del(i).assignment_id);
5692                               FETCH c_max_pact INTO l_max_pact,l_assignment_id;
5693                               CLOSE c_max_pact;
5694                             IF (g_sal_data_rec_del(i).source_id < l_max_pact) AND (l_max_pact IS NOT NULL)
5695                             THEN
5696                               l_prev_pay := TRUE;
5697                             END IF;
5698                         END IF;
5699 
5700                        OPEN  c_max_salary_number_24qc;
5701                         FETCH c_max_salary_number_24qc INTO k;
5702                        CLOSE c_max_salary_number_24qc;
5703 
5704                        OPEN  c_max_salary_number_24q;
5705                         FETCH c_max_salary_number_24q INTO j;
5706                        CLOSE c_max_salary_number_24q;
5707 
5708                        pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
5709                        pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
5710 
5711                        l_flag2 := check_archival_status(l_max_pact,'IN_24QC_PERSON',NULL,'A');
5712 
5713                        IF (INSTR(l_action_information_category,'C4')<> 0) AND (g_correction_mode IN ('%','C4'))
5714                             AND ((l_c5_change_only=FALSE)) AND (l_prev_pay) AND (g_quarter IN ('Q4') AND (l_flag2=0))
5715                        THEN
5716 
5717                         pay_in_utils.trace('Delete Source ID :   ', g_sal_data_rec_del(i).source_id );
5718                         pay_in_utils.trace('l_max_pact       :   ', l_max_pact );
5719 
5720                                 pay_action_information_api.create_action_information
5721                                              (p_action_context_id              =>     l_arch_asg_action_id
5722                                              ,p_action_context_type            =>     'AAP'
5723                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
5724                                              ,p_source_id                      =>     l_max_pact
5725                                              ,p_assignment_id                  =>     g_sal_data_rec_del(i).assignment_id
5726                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
5727                                              ,p_action_information2            =>     g_year||g_quarter
5728                                              ,p_action_information3            =>     g_gre_id
5729                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
5730                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
5731                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
5732                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
5733                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
5734                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
5735                                              ,p_action_information10           =>     'A'
5736                                              ,p_action_information11           =>     'C4'
5737                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0)) + s
5738                                              ,p_action_information_id          =>     l_action_info_id
5739                                              ,p_object_version_number          =>     l_ovn
5740                                              );
5741 
5742                            FOR l IN 1..tab_liv_ba_data.COUNT
5743                            LOOP
5744 
5745                                IF ((tab_liv_ba_data(l).balance_value <> 0) AND
5746                                    (tab_liv_ba_data(l).balance_name IN ('80CCE','Others'))
5747                                   )
5748                                THEN
5749                                           pay_action_information_api.create_action_information
5750                                                         (p_action_context_id              =>     l_arch_asg_action_id
5751                                                         ,p_action_context_type            =>     'AAP'
5752                                                         ,p_action_information_category    =>     'IN_24QC_VIA'
5753                                                         ,p_source_id                      =>     l_max_pact
5754                                                         ,p_action_information1            =>     tab_liv_ba_data(l).balance_name
5755                                                         ,p_action_information2            =>     tab_liv_ba_data(l).balance_value
5756                                                         ,p_action_information3            =>     0
5757                                                         ,p_action_information_id          =>     l_action_info_id
5758                                                         ,p_object_version_number          =>     l_ovn
5759                                                         );
5760                                 ELSIF ((tab_liv_ba_data(l).balance_value <> 0) AND
5761                                        (tab_liv_ba_data(l).balance_name NOT IN ('F16 Deductions Sec 80CCE'))
5762                                       )
5763                                 THEN
5764                                           pay_action_information_api.create_action_information
5765                                                         (p_action_context_id              =>     l_arch_asg_action_id
5766                                                         ,p_action_context_type            =>     'AAP'
5767                                                         ,p_action_information_category    =>     'IN_24QC_SALARY'
5768                                                         ,p_source_id                      =>     l_max_pact
5769                                                         ,p_action_information1            =>     tab_liv_ba_data(l).balance_name
5770                                                         ,p_action_information2            =>     tab_liv_ba_data(l).balance_value
5771                                                         ,p_action_information_id          =>     l_action_info_id
5772                                                         ,p_object_version_number          =>     l_ovn
5773                                                         );
5774                                 END IF;
5775                           END LOOP;
5776                        s := s + 1;
5777                        END IF;
5778 
5779                           OPEN  c_salary_number_24qc(tab_liv_pe_data.person_id,g_sal_data_rec_del(i).source_id);
5780                           FETCH c_salary_number_24qc INTO k;
5781                           CLOSE c_salary_number_24qc;
5782 
5783                           OPEN  c_salary_number_24q(tab_liv_pe_data.person_id,g_sal_data_rec_del(i).source_id);
5784                           FETCH c_salary_number_24q INTO j;
5785                           CLOSE c_salary_number_24q;
5786 
5787                           pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
5788                           pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
5789 
5790 
5791                           IF (INSTR(l_action_information_category,'C5')<> 0) AND (g_correction_mode IN ('%','C5') AND (l_prev_pay) AND (l_flag1=0))
5792                           THEN
5793 
5794                                 pay_action_information_api.create_action_information
5795                                              (p_action_context_id              =>     l_arch_asg_action_id
5796                                              ,p_action_context_type            =>     'AAP'
5797                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
5798                                              ,p_source_id                      =>     l_max_pact
5799                                              ,p_assignment_id                  =>     g_sal_data_rec_del(i).assignment_id
5800                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
5801                                              ,p_action_information2            =>     g_year||g_quarter
5802                                              ,p_action_information3            =>     g_gre_id
5803                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
5804                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
5805                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
5806                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
5807                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
5808                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
5809                                              ,p_action_information10           =>     'NA'
5810                                              ,p_action_information11           =>     'C5'
5811                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0))
5812                                              ,p_action_information_id          =>     l_action_info_id
5813                                              ,p_object_version_number          =>     l_ovn
5814                                              );
5815 
5816                                  FOR l IN 1..tab_24q_ba_data.COUNT
5817                                  LOOP
5818 
5819                                     IF ((tab_24q_ba_data(l).balance_name IN ('F16 Gross Total Income')) AND
5820                                         (tab_24q_ba_data(l).balance_value <> 0)
5821                                        )
5822                                     THEN
5823 
5824                                      pay_action_information_api.create_action_information
5825                                                    (p_action_context_id              =>     l_arch_asg_action_id
5826                                                    ,p_action_context_type            =>     'AAP'
5827                                                    ,p_action_information_category    =>     'IN_24QC_SALARY'
5828                                                    ,p_source_id                      =>     l_max_pact
5829                                                    ,p_action_information1            =>     'Prev F16 Gross Total Income'
5830                                                    ,p_action_information2            =>     tab_24q_ba_data(l).balance_value
5831                                                    ,p_action_information_id          =>     l_action_info_id
5832                                                    ,p_object_version_number          =>     l_ovn
5833                                                    );
5834                                       END IF;
5835                                  END LOOP;
5836 
5837                         END IF;
5838 
5839              END LOOP;
5840          END IF;
5841 
5842 
5843       IF (s = 1) THEN
5844         s := 1;
5845       END IF;
5846       l_24qa_source_id := NULL;
5847       l_24qa_asg_action_id := NULL;
5848       l_prev_asg_action_id := NULL;
5849       l_prev_category := NULL;
5850       IF (g_correction_mode IN('C4','C5','%'))
5851       THEN
5852              pay_in_utils.set_location(g_debug,'Value of g_count_sal_addition : '|| g_count_sal_addition, 1);
5853              FOR i IN 1..g_count_sal_addition - 1
5854              LOOP
5855 
5856                 OPEN c_asg_act_id(p_24qa_pay_act_id,g_sal_data_rec_add(i).assignment_id);
5857                 FETCH c_asg_act_id INTO l_24qa_asg_action_id;
5858                 CLOSE c_asg_act_id;
5859 
5860                 OPEN  c_24qc_source_id(l_24qa_asg_action_id,g_sal_data_rec_add(i).assignment_id);
5861                 FETCH c_24qc_source_id INTO l_24qa_source_id,l_24qa_asg_action_id;
5862                  pay_in_utils.set_location(g_debug,'Found source id in 24Q Correction: '|| l_24qa_source_id ,2);
5863                 CLOSE c_24qc_source_id;
5864 
5865                 IF (l_24qa_source_id IS NOT NULL)
5866                 THEN
5867                  l_prev_asg_action_id := l_24qa_asg_action_id;
5868                  l_prev_category := 'IN_24QC_SALARY';
5869                 END IF;
5870 
5871                 IF (l_24qa_source_id IS NULL)
5872                 THEN
5873                    pay_in_utils.set_location(g_debug,'Source ID is NULL' ,2);
5874                    pay_in_utils.set_location(g_debug,'Hence Searching in 24Q Archival ' ,2);
5875                    OPEN  c_24qa_source_id(l_24qa_asg_action_id,g_sal_data_rec_add(i).assignment_id);
5876                    FETCH c_24qa_source_id INTO l_24qa_source_id,l_24qa_asg_action_id;
5877                    CLOSE c_24qa_source_id;
5878                 l_prev_asg_action_id := l_24qa_asg_action_id;
5879                 l_prev_category := 'IN_24Q_SALARY';
5880                 END IF;
5881 
5882                 pay_in_utils.trace('l_24qa_source_id in g_count_sal_addition ',l_24qa_source_id);
5883 
5884                 pay_in_utils.set_location(g_debug,'Checking archived presence of this added assignment action',1);
5885                 l_flag := -1;
5886                 l_flag1 := -1;
5887                 l_flag2 := -1;
5888                 l_gre_count := 0;
5889                 l_prev_c5 := TRUE;
5890 
5891                 pay_in_utils.trace('l_24qa_source_id in g_count_sal_addition ',l_24qa_source_id);
5892 
5893                 l_flag := check_archival_status(g_sal_data_rec_add(i).source_id,'IN_24QC_PERSON',NULL,'A');
5894                 l_flag1 := check_archival_status(g_sal_data_rec_add(i).source_id,'IN_24QC_PERSON',NULL,'NA');
5895 
5896                 pay_in_utils.trace('l_flag in g_count_sal_addition  :',l_flag);
5897                 pay_in_utils.trace('l_flag1 in g_count_sal_addition :',l_flag1);
5898 
5899                 IF ((l_flag = 0) AND (l_flag1 = 0))
5900                 THEN
5901                      pay_in_utils.set_location(g_debug,'Added Salary Detail Not Archived. Hence doing.. '||g_sal_data_rec_add(i).source_id,1);
5902 
5903                     pay_in_utils.set_location(g_debug,'Fetching balance data  ', 1);
5904                     pay_in_utils.set_location(g_debug,'For Assignment Action ID :  '|| g_sal_data_rec_add(i).source_id,1);
5905                     pay_in_utils.set_location(g_debug,'Calling....get_balance_values ',1);
5906                     pay_in_utils.set_location(g_debug,'Assignment Action id is ' || g_sal_data_rec_add(i).last_action_context_id ,2);
5907                     pay_in_utils.set_location(g_debug,'Assignment id is ' || g_sal_data_rec_add(i).assignment_id,3);
5908 
5909 
5910                      IF (l_24qa_asg_action_id IS NULL) THEN
5911                            l_24qa_asg_action_id := g_sal_data_rec_add(i).source_id;
5912                      END IF;
5913 
5914                        get_balance_values
5915                         (
5916                           g_sal_data_rec_add(i).source_id
5917                          ,l_24qa_asg_action_id
5918                          ,g_sal_data_rec_add(i).assignment_id
5919                          ,p_24qa_pay_act_id
5920                          ,'A'
5921                          ,tab_liv_ba_data
5922                          ,tab_24q_ba_data
5923                          ,tab_liv_pe_data
5924                          ,tab_24q_pe_data
5925                          ,l_gre_count
5926                         );
5927 
5928                       pay_in_utils.set_location(g_debug,'Called....get_balance_values ',1);
5929                       pay_in_utils.set_location(g_debug,'Fetched balance data  ', 1);
5930 
5931                       pay_in_utils.trace('tab_liv_pe_data.pan_number  : ', tab_liv_pe_data.pan_number );
5932                       pay_in_utils.trace('tab_24q_pe_data.pan_number  : ', tab_24q_pe_data.pan_number );
5933 
5934 
5935                       IF ((g_correction_mode IN('C4','C5','%'))
5936                             AND(tab_24q_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
5937                             AND(tab_liv_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
5938                             AND(tab_24q_pe_data.pan_number <> tab_liv_pe_data.pan_number)
5939                           )
5940                       THEN
5941                                l_action_information_category := 'C4:C5';
5942                       ELSE
5943                                l_action_information_category := 'C4';
5944                       END IF;
5945 
5946                       OPEN c_asg_act_id(p_payroll_action_id,g_sal_data_rec_add(i).assignment_id);
5947                       FETCH c_asg_act_id INTO l_arch_asg_action_id;
5948                       CLOSE c_asg_act_id;
5949 
5950                       j := -1;
5951                       k := -1;
5952 
5953                       OPEN  c_salary_number_24qc(tab_liv_pe_data.person_id,l_24qa_source_id);
5954                       FETCH c_salary_number_24qc INTO k;
5955                       CLOSE c_salary_number_24qc;
5956 
5957                       OPEN  c_salary_number_24q(tab_liv_pe_data.person_id,l_24qa_source_id);
5958                       FETCH c_salary_number_24q INTO j;
5959                       CLOSE c_salary_number_24q;
5960 
5961                       pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
5962                       pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
5963 
5964                        l_c5_change_only := TRUE;
5965                        pay_in_utils.trace('Count of live balances  : ', tab_liv_ba_data.COUNT );
5966                        pay_in_utils.trace('Count of 24q balances   : ', tab_24q_ba_data.COUNT );
5967 
5968                        FOR j IN 1..tab_liv_ba_data.COUNT
5969                        LOOP
5970                          FOR k IN 1..tab_24q_ba_data.COUNT
5971                          LOOP
5972                            IF (tab_liv_ba_data(j).balance_name = tab_24q_ba_data(k).balance_name)
5973                            THEN
5974 
5975                                IF ((tab_liv_ba_data(j).balance_value <> 0) AND
5976                                    (tab_liv_ba_data(j).balance_value <> tab_24q_ba_data(k).balance_value) AND
5977                                    (tab_liv_ba_data(j).balance_name NOT IN ('F16 Deductions Sec 80CCE'))
5978                                   )
5979                                THEN
5980                                    l_c5_change_only := FALSE;
5981                                END IF;
5982 
5983                            END IF;
5984                           END LOOP;
5985                         END LOOP;
5986 
5987                         IF (tab_24q_ba_data.COUNT = 0)
5988                         THEN
5989                            l_c5_change_only := FALSE;
5990                            l_prev_c5 := FALSE;
5991                         END IF;
5992 
5993                         pay_in_utils.trace('Addition Source ID : ', g_sal_data_rec_add(i).source_id );
5994                         pay_in_utils.trace('Addition Assignment ID :  ', g_sal_data_rec_add(i).assignment_id );
5995 
5996                         IF (INSTR(l_action_information_category,'C5')<> 0) AND (g_correction_mode IN ('%','C5') AND (l_flag1=0) AND (l_prev_c5))
5997                         THEN
5998                                 pay_action_information_api.create_action_information
5999                                              (p_action_context_id              =>     l_arch_asg_action_id
6000                                              ,p_action_context_type            =>     'AAP'
6001                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
6002                                              ,p_source_id                      =>     g_sal_data_rec_add(i).source_id
6003                                              ,p_assignment_id                  =>     g_sal_data_rec_add(i).assignment_id
6004                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
6005                                              ,p_action_information2            =>     g_year||g_quarter
6006                                              ,p_action_information3            =>     g_gre_id
6007                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
6008                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
6009                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
6010                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
6011                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
6012                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
6013                                              ,p_action_information10           =>     'NA'
6014                                              ,p_action_information11           =>     'C5'
6015                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0))
6016                                              ,p_action_information_id          =>     l_action_info_id
6017                                              ,p_object_version_number          =>     l_ovn
6018                                              );
6019 
6020                                        FOR l IN 1..tab_24q_ba_data.COUNT
6021                                        LOOP
6022 
6023                                            IF ((tab_24q_ba_data(l).balance_name IN ('F16 Gross Total Income')) AND
6024                                                (tab_24q_ba_data(l).balance_value <> 0)
6025                                               )
6026                                            THEN
6027 
6028                                             pay_action_information_api.create_action_information
6029                                                           (p_action_context_id              =>     l_arch_asg_action_id
6030                                                           ,p_action_context_type            =>     'AAP'
6031                                                           ,p_action_information_category    =>     'IN_24QC_SALARY'
6032                                                           ,p_source_id                      =>     g_sal_data_rec_add(i).source_id
6033                                                           ,p_action_information1            =>     'Prev F16 Gross Total Income'
6034                                                           ,p_action_information2            =>     tab_24q_ba_data(l).balance_value
6035                                                           ,p_action_information_id          =>     l_action_info_id
6036                                                           ,p_object_version_number          =>     l_ovn
6037                                                           );
6038                                              END IF;
6039                                         END LOOP;
6040 
6041                         END IF;
6042 
6043 
6044                         OPEN  c_max_salary_number_24qc;
6045                         FETCH c_max_salary_number_24qc INTO k;
6046                         CLOSE c_max_salary_number_24qc;
6047 
6048                         OPEN  c_max_salary_number_24q;
6049                         FETCH c_max_salary_number_24q INTO j;
6050                         CLOSE c_max_salary_number_24q;
6051 
6052                         pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
6053                         pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
6054 
6055 
6056                        IF (INSTR(l_action_information_category,'C4')<> 0) AND (g_correction_mode IN ('%','C4'))
6057                             AND ((l_c5_change_only=FALSE)) AND (g_quarter IN ('Q4') AND (l_flag=0))
6058                        THEN
6059 
6060                                 pay_action_information_api.create_action_information
6061                                              (p_action_context_id              =>     l_arch_asg_action_id
6062                                              ,p_action_context_type            =>     'AAP'
6063                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
6064                                              ,p_source_id                      =>     g_sal_data_rec_add(i).source_id
6065                                              ,p_assignment_id                  =>     g_sal_data_rec_add(i).assignment_id
6066                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
6067                                              ,p_action_information2            =>     g_year||g_quarter
6068                                              ,p_action_information3            =>     g_gre_id
6069                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
6070                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
6071                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
6072                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
6073                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
6074                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
6075                                              ,p_action_information10           =>     'A'
6076                                              ,p_action_information11           =>     'C4'
6077                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0)) + s
6078                                              ,p_action_information_id          =>     l_action_info_id
6079                                              ,p_object_version_number          =>     l_ovn
6080                                              );
6081 
6082                                  FOR l IN 1..tab_liv_ba_data.COUNT
6083                                  LOOP
6084 
6085                                      IF ((tab_liv_ba_data(l).balance_value <> 0) AND
6086                                          (tab_liv_ba_data(l).balance_name IN ('80CCE','Others'))
6087                                         )
6088                                      THEN
6089                                                 pay_action_information_api.create_action_information
6090                                                               (p_action_context_id              =>     l_arch_asg_action_id
6091                                                               ,p_action_context_type            =>     'AAP'
6092                                                               ,p_action_information_category    =>     'IN_24QC_VIA'
6093                                                               ,p_source_id                      =>     g_sal_data_rec_add(i).source_id
6094                                                               ,p_action_information1            =>     tab_liv_ba_data(l).balance_name
6095                                                               ,p_action_information2            =>     tab_liv_ba_data(l).balance_value
6096                                                               ,p_action_information3            =>     0
6097                                                               ,p_action_information_id          =>     l_action_info_id
6098                                                               ,p_object_version_number          =>     l_ovn
6099                                                               );
6100                                       ELSIF ((tab_liv_ba_data(l).balance_value <> 0) AND
6101                                              (tab_liv_ba_data(l).balance_name NOT IN ('F16 Deductions Sec 80CCE'))
6102                                             )
6103                                       THEN
6104                                                 pay_action_information_api.create_action_information
6105                                                               (p_action_context_id              =>     l_arch_asg_action_id
6106                                                               ,p_action_context_type            =>     'AAP'
6107                                                               ,p_action_information_category    =>     'IN_24QC_SALARY'
6108                                                               ,p_source_id                      =>     g_sal_data_rec_add(i).source_id
6109                                                               ,p_action_information1            =>     tab_liv_ba_data(l).balance_name
6110                                                               ,p_action_information2            =>     tab_liv_ba_data(l).balance_value
6111                                                               ,p_action_information_id          =>     l_action_info_id
6112                                                               ,p_object_version_number          =>     l_ovn
6113                                                               );
6114                                       END IF;
6115                                 END LOOP;
6116                        s := s + 1;
6117                        END IF;
6118                 END IF;
6119 
6120 
6121 
6122                       l_future_pay := FALSE;
6123                       l_prev_max_pact := NULL;
6124                       l_count_delete := 0;
6125 
6126                       IF (l_c5_change_only)
6127                       THEN
6128                       NULL;
6129                       ELSE
6130                           OPEN  c_prev_max_pact(g_sal_data_rec_add(i).assignment_id,g_sal_data_rec_add(i).source_id);
6131                           FETCH c_prev_max_pact INTO l_prev_max_pact,l_assignment_id;
6132                           CLOSE c_prev_max_pact;
6133                         IF (l_prev_max_pact IS NOT NULL)
6134                         THEN
6135                                FOR p IN 1..g_count_sal_delete - 1
6136                                LOOP
6137                                  IF (g_sal_data_rec_add(i).assignment_id = g_sal_data_rec_del(p).assignment_id)
6138                                  THEN
6139                                   l_count_delete := l_count_delete + 1;
6140                                  END IF;
6141                                END LOOP;
6142                                IF (l_count_delete = 0) THEN
6143                                   l_future_pay := TRUE;
6144                                END IF;
6145                         END IF;
6146                       END IF;
6147 
6148 
6149 
6150                       OPEN  c_salary_number_24qc(tab_liv_pe_data.person_id,l_prev_max_pact);
6151                       FETCH c_salary_number_24qc INTO k;
6152                       CLOSE c_salary_number_24qc;
6153 
6154                       OPEN  c_salary_number_24q(tab_liv_pe_data.person_id,l_prev_max_pact);
6155                       FETCH c_salary_number_24q INTO j;
6156                       CLOSE c_salary_number_24q;
6157 
6158                       pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
6159                       pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
6160 
6161                        l_flag2 := check_archival_status(l_prev_max_pact,'IN_24QC_PERSON',NULL,'D');
6162 
6163                        IF (INSTR(l_action_information_category,'C4')<> 0) AND (g_correction_mode IN ('%','C4'))
6164                             AND ((l_c5_change_only=FALSE)) AND (l_future_pay=TRUE) AND ((j>0) OR (j IS NULL)) AND (g_quarter IN ('Q4') AND (l_flag2=0))
6165                        THEN
6166 
6167                                 pay_action_information_api.create_action_information
6168                                              (p_action_context_id              =>     l_arch_asg_action_id
6169                                              ,p_action_context_type            =>     'AAP'
6170                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
6171                                              ,p_source_id                      =>     l_prev_max_pact
6172                                              ,p_assignment_id                  =>     g_sal_data_rec_add(i).assignment_id
6173                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
6174                                              ,p_action_information2            =>     g_year||g_quarter
6175                                              ,p_action_information3            =>     g_gre_id
6176                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
6177                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
6178                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
6179                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
6180                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
6181                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
6182                                              ,p_action_information10           =>     'D'
6183                                              ,p_action_information11           =>     'C4'
6184                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0))
6185                                              ,p_action_information_id          =>     l_action_info_id
6186                                              ,p_object_version_number          =>     l_ovn
6187                                              );
6188 
6189 
6190                                              OPEN  c_get_bal_24q(l_prev_asg_action_id,l_prev_max_pact,l_prev_category,'F16 Gross Total Income');
6191                                              FETCH c_get_bal_24q INTO l_balance_value;
6192                                              CLOSE c_get_bal_24q;
6193 
6194                                              pay_in_utils.trace('l_balance_value : ',l_balance_value);
6195 
6196                                              IF ((l_prev_asg_action_id IS NOT NULL) AND (l_balance_value <> 0))
6197                                              THEN
6198 
6199                                                    pay_action_information_api.create_action_information
6200                                                                  (p_action_context_id              =>     l_arch_asg_action_id
6201                                                                  ,p_action_context_type            =>     'AAP'
6202                                                                  ,p_action_information_category    =>     'IN_24QC_SALARY'
6203                                                                  ,p_source_id                      =>     l_prev_max_pact
6204                                                                  ,p_action_information1            =>     'Prev F16 Gross Total Income'
6205                                                                  ,p_action_information2            =>     l_balance_value--tab_24q_ba_data(l).balance_value
6206                                                                  ,p_action_information_id          =>     l_action_info_id
6207                                                                  ,p_object_version_number          =>     l_ovn
6208                                                                  );
6209                                              END IF;
6210 
6211 
6212                                                 OPEN c_asg_act_id(p_24qa_pay_act_id,g_sal_data_rec_add(i).assignment_id);
6213                                                 FETCH c_asg_act_id INTO l_24qa_asg_action_id;
6214                                                 CLOSE c_asg_act_id;
6215 
6216                                                 OPEN  c_24qa_source_id(l_24qa_asg_action_id,g_sal_data_rec_add(i).assignment_id);
6217                                                 FETCH c_24qa_source_id INTO l_24qa_source_id,l_24qa_asg_action_id;
6218                                                 CLOSE c_24qa_source_id;
6219 
6220                                                 OPEN  c_get_bal_24q(l_24qa_asg_action_id,l_24qa_source_id,'IN_24Q_SALARY','F16 Gross Total Income');
6221                                                 FETCH c_get_bal_24q INTO l_balance_value;
6222                                                 CLOSE c_get_bal_24q;
6223 
6224                                            IF ((l_24qa_source_id IS NOT NULL) AND (l_balance_value <> 0))
6225                                            THEN
6226                                                    pay_action_information_api.create_action_information
6227                                                                  (p_action_context_id              =>     l_arch_asg_action_id
6228                                                                  ,p_action_context_type            =>     'AAP'
6229                                                                  ,p_action_information_category    =>     'IN_24QC_SALARY'
6230                                                                  ,p_source_id                      =>     l_prev_max_pact
6231                                                                  ,p_action_information1            =>     'Form24Q F16 Gross Total Income'
6232                                                                  ,p_action_information2            =>     l_balance_value
6233                                                                  ,p_action_information_id          =>     l_action_info_id
6234                                                                  ,p_object_version_number          =>     l_ovn
6235                                                                  );
6236                                            END IF;
6237 
6238                        END IF;
6239              END LOOP;
6240       END IF;
6241 
6242 
6243       IF (s = 1) THEN
6244         s := 1;
6245       END IF;
6246       l_24qa_source_id := NULL;
6247       l_24qa_asg_action_id := NULL;
6248       IF (g_correction_mode IN('C4','C5','%'))
6249       THEN
6250         pay_in_utils.set_location(g_debug,'Value of g_count_sal_update : '|| g_count_sal_update, 1);
6251 
6252       FOR i IN 1..g_count_sal_update - 1
6253       LOOP
6254          pay_in_utils.set_location(g_debug,'Checking archived presence of this updated assignment action',1);
6255          l_flag  := -1;
6256          l_flag1 := -1;
6257          l_flag2 := -1;
6258          l_gre_count := 0;
6259          l_c5_tot_income_flag := FALSE;
6260 
6261          l_flag  := check_archival_status(g_sal_data_rec_upd(i).source_id,'IN_24QC_PERSON',NULL,'A');
6262          l_flag1 := check_archival_status(g_sal_data_rec_upd(i).source_id,'IN_24QC_PERSON',NULL,'NA');
6263          l_flag2 := check_archival_status(g_sal_data_rec_upd(i).source_id,'IN_24QC_PERSON',NULL,'D');
6264 
6265           pay_in_utils.trace('l_flag in g_count_sal_update   : ', l_flag );
6266           pay_in_utils.trace('l_flag1 in g_count_sal_update  : ', l_flag1 );
6267           pay_in_utils.trace('l_flag2 in g_count_sal_update  : ', l_flag2 );
6268 
6269 
6270          IF ((l_flag = 0) AND (l_flag1 = 0) )
6271          THEN
6272               pay_in_utils.set_location(g_debug,'Updated Asg Action Not Archived. hence doing '||g_sal_data_rec_upd(i).source_id,1);
6273 
6274                pay_in_utils.set_location(g_debug,'Fetching balances...',2);
6275 
6276                        get_balance_values
6277                         (
6278                           g_sal_data_rec_upd(i).source_id
6279                          ,g_sal_data_rec_upd(i).last_action_context_id
6280                          ,g_sal_data_rec_upd(i).assignment_id
6281                          ,p_24qa_pay_act_id
6282                          ,'U'
6283                          ,tab_liv_ba_data
6284                          ,tab_24q_ba_data
6285                          ,tab_liv_pe_data
6286                          ,tab_24q_pe_data
6287                          ,l_gre_count
6288                         );
6289 
6290 
6291                 pay_in_utils.set_location(g_debug,'Fetched balances...',2);
6292                 pay_in_utils.set_location(g_debug,'Fetching Archival Assignment Action ID...',2);
6293                 pay_in_utils.set_location(g_debug,'Asg ID' ||   g_sal_data_rec_upd(i).assignment_id ,2);
6294                 pay_in_utils.set_location(g_debug,'Payroll Action id is ' || p_payroll_action_id ,2);
6295 
6296                 OPEN c_asg_act_id(p_payroll_action_id,g_sal_data_rec_upd(i).assignment_id);
6297                 FETCH c_asg_act_id INTO l_arch_asg_action_id;
6298                 CLOSE c_asg_act_id;
6299 
6300                  pay_in_utils.set_location(g_debug,'Archival Assignment Action ID is :'|| l_arch_asg_action_id ,2);
6301 
6302                 --      if g_correction_mode = 'C5' and tab_24q_pe_data.pan_number IS VALID and
6303                 --       tab_liv_pe_data.pan_number is also valid and not equal 2 each other
6304                 --       then not only arhcive this assignment data, but also last organization PA data
6305 
6306                          pay_in_utils.trace('tab_liv_pe_data.pan_number  : ', tab_liv_pe_data.pan_number );
6307                          pay_in_utils.trace('tab_24q_pe_data.pan_number  : ', tab_24q_pe_data.pan_number );
6308 
6309                          IF ((g_correction_mode IN('C4','C5','%'))
6310                               AND(tab_24q_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
6311                               AND(tab_liv_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
6312                               AND(tab_24q_pe_data.pan_number <> tab_liv_pe_data.pan_number)
6313                             )
6314                          THEN
6315                                  l_action_information_category := 'C4:C5';
6316                          ELSE
6317                                  l_action_information_category := 'C4';
6318                          END IF;
6319 
6320                           OPEN  c_salary_number_24qc(tab_liv_pe_data.person_id,g_sal_data_rec_upd(i).source_id);
6321                           FETCH c_salary_number_24qc INTO k;
6322                           CLOSE c_salary_number_24qc;
6323 
6324                           OPEN  c_salary_number_24q(tab_liv_pe_data.person_id,g_sal_data_rec_upd(i).source_id);
6325                           FETCH c_salary_number_24q INTO j;
6326                           CLOSE c_salary_number_24q;
6327 
6328                           pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
6329                           pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
6330 
6331                     l_c5_change_only := TRUE;
6332                     pay_in_utils.trace('Count of live balances  : ', tab_liv_ba_data.COUNT );
6333                     pay_in_utils.trace('Count of 24q balances   : ', tab_24q_ba_data.COUNT );
6334 
6335                     FOR j IN 1..tab_liv_ba_data.COUNT
6336                     LOOP
6337                        FOR k IN 1..tab_24q_ba_data.COUNT
6338                        LOOP
6339 
6340                           IF (tab_liv_ba_data(j).balance_name = tab_24q_ba_data(k).balance_name)
6341                             THEN
6342                                 IF ((tab_liv_ba_data(j).balance_value <> 0) AND
6343                                     (tab_liv_ba_data(j).balance_value <> tab_24q_ba_data(k).balance_value) AND
6344                                     (tab_liv_ba_data(j).balance_name NOT IN ('F16 Deductions Sec 80CCE'))
6345                                     )
6346                                 THEN
6347                                   l_c5_change_only := FALSE;
6348                                  END IF;
6349                             END IF;
6350 
6351                      END LOOP;
6352                     END LOOP;
6353 
6354                      l_future_pay := TRUE;
6355 
6356                      OPEN  c_max_pact(g_sal_data_rec_upd(i).assignment_id);
6357                        FETCH c_max_pact INTO l_max_pact,l_assignment_id;
6358                      CLOSE c_max_pact;
6359 
6360                      IF ((g_sal_data_rec_upd(i).source_id < l_max_pact) AND (l_gre_count <= 2))
6361                      THEN
6362                        l_future_pay := FALSE;
6363                      END IF;
6364 
6365                          pay_in_utils.trace('Update Source_id :',g_sal_data_rec_upd(i).source_id);
6366                          pay_in_utils.trace('l_max_pact ',l_max_pact);
6367                          pay_in_utils.trace('l_gre_count in g_count_sal_update: ',l_gre_count);
6368 
6369                           IF (INSTR(l_action_information_category,'C5')<> 0) AND (g_correction_mode IN ('%','C5') AND (l_flag1=0) AND (l_future_pay=TRUE))
6370                           THEN
6371 
6372                                 pay_action_information_api.create_action_information
6373                                              (p_action_context_id              =>     l_arch_asg_action_id
6374                                              ,p_action_context_type            =>     'AAP'
6375                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
6376                                              ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6377                                              ,p_assignment_id                  =>     g_sal_data_rec_upd(i).assignment_id
6378                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
6379                                              ,p_action_information2            =>     g_year||g_quarter
6380                                              ,p_action_information3            =>     g_gre_id
6381                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
6382                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
6383                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
6384                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
6385                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
6386                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
6387                                              ,p_action_information10           =>     'NA'
6388                                              ,p_action_information11           =>     'C5'
6389                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0))
6390                                              ,p_action_information_id          =>     l_action_info_id
6391                                              ,p_object_version_number          =>     l_ovn
6392                                              );
6393 
6394                                               FOR l IN 1..tab_24q_ba_data.COUNT
6395                                               LOOP
6396 
6397                                                   IF ((tab_24q_ba_data(l).balance_name IN ('F16 Gross Total Income')) AND
6398                                                       (tab_24q_ba_data(l).balance_value <> 0)
6399                                                      )
6400                                                   THEN
6401 
6402                                                    pay_action_information_api.create_action_information
6403                                                                  (p_action_context_id              =>     l_arch_asg_action_id
6404                                                                  ,p_action_context_type            =>     'AAP'
6405                                                                  ,p_action_information_category    =>     'IN_24QC_SALARY'
6406                                                                  ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6407                                                                  ,p_action_information1            =>     'Prev F16 Gross Total Income'
6408                                                                  ,p_action_information2            =>     tab_24q_ba_data(l).balance_value
6409                                                                  ,p_action_information_id          =>     l_action_info_id
6410                                                                  ,p_object_version_number          =>     l_ovn
6411                                                                  );
6412                                                     l_c5_tot_income_flag := TRUE;
6413                                                     END IF;
6414                                                END LOOP;
6415 
6416                        END IF;
6417 
6418                        IF (INSTR(l_action_information_category,'C4')<> 0) AND (g_correction_mode IN ('%','C4'))
6419                             AND (l_c5_change_only=FALSE) AND (g_quarter IN ('Q4') AND (l_flag2 = 0))
6420                        THEN
6421 
6422                                 pay_action_information_api.create_action_information
6423                                              (p_action_context_id              =>     l_arch_asg_action_id
6424                                              ,p_action_context_type            =>     'AAP'
6425                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
6426                                              ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6427                                              ,p_assignment_id                  =>     g_sal_data_rec_upd(i).assignment_id
6428                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
6429                                              ,p_action_information2            =>     g_year||g_quarter
6430                                              ,p_action_information3            =>     g_gre_id
6431                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
6432                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
6433                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
6434                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
6435                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
6436                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
6437                                              ,p_action_information10           =>     'D'
6438                                              ,p_action_information11           =>     'C4'
6439                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0))
6440                                              ,p_action_information_id          =>     l_action_info_id
6441                                              ,p_object_version_number          =>     l_ovn
6442                                              );
6443 
6444                                        IF (l_c5_tot_income_flag=FALSE)
6445                                        THEN
6446                                               FOR l IN 1..tab_24q_ba_data.COUNT
6447                                               LOOP
6448 
6449                                                   IF ((tab_24q_ba_data(l).balance_name IN ('F16 Gross Total Income')) AND
6450                                                       (tab_24q_ba_data(l).balance_value <> 0)
6451                                                      )
6452                                                   THEN
6453 
6454                                                    pay_action_information_api.create_action_information
6455                                                                  (p_action_context_id              =>     l_arch_asg_action_id
6456                                                                  ,p_action_context_type            =>     'AAP'
6457                                                                  ,p_action_information_category    =>     'IN_24QC_SALARY'
6458                                                                  ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6459                                                                  ,p_action_information1            =>     'Prev F16 Gross Total Income'
6460                                                                  ,p_action_information2            =>     tab_24q_ba_data(l).balance_value
6461                                                                  ,p_action_information_id          =>     l_action_info_id
6462                                                                  ,p_object_version_number          =>     l_ovn
6463                                                                  );
6464                                                     END IF;
6465                                                END LOOP;
6466                                           END IF;
6467 
6468 
6469                                                 OPEN c_asg_act_id(p_24qa_pay_act_id,g_sal_data_rec_upd(i).assignment_id);
6470                                                 FETCH c_asg_act_id INTO l_24qa_asg_action_id;
6471                                                 CLOSE c_asg_act_id;
6472 
6473                                                 OPEN  c_24qa_source_id(l_24qa_asg_action_id,g_sal_data_rec_upd(i).assignment_id);
6474                                                 FETCH c_24qa_source_id INTO l_24qa_source_id,l_24qa_asg_action_id;
6475                                                 CLOSE c_24qa_source_id;
6476 
6477                                                 OPEN  c_get_bal_24q(l_24qa_asg_action_id,l_24qa_source_id,'IN_24Q_SALARY','F16 Gross Total Income');
6478                                                 FETCH c_get_bal_24q INTO l_balance_value;
6479                                                 CLOSE c_get_bal_24q;
6480 
6481                                                 IF ((l_24qa_source_id IS NOT NULL) AND (l_balance_value <> 0)) THEN
6482                                                    pay_action_information_api.create_action_information
6483                                                                  (p_action_context_id              =>     l_arch_asg_action_id
6484                                                                  ,p_action_context_type            =>     'AAP'
6485                                                                  ,p_action_information_category    =>     'IN_24QC_SALARY'
6486                                                                  ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6487                                                                  ,p_action_information1            =>     'Form24Q F16 Gross Total Income'
6488                                                                  ,p_action_information2            =>     l_balance_value
6489                                                                  ,p_action_information_id          =>     l_action_info_id
6490                                                                  ,p_object_version_number          =>     l_ovn
6491                                                                  );
6492                                                 END IF;
6493 
6494                        END IF;
6495 
6496                        j := -1;
6497                        k := -1;
6498 
6499                        OPEN  c_max_salary_number_24qc;
6500                         FETCH c_max_salary_number_24qc INTO k;
6501                        CLOSE c_max_salary_number_24qc;
6502 
6503                        OPEN  c_max_salary_number_24q;
6504                         FETCH c_max_salary_number_24q INTO j;
6505                        CLOSE c_max_salary_number_24q;
6506 
6507                        pay_in_utils.set_location(g_debug,'Previous Salary Detail Record Number was:' || j, 3);
6508                        pay_in_utils.set_location(g_debug,'New Salary Detail Record Number is:' || k,4);
6509 
6510                        IF (INSTR(l_action_information_category,'C4')<> 0)AND(g_correction_mode IN ('%','C4'))
6511                             AND (l_c5_change_only=FALSE) AND (g_quarter IN ('Q4') AND (l_flag = 0))
6512                        THEN
6513 
6514                                 pay_action_information_api.create_action_information
6515                                              (p_action_context_id              =>     l_arch_asg_action_id
6516                                              ,p_action_context_type            =>     'AAP'
6517                                              ,p_action_information_category    =>     'IN_24QC_PERSON'
6518                                              ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6519                                              ,p_assignment_id                  =>     g_sal_data_rec_upd(i).assignment_id
6520                                              ,p_action_information1            =>     tab_liv_pe_data.person_id
6521                                              ,p_action_information2            =>     g_year||g_quarter
6522                                              ,p_action_information3            =>     g_gre_id
6523                                              ,p_action_information4            =>     tab_liv_pe_data.pan_number
6524                                              ,p_action_information5            =>     tab_liv_pe_data.pan_ref_number
6525                                              ,p_action_information6            =>     tab_liv_pe_data.full_name
6526                                              ,p_action_information7            =>     pay_in_24q_er_returns.get_emp_category(tab_liv_pe_data.person_id)
6527                                              ,p_action_information8            =>     fnd_date.date_to_canonical(tab_liv_pe_data.start_date)
6528                                              ,p_action_information9            =>     fnd_date.date_to_canonical(tab_liv_pe_data.end_date)
6529                                              ,p_action_information10           =>     'A'
6530                                              ,p_action_information11           =>     'C4'
6531                                              ,p_action_information12           =>     GREATEST(NVL(j,0),NVL(k,0)) + s
6532                                              ,p_action_information_id          =>     l_action_info_id
6533                                              ,p_object_version_number          =>     l_ovn
6534                                              );
6535 
6536                            FOR l IN 1..tab_liv_ba_data.COUNT
6537                            LOOP
6538 
6539                                IF ((tab_liv_ba_data(l).balance_value <> 0) AND
6540                                    (tab_liv_ba_data(l).balance_name IN ('80CCE','Others'))
6541                                   )
6542                                THEN
6543                                           pay_action_information_api.create_action_information
6544                                                         (p_action_context_id              =>     l_arch_asg_action_id
6545                                                         ,p_action_context_type            =>     'AAP'
6546                                                         ,p_action_information_category    =>     'IN_24QC_VIA'
6547                                                         ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6548                                                         ,p_action_information1            =>     tab_liv_ba_data(l).balance_name
6549                                                         ,p_action_information2            =>     tab_liv_ba_data(l).balance_value
6550                                                         ,p_action_information3            =>     0
6551                                                         ,p_action_information_id          =>     l_action_info_id
6552                                                         ,p_object_version_number          =>     l_ovn
6553                                                         );
6554                                 ELSIF ((tab_liv_ba_data(l).balance_value <> 0) AND
6555                                        (tab_liv_ba_data(l).balance_name NOT IN ('F16 Deductions Sec 80CCE'))
6556                                       )
6557                                 THEN
6558                                           pay_action_information_api.create_action_information
6559                                                         (p_action_context_id              =>     l_arch_asg_action_id
6560                                                         ,p_action_context_type            =>     'AAP'
6561                                                         ,p_action_information_category    =>     'IN_24QC_SALARY'
6562                                                         ,p_source_id                      =>     g_sal_data_rec_upd(i).source_id
6563                                                         ,p_action_information1            =>     tab_liv_ba_data(l).balance_name
6564                                                         ,p_action_information2            =>     tab_liv_ba_data(l).balance_value
6565                                                         ,p_action_information_id          =>     l_action_info_id
6566                                                         ,p_object_version_number          =>     l_ovn
6567                                                         );
6568                                 END IF;
6569                           END LOOP;
6570                    s := s + 1;
6571                        END IF;
6572         END IF;
6573       END LOOP;
6574 
6575     END IF;
6576 
6577 
6578   pay_in_utils.set_location(g_debug,'Leaving '|| l_procedure, 5);
6579 
6580   EXCEPTION
6581     WHEN OTHERS THEN
6582       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
6583       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
6584   END archive_salary_data;
6585 
6586 
6587 
6588   --------------------------------------------------------------------------
6589   --                                                                      --
6590   -- Name           : ARCHIVE_DEDUCTEE_DATA                               --
6591   -- Type           : PROCEDURE                                           --
6592   -- Access         : Private                                             --
6593   -- Description    : Procedure to actually archive the data.             --
6594   -- Parameters     :                                                     --
6595   --             IN :                                                     --
6596   --                                                                      --
6597   --            OUT : N/A                                                 --
6598   --                                                                      --
6599   -- Change History :                                                     --
6600   --------------------------------------------------------------------------
6601   -- Rev#  Date           Userid    Description                           --
6602   --------------------------------------------------------------------------
6603   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
6604   --------------------------------------------------------------------------
6605   PROCEDURE archive_deductee_data(p_payroll_action_id   NUMBER
6606                                  ,p_24qa_pay_act_id     NUMBER
6607                                  )
6608   IS
6609   CURSOR c_c5_correction_type_details(p_last_arc_asg_action_id  NUMBER)
6610   IS
6611     SELECT pai.action_information_category
6612           ,pai.action_context_id
6613       FROM pay_action_information pai
6614           ,pay_assignment_actions paa
6615      WHERE paa.assignment_action_id = p_last_arc_asg_action_id
6616        AND pai.action_context_id    = paa.payroll_action_id
6617        AND pai.action_context_type  = 'PA'
6618      ORDER BY pai.action_context_id DESC;
6619 
6620   CURSOR c_deductee_number_24q(p_challan_number      VARCHAR2
6621                               ,p_element_entry_id    NUMBER
6622                               )
6623   IS
6624         SELECT action_information25
6625           FROM pay_action_information pai
6626               ,pay_assignment_actions paa
6627          WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
6628            AND pai.action_information3         = g_gre_id
6629            AND pai.action_information1         = p_challan_number
6630            AND pai.action_context_id           = paa.assignment_action_id
6631            AND paa.payroll_action_id           = p_24qa_pay_act_id
6632            AND pai.source_id                   = p_element_entry_id;
6633 
6634   CURSOR c_deductee_number_24qc(p_challan_number      VARCHAR2
6635                                ,p_element_entry_id    NUMBER
6636                                )
6637       IS
6638         SELECT action_information25
6639           FROM pay_action_information pai
6640               ,pay_assignment_actions paa
6641               ,pay_action_interlocks  locks
6642          WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
6643            AND pai.action_information3         = g_gre_id
6644            AND pai.action_information2         = g_year||g_quarter
6645            AND pai.action_information1         = p_challan_number
6646            AND locks.locking_action_id         = pai.action_context_id
6647            AND locks.locked_action_id          = paa.assignment_action_id
6648            AND paa.payroll_action_id           = p_24qa_pay_act_id
6649            AND pai.source_id                   = p_element_entry_id;
6650 
6651 
6652   CURSOR c_max_challan_number_24qc(p_challan_number      VARCHAR2)
6653       IS
6654         SELECT MAX(TO_NUMBER(action_information25))
6655           FROM pay_action_information pai
6656               ,pay_assignment_actions paa
6657               ,pay_action_interlocks  locks
6658               ,pay_assignment_actions paa_master
6659          WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
6660            AND pai.action_information3         = g_gre_id
6661            AND pai.action_information2         = g_year||g_quarter
6662            AND pai.action_information1         = p_challan_number
6663            AND locks.locking_action_id         = pai.action_context_id
6664            AND locks.locked_action_id          = paa.assignment_action_id
6665            AND paa.payroll_action_id           = p_24qa_pay_act_id
6666            AND paa_master.assignment_action_id = pai.action_context_id
6667            AND paa_master.payroll_action_id IN(
6668                                                   SELECT org_information3
6669                                                     FROM hr_organization_information
6670                                                    WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
6671                                                      AND organization_id         = g_gre_id
6672                                                      AND org_information1        = g_year
6673                                                      AND org_information2        = g_quarter
6674                                                      AND org_information5        = 'A'
6675                                                      AND org_information6        = 'C'
6676                                                  );
6677 
6678   CURSOR c_max_challan_number_24q(p_challan_number      VARCHAR2)
6679       IS
6680         SELECT MAX(TO_NUMBER(action_information25))
6681           FROM pay_action_information pai
6682               ,pay_assignment_actions paa
6683          WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
6684            AND pai.action_information3         = g_gre_id
6685            AND pai.action_information1         = p_challan_number
6686            AND pai.action_context_id           = paa.assignment_action_id
6687            AND paa.payroll_action_id           = p_24qa_pay_act_id
6688            AND paa.payroll_action_id IN(
6689                                         SELECT org_information3
6690                                           FROM hr_organization_information
6691                                          WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
6692                                            AND organization_id         = g_gre_id
6693                                            AND org_information1        = g_year
6694                                            AND org_information2        = g_quarter
6695                                            AND org_information5        = 'A'
6696                                            AND org_information6        = 'O'
6697                                        );
6698 
6699   CURSOR c_asg_act_id(p_assignment_id         NUMBER)
6700   IS
6701      SELECT assignment_action_id
6702        FROM pay_assignment_actions
6703       WHERE payroll_action_id = p_payroll_action_id
6704         AND assignment_id     = p_assignment_id;
6705 
6706     tab_24q_ee_data  t_screen_entry_value_rec;
6707     tab_liv_ee_data  t_screen_entry_value_rec;
6708     tab_24q_pe_data  t_person_data_rec;
6709     tab_liv_pe_data  t_person_data_rec;
6710 
6711     l_action_information_category pay_action_information.action_information_category%TYPE;
6712     l_action_context_id           NUMBER;
6713     l_deductee_detail             NUMBER;
6714     l_arch_asg_action_id          NUMBER;
6715     l_action_info_id              NUMBER;
6716     l_ovn                         NUMBER;
6717     j                             NUMBER;
6718     k                             NUMBER;
6719     s                             NUMBER;
6720     l_dummy                       NUMBER  := -1;
6721     l_flag                        NUMBER  := -1;
6722     l_c5_change                   BOOLEAN;
6723     l_category                    pay_action_information.action_information_category%TYPE;
6724     l_procedure                   VARCHAR2(250);
6725     l_message                     VARCHAR2(250);
6726   BEGIN
6727       g_debug     := hr_utility.debug_enabled;
6728       l_procedure := g_package ||'.archive_deductee_data';
6729       pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
6730       pay_in_utils.set_location(g_debug,'Fetching Deductee Data ', 1);
6731       pay_in_utils.set_location(g_debug,'Value of g_count_ee_delete : '|| g_count_ee_delete, 1);
6732       IF (g_correction_mode <> 'C9')
6733       THEN
6734              FOR i IN 1..g_count_ee_delete - 1
6735              LOOP
6736 
6737                 pay_in_utils.set_location(g_debug,'Checking archived presence of this deleted ee',1);
6738                 l_flag := -1;
6739 
6740                 l_flag := check_archival_status(g_ee_data_rec_del(i).element_entry_id,'IN_24QC_DEDUCTEE',NULL,'D');
6741                 IF (l_flag = 0)
6742                 THEN
6743                       pay_in_utils.set_location(g_debug,'Deleted EE Not Archived. hence doing '||g_ee_data_rec_del(i).element_entry_id,1);
6744 
6745                        get_element_entry_values
6746                         (
6747                           g_ee_data_rec_del(i).element_entry_id
6748                          ,g_ee_data_rec_del(i).last_action_context_id
6749                          ,g_ee_data_rec_del(i).assignment_id
6750                          ,tab_liv_ee_data
6751                          ,tab_24q_ee_data
6752                          ,tab_liv_pe_data
6753                          ,tab_24q_pe_data
6754                         );
6755 
6756                 --      if g_correction_mode = 'C5' and tab_24q_pe_data.pan_number IS VALID and
6757                 --       tab_liv_pe_data.pan_number is also valid and not equal 2 each other
6758                 --       then not only arhcive this assignment data, but also last organization PA data
6759 
6760                          IF ((g_correction_mode IN('C3','C5','%'))
6761                               AND(tab_24q_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
6762                               AND(tab_liv_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
6763                               AND(tab_24q_pe_data.pan_number <> tab_liv_pe_data.pan_number)
6764                             )
6765                          THEN
6766                                  l_action_information_category := 'C3:C5';
6767                                  l_action_context_id           := -1;
6768                          ELSE
6769                                  l_action_information_category := 'C3';
6770                                  l_action_context_id           := -1;
6771                          END IF;
6772 
6773                          OPEN  c_asg_act_id(g_ee_data_rec_del(i).assignment_id);
6774                          FETCH c_asg_act_id INTO l_arch_asg_action_id;
6775                          CLOSE c_asg_act_id;
6776 
6777                           OPEN  c_deductee_number_24qc(tab_24q_ee_data.challan_number,g_ee_data_rec_del(i).element_entry_id);
6778                           FETCH c_deductee_number_24qc INTO k;
6779                           CLOSE c_deductee_number_24qc;
6780 
6781                           OPEN  c_deductee_number_24q(tab_24q_ee_data.challan_number,g_ee_data_rec_del(i).element_entry_id);
6782                           FETCH c_deductee_number_24q INTO j;
6783                           CLOSE c_deductee_number_24q;
6784 
6785                           pay_in_utils.set_location(g_debug,'Previous Challan Deductee Record Number was:' || j, 3);
6786                           pay_in_utils.set_location(g_debug,'New Challan Deductee Record Number is:' || k,4);
6787 
6788                           IF (INSTR(l_action_information_category,'C5')<> 0)AND(g_correction_mode IN ('%','C5'))
6789                           THEN
6790                                 l_category := SUBSTR(l_action_information_category
6791                                                     ,1
6792                                                     ,INSTR(l_action_information_category,'G')
6793                                                     );
6794                                 l_category := l_category || 'C5';
6795 
6796                                 pay_action_information_api.create_action_information
6797                                              (p_action_context_id              =>     l_arch_asg_action_id
6798                                              ,p_action_context_type            =>     'AAP'
6799                                              ,p_action_information_category    =>     'IN_24QC_DEDUCTEE'
6800                                              ,p_source_id                      =>     g_ee_data_rec_del(i).element_entry_id
6801                                              ,p_assignment_id                  =>     g_ee_data_rec_del(i).assignment_id
6802                                              ,p_action_information1            =>     tab_24q_ee_data.challan_number
6803                                              ,p_action_information2            =>     g_year||g_quarter
6804                                              ,p_action_information3            =>     g_gre_id
6805                                              ,p_action_information4            =>     tab_24q_ee_data.payment_date
6806                                              ,p_action_information5            =>     tab_24q_ee_data.taxable_income
6807                                              ,p_action_information6            =>     tab_24q_ee_data.income_tax
6808                                              ,p_action_information7            =>     tab_24q_ee_data.surcharge
6809                                              ,p_action_information8            =>     tab_24q_ee_data.education_cess
6810                                              ,p_action_information9            =>     tab_liv_pe_data.pan_number
6811                                              ,p_action_information10           =>     tab_liv_pe_data.full_name
6812                                              ,p_action_information11           =>     tab_liv_pe_data.pan_ref_number
6813                                              ,p_action_information12           =>     tab_liv_pe_data.person_id
6814                                              ,p_action_information13           =>     tab_24q_pe_data.pan_number
6815                                              ,p_action_information14           =>     tab_24q_pe_data.pan_ref_number
6816                                              ,p_action_information15           =>     'D'
6817                                              ,p_action_information16           =>     tab_24q_ee_data.amount_deposited
6818                                              ,p_action_information17           =>     NVL(tab_24q_ee_data.income_tax,0) + NVL(tab_24q_ee_data.surcharge,0) + NVL(tab_24q_ee_data.education_cess,0)
6819                                              ,p_action_information18           =>     tab_liv_pe_data.tax_rate
6820                                              ,p_action_information19           =>     l_category
6821                                              ,p_action_information20           =>     l_action_context_id
6822                                              ,p_action_information21           =>     tab_24q_ee_data.income_tax
6823                                              ,p_action_information22           =>     tab_24q_ee_data.surcharge
6824                                              ,p_action_information23           =>     tab_24q_ee_data.education_cess
6825                                              ,p_action_information24           =>     tab_24q_ee_data.amount_deposited
6826                                              ,p_action_information25           =>     GREATEST(NVL(j,0),NVL(k,0))
6827                                              ,p_action_information_id          =>     l_action_info_id
6828                                              ,p_object_version_number          =>     l_ovn
6829                                              );
6830                        END IF;
6831 
6832                        IF (INSTR(l_action_information_category,'C3')<> 0)AND(g_correction_mode IN ('%','C3'))
6833                        THEN
6834                                 l_category := SUBSTR(l_action_information_category
6835                                                     ,1
6836                                                     ,INSTR(l_action_information_category,'G')
6837                                                     );
6838                                 l_category := l_category || 'C3';
6839 
6840                                 pay_action_information_api.create_action_information
6841                                              (p_action_context_id              =>     l_arch_asg_action_id
6842                                              ,p_action_context_type            =>     'AAP'
6843                                              ,p_action_information_category    =>     'IN_24QC_DEDUCTEE'
6844                                              ,p_source_id                      =>     g_ee_data_rec_del(i).element_entry_id
6845                                              ,p_assignment_id                  =>     g_ee_data_rec_del(i).assignment_id
6846                                              ,p_action_information1            =>     tab_24q_ee_data.challan_number
6847                                              ,p_action_information2            =>     g_year||g_quarter
6848                                              ,p_action_information3            =>     g_gre_id
6849                                              ,p_action_information4            =>     tab_24q_ee_data.payment_date
6850                                              ,p_action_information5            =>     tab_24q_ee_data.taxable_income
6851                                              ,p_action_information6            =>     tab_24q_ee_data.income_tax
6852                                              ,p_action_information7            =>     tab_24q_ee_data.surcharge
6853                                              ,p_action_information8            =>     tab_24q_ee_data.education_cess
6854                                              ,p_action_information9            =>     tab_liv_pe_data.pan_number
6855                                              ,p_action_information10           =>     tab_liv_pe_data.full_name
6856                                              ,p_action_information11           =>     tab_liv_pe_data.pan_ref_number
6857                                              ,p_action_information12           =>     tab_liv_pe_data.person_id
6858                                              ,p_action_information13           =>     tab_24q_pe_data.pan_number
6859                                              ,p_action_information14           =>     tab_24q_pe_data.pan_ref_number
6860                                              ,p_action_information15           =>     'D'
6861                                              ,p_action_information16           =>     tab_24q_ee_data.amount_deposited
6862                                              ,p_action_information17           =>     NVL(tab_24q_ee_data.income_tax,0) + NVL(tab_24q_ee_data.surcharge,0) + NVL(tab_24q_ee_data.education_cess,0)
6863                                              ,p_action_information18           =>     tab_liv_pe_data.tax_rate
6864                                              ,p_action_information19           =>     l_category
6865                                              ,p_action_information20           =>     l_action_context_id
6866                                              ,p_action_information21           =>     tab_24q_ee_data.income_tax
6867                                              ,p_action_information22           =>     tab_24q_ee_data.surcharge
6868                                              ,p_action_information23           =>     tab_24q_ee_data.education_cess
6869                                              ,p_action_information24           =>     tab_24q_ee_data.amount_deposited
6870                                              ,p_action_information25           =>     GREATEST(NVL(j,0),NVL(k,0))
6871                                              ,p_action_information_id          =>     l_action_info_id
6872                                              ,p_object_version_number          =>     l_ovn
6873                                              );
6874                        END IF;
6875                  END IF;
6876              END LOOP;
6877          END IF;
6878       IF (g_correction_mode <> 'C5')
6879       THEN
6880              pay_in_utils.set_location(g_debug,'Value of g_count_ee_addition : '|| g_count_ee_addition, 1);
6881              FOR i IN 1..g_count_ee_addition - 1
6882              LOOP
6883 
6884                 pay_in_utils.set_location(g_debug,'Checking archived presence of this added ee',1);
6885                 l_flag := -1;
6886 
6887                 l_flag := check_archival_status(g_ee_data_rec_add(i).element_entry_id,'IN_24QC_DEDUCTEE',NULL,'A');
6888                 IF (l_flag = 0)
6889                 THEN
6890                      pay_in_utils.set_location(g_debug,'Added EE Not Archived. hence doing '||g_ee_data_rec_add(i).element_entry_id,1);
6891 
6892                     IF (l_dummy <> pay_in_utils.get_ee_value(g_ee_data_rec_add(i).element_entry_id,'Challan or Voucher Number'))
6893                     THEN
6894                            s := 1;
6895                            l_dummy := pay_in_utils.get_ee_value(g_ee_data_rec_add(i).element_entry_id,'Challan or Voucher Number');
6896                     END IF;
6897 
6898                     pay_in_utils.set_location(g_debug,'Fetching element entry data  ', 1);
6899                     pay_in_utils.set_location(g_debug,'For Element Entry ID :  '|| g_ee_data_rec_add(i).element_entry_id,1);
6900                     pay_in_utils.set_location(g_debug,'Calling....get_element_entry_values ',1);
6901                     pay_in_utils.set_location(g_debug,'Assignment Action id is ' || g_ee_data_rec_add(i).last_action_context_id ,2);
6902                     pay_in_utils.set_location(g_debug,'Assignment id is ' || g_ee_data_rec_add(i).assignment_id,3);
6903                     get_element_entry_values
6904                      (
6905                        g_ee_data_rec_add(i).element_entry_id
6906                       ,g_ee_data_rec_add(i).last_action_context_id
6907                       ,g_ee_data_rec_add(i).assignment_id
6908                       ,tab_liv_ee_data
6909                       ,tab_24q_ee_data
6910                       ,tab_liv_pe_data
6911                       ,tab_24q_pe_data
6912                      );
6913                     pay_in_utils.set_location(g_debug,'Called....get_element_entry_values ',1);
6914                     pay_in_utils.set_location(g_debug,'Fetched element entry data  ', 1);
6915 
6916                     OPEN c_asg_act_id(g_ee_data_rec_add(i).assignment_id);
6917                     FETCH c_asg_act_id INTO l_arch_asg_action_id;
6918                     CLOSE c_asg_act_id;
6919 
6920                       j := -1;
6921                       k := -1;
6922                       pay_in_utils.set_location(g_debug,'Value of p_24qa_pay_act_id is ' || p_24qa_pay_act_id ,1);
6923                       pay_in_utils.set_location(g_debug,'Checking Challan Deductee Number in 24Q for ' || tab_liv_ee_data.challan_number,1);
6924                       OPEN  c_max_challan_number_24q(tab_liv_ee_data.challan_number);
6925                       FETCH c_max_challan_number_24q INTO k;
6926                       CLOSE c_max_challan_number_24q;
6927                       pay_in_utils.set_location(g_debug,'Number found is ' || k, 2);
6928                       pay_in_utils.set_location(g_debug,'Checking Challan Deductee Number in 24QC for ' || tab_liv_ee_data.challan_number,1);
6929                       OPEN  c_max_challan_number_24qc(tab_liv_ee_data.challan_number);
6930                       FETCH c_max_challan_number_24qc INTO j;
6931                       CLOSE c_max_challan_number_24qc;
6932                       pay_in_utils.set_location(g_debug,'Number found is ' || j, 2);
6933 
6934                       pay_action_information_api.create_action_information
6935                                   (p_action_context_id              =>     l_arch_asg_action_id
6936                                   ,p_action_context_type            =>     'AAP'
6937                                   ,p_action_information_category    =>     'IN_24QC_DEDUCTEE'
6938                                   ,p_source_id                      =>     g_ee_data_rec_add(i).element_entry_id
6939                                   ,p_assignment_id                  =>     g_ee_data_rec_add(i).assignment_id
6940                                   ,p_action_information1            =>     tab_liv_ee_data.challan_number
6941                                   ,p_action_information2            =>     g_year||g_quarter
6942                                   ,p_action_information3            =>     g_gre_id
6943                                   ,p_action_information4            =>     tab_liv_ee_data.payment_date
6944                                   ,p_action_information5            =>     tab_liv_ee_data.taxable_income
6945                                   ,p_action_information6            =>     tab_liv_ee_data.income_tax
6946                                   ,p_action_information7            =>     tab_liv_ee_data.surcharge
6947                                   ,p_action_information8            =>     tab_liv_ee_data.education_cess
6948                                   ,p_action_information9            =>     tab_liv_pe_data.pan_number
6949                                   ,p_action_information10           =>     tab_liv_pe_data.full_name
6950                                   ,p_action_information11           =>     tab_liv_pe_data.pan_ref_number
6951                                   ,p_action_information12           =>     tab_liv_pe_data.person_id
6952                                   ,p_action_information13           =>     NULL
6953                                   ,p_action_information14           =>     NULL
6954                                   ,p_action_information15           =>     'A'
6955                                   ,p_action_information16           =>     tab_liv_ee_data.amount_deposited
6956                                   ,p_action_information17           =>     NULL
6957                                   ,p_action_information18           =>     tab_liv_pe_data.tax_rate
6958                                   ,p_action_information19           =>     NULL
6959                                   ,p_action_information20           =>     NULL
6960                                   ,p_action_information21           =>     tab_24q_ee_data.income_tax
6961                                   ,p_action_information22           =>     tab_24q_ee_data.surcharge
6962                                   ,p_action_information23           =>     tab_24q_ee_data.education_cess
6963                                   ,p_action_information24           =>     tab_24q_ee_data.amount_deposited
6964                                   ,p_action_information25           =>     GREATEST(NVL(j,0),NVL(k,0))+ s
6965                                   ,p_action_information_id          =>     l_action_info_id
6966                                   ,p_object_version_number          =>     l_ovn
6967                                   );
6968                        s := s + 1;
6969                 END IF;
6970              END LOOP;
6971       END IF;
6972       pay_in_utils.set_location(g_debug,'Value of g_count_ee_update : '|| g_count_ee_update, 1);
6973       FOR i IN 1..g_count_ee_update - 1
6974       LOOP
6975          pay_in_utils.set_location(g_debug,'Checking archived presence of this updated ee',1);
6976          l_flag := -1;
6977 
6978          l_flag := check_archival_status(g_ee_data_rec_upd(i).element_entry_id,'IN_24QC_DEDUCTEE',NULL,'U');
6979          IF (l_flag = 0)
6980          THEN
6981               pay_in_utils.set_location(g_debug,'Updated EE Not Archived. hence doing '||g_ee_data_rec_upd(i).element_entry_id,1);
6982 
6983                pay_in_utils.set_location(g_debug,'Fetching element entries...',2);
6984                get_element_entry_values
6985                 (
6986                   g_ee_data_rec_upd(i).element_entry_id
6987                  ,g_ee_data_rec_upd(i).last_action_context_id
6988                  ,g_ee_data_rec_upd(i).assignment_id
6989                  ,tab_liv_ee_data
6990                  ,tab_24q_ee_data
6991                  ,tab_liv_pe_data
6992                  ,tab_24q_pe_data
6993                 );
6994 
6995                 pay_in_utils.set_location(g_debug,'Fetched element entries...',2);
6996                 pay_in_utils.set_location(g_debug,'Fetching Archival Assignment Action ID...',2);
6997                 pay_in_utils.set_location(g_debug,'Asg ID' ||   g_ee_data_rec_upd(i).assignment_id ,1);
6998                 pay_in_utils.set_location(g_debug,'Payroll Action id is ' || p_payroll_action_id ,1);
6999 
7000                 OPEN c_asg_act_id(g_ee_data_rec_upd(i).assignment_id);
7001                 FETCH c_asg_act_id INTO l_arch_asg_action_id;
7002                 CLOSE c_asg_act_id;
7003 
7004                  pay_in_utils.set_location(g_debug,'Archival Assignment Action ID is :'|| l_arch_asg_action_id ,2);
7005 
7006                  OPEN  c_deductee_number_24qc(tab_24q_ee_data.challan_number,g_ee_data_rec_upd(i).element_entry_id);
7007                  FETCH c_deductee_number_24qc INTO k;
7008                  CLOSE c_deductee_number_24qc;
7009 
7010                  OPEN  c_deductee_number_24q(tab_24q_ee_data.challan_number,g_ee_data_rec_upd(i).element_entry_id);
7011                  FETCH c_deductee_number_24q INTO j;
7012                  CLOSE c_deductee_number_24q;
7013 
7014                  pay_in_utils.set_location(g_debug,'Previous Challan Deductee Record Number was:' || j, 3);
7015 
7016                  pay_in_utils.set_location(g_debug,'New Challan Deductee Record Number is:' || k,4);
7017 --      if g_correction_mode = 'C5' and tab_24q_pe_data.pan_number IS VALID and
7018 --       tab_liv_pe_data.pan_number is also valid and not equal 2 each other
7019 --       then not only arhcive this assignment data, but also last organization PA data
7020 
7021               IF ((g_correction_mode IN('C3','C5','%'))
7022                    AND(tab_24q_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
7023                    AND(tab_liv_pe_data.pan_number NOT IN ('APPLIEDFOR','PANNOTAVBL'))
7024                    AND(tab_24q_pe_data.pan_number <> tab_liv_pe_data.pan_number)
7025                  )
7026               THEN
7027                       OPEN  c_c5_correction_type_details(g_ee_data_rec_upd(i).last_action_context_id);
7028                       FETCH c_c5_correction_type_details INTO l_action_information_category,l_action_context_id;
7029                       CLOSE c_c5_correction_type_details;
7030 
7031                       pay_in_utils.set_location(g_debug,'C5 Change Found!!!',1);
7032                       pay_in_utils.set_location(g_debug,'Checking C5 Change only',2);
7033                       pay_in_utils.set_location(g_debug,'EE ID '|| g_ee_data_rec_upd(i).element_entry_id,1);
7034                       pay_in_utils.set_location(g_debug,'Asg id '|| g_ee_data_rec_upd(i).assignment_id,2);
7035                       pay_in_utils.set_location(g_debug,'Act cntxt id '|| g_ee_data_rec_upd(i).last_action_context_id,3);
7036 
7037                       l_c5_change := check_c5_change_only(g_ee_data_rec_upd(i).element_entry_id
7038                                                          ,g_ee_data_rec_upd(i).last_action_context_id
7039                                                          ,g_ee_data_rec_upd(i).assignment_id
7040                                                          );
7041                      IF (l_c5_change)
7042                      THEN
7043                         IF (g_correction_mode IN ('%','C5'))
7044                         THEN
7045                              pay_in_utils.set_location(g_debug,'Only C5 Change!!!',3);
7046                              l_action_information_category := l_action_information_category || ':C5';
7047                         END IF;
7048                      ELSIF g_correction_mode = '%'
7049                      THEN
7050                         pay_in_utils.set_location(g_debug,'C3 and C5 Change is there!',4);
7051                         l_action_information_category := l_action_information_category || ':C3:C5';
7052                      ELSIF g_correction_mode = 'C5'
7053                      THEN
7054                         l_action_information_category := l_action_information_category || ':C5';
7055                      ELSE
7056                         l_action_information_category := l_action_information_category || ':C3';
7057                      END IF;
7058               ELSE
7059                       l_action_information_category := 'C3';
7060                       l_action_context_id           := NULL;
7061               END IF;
7062 
7063               pay_in_utils.set_location(g_debug,'l_action_information_category is '|| l_action_information_category,1);
7064 
7065               IF (INSTR(l_action_information_category,'C5')<> 0)AND(g_correction_mode IN ('%','C5'))
7066               THEN
7067                    pay_in_utils.set_location(g_debug,'Archiving C5 data for this deductee',1);
7068                    l_category := SUBSTR(l_action_information_category
7069                                        ,1
7070                                        ,INSTR(l_action_information_category,'G')
7071                                        );
7072                    l_category := l_category || 'C5';
7073 
7074                    pay_action_information_api.create_action_information
7075                                (p_action_context_id              =>     l_arch_asg_action_id
7076                                ,p_action_context_type            =>     'AAP'
7077                                ,p_action_information_category    =>     'IN_24QC_DEDUCTEE'
7078                                ,p_source_id                      =>     g_ee_data_rec_upd(i).element_entry_id
7079                                ,p_assignment_id                  =>     g_ee_data_rec_upd(i).assignment_id
7080                                ,p_action_information1            =>     tab_24q_ee_data.challan_number
7081                                ,p_action_information2            =>     g_year||g_quarter
7082                                ,p_action_information3            =>     g_gre_id
7083                                ,p_action_information4            =>     tab_24q_ee_data.payment_date
7084                                ,p_action_information5            =>     tab_24q_ee_data.taxable_income
7085                                ,p_action_information6            =>     tab_24q_ee_data.income_tax
7086                                ,p_action_information7            =>     tab_24q_ee_data.surcharge
7087                                ,p_action_information8            =>     tab_24q_ee_data.education_cess
7088                                ,p_action_information9            =>     tab_liv_pe_data.pan_number
7089                                ,p_action_information10           =>     tab_liv_pe_data.full_name
7090                                ,p_action_information11           =>     tab_liv_pe_data.pan_ref_number
7091                                ,p_action_information12           =>     tab_liv_pe_data.person_id
7092                                ,p_action_information13           =>     tab_24q_pe_data.pan_number
7093                                ,p_action_information14           =>     tab_24q_pe_data.pan_ref_number
7094                                ,p_action_information15           =>     'U'
7095                                ,p_action_information16           =>     tab_24q_ee_data.amount_deposited
7096                                ,p_action_information17           =>     NVL(tab_24q_ee_data.income_tax,0) + NVL(tab_24q_ee_data.surcharge,0) + NVL(tab_24q_ee_data.education_cess,0)
7097                                ,p_action_information18           =>     tab_liv_pe_data.tax_rate
7098                                ,p_action_information19           =>     l_category
7099                                ,p_action_information20           =>     l_action_context_id
7100                                ,p_action_information21           =>     tab_24q_ee_data.income_tax
7101                                ,p_action_information22           =>     tab_24q_ee_data.surcharge
7102                                ,p_action_information23           =>     tab_24q_ee_data.education_cess
7103                                ,p_action_information24           =>     tab_24q_ee_data.amount_deposited
7104                                ,p_action_information25           =>     GREATEST(NVL(j,0),NVL(k,0))
7105                                ,p_action_information_id          =>     l_action_info_id
7106                                ,p_object_version_number          =>     l_ovn
7107                                );
7108               END IF;
7109 
7110               IF (INSTR(l_action_information_category,'C3')<> 0)AND(g_correction_mode IN ('%','C3'))
7111               THEN
7112                    pay_in_utils.set_location(g_debug,'Archiving C3 data for this deductee',1);
7113                    l_category := SUBSTR(l_action_information_category
7114                                        ,1
7115                                        ,INSTR(l_action_information_category,'G')
7116                                        );
7117                    l_category := l_category || 'C3';
7118 
7119                    pay_action_information_api.create_action_information
7120                                 (p_action_context_id              =>     l_arch_asg_action_id
7121                                 ,p_action_context_type            =>     'AAP'
7122                                 ,p_action_information_category    =>     'IN_24QC_DEDUCTEE'
7123                                 ,p_source_id                      =>     g_ee_data_rec_upd(i).element_entry_id
7124                                 ,p_assignment_id                  =>     g_ee_data_rec_upd(i).assignment_id
7125                                 ,p_action_information1            =>     tab_liv_ee_data.challan_number
7126                                 ,p_action_information2            =>     g_year||g_quarter
7127                                 ,p_action_information3            =>     g_gre_id
7128                                 ,p_action_information4            =>     tab_liv_ee_data.payment_date
7129                                 ,p_action_information5            =>     tab_liv_ee_data.taxable_income
7130                                 ,p_action_information6            =>     tab_liv_ee_data.income_tax
7131                                 ,p_action_information7            =>     tab_liv_ee_data.surcharge
7132                                 ,p_action_information8            =>     tab_liv_ee_data.education_cess
7133                                 ,p_action_information9            =>     tab_liv_pe_data.pan_number
7134                                 ,p_action_information10           =>     tab_liv_pe_data.full_name
7135                                 ,p_action_information11           =>     tab_liv_pe_data.pan_ref_number
7136                                 ,p_action_information12           =>     tab_liv_pe_data.person_id
7137                                 ,p_action_information13           =>     tab_24q_pe_data.pan_number
7138                                 ,p_action_information14           =>     tab_24q_pe_data.pan_ref_number
7139                                 ,p_action_information15           =>     'U'
7140                                 ,p_action_information16           =>     tab_liv_ee_data.amount_deposited
7141                                 ,p_action_information17           =>     NVL(tab_24q_ee_data.income_tax,0) + NVL(tab_24q_ee_data.surcharge,0) + NVL(tab_24q_ee_data.education_cess,0)
7142                                 ,p_action_information18           =>     tab_liv_pe_data.tax_rate
7143                                 ,p_action_information19           =>     l_category
7144                                 ,p_action_information20           =>     l_action_context_id
7145                                 ,p_action_information21           =>     tab_24q_ee_data.income_tax
7146                                 ,p_action_information22           =>     tab_24q_ee_data.surcharge
7147                                 ,p_action_information23           =>     tab_24q_ee_data.education_cess
7148                                 ,p_action_information24           =>     tab_24q_ee_data.amount_deposited
7149                                 ,p_action_information25           =>     GREATEST(NVL(j,0),NVL(k,0))
7150                                 ,p_action_information_id          =>     l_action_info_id
7151                                 ,p_object_version_number          =>     l_ovn
7152                                 );
7153               END IF;
7154         END IF;
7155       END LOOP;
7156       pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.archive_deductee_data ', 5);
7157   EXCEPTION
7158     WHEN OTHERS THEN
7159       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
7160       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
7161   END archive_deductee_data;
7162 
7163   --------------------------------------------------------------------------
7164   --                                                                      --
7165   -- Name           : ARCHIVE_NO_CHANGE_CHALLAN                           --
7166   -- Type           : PROCEDURE                                           --
7167   -- Access         : Private                                             --
7168   -- Description    : Procedure to actually archive the data.             --
7169   -- Parameters     :                                                     --
7170   --             IN :                                                     --
7171   --            OUT : N/A                                                 --
7172   --                                                                      --
7173   -- Change History :                                                     --
7174   --------------------------------------------------------------------------
7175   -- Rev#  Date           Userid    Description                           --
7176   --------------------------------------------------------------------------
7177   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
7178   --------------------------------------------------------------------------
7179   PROCEDURE archive_no_change_challan(p_24qc_pay_act_id         NUMBER
7180                                      ,p_24qa_pay_act_id         NUMBER
7181                                      )
7182   IS
7183     CURSOR c_latest_correction_details(p_transfer_voucher_number VARCHAR2)
7184     IS
7185        SELECT  action_information13
7186               ,action_information14
7187               ,action_information17
7188               ,action_information25
7189               ,action_information_id
7190           FROM pay_action_information
7191          WHERE action_context_type         = 'PA'
7192            AND action_information_category = 'IN_24QC_CHALLAN'
7193            AND action_information15        = p_24qa_pay_act_id
7194            AND NVL(action_information4,'BOOK')||' - '||action_information1||' - '||to_char(fnd_date.canonical_to_date(action_information5),'DD-Mon-RRRR')         = p_transfer_voucher_number
7195            AND action_context_id IN(
7196                                     SELECT org_information3
7197                                       FROM hr_organization_information
7198                                      WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
7199                                        AND organization_id         = g_gre_id
7200                                        AND org_information1        = g_year
7201                                        AND org_information2        = g_quarter
7202                                        AND org_information5        = 'A'
7203                                        AND org_information6        = 'C'
7204                                    )
7205          ORDER BY action_information_id DESC;
7206 
7207     CURSOR c_24q_details(p_transfer_voucher_number VARCHAR2)
7208     IS
7209         SELECT action_information4      bank_code
7210               ,action_information5      payment_date
7211               , NVL(action_information6,0)
7212               + NVL(action_information7,0)
7213               + NVL(action_information8,0)
7214               + NVL(action_information9,0)
7215               + NVL(action_information10,0)
7216               ,action_information25
7217           FROM pay_action_information pai
7218          WHERE pai.action_context_type         = 'PA'
7219            AND pai.action_information_category = 'IN_24Q_CHALLAN'
7220            AND pai.action_context_id           = p_24qa_pay_act_id
7221            AND NVL(action_information4,'BOOK')||' - '||action_information1||' - '||to_char(fnd_date.canonical_to_date(action_information5),'DD-Mon-RRRR')         = p_transfer_voucher_number
7222          ORDER BY action_information_id DESC;
7223 
7224     CURSOR c_populate_no_change_data
7225     IS
7226       SELECT hoi.org_information3           challan_number,
7227              hoi.org_information2           transfer_voucher_date,
7228              hoi.org_information4           amount,
7229              hoi.org_information7           surcharge,
7230              hoi.org_information8           education_cess,
7231              hoi.org_information10          other,
7232              hoi.org_information9           interest,
7233              (SELECT hoi_bank.org_information4
7234                FROM hr_organization_information hoi_bank
7235               WHERE hoi_bank.organization_id = g_gre_id
7236                 AND hoi_bank.org_information_context = 'PER_IN_CHALLAN_BANK'
7237                 AND hoi_bank.org_information_id = hoi.org_information5
7238              )                              bank_branch_code,
7239              hoi.org_information11          cheque_dd_num,
7240              hoi.org_information12          book_entry,
7241              hoi.org_information_id         org_information_id
7242         FROM hr_organization_information hoi
7243        WHERE hoi.org_information_id IN
7244        (
7245             SELECT hoi.org_information_id
7246               FROM hr_organization_information hoi
7247                   ,hr_organization_units hou
7248              WHERE hoi.organization_id     = g_gre_id
7249                AND  hoi.organization_id    = hou.organization_id
7250                AND  hou.business_group_id  = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
7251                AND org_information_context = 'PER_IN_IT_CHALLAN_INFO'
7252        )
7253          AND hoi.org_information13 = g_quarter
7254          AND hoi.org_information1  = g_tax_year;
7255 
7256         l_flag                           BOOLEAN;
7257         l_action_information_id          NUMBER;
7258         l_pre_bank_branch_code           VARCHAR2(150);
7259         l_pre_transfer_voucher_date      VARCHAR2(150);
7260         l_previous_total_amount          NUMBER;
7261         l_challan_deductee_no            NUMBER;
7262         l_action_info_id                 NUMBER;
7263         l_ovn                            NUMBER;
7264         l_flag_number                    NUMBER := -1;
7265         l_procedure                      VARCHAR2(250);
7266         l_message                        VARCHAR2(250);
7267     BEGIN
7268        g_debug     := hr_utility.debug_enabled;
7269        l_procedure := g_package ||'.archive_no_change_challan';
7270        pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
7271        FOR c_rec IN c_populate_no_change_data
7272        LOOP
7273           l_flag := TRUE;
7274 
7275          pay_in_utils.set_location(g_debug,'Checking in Added Challans ', 1);
7276           -- Checking in Added Challans
7277           FOR i IN 1..g_count_challan_add - 1
7278           LOOP
7279              IF( (g_challan_data_add(i).transfer_voucher_number = NVL(c_rec.bank_branch_code,'BOOK')||' - '||c_rec.challan_number||' - '||to_char(fnd_date.canonical_to_date(c_rec.transfer_voucher_date),'DD-Mon-RRRR') )
7280                 OR
7281                  (g_challan_data_add(i).org_information_id      = c_rec.org_information_id)
7282                )
7283              THEN
7284                   l_flag := FALSE;
7285              END IF;
7286           END LOOP;
7287 
7288           pay_in_utils.set_location(g_debug,'Checking in Updated Challans ', 1);
7289           FOR i IN 1..g_count_challan_upd - 1
7290           LOOP
7291              IF ((g_challan_data_upd(i).transfer_voucher_number = NVL(c_rec.bank_branch_code,'BOOK')||' - '||c_rec.challan_number||' - '||to_char(fnd_date.canonical_to_date(c_rec.transfer_voucher_date),'DD-Mon-RRRR') )
7292              OR
7293                  (g_challan_data_upd(i).org_information_id      = c_rec.org_information_id)
7294                 )
7295              THEN
7296                   l_flag := FALSE;
7297              END IF;
7298           END LOOP;
7299           --Insert Record in PL/SQL Table for no change Challans
7300           IF (l_flag)
7301           THEN
7302                 g_challan_data_noc(g_count_challan_noc).transfer_voucher_number := NVL(c_rec.bank_branch_code,'BOOK')||' - '||c_rec.challan_number||' - '||to_char(fnd_date.canonical_to_date(c_rec.transfer_voucher_date),'DD-Mon-RRRR') ;
7303                 g_challan_data_noc(g_count_challan_noc).transfer_voucher_date   := c_rec.transfer_voucher_date;
7304                 g_challan_data_noc(g_count_challan_noc).amount                  := c_rec.amount;
7305                 g_challan_data_noc(g_count_challan_noc).surcharge               := c_rec.surcharge;
7306                 g_challan_data_noc(g_count_challan_noc).education_cess          := c_rec.education_cess;
7307                 g_challan_data_noc(g_count_challan_noc).interest                := c_rec.interest;
7308                 g_challan_data_noc(g_count_challan_noc).other                   := c_rec.other;
7309                 g_challan_data_noc(g_count_challan_noc).bank_branch_code        := c_rec.bank_branch_code;
7310                 g_challan_data_noc(g_count_challan_noc).cheque_dd_num           := c_rec.cheque_dd_num;
7311                 g_challan_data_noc(g_count_challan_noc).org_information_id      := c_rec.org_information_id;
7312                 g_challan_data_noc(g_count_challan_noc).modes                   := 'NC';
7313                 g_challan_data_noc(g_count_challan_noc).book_entry              := c_rec.book_entry;
7314                 g_count_challan_noc := g_count_challan_noc + 1;
7315           END IF;
7316        END LOOP;
7317 
7318        FOR i IN 1..g_count_challan_noc - 1
7319        LOOP
7320          pay_in_utils.set_location(g_debug,'Checking Challan no change status',1);
7321          l_flag_number := -1;
7322          l_flag_number := check_archival_status(NULL,'IN_24QC_CHALLAN',g_challan_data_noc(i).transfer_voucher_number,NULL);
7323          IF (l_flag_number = 0 AND g_correction_mode <> 'C5')
7324          THEN
7325                       pay_in_utils.set_location(g_debug,'Fetching details from 24Q Correction Archival',2);
7326                       pay_in_utils.set_location(g_debug,'Fetching details from 24Q Correction Archival for g_challan_data_noc(i).transfer_voucher_number' || g_challan_data_noc(i).transfer_voucher_number,2);
7327                       OPEN  c_latest_correction_details(g_challan_data_noc(i).transfer_voucher_number);
7328                       FETCH c_latest_correction_details INTO  l_pre_bank_branch_code
7329                                                              ,l_pre_transfer_voucher_date
7330                                                              ,l_previous_total_amount
7331                                                              ,l_challan_deductee_no
7332                                                              ,l_action_information_id;
7333                       CLOSE c_latest_correction_details;
7334                       pay_in_utils.set_location(g_debug,'Fetched details from 24Q Correction Archival',2);
7335                       pay_in_utils.set_location(g_debug,'l_pre_bank_branch_code      '|| l_pre_bank_branch_code      ,3);
7336                       pay_in_utils.set_location(g_debug,'l_pre_transfer_voucher_date '|| l_pre_transfer_voucher_date ,3);
7337                       pay_in_utils.set_location(g_debug,'l_previous_total_amount     '|| l_previous_total_amount     ,3);
7338                       pay_in_utils.set_location(g_debug,'l_challan_deductee_no       '|| l_challan_deductee_no       ,3);
7339                       pay_in_utils.set_location(g_debug,'l_action_information_id     '|| l_action_information_id     ,3);
7340 
7341 
7342                       IF (l_action_information_id IS NULL)
7343                       THEN
7344                                 pay_in_utils.set_location(g_debug,'Fetching details from 24Q Archival',2);
7345                                 pay_in_utils.set_location(g_debug,'Fetching details from 24Q Correction Archival for g_challan_data_noc(i).transfer_voucher_number' || g_challan_data_noc(i).transfer_voucher_number,2);
7346                                 OPEN  c_24q_details(g_challan_data_noc(i).transfer_voucher_number);
7347                                 FETCH c_24q_details INTO l_pre_bank_branch_code
7348                                                         ,l_pre_transfer_voucher_date
7349                                                         ,l_previous_total_amount
7350                                                         ,l_challan_deductee_no;
7351                                 CLOSE c_24q_details;
7352                                 pay_in_utils.set_location(g_debug,'Fetched details from 24Q Correction Archival',2);
7353                                 pay_in_utils.set_location(g_debug,'l_pre_bank_branch_code      '|| l_pre_bank_branch_code      ,3);
7354                                 pay_in_utils.set_location(g_debug,'l_pre_transfer_voucher_date '|| l_pre_transfer_voucher_date ,3);
7355                                 pay_in_utils.set_location(g_debug,'l_previous_total_amount     '|| l_previous_total_amount     ,3);
7356                                 pay_in_utils.set_location(g_debug,'l_challan_deductee_no       '|| l_challan_deductee_no       ,3);
7357                                 pay_in_utils.set_location(g_debug,'l_action_information_id     '|| l_action_information_id     ,3);
7358                       END IF;
7359                       -- Now Archive these details
7360                          pay_action_information_api.create_action_information
7361                                     (p_action_context_id              =>     p_24qc_pay_act_id
7362                                     ,p_action_context_type            =>     'PA'
7363                                     ,p_action_information_category    =>     'IN_24QC_CHALLAN'
7364                                     ,p_source_id                      =>     g_challan_data_noc(i).org_information_id
7365                                     ,p_action_information1            =>     g_challan_data_noc(i).transfer_voucher_number
7366                                     ,p_action_information2            =>     g_year||g_quarter
7367                                     ,p_action_information3            =>     g_gre_id
7368                                     ,p_action_information4            =>     g_challan_data_noc(i).bank_branch_code
7369                                     ,p_action_information5            =>     g_challan_data_noc(i).transfer_voucher_date
7370                                     ,p_action_information6            =>     g_challan_data_noc(i).amount
7371                                     ,p_action_information7            =>     g_challan_data_noc(i).surcharge
7372                                     ,p_action_information8            =>     g_challan_data_noc(i).education_cess
7373                                     ,p_action_information9            =>     g_challan_data_noc(i).interest
7374                                     ,p_action_information10           =>     g_challan_data_noc(i).other
7375                                     ,p_action_information11           =>     g_challan_data_noc(i).cheque_dd_num
7376                                     ,p_action_information12           =>     g_challan_data_noc(i).transfer_voucher_number
7377                                     ,p_action_information13           =>     l_pre_bank_branch_code
7378                                     ,p_action_information14           =>     l_pre_transfer_voucher_date
7379                                     ,p_action_information15           =>     p_24qa_pay_act_id
7380                                     ,p_action_information16           =>     g_challan_data_noc(i).book_entry
7381                                     ,p_action_information17           =>     l_previous_total_amount
7382                                     ,p_action_information18           =>     'NC'
7383                                     ,p_action_information19           =>     update_challans(g_challan_data_noc(i).transfer_voucher_number)
7384                                     ,p_action_information25           =>     l_challan_deductee_no
7385                                     ,p_action_information_id          =>     l_action_info_id
7386                                     ,p_object_version_number          =>     l_ovn
7387                                     );
7388           END IF;
7389        END LOOP;
7390        pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.archive_no_change_challan ', 5);
7391   EXCEPTION
7392     WHEN OTHERS THEN
7393       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
7394       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
7395     END archive_no_change_challan;
7396   --------------------------------------------------------------------------
7397   --                                                                      --
7398   -- Name           : ARCHIVE_CHALLAN_DATA                                --
7399   -- Type           : PROCEDURE                                           --
7400   -- Access         : Public                                              --
7401   -- Description    : Procedure to actually archive the data.             --
7402   -- Parameters     :                                                     --
7403   --             IN :                                                     --
7404   --            OUT : N/A                                                 --
7405   --                                                                      --
7406   -- Change History :                                                     --
7407   --------------------------------------------------------------------------
7408   -- Rev#  Date           Userid    Description                           --
7409   --------------------------------------------------------------------------
7410   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
7411   --------------------------------------------------------------------------
7412 PROCEDURE archive_challan_data(p_24qc_pay_act_id   NUMBER
7413                                 ,p_24qa_pay_act_id   NUMBER
7414                                 )
7415   IS
7416     CURSOR c_challan_live_data(p_challan_number         VARCHAR2
7417                               ,p_org_information_id     VARCHAR2
7418                               )
7419     IS
7420       SELECT hoi.org_information3           challan_number,
7421              hoi.org_information2           transfer_voucher_date,
7422              hoi.org_information4           amount,
7423              hoi.org_information7           surcharge,
7424              hoi.org_information8           education_cess,
7425              hoi.org_information10          other,
7426              hoi.org_information9           interest,
7427              (SELECT hoi_bank.org_information4
7428                FROM hr_organization_information hoi_bank
7429               WHERE hoi_bank.organization_id = g_gre_id
7430                 AND hoi_bank.org_information_context = 'PER_IN_CHALLAN_BANK'
7431                 AND hoi_bank.org_information_id = hoi.org_information5
7432              )                              bank_branch_code,
7433              hoi.org_information11          cheque_dd_num,
7434              hoi.org_information12          book_entry,
7435              hoi.org_information_id         org_information_id
7436         FROM hr_organization_information hoi
7437        WHERE hoi.org_information_id IN
7438        (
7439             SELECT hoi.org_information_id
7440               FROM hr_organization_information hoi
7441                   ,hr_organization_units hou
7442              WHERE hoi.organization_id     = g_gre_id
7443                AND  hoi.organization_id    = hou.organization_id
7444                AND  hou.business_group_id  = FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID')
7445                AND org_information_context = 'PER_IN_IT_CHALLAN_INFO'
7446        )
7447          AND hoi.org_information13 = g_quarter
7448          AND hoi.org_information1  = g_tax_year
7449          AND (
7450                (hoi.org_information3   = SUBSTR(p_challan_number ,INSTR (p_challan_number, ' -',1,1)+3,(INSTR (p_challan_number, ' -',1,2)-(INSTR (p_challan_number, ' -',1,1)+3))))
7451              OR
7452                (hoi.org_information_id = p_org_information_id)
7453              );
7454 
7455     l_transfer_voucher_number     hr_organization_information.org_information3%TYPE;
7456     l_transfer_voucher_date       hr_organization_information.org_information2%TYPE;
7457     l_amount                      hr_organization_information.org_information4%TYPE;
7458     l_surcharge                   hr_organization_information.org_information7%TYPE;
7459     l_education_cess              hr_organization_information.org_information8%TYPE;
7460     l_others                      hr_organization_information.org_information10%TYPE;
7461     l_interest                    hr_organization_information.org_information9%TYPE;
7462     l_bank_branch_code            hr_organization_information.org_information4%TYPE;
7463     l_cheque_dd_num               hr_organization_information.org_information11%TYPE;
7464     l_book_entry                  hr_organization_information.org_information12%TYPE;
7465     l_org_information_id          NUMBER;
7466     l_previous_total_amount       NUMBER;
7467     l_challan_record_number       NUMBER;
7468     l_action_info_id              NUMBER;
7469     l_ovn                         NUMBER;
7470     j                             NUMBER;
7471     k                             NUMBER;
7472     l_flag                        NUMBER := -1;
7473     l_procedure                   VARCHAR2(250);
7474     l_message                     VARCHAR2(250);
7475    BEGIN
7476         g_debug     := hr_utility.debug_enabled;
7477         l_procedure := g_package ||'.archive_challan_data';
7478         pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
7479         pay_in_utils.set_location(g_debug,'Fetching Challan Data ', 1);
7480         BEGIN
7481              SELECT MAX(TO_NUMBER(action_information25))
7482                INTO j
7483                FROM pay_action_information
7484               WHERE action_information_category = 'IN_24Q_CHALLAN'
7485                 AND action_information3         = g_gre_id
7486                 AND action_information2         = g_year||g_quarter
7487                 AND action_context_id           = p_24qa_pay_act_id
7488                 AND action_context_id           IN(
7489                                                    SELECT org_information3
7490                                                      FROM hr_organization_information
7491                                                     WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
7492                                                       AND organization_id  = g_gre_id
7493                                                       AND org_information1 = g_year
7494                                                       AND org_information2 = g_quarter
7495                                                       AND org_information5 = 'A'
7496                                                       AND org_information6 = 'O'
7497                                                     );
7498 
7499              pay_in_utils.set_location(g_debug,'Addition:Value of j is : '|| j ,1);
7500              SELECT MAX(TO_NUMBER(action_information25))
7501                INTO k
7502                FROM pay_action_information
7503               WHERE action_information_category = 'IN_24QC_CHALLAN'
7504                 AND action_information3         = g_gre_id
7505                 AND action_information2         = g_year||g_quarter
7506                 AND action_information15        = p_24qa_pay_act_id
7507                 AND action_context_id           IN(
7508                                                    SELECT org_information3
7509                                                      FROM hr_organization_information
7510                                                     WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
7511                                                       AND organization_id  = g_gre_id
7512                                                       AND org_information1 = g_year
7513                                                       AND org_information2 = g_quarter
7514                                                       AND org_information5 = 'A'
7515                                                       AND org_information6 = 'C'
7516                                                     );
7517            EXCEPTION
7518                 WHEN OTHERS THEN
7519                         NULL;
7520            END;
7521 
7522            pay_in_utils.set_location(g_debug,'Value of k is : '|| k ,1);
7523            l_challan_record_number := GREATEST(NVL(j,0),NVL(k,0));
7524 
7525           pay_in_utils.set_location(g_debug,'Value of l_challan_record_number is : '|| l_challan_record_number ,1);
7526 
7527    --if C9 only new Challans would (addition/Insert) be archived
7528     IF (g_correction_mode IN ('C9','%'))
7529     THEN
7530       FOR i IN 1.. g_count_challan_add - 1
7531         LOOP
7532              pay_in_utils.set_location(g_debug,'Checking archived presence of this added challan',1);
7533              l_flag := -1;
7534 
7535              l_flag := check_archival_status(NULL,'IN_24QC_CHALLAN',g_challan_data_add(i).transfer_voucher_number,NULL);
7536              IF (l_flag = 0)
7537              THEN
7538                       pay_in_utils.set_location(g_debug,'Archiving added challan ' || g_challan_data_add(i).transfer_voucher_number,1);
7539                       pay_in_utils.set_location(g_debug,'Fetching Live Data ' ,1);
7540                       OPEN  c_challan_live_data(g_challan_data_add(i).transfer_voucher_number,g_challan_data_add(i).org_information_id);
7541                       FETCH c_challan_live_data INTO l_transfer_voucher_number,
7542                                                      l_transfer_voucher_date,
7543                                                      l_amount,
7544                                                      l_surcharge,
7545                                                      l_education_cess,
7546                                                      l_others,
7547                                                      l_interest,
7548                                                      l_bank_branch_code,
7549                                                      l_cheque_dd_num,
7550                                                      l_book_entry,
7551                                                      l_org_information_id;
7552                       CLOSE c_challan_live_data;
7553                       pay_in_utils.set_location(g_debug,'Fetched Live Data ' ,1);
7554 
7555                       pay_in_utils.set_location(g_debug,'Archiving Data ' ,1);
7556                       pay_action_information_api.create_action_information
7557                                  (p_action_context_id              =>     p_24qc_pay_act_id
7558                                  ,p_action_context_type            =>     'PA'
7559                                  ,p_action_information_category    =>     'IN_24QC_CHALLAN'
7560                                  ,p_source_id                      =>     g_challan_data_add(i).org_information_id
7561                                  ,p_action_information1            =>     g_challan_data_add(i).transfer_voucher_number
7562                                  ,p_action_information2            =>     g_year||g_quarter
7563                                  ,p_action_information3            =>     g_gre_id
7564                                  ,p_action_information4            =>     g_challan_data_add(i).bank_branch_code
7565                                  ,p_action_information5            =>     g_challan_data_add(i).transfer_voucher_date
7566                                  ,p_action_information6            =>     NVL(g_challan_data_add(i).amount,0)
7567                                  ,p_action_information7            =>     NVL(g_challan_data_add(i).surcharge,0)
7568                                  ,p_action_information8            =>     NVL(g_challan_data_add(i).education_cess,0)
7569                                  ,p_action_information9            =>     NVL(g_challan_data_add(i).interest,0)
7570                                  ,p_action_information10           =>     NVL(g_challan_data_add(i).other,0)
7571                                  ,p_action_information11           =>     g_challan_data_add(i).cheque_dd_num
7572                                  ,p_action_information12           =>     NULL
7573                                  ,p_action_information13           =>     NULL
7574                                  ,p_action_information14           =>     NULL
7575                                  ,p_action_information15           =>     p_24qa_pay_act_id
7576                                  ,p_action_information16           =>     l_book_entry
7577                                  ,p_action_information17           =>     NULL
7578                                  ,p_action_information18           =>     'A'
7579                                  ,p_action_information19           =>     update_challans(g_challan_data_add(i).transfer_voucher_number)
7580                                  ,p_action_information25           =>     l_challan_record_number + i
7581                                  ,p_action_information_id          =>     l_action_info_id
7582                                  ,p_object_version_number          =>     l_ovn
7583                                  );
7584            END IF;
7585         END LOOP;
7586    END IF;
7587 
7588    pay_in_utils.set_location(g_debug,'Fetching Updated Challan Data ' ,1);
7589  --C2,C3 then archive only updated Challans
7590  --Later need to archive all those challans that have undergone no change under C3
7591     IF (g_correction_mode IN ('C2','C3','%'))
7592     THEN
7593       FOR i IN 1.. g_count_challan_upd - 1
7594         LOOP
7595              pay_in_utils.set_location(g_debug,'Checking archived presence of this updated challan',1);
7596              l_flag := -1;
7597 
7598              l_flag := check_archival_status(NULL,'IN_24QC_CHALLAN',g_challan_data_upd(i).transfer_voucher_number,NULL);
7599              IF (l_flag = 0)
7600              THEN
7601 
7602                         j := -1;
7603                         k := -1;
7604                         BEGIN
7605                               SELECT DISTINCT action_information25
7606                                 INTO j
7607                                 FROM pay_action_information
7608                                WHERE action_information_category = 'IN_24Q_CHALLAN'
7609                                  AND action_information3         = g_gre_id
7610                                  AND action_information2         = g_year||g_quarter
7611                                  AND action_context_id           = p_24qa_pay_act_id
7612                                  AND(action_information1         = g_challan_data_upd(i).transfer_voucher_number
7613                                     OR
7614                                      source_id                   = g_challan_data_upd(i).org_information_id
7615                                     )
7616                                  AND p_24qa_pay_act_id IN(
7617                                                          SELECT org_information3
7618                                                            FROM hr_organization_information
7619                                                           WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
7620                                                             AND organization_id  = g_gre_id
7621                                                             AND org_information1 = g_year
7622                                                             AND org_information2 = g_quarter
7623                                                             AND org_information5 = 'A'
7624                                                             AND org_information6 = 'O'
7625                                                           );
7626                           EXCEPTION
7627                                    WHEN OTHERS THEN
7628                                            NULL;
7629                           END;
7630                           pay_in_utils.set_location(g_debug,'Updation:Value of j is : '|| j ,1);
7631 
7632                         BEGIN
7633                             SELECT DISTINCT action_information25
7634                               INTO k
7635                               FROM pay_action_information
7636                              WHERE action_information_category = 'IN_24QC_CHALLAN'
7637                                AND action_information3         = g_gre_id
7638                                AND action_information2         = g_year||g_quarter
7639                                AND action_context_id           = p_24qa_pay_act_id
7640                                AND(action_information1         = g_challan_data_upd(i).transfer_voucher_number
7641                                   OR
7642                                    source_id                   = g_challan_data_upd(i).org_information_id
7643                                   )
7644                               AND action_information15 IN(
7645                                                        SELECT org_information3
7646                                                          FROM hr_organization_information
7647                                                         WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
7648                                                           AND organization_id  = g_gre_id
7649                                                           AND org_information1 = g_year
7650                                                           AND org_information2 = g_quarter
7651                                                           AND org_information5 = 'A'
7652                                                           AND org_information6 = 'C'
7653                                                         );
7654                          EXCEPTION
7655                              WHEN OTHERS THEN
7656                                    NULL;
7657                          END;
7658                            pay_in_utils.set_location(g_debug,'Value of k is : '|| k ,1);
7659 
7660                         l_challan_record_number := GREATEST(j,k);
7661 
7662                         pay_in_utils.set_location(g_debug,'Value of l_challan_record_number is : '|| l_challan_record_number ,1);
7663 
7664                         OPEN  c_challan_live_data(g_challan_data_upd(i).transfer_voucher_number,g_challan_data_upd(i).org_information_id);
7665                         FETCH c_challan_live_data INTO l_transfer_voucher_number,
7666                                                        l_transfer_voucher_date,
7667                                                        l_amount,
7668                                                        l_surcharge,
7669                                                        l_education_cess,
7670                                                        l_others,
7671                                                        l_interest,
7672                                                        l_bank_branch_code,
7673                                                        l_cheque_dd_num,
7674                                                        l_book_entry,
7675                                                        l_org_information_id;
7676                         CLOSE c_challan_live_data;
7677 
7678                         l_previous_total_amount  := NVL(g_challan_data_upd(i).amount,0)
7679                                                   + NVL(g_challan_data_upd(i).surcharge,0)
7680                                                   + NVL(g_challan_data_upd(i).education_cess,0)
7681                                                   + NVL(g_challan_data_upd(i).interest,0)
7682                                                   + NVL(g_challan_data_upd(i).other,0);
7683 
7684                         pay_action_information_api.create_action_information
7685                                    (p_action_context_id              =>     p_24qc_pay_act_id
7686                                    ,p_action_context_type            =>     'PA'
7687                                    ,p_action_information_category    =>     'IN_24QC_CHALLAN'
7688                                    ,p_source_id                      =>     l_org_information_id
7689                                    ,p_action_information1            =>     NVL(l_bank_branch_code,'BOOK')||' - '||l_transfer_voucher_number||' - '||to_char(fnd_date.canonical_to_date(l_transfer_voucher_date),'DD-Mon-RRRR')
7690                                    ,p_action_information2            =>     g_year||g_quarter
7691                                    ,p_action_information3            =>     g_gre_id
7692                                    ,p_action_information4            =>     l_bank_branch_code
7693                                    ,p_action_information5            =>     l_transfer_voucher_date
7694                                    ,p_action_information6            =>     l_amount
7695                                    ,p_action_information7            =>     l_surcharge
7696                                    ,p_action_information8            =>     l_education_cess
7697                                    ,p_action_information9            =>     l_interest
7698                                    ,p_action_information10           =>     l_others
7699                                    ,p_action_information11           =>     l_cheque_dd_num
7700                                    ,p_action_information12           =>     g_challan_data_upd(i).transfer_voucher_number
7701                                    ,p_action_information13           =>     g_challan_data_upd(i).bank_branch_code
7702                                    ,p_action_information14           =>     g_challan_data_upd(i).transfer_voucher_date
7703                                    ,p_action_information15           =>     p_24qa_pay_act_id
7704                                    ,p_action_information16           =>     l_book_entry
7705                                    ,p_action_information17           =>     l_previous_total_amount
7706                                    ,p_action_information18           =>     'U'
7707                                    ,p_action_information19           =>     update_challans(g_challan_data_upd(i).transfer_voucher_number)
7708                                    ,p_action_information25           =>     l_challan_record_number
7709                                    ,p_action_information_id          =>     l_action_info_id
7710                                    ,p_object_version_number          =>     l_ovn
7711                                    );
7712              END IF;
7713         END LOOP;
7714     END IF;
7715     IF (g_correction_mode IN ('C3','C5','%'))
7716     THEN
7717         pay_in_utils.set_location(g_debug,'Starting Archival of no change challans ',1);
7718         archive_no_change_challan(p_24qc_pay_act_id,p_24qa_pay_act_id);
7719     END IF;
7720     pay_in_utils.set_location(g_debug,'Leaving '|| g_package||'.archive_challan_data ',1);
7721   EXCEPTION
7722     WHEN OTHERS THEN
7723       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
7724       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
7725    END archive_challan_data;
7726 
7727 
7728   --------------------------------------------------------------------------
7729   --                                                                      --
7730   -- Name           : ARCHIVE_CANCELLATION_DATA                           --
7731   -- Type           : PROCEDURE                                           --
7732   -- Access         : Private                                             --
7733   -- Description    : Procedure to actually archive the data.             --
7734   -- Parameters     :                                                     --
7735   --             IN :                                                     --
7736   --            OUT : N/A                                                 --
7737   --                                                                      --
7738   -- Change History :                                                     --
7739   --------------------------------------------------------------------------
7740   -- Rev#  Date           Userid    Description                           --
7741   --------------------------------------------------------------------------
7742   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
7743   --------------------------------------------------------------------------
7744   PROCEDURE archive_cancellation_data(p_payroll_action_id       NUMBER)
7745   IS
7746     CURSOR c_get_act_ctxt_id
7747     IS
7748        SELECT org_information3
7749          FROM hr_organization_information
7750         WHERE org_information_context  = 'PER_IN_FORM24Q_RECEIPT_DF'
7751           AND organization_id          = g_gre_id
7752           AND org_information1         = g_year
7753           AND org_information4         = g_cancel_ref_number;
7754 
7755     CURSOR c_get_last_stmt_details(p_action_context_id  NUMBER)
7756     IS
7757        SELECT action_information2
7758              ,action_information5
7759              ,action_information7
7760              ,DECODE(action_information_category,'IN_24Q_ORG',action_information21,action_information7)
7761          FROM pay_action_information
7762         WHERE action_context_id = p_action_context_id
7763           AND action_information_category LIKE 'IN_24Q%ORG'
7764           AND action_context_type = 'PA';
7765 
7766     l_action_context_id          NUMBER;
7767     l_tan_number                 VARCHAR2(250);
7768     l_legal_name                 VARCHAR2(250);
7769     l_deductor_type              VARCHAR2(250);
7770     l_emplr_type                 VARCHAR2(250);
7771     l_emplr_type_24Q             VARCHAR2(250);
7772     l_action_info_id             NUMBER;
7773     l_ovn                        NUMBER;
7774     l_procedure                  VARCHAR2(250);
7775     l_message                    VARCHAR2(250);
7776   BEGIN
7777         g_debug     := hr_utility.debug_enabled;
7778         l_procedure := g_package ||'.archive_cancellation_data';
7779         pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
7780         pay_in_utils.set_location(g_debug,'In this procedure archive only Name ',2);
7781         pay_in_utils.set_location(g_debug,'and Deductor type and that too as per ',3);
7782         pay_in_utils.set_location(g_debug,'the receipt number passed in concurrent ',4);
7783         pay_in_utils.set_location(g_debug,'Program parameters ',5);
7784         pay_in_utils.set_location(g_debug,'Fetching Action Context ID ',5);
7785 
7786         OPEN  c_get_act_ctxt_id;
7787         FETCH c_get_act_ctxt_id INTO l_action_context_id;
7788         CLOSE c_get_act_ctxt_id;
7789 
7790         OPEN  c_get_last_stmt_details(l_action_context_id);
7791         FETCH c_get_last_stmt_details INTO l_tan_number
7792                                           ,l_legal_name
7793                                           ,l_emplr_type
7794                                           ,l_emplr_type_24Q;
7795         CLOSE c_get_last_stmt_details;
7796 
7797         IF g_old_format = 'Y' THEN
7798         l_deductor_type := l_emplr_type;
7799         ELSE
7800         l_deductor_type := l_emplr_type_24Q;
7801         END IF;
7802 
7803         pay_in_utils.set_location(g_debug,'Action Context ID is: ' || l_action_context_id, 6);
7804         pay_in_utils.set_location(g_debug,'TAN Number is       : ' || l_tan_number,7);
7805         pay_in_utils.set_location(g_debug,'Legal Name is       : ' || l_legal_name,8);
7806         pay_in_utils.set_location(g_debug,'Deductor Type is    : ' || l_deductor_type,9);
7807 
7808         pay_in_utils.set_location(g_debug,'Archiving Data ', 9);
7809 
7810         pay_action_information_api.create_action_information
7811                   (p_action_context_id              =>     p_payroll_action_id
7812                   ,p_action_context_type            =>     'PA'
7813                   ,p_action_information_category    =>     'IN_24QC_ORG'
7814                   ,p_source_id                      =>     l_action_context_id
7815                   ,p_action_information1            =>     g_gre_id
7816                   ,p_action_information2            =>     l_tan_number
7817                   ,p_action_information3            =>     g_year||g_quarter
7818                   ,p_action_information4            =>     NULL
7819                   ,p_action_information5            =>     l_legal_name
7820                   ,p_action_information6            =>     NULL
7821                   ,p_action_information7            =>     l_deductor_type
7822                   ,p_action_information8            =>     NULL
7823                   ,p_action_information9            =>     NULL
7824                   ,p_action_information10           =>     NULL
7825                   ,p_action_information11           =>     NULL
7826                   ,p_action_information12           =>     NULL
7827                   ,p_action_information13           =>     NULL
7828                   ,p_action_information14           =>     NULL
7829                   ,p_action_information15           =>     NULL
7830                   ,p_action_information16           =>     NULL
7831                   ,p_action_information17           =>     NULL
7832                   ,p_action_information18           =>     NULL
7833                   ,p_action_information19           =>     NULL
7834                   ,p_action_information30           =>     g_24qc_reference
7835                   ,p_action_information25           =>     NULL
7836                   ,p_action_information26           =>     NULL
7837                   ,p_action_information29           =>     'Y'
7838 		  ,p_action_information20           =>     NULL
7839                   ,p_action_information21           =>     NULL
7840                   ,p_action_information22           =>     NULL
7841                   ,p_action_information23           =>     NULL
7842                   ,p_action_information24           =>     NULL
7843                   ,p_action_information27           =>     NULL
7844                   ,p_action_information28           =>     NULL
7845                   ,p_action_information_id          =>     l_action_info_id
7846                   ,p_object_version_number          =>     l_ovn
7847                   );
7848 
7849         pay_in_utils.set_location(g_debug,'Leaving: '|| g_package||'.archive_cancellation_data', 1);
7850   EXCEPTION
7851     WHEN OTHERS THEN
7852       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
7853       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
7854   END archive_cancellation_data;
7855 
7856   --------------------------------------------------------------------------
7857   --                                                                      --
7858   -- Name           : ARCHIVE_ORGANIZATION_DATA                           --
7859   -- Type           : PROCEDURE                                           --
7860   -- Access         : Private                                             --
7861   -- Description    : Procedure to actually archive the data.             --
7862   -- Parameters     :                                                     --
7863   --             IN :                                                     --
7864   --            OUT : N/A                                                 --
7865   --                                                                      --
7866   -- Change History :                                                     --
7867   --------------------------------------------------------------------------
7868   -- Rev#  Date           Userid    Description                           --
7869   --------------------------------------------------------------------------
7870   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
7871   --------------------------------------------------------------------------
7872   PROCEDURE archive_organization_data(p_24qc_pay_act_id   NUMBER
7873                                      ,p_24qa_pay_act_id   NUMBER
7874                                      )
7875   IS
7876      CURSOR c_prev_stmt_details(p_tan_number      VARCHAR2
7877                                ,p_last_act_cxt_id NUMBER
7878                                )
7879      IS
7880        SELECT action_information5    legal_name
7881              ,action_information7    emplr_type
7882              ,DECODE(action_information_category,'IN_24Q_ORG',action_information21,action_information7) emplr_type_24Q
7883              ,1                      BUI
7884              ,action_context_id
7885          FROM pay_action_information
7886         WHERE action_information_category IN ('IN_24Q_ORG','IN_24QC_ORG')
7887           AND action_context_id   = p_last_act_cxt_id
7888           AND action_context_type = 'PA'
7889           AND action_information1 = g_gre_id
7890           AND action_information2 = p_tan_number
7891           AND action_information3 = g_year||g_quarter
7892         ORDER BY action_context_id DESC;
7893 
7894      CURSOR c_24qa_nil_challan_indicator(p_tan_number      VARCHAR2)
7895      IS
7896         SELECT action_information26
7897          FROM pay_action_information
7898         WHERE action_information_category = 'IN_24Q_ORG'
7899           AND action_context_id   = p_24qa_pay_act_id
7900           AND action_context_type = 'PA'
7901           AND action_information1 = g_gre_id
7902           AND action_information2 = p_tan_number
7903           AND action_information3 = g_year||g_quarter
7904         ORDER BY action_context_id DESC;
7905 
7906        l_tan_number               hr_organization_information.org_information1%TYPE;
7907        l_deductor_type            hr_organization_information.org_information3%TYPE;
7908        l_branch_or_division       hr_organization_information.org_information7%TYPE;
7909        l_org_location             hr_organization_units.location_id%TYPE;
7910        l_pan_number               hr_organization_information.org_information3%TYPE;
7911        l_legal_name               hr_organization_information.org_information4%TYPE;
7912        l_state                    hr_organization_information.org_information9%TYPE;
7913        l_pao_code                 hr_organization_information.org_information10%TYPE;
7914        l_ddo_code                 hr_organization_information.org_information11%TYPE;
7915        l_ministry_name            hr_organization_information.org_information12%TYPE;
7916        l_other_ministry_name      hr_organization_information.org_information13%TYPE;
7917        l_pao_reg_code             hr_organization_information.org_information14%TYPE;
7918        l_ddo_reg_code             hr_organization_information.org_information15%TYPE;
7919        l_rep_name                 per_all_people_f.full_name%TYPE;
7920        l_rep_position             per_all_positions.name%TYPE;
7921        l_rep_location             hr_organization_units.location_id%TYPE;
7922        l_rep_email_id             per_all_people_f.email_address%TYPE;
7923        l_rep_work_phone           per_phones.phone_number%TYPE;
7924        l_rep_std_code             per_phones.phone_number%TYPE;
7925 
7926        l_action_info_id           NUMBER;
7927        l_ovn                      NUMBER;
7928        l_new_nil_challan          VARCHAR2(1);
7929        l_old_nil_challan          VARCHAR2(1);
7930        l_previous_org_legal_name  hr_organization_information.org_information4%TYPE;
7931        l_previous_deductor_type   hr_organization_information.org_information3%TYPE;
7932        l_previous_emplr_type      hr_organization_information.org_information3%TYPE;
7933        l_previous_emplr_type_24Q  hr_organization_information.org_information6%TYPE;
7934        l_batch_upd_indicator      NUMBER;
7935        i                          NUMBER;
7936        l_dummy                    NUMBER;
7937        l_flag                     NUMBER := -1;
7938        l_procedure                VARCHAR2(250);
7939        l_message                  VARCHAR2(250);
7940   BEGIN
7941         g_debug     := hr_utility.debug_enabled;
7942         l_procedure := g_package ||'.archive_organization_data';
7943         pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
7944         pay_in_utils.set_location(g_debug,'Fetching Organization Data ', 1);
7945         get_org_details(g_gre_id,
7946                         l_tan_number,
7947                         l_deductor_type,
7948                         l_branch_or_division,
7949                         l_org_location,
7950                         l_pan_number,
7951                         l_legal_name,
7952                         l_rep_name,
7953                         l_rep_position,
7954                         l_rep_location,
7955                         l_rep_email_id,
7956                         l_rep_work_phone,
7957                         l_rep_std_code,
7958 			l_state,
7959                         l_pao_code,
7960                         l_ddo_code,
7961                         l_ministry_name,
7962                         l_other_ministry_name,
7963                         l_pao_reg_code,
7964                         l_ddo_reg_code
7965                        );
7966 
7967         pay_in_utils.set_location(g_debug,'Received Organization Data ', 1);
7968 
7969         l_previous_org_legal_name := NULL;
7970         l_previous_deductor_type  := NULL;
7971         l_batch_upd_indicator     := 0;
7972 
7973         IF (g_count_org = 1)
7974         THEN
7975                 pay_in_utils.set_location(g_debug,'Archiving ORG data',1);
7976                 SELECT DECODE(DECODE(g_24qc_empr_change,'N',DECODE(g_24qc_rep_adr_chg,'Y','Y','N'),'Y'),'Y',1,0)
7977                   INTO l_batch_upd_indicator
7978                   FROM dual;
7979 
7980                 pay_in_utils.set_location(g_debug,'Checking Last NIL Challan Indicator details ',6);
7981                 OPEN  c_24qa_nil_challan_indicator(l_tan_number);
7982                 FETCH c_24qa_nil_challan_indicator INTO l_old_nil_challan;
7983                 CLOSE c_24qa_nil_challan_indicator;
7984 
7985                 IF ((g_count_challan_add > 1) OR (g_count_challan_upd > 1) OR (g_count_challan_noc > 1))
7986                 THEN
7987                          l_new_nil_challan := 'N';
7988                 ELSE
7989                          l_new_nil_challan := 'Y';
7990                 END IF;
7991 
7992                 pay_action_information_api.create_action_information
7993                           (p_action_context_id              =>     p_24qc_pay_act_id
7994                           ,p_action_context_type            =>     'PA'
7995                           ,p_action_information_category    =>     'IN_24QC_ORG'
7996                           ,p_source_id                      =>     p_24qa_pay_act_id
7997                           ,p_action_information1            =>     g_gre_id
7998                           ,p_action_information2            =>     l_tan_number
7999                           ,p_action_information3            =>     g_year||g_quarter
8000                           ,p_action_information4            =>     l_pan_number
8001                           ,p_action_information5            =>     l_legal_name
8002                           ,p_action_information6            =>     l_org_location
8003                           ,p_action_information7            =>     l_deductor_type
8004                           ,p_action_information8            =>     l_branch_or_division
8005                           ,p_action_information9            =>     l_rep_name
8006                           ,p_action_information10           =>     l_rep_email_id
8007                           ,p_action_information11           =>     l_rep_position
8008                           ,p_action_information12           =>     l_rep_location
8009                           ,p_action_information13           =>     l_rep_work_phone
8010                           ,p_action_information14           =>     l_rep_std_code
8011                           ,p_action_information15           =>     l_batch_upd_indicator
8012                           ,p_action_information16           =>     l_legal_name
8013                           ,p_action_information17           =>     l_deductor_type
8014                           ,p_action_information18           =>     g_24qc_empr_change
8015                           ,p_action_information19           =>     g_24qc_rep_adr_chg
8016                           ,p_action_information30           =>     g_24qc_reference
8017                           ,p_action_information25           =>     l_old_nil_challan
8018                           ,p_action_information26           =>     l_new_nil_challan
8019 			  ,p_action_information20           =>     l_state
8020 			  ,p_action_information21           =>     l_pao_code
8021                           ,p_action_information22           =>     l_ddo_code
8022                           ,p_action_information23           =>     l_ministry_name
8023                           ,p_action_information24           =>     l_other_ministry_name
8024                           ,p_action_information27           =>     l_pao_reg_code
8025                           ,p_action_information28           =>     l_ddo_reg_code
8026                           ,p_action_information_id          =>     l_action_info_id
8027                           ,p_object_version_number          =>     l_ovn
8028                           );
8029                        pay_in_utils.set_location(g_debug,'Leaving archive_organization_data NC',9);
8030 
8031                        RETURN;
8032         END IF;
8033 
8034         pay_in_utils.set_location(g_debug,'Value of g_count_org is '|| g_count_org ,2);
8035 
8036         FOR i IN 1.. g_count_org - 1
8037         LOOP
8038                 IF (g_org_data(i).gre_id = g_gre_id)
8039                 THEN
8040                        pay_in_utils.set_location(g_debug,'Fetching previous statement details ',3);
8041                        OPEN  c_prev_stmt_details(l_tan_number,g_org_data(i).last_action_context_id);
8042                        FETCH c_prev_stmt_details INTO l_previous_org_legal_name
8043                                                      ,l_previous_emplr_type
8044                                                      ,l_previous_emplr_type_24Q
8045                                                      ,l_batch_upd_indicator
8046                                                      ,l_dummy;
8047                        CLOSE c_prev_stmt_details;
8048 		       IF g_old_format = 'Y'
8049                        THEN
8050                        l_previous_deductor_type := l_previous_emplr_type;
8051                        ELSE
8052                        l_previous_deductor_type := l_previous_emplr_type_24Q;
8053                        END IF;
8054                        pay_in_utils.set_location(g_debug,'Fetched previous statement details ',3);
8055 
8056                        pay_in_utils.set_location(g_debug,'Checking New NIL Challan Indicator details ',4);
8057                        IF ((g_count_challan_add > 1) OR (g_count_challan_upd > 1) OR (g_count_challan_noc > 1))
8058                        THEN
8059                                 l_new_nil_challan := 'N';
8060                        ELSE
8061                                 l_new_nil_challan := 'Y';
8062                        END IF;
8063                        pay_in_utils.set_location(g_debug,'New NIL Challan Indicator is '|| l_new_nil_challan,5);
8064                 END IF;
8065         END LOOP;
8066 
8067         pay_in_utils.set_location(g_debug,'Checking Last NIL Challan Indicator details ',6);
8068         OPEN  c_24qa_nil_challan_indicator(l_tan_number);
8069         FETCH c_24qa_nil_challan_indicator INTO l_old_nil_challan;
8070         CLOSE c_24qa_nil_challan_indicator;
8071 
8072         pay_in_utils.set_location(g_debug,'Archiving Data ',7);
8073         pay_in_utils.set_location(g_debug,'Address Change is '|| g_24qc_empr_change , 2);
8074 
8075         pay_action_information_api.create_action_information
8076                   (p_action_context_id              =>     p_24qc_pay_act_id
8077                   ,p_action_context_type            =>     'PA'
8078                   ,p_action_information_category    =>     'IN_24QC_ORG'
8079                   ,p_source_id                      =>     p_24qa_pay_act_id
8080                   ,p_action_information1            =>     g_gre_id
8081                   ,p_action_information2            =>     l_tan_number
8082                   ,p_action_information3            =>     g_year||g_quarter
8083                   ,p_action_information4            =>     l_pan_number
8084                   ,p_action_information5            =>     l_legal_name
8085                   ,p_action_information6            =>     l_org_location
8086                   ,p_action_information7            =>     l_deductor_type
8087                   ,p_action_information8            =>     l_branch_or_division
8088                   ,p_action_information9            =>     l_rep_name
8089                   ,p_action_information10           =>     l_rep_email_id
8090                   ,p_action_information11           =>     l_rep_position
8091                   ,p_action_information12           =>     l_rep_location
8092                   ,p_action_information13           =>     l_rep_work_phone
8093                   ,p_action_information14           =>     l_rep_std_code
8094                   ,p_action_information15           =>     l_batch_upd_indicator
8095                   ,p_action_information16           =>     l_previous_org_legal_name
8096                   ,p_action_information17           =>     l_previous_deductor_type
8097                   ,p_action_information18           =>     g_24qc_empr_change
8098                   ,p_action_information19           =>     g_24qc_rep_adr_chg
8099                   ,p_action_information30           =>     g_24qc_reference
8100                   ,p_action_information25           =>     l_old_nil_challan
8101                   ,p_action_information26           =>     l_new_nil_challan
8102 	          ,p_action_information20           =>     l_state
8103 	          ,p_action_information21           =>     l_pao_code
8104                   ,p_action_information22           =>     l_ddo_code
8105                   ,p_action_information23           =>     l_ministry_name
8106                   ,p_action_information24           =>     l_other_ministry_name
8107                   ,p_action_information27           =>     l_pao_reg_code
8108                   ,p_action_information28           =>     l_ddo_reg_code
8109                   ,p_action_information_id          =>     l_action_info_id
8110                   ,p_object_version_number          =>     l_ovn
8111                   );
8112         pay_in_utils.set_location(g_debug,'Leaving:'|| g_package||'.archive_organization_data',1);
8113   EXCEPTION
8114     WHEN OTHERS THEN
8115       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
8116       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
8117   END archive_organization_data;
8118   --------------------------------------------------------------------------
8119   --                                                                      --
8120   -- Name           : CHECK_GRE                                           --
8121   -- Type           : FUNCTION                                           --
8122   -- Access         : Private                                             --
8123   -- Description    :                                                     --
8124   -- Parameters     :                                                     --
8125   --             IN : p_assignment_act_id    NUMBER                       --
8126   --            OUT : N/A                                                 --
8127   --                                                                      --
8128   -- Change History :                                                     --
8129   --------------------------------------------------------------------------
8130   -- Rev#  Date           Userid    Description                           --
8131   --------------------------------------------------------------------------
8132   -- 115.0 02-May-2006    aaagarwa  Initial Version                       --
8133   --------------------------------------------------------------------------
8134   FUNCTION check_gre(p_assignment_act_id   IN NUMBER)
8135   RETURN BOOLEAN
8136   IS
8137     CURSOR c_24q_per_check
8138     IS
8139        SELECT 1
8140          FROM pay_action_information
8141         WHERE action_information_category = 'IN_24Q_PERSON'
8142           AND action_context_id = p_assignment_act_id
8143           AND action_information3 = g_gre_id;
8144 
8145     CURSOR c_24qc_ded_check
8146     IS
8147        SELECT 1
8148          FROM pay_action_information
8149         WHERE action_information_category = 'IN_24QC_DEDUCTEE'
8150           AND action_context_id = p_assignment_act_id
8151           AND action_information3 = g_gre_id;
8152 
8153     l_flag                NUMBER;
8154     l_procedure           VARCHAR2(250);
8155     l_message             VARCHAR2(250);
8156   BEGIN
8157     l_procedure  :=  g_package || '.check_gre';
8158     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
8159     pay_in_utils.set_location(g_debug,'Checking Asg Action ID: '|| p_assignment_act_id,20);
8160 
8161     l_flag := -1;
8162 
8163     OPEN  c_24q_per_check;
8164     FETCH c_24q_per_check INTO l_flag;
8165     CLOSE c_24q_per_check;
8166 
8167     pay_in_utils.set_location(g_debug,'Value of l_flag:'|| l_flag,25);
8168 
8169     IF (l_flag = -1)
8170     THEN
8171         pay_in_utils.set_location(g_debug,'Checking in 24Q Correction',30);
8172         OPEN  c_24qc_ded_check;
8173         FETCH c_24qc_ded_check INTO l_flag;
8174         CLOSE c_24qc_ded_check;
8175         pay_in_utils.set_location(g_debug,'Value of l_flag:'|| l_flag,40);
8176     END IF;
8177 
8178     IF (l_flag = 1)
8179     THEN
8180         RETURN TRUE;
8181     ELSE
8182        RETURN FALSE;
8183     END IF;
8184   EXCEPTION
8185     WHEN OTHERS THEN
8186       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
8187       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
8188   END check_gre;
8189   --------------------------------------------------------------------------
8190   --                                                                      --
8191   -- Name           : GENERATE_LOCKING                                    --
8192   -- Type           : PROCEDURE                                           --
8193   -- Access         : Private                                             --
8194   -- Description    : This procedure locks the assignments                --
8195   -- Parameters     :                                                     --
8196   --             IN : p_lcking_pay_act_id    NUMBER                       --
8197   --                : p_locked_pay_act_id_q  NUMBER                       --
8198   --                : p_locked_pay_act_id_qc NUMBER                       --
8199   --                : p_chunk                NUMBER                       --
8200   --            OUT : N/A                                                 --
8201   --                                                                      --
8202   -- Change History :                                                     --
8203   --------------------------------------------------------------------------
8204   -- Rev#  Date           Userid    Description                           --
8205   --------------------------------------------------------------------------
8206   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
8207   --------------------------------------------------------------------------
8208   PROCEDURE generate_locking(p_locking_pay_act_id   IN NUMBER
8209                             ,p_locked_pay_act_id_q  IN NUMBER
8210                             ,p_locked_pay_act_id_qc IN NUMBER
8211                             ,p_chunk                IN NUMBER
8212                             )
8213   IS
8214     CURSOR c_assignment_action_id(p_payroll_action_id   NUMBER)
8215     IS
8216        SELECT assignment_action_id
8217              ,assignment_id
8218          FROM pay_assignment_actions
8219         WHERE payroll_action_id = p_payroll_action_id;
8220 
8221     CURSOR c_chk_asg_action(p_assignment_id     NUMBER
8222                            ,p_payroll_action_id NUMBER
8223                            )
8224     IS
8225        SELECT assignment_action_id
8226          FROM pay_assignment_actions paa
8227              ,pay_action_interlocks  pai
8228         WHERE paa.assignment_id        = p_assignment_id
8229           AND paa.assignment_action_id = pai.locking_action_id
8230           AND paa.payroll_action_id    = p_payroll_action_id;
8231 
8232     CURSOR c_check_action(p_locking_act_id     NUMBER
8233                          ,p_locked_act_id      NUMBER
8234                          )
8235     IS
8236        SELECT 1
8237          FROM pay_action_interlocks  pai
8238         WHERE pai.locking_action_id   = p_locking_act_id
8239           AND pai.locked_action_id    = p_locked_act_id;
8240 
8241     CURSOR c_select_prev_24qc
8242     IS
8243        SELECT MAX(org_information3)
8244          FROM hr_organization_information
8245         WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
8246           AND organization_id  = g_gre_id
8247           AND org_information1 = g_year
8248           AND org_information2 = g_quarter
8249           AND org_information5 = 'A'
8250           AND org_information6 = 'C'
8251           AND org_information3 <> p_locked_pay_act_id_qc;
8252 
8253     l_action_id           NUMBER;
8254     l_procedure           VARCHAR2(250);
8255     l_message             VARCHAR2(250);
8256     l_flag                NUMBER;
8257     l_24qc_prv_pay_act_id NUMBER;
8258     --
8259   BEGIN
8260     l_procedure  :=  g_package || '.generate_locking';
8261     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
8262 
8263     FOR c_rec IN c_assignment_action_id(p_locked_pay_act_id_q)
8264     LOOP
8265        IF (check_gre(c_rec.assignment_action_id))
8266        THEN
8267            l_action_id := NULL;
8268            OPEN  c_chk_asg_action(c_rec.assignment_id,p_locking_pay_act_id);
8269            FETCH c_chk_asg_action INTO l_action_id;
8270            CLOSE c_chk_asg_action;
8271            IF (l_action_id IS NULL)
8272            THEN
8273                    SELECT pay_assignment_actions_s.NEXTVAL
8274                      INTO l_action_id
8275                      FROM dual;
8276 
8277                    pay_in_utils.set_location(g_debug,'Value of l_action_id is        '|| l_action_id, 11);
8278                    pay_in_utils.set_location(g_debug,'Value of l_locked_action_id is '|| c_rec.assignment_action_id, 12);
8279                    pay_in_utils.set_location(g_debug,'Value of assignment_id is      '|| c_rec.assignment_id, 13);
8280 
8281                    pay_in_utils.set_location(g_debug,'Inserting Assignment Actions ', 14);
8282                    hr_nonrun_asact.insact(lockingactid => l_action_id
8283                                          ,assignid     => c_rec.assignment_id
8284                                          ,pactid       => p_locking_pay_act_id
8285                                          ,chunk        => p_chunk
8286                                          );
8287                    pay_in_utils.set_location(g_debug,'Enforcing Locking ', 15);
8288                    hr_nonrun_asact.insint(lockingactid => l_action_id
8289                                          ,lockedactid  => c_rec.assignment_action_id
8290                                          );
8291                    pay_in_utils.set_location(g_debug,'Locking enforced', 16);
8292            END IF;
8293       END IF;
8294     END LOOP;
8295 
8296     pay_in_utils.set_location(g_debug,'Now starting locking Latest 24Q Correction Assignments', 16);
8297     FOR c_rec IN c_assignment_action_id(p_locked_pay_act_id_qc)
8298     LOOP
8299        IF (check_gre(c_rec.assignment_action_id))
8300        THEN
8301            l_action_id := NULL;
8302            OPEN  c_chk_asg_action(c_rec.assignment_id,p_locking_pay_act_id);
8303            FETCH c_chk_asg_action INTO l_action_id;
8304            CLOSE c_chk_asg_action;
8305            pay_in_utils.set_location(g_debug,'Value of l_action_id is        '|| l_action_id, 11);
8306 
8307            IF (l_action_id IS NULL)
8308            THEN
8309                SELECT pay_assignment_actions_s.NEXTVAL
8310                  INTO l_action_id
8311                  FROM dual;
8312 
8313                 pay_in_utils.set_location(g_debug,'Inserting Assignment Actions as it was null', 14);
8314                 hr_nonrun_asact.insact(lockingactid => l_action_id
8315                                       ,assignid     => c_rec.assignment_id
8316                                       ,pactid       => p_locking_pay_act_id
8317                                       ,chunk        => p_chunk
8318                                       );
8319            END IF;
8320 
8321            pay_in_utils.set_location(g_debug,'Value of l_locked_action_id is '|| c_rec.assignment_action_id, 12);
8322            pay_in_utils.set_location(g_debug,'Value of assignment_id is      '|| c_rec.assignment_id, 13);
8323 
8324            l_flag := NULL;
8325            OPEN  c_check_action(l_action_id,c_rec.assignment_action_id);
8326            FETCH c_check_action INTO l_flag;
8327            CLOSE c_check_action;
8328 
8329            IF (l_flag IS NULL)
8330            THEN
8331                 pay_in_utils.set_location(g_debug,'Enforcing Locking ', 15);
8332                 hr_nonrun_asact.insint(lockingactid => l_action_id
8333                                       ,lockedactid  => c_rec.assignment_action_id
8334                                       );
8335                 pay_in_utils.set_location(g_debug,'Locking enforced', 16);
8336            END IF;
8337        END IF;
8338     END LOOP;
8339 
8340     OPEN  c_select_prev_24qc;
8341     FETCH c_select_prev_24qc INTO l_24qc_prv_pay_act_id;
8342     CLOSE c_select_prev_24qc;
8343 
8344     pay_in_utils.set_location(g_debug,'Payroll Action ID of previous 24Q Correction archival is '||l_24qc_prv_pay_act_id,1);
8345 
8346     IF (l_24qc_prv_pay_act_id IS NOT NULL)
8347     THEN
8348         pay_in_utils.set_location(g_debug,'Now starting locking Previous 24Q Correction Assignments', 16);
8349         FOR c_rec IN c_assignment_action_id(l_24qc_prv_pay_act_id)
8350         LOOP
8351           IF (check_gre(c_rec.assignment_action_id))
8352           THEN
8353                l_action_id := NULL;
8354                OPEN  c_chk_asg_action(c_rec.assignment_id,p_locking_pay_act_id);
8355                FETCH c_chk_asg_action INTO l_action_id;
8356                CLOSE c_chk_asg_action;
8357                pay_in_utils.set_location(g_debug,'Value of l_action_id is        '|| l_action_id, 11);
8358 
8359                IF (l_action_id IS NULL)
8360                THEN
8361                    SELECT pay_assignment_actions_s.NEXTVAL
8362                      INTO l_action_id
8363                      FROM dual;
8364 
8365                     pay_in_utils.set_location(g_debug,'Inserting Assignment Actions as it was null', 14);
8366                     hr_nonrun_asact.insact(lockingactid => l_action_id
8367                                           ,assignid     => c_rec.assignment_id
8368                                           ,pactid       => p_locking_pay_act_id
8369                                           ,chunk        => p_chunk
8370                                           );
8371                END IF;
8372 
8373                pay_in_utils.set_location(g_debug,'Value of l_locked_action_id is '|| c_rec.assignment_action_id, 12);
8374                pay_in_utils.set_location(g_debug,'Value of assignment_id is      '|| c_rec.assignment_id, 13);
8375 
8376                l_flag := NULL;
8377                OPEN  c_check_action(l_action_id,c_rec.assignment_action_id);
8378                FETCH c_check_action INTO l_flag;
8379                CLOSE c_check_action;
8380 
8381                IF (l_flag IS NULL)
8382                THEN
8383                     pay_in_utils.set_location(g_debug,'Enforcing Locking ', 15);
8384                     hr_nonrun_asact.insint(lockingactid => l_action_id
8385                                           ,lockedactid  => c_rec.assignment_action_id
8386                                           );
8387                     pay_in_utils.set_location(g_debug,'Locking enforced', 16);
8388                  END IF;
8389           END IF;
8390         END LOOP;
8391     END IF;
8392     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,10);
8393   EXCEPTION
8394     WHEN OTHERS THEN
8395       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
8396       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
8397 END generate_locking;
8398 
8399   --------------------------------------------------------------------------
8400   --                                                                      --
8401   -- Name           : ARCHIVE_C5_DATA_ONLY                                --
8402   -- Type           : PROCEDURE                                           --
8403   -- Access         : Public                                              --
8404   -- Description    :                                                     --
8405   -- Parameters     :                                                     --
8406   --             IN : p_payroll_action_id      NUMBER                     --
8407   --                                                                      --
8408   --            OUT : N/A                                                 --
8409   --                                                                      --
8410   -- Change History :                                                     --
8411   --------------------------------------------------------------------------
8412   -- Rev#  Date           Userid    Description                           --
8413   --------------------------------------------------------------------------
8414   -- 115.0 13-Mar-2006    abhjain    Initial Version                      --
8415   --------------------------------------------------------------------------
8416 PROCEDURE archive_c5_data_only(p_payroll_action_id      NUMBER)
8417 IS
8418   CURSOR c_select_deductee
8419   IS
8420      SELECT DISTINCT pai.action_information1 challan
8421        FROM pay_action_information pai
8422            ,pay_assignment_actions paa
8423       WHERE pai.action_information_category = 'IN_24QC_DEDUCTEE'
8424         AND paa.assignment_action_id        = pai.action_context_id
8425         AND paa.payroll_action_id           = p_payroll_action_id
8426         AND pai.action_information19        IS NOT NULL
8427         AND pai.action_information20        IS NOT NULL;
8428 
8429   CURSOR c_challan_sequence(p_challan_number   VARCHAR2)
8430   IS
8431      SELECT pai.action_information25 challan_seq
8432        FROM pay_action_information pai
8433       WHERE pai.action_information_category IN ('IN_24QC_CHALLAN','IN_24Q_CHALLAN')
8434         AND pai.action_information1         = p_challan_number
8435         AND pai.action_context_id IN
8436                                    (
8437                                     SELECT org_information3
8438                                       FROM hr_organization_information
8439                                      WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
8440                                        AND organization_id  = g_gre_id
8441                                        AND org_information1 = g_year
8442                                        AND org_information2 = g_quarter
8443                                        AND org_information5 = 'A'
8444                                 )
8445         AND ROWNUM                          = 1;
8446 
8447   CURSOR c_prev_stmt_details(p_last_act_cxt_id NUMBER
8448                             )
8449   IS
8450     SELECT action_information2    tan_number
8451           ,action_information5    legal_name
8452           ,action_information7    emplr_type
8453           ,DECODE(action_information_category,'IN_24Q_ORG',action_information21,action_information7) emplr_type_24Q
8454       FROM pay_action_information
8455      WHERE action_information_category IN ('IN_24Q_ORG','IN_24QC_ORG')
8456        AND action_context_id   = p_last_act_cxt_id
8457        AND action_context_type = 'PA'
8458        AND action_information1 = g_gre_id
8459        AND action_information3 = g_year||g_quarter
8460      ORDER BY action_context_id DESC;
8461 
8462   l_challan_deductee_no      VARCHAR2(250);
8463   l_tan_number               hr_organization_information.org_information1%TYPE;
8464   l_deductor_type            hr_organization_information.org_information3%TYPE;
8465   l_emplr_type                 hr_organization_information.org_information3%TYPE;
8466   l_emplr_type_24Q             hr_organization_information.org_information6%TYPE;
8467   l_branch_or_division       hr_organization_information.org_information7%TYPE;
8468   l_org_location             hr_organization_units.location_id%TYPE;
8469   l_pan_number               hr_organization_information.org_information3%TYPE;
8470   l_legal_name               hr_organization_information.org_information4%TYPE;
8471   l_state                    hr_organization_information.org_information9%TYPE;
8472   l_pao_code                 hr_organization_information.org_information10%TYPE;
8473   l_ddo_code                 hr_organization_information.org_information11%TYPE;
8474   l_ministry_name            hr_organization_information.org_information12%TYPE;
8475   l_other_ministry_name      hr_organization_information.org_information13%TYPE;
8476   l_pao_reg_code             hr_organization_information.org_information14%TYPE;
8477   l_ddo_reg_code             hr_organization_information.org_information15%TYPE;
8478   l_rep_name                 per_all_people_f.full_name%TYPE;
8479   l_rep_position             per_all_positions.name%TYPE;
8480   l_rep_location             hr_organization_units.location_id%TYPE;
8481   l_rep_email_id             per_all_people_f.email_address%TYPE;
8482   l_rep_work_phone           per_phones.phone_number%TYPE;
8483   l_rep_std_code             per_phones.phone_number%TYPE;
8484   l_flag_number              NUMBER := -1;
8485   l_action_info_id           NUMBER;
8486   l_ovn                      NUMBER;
8487 
8488   l_procedure   VARCHAR2(250);
8489   l_message     VARCHAR2(250);
8490 BEGIN
8491    g_debug     := hr_utility.debug_enabled;
8492    l_procedure := g_package ||'.archive_c5_data_only';
8493    pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
8494 
8495    pay_in_utils.set_location(g_debug,'Checking Challan Data', 1);
8496    FOR c_rec IN c_select_deductee
8497    LOOP
8498         OPEN  c_challan_sequence(c_rec.challan);
8499         FETCH c_challan_sequence INTO l_challan_deductee_no;
8500         CLOSE c_challan_sequence;
8501 
8502          pay_in_utils.set_location(g_debug,'Challan No is :'|| c_rec.challan, 1);
8503          pay_in_utils.set_location(g_debug,'Challan Seq No is :'|| l_challan_deductee_no, 1);
8504          pay_in_utils.set_location(g_debug,'Checking Challan Data in updated Data', 1);
8505          pay_in_utils.set_location(g_debug,'Value of g_count_challan_upd C5 is '|| g_count_challan_upd,2);
8506 
8507         FOR i IN 1..g_count_challan_upd - 1
8508         LOOP
8509                 pay_in_utils.set_location(g_debug,'Found Challan in updated Data', 1);
8510                 l_flag_number := -1;
8511                 l_flag_number := check_archival_status(NULL,'IN_24QC_CHALLAN',g_challan_data_upd(i).transfer_voucher_number,NULL);
8512                 IF((g_challan_data_upd(i).transfer_voucher_number = c_rec.challan)AND(l_flag_number = 0))
8513                 THEN
8514                          pay_action_information_api.create_action_information
8515                                     (p_action_context_id              =>     p_payroll_action_id
8516                                     ,p_action_context_type            =>     'PA'
8517                                     ,p_action_information_category    =>     'IN_24QC_CHALLAN'
8518                                     ,p_source_id                      =>     g_challan_data_upd(i).org_information_id
8519                                     ,p_action_information1            =>     g_challan_data_upd(i).transfer_voucher_number
8520                                     ,p_action_information2            =>     g_year||g_quarter
8521                                     ,p_action_information3            =>     g_gre_id
8522                                     ,p_action_information5            =>     g_challan_data_upd(i).transfer_voucher_date
8523                                     ,p_action_information17           =>     g_challan_data_upd(i).amount
8524                                                                            + g_challan_data_upd(i).surcharge
8525                                                                            + g_challan_data_upd(i).education_cess
8526                                                                            + g_challan_data_upd(i).interest
8527                                                                            + g_challan_data_upd(i).other
8528                                     ,p_action_information18           =>     'NC'
8529                                     ,p_action_information19           =>     update_challans(g_challan_data_upd(i).transfer_voucher_number)
8530                                     ,p_action_information25           =>     l_challan_deductee_no
8531                                     ,p_action_information29           =>     'C5'
8532                                     ,p_action_information_id          =>     l_action_info_id
8533                                     ,p_object_version_number          =>     l_ovn
8534                                     );
8535                 END IF;
8536         END LOOP;
8537 
8538         pay_in_utils.set_location(g_debug,'Checking Challan Data in No Change Data', 1);
8539          pay_in_utils.set_location(g_debug,'Value of g_count_challan_noc C5 is '|| g_count_challan_noc,2);
8540         FOR i IN 1..g_count_challan_noc - 1
8541         LOOP
8542                 pay_in_utils.set_location(g_debug,'Found Challan in no change Data', 1);
8543                 l_flag_number := -1;
8544                 l_flag_number := check_archival_status(NULL,'IN_24QC_CHALLAN',g_challan_data_noc(i).transfer_voucher_number,NULL);
8545                 IF((g_challan_data_noc(i).transfer_voucher_number = c_rec.challan)AND(l_flag_number =0))
8546                 THEN
8547                          pay_action_information_api.create_action_information
8548                                     (p_action_context_id              =>     p_payroll_action_id
8549                                     ,p_action_context_type            =>     'PA'
8550                                     ,p_action_information_category    =>     'IN_24QC_CHALLAN'
8551                                     ,p_source_id                      =>     g_challan_data_noc(i).org_information_id
8552                                     ,p_action_information1            =>     g_challan_data_noc(i).transfer_voucher_number
8553                                     ,p_action_information2            =>     g_year||g_quarter
8554                                     ,p_action_information3            =>     g_gre_id
8555                                     ,p_action_information5            =>     g_challan_data_noc(i).transfer_voucher_date
8556                                     ,p_action_information17           =>     g_challan_data_noc(i).amount
8557                                                                            + g_challan_data_noc(i).surcharge
8558                                                                            + g_challan_data_noc(i).education_cess
8559                                                                            + g_challan_data_noc(i).interest
8560                                                                            + g_challan_data_noc(i).other
8561                                     ,p_action_information18           =>     'NC'
8562                                     ,p_action_information19           =>     update_challans(g_challan_data_noc(i).transfer_voucher_number)
8563                                     ,p_action_information25           =>     l_challan_deductee_no
8564                                     ,p_action_information29           =>     'C5'
8565                                     ,p_action_information_id          =>     l_action_info_id
8566                                     ,p_object_version_number          =>     l_ovn
8567                                     );
8568                 END IF;
8569         END LOOP;
8570    END LOOP;
8571 
8572    pay_in_utils.set_location(g_debug,'Checking Organization Data', 1);
8573    l_flag_number := -1;
8574    l_flag_number := check_archival_status(NULL,'IN_24QC_ORG',NULL,NULL);
8575    IF (l_flag_number <> 0)
8576    THEN
8577           RETURN;
8578    END IF;
8579    pay_in_utils.set_location(g_debug,'Value of g_count_org is ' || g_count_org,2);
8580 
8581    IF (g_count_org = 1)
8582    THEN
8583         pay_in_utils.set_location(g_debug,'Fetching Live Organization Data ', 1);
8584         get_org_details(g_gre_id,
8585                         l_tan_number,
8586                         l_deductor_type,
8587                         l_branch_or_division,
8588                         l_org_location,
8589                         l_pan_number,
8590                         l_legal_name,
8591                         l_rep_name,
8592                         l_rep_position,
8593                         l_rep_location,
8594                         l_rep_email_id,
8595                         l_rep_work_phone,
8596                         l_rep_std_code,
8597 			l_state,
8598                         l_pao_code,
8599                         l_ddo_code,
8600                         l_ministry_name,
8601                         l_other_ministry_name,
8602                         l_pao_reg_code,
8603                         l_ddo_reg_code
8604                        );
8605    ELSE
8606          FOR c_rec IN c_prev_stmt_details(g_org_data(1).last_action_context_id)
8607          LOOP
8608                  l_tan_number     :=  c_rec.tan_number;
8609                  l_legal_name     :=  c_rec.legal_name;
8610                  l_emplr_type     :=  c_rec.emplr_type;
8611                  l_emplr_type_24Q :=  c_rec.emplr_type_24Q;
8612          END LOOP;
8613 	 IF g_old_format = 'Y' THEN
8614          l_deductor_type := l_emplr_type;
8615          ELSE
8616          l_deductor_type := l_emplr_type_24Q;
8617          END IF;
8618    END IF;
8619 
8620   pay_in_utils.set_location(g_debug,'Archiving Org Data for C5 ', 9);
8621   pay_in_utils.set_location(g_debug,'p_payroll_action_id is '|| p_payroll_action_id, 10);
8622   l_action_info_id := NULL;
8623   l_ovn            := NULL;
8624 
8625   pay_action_information_api.create_action_information
8626             (p_action_context_id              =>     p_payroll_action_id
8627             ,p_action_context_type            =>     'PA'
8628             ,p_action_information_category    =>     'IN_24QC_ORG'
8629             ,p_action_information1            =>     g_gre_id
8630             ,p_action_information2            =>     l_tan_number
8631             ,p_action_information3            =>     g_year||g_quarter
8632             ,p_action_information4            =>     NULL
8633             ,p_action_information5            =>     l_legal_name
8634             ,p_action_information6            =>     NULL
8635             ,p_action_information7           =>     l_deductor_type
8636             ,p_action_information15           =>     '0'
8637             ,p_action_information29           =>     'C5'
8638             ,p_action_information30           =>     g_24qc_reference
8639             ,p_action_information_id          =>     l_action_info_id
8640             ,p_object_version_number          =>     l_ovn
8641             );
8642 
8643    pay_in_utils.set_location(g_debug,'Archived Org Data for C5 ', 9);
8644    pay_in_utils.set_location(g_debug,'Leaving: '|| g_package||'.archive_c5_data_only', 1);
8645   EXCEPTION
8646     WHEN OTHERS THEN
8647       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
8648       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
8649 END archive_c5_data_only;
8650 
8651   --------------------------------------------------------------------------
8652   --                                                                      --
8653   -- Name           : ASSIGNMENT_ACTION_CODE                              --
8654   -- Type           : PROCEDURE                                           --
8655   -- Access         : Public                                              --
8656   -- Description    : This procedure further restricts the assignment_id's--
8657   --                  returned by range_code.                             --
8658   --                  It selects assignments that have prepayments/balance--
8659   --                  initialization in the specified duration OR those   --
8660   --                  that have Challan information entries               --
8661   --                  of challans in the specified quarter                --
8662   -- Parameters     :                                                     --
8663   --             IN : p_payroll_action_id    NUMBER                       --
8664   --                  p_start_person         NUMBER                       --
8665   --                  p_end_person           NUMBER                       --
8666   --                  p_chunk                NUMBER                       --
8667   --            OUT : N/A                                                 --
8668   --                                                                      --
8669   -- Change History :                                                     --
8670   --------------------------------------------------------------------------
8671   -- Rev#  Date           Userid    Description                           --
8672   --------------------------------------------------------------------------
8673   -- 115.0 13-Mar-2006    aaagarwa  Initial Version                       --
8674   -- 115.1 07-Feb-2007    rpalli    5754018 : 24QC Quarter4 Stat Update   --
8675   --------------------------------------------------------------------------
8676   --
8677   PROCEDURE assignment_action_code(p_payroll_action_id   IN NUMBER
8678                                   ,p_start_person        IN NUMBER
8679                                   ,p_end_person          IN NUMBER
8680                                   ,p_chunk               IN NUMBER
8681                                   )
8682   IS
8683     CURSOR c_pay_act_id_last_24Q
8684     IS
8685       SELECT org_information3 -- payroll action id of this quarter Form 24Q A/C Archival
8686             ,org_information6 -- Archival Type (Original or Correction Statement)
8687         FROM hr_organization_information
8688        WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
8689          AND organization_id  = g_gre_id
8690          AND org_information1 = g_year
8691          AND org_information2 = g_quarter
8692          AND org_information5 = 'A'
8693        ORDER BY org_information3 DESC;
8694 
8695     CURSOR c_chk_action_lock(p_locking_action_id NUMBER
8696                             ,p_locked_action_id NUMBER
8697                            )
8698     IS
8699       SELECT 1
8700         FROM pay_action_interlocks
8701        WHERE locking_action_id = p_locking_action_id
8702          AND locked_action_id  = p_locked_action_id;
8703 
8704     CURSOR c_chk_asg_action(p_assignment_id     NUMBER
8705                            ,p_payroll_act_id    NUMBER
8706                            )
8707     IS
8708       SELECT assignment_action_id
8709         FROM pay_assignment_actions
8710        WHERE payroll_action_id = p_payroll_act_id
8711          AND assignment_id     = p_assignment_id;
8712 
8713     CURSOR c_max_24qc_locking_24q(p_24qc_arc_asg_act_id      NUMBER)
8714     IS
8715       SELECT max(locking_action_id)
8716        FROM pay_action_interlocks
8717       WHERE locked_action_id = p_24qc_arc_asg_act_id
8718       ORDER BY locking_action_id DESC;
8719 
8720     CURSOR c_select_prev_24qc(p_locked_pay_act_id_qc  NUMBER)
8721     IS
8722        SELECT MAX(org_information3)
8723          FROM hr_organization_information
8724         WHERE org_information_context = 'PER_IN_FORM24Q_RECEIPT_DF'
8725           AND organization_id  = g_gre_id
8726           AND org_information1 = g_year
8727           AND org_information2 = g_quarter
8728           AND org_information5 = 'A'
8729           AND org_information6 = 'C'
8730           AND org_information3 <> p_locked_pay_act_id_qc;
8731 
8732     CURSOR c_source_id(p_pay_act_id_last_24Q     NUMBER)
8733     IS
8734        SELECT source_id
8735          FROM pay_action_information
8736         WHERE action_context_id           = p_pay_act_id_last_24Q
8737           AND action_information_category = 'IN_24QC_ORG'
8738           AND action_context_type         = 'PA'
8739           AND action_information3         = g_year||g_quarter;
8740 
8741     CURSOR c_act_category(p_pay_act_id_last_24Q     NUMBER)
8742     IS
8743       SELECT DECODE(pai.action_information_category,'IN_24Q_ORG',1,2)
8744        FROM pay_action_information pai
8745       WHERE pai.action_information_category IN ('IN_24QC_ORG','IN_24Q_ORG')
8746         AND pai.action_context_id           = p_pay_act_id_last_24Q
8747         AND pai.action_context_type         = 'PA'
8748         AND pai.action_information3         = g_year||g_quarter
8749         AND pai.action_information1         = g_gre_id;
8750 
8751     l_max_24qc_locking_24q      NUMBER;
8752     l_procedure                 VARCHAR2(100);
8753     l_message                   VARCHAR2(250);
8754     l_action_id                 NUMBER;
8755     l_pay_act_id_last_24Q       NUMBER;
8756     l_dummy                     NUMBER;
8757     l_24q_asg_action_id         NUMBER;
8758     l_24q_locked_pay_id         NUMBER;
8759     l_24qc_locked_pay_id        NUMBER;
8760     l_flag                      BOOLEAN;
8761     l_flag_number               NUMBER := -1;
8762     l_last_24qc_pay_act_id      NUMBER;
8763 
8764     l_lock_exists               NUMBER;
8765 
8766   --
8767   BEGIN
8768   --
8769 
8770     l_procedure  :=  g_package || '.assignment_action_code';
8771     g_debug :=  hr_utility.debug_enabled;
8772     pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,10);
8773 
8774     pay_in_utils.set_location(g_debug,'Archival for C4,C5 Modes Starts : '||l_procedure,12);
8775 
8776  --C4,C5 Salary Data Archival Starts
8777     IF (g_sal_action)
8778     THEN
8779            pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,15);
8780 
8781            initialization_code(p_payroll_action_id);
8782 
8783            l_flag  := TRUE;
8784            --Fetch last Form 24Q archival Payroll action id
8785             FOR c_rec IN c_pay_act_id_last_24Q
8786             LOOP
8787                pay_in_utils.set_location(g_debug,'ASSIGNMENT_ACTION_CODE : In c_pay_act_id_last_24Q ', 1);
8788                pay_in_utils.set_location(g_debug,'In c_rec.org_information6 : ' || c_rec.org_information6, 1);
8789                pay_in_utils.set_location(g_debug,'In c_rec.org_information3 : ' || c_rec.org_information3, 1);
8790                IF (l_flag)
8791                THEN
8792                      IF (c_rec.org_information6 = 'O')
8793                      THEN
8794                              l_pay_act_id_last_24Q := c_rec.org_information3;
8795                              pay_in_utils.set_location(g_debug,'In l_pay_act_id_last_24Q : ' || l_pay_act_id_last_24Q, 1);
8796                      ELSE
8797                              l_pay_act_id_last_24Q := c_rec.org_information3;
8798                              pay_in_utils.set_location(g_debug,'In l_pay_act_id_last_24Q : ' || l_pay_act_id_last_24Q, 1);
8799                      END IF;
8800                      l_flag := FALSE;
8801                END IF;
8802             END LOOP;
8803             pay_in_utils.set_location(g_debug,' Archival Action with which we need comparison is '|| l_pay_act_id_last_24Q,1);
8804 
8805            IF (l_pay_act_id_last_24Q IS NOT NULL)
8806            THEN
8807                  OPEN c_act_category(l_pay_act_id_last_24Q);
8808                  FETCH c_act_category INTO l_dummy;
8809                  CLOSE c_act_category;
8810            END IF;
8811             pay_in_utils.set_location(g_debug,' l_dummy is : '|| l_dummy, 3);
8812 
8813              IF (l_dummy = 1)
8814              THEN
8815              -- This means that l_pay_act_id_last_24Q corresponds to 24Q Archival only.
8816                 l_24q_locked_pay_id  := l_pay_act_id_last_24Q;
8817                 l_24qc_locked_pay_id := NULL;
8818              ELSIF(l_dummy = 2)
8819              THEN
8820              -- This means that l_pay_act_id_last_24Q corresponds to 24QC Archival.
8821                  OPEN c_source_id(l_pay_act_id_last_24Q);
8822                  FETCH c_source_id INTO l_24q_locked_pay_id;
8823                  CLOSE c_source_id;
8824 
8825                 l_24qc_locked_pay_id := l_pay_act_id_last_24Q;
8826              END IF;
8827             pay_in_utils.set_location(g_debug,' l_24q_locked_pay_id  is '|| l_24q_locked_pay_id  ,4);
8828             pay_in_utils.set_location(g_debug,' l_24qc_locked_pay_id is '|| l_24qc_locked_pay_id ,5);
8829 
8830            g_payroll_action_id   := p_payroll_action_id;
8831            g_24q_payroll_act_id  := l_24q_locked_pay_id;
8832            g_24qc_payroll_act_id := l_24qc_locked_pay_id;
8833 
8834            OPEN  c_select_prev_24qc(g_24qc_payroll_act_id);
8835            FETCH c_select_prev_24qc INTO l_last_24qc_pay_act_id;
8836            CLOSE c_select_prev_24qc;
8837 
8838            pay_in_utils.set_location(g_debug,'Payroll Action ID of previous 24Q Correction is '|| l_last_24qc_pay_act_id,2);
8839 
8840            IF ((l_pay_act_id_last_24Q IS NULL)AND(g_correction_mode <> 'Y'))
8841            THEN
8842                 RETURN;
8843            END IF;
8844 
8845            IF (g_correction_mode <> 'Y')
8846            THEN
8847                pay_in_utils.set_location(g_debug,'Calling : generate_employee_data '|| l_procedure,10);
8848                pay_in_utils.set_location(g_debug,'l_24q_locked_pay_id is ' || l_24q_locked_pay_id ,11);
8849                generate_employee_data(l_24q_locked_pay_id);
8850 
8851                pay_in_utils.set_location(g_debug,'Calling : generate_salary_data '|| l_procedure,20);
8852                pay_in_utils.set_location(g_debug,'l_24q_locked_pay_id is ' || l_24q_locked_pay_id ,21);
8853                generate_salary_data(l_24q_locked_pay_id, p_start_person, p_end_person);
8854 
8855                pay_in_utils.set_location(g_debug,'Calling : generate_challan_data '|| l_procedure,30);
8856                generate_challan_data(l_24q_locked_pay_id,g_gre_id);
8857 
8858                pay_in_utils.set_location(g_debug,'Calling : generate_organization_data '|| l_procedure,20);
8859                generate_organization_data(l_24q_locked_pay_id,g_gre_id);
8860            ELSE
8861                pay_in_utils.set_location(g_debug,'Calling : archive_cancellation_data '|| l_procedure,20);
8862                pay_in_utils.set_location(g_debug,'Checking Org archival status',1);
8863                l_flag_number := -1;
8864                l_flag_number := check_archival_status(NULL,'IN_24QC_ORG',NULL,NULL);
8865                IF (l_flag_number = 0)
8866                THEN
8867                        archive_cancellation_data(p_payroll_action_id);
8868                END IF;
8869                g_sal_action := FALSE;
8870                generate_locking(p_payroll_action_id,l_24q_locked_pay_id,l_24qc_locked_pay_id,p_chunk);
8871                RETURN;
8872            END IF;
8873 
8874            pay_in_utils.set_location(g_debug,'Inserting assignment action ids for Salary Records',30);
8875 
8876            pay_in_utils.set_location(g_debug,'Inserting Asg Action ID for Deleted Assignment Actions ' ,35);
8877 
8878            pay_in_utils.set_location(g_debug,'Value of g_count_sal_delete is '|| g_count_sal_delete, 39);
8879            IF ((g_count_sal_delete > 1) AND (g_correction_mode <> 'Y'))
8880            THEN
8881                    FOR i IN 1..g_count_sal_delete - 1
8882                    LOOP
8883                       l_24q_asg_action_id := NULL;
8884                       l_dummy             := NULL;
8885                       pay_in_utils.set_location(g_debug,'Checking for Assignment '|| g_sal_data_rec_del(i).assignment_id,1);
8886                       pay_in_utils.set_location(g_debug,'Payroll Action id is ' || p_payroll_action_id,2);
8887                       OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,p_payroll_action_id);
8888                       FETCH c_chk_asg_action INTO l_dummy;
8889                       CLOSE c_chk_asg_action;
8890 
8891 
8892                       pay_in_utils.trace('l_dummy in g_count_sal_delete ',l_dummy);
8893 
8894                        IF (l_dummy IS NULL)
8895                        THEN
8896                            SELECT pay_assignment_actions_s.NEXTVAL
8897                              INTO l_action_id
8898                              FROM dual;
8899 
8900                            pay_in_utils.set_location(g_debug,'Value of l_action_id is '|| l_action_id, 61);
8901                            pay_in_utils.set_location(g_debug,'Inserting Assignment action id ',61);
8902 
8903                             hr_nonrun_asact.insact(lockingactid => l_action_id
8904                                                   ,assignid     => g_sal_data_rec_del(i).assignment_id
8905                                                   ,pactid       => p_payroll_action_id
8906                                                   ,chunk        => p_chunk
8907                                                   );
8908 
8909                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
8910 
8911                            OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,l_24q_locked_pay_id);
8912                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
8913                            CLOSE c_chk_asg_action;
8914 
8915                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
8916 
8917                            IF (l_24q_asg_action_id IS NOT NULL)
8918                            THEN
8919                                    hr_nonrun_asact.insint(lockingactid => l_action_id
8920                                                          ,lockedactid  => l_24q_asg_action_id
8921                                                          );
8922                            END IF;
8923 
8924                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
8925                            l_24q_asg_action_id := NULL;
8926                            OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,l_24qc_locked_pay_id);
8927                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
8928                            CLOSE c_chk_asg_action;
8929 
8930                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
8931 
8932                            IF (l_24q_asg_action_id IS NOT NULL)
8933                            THEN
8934                                    hr_nonrun_asact.insint(lockingactid => l_action_id
8935                                                          ,lockedactid  => l_24q_asg_action_id
8936                                                          );
8937                            END IF;
8938 
8939                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
8940                            l_24q_asg_action_id := NULL;
8941                            OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,l_last_24qc_pay_act_id);
8942                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
8943                            CLOSE c_chk_asg_action;
8944 
8945                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
8946 
8947                            IF (l_24q_asg_action_id IS NOT NULL)
8948                            THEN
8949                                    hr_nonrun_asact.insint(lockingactid => l_action_id
8950                                                          ,lockedactid  => l_24q_asg_action_id
8951                                                          );
8952                            END IF;
8953                        END IF;
8954 
8955                        IF (l_dummy IS NOT NULL)
8956                        THEN
8957 
8958                            pay_in_utils.set_location(g_debug,'Value of l_dummy is '|| l_dummy, 61);
8959 
8960                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
8961                            l_24q_asg_action_id := NULL;
8962                            l_lock_exists := 0;
8963 
8964                            OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,l_24q_locked_pay_id);
8965                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
8966                            CLOSE c_chk_asg_action;
8967 
8968                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
8969                            FETCH c_chk_action_lock INTO l_lock_exists;
8970                            CLOSE c_chk_action_lock;
8971 
8972                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
8973 
8974                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
8975                            THEN
8976                                    hr_nonrun_asact.insint(lockingactid => l_dummy
8977                                                          ,lockedactid  => l_24q_asg_action_id
8978                                                          );
8979                            END IF;
8980 
8981                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
8982                            l_24q_asg_action_id := NULL;
8983                            l_lock_exists := 0;
8984                            OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,l_24qc_locked_pay_id);
8985                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
8986                            CLOSE c_chk_asg_action;
8987 
8988                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
8989                            FETCH c_chk_action_lock INTO l_lock_exists;
8990                            CLOSE c_chk_action_lock;
8991 
8992                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
8993 
8994                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
8995                            THEN
8996                                    hr_nonrun_asact.insint(lockingactid => l_dummy
8997                                                          ,lockedactid  => l_24q_asg_action_id
8998                                                          );
8999                            END IF;
9000 
9001                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9002                            l_24q_asg_action_id := NULL;
9003                            l_lock_exists := 0;
9004                            OPEN  c_chk_asg_action(g_sal_data_rec_del(i).assignment_id,l_last_24qc_pay_act_id);
9005                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9006                            CLOSE c_chk_asg_action;
9007 
9008                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9009                            FETCH c_chk_action_lock INTO l_lock_exists;
9010                            CLOSE c_chk_action_lock;
9011 
9012                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9013 
9014                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9015                            THEN
9016                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9017                                                          ,lockedactid  => l_24q_asg_action_id
9018                                                          );
9019                            END IF;
9020                        END IF;
9021 
9022                   END LOOP;
9023            END IF;
9024 
9025 
9026            pay_in_utils.set_location(g_debug,'Inserting Asg Action ID for Added Assignment Actions ' ,60);
9027            pay_in_utils.set_location(g_debug,'Value of g_count_sal_addition is '|| g_count_sal_addition, 61);
9028            IF ((g_count_sal_addition > 1) AND (g_correction_mode <> 'Y'))
9029            THEN
9030                   FOR i IN 1..g_count_sal_addition - 1
9031                   LOOP
9032                       l_24q_asg_action_id := NULL;
9033                       l_dummy             := NULL;
9034                       pay_in_utils.set_location(g_debug,'Checking for Assignment '|| g_sal_data_rec_add(i).assignment_id,1);
9035                       pay_in_utils.set_location(g_debug,'Payroll Action id is ' || p_payroll_action_id,2);
9036 
9037                       OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,p_payroll_action_id);
9038                       FETCH c_chk_asg_action INTO l_dummy;
9039                       CLOSE c_chk_asg_action;
9040 
9041                       pay_in_utils.trace('l_dummy in g_count_sal_addition ',l_dummy);
9042 
9043                        IF (l_dummy IS NULL)
9044                        THEN
9045                            SELECT pay_assignment_actions_s.NEXTVAL
9046                              INTO l_action_id
9047                              FROM dual;
9048 
9049                            pay_in_utils.set_location(g_debug,'Value of l_action_id is '|| l_action_id, 61);
9050                            pay_in_utils.set_location(g_debug,'Inserting Assignment action id ',61);
9051 
9052                             hr_nonrun_asact.insact(lockingactid => l_action_id
9053                                                   ,assignid     => g_sal_data_rec_add(i).assignment_id
9054                                                   ,pactid       => p_payroll_action_id
9055                                                   ,chunk        => p_chunk
9056                                                   );
9057 
9058                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9059 
9060                            OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,l_24q_locked_pay_id);
9061                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9062                            CLOSE c_chk_asg_action;
9063 
9064                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9065 
9066                            IF (l_24q_asg_action_id IS NOT NULL)
9067                            THEN
9068                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9069                                                          ,lockedactid  => l_24q_asg_action_id
9070                                                          );
9071                            END IF;
9072 
9073                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9074                            l_24q_asg_action_id := NULL;
9075                            OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,l_24qc_locked_pay_id);
9076                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9077                            CLOSE c_chk_asg_action;
9078 
9079                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9080 
9081                            IF (l_24q_asg_action_id IS NOT NULL)
9082                            THEN
9083                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9084                                                          ,lockedactid  => l_24q_asg_action_id
9085                                                          );
9086                            END IF;
9087 
9088                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9089                            l_24q_asg_action_id := NULL;
9090                            OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,l_last_24qc_pay_act_id);
9091                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9092                            CLOSE c_chk_asg_action;
9093 
9094                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9095 
9096                            IF (l_24q_asg_action_id IS NOT NULL)
9097                            THEN
9098                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9099                                                          ,lockedactid  => l_24q_asg_action_id
9100                                                          );
9101                            END IF;
9102 
9103                        END IF;
9104 
9105                        IF (l_dummy IS NOT NULL)
9106                        THEN
9107 
9108                            pay_in_utils.set_location(g_debug,'Value of l_dummy is '|| l_dummy, 61);
9109 
9110                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9111                            l_24q_asg_action_id := NULL;
9112                            l_lock_exists := 0;
9113 
9114                            OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,l_24q_locked_pay_id);
9115                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9116                            CLOSE c_chk_asg_action;
9117 
9118                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9119                            FETCH c_chk_action_lock INTO l_lock_exists;
9120                            CLOSE c_chk_action_lock;
9121 
9122                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9123 
9124                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9125                            THEN
9126                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9127                                                          ,lockedactid  => l_24q_asg_action_id
9128                                                          );
9129                            END IF;
9130 
9131                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9132                            l_24q_asg_action_id := NULL;
9133                            l_lock_exists := 0;
9134                            OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,l_24qc_locked_pay_id);
9135                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9136                            CLOSE c_chk_asg_action;
9137 
9138                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9139                            FETCH c_chk_action_lock INTO l_lock_exists;
9140                            CLOSE c_chk_action_lock;
9141 
9142                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9143 
9144                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9145                            THEN
9146                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9147                                                          ,lockedactid  => l_24q_asg_action_id
9148                                                          );
9149                            END IF;
9150 
9151                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9152                            l_24q_asg_action_id := NULL;
9153                            l_lock_exists := 0;
9154                            OPEN  c_chk_asg_action(g_sal_data_rec_add(i).assignment_id,l_last_24qc_pay_act_id);
9155                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9156                            CLOSE c_chk_asg_action;
9157 
9158                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9159                            FETCH c_chk_action_lock INTO l_lock_exists;
9160                            CLOSE c_chk_action_lock;
9161 
9162                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9163 
9164                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9165                            THEN
9166                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9167                                                          ,lockedactid  => l_24q_asg_action_id
9168                                                          );
9169                            END IF;
9170                        END IF;
9171 
9172                   END LOOP;
9173            END IF;
9174 
9175 
9176            pay_in_utils.set_location(g_debug,'Inserting Asg Action ID for Updated Assignment Actions ' ,70);
9177            pay_in_utils.set_location(g_debug,'Value of g_count_sal_update is '|| g_count_sal_update, 71);
9178            IF ((g_count_sal_update > 1) AND (g_correction_mode <> 'Y'))
9179            THEN
9180                   FOR i IN 1..g_count_sal_update - 1
9181                   LOOP
9182                       l_24q_asg_action_id := NULL;
9183                       l_dummy             := NULL;
9184 
9185                       pay_in_utils.set_location(g_debug,'Checking for Assignment '|| g_sal_data_rec_upd(i).assignment_id,1);
9186                       pay_in_utils.set_location(g_debug,'Payroll Action id is ' || p_payroll_action_id,2);
9187                       OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,p_payroll_action_id);
9188                       FETCH c_chk_asg_action INTO l_dummy;
9189                       CLOSE c_chk_asg_action;
9190 
9191 
9192                       pay_in_utils.trace('l_dummy in g_count_sal_update ',l_dummy);
9193 
9194                        IF (l_dummy IS NULL)
9195                        THEN
9196                            SELECT pay_assignment_actions_s.NEXTVAL
9197                              INTO l_action_id
9198                              FROM dual;
9199 
9200                            pay_in_utils.set_location(g_debug,'Value of l_action_id is '|| l_action_id, 61);
9201                            pay_in_utils.set_location(g_debug,'Inserting Assignment action id ',61);
9202 
9203                             hr_nonrun_asact.insact(lockingactid => l_action_id
9204                                                   ,assignid     => g_sal_data_rec_upd(i).assignment_id
9205                                                   ,pactid       => p_payroll_action_id
9206                                                   ,chunk        => p_chunk
9207                                                   );
9208 
9209                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9210 
9211                            OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,l_24q_locked_pay_id);
9212                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9213                            CLOSE c_chk_asg_action;
9214 
9215                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9216 
9217                            IF (l_24q_asg_action_id IS NOT NULL)
9218                            THEN
9219                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9220                                                          ,lockedactid  => l_24q_asg_action_id
9221                                                          );
9222                            END IF;
9223                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9224                            l_24q_asg_action_id := NULL;
9225                            OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,l_24qc_locked_pay_id);
9226                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9227                            CLOSE c_chk_asg_action;
9228 
9229                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9230 
9231                            IF (l_24q_asg_action_id IS NOT NULL)
9232                            THEN
9233                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9234                                                          ,lockedactid  => l_24q_asg_action_id
9235                                                          );
9236                            END IF;
9237 
9238                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9239                            l_24q_asg_action_id := NULL;
9240                            OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,l_last_24qc_pay_act_id);
9241                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9242                            CLOSE c_chk_asg_action;
9243 
9244                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9245 
9246                            IF (l_24q_asg_action_id IS NOT NULL)
9247                            THEN
9248                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9249                                                          ,lockedactid  => l_24q_asg_action_id
9250                                                          );
9251                            END IF;
9252                        END IF;
9253 
9254                        IF (l_dummy IS NOT NULL)
9255                        THEN
9256 
9257                            pay_in_utils.set_location(g_debug,'Value of l_dummy is '|| l_dummy, 61);
9258 
9259                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9260                            l_24q_asg_action_id := NULL;
9261                            l_lock_exists := 0;
9262 
9263                            OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,l_24q_locked_pay_id);
9264                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9265                            CLOSE c_chk_asg_action;
9266 
9267                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9268                            FETCH c_chk_action_lock INTO l_lock_exists;
9269                            CLOSE c_chk_action_lock;
9270 
9271                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9272 
9273                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9274                            THEN
9275                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9276                                                          ,lockedactid  => l_24q_asg_action_id
9277                                                          );
9278                            END IF;
9279 
9280                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9281                            l_24q_asg_action_id := NULL;
9282                            l_lock_exists := 0;
9283                            OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,l_24qc_locked_pay_id);
9284                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9285                            CLOSE c_chk_asg_action;
9286 
9287                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9288                            FETCH c_chk_action_lock INTO l_lock_exists;
9289                            CLOSE c_chk_action_lock;
9290 
9291                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9292 
9293                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9294                            THEN
9295                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9296                                                          ,lockedactid  => l_24q_asg_action_id
9297                                                          );
9298                            END IF;
9299 
9300                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9301                            l_24q_asg_action_id := NULL;
9302                            l_lock_exists := 0;
9303                            OPEN  c_chk_asg_action(g_sal_data_rec_upd(i).assignment_id,l_last_24qc_pay_act_id);
9304                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9305                            CLOSE c_chk_asg_action;
9306 
9307                            OPEN  c_chk_action_lock(l_dummy,l_24q_asg_action_id);
9308                            FETCH c_chk_action_lock INTO l_lock_exists;
9309                            CLOSE c_chk_action_lock;
9310 
9311                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9312 
9313                            IF ((l_24q_asg_action_id IS NOT NULL) AND (l_lock_exists=0))
9314                            THEN
9315                                    hr_nonrun_asact.insint(lockingactid => l_dummy
9316                                                          ,lockedactid  => l_24q_asg_action_id
9317                                                          );
9318                            END IF;
9319                        END IF;
9320 
9321                   END LOOP;
9322            END IF;
9323 
9324            pay_in_utils.set_location(g_debug,'Asg Action ID Insertion Over for Salary Records ', 80);
9325 
9326            pay_in_utils.set_location(g_debug,'Archiving PL/SQL Data for Salary Records: archive_code ',90);
9327 
9328           --For C4,C5 only salary data should be Archived
9329            IF (g_correction_mode IN('C4','C5','%'))
9330            THEN
9331                    archive_salary_data(g_payroll_action_id,l_24q_locked_pay_id);
9332            END IF;
9333 
9334  END IF;
9335  --C4,C5 Salary Data Archival Ends
9336   pay_in_utils.set_location(g_debug,'Archival for C4,C5 Modes Ends : '||l_procedure,100);
9337 
9338 
9339     IF (g_action)
9340     THEN
9341            pay_in_utils.set_location(g_debug,'Entering : '||l_procedure,110);
9342 
9343            pay_in_utils.set_location(g_debug,'Inserting assignment action id in pay_assignment_actions ',40);
9344            pay_in_utils.set_location(g_debug,'Inserting Asg Action ID for Deleted Element Entries ' ,50);
9345 
9346            pay_in_utils.set_location(g_debug,'Value of g_count_ee_delete is '|| g_count_ee_delete, 51);
9347            IF ((g_count_ee_delete > 1)AND (g_correction_mode <> 'Y'))
9348            THEN
9349                    FOR i IN 1..g_count_ee_delete - 1
9350                    LOOP
9351                       l_24q_asg_action_id := NULL;
9352                       l_dummy             := NULL;
9353                       OPEN  c_chk_asg_action(g_ee_data_rec_del(i).assignment_id,p_payroll_action_id);
9354                       FETCH c_chk_asg_action INTO l_dummy;
9355                       CLOSE c_chk_asg_action;
9356 
9357                        IF (l_dummy IS NULL)
9358                        THEN
9359                            SELECT pay_assignment_actions_s.NEXTVAL
9360                              INTO l_action_id
9361                              FROM dual;
9362 
9363                            pay_in_utils.set_location(g_debug,'Value of l_action_id is '|| l_action_id, 61);
9364                            pay_in_utils.set_location(g_debug,'Inserting Assignment action id ',61);
9365 
9366                             hr_nonrun_asact.insact(lockingactid => l_action_id
9367                                                   ,assignid     => g_ee_data_rec_del(i).assignment_id
9368                                                   ,pactid       => p_payroll_action_id
9369                                                   ,chunk        => p_chunk
9370                                                   );
9371 
9372                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9373 
9374                            OPEN  c_chk_asg_action(g_ee_data_rec_del(i).assignment_id,l_24q_locked_pay_id);
9375                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9376                            CLOSE c_chk_asg_action;
9377 
9378                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9379 
9380                            IF (l_24q_asg_action_id IS NOT NULL)
9381                            THEN
9382                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9383                                                          ,lockedactid  => l_24q_asg_action_id
9384                                                          );
9385                            END IF;
9386 
9387                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9388                            l_24q_asg_action_id := NULL;
9389                            OPEN  c_chk_asg_action(g_ee_data_rec_del(i).assignment_id,l_24qc_locked_pay_id);
9390                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9391                            CLOSE c_chk_asg_action;
9392 
9393                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9394 
9395                            IF (l_24q_asg_action_id IS NOT NULL)
9396                            THEN
9397                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9398                                                          ,lockedactid  => l_24q_asg_action_id
9399                                                          );
9400                            END IF;
9401 
9402                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9403                            l_24q_asg_action_id := NULL;
9404                            OPEN  c_chk_asg_action(g_ee_data_rec_del(i).assignment_id,l_last_24qc_pay_act_id);
9405                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9406                            CLOSE c_chk_asg_action;
9407 
9408                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9409 
9410                            IF (l_24q_asg_action_id IS NOT NULL)
9411                            THEN
9412                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9413                                                          ,lockedactid  => l_24q_asg_action_id
9414                                                          );
9415                            END IF;
9416                        END IF;
9417                   END LOOP;
9418            END IF;
9419 
9420            pay_in_utils.set_location(g_debug,'Inserting Asg Action ID for Added Element Entries ' ,60);
9421            pay_in_utils.set_location(g_debug,'Value of g_count_ee_addition is '|| g_count_ee_addition, 61);
9422            IF ((g_count_ee_addition > 1)AND(g_correction_mode <> 'Y'))
9423            THEN
9424                   FOR i IN 1..g_count_ee_addition - 1
9425                   LOOP
9426                       l_24q_asg_action_id := NULL;
9427                       l_dummy             := NULL;
9428                       OPEN  c_chk_asg_action(g_ee_data_rec_add(i).assignment_id,p_payroll_action_id);
9429                       FETCH c_chk_asg_action INTO l_dummy;
9430                       CLOSE c_chk_asg_action;
9431 
9432                       pay_in_utils.set_location(g_debug,'Value of l_dummy is '|| l_dummy, 61);
9433                        IF (l_dummy IS NULL)
9434                        THEN
9435                            SELECT pay_assignment_actions_s.NEXTVAL
9436                              INTO l_action_id
9437                              FROM dual;
9438 
9439                            pay_in_utils.set_location(g_debug,'Value of l_action_id is '|| l_action_id, 61);
9440                            pay_in_utils.set_location(g_debug,'Inserting Assignment action id ',61);
9441 
9442                             hr_nonrun_asact.insact(lockingactid => l_action_id
9443                                                   ,assignid     => g_ee_data_rec_add(i).assignment_id
9444                                                   ,pactid       => p_payroll_action_id
9445                                                   ,chunk        => p_chunk
9446                                                   );
9447 
9448                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9449 
9450                            OPEN  c_chk_asg_action(g_ee_data_rec_add(i).assignment_id,l_24q_locked_pay_id);
9451                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9452                            CLOSE c_chk_asg_action;
9453 
9454                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9455 
9456                            IF (l_24q_asg_action_id IS NOT NULL)
9457                            THEN
9458                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9459                                                          ,lockedactid  => l_24q_asg_action_id
9460                                                          );
9461                            END IF;
9462 
9463                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9464                            l_24q_asg_action_id := NULL;
9465                            OPEN  c_chk_asg_action(g_ee_data_rec_add(i).assignment_id,l_24qc_locked_pay_id);
9466                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9467                            CLOSE c_chk_asg_action;
9468 
9469                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9470 
9471                            IF (l_24q_asg_action_id IS NOT NULL)
9472                            THEN
9473                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9474                                                          ,lockedactid  => l_24q_asg_action_id
9475                                                          );
9476                            END IF;
9477 
9478                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9479                            l_24q_asg_action_id := NULL;
9480                            OPEN  c_chk_asg_action(g_ee_data_rec_add(i).assignment_id,l_last_24qc_pay_act_id);
9481                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9482                            CLOSE c_chk_asg_action;
9483 
9484                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9485 
9486                            IF (l_24q_asg_action_id IS NOT NULL)
9487                            THEN
9488                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9489                                                          ,lockedactid  => l_24q_asg_action_id
9490                                                          );
9491                            END IF;
9492 
9493                        END IF;
9494                   END LOOP;
9495            END IF;
9496 
9497            pay_in_utils.set_location(g_debug,'Inserting Asg Action ID for Updated Element Entries ' ,70);
9498            pay_in_utils.set_location(g_debug,'Value of g_count_ee_update is '|| g_count_ee_update, 71);
9499            IF ((g_count_ee_update > 1)AND(g_correction_mode <> 'Y'))
9500            THEN
9501                   FOR i IN 1..g_count_ee_update - 1
9502                   LOOP
9503                       l_24q_asg_action_id := NULL;
9504                       l_dummy             := NULL;
9505 
9506                       pay_in_utils.set_location(g_debug,'Checking for Assignment '|| g_ee_data_rec_upd(i).assignment_id,1);
9507                       pay_in_utils.set_location(g_debug,'Payroll Action id is ' || p_payroll_action_id,2);
9508                       OPEN  c_chk_asg_action(g_ee_data_rec_upd(i).assignment_id,p_payroll_action_id);
9509                       FETCH c_chk_asg_action INTO l_dummy;
9510                       CLOSE c_chk_asg_action;
9511 
9512                       pay_in_utils.set_location(g_debug,'Value of dummy is ' || l_dummy ,3);
9513                        IF (l_dummy IS NULL)
9514                        THEN
9515                            SELECT pay_assignment_actions_s.NEXTVAL
9516                              INTO l_action_id
9517                              FROM dual;
9518 
9519                            pay_in_utils.set_location(g_debug,'Value of l_action_id is '|| l_action_id, 61);
9520                            pay_in_utils.set_location(g_debug,'Inserting Assignment action id ',61);
9521 
9522                             hr_nonrun_asact.insact(lockingactid => l_action_id
9523                                                   ,assignid     => g_ee_data_rec_upd(i).assignment_id
9524                                                   ,pactid       => p_payroll_action_id
9525                                                   ,chunk        => p_chunk
9526                                                   );
9527 
9528                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Archival', 61);
9529 
9530                            OPEN  c_chk_asg_action(g_ee_data_rec_upd(i).assignment_id,l_24q_locked_pay_id);
9531                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9532                            CLOSE c_chk_asg_action;
9533 
9534                            pay_in_utils.trace('Value of l_locked_action_id for 24Q is ',l_24q_asg_action_id);
9535 
9536                            IF (l_24q_asg_action_id IS NOT NULL)
9537                            THEN
9538                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9539                                                          ,lockedactid  => l_24q_asg_action_id
9540                                                          );
9541                            END IF;
9542                            pay_in_utils.set_location(g_debug,'Enforcing Locking on 24Q Correction', 61);
9543                            l_24q_asg_action_id := NULL;
9544                            OPEN  c_chk_asg_action(g_ee_data_rec_upd(i).assignment_id,l_24qc_locked_pay_id);
9545                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9546                            CLOSE c_chk_asg_action;
9547 
9548                            pay_in_utils.trace('Value of l_locked_action_id for 24Q Correction is ',l_24q_asg_action_id);
9549 
9550                            IF (l_24q_asg_action_id IS NOT NULL)
9551                            THEN
9552                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9553                                                          ,lockedactid  => l_24q_asg_action_id
9554                                                          );
9555                            END IF;
9556 
9557                            pay_in_utils.set_location(g_debug,'Enforcing Locking on Previous 24Q Correction', 61);
9558                            l_24q_asg_action_id := NULL;
9559                            OPEN  c_chk_asg_action(g_ee_data_rec_upd(i).assignment_id,l_last_24qc_pay_act_id);
9560                            FETCH c_chk_asg_action INTO l_24q_asg_action_id;
9561                            CLOSE c_chk_asg_action;
9562 
9563                            pay_in_utils.trace('Value of l_locked_action_id for Previous 24Q Correction is ',l_24q_asg_action_id);
9564 
9565                            IF (l_24q_asg_action_id IS NOT NULL)
9566                            THEN
9567                                    hr_nonrun_asact.insint(lockingactid => l_action_id
9568                                                          ,lockedactid  => l_24q_asg_action_id
9569                                                          );
9570                            END IF;
9571                        END IF;
9572                   END LOOP;
9573            END IF;
9574 
9575            pay_in_utils.set_location(g_debug,'Asg Action ID Insertion Over ', 80);
9576            pay_in_utils.set_location(g_debug,'Archiving PL/SQL Data : archive_code ',90);
9577 
9578            --C2,C3 then archive only updated Challans, if C9 then only added challans
9579            IF (g_correction_mode NOT IN ('Y','C1'))
9580            THEN
9581                    archive_challan_data(g_payroll_action_id,l_24q_locked_pay_id);
9582            END IF;
9583 
9584            IF (g_correction_mode NOT IN ('C5','Y')) THEN
9585                 pay_in_utils.set_location(g_debug,'Checking Org archival status',1);
9586                 l_flag_number := -1;
9587                 l_flag_number := check_archival_status(NULL,'IN_24QC_ORG',NULL,NULL);
9588                 IF (l_flag_number = 0)
9589                 THEN
9590                    archive_organization_data(g_payroll_action_id,l_24q_locked_pay_id);
9591                 END IF;
9592            END IF;
9593 
9594             --For C3,C5,C9 only deductee data should be archived
9595            IF (g_correction_mode IN('C3','C5','C9','%'))
9596            THEN
9597                    archive_deductee_data(g_payroll_action_id,l_24q_locked_pay_id);
9598            END IF;
9599 
9600            pay_in_utils.set_location(g_debug,'Generating Locking...',1);
9601            --Inserting Assignment Actions and Locking if no deductee records exist for this archival.
9602            IF ((g_count_ee_delete = 1) AND (g_count_ee_addition = 1) AND (g_count_ee_update = 1))
9603            THEN
9604                         pay_in_utils.set_location(g_debug,'Generating Locking...',2);
9605                         pay_in_utils.set_location(g_debug,'p_payroll_action_id ' || p_payroll_action_id ,1);
9606                         pay_in_utils.set_location(g_debug,'l_24q_locked_pay_id ' || l_24q_locked_pay_id ,1);
9607                         pay_in_utils.set_location(g_debug,'l_24qc_locked_pay_id' || l_24qc_locked_pay_id,1);
9608                         generate_locking(p_payroll_action_id,l_24q_locked_pay_id,l_24qc_locked_pay_id,p_chunk);
9609            END IF;
9610 
9611            g_action := FALSE;
9612 
9613            IF (g_correction_mode =  'C5')
9614            THEN
9615               archive_c5_data_only(p_payroll_action_id);
9616            END IF;
9617 
9618            IF (g_debug)
9619            THEN
9620                 trace_pl_sql_table_data();
9621            END IF;
9622 
9623     END IF;
9624 
9625     pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure,100);
9626 
9627   --
9628   EXCEPTION
9629     WHEN OTHERS THEN
9630       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
9631       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
9632   END assignment_action_code;
9633 
9634   --------------------------------------------------------------------------
9635   --                                                                      --
9636   -- Name           : ARCHIVE_CODE                                        --
9637   -- Type           : PROCEDURE                                           --
9638   -- Access         : Public                                              --
9639   -- Description    : Procedure to call the internal procedures to        --
9640   --                  actually archive the data.                          --
9641   -- Parameters     :                                                     --
9642   --             IN : p_assignment_action_id       NUMBER                 --
9643   --                  p_effective_date             DATE                   --
9644   --                                                                      --
9645   --            OUT : N/A                                                 --
9646   --                                                                      --
9647   -- Change History :                                                     --
9648   --------------------------------------------------------------------------
9649   -- Rev#  Date           Userid    Description                           --
9650   --------------------------------------------------------------------------
9651   -- 115.0 13-Mar-2006    aaagarwa   Initial Version                      --
9652   --------------------------------------------------------------------------
9653   PROCEDURE archive_code (p_assignment_action_id  IN NUMBER
9654                          ,p_effective_date        IN DATE
9655                          )
9656   IS
9657   BEGIN
9658         NULL;
9659   END archive_code;
9660 
9661   --------------------------------------------------------------------------
9662   --                                                                      --
9663   -- Name           : DEINITIALIZATION_CODE                               --
9664   -- Type           : PROCEDURE                                           --
9665   -- Access         : Public                                              --
9666   -- Description    :                                                     --
9667   -- Parameters     :                                                     --
9668   --             IN : p_payroll_action_id          NUMBER                 --
9669   --                                                                      --
9670   --            OUT : N/A                                                 --
9671   --                                                                      --
9672   -- Change History :                                                     --
9673   --------------------------------------------------------------------------
9674   -- Rev#  Date           Userid    Description                           --
9675   --------------------------------------------------------------------------
9676   -- 115.0 13-Mar-2006    abhjain    Initial Version                      --
9677   -- 115.1 07-Feb-2007    rpalli     5754018 :24QC Quarter4 Stat Update   --
9678   --------------------------------------------------------------------------
9679   PROCEDURE deinitialization_code (p_payroll_action_id IN NUMBER)
9680   IS
9681    CURSOR cur_org_recs(p_payroll_action_id NUMBER)
9682    IS
9683    SELECT DECODE(action_information15, 1, 'C1')
9684          ,action_information_id
9685          ,object_version_number
9686          ,action_information29
9687      FROM pay_action_information
9688     WHERE action_information1 = g_gre_id
9689       AND action_information3 = g_year||g_quarter
9690       AND action_context_type = 'PA'
9691       AND action_information_category = 'IN_24QC_ORG'
9692       AND action_context_id = p_payroll_action_id;
9693 
9694    CURSOR cur_challan_recs(p_payroll_action_id NUMBER)
9695     IS
9696     SELECT action_information1 challan
9697         ,DECODE(action_information18, 'U', 'C2', 'A', 'C9', 'NC', null) correction_type
9698         ,action_information_id
9699         ,object_version_number
9700     FROM pay_action_information
9701    WHERE action_information3 = g_gre_id
9702      AND action_information2 = g_year||g_quarter
9703      AND action_context_type = 'PA'
9704      AND action_information_category = 'IN_24QC_CHALLAN'
9705      AND action_context_id = p_payroll_action_id;
9706 
9707    CURSOR cur_deductee_recs(p_payroll_action_id NUMBER
9708                            ,p_challan_number    VARCHAR2)
9709     IS
9710     SELECT 'C3' correction_type
9711       FROM pay_action_information pai
9712      WHERE pai.action_context_id IN (SELECT assignment_action_id
9713                                        FROM pay_assignment_actions
9714                                       WHERE payroll_action_id = p_payroll_action_id
9715                                         AND assignment_id     = pai.assignment_id
9716                                     )
9717      AND action_context_type = 'AAP'
9718      AND action_information_category = 'IN_24QC_DEDUCTEE'
9719      AND action_information3 = g_gre_id
9720      AND action_information2 = g_year||g_quarter
9721      AND action_information15 IN ('U', 'A', 'D')
9722      AND (
9723             (    action_information19 IS NULL
9724              AND action_information20 IS NULL
9725             )
9726             OR
9727             (    (INSTR(action_information19,'C3') <> 0)
9728             )
9729          )
9730      AND action_information1 = p_challan_number;
9731 
9732    CURSOR cur_c5_deductee_recs(p_payroll_action_id NUMBER
9733                            ,p_challan_number    VARCHAR2)
9734     IS
9735     SELECT 'C5' correction_type
9736       FROM pay_action_information pai
9737      WHERE pai.action_context_id IN ( SELECT assignment_action_id
9738                                         FROM pay_assignment_actions
9739                                        WHERE payroll_action_id = p_payroll_action_id
9740                                          AND assignment_id     = pai.assignment_id
9741                                     )
9742      AND action_context_type = 'AAP'
9743      AND action_information_category = 'IN_24QC_DEDUCTEE'
9744      AND action_information3 = g_gre_id
9745      AND action_information2 = g_year||g_quarter
9746      AND INSTR(action_information19,'C5') <> 0
9747      AND action_information20 IS NOT NULL
9748      AND action_information1 = p_challan_number;
9749 
9750    CURSOR cur_c5_salary_recs(p_payroll_action_id NUMBER
9751                            ,p_person_id    NUMBER)
9752     IS
9753     SELECT 'C5' correction_type
9754       FROM pay_action_information pai
9755      WHERE pai.action_context_id IN ( SELECT assignment_action_id
9756                                         FROM pay_assignment_actions
9757                                        WHERE payroll_action_id = p_payroll_action_id
9758                                          AND assignment_id     = pai.assignment_id
9759                                     )
9760      AND action_context_type = 'AAP'
9761      AND action_information_category = 'IN_24QC_PERSON'
9762      AND action_information3 = g_gre_id
9763      AND action_information2 = g_year||g_quarter
9764      AND INSTR(action_information11,'C5') <> 0
9765      AND action_information1 = p_person_id;
9766 
9767    CURSOR cur_c4_salary_recs(p_payroll_action_id NUMBER
9768                            ,p_person_id    NUMBER)
9769     IS
9770     SELECT 'C4' correction_type
9771       FROM pay_action_information pai
9772      WHERE pai.action_context_id IN ( SELECT assignment_action_id
9773                                         FROM pay_assignment_actions
9774                                        WHERE payroll_action_id = p_payroll_action_id
9775                                          AND assignment_id     = pai.assignment_id
9776                                     )
9777      AND action_context_type = 'AAP'
9778      AND action_information_category = 'IN_24QC_PERSON'
9779      AND action_information3 = g_gre_id
9780      AND action_information2 = g_year||g_quarter
9781      AND INSTR(action_information11,'C4') <> 0
9782      AND action_information1 = p_person_id;
9783 
9784  CURSOR cur_salary_update_recs
9785   IS
9786 SELECT DISTINCT action_information3          gre_id
9787   FROM pay_action_information
9788  WHERE action_information_category = 'IN_24QC_PERSON'
9789    AND action_context_type         = 'AAP'
9790    AND action_information10        = 'A'
9791    AND action_information11        = 'C4'
9792    AND action_context_id IN (SELECT assignment_action_id
9793                                FROM pay_assignment_actions
9794                               WHERE payroll_action_id = p_payroll_action_id)
9795    ORDER BY action_information3;
9796 
9797 
9798  CURSOR cur_person_update_recs( p_gre_id VARCHAR2)
9799   IS
9800 SELECT DISTINCT action_information1 person_id
9801      , source_id
9802      , action_information_id
9803      , object_version_number
9804   FROM pay_action_information
9805  WHERE action_information_category = 'IN_24QC_PERSON'
9806    AND action_context_type         = 'AAP'
9807    AND action_information3 = fnd_number.canonical_to_number(p_gre_id)
9808    AND action_information10 = 'A'
9809    AND action_information11 = 'C4'
9810    AND action_context_id IN (SELECT assignment_action_id
9811                                FROM pay_assignment_actions
9812                               WHERE payroll_action_id = p_payroll_action_id)
9813    ORDER BY  LENGTH(action_information1)
9814             ,action_information1
9815             ,source_id;
9816 
9817  CURSOR cur_min_salary_record( p_gre_id VARCHAR2)
9818   IS
9819 SELECT MIN(fnd_number.canonical_to_number(action_information12)) min_salary_rec
9820   FROM pay_action_information
9821  WHERE action_information_category = 'IN_24QC_PERSON'
9822    AND action_context_type         = 'AAP'
9823    AND action_information3 = fnd_number.canonical_to_number(p_gre_id)
9824    AND action_information10 = 'A'
9825    AND action_information11 = 'C4'
9826    AND action_context_id IN (SELECT assignment_action_id
9827                                FROM pay_assignment_actions
9828                               WHERE payroll_action_id = p_payroll_action_id);
9829 
9830 
9831 CURSOR cur_salary_recs(p_payroll_action_id NUMBER)
9832   IS
9833 SELECT DISTINCT action_information1 person_id
9834   FROM pay_action_information pai
9835  WHERE action_information_category = 'IN_24QC_PERSON'
9836    AND action_context_type         = 'AAP'
9837    AND action_context_id IN (SELECT assignment_action_id
9838                                FROM pay_assignment_actions
9839                               WHERE payroll_action_id = p_payroll_action_id
9840                                 AND assignment_id     = pai.assignment_id)
9841    AND action_information3 = g_gre_id
9842    AND action_information2 = g_year||g_quarter;
9843 
9844     CURSOR c_24q_ee_sum(p_challan_number       VARCHAR2
9845                         ,p_24q_pay_action_id   NUMBER
9846                        )
9847     IS
9848         SELECT SUM(NVL(pai.action_information9,0)) amount_deposited
9849           FROM pay_action_information  pai
9850               ,pay_assignment_actions  paa
9851          WHERE pai.action_information_category = 'IN_24Q_DEDUCTEE'
9852            AND paa.assignment_action_id        = pai.action_context_id
9853            AND pai.action_information1         = p_challan_number
9854            AND paa.payroll_action_id           = p_24q_pay_action_id;
9855 
9856      TYPE t_challan_data IS RECORD
9857        ( challan_no            hr_organization_information.org_information1%TYPE
9858         ,correction_type       VARCHAR2(100)
9859         ,action_information_id NUMBER
9860         ,object_version_number NUMBER
9861        );
9862 
9863       TYPE t_challan_data_tab IS TABLE OF t_challan_data
9864       INDEX BY binary_integer;
9865       t_challan_nos t_challan_data_tab;
9866 
9867       l_index             NUMBER ;
9868       l_correction_type   VARCHAR2(100);
9869       org_correction_type VARCHAR2(100);
9870       l_org_update_string VARCHAR(2400);
9871       l_action_info_id    NUMBER;
9872       l_ovn               NUMBER;
9873       l_y_flag            VARCHAR2(10);
9874       l_last_sum          VARCHAR2(250);
9875       l_procedure         VARCHAR2(100);
9876       l_message           VARCHAR2(300);
9877   BEGIN
9878 
9879      l_procedure := g_package ||'.deinitialization_code';
9880      pay_in_utils.set_location(g_debug,'Entering: '||l_procedure,10);
9881 
9882      IF (g_correction_mode =  'C5')
9883      THEN
9884         RETURN;
9885      END IF;
9886 
9887     OPEN  cur_org_recs(p_payroll_action_id);
9888     FETCH cur_org_recs INTO org_correction_type, l_action_info_id, l_ovn, l_y_flag;
9889     CLOSE cur_org_recs;
9890 
9891     IF (l_y_flag IS NOT NULL)
9892     THEN
9893        RETURN;
9894     END IF;
9895 
9896     pay_in_utils.set_location(g_debug,'Checking in Challans...',2);
9897     FOR i IN  cur_challan_recs(p_payroll_action_id) LOOP
9898       l_index                                      := nvl(l_index, 0) + 1;
9899       t_challan_nos(l_index).challan_no            := i.challan;
9900       t_challan_nos(l_index).correction_type       := i.correction_type;
9901       t_challan_nos(l_index).action_information_id := i.action_information_id;
9902       t_challan_nos(l_index).object_version_number := i.object_version_number;
9903 
9904       l_correction_type := null;
9905 
9906       OPEN  cur_deductee_recs(p_payroll_action_id, t_challan_nos(l_index).challan_no);
9907       FETCH cur_deductee_recs INTO l_correction_type;
9908       CLOSE cur_deductee_recs;
9909 
9910       IF nvl(t_challan_nos(l_index).correction_type, 'C2') = 'C2'  AND l_correction_type = 'C3' THEN
9911          t_challan_nos(l_index).correction_type := 'C3';
9912       END IF;
9913 
9914       OPEN  cur_c5_deductee_recs(p_payroll_action_id, t_challan_nos(l_index).challan_no);
9915       FETCH cur_c5_deductee_recs INTO l_correction_type;
9916       CLOSE cur_c5_deductee_recs;
9917 
9918       IF NVL(t_challan_nos(l_index).correction_type, '%') <> 'C9' AND l_correction_type = 'C5' THEN
9919          IF t_challan_nos(l_index).correction_type IS NULL THEN
9920             t_challan_nos(l_index).correction_type := 'C5';
9921          ELSE
9922             t_challan_nos(l_index).correction_type := t_challan_nos(l_index).correction_type||':C5';
9923          END IF;
9924       END IF;
9925 
9926       pay_in_utils.set_location(g_debug,'Updating API called for Challan ', 3);
9927       pay_action_information_api.update_action_information
9928                 (p_validate                       =>  FALSE
9929                 ,p_action_information_id          =>  t_challan_nos(l_index).action_information_id
9930                 ,p_object_version_number          =>  t_challan_nos(l_index).object_version_number
9931                 ,p_action_information29           =>  t_challan_nos(l_index).correction_type
9932                 );
9933       pay_in_utils.set_location(g_debug,'Updating API successful for Challan ', 3);
9934       l_org_update_string := NVL(l_org_update_string, '1') ||':'||t_challan_nos(l_index).correction_type;
9935 
9936     END LOOP;
9937 
9938     pay_in_utils.set_location(g_debug,'Checked Challans...',2);
9939 
9940 
9941     pay_in_utils.set_location(g_debug,'Updating SD Record Number for A mode in Salary Records : ',3);
9942 
9943     l_index := 0;
9944     FOR c_salary_rec IN cur_salary_update_recs
9945     LOOP
9946       OPEN cur_min_salary_record(c_salary_rec.gre_id);
9947       FETCH cur_min_salary_record INTO l_index;
9948       CLOSE cur_min_salary_record;
9949     pay_in_utils.set_location(g_debug,'l_index...',1);
9950     pay_in_utils.set_location(g_debug,'c_salary_rec.gre_id...',c_salary_rec.gre_id);
9951 
9952       FOR cur_rec IN cur_person_update_recs(c_salary_rec.gre_id)
9953       LOOP
9954                pay_action_information_api.update_action_information
9955                 (p_validate                       => FALSE
9956                 ,p_action_information_id          => cur_rec.action_information_id
9957                 ,p_object_version_number          => cur_rec.object_version_number
9958                 ,p_action_information12           => l_index
9959                 );
9960                l_index := l_index + 1;
9961     pay_in_utils.set_location(g_debug,'l_index...',2);
9962     pay_in_utils.set_location(g_debug,'l_index...',2);
9963       END LOOP;
9964     END LOOP;
9965 
9966     pay_in_utils.set_location(g_debug,'Updated SD Record Number for A mode in Salary Records : ',3);
9967 
9968     pay_in_utils.set_location(g_debug,'Checking in Salary Records...',3);
9969 
9970     FOR i IN cur_salary_recs(p_payroll_action_id) LOOP
9971 
9972       OPEN  cur_c5_salary_recs(p_payroll_action_id, i.person_id);
9973       FETCH cur_c5_salary_recs INTO l_correction_type;
9974       CLOSE cur_c5_salary_recs;
9975 
9976       IF l_correction_type = 'C5' THEN
9977        l_org_update_string := NVL(l_org_update_string, '1') ||':'||l_correction_type;
9978       END IF;
9979 
9980       OPEN  cur_c4_salary_recs(p_payroll_action_id, i.person_id);
9981       FETCH cur_c4_salary_recs INTO l_correction_type;
9982       CLOSE cur_c4_salary_recs;
9983 
9984       IF l_correction_type = 'C4' THEN
9985        l_org_update_string := NVL(l_org_update_string, '1') ||':'||l_correction_type;
9986       END IF;
9987 
9988     END LOOP;
9989 
9990     pay_in_utils.set_location(g_debug,'Checked Salary Records...',3);
9991 
9992     IF INSTR(l_org_update_string, 'C2') <> 0 THEN
9993        IF org_correction_type is null or org_correction_type = 'C1' THEN
9994           org_correction_type := 'C2';
9995        ELSE
9996           org_correction_type := org_correction_type || ':C2';
9997        END IF;
9998     END IF;
9999     IF INSTR(l_org_update_string, 'C3') <> 0 THEN
10000        IF org_correction_type IS NULL OR org_correction_type = 'C1' THEN
10001           org_correction_type := 'C3';
10002        ELSE
10003           org_correction_type := org_correction_type || ':C3';
10004        END IF;
10005     END IF;
10006     IF INSTR(l_org_update_string, 'C4') <> 0 THEN
10007        IF org_correction_type IS NULL THEN
10008           org_correction_type := 'C4';
10009        ELSE
10010           org_correction_type := org_correction_type || ':C4';
10011        END IF;
10012     END IF;
10013     IF INSTR(l_org_update_string, 'C5') <> 0 THEN
10014        IF org_correction_type IS NULL THEN
10015           org_correction_type := 'C5';
10016        ELSE
10017           org_correction_type := org_correction_type || ':C5';
10018        END IF;
10019     END IF;
10020     IF INSTR(l_org_update_string, 'C9') <> 0 THEN
10021        IF org_correction_type IS NULL THEN
10022           org_correction_type := 'C9';
10023        ELSE
10024           org_correction_type := org_correction_type || ':C9';
10025        END IF;
10026     END IF;
10027 
10028 
10029      pay_in_utils.set_location(g_debug,'Updating API called for Org ', 3);
10030      pay_action_information_api.update_action_information
10031                (p_validate                       =>  FALSE
10032                ,p_action_information_id          =>  l_action_info_id
10033                ,p_object_version_number          =>  l_ovn
10034                ,p_action_information29           =>  org_correction_type
10035                );
10036      pay_in_utils.set_location(g_debug,'Updating API successful for Org ', 3);
10037      pay_in_utils.set_location(g_debug,'Leaving: '|| g_package||'.deinitialization_code',1);
10038 
10039   EXCEPTION
10040     WHEN OTHERS THEN
10041       l_message := pay_in_utils.get_pay_message('PER_IN_ORACLE_GENERIC_ERROR', 'FUNCTION:'||l_procedure, 'SQLERRMC:'||sqlerrm);
10042       pay_in_utils.set_location(g_debug,'Leaving : '||l_procedure, 150);
10043   END deinitialization_code;
10044 
10045 
10046 END pay_in_24qc_archive;