QuoteCostSheet.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. [UserTracking(typeof(Quote))]
  9. public class QuoteCostSheet : Entity, IRemotable, IPersistent, IQuoteCostSheet, ILicense<QuotesManagementLicense>,
  10. IStringAutoIncrement<QuoteCostSheet>
  11. {
  12. [NullEditor]
  13. public long Sequence { get; set; }
  14. #region IAutoIncrement
  15. public Expression<Func<QuoteCostSheet, String>> AutoIncrementField() => x => x.Number;
  16. public String AutoIncrementPrefix() => "QC";
  17. public virtual string AutoIncrementFormat() => "{0:D6}";
  18. public Filter<QuoteCostSheet> AutoIncrementFilter() => null;
  19. #endregion
  20. [NullEditor]
  21. [Obsolete("Replaced with Parent")]
  22. [EntityRelationship(DeleteAction.Cascade)]
  23. public QuoteLink Quote { get; set; }
  24. [CodeEditor]
  25. [EditorSequence(1)]
  26. public string Number { get; set; }
  27. [TextBoxEditor(Visible = Visible.Default)]
  28. [EditorSequence(2)]
  29. public string Description { get; set; }
  30. private class QuoteCostSheetFormLookup : LookupDefinitionGenerator<QuoteForm, QuoteCostSheet>
  31. {
  32. public override Filter<QuoteForm> DefineFilter(QuoteCostSheet[] items)
  33. {
  34. if (items?.Any() != true)
  35. return LookupFactory.DefineFilter<QuoteForm>();
  36. return new Filter<QuoteForm>(x => x.Parent.ID).IsEqualTo(items.First().Quote.ID);
  37. }
  38. public override Columns<QuoteCostSheet> DefineFilterColumns()
  39. => new Columns<QuoteCostSheet>(ColumnTypeFlags.Required);
  40. }
  41. [LookupDefinition(typeof(QuoteCostSheetFormLookup))]
  42. [EditorSequence(3)]
  43. public QuoteFormLink Form { get; set; }
  44. [EntityRelationship(DeleteAction.SetNull)]
  45. [EditorSequence(4)]
  46. public CostSheetLink CostSheet { get; set; }
  47. [EditorSequence(5)]
  48. [CurrencyEditor]
  49. public double Price { get; set; }
  50. [EditorSequence(6)]
  51. public TaxCodeLink TaxCode { get; set; }
  52. private class ExTaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
  53. {
  54. public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
  55. x => x.Property(x => x.Price),
  56. Condition.Equals,
  57. x => Constant(0.0))
  58. .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.ExTax)).WithLink(x => x.CostSheet.ID, x => x.ID))
  59. .Else(Property(x => x.Price));
  60. }
  61. [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
  62. [ComplexFormula(typeof(ExTaxFormula))]
  63. public double ExTax { get; set; }
  64. private class TaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
  65. {
  66. public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
  67. x => x.Property(x => x.Price),
  68. Condition.Equals,
  69. x => x.Constant(0.0))
  70. .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.Tax)).WithLink(x => x.CostSheet.ID, x => x.ID))
  71. .Else(Formula(FormulaOperator.Multiply, Property(x => x.Price), Property(x => x.TaxCode.Rate), Constant(0.01)));
  72. }
  73. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  74. [ComplexFormula(typeof(TaxFormula))]
  75. public double Tax { get; set; }
  76. private class IncTaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
  77. {
  78. public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
  79. x => x.Property(x => x.Price),
  80. Condition.Equals,
  81. x => x.Constant(0.0))
  82. .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.IncTax)).WithLink(x => x.CostSheet.ID, x => x.ID))
  83. .Else(Formula(FormulaOperator.Add, Property(x => x.Price), Property(x => x.Tax)));
  84. }
  85. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  86. [ComplexFormula(typeof(IncTaxFormula))]
  87. public double IncTax { get; set; }
  88. }
  89. }