| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 | using System;using System.Collections.Generic;using System.Linq.Expressions;using InABox.Core;namespace Comal.Classes{    public class CustomerSales : CoreAggregate<Customer, InvoiceLine, double>    {        public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.IncTax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Customer, object>>> Links =>            new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Customer, object>>>()            {                { InvoiceLine => InvoiceLine.InvoiceLink.CustomerLink.ID, Customer => Customer.ID }            };    }    public class CustomerReceipts : CoreAggregate<Customer, InvoiceReceipt, double>    {        public override Expression<Func<InvoiceReceipt, double>> Aggregate => x => x.Amount;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Customer, object>>> Links =>            new Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Customer, object>>>()            {                { InvoiceReceipt => InvoiceReceipt.InvoiceLink.CustomerLink.ID, Customer => Customer.ID }            };    }    public class CustomerSites : CoreAggregate<Customer, Customer, Guid>    {        public override Expression<Func<Customer, Guid>> Aggregate => x => x.ID;        public override AggregateCalculation Calculation => AggregateCalculation.Count;        public override Dictionary<Expression<Func<Customer, object>>, Expression<Func<Customer, object>>> Links =>            new Dictionary<Expression<Func<Customer, object>>, Expression<Func<Customer, object>>>()            {                { Customer => Customer.Account.ID, Customer => Customer.ID }            };    }    public class CustomerBalance : IFormula<Customer, double>    {        public Expression<Func<Customer, double>> Value => x => x.TotalSales;        public Expression<Func<Customer, double>>[] Modifiers => new Expression<Func<Customer, double>>[] { x => x.TotalReceipts };        public FormulaOperator Operator => FormulaOperator.Subtract;        public FormulaType Type => FormulaType.Virtual;    }    [UserTracking(typeof(Job))]    public class Customer : Entity, IPersistent, IRemotable, ISchedulable, ILicense<ProjectManagementLicense>, IExportable, IImportable, IMergeable,        IPostable, IPostableFragment<Invoice>, IPostableFragment<Receipt>    {        [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)]        [LookupDefinition(typeof(AccountsReceivablePaymentTermsLookup<Customer>))]        public PaymentTermsLink Terms { get; set; }                [EditorSequence("Accounts", 5)]        public SalesGLCodeLink GLCode { get; set; }                [EditorSequence("Accounts", 5)]        [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]        [Aggregate(typeof(CustomerSales))]        public double TotalSales { get; set; }        [EditorSequence("Accounts", 6)]        [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]        [Aggregate(typeof(CustomerReceipts))]        public double TotalReceipts { get; set; }        [EditorSequence("Accounts", 7)]        [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]        [Formula(typeof(CustomerBalance))]        public double Balance { get; set; }        [NullEditor]        [ComplexFormula(typeof(ActiveSchedulesFormula<Customer>))]        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;        }        static Customer()        {            LinkedProperties.Register<Customer,PaymentTermsLink,Guid>(x=>x.Account.Terms,x=>x.ID, x=>x.Terms.ID);            LinkedProperties.Register<Customer,PaymentTermsLink,String>(x=>x.Account.Terms,x=>x.Code, x=>x.Terms.Code);            LinkedProperties.Register<Customer,PaymentTermsLink,String>(x=>x.Account.Terms,x=>x.Description, x=>x.Terms.Description);            LinkedProperties.Register<Customer,PaymentTermsLink,String>(x=>x.Account.Terms,x=>x.Calculation, x=>x.Terms.Calculation);            LinkedProperties.Register<Customer,SalesGLCodeLink,Guid>(x=>x.Account.GLCode,x=>x.ID, x=>x.GLCode.ID);            DefaultColumns.Add<Customer>(x => x.Code);            DefaultColumns.Add<Customer>(x => x.Name);            DefaultColumns.Add<Customer>(x => x.Delivery.Street);            DefaultColumns.Add<Customer>(x => x.Delivery.City);        }    }}
 |