Пример #1
0
        private IResult <Lot> CreatePackagingLot(DateTime timeStamp, IEmployeeKey employeeKey, ReceiveInventoryParameters parameters)
        {
            var packagingProductKey = PackagingProductKey.FromProductKey(parameters.ProductKey);
            var packagingProduct    = _inventoryUnitOfWork.PackagingProductRepository.FindByKey(packagingProductKey);

            if (packagingProduct == null)
            {
                return(new InvalidResult <Lot>(null, string.Format(UserMessages.PackagingProductNotFound, packagingProductKey.KeyValue)));
            }

            var packagingLotResult = new CreateNewPackagingLotCommand(_inventoryUnitOfWork).Execute(new CreateNewPackagingLotCommandParameters
            {
                EmployeeKey = employeeKey,
                TimeStamp   = timeStamp,

                PackagingProductKey  = packagingProduct,
                PackagingReceivedKey = parameters.PackagingReceivedKey,

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

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

            return(!packagingLotResult.Success ? packagingLotResult.ConvertTo <Lot>() : new SuccessResult <Lot>(packagingLotResult.ResultingObject.Lot));
        }
Пример #2
0
 public InventoryTransactionParameters(IEmployeeKey employeeKey, DateTime timeStamp, InventoryTransactionType transactionType, string sourceReference, ILotKey destinationLotKey = null)
 {
     EmployeeKey       = employeeKey;
     TimeStamp         = timeStamp;
     TransactionType   = transactionType;
     Description       = InventoryTransactionsHelper.GetDescription(transactionType);
     SourceReference   = sourceReference;
     DestinationLotKey = destinationLotKey;
 }
Пример #3
0
        private tblLocation Create(IEmployeeKey employeeKey, Location location, ref int?locID)
        {
            locID = (locID ?? (OldContext.tblLocations.Any() ? OldContext.tblLocations.Max(l => l.LocID) : 0)) + 1;

            var tblLocation = Update(employeeKey, location, new tblLocation
            {
                LocID = locID.Value
            });

            OldContext.tblLocations.AddObject(tblLocation);

            return(tblLocation);
        }
Пример #4
0
        internal IResult <Contract> SetCustomerContract(Contract contract, IEmployeeKey employeeKey, DateTime timeStamp, IUpdateCustomerContractCommandParameters parameters)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }
            if (timeStamp == null)
            {
                throw new ArgumentNullException("timeStamp");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (contract.ContractStatus == ContractStatus.Completed && parameters.ContractStatus == ContractStatus.Completed)
            {
                return(new InvalidResult <Contract>(null, string.Format(UserMessages.CustomerContractCompletedCannotChange, new ContractKey(contract).KeyValue)));
            }

            contract.EmployeeId = employeeKey.EmployeeKey_Id;
            contract.TimeStamp  = timeStamp;

            contract.ContactName    = parameters.ContactName;
            contract.FOB            = parameters.FOB;
            contract.ContactAddress = parameters.ContactAddress ?? new Address();

            contract.ContractType          = parameters.ContractType;
            contract.ContractStatus        = parameters.ContractStatus;
            contract.PaymentTerms          = parameters.PaymentTerms;
            contract.CustomerPurchaseOrder = parameters.CustomerPurchaseOrder;
            contract.ContractDate          = parameters.ContractDate.Date;
            contract.TermBegin             = parameters.TermBegin;
            contract.TermEnd = parameters.TermEnd;

            contract.NotesToPrint = parameters.NotesToPrint;

            var setItemsResult = new SetContractItemsCommand(_salesUnitOfWork).Execute(contract, parameters.ContractItems);

            if (!setItemsResult.Success)
            {
                return(setItemsResult.ConvertTo((Contract)null));
            }

            return(new SuccessResult <Contract>(contract));
        }
Пример #5
0
        private List <tblLocation> SynchronizeLocations(IEmployeeKey employeeKey, List <LocationKey> locationKeys, out bool syncNewContext)
        {
            var predicate = PredicateBuilder.False <Location>().Expand();

            locationKeys.ForEach(k => predicate = predicate.Or(k.FindByPredicate).Expand());

            var locations = UnitOfWork.LocationRepository.Filter(predicate, l => l.Facility);
            var missing   = locationKeys.FirstOrDefault(k => !locations.Any(k.FindByPredicate));

            if (missing != null)
            {
                throw new Exception(string.Format("Cannot find Location[{0}].", missing.KeyValue));
            }

            var oldPredicate          = PredicateBuilder.False <tblLocation>().Expand();
            var expectingOldLocations = locations.Where(l => l.LocID != null).ToList();

            expectingOldLocations.ForEach(l => oldPredicate = oldPredicate.Or(p => p.LocID == l.LocID.Value).Expand());

            var oldLocations = OldContext.tblLocations.Where(oldPredicate).ToDictionary(l => l.LocID, l => l);
            var oldMissing   = expectingOldLocations.FirstOrDefault(l => !oldLocations.ContainsKey(l.LocID.Value));

            if (oldMissing != null)
            {
                throw new Exception(string.Format("Could not find tblLocation[{0}].", oldMissing.LocID.Value));
            }

            syncNewContext = false;
            int?locId = null;

            foreach (var location in locations)
            {
                if (location.LocID == null)
                {
                    syncNewContext = true;
                    var oldLocation = Create(employeeKey, location, ref locId);
                    oldLocations.Add(oldLocation.LocID, oldLocation);
                }
                else
                {
                    Update(employeeKey, location, oldLocations[location.LocID.Value]);
                }
            }

            return(oldLocations.Values.ToList());
        }
Пример #6
0
        private static tblLocation Update(IEmployeeKey employeeKey, Location location, tblLocation tblLocation)
        {
            string street;
            int    row;

            LocationDescriptionHelper.GetStreetRow(location.Description, out street, out row);

            tblLocation.EmployeeID = employeeKey == null ? tblLocation.EmployeeID : employeeKey.EmployeeKey_Id;
            tblLocation.EntryDate  = tblLocation.EntryDate ?? DateTime.UtcNow.ConvertUTCToLocal();
            tblLocation.Street     = street;
            tblLocation.Row        = row;
            tblLocation.WHID       = location.Facility.WHID.Value;
            tblLocation.InActive   = !location.Active;
            tblLocation.FreezeRow  = location.Locked ? "Yes" : null;

            return(tblLocation);
        }
        public static LotDefectResolution ResolveDefect(this LotDefect lotDefect, IEmployeeKey employee, ResolutionTypeEnum?resolutionType = null, string resolutionDescription = null)
        {
            if (lotDefect.Resolution != null)
            {
                throw new Exception(string.Format("LotDefect[{0}] already has resolution.", new LotKey(lotDefect)));
            }

            var resolution = new LotDefectResolution
            {
                EmployeeId = employee.EmployeeKey_Id,
                TimeStamp  = DateTime.UtcNow,

                LotDateCreated  = lotDefect.LotKey_DateCreated,
                LotDateSequence = lotDefect.LotKey_DateSequence,
                LotTypeId       = lotDefect.LotKey_LotTypeId,
                DefectId        = lotDefect.DefectId,

                ResolutionType = resolutionType ?? ResolutionTypeEnum.AcceptedByUser,
                Description    = resolutionDescription ?? "Resolved by user in Access."
            };

            lotDefect.Resolution = resolution;
            return(resolution);
        }
Пример #8
0
        protected IResult <ProductionSchedule> Set(ProductionSchedule productionSchedule, IEmployeeKey user, DateTime timestamp, IEnumerable <SetProductionScheduleItemParameters> items)
        {
            productionSchedule.EmployeeId = user.EmployeeKey_Id;
            productionSchedule.TimeStamp  = timestamp;

            var itemsToRemove = productionSchedule.ScheduledItems.ToDictionary(i => i.Index);

            foreach (var item in items)
            {
                ProductionScheduleItem scheduledItem;
                if (itemsToRemove.TryGetValue(item.Index, out scheduledItem))
                {
                    itemsToRemove.Remove(item.Index);
                }
                else
                {
                    scheduledItem = ProductionUnitOfWork.ProductionScheduleItemRepository.Add(new ProductionScheduleItem
                    {
                        ProductionDate           = productionSchedule.ProductionDate,
                        ProductionLineLocationId = productionSchedule.ProductionLineLocationId,
                        Index = item.Index
                    });
                }

                scheduledItem.FlushBefore             = item.FlushBefore;
                scheduledItem.FlushBeforeInstructions = item.FlushBeforeInstructions;
                scheduledItem.FlushAfter              = item.FlushAfter;
                scheduledItem.FlushAfterInstructions  = item.FlushAfterInstructions;
                scheduledItem.PackScheduleDateCreated = item.PackScheduleKey.PackScheduleKey_DateCreated;
                scheduledItem.PackScheduleSequence    = item.PackScheduleKey.PackScheduleKey_DateSequence;
            }

            foreach (var item in itemsToRemove)
            {
                ProductionUnitOfWork.ProductionScheduleItemRepository.Remove(item.Value);
            }

            return(new SuccessResult <ProductionSchedule>(productionSchedule));
        }
        protected IResult <ChileLotProduction> SetMillAndWetdown <TParams>(ChileLotProduction millAndWetdown, SetMillAndWetdownParameters <TParams> parameters, DateTime timestamp, IEmployeeKey employee)
            where TParams : ISetMillAndWetdownParameters
        {
            millAndWetdown.ProductionType = ProductionType.MillAndWetdown;
            millAndWetdown.EmployeeId     = employee.EmployeeKey_Id;
            millAndWetdown.TimeStamp      = timestamp;

            millAndWetdown.Results.EmployeeId = employee.EmployeeKey_Id;
            millAndWetdown.Results.TimeStamp  = timestamp;
            millAndWetdown.Results.ProductionLineLocationId = parameters.ProductionLineKey.LocationKey_Id;
            millAndWetdown.Results.ShiftKey        = parameters.Params.ShiftKey;
            millAndWetdown.Results.ProductionBegin = parameters.Params.ProductionBegin;
            millAndWetdown.Results.ProductionEnd   = parameters.Params.ProductionEnd;

            var lotKey = new LotKey(millAndWetdown);

            if (!parameters.ChileProductKey.Equals(millAndWetdown.ResultingChileLot))
            {
                var chileProduct = ProductionUnitOfWork.ChileProductRepository.FindByKey(parameters.ChileProductKey);
                if (chileProduct == null)
                {
                    return(new InvalidResult <ChileLotProduction>(null, string.Format(UserMessages.ChileProductNotFound, parameters.ChileProductKey)));
                }

                if (chileProduct.ChileState.ToLotType() != millAndWetdown.ResultingChileLot.ChileProduct.ChileState.ToLotType())
                {
                    return(new InvalidResult <ChileLotProduction>(null, UserMessages.ChileProductDifferentLotType));
                }

                if (ProductionUnitOfWork.PickedInventoryItemRepository.Filter(PickedInventoryItemPredicates.FilterByLotKey(lotKey)).Any())
                {
                    return(new InvalidResult <ChileLotProduction>(null, string.Format(UserMessages.LotHasExistingPickedInventory, lotKey)));
                }

                millAndWetdown.ResultingChileLot.ChileProductId = parameters.ChileProductKey.ChileProductKey_ProductId;
            }

            var pickedInventoryItemModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(millAndWetdown.PickedInventory, parameters.PickedItems);
            var validationResults = PickedInventoryValidator.ForMillAndWetdown.ValidateItems(ProductionUnitOfWork.InventoryRepository, pickedInventoryItemModifications.Where(i => i.DeltaQuantity > 0).Select(i => i.InventoryKey));

            if (!validationResults.Success)
            {
                return(validationResults.ConvertTo <ChileLotProduction>());
            }

            var modifyPickedResult = new ModifyPickedInventoryItemsCommand(ProductionUnitOfWork).Execute(millAndWetdown, pickedInventoryItemModifications);

            if (!modifyPickedResult.Success)
            {
                return(modifyPickedResult.ConvertTo <ChileLotProduction>());
            }

            millAndWetdown.PickedInventory.Archived = true;
            var inventoryModifications = pickedInventoryItemModifications.Select(i => i.ToModifySourceInventoryParameters()).ToList();
            var setResults             = new SetLotProductionResultItemsCommand(ProductionUnitOfWork).Execute(millAndWetdown.Results, parameters.ResultItems, ref inventoryModifications);

            if (!setResults.Success)
            {
                return(setResults.ConvertTo <ChileLotProduction>());
            }

            var transaction           = new InventoryTransactionParameters(employee, timestamp, InventoryTransactionType.CreatedMillAndWetdown, lotKey, millAndWetdown);
            var modifyInventoryResult = new ModifyInventoryCommand(ProductionUnitOfWork).Execute(inventoryModifications, transaction);

            if (!modifyInventoryResult.Success)
            {
                return(modifyInventoryResult.ConvertTo <ChileLotProduction>());
            }

            return(new SuccessResult <ChileLotProduction>(millAndWetdown));
        }
Пример #10
0
        private static IResult <List <ModifyInventoryParameters> > PostOrder(Parameters parameters, InventoryShipmentOrder order, IEmployeeKey employee)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (employee == null)
            {
                throw new ArgumentNullException("order");
            }

            if (order.OrderStatus == OrderStatus.Fulfilled)
            {
                switch (order.OrderType)
                {
                case InventoryShipmentOrderTypeEnum.InterWarehouseOrder:
                    return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.InterWarehouseOrderAlreadyFulfilled, order.ToInventoryShipmentOrderKey())));

                case InventoryShipmentOrderTypeEnum.TreatmentOrder:
                    return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.TreatmentOrderAlreadyFulfilled, order.ToInventoryShipmentOrderKey())));

                case InventoryShipmentOrderTypeEnum.SalesOrder:
                case InventoryShipmentOrderTypeEnum.MiscellaneousOrder:
                    return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.SalesOrderAlreadyFulfilled, order.ToInventoryShipmentOrderKey())));

                default: throw new ArgumentOutOfRangeException("order.OrderType");
                }
            }

            if (order.ShipmentInformation.Status == ShipmentStatus.Shipped)
            {
                return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.ShipmentStatusCannotPost, order.ShipmentInformation.Status)));
            }

            var inventoryModifications = new List <ModifyInventoryParameters>();

            foreach (var item in order.PickedInventory.Items)
            {
                var pickedItemKey  = new PickedInventoryItemKey(item);
                var itemParameters = parameters.ItemParams.FirstOrDefault(i => i.ItemKey.Equals(pickedItemKey));
                if (itemParameters == null)
                {
                    if (order.DestinationFacility != null)
                    {
                        return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.DestinationLocationRequiredForPicked, pickedItemKey)));
                    }
                }
                else if (itemParameters.DestinationKey != null)
                {
                    if (order.DestinationFacility != null && !order.DestinationFacility.Locations.Any(l => itemParameters.DestinationKey.Equals(l)))
                    {
                        return(new InvalidResult <List <ModifyInventoryParameters> >(null, string.Format(UserMessages.DestinationLocationMustBelongToFacility, new FacilityKey(order.DestinationFacility))));
                    }

                    item.CurrentLocationId = itemParameters.DestinationKey.LocationKey_Id;
                    inventoryModifications.Add(item.ToModifyInventoryDestinationParameters(itemParameters.DestinationKey));
                }
            }

            order.ShipmentInformation.Status = ShipmentStatus.Shipped;
            order.EmployeeId = employee.EmployeeKey_Id;

            return(new SuccessResult <List <ModifyInventoryParameters> >(inventoryModifications));
        }
