Supplier.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  47. {
  48. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  49. [EditorSequence(1)]
  50. public string Code { get; set; }
  51. [TextBoxEditor]
  52. [EditorSequence(2)]
  53. public string Name { get; set; }
  54. [EditorSequence(3)]
  55. public String ABN { get; set; }
  56. [TextBoxEditor]
  57. [EditorSequence(4)]
  58. public string Email { get; set; } = "";
  59. [EditorSequence(5)]
  60. public StockLocationLink DefaultLocation { get; set; }
  61. [EditorSequence(6)]
  62. public SupplierCategoryLink Category { get; set; }
  63. [EditorSequence("Delivery",1)]
  64. public Address Delivery { get; set; }
  65. [EditorSequence("Accounts",2)]
  66. public Address Postal { get; set; }
  67. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  68. [Aggregate(typeof(SupplierOrderBalance))]
  69. public double OrderBalance { get; set; }
  70. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  71. [Aggregate(typeof(SupplierTotalBills))]
  72. public double TotalBills { get; set; }
  73. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  74. [Aggregate(typeof(SupplierTotalPayments))]
  75. public double TotalPayments { get; set; }
  76. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  77. [Formula(typeof(SupplierBalance))]
  78. public double Balance { get; set; }
  79. public override string ToString()
  80. {
  81. return string.Format("{0}: {1}", Code, Name);
  82. }
  83. }
  84. }