public JsonResult GetLeaveStatus()
        {
            JsonResult result = null;

            try
            {
                EmployeeLeaveDetails employeeLeaveDetails = new EmployeeLeaveDetails();
                employeeLeaveDetails.AppliedStatusCount = Leaveservice.GetLeaveList <EmployeeLeaveList>(s => s.Status == "Applied" && s.BranchId == USER_OBJECT.BranchId && s.EmployeeId == USER_OBJECT.EmployeeId).Count();
                var GrantedLeavesList = Leaveservice.GetLeaveList <EmployeeLeaveList>
                                            (s => s.EmployeeId == USER_OBJECT.EmployeeId && s.BranchId == USER_OBJECT.BranchId)
                                        .GroupBy(g => g.LeaveTypeId).ToList().Select(s => new
                {
                    count = s.Count(),
                    name  = LookUpCodeService.GetLookUpType(s.Key).LookUpCode
                });
                employeeLeaveDetails.GrantedLeaves = Leaveservice.GetLeaveList <EmployeeLeaveList>(s => s.Status == "Grant" && s.BranchId == USER_OBJECT.BranchId && s.EmployeeId == USER_OBJECT.EmployeeId).Count();
                List <LeaveHeader> LeaveHeaders = GrantLeaveService.GetAll <LeaveHeader>(l => l.BranchID == USER_OBJECT.BranchId).ToList();
                var TotalLeaves = LeaveHeaders.Select(l => l.LeaveDetail.Sum(s => s.TotalLeaves)).Count();
                employeeLeaveDetails.RemaingStatusCount = Math.Abs(employeeLeaveDetails.GrantedLeaves - TotalLeaves);
                result = Json(new { employeeLeaveDetails = employeeLeaveDetails, GrantedLeavesList = GrantedLeavesList }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    return(Json(new { success = false, message = ex.InnerException.Message }, JsonRequestBehavior.DenyGet));
                }
            }
            return(result);
        }
        public JsonResult SaveEmployeeLeaveForm(EmployeeLeaveList employeeLeaveList)
        {
            JsonResult result = new JsonResult();

            if (employeeLeaveList != null)
            {
                try
                {
                    EmployeeLeaveList _employeeLeaveList = new EmployeeLeaveList();
                    if (employeeLeaveList.Id > 0)
                    {
                        _employeeLeaveList            = Leaveservice.GetLeaveListById(employeeLeaveList.Id);
                        _employeeLeaveList.ModifiedBy = USER_OBJECT.UserName;
                        _employeeLeaveList.ModifiedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
                    }
                    else
                    {
                        _employeeLeaveList.CreatedBy = USER_OBJECT.UserName;
                        _employeeLeaveList.CreatedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
                        _employeeLeaveList.ApplyDate = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
                    }
                    EmployeeHeader employeeHeader = EmployeeProfileService.GetEmployeeProfileList <EmployeeHeader>(e => e.Id == employeeLeaveList.EmployeeId).FirstOrDefault();

                    _employeeLeaveList.EmployeeId  = employeeHeader.Id;
                    _employeeLeaveList.FromDate    = employeeLeaveList.FromDate;
                    _employeeLeaveList.ToDate      = employeeLeaveList.ToDate;
                    _employeeLeaveList.Days        = employeeLeaveList.Days;
                    _employeeLeaveList.Reason      = employeeLeaveList.Reason;
                    _employeeLeaveList.Remarks     = employeeLeaveList.Remarks;
                    _employeeLeaveList.LeaveTypeId = employeeLeaveList.LeaveTypeId;
                    _employeeLeaveList.Status      = employeeLeaveList.Status;
                    _employeeLeaveList.ManagerId   = employeeHeader.ManagerId.HasValue ? employeeHeader.ManagerId.Value : 0;
                    Leaveservice.SaveLeaveList(_employeeLeaveList);

                    result = Json(new { sucess = true, message = "Sent successfully" }, JsonRequestBehavior.AllowGet);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                    {
                        return(Json(new { success = false, message = ex.InnerException.Message }, JsonRequestBehavior.DenyGet));
                    }
                }
            }
            else
            {
                result = Json(new { sucess = false, message = "No Data Found" }, JsonRequestBehavior.AllowGet);
            }

            return(result);
        }
Exemple #3
0
        public JsonResult GetAppliedLeaveList()
        {
            JsonResult result = null;

            try
            {
                LookUp employeeDepartment = LookUpCodeService.GetLookUp <LookUp>(s => s.LookUpCategory == "EmployeeDesignation" && s.LookUpCode == "Manager").FirstOrDefault();

                EmployeeHeader employeeHeader = EmployeeProfileService.GetEmployeeProfileList <EmployeeHeader>(e => e.Id == USER_OBJECT.EmployeeId && e.EmployeeWorkDetail.FirstOrDefault().DesignationId == employeeDepartment.LookUpID).FirstOrDefault();

                List <EmployeeLeaveList>      employeeLeaveList          = Leaveservice.GetLeaveList <EmployeeLeaveList>(e => e.ManagerId == employeeHeader.Id).OrderBy(o => o.EmployeeId).ToList();
                List <EmployeeLeaveViewModel> employeeLeaveViewModelList = new List <EmployeeLeaveViewModel>();
                foreach (EmployeeLeaveList employeeLeave in employeeLeaveList)
                {
                    LookUp leaveType = LookUpCodeService.GetLookUpType(employeeLeave.LeaveTypeId);
                    EmployeeLeaveViewModel employeeLeaveViewModel = new EmployeeLeaveViewModel();
                    employeeLeaveViewModel.Id             = employeeLeave.Id;
                    employeeLeaveViewModel.EmployeeName   = employeeLeave.Employee.FirstName + " " + employeeLeave.Employee.LastName;
                    employeeLeaveViewModel.EmployeeId     = employeeLeave.Employee.Id;
                    employeeLeaveViewModel.EmployeeNumber = employeeLeave.Employee.IDNumber;
                    employeeLeaveViewModel.LeaveType      = leaveType.LookUpCode;
                    employeeLeaveViewModel.LeaveTypeId    = leaveType.LookUpID;
                    employeeLeaveViewModel.FromDate       = employeeLeave.FromDate;
                    employeeLeaveViewModel.Days           = employeeLeave.Days;
                    employeeLeaveViewModel.ToDate         = employeeLeave.ToDate;
                    employeeLeaveViewModel.ApplyDate      = employeeLeave.ApplyDate;
                    employeeLeaveViewModel.Status         = employeeLeave.Status;
                    employeeLeaveViewModel.Reason         = employeeLeave.Reason;
                    employeeLeaveViewModel.Remarks        = employeeLeave.Remarks;
                    employeeLeaveViewModel.BranchId       = employeeLeave.BranchId;
                    employeeLeaveViewModel.TeamLeadId     = employeeLeave.ManagerId;
                    employeeLeaveViewModelList.Add(employeeLeaveViewModel);
                }
                if (employeeLeaveViewModelList != null && employeeLeaveViewModelList.Any())
                {
                    result = Json(new { employeeLeaveList = employeeLeaveViewModelList, sucess = true }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    result = Json(new { sucess = false, message = "No Data Found." }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    return(Json(new { success = false, message = ex.InnerException.Message }, JsonRequestBehavior.DenyGet));
                }
            }
            return(result);
        }