Пример #11
0
        private tblProduct GetOrCreatePackagingProduct(PackagingProduct packagingProduct, IEmployeeKey employeeKey, DateTime timestamp)
        {
            tblPackaging tblPackaging;
            var          product = _oldContextHelper.GetProductFromPackagingId(packagingProduct.Product.ProductCode, out tblPackaging);

            if (product == null)
            {
                product = new tblProduct
                {
                    ProdID     = _oldContextHelper.GetNextProductId(5),
                    Product    = packagingProduct.Product.Name,
                    ProdGrpID  = 98,
                    PTypeID    = 5,
                    PkgID      = tblPackaging == null ? (int?)null : tblPackaging.PkgID,
                    TrtmtID    = 0,
                    EmployeeID = employeeKey.EmployeeKey_Id,
                    EntryDate  = timestamp.ConvertUTCToLocal(),
                    InActive   = false
                };
                _oldContext.CreateObjectSet <tblProduct>().AddObject(product);
            }

            return(product);
        }
 private static tblOutgoing CreateOutgoingFromBatchItem(tblBatchItem batchItem, IEmployeeKey employeeKey)
 {
     return(new tblOutgoing
     {
         EntryDate = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),
         NewLot = batchItem.NewLot,
         Lot = batchItem.Lot,
         Quantity = batchItem.Quantity,
         TtlWgt = batchItem.TtlWgt,
         EmployeeID = employeeKey.EmployeeKey_Id,
         PkgID = batchItem.PkgID,
         Tote = batchItem.Tote,
         NetWgt = batchItem.NetWgt,
         TTypeID = (int?)TransType.Production,
         BOMID = batchItem.BOMID,
         BatchLot = batchItem.NewLot,
         LocID = batchItem.LocID,
         AstaCalc = batchItem.AstaCalc,
         PackSchID = batchItem.PackSchID,
         TrtmtID = batchItem.TrtmtID,
     });
 }
Пример #13
0
 public static EmployeeKey ToEmployeeKey(this IEmployeeKey k)
 {
     return(new EmployeeKey(k));
 }
        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())));
        }
Пример #15
0
 protected static LotAttribute BuildLotAttribute(AttributeName attributeName, double value, DateTime?testDate = null, bool computed = false, IEmployeeKey employee = null)
 {
     return(new LotAttribute
     {
         AttributeName = attributeName,
         AttributeShortName = attributeName.AttributeNameKey_ShortName,
         AttributeValue = value,
         AttributeDate = testDate ?? DateTime.MinValue,
         TimeStamp = testDate ?? DateTime.MinValue,
         Computed = computed,
         EmployeeId = employee == null ? 0 : employee.EmployeeKey_Id
     });
 }