Invoice.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 InvoiceChargeableHours : CoreAggregate<Invoice, Assignment, TimeSpan>
  8. // {
  9. // public override Expression<Func<Assignment, TimeSpan>> Aggregate => x => x.ChargeableHours;
  10. //
  11. // public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  12. //
  13. // public override Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Invoice, object>>> Links =>
  14. // new Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Invoice, object>>>()
  15. // {
  16. // { Assignment => Assignment.Invoice.ID, Invoice => Invoice.ID }
  17. // };
  18. //
  19. // public override Filter<Assignment>? Filter => new Filter<Assignment>(x => x.Chargeable).IsEqualTo(true);
  20. // }
  21. public class InvoiceExTax : CoreAggregate<Invoice, InvoiceLine, double>
  22. {
  23. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.ExTax;
  24. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  25. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>> Links =>
  26. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>>()
  27. {
  28. { InvoiceLine => InvoiceLine.InvoiceLink.ID, Invoice => Invoice.ID }
  29. };
  30. }
  31. public class InvoiceTax : CoreAggregate<Invoice, InvoiceLine, double>
  32. {
  33. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.Tax;
  34. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  35. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>> Links =>
  36. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>>()
  37. {
  38. { InvoiceLine => InvoiceLine.InvoiceLink.ID, Invoice => Invoice.ID }
  39. };
  40. }
  41. public class InvoiceIncTax : CoreAggregate<Invoice, InvoiceLine, double>
  42. {
  43. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.IncTax;
  44. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  45. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>> Links =>
  46. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>>()
  47. {
  48. { InvoiceLine => InvoiceLine.InvoiceLink.ID, Invoice => Invoice.ID }
  49. };
  50. }
  51. public class InvoiceAmountPaid : CoreAggregate<Invoice, InvoiceReceipt, double>
  52. {
  53. public override Expression<Func<InvoiceReceipt, double>> Aggregate => x => x.Amount;
  54. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  55. public override Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Invoice, object>>> Links =>
  56. new Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Invoice, object>>>()
  57. {
  58. { InvoiceReceipt => InvoiceReceipt.InvoiceLink.ID, Invoice => Invoice.ID }
  59. };
  60. }
  61. public class InvoiceBalance : IFormula<Invoice, double>
  62. {
  63. public Expression<Func<Invoice, double>> Value => x => x.IncTax;
  64. public Expression<Func<Invoice, double>>[] Modifiers => new Expression<Func<Invoice, double>>[] { x => x.AmountPaid };
  65. public FormulaOperator Operator => FormulaOperator.Subtract;
  66. public FormulaType Type => FormulaType.Virtual;
  67. }
  68. [UserTracking("Accounts Receivable")]
  69. public class Invoice : Entity, IPersistent, IRemotable, INumericAutoIncrement<Invoice>, ILicense<AccountsReceivableLicense>, IExportable
  70. {
  71. [EditorSequence(1)]
  72. [IntegerEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  73. public int Number { get; set; }
  74. [EditorSequence(2)]
  75. [DateEditor(Visible = Visible.Default, TodayVisible = true)]
  76. public DateTime Date { get; set; }
  77. [EditorSequence(3)]
  78. [MemoEditor(Visible = Visible.Default)]
  79. public string Description { get; set; }
  80. [EditorSequence(4)]
  81. public JobLink JobLink { get; set; }
  82. [EditorSequence(5)]
  83. public CustomerLink CustomerLink { get; set; }
  84. // [EditorSequence(6)]
  85. // [DurationEditor(Editable = Editable.Hidden)]
  86. // [Aggregate(typeof(InvoiceChargeableHours))]
  87. // public TimeSpan ChargeableHours { get; set; }
  88. [EditorSequence(7)]
  89. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  90. [Aggregate(typeof(InvoiceExTax))]
  91. public double ExTax { get; set; }
  92. [EditorSequence(8)]
  93. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  94. [Aggregate(typeof(InvoiceTax))]
  95. public double Tax { get; set; }
  96. [EditorSequence(9)]
  97. [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden, Summary = Summary.Sum)]
  98. [Aggregate(typeof(InvoiceIncTax))]
  99. public double IncTax { get; set; }
  100. [EditorSequence(10)]
  101. [CurrencyEditor(Editable = Editable.Hidden)]
  102. [Aggregate(typeof(InvoiceExTax))]
  103. public double Total { get; set; }
  104. [EditorSequence(11)]
  105. [CurrencyEditor(Editable = Editable.Hidden)]
  106. [Aggregate(typeof(InvoiceAmountPaid))]
  107. public double AmountPaid { get; set; }
  108. [EditorSequence(12)]
  109. [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  110. [Formula(typeof(InvoiceBalance))]
  111. public double Balance { get; set; }
  112. public Expression<Func<Invoice, int>> AutoIncrementField()
  113. {
  114. return x => x.Number;
  115. }
  116. public Filter<Invoice> AutoIncrementFilter()
  117. {
  118. return null;
  119. }
  120. protected override void Init()
  121. {
  122. base.Init();
  123. JobLink = new JobLink();
  124. CustomerLink = new CustomerLink();
  125. Date = DateTime.Today;
  126. }
  127. public override string ToString()
  128. {
  129. return string.Format("{0}: {1}", Number, Description);
  130. }
  131. protected override void DoPropertyChanged(string name, object before, object after)
  132. {
  133. base.DoPropertyChanged(name, before, after);
  134. if (name.Equals("IncTax"))
  135. Balance = (double)after - AmountPaid;
  136. else if (name.Equals("AmountPaid"))
  137. Balance = IncTax - (double)after;
  138. }
  139. }
  140. }