public static LeaveInfo ApplyLeave(string employeeID, string reason, string leaveType, string description, List <TimeDurationInfo> durationList) { LeaveInfo leaveInfo = null; if (!string.IsNullOrEmpty(employeeID) && !string.IsNullOrEmpty(reason) && !string.IsNullOrEmpty(leaveType) && null != durationList) { Employee employee = EmployeeBLL.GetEmployeeByID(employeeID); if (null != employee) { if (employee.Manager == null) { throw new Exception("You didn't set supervisor to approve your leave application."); } List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Name, leaveType, SearchComparator.Equal, SearchType.SearchString)); LeaveType lType = CommonDAL <LeaveType> .GetSingleObject(conditions); leaveInfo = LeaveInfo.CreateLeaveInfo(employee.PKEmployeeID, employee.FKReportManagerID, lType.PKLeaveTypeID, LeaveStatus.Applying, reason, description, durationList); leaveInfo.Save(); conditions.Clear(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKLeaveTypeID, leaveInfo.FKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); leaveInfo.Type = CommonDAL <LeaveType> .GetSingleObject(conditions); } } return(leaveInfo); }
/// <summary> /// If the employeeID or leaveTypeName doesn't exist, return 0. /// </summary> /// <param name="employeeID"></param> /// <param name="leaveTypeName"></param> /// <returns></returns> public static double GetUsedHours(string employeeID, string leaveTypeName) { double hours = 0; if (!string.IsNullOrEmpty(employeeID) && !string.IsNullOrEmpty(leaveTypeName)) { Employee employee = EmployeeBLL.GetEmployeeByID(employeeID); LeaveType leaveType = GetLeaveTypeByName(leaveTypeName); if (null != employee && null != leaveType) { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKEmployeeID, employee.PKEmployeeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKLeaveTypeID, leaveType.PKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Year, DateTime.Now.Year.ToString(), SearchComparator.Equal, SearchType.SearchNotString)); EmployeeLeaveSummary leaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions); if (null != leaveSummary) { hours = leaveSummary.UsedHours; } } } return(hours); }
public static List <Employee> GetManagers() { List <Employee> managers = null; Role role = Role.GetRoleByName(RoleRank.Manager.ToString()); if (null != role) { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKRoleID, role.PKRoleID.ToString(), SearchComparator.Equal, SearchType.SearchString)); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.IsDeleted, Convert.ToString(0), SearchComparator.Equal, SearchType.SearchNotString)); List <EmployeeRoleRL> employeeRoleRLs = CommonDAL <EmployeeRoleRL> .GetObjects(conditions); if (null != employeeRoleRLs) { managers = new List <Employee>(); foreach (EmployeeRoleRL item in employeeRoleRLs) { if (item.IsDeleted == false) // remove the supervisor who is not actived { managers.Add(EmployeeBLL.GetEmployeeByID(item.FKEmployeeID.ToString())); } } } } return(managers); }
public static void UpdateEmployee(string employeeID, string email, string firstName, string middleName, string lastName, Sex gender, float serviceYear, DateTime dateOfHire, string supervisorEmail, string password, string phone, string mobile, bool isAdmin, bool isActive, bool isManager, string costCenterCode, int employeeNum, string legalName) { if (!string.IsNullOrEmpty(employeeID) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName)) { Employee employee = EmployeeBLL.GetEmployeeByID(employeeID); if (null != employee) { if (!string.IsNullOrEmpty(employee.Email) && !string.IsNullOrEmpty(supervisorEmail) && employee.Email.Equals(supervisorEmail)) { throw new Exception(GlobalParams.SelectSupervisorError); } employee.Email = email; employee.FirstName = firstName; employee.MiddleName = middleName; employee.LastName = lastName; employee.Gender = gender; employee.ServiceYears = serviceYear; employee.HiredDate = dateOfHire; employee.Password = password; employee.Phone = phone; employee.Mobile = mobile; employee.IsActive = isActive; employee.SetPrivilege(isAdmin, RoleRank.Admin); employee.SetPrivilege(isManager, RoleRank.Manager); employee.CostCenter = costCenterCode; employee.EmployeeNum = employeeNum; employee.LegalName = legalName; if (!string.IsNullOrEmpty(supervisorEmail)) { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Email, supervisorEmail, SearchComparator.Equal, SearchType.SearchString)); Employee manager = CommonDAL <Employee> .GetSingleObject(conditions); employee.FKReportManagerID = manager.PKEmployeeID; } else { employee.FKReportManagerID = Guid.Empty; } employee.Save(); } } }
/// <summary> /// All the employee earn the same hours every month. /// </summary> /// <returns></returns> public static double GetAnnualLeaveEarnedHours(string employeeID) { double result = 0.0d; Employee employee = EmployeeBLL.GetEmployeeByID(employeeID); if (employee.HiredDate.Year == DateTime.Now.Year) { for (int i = 1; i <= DateTime.Now.Month; i++) { // If the employee is hired after 15th, he/she doesn't earn the annual leave hours that month. if (i == employee.HiredDate.Month && employee.HiredDate.Day > 15) { continue; } else if (i == employee.HiredDate.Month && employee.HiredDate.Day <= 15) { result += 10d; continue; } // Employee will earn 10 hours annual leave if current date is equal or after 15th in current month. if (i == DateTime.Now.Month && DateTime.Now.Day >= 15) { result += 10d; } // Employee will earn 10 hours annual leave in past monthes between his/her joined date and now if (i > employee.HiredDate.Month && i < DateTime.Now.Month) { result += 10d; } } } else { // Employee will earn 10 hours annual leave if current date is equal or after 15th. if (DateTime.Now.Day >= 15) { result = DateTime.Now.Month * 10; } else { result = (DateTime.Now.Month - 1) * 10; } } return(result); }