public static FinancialTransactionRows FromArray(BasicFinancialTransactionRow[] basicArray) { FinancialTransactionRows result = new FinancialTransactionRows { Capacity = (basicArray.Length * 11 / 10) }; foreach (BasicFinancialTransactionRow basic in basicArray) { result.Add(FinancialTransactionRow.FromBasic(basic)); } return(result); }
public Int64 this [FinancialAccount account] { get { Int64 result = 0; FinancialTransactionRows rows = Rows; foreach (FinancialTransactionRow row in rows) { if (row.FinancialAccountId == account.Identity) { result += row.AmountCents; } } return(result); } }
private void AddVatReportItemsFromAccountRows(FinancialAccountRows rows, Dictionary <int, bool> transactionsIncludedLookup) { if (rows.Count == 0) { return; } Organization organization = rows[0].Transaction.Organization; // there is always a rows[0] because check above int vatInboundAccountId = organization.FinancialAccounts.AssetsVatInboundUnreported.Identity; int vatOutboundAccountId = organization.FinancialAccounts.DebtsVatOutboundUnreported.Identity; Dictionary <int, bool> turnoverAccountLookup = new Dictionary <int, bool>(); FinancialAccounts turnoverAccounts = FinancialAccounts.ForOrganization(organization, FinancialAccountType.Income); foreach (FinancialAccount turnoverAccount in turnoverAccounts) { turnoverAccountLookup[turnoverAccount.Identity] = true; } foreach (FinancialAccountRow accountRow in rows) { FinancialTransaction tx = accountRow.Transaction; if (tx.Dependency is VatReport) { continue; // Never include previous VAT reports in new VAT reports } if (!transactionsIncludedLookup.ContainsKey(tx.Identity)) { Int64 vatInbound = 0; Int64 vatOutbound = 0; Int64 turnOver = 0; transactionsIncludedLookup[accountRow.FinancialTransactionId] = true; FinancialTransactionRows txRows = accountRow.Transaction.Rows; foreach (FinancialTransactionRow txRow in txRows) { if (txRow.FinancialAccountId == vatInboundAccountId) { vatInbound += txRow.AmountCents; } else if (txRow.FinancialAccountId == vatOutboundAccountId) { vatOutbound += -txRow.AmountCents; // this is a negative, so converting to positive } else if (turnoverAccountLookup.ContainsKey(txRow.FinancialAccountId)) { turnOver -= txRow.AmountCents; // turnover accounts are sign reversed, so convert to positive } } // Add new row to the VAT report AddItem(tx, turnOver, vatInbound, vatOutbound); } } }