JobScope.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 JobFinancialInvoiceExTax : CoreAggregate<JobScope, InvoiceLine, double>
  8. {
  9. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.ExTax;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  11. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<JobScope, object>>> Links =>
  12. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<JobScope, object>>>()
  13. {
  14. { InvoiceLine => InvoiceLine.Scope.ID, JobPrice => JobPrice.ID }
  15. };
  16. }
  17. public class JobFinancialInvoiceTax : CoreAggregate<JobScope, InvoiceLine, double>
  18. {
  19. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.Tax;
  20. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  21. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<JobScope, object>>> Links =>
  22. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<JobScope, object>>>()
  23. {
  24. { InvoiceLine => InvoiceLine.Scope.ID, JobPrice => JobPrice.ID }
  25. };
  26. }
  27. public class JobFinancialInvoiceIncTax : CoreAggregate<JobScope, InvoiceLine, double>
  28. {
  29. public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.IncTax;
  30. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  31. public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<JobScope, object>>> Links =>
  32. new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<JobScope, object>>>()
  33. {
  34. { InvoiceLine => InvoiceLine.Scope.ID, JobPrice => JobPrice.ID }
  35. };
  36. }
  37. public class JobFinancialUninvoicedExTax : IFormula<JobScope, double>
  38. {
  39. public Expression<Func<JobScope, double>> Value => x => x.ExTax;
  40. public Expression<Func<JobScope, double>>[] Modifiers => new Expression<Func<JobScope, double>>[] { x => x.InvoiceExTax };
  41. public FormulaOperator Operator => FormulaOperator.Subtract;
  42. public FormulaType Type => FormulaType.Virtual;
  43. }
  44. public interface IJobScopedItem
  45. {
  46. JobLink JobLink { get; set; }
  47. JobScopeLink JobScope { get; set; }
  48. }
  49. [UserTracking(typeof(Job))]
  50. public class JobScope : Entity, IRemotable, IPersistent, ITaxable, IStringAutoIncrement<JobScope>, ILicense<ProjectManagementLicense>
  51. {
  52. [NullEditor]
  53. public InternalJobLink Job { get; set; }
  54. [EnumLookupEditor(typeof(JobScopeType), Visible = Visible.Default)]
  55. [EditorSequence(1)]
  56. public JobScopeType Type { get; set; } = JobScopeType.Variation;
  57. [CodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  58. [EditorSequence(2)]
  59. public string Number { get; set; }
  60. [MemoEditor(Visible = Visible.Default)]
  61. [EditorSequence(3)]
  62. public string Description { get; set; }
  63. [EditorSequence(5)]
  64. public TaxCodeLink TaxCode { get; set; }
  65. [EditorSequence(7)]
  66. public JobScopeStatusLink Status { get; set; }
  67. [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden, Summary = Summary.Sum)]
  68. [Aggregate(typeof(JobFinancialInvoiceExTax))]
  69. public double InvoiceExTax { get; set; }
  70. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden, Summary = Summary.Sum)]
  71. [Aggregate(typeof(JobFinancialInvoiceTax))]
  72. public double InvoiceTax { get; set; }
  73. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden, Summary = Summary.Sum)]
  74. [Aggregate(typeof(JobFinancialInvoiceIncTax))]
  75. public double InvoiceIncTax { get; set; }
  76. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden, Summary = Summary.Sum)]
  77. [Formula(typeof(JobFinancialUninvoicedExTax))]
  78. public double UninvoiceIncTax { get; set; }
  79. public Expression<Func<JobScope, string>> AutoIncrementField() => x => x.Number;
  80. public Filter<JobScope> AutoIncrementFilter() => new Filter<JobScope>(x => x.Job.ID).IsEqualTo(Job.ID);
  81. public String AutoIncrementPrefix() => "";
  82. public string AutoIncrementFormat() => "{0:D3}";
  83. [CurrencyEditor(Summary = Summary.Sum, Visible = Visible.Default)]
  84. [EditorSequence(4)]
  85. public double ExTax { get; set; }
  86. [NullEditor]
  87. public double TaxRate { get; set; }
  88. [NullEditor(Summary = Summary.Sum, Visible = Visible.Optional)]
  89. public double Tax { get; set; }
  90. [CurrencyEditor(Summary = Summary.Sum, Visible = Visible.Optional)]
  91. [EditorSequence(6)]
  92. public double IncTax { get; set; }
  93. static JobScope()
  94. {
  95. LinkedProperties.Register<JobScope, TaxCodeLink, double>(x=>x.TaxCode, x => x.Rate, x => x.TaxRate);
  96. }
  97. public static void LinkScopeProperties<TScoped>() where TScoped : IJobScopedItem
  98. {
  99. LinkedProperties.Register<TScoped, JobScopeLink, Guid>(ass => ass.JobLink.DefaultScope, scope => scope.ID, ass => ass.JobScope.ID);
  100. LinkedProperties.Register<TScoped, JobScopeLink, String>(ass => ass.JobLink.DefaultScope, scope => scope.Number, ass => ass.JobScope.Number);
  101. LinkedProperties.Register<TScoped, JobScopeLink, String>(ass => ass.JobLink.DefaultScope, scope => scope.Description, ass => ass.JobScope.Description);
  102. }
  103. }
  104. }