Exemple #1
0
        public ActionResult Edit(VacationRecord vacationRecord)
        {
            var currentUser                 = _userService.GetUserDataForVersion();
            var currentUserEmployee         = _userService.GetEmployeeForCurrentUser();
            var tsHoursRecordByVacationList = _tsHoursRecordService.Get(x => x.Where(t => t.ParentVacationRecordID == vacationRecord.ID).ToList());
            var originalItem                = _vacationRecordService.Get(records => records.Where(x => x.ID == vacationRecord.ID).AsNoTracking().ToList()).FirstOrDefault();

            if (vacationRecord.VacationBeginDate > vacationRecord.VacationEndDate)
            {
                ModelState.AddModelError("VacationBeginDate", "Дата начала не может быть больше даты конца.");
            }
            var reportingPeriodForBeginDate = _reportingPeriodService.GetAll(x => x.Month == vacationRecord.VacationBeginDate.Month && x.Year == vacationRecord.VacationBeginDate.Year).FirstOrDefault();
            var reportingPeriodForEndDate   = _reportingPeriodService.GetAll(x => x.Month == vacationRecord.VacationEndDate.Month &&
                                                                             x.Year == vacationRecord.VacationEndDate.Year).FirstOrDefault();

            //дату начала отпуска в закрытый перод менить нельзя
            if (reportingPeriodForBeginDate != null && reportingPeriodForBeginDate.NewTSRecordsAllowedUntilDate < DateTime.Now &&
                originalItem.VacationBeginDate != vacationRecord.VacationBeginDate)
            {
                ModelState.AddModelError("VacationBeginDate", "Дату начала отпуска нельзя изменить, так как отчетный период закрыт.");
            }

            //дату окончания отпуска в закрытый перод менить нельзя
            if (reportingPeriodForEndDate != null && reportingPeriodForEndDate.NewTSRecordsAllowedUntilDate < DateTime.Now &&
                originalItem.VacationEndDate != vacationRecord.VacationEndDate)
            {
                ModelState.AddModelError("VacationEndDate", "Дату окончания отпуска нельзя изменить, так как отчетный период закрыт.");
            }

            //невозможно изменить вид отпуска если запись в таймшите уже есть
            if (tsHoursRecordByVacationList != null &&
                tsHoursRecordByVacationList.Count() != 0 &&
                originalItem.VacationType != vacationRecord.VacationType)
            {
                ModelState.AddModelError("VacationType", "Невозможно изменить вид отпуска, так как созданы связанные записи ТШ.");
            }

            if (ModelState.IsValid)
            {
                _vacationRecordService.Update(vacationRecord);

                //TODO добавить
                //_taskTimesheetProcessing.ProcessVacationRecords(currentEmployee, vacationRecord);
                return(RedirectToAction("Index"));
            }

            SetViewBag(vacationRecord);
            ViewBag.EmployeeID = new SelectList(_employeeService.Get(x => x.Where(e => e.ID == originalItem.EmployeeID).ToList()), "ID", "FullName", originalItem?.EmployeeID ?? 1);

            return(View(vacationRecord));
        }
