public void Insert(Model.Leave leave) { Validate(leave); Model.Leave model; int flag = 0; decimal a = Math.Truncate(leave.LeaveDateCount.Value); IList <Model.Leave> mLeaveList = this.SelectLeaveListbyEmp("'" + leave.EmployeeId + "'"); //获得假期列表 IList <Model.AnnualHoliday> holidaylist = new BL.AnnualHolidayManager().SelectBigThanDate(leave.LeaveDate.Value); bool cando; #region 注释 //decimal a = Math.Truncate(leave.LeaveDateCount.Value); //for (int i = 0; i < a; i++) //{ // if (i > 0) // { // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // } // leave.LeaveRange = 0; // accessor.Insert(leave); //} //if (a < leave.LeaveDateCount.Value) //{ // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // leave.LeaveRange = 1; // accessor.Insert(leave); //} #endregion try { BL.V.BeginTransaction(); if (a > 1) { for (int i = 0; i < a; i++) { cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.AddDays(i).Date); if (cando) { continue; } cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value); if (cando) { //continue; throw new Helper.MessageValueException(leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //Model.HrDailyEmployeeAttendInfo hr = hrDatilyManager.SelectByDateAndEmp(leave.EmployeeId,leave.LeaveDate.Value.AddDays(i)); //if (hrDatilyManager.SelectByDateAndEmp(leave.EmployeeId, leave.LeaveDate.Value.AddDays(i)) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); model = new Book.Model.Leave(); model.EmployeeId = leave.EmployeeId; model.LeaveDate = leave.LeaveDate.Value.Date.AddDays(i); model.LeaveDateCount = leave.LeaveDateCount; if (flag == 0) { model.LeaveId = leave.LeaveId; } else { model.LeaveId = Guid.NewGuid().ToString(); } model.LeaveRange = leave.LeaveRange; model.LeaveText = leave.LeaveText; model.LeaveTypeId = leave.LeaveTypeId; accessor.Insert(model); //增加列表项 //mLeaveList.Add(model); if (DateTime.Now.Date > model.LeaveDate) { hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); } flag = 1; } } else { //cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.Date); //if (cando) // throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveDate + "_IsHoliday"); cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value); if (cando) { //throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveId + "_1"); throw new Helper.MessageValueException(leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //if (hrDatilyManager.SelectByDateAndEmp(leave.EmployeeId, leave.LeaveDate.Value) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); accessor.Insert(leave); hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); } BL.V.CommitTransaction(); } catch (Exception ex) { BL.V.RollbackTransaction(); throw ex; } }
public void Insert(Model.Leave leave, IList <Model.Employee> empList) { Validate(leave); //for (int i = 0; i < a; i++) //{ // if (i > 0) // { // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // } // leave.LeaveRange = 0; // accessor.Insert(leave); //} //if (a < leave.LeaveDateCount.Value) //{ // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // leave.LeaveRange = 1; // accessor.Insert(leave); //} IList <Model.Leave> mLeaveList; StringBuilder sb = new StringBuilder(); foreach (Model.Employee emp in empList) { sb.Append("'" + emp.EmployeeId + "',"); } mLeaveList = this.SelectLeaveListbyEmp(sb.ToString().Substring(0, sb.ToString().Length - 1)); //获得假期列表 IList <Model.AnnualHoliday> holidaylist = new BL.AnnualHolidayManager().SelectBigThanDate(DateTime.Parse(DateTime.Now.Date.AddMonths(-1).ToString("yyyy-MM-01"))); bool cando; try { BL.V.BeginTransaction(); Model.Leave model; int flag = 0; decimal a = Math.Truncate(leave.LeaveDateCount.Value); foreach (Model.Employee emp in empList) { if (a > 1) { for (int i = 0; i < a; i++) { cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.AddDays(i).Date); if (cando) { continue; } cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value && mle.EmployeeId == emp.EmployeeId); if (cando) { //continue; throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //if (hrDatilyManager.SelectByDateAndEmp(emp.EmployeeId, leave.LeaveDate.Value.AddDays(i)) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); model = new Book.Model.Leave(); model.EmployeeId = emp.EmployeeId; model.LeaveDate = leave.LeaveDate.Value.Date.AddDays(i); model.LeaveDateCount = leave.LeaveDateCount; if (flag == 0) { model.LeaveId = leave.LeaveId; } else { model.LeaveId = Guid.NewGuid().ToString(); } model.LeaveRange = leave.LeaveRange; model.LeaveText = leave.LeaveText; model.LeaveTypeId = leave.LeaveTypeId; accessor.Insert(model); //增加列表 //mLeaveList.Add(model); if (DateTime.Now.Date > model.LeaveDate) { hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); } flag = 1; } } else { //cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.Date); //if (cando) // throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveDate + "_IsHoliday"); cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value && mle.EmployeeId == emp.EmployeeId); if (cando) { //throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveId + "_1"); throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //if (hrDatilyManager.SelectByDateAndEmp(emp.EmployeeId, leave.LeaveDate.Value) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); model = new Book.Model.Leave(); model.EmployeeId = emp.EmployeeId; model.LeaveDate = leave.LeaveDate.Value.Date; model.LeaveDateCount = leave.LeaveDateCount; if (flag == 0) { model.LeaveId = leave.LeaveId; } else { model.LeaveId = Guid.NewGuid().ToString(); } model.LeaveRange = leave.LeaveRange; model.LeaveText = leave.LeaveText; model.LeaveTypeId = leave.LeaveTypeId; accessor.Insert(model); //增加列表项 //mLeaveList.Add(model); hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); flag = 1; } } BL.V.CommitTransaction(); } catch (Exception ex) { BL.V.RollbackTransaction(); throw; } }
/// <summary> /// 异常考勤订正处理 /// </summary> /// <param name="checkdate"></param> /// <param name="emp"></param> /// <param name="mActualCheckIn"></param> /// <param name="mActualCheckOut"></param> /// <returns></returns> public Model.HrDailyEmployeeAttendInfo Reatten_Controller(DateTime checkdate, Model.Employee emp, DateTime?mActualCheckIn, DateTime?mActualCheckOut) { Model.BusinessHours mBusinessHour = new Book.Model.BusinessHours(); //--當日應上的班別 DateTime? mShouldCheckIn = null; //--應上班時間 DateTime? mShouldCheckOut = null; //--應下班時間 int mLateInMinute = 0; //--遲到(分) Double?mDayFactor = 0; //--日基數 double?mMonthFactor = 0; //--月基數 Double?mSpecialBonus = 0; //--班别津贴 bool mIsNormal = true; //--是否正常出勤 string mNote = string.Empty; //--備註 string mCardNo = string.Empty; //--卡号 //取得班別表及班別津貼集合 IList <Model.BusinessHours> mBusinessHourCollection = new BL.BusinessHoursManager().Select(); //取得年度假日列表 IList <Model.AnnualHoliday> holidayList = new BL.AnnualHolidayManager().SelectAnnualInfoByYear_list(checkdate.Year); //檢查考勤日是否為假日 Model.AnnualHoliday holiday = null; //取得考情日上班部门,确定员工是否休假 bool h_bool = holidayList.Any(pd => (pd.HolidayDate.Value.ToString("yyyy-MM-dd") == checkdate.ToString("yyyy-MM-dd"))); if (h_bool) { holiday = holidayList.Where(pd => (pd.HolidayDate.Value.ToString("yyyy-MM-dd") == checkdate.ToString("yyyy-MM-dd"))).First(); if (holiday != null) { if (!string.IsNullOrEmpty(holiday.Departs)) { if (!holiday.Departs.Contains(emp.DepartmentId)) { holiday = null; } } } } //取得假別列表 IList <Model.LeaveType> mleaveTypeList = new BL.LeaveTypeManager().Select(); //請假資訊 //Model.Leave mLeave = new BL.LeaveManager().GetEmployeeLeavebyDate(emp.EmployeeId, checkdate); IList <Model.Leave> mLeaves = new BL.LeaveManager().GetEmployeeLeavebyDate(emp.EmployeeId, checkdate); //若该请假不参与考勤 2015年4月1日23:31:08:有考勤资料优先,请假靠后 //if (mLeaves != null && mLeaves.Count > 0) //{ // foreach (Model.Leave l in mLeaves) // if (!l.LeaveType.doAttendance.Value) // return null; // //if (!mLeave.LeaveType.doAttendance.Value) // // return null; //} //彈性排班資訊 Model.Flextime mFlexTime = new BL.FlextimeManager().getbyempiddate(emp.EmployeeId, checkdate); if (mFlexTime == null) { //沒有彈性排班,則取原訂班別 mBusinessHour = emp.BusinessHours; } else { //有彈性排班,則排定之訂班別 mBusinessHour = mFlexTime.BusinessHours; } if (mBusinessHour == null) { return(null); } //____查詢是否有換臨時卡 Model.TempCard mTempCard = new BL.TempCardManager().Selectbyemployeedate(emp.EmployeeId, checkdate, checkdate); if (mTempCard == null) { mCardNo = emp.CardNo; } else { mCardNo = mTempCard.CardNo; } if (holiday == null) { //---------------------------------------------- //非假日:查詢是否有請假及彈性排班, //並查出該員當日應上的班別 //---------------------------------------------- //先找出該員正常應上下班之時間 if (mBusinessHour.Fromtime.Value.Hour == 0) { mShouldCheckIn = DateTime.Parse(checkdate.AddDays(1).ToShortDateString() + " " + "00:" + mBusinessHour.Fromtime.Value.Minute.ToString().PadLeft(2, '0')); } else { mShouldCheckIn = DateTime.Parse(checkdate.ToShortDateString() + " " + mBusinessHour.Fromtime.Value.Hour.ToString().PadLeft(2, '0') + ":" + mBusinessHour.Fromtime.Value.Minute.ToString().PadLeft(2, '0')); } if (mBusinessHour.Fromtime.Value.Hour > mBusinessHour.ToTime.Value.Hour || mBusinessHour.Fromtime.Value.Hour == 0) //上班時段有跨日 { mShouldCheckOut = DateTime.Parse(checkdate.AddDays(1).ToShortDateString() + " " + mBusinessHour.ToTime.Value.Hour.ToString().PadLeft(2, '0') + ":" + mBusinessHour.ToTime.Value.Minute.ToString().PadLeft(2, '0')); } else //沒有跨日 { if (mBusinessHour.ToTime.Value.Hour == 0) { mShouldCheckOut = DateTime.Parse(checkdate.AddDays(1).ToShortDateString() + " " + "00:" + ":" + mBusinessHour.ToTime.Value.Minute.ToString().PadLeft(2, '0')); } else { mShouldCheckOut = DateTime.Parse(checkdate.ToShortDateString() + " " + mBusinessHour.ToTime.Value.Hour.ToString().PadLeft(2, '0') + ":" + mBusinessHour.ToTime.Value.Minute.ToString().PadLeft(2, '0')); } } //是否有請假 if (mLeaves != null && mLeaves.Count > 0) { if (mLeaves.Count == 1) //本日只有一条请假记录 { Model.LeaveType mLeaveType = mLeaves[0].LeaveType; switch (mLeaves[0].LeaveRange.Value) { case 0: //請整日 //mShouldCheckIn = null; //请假也有应上下班时间,为了下面计算实际上下班时间,即使请假但是有上下班时间还是要显示出来。 //mShouldCheckOut = null; if (mLeaveType.PayRate.Value == 0.5) { mDayFactor = 0.5; } else { mDayFactor = Convert.ToInt32(mLeaveType.PayRate); } //if (emp.IsMigrantWorker) //外劳员工请假不计工资(外劳以月薪计算) // mMonthFactor = 0; //else mMonthFactor = 1; mIsNormal = true; mNote = mLeaves[0].LeaveType.ToString() + "(整日)"; break; case 1: //請上半日 mShouldCheckIn = mShouldCheckOut.Value.AddHours(-4); //以應下班時間減四小時為應上班時間 if (mLeaveType.PayRate.Value == 0.5) { mDayFactor = 0.75; } else { mDayFactor = 0.5 + 0.5 * mLeaveType.PayRate; } mNote = mLeaves[0].LeaveType.ToString() + "(上半日)"; //if (emp.IsMigrantWorker) // mMonthFactor = 0.5; //else mMonthFactor = 1; break; case 2: //請下半日 mShouldCheckOut = mShouldCheckIn.Value.AddHours(4); //以應上班時間加四小時為應下班時間 if (mLeaveType.PayRate.Value == 0.5) { mDayFactor = 0.75; } else { mDayFactor = 0.5 + 0.5 * mLeaveType.PayRate; } mNote = mLeaves[0].LeaveType.ToString() + "(下半日)"; //if (emp.IsMigrantWorker) // mMonthFactor = 0.5; //else mMonthFactor = 1; break; } } else //上下半天都有请假记录 { //mShouldCheckIn = null; //mShouldCheckOut = null; mIsNormal = true; string _aNote = string.Empty; double _aDayFactor = 0; foreach (Model.Leave l in mLeaves) { _aDayFactor += l.LeaveType.PayRate.Value / 2; if (l.LeaveRange == 1) { _aNote += l.LeaveType.ToString() + "(上半日)"; } else { _aNote += l.LeaveType.ToString() + "(下半日)"; } } mDayFactor = _aDayFactor; mNote = _aNote; if (emp.IsMigrantWorker) //外劳员工请假不计工资(外劳以月薪计算) { mMonthFactor = 0; } else { mMonthFactor = 1; } } } //判斷出勤記錄 //___找不到上下班打卡資料 if (mActualCheckIn == null || mActualCheckOut == null) { //有請假 if (mLeaves != null && mLeaves.Count > 0) { if (mLeaves.Count == 1) { //只對請半天的做處理 if (mLeaves[0].LeaveRange != 0) { mIsNormal = false; mNote = mNote + ";卻刷卡資料"; } } } else //沒請假 { mIsNormal = false; mNote = "卻刷卡資料"; } } //___有上下班打卡資料 else { if (mLeaves != null && mLeaves.Count > 0) { //有請假 Model.LeaveType mLeaveType = mLeaves[0].LeaveType; if (mLeaves[0].LeaveRange != 0) { //只對請半天的做處理 if (mLeaveType.PayRate.Value == 0.5) { mDayFactor = 0.75; } else { mDayFactor = 0.5 + 0.5 * mLeaveType.PayRate; } //if (emp.IsMigrantWorker) // mMonthFactor = 0.5; //else mMonthFactor = 1; mSpecialBonus = Convert.ToDouble(mBusinessHour.SpecialPay) * 0.5; mIsNormal = true; } } else { //沒請假 mDayFactor = 1; mMonthFactor = 1; mSpecialBonus = Convert.ToDouble(mBusinessHour.SpecialPay); mIsNormal = true; } //if (mActualCheckIn > mShouldCheckIn && mLeaves != null && mLeaves.Count > 0 && mLeaves[0].LeaveRange != 0) if (mActualCheckIn > mShouldCheckIn && !(mLeaves != null && mLeaves.Count > 0 && mLeaves[0].LeaveRange == 0)) { TimeSpan ts = TimeSpan.Parse((mActualCheckIn - mShouldCheckIn).ToString()); mLateInMinute = ts.Hours * 60 + ts.Minutes; if (mLateInMinute > 0) { //if (mLateInMinute > 10) //{ //遲到超過10分鐘,顯示異常(讓員工有申訴機會) mIsNormal = false; //if (mNote != "") if (!string.IsNullOrEmpty(mNote)) { mNote = mNote + ";"; } mNote = mNote + "遲到"; //} } } else { mLateInMinute = 0; } //早退超過5分鐘,顯示異常 //if (mActualCheckOut < mShouldCheckOut && mLeaves != null && mLeaves.Count > 0 && mLeaves[0].LeaveRange != 0) if (mActualCheckOut < mShouldCheckOut && !(mLeaves != null && mLeaves.Count > 0 && mLeaves[0].LeaveRange == 0)) { TimeSpan ts = TimeSpan.Parse((mShouldCheckOut - mActualCheckOut).ToString()); int mLeaveEarly = ts.Hours * 60 + ts.Minutes; if (mLeaveEarly > 0) { mIsNormal = false; //if (mNote != "") if (!string.IsNullOrEmpty(mNote)) { mNote = mNote + ";"; } mNote = mNote + "早退"; } } } } else { //假日 mDayFactor = 1; mMonthFactor = 1; mLateInMinute = 0; mIsNormal = true; mNote = holiday.HolidayName; //找出是否有假日出勤記錄 //___依正常排班表來判 DateTime mayBeCheckIn = global::Helper.DateTimeParse.NullDate; DateTime mayBeCheckOut = global::Helper.DateTimeParse.NullDate; //先找出該員可能上下班之時間 if (mBusinessHour.Fromtime.Value.Hour == 0) { mayBeCheckIn = DateTime.Parse(checkdate.AddDays(1).ToString("yyyy-MM-dd") + " " + "00:" + mBusinessHour.Fromtime.Value.Minute.ToString().PadLeft(2, '0')); } else { mayBeCheckIn = DateTime.Parse(checkdate.ToString("yyyy-MM-dd") + " " + mBusinessHour.Fromtime.Value.Hour.ToString().PadLeft(2, '0') + ":" + mBusinessHour.Fromtime.Value.Minute.ToString().PadLeft(2, '0')); } if (mBusinessHour.Fromtime.Value.Hour > mBusinessHour.ToTime.Value.Hour) { //上班時段有跨日 mayBeCheckOut = DateTime.Parse(checkdate.AddDays(1).ToString("yyyy-MM-dd") + " " + mBusinessHour.ToTime.Value.Hour.ToString().PadLeft(2, '0') + ":" + mBusinessHour.ToTime.Value.Minute.ToString().PadLeft(2, '0')); } else { //上班時段有沒有跨日 if (mBusinessHour.ToTime.Value.Hour == 0) { mayBeCheckOut = DateTime.Parse(checkdate.AddDays(1).ToString("yyyy-MM-dd") + " " + "00:" + ":" + mBusinessHour.ToTime.Value.Minute.ToString().PadLeft(2, '0')); } else { mayBeCheckOut = DateTime.Parse(checkdate.ToString("yyyy-MM-dd") + " " + mBusinessHour.ToTime.Value.Hour.ToString().PadLeft(2, '0') + ":" + mBusinessHour.ToTime.Value.Minute.ToString().PadLeft(2, '0')); } } //有正常刷卡假日加班 if (mActualCheckIn != null && mActualCheckOut != null) { //------------------------------ //檢查是否有上滿一整個班別 //若有,則給予班別津貼 //------------------------------ TimeSpan ts1 = TimeSpan.Parse((mActualCheckOut - mActualCheckIn).ToString()); TimeSpan ts2 = TimeSpan.Parse((mayBeCheckOut - mayBeCheckOut).ToString()); if (ts1.Minutes >= ts2.Minutes) { mSpecialBonus = Convert.ToDouble(mBusinessHour.SpecialPay); } } } Model.HrDailyEmployeeAttendInfo _hrEA = new Book.Model.HrDailyEmployeeAttendInfo(); _hrEA.HrDailyEmployeeAttendInfoId = Guid.NewGuid().ToString(); _hrEA.DutyDate = checkdate; _hrEA.EmployeeId = emp.EmployeeId; _hrEA.ShouldCheckIn = mShouldCheckIn; _hrEA.ShouldCheckOut = mShouldCheckOut; _hrEA.ActualCheckIn = mActualCheckIn; _hrEA.ActualCheckOut = mActualCheckOut; _hrEA.LateInMinute = mLateInMinute; _hrEA.DayFactor = mDayFactor; _hrEA.MonthFactor = mMonthFactor; _hrEA.SpecialBonus = Convert.ToInt32(mSpecialBonus); _hrEA.IsNormal = mIsNormal; _hrEA.Note = mNote; _hrEA.MBusinessHours = mBusinessHour; _hrEA.MLeave = (mLeaves == null || mLeaves.Count == 0) ? null : mLeaves[0]; ReattenSave(_hrEA); return(_hrEA); }