[Home] [Help]
PACKAGE BODY: APPS.PAY_NL_TAXOFFICE_FILE
Source
1 PACKAGE BODY PAY_NL_TAXOFFICE_FILE as
2 /* $Header: pynltosf.pkb 120.0.12000000.1 2007/01/17 23:04:56 appldev noship $ */
3 g_package varchar2(33) := ' PAY_NL_TAXOFFICE_FILE.';
4
5
6 g_error_flag varchar2(30);
7 g_warning_flag varchar2(30);
8 g_error_count NUMBER;
9 g_payroll_action_id NUMBER;
10 g_assignment_number VARCHAR2(30);
11 g_full_name VARCHAR2(150);
12 g_debug boolean;
13
14 /*------------------------------------------------------------------------------
15 |Name : GET_PARAMETER |
16 |Type : Function |
17 |Description : Funtion to get the parameters of the archive process |
18 -------------------------------------------------------------------------------*/
19
20 function get_parameter(
21 p_parameter_string in varchar2
22 ,p_token in varchar2
23 ,p_segment_number in number default null) RETURN varchar2
24 IS
25
26 l_parameter pay_payroll_actions.legislative_parameters%TYPE:=NULL;
27 l_start_pos NUMBER;
28 l_delimiter varchar2(1):=' ';
29 l_proc VARCHAR2(400):= g_package||' get parameter ';
30
31 BEGIN
32 if g_debug then
33 hr_utility.set_location('Entering get_parameter',52);
34 end if;
35
36 l_start_pos := instr(' '||p_parameter_string,l_delimiter||p_token||'=');
37 --
38 IF l_start_pos = 0 THEN
39 l_delimiter := '|';
40 l_start_pos := instr(' '||p_parameter_string,l_delimiter||p_token||'=');
41 end if;
42
43 IF l_start_pos <> 0 THEN
44 l_start_pos := l_start_pos + length(p_token||'=');
45 l_parameter := substr(p_parameter_string,
46 l_start_pos,
47 instr(p_parameter_string||' ',
48 l_delimiter,l_start_pos)
49 - l_start_pos);
50 IF p_segment_number IS NOT NULL THEN
51 l_parameter := ':'||l_parameter||':';
52 l_parameter := substr(l_parameter,
53 instr(l_parameter,':',1,p_segment_number)+1,
54 instr(l_parameter,':',1,p_segment_number+1) -1
55 - instr(l_parameter,':',1,p_segment_number));
56 END IF;
57 END IF;
58 --
59 if g_debug then
60 hr_utility.set_location('Leaving get_parameter',53);
61 end if;
62
63 RETURN l_parameter;
64 END get_parameter;
65
66 -----------------------------------------------------------------------------
67 -- GET_ALL_PARAMETERS gets all parameters for the payroll action
68 -----------------------------------------------------------------------------
69 PROCEDURE get_all_parameters (
70 p_payroll_action_id IN NUMBER
71 ,p_business_group_id OUT NOCOPY NUMBER
72 ,p_effective_date OUT NOCOPY DATE
73 ,p_tax_year OUT NOCOPY date
74 ,p_employer OUT NOCOPY number
75 ,p_org_struct_id OUT NOCOPY number) IS
76 --
77 CURSOR csr_parameter_info(p_payroll_action_id NUMBER) IS
78 SELECT fnd_date.canonical_to_date(pay_nl_taxoffice_file.get_parameter(legislative_parameters,'REPORT_YEAR'))
79 ,pay_nl_taxoffice_file.get_parameter(legislative_parameters,'EMPLOYER_ID')
80 ,pay_nl_taxoffice_file.get_parameter(legislative_parameters,'ORG_HIERARCHY')
81 ,effective_date
82 ,business_group_id
83 FROM pay_payroll_actions
84 WHERE payroll_action_id = p_payroll_action_id;
85 --
86 l_effective_date date;
87 l_proc VARCHAR2(400):= g_package||' get_all_parameters ';
88 --
89 BEGIN
90 if g_debug then
91 hr_utility.set_location('Entering get_all_parameters',51);
92 end if;
93
94 OPEN csr_parameter_info (p_payroll_action_id);
95 FETCH csr_parameter_info INTO
96 p_tax_year, p_employer, p_org_struct_id
97 ,p_effective_date,p_business_group_id;
98 CLOSE csr_parameter_info;
99
100 if g_debug then
101 hr_utility.set_location('Leaving get_all_parameters',54);
102 end if;
103 END;
104
105
106
107 /*-------------------------------------------------------------------------------
108 |Name : Mandatory_Check |
109 |Type : Procedure |
110 |Description : Procedure to check if the specified Mandatory Field is NULL |
111 | if so flag a Error message to the Log File |
112 -------------------------------------------------------------------------------*/
113
114 Procedure Mandatory_Check(p_message_name varchar2
115 ,p_field varchar2
116 ,p_value varchar2) is
117 v_message_text fnd_new_messages.message_text%TYPE;
118 v_employee_dat VARCHAR2(255);
119 v_label_desc hr_lookups.meaning%TYPE;
120 Begin
121 if g_debug then
122 hr_utility.set_location('Checking Field '||p_field,425);
123 end if;
124
125 If p_value is null then
126 v_label_desc := hr_general.decode_lookup('HR_NL_REPORT_LABELS', p_field);
127 v_employee_dat :=RPAD(SUBSTR(g_assignment_number,1,20),20)
128 ||' '||RPAD(SUBSTR(g_full_name,1,25),25)
129 ||' '||RPAD(SUBSTR(v_label_desc,1,25),25)
130 ||' '||RPAD(SUBSTR(g_error_flag,1,15),15);
131 hr_utility.set_message(801,p_message_name);
132 v_message_text :=SUBSTR(fnd_message.get,1,70);
133 g_error_count := NVL(g_error_count,0) +1;
134 FND_FILE.PUT_LINE(FND_FILE.LOG, v_employee_dat||' '||v_message_text);
135 end if;
136
137 end;
138
139
140 /*--------------------------------------------------------------------
141 |Name : RANGE_CODE |
142 |Type : Procedure |
143 |Description: This procedure returns a sql string to select a range of|
144 | assignments eligible for archival
145 ----------------------------------------------------------------------*/
146
147 Procedure RANGE_CODE (pactid IN NUMBER
148 ,sqlstr OUT NOCOPY VARCHAR2) is
149 v_log_header VARCHAR2(255);
150
151 l_business_group_id number;
152 l_effective_date date;
153 l_tax_year date;
154 l_employer_id number;
155 l_org_struct_id number;
156
157 l_sender_details number;
158 l_sender_tax_rep_name varchar2(255);
159 l_sender_tax_reg_number varchar2(255);
160 l_tax_rep_name varchar2(255);
161 l_tax_reg_number varchar2(255);
162
163 l_org_address number;
164 l_house_number varchar2(255);
165 l_house_no_add varchar2(255);
166 l_street_name varchar2(255);
167 l_line1 varchar2(255);
168 l_line2 varchar2(255);
169 l_line3 varchar2(255);
170 l_city varchar2(255);
171 l_country varchar2(255);
172 l_postal_code varchar2(255);
173
174 l_sender_address number;
175 l_sen_house_number varchar2(255);
176 l_sen_house_no_add varchar2(255);
177 l_sen_street_name varchar2(255);
178 l_sen_line1 varchar2(255);
179 l_sen_line2 varchar2(255);
180 l_sen_line3 varchar2(255);
181 l_sen_city varchar2(255);
182 l_sen_country varchar2(255);
183 l_sen_postal_code varchar2(255);
184 l_sender_address_field varchar2(255);
185 l_sen_city_field varchar2(255);
186 l_tax_address_field varchar2(255);
187 l_tax_city_field varchar2(255);
188
189
190
191
192 BEGIN
193 -- g_debug:=TRUE;
194 if g_debug then
195 hr_utility.trace_on(NULL,'TOF');
196 hr_utility.set_location('Entering Range Code',50);
197 end if;
198
199 g_error_count := 0;
200 g_payroll_action_id:=pactid;
201
202 get_all_parameters (pactid
203 ,l_business_group_id
204 ,l_effective_date
205 ,l_tax_year
206 ,l_employer_id
207 ,l_org_struct_id);
208
209 l_sender_details:=GET_TOS_SENDER_DETAILS(l_business_group_id,l_employer_id,l_sender_tax_rep_name,l_sender_tax_reg_number,l_tax_rep_name,l_tax_reg_number);
210 l_org_address:=PAY_NL_GENERAL.GET_ORGANIZATION_ADDRESS(l_employer_id,l_business_group_id,l_house_number,l_house_no_add,l_street_name,l_line1,l_line2,l_line3,l_city,l_country,l_postal_code);
211 l_sender_address:=PAY_NL_GENERAL.GET_ORGANIZATION_ADDRESS(l_business_group_id,l_business_group_id,l_sen_house_number,l_sen_house_no_add,l_sen_street_name,l_sen_line1,l_sen_line2,l_sen_line3,l_sen_city,l_sen_country,l_sen_postal_code);
212
213 l_sender_address_field := l_sen_street_name || l_sen_house_number || l_sen_house_no_add;
214 l_sen_city_field := l_sen_postal_code || l_sen_city;
215 l_tax_address_field := l_street_name || l_house_number || l_house_no_add;
216 l_tax_city_field := l_postal_code || l_city;
217
218
219
220 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_SENDER_NAME',l_sender_tax_rep_name);
221 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_SENDER_ADDR',l_sender_address_field);
222 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_SENDER_CITY',l_sen_city_field);
223 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_SENDER_REG_NUM',l_sender_tax_reg_number);
224 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_TAX_REPORTING_NAME',l_tax_rep_name);
225 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_ER_ADDR',l_tax_address_field);
226 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_CITY',l_tax_city_field);
227 Mandatory_Check('PAY_NL_ER_REQUIRED_FIELD','NL_TAX_REGISTRATION_NUMBER',l_tax_reg_number);
228
229
230 /*Return the SELECT Statement to select a range of assignments
231 eligible for archival */
232
233 IF g_error_count=0 THEN
234 sqlstr := 'SELECT DISTINCT person_id
235 FROM per_people_f ppf
236 ,pay_payroll_actions ppa
237 WHERE ppa.payroll_action_id = :payroll_action_id
238 AND ppa.business_group_id = ppf.business_group_id
239 ORDER BY ppf.person_id';
240
241 --Write to Log File
242 v_log_header := RPAD(SUBSTR(hr_general.decode_lookup('HR_NL_REPORT_LABELS','NL_ASSIGNMENT_NUMBER'),1,20),20)
243 ||' '||RPAD(SUBSTR(hr_general.decode_lookup('HR_NL_REPORT_LABELS','FULL_NAME'),1,25),25)
244 ||' '||RPAD(SUBSTR(hr_general.decode_lookup('HR_NL_REPORT_LABELS','FIELD_NAME'),1,25),25)
245 ||' '||RPAD(SUBSTR(hr_general.decode_lookup('HR_NL_REPORT_LABELS','ERROR_TYPE'),1,15),15)
246 ||' '||RPAD(SUBSTR(hr_general.decode_lookup('HR_NL_REPORT_LABELS','MESSAGE'),1,70),70);
247 Fnd_file.put_line(FND_FILE.LOG,v_log_header);
248
249 if g_debug then
250 hr_utility.set_location('Leaving Range Code',350);
251 end if;
252 ELSE
253 sqlstr := 'SELECT DISTINCT person_id
254 FROM per_people_f ppf
255 ,pay_payroll_actions ppa
256 WHERE ppa.payroll_action_id = :payroll_action_id
257 AND 1 = 2
258 AND ppa.business_group_id = ppf.business_group_id
259 ORDER BY ppf.person_id';
260 END IF;
261
262
263 END RANGE_CODE;
264
265
266
267 Procedure ARCHIVE_CODE (p_assignment_action_id IN NUMBER
268 ,p_effective_date IN DATE) IS
269
270
271 BEGIN
272 --g_debug:=TRUE;
273 if g_debug then
274 hr_utility.set_location('Entering Archive Code',800);
275 hr_utility.set_location('Leaving Archive Code',800);
276 end if;
277
278 END ARCHIVE_CODE;
279
280
281
282
283 /*--------------------------------------------------------------------
284 |Name : ASSIGNMENT_ACTION_CODE |
285 |Type : Procedure |
286 |Description: This procedure Fetches,validates and
287 | generates Assignment Action for the File Process
288 | Locks the Archive Assignment Action Record.
289 ----------------------------------------------------------------------*/
290
291
292 Procedure ASSIGNMENT_ACTION_CODE (
293 p_payroll_action_id in number
294 ,p_start_person_id in number
295 ,p_end_person_id in number
296 ,p_chunk in number) IS
297 /*Cursor Fetches All the Archived Assignment Records
298 that have not been processed in a previous run of a
299 Annual Tax Statement File process for the selected year and the Employer matches
300 the one selected in the SRS Request */
301 CURSOR Cur_EE_ATS_File(lp_employer_id number,
302 lp_Tax_Year_Start_Date Date,
303 lp_Tax_Year_End_Date Date,
304 lp_start_person_id number,
305 lp_end_person_id number) IS
306 Select
307 ee_ats.effective_date
308 ,ee_ats.action_information1 employer_id
309 ,ee_ats.action_information2 person_id
310 ,ee_ats.action_information3 assignment_id
311 ,ee_ats.action_context_id arch_ass_act_id
312 ,pap.full_name full_name
313 ,paa.assignment_number assignment_number
314 from pay_action_information ee_ats
315 ,per_all_people_f pap
316 ,per_all_assignments_f paa
317 WHERE ee_ats.action_context_type='AAP'
318 AND ee_ats.action_information_category = 'NL ATS EMPLOYEE DETAILS'
319 AND ee_ats.effective_date =lp_Tax_Year_End_Date
320 AND ee_ats.action_information1 =fnd_number.number_to_canonical(lp_employer_id)
321 AND fnd_number.canonical_to_number(ee_ats.action_information2) BETWEEN lp_start_person_id AND lp_end_person_id
322 AND paa.assignment_id = fnd_number.canonical_to_number(ee_ats.action_information3)
323 AND paa.effective_start_date =
324 (
325 SELECT MIN(asg.effective_start_date)
326 FROM per_assignment_status_types past, per_all_assignments_f asg
327 WHERE asg.assignment_id = paa.assignment_id
328 and past.per_system_status = 'ACTIVE_ASSIGN'
329 and asg.assignment_status_type_id = past.assignment_status_type_id
330 and asg.effective_start_date <= lp_Tax_Year_End_Date
331 and nvl(asg.effective_end_date, lp_Tax_Year_End_Date) >= lp_Tax_Year_Start_Date
332
333 )
334 AND pap.person_id = fnd_number.canonical_to_number(ee_ats.action_information2)
335 AND lp_Tax_Year_End_Date between pap.effective_start_date and pap.effective_end_date
336 AND pap.person_id = paa.person_id
337 AND not exists
338 (select arc_lck.locked_action_id from pay_action_interlocks arc_lck
339 where arc_lck.locked_action_id = ee_ats.action_context_id);
340
341
342
343
344 l_business_group_id number;
345 l_effective_date date;
346 l_tax_year date;
347 l_tax_year_date varchar2(100);
348 l_tax_year_start_date date;
349 l_tax_year_end_date date;
350 l_employer_id number;
351 l_org_struct_id number;
352 l_asg_act_id number;
353 l_assignment_id number;
354 l_tax_yr date;
355 l_locked_aai number;
356
357 l_employee_address number;
358 l_ee_house_number varchar2(255);
359 l_ee_house_no_add varchar2(255);
360 l_ee_street_name varchar2(255);
361 l_ee_line1 varchar2(255);
362 l_ee_line2 varchar2(255);
363 l_ee_line3 varchar2(255);
364 l_ee_city varchar2(255);
365 l_ee_country varchar2(255);
366 l_ee_postal_code varchar2(255);
367 l_ee_house_no_field varchar2(255);
368
369
370
371 BEGIN
372
373 if g_debug then
374 hr_utility.trace_on(NULL,'TOF');
375 hr_utility.set_location('Entering ASSIGNMENT_ACTION_CODE',600);
376 end if;
377
378 g_error_flag := hr_general.decode_lookup('HR_NL_REPORT_LABELS','ERROR');
379
380 /*Fetch the Process Parameters by invoking the above procedure
381 Get_all_parameters
382 */
383 get_all_parameters (
384 p_payroll_action_id,l_business_group_id
385 ,l_effective_date,l_tax_year,l_employer_id,l_org_struct_id);
386
387 hr_utility.set_location('l_business_group_id'||l_business_group_id,425);
388 hr_utility.set_location('l_effective_date'||l_effective_date,425);
389 hr_utility.set_location('l_tax_year'||l_tax_year,425);
390 hr_utility.set_location('l_employer_id'||l_employer_id,425);
391
392
393
394 l_tax_year_date:=to_char(l_tax_year,'YYYY');
395 l_tax_year_start_date := to_date('01-01-'||l_tax_year_date,'DD-MM-YYYY');
396 l_tax_year_end_date:= to_date('31-12-'||l_tax_year_date,'DD-MM-YYYY');
397
398 if g_debug then
399 hr_utility.set_location('l_tax_year_end_date'||l_tax_year_end_date,425);
403
400 hr_utility.set_location('l_tax_year_start_date'||l_tax_year_start_date,425);
401 end if;
402
404 FOR Cur_EE_ATS_File_rec in Cur_EE_ATS_File(l_employer_id, l_tax_year_start_date, l_tax_year_end_date, p_start_person_id,p_end_person_id)
405
406 LOOP
407
408 l_assignment_id :=Cur_EE_ATS_File_rec.assignment_id;
409 g_assignment_number:=Cur_EE_ATS_File_rec.assignment_number;
410 g_full_name:=Cur_EE_ATS_File_rec.full_name;
411 g_error_count:=0;
412
413 if g_debug then
414 hr_utility.set_location('l_assignment_id'||l_assignment_id,425);
415 hr_utility.set_location('effective_date'||Cur_EE_ATS_File_rec.effective_date,425);
416 hr_utility.set_location('person_id'||Cur_EE_ATS_File_rec.person_id,425);
417 hr_utility.set_location('employer_id'||Cur_EE_ATS_File_rec.employer_id,425);
418 end if;
419
420 l_locked_aai:=Cur_EE_ATS_File_rec.arch_ass_act_id;
421 hr_utility.set_location('l_locked_aai'||l_locked_aai,425);
422
423 if l_locked_aai is not null then
424
425 l_employee_address:=PAY_NL_GENERAL.get_employee_address(Cur_EE_ATS_File_rec.person_id,l_tax_year_end_date,l_ee_house_number,l_ee_house_no_add,l_ee_street_name,l_ee_line1,l_ee_line2,l_ee_line3,l_ee_city,l_ee_country,l_ee_postal_code);
426
427 l_ee_house_no_field := l_ee_house_number || l_ee_house_no_add;
428
429
430 Mandatory_Check('PAY_NL_ASG_REQUIRED_FIELD','NL_STREET',l_ee_street_name);
431 Mandatory_Check('PAY_NL_ASG_REQUIRED_FIELD','NL_HNO_ADD_TO_HNO',l_ee_house_no_field );
432 Mandatory_Check('PAY_NL_ASG_REQUIRED_FIELD','NL_CITY',l_ee_city);
433
434
435
436 if g_error_count=0 then
437
438
439 /*Create the Assignment Action for the Assignment
440 and Lock the respective Annual tax Statement Archive Assignment Action for the Assignment
441 */
442 SELECT pay_assignment_actions_s.NEXTVAL
443 INTO l_asg_act_id
444 FROM dual;
445 --
446 -- Create the archive assignment action
447 --
448 hr_nonrun_asact.insact(l_asg_act_id,l_Assignment_ID, p_payroll_action_id,p_chunk,NULL);
449 hr_nonrun_asact.insint(l_asg_act_id,l_locked_aai);
450 end if;
451 end if;
452
453 END LOOP;
454
455 if g_debug then
456 hr_utility.set_location('Exiting ASSIGNMENT_ACTION_CODE',600);
457 end if;
458
459 END ASSIGNMENT_ACTION_CODE;
460
461 /*-------------------------------------------------------------------------------
462 |Name : ARCHIVE_INIT |
463 |Type : Procedure |
464 |Description : Initialization Code for Archiver |
465 -------------------------------------------------------------------------------*/
466
467 Procedure ARCHIVE_INIT(p_payroll_action_id IN NUMBER) IS
468
469 BEGIN
470 if g_debug then
471 hr_utility.set_location('Entering Archive Init',600);
472 hr_utility.set_location('Leaving Archive Init',700);
473 end if;
474
475 END ARCHIVE_INIT;
476
477 /*-----------------------------------------------------------------------------
478 |Name : Get_TOS_Sender_Details |
479 |Type : Function |
480 |Description: Function which returns Tax office and Sender Details |
481 -------------------------------------------------------------------------------*/
482
483 FUNCTION Get_TOS_Sender_Details(P_Business_Group_Id in number
484 ,P_Employer_ID in number
485 ,P_Sender_Tax_Rep_Name out nocopy varchar2
486 ,P_Sender_Tax_Reg_Number out nocopy varchar2
487 ,P_Tax_Rep_Name out nocopy varchar2
488 ,P_Tax_Reg_Number out nocopy varchar2) return number IS
489
490 CURSOR csr_Sender_tax_Details IS
491 select ORG_INFORMATION3,ORG_INFORMATION4
492 from hr_organization_information
493 where ORG_INFORMATION_CONTEXT='NL_BG_INFO' and
494 organization_id=P_Business_Group_Id;
495
496 CURSOR csr_tax_details IS
497 select hoi.ORG_INFORMATION14,hoi.ORG_INFORMATION4
498 from hr_organization_units hou,hr_organization_information hoi
499 where
500 hoi.org_information_context= 'NL_ORG_INFORMATION'
501 and hou.business_group_id=p_business_group_id
502 and hou.organization_id= hoi.organization_id
503 and hou.organization_id = P_Employer_ID;
504
505 l_number number;
506
507 BEGIN
508
509 hr_utility.set_location('Entering Get_TOS_Sender_Details',600);
510
511 OPEN csr_Sender_tax_Details;
512 FETCH csr_Sender_tax_Details into P_Sender_Tax_Rep_Name,P_Sender_Tax_Reg_Number;
513 CLOSE csr_Sender_tax_Details;
514
515 if g_debug then
516 hr_utility.set_location('P_Sender_Tax_Rep_Name'||P_Sender_Tax_Rep_Name,425);
517 hr_utility.set_location('P_Sender_Tax_Reg_Number'||P_Sender_Tax_Reg_Number,425);
518 end if;
519
520 OPEN csr_tax_details;
521 FETCH csr_tax_details into P_Tax_Rep_Name,P_Tax_Reg_Number;
522 CLOSE csr_tax_details;
523
524 if g_debug then
525 hr_utility.set_location('P_Tax_Rep_Name'||P_Tax_Rep_Name,425);
526 hr_utility.set_location('P_Tax_Reg_Number'||P_Tax_Reg_Number,425);
527
528 hr_utility.set_location('Leaving Get_TOS_Sender_Details',700);
529 end if;
530
531 l_number:=1;
532 return l_number;
533
534 END Get_TOS_Sender_Details;
535
536
537 END PAY_NL_TAXOFFICE_FILE ;