using System; using System.Collections.Generic; using System.Linq.Expressions; using InABox.Core; namespace Comal.Classes { public class CustomerSales : CoreAggregate { public override Expression> Aggregate => x => x.IncTax; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { InvoiceLine => InvoiceLine.InvoiceLink.CustomerLink.ID, Customer => Customer.ID } }; } public class CustomerReceipts : CoreAggregate { public override Expression> Aggregate => x => x.Amount; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { InvoiceReceipt => InvoiceReceipt.InvoiceLink.CustomerLink.ID, Customer => Customer.ID } }; } public class CustomerSites : CoreAggregate { public override Expression> Aggregate => x => x.ID; public override AggregateCalculation Calculation => AggregateCalculation.Count; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { Customer => Customer.Account.ID, Customer => Customer.ID } }; } public class CustomerBalance : IFormula { public Expression> Value => x => x.TotalSales; public Expression>[] Modifiers => new Expression>[] { x => x.TotalReceipts }; public FormulaOperator Operator => FormulaOperator.Subtract; public FormulaType Type => FormulaType.Virtual; } [UserTracking(typeof(Job))] public class Customer : Entity, IPersistent, IRemotable, ISchedulable, ILicense, IExportable, IImportable, IMergeable, IPostable, IPostableFragment, IPostableFragment { [EditorSequence(1)] [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)] public string Code { get; set; } [EditorSequence(2)] public string Name { get; set; } [EditorSequence(3)] public String ABN { get; set; } [EditorSequence(4)] [Caption("Delivery")] public Address Delivery { get; set; } [TextBoxEditor(Visible = Visible.Optional, Editable = Editable.Disabled)] [Obsolete("Replaced with DefaultContact", false)] public string Contact { get; set; } [EditorSequence(5)] public ContactLink DefaultContact { get; set; } [EditorSequence(6)] [TextBoxEditor] public string Email { get; set; } [EditorSequence(7)] public CustomerStatusLink CustomerStatus { get; set; } [EditorSequence("Accounts", 1)] [Caption("Bill To")] public AccountLink Account { get; set; } [EditorSequence("Accounts", 2)] [Caption("Address")] public Address Postal { get; set; } [EditorSequence("Accounts", 3)] [Caption("# Sites")] [IntegerEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(CustomerSites))] public int Sites { get; set; } [EditorSequence("Accounts", 4)] [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)] [Aggregate(typeof(CustomerSales))] public double TotalSales { get; set; } [EditorSequence("Accounts", 5)] [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)] [Aggregate(typeof(CustomerReceipts))] public double TotalReceipts { get; set; } [EditorSequence("Accounts", 6)] [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Formula(typeof(CustomerBalance))] public double Balance { get; set; } [NullEditor] [Aggregate(typeof(ActiveSchedules))] public int ActiveSchedules { get; set; } [NullEditor] public DateTime Posted { get; set; } [NullEditor] [RequiredColumn] public PostedStatus PostedStatus { get; set; } [NullEditor] public string PostedNote { get; set; } [NullEditor] public string PostedReference { get; set; } public override string ToString() { return Name; } } }