Customer.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class CustomerSales : CoreAggregate<Customer, InvoiceLine, double>
  8. {
  9. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.IncTax;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  11. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Customer, object>>> Links =>
  12. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Customer, object>>>()
  13. {
  14. { InvoiceLine => InvoiceLine.InvoiceLink.CustomerLink.ID, Customer => Customer.ID }
  15. };
  16. }
  17. public class CustomerReceipts : CoreAggregate<Customer, InvoiceReceipt, double>
  18. {
  19. public override Expression<Func<InvoiceReceipt, double>> Aggregate => x => x.Amount;
  20. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  21. public override Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Customer, object>>> Links =>
  22. new Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Customer, object>>>()
  23. {
  24. { InvoiceReceipt => InvoiceReceipt.InvoiceLink.CustomerLink.ID, Customer => Customer.ID }
  25. };
  26. }
  27. public class CustomerSites : CoreAggregate<Customer, Customer, Guid>
  28. {
  29. public override Expression<Func<Customer, Guid>> Aggregate => x => x.ID;
  30. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  31. public override Dictionary<Expression<Func<Customer, object>>, Expression<Func<Customer, object>>> Links =>
  32. new Dictionary<Expression<Func<Customer, object>>, Expression<Func<Customer, object>>>()
  33. {
  34. { Customer => Customer.Account.ID, Customer => Customer.ID }
  35. };
  36. }
  37. public class CustomerBalance : IFormula<Customer, double>
  38. {
  39. public Expression<Func<Customer, double>> Value => x => x.TotalSales;
  40. public Expression<Func<Customer, double>>[] Modifiers => new Expression<Func<Customer, double>>[] { x => x.TotalReceipts };
  41. public FormulaOperator Operator => FormulaOperator.Subtract;
  42. public FormulaType Type => FormulaType.Virtual;
  43. }
  44. [UserTracking(typeof(Job))]
  45. public class Customer : Entity, IPersistent, IRemotable, ISchedulable, ILicense<ProjectManagementLicense>, IExportable, IImportable, IMergeable,
  46. IPostable, IPostableFragment<Invoice>, IPostableFragment<Receipt>
  47. {
  48. [EditorSequence(1)]
  49. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  50. public string Code { get; set; }
  51. [EditorSequence(2)]
  52. public string Name { get; set; }
  53. [EditorSequence(3)]
  54. public String ABN { get; set; }
  55. [EditorSequence(4)]
  56. [Caption("Delivery")]
  57. public Address Delivery { get; set; }
  58. [TextBoxEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  59. [Obsolete("Replaced with DefaultContact", false)]
  60. public string Contact { get; set; }
  61. [EditorSequence(5)]
  62. public ContactLink DefaultContact { get; set; }
  63. [EditorSequence(6)]
  64. [TextBoxEditor]
  65. public string Email { get; set; }
  66. [EditorSequence(7)]
  67. public CustomerStatusLink CustomerStatus { get; set; }
  68. [EditorSequence("Accounts", 1)]
  69. [Caption("Bill To")]
  70. public AccountLink Account { get; set; }
  71. [EditorSequence("Accounts", 2)]
  72. [Caption("Address")]
  73. public Address Postal { get; set; }
  74. [EditorSequence("Accounts", 3)]
  75. [Caption("# Sites")]
  76. [IntegerEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  77. [Aggregate(typeof(CustomerSites))]
  78. public int Sites { get; set; }
  79. [EditorSequence("Accounts", 4)]
  80. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  81. [Aggregate(typeof(CustomerSales))]
  82. public double TotalSales { get; set; }
  83. [EditorSequence("Accounts", 5)]
  84. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  85. [Aggregate(typeof(CustomerReceipts))]
  86. public double TotalReceipts { get; set; }
  87. [EditorSequence("Accounts", 6)]
  88. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  89. [Formula(typeof(CustomerBalance))]
  90. public double Balance { get; set; }
  91. [NullEditor]
  92. [Aggregate(typeof(ActiveSchedules))]
  93. public int ActiveSchedules { get; set; }
  94. [NullEditor]
  95. public DateTime Posted { get; set; }
  96. [NullEditor]
  97. [RequiredColumn]
  98. public PostedStatus PostedStatus { get; set; }
  99. [NullEditor]
  100. public string PostedNote { get; set; }
  101. [NullEditor]
  102. public string PostedReference { get; set; }
  103. public override string ToString()
  104. {
  105. return Name;
  106. }
  107. }
  108. }