Exemplo n.º 1
0
        public IResult <IChileProductDetailReturn> GetChileProductDetail(string keyValue)
        {
            if (keyValue == null)
            {
                throw new ArgumentNullException("keyValue");
            }

            var chileProductKeyResult = KeyParserHelper.ParseResult <IChileProductKey>(keyValue);

            if (!chileProductKeyResult.Success)
            {
                return(chileProductKeyResult.ConvertTo <IChileProductDetailReturn>());
            }
            var predicate = new ChileProductKey(chileProductKeyResult.ResultingObject).FindByPredicate;
            var selector  = ProductProjectors.SelectChileProductDetail();

            var chileProduct = _productUnitOfWork.ChileProductRepository.Filter(predicate).AsExpandable().Select(selector).FirstOrDefault();

            if (chileProduct == null)
            {
                return(new FailureResult <IChileProductDetailReturn>(null, string.Format(UserMessages.ChileProductNotFound, new ChileProductKey(chileProductKeyResult.ResultingObject).KeyValue)));
            }

            return(new SuccessResult <IChileProductDetailReturn>(chileProduct));
        }
Exemplo n.º 2
0
        private void Serialize(ChileProductKey chileProductKey, CustomerKey customerKey, out int prodId, out string companyIA)
        {
            var chileProduct = UnitOfWork.ChileProductRepository.FindByKey(chileProductKey, c => c.Product);
            var customer     = UnitOfWork.CustomerRepository.FindByKey(customerKey,
                                                                       c => c.Company,
                                                                       c => c.ProductSpecs);

            var pId      = prodId = int.Parse(chileProduct.Product.ProductCode);
            var cIA      = companyIA = customer.Company.Name;
            var existing = OldContext.SerializedCustomerProdSpecs.FirstOrDefault(s => s.ProdID == pId && s.Company_IA == cIA);

            var specs = customer.ProductSpecs.Where(s => s.ChileProductId == chileProduct.Id).ToList();

            if (!specs.Any())
            {
                if (existing != null)
                {
                    OldContext.SerializedCustomerProdSpecs.DeleteObject(existing);
                }
            }
            else
            {
                if (existing == null)
                {
                    existing = new SerializedCustomerProdSpecs
                    {
                        ProdID     = prodId,
                        Company_IA = companyIA
                    };
                    OldContext.SerializedCustomerProdSpecs.AddObject(existing);
                }

                existing.Serialized = SerializableCustomerSpec.Serialize(specs);
            }
        }
Exemplo n.º 3
0
        public void Returns_non_successful_result_if_any_Quantity_is_less_than_or_equal_to_0()
        {
            //Arrange
            const int quantity = 0;
            var       orderKey = CreateKeyFromOrder(TestHelper.CreateObjectGraphAndInsertIntoDatabase <TOrder>(InitializeOrder, o => o.InventoryPickOrder.Items = new List <InventoryPickOrderItem>
            {
                TestHelper.CreateObjectGraph <InventoryPickOrderItem>(i => i.InventoryPickOrder = null),
                TestHelper.CreateObjectGraph <InventoryPickOrderItem>(i => i.InventoryPickOrder = null),
                TestHelper.CreateObjectGraph <InventoryPickOrderItem>(i => i.InventoryPickOrder = null)
            }));
            var chileProductKey     = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>()).KeyValue;
            var packagingProductKey = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>()).KeyValue;
            var treatmentKey        = new InventoryTreatmentKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryTreatment>()).KeyValue;

            Assert.IsNotEmpty(RVCUnitOfWork.InventoryPickOrderItemRepository.All());

            //Act
            var result = GetResult(new SetInventoryPickOrderParameters(orderKey.KeyValue)
            {
                UserToken = TestUser.UserName,
                InventoryPickOrderItems = new List <ISetInventoryPickOrderItemParameters>
                {
                    new SetInventoryPickOrderItemParameters
                    {
                        ProductKey   = chileProductKey,
                        PackagingKey = packagingProductKey,
                        TreatmentKey = treatmentKey,
                        Quantity     = quantity
                    }
                }
            });

            //Assert
            result.AssertNotSuccess();
        }
            public void Returns_non_succesful_result_if_any_Items_received_have_a_Quantity_not_greater_than_0()
            {
                //Arrange
                var chileProductKey = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var dehydratorKey   = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                var packagingProductKey0  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey0 = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = new DateTime(2012, 3, 29),
                    ChileProductKey = chileProductKey,
                    SupplierKey     = dehydratorKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 0,
                            Variety             = "variety",
                            PackagingProductKey = packagingProductKey0.KeyValue,
                            LocationKey         = warehouseLocationKey0.KeyValue
                        }
                    }
                });

                //Assert
                result.AssertNotSuccess(UserMessages.QuantityNotGreaterThanZero);
            }
        internal IResult Execute(CustomerKey customerKey, ChileProductKey chileProductKey, string code)
        {
            var customerProductCodeKey = new CustomerProductCodeKey(customerKey, chileProductKey);
            var productCode            = _salesUnitOfWork.CustomerProductCodeRepository.FindByKey(customerProductCodeKey);

            if (productCode == null)
            {
                var customer = _salesUnitOfWork.CustomerRepository.FindByKey(customerKey);
                if (customer == null)
                {
                    return(new InvalidResult(string.Format(UserMessages.CustomerNotFound, customerKey)));
                }

                var chileProduct = _salesUnitOfWork.ChileProductRepository.FindByKey(chileProductKey);
                if (chileProduct == null)
                {
                    return(new InvalidResult(string.Format(UserMessages.ChileProductNotFound, chileProductKey)));
                }

                productCode = _salesUnitOfWork.CustomerProductCodeRepository.Add(new CustomerProductCode
                {
                    CustomerId     = customer.Id,
                    ChileProductId = chileProduct.Id
                });
            }

            productCode.Code = code;

            return(new SuccessResult());
        }
