Quote.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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>
  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. [NotesEditor]
  59. [EditorSequence(6)]
  60. public string[] Notes { get; set; }
  61. [DateEditor]
  62. [EditorSequence(7)]
  63. public DateTime ReceivedDate { get; set; }
  64. [DateEditor]
  65. [EditorSequence(8)]
  66. public DateTime DueDate { get; set; }
  67. [DateEditor]
  68. [EditorSequence(9)]
  69. public DateTime QuoteDate { get; set; }
  70. [DateEditor]
  71. [EditorSequence(10)]
  72. public DateTime ArchivedDate { get; set; }
  73. [EditorSequence(11)]
  74. public EmployeeLink Salesperson { get; set; }
  75. [DoubleEditor(Editable = Editable.Hidden)]
  76. [EditorSequence(12)]
  77. [Aggregate(typeof(QuoteExTax))]
  78. public double ExTax { get; set; }
  79. [DoubleEditor(Editable = Editable.Hidden)]
  80. [EditorSequence(13)]
  81. [Aggregate(typeof(QuoteTax))]
  82. public double Tax { get; set; }
  83. [DoubleEditor(Editable = Editable.Hidden)]
  84. [EditorSequence(14)]
  85. [Aggregate(typeof(QuoteIncTax))]
  86. public double IncTax { get; set; }
  87. [EditorSequence(15)]
  88. public QuoteStatusLink Status { get; set; }
  89. public Expression<Func<Quote, string>> AutoIncrementField()
  90. {
  91. return x => x.Number;
  92. }
  93. public Filter<Quote> AutoIncrementFilter()
  94. {
  95. return null;
  96. }
  97. public string AutoIncrementFormat()
  98. {
  99. return "{0:D6}";
  100. }
  101. protected override void Init()
  102. {
  103. base.Init();
  104. Status = new QuoteStatusLink();
  105. Customer = new CustomerLink();
  106. Contact = new ContactLink();
  107. Account = new AccountLink();
  108. SiteAddress = new Address();
  109. Salesperson = new EmployeeLink();
  110. Customer.Account.PropertyChanged += Account_PropertyChanged;
  111. Customer.Delivery.PropertyChanged += Delivery_PropertyChanged;
  112. }
  113. private void Delivery_PropertyChanged(object sender, PropertyChangedEventArgs e)
  114. {
  115. var value = CoreUtils.GetPropertyValue(Customer.Delivery, e.PropertyName);
  116. CoreUtils.SetPropertyValue(SiteAddress, e.PropertyName, value);
  117. }
  118. private void Account_PropertyChanged(object sender, PropertyChangedEventArgs e)
  119. {
  120. if (e.PropertyName.Equals("ID"))
  121. Account.ID = Customer.Account.ID;
  122. else if (e.PropertyName.Equals("Code"))
  123. Account.Code = Customer.Account.Code;
  124. else if (e.PropertyName.Equals("Name"))
  125. Account.Name = Customer.Account.Name;
  126. }
  127. }
  128. }