Invoice.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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, IPostable
  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; } = DateTime.Today;
  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. [NullEditor]
  113. [LoggableProperty]
  114. public PostedStatus PostedStatus { get; set; } = PostedStatus.NeverPosted;
  115. [NullEditor]
  116. [LoggableProperty]
  117. public DateTime Posted { get; set; }
  118. [NullEditor]
  119. public string PostedNote { get; set; }
  120. [NullEditor]
  121. public string PostedReference { get; set; }
  122. public Expression<Func<Invoice, int>> AutoIncrementField()
  123. {
  124. return x => x.Number;
  125. }
  126. public Filter<Invoice>? AutoIncrementFilter()
  127. {
  128. return null;
  129. }
  130. public override string ToString()
  131. {
  132. return string.Format("{0}: {1}", Number, Description);
  133. }
  134. protected override void DoPropertyChanged(string name, object? before, object? after)
  135. {
  136. base.DoPropertyChanged(name, before, after);
  137. if (name.Equals("IncTax"))
  138. Balance = (double)after - AmountPaid;
  139. else if (name.Equals("AmountPaid"))
  140. Balance = IncTax - (double)after;
  141. }
  142. }
  143. }