Exemplo n.º 6
0
        private IResult <Lot> CreateChileLot(DateTime timeStamp, IEmployeeKey employeeKey, ReceiveInventoryParameters parameters)
        {
            var chileProductKey = ChileProductKey.FromProductKey(parameters.ProductKey);
            var chileProduct    = _inventoryUnitOfWork.ChileProductRepository.FindByKey(chileProductKey);

            if (chileProduct == null)
            {
                return(new InvalidResult <Lot>(null, string.Format(UserMessages.ChileProductNotFound, chileProductKey.KeyValue)));
            }

            var chileLotResult = new CreateNewChileLotCommand(_inventoryUnitOfWork).Execute(new CreateNewChileLotCommandParameters
            {
                EmployeeKey = employeeKey,
                TimeStamp   = timeStamp,

                ChileProductKey = chileProduct,

                LotType     = parameters.Parameters.LotType,
                LotDate     = parameters.Parameters.LotDate?.Date ?? timeStamp,
                LotSequence = parameters.Parameters.LotSequence,

                PackagingReceivedKey = parameters.PackagingReceivedKey,

                SetLotProductionStatus = LotProductionStatus.Produced,
                SetLotQualityStatus    = LotQualityStatus.Released,

                VendorKey           = parameters.VendorKey,
                PurchaseOrderNumber = parameters.Parameters.PurchaseOrderNumber,
                ShipperNumber       = parameters.Parameters.ShipperNumber
            });

            return(!chileLotResult.Success ? chileLotResult.ConvertTo <Lot>() : new SuccessResult <Lot>(chileLotResult.ResultingObject.Lot));
        }
        private IResult ValidateModifyPickedInventoryItems(InventoryShipmentOrder order, IEnumerable <ModifyPickedInventoryItemParameters> items)
        {
            var validator  = PickedInventoryValidator.ForInterWarehouseOrder(order.SourceFacility);
            var orderItems = order.InventoryPickOrder.Items.ToDictionary(i => i.ToInventoryPickOrderItemKey());

            foreach (var item in items)
            {
                InventoryPickOrderItem orderItem = null;
                if (item.OrderItemKey != null && !orderItems.TryGetValue(item.OrderItemKey, out orderItem))
                {
                    return(new InvalidResult(string.Format(UserMessages.CannotPickForOrderItem_DoesNotExist, item.OrderItemKey)));
                }

                if (item.NewQuantity > item.OriginalQuantity)
                {
                    Dictionary <string, Inventory> inventory;
                    var validResult = validator.ValidateItems(_inventoryShipmentUnitOfWork.InventoryRepository, new[] { item.InventoryKey }, out inventory);

                    IChileProductKey chileProduct;
                    if (orderItem != null)
                    {
                        chileProduct = ChileProductKey.FromProductKey(orderItem.Product);
                    }
                    else
                    {
                        var lotKey = inventory.Single().Value.ToLotKey();
                        chileProduct = _inventoryShipmentUnitOfWork.ChileLotRepository.FindByKey(lotKey);
                        if (chileProduct == null)
                        {
                            return(new InvalidResult(string.Format(UserMessages.ChileLotNotFound, lotKey)));
                        }
                    }

                    IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec;
                    IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec;
                    var specResult = new GetProductSpecCommand(_inventoryShipmentUnitOfWork).Execute(chileProduct, orderItem == null ? null : orderItem.Customer, out productSpec, out customerSpec);
                    if (!specResult.Success)
                    {
                        return(specResult);
                    }

                    var inventoryItem  = inventory.Values.Single();
                    var context        = new PickingValidatorContext(productSpec, customerSpec, null, null, orderItem == null ? null : orderItem.Customer);
                    var pickable       = new PickingValidator(inventoryItem.Lot);
                    var pickableResult = pickable.ValidForPicking(context);

                    if (!validResult.Success || !pickableResult.Success)
                    {
                        return(new InvalidResult(new[] { validResult, pickableResult }.CombineMessages()));
                    }
                }
            }

            return(new SuccessResult());
        }
            public void Creates_DehydratedMaterialsReceived_record_as_expected_on_success()
            {
                //Arrange
                var          expectedLotDate         = new DateTime(2012, 3, 29);
                const int    expectedLotDateSequence = 1;
                const int    expectedLotTypeId       = (int)LotTypeEnum.DeHydrated;
                const string expectedLoad            = "123";
                const string expectedPurchaseOrder   = "MLAH!";
                const string expectedShipperNumber   = "1029384756";

                var chileProductKey     = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var locationKey         = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var supplierKey         = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    ChileMaterialsReceivedType = ChileMaterialsReceivedType.Dehydrated,
                    UserToken       = TestUser.UserName,
                    DateReceived    = expectedLotDate,
                    ChileProductKey = chileProductKey,
                    SupplierKey     = supplierKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = expectedLoad,
                    PurchaseOrder   = expectedPurchaseOrder,
                    ShipperNumber   = expectedShipperNumber,
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey,
                            LocationKey         = locationKey,
                            Variety             = "Variety"
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var received = RVCUnitOfWork.ChileMaterialsReceivedRepository.Filter(d => true, d => d.ChileLot.Lot, d => d.Items).Single();

                Assert.AreEqual(expectedLotDate, received.LotDateCreated);
                Assert.AreEqual(expectedLotDateSequence, received.LotDateSequence);
                Assert.AreEqual(expectedLotTypeId, received.LotTypeId);

                Assert.AreEqual(expectedLoad, received.LoadNumber);
                Assert.AreEqual(expectedPurchaseOrder, received.ChileLot.Lot.PurchaseOrderNumber);
                Assert.AreEqual(expectedShipperNumber, received.ChileLot.Lot.ShipperNumber);

                Assert.IsNotNull(received.ChileLot);
                Assert.IsNotNull(received.Items.SingleOrDefault());
            }
