Exemple #1
0
 public List <DropDownItem> GetReportToList(long OfficeId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetReportToList(OfficeId));
     }
 }
Exemple #2
0
 public IList <DropDownItem> GetEmploymentTypes()
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetEmploymentTypes());
     }
 }
Exemple #3
0
 public EmployeeProfile GetEmployeeProfile(Int64 userId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetEmployeeProfile(userId));
     }
 }
Exemple #4
0
 public long GetUserId(string name)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetUserId(name));
     }
 }
Exemple #5
0
 public string GetNewEmpId(Int64 OfficeId, long employmentTypeId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetNewEmpId(OfficeId, employmentTypeId));
     }
 }
Exemple #6
0
 public long GetEmployeeId(string LogonId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetEmployeeId(LogonId));
     }
 }
Exemple #7
0
 public string ReportingToName(Int64 userId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.ReportingToName(userId));
     }
 }
Exemple #8
0
 public IList <LeaveCreditModel> GetEmployeeProfilesforCLSL(long leaveTypeId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetEmployeeProfilesforCLSL(leaveTypeId));
     }
 }
Exemple #9
0
 public string UpdateEmployeeProfile(EmployeeProfile profile, Int64 ModifiedBy)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.UpdateEmployeeProfile(profile, ModifiedBy));
     }
 }
Exemple #10
0
 public IList <ViewEmployeeProfileModel> GetTeamProfiles(Int64 userId, bool onlyReportedToMe, Int64?paramUserId, string requestMenuUser, bool hideInactiveEmp)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetTeamProfiles(userId, onlyReportedToMe, paramUserId, requestMenuUser, hideInactiveEmp));
     }
 }
Exemple #11
0
 public IList <LeaveCreditModel> GetEmployeeProfilesforEL(DateTime lastCreditRun)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetEmployeeProfilesforEL(lastCreditRun));
     }
 }
Exemple #12
0
 public List <DropDownItem> GetActiveEmpList(long OfficeId, Int64?exceptUserId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetActiveEmpList(OfficeId, exceptUserId));
     }
 }
Exemple #13
0
        public List <ShiftEmployees> GetShiftDetailsForUsers(Int64 UserId, string RequestMenuUser)
        {
            var lstShiftEmployees = new List <ShiftEmployees>();

            try
            {
                using (var context = new NLTDDbContext())
                {
                    EmployeeDac employeeDac = new EmployeeDac();
                    string      leadRole    = employeeDac.GetEmployeeRole(UserId);

                    if (leadRole == "ADMIN" || leadRole == "HR")
                    {
                        lstShiftEmployees = (from e in context.Employee
                                             where e.IsActive == true
                                             select new ShiftEmployees
                        {
                            Name = e.FirstName + " " + e.LastName,
                            EmpId = e.EmployeeId,
                            UserId = e.UserId
                        }).ToList();
                    }
                    else
                    {
                        lstShiftEmployees = GetEmployees(context, UserId);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(lstShiftEmployees);
        }
Exemple #14
0
 public EmployeeProfile GetEmployeeLoginProfile(string LogonId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.GetEmployeeLoginProfile(LogonId));
     }
 }
Exemple #15
0
 public ViewEmployeeProfileModel ViewEmployeeProfile(Int64 userId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.ViewEmployeeProfile(userId));
     }
 }
