QuoteProposal.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 QuoteProposalExTax : CoreAggregate<QuoteProposal, QuoteProposalCostSheet, double>
  8. {
  9. public override Expression<Func<QuoteProposalCostSheet, double>> Aggregate => x => x.ExTax;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  11. public override Dictionary<Expression<Func<QuoteProposalCostSheet, object>>, Expression<Func<QuoteProposal, object>>> Links =>
  12. new Dictionary<Expression<Func<QuoteProposalCostSheet, object>>, Expression<Func<QuoteProposal, object>>>()
  13. {
  14. { QuoteProposalCostSheet => QuoteProposalCostSheet.Proposal.ID, QuoteProposal => QuoteProposal.ID }
  15. };
  16. }
  17. public class QuoteProposalTax : CoreAggregate<QuoteProposal, QuoteProposalCostSheet, double>
  18. {
  19. public override Expression<Func<QuoteProposalCostSheet, double>> Aggregate => x => x.Tax;
  20. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  21. public override Dictionary<Expression<Func<QuoteProposalCostSheet, object>>, Expression<Func<QuoteProposal, object>>> Links =>
  22. new Dictionary<Expression<Func<QuoteProposalCostSheet, object>>, Expression<Func<QuoteProposal, object>>>()
  23. {
  24. { QuoteProposalCostSheet => QuoteProposalCostSheet.Proposal.ID, QuoteProposal => QuoteProposal.ID }
  25. };
  26. }
  27. public class QuoteProposalIncTax : CoreAggregate<QuoteProposal, QuoteProposalCostSheet, double>
  28. {
  29. public override Expression<Func<QuoteProposalCostSheet, double>> Aggregate => x => x.IncTax;
  30. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  31. public override Dictionary<Expression<Func<QuoteProposalCostSheet, object>>, Expression<Func<QuoteProposal, object>>> Links =>
  32. new Dictionary<Expression<Func<QuoteProposalCostSheet, object>>, Expression<Func<QuoteProposal, object>>>()
  33. {
  34. { QuoteProposalCostSheet => QuoteProposalCostSheet.Proposal.ID, QuoteProposal => QuoteProposal.ID }
  35. };
  36. }
  37. [UserTracking(typeof(Quote))]
  38. public class QuoteProposal : Entity, IRemotable, IPersistent, IQuoteProposal, IOneToMany<Quote>, ILicense<QuotesManagementLicense>
  39. {
  40. [NullEditor]
  41. [EntityRelationship(DeleteAction.Cascade)]
  42. public QuoteLink Quote { get; set; }
  43. [DateEditor(Visible = Visible.Default)]
  44. [EditorSequence(1)]
  45. public DateTime Date { get; set; }
  46. [TextBoxEditor(Visible = Visible.Default)]
  47. [EditorSequence(2)]
  48. public string Description { get; set; }
  49. [EditorSequence(3)]
  50. public double Price { get; set; }
  51. [EditorSequence(4)]
  52. public TaxCodeLink TaxCode { get; set; }
  53. [CheckBoxEditor]
  54. [EditorSequence(5)]
  55. public bool Default { get; set; }
  56. private class ExTaxFormula : ComplexFormulaGenerator<QuoteProposal, double>
  57. {
  58. public override IComplexFormulaNode<QuoteProposal, double> GetFormula() => If<double>(
  59. x => x.Property(x => x.Price),
  60. Condition.Equals,
  61. x => Constant(0.0))
  62. .Then(Aggregate<QuoteProposalCostSheet>(AggregateCalculation.Sum, x => x.Property(x => x.ExTax)).WithLink(x => x.Proposal.ID, x => x.ID))
  63. .Else(Property(x => x.Price));
  64. }
  65. [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
  66. [ComplexFormula(typeof(ExTaxFormula))]
  67. public double ExTax { get; set; }
  68. private class TaxFormula : ComplexFormulaGenerator<QuoteProposal, double>
  69. {
  70. public override IComplexFormulaNode<QuoteProposal, double> GetFormula() => If<double>(
  71. x => x.Property(x => x.Price),
  72. Condition.Equals,
  73. x => x.Constant(0.0))
  74. .Then(Aggregate<QuoteProposalCostSheet>(AggregateCalculation.Sum, x => x.Property(x => x.Tax)).WithLink(x => x.Proposal.ID, x => x.ID))
  75. .Else(Formula(FormulaOperator.Multiply, Property(x => x.Price), Property(x => x.TaxCode.Rate), Constant(0.01)));
  76. }
  77. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  78. [ComplexFormula(typeof(TaxFormula))]
  79. public double Tax { get; set; }
  80. private class IncTaxFormula : ComplexFormulaGenerator<QuoteProposal, double>
  81. {
  82. public override IComplexFormulaNode<QuoteProposal, double> GetFormula() => If<double>(
  83. x => x.Property(x => x.Price),
  84. Condition.Equals,
  85. x => x.Constant(0.0))
  86. .Then(Aggregate<QuoteProposalCostSheet>(AggregateCalculation.Sum, x => x.Property(x => x.IncTax)).WithLink(x => x.Proposal.ID, x => x.ID))
  87. .Else(Formula(FormulaOperator.Add, Property(x => x.Price), Property(x => x.Tax)));
  88. }
  89. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  90. [ComplexFormula(typeof(IncTaxFormula))]
  91. public double IncTax { get; set; }
  92. [RichTextEditor(Visible = Visible.Hidden)]
  93. [EditorSequence("Preamble", 1)]
  94. public string Preamble { get; set; }
  95. [RichTextEditor(Visible = Visible.Hidden)]
  96. [EditorSequence("Summary", 1)]
  97. public string Summary { get; set; }
  98. [NullEditor]
  99. public long Sequence { get; set; }
  100. }
  101. }