Ejemplo n.º 1
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))
                            );
            }
        }
Ejemplo n.º 2
0
        private void SetValue(
            SettingsMatchEmployeesViewModel settings,
            IUnitOfWork uow,
            EmployeeCard employee,
            SheetRowEmployee row,
            ImportedColumn <DataTypeEmployee> column)
        {
            var value    = row.CellStringValue(column.Index);
            var dataType = column.DataType;

            if (String.IsNullOrWhiteSpace(value))
            {
                return;
            }

            switch (dataType)
            {
            case DataTypeEmployee.CardKey:
                employee.CardKey = value;
                break;

            case DataTypeEmployee.PersonnelNumber:
                employee.PersonnelNumber = (settings.ConvertPersonnelNumber ?
                                            EmployeeParse.ConvertPersonnelNumber(value) : value)?.Trim();
                break;

            case DataTypeEmployee.Phone:
                employee.PhoneNumber = phoneFormatter.FormatString(value);
                break;

            case DataTypeEmployee.LastName:
                employee.LastName = value;
                break;

            case DataTypeEmployee.FirstName:
                employee.FirstName = value;
                if (employee.Sex == Sex.None)
                {
                    employee.Sex = personNames.GetSexByName(employee.FirstName);
                }
                break;

            case DataTypeEmployee.Patronymic:
                employee.Patronymic = value;
                break;

            case DataTypeEmployee.Sex:
                //Первая М английская, вторая русская.
                if (value.StartsWith("M", StringComparison.CurrentCultureIgnoreCase) ||
                    value.StartsWith("М", StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.Sex = Sex.M;
                }
                if (value.StartsWith("F", StringComparison.CurrentCultureIgnoreCase) ||
                    value.StartsWith("Ж", StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.Sex = Sex.F;
                }
                break;

            case DataTypeEmployee.Fio:
                value.SplitFullName(out var lastName, out var firstName, out var patronymic);
                if (!String.IsNullOrEmpty(lastName) && !String.Equals(employee.LastName, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.LastName = lastName;
                }
                if (!String.IsNullOrEmpty(firstName) && !String.Equals(employee.FirstName, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.FirstName = firstName;
                }
                if (!String.IsNullOrEmpty(patronymic) && !String.Equals(employee.Patronymic, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.Patronymic = patronymic;
                }
                if (employee.Sex == Sex.None && !String.IsNullOrWhiteSpace(employee.FirstName))
                {
                    employee.Sex = personNames.GetSexByName(employee.FirstName);
                }
                break;

            case DataTypeEmployee.HireDate:
                var hireDate = row.CellDateTimeValue(column.Index);
                if (hireDate != null)
                {
                    employee.HireDate = hireDate;
                }
                break;

            case DataTypeEmployee.DismissDate:
                var dismissDate = row.CellDateTimeValue(column.Index);
                if (dismissDate != null)
                {
                    employee.DismissDate = dismissDate;
                }
                break;

            case DataTypeEmployee.BirthDate:
                var birthDate = row.CellDateTimeValue(column.Index);
                if (birthDate != null)
                {
                    employee.BirthDate = birthDate;
                }
                break;

            case DataTypeEmployee.Subdivision:
            case DataTypeEmployee.Department:
            case DataTypeEmployee.Post:
                //Устанавливаем в MakeChange;
                break;

            case DataTypeEmployee.Growth:
                var height = SizeParser.ParseSize(uow, value, sizeService, CategorySizeType.Height);
                if (height is null)
                {
                    break;
                }
                var employeeHeight = employee.Sizes.FirstOrDefault(x => x.SizeType == height.SizeType);
                if (employeeHeight is null)
                {
                    employeeHeight = new EmployeeSize
                    {
                        Size = height, SizeType = height.SizeType, Employee = employee
                    };
                    employee.Sizes.Add(employeeHeight);
                }
                else
                {
                    employeeHeight.Size = height;
                }
                break;

            case DataTypeEmployee.WearSize:
                var size = SizeParser.ParseSize(uow, value, sizeService, CategorySizeType.Size);
                if (size is null)
                {
                    break;
                }
                var employeeSize = employee.Sizes.FirstOrDefault(x => x.SizeType == size.SizeType);
                if (employeeSize is null)
                {
                    employeeSize = new EmployeeSize
                    {
                        Size = size, SizeType = size.SizeType, Employee = employee
                    };
                    employee.Sizes.Add(employeeSize);
                }
                else
                {
                    employeeSize.Size = size;
                }
                break;

            case DataTypeEmployee.ShoesSize:
            {
                var shoesSize = SizeParser.ParseSize(uow, value, sizeService, CategorySizeType.Size);
                if (shoesSize is null)
                {
                    break;
                }
                var employeeShoesSize = employee.Sizes.FirstOrDefault(x => x.SizeType == shoesSize.SizeType);
                if (employeeShoesSize is null)
                {
                    employeeShoesSize = new EmployeeSize
                    {
                        Size = shoesSize, SizeType = shoesSize.SizeType, Employee = employee
                    };
                    employee.Sizes.Add(employeeShoesSize);
                }
                else
                {
                    employeeShoesSize.Size = shoesSize;
                }
            }
            break;

            default:
                throw new NotSupportedException($"Тип данных {dataType} не поддерживается.");
            }
        }
Ejemplo n.º 3
0
        public void MatchChanges(
            IProgressBarDisplayable progress,
            SettingsWorkwearItemsViewModel settings,
            CountersViewModel counters,
            IUnitOfWork uow,
            IEnumerable <SheetRowWorkwearItems> list,
            List <ImportedColumn <DataTypeWorkwearItems> > columns)
        {
            var personnelNumberColumn = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.PersonnelNumber);
            var protectionToolsColumn = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.ProtectionTools);
            var nomenclatureColumn    = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.Nomenclature);
            var issueDateColumn       = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.IssueDate);
            var countColumn           = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.Count);
            var postColumn            = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.Post);
            var subdivisionColumn     = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.Subdivision);
            var sizeAndGrowthColumn   = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.SizeAndGrowth);
            var sizeColumn            = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.Size);
            var growthColumn          = columns.FirstOrDefault(x => x.DataType == DataTypeWorkwearItems.Growth);

            progress.Start(list.Count() * 2 + 3, text: "Загрузка сотрудников");
            var personnelNumbers = list.Select(x => GetPersonalNumber(settings, x, personnelNumberColumn.Index))
                                   .Where(x => !String.IsNullOrWhiteSpace(x)).Distinct().ToArray();

            var employees = uow.Session.QueryOver <EmployeeCard>()
                            .Where(x => x.PersonnelNumber.IsIn(personnelNumbers))
                            .Fetch(SelectMode.Fetch, x => x.WorkwearItems)
                            .List();

            foreach (var row in list)
            {
                progress.Add(text: "Сопоставление");
                row.Date = ParseDateOrNull(row.CellStringValue(issueDateColumn.Index));
                if (row.Date == null)
                {
                    row.ProgramSkipped = true;
                    row.AddColumnChange(issueDateColumn, ChangeType.ParseError);
                    continue;
                }

                if (row.CellIntValue(countColumn.Index) == null)
                {
                    row.ProgramSkipped = true;
                    row.AddColumnChange(countColumn, ChangeType.ParseError);
                    continue;
                }

                row.Employee = employees.FirstOrDefault(x => x.PersonnelNumber == GetPersonalNumber(settings, row, personnelNumberColumn.Index));
                if (row.Employee == null)
                {
                    logger.Warn(
                        $"Не найден сотрудник в табельным номером [{GetPersonalNumber(settings, row, personnelNumberColumn.Index)}]. Пропускаем.");
                    row.ProgramSkipped = true;
                    row.AddColumnChange(personnelNumberColumn, ChangeType.NotFound);
                    counters.AddCount(CountersWorkwearItems.EmployeeNotFound);
                    continue;
                }

                var protectionToolName = row.CellStringValue(protectionToolsColumn.Index);
                row.WorkwearItem = row.Employee.WorkwearItems.FirstOrDefault(x => x.ProtectionTools.Name == protectionToolName);
                if (row.WorkwearItem == null && postColumn != null && subdivisionColumn != null)
                {
                    if (!TryAddNorm(uow, row.CellStringValue(postColumn.Index),
                                    row.CellStringValue(subdivisionColumn.Index), row.Employee))
                    {
                        row.AddColumnChange(postColumn, ChangeType.NotFound);
                        row.AddColumnChange(subdivisionColumn, ChangeType.NotFound);
                    }
                    else
                    {
                        counters.AddCount(CountersWorkwearItems.EmployeesAddNorm);
                    }
                }

                if (row.WorkwearItem != null)
                {
                    continue;
                }
                row.ProgramSkipped = true;
                row.AddColumnChange(protectionToolsColumn, ChangeType.NotFound);
            }

            progress.Add(text: "Загрузка номенклатуры");
            var nomenclatureTypes = new NomenclatureTypes(uow, sizeService, true);
            var nomenclatureNames =
                list.Select(x => x.CellStringValue(nomenclatureColumn.Index)).Where(x => x != null).Distinct().ToArray();
            var nomenclatures = nomenclatureRepository.GetNomenclatureByName(uow, nomenclatureNames);

            progress.Add(text: "Загрузка операций выдачи");
            var dates = list
                        .Select(x => x.Date)
                        .Where(x => x != null)
                        .Select(x => x.Value);
            var startDate   = dates.Min();
            var endDate     = dates.Max();
            var employeeIds = list.Where(x => x.Employee != null)
                              .Select(x => x.Employee.Id).Distinct().ToArray();
            var operations = uow.Session.QueryOver <EmployeeIssueOperation>()
                             .Where(x => x.Employee.Id.IsIn(employeeIds))
                             .Where(x => x.OperationTime >= startDate)
                             .Where(x => x.OperationTime < endDate.AddDays(1))
                             .List()
                             .GroupBy(x => x.Employee);

            foreach (var row in list)
            {
                progress.Add(text: "Обработка операций выдачи");
                if (row.Skipped)
                {
                    continue;
                }
                var nomenclatureName = row.CellStringValue(nomenclatureColumn.Index);
                if (String.IsNullOrWhiteSpace(nomenclatureName))
                {
                    row.AddColumnChange(nomenclatureColumn, ChangeType.NotFound);
                    continue;
                }

                var nomenclature =
                    UsedNomeclature.FirstOrDefault(x => String.Equals(x.Name, nomenclatureName, StringComparison.CurrentCultureIgnoreCase));
                if (nomenclature == null)
                {
                    nomenclature =
                        nomenclatures.FirstOrDefault(x => String.Equals(x.Name, nomenclatureName, StringComparison.CurrentCultureIgnoreCase));
                    if (nomenclature == null)
                    {
                        nomenclature = new Nomenclature {
                            Name    = nomenclatureName,
                            Type    = row.WorkwearItem.ProtectionTools.Type,
                            Comment = "Создана при импорте выдачи из Excel",
                        };
                        nomenclature.Sex = nomenclatureTypes.ParseSex(nomenclature.Name) ?? ClothesSex.Universal;
                        row.WorkwearItem.ProtectionTools.AddNomeclature(nomenclature);
                    }
                    UsedNomeclature.Add(nomenclature);
                }

                row.Operation = operations.FirstOrDefault(group => group.Key == row.Employee)
                                ?.FirstOrDefault(x => x.OperationTime.Date == row.Date && x.Nomenclature == nomenclature);

                if (row.Operation != null)
                {
                    //TODO Обновление операций не реализовано
                    continue;
                }

                if (row.Operation != null)
                {
                    continue;
                }
                {
                    var count       = row.CellIntValue(countColumn.Index).Value;
                    var expenseDate = row.WorkwearItem.ActiveNormItem.CalculateExpireDate(row.Date.Value, count);
                    row.Operation = new EmployeeIssueOperation {
                        OperationTime    = row.Date.Value,
                        Employee         = row.Employee,
                        Issued           = count,
                        Nomenclature     = nomenclature,
                        AutoWriteoffDate = expenseDate,
                        ExpiryByNorm     = expenseDate,
                        NormItem         = row.WorkwearItem.ActiveNormItem,
                        ProtectionTools  = row.WorkwearItem.ProtectionTools,
                        Returned         = 0,
                        StartOfUse       = row.Date,
                        UseAutoWriteoff  = expenseDate != null,
                    };
                    //Обрабатываем размер.
                    if (TryParseSizeAndGrowth(uow, row, columns, out var sizeAndGrowth))
                    {
                        row.Operation.WearSize = sizeAndGrowth.Size;
                        row.Operation.Height   = sizeAndGrowth.Growth;
                        var sizeOk   = nomenclature.Type.SizeType == sizeAndGrowth.Size.SizeType;
                        var growthOk = nomenclature.Type.HeightType == sizeAndGrowth.Growth.SizeType;
                        if (sizeAndGrowthColumn != null)
                        {
                            row.ChangedColumns.Add(sizeAndGrowthColumn, new ChangeState(sizeOk && growthOk ? ChangeType.NewEntity : ChangeType.ParseError));
                        }
                        if (sizeColumn != null)
                        {
                            row.ChangedColumns.Add(sizeColumn, new ChangeState(sizeOk ? ChangeType.NewEntity : ChangeType.ParseError));
                        }
                        if (growthColumn != null)
                        {
                            row.ChangedColumns.Add(growthColumn, new ChangeState(growthOk ? ChangeType.NewEntity : ChangeType.ParseError));
                        }
                    }
                    //Проставляем размер в сотрудника.
                    if (row.Operation.Height != null)
                    {
                        var employeeSize = row.Employee.Sizes.FirstOrDefault(x => x.SizeType == row.Operation.Height.SizeType);
                        if (employeeSize is null)
                        {
                            employeeSize = new EmployeeSize
                            {
                                Size = row.Operation.Height, SizeType = row.Operation.Height.SizeType, Employee = row.Employee
                            };
                            row.Employee.Sizes.Add(employeeSize);
                        }
                        else
                        {
                            employeeSize.Size = row.Operation.Height;
                        }
                        ChangedEmployees.Add(row.Employee);
                        counters.AddCount(CountersWorkwearItems.EmployeesSetSize);
                    }
                    if (row.Operation.WearSize != null)
                    {
                        var employeeSize = row.Employee.Sizes.FirstOrDefault(x => x.SizeType == row.Operation.WearSize.SizeType);
                        if (employeeSize is null)
                        {
                            employeeSize = new EmployeeSize
                            {
                                Size = row.Operation.WearSize, SizeType = row.Operation.WearSize.SizeType, Employee = row.Employee
                            };
                            row.Employee.Sizes.Add(employeeSize);
                        }
                        else
                        {
                            employeeSize.Size = row.Operation.WearSize;
                        }
                        ChangedEmployees.Add(row.Employee);
                        counters.AddCount(CountersWorkwearItems.EmployeesSetSize);
                    }
                    var toSetChangeColumns = columns.Where(
                        x => x.DataType != DataTypeWorkwearItems.Unknown &&
                        x.DataType != DataTypeWorkwearItems.SizeAndGrowth &&
                        x.DataType != DataTypeWorkwearItems.Size &&
                        x.DataType != DataTypeWorkwearItems.Growth
                        );
                    foreach (var column in toSetChangeColumns)
                    {
                        if (!row.ChangedColumns.ContainsKey(column))
                        {
                            row.ChangedColumns.Add(column, new ChangeState(ChangeType.NewEntity));
                        }
                    }
                }
            }
            progress.Close();
        }
        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));
            }
        }
        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));
            }
        }
        public void BestChoise_IssuingMultipleRows_TwoNomeclatureWearTypeSameNeedsTest()
        {
            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 {
                    Name = "Тестовый тип", CategorySizeType = CategorySizeType.Size
                };
                var heightType = new SizeType {
                    Name = "Тестовый рост", CategorySizeType = CategorySizeType.Height
                };
                uow.Save(sizeType);
                uow.Save(heightType);

                var nomenclatureType = new ItemsType {
                    Name       = "Тестовый тип номенклатуры",
                    Category   = ItemTypeCategory.wear,
                    SizeType   = sizeType,
                    HeightType = heightType
                };
                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);
                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 size = new Size {
                    Name = "50", SizeType = sizeType
                };
                var height = new Size {
                    Name = "176", SizeType = heightType
                };
                uow.Save(size);
                uow.Save(height);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                employee.Sex = Sex.M;
                Assert.That(employee.WorkwearItems.Count, Is.GreaterThan(0));
                uow.Save(employee);
                var employeeSize = new EmployeeSize {
                    Size = size, SizeType = sizeType, Employee = employee
                };
                var employeeHeight = new EmployeeSize {
                    Size = height, SizeType = heightType, Employee = employee
                };
                uow.Save(employeeSize);
                uow.Save(employeeHeight);
                employee.Sizes.Add(employeeSize);
                employee.Sizes.Add(employeeHeight);
                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;
                incomeItem1.WearSize = size;
                incomeItem1.Height   = height;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount   = 5;
                incomeItem2.WearSize = size;
                incomeItem2.Height   = height;

                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();
                var employeeCardItemCount = employee.GetUnderreceivedItems(baseParameters).Count();

                var inStock = employeeCardItem.InStock;

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

                var bestChoice = employeeCardItem.BestChoiceInStock.First();

                Assert.That(bestChoice.Nomenclature, Is.EqualTo(nomenclature));
            }
        }