| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using InABox.Core;
- namespace Comal.Classes
- {
- [UserTracking(typeof(Quote))]
- public class QuoteCostSheet : Entity, IRemotable, IPersistent, IQuoteCostSheet, ILicense<QuotesManagementLicense>,
- IStringAutoIncrement<QuoteCostSheet>
- {
-
- [NullEditor]
- public long Sequence { get; set; }
-
- #region IAutoIncrement
-
- public Expression<Func<QuoteCostSheet, String>> AutoIncrementField() => x => x.Number;
- public String AutoIncrementPrefix() => "QC";
- public virtual string AutoIncrementFormat() => "{0:D6}";
- public Filter<QuoteCostSheet> AutoIncrementFilter() => null;
- public int AutoIncrementDefault() => 1;
-
- #endregion
-
- [NullEditor]
- [Obsolete("Replaced with Parent")]
- [EntityRelationship(DeleteAction.Cascade)]
- public QuoteLink Quote { get; set; }
-
- [CodeEditor]
- [EditorSequence(1)]
- public string Number { get; set; }
-
- [TextBoxEditor(Visible = Visible.Default)]
- [EditorSequence(2)]
- public string Description { get; set; }
-
- private class QuoteCostSheetFormLookup : LookupDefinitionGenerator<QuoteForm, QuoteCostSheet>
- {
- public override Filter<QuoteForm> DefineFilter(QuoteCostSheet[] items)
- {
- if (items?.Any() != true)
- return LookupFactory.DefineFilter<QuoteForm>();
- return new Filter<QuoteForm>(x => x.Parent.ID).IsEqualTo(items.First().Quote.ID);
- }
- public override Columns<QuoteCostSheet> DefineFilterColumns()
- => new Columns<QuoteCostSheet>(ColumnTypeFlags.Required);
- }
- [LookupDefinition(typeof(QuoteCostSheetFormLookup))]
- [EditorSequence(3)]
- public QuoteFormLink Form { get; set; }
-
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(4)]
- public CostSheetLink CostSheet { get; set; }
- [EditorSequence(5)]
- [CurrencyEditor]
- public double Price { get; set; }
-
- [EditorSequence(6)]
- public TaxCodeLink TaxCode { get; set; }
- private class ExTaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
- {
- public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
- x => x.Property(x => x.Price),
- Condition.Equals,
- x => Constant(0.0))
- .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.ExTax)).WithLink(x => x.CostSheet.ID, x => x.ID))
- .Else(Property(x => x.Price));
- }
-
- [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
- [ComplexFormula(typeof(ExTaxFormula))]
- public double ExTax { get; set; }
- private class TaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
- {
- public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
- x => x.Property(x => x.Price),
- Condition.Equals,
- x => x.Constant(0.0))
- .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.Tax)).WithLink(x => x.CostSheet.ID, x => x.ID))
- .Else(Formula(FormulaOperator.Multiply, Property(x => x.Price), Property(x => x.TaxCode.Rate), Constant(0.01)));
- }
-
- [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
- [ComplexFormula(typeof(TaxFormula))]
- public double Tax { get; set; }
- private class IncTaxFormula : ComplexFormulaGenerator<QuoteCostSheet, double>
- {
- public override IComplexFormulaNode<QuoteCostSheet, double> GetFormula() => If<double>(
- x => x.Property(x => x.Price),
- Condition.Equals,
- x => x.Constant(0.0))
- .Then(Aggregate<QuoteCostSheetItem>(AggregateCalculation.Sum, x => x.Property(x => x.IncTax)).WithLink(x => x.CostSheet.ID, x => x.ID))
- .Else(Formula(FormulaOperator.Add, Property(x => x.Price), Property(x => x.Tax)));
- }
-
- [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
- [ComplexFormula(typeof(IncTaxFormula))]
- public double IncTax { get; set; }
-
- }
- }
|