Example #1
0
        internal static IEnumerable <Expression <Func <PackSchedule, ProductionPacketReturn> > > SplitSelectProductionPacket(IInventoryUnitOfWork inventoryUnitOfWork, DateTime currentDate, ILotKey batchKey = null)
        {
            var packScheduleKey          = SelectKey();
            var companyHeader            = CompanyProjectors.SelectHeader();
            var workType                 = WorkTypeProjectors.Select();
            var chileProduct             = ProductProjectors.SelectProduct();
            var productKeyName           = ProductProjectors.SelectProductKeyName();
            var productionBatchPredicate = batchKey != null?ProductionBatchPredicates.ByLotKey(batchKey) : b => true;

            return(ProductionBatchProjectors.SplitSelectProductionPacket(inventoryUnitOfWork, currentDate)
                   .Select(b => Projector <PackSchedule> .To(p => new ProductionPacketReturn
            {
                Batches = p.ProductionBatches.Where(a => productionBatchPredicate.Invoke(a)).Select(a => b.Invoke(a))
            }))
                   .ToAppendedList(Projector <PackSchedule> .To(p => new ProductionPacketReturn
            {
                PackScheduleKeyReturn = packScheduleKey.Invoke(p),
                PSNum = p.PSNum,
                DateCreated = p.DateCreated,
                SummaryOfWork = p.SummaryOfWork
            }),
                                   Projector <PackSchedule> .To(p => new ProductionPacketReturn
            {
                ChileProduct = chileProduct.Invoke(p.ChileProduct.Product),
                PackagingProduct = productKeyName.Invoke(p.PackagingProduct.Product)
            }),
                                   Projector <PackSchedule> .To(p => new ProductionPacketReturn
            {
                ProductionLineDescription = p.ProductionLineLocation.Description,
                WorkType = workType.Invoke(p.WorkType),
                Customer = new[] { p.Customer }.Where(c => c != null).Select(c => companyHeader.Invoke(c.Company)).FirstOrDefault()
            })));
        }
        internal static Expression <Func <LotProductionResults, ProductionRecapLot> > SelectProductionRecap(IQueryable <ProductionBatch> productionBatches)
        {
            var product        = ProductProjectors.SelectChileProductSummary();
            var location       = LocationProjectors.SelectLocation();
            var lotKey         = LotProjectors.SelectLotKey <ChileLotProduction>();
            var batchPredicate = ProductionBatchPredicates.ByLotKeyEntity <LotProductionResults>();
            var batchSelect    = PackScheduleProjectors.SelectProductionRecap();

            return(Projector <LotProductionResults> .To(p => new ProductionRecapLot
            {
                ProductionType = p.Production.ProductionType,
                LotProductionStatus = p.Production.ResultingChileLot.Lot.ProductionStatus,
                LotQualityStatus = p.Production.ResultingChileLot.Lot.QualityStatus,
                OutOfSpec = p.Production.ResultingChileLot.Lot.ProductSpecOutOfRange,
                ProductionBegin = p.ProductionBegin,
                ProductionEnd = p.ProductionEnd,
                ProductionLocation = location.Invoke(p.ProductionLineLocation),

                ChileProduct = product.Invoke(p.Production.ResultingChileLot.ChileProduct),
                LotKey = lotKey.Invoke(p.Production),
                TotalInputWeight = p.Production.PickedInventory.Items.Any() ? p.Production.PickedInventory.Items.Sum(i => i.Quantity *i.PackagingProduct.Weight) : 0.0,
                TotalOutputWeight = p.ResultItems.Any() ? p.ResultItems.Sum(i => i.Quantity *i.PackagingProduct.Weight) : 0.0,
                Shift = p.ShiftKey,

                ProductionBatch = productionBatches.Where(b => batchPredicate.Invoke(p, b)).Select(b => batchSelect.Invoke(b.PackSchedule)).FirstOrDefault(),
                UnresolvedDefects = p.Production.ResultingChileLot.Lot.LotDefects.Where(d => d.Resolution == null).Select(d => d.Description)
            }));
        }
Example #3
0
        public IResult <IInventoryTransactionsByLotReturn> GetLotInputTransactions(string lotKey)
        {
            var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey);

            if (!lotKeyResult.Success)
            {
                return(lotKeyResult.ConvertTo <IInventoryTransactionsByLotReturn>());
            }
            var parsedLotKey = lotKeyResult.ResultingObject.ToLotKey();

            var product = _inventoryUnitOfWork.LotRepository.FilterByKey(parsedLotKey)
                          .Select(LotProjectors.SelectDerivedProduct())
                          .FirstOrDefault();

            var predicate = InventoryTransactionPredicates.ByDestinationLot(parsedLotKey);
            var select    = InventoryTransactionProjectors.Select(_inventoryUnitOfWork);

            var query = _inventoryUnitOfWork.InventoryTransactionsRepository.Filter(predicate).Select(select).ToList();

            var batchPredicate = ProductionBatchPredicates.ByLotKey(parsedLotKey);
            var pickedSelect   = PickedInventoryItemProjectors.SelectTransaction(_inventoryUnitOfWork);
            var pickedResults  = _inventoryUnitOfWork.ProductionBatchRepository
                                 .Filter(batchPredicate.And(b => new[] { b.Production.Results }.All(r => r == null)))
                                 .AsExpandable()
                                 .SelectMany(b => b.Production.PickedInventory.Items.Select(i => pickedSelect.Invoke(i, b)));

            var results = query.ToList <IInventoryTransactionReturn>().Concat(pickedResults).AsQueryable();

            return(new SuccessResult <IInventoryTransactionsByLotReturn>(new InventoryTransactionsByLotReturn
            {
                Product = product,
                InputItems = results
            }));
        }