protected override void afterUpdate(DatabaseConnection dbConn, DBManager db) { int oldLeaveTypeID = 0; int newLeaveTypeID = m_LeaveTypeID; DateTime oldLeaveBalanceEntitleDateExpiry = new DateTime(); DateTime newLeaveBalanceEntitleDateExpiry = m_LeaveBalanceEntitleDateExpiry; if (oldValueObject != null) { ELeaveBalanceEntitle oldLeaveBalanceEntitle = (ELeaveBalanceEntitle)oldValueObject; oldLeaveTypeID = oldLeaveBalanceEntitle.LeaveTypeID; oldLeaveBalanceEntitleDateExpiry = oldLeaveBalanceEntitle.LeaveBalanceEntitleDateExpiry; } { ELeaveType leaveType = new ELeaveType(); if (!oldLeaveBalanceEntitleDateExpiry.Ticks.Equals(0)) { leaveType.LeaveTypeID = oldLeaveTypeID; if (ELeaveType.db.select(dbConn, leaveType)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, this.EmpID, leaveType.LeaveTypeID, oldLeaveBalanceEntitleDateExpiry); } } if (!newLeaveBalanceEntitleDateExpiry.Ticks.Equals(0)) { leaveType.LeaveTypeID = newLeaveTypeID; if (ELeaveType.db.select(dbConn, leaveType)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, this.EmpID, leaveType.LeaveTypeID, newLeaveBalanceEntitleDateExpiry); } } } base.afterUpdate(dbConn, db); }
public static void DeleteLeaveBalanceAfter(DatabaseConnection dbConn, int EmpID, int LeaveTypeID, DateTime DateAfter) { ELeaveType leaveType_SLCat1 = ELeaveType.SLCAT1_LEAVE_TYPE(dbConn); ELeaveType leaveType_SLCat2 = ELeaveType.SLCAT2_LEAVE_TYPE(dbConn); DBFilter filter = new DBFilter(); filter.add(new Match("EmpID", EmpID)); if (LeaveTypeID > 0) { OR orLeaveTypeID = new OR(); orLeaveTypeID.add(new Match("LeaveTypeID", LeaveTypeID)); if (leaveType_SLCat1 != null && leaveType_SLCat2 != null) { if (LeaveTypeID.Equals(leaveType_SLCat1.LeaveTypeID)) { orLeaveTypeID.add(new Match("LeaveTypeID", leaveType_SLCat2.LeaveTypeID)); } if (LeaveTypeID.Equals(leaveType_SLCat2.LeaveTypeID)) { orLeaveTypeID.add(new Match("LeaveTypeID", leaveType_SLCat1.LeaveTypeID)); } } filter.add(orLeaveTypeID); } // Do NOT remove entitlement history. Keep history for retriving expiry date //DBFilter entitleFilter = new DBFilter(filter); if (!DateAfter.Ticks.Equals(0)) { filter.add(new Match("LeaveBalanceEffectiveDate", ">", DateAfter)); // entitleFilter.add(new Match("LeaveBalanceEntitleEffectiveDate", ">", DateAfter)); } ELeaveBalance.db.delete(dbConn, filter); //ELeaveBalanceEntitle.db.delete(dbConn, entitleFilter); }
protected override void afterUpdate(DatabaseConnection dbConn, DBManager db) { DateTime oldLeaveAdjustDate = new DateTime(); DateTime newLeaveAdjustDate = m_CompensationLeaveEntitleEffectiveDate; if (oldValueObject != null) { ECompensationLeaveEntitle oldCompLeaveEntitle = (ECompensationLeaveEntitle)oldValueObject; oldLeaveAdjustDate = oldCompLeaveEntitle.CompensationLeaveEntitleEffectiveDate; } { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, m_EmpID, ELeaveType.COMPENSATION_LEAVE_TYPE(dbConn).LeaveTypeID, oldLeaveAdjustDate); ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, m_EmpID, ELeaveType.COMPENSATION_LEAVE_TYPE(dbConn).LeaveTypeID, newLeaveAdjustDate); } base.afterUpdate(dbConn, db); }
private static void DeleteLeaveApplication(DatabaseConnection dbConn, ERosterTable rosterTable) { if (rosterTable.LeaveAppID > 0) { DBFilter attendanceRecordFilter = new DBFilter(); attendanceRecordFilter.add(new Match("LeaveAppID", rosterTable.LeaveAppID)); // do not delete leave application if the attendance record use that leave application if (EAttendanceRecord.db.count(dbConn, attendanceRecordFilter) > 0) { return; } ERosterCode rosterCode = new ERosterCode(); rosterCode.RosterCodeID = rosterTable.RosterCodeID; if (ERosterCode.db.select(dbConn, rosterCode)) { ELeaveApplication leaveApp = new ELeaveApplication(); leaveApp.LeaveAppID = rosterTable.LeaveAppID; if (ELeaveApplication.db.select(dbConn, leaveApp)) { if (leaveApp.EmpPayrollID <= 0 && rosterCode.LeaveCodeID.Equals(leaveApp.LeaveCodeID) && rosterTable.RosterTableDate.Equals(leaveApp.LeaveAppDateFrom) && rosterTable.RosterTableDate.Equals(leaveApp.LeaveAppDateTo) ) { ELeaveCode leaveCode = new ELeaveCode(); leaveCode.LeaveCodeID = leaveApp.LeaveCodeID; if (ELeaveCode.db.select(dbConn, leaveCode)) { ELeaveApplication.db.delete(dbConn, leaveApp); } } } } } if (rosterTable.RosterCodeID > 0 && rosterTable.LeaveAppID <= 0) { ERosterCode rosterCode = new ERosterCode(); rosterCode.RosterCodeID = rosterTable.RosterCodeID; if (ERosterCode.db.select(dbConn, rosterCode)) { if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_RESTDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, rosterTable.EmpID, ELeaveType.RESTDAY_LEAVE_TYPE(dbConn).LeaveTypeID, rosterTable.RosterTableDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_STATUTORYHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, rosterTable.EmpID, ELeaveType.STATUTORYHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, rosterTable.RosterTableDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_PUBLICHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, rosterTable.EmpID, ELeaveType.PUBLICHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, rosterTable.RosterTableDate); } } } }
private static void CreateLeaveApplication(DatabaseConnection dbConn, ERosterTable rosterTable) { if (rosterTable.LeaveAppID == 0) { DBFilter attendanceRecordFilter = new DBFilter(); attendanceRecordFilter.add(new Match("EmpID", rosterTable.EmpID)); attendanceRecordFilter.add(new Match("AttendanceRecordDate", rosterTable.RosterTableDate)); attendanceRecordFilter.add(new Match("RosterCodeID", rosterTable.RosterCodeID)); attendanceRecordFilter.add(new Match("LeaveAppID", ">", 0)); System.Collections.ArrayList existingAttendanceRecordList = EAttendanceRecord.db.select(dbConn, attendanceRecordFilter); // do not create leave application if the attendance record for that day exists if (existingAttendanceRecordList.Count > 0) { rosterTable.LeaveAppID = ((EAttendanceRecord)existingAttendanceRecordList[0]).LeaveAppID; return; } } if (rosterTable.LeaveAppID == 0) { DBFilter attendanceRecordFilter = new DBFilter(); attendanceRecordFilter.add(new Match("EmpID", rosterTable.EmpID)); attendanceRecordFilter.add(new Match("AttendanceRecordDate", rosterTable.RosterTableDate)); attendanceRecordFilter.add(new Match("RosterCodeID", "<>", rosterTable.RosterCodeID)); // do not create leave application if the attendance record for that day exists if (EAttendanceRecord.db.count(dbConn, attendanceRecordFilter) > 0) { return; } } if (rosterTable.LeaveAppID > 0) { ELeaveApplication leaveApp = new ELeaveApplication(); leaveApp.LeaveAppID = rosterTable.LeaveAppID; if (!ELeaveApplication.db.select(dbConn, leaveApp)) { rosterTable.LeaveAppID = 0; } } // Check LeaveAppID <= 0 To prevent override LeaveAppID created by external function if (rosterTable.RosterCodeID > 0 && rosterTable.LeaveAppID <= 0) { ERosterCode rosterCode = new ERosterCode(); rosterCode.RosterCodeID = rosterTable.RosterCodeID; if (ERosterCode.db.select(dbConn, rosterCode)) { if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_LEAVE) && rosterCode.LeaveCodeID > 0) { ELeaveCode leaveCode = new ELeaveCode(); leaveCode.LeaveCodeID = rosterCode.LeaveCodeID; if (ELeaveCode.db.select(dbConn, leaveCode)) { ELeaveApplication leaveApp = ELeaveApplication.GetOrCreateSingleDayLeaveApplicationObject(dbConn, rosterTable.EmpID, rosterCode.LeaveCodeID, rosterTable.RosterTableDate); if (leaveApp != null) { if (leaveApp.LeaveAppID <= 0) { ELeaveApplication.db.insert(dbConn, leaveApp); rosterTable.LeaveAppID = leaveApp.LeaveAppID; } } } } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_RESTDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, rosterTable.EmpID, ELeaveType.RESTDAY_LEAVE_TYPE(dbConn).LeaveTypeID, rosterTable.RosterTableDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_STATUTORYHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, rosterTable.EmpID, ELeaveType.STATUTORYHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, rosterTable.RosterTableDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_PUBLICHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, rosterTable.EmpID, ELeaveType.PUBLICHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, rosterTable.RosterTableDate); } } } }
private static void DeleteLeaveApplication(DatabaseConnection dbConn, EAttendanceRecord attendanceRecord) { if (attendanceRecord.LeaveAppID > 0) { ERosterCode rosterCode = new ERosterCode(); rosterCode.RosterCodeID = attendanceRecord.RosterCodeID; if (ERosterCode.db.select(dbConn, rosterCode)) { ELeaveApplication leaveApp = new ELeaveApplication(); leaveApp.LeaveAppID = attendanceRecord.LeaveAppID; if (ELeaveApplication.db.select(dbConn, leaveApp)) { if (leaveApp.EmpPayrollID <= 0 && rosterCode.LeaveCodeID.Equals(leaveApp.LeaveCodeID) && attendanceRecord.AttendanceRecordDate.Equals(leaveApp.LeaveAppDateFrom) && attendanceRecord.AttendanceRecordDate.Equals(leaveApp.LeaveAppDateTo) ) { //ELeaveCode leaveCode = new ELeaveCode(); //leaveCode.LeaveCodeID = leaveApp.LeaveCodeID; //if (ELeaveCode.db.select(dbConn, leaveCode)) ELeaveApplication.db.delete(dbConn, leaveApp); } } } } if (attendanceRecord.RosterCodeID > 0 && attendanceRecord.LeaveAppID <= 0) { ERosterCode rosterCode = new ERosterCode(); rosterCode.RosterCodeID = attendanceRecord.RosterCodeID; if (ERosterCode.db.select(dbConn, rosterCode)) { if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_RESTDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, attendanceRecord.EmpID, ELeaveType.RESTDAY_LEAVE_TYPE(dbConn).LeaveTypeID, attendanceRecord.AttendanceRecordDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_STATUTORYHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, attendanceRecord.EmpID, ELeaveType.STATUTORYHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, attendanceRecord.AttendanceRecordDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_PUBLICHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, attendanceRecord.EmpID, ELeaveType.PUBLICHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, attendanceRecord.AttendanceRecordDate); } } } }
private static void CreateLeaveApplication(DatabaseConnection dbConn, EAttendanceRecord attendanceRecord) { if (attendanceRecord.LeaveAppID > 0) { ELeaveApplication leaveApp = new ELeaveApplication(); leaveApp.LeaveAppID = attendanceRecord.LeaveAppID; if (!ELeaveApplication.db.select(dbConn, leaveApp)) { attendanceRecord.LeaveAppID = 0; } } // Check LeaveAppID <= 0 To prevent override LeaveAppID created by external function if (attendanceRecord.RosterCodeID > 0 && attendanceRecord.LeaveAppID <= 0) { ERosterCode rosterCode = new ERosterCode(); rosterCode.RosterCodeID = attendanceRecord.RosterCodeID; if (ERosterCode.db.select(dbConn, rosterCode)) { if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_LEAVE) && rosterCode.LeaveCodeID > 0) { ELeaveCode leaveCode = new ELeaveCode(); leaveCode.LeaveCodeID = rosterCode.LeaveCodeID; if (ELeaveCode.db.select(dbConn, leaveCode)) { ELeaveApplication leaveApp = ELeaveApplication.GetOrCreateSingleDayLeaveApplicationObject(dbConn, attendanceRecord.EmpID, rosterCode.LeaveCodeID, attendanceRecord.AttendanceRecordDate); if (leaveApp != null) { if (leaveApp.LeaveAppID <= 0) { ELeaveApplication.db.insert(dbConn, leaveApp); attendanceRecord.LeaveAppID = leaveApp.LeaveAppID; } } } } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_RESTDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, attendanceRecord.EmpID, ELeaveType.RESTDAY_LEAVE_TYPE(dbConn).LeaveTypeID, attendanceRecord.AttendanceRecordDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_STATUTORYHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, attendanceRecord.EmpID, ELeaveType.STATUTORYHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, attendanceRecord.AttendanceRecordDate); } else if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_PUBLICHOLIDAY)) { ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, attendanceRecord.EmpID, ELeaveType.PUBLICHOLIDAY_LEAVE_TYPE(dbConn).LeaveTypeID, attendanceRecord.AttendanceRecordDate); } } } }
protected override void afterDelete(DatabaseConnection dbConn, DBManager db) { base.afterDelete(dbConn, db); ELeaveBalance.DeleteLeaveBalanceAfter(dbConn, m_EmpID, ELeaveType.COMPENSATION_LEAVE_TYPE(dbConn).LeaveTypeID, m_CompensationLeaveEntitleEffectiveDate); }
public static double GetEstimatedNumOfLeaveDays(DatabaseConnection dbConn, int EmpID, DateTime DateFrom, DateTime DateTo, int LeaveCodeID, out DateTime[] DateSkipArray) { System.Collections.ArrayList dateSkipArrayList = new System.Collections.ArrayList(); EEmpPositionInfo empPos = null; double totalDays = 0; ELeaveType leaveType = new ELeaveType(); leaveType.LeaveTypeIsUseWorkHourPattern = true; ELeaveCode leaveCode = new ELeaveCode(); leaveCode.LeaveCodeID = LeaveCodeID; if (ELeaveCode.db.select(dbConn, leaveCode)) { leaveType.LeaveTypeID = leaveCode.LeaveTypeID; ELeaveType.db.select(dbConn, leaveType); } for (DateTime currentDate = DateFrom; currentDate <= DateTo; currentDate = currentDate.AddDays(1)) { // default every date count = 1 double dateCount = 1; if (EStatutoryHoliday.IsHoliday(dbConn, currentDate)) { if (!leaveType.LeaveTypeIsSkipStatutoryHolidayChecking) { dateCount = 0; } } else if (EPublicHoliday.IsHoliday(dbConn, currentDate)) { if (!leaveType.LeaveTypeIsSkipPublicHolidayChecking) { dateCount = 0; } } if (empPos == null) { empPos = AppUtils.GetLastPositionInfo(dbConn, currentDate, EmpID); } else if (!empPos.EmpPosEffTo.Ticks.Equals(0) && empPos.EmpPosEffTo <= currentDate) { empPos = AppUtils.GetLastPositionInfo(dbConn, currentDate, EmpID); } if (empPos != null) { EWorkHourPattern workPattern = new EWorkHourPattern(); workPattern.WorkHourPatternID = empPos.WorkHourPatternID; if (EWorkHourPattern.db.select(dbConn, workPattern)) { if (leaveType.LeaveTypeIsUseWorkHourPattern) { dateCount = workPattern.GetDefaultDayUnit(dbConn, currentDate, leaveType.LeaveTypeIsSkipStatutoryHolidayChecking, leaveType.LeaveTypeIsSkipPublicHolidayChecking); } } } totalDays += dateCount; if (dateCount <= 0) { dateSkipArrayList.Add(currentDate); } } DateSkipArray = (DateTime[])dateSkipArrayList.ToArray(typeof(DateTime)); return(totalDays); }