using System; using System.Collections.Generic; using System.Linq.Expressions; using InABox.Core; namespace Comal.Classes { public class SupplierOrderBalance : CoreAggregate { public override Expression> Aggregate => x => x.Balance; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { PurchaseOrderItem => PurchaseOrderItem.PurchaseOrderLink.SupplierLink.ID, Supplier => Supplier.ID } }; } public class SupplierTotalBills : CoreAggregate { public override Expression> Aggregate => x => x.IncTax; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { BillLine => BillLine.BillLink.SupplierLink.ID, Supplier => Supplier.ID } }; } public class SupplierTotalPayments : CoreAggregate { public override Expression> Aggregate => x => x.Amount; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { BillPayment => BillPayment.BillLink.SupplierLink.ID, Supplier => Supplier.ID } }; } public class SupplierBalance : IFormula { public Expression> Value => x => x.TotalBills; public Expression>[] Modifiers => new Expression>[] { x => x.TotalPayments }; public FormulaOperator Operator => FormulaOperator.Subtract; public FormulaType Type => FormulaType.Virtual; } [UserTracking(typeof(Bill))] public class Supplier : Entity, IPersistent, IRemotable, ILicense, IExportable, IImportable, IMergeable { [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)] public string Code { get; set; } [TextBoxEditor] public string Name { get; set; } [TextBoxEditor] public string Email { get; set; } public Address Delivery { get; set; } public Address Postal { get; set; } [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(SupplierOrderBalance))] public double OrderBalance { get; set; } [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(SupplierTotalBills))] public double TotalBills { get; set; } [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(SupplierTotalPayments))] public double TotalPayments { get; set; } [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Formula(typeof(SupplierBalance))] public double Balance { get; set; } public StockLocationLink DefaultLocation { get; set; } public override string ToString() { return string.Format("{0}: {1}", Code, Name); } protected override void Init() { base.Init(); Delivery = new Address(); Postal = new Address(); Email = ""; DefaultLocation = new StockLocationLink(); } } }