Ejemplo n.º 1
0
        public async Task <IActionResult> GetProcessingPercentageJson()
        {
            try
            {
                decimal result = 100;

                var unCompletedRequest = await _processingsRequestsManager.GetSingleItemAsync(p => p.Completed == false);

                if (unCompletedRequest != null)
                {
                    int daysCount      = (int)unCompletedRequest.ToDate.Subtract(unCompletedRequest.FromDate).TotalDays + 1;
                    int employeesCount = unCompletedRequest.Employees?.TryParseToNumbers()?.Count() ?? 0;
                    if (employeesCount == 0)
                    {
                        var allEmployees = await _erpManager.GetShortEmployeesInfo();

                        employeesCount = allEmployees.Count;
                    }

                    int totalRecords = daysCount * employeesCount;

                    var completedDaysReports = await _employeesDaysReportsManager
                                               .GetAll(d => d.ProcessingDate >= unCompletedRequest.RequestDate).AsNoTracking().CountAsync();

                    if (completedDaysReports > 0 && totalRecords > 0)
                    {
                        result = ((decimal)completedDaysReports / (decimal)totalRecords) * 100m;
                    }
                }

                return(Json(new { Percentage = Math.Round(result, 2) }));
            }
            catch (Exception)
            {
                return(Json(new { Percentage = 0 }));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> ShortEmployeesInfoJson()
        {
            IEnumerable <ShortEmployeeInfoViewModel> results = await _erpManager.GetShortEmployeesInfo();

            return(Json(results.OrderBy(e => e.EmployeeId).ToList()));
        }