internal static Inventory SetValidToPick(this Inventory inventory, IFacilityKey sourceFacility = null)
        {
            if (inventory == null)
            {
                throw new ArgumentNullException("inventory");
            }

            inventory.Lot.SetValidToPick();
            inventory.Location.ConstrainByKeys(sourceFacility).Locked = false;
            inventory.Location.Active = true;

            return(inventory);
        }
        internal IResult UpdateFacility(IFacilityKey facilityKey, ICreateFacilityParameters parameters)
        {
            var key      = facilityKey.ToFacilityKey();
            var facility = _facilityUnitOfWork.FacilityRepository.FindByKey(key);

            if (facility == null)
            {
                return(new InvalidResult(string.Format(UserMessages.FacilityNotFound, key)));
            }

            UpdateFacility(facility, parameters);

            return(new SuccessResult());
        }
        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())) }
            });
        }
Beispiel #4
0
        internal IResult <Facility> DeleteFacility(IFacilityKey facilityKey)
        {
            var key      = new FacilityKey(facilityKey);
            var facility = _facilityUnitOfWork.FacilityRepository.FindByKey(key);

            if (facility == null)
            {
                return(new InvalidResult <Facility>(null, string.Format(UserMessages.FacilityNotFound, key)));
            }

            _facilityUnitOfWork.FacilityRepository.Remove(facility);

            return(new SuccessResult <Facility>(facility));
        }
Beispiel #5
0
        internal static Location ConstrainByKeys(this Location location, IFacilityKey facilityKey = null)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            if (facilityKey != null)
            {
                location.Facility   = null;
                location.FacilityId = facilityKey.FacilityKey_Id;
            }

            return(location);
        }
Beispiel #6
0
        internal static SalesOrder SetShipFromWarehouse(this SalesOrder salesOrder, IFacilityKey facilityKey)
        {
            if (salesOrder == null)
            {
                throw new ArgumentNullException("salesOrder");
            }
            if (facilityKey == null)
            {
                throw new ArgumentNullException("facilityKey");
            }

            salesOrder.InventoryShipmentOrder.SourceFacility   = null;
            salesOrder.InventoryShipmentOrder.SourceFacilityId = facilityKey.FacilityKey_Id;

            return(salesOrder);
        }
        internal static IInventoryValidator ForSalesOrder(IFacilityKey sourceFacility)
        {
            var facilityKey       = sourceFacility.ToFacilityKey();
            var facilityPredicate = facilityKey.FindByPredicate;

            return(new PickedInventoryValidator(i => i.Location.Facility,
                                                i => i.Lot.CustomerAllowances,
                                                i => i.Lot.ContractAllowances,
                                                i => i.Lot.SalesOrderAllowances,
                                                i => i.Lot.Attributes,
                                                i => i.Lot.LotDefects.Select(d => d.Resolution),
                                                i => i.Lot.AttributeDefects.Select(d => d.LotDefect.Resolution))
            {
                { 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 },
                { InventoryPredicates.ByLotStatus(LotQualityStatus.Released), i => new InvalidResult(string.Format(UserMessages.CannotPickLotQualityState, i.ToLotKey(), i.Lot.QualityStatus)), false },
                { i => i.Lot.Hold == null || i.Lot.Hold == LotHoldType.HoldForCustomer, i => new InvalidResult(string.Format(UserMessages.CannotPickLotOnHold, i.ToLotKey(), i.Lot.Hold)), false },
                { i => facilityPredicate.Invoke(i.Location.Facility), i => new InvalidResult(string.Format(UserMessages.SourceLocationMustBelongToFacility, facilityKey)) },
                { InventoryPredicates.ByLotProductionStatus(LotProductionStatus.Produced), i => new InvalidResult(string.Format(UserMessages.CannotPickLotNotProduced, i.ToLotKey())), false }
            });
        }
Beispiel #8
0
 public static Expression <Func <Location, bool> > ByFacilityKey(IFacilityKey facilityKey)
 {
     return(l => l.FacilityId == facilityKey.FacilityKey_Id);
 }
Beispiel #9
0
 public static FacilityKey ToFacilityKey(this IFacilityKey k)
 {
     return(new FacilityKey(k));
 }
        protected List <InventoryKey> GetExpectedInventoryKeys(IEnumerable <ILotKey> expectedLots, bool includeUnavailable, IFacilityKey facilityKey = null)
        {
            facilityKey = facilityKey ?? FacilityKey.Null;
            var useWarehouseKey = !facilityKey.Equals(FacilityKey.Null);

            return(TestHelper.Context.Inventory
                   .Where(i =>
                          (includeUnavailable || i.Quantity > 0) &&
                          (!useWarehouseKey || i.Location.FacilityId == facilityKey.FacilityKey_Id)).ToList()
                   .Join(
                       expectedLots.ToList(),
                       i => new { i.LotKey_DateCreated, i.LotKey_DateSequence, i.LotKey_LotTypeId },
                       l => new { l.LotKey_DateCreated, l.LotKey_DateSequence, l.LotKey_LotTypeId },
                       (i, l) => new InventoryKey(i))
                   .OrderBy(i => i.KeyValue).ToList());
        }
        internal static InventoryShipmentOrder SetSourceFacility(this InventoryShipmentOrder order, IFacilityKey facilityKey)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            order.SourceFacility   = null;
            order.SourceFacilityId = facilityKey.FacilityKey_Id;

            return(order);
        }
Beispiel #12
0
        internal static PickedInventoryItem SetSourceWarehouse(this PickedInventoryItem item, IFacilityKey facilityKey)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (facilityKey == null)
            {
                throw new ArgumentNullException("facilityKey");
            }

            if (item.FromLocation != null)
            {
                item.FromLocation.ConstrainByKeys(facilityKey);
            }

            return(item);
        }
        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);
        }