Supplier.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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>
  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. public Address Delivery { get; set; }
  71. [EditorSequence("Accounts",2)]
  72. public Address Postal { get; set; }
  73. [EditorSequence("Accounts",3)]
  74. public ForeignCurrencyLink Currency { get; set; }
  75. [EditorSequence("Accounts", 4)]
  76. [LookupDefinition(typeof(AccountsPayablePaymentTermsLookup<Supplier>))]
  77. public PaymentTermsLink Terms { get; set; }
  78. [EditorSequence("Accounts", 5)]
  79. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  80. [Aggregate(typeof(SupplierOrderBalance))]
  81. public double OrderBalance { get; set; }
  82. [EditorSequence("Accounts", 6)]
  83. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  84. [Aggregate(typeof(SupplierTotalBills))]
  85. public double TotalBills { get; set; }
  86. [EditorSequence("Accounts", 7)]
  87. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  88. [Aggregate(typeof(SupplierTotalPayments))]
  89. public double TotalPayments { get; set; }
  90. [EditorSequence("Accounts", 8)]
  91. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  92. [Formula(typeof(SupplierBalance))]
  93. public double Balance { 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 string.Format("{0}: {1}", Code, Name);
  106. }
  107. }
  108. }