Пример #1
0
        public async Task <JsonResult> GetDepartmentEmployees([DataSourceRequest] DataSourceRequest request, string deptCode)
        {
            if (string.IsNullOrWhiteSpace(deptCode))
            {
                return(Json(new List <object>()
                {
                }));
            }

            var allDataList = await _erpManager.GetDepartmentEmployeesInfo(deptCode);

            allDataList = await setupEmployeesInfo(allDataList.OrderBy(d => d.DepartmentName), DateTime.Now);

            var result = allDataList.ToTreeDataSourceResult(request,
                                                            e => e.EmployeeId,
                                                            e => e.ReportToId,
                                                            e => e);

            return(Json(result));
        }
Пример #2
0
        public async Task <IActionResult> AbsentsReport(DateTime startDate, DateTime endDate
                                                        , int[] employeesIds = null, string[] departments = null, string absentNotes = "all"
                                                        , bool summaryReport = true, int?pageNumber       = null, int pageSize       = 31)
        {
            try
            {
                startDate = startDate.Date;
                endDate   = endDate.Date;

                employeesIds = employeesIds ?? new int[] { };
                departments  = departments ?? new string[] { };

                var employeesIdsList = employeesIds.ToList();

                if (departments.Count() > 0)
                {
                    var departmentsEmployees = new List <EmployeeInfoViewModel>();
                    foreach (var department in departments)
                    {
                        departmentsEmployees.AddRange(await _erpManager.GetDepartmentEmployeesInfo(department));
                    }

                    if (departmentsEmployees.Any())
                    {
                        employeesIdsList.AddRange(departmentsEmployees.Select(d => d.EmployeeId));
                        employeesIds = employeesIdsList.Distinct().OrderBy(e => e).ToArray();
                    }
                }


                try
                {
                    string reportType = "Absents " + (pageNumber.HasValue ? "Page : 1" : "All Pages") + ", ";
                    reportType += $"Notes : {absentNotes} ,";
                    reportType += summaryReport ? "Summary" : "Details";

                    saveReportRequest(employeesIds, departments, startDate, endDate, reportType);
                }
                catch (Exception)
                {
                }

                var resultsQuery = _employeesDaysReportsManager
                                   .GetAll(d => (employeesIds.Count() < 1 || employeesIds.Contains(d.EmployeeId)) &&
                                           (absentNotes.Trim().ToLower() == "show" ||
                                            (absentNotes.Trim().ToLower() == "hide" && !d.IsDelegationRequest && !d.IsVacationRequest) ||
                                            (absentNotes.Trim().ToLower() == "notes" && (d.IsDelegationRequest || d.IsVacationRequest)) ||
                                            (absentNotes.Trim().ToLower() == "vacations" && d.IsVacationRequest) ||
                                            (absentNotes.Trim().ToLower() == "delegations" && d.IsDelegationRequest)) &&
                                           d.DayDate >= startDate && d.DayDate <= endDate && d.IsAbsentEmployee == true);

                if (pageNumber.HasValue)
                {
                    resultsQuery = resultsQuery.Skip((pageNumber.Value - 1) * pageSize).Take(pageSize);
                }

                var resultsData = await resultsQuery.AsNoTracking().ToListAsync();

                var resultViewModels = _mapper.Map <List <EmployeeDayReportViewModel> >(resultsData);

                if (resultViewModels.Count > 0)
                {
                    employeesIds = resultViewModels.Select(d => d.EmployeeId).Distinct().ToArray();

                    //var erpEmployees = await _erpManager.GetEmployeesInfo(employeesIds);

                    //foreach (var erpEmp in erpEmployees)
                    //{
                    //    foreach (var dayReport in resultViewModels.Where(d => d.EmployeeId == erpEmp.EmployeeId))
                    //    {
                    //        dayReport.EmployeeName = erpEmp.Name;
                    //        dayReport.DepartmentName = erpEmp.DepartmentName;
                    //    }
                    //}
                }

                resultViewModels = resultViewModels.OrderBy(d => d.EmployeeId).ThenBy(d => d.DayDate).ToList();

                if (!summaryReport)
                {
                    return(PartialView(resultViewModels));
                }
                else
                {
                    var summaryViewModels = new List <EmployeeMonthReportViewModel>();
                    foreach (var employeeDays in resultViewModels.GroupBy(e => e.EmployeeId))
                    {
                        var newSummary = new EmployeeMonthReportViewModel
                        {
                            EmployeeId         = employeeDays.Key,
                            EmployeeName       = employeeDays.First().EmployeeName,
                            DepartmentName     = employeeDays.First().DepartmentName,
                            ProcessingDate     = employeeDays.Max(d => d.ProcessingDate),
                            StartDate          = startDate,
                            ToDate             = endDate,
                            TotalAbsentsDays   = employeeDays.Count(),
                            AllAbsentsNotified = !employeeDays.Where(d => d.IsAbsentEmployee &&
                                                                     !d.IsDelegationRequest &&
                                                                     !d.IsVacationRequest).Any(d => !d.AbsentNotified),
                            AllAbsentsWithNotes = !employeeDays.Where(d => d.IsAbsentEmployee &&
                                                                      !d.IsDelegationRequest &&
                                                                      !d.IsVacationRequest).Any()
                        };
                        summaryViewModels.Add(newSummary);
                    }

                    ViewBag.ShowAbsents = true;
                    ViewBag.ShowWaste   = false;
                    return(PartialView("WastesReport", summaryViewModels.OrderBy(s => s.EmployeeId).ToList()));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }