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}";
 }
Esempio n. 2
0
        public void HandleDelete_CanDeleteEmployeeTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            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.Month;
                normItem.PeriodCount = 2;
                uow.Save(norm);

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

                var warehouseOperation = new WarehouseOperation();
                var expenseOp          = new EmployeeIssueOperation();
                expenseOp.OperationTime      = warehouseOperation.OperationTime = new DateTime(2019, 1, 1);
                expenseOp.ExpiryByNorm       = new DateTime(2019, 4, 1);
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = warehouseOperation.Nomenclature = nomenclature;
                expenseOp.NormItem           = normItem;
                warehouseOperation.Amount    = expenseOp.Issued = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                uow.Save(nomenclature);
                uow.Save(normItem);
                uow.Save(warehouseOperation);
                uow.Save(expenseOp);
                uow.Commit();

                //FIXME Временно чтобы переделака не вызвала конфликт мержа в 2.4
                Configure.ConfigureDeletion();
                var deletion = new DeleteCore(DeleteConfig.Main, uow);
                deletion.PrepareDeletion(typeof(EmployeeCard), employee.Id, CancellationToken.None);
                deletion.RunDeletion(CancellationToken.None);
            }
        }
Esempio n. 3
0
        public IList <EmployeeIssueOperation> GetOperationsForEmployee(
            IUnitOfWork uow, EmployeeCard employee,
            ProtectionTools protectionTools,
            Action <IQueryOver <EmployeeIssueOperation, EmployeeIssueOperation> > makeEager = null)
        {
            var query = uow.Session.QueryOver <EmployeeIssueOperation>()
                        .Where(o => o.Employee == employee)
                        .Where(o => o.ProtectionTools == protectionTools);

            makeEager?.Invoke(query);

            return(query.OrderBy(x => x.OperationTime).Asc.List());
        }
Esempio n. 4
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)));
            }
        }
Esempio n. 5
0
        public void GetOperationsTouchDates_OneDateRangeTest()
        {
            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

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

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

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

                var opBefore = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2018, 12, 31, 14, 0, 0),
                    AutoWriteoffDate = new DateTime(2020, 1, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools,
                    Issued           = 1
                };
                uow.Save(opBefore);

                var opInRange = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2019, 1, 1, 0, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 1, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools,
                    Issued           = 1
                };
                uow.Save(opInRange);

                var opInRange2 = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2019, 1, 1, 13, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 2, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools,
                    Issued           = 2
                };
                uow.Save(opInRange2);

                var opAfter = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2019, 1, 2, 13, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 5, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools,
                    Issued           = 1
                };
                uow.Save(opAfter);

                uow.Commit();

                var repository = new EmployeeIssueRepository(uow);
                var result     =
                    repository.GetOperationsByDates(
                        new[] { employee }, new DateTime(2019, 1, 1), new DateTime(2019, 1, 1));
                Assert.That(result.Any(x => x.OperationTime == new DateTime(2019, 1, 1, 0, 0, 0)), Is.True);
                Assert.That(result.Any(x => x.OperationTime == new DateTime(2019, 1, 1, 13, 0, 0)), Is.True);
                Assert.That(result.Count, Is.EqualTo(2));
            }
        }
Esempio n. 6
0
        public void GetLastOperationsForEmployee_HappyPathTest()
        {
            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var nomenclatureType = new ItemsType {
                    Name = "Тестовый тип номенклатуры"
                };
                uow.Save(nomenclatureType);

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

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

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

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

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

                //Лишний
                var employee3 = new EmployeeCard();
                uow.Save(employee3);

                //Операция employee1 СИЗ 1
                var opE1P1 = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2018, 1, 1, 14, 0, 0),
                    AutoWriteoffDate = new DateTime(2020, 1, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools,
                    Issued           = 1
                };
                uow.Save(opE1P1);

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

                var opE1P2 = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2021, 1, 1, 13, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 5, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools2,
                    Issued           = 1
                };
                uow.Save(opE1P2);

                var opE1P2Return = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2021, 2, 1, 13, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 5, 1),
                    Employee         = employee,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools2,
                    Issued           = 0,
                    Returned         = 1
                };
                uow.Save(opE1P2Return);

                var opE2P2 = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2021, 2, 1, 14, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 5, 1),
                    Employee         = employee2,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools2,
                    Issued           = 1
                };
                uow.Save(opE2P2);

                //Не хотим видеть в выборке от сотрудника 3
                var opE3P2 = new EmployeeIssueOperation {
                    OperationTime    = new DateTime(2021, 2, 1, 14, 0, 0),
                    AutoWriteoffDate = new DateTime(2021, 5, 1),
                    Employee         = employee3,
                    Nomenclature     = nomenclature,
                    ProtectionTools  = protectionTools2,
                    Issued           = 1
                };
                uow.Save(opE3P2);

                uow.Commit();

                var repository = new EmployeeIssueRepository(uow);
                var result     = repository.GetLastIssueOperationsForEmployee(new[] { employee, employee2 });

                Assert.That(result, Has.No.Member(opE1P1));
                Assert.That(result, Has.Member(op2E1P1));
                Assert.That(result, Has.Member(opE1P2));
                Assert.That(result, Has.No.Member(opE1P2Return));
                Assert.That(result, Has.Member(opE2P2));
                Assert.That(result, Has.No.Member(opE3P2));
            }
        }
Esempio n. 7
0
        public void GetReferencedDocuments_CollectiveExpenseTest()
        {
            var interactive = Substitute.For <IInteractiveQuestion>();

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

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var protectionTools = new ProtectionTools {
                    Name = "Тестовая курточка"
                };
                uow.Save(protectionTools);

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

                var nomenclature = new Nomenclature {
                    Type = nomenclatureType
                };
                nomenclature.ProtectionTools.Add(protectionTools);
                uow.Save(nomenclature);

                var norm = new Norm();
                norm.AddItem(protectionTools);
                uow.Save(norm);

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

                var employee2 = new EmployeeCard();
                employee2.AddUsedNorm(norm);
                uow.Save(employee2);

                var expense = new CollectiveExpense()
                {
                    Date      = new DateTime(2021, 9, 10),
                    Warehouse = warehouse,
                };

                var size   = new Size();
                var height = new Size();
                uow.Save(size);
                uow.Save(height);

                var stockPosition = new StockPosition(nomenclature, 0, size, height);
                var item          = expense.AddItem(employee.WorkwearItems.FirstOrDefault(), stockPosition, 1);
                var item2         = expense.AddItem(employee2.WorkwearItems.FirstOrDefault(), stockPosition, 10);

                expense.UpdateOperations(uow, baseParameters, interactive);
                uow.Save(expense);
                uow.Commit();

                var repository = new EmployeeIssueRepository(uow);
                var results    = repository
                                 .GetReferencedDocuments(item.EmployeeIssueOperation.Id, item2.EmployeeIssueOperation.Id);
                var result1 = results.First(x => x.OperationId == item.EmployeeIssueOperation.Id);
                Assert.That(result1.DocumentType, Is.EqualTo(StokDocumentType.CollectiveExpense));
                Assert.That(result1.DocumentId, Is.EqualTo(expense.Id));
                Assert.That(result1.ItemId, Is.EqualTo(item.Id));
                var result2 = results.First(x => x.OperationId == item2.EmployeeIssueOperation.Id);
                Assert.That(result2.DocumentType, Is.EqualTo(StokDocumentType.CollectiveExpense));
                Assert.That(result2.DocumentId, Is.EqualTo(expense.Id));
                Assert.That(result2.ItemId, Is.EqualTo(item2.Id));
            }
        }
Esempio n. 8
0
        public void WriteoffMainTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

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

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

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

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

                var size   = new Size();
                var height = new Size();
                uow.Save(size);
                uow.Save(height);

                var position1 = new StockPosition(nomenclature, 0, size, height);

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

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

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense {
                    Operation = ExpenseOperations.Employee,
                    Warehouse = warehouse,
                    Employee  = employee,
                    Date      = new DateTime(2018, 10, 22)
                };
                var item = expense.AddItem(position1, 3);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                var balance = EmployeeRepository.ItemsBalance(uow, employee, new DateTime(2018, 10, 30));
                Assert.That(balance.First().Amount, Is.EqualTo(3));

                //Списываем
                var writeoff = new Writeoff {
                    Date = new DateTime(2018, 10, 25)
                };
                writeoff.AddItem(item.EmployeeIssueOperation, 1);

                //Обновление операций
                writeoff.UpdateOperations(uow);
                uow.Save(writeoff);
                uow.Commit();

                var balanceAfter = EmployeeRepository.ItemsBalance(uow, employee, new DateTime(2018, 10, 30));
                Assert.That(balanceAfter.First().Amount, Is.EqualTo(2));
            }
        }
        public void BestChoise_IssuingMultipleRows_TwoNomeclatureSameNeedsTest()
        {
            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()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

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

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

                var nomenclature2 = new Nomenclature {
                    Type = nomenclatureType
                };
                uow.Save(nomenclature2);

                var protectionTools = new ProtectionTools {
                    Name = "Номенклатура нормы"
                };
                protectionTools.AddNomeclature(nomenclature);
                protectionTools.AddNomeclature(nomenclature2);
                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);
                Assert.That(employee.WorkwearItems.Count, Is.GreaterThan(0));
                uow.Save(employee);
                uow.Commit();

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2020, 07, 20),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                uow.Commit();
                Assert.That(uow.GetAll <WarehouseOperation>().Count(), Is.EqualTo(2));

                employee.FillWearInStockInfo(uow, baseParameters, warehouse, new DateTime(2020, 07, 22));
                Assert.That(employee.GetUnderreceivedItems(baseParameters).Count(), Is.GreaterThan(0));
                var employeeCardItem = employee.GetUnderreceivedItems(baseParameters).First();
                Assert.That(employeeCardItem.BestChoiceInStock.Count(), Is.GreaterThan(0));

                var bestChoice = employeeCardItem.BestChoiceInStock.First();

                Assert.That(bestChoice.Nomenclature, Is.EqualTo(nomenclature));
            }
        }
        public void FillWearRecivedInfo_LastIssueDateExistAfterAutoWriteoffDateTest()
        {
            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var nomenclatureType = new ItemsType();
                nomenclatureType.Name     = "Тестовый тип номенклатуры";
                nomenclatureType.Category = ItemTypeCategory.wear;
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                nomenclature.Sex  = ClothesSex.Men;
                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);
                employee.Sex = Sex.M;
                Assert.That(employee.WorkwearItems.Count, Is.GreaterThan(0));
                uow.Save(employee);
                uow.Commit();

                var warehouseOperation = new WarehouseOperation {
                    Nomenclature  = nomenclature,
                    Amount        = 1,
                    OperationTime = new DateTime(2018, 1, 20),
                };
                uow.Save(warehouseOperation);

                var operationIssue = new EmployeeIssueOperation {
                    Employee           = employee,
                    ExpiryByNorm       = new DateTime(2019, 1, 20),
                    AutoWriteoffDate   = new DateTime(2019, 1, 20),
                    UseAutoWriteoff    = true,
                    Issued             = 1,
                    Nomenclature       = nomenclature,
                    NormItem           = normItem,
                    ProtectionTools    = protectionTools,
                    OperationTime      = new DateTime(2018, 1, 20),
                    StartOfUse         = new DateTime(2018, 1, 20),
                    WarehouseOperation = warehouseOperation,
                };
                uow.Save(operationIssue);

                uow.Commit();

                employee.FillWearRecivedInfo(new EmployeeIssueRepository(uow));
                var item = employee.WorkwearItems.First();
                Assert.That(item.Amount, Is.EqualTo(1));
                Assert.That(item.LastIssue, Is.EqualTo(new DateTime(2018, 1, 20)));
            }
        }
Esempio n. 11
0
        public void UpdateOperations_DeleteRowTest()
        {
            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 warehouse = new Warehouse();
                uow.Save(warehouse);

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

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

                var position1 = new StockPosition(nomenclature, 0, null, null);

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

                var nomenclature2 = new Nomenclature();
                nomenclature2.Type = nomenclatureType2;
                uow.Save(nomenclature2);

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

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

                var position2 = new StockPosition(nomenclature2, 0, null, null);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools1);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                var normItem2 = norm.AddItem(protectionTools2);
                normItem2.Amount      = 1;
                normItem2.NormPeriod  = NormPeriodType.Month;
                normItem2.PeriodCount = 4;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.HireDate = new DateTime(2018, 1, 15);
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income();
                income.Warehouse = warehouse;
                income.Date      = new DateTime(2017, 1, 1);
                income.Operation = IncomeOperations.Enter;
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 10;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense();
                expense.Warehouse = warehouse;
                expense.Employee  = employee;
                expense.Date      = new DateTime(2018, 4, 22);
                expense.Operation = ExpenseOperations.Employee;
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();
                expense.UpdateEmployeeWearItems();
                employee.WorkwearItems.First(e => e.ProtectionTools.IsSame(protectionTools2)).Created = new DateTime(2018, 4, 22);
                uow.Save(expense.Employee);
                uow.Commit();

                Assert.That(employee.WorkwearItems.First(e => e.ProtectionTools.IsSame(protectionTools2)).NextIssue,
                            Is.EqualTo(new DateTime(2018, 8, 22))
                            );

                //Выполняем удаление
                expense.RemoveItem(expense.Items.First(e => e.Nomenclature.Type.IsSame(nomenclatureType2)));
                uow.Save(expense);
                uow.Commit();

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultEmployee = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(resultEmployee.WorkwearItems.First(e => e.ProtectionTools.IsSame(protectionTools2)).NextIssue,
                                Is.EqualTo(new DateTime(2018, 4, 22)));
                }
            }
        }
Esempio n. 12
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)));
                }
            }
        }
Esempio n. 13
0
        public void UpdateEmployeeWearItems_NextIssueDiffIdsTest()
        {
            NewSessionWithSameDB();
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

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

                var nomenclature = new Nomenclature {
                    Type = nomenclatureType,
                    Name = "Тестовая номенклатура"
                };
                uow.Save(nomenclature);

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

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

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var baseParameters = Substitute.For <BaseParameters>();
                baseParameters.ColDayAheadOfShedule.Returns(0);

                employee.FillWearInStockInfo(uow, baseParameters, warehouse, new DateTime(2018, 10, 22));

                var expense = new Expense {
                    Operation = ExpenseOperations.Employee,
                    Warehouse = warehouse,
                    Employee  = employee,
                    Date      = new DateTime(2018, 10, 22)
                };
                var itemExpense = expense.AddItem(employee.WorkwearItems.First(), baseParameters);
                itemExpense.Nomenclature = nomenclature;
                itemExpense.Amount       = 1;

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot()) {
                    var employeeTest = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(employeeTest.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2018, 11, 22)));
                }

                var returnOnStock = new Income {
                    Operation    = IncomeOperations.Return,
                    Warehouse    = warehouse,
                    EmployeeCard = employee,
                    Date         = new DateTime(2018, 11, 2)
                };
                returnOnStock.AddItem(expense.Items.First().EmployeeIssueOperation, 1);
                returnOnStock.UpdateOperations(uow, ask);
                uow.Save(returnOnStock);
                uow.Commit();

                returnOnStock.UpdateEmployeeWearItems();
                uow.Commit();

                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot()) {
                    var employeeTest = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(employeeTest.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2018, 11, 2)));
                }
            }
        }
        public void UpdateOperations_RecalculeteDatesAfterCreateVacation()
        {
            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()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

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

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

                var position1 = new StockPosition(nomenclature, 0, null, null);

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

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

                var position2 = new StockPosition(nomenclature2, 0, null, null);

                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);
                uow.Save(employee);
                uow.Commit();

                var income = new Income();
                income.Warehouse = warehouse;
                income.Date      = new DateTime(2017, 1, 1);
                income.Operation = IncomeOperations.Enter;
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense();
                expense.Warehouse = warehouse;
                expense.Employee  = employee;
                expense.Date      = new DateTime(2018, 5, 10);
                expense.Operation = ExpenseOperations.Employee;
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 10))
                            );

                //Добавляем новый отпуск на 10 дней.
                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);
                vacation.UpdateRelatedOperations(uow, new workwear.Repository.Operations.EmployeeIssueRepository(), baseParameters, ask);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 20))
                            );
            }
        }
Esempio n. 15
0
        public void Deletion_ExpenseEmployeeDocumentTest()
        {
            NewSessionWithSameDB();
            var ask = Substitute.For <IInteractiveQuestion>();

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

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

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

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

                var position1 = new StockPosition(nomenclature, 0, null, null);

                var nomenclature2 = new Nomenclature {
                    Type = nomenclatureType
                };
                uow.Save(nomenclature2);

                var position2 = new StockPosition(nomenclature2, 0, null, null);

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

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

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

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense {
                    Operation = ExpenseOperations.Employee,
                    Warehouse = warehouse,
                    Employee  = employee,
                    Date      = new DateTime(2018, 10, 22)
                };
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                var baseParameters = Substitute.For <BaseParameters>();
                baseParameters.ColDayAheadOfShedule.Returns(0);

                expense.CreateIssuanceSheet(null);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Save(expense.IssuanceSheet);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                var docs = uow.GetAll <Expense>().ToList();
                Assert.That(docs.Count, Is.EqualTo(1));

                //Непосредственно удаление документа
                var cancel = new CancellationTokenSource();
                using (var uowDel = UnitOfWorkFactory.CreateWithoutRoot()) {
                    var deletionService = new DeleteCore(DeleteConfig.Main, uowDel);
                    deletionService.PrepareDeletion(typeof(Expense), expense.Id, cancel.Token);
                    Assert.That(deletionService.TotalLinks, Is.GreaterThan(0));
                    deletionService.RunDeletion(cancel.Token);
                }

                //Проверяем удаление
                var expenseId = expense.Id;
                using (var uowCheck = UnitOfWorkFactory.CreateWithoutRoot()) {
                    //Проверяем что удалили документ.
                    docs = uow.GetAll <Expense>().ToList();
                    Assert.That(docs.Count, Is.Zero);

                    //Проверяем что случайно не удалили СИЗ и номеклатуру.
                    var protections = uow.GetAll <ProtectionTools>().ToList();
                    Assert.That(protections.Count, Is.EqualTo(2));
                    var nomenclatures = uow.GetAll <Nomenclature>().ToList();
                    Assert.That(nomenclatures.Count, Is.EqualTo(2));
                }
            }
        }
        public void FillWearRecivedInfo_NotMergeAnalogTest()
        {
            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var nomenclatureType = new ItemsType();
                nomenclatureType.Name     = "Тестовый тип номенклатуры";
                nomenclatureType.Category = ItemTypeCategory.wear;
                uow.Save(nomenclatureType);

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

                var protectionToolsAnalog = new ProtectionTools();
                protectionToolsAnalog.Name = "Номенклатура нормы Аналог";
                protectionToolsAnalog.AddNomeclature(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "Номенклатура нормы";
                protectionTools.AddAnalog(protectionToolsAnalog);
                protectionTools.AddNomeclature(nomenclature);
                protectionToolsAnalog.AddAnalog(protectionTools);
                uow.Save(protectionToolsAnalog);
                uow.Save(protectionTools);

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

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                employee.Sex = Sex.M;
                Assert.That(employee.WorkwearItems.Count, Is.GreaterThan(0));
                uow.Save(employee);
                uow.Commit();

                var warehouseOperation = new WarehouseOperation {
                    Nomenclature  = nomenclature,
                    Amount        = 1,
                    OperationTime = new DateTime(2018, 1, 20),
                };
                uow.Save(warehouseOperation);

                var operation = new EmployeeIssueOperation {
                    Employee           = employee,
                    ExpiryByNorm       = new DateTime(2019, 1, 20),
                    Issued             = 1,
                    Nomenclature       = nomenclature,
                    NormItem           = normItem,
                    ProtectionTools    = protectionTools,
                    OperationTime      = new DateTime(2018, 1, 20),
                    WarehouseOperation = warehouseOperation,
                };
                uow.Save(operation);

                var warehouseOperation2 = new WarehouseOperation {
                    Nomenclature  = nomenclature,
                    Amount        = 2,
                    OperationTime = new DateTime(2018, 1, 20),
                };
                uow.Save(warehouseOperation2);

                var operation2 = new EmployeeIssueOperation {
                    Employee           = employee,
                    ExpiryByNorm       = new DateTime(2019, 1, 20),
                    Issued             = 2,
                    Nomenclature       = nomenclature,
                    NormItem           = normItem2,
                    ProtectionTools    = protectionToolsAnalog,
                    OperationTime      = new DateTime(2018, 1, 20),
                    WarehouseOperation = warehouseOperation,
                };
                uow.Save(operation2);

                uow.Commit();

                employee.FillWearRecivedInfo(new EmployeeIssueRepository(uow));
                var item1 = employee.WorkwearItems.FirstOrDefault(x => x.ActiveNormItem == normItem);
                Assert.That(item1.Amount, Is.EqualTo(1));
                var item2 = employee.WorkwearItems.FirstOrDefault(x => x.ActiveNormItem == normItem2);
                Assert.That(item2.Amount, Is.EqualTo(2));
            }
        }
Esempio n. 17
0
        public void UpdateEmployeeWearItems_NextIssueDiffIdsTest()
        {
            NewSessionWithSameDB();
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var sizeType   = new SizeType();
                var heightType = new SizeType();
                uow.Save(sizeType);
                uow.Save(heightType);

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


                //Поднимаем id номенклатуры до 2.
                uow.Save(new Nomenclature());

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

                var size = new Size {
                    SizeType = sizeType
                };
                var height = new Size {
                    SizeType = heightType
                };
                uow.Save(size);
                uow.Save(height);

                var position1 = new StockPosition(nomenclature, 0, size, height);

                //Поднимаем id сиза до 3.
                uow.Save(new ProtectionTools {
                    Name = "Id = 1"
                });
                uow.Save(new ProtectionTools {
                    Name = "Id = 2"
                });

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

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

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense {
                    Operation = ExpenseOperations.Employee,
                    Warehouse = warehouse,
                    Employee  = employee,
                    Date      = new DateTime(2018, 10, 22)
                };
                expense.AddItem(position1, 1);

                var baseParameters = Substitute.For <BaseParameters>();
                baseParameters.ColDayAheadOfShedule.Returns(0);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot()) {
                    var employeeTest = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(employeeTest.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2018, 11, 22)));
                }
            }
        }
        protected override IQueryOver <EmployeeCard> ItemsQuery(IUnitOfWork uow)
        {
            EmployeeNotificationJournalNode resultAlias = null;

            Post             postAlias        = null;
            Subdivision      subdivisionAlias = null;
            EmployeeCard     employeeAlias    = null;
            EmployeeCardItem itemAlias        = null;
            ProtectionTools  toolsAlias       = null;
            ItemsType        typesAlias       = null;

            var employees = uow.Session.QueryOver(() => employeeAlias);

            DateTime startTime;

            if (Filter.ShowOverdue)
            {
                startTime = DateTime.MinValue;
            }
            else
            {
                startTime = Filter.StartDateIssue;
            }

            if (Filter.ShowOnlyWork)
            {
                employees.Where(() => employeeAlias.DismissDate == null);
            }
            if (Filter.ShowOnlyLk)
            {
                employees.Where(() => employeeAlias.LkRegistered);
            }
            if (Filter.Subdivision != null)
            {
                employees.Where(() => employeeAlias.Subdivision.Id == Filter.Subdivision.Id);
            }

            employees
            .JoinAlias(() => employeeAlias.WorkwearItems, () => itemAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin);
            if (Filter.ContainsPeriod)
            {
                employees = employees.Where(() => itemAlias.NextIssue >= startTime && itemAlias.NextIssue <= Filter.EndDateIssue);
            }

            if (Filter.ContainsDateBirthPeriod)
            {
                if (Filter.StartDateBirth.Month <= Filter.EndDateBirth.Month)
                {
                    var projection = Projections.SqlFunction(
                        new SQLFunctionTemplate(NHibernateUtil.DateTime,
                                                "(DATE_FORMAT(?1,'%m%d%h%i') between DATE_FORMAT(?2,'%m%d%h%i') and DATE_FORMAT(?3,'%m%d%h%i'))"),
                        NHibernateUtil.DateTime,
                        Projections.Property(() => employeeAlias.BirthDate),
                        Projections.Constant(Filter.StartDateBirth),
                        Projections.Constant(Filter.EndDateBirth)
                        );
                    employees.Where(x => x.BirthDate != null).And(Restrictions.Eq(projection, true));
                }
                else
                {
                    //когда в период попадает переход между годами
                    var projection = Projections.SqlFunction(
                        new SQLFunctionTemplate(NHibernateUtil.DateTime,
                                                "(DATE_FORMAT(?1,'%m%d%h%i') between DATE_FORMAT(?2,'%m%d%h%i') and DATE_FORMAT(?4,'%m%d%h%i') " +
                                                "OR DATE_FORMAT(?1,'%m%d%h%i') between DATE_FORMAT(?5,'%m%d%h%i') and DATE_FORMAT(?3,'%m%d%h%i'))"),
                        NHibernateUtil.DateTime,
                        Projections.Property(() => employeeAlias.BirthDate),
                        Projections.Constant(Filter.StartDateBirth),
                        Projections.Constant(Filter.EndDateBirth),
                        Projections.Constant(new DateTime(1, 12, 31)),
                        Projections.Constant(new DateTime(1, 1, 1))
                        );
                    employees.Where(x => x.BirthDate != null).And(Restrictions.Eq(projection, true));
                }
            }

            switch (Filter.IsueType)
            {
            case (AskIssueType.Personal):
                employees
                .JoinAlias(() => itemAlias.ProtectionTools, () => toolsAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                .JoinAlias(() => toolsAlias.Type, () => typesAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                .Where(() => typesAlias.IssueType == IssueType.Personal);
                break;

            case (AskIssueType.Сollective):
                employees
                .JoinAlias(() => itemAlias.ProtectionTools, () => toolsAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                .JoinAlias(() => toolsAlias.Type, () => typesAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                .Where(() => typesAlias.IssueType == IssueType.Collective);
                break;
            }

            employees
            .Where(GetSearchCriterion(
                       () => employeeAlias.Id,
                       () => employeeAlias.CardNumber,
                       () => employeeAlias.PersonnelNumber,
                       () => employeeAlias.LastName,
                       () => employeeAlias.FirstName,
                       () => employeeAlias.Patronymic,
                       () => employeeAlias.PhoneNumber,
                       () => postAlias.Name,
                       () => subdivisionAlias.Name
                       ))
            .JoinAlias(() => employeeAlias.Post, () => postAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
            .JoinAlias(() => employeeAlias.Subdivision, () => subdivisionAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
            .SelectList(list => list
                        .SelectGroup(x => x.Id).WithAlias(() => resultAlias.Id)
                        .Select(x => x.CardNumber).WithAlias(() => resultAlias.CardNumber)
                        .Select(x => x.PersonnelNumber).WithAlias(() => resultAlias.PersonnelNumber)
                        .Select(x => x.FirstName).WithAlias(() => resultAlias.FirstName)
                        .Select(x => x.LastName).WithAlias(() => resultAlias.LastName)
                        .Select(x => x.Patronymic).WithAlias(() => resultAlias.Patronymic)
                        .Select(x => x.DismissDate).WithAlias(() => resultAlias.DismissDate)
                        .Select(x => x.PhoneNumber).WithAlias(() => resultAlias.Phone)
                        .Select(x => x.LkRegistered).WithAlias(() => resultAlias.LkRegistered)
                        .SelectCount(() => itemAlias.Id).WithAlias(() => resultAlias.IssueCount)
                        .Select(() => postAlias.Name).WithAlias(() => resultAlias.Post)
                        .Select(() => subdivisionAlias.Name).WithAlias(() => resultAlias.Subdivision)
                        .Select(x => x.BirthDate).WithAlias(() => resultAlias.BirthDate)
                        );
            if (Filter.ContainsDateBirthPeriod)
            {
                if (Filter.StartDateBirth.Month <= Filter.EndDateBirth.Month)
                {
                    employees = employees
                                .OrderBy(() => employeeAlias.BirthDate.Value.Month).Asc;
                }
                else
                {
                    employees = employees
                                .OrderBy(() => employeeAlias.BirthDate.Value.Month).Desc;
                }
                employees = employees
                            .ThenBy(() => employeeAlias.BirthDate.Value.Day).Asc
                            .ThenBy(() => employeeAlias.LastName).Asc
                            .ThenBy(() => employeeAlias.FirstName).Asc
                            .ThenBy(() => employeeAlias.Patronymic).Asc;
            }
            else
            {
                employees = employees.OrderBy(() => employeeAlias.LastName).Asc
                            .ThenBy(() => employeeAlias.FirstName).Asc
                            .ThenBy(() => employeeAlias.Patronymic).Asc;
            }

            return(employees.TransformUsing(Transformers.AliasToBean <EmployeeNotificationJournalNode>()));
        }
Esempio n. 19
0
        public void UpdateOperations_IssuingMultipleRows_TwoNomenclatureSameNeedsTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var sizeType   = new SizeType();
                var heightType = new SizeType();
                uow.Save(sizeType);
                uow.Save(heightType);

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

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

                var size = new Size {
                    SizeType = sizeType
                };
                var height = new Size {
                    SizeType = heightType
                };
                uow.Save(size);
                uow.Save(height);

                var position1 = new StockPosition(nomenclature, 0, size, height);

                var nomenclature2 = new Nomenclature {
                    Type = nomenclatureType
                };
                uow.Save(nomenclature2);

                var position2 = new StockPosition(nomenclature2, 0, size, height);

                var protectionTools = new ProtectionTools {
                    Name = "СИЗ для тестирования"
                };
                protectionTools.AddNomeclature(nomenclature);
                protectionTools.AddNomeclature(nomenclature2);
                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);
                uow.Save(employee);
                uow.Commit();

                var employeeSize = new EmployeeSize {
                    Size = size, SizeType = sizeType, Employee = employee
                };
                var employeeHeight = new EmployeeSize {
                    Size = height, SizeType = heightType, Employee = employee
                };

                employee.Sizes.Add(employeeSize);
                employee.Sizes.Add(employeeHeight);

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense {
                    Operation = ExpenseOperations.Employee,
                    Warehouse = warehouse,
                    Employee  = employee,
                    Date      = new DateTime(2018, 10, 22)
                };
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                var baseParameters = Substitute.For <BaseParameters>();
                baseParameters.ColDayAheadOfShedule.Returns(0);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();

                //Тут ожидаем предложение перенести дату использование второй номенклатуры на год.
                ask.ReceivedWithAnyArgs().Question(String.Empty);

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 10, 22))
                            );
            }
        }