Exemple #2
0
        private DataTable GetTSHoursUtilizationReportDataTable(DataTable dataTable,
                                                               DateTime periodStart, DateTime periodEnd,
                                                               List <int> departmentsIDs)
        {
            List <Employee> currentEmployeeList = _employeeService.GetCurrentEmployees(new DateTimeRange(periodStart, periodEnd)).ToList()
                                                  .Where(e => e.Department != null)
                                                  .OrderBy(e => e.Department.ShortName + (e.Department.DepartmentManagerID != e.ID).ToString() + e.FullName).ToList();

            var tsHoursRecordForPeriodList = _tsHoursRecordService.Get(x => x.Where(r => r.RecordDate >= periodStart && r.RecordDate <= periodEnd &&
                                                                                    r.Project != null && r.Project.ProjectType != null).ToList());

            int periodRowStartIndex = dataTable.Rows.Count;

            var projectTypeUtilizationList    = _projectTypeService.Get(x => x.Where(pt => pt.Utilization == true).ToList());
            var projectTypeNonUtilizationList = _projectTypeService.Get(x => x.Where(pt => pt.Utilization == false).ToList());

            dataTable.Rows.Add(periodStart.ToString("MMMM").ToUpper());
            dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = true;

            double hoursPeriodTotal = 0;

            if (departmentsIDs != null)
            {
                foreach (int depID in departmentsIDs)
                {
                    var employeeInDepartmentIDs = GetEmployeesByDepartmentID(depID, currentEmployeeList.ToList()).Select(e => e.ID);

                    double hoursPeriodInDepartment = Math.Round(tsHoursRecordForPeriodList.Where(r => r.EmployeeID != null && employeeInDepartmentIDs.Contains(r.EmployeeID.Value))
                                                                .ToList()
                                                                .Select(c => c.Hours ?? 0)
                                                                .DefaultIfEmpty()
                                                                .Sum(h => h), 2);

                    dataTable.Rows[periodRowStartIndex]["Department_" + depID.ToString()] = hoursPeriodInDepartment;

                    hoursPeriodTotal += hoursPeriodInDepartment;
                }
            }

            dataTable.Rows[periodRowStartIndex]["Total"] = hoursPeriodTotal;

            periodRowStartIndex = dataTable.Rows.Count - 1;
            foreach (var group in projectTypeUtilizationList.GroupBy(pt => pt.ActivityType))
            {
                dataTable.Rows.Add("-" + group.FirstOrDefault().ActivityType.GetAttributeOfType <DisplayAttribute>().Name);
                dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = false;

                foreach (var projectType in group.OrderBy(pt => pt.ShortName))
                {
                    dataTable.Rows.Add("--" + projectType.Title);
                    dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = false;
                }
            }

            dataTable.Rows.Add("ИТОГО Утилизировано");
            dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = true;
            int utilizationRowNum = dataTable.Rows.Count - 1;

            dataTable = FillDataTableHoursForProjectTypes(dataTable, departmentsIDs, currentEmployeeList, tsHoursRecordForPeriodList,
                                                          projectTypeUtilizationList, periodRowStartIndex);

            periodRowStartIndex = dataTable.Rows.Count - 1;
            foreach (var group in projectTypeNonUtilizationList.GroupBy(pt => pt.ActivityType))
            {
                dataTable.Rows.Add("-" + group.FirstOrDefault().ActivityType.GetAttributeOfType <DisplayAttribute>().Name);
                dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = false;

                foreach (var projectType in group.OrderBy(pt => pt.ShortName))
                {
                    dataTable.Rows.Add("--" + projectType.Title);
                    dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = false;
                }
            }

            dataTable.Rows.Add("ИТОГО Не улитизировано");
            dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = true;
            int nonUtilizationRowNum = dataTable.Rows.Count - 1;

            dataTable = FillDataTableHoursForProjectTypes(dataTable, departmentsIDs, currentEmployeeList, tsHoursRecordForPeriodList,
                                                          projectTypeNonUtilizationList, periodRowStartIndex);

            dataTable.Rows.Add("ИТОГО Утилизация");
            dataTable.Rows[dataTable.Rows.Count - 1]["_ISGROUPROW_"] = true;

            if (departmentsIDs != null)
            {
                foreach (int depID in departmentsIDs)
                {
                    double hoursUtilization    = 0;
                    double hoursNonUtilization = 0;

                    if (dataTable.Rows[utilizationRowNum]["Department_" + depID.ToString()] != null ||
                        String.IsNullOrEmpty(dataTable.Rows[utilizationRowNum]["Department_" + depID.ToString()].ToString()) == false)
                    {
                        hoursUtilization = (double)dataTable.Rows[utilizationRowNum]["Department_" + depID.ToString()];
                    }

                    if (dataTable.Rows[nonUtilizationRowNum]["Department_" + depID.ToString()] != null ||
                        String.IsNullOrEmpty(dataTable.Rows[nonUtilizationRowNum]["Department_" + depID.ToString()].ToString()) == false)
                    {
                        hoursNonUtilization = (double)dataTable.Rows[nonUtilizationRowNum]["Department_" + depID.ToString()];
                    }

                    if ((hoursUtilization + hoursNonUtilization) != 0)
                    {
                        dataTable.Rows[dataTable.Rows.Count - 1]["Department_" + depID.ToString()] = Math.Round(hoursUtilization / (hoursUtilization + hoursNonUtilization), 2);
                    }
                }
            }

            double hoursUtilizationTotal    = 0;
            double hoursNonUtilizationTotal = 0;

            if (dataTable.Rows[utilizationRowNum]["Total"] != null ||
                String.IsNullOrEmpty(dataTable.Rows[utilizationRowNum]["Total"].ToString()) == false)
            {
                hoursUtilizationTotal = (double)dataTable.Rows[utilizationRowNum]["Total"];
            }

            if (dataTable.Rows[nonUtilizationRowNum]["Total"] != null ||
                String.IsNullOrEmpty(dataTable.Rows[nonUtilizationRowNum]["Total"].ToString()) == false)
            {
                hoursNonUtilizationTotal = (double)dataTable.Rows[nonUtilizationRowNum]["Total"];
            }

            if ((hoursUtilizationTotal + hoursNonUtilizationTotal) != 0)
            {
                dataTable.Rows[dataTable.Rows.Count - 1]["Total"] = Math.Round(hoursUtilizationTotal / (hoursUtilizationTotal + hoursNonUtilizationTotal), 2);
            }

            dataTable.Rows.Add("");

            return(dataTable);
        }