Exemplo n.º 9
0
        public void Will_successfully_create_an_InventoryPickOrderItem_with_null_Treatment()
        {
            //Arrange
            var order    = TestHelper.CreateObjectGraphAndInsertIntoDatabase <TOrder>(InitializeOrder, o => GetPickOrderFromOrder(o).Items = null);
            var orderKey = CreateKeyFromOrder(order);

            TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryPickOrderItem>(i => i.InventoryPickOrder = null, i => ConstrainItemToOrder(i, GetPickOrderFromOrder(order)));

            var       chileProductKey0     = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>()).KeyValue;
            var       packagingProductKey0 = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>()).KeyValue;
            const int expectedQuantity0    = 10;

            var       chileProductKey1     = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>()).KeyValue;
            var       packagingProductKey1 = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>()).KeyValue;
            const int expectedQuantity1    = 20;

            //Act
            var testParams = new SetInventoryPickOrderParameters(orderKey.KeyValue)
            {
                UserToken = TestUser.UserName,
                InventoryPickOrderItems = new List <ISetInventoryPickOrderItemParameters>
                {
                    new SetInventoryPickOrderItemParameters
                    {
                        ProductKey   = chileProductKey0,
                        PackagingKey = packagingProductKey0,
                        TreatmentKey = null,
                        Quantity     = expectedQuantity0
                    },
                    new SetInventoryPickOrderItemParameters
                    {
                        ProductKey   = chileProductKey1,
                        PackagingKey = packagingProductKey1,
                        TreatmentKey = null,
                        Quantity     = expectedQuantity1
                    }
                }
            };
            var result = GetResult(testParams);

            //Assert
            result.AssertSuccess();
            var items = RVCUnitOfWork.InventoryPickOrderRepository.Filter(i => true, i => i.Items.Select(m => m.InventoryTreatment)).Single().Items.ToList();

            Assert.AreEqual(testParams.InventoryPickOrderItems.Count(), items.Count);
            testParams.InventoryPickOrderItems.ForEach(i => items.Single(r =>
                                                                         i.ProductKey == new ProductKey((IProductKey)r).KeyValue&&
                                                                         i.PackagingKey == new PackagingProductKey(r).KeyValue&&
                                                                         r.TreatmentId == 0 &&
                                                                         i.Quantity == r.Quantity));
        }
            public void Creates_a_single_Inventory_record_with_aggregate_Quantity_for_Items_received_that_reference_the_same_Packaging_WarehouseLocation()
            {
                //Arrange
                var       expectedLotDate         = new DateTime(2012, 3, 29);
                const int expectedLotDateSequence = 1;
                const int expectedLotTypeId       = (int)LotTypeEnum.DeHydrated;
                const int quantity0        = 10;
                const int quantity1        = 21;
                const int expectedQuantity = quantity0 + quantity1;

                var chileProductKey = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var dehydratorKey   = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = expectedLotDate,
                    ChileProductKey = chileProductKey.KeyValue,
                    SupplierKey     = dehydratorKey.KeyValue,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity0,
                            Variety             = "Variety",
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue
                        },
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity1,
                            Variety             = "Variety",
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var inventory = RVCUnitOfWork.InventoryRepository.All().Single(i => i.LotDateCreated == expectedLotDate && i.LotDateSequence == expectedLotDateSequence && i.LotTypeId == expectedLotTypeId);

                Assert.AreEqual(expectedQuantity, inventory.Quantity);
            }
