Customer.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. {
  47. [EditorSequence(1)]
  48. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  49. public string Code { get; set; }
  50. [EditorSequence(2)]
  51. public string Name { get; set; }
  52. [EditorSequence(3)]
  53. public String ABN { get; set; }
  54. [EditorSequence(4)]
  55. [Caption("Delivery")]
  56. public Address Delivery { get; set; }
  57. [TextBoxEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  58. [Obsolete("Replaced with DefaultContact", false)]
  59. public string Contact { get; set; }
  60. [EditorSequence(5)]
  61. public ContactLink DefaultContact { get; set; }
  62. [EditorSequence(6)]
  63. [TextBoxEditor]
  64. public string Email { get; set; }
  65. [EditorSequence("Accounts", 1)]
  66. [Caption("Bill To")]
  67. public AccountLink Account { get; set; }
  68. [EditorSequence("Accounts", 2)]
  69. [Caption("Address")]
  70. public Address Postal { get; set; }
  71. [EditorSequence("Accounts", 3)]
  72. [Caption("# Sites")]
  73. [IntegerEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  74. [Aggregate(typeof(CustomerSites))]
  75. public int Sites { get; set; }
  76. [EditorSequence("Accounts", 4)]
  77. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  78. [Aggregate(typeof(CustomerSales))]
  79. public double TotalSales { get; set; }
  80. [EditorSequence("Accounts", 5)]
  81. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  82. [Aggregate(typeof(CustomerReceipts))]
  83. public double TotalReceipts { get; set; }
  84. [EditorSequence("Accounts", 6)]
  85. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  86. [Formula(typeof(CustomerBalance))]
  87. public double Balance { get; set; }
  88. [NullEditor]
  89. [Aggregate(typeof(ActiveSchedules))]
  90. public int ActiveSchedules { get; set; }
  91. public override string ToString()
  92. {
  93. return Name;
  94. }
  95. }
  96. }