using System; using System.Collections.Generic; using System.Linq; using InABox.Clients; using InABox.Core; namespace Comal.Classes { public class StockLocationLookups : EntityLookup, ILookupDefinition, ILookupDefinition { // If there are multiple items, they must be all in the same warehouse public Filter DefineFilter(Product[] items) { var warehouses = items.Select(x => x.Warehouse.ID).Distinct().ToArray(); if (warehouses.Length == 1) return new Filter(x => x.Active).IsEqualTo(true).And(x => x.Warehouse.ID).IsEqualTo(warehouses.First()); return new Filter(x => x.ID).IsEqualTo(CoreUtils.FullGuid); } public Filter DefineFilter(RequisitionItem[] items) { var productid = items.Select(x => x.Product.ID).FirstOrDefault(); var styleid = items.Select(x => x.Style.ID).FirstOrDefault(); var result =new Filter(x => x.ID).InQuery( new Filter(x => x.Product.ID).IsEqualTo(productid) .And(x=>x.Style.ID).IsEqualTo(styleid), x => x.Location.ID); return result; // var locationids = new Client().Query( // new Filter(x => x.Product.ID).IsEqualTo(productid), // new Columns(x => x.Location.ID) // ).Rows.Select(r => r.Get(c => c.Location.ID)).Distinct().ToArray(); // return new Filter(x => x.ID).InList(locationids); } public override Columns DefineColumns() { return new Columns ( x => x.ID, x => x.Code, x => x.Area.Warehouse.Description, x => x.Area.Description, x => x.Description ); } public override Filter DefineFilter() { return new Filter(x => x.Active).IsEqualTo(true); } public override SortOrder DefineSortOrder() { return new SortOrder(x => x.Code); } public override string FormatLookup(Dictionary values, IEnumerable exclude) { return base.FormatLookup(values, exclude); } } }