using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Runtime.InteropServices; using InABox.Core; namespace Comal.Classes { public class SupplierOrderBalance : CoreAggregate { public override Expression> Aggregate => x => x.Balance; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { PurchaseOrderItem => PurchaseOrderItem.PurchaseOrderLink.SupplierLink.ID, Supplier => Supplier.ID } }; } public class SupplierTotalBills : CoreAggregate { public override Expression> Aggregate => x => x.IncTax; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { BillLine => BillLine.BillLink.SupplierLink.ID, Supplier => Supplier.ID } }; } public class SupplierTotalPayments : CoreAggregate { public override Expression> Aggregate => x => x.Amount; public override AggregateCalculation Calculation => AggregateCalculation.Sum; public override Dictionary>, Expression>> Links => new Dictionary>, Expression>>() { { BillPayment => BillPayment.BillLink.SupplierLink.ID, Supplier => Supplier.ID } }; } public class SupplierBalance : IFormula { public Expression> Value => x => x.TotalBills; public Expression>[] Modifiers => new Expression>[] { x => x.TotalPayments }; public FormulaOperator Operator => FormulaOperator.Subtract; public FormulaType Type => FormulaType.Virtual; } [UserTracking(typeof(Bill))] public class Supplier : Entity, IPersistent, IRemotable, ILicense, IExportable, IImportable, IMergeable, IPostable, IPostableFragment, IPostableFragment { [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)] [EditorSequence(1)] public string Code { get; set; } [TextBoxEditor] [EditorSequence(2)] public string Name { get; set; } [EditorSequence(3)] public String ABN { get; set; } [TextBoxEditor] [EditorSequence(4)] public string Email { get; set; } = ""; [TextBoxEditor] [EditorSequence(5)] public string Telephone { get; set; } = ""; [EditorSequence(6)] public SupplierStockLocationLink DefaultLocation { get; set; } [EditorSequence(7)] public SupplierCategoryLink Category { get; set; } [EditorSequence(8)] public SupplierStatusLink SupplierStatus { get; set; } [EditorSequence("Delivery",1)] public Address Delivery { get; set; } [EditorSequence("Accounts",2)] public Address Postal { get; set; } [EditorSequence("Accounts",3)] public ForeignCurrencyLink Currency { get; set; } [EditorSequence("Accounts", 4)] [LookupDefinition(typeof(AccountsPayablePaymentTermsLookup))] public PaymentTermsLink Terms { get; set; } [EditorSequence("Accounts", 5)] [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(SupplierOrderBalance))] public double OrderBalance { get; set; } [EditorSequence("Accounts", 6)] [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(SupplierTotalBills))] public double TotalBills { get; set; } [EditorSequence("Accounts", 7)] [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Aggregate(typeof(SupplierTotalPayments))] public double TotalPayments { get; set; } [EditorSequence("Accounts", 8)] [CurrencyEditor(Editable = Editable.Hidden, Summary = Summary.Sum)] [Formula(typeof(SupplierBalance))] public double Balance { get; set; } [NullEditor] public DateTime Posted { get; set; } [NullEditor] [RequiredColumn] public PostedStatus PostedStatus { get; set; } [NullEditor] public string PostedNote { get; set; } [NullEditor] public string PostedReference { get; set; } public override string ToString() { return string.Format("{0}: {1}", Code, Name); } } }