internal static IEnumerable <Expression <Func <PickedInventoryItem, PickSheetItemReturn> > > SplitSelectPickSheetItem()
        {
            var key              = SelectKey();
            var lotKey           = LotProjectors.SelectLotKey <Lot>();
            var locationKey      = LocationProjectors.SelectLocationKey();
            var loBac            = LotProjectors.SelectLoBac();
            var lotProduct       = LotProjectors.SelectDerivedProduct();
            var packagingProduct = ProductProjectors.SelectPackagingProduct();
            var treatment        = InventoryTreatmentProjectors.SelectInventoryTreatment();

            return(new Projectors <PickedInventoryItem, PickSheetItemReturn>
            {
                i => new PickSheetItemReturn
                {
                    LocationKeyReturn = locationKey.Invoke(i.FromLocation),
                    Description = i.FromLocation.Description,
                    PickedInventoryItemKeyReturn = key.Invoke(i),
                    LotKeyReturn = lotKey.Invoke(i.Lot),
                    Quantity = i.Quantity,
                    LoBac = loBac.Invoke(i.Lot),
                    CustomerProductCode = i.CustomerProductCode
                },
                i => new PickSheetItemReturn
                {
                    LotProduct = lotProduct.Invoke(i.Lot),
                    InventoryTreatment = treatment.Invoke(i.Treatment)
                },
                i => new PickSheetItemReturn
                {
                    PackagingProduct = packagingProduct.Invoke(i.PackagingProduct),
                    NetWeight = i.Quantity * i.PackagingProduct.Weight
                }
            });
        }
        internal static IEnumerable <Expression <Func <PickedInventoryItem, InventoryShipmentOrderItemAnalysisReturn> > > SplitSelectCOAItem()
        {
            var lotKey     = LotProjectors.SelectLotKey <Lot>();
            var loBac      = LotProjectors.SelectLoBac();
            var lotProduct = LotProjectors.SelectDerivedProduct();
            var treatment  = InventoryTreatmentProjectors.SelectInventoryTreatment();
            var attribute  = LotAttributeProjectors.Select();

            return(new Projectors <PickedInventoryItem, InventoryShipmentOrderItemAnalysisReturn>
            {
                i => new InventoryShipmentOrderItemAnalysisReturn
                {
                    LotKeyReturn = lotKey.Invoke(i.Lot),
                    TreatmentReturn = treatment.Invoke(i.Treatment),
                    Attributes = i.Lot.Attributes.Select(a => attribute.Invoke(a)),
                    Notes = i.Lot.Notes
                },
                i => new InventoryShipmentOrderItemAnalysisReturn
                {
                    ProductionDate = new [] { i.Lot.ChileLot }.Where(c => c != null && c.Production != null && c.Production.Results != null)
                    .Select(c => (DateTime?)c.Production.Results.ProductionEnd).FirstOrDefault(),
                },
                i => new InventoryShipmentOrderItemAnalysisReturn
                {
                    LoBac = loBac.Invoke(i.Lot),
                    LotProduct = lotProduct.Invoke(i.Lot),
                }
            });
        }
        internal static Expression <Func <SalesOrder, SalesOrderInvoiceReturn> > SelectCustomerOrderInvoice()
        {
            var contractKey       = ContractProjectors.SelectKey();
            var loBac             = LotProjectors.SelectLoBac();
            var salesOrderItemKey = SalesOrderItemProjectors.SelectKey();

            return(o => new SalesOrderInvoiceReturn
            {
                MovementNumber = o.InventoryShipmentOrder.MoveNum,
                InvoiceDateReturn = o.InvoiceDate,
                PONumber = o.InventoryShipmentOrder.PurchaseOrderNumber,
                FreightCharge = o.FreightCharge,
                InvoiceNotes = o.InvoiceNotes,
                CreditMemo = o.CreditMemo,

                Origin = o.InventoryShipmentOrder.SourceFacility.Name,
                ShipDate = o.InventoryShipmentOrder.ShipmentInformation.ShipmentDate,
                Broker = new[] { o.Broker }.Where(b => b != null).Select(b => b.Name).FirstOrDefault(),
                PaymentTerms = o.PaymentTerms,
                Freight = o.InventoryShipmentOrder.ShipmentInformation.FreightBillType,
                ShipVia = o.InventoryShipmentOrder.ShipmentInformation.ShipmentMethod,

                SoldTo = o.SoldTo,
                ShipTo = o.InventoryShipmentOrder.ShipmentInformation.ShipTo,

                PickedItems = o.SalesOrderPickedItems.Select(i => new SalesOrderInvoicePickedItemReturn
                {
                    SalesOrderItemKeyReturn = salesOrderItemKey.Invoke(i.SalesOrderItem),
                    ProductCode = i.PickedInventoryItem.Lot.ChileLot.ChileProduct.Product.ProductCode,
                    ProductName = i.PickedInventoryItem.Lot.ChileLot.ChileProduct.Product.Name,
                    ProductType = i.PickedInventoryItem.Lot.ChileLot.ChileProduct.ChileType.Description,

                    CustomerProductCode = i.PickedInventoryItem.CustomerProductCode,
                    PackagingName = i.PickedInventoryItem.PackagingProduct.Product.Name,
                    TreatmentNameShort = i.PickedInventoryItem.Treatment.ShortName,
                    QuantityShipped = i.PickedInventoryItem.Quantity,
                    NetWeight = i.PickedInventoryItem.PackagingProduct.Weight * i.PickedInventoryItem.Quantity,
                    LoBac = loBac.Invoke(i.PickedInventoryItem.Lot)
                }),
                OrderItems = o.SalesOrderItems.Select(i => new SalesOrderInvoiceOrderItemReturn
                {
                    ProductCode = i.InventoryPickOrderItem.Product.ProductCode,
                    ProductName = i.InventoryPickOrderItem.Product.Name,
                    PackagingName = i.InventoryPickOrderItem.PackagingProduct.Product.Name,
                    NetWeight = i.InventoryPickOrderItem.PackagingProduct.Weight * i.InventoryPickOrderItem.Quantity,

                    SalesOrderItemKeyReturn = salesOrderItemKey.Invoke(i),
                    ContractKeyReturn = new[] { i.ContractItem }.Where(n => n != null).Select(n => contractKey.Invoke(n.Contract)).FirstOrDefault(),
                    ContractId = new[] { i.ContractItem }.Where(n => n != null).Select(n => n.Contract.ContractId).FirstOrDefault(),
                    QuantityOrdered = i.InventoryPickOrderItem.Quantity,

                    PriceBase = i.PriceBase,
                    PriceFreight = i.PriceFreight,
                    PriceTreatment = i.PriceTreatment,
                    PriceWarehouse = i.PriceWarehouse,
                    PriceRebate = i.PriceRebate
                })
            });
        }