Supplier.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using System.Runtime.InteropServices;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. public class SupplierOrderBalance : CoreAggregate<Supplier, PurchaseOrderItem, double>
  9. {
  10. public override Expression<Func<PurchaseOrderItem, double>> Aggregate => x => x.Balance;
  11. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  12. public override Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Supplier, object>>> Links =>
  13. new Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Supplier, object>>>()
  14. {
  15. { PurchaseOrderItem => PurchaseOrderItem.PurchaseOrderLink.SupplierLink.ID, Supplier => Supplier.ID }
  16. };
  17. }
  18. public class SupplierTotalBills : CoreAggregate<Supplier, BillLine, double>
  19. {
  20. public override Expression<Func<BillLine, double>> Aggregate => x => x.IncTax;
  21. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  22. public override Dictionary<Expression<Func<BillLine, object>>, Expression<Func<Supplier, object>>> Links =>
  23. new Dictionary<Expression<Func<BillLine, object>>, Expression<Func<Supplier, object>>>()
  24. {
  25. { BillLine => BillLine.BillLink.SupplierLink.ID, Supplier => Supplier.ID }
  26. };
  27. }
  28. public class SupplierTotalPayments : CoreAggregate<Supplier, BillPayment, double>
  29. {
  30. public override Expression<Func<BillPayment, double>> Aggregate => x => x.Amount;
  31. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  32. public override Dictionary<Expression<Func<BillPayment, object>>, Expression<Func<Supplier, object>>> Links =>
  33. new Dictionary<Expression<Func<BillPayment, object>>, Expression<Func<Supplier, object>>>()
  34. {
  35. { BillPayment => BillPayment.BillLink.SupplierLink.ID, Supplier => Supplier.ID }
  36. };
  37. }
  38. public class SupplierBalance : IFormula<Supplier, double>
  39. {
  40. public Expression<Func<Supplier, double>> Value => x => x.TotalBills;
  41. public Expression<Func<Supplier, double>>[] Modifiers => new Expression<Func<Supplier, double>>[] { x => x.TotalPayments };
  42. public FormulaOperator Operator => FormulaOperator.Subtract;
  43. public FormulaType Type => FormulaType.Virtual;
  44. }
  45. [UserTracking(typeof(Bill))]
  46. public class Supplier : Entity, IPersistent, IRemotable, ILicense<CoreLicense>, IExportable, IImportable, IMergeable, IPostable,
  47. IPostableFragment<Bill>, IPostableFragment<PurchaseOrder>, IProblems<ManagedProblem>
  48. {
  49. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  50. [EditorSequence(1)]
  51. public string Code { get; set; }
  52. [TextBoxEditor]
  53. [EditorSequence(2)]
  54. public string Name { get; set; }
  55. [EditorSequence(3)]
  56. public String ABN { get; set; }
  57. [TextBoxEditor]
  58. [EditorSequence(4)]
  59. public string Email { get; set; } = "";
  60. [TextBoxEditor]
  61. [EditorSequence(5)]
  62. public string Telephone { get; set; } = "";
  63. [EditorSequence(6)]
  64. public SupplierStockLocationLink DefaultLocation { get; set; }
  65. [EditorSequence(7)]
  66. public SupplierCategoryLink Category { get; set; }
  67. [EditorSequence(8)]
  68. public SupplierStatusLink SupplierStatus { get; set; }
  69. [EditorSequence("Delivery",1)]
  70. [AddressEditor(true)]
  71. public Address Delivery { get; set; }
  72. [EditorSequence("Accounts",2)]
  73. public Address Postal { get; set; }
  74. [EditorSequence("Accounts",3)]
  75. public ForeignCurrencyLink Currency { get; set; }
  76. [EditorSequence("Accounts", 4)]
  77. [LookupDefinition(typeof(AccountsPayablePaymentTermsLookup<Supplier>))]
  78. public PaymentTermsLink Terms { get; set; }
  79. [EditorSequence("Accounts", 5)]
  80. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  81. [Aggregate(typeof(SupplierOrderBalance))]
  82. public double OrderBalance { get; set; }
  83. [EditorSequence("Accounts", 6)]
  84. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  85. [Aggregate(typeof(SupplierTotalBills))]
  86. public double TotalBills { get; set; }
  87. [EditorSequence("Accounts", 7)]
  88. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  89. [Aggregate(typeof(SupplierTotalPayments))]
  90. public double TotalPayments { get; set; }
  91. [EditorSequence("Accounts", 8)]
  92. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  93. [Formula(typeof(SupplierBalance))]
  94. public double Balance { get; set; }
  95. [NullEditor]
  96. public DateTime Posted { get; set; }
  97. [NullEditor]
  98. [RequiredColumn]
  99. public PostedStatus PostedStatus { get; set; }
  100. [NullEditor]
  101. public string PostedNote { get; set; }
  102. [NullEditor]
  103. public string PostedReference { get; set; }
  104. [EditorSequence("Issues", 1)]
  105. public ManagedProblem Problem { get; set; }
  106. public override string ToString()
  107. {
  108. return string.Format("{0}: {1}", Code, Name);
  109. }
  110. }
  111. }