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) })); }
internal static Expression <Func <PickedInventoryItem, ProductionBatch, PickedForBatchTransactionReturn> > SelectTransaction(ILotUnitOfWork lotUnitOfWork) { var lotKey = LotProjectors.SelectLotKey <Lot>(); var batchLotKey = LotProjectors.SelectLotKey <ProductionBatch>(); var packScheduleKey = PackScheduleProjectors.SelectKey(); var product = LotProjectors.SelectDerivedProduct(); var location = LocationProjectors.SelectLocation(); var treatment = InventoryTreatmentProjectors.SelectInventoryTreatment(); var packaging = ProductProjectors.SelectPackagingProduct(); return(Projector <PickedInventoryItem, ProductionBatch> .To((i, b) => new PickedForBatchTransactionReturn { EmployeeName = i.PickedInventory.Employee.UserName, TimeStamp = i.PickedInventory.TimeStamp, TransactionType = InventoryTransactionType.PickedForBatch, Quantity = -i.Quantity, Weight = -i.Quantity * i.PackagingProduct.Weight, ToteKey = i.ToteKey, SourceLotVendorName = new[] { i.Lot.Vendor }.Where(v => v != null).Select(v => v.Name).FirstOrDefault(), SourceLotPurchaseOrderNumber = i.Lot.PurchaseOrderNumber, SourceLotShipperNumber = i.Lot.ShipperNumber, Product = product.Invoke(i.Lot), Packaging = packaging.Invoke(i.PackagingProduct), Location = location.Invoke(i.FromLocation), Treatment = treatment.Invoke(i.Treatment), SourceLotKeyReturn = lotKey.Invoke(i.Lot), DestinationLotKeyReturn = batchLotKey.Invoke(b), PackScheduleKeyReturn = packScheduleKey.Invoke(b.PackSchedule) })); }
internal static IEnumerable <Expression <Func <ProductionSchedule, ProductionScheduleReportReturn> > > SelectReport() { var batchLotKey = LotProjectors.SelectLotKey <ProductionBatch>(); var chileProduct = ProductProjectors.SelectChileProductSummary(); var packScheduleKey = PackScheduleProjectors.SelectKey(); return(new Projectors <ProductionSchedule, ProductionScheduleReportReturn> { p => new ProductionScheduleReportReturn { Timestamp = p.TimeStamp, ProductionDate = p.ProductionDate, ProductionLocation = p.ProductionLineLocation.Description, ScheduledItems = p.ScheduledItems .Where(i => i.PackSchedule.ProductionBatches.Any(b => !b.ProductionHasBeenCompleted)) .Select(i => new ProductionScheduleItemReportReturn { FlushBefore = i.FlushBefore, FlushBeforeInstructions = i.FlushBeforeInstructions, PackScheduleKeyReturn = packScheduleKey.Invoke(i.PackSchedule), CustomerName = new[] { i.PackSchedule.Customer }.Where(c => c != null).Select(c => c.Company.Name).FirstOrDefault(), WorkType = i.PackSchedule.WorkType.Description, Instructions = i.PackSchedule.SummaryOfWork, ProductionDeadline = i.PackSchedule.ProductionDeadline, OrderNumber = i.PackSchedule.OrderNumber, PackagingProduct = i.PackSchedule.PackagingProduct.Product.Name, FlushAfter = i.FlushAfter, FlushAfterInstructions = i.FlushAfterInstructions, ChileProductReturn = chileProduct.Invoke(i.PackSchedule.ChileProduct) }) }, p => new ProductionScheduleReportReturn { ScheduledItems = p.ScheduledItems .Where(i => i.PackSchedule.ProductionBatches.Any(b => !b.ProductionHasBeenCompleted)) .Select(i => new ProductionScheduleItemReportReturn { ProductionBatches = i.PackSchedule.ProductionBatches.Where(b => !b.ProductionHasBeenCompleted) .OrderBy(b => b.LotTypeId) .ThenBy(b => b.LotDateCreated) .ThenBy(b => b.LotDateSequence) .Select(b => new ProductionScheduleBatchReturn { LotKeyReturn = batchLotKey.Invoke(b) }), Granularity = i.PackSchedule.ChileProduct.Mesh, Scan = i.PackSchedule.ProductionBatches.Where(b => !b.ProductionHasBeenCompleted).Average(b => (double?)b.TargetParameters.BatchTargetScan) }) }, }); }
internal static IEnumerable <Expression <Func <Lot, LotSummaryReturn> > > SplitSelectLotSummary(ILotUnitOfWork lotUnitOfWork, DateTime currentDate) { if (lotUnitOfWork == null) { throw new ArgumentNullException("lotUnitOfWork"); } var attributes = LotAttributeProjectors.Select(); var lotDefects = LotDefectProjectors.SelectLotDefect(); var product = SelectDerivedProduct(); var loBac = SelectLoBac(); var astaCalc = SelectAstaCalc(lotUnitOfWork, currentDate); var customer = PackScheduleProjectors.SelectCustomerHeader(); var productionBatches = lotUnitOfWork.ProductionBatchRepository.All(); var lotKeyFilter = LotPredicates.ConstructLotKeyPredicate <Lot, ProductionBatch>(); return(new[] { SelectLotBase().Merge(l => new LotSummaryReturn { LotDateCreated = l.LotDateCreated, }).ExpandAll(), Projector <Lot> .To(l => new LotSummaryReturn { AstaCalcDate = currentDate, Attributes = l.Attributes.Select(a => attributes.Invoke(a)), Defects = l.LotDefects.OrderBy(d => d.DefectId).Select(d => lotDefects.Invoke(d)) }), Projector <Lot> .To(l => new LotSummaryReturn { LoBac = loBac.Invoke(l), LotProduct = product.Invoke(l), }), Projector <Lot> .To(l => new LotSummaryReturn { AstaCalc = astaCalc.Invoke(l), }), Projector <Lot> .To(l => new LotSummaryReturn { Customer = productionBatches .Where(lotKeyFilter.Invoke(l)) .Select(b => customer.Invoke(b.PackSchedule)).FirstOrDefault() }) }); }
internal static IEnumerable <Expression <Func <ChileLot, LabReportChileLotReturn> > > SplitSelectLabReportChileLot(IQueryable <ProductionBatch> productionBatches, IQueryable <LotProductionResults> lotProdcutionResuls, IQueryable <ChileLotProduction> chileLotProduction) { var chileProductKey = ProductProjectors.SelectProductKey(); var packSchedule = PackScheduleProjectors.SelectBaseWithCustomer(); var productionResult = LotProductionResultsProjectors.SelectBase(); var attribute = LotAttributeProjectors.Select <WeightedLotAttributeReturn>(); var lotTotes = PickedInventoryItemProjectors.SelectPickedLot(); var customerAllowance = LotCustomerAllowanceProjectors.Select(); return(new[] { SelectLotBase().Merge(Projector <ChileLot> .To(c => new LabReportChileLotReturn { LoBac = c.AllAttributesAreLoBac }), c => c.Lot).ExpandAll(), Projector <ChileLot> .To(c => new LabReportChileLotReturn { UnresolvedDefects = c.Lot.LotDefects.Where(d => d.Resolution == null).Select(d => d.Description), WeightedAttributes = c.Lot.Attributes.Select(a => attribute.Invoke(a)), CustomerAllowances = c.Lot.CustomerAllowances.Select(a => customerAllowance.Invoke(a)) }), Projector <ChileLot> .To(c => new LabReportChileLotReturn { WeightedAttributes = c.Lot.Attributes.Select(a => new WeightedLotAttributeReturn { HasResolvedDefects = c.Lot.AttributeDefects.Any(d => d.AttributeShortName == a.AttributeShortName) && c.Lot.AttributeDefects.Where(d => d.AttributeShortName == a.AttributeShortName).All(d => d.LotDefect.Resolution != null) }) }), Projector <ChileLot> .To(c => new LabReportChileLotReturn { ChileProductKeyReturn = chileProductKey.Invoke(c.ChileProduct.Product), PackScheduleBaseReturn = productionBatches.Where(b => b.LotDateCreated == c.LotDateCreated && b.LotDateSequence == c.LotDateSequence && b.LotTypeId == c.LotTypeId) .Select(b => packSchedule.Invoke(b.PackSchedule)).FirstOrDefault() }), Projector <ChileLot> .To(c => new LabReportChileLotReturn { ProductionResultBaseReturn = lotProdcutionResuls.Where(r => r.LotDateCreated == c.LotDateCreated && r.LotDateSequence == c.LotDateSequence && r.LotTypeId == c.LotTypeId) .Select(r => productionResult.Invoke(r)).FirstOrDefault(), PickedLots = chileLotProduction.Where(r => r.LotDateCreated == c.LotDateCreated && r.LotDateSequence == c.LotDateSequence && r.LotTypeId == c.LotTypeId) .SelectMany(r => r.PickedInventory.Items.Select(i => lotTotes.Invoke(i))) }) }); }
internal static IEnumerable <Expression <Func <ProductionBatch, ProductionBatchDetailReturn> > > SplitSelectDetail(Data.Interfaces.UnitsOfWork.IProductionUnitOfWork productionUnitOfWork, DateTime currentDate) { if (productionUnitOfWork == null) { throw new ArgumentNullException("productionUnitOfWork"); } var packScheduleKey = PackScheduleProjectors.SelectKey(); var productKey = ProductProjectors.SelectProductKey(); var chileProduct = ProductProjectors.SelectChileProductWithIngredients(); var workType = WorkTypeProjectors.Select(); var notebook = NotebookProjectors.Select(); var pickedChile = PickedInventoryProjectors.SelectPickedChileInventoryItem(productionUnitOfWork); var pickedPackaging = PickedInventoryProjectors.SelectPickedPackagingInventoryItem(productionUnitOfWork); var pickedAdditve = PickedInventoryProjectors.SelectPickedAdditiveInventoryItem(productionUnitOfWork); var pickedItemProjectors = PickedInventoryItemProjectors.SplitSelect(productionUnitOfWork, currentDate); return(new[] { SelectSummary().Merge(b => new ProductionBatchDetailReturn { HasProductionBeenCompleted = b.ProductionHasBeenCompleted, }).ExpandAll(), Projector <ProductionBatch> .To(b => new ProductionBatchDetailReturn { PackScheduleKeyReturn = packScheduleKey.Invoke(b.PackSchedule), ChileProductKeyReturn = productKey.Invoke(b.Production.ResultingChileLot.ChileProduct.Product), ChileProductName = b.Production.ResultingChileLot.ChileProduct.Product.Name, ChileProductWithIngredients = chileProduct.Invoke(b.Production.ResultingChileLot.ChileProduct) }), Projector <ProductionBatch> .To(b => new ProductionBatchDetailReturn { WorkType = workType.Invoke(b.PackSchedule.WorkType), InstructionsNotebook = notebook.Invoke(b.InstructionNotebook) }), Projector <ProductionBatch> .To(b => new ProductionBatchDetailReturn { PickedChileItems = pickedChile.Invoke(b.Production.PickedInventory), PickedPackagingItems = pickedPackaging.Invoke(b.Production.PickedInventory), PickedAdditiveItems = pickedAdditve.Invoke(b.Production.PickedInventory) }) }.ToAppendedList(pickedItemProjectors.Select(p => Projector <ProductionBatch> .To(b => new ProductionBatchDetailReturn { PickedInventoryItems = b.Production.PickedInventory.Items.Select(i => p.Invoke(i)) })))); }
internal static IEnumerable <Expression <Func <ProductionScheduleItem, ProductionScheduleItemReturn> > > Select() { var packSchedule = PackScheduleProjectors.SelectScheduled(); return(new Projectors <ProductionScheduleItem, ProductionScheduleItemReturn> { i => new ProductionScheduleItemReturn { Index = i.Index, FlushBefore = i.FlushBefore, FlushBeforeInstructions = i.FlushBeforeInstructions, FlushAfter = i.FlushAfter, FlushAfterInstructions = i.FlushAfterInstructions, }, { packSchedule, p => i => new ProductionScheduleItemReturn { PackSchedule = p.Invoke(i.PackSchedule) } } }); }
internal static IEnumerable <Expression <Func <ProductionBatch, ProductionPacketReturn> > > SplitSelectProductionPacketFromBatch(IInventoryUnitOfWork inventoryUnitOfWork, DateTime currentDate, ILotKey batchKey) { return(PackScheduleProjectors.SplitSelectProductionPacket(inventoryUnitOfWork, currentDate, batchKey) .Select(b => Projector <ProductionBatch> .To(a => b.Invoke(a.PackSchedule)))); }