public EmployeeIssueGraphViewModel(
     INavigationManager navigation,
     IUnitOfWorkFactory factory,
     EmployeeCard employee,
     ProtectionTools protectionTools) : base(navigation)
 {
     using (var unitOfWork = factory.CreateWithoutRoot())
         Intervals = IssueGraph.MakeIssueGraph(unitOfWork, employee, protectionTools).Intervals;
     Title = $"Хронология {employee.ShortName} - {protectionTools.Name}";
 }
예제 #2
0
        public void MakeIssueGraph_UseManualOperationsTest()
        {
            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "СИЗ для тестирования";
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

                var employee = new EmployeeCard();
                uow.Save(employee);

                //Операция без номеклатуры
                var manualOp = new EmployeeIssueOperation();
                manualOp.OperationTime    = new DateTime(2019, 1, 1, 14, 0, 0);
                manualOp.AutoWriteoffDate = new DateTime(2020, 1, 1);
                manualOp.Employee         = employee;
                manualOp.ProtectionTools  = protectionTools;
                manualOp.Issued           = 1;
                manualOp.OverrideBefore   = true;
                uow.Save(manualOp);

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime    = new DateTime(2020, 1, 1, 13, 0, 0);
                expenseOp.AutoWriteoffDate = new DateTime(2021, 1, 1);
                expenseOp.Employee         = employee;
                expenseOp.Nomenclature     = nomenclature;
                expenseOp.ProtectionTools  = protectionTools;
                expenseOp.Issued           = 1;
                uow.Save(expenseOp);

                uow.Commit();

                var graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                Assert.That(graph.Intervals.Count, Is.EqualTo(3));
                var first = graph.OrderedIntervals.First();
                Assert.That(first.StartDate, Is.EqualTo(new DateTime(2019, 1, 1)));
            }
        }
예제 #3
0
        public void RecalculateLastIssue(EmployeeCardItem row)
        {
            var operation = row.LastIssueOperation;

            //Если строку нормы по которой выдавали удалили, пытаемся пере-подвязать к имеющийся совпадающей по СИЗ
            if (!row.EmployeeCard.WorkwearItems.Any(x => x.ActiveNormItem.IsSame(operation.NormItem)))
            {
                if (row.EmployeeCard.WorkwearItems.Any(x => x.ProtectionTools.Id == operation.ProtectionTools.Id))
                {
                    var norm = row.EmployeeCard.WorkwearItems
                               .Where(x => x.ProtectionTools.Id == operation.ProtectionTools.Id)
                               .Select(x => x.ActiveNormItem)
                               .FirstOrDefault();
                    if (norm != null)
                    {
                        operation.NormItem = norm;
                    }
                }
            }
            var graph = IssueGraph.MakeIssueGraph(UoW, row.EmployeeCard, operation.ProtectionTools);

            operation.RecalculateDatesOfIssueOperation(graph, BaseParameters, interactive);
            row.UpdateNextIssue(UoW);
        }
예제 #4
0
        public void HandleDeleteEmployeeVacation_RecalculateWithTwoIssuePerDayTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);
            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления")) {
                BuisnessLogicGlobalEventHandler.Init(ask, UnitOfWorkFactory);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "СИЗ для тестирования";
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);

                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 2, 10);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);
                uow.Commit();

                var warehouseOperation = new WarehouseOperation();
                warehouseOperation.Nomenclature = nomenclature;
                uow.Save(warehouseOperation);

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime      = new DateTime(2019, 1, 1, 14, 0, 0);
                expenseOp.AutoWriteoffDate   = new DateTime(2020, 1, 1);
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = nomenclature;
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.NormItem           = normItem;
                expenseOp.Issued             = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                var graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                expenseOp.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);
                uow.Save(expenseOp);

                var warehouseOperation2 = new WarehouseOperation();
                warehouseOperation2.Nomenclature = nomenclature;
                uow.Save(warehouseOperation2);

                var expenseOp2 = new EmployeeIssueOperation();
                expenseOp2.OperationTime      = new DateTime(2019, 1, 1, 13, 0, 0);
                expenseOp2.AutoWriteoffDate   = new DateTime(2020, 1, 1);
                expenseOp2.Employee           = employee;
                expenseOp2.Nomenclature       = nomenclature;
                expenseOp2.ProtectionTools    = protectionTools;
                expenseOp2.NormItem           = normItem;
                expenseOp2.Issued             = 1;
                expenseOp2.WarehouseOperation = warehouseOperation2;
                graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                expenseOp2.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);
                uow.Save(expenseOp2);
                uow.Commit();

                vacation.UpdateRelatedOperations(uow, new EmployeeIssueRepository(), baseParameters, ask);
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2021, 1, 11)));

                //Выполняем удаление
                employee.Vacations.Remove(vacation);
                uow.Delete(vacation);
                uow.Commit();

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultEmployee = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(resultEmployee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2021, 1, 1)));
                }
            }
        }