Exemple #16
0
        public List <ShiftAllocation> GetShiftAllocation(Int64 UserId, string RequestMenuUser)
        {
            List <ShiftAllocation> lstShiftAllocation = new List <ShiftAllocation>();

            try
            {
                using (var context = new NLTDDbContext())
                {
                    if (RequestMenuUser == "Admin")
                    {
                        EmployeeDac employeeDac = new EmployeeDac();
                        string      leadRole    = employeeDac.GetEmployeeRole(UserId);

                        if (leadRole == "ADMIN" || leadRole == "HR")
                        {
                            lstShiftAllocation = (from sm in context.ShiftMapping
                                                  join s in context.ShiftMaster on sm.ShiftID equals s.ShiftID
                                                  join e in context.Employee on sm.UserID equals e.UserId
                                                  where e.IsActive == true
                                                  select new ShiftAllocation
                            {
                                Name = e.FirstName + " " + e.LastName,
                                EmpId = e.EmployeeId,
                                UserId = sm.UserID,
                                ShiftID = s.ShiftID,
                                ShiftDate = sm.ShiftDate,
                                FromTime = s.FromTime,
                                ToTime = s.ToTime,
                                ShiftName = s.ShiftDescription,
                                IsActive = e.IsActive,
                                ShiftMappingID = sm.ShiftMappingID
                            }).ToList();
                        }
                    }
                    else
                    {
                        lstShiftAllocation = GetShiftEmployees(context, UserId);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(lstShiftAllocation);
        }
Exemple #17
0
        public void Retrieve()
        {
            _Info = EmployeeDac.Retrieve(this).Tables[0];
            if (_Info.HasRows())
            {
                InitializeProperties(_Info.Rows[0]);

                ReportingDepartment reportingDepartments = new ReportingDepartment(_ResourceID);
                _ReportingDepartment = reportingDepartments;

                WarehouseDesignation warehouseDesignation = new WarehouseDesignation(_EmployeeId);
                _WarehouseDesignation = (IWarehouseDesignation)warehouseDesignation;
            }
            else
            {
                throw new KeyNotFoundException("Email not found.");
            }
        }
Exemple #18
0
        public List <TimeSheetModel> GetMyTeamTimeSheet(Int64 UserID, DateTime FromDate, DateTime ToDate, bool myDirectEmployees)
        {
            List <TimeSheetModel> timeSheetModelList = new List <TimeSheetModel>();

            EmployeeDac employeeDac = new EmployeeDac();
            string      leadRole    = employeeDac.GetEmployeeRole(UserID);

            try
            {
                List <EmployeeProfile> employeeProfileListUnderManager = employeeDac.GetReportingEmployeeProfile(UserID, leadRole, myDirectEmployees).OrderBy(m => m.FirstName).ToList();
                for (int i = 0; i < employeeProfileListUnderManager.Count; i++)
                {
                    List <TimeSheetModel> timeSheetModelListTemp = GetMyTimeSheet(employeeProfileListUnderManager[i].UserId, FromDate, ToDate);
                    timeSheetModelList.AddRange(timeSheetModelListTemp);
                }
                return(timeSheetModelList);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #19
0
        public List <NoOfLateInMonth> GetLateReport(Int64 UserID, DateTime FromDate, DateTime ToDate, bool myDirectEmployees)
        {
            List <ReportLateMonth> reportLateMonthlst = new List <ReportLateMonth>();
            List <NoOfLateInMonth> noOfLateInMonth    = new List <NoOfLateInMonth>();
            // To Get all the employee profile under the manager or lead
            EmployeeDac employeeDac = new EmployeeDac();
            string      leadRole    = employeeDac.GetEmployeeRole(UserID);

            // To get the employee role, whether he is the Team lead or HR Or admin
            try
            {
                List <EmployeeProfile> employeesUnderManager = employeeDac.GetReportingEmployeeProfile(UserID, leadRole, myDirectEmployees).OrderBy(m => m.FirstName).ToList();
                for (int i = 0; i < employeesUnderManager.Count; i++)
                {
                    string Name = employeesUnderManager[i].FirstName + " " + employeesUnderManager[i].LastName;
                    List <ReportLateMonth> reportLateMonth = GetMyTimeSheet(employeesUnderManager[i].UserId, FromDate, ToDate, employeesUnderManager[i].ReportedToName, Name, employeesUnderManager[i].EmployeeId);
                    reportLateMonthlst.AddRange(reportLateMonth);
                }

                noOfLateInMonth = (from p in reportLateMonthlst
                                   where p.LateEntry != null
                                   group p by new { p.UserID, p.Name, p.ReportingTo, p.EmpId } into g
                                   select new NoOfLateInMonth
                {
                    Name = g.Key.Name,
                    UserID = g.Key.UserID,
                    ReportingTo = g.Key.ReportingTo,
                    EmpId = g.Key.EmpId,
                    NoOfLate = g.Count()
                }).ToList();
                return(noOfLateInMonth);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #20
0
 public DataTable Retrieve(String EmployeeId)
 {
     return(EmployeeDac.Retrieve(EmployeeId).Tables[0]);
 }
Exemple #21
0
 public DataTable Retrieve(Int32 Id)
 {
     return(EmployeeDac.Retrieve(Id).Tables[0]);
 }
Exemple #22
0
 public DataTable RetrieveAll()
 {
     return(EmployeeDac.Retrieve().Tables[0]);
 }
Exemple #23
0
 public void Delete(Int32 Id)
 {
     EmployeeDac.Delete(Id);
 }
Exemple #24
0
 public void Update()
 {
     EmployeeDac.Update(this);
 }
Exemple #25
0
 public Int32 Insert()
 {
     return(EmployeeDac.Insert(this));
 }
Exemple #26
0
        public List <TimeSheetModel> GetMyTimeSheet(Int64 UserID, DateTime FromDate, DateTime ToDate)
        {
            List <TimeSheetModel>  timeSheetModelList  = new List <TimeSheetModel>();
            List <ShiftQueryModel> ShiftQueryModelList = GetShiftDetails(UserID, FromDate, ToDate);

            string PersonalPermisionLabel = ConfigurationManager.AppSettings["PersonalPermission"].ToString();
            string officialPermisionLabel = ConfigurationManager.AppSettings["OfficialPermission"].ToString();

            var toDateShift = (from m in ShiftQueryModelList where m.ShiftDate == ToDate select new { fromTime = m.ShiftFromtime, toTime = m.ShiftTotime }).FirstOrDefault();

            if (toDateShift != null)
            {
                TimeSpan fromTime = toDateShift.fromTime;
                TimeSpan toTime   = toDateShift.toTime;
                if (fromTime > toTime)
                {
                    ToDate = ToDate.AddDays(1).Add(toTime.Add(new TimeSpan(AfterShiftBuffer, 0, 0)));
                }
                else
                {
                    ToDate = ToDate.Add(toTime.Add(new TimeSpan(AfterShiftBuffer, 0, 0)));
                }
            }

            IEmployeeAttendanceHelper EmployeeAttendanceDacObj = new EmployeeAttendanceDac();

            //To Retrieve the Employee Attendance for the given date.
            List <EmployeeAttendanceModel> EmployeeAttendanceList = EmployeeAttendanceDacObj.GetAttendanceForRange(UserID, FromDate, ToDate, "My", true, false);

            // To Get the Employee name
            EmployeeProfile EmployeeProfileObj = new EmployeeDac().GetEmployeeProfile(UserID);
            string          name             = string.Empty;
            string          reportingManager = string.Empty;
            DateTime?       employeeDOJ      = null;

            if (EmployeeProfileObj != null)
            {
                name             = EmployeeProfileObj.FirstName + ' ' + EmployeeProfileObj.LastName;
                reportingManager = EmployeeProfileObj.ReportedToName;
                employeeDOJ      = EmployeeProfileObj.DOJ;
            }

            // To get the employee week off Days
            OfficeWeekOffDac officeWeekOffDacObj  = new OfficeWeekOffDac();
            List <string>    officeWeekOffDayList = officeWeekOffDacObj.GetEmployeeWeekOffDay(UserID);

            // To get the employee Holiday List
            OfficeHolidayDac     officeHolidayDacObj = new OfficeHolidayDac();
            List <OfficeHoliday> officeHolidayList   = officeHolidayDacObj.GetOfficeHoliday(UserID);

            // To get the employee Leave Details
            LeaveTransactionHistoryDac leaveTransactionHistoryDacObj = new LeaveTransactionHistoryDac();
            List <EmployeeLeave>       employeeLeaveList             = leaveTransactionHistoryDacObj.GetLeaveForEmployee(UserID, FromDate, ToDate);

            for (int i = 0; i < ShiftQueryModelList.Count(); i++)
            {
                decimal        permissionCountOfficial = 0, permissionCountPersonal = 0, LeaveDayQty = 0, WorkFromHomeDayQty = 0;
                TimeSheetModel TimeSheetModelObj = new TimeSheetModel();
                DateTime       shiftFromDateTime = ShiftQueryModelList[i].ShiftDate.Add(ShiftQueryModelList[i].ShiftFromtime.Add(new TimeSpan(-BeforeShiftBuffer, 0, 0)));
                DateTime       shiftEndDateTime  = ShiftQueryModelList[i].ShiftDate.Add(ShiftQueryModelList[i].ShiftTotime.Add(new TimeSpan(AfterShiftBuffer, 0, 0)));

                if (shiftEndDateTime < shiftFromDateTime)
                {
                    shiftEndDateTime = shiftEndDateTime.AddDays(1);
                }
                // To add the employee basic details
                TimeSheetModelObj.Shift            = ShiftQueryModelList[i].ShiftFromtime.ToString(@"hh\:mm") + '-' + ShiftQueryModelList[i].ShiftTotime.ToString(@"hh\:mm");
                TimeSheetModelObj.userID           = UserID;
                TimeSheetModelObj.Name             = name;
                TimeSheetModelObj.ReportingManager = reportingManager;
                TimeSheetModelObj.WorkingDate      = ShiftQueryModelList[i].ShiftDate;
                // Linq query to find the min and max for the given date
                var maxmin = from s in EmployeeAttendanceList
                             where s.InOutDate >= shiftFromDateTime && s.InOutDate <= shiftEndDateTime
                             group s by true into r
                             select new
                {
                    min = r.Min(z => z.InOutDate),
                    max = r.Max(z => z.InOutDate)
                };
                if (maxmin != null && maxmin.Count() > 0)
                {
                    TimeSheetModelObj.InTime  = maxmin.ToList()[0].min;
                    TimeSheetModelObj.OutTime = maxmin.ToList()[0].max;
                    if (employeeLeaveList.Select(e => e.LeaveType == officialPermisionLabel).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.LeaveType == officialPermisionLabel)
                            {
                                permissionCountOfficial += permissionTime.PermissionCount;
                            }
                        }
                    }

                    if (employeeLeaveList.Select(e => e.LeaveType == PersonalPermisionLabel).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.LeaveType == PersonalPermisionLabel)
                            {
                                permissionCountPersonal += permissionTime.PermissionCount;
                            }
                        }
                    }

                    if (employeeLeaveList.Select(e => e.LeaveTypeId = 0).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.LeaveDayQty != 0 && permissionTime.IsLeave == true)
                            {
                                LeaveDayQty += permissionTime.LeaveDayQty;
                            }
                        }
                    }

                    if (employeeLeaveList.Select(e => e.LeaveTypeId = 0).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.WorkFromHomeDayQty != 0 && permissionTime.IsLeave == false)
                            {
                                WorkFromHomeDayQty += permissionTime.WorkFromHomeDayQty;
                            }
                        }
                    }

                    TimeSheetModelObj.WorkingHours = TimeSheetModelObj.OutTime - TimeSheetModelObj.InTime;

                    if (TimeSheetModelObj.WorkingDate < employeeDOJ)
                    {
                        TimeSheetModelObj.Status = "Non-Employee (DOJ: " + String.Format("{0:dd-MM-yyyy}", employeeDOJ) + ")";
                    }
                    else
                    {
                        string holidayStatus = GetAbsentStatus(ShiftQueryModelList[i].ShiftDate, officeWeekOffDayList, officeHolidayList);

                        if (holidayStatus == "")
                        {
                            TimeSheetModelObj.Status = "Present";
                        }
                        else
                        {
                            TimeSheetModelObj.Status        = "Present (" + holidayStatus + ")";
                            TimeSheetModelObj.HolidayStatus = holidayStatus;
                        }
                    }


                    if (TimeSheetModelObj.InTime.TimeOfDay > ShiftQueryModelList[i].ShiftFromtime)
                    {
                        TimeSheetModelObj.LateIn = TimeSheetModelObj.InTime.TimeOfDay - ShiftQueryModelList[i].ShiftFromtime;
                    }

                    DateTime shiftToTime   = ShiftQueryModelList[i].ShiftDate.Add(ShiftQueryModelList[i].ShiftTotime);
                    DateTime shiftFromTime = ShiftQueryModelList[i].ShiftDate.Add(ShiftQueryModelList[i].ShiftFromtime);
                    if (shiftToTime < shiftFromTime)
                    {
                        shiftToTime = shiftToTime.AddDays(1);
                    }
                    if (shiftToTime > TimeSheetModelObj.OutTime)
                    {
                        TimeSheetModelObj.EarlyOut = ShiftQueryModelList[i].ShiftTotime - TimeSheetModelObj.OutTime.TimeOfDay;
                    }
                }
                else// If no record found in the employee for the given date
                {
                    if (TimeSheetModelObj.WorkingDate < employeeDOJ)
                    {
                        TimeSheetModelObj.Status = "Non-Employee (DOJ: " + String.Format("{0:dd-MM-yyyy}", employeeDOJ) + ")";
                    }
                    else
                    {
                        // Get Absent Details
                        string holidayStatus = GetAbsentStatus(ShiftQueryModelList[i].ShiftDate, officeWeekOffDayList, officeHolidayList);
                        TimeSheetModelObj.Status        = holidayStatus;
                        TimeSheetModelObj.HolidayStatus = holidayStatus;
                    }

                    if (employeeLeaveList.Select(e => e.LeaveType == officialPermisionLabel).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.LeaveType == officialPermisionLabel)
                            {
                                permissionCountOfficial += permissionTime.PermissionCount;
                            }
                        }
                    }

                    if (employeeLeaveList.Select(e => e.LeaveType == PersonalPermisionLabel).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.LeaveType == PersonalPermisionLabel)
                            {
                                permissionCountPersonal += permissionTime.PermissionCount;
                            }
                        }
                    }

                    if (employeeLeaveList.Select(e => e.LeaveTypeId = 0).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.LeaveDayQty != 0 && permissionTime.IsLeave == true)
                            {
                                LeaveDayQty += permissionTime.LeaveDayQty;
                            }
                        }
                    }
                    if (employeeLeaveList.Select(e => e.LeaveTypeId = 0).Count() > 0)
                    {
                        foreach (var permissionTime in employeeLeaveList)
                        {
                            if (permissionTime.StartDate == TimeSheetModelObj.WorkingDate && permissionTime.WorkFromHomeDayQty != 0 && permissionTime.IsLeave == false)
                            {
                                WorkFromHomeDayQty += permissionTime.WorkFromHomeDayQty;
                            }
                        }
                    }
                }

                // To get the employee Leave Details
                TimeSheetModelObj.Requests      = GetLMSStatus(employeeLeaveList, ShiftQueryModelList[i].ShiftDate);
                TimeSheetModelObj.StartDateType = GetHalfDayLMSType(employeeLeaveList, ShiftQueryModelList[i].ShiftDate, out string StartDateType);
                TimeSheetModelObj.EndDateType   = GetHalfDayLMSType(employeeLeaveList, ShiftQueryModelList[i].ShiftDate, out string EndDateType);

                TimeSheetModelObj.LeaveDayQty        = LeaveDayQty;
                TimeSheetModelObj.WorkFromHomeDayQty = WorkFromHomeDayQty;
                TimeSheetModelObj.PermissionCount    = permissionCountPersonal;

                TimeSheetModelObj.permissionCountOfficial = permissionCountOfficial;
                TimeSheetModelObj.permissionCountPersonal = permissionCountPersonal;

                timeSheetModelList.Add(TimeSheetModelObj);
            }

            return(timeSheetModelList.OrderByDescending(m => m.WorkingDate).ToList());
        }
