using System; using System.Collections.Generic; using System.Linq.Expressions; using InABox.Core; using PRSClasses; namespace Comal.Classes { // public class StockHoldingViewQtyAggregate : CoreAggregate // { // public override Expression> Aggregate => x => x.Qty; // public override AggregateCalculation Calculation => AggregateCalculation.Sum; // } // // public class StockHoldingViewUnitsFormula : IFormula // { // public Expression> Value => x => x.Qty; // // public Expression>[] Modifiers => new Expression>[] { x => x.Dimensions.Value }; // // public FormulaOperator Operator => FormulaOperator.Divide; // } // // public class StockHoldingViewIsRemnantCondition : ICondition // { // public Expression> Left => x => x.Dimensions.Value; // // public Condition Condition => Condition.LessThan; // // public Expression> Right => x => x.Product.Dimensions.Value; // // public Expression> True => x => true; // // public Expression> False => x => null; // } // // public class StockHoldingView : Entity, IRemotable, IPersistent, IView, IStockHolding // { // public ProductLink Product { get; set; } // // public ProductStyleLink Style { get; set; } // // public StockLocationLink Location { get; set; } // // public JobLink Job { get; set; } // // public StockDimensions Dimensions { get; set; } // // [Condition(typeof(StockHoldingViewIsRemnantCondition))] // public bool IsRemnant { get; set; } // // [Aggregate(typeof(StockHoldingViewQtyAggregate))] // public double Qty { get; set; } // // [Formula(typeof(StockHoldingViewUnitsFormula))] // public double Units { get; set; } // // protected override void Init() // { // base.Init(); // Product = new ProductLink(); // Location = new StockLocationLink(); // Job = new JobLink(); // Style = new ProductStyleLink(); // Dimensions = new StockDimensions(); // } // } public class StockHoldingUnitAggregate : CoreAggregate { public override Expression> Aggregate => x => x.Units; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { StockMovement => StockMovement.Product.ID, StockHolding => StockHolding.Product.ID }, { StockMovement => StockMovement.Job.ID, StockHolding => StockHolding.Job.ID }, { StockMovement => StockMovement.Location.ID, StockHolding => StockHolding.Location.ID }, { StockMovement => StockMovement.Style.ID, StockHolding => StockHolding.Style.ID }, { StockMovement => StockMovement.Dimensions.UnitSize, StockHolding => StockHolding.Dimensions.UnitSize } }; public override AggregateCalculation Calculation => AggregateCalculation.Sum; } public class StockHoldingQuantityAggregate : CoreAggregate { public override Expression> Aggregate => x => x.Qty; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { StockMovement => StockMovement.Product.ID, StockHolding => StockHolding.Product.ID }, { StockMovement => StockMovement.Job.ID, StockHolding => StockHolding.Job.ID }, { StockMovement => StockMovement.Location.ID, StockHolding => StockHolding.Location.ID }, { StockMovement => StockMovement.Style.ID, StockHolding => StockHolding.Style.ID }, { StockMovement => StockMovement.Dimensions.UnitSize, StockHolding => StockHolding.Dimensions.UnitSize } }; public override AggregateCalculation Calculation => AggregateCalculation.Sum; } public class StockHoldingWeightFormula : IFormula { public Expression> Value => x => x.Qty; public Expression>[] Modifiers => new Expression>[] { x => x.Dimensions.Weight }; public FormulaOperator Operator => FormulaOperator.Multiply; public FormulaType Type => FormulaType.Virtual; } public class StockHoldingIsRemnantCondition : ICondition { public Expression> Left => x => x.Dimensions.Value; public Condition Condition => Condition.LessThan; public Expression> Right => x => x.Product.Dimensions.Value; public Expression> True => x => true; public Expression> False => x => null; public ConditionType Type => ConditionType.Virtual; } public class StockHoldingUnionGenerator : AutoEntityUnionGenerator { protected override void Configure() { AddTable(); } public override bool Distinct => true; public override Column[] IDColumns => new Column[] { new Column(x => x.Job.ID), new Column(x => x.Location.ID), new Column(x => x.Product.ID), new Column(x => x.Style.ID), new Column(x => x.Dimensions.Unit.ID), new Column(x => x.Dimensions.Quantity), new Column(x => x.Dimensions.Length), new Column(x => x.Dimensions.Width), new Column(x => x.Dimensions.Height), new Column(x => x.Dimensions.Weight), }; } [UserTracking(typeof(StockMovement))] [AutoEntity(typeof(StockHoldingUnionGenerator))] public class StockHolding : StockEntity, IRemotable, IPersistent, IOneToMany, IOneToMany, IStockHolding, ILicense { public override ProductLink Product { get; set; } public ProductStyleLink Style { get; set; } public StockLocationLink Location { get; set; } public JobLink Job { get; set; } [RequiredColumn] [DimensionsEditor(typeof(StockDimensions), AllowEditingUnit = false)] public override StockDimensions Dimensions { get; set; } [Condition(typeof(StockHoldingIsRemnantCondition))] public bool IsRemnant { get; set; } [Aggregate(typeof(StockHoldingUnitAggregate))] [DoubleEditor(Editable = Editable.Disabled)] public double Units { get; set; } [Aggregate(typeof(StockHoldingQuantityAggregate))] [DoubleEditor(Editable = Editable.Disabled)] public double Qty { get; set; } [Formula(typeof(StockHoldingWeightFormula))] public double Weight { get; set; } //[DoubleEditor(Editable = Editable.Disabled)] /*[NullEditor] [Obsolete("Replaced with Dimensions", true)] public double UnitSize { get; set; }*/ protected override void Init() { base.Init(); Location = new StockLocationLink(); Job = new JobLink(); Style = new ProductStyleLink(); } } }