예제 #5
0
        void UpdateLastIssue(EmployeeProcessingJournalNode[] nodes)
        {
            var progressPage = NavigationManager.OpenViewModel <ProgressWindowViewModel>(null);
            var progress     = progressPage.ViewModel.Progress;

            loggerProcessing.Info($"Пересчет сроков носки получного для {nodes.Length} сотрудников");
            loggerProcessing.Info($"База данных: {dataBaseInfo.Name}");

            progress.Start(nodes.Length + 2, text: "Загружаем сотрудников");
            var employees = UoW.GetById <EmployeeCard>(nodes.Select(x => x.Id)).ToArray();

            progress.Add(text: $"Получаем последние выдачи");
            var employeeIssueRepository = AutofacScope.Resolve <EmployeeIssueRepository>(new TypedParameter(typeof(IUnitOfWork), UoW));
            var operations = employeeIssueRepository.GetLastIssueOperationsForEmployee(employees);
            int step       = 0;

            foreach (var employee in employees)
            {
                progress.Add(text: $"Обработка {employee.ShortName}");
                step++;
                var employeeOperations = operations.Where(x => x.Employee.IsSame(employee)).ToList();
                if (employeeOperations.Count == 0)
                {
                    Results[employee.Id] = "Нет выданного";
                    continue;
                }
                int changes = 0;
                foreach (var operation in employeeOperations)
                {
                    if (operation.ProtectionTools == null)
                    {
                        continue;
                    }
                    var oldDate = operation.ExpiryByNorm;
                    var graph   = IssueGraph.MakeIssueGraph(UoW, employee, operation.ProtectionTools);
                    operation.RecalculateDatesOfIssueOperation(graph, baseParameters, interactive);
                    if (operation.ExpiryByNorm?.Date != oldDate?.Date)
                    {
                        UoW.Save(operation);
                        loggerProcessing.Info($"Изменена дата окончания носки с {oldDate:d} на {operation.ExpiryByNorm:d} для выдачи {operation.OperationTime} [{operation.Title}]");
                        changes++;
                        var item = employee.WorkwearItems.FirstOrDefault(x => x.ProtectionTools.IsSame(operation.ProtectionTools));
                        if (item != null)
                        {
                            var lastDate = item.NextIssue;
                            item.UpdateNextIssue(UoW);
                            if (item.NextIssue?.Date != lastDate?.Date)
                            {
                                loggerProcessing.Info($"Изменена дата следующей выдачи с {lastDate:d} на {item.NextIssue:d} для потребности [{item.Title}]");
                            }
                        }
                    }
                }
                if (changes > 0)
                {
                    Results[employee.Id] = NumberToTextRus.FormatCase(changes, "изменена {0} дата", "изменено {0} даты", "изменено {0} дат");
                    UoW.Save(employee);
                }
                else
                {
                    Results[employee.Id] = "Без изменений";
                }
                if (step % 10 == 0)
                {
                    UoW.Commit();
                }
            }
            progress.Add(text: "Готово");
            UoW.Commit();
            NavigationManager.ForceClosePage(progressPage, CloseSource.FromParentPage);
            Refresh();
        }