Supplier.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 SupplierOrderBalance : CoreAggregate<Supplier, PurchaseOrderItem, double>
  8. {
  9. public override Expression<Func<PurchaseOrderItem, double>> Aggregate => x => x.Balance;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  11. public override Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Supplier, object>>> Links =>
  12. new Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Supplier, object>>>()
  13. {
  14. { PurchaseOrderItem => PurchaseOrderItem.PurchaseOrderLink.SupplierLink.ID, Supplier => Supplier.ID }
  15. };
  16. }
  17. public class SupplierTotalBills : CoreAggregate<Supplier, BillLine, double>
  18. {
  19. public override Expression<Func<BillLine, double>> Aggregate => x => x.IncTax;
  20. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  21. public override Dictionary<Expression<Func<BillLine, object>>, Expression<Func<Supplier, object>>> Links =>
  22. new Dictionary<Expression<Func<BillLine, object>>, Expression<Func<Supplier, object>>>()
  23. {
  24. { BillLine => BillLine.BillLink.SupplierLink.ID, Supplier => Supplier.ID }
  25. };
  26. }
  27. public class SupplierTotalPayments : CoreAggregate<Supplier, BillPayment, double>
  28. {
  29. public override Expression<Func<BillPayment, double>> Aggregate => x => x.Amount;
  30. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  31. public override Dictionary<Expression<Func<BillPayment, object>>, Expression<Func<Supplier, object>>> Links =>
  32. new Dictionary<Expression<Func<BillPayment, object>>, Expression<Func<Supplier, object>>>()
  33. {
  34. { BillPayment => BillPayment.BillLink.SupplierLink.ID, Supplier => Supplier.ID }
  35. };
  36. }
  37. public class SupplierBalance : IFormula<Supplier, double>
  38. {
  39. public Expression<Func<Supplier, double>> Value => x => x.TotalBills;
  40. public Expression<Func<Supplier, double>>[] Modifiers => new Expression<Func<Supplier, double>>[] { x => x.TotalPayments };
  41. public FormulaOperator Operator => FormulaOperator.Subtract;
  42. public FormulaType Type => FormulaType.Virtual;
  43. }
  44. [UserTracking(typeof(Bill))]
  45. public class Supplier : Entity, IPersistent, IRemotable, ILicense<CoreLicense>, IExportable, IImportable, IMergeable
  46. {
  47. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  48. [EditorSequence(1)]
  49. public string Code { get; set; }
  50. [TextBoxEditor]
  51. [EditorSequence(2)]
  52. public string Name { get; set; }
  53. [EditorSequence(3)]
  54. public String ABN { get; set; }
  55. [TextBoxEditor]
  56. [EditorSequence(4)]
  57. public string Email { get; set; } = "";
  58. [EditorSequence(5)]
  59. public StockLocationLink DefaultLocation { get; set; }
  60. [EditorSequence("Delivery",1)]
  61. public Address Delivery { get; set; }
  62. [EditorSequence("Accounts",2)]
  63. public Address Postal { get; set; }
  64. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  65. [Aggregate(typeof(SupplierOrderBalance))]
  66. public double OrderBalance { get; set; }
  67. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  68. [Aggregate(typeof(SupplierTotalBills))]
  69. public double TotalBills { get; set; }
  70. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  71. [Aggregate(typeof(SupplierTotalPayments))]
  72. public double TotalPayments { get; set; }
  73. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  74. [Formula(typeof(SupplierBalance))]
  75. public double Balance { get; set; }
  76. public override string ToString()
  77. {
  78. return string.Format("{0}: {1}", Code, Name);
  79. }
  80. }
  81. }