using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq.Expressions; using InABox.Core; namespace Comal.Classes { public class QuoteExTax : CoreAggregate { public override Expression> Aggregate => x => x.ProposalExTax; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>> () { { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID } }; public override Filter Filter => new Filter(x => x.Default).IsEqualTo(true); } public class QuoteTax : CoreAggregate { public override Expression> Aggregate => x => x.ProposalTax; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID } }; public override Filter Filter => new Filter(x => x.Default).IsEqualTo(true); } public class QuoteIncTax : CoreAggregate { public override Expression> Aggregate => x => x.ProposalIncTax; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID } }; public override Filter Filter => new Filter(x => x.Default).IsEqualTo(true); } [UserTracking("Quote Management")] public class Quote : Entity, IRemotable, IPersistent, IStringAutoIncrement, ILicense, IScannable { [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; } [EditorSequence(3)] 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; } #region Management [DateEditor] [EditorSequence("Management", 1)] public DateTime ReceivedDate { get; set; } [DateEditor] [EditorSequence("Management", 2)] public DateTime DueDate { get; set; } [DateEditor] [EditorSequence("Management", 3)] public DateTime QuoteDate { get; set; } [DateEditor] [EditorSequence("Management", 4)] public DateTime ArchivedDate { get; set; } [EditorSequence("Management", 5)] public EmployeeLink Salesperson { get; set; } #endregion #region Notes [NotesEditor] [EditorSequence("Notes", 1)] public string[] Notes { get; set; } #endregion public Expression> AutoIncrementField() { return x => x.Number; } public Filter AutoIncrementFilter() { return null; } public string AutoIncrementFormat() { return "{0:D6}"; } protected override void Init() { base.Init(); Status = new QuoteStatusLink(); Customer = new CustomerLink(); Contact = new ContactLink(); Account = new AccountLink(); SiteAddress = new Address(); Salesperson = new EmployeeLink(); 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; } } }