DBA Data[Home] [Help]

PACKAGE: APPS.PAY_NO_EMP_CONT_2007

Source


1 PACKAGE PAY_NO_EMP_CONT_2007 AS
2 /* $Header: pynoempcont2007.pkh 120.0.12010000.1 2008/07/27 23:13:59 appldev ship $ */
3 
4 ------------------------------- Definig Globals and initializing ----------------------------------------------------
5 
6 g_error_flag	BOOLEAN	:= FALSE;
7 
8 g_error_check	BOOLEAN := FALSE;
9 
10 --------------------------------Defining record Types------------------------------------------------
11 
12 -- record type for Main table for Legal Employer and Local Unit
13 
14 TYPE g_tab_main_rectype IS
15    RECORD ( legal_employer_id           NUMBER
16            ,local_unit_id           	NUMBER
17 	   ,zone                        VARCHAR2(10)
18 	   ,exemption_limit_used	NUMBER
19 	   ,run_base			NUMBER
20 	   ,run_contribution            NUMBER );
21 
22 
23 -- record type for Calculation table for Legal Employer and Local Unit
24 
25 TYPE g_tab_calc_rectype IS
26    RECORD ( zone                        VARCHAR2(10)
27            ,under_limit                 VARCHAR2(10)
28            ,status                      VARCHAR2(200)
29            ,bimonth_base                NUMBER
30            ,run_base                    NUMBER
31            ,bimonth_contribution        NUMBER
32            ,bimonth_contribution_todate NUMBER
33            ,run_contribution            NUMBER );
34 
35 
36 
37 ---------------------------------Defining Table Types-----------------------------------------------
38 
39 
40 -- table type for Main table for Legal Employer and Local Unit
41 
42 TYPE g_tab_main_tabtype IS TABLE OF g_tab_main_rectype
43    INDEX BY BINARY_INTEGER;
44 
45 
46 -- table type for Calculation table for Legal Employer and Local Unit
47 
48 TYPE g_tab_calc_tabtype IS TABLE OF g_tab_calc_rectype
49    INDEX BY BINARY_INTEGER;
50 
51 ------------------new table types
52 
53 -- table type for unique LU
54 TYPE g_lu_tabtype IS TABLE OF NUMBER (20)
55    INDEX BY BINARY_INTEGER;
56 
57 -- table type for unique MU
58 -- changing type from Number to Varchar for Jurisdiction code (text) / TM
59 
60  TYPE g_mu_tabtype IS TABLE OF VARCHAR2 (20)
61    INDEX BY BINARY_INTEGER;
62 
63 
64 
65 
66 ---------------------------------Defining Global PL/SQL Table -----------------------------------------------
67 
68 	g_tab_main		PAY_NO_EMP_CONT_2007.g_tab_main_tabtype;
69 
70 --------------------------------Cursor Definitions ----------------------------------------------------------
71 
72     -- cursor to get Status and Report Separately from Local Unit
73 	cursor get_lu_details(l_local_unit_id   NUMBER) IS
74 	select ORG_INFORMATION4 status , ORG_INFORMATION5 report_sep , ORG_INFORMATION6 lu_tax_mun
75 	from HR_ORGANIZATION_INFORMATION
76 	where ORGANIZATION_ID = l_local_unit_id
77 	and org_information_context = 'NO_LOCAL_UNIT_DETAILS';
78 
79 
80 
81     -- Cursor to get the payroll_action_id
82 
83 	cursor csr_payroll_action_id (p_date_earned  DATE ) is
84 	select ppa.PAYROLL_ACTION_ID
85 	from pay_payroll_actions	ppa
86 	    ,pay_run_types_f		prt
87 	where ppa.RUN_TYPE_ID = prt.RUN_TYPE_ID
88 	and   prt.LEGISLATION_CODE = 'NO'
89 	and   prt.RUN_TYPE_NAME IN ('Main','Standard','Process Alone','Pay Separately')
90 	and   p_date_earned between prt.EFFECTIVE_START_DATE and prt.EFFECTIVE_END_DATE
91 	and  ppa.effective_date between trunc(Add_months(p_date_earned,MOD(TO_NUMBER(TO_CHAR(p_date_earned,'MM')),2)-1),'MM')
92                     	        and     last_day(Add_months(p_date_earned,MOD(TO_NUMBER(TO_CHAR(p_date_earned,'MM')),2)));
93 
94 
95 
96 	-- Cursor to get the assignment_action_id and assignment_id
97 	cursor csr_assignment_id (p_tax_unit_id   pay_assignment_actions.TAX_UNIT_ID%TYPE
98     	                     ,l_payroll_action_id  pay_payroll_actions.PAYROLL_ACTION_ID%type) is
99 	select ASSIGNMENT_ID
100 	      ,ASSIGNMENT_ACTION_ID
101 	from pay_assignment_actions
102 	where PAYROLL_ACTION_ID = l_payroll_action_id
103 	and TAX_UNIT_ID = p_tax_unit_id;
104 
105 	-- Cursor to get the Local Unit and Tax Municipality
106 
107 	cursor csr_lu_mu (l_assignment_id   per_all_assignments_f.ASSIGNMENT_ID%type
108 	                 ,l_assignment_action_id   pay_assignment_actions.ASSIGNMENT_ACTION_ID   %type
109 			 ,p_date_earned  DATE
110 			 ,l_ele_type_id	 NUMBER ) is
111 	SELECT scl.segment2             local_unit_id
112     	      ,rr.jurisdiction_code     tax_mun_id
113 	FROM pay_assignment_actions   assact
114 	    ,per_all_assignments_f    asg
115 	    ,hr_soft_coding_keyflex   scl
116 	    ,pay_run_results          rr
117 	WHERE assact.assignment_action_id = l_assignment_action_id
118 	AND   assact.assignment_id = asg.assignment_id
119 	AND   asg.assignment_id = l_assignment_id
120 	AND   p_date_earned BETWEEN asg.EFFECTIVE_START_DATE AND asg.EFFECTIVE_END_DATE
121 	AND   asg.SOFT_CODING_KEYFLEX_ID = scl.SOFT_CODING_KEYFLEX_ID
122 	AND   assact.assignment_action_id = rr.assignment_action_id
123 	AND   rr.ELEMENT_TYPE_ID = l_ele_type_id
124 	AND   rr.ASSIGNMENT_ACTION_ID = l_assignment_action_id ;
125 
126 
127 	-- cursor to get the Local Units (LU) and Legal Employers (LE) of the current assignments
128 
129 	cursor csr_get_lu_le
130 		(p_payroll_action_id  pay_payroll_actions.PAYROLL_ACTION_ID%type
131 		,p_date_earned  DATE ) is
132 
133 	SELECT  scl.segment2	loc_unit , assact.tax_unit_id	leg_emp
134 	FROM pay_assignment_actions	assact
135 	    ,pay_run_types_f		prt
136 	    ,per_all_assignments_f	asg
137 	    ,hr_soft_coding_keyflex	scl
138 	WHERE	assact.PAYROLL_ACTION_ID = p_payroll_action_id
139 	and	prt.LEGISLATION_CODE = 'NO'
140 	and	prt.RUN_TYPE_NAME = 'Employer Contributions'
141 	and	nvl(assact.RUN_TYPE_ID,-99) <> prt.RUN_TYPE_ID
142 	and	p_date_earned between prt.EFFECTIVE_START_DATE and prt.EFFECTIVE_END_DATE
143 	and	asg.assignment_id = assact.assignment_id
144 	and	asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id
145 	group by scl.segment2 ,assact.tax_unit_id ;
146 
147 
148     -- cursor to get Name of Organisation (LE or LU) from org_id
149 
150     CURSOR csr_org_name (p_org_id  HR_ORGANIZATION_UNITS.ORGANIZATION_ID%TYPE ,
151                          p_bus_group_id  HR_ORGANIZATION_UNITS.BUSINESS_GROUP_ID%TYPE ) IS
152     SELECT NAME
153     FROM HR_ORGANIZATION_UNITS
154     WHERE ORGANIZATION_ID = p_org_id
155     AND BUSINESS_GROUP_ID = p_bus_group_id ;
156 
157 
158     -- cursor to get STATUS from Legal Employer
159     cursor get_le_status(p_tax_unit_id   pay_assignment_actions.TAX_UNIT_ID%TYPE) IS
160     select ORG_INFORMATION3
161     from HR_ORGANIZATION_INFORMATION
162     where ORGANIZATION_ID = p_tax_unit_id
163     and org_information_context = 'NO_LEGAL_EMPLOYER_DETAILS';
164 
165 /*
166    -- cursor to get the Exemption Limit of Legal Employer or Local Unit
167 	cursor csr_get_exemption_limit (p_org_id NUMBER , p_date_earned DATE) is
168 	select nvl(to_number(ORG_INFORMATION1),0)
169 	from hr_organization_information
170 	where ORGANIZATION_ID = p_org_id
171 	and ORG_INFORMATION_CONTEXT = 'NO_NI_EXEMPTION_LIMIT'
172 	and p_date_earned between fnd_date.canonical_to_date(ORG_INFORMATION2) and fnd_date.canonical_to_date(ORG_INFORMATION3);
173 
174 */
175 
176    -- 2007 Legislative changes for Economic support to Employer
177    -- a new field 'Economic Aid' (ORG_INFORMATION4) has been added
178 
179    -- cursor to get the Exemption Limit of Legal Employer or Local Unit
180 
181 /*
182 	cursor csr_get_exemption_limit (p_org_id NUMBER , p_date_earned DATE) is
183 	select nvl(fnd_number.canonical_to_number(ORG_INFORMATION1),0) exemption_limit
184 	      ,nvl(fnd_number.canonical_to_number(ORG_INFORMATION4),0) economic_aid
185 	from hr_organization_information
186 	where ORGANIZATION_ID = p_org_id
187 	and ORG_INFORMATION_CONTEXT = 'NO_NI_EXEMPTION_LIMIT'
188 	and p_date_earned between fnd_date.canonical_to_date(ORG_INFORMATION2) and fnd_date.canonical_to_date(ORG_INFORMATION3);
189 
190 */
191 
192    -- cursor to get the Exemption Limit And Economic Aid of Legal Employer or Local Unit
193    -- modified the cursor to fetch the sum of exemption limit and economic aid values over the entire year
194 
195 	cursor csr_get_exemption_limit (p_org_id NUMBER , p_date_earned DATE) is
196 	select sum(nvl(fnd_number.canonical_to_number(ORG_INFORMATION1),0)) exemption_limit
197 	      ,sum(nvl(fnd_number.canonical_to_number(ORG_INFORMATION4),0)) economic_aid
198 	from hr_organization_information
199 	where ORGANIZATION_ID = p_org_id
200 	and ORG_INFORMATION_CONTEXT = 'NO_NI_EXEMPTION_LIMIT'
201 	and fnd_date.canonical_to_date(ORG_INFORMATION2) between trunc(p_date_earned,'YYYY') and add_months(trunc(p_date_earned,'YYYY')-1,12)
202 	and fnd_date.canonical_to_date(ORG_INFORMATION3) between trunc(p_date_earned,'YYYY') and add_months(trunc(p_date_earned,'YYYY')-1,12);
203 
204 ----------------------------------Function declarations----------------------------------------------
205 
206 
207 -- Function to calculate the Employer Contributions
208 
209 FUNCTION GET_EMPLOYER_DEDUCTION
210   (p_tax_unit_id    		IN  NUMBER
211   ,p_local_unit_id  		IN  NUMBER
212   ,p_jurisdiction_code		IN  VARCHAR2
213   ,p_payroll_id     		IN  NUMBER
214   ,p_payroll_action_id		IN  NUMBER
215   ,p_date_earned    		IN  DATE
216   ,p_asg_act_id     		IN  NUMBER
217   ,p_bus_group_id		IN  NUMBER
218   ,p_under_age_high_rate	IN  NUMBER
219   ,p_over_age_high_rate		IN  NUMBER
220   ,p_run_base			OUT NOCOPY  NUMBER
221   ,p_run_contribution      	OUT NOCOPY  NUMBER
222   ,p_curr_exemption_limit_used	OUT NOCOPY  NUMBER) RETURN NUMBER  ;
223 
224 
225 -- Function to get defined balance id
226 
227 FUNCTION get_defined_balance_id
228   (p_balance_name   		IN  VARCHAR2
229   ,p_dbi_suffix     		IN  VARCHAR2 ) RETURN NUMBER ;
230 
231 
232 FUNCTION populate_tables
233   (p_tax_unit_id    IN  NUMBER
234   ,p_payroll_id     IN  NUMBER
235   ,p_date_earned    IN  DATE
236   ,g_lu_tab    	    IN  OUT NOCOPY PAY_NO_EMP_CONT_2007.g_lu_tabtype
237   ,g_mu_tab  	    IN  OUT NOCOPY PAY_NO_EMP_CONT_2007.g_mu_tabtype ) RETURN NUMBER ;
238 
239 
240 -- function to get the lookup meaning
241   FUNCTION get_lookup_meaning (p_lookup_type IN varchar2,p_lookup_code IN varchar2) RETURN VARCHAR2 ;
242 
243 -- Function to look up the corresponding cell number in he table g_tab_calc
244 FUNCTION lookup_cell
245   (g_tab_calc  IN  PAY_NO_EMP_CONT_2007.g_tab_calc_tabtype
246   ,l_zone      IN  VARCHAR2 ) RETURN NUMBER ;
247 
248 
249 -- function for main calculation
250 
251 FUNCTION ec_main_calculation
252 
253   (g_tab_calc  			IN  OUT NOCOPY 	PAY_NO_EMP_CONT_2007.g_tab_calc_tabtype
254   ,g_tab_main  			IN  OUT NOCOPY  PAY_NO_EMP_CONT_2007.g_tab_main_tabtype
255   ,p_tax_unit_id    		IN  NUMBER
256   ,p_local_unit_id 		IN  NUMBER
257   ,p_exemption_limit_used 	IN  NUMBER
258   ,p_org_status 		IN  VARCHAR2
259   ,p_bus_group_id      		IN  NUMBER
260   ,p_date_earned    		IN  DATE
261   ,p_under_age_high_rate	IN  NUMBER
262   ,p_over_age_high_rate		IN  NUMBER
263   ,l_curr_zone			IN  VARCHAR2
264   ) RETURN NUMBER ;
265 
266 
267 -- function to get the ec rate
268 
269 FUNCTION get_ec_rate
270 
271   (p_zone			IN  VARCHAR2
272   ,p_under_limit		IN  VARCHAR2
273   ,p_org_status 		IN  VARCHAR2
274   ,p_bus_group_id      		IN  NUMBER
275   ,p_date_earned    		IN  DATE
276   ,p_under_age_high_rate	IN  NUMBER
277   ,p_over_age_high_rate		IN  NUMBER ) RETURN NUMBER ;
278 
279 
280 -- function to display table values of g_tab_calc
281 
282 FUNCTION display_table_calc
283   (g_tab_calc  IN  PAY_NO_EMP_CONT_2007.g_tab_calc_tabtype ) RETURN NUMBER ;
284 
285 
286 -- function to get the average NI Base Rate Value
287 
288 FUNCTION avg_ni_base_rate (p_date_earned  IN  DATE , p_bus_grp_id NUMBER ) RETURN NUMBER ;
289 
290 
291 -- Function to look up the corresponding cell number in he table g_tab_main
292 
293 FUNCTION main_lookup_cell
294   (g_tab_main  		IN  PAY_NO_EMP_CONT_2007.g_tab_main_tabtype
295   ,start_main_index	IN  NUMBER
296   ,l_zone      		IN  VARCHAR2 ) RETURN NUMBER ;
297 
298 
299 -- Function to check if any exemption limit error exists
300 
301 FUNCTION chk_exemption_limit_err
302   (p_date_earned	IN  DATE
303   ,p_bus_grp_id		IN  NUMBER
304   ,p_payroll_action_id  IN  NUMBER )  RETURN NUMBER ;
305 
306 
307 -- function to get the employer contribution rate
308 FUNCTION get_emp_contr_rate
309 
310   (p_bus_group_id		IN NUMBER,
311   p_tax_unit_id			IN NUMBER,
312   p_local_unit_id		IN NUMBER,
313   p_jurisdiction_code		IN VARCHAR2,
314   p_date_earned			IN DATE,
315   p_asg_act_id			IN NUMBER,
316   p_under_age_high_rate		IN NUMBER,
317   p_over_age_high_rate		IN NUMBER,
318   p_under_limit			IN VARCHAR2 ) RETURN NUMBER;
319 
320 
321 --------------------------------------------------------------------------------
322 
323 
324 
325 END PAY_NO_EMP_CONT_2007 ;