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 IEnumerable <Expression <Func <ContractItem, ContractItemReturn> > > Select() { var key = SelectKey(); var product = ProductProjectors.SelectChileProductSummary(); var packaging = ProductProjectors.SelectPackagingProduct(); var treament = InventoryTreatmentProjectors.SelectInventoryTreatment(); return(new[] { Projector <ContractItem> .To(i => new ContractItemReturn { ContractItemKeyReturn = key.Invoke(i), Treatment = treament.Invoke(i.Treatment), UseCustomerSpec = i.UseCustomerSpec, CustomerProductCode = i.CustomerProductCode, Quantity = i.Quantity, PriceBase = i.PriceBase, PriceFreight = i.PriceFreight, PriceTreatment = i.PriceTreatment, PriceWarehouse = i.PriceWarehouse, PriceRebate = i.PriceRebate }), Projector <ContractItem> .To(i => new ContractItemReturn { ChileProduct = product.Invoke(i.ChileProduct), PackagingProduct = packaging.Invoke(i.PackagingProduct), }) }); }
internal static IEnumerable <Expression <Func <PackSchedule, ScheduledPackScheduleReturn> > > SelectScheduled() { var key = SelectKey(); var ab = SelectAverage(StaticAttributeNames.AB); var scoville = SelectAverage(StaticAttributeNames.Scoville); var scan = SelectAverage(StaticAttributeNames.Scan); var chileProduct = ProductProjectors.SelectChileProductSummary(); return(new Projectors <PackSchedule, ScheduledPackScheduleReturn> { p => new ScheduledPackScheduleReturn { PackScheduleKeyReturn = key.Invoke(p), ProductionDeadline = p.ProductionDeadline, Instructions = p.SummaryOfWork, ChileProduct = chileProduct.Invoke(p.ChileProduct) }, p => new ScheduledPackScheduleReturn { AverageGranularity = p.ChileProduct.Mesh, AverageAoverB = ab.Invoke(p), AverageScoville = scoville.Invoke(p), AverageScan = scan.Invoke(p), } }); }
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 Expression <Func <Customer, IEnumerable <CustomerChileProductAttributeRangesReturn> > > SelectProductSpecs(bool onlyActive = false) { var customerKey = SelectKey(); var productKey = ProductProjectors.SelectChileProductSummary(); var rangeSelect = CustomerProductAttributeRangeProjectors.Select(); return(Projector <Customer> .To(c => c.ProductSpecs .Where(r => r.Active || !onlyActive) .GroupBy(r => r.ChileProduct) .Select(g => new CustomerChileProductAttributeRangesReturn { CustomerKeyReturn = customerKey.Invoke(c), ChileProduct = productKey.Invoke(g.Key), AttributeRanges = g.Select(r => rangeSelect.Invoke(r)) }))); }
private static Expression <Func <ChileMaterialsReceived, ChileMaterialsReceivedReturn> > SelectBase() { var key = LotProjectors.SelectLotKey <ChileMaterialsReceived>(); var chileProduct = ProductProjectors.SelectChileProductSummary(); var company = CompanyProjectors.SelectSummary(); var treatment = InventoryTreatmentProjectors.SelectInventoryTreatment(); return(Projector <ChileMaterialsReceived> .To(m => new ChileMaterialsReceivedReturn { DateReceived = m.DateReceived, LoadNumber = m.LoadNumber, PurchaseOrder = m.ChileLot.Lot.PurchaseOrderNumber, ShipperNumber = m.ChileLot.Lot.ShipperNumber, ChileProduct = chileProduct.Invoke(m.ChileProduct), Supplier = company.Invoke(m.Supplier), Treatment = treatment.Invoke(m.InventoryTreatment), LotKeyReturn = key.Invoke(m), })); }