QuoteCostSheet.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. public int AutoIncrementDefault() => 1;
  20. #endregion
  21. [NullEditor]
  22. [Obsolete("Replaced with Parent")]
  23. [EntityRelationship(DeleteAction.Cascade)]
  24. public QuoteLink Quote { get; set; }
  25. [CodeEditor]
  26. [EditorSequence(1)]
  27. public string Number { get; set; }
  28. [TextBoxEditor(Visible = Visible.Default)]
  29. [EditorSequence(2)]
  30. public string Description { get; set; }
  31. private class QuoteCostSheetFormLookup : LookupDefinitionGenerator<QuoteForm, QuoteCostSheet>
  32. {
  33. public override Filter<QuoteForm> DefineFilter(QuoteCostSheet[] items)
  34. {
  35. if (items?.Any() != true)
  36. return LookupFactory.DefineFilter<QuoteForm>();
  37. return new Filter<QuoteForm>(x => x.Parent.ID).IsEqualTo(items.First().Quote.ID);
  38. }
  39. public override Columns<QuoteCostSheet> DefineFilterColumns()
  40. => new Columns<QuoteCostSheet>(ColumnTypeFlags.Required);
  41. }
  42. [LookupDefinition(typeof(QuoteCostSheetFormLookup))]
  43. [EditorSequence(3)]
  44. public QuoteFormLink Form { get; set; }
  45. [EntityRelationship(DeleteAction.SetNull)]
  46. [EditorSequence(4)]
  47. public CostSheetLink CostSheet { get; set; }
  48. [EditorSequence(5)]
  49. [CurrencyEditor]
  50. public double Price { get; set; }
  51. [EditorSequence(6)]
  52. public TaxCodeLink TaxCode { get; set; }
  53. private class ExTaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
  54. {
  55. public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
  56. x => x.Property(x => x.Price),
  57. Condition.Equals,
  58. x => Constant(0.0))
  59. .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.ExTax)).WithLink(x => x.CostSheet.ID, x => x.ID))
  60. .Else(Property(x => x.Price));
  61. }
  62. [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
  63. [ComplexFormula(typeof(ExTaxFormula))]
  64. public double ExTax { get; set; }
  65. private class TaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
  66. {
  67. public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
  68. x => x.Property(x => x.Price),
  69. Condition.Equals,
  70. x => x.Constant(0.0))
  71. .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.Tax)).WithLink(x => x.CostSheet.ID, x => x.ID))
  72. .Else(Formula(FormulaOperator.Multiply, Property(x => x.Price), Property(x => x.TaxCode.Rate), Constant(0.01)));
  73. }
  74. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  75. [ComplexFormula(typeof(TaxFormula))]
  76. public double Tax { get; set; }
  77. private class IncTaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
  78. {
  79. public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
  80. x => x.Property(x => x.Price),
  81. Condition.Equals,
  82. x => x.Constant(0.0))
  83. .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.IncTax)).WithLink(x => x.CostSheet.ID, x => x.ID))
  84. .Else(Formula(FormulaOperator.Add, Property(x => x.Price), Property(x => x.Tax)));
  85. }
  86. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  87. [ComplexFormula(typeof(IncTaxFormula))]
  88. public double IncTax { get; set; }
  89. }
  90. }