Esempio n. 20
0
        public void HandleDeleteEmployeeVacation_RecalculateDatesAndNextIssueTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            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.Month;
                normItem.PeriodCount = 2;
                uow.Save(norm);

                var employee = new EmployeeCard();

                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, 3, 1);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

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

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime      = new DateTime(2019, 1, 1);
                expenseOp.ExpiryByNorm       = new DateTime(2019, 4, 1);
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = nomenclature;
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.NormItem           = normItem;
                expenseOp.Issued             = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                uow.Save(expenseOp);
                uow.Commit();

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

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultOp = uow2.GetById <EmployeeIssueOperation>(expenseOp.Id);
                    Assert.That(resultOp.ExpiryByNorm, Is.EqualTo(new DateTime(2019, 3, 1)));
                }
            }
        }
        public void BestChoise_SelfNomenclatureFirstTest()
        {
            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()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var sizeType = new SizeType();
                uow.Save(sizeType);

                var nomenclatureType = new ItemsType {
                    Name     = "Обувь",
                    Category = ItemTypeCategory.wear,
                    SizeType = sizeType
                };
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature {
                    Type = nomenclatureType,
                    Sex  = ClothesSex.Men,
                };
                uow.Save(nomenclature);

                var nomenclature2 = new Nomenclature {
                    Type = nomenclatureType,
                    Sex  = ClothesSex.Men,
                };
                uow.Save(nomenclature2);

                var protectionTools = new ProtectionTools {
                    Name = "Номенклатура нормы"
                };
                protectionTools.AddNomeclature(nomenclature);

                var protectionTools2 = new ProtectionTools {
                    Name = "Номенклатура нормы_2"
                };
                protectionTools2.AddNomeclature(nomenclature2);

                protectionTools.AddAnalog(protectionTools2);
                protectionTools2.AddAnalog(protectionTools);
                uow.Save(protectionTools);
                uow.Save(protectionTools2);

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

                var normItem2 = norm.AddItem(protectionTools2);
                normItem2.Amount      = 1;
                normItem2.NormPeriod  = NormPeriodType.Year;
                normItem2.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                employee.Sex = Sex.M;
                Assert.That(employee.WorkwearItems.Count, Is.EqualTo(2));
                uow.Save(employee);
                uow.Commit();

                var size = new Size {
                    SizeType = sizeType
                };
                uow.Save(size);
                var employeeSize = new EmployeeSize {
                    SizeType = sizeType, Size = size, Employee = employee
                };
                uow.Save(employeeSize);
                employee.Sizes.Add(employeeSize);

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2020, 07, 20),
                    Operation = IncomeOperations.Enter
                };

                var incomeItem1 = income.AddItem(nomenclature);

                incomeItem1.Amount   = 1;
                incomeItem1.WearSize = size;

                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount   = 2;
                incomeItem2.WearSize = size;

                income.UpdateOperations(uow, ask);
                uow.Save(income);
                uow.Commit();
                Assert.That(uow.GetAll <WarehouseOperation>().Count(), Is.EqualTo(2));

                employee.FillWearInStockInfo(uow, baseParameters, warehouse, new DateTime(2020, 07, 22));
                var item1 = employee.WorkwearItems.FirstOrDefault(x => x.ActiveNormItem == normItem);
                var item2 = employee.WorkwearItems.FirstOrDefault(x => x.ActiveNormItem == normItem2);
                Assert.That(item1.BestChoiceInStock.First().Nomenclature.Id, Is.EqualTo(nomenclature.Id));
                Assert.That(item1.BestChoiceInStock.Count(), Is.EqualTo(2));
                Assert.That(item2.BestChoiceInStock.First().Nomenclature.Id, Is.EqualTo(nomenclature2.Id));
                Assert.That(item2.BestChoiceInStock.Count(), Is.EqualTo(2));
            }
        }
