예제 #1
0
        private void SetOutgoingRecords(tblLot tblLot, ChileLotProduction production)
        {
            foreach (var previousInput in OldContext.tblOutgoings.Where(o => o.NewLot == tblLot.Lot).ToList())
            {
                OldContext.tblOutgoings.DeleteObject(previousInput);
            }

            foreach (var item in production.PickedInventory.Items)
            {
                var sourceLotNumber = LotNumberBuilder.BuildLotNumber(item);
                var packaging       = OldContextHelper.GetPackaging(item.PackagingProduct);

                OldContext.tblOutgoings.AddObject(new tblOutgoing
                {
                    EmployeeID = tblLot.EmployeeID,
                    EntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    Lot     = sourceLotNumber,
                    NewLot  = tblLot.Lot,
                    TTypeID = (int?)TransType.DeHy,

                    PkgID    = packaging.PkgID,
                    Tote     = item.ToteKey,
                    Quantity = item.Quantity,
                    NetWgt   = packaging.NetWgt,
                    TtlWgt   = item.Quantity * packaging.NetWgt,
                    LocID    = item.FromLocation.LocID.Value,
                    TrtmtID  = 0
                });
            }
        }
예제 #2
0
        private tblLot GetOrCreateLot(ChileLotProduction production, out bool newLot)
        {
            newLot = false;
            var lotNumber = LotNumberBuilder.BuildLotNumber(production);
            var tblLot    = OldContext.tblLots
                            .Include(l => l.tblIncomings, l => l.tblOutgoings)
                            .FirstOrDefault(l => l.Lot == lotNumber);

            if (tblLot == null)
            {
                tblLot = new tblLot
                {
                    Lot        = lotNumber,
                    EmployeeID = production.ResultingChileLot.Lot.EmployeeId,
                    EntryDate  = production.ResultingChileLot.Lot.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    PTypeID  = production.LotTypeId,
                    Julian   = lotNumber.Julian,
                    BatchNum = production.LotDateSequence,

                    Shift             = production.Results.ShiftKey,
                    Notes             = "Old Context Synchronization",
                    BatchProdctnOrder = 0,
                    SetTrtmtID        = 0,
                    BatchStatID       = (int?)BatchStatID.Produced,
                    TargetWgt         = 0, //looks like default value set in old context - RI 2014/2/17,
                    tblOutgoings      = new EntityCollection <tblOutgoing>(),
                    tblIncomings      = new EntityCollection <tblIncoming>()
                };
                OldContext.tblLots.AddObject(tblLot);
                newLot = true;
            }

            var product        = OldContextHelper.GetProduct(production.ResultingChileLot.ChileProduct);
            var productionLine = OldContextHelper.GetProductionLine(production.Results.ProductionLineLocation).Value;
            var productionDate = production.LotDateCreated.Date;
            var batchBegTime   = production.Results.ProductionBegin.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var batchEndTime   = production.Results.ProductionEnd.ConvertUTCToLocal().RoundMillisecondsForSQL();

            tblLot.ProdID         = product.ProdID;
            tblLot.ProductionLine = productionLine;
            tblLot.BatchBegTime   = batchBegTime;
            tblLot.BatchEndTime   = batchEndTime;
            tblLot.ProductionDate = productionDate;
            tblLot.Produced       = productionDate;

            return(tblLot);
        }
        internal static ChileLotProduction Set(this ChileLotProduction production, ILotKey lotKey, ProductionType?productionType = null)
        {
            if (production == null)
            {
                throw new ArgumentNullException("production");
            }

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

            if (productionType != null)
            {
                production.ProductionType = productionType.Value;
            }

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