| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Linq.Expressions;using InABox.Clients;using InABox.Core;namespace Comal.Classes{    public class QuoteExTax : CoreAggregate<Quote, QuoteProposal, double>    {        public override Expression<Func<QuoteProposal, double>> Aggregate => x => x.ExTax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> Links =>            new Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> ()            {                { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID }            };        public override Filter<QuoteProposal> Filter => new Filter<QuoteProposal>(x => x.Default).IsEqualTo(true);    }    public class QuoteTax : CoreAggregate<Quote, QuoteProposal, double>    {        public override Expression<Func<QuoteProposal, double>> Aggregate => x => x.Tax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> Links =>            new Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>>()            {                { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID }            };        public override Filter<QuoteProposal> Filter => new Filter<QuoteProposal>(x => x.Default).IsEqualTo(true);    }    public class QuoteIncTax : CoreAggregate<Quote, QuoteProposal, double>    {        public override Expression<Func<QuoteProposal, double>> Aggregate => x => x.IncTax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> Links =>            new Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>>()            {                { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID }            };        public override Filter<QuoteProposal> Filter => new Filter<QuoteProposal>(x => x.Default).IsEqualTo(true);    }    [UserTracking("Quote Management")]    public class Quote : Entity, IRemotable, IPersistent, IStringAutoIncrement<Quote>, ILicense<QuotesManagementLicense>, IDataEntryInstance    {        [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]        [EditorSequence(0)]        public string Number { get; set; }        [TextBoxEditor]        [EditorSequence(1)]        public string Title { get; set; }        [EditorSequence(2)]        public CustomerLink Customer { get; set; }        private class ContactLookup : LookupDefinitionGenerator<Contact, Quote>        {            public override Filter<Contact> DefineFilter(Quote[] items)            {                if (items == null || !items.Any())                    return new Filter<Contact>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);                var customer = items.First().Customer;                if (!customer.IsValid())                    return new Filter<Contact>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);                var contacts = new Client<CustomerContact>().Query(                    new Filter<CustomerContact>(x => x.Customer.ID).IsEqualTo(customer.ID),                    Columns.None<CustomerContact>().Add(x => x.Contact.ID)                );                var ids = contacts.Rows.Select(x => x.Get<CustomerContact, Guid>(c => c.Contact.ID));                if (!ids.Any())                    return new Filter<Contact>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);                return new Filter<Contact>(x => x.ID).InList(ids.ToArray());            }            public override Columns<Quote> DefineFilterColumns()                => Columns.None<Quote>().Add(x => x.Customer.ID);        }        [EditorSequence(3)]        [LookupDefinition(typeof(ContactLookup))]        public ContactLink Contact { get; set; }        [EditorSequence(4)]        public Address SiteAddress { get; set; }        [EditorSequence(5)]        public AccountLink Account { get; set; }                [DoubleEditor(Editable = Editable.Hidden)]        [EditorSequence(6)]        [Aggregate(typeof(QuoteExTax))]        public double ExTax { get; set; }        [DoubleEditor(Editable = Editable.Hidden)]        [EditorSequence(7)]        [Aggregate(typeof(QuoteTax))]        public double Tax { get; set; }        [DoubleEditor(Editable = Editable.Hidden)]        [EditorSequence(8)]        [Aggregate(typeof(QuoteIncTax))]        public double IncTax { get; set; }        [EditorSequence(9)]        public QuoteStatusLink Status { get; set; }                [EditorSequence(10)]        public JobLink Job { get; set; }        #region Management                [TimestampEditor]        [EditorSequence("Management", 1)]        public DateTime DataEntered { get; set; }        [DateEditor]        [EditorSequence("Management", 2)]        public DateTime ReceivedDate { get; set; }        [DateEditor]        [EditorSequence("Management", 3)]        public DateTime DueDate { get; set; }        [DateEditor]        [EditorSequence("Management", 4)]        public DateTime QuoteDate { get; set; }        [DateEditor]        [EditorSequence("Management", 5)]        public DateTime ArchivedDate { get; set; }        [EditorSequence("Management", 6)]        public EmployeeLink Salesperson { get; set; }        #endregion        #region Notes        [NotesEditor]        [EditorSequence("Notes", 1)]        public string[] Notes { get; set; }        #endregion        [DoNotPersist]        [DoNotSerialize]        public static String NumberPrefix { get; set; }                 public Expression<Func<Quote, string>> AutoIncrementField() => x => x.Number;        public Filter<Quote> AutoIncrementFilter() => null;        public string AutoIncrementPrefix() => NumberPrefix;        public string AutoIncrementFormat() => "{0:D6}";        public int AutoIncrementDefault() => 1;                protected override void Init()        {            base.Init();            Customer.Account.PropertyChanged += Account_PropertyChanged;            Customer.Delivery.PropertyChanged += Delivery_PropertyChanged;        }        private void Delivery_PropertyChanged(object sender, PropertyChangedEventArgs e)        {            var value = CoreUtils.GetPropertyValue(Customer.Delivery, e.PropertyName);            CoreUtils.SetPropertyValue(SiteAddress, e.PropertyName, value);        }        private void Account_PropertyChanged(object sender, PropertyChangedEventArgs e)        {            if (e.PropertyName.Equals("ID"))                Account.ID = Customer.Account.ID;            else if (e.PropertyName.Equals("Code"))                Account.Code = Customer.Account.Code;            else if (e.PropertyName.Equals("Name"))                Account.Name = Customer.Account.Name;        }    }}
 |