| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 | using System;using System.Collections.Generic;using System.Linq.Expressions;using InABox.Core;namespace Comal.Classes{    // public class InvoiceChargeableHours : CoreAggregate<Invoice, Assignment, TimeSpan>    // {    //     public override Expression<Func<Assignment, TimeSpan>> Aggregate => x => x.ChargeableHours;    //    //     public override AggregateCalculation Calculation => AggregateCalculation.Sum;    //    //     public override Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Invoice, object>>> Links =>    //         new Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Invoice, object>>>()    //         {    //             { Assignment => Assignment.Invoice.ID, Invoice => Invoice.ID }    //         };    //    //     public override Filter<Assignment>? Filter => new Filter<Assignment>(x => x.Chargeable).IsEqualTo(true);    // }    public class InvoiceExTax : CoreAggregate<Invoice, InvoiceLine, double>    {        public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.ExTax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>> Links =>            new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>>()            {                { InvoiceLine => InvoiceLine.InvoiceLink.ID, Invoice => Invoice.ID }            };    }    public class InvoiceTax : CoreAggregate<Invoice, InvoiceLine, double>    {        public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.Tax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>> Links =>            new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>>()            {                { InvoiceLine => InvoiceLine.InvoiceLink.ID, Invoice => Invoice.ID }            };    }    public class InvoiceIncTax : CoreAggregate<Invoice, InvoiceLine, double>    {        public override Expression<Func<InvoiceLine, double>> Aggregate => x => x.IncTax;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>> Links =>            new Dictionary<Expression<Func<InvoiceLine, object>>, Expression<Func<Invoice, object>>>()            {                { InvoiceLine => InvoiceLine.InvoiceLink.ID, Invoice => Invoice.ID }            };    }    public class InvoiceAmountPaid : CoreAggregate<Invoice, InvoiceReceipt, double>    {        public override Expression<Func<InvoiceReceipt, double>> Aggregate => x => x.Amount;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Invoice, object>>> Links =>            new Dictionary<Expression<Func<InvoiceReceipt, object>>, Expression<Func<Invoice, object>>>()            {                { InvoiceReceipt => InvoiceReceipt.InvoiceLink.ID, Invoice => Invoice.ID }            };    }    public class InvoiceBalance : IFormula<Invoice, double>    {        public Expression<Func<Invoice, double>> Value => x => x.IncTax;        public Expression<Func<Invoice, double>>[] Modifiers => new Expression<Func<Invoice, double>>[] { x => x.AmountPaid };        public FormulaOperator Operator => FormulaOperator.Subtract;        public FormulaType Type => FormulaType.Virtual;    }    [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; }        // [EditorSequence(6)]        // [DurationEditor(Editable = Editable.Hidden)]        // [Aggregate(typeof(InvoiceChargeableHours))]        // public TimeSpan ChargeableHours { get; set; }        [EditorSequence(7)]        [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]        [Aggregate(typeof(InvoiceExTax))]        public double ExTax { get; set; }        [EditorSequence(8)]        [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]        [Aggregate(typeof(InvoiceTax))]        public double Tax { get; set; }        [EditorSequence(9)]        [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden, Summary = Summary.Sum)]        [Aggregate(typeof(InvoiceIncTax))]        public double IncTax { get; set; }        [EditorSequence(10)]        [CurrencyEditor(Editable = Editable.Hidden)]        [Aggregate(typeof(InvoiceExTax))]        public double Total { get; set; }        [EditorSequence(11)]        [CurrencyEditor(Editable = Editable.Hidden)]        [Aggregate(typeof(InvoiceAmountPaid))]        public double AmountPaid { get; set; }        [EditorSequence(12)]        [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]        [Formula(typeof(InvoiceBalance))]        public double Balance { get; set; }        [NullEditor]        [LoggableProperty]        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; }        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;        }            }}
 |