Exemple #27
0
        public EmpShift GetEmployeeShiftDetails(Int64 UserId, string RequestMenuUser, long LeaduserId)
        {
            EmpShift retModel = new EmpShift();

            try
            {
                using (var context = new NLTDDbContext())
                {
                    EmployeeDac employeeDac = new EmployeeDac();
                    long        userId = 0; string EmpId = "";
                    string      Name = "";

                    if (RequestMenuUser != "My")
                    {
                        var empPrf = context.Employee
                                     .Where(x => x.UserId == UserId)
                                     .FirstOrDefault();
                        if (empPrf != null)
                        {
                            userId = empPrf.UserId;
                            EmpId  = empPrf.EmployeeId;
                            Name   = empPrf.FirstName + " " + empPrf.LastName;
                        }
                    }
                    else
                    {
                        var empPrf = context.Employee.Where(x => (x.UserId) == LeaduserId).FirstOrDefault();
                        if (empPrf != null)
                        {
                            userId = empPrf.UserId;
                            EmpId  = empPrf.EmployeeId;
                            Name   = empPrf.FirstName + " " + empPrf.LastName;
                        }
                    }

                    if (userId > 0 || (RequestMenuUser == "My" && LeaduserId > 0))
                    {
                        string ReportingTo = (RequestMenuUser == "My" && LeaduserId > 0) ? employeeDac.ReportingToName(LeaduserId) : employeeDac.ReportingToName(userId);

                        string leadRole = employeeDac.GetEmployeeRole(LeaduserId);

                        List <ShiftAllocation> shiftDetails = new List <ShiftAllocation>();
                        if (RequestMenuUser == "My")
                        {
                            shiftDetails = GetShiftDetails(context, LeaduserId);
                        }
                        else if (leadRole == "ADMIN" || leadRole == "HR")
                        {
                            shiftDetails = GetShiftDetails(context, userId);
                        }
                        else if (RequestMenuUser == "Team")
                        {
                            var user = (from e in context.Employee
                                        where e.ReportingToId == LeaduserId
                                        select e).ToList();

                            var found = LeaveTransactionHistoryDac.FindControlRecursively(user, userId);
                            if (found != null)
                            {
                                shiftDetails = GetShiftDetails(context, userId);
                            }
                        }

                        var groupedLeaveList = shiftDetails.GroupBy(u => u.Month)
                                               .Select(grp => new { Month = grp.Key, shiftAllocation = grp.ToList() })
                                               .ToList();

                        List <ShiftDetail> lstshiftDetails = (from gv in groupedLeaveList
                                                              select new ShiftDetail
                        {
                            Month = gv.Month,
                            shiftAllocation = gv.shiftAllocation
                        }).ToList();
                        retModel.shiftDetail = lstshiftDetails;
                        retModel.ReportingTo = ReportingTo;

                        var lstShift = context.ShiftMaster.AsEnumerable().OrderBy(x => x.FromTime).Select(s => new Shifts
                        {
                            ShiftId   = s.ShiftID,
                            ShiftName = string.Format("{0:hh\\:mm}", s.FromTime) + " - " + string.Format("{0:hh\\:mm}", s.ToTime),
                        }).ToList();

                        retModel.Shifts = lstShift;
                    }

                    retModel.Name   = Name;
                    retModel.EmpId  = EmpId;
                    retModel.UserId = userId;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(retModel);
        }
Exemple #28
0
        public string UpdateLeaveBalance(List <EmployeeLeaveBalanceDetails> empLeaveBalanceDetails, Int64 LoginUserId, bool isElCredit = false)
        {
            try
            {
                int isSaved = 0;

                using (var context = new NLTDDbContext())
                {
                    EmployeeDac employeeDac = new EmployeeDac();
                    string      userRole    = string.Empty;
                    if (LoginUserId != 0)
                    {
                        userRole = employeeDac.GetEmployeeRole(LoginUserId);
                    }
                    else
                    {
                        userRole = "System";
                    }

                    if (userRole == "HR" || userRole == "System")
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            int creditYear = Convert.ToDateTime(context.LeaveType.Where(x => x.Type == "Earned Leave").FirstOrDefault().lastCreditRun).Year;

                            foreach (var item in empLeaveBalanceDetails)
                            {
                                if (item.NoOfDays > 0)
                                {
                                    EmployeeLeaveBalance leaveBalance;
                                    if (isElCredit == false)
                                    {
                                        leaveBalance = context.EmployeeLeaveBalance.Where(x => x.UserId == item.UserId && x.LeaveTypeId == item.LeaveTypeId &&
                                                                                          x.LeaveBalanceId == item.LeaveBalanceId && x.Year == DateTime.Now.Year).FirstOrDefault();
                                    }
                                    else
                                    {
                                        leaveBalance = context.EmployeeLeaveBalance.Where(x => x.UserId == item.UserId && x.LeaveTypeId == item.LeaveTypeId &&
                                                                                          x.LeaveBalanceId == item.LeaveBalanceId && x.Year == creditYear).FirstOrDefault();
                                    }

                                    if (leaveBalance != null)
                                    {
                                        leaveBalance.TotalDays   = item.CreditOrDebit == "C" ? (leaveBalance.TotalDays + item.NoOfDays) : (leaveBalance.TotalDays - item.NoOfDays);
                                        leaveBalance.ModifiedBy  = LoginUserId;
                                        leaveBalance.ModifiedOn  = DateTime.Now;
                                        leaveBalance.BalanceDays = item.TotalDays;
                                        isSaved = context.SaveChanges();
                                    }
                                    else
                                    {
                                        leaveBalance = new EmployeeLeaveBalance
                                        {
                                            UserId = Convert.ToInt64(item.UserId)
                                        };
                                        if (isElCredit == false)
                                        {
                                            leaveBalance.Year = DateTime.Now.Year;
                                        }
                                        else
                                        {
                                            leaveBalance.Year = creditYear;
                                        }
                                        leaveBalance.LeaveTypeId         = Convert.ToInt64(item.LeaveTypeId);
                                        leaveBalance.TotalDays           = item.TotalDays;
                                        leaveBalance.LeaveTakenDays      = 0;
                                        leaveBalance.PendingApprovalDays = 0;
                                        leaveBalance.BalanceDays         = item.TotalDays;
                                        leaveBalance.CreatedBy           = LoginUserId;
                                        leaveBalance.CreatedOn           = DateTime.Now;
                                        leaveBalance.ModifiedBy          = LoginUserId;
                                        leaveBalance.ModifiedOn          = DateTime.Now;
                                        context.EmployeeLeaveBalance.Add(leaveBalance);
                                        isSaved = context.SaveChanges();
                                    }

                                    LeaveTransactionHistory leaveTransactionHistory = new LeaveTransactionHistory
                                    {
                                        UserId          = Convert.ToInt64(item.UserId),
                                        LeaveTypeId     = Convert.ToInt64(item.LeaveTypeId),
                                        LeaveId         = -1,
                                        TransactionDate = DateTime.Now,
                                        TransactionType = item.CreditOrDebit,
                                        NumberOfDays    = item.NoOfDays,
                                        TransactionBy   = LoginUserId,
                                        Remarks         = item.Remarks
                                    };
                                    context.LeaveTransactionHistory.Add(leaveTransactionHistory);
                                    isSaved = context.SaveChanges();
                                    if (isSaved > 0)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            if (isSaved > 0 && isElCredit == true)
                            {
                                var leaveType = context.LeaveType.Where(x => x.Type.ToUpper() == "EARNED LEAVE").FirstOrDefault();

                                if (leaveType != null)
                                {
                                    leaveType.lastCreditRun = System.DateTime.Now;
                                    leaveType.ModifiedBy    = LoginUserId;
                                    leaveType.Modifiedon    = System.DateTime.Now;
                                    isSaved = context.SaveChanges();
                                }
                            }
                            if (isSaved > 0)
                            {
                                transaction.Commit();
                            }
                            else
                            {
                                transaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        return("Need Role");
                    }
                }
                if (isSaved > 0)
                {
                    return("Saved");
                }
                else
                {
                    return("Failed");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public List <EmployeeAttendanceModel> GetAttendanceForRange(Int64 UserID, DateTime FromDateTime, DateTime ToDateTime, string requestLevelPerson, bool isDirectEmployees, bool getBreakStatus)
        {
            List <EmployeeAttendanceModel> employeeAttendanceModelList = new List <EmployeeAttendanceModel>();
            EmployeeDac   employeeDac = new EmployeeDac();
            IList <Int64> employeeIDs = new List <Int64>();

            if (requestLevelPerson.ToUpper() == "MY")
            {
                employeeIDs.Add(UserID);
            }
            else
            {
                if (isDirectEmployees)
                {
                    employeeIDs = employeeDac.GetDirectEmployees(UserID);
                }
                else
                {
                    employeeIDs = employeeDac.GetEmployeesReporting(UserID);
                }
            }

            using (var context = new NLTDDbContext())
            {
                employeeAttendanceModelList = (from ea in context.EmployeeAttendance
                                               join e in context.Employee on ea.UserID equals e.UserId
                                               join s in context.ShiftMapping on e.UserId equals s.UserID
                                               join sm in context.ShiftMaster on s.ShiftID equals sm.ShiftID
                                               where employeeIDs.Contains(ea.UserID ?? 0) && ea.InOutDate >= FromDateTime && ea.InOutDate <= ToDateTime &&
                                               ea.InOutDate >= DbFunctions.AddHours(s.ShiftDate, sm.FromTime.Hours - BeforeShiftBuffer) &&
                                               ea.InOutDate <= (sm.ToTime.Hours > 9 ? DbFunctions.AddHours(s.ShiftDate, sm.ToTime.Hours + AfterShiftBuffer) : DbFunctions.AddHours(DbFunctions.AddDays(s.ShiftDate, 1), sm.ToTime.Hours + AfterShiftBuffer))
                                               select new EmployeeAttendanceModel
                {
                    UserID = ea.UserID,
                    InOutDate = ea.InOutDate,
                    InOut = (ea.InOut ? "Out" : "In"),
                    Name = (e.FirstName + " " + e.LastName),
                    ShiftDate = s.ShiftDate
                }).OrderBy(e => e.UserID).ThenBy(e => e.InOutDate).ToList();
            }

            if (getBreakStatus)
            {
                TimeSpan punchTime = new TimeSpan();
                TimeSpan breakTime = new TimeSpan();
                TimeSpan workTime  = new TimeSpan();

                for (int i = 0; i <= employeeAttendanceModelList.Count - 1; i++)
                {
                    if (i == employeeAttendanceModelList.Count - 1)
                    {
                        employeeAttendanceModelList[i].BreakDuration = "Total Work : " + workTime.ToString() + ", Total Break : " + breakTime.ToString();
                    }
                    else if (employeeAttendanceModelList[i].UserID == employeeAttendanceModelList[i + 1].UserID)
                    {
                        punchTime = (employeeAttendanceModelList[i + 1].InOutDate - employeeAttendanceModelList[i].InOutDate);

                        if (employeeAttendanceModelList[i].ShiftDate == employeeAttendanceModelList[i + 1].ShiftDate)
                        {
                            if (employeeAttendanceModelList[i].InOut == "In")
                            {
                                if (employeeAttendanceModelList[i + 1].InOut == "Out")
                                {
                                    employeeAttendanceModelList[i].BreakDuration = "Work : " + punchTime.ToString();
                                    workTime += punchTime;
                                }
                                else
                                {
                                    employeeAttendanceModelList[i].BreakDuration = "Missing Out Punch";
                                }
                            }
                            else
                            {
                                if (employeeAttendanceModelList[i + 1].InOut == "In")
                                {
                                    employeeAttendanceModelList[i].BreakDuration = "Break : " + punchTime.ToString();
                                    breakTime += punchTime;
                                }
                                else
                                {
                                    employeeAttendanceModelList[i].BreakDuration = "Missing In Punch";
                                }
                            }
                        }
                        else
                        {
                            employeeAttendanceModelList[i].BreakDuration = "Total Work : " + workTime.ToString() + ", Total Break : " + breakTime.ToString();
                            workTime  = TimeSpan.Zero;
                            breakTime = TimeSpan.Zero;
                        }
                    }
                    else
                    {
                        employeeAttendanceModelList[i].BreakDuration = "Total Work : " + workTime.ToString() + ", Total Break : " + breakTime.ToString();
                        workTime  = TimeSpan.Zero;
                        breakTime = TimeSpan.Zero;
                    }
                }
            }
            return(employeeAttendanceModelList.OrderBy(e => e.Name).ThenByDescending(e => e.InOutDate).ToList());
        }
        public IList <LeaveTransactionDetail> GetTransactionLog(string Name, string RequestMenuUser, long leadUserId)
        {
            IList <LeaveTransactionDetail> retModel = new List <LeaveTransactionDetail>();
            LeaveDac      lv      = new LeaveDac();
            IList <Int64> empList = lv.GetEmployeesReporting(leadUserId);

            try
            {
                using (var context = new NLTDDbContext())
                {
                    EmployeeDac employeeDac = new EmployeeDac();
                    long        userId      = 0;

                    if (RequestMenuUser != "My")
                    {
                        userId = employeeDac.GetUserId(Name);
                    }

                    if (userId > 0 || (RequestMenuUser == "My" && leadUserId > 0))
                    {
                        string ReportingTo = (RequestMenuUser == "My" && leadUserId > 0) ? employeeDac.ReportingToName(leadUserId) : employeeDac.ReportingToName(userId);

                        List <LeaveTransactionHistoryModel> transactionDetails = new List <LeaveTransactionHistoryModel>();
                        if (RequestMenuUser == "My")
                        {
                            transactionDetails = GetTransactionDetails(context, leadUserId);
                        }
                        if (RequestMenuUser == "Team")
                        {
                            string leadRole = employeeDac.GetEmployeeRole(leadUserId);

                            if (leadRole == "ADMIN" || leadRole == "HR")
                            {
                                transactionDetails = GetTransactionDetails(context, userId);
                            }
                            else
                            {
                                var user = empList.Where(x => x == userId).FirstOrDefault();

                                if (user > 0)
                                {
                                    transactionDetails = GetTransactionDetails(context, userId);
                                }
                            }
                        }

                        var groupedLeaveList = transactionDetails.GroupBy(u => u.LeaveTypeId)
                                               .Select(grp => new { LeaveTypeId = grp.Key, leaveTransactionHistoryModel = grp.ToList() })
                                               .ToList();

                        retModel = (from gv in groupedLeaveList
                                    select new LeaveTransactionDetail
                        {
                            ReportingTo = ReportingTo,
                            LeaveTypeId = gv.LeaveTypeId,
                            LeaveType = gv.leaveTransactionHistoryModel[0].Type,
                            leaveTransactionHistoryModel = gv.leaveTransactionHistoryModel
                        }).ToList();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(retModel);
        }