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. public string Code { get; set; }
  49. [TextBoxEditor]
  50. public string Name { get; set; }
  51. [TextBoxEditor]
  52. public string Email { get; set; }
  53. public Address Delivery { get; set; }
  54. public Address Postal { get; set; }
  55. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  56. [Aggregate(typeof(SupplierOrderBalance))]
  57. public double OrderBalance { get; set; }
  58. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  59. [Aggregate(typeof(SupplierTotalBills))]
  60. public double TotalBills { get; set; }
  61. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  62. [Aggregate(typeof(SupplierTotalPayments))]
  63. public double TotalPayments { get; set; }
  64. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  65. [Formula(typeof(SupplierBalance))]
  66. public double Balance { get; set; }
  67. public StockLocationLink DefaultLocation { get; set; }
  68. public override string ToString()
  69. {
  70. return string.Format("{0}: {1}", Code, Name);
  71. }
  72. protected override void Init()
  73. {
  74. base.Init();
  75. Delivery = new Address();
  76. Postal = new Address();
  77. Email = "";
  78. DefaultLocation = new StockLocationLink();
  79. }
  80. }
  81. }