Quote.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq.Expressions;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. public class QuoteExTax : CoreAggregate<Quote, QuoteProposal, double>
  9. {
  10. public override Expression<Func<QuoteProposal, double>> Aggregate => x => x.ProposalExTax;
  11. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  12. public override Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> Links =>
  13. new Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> ()
  14. {
  15. { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID }
  16. };
  17. public override Filter<QuoteProposal> Filter => new Filter<QuoteProposal>(x => x.Default).IsEqualTo(true);
  18. }
  19. public class QuoteTax : CoreAggregate<Quote, QuoteProposal, double>
  20. {
  21. public override Expression<Func<QuoteProposal, double>> Aggregate => x => x.ProposalTax;
  22. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  23. public override Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> Links =>
  24. new Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>>()
  25. {
  26. { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID }
  27. };
  28. public override Filter<QuoteProposal> Filter => new Filter<QuoteProposal>(x => x.Default).IsEqualTo(true);
  29. }
  30. public class QuoteIncTax : CoreAggregate<Quote, QuoteProposal, double>
  31. {
  32. public override Expression<Func<QuoteProposal, double>> Aggregate => x => x.ProposalIncTax;
  33. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  34. public override Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>> Links =>
  35. new Dictionary<Expression<Func<QuoteProposal, object>>, Expression<Func<Quote, object>>>()
  36. {
  37. { QuoteProposal => QuoteProposal.Quote.ID, Quote => Quote.ID }
  38. };
  39. public override Filter<QuoteProposal> Filter => new Filter<QuoteProposal>(x => x.Default).IsEqualTo(true);
  40. }
  41. [UserTracking("Quote Management")]
  42. public class Quote : Entity, IRemotable, IPersistent, IStringAutoIncrement<Quote>, ILicense<QuotesManagementLicense>, IScannable
  43. {
  44. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  45. [EditorSequence(0)]
  46. public string Number { get; set; }
  47. [TextBoxEditor]
  48. [EditorSequence(1)]
  49. public string Title { get; set; }
  50. [EditorSequence(2)]
  51. public CustomerLink Customer { get; set; }
  52. [EditorSequence(3)]
  53. public ContactLink Contact { get; set; }
  54. [EditorSequence(4)]
  55. public Address SiteAddress { get; set; }
  56. [EditorSequence(5)]
  57. public AccountLink Account { get; set; }
  58. [DoubleEditor(Editable = Editable.Hidden)]
  59. [EditorSequence(6)]
  60. [Aggregate(typeof(QuoteExTax))]
  61. public double ExTax { get; set; }
  62. [DoubleEditor(Editable = Editable.Hidden)]
  63. [EditorSequence(7)]
  64. [Aggregate(typeof(QuoteTax))]
  65. public double Tax { get; set; }
  66. [DoubleEditor(Editable = Editable.Hidden)]
  67. [EditorSequence(8)]
  68. [Aggregate(typeof(QuoteIncTax))]
  69. public double IncTax { get; set; }
  70. [EditorSequence(9)]
  71. public QuoteStatusLink Status { get; set; }
  72. #region Management
  73. [DateEditor]
  74. [EditorSequence("Management", 1)]
  75. public DateTime ReceivedDate { get; set; }
  76. [DateEditor]
  77. [EditorSequence("Management", 2)]
  78. public DateTime DueDate { get; set; }
  79. [DateEditor]
  80. [EditorSequence("Management", 3)]
  81. public DateTime QuoteDate { get; set; }
  82. [DateEditor]
  83. [EditorSequence("Management", 4)]
  84. public DateTime ArchivedDate { get; set; }
  85. [EditorSequence("Management", 5)]
  86. public EmployeeLink Salesperson { get; set; }
  87. #endregion
  88. #region Notes
  89. [NotesEditor]
  90. [EditorSequence("Notes", 1)]
  91. public string[] Notes { get; set; }
  92. #endregion
  93. public Expression<Func<Quote, string>> AutoIncrementField()
  94. {
  95. return x => x.Number;
  96. }
  97. public Filter<Quote> AutoIncrementFilter()
  98. {
  99. return null;
  100. }
  101. public string AutoIncrementFormat()
  102. {
  103. return "{0:D6}";
  104. }
  105. protected override void Init()
  106. {
  107. base.Init();
  108. Status = new QuoteStatusLink();
  109. Customer = new CustomerLink();
  110. Contact = new ContactLink();
  111. Account = new AccountLink();
  112. SiteAddress = new Address();
  113. Salesperson = new EmployeeLink();
  114. Customer.Account.PropertyChanged += Account_PropertyChanged;
  115. Customer.Delivery.PropertyChanged += Delivery_PropertyChanged;
  116. }
  117. private void Delivery_PropertyChanged(object sender, PropertyChangedEventArgs e)
  118. {
  119. var value = CoreUtils.GetPropertyValue(Customer.Delivery, e.PropertyName);
  120. CoreUtils.SetPropertyValue(SiteAddress, e.PropertyName, value);
  121. }
  122. private void Account_PropertyChanged(object sender, PropertyChangedEventArgs e)
  123. {
  124. if (e.PropertyName.Equals("ID"))
  125. Account.ID = Customer.Account.ID;
  126. else if (e.PropertyName.Equals("Code"))
  127. Account.Code = Customer.Account.Code;
  128. else if (e.PropertyName.Equals("Name"))
  129. Account.Name = Customer.Account.Name;
  130. }
  131. }
  132. }