CREATE OR REPLACE PROCEDURE pr_attendleave(year in varchar2, statdate IN date, empId in varchar2) AS BEGIN DECLARE 司龄 number(10, 2); 工龄 number(10, 2); 核定年休假天数 number(10, 2); num4 number(10); 核定年度最后一天 Date; 核定年度第一天 Date; 核定年度剩余天数 number(10); upyearDay number(10, 2); --上一年剩余年假天数 type ref_c_type is ref cursor; --定义游标 type rec_aaa is record( empid gcemployee.empid%type, joindate gcemployee.joindate%type, startworkdate gcemployee.startworkdate%type, MonthDeduction gcemployee.MonthDeduction%type); empIdResult ref_c_type; --实例化这个游标类型 aaa rec_aaa; ref_c_sql varchar2(500); --动态游标的sql BEGIN ref_c_sql := 'select empid,joindate,startworkdate,MonthDeduction from gcemployee t where t.status=''ES1'''; if (empId is not null) or empId <> '' then ref_c_sql := ref_c_sql || ' and t.empid=''' || empId || ''''; end if; open empIdResult for ref_c_sql; LOOP fetch empIdResult into aaa; exit when empIdResult%notfound; 司龄 := months_between(statdate, aaa.joindate); --司龄 工龄 := months_between(statdate, aaa.startworkdate) - nvl(aaa.MonthDeduction, 0); --工龄 if (year = '2008') then if (司龄 > 24) then --进本单位大于2年的 考虑工作日期 if (工龄 > 21 * 12) then --判断大于21年的 核定年休假天数 := 15; elsif (工龄 > 20 * 12) then --判断大于20 可能出现工龄界点 核定年休假天数 := 10 * (1 - (工龄 - 240) / 12) + 15 * ((工龄 - 240) / 12); elsif (工龄 > 11 * 12) then --判断大于11年 核定年休假天数 := 10; elsif (工龄 > 10 * 12) then --判断大于10年 可能出现工龄界点 核定年休假天数 := 5 * (1 - (工龄 - 120) / 12) + 10 * ((工龄 - 120) / 12); else 核定年休假天数 := 5; --判断小于10年的为5天 end if; elsif (司龄 between 12 and 24) then --不到2年的 需要计算 百分比 if (工龄 > 21 * 12) then --判断大于21年的 核定年休假天数 := 15; elsif (工龄 > 20 * 12) then --判断大于20 核定年休假天数 := 10 * (1 - (工龄 - 240) / 12) + 15 * ((工龄 - 240) / 12); elsif (工龄 > 11 * 12) then --判断大于11年 核定年休假天数 := 10; elsif (工龄 > 10 * 12) then 核定年休假天数 := 5 * (1 - (工龄 - 120) / 12) + 10 * ((工龄 - 120) / 12); else 核定年休假天数 := 5; --判断小于10年的为5天 end if; else --不到1年的均为0 核定年休假天数 := 0; end if; else --大于2008年的 if (司龄 > 24) then --进本单位大于2年的 考虑工作日期 if (工龄 > 21 * 12) then --判断大于21年的 核定年休假天数 := 15; elsif (工龄 > 20 * 12) then --判断大于20 可能出现工龄界点 核定年休假天数 := 10 * (1 - (工龄 - 240) / 12) + 15 * ((工龄 - 240) / 12); elsif (工龄 > 11 * 12) then --判断大于11年 核定年休假天数 := 10; elsif (工龄 > 10 * 12) then --判断大于10年 可能出现工龄界点 核定年休假天数 := 5 * (1 - (工龄 - 120) / 12) + 10 * ((工龄 - 120) / 12); else 核定年休假天数 := 5; --判断小于10年的为5天 end if; elsif (司龄 between 12 and 24) then --不到2年的 需要计算 百分比 if (工龄 > 21 * 12) then --判断大于21年的 核定年休假天数 := 15; elsif (工龄 > 20 * 12) then --判断大于20 核定年休假天数 := 10 * (1 - (工龄 - 240) / 12) + 15 * ((工龄 - 240) / 12); elsif (工龄 > 11 * 12) then --判断大于11年 核定年休假天数 := 10; elsif (工龄 > 10 * 12) then 核定年休假天数 := 5 * (1 - (工龄 - 120) / 12) + 10 * ((工龄 - 120) / 12); elsif (工龄 > 24) then 核定年休假天数 := 5; --判断小于10年的为5天 elsif (工龄 > 12) then 核定年休假天数 := 5 * (工龄 - 12) / 12; --判断小于10年的为5天 else 核定年休假天数 := 0; end if; else --近公司不足一年的 if (工龄 > 21 * 12) then --判断大于21年的 司龄界点 核定年休假天数 := 15 * (司龄) / 12; elsif (工龄 > 20 * 12) then --判断大于20 可能出现工龄、司龄界点 --判断先出现 工龄界点还是司龄界点 if ((工龄 - 240) > (司龄)) then --工龄月份早 如工龄 3月 司龄 5月 核定年休假天数 := 15 * ((司龄) / 12); elsif ((司龄) < (工龄 - 240)) then --工龄月份早 如司龄 5月 工龄 7月 核定年休假天数 := 10 * ((工龄 - 240 + 司龄) / 12) + 15 * (工龄 - 240) / 12; end if; elsif (工龄 > 11 * 12) then --判断大于11年 核定年休假天数 := 10; elsif (工龄 > 10 * 12) then --判断大于10年 可能出现工龄、司龄界点 --判断先出现 工龄界点还是司龄界点 if ((工龄 - 120) > (司龄)) then --工龄月份早 如工龄 3月 司龄 5月 核定年休假天数 := 10 * ((司龄) / 12); elsif ((司龄) < (工龄 - 120)) then --工龄月份早 如司龄 5月 工龄 7月 核定年休假天数 := 5 * ((工龄 - 120 + 司龄) / 12) + 10 * (工龄 - 120) / 12; end if; elsif (工龄 > 24) then 核定年休假天数 := 5; --判断小于10年的为5天 elsif (工龄 > 12) then --核定年休假天数:=5 * (1-(工龄 -12)/12); --判断小于10年的为5天 if ((工龄 - 12) >= (司龄)) then --工龄月份早 如工龄 3月 司龄 5月 核定年休假天数 := 5 * ((司龄) / 12); else --工龄月份早 如司龄 5月 工龄 7月 核定年休假天数 := 5 * (工龄 - 12) / 12; end if; else 核定年休假天数 := 0; end if; end if; end if; -- 统计当年最后一天 核定年度最后一天 := to_date(year || '1231', 'yyyyMMdd'); 核定年度第一天 := to_date(year || '0101', 'yyyyMMdd'); -- 如果是统计当年入司,计算剩余日历 if (aaa.joindate <= 核定年度最后一天 and 核定年度第一天 <= aaa.joindate) then -- 剩余天数 核定年度剩余天数 := trunc((((86400 * (核定年度最后一天 - aaa.joindate)) / 60) / 60) / 24); 核定年休假天数 := trunc(核定年休假天数 * 核定年度剩余天数 / 365); end if; select count(*) into num4 from GCAttendLeave where StatYear = year and EmpID = aaa.empid; if (num4 > 0) then Update GCAttendLeave Set AnnualLeaveI = trunc(核定年休假天数), ynxjleavei = nvl(upyearDay, 0.0) where EmpID = aaa.empid and StatYear = year; else INSERT INTO GCAttendLeave(EmpID, StatYear, AnnualLeaveI, ynxjleavei) VALUES(aaa.empid, year, trunc(核定年休假天数), nvl(upyearDay, 0.0)); end if; END Loop; close empIdResult; END; end;
自定义记录类型游标
猜你喜欢
转载自laonao.iteye.com/blog/1836563
今日推荐
周排行