Customer.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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, decimal>
  8. {
  9. public override Expression<Func<InvoiceLine, decimal>> 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.Invoice.Customer.ID, Customer => Customer.ID }
  15. };
  16. }
  17. public class CustomerReceipts : CoreAggregate<Customer, InvoiceReceipt, decimal>
  18. {
  19. public override Expression<Func<InvoiceReceipt, decimal>> 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.Invoice.Customer.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, decimal>
  38. {
  39. public Expression<Func<Customer, decimal>> Value => x => x.TotalSales;
  40. public Expression<Func<Customer, decimal>>[] Modifiers => new Expression<Func<Customer, decimal>>[] { 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. [EditorSequence(5)]
  59. public ContactLink DefaultContact { get; set; }
  60. [EditorSequence(6)]
  61. [TextBoxEditor]
  62. public string Email { get; set; }
  63. [EditorSequence(7)]
  64. public CustomerStatusLink CustomerStatus { 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. [LookupDefinition(typeof(AccountsReceivablePaymentTermsLookup<Customer>))]
  78. public PaymentTermsLink Terms { get; set; }
  79. [EditorSequence("Accounts", 5)]
  80. public SalesGLCodeLink GLCode { get; set; }
  81. [EditorSequence("Accounts", 5)]
  82. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  83. [Aggregate(typeof(CustomerSales))]
  84. public decimal TotalSales { get; set; }
  85. [EditorSequence("Accounts", 6)]
  86. [CurrencyEditor(Editable = Editable.Disabled, Summary = Summary.Sum)]
  87. [Aggregate(typeof(CustomerReceipts))]
  88. public decimal TotalReceipts { get; set; }
  89. [EditorSequence("Accounts", 7)]
  90. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  91. [Formula(typeof(CustomerBalance))]
  92. public decimal Balance { get; set; }
  93. [EditorSequence("Accounts", 8)]
  94. [DecimalEditor]
  95. public decimal Markup { get; set; }
  96. [NullEditor]
  97. [ComplexFormula(typeof(ActiveSchedulesFormula<Customer>))]
  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. DefaultColumns.Add<Customer>(x => x.Code);
  120. DefaultColumns.Add<Customer>(x => x.Name);
  121. DefaultColumns.Add<Customer>(x => x.Delivery.Street);
  122. DefaultColumns.Add<Customer>(x => x.Delivery.City);
  123. }
  124. }
  125. }