using System; using System.Linq; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Financial; using Swarmops.Database; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; namespace Swarmops.Logic.Financial { public class InboundInvoices : PluralBase { public InboundInvoices WhereAttested { get { InboundInvoices result = new InboundInvoices(); result.AddRange (this.Where (invoice => invoice.Attested)); return result; } } public InboundInvoices WhereUnattested { get { InboundInvoices result = new InboundInvoices(); result.AddRange (this.Where (invoice => invoice.Attested == false)); return result; } } public decimal TotalAmount { get { decimal result = 0.0m; foreach (InboundInvoice invoice in this) { result += invoice.Amount; } return result; } } public Int64 TotalAmountCents { get { Int64 result = 0; foreach (InboundInvoice invoice in this) { result += invoice.AmountCents; } return result; } } /// /// Gets all open inbound invoices for a particular organization. /// /// The organization. /// The list of inbound invoices. public static InboundInvoices ForOrganization (Organization organization) { return ForOrganization (organization, false); } /// /// Gets all inbound invoices for an organization, optionally including closed ones. /// /// The organizations. /// True to include closed records. /// The list of inbound invoices. public static InboundInvoices ForOrganization (Organization organization, bool includeClosed) { return FromArray (SwarmDb.GetDatabaseForReading().GetInboundInvoices (organization, includeClosed ? DatabaseCondition.None : DatabaseCondition.OpenTrue)); } } }