Customer.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. [LookupDefinition(typeof(AccountsReceivablePaymentTermsLookup<Customer>))]
  81. public PaymentTermsLink Terms { get; set; }
  82. [EditorSequence("Accounts", 5)]
  83. public SalesGLCodeLink GLCode { get; set; }
  84. [EditorSequence("Accounts", 5)]
  85. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  86. [Aggregate(typeof(CustomerSales))]
  87. public double TotalSales { get; set; }
  88. [EditorSequence("Accounts", 6)]
  89. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  90. [Aggregate(typeof(CustomerReceipts))]
  91. public double TotalReceipts { get; set; }
  92. [EditorSequence("Accounts", 7)]
  93. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  94. [Formula(typeof(CustomerBalance))]
  95. public double Balance { get; set; }
  96. [NullEditor]
  97. [Aggregate(typeof(ActiveSchedules))]
  98. public int ActiveSchedules { get; set; }
  99. [NullEditor]
  100. public DateTime Posted { get; set; }
  101. [NullEditor]
  102. [RequiredColumn]
  103. public PostedStatus PostedStatus { get; set; }
  104. [NullEditor]
  105. public string PostedNote { get; set; }
  106. [NullEditor]
  107. public string PostedReference { get; set; }
  108. public override string ToString()
  109. {
  110. return Name;
  111. }
  112. static Customer()
  113. {
  114. LinkedProperties.Register<Customer,PaymentTermsLink,Guid>(x=>x.Account.Terms,x=>x.ID, x=>x.Terms.ID);
  115. LinkedProperties.Register<Customer,PaymentTermsLink,String>(x=>x.Account.Terms,x=>x.Code, x=>x.Terms.Code);
  116. LinkedProperties.Register<Customer,PaymentTermsLink,String>(x=>x.Account.Terms,x=>x.Description, x=>x.Terms.Description);
  117. LinkedProperties.Register<Customer,PaymentTermsLink,String>(x=>x.Account.Terms,x=>x.Calculation, x=>x.Terms.Calculation);
  118. LinkedProperties.Register<Customer,SalesGLCodeLink,Guid>(x=>x.Account.GLCode,x=>x.ID, x=>x.GLCode.ID);
  119. }
  120. }
  121. }