Esempio n. 22
0
        public void IssueAndCreateIssuanceSheetTest()
        {
            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()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var sizeType   = new SizeType();
                var heightType = new SizeType();
                uow.Save(sizeType);
                uow.Save(heightType);

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

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

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

                var size = new Size {
                    SizeType = sizeType
                };
                var height = new Size {
                    SizeType = heightType
                };
                uow.Save(size);
                uow.Save(height);

                var position1 = new StockPosition(nomenclature, 0, size, height);

                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);
                uow.Save(employee);
                uow.Commit();

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense {
                    Operation = ExpenseOperations.Employee,
                    Warehouse = warehouse,
                    Employee  = employee,
                    Date      = new DateTime(2018, 10, 22)
                };
                var expenseItem = expense.AddItem(position1, 1);

                expense.CreateIssuanceSheet(null);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                expense.UpdateIssuanceSheet();
                uow.Save(expense.IssuanceSheet);
                uow.Save(expense);
                uow.Commit();
                expense.UpdateEmployeeWearItems();
                uow.Commit();

                Assert.That(expense.IssuanceSheet, Is.Not.Null);
                var issuanceItem = expense.IssuanceSheet.Items.First();
                Assert.That(issuanceItem.ExpenseItem, Is.EqualTo(expenseItem));
            }
        }
Esempio n. 23
0
        public void CreateAndResaveDocWithWriteoff()
        {
            NewSessionWithSameDB();

            var navigation      = Substitute.For <INavigationManager>();
            var validator       = new ValidatorForTests();
            var userService     = Substitute.For <IUserService>();
            var userRepository  = Substitute.For <UserRepository>();
            var interactive     = Substitute.For <IInteractiveService>();
            var commonMessages  = Substitute.For <CommonMessages>(interactive);
            var featuresService = Substitute.For <FeaturesService>();
            var baseParameters  = Substitute.For <BaseParameters>();
            var sizeService     = Substitute.For <SizeService>();
            var deleteService   = Substitute.For <IDeleteEntityService>();

            var stockRepository = new StockRepository();

            var builder = new ContainerBuilder();

            builder.RegisterType <ExpenseDocItemsEmployeeViewModel>().AsSelf();
            builder.Register(x => featuresService).As <FeaturesService>();
            builder.Register(x => navigation).As <INavigationManager>();
            builder.Register(x => sizeService).As <SizeService>();
            builder.Register(x => deleteService).As <IDeleteEntityService>();
            builder.Register(x => baseParameters).As <BaseParameters>();
            builder.Register(x => Substitute.For <IUserService>()).As <IUserService>();
            var container = builder.Build();

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot())
            {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var user = new UserBase();
                uow.Save(user);
                userService.GetCurrentUser(Arg.Any <IUnitOfWork>()).Returns(user);

                var itemType = new ItemsType {
                    Name = "Тип"
                };
                uow.Save(itemType);

                var nomenclature = new Nomenclature {
                    Type = itemType
                };
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools {
                    Name = "Тестовый СИЗ",
                    Type = itemType
                };
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

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

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

                var warehouseOperation = new WarehouseOperation {
                    Amount           = 10,
                    ReceiptWarehouse = warehouse,
                    Nomenclature     = nomenclature,
                };
                uow.Save(warehouseOperation);

                uow.Commit();

                //Создаем предыдущую выдачу которая должна быть списана.
                using (var vmCreateLastIssue = new ExpenseEmployeeViewModel(
                           EntityUoWBuilder.ForCreate(),
                           UnitOfWorkFactory,
                           navigation,
                           container.BeginLifetimeScope(),
                           validator,
                           userService,
                           userRepository,
                           interactive,
                           stockRepository,
                           commonMessages,
                           featuresService,
                           baseParameters))
                {
                    vmCreateLastIssue.Entity.Date      = new DateTime(2022, 04, 1);
                    vmCreateLastIssue.Entity.Warehouse = vmCreateLastIssue.UoW.GetById <Warehouse>(warehouse.Id);
                    vmCreateLastIssue.Entity.Employee  = vmCreateLastIssue.UoW.GetById <EmployeeCard>(employee.Id);

                    Assert.That(vmCreateLastIssue.Entity.Items.Count, Is.EqualTo(1));
                    var itemLast = vmCreateLastIssue.Entity.Items.First();
                    itemLast.Amount = 1;
                    Assert.That(itemLast.IsEnableWriteOff, Is.False);

                    Assert.That(vmCreateLastIssue.Save(), Is.True);
                }

                //Создаем выдачу в место выданного ранее.
                int expenseIdForResave;
                using (var vmCreate = new ExpenseEmployeeViewModel(EntityUoWBuilder.ForCreate(), UnitOfWorkFactory, navigation, container.BeginLifetimeScope(), validator, userService, userRepository, interactive, stockRepository, commonMessages, featuresService, baseParameters, employee))
                {
                    vmCreate.Entity.Date      = new DateTime(2022, 04, 12);
                    vmCreate.Entity.Warehouse = vmCreate.UoW.GetById <Warehouse>(warehouse.Id);

                    Assert.That(vmCreate.Entity.Items.Count, Is.EqualTo(1));
                    var item = vmCreate.Entity.Items.First();
                    item.Amount = 1;
                    Assert.That(item.IsEnableWriteOff, Is.True);
                    //Главное в этом тесте, устанавливаем галочку что выдача идет вместе со списанием.
                    item.IsWriteOff = true;

                    Assert.That(vmCreate.Save(), Is.True);
                    expenseIdForResave = vmCreate.Entity.Id;
                }

                //Пересохраняем для проверки что это работает
                using (var vmResave = new ExpenseEmployeeViewModel(EntityUoWBuilder.ForOpen(expenseIdForResave), UnitOfWorkFactory, navigation, container.BeginLifetimeScope(), validator, userService, userRepository, interactive, stockRepository, commonMessages, featuresService, baseParameters))
                {
                    Assert.That(vmResave.Save(), Is.True);
                }
            }
        }
Esempio n. 24
0
        public static IssueGraph MakeIssueGraph(IUnitOfWork uow, EmployeeCard employee, ProtectionTools protectionTools, EmployeeIssueOperation[] unsavedOprarations = null)
        {
            if (MakeIssueGraphTestGap != null)
            {
                return(MakeIssueGraphTestGap(employee, protectionTools));
            }

            var matchedProtectionTools = protectionTools.MatchedProtectionTools;

            var issues = uow.Session.QueryOver <EmployeeIssueOperation>()
                         .Where(x => x.Employee.Id == employee.Id)
                         .Where(x => x.ProtectionTools.Id.IsIn(matchedProtectionTools.Select(n => n.Id).ToArray()))
                         .OrderBy(x => x.OperationTime).Asc
                         .List();

            if (unsavedOprarations != null)
            {
                foreach (var operation in unsavedOprarations)
                {
                    if (!issues.Any(x => x.IsSame(operation)))
                    {
                        issues.Add(operation);
                    }
                }
            }

            return(new IssueGraph(issues));
        }
        public void BestChoise_IssuingMultipleRows_TwoNomeclatureShoesTypeSameNeedsTest()
        {
            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()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var shoes = new SizeType {
                    Name = "Обувь"
                };
                uow.Save(shoes);
                var winterShoes = new SizeType {
                    Name = "Зимняя обувь"
                };
                uow.Save(winterShoes);

                var nomenclatureType = new ItemsType {
                    Name     = "Обувь",
                    Category = ItemTypeCategory.wear,
                    SizeType = shoes
                };
                uow.Save(nomenclatureType);

                var nomenclatureType2 = new ItemsType {
                    Name     = "Зимняя обувь",
                    Category = ItemTypeCategory.wear,
                    SizeType = winterShoes
                };
                uow.Save(nomenclatureType2);

                var nomenclature = new Nomenclature {
                    Type = nomenclatureType,
                    Sex  = ClothesSex.Men
                };
                uow.Save(nomenclature);

                var nomenclature2 = new Nomenclature {
                    Type = nomenclatureType2,
                    Sex  = ClothesSex.Men
                };
                uow.Save(nomenclature2);

                var nomenclature3 = new Nomenclature {
                    Type = nomenclatureType,
                    Sex  = ClothesSex.Men
                };
                uow.Save(nomenclature3);

                var protectionTools = new ProtectionTools {
                    Name = "Номеклатура нормы"
                };
                protectionTools.AddNomeclature(nomenclature);
                protectionTools.AddNomeclature(nomenclature3);

                uow.Save(protectionTools);

                var protectionTools2 = new ProtectionTools {
                    Name = "Номенклатура нормы_2"
                };
                protectionTools2.AddNomeclature(nomenclature2);
                uow.Save(protectionTools2);

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

                var normItem2 = norm.AddItem(protectionTools2);
                normItem2.Amount      = 1;
                normItem2.NormPeriod  = NormPeriodType.Year;
                normItem2.PeriodCount = 1;
                uow.Save(norm);

                var shoesSize = new Size {
                    SizeType = shoes, Name = "42"
                };
                var winterShoesSize = new Size {
                    SizeType = winterShoes, Name = "43"
                };
                uow.Save(shoesSize);
                uow.Save(winterShoesSize);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                employee.Sex = Sex.M;
                Assert.That(employee.WorkwearItems.Count, Is.GreaterThan(0));
                uow.Save(employee);
                uow.Commit();

                var employeeShoesSize = new EmployeeSize {
                    Size = shoesSize, SizeType = shoes, Employee = employee
                };
                var employeeWinterShoesSize = new EmployeeSize {
                    Size = winterShoesSize, SizeType = winterShoes, Employee = employee
                };
                uow.Save(employeeShoesSize);
                uow.Save(employeeWinterShoesSize);

                employee.Sizes.Add(employeeShoesSize);
                employee.Sizes.Add(employeeWinterShoesSize);

                var income = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2020, 07, 20),
                    Operation = IncomeOperations.Enter
                };

                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount   = 1;
                incomeItem1.WearSize = shoesSize;

                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount   = 2;
                incomeItem2.WearSize = winterShoesSize;

                var incomeItem3 = income.AddItem(nomenclature3);
                incomeItem3.Amount   = 3;
                incomeItem3.WearSize = shoesSize;

                income.UpdateOperations(uow, ask);
                uow.Save(income);
                uow.Commit();
                Assert.That(uow.GetAll <WarehouseOperation>().Count(), Is.EqualTo(3));

                employee.FillWearInStockInfo(uow, baseParameters, warehouse, new DateTime(2020, 07, 22));
                Assert.That(employee.GetUnderreceivedItems(baseParameters).Count(), Is.GreaterThan(0));

                Assert.That(employee.GetUnderreceivedItems(baseParameters).Count(), Is.EqualTo(2));

                var employeeCardItem = employee.GetUnderreceivedItems(baseParameters).First();
                Assert.That(employeeCardItem.InStock.Count(), Is.GreaterThan(0));

                var bestChoiceInStock = employeeCardItem.BestChoiceInStock;
                var bestChoiceCount   = employeeCardItem.BestChoiceInStock.Count();
                Assert.That(employeeCardItem.BestChoiceInStock.Count(), Is.GreaterThan(0));

                Assert.That(employeeCardItem.BestChoiceInStock.Count(), Is.EqualTo(2));
            }
        }