Exemple #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            var tsAutoHoursRecord = _tsAutoHoursRecordService.GetById(id);
            var user      = _userService.GetUserDataForVersion();
            var isDeleted = true;
            var errorOnParentTSHoursRecord = string.Empty;
            var errorOnTSAutoHoursRecord   = string.Empty;

            if (tsAutoHoursRecord != null)
            {
                var reportingPeriodForBeginDate = _reportingPeriodService.GetAll(x => x.Month == tsAutoHoursRecord.BeginDate.Value.Month && x.Year == tsAutoHoursRecord.BeginDate.Value.Year).FirstOrDefault();
                var reportingPeriodForEndDate   = _reportingPeriodService.GetAll(x => x.Month == tsAutoHoursRecord.EndDate.Value.Month && x.Year == tsAutoHoursRecord.EndDate.Value.Year).FirstOrDefault();
                if (reportingPeriodForBeginDate != null && reportingPeriodForEndDate != null &&
                    (reportingPeriodForEndDate.NewTSRecordsAllowedUntilDate > DateTime.Now &&
                     reportingPeriodForBeginDate.NewTSRecordsAllowedUntilDate > DateTime.Now))
                {
                    var parentHoursRecords = _tsHoursRecordService.Get(x => x.Where(t => t.ParentTSAutoHoursRecordID == id).ToList());
                    if (parentHoursRecords != null)
                    {
                        foreach (var hoursRecord in parentHoursRecords)
                        {
                            var recycleBinInDBRelationParentTSHoursRecord = _serviceService.HasRecycleBinInDBRelation(hoursRecord);
                            if (recycleBinInDBRelationParentTSHoursRecord.hasRelated == false)
                            {
                                var recycleToRecycleBinParentTSHoursRecords = _tsAutoHoursRecordService.RecycleToRecycleBin(hoursRecord.ID, user.Item1, user.Item2);
                                isDeleted = recycleToRecycleBinParentTSHoursRecords.toRecycleBin;
                                errorOnParentTSHoursRecord = recycleToRecycleBinParentTSHoursRecords.toRecycleBin ? string.Empty : recycleToRecycleBinParentTSHoursRecords.relatedClassId;
                            }
                            else
                            {
                                errorOnParentTSHoursRecord = recycleBinInDBRelationParentTSHoursRecord.relatedInDBClassId;
                            }
                        }
                    }

                    var recycleBinInDBRelationTSAutoHoursRecord = _serviceService.HasRecycleBinInDBRelation(new TSAutoHoursRecord()
                    {
                        ID = id
                    });
                    if (recycleBinInDBRelationTSAutoHoursRecord.hasRelated == false)
                    {
                        var recycleToRecycleBinTSAutoHoursRecords = _tsAutoHoursRecordService.RecycleToRecycleBin(id, user.Item1, user.Item2);
                        isDeleted = recycleToRecycleBinTSAutoHoursRecords.toRecycleBin;
                        errorOnTSAutoHoursRecord = recycleToRecycleBinTSAutoHoursRecords.toRecycleBin ? string.Empty : recycleToRecycleBinTSAutoHoursRecords.relatedClassId;
                    }
                    else
                    {
                        errorOnTSAutoHoursRecord = recycleBinInDBRelationTSAutoHoursRecord.relatedInDBClassId;
                    }
                }
            }

            if (!isDeleted)
            {
                if (!string.IsNullOrEmpty(errorOnParentTSHoursRecord))
                {
                    ViewBag.RecycleBinError = "Невозможно удалить, так как на удаляемый элемент ссылаются другие элементы в системе." +
                                              $"Сначала необходимо удалить элементы, которые ссылаются на данный элемент. {errorOnParentTSHoursRecord}";
                }
                else if (!string.IsNullOrEmpty(errorOnTSAutoHoursRecord))
                {
                    ViewBag.RecycleBinError = "Невозможно удалить, так как на удаляемый элемент ссылаются другие элементы в системе." +
                                              $"Сначала необходимо удалить элементы, которые ссылаются на данный элемент. {errorOnTSAutoHoursRecord}";
                }
                return(View(tsAutoHoursRecord));
            }
            return(RedirectToAction("Index"));
        }