Exemplo n.º 11
0
        private void SetValidToPick(LabReportChileLotReturn chileLot)
        {
            var customerKey = chileLot.PackScheduleBaseReturn != null && chileLot.PackScheduleBaseReturn.Customer != null ? chileLot.PackScheduleBaseReturn.Customer.CustomerKeyReturn : null;
            IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec;
            IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec;

            if (!new GetProductSpecCommand(_lotUnitOfWork).Execute(ChileProductKey.FromProductKey(chileLot.ChileProductKeyReturn), customerKey, out productSpec, out customerSpec).Success)
            {
                chileLot.ValidToPick = true;
            }

            var lot = _lotUnitOfWork.LotRepository.FindByKey(chileLot.LotKeyReturn.ToLotKey(),
                                                             l => l.ContractAllowances,
                                                             l => l.SalesOrderAllowances,
                                                             l => l.CustomerAllowances,
                                                             l => l.Attributes,
                                                             l => l.AttributeDefects.Select(a => a.LotDefect.Resolution));
            var context   = new PickingValidatorContext(productSpec, customerSpec, null, null, customerKey);
            var validator = new PickingValidator(lot).ValidForPicking(context);

            chileLot.ValidToPick = validator.Success;
        }
            public void Creates_Lot_record_with_LotProductionStatus_set_to_Produced()
            {
                //Arrange
                var chileProductKey      = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var dehydratorKey        = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = new DateTime(2012, 3, 29),
                    ChileProductKey = chileProductKey,
                    SupplierKey     = dehydratorKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = "123",
                    PurchaseOrder   = "MLAH!",
                    ShipperNumber   = "1029384756",
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue,
                            Variety             = "Variety"
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var dehydratedReceived = RVCUnitOfWork.ChileMaterialsReceivedRepository.Filter(d => true, d => d.ChileLot.Lot, d => d.Items).Single();

                Assert.AreEqual(LotProductionStatus.Produced, dehydratedReceived.ChileLot.Lot.ProductionStatus);
            }
            public void Returns_successful_result_if_ProductionDate_has_a_time_component_and_a_Lot_exists_with_the_same_Date_Type_and_a_Sequence_of_1()
            {
                //Arrange
                var productionDate = new DateTime(2012, 4, 1, 10, 30, 21);

                TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileLot>(c => c.LotDateCreated = productionDate, c => c.LotDateSequence = 1, c => c.LotTypeId = (int)LotTypeEnum.DeHydrated);

                var chileProductKey      = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var dehydratorKey        = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = productionDate,
                    ChileProductKey = chileProductKey,
                    SupplierKey     = dehydratorKey,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = "123",
                    PurchaseOrder   = "POPO",
                    ShipperNumber   = "1029384756",
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue,
                            Variety             = "variety"
                        }
                    }
                });

                //Assert
                result.AssertSuccess();
            }
            public void Returns_non_successful_result_if_Dehydrator_Company_is_not_of_CompanyType_Dehydrator()
            {
                //Arrange
                var chileProductKey      = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var packagingProductKey  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                var supplier = TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Supplier));

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    ChileMaterialsReceivedType = ChileMaterialsReceivedType.Dehydrated,
                    UserToken       = TestUser.UserName,
                    DateReceived    = new DateTime(2012, 3, 29),
                    ChileProductKey = chileProductKey,
                    SupplierKey     = supplier.ToCompanyKey(),
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    LoadNumber      = "123",
                    PurchaseOrder   = "MLAH!",
                    ShipperNumber   = "1029384756",
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = 10,
                            PackagingProductKey = packagingProductKey.KeyValue,
                            LocationKey         = warehouseLocationKey.KeyValue,
                            Variety             = "Variety"
                        }
                    }
                });

                //Assert
                result.AssertNotSuccess(string.Format(UserMessages.CompanyNotOfType, "{0}", "{1}", CompanyType.Dehydrator));
            }
