internal static Inventory ToInventory(this ChileMaterialsReceivedItem item, IInventoryTreatmentKey treatment)
 {
     return(new Inventory
     {
         Quantity = item.Quantity
     }.ConstrainByKeys(item.ChileMaterialsReceived, item, item, treatment, null, item.ToteKey));
 }
Example #2
0
        public tblTreatment GetTreatment(IInventoryTreatmentKey inventoryTreatmentKey)
        {
            tblTreatment treatment;

            Treatments.TryGetValue(inventoryTreatmentKey.InventoryTreatmentKey_Id, out treatment);
            return(treatment);
        }
        internal static IResult <List <InventoryPickOrderItemParameter> > ToParsedItems(this IEnumerable <ISetInventoryPickOrderItemParameters> parameters)
        {
            var pickedItems = new List <InventoryPickOrderItemParameter>();

            foreach (var item in parameters)
            {
                if (item.Quantity <= 0)
                {
                    return(new InvalidResult <List <InventoryPickOrderItemParameter> >(null, "Quantity cannot be less than or equal to 0."));
                }

                var productKeyResult = KeyParserHelper.ParseResult <IProductKey>(item.ProductKey);
                if (!productKeyResult.Success)
                {
                    return(productKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                }

                var packagingProductKeyResult = KeyParserHelper.ParseResult <IPackagingProductKey>(item.PackagingKey);
                if (!packagingProductKeyResult.Success)
                {
                    return(packagingProductKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                }

                IInventoryTreatmentKey treatmentKey = StaticInventoryTreatments.NoTreatment;
                if (!string.IsNullOrEmpty(item.TreatmentKey))
                {
                    var treatmentKeyResult = KeyParserHelper.ParseResult <IInventoryTreatmentKey>(item.TreatmentKey);
                    if (!treatmentKeyResult.Success)
                    {
                        return(treatmentKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                    }
                    treatmentKey = treatmentKeyResult.ResultingObject;
                }

                ICustomerKey customer = null;
                if (!string.IsNullOrWhiteSpace(item.CustomerKey))
                {
                    var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(item.CustomerKey);
                    if (!customerKeyResult.Success)
                    {
                        return(customerKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                    }
                    customer = customerKeyResult.ResultingObject;
                }

                pickedItems.Add(new InventoryPickOrderItemParameter(productKeyResult.ResultingObject, packagingProductKeyResult.ResultingObject, treatmentKey, item.Quantity, customer, item.CustomerProductCode, item.CustomerLotCode));
            }

            return(new SuccessResult <List <InventoryPickOrderItemParameter> >(pickedItems));
        }
        private static Expression <Func <Inventory, bool> > ValidForTreatmentOrder(IInventoryTreatmentKey treatment, ITreatmentOrderUnitOfWork unitOfWork)
        {
            var lotsAreEqual   = LotProjectors.SelectLotsAreEqual();
            var validTreatment = treatment.ToInventoryTreatmentKey().FindByPredicate
                                 .Or(Data.Models.StaticRecords.StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey().FindByPredicate);

            var treatmentOrders = unitOfWork.TreatmentOrderRepository.All();
            var lots            = unitOfWork.LotRepository.All();

            return(i => lots
                   .Where(l => lotsAreEqual.Invoke(i.Lot, l))
                   .SelectMany(l => l.Inventory.Select(n => n.Treatment).Concat(l.PickedInventory.Select(p => p.Treatment)))
                   .Concat(treatmentOrders
                           .Where(o =>
                                  o.InventoryShipmentOrder.OrderStatus != OrderStatus.Void &&
                                  o.InventoryShipmentOrder.PickedInventory.Items.Any(l => lotsAreEqual.Invoke(l.Lot, i.Lot)))
                           .Select(o => o.Treatment))
                   .All(t => validTreatment.Invoke(t)));
        }
        internal static InventoryPickOrderItem SetTreatment(this InventoryPickOrderItem item, IInventoryTreatmentKey treatment)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            item.InventoryTreatment = null;
            item.TreatmentId        = treatment.InventoryTreatmentKey_Id;

            return(item);
        }
 internal static InventoryTreatment SetKey(this InventoryTreatment treatment, IInventoryTreatmentKey treatmentKey)
 {
     treatment.Id = treatmentKey.InventoryTreatmentKey_Id;
     return(treatment);
 }
Example #7
0
        internal static ModifyInventoryParameters ToAddInventoryParameters(this ChileMaterialsReceivedItem item, IInventoryTreatmentKey treatment)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(new ModifyInventoryParameters(item, item, item, treatment, item.ToteKey, item.Quantity));
        }
        internal static Inventory ConstrainByKeys(this Inventory inventory, ILotKey lotKey = null, IPackagingProductKey packagingProductKey = null, ILocationKey locationKey = null, IInventoryTreatmentKey treatment = null, IFacilityKey facility = null, string toteKey = null)
        {
            if (inventory == null)
            {
                throw new ArgumentNullException("inventory");
            }

            if (lotKey != null)
            {
                inventory.Lot             = null;
                inventory.LotDateCreated  = lotKey.LotKey_DateCreated;
                inventory.LotDateSequence = lotKey.LotKey_DateSequence;
                inventory.LotTypeId       = lotKey.LotKey_LotTypeId;
            }

            if (packagingProductKey != null)
            {
                inventory.PackagingProduct   = null;
                inventory.PackagingProductId = packagingProductKey.PackagingProductKey_ProductId;
            }

            if (locationKey != null)
            {
                inventory.Location   = null;
                inventory.LocationId = locationKey.LocationKey_Id;
            }

            if (treatment != null)
            {
                inventory.Treatment   = null;
                inventory.TreatmentId = treatment.InventoryTreatmentKey_Id;
            }

            if (facility != null)
            {
                if (inventory.Location == null)
                {
                    throw new ArgumentNullException("warehouseLocation is null. Maybe you tried constraining by both the LocationKey and FacilityKey. Can't do that. Pick one or the other. -RI");
                }
                inventory.Location.Facility   = null;
                inventory.Location.FacilityId = facility.FacilityKey_Id;
            }

            if (toteKey != null)
            {
                inventory.ToteKey = toteKey;
            }

            return(inventory);
        }
Example #9
0
 public InventoryPickOrderItemParameter(IProductKey productKey, IPackagingProductKey packagingProductKey, IInventoryTreatmentKey treatmentKey, int quantity, ICustomerKey customer, string customerProductCode, string customerLotCode)
 {
     ProductId           = productKey.ProductKey_ProductId;
     PackagingProductId  = packagingProductKey.PackagingProductKey_ProductId;
     TreatmentId         = treatmentKey == null ? (int?)null : treatmentKey.InventoryTreatmentKey_Id;
     Quantity            = quantity;
     CustomerKey         = customer != null ? new CustomerKey(customer) : null;
     CustomerProductCode = customerProductCode;
     CustomerLotCode     = customerLotCode;
 }
Example #10
0
 public static InventoryTreatmentKey ToInventoryTreatmentKey(this IInventoryTreatmentKey k)
 {
     return(new InventoryTreatmentKey(k));
 }
Example #11
0
        internal static PickedInventoryItem ConstrainByKeys(this PickedInventoryItem item, IPickedInventoryKey pickedInventoryKey = null, ILotKey lotKey = null, IPackagingProductKey packagingProductKey = null, IInventoryTreatmentKey treatmentKey = null, ILocationKey sourceLocationKey = null, ILocationKey currentLocationKey = null, string toteKey = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (pickedInventoryKey != null)
            {
                item.PickedInventory = null;
                item.DateCreated     = pickedInventoryKey.PickedInventoryKey_DateCreated;
                item.Sequence        = pickedInventoryKey.PickedInventoryKey_Sequence;
            }

            if (lotKey != null)
            {
                item.Lot             = null;
                item.LotDateCreated  = lotKey.LotKey_DateCreated;
                item.LotDateSequence = lotKey.LotKey_DateSequence;
                item.LotTypeId       = lotKey.LotKey_LotTypeId;
            }

            if (packagingProductKey != null)
            {
                item.PackagingProduct   = null;
                item.PackagingProductId = packagingProductKey.PackagingProductKey_ProductId;
            }

            if (treatmentKey != null)
            {
                item.Treatment   = null;
                item.TreatmentId = treatmentKey.InventoryTreatmentKey_Id;
            }

            if (sourceLocationKey != null)
            {
                item.FromLocation   = null;
                item.FromLocationId = sourceLocationKey.LocationKey_Id;
            }

            if (currentLocationKey != null)
            {
                item.CurrentLocation   = null;
                item.CurrentLocationId = currentLocationKey.LocationKey_Id;
            }

            if (toteKey != null)
            {
                item.ToteKey = toteKey;
            }

            return(item);
        }
        internal static InventoryTreatmentForAttribute ConstrainKeys(this InventoryTreatmentForAttribute treatmentForAttribute, IInventoryTreatmentKey treatmentKey = null, IAttributeNameKey attributeNameKey = null)
        {
            if (treatmentKey != null)
            {
                treatmentForAttribute.Treatment   = null;
                treatmentForAttribute.TreatmentId = treatmentKey.InventoryTreatmentKey_Id;
            }

            if (attributeNameKey != null)
            {
                treatmentForAttribute.AttributeName      = null;
                treatmentForAttribute.AttributeShortName = attributeNameKey.AttributeNameKey_ShortName;
            }

            return(treatmentForAttribute);
        }
Example #13
0
 public InventoryKey(ILotKey lotKey, IPackagingProductKey packagingProductKey, ILocationKey locationKey, IInventoryTreatmentKey treatmentKey, string toteKey)
     : this(lotKey.LotKey_DateCreated, lotKey.LotKey_DateSequence, lotKey.LotKey_LotTypeId, packagingProductKey.PackagingProductKey_ProductId, locationKey.LocationKey_Id, treatmentKey.InventoryTreatmentKey_Id, toteKey)
 {
 }
        private IResult SetItems(ChileMaterialsReceived received, IEnumerable <SetChileMaterialsReceivedItemParameters> setItems, IInventoryTreatmentKey previousTreatment, IEmployeeKey employee, DateTime timeStamp)
        {
            var maxSequence   = received.Items.Select(i => i.ItemSequence).DefaultIfEmpty(0).Max();
            var itemsToRemove = received.Items.ToDictionary(i => i.ToChileMaterialsReceivedItemKey());

            var modifications = itemsToRemove.Values.Select(i => i.ToRemoveInventoryParameters(previousTreatment)).ToList();

            foreach (var setItem in setItems)
            {
                ChileMaterialsReceivedItem item;
                if (setItem.ItemKey != null && itemsToRemove.TryGetValue(setItem.ItemKey, out item))
                {
                    itemsToRemove.Remove(setItem.ItemKey);
                }
                else
                {
                    item = MaterialsReceivedUnitOfWork.ChileMaterialsReceivedItemRepository.Add(new ChileMaterialsReceivedItem
                    {
                        LotDateCreated  = received.LotDateCreated,
                        LotDateSequence = received.LotDateSequence,
                        LotTypeId       = received.LotTypeId,
                        ItemSequence    = ++maxSequence,
                    });
                    received.Items.Add(item);
                }

                item.GrowerCode         = setItem.GrowerCode;
                item.ToteKey            = setItem.ToteKey;
                item.ChileVariety       = setItem.ChileVariety;
                item.Quantity           = setItem.Quantity;
                item.LocationId         = setItem.LocationKey.LocationKey_Id;
                item.PackagingProductId = setItem.PackagingProductKey.PackagingProductKey_ProductId;
            }

            itemsToRemove.Values.ForEach(MaterialsReceivedUnitOfWork.ChileMaterialsReceivedItemRepository.Remove);
            modifications.AddRange(received.Items.Select(i => i.ToAddInventoryParameters(received)));

            return(new ModifyInventoryCommand(MaterialsReceivedUnitOfWork).Execute(modifications,
                                                                                   new InventoryTransactionParameters(employee, timeStamp,
                                                                                                                      received.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated
                    ? InventoryTransactionType.ReceivedDehydratedMaterials
                    : InventoryTransactionType.ReceivedOtherMaterials, received.ToLotKey())));
        }
Example #15
0
        internal static SalesOrderItem ConstrainByKeys(this SalesOrderItem item, ISalesOrderKey order = null, IContractItemKey contractItem = null, IChileProductKey chileProduct = null, IPackagingProductKey packagingProduct = null, IInventoryTreatmentKey treatment = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (order != null)
            {
                item.Order       = null;
                item.DateCreated = order.SalesOrderKey_DateCreated;
                item.Sequence    = order.SalesOrderKey_Sequence;

                if (item.InventoryPickOrderItem != null)
                {
                    item.InventoryPickOrderItem.InventoryPickOrder = null;
                }
            }

            if (contractItem != null)
            {
                item.ContractItem         = null;
                item.ContractYear         = contractItem.ContractKey_Year;
                item.ContractSequence     = contractItem.ContractKey_Sequence;
                item.ContractItemSequence = contractItem.ContractItemKey_Sequence;
            }

            if (chileProduct != null)
            {
                item.InventoryPickOrderItem.Product   = null;
                item.InventoryPickOrderItem.ProductId = chileProduct.ChileProductKey_ProductId;
            }

            if (packagingProduct != null)
            {
                item.InventoryPickOrderItem.PackagingProduct   = null;
                item.InventoryPickOrderItem.PackagingProductId = packagingProduct.PackagingProductKey_ProductId;
            }

            if (treatment != null)
            {
                item.InventoryPickOrderItem.InventoryTreatment = null;
                item.InventoryPickOrderItem.TreatmentId        = treatment.InventoryTreatmentKey_Id;
            }

            return(item);
        }
        internal static IInventoryValidator ForTreatmentOrder(IFacilityKey sourceFacility, IInventoryTreatmentKey treatmentKey, ITreatmentOrderUnitOfWork unitOfWork)
        {
            var facilityKey       = sourceFacility.ToFacilityKey();
            var facilityPredicate = facilityKey.FindByPredicate;

            return(new PickedInventoryValidator(i => i.Location.Facility, i => i.Lot.Inventory.Select(n => n.Treatment))
            {
                { i => i.Location.Active, i => new InvalidResult(string.Format(UserMessages.InventoryInactiveLocation, i.ToInventoryKey())), false },
                { i => !i.Location.Locked, i => new InvalidResult(string.Format(UserMessages.InventoryLocationLocked, i.ToInventoryKey())), false },
                { i => i.Lot.QualityStatus != LotQualityStatus.Rejected, i => new InvalidResult(string.Format(UserMessages.CannotPickLotQualityState, i.ToLotKey(), i.Lot.QualityStatus)), false },
                { i => facilityPredicate.Invoke(i.Location.Facility), i => new InvalidResult(string.Format(UserMessages.SourceLocationMustBelongToFacility, facilityKey)) },
                { ValidForTreatmentOrder(treatmentKey, unitOfWork), i => new InvalidResult(string.Format(UserMessages.LotConflictingInventoryTreatment, i.ToLotKey())) }
            });
        }
        public ModifyInventoryParameters(ILotKey lotKey, IPackagingProductKey packagingProductKey, ILocationKey locationKey, IInventoryTreatmentKey inventoryTreatmentKey, string toteKey, int adjustQuantity)
        {
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }
            if (packagingProductKey == null)
            {
                throw new ArgumentNullException("packagingProductKey");
            }
            if (locationKey == null)
            {
                throw new ArgumentNullException("locationKey");
            }
            if (inventoryTreatmentKey == null)
            {
                throw new ArgumentNullException("inventoryTreatmentKey");
            }

            InventoryKey          = new InventoryKey(lotKey, packagingProductKey, locationKey, inventoryTreatmentKey, toteKey);
            LotKey                = lotKey.ToLotKey();
            PackagingProductKey   = packagingProductKey.ToPackagingProductKey();
            LocationKey           = locationKey.ToLocationKey();
            InventoryTreatmentKey = inventoryTreatmentKey.ToInventoryTreatmentKey();

            ModifyQuantity = adjustQuantity;
        }
 internal static ModifyInventoryParameters ToModifyInventoryDestinationParameters(this PickedInventoryItem item, ILocationKey destinationLocation, IInventoryTreatmentKey newTreamentKey = null)
 {
     return(new ModifyInventoryParameters(item, item, destinationLocation, newTreamentKey ?? item, item.ToteKey, item.Quantity));
 }