| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq.Expressions;
 
- using InABox.Core;
 
- namespace Comal.Classes
 
- {
 
-     public enum InvoiceType
 
-     {
 
-         Standard,
 
-         ProgressClaim
 
-     }
 
-     [UserTracking("Accounts Receivable")]
 
-     public class Invoice : Entity, IPersistent, IRemotable, INumericAutoIncrement<Invoice>, ILicense<AccountsReceivableLicense>, IExportable, IPostable
 
-     {
 
-         [EditorSequence(1)]
 
-         [IntegerEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
 
-         public int Number { get; set; }
 
-         [EditorSequence(2)]
 
-         [DateEditor(Visible = Visible.Default, TodayVisible = true)]
 
-         public DateTime Date { get; set; } = DateTime.Today;
 
-         [EditorSequence(3)]
 
-         [MemoEditor(Visible = Visible.Default)]
 
-         public string Description { get; set; }
 
-         [EditorSequence(4)]
 
-         public JobLink JobLink { get; set; }
 
-         [EditorSequence(5)]
 
-         public CustomerLink CustomerLink { get; set; }
 
-         private class ClaimedFormula : ComplexFormulaGenerator<Invoice, double>
 
-         {
 
-             public override IComplexFormulaNode<Invoice, double> GetFormula() =>
 
-                 Aggregate<InvoiceLine>(AggregateCalculation.Sum, x => x.Property(x => x.ExTax))
 
-                     .WithLink(x => x.InvoiceLink.ID, x => x.ID);
 
-         }
 
-         [EditorSequence(6)]
 
-         [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
 
-         [ComplexFormula(typeof(ClaimedFormula))]
 
-         public double Claimed { get; set; }
 
-         
 
-         [EditorSequence(7)]
 
-         [CurrencyEditor(Summary = Summary.Sum)]
 
-         public double Retained { get; set; }
 
-         
 
-         private class ExTaxFormula : ComplexFormulaGenerator<Invoice, double>
 
-         {
 
-             public override IComplexFormulaNode<Invoice, double> GetFormula() =>
 
-                 Formula(FormulaOperator.Subtract, Property(x => x.Claimed), Property(x => x.Retained));
 
-         }
 
-         [EditorSequence(8)]
 
-         [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
 
-         [ComplexFormula(typeof(ExTaxFormula))]
 
-         public double ExTax { get; set; }
 
-         private class TaxFormula : ComplexFormulaGenerator<Invoice, double>
 
-         {
 
-             public override IComplexFormulaNode<Invoice, double> GetFormula() =>
 
-                 Aggregate<InvoiceLine>(AggregateCalculation.Sum, x => x.Property(x => x.Tax))
 
-                     .WithLink(x => x.InvoiceLink.ID, x => x.ID);
 
-         }
 
-         [EditorSequence(9)]
 
-         [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
 
-         [ComplexFormula(typeof(TaxFormula))]
 
-         public double Tax { get; set; }
 
-         private class IncTaxFormula : ComplexFormulaGenerator<Invoice, double>
 
-         {
 
-             public override IComplexFormulaNode<Invoice, double> GetFormula() =>
 
-                 Aggregate<InvoiceLine>(AggregateCalculation.Sum, x => x.Property(x => x.IncTax))
 
-                     .WithLink(x => x.InvoiceLink.ID, x => x.ID);
 
-         }
 
-         [EditorSequence(10)]
 
-         [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden, Summary = Summary.Sum)]
 
-         [ComplexFormula(typeof(IncTaxFormula))]
 
-         public double IncTax { get; set; }
 
-         private class AmountPaidFormula : ComplexFormulaGenerator<Invoice, double>
 
-         {
 
-             public override IComplexFormulaNode<Invoice, double> GetFormula() =>
 
-                 Aggregate<InvoiceReceipt>(AggregateCalculation.Sum, x => x.Property(x => x.Amount))
 
-                     .WithLink(x => x.InvoiceLink.ID, x => x.ID);
 
-         }
 
-         [EditorSequence(11)]
 
-         [CurrencyEditor(Editable = Editable.Hidden)]
 
-         [ComplexFormula(typeof(AmountPaidFormula))]
 
-         public double AmountPaid { get; set; }
 
-         private class BalanceFormula : ComplexFormulaGenerator<Invoice, double>
 
-         {
 
-             public override IComplexFormulaNode<Invoice, double> GetFormula() =>
 
-                 Formula(FormulaOperator.Subtract, Property(x => x.IncTax), Property(x => x.AmountPaid));
 
-         }
 
-         /// <summary>
 
-         /// Balance = <see cref="IncTax"/> - <see cref="AmountPaid"/>.
 
-         /// </summary>
 
-         [EditorSequence(12)]
 
-         [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
 
-         [ComplexFormula(typeof(BalanceFormula))]
 
-         public double Balance { get; set; }
 
-         
 
-         [NullEditor]
 
-         [LoggableProperty]
 
-         [RequiredColumn]
 
-         public PostedStatus PostedStatus { get; set; } = PostedStatus.NeverPosted;
 
-         [NullEditor]
 
-         [LoggableProperty]
 
-         public DateTime Posted { get; set; }
 
-         [NullEditor]
 
-         public string PostedNote { get; set; }
 
-         [NullEditor]
 
-         public string PostedReference { get; set; }
 
-         
 
-         [NullEditor]
 
-         public InvoiceType Type { get; set; }
 
-         public Expression<Func<Invoice, int>> AutoIncrementField()
 
-         {
 
-             return x => x.Number;
 
-         }
 
-         public Filter<Invoice>? AutoIncrementFilter()
 
-         {
 
-             return null;
 
-         }
 
-         public override string ToString()
 
-         {
 
-             return string.Format("{0}: {1}", Number, Description);
 
-         }
 
-         protected override void DoPropertyChanged(string name, object? before, object? after)
 
-         {
 
-             base.DoPropertyChanged(name, before, after);
 
-             if (name.Equals("IncTax"))
 
-                 Balance = (double)after - AmountPaid;
 
-             else if (name.Equals("AmountPaid"))
 
-                 Balance = IncTax - (double)after;
 
-         }
 
-         
 
-     }
 
- }
 
 
  |