using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using InABox.Core; namespace Comal.Classes { public class StockLocationHoldings : CoreAggregate { public override Expression> Aggregate => x => x.Product.ID; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { StockHolding => StockHolding.Location.ID, StockLocation => StockLocation.ID }, }; public override AggregateCalculation Calculation => AggregateCalculation.Count; } public enum StockTakeStatus { None, InProgress } [UserTracking(typeof(StockMovement))] public class StockLocation : Entity, IRemotable, IPersistent, IStockLocation, ILicense, IExportable, IImportable { [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)] [EditorSequence(1)] public string Code { get; set; } [TextBoxEditor] [EditorSequence(2)] public string Description { get; set; } [EntityRelationship(DeleteAction.SetNull)] [EditorSequence(3)] public StockWarehouseLink Warehouse { get; set; } private class StockAreaLookup : LookupDefinitionGenerator { public override Filter DefineFilter(StockLocation[] items) { var ids = items.Select(x => x.Warehouse.ID).Distinct().ToArray(); if (ids.Length == 1) return new Filter(x => x.Warehouse.ID).IsEqualTo(ids[0]).And(x => x.Active).IsEqualTo(true); return new Filter(x => x.ID).IsEqualTo(CoreUtils.FullGuid); } public override Columns DefineFilterColumns() => new Columns(x => x.Warehouse.ID); } [LookupDefinition(typeof(StockAreaLookup))] [EntityRelationship(DeleteAction.SetNull)] [EditorSequence(4)] public StockAreaLink Area { get; set; } [EditorSequence(5)] public JobLink Job { get; set; } /// /// Is the location a "shelf" (ie permanent) or "pack" (ie transient) /// [EnumLookupEditor(typeof(StockLocationType))] [EditorSequence(6)] public StockLocationType Type { get; set; } /// /// Is the Stock Location Active? /// [EditorSequence(7)] public bool Active { get; set; } /// /// Mark this location as the default receival location for the warehouse /// [EditorSequence(8)] public bool Default { get; set; } /// /// Mark this location as a favourite which shows up in Timebench Transfer module for quick selection /// [EditorSequence(9)] public bool Favourite { get; set; } = false; [Aggregate(typeof(StockLocationHoldings))] [DoubleEditor(Editable = Editable.Hidden)] [EditorSequence(10)] public double Holdings { get; set; } [EnumLookupEditor(typeof(StockTakeStatus))] [EditorSequence(11)] public StockTakeStatus StocktakeStatus { get; set; } [DateEditor] [EditorSequence(12)] public DateTime LastStocktake { get; set; } } }