Invoice.cs 6.4 KB

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