Exemplo n.º 15
0
        public IResult <IPickableInventoryReturn> GetInventoryToPickForOrder(FilterInventoryForShipmentOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            InventoryShipmentOrderKey orderKey;
            InventoryPickOrderItemKey orderItemKey;
            var filterResults = parameters.ParseToPredicateBuilderFilters(out orderKey, out orderItemKey);

            if (!filterResults.Success)
            {
                return(filterResults.ConvertTo <IPickableInventoryReturn>());
            }
            var salesOrderKey     = new SalesOrderKey(orderKey);
            var salesOrderItemKey = orderItemKey == null ? null : new SalesOrderItemKey(orderItemKey);

            var salesOrder = _inventoryShipmentOrderUnitOfWork.SalesOrderRepository.FindByKey(salesOrderKey,
                                                                                              o => o.InventoryShipmentOrder.SourceFacility,
                                                                                              o => o.SalesOrderItems.Select(i => i.ContractItem),
                                                                                              o => o.SalesOrderItems.Select(i => i.InventoryPickOrderItem));

            if (salesOrder == null)
            {
                return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.SalesOrderNotFound, orderKey.KeyValue)));
            }

            IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec  = null;
            IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec = null;
            SalesOrderItem orderItem = null;

            if (salesOrderItemKey != null)
            {
                var item = salesOrder.SalesOrderItems.FirstOrDefault(salesOrderItemKey.FindByPredicate.Compile());
                if (item == null)
                {
                    return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.SalesOrderItemNotFound, salesOrderItemKey)));
                }
                orderItem = item;

                var specResult = new GetProductSpecCommand(_inventoryShipmentOrderUnitOfWork).Execute(ChileProductKey.FromProductKey(item.InventoryPickOrderItem),
                                                                                                      item.Order, out productSpec, out customerSpec);
                if (!specResult.Success)
                {
                    return(specResult.ConvertTo <IPickableInventoryReturn>());
                }
            }

            var itemsResult = new GetPickableInventoryCommand(_inventoryShipmentOrderUnitOfWork).Execute(filterResults.ResultingObject, _timeStamper.CurrentTimeStamp,
                                                                                                         PickedInventoryValidator.ForSalesOrder(salesOrder.InventoryShipmentOrder.SourceFacility), true);

            if (itemsResult.Success)
            {
                itemsResult.ResultingObject.Initializer = new ValidPickingForOrder(new PickingValidatorContext(productSpec, customerSpec, orderItem == null ? null : orderItem.ContractItem, salesOrder, salesOrder));
            }

            return(itemsResult);
        }
            public void Creates_Inventory_records_as_expected_on_success()
            {
                //Arrange
                var          expectedLotDate         = new DateTime(2012, 3, 29);
                const int    expectedLotDateSequence = 1;
                const int    expectedLotTypeId       = (int)LotTypeEnum.DeHydrated;
                const int    expectedItems           = 3;
                const int    quantity0   = 10;
                const int    quantity1   = 21;
                const int    quantity2   = 40001;
                const string toteKey0    = "tote0";
                const string toteKey1    = "tote-1";
                const string toteKey2    = "";
                const string varietyKey0 = "variety0";
                const string varietyKey1 = "variety1";

                var chileProductKey = new ChileProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileProduct>(c => c.EmptyProduct().ChileState = ChileStateEnum.Dehydrated));
                var dehydratorKey   = new CompanyKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Company>(c => c.SetCompanyTypes(CompanyType.Dehydrator)));

                var packagingProductKey0  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var packagingProductKey1  = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>());
                var warehouseLocationKey0 = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());
                var warehouseLocationKey1 = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>());

                //Act
                var result = Service.CreateChileMaterialsReceived(new ChileMaterialsReceivedParameters
                {
                    UserToken       = TestUser.UserName,
                    DateReceived    = expectedLotDate,
                    ChileProductKey = chileProductKey.KeyValue,
                    SupplierKey     = dehydratorKey.KeyValue,
                    TreatmentKey    = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(),
                    Items           = new List <ChileMaterialsReceivedItemParameters>
                    {
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity0,
                            Variety             = varietyKey0,
                            PackagingProductKey = packagingProductKey0.KeyValue,
                            LocationKey         = warehouseLocationKey0.KeyValue,
                            ToteKey             = toteKey0
                        },
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity1,
                            Variety             = varietyKey0,
                            PackagingProductKey = packagingProductKey1.KeyValue,
                            LocationKey         = warehouseLocationKey0.KeyValue,
                            ToteKey             = toteKey1
                        },
                        new ChileMaterialsReceivedItemParameters
                        {
                            Quantity            = quantity2,
                            Variety             = varietyKey1,
                            PackagingProductKey = packagingProductKey0.KeyValue,
                            LocationKey         = warehouseLocationKey1.KeyValue,
                            ToteKey             = toteKey2
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var inventory = RVCUnitOfWork.InventoryRepository.Filter(i => i.LotDateCreated == expectedLotDate && i.LotDateSequence == expectedLotDateSequence && i.LotTypeId == expectedLotTypeId).ToList();

                Assert.AreEqual(expectedItems, inventory.Count);

                var item = inventory.Single(i => i.Quantity == quantity0);

                Assert.IsTrue(packagingProductKey0.Equals(item));
                Assert.IsTrue(warehouseLocationKey0.Equals(item));
                Assert.IsTrue(NoTreatmentKey.Equals(item));
                Assert.AreEqual(toteKey0, item.ToteKey);

                item = inventory.Single(i => i.Quantity == quantity1);
                Assert.IsTrue(packagingProductKey1.Equals(item));
                Assert.IsTrue(warehouseLocationKey0.Equals(item));
                Assert.IsTrue(NoTreatmentKey.Equals(item));
                Assert.AreEqual(toteKey1, item.ToteKey);

                item = inventory.Single(i => i.Quantity == quantity2);
                Assert.IsTrue(packagingProductKey0.Equals(item));
                Assert.IsTrue(warehouseLocationKey1.Equals(item));
                Assert.IsTrue(NoTreatmentKey.Equals(item));
                Assert.AreEqual(toteKey2, item.ToteKey);
            }
        internal IResult <CustomerProductCodeReturn> Execute(CustomerKey customerKey, ChileProductKey chileProductKey)
        {
            var predicate = new CustomerProductCodeKey(customerKey, chileProductKey).FindByPredicate;
            var select    = CustomerProductCodeProjectors.Select();
            var code      = _salesUnitOfWork.CustomerProductCodeRepository.Filter(predicate).Select(select).FirstOrDefault();

            return(new SuccessResult <CustomerProductCodeReturn>(code));
        }
        public IResult <IPickableInventoryReturn> GetInventoryItemsToPickWarehouseOrder(FilterInventoryForShipmentOrderParameters parameters)
        {
            parameters = parameters ?? new FilterInventoryForShipmentOrderParameters();

            InventoryShipmentOrderKey orderKey;
            InventoryPickOrderItemKey orderItemKey;
            var filterResults = parameters.ParseToPredicateBuilderFilters(out orderKey, out orderItemKey);

            if (!filterResults.Success)
            {
                return(filterResults.ConvertTo <IPickableInventoryReturn>());
            }

            var order = _inventoryShipmentOrderUnitOfWork.InventoryShipmentOrderRepository.FindByKey(orderKey,
                                                                                                     o => o.SourceFacility,
                                                                                                     o => o.InventoryPickOrder.Items.Select(i => i.Customer));

            if (order == null)
            {
                return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.InterWarehouseOrderNotFound, orderKey)));
            }
            var facilityKey = order.SourceFacility.ToFacilityKey();

            IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec  = null;
            IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec = null;
            Customer customer = null;

            if (orderItemKey != null)
            {
                var item = order.InventoryPickOrder.Items.FirstOrDefault(orderItemKey.FindByPredicate.Compile());
                if (item == null)
                {
                    return(new InvalidResult <IPickableInventoryReturn>(null, string.Format(UserMessages.InventoryPickOrderItemNotFound, orderItemKey)));
                }
                customer = item.Customer;

                var specResult = new GetProductSpecCommand(_inventoryShipmentOrderUnitOfWork).Execute(ChileProductKey.FromProductKey(item),
                                                                                                      customer, out productSpec, out customerSpec);
                if (!specResult.Success)
                {
                    return(specResult.ConvertTo <IPickableInventoryReturn>());
                }
            }

            var itemsResult = new GetPickableInventoryCommand(_inventoryShipmentOrderUnitOfWork).Execute(filterResults.ResultingObject, _timeStamper.CurrentTimeStamp,
                                                                                                         PickedInventoryValidator.ForInterWarehouseOrder(facilityKey), true);

            return(itemsResult);
        }
        private IResult ValidateModifyPickedInventoryItems(SalesOrder salesOrder, IEnumerable <ModifySalesOrderPickedInventoryItemParameters> items)
        {
            var validator  = PickedInventoryValidator.ForSalesOrder(salesOrder.InventoryShipmentOrder.SourceFacility);
            var orderItems = salesOrder.SalesOrderItems.ToDictionary(i => i.ToSalesOrderItemKey());

            foreach (var item in items)
            {
                SalesOrderItem orderItem;
                if (!orderItems.TryGetValue(item.SalesOrderItemKey, out orderItem))
                {
                    return(new InvalidResult(string.Format(UserMessages.CannotPickForCustomerOrderItem_DoesNotExist, item.SalesOrderItemKey.KeyValue)));
                }

                if (item.NewQuantity > item.OriginalQuantity)
                {
                    IDictionary <AttributeNameKey, ChileProductAttributeRange>    productSpec;
                    IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec;
                    var specResult = new GetProductSpecCommand(_salesUnitOfWork).Execute(ChileProductKey.FromProductKey(orderItem.InventoryPickOrderItem),
                                                                                         orderItem.Order, out productSpec, out customerSpec);
                    if (!specResult.Success)
                    {
                        return(specResult);
                    }

                    Dictionary <string, Inventory> inventory;
                    var validResult    = validator.ValidateItems(_salesUnitOfWork.InventoryRepository, new[] { item.InventoryKey }, out inventory);
                    var inventoryItem  = inventory.Values.Single();
                    var context        = new PickingValidatorContext(productSpec, customerSpec, orderItem.ContractItem, orderItem, orderItem.Order);
                    var pickable       = new PickingValidator(inventoryItem.Lot);
                    var pickableResult = pickable.ValidForPicking(context);

                    if (!validResult.Success || !pickableResult.Success)
                    {
                        return(new InvalidResult(new[] { validResult, pickableResult }.CombineMessages()));
                    }
                }
            }

            return(new SuccessResult());
        }