Exemplo n.º 1
0
        public double GetAccountBalace(MoneyDataSet.AccountsRow account, DateTime date)
        {
            double amount = 0;

            if (account.IsActive)
            {
                // checking for account creation time
                DateTime creationTime = account.EntryTime;
                if ((!account.IsHistoryReferenceIDNull()) && ((account.HistoryReferenceID != 0)))
                {
                    creationTime = ds.Accounts.Where(a => ((!a.IsHistoryReferenceIDNull()) && (a.HistoryReferenceID == account.HistoryReferenceID))).Select(s => (s.EntryTime)).Min();
                }
                if (creationTime < date)
                {
                    // rolling back transactions until we pass required date
                    amount = account.Balance;
                    IOrderedEnumerable<MoneyDataSet.TransactionsRow> transactions = null;
                    if ((account.IsHistoryReferenceIDNull()) || (account.HistoryReferenceID == 0))
                    {
                        transactions = this.Transactions.Where(t => ((t.AccountID == account.ID))).OrderByDescending(o => (o.TransactionTime));
                    }
                    else
                    {
                        transactions = this.Transactions.Where(t => ((!t.AccountRow.IsHistoryReferenceIDNull()) &&
                            (t.AccountRow.HistoryReferenceID == account.HistoryReferenceID))).OrderByDescending(o => (o.TransactionTime));
                    }

                    foreach (MoneyDataSet.TransactionsRow transaction in transactions)
                    {
                        if (transaction.TransactionTime < date)
                        {
                            // we've passed required date, current amount is actual balance
                            return amount;
                        }

                        if (transaction.TransactionTypesRow.IsIncome)
                        {
                            amount -= transaction.Amount;
                        }
                        else
                        {
                            amount += transaction.Amount;
                        }
                    }
                    // no transactions found before that date
                }
            }
            return amount;
        }
Exemplo n.º 2
0
        public IEnumerable<MoneyDataSet.TransactionsRow> GetPlannedTransactionImplementations(MoneyDataSet.PlannedTransactionsRow plan, DateTime date)
        {
            IEnumerable<MoneyDataSet.TransactionsRow> transactions = this.Transactions.Where(t => (!t.IsPlannedTransactionIDNull()));

            if ((plan.IsHistoryReferenceIDNull()) || (plan.HistoryReferenceID == 0))
            {
                transactions = transactions.Where(t => (t.PlannedTransactionID == plan.ID));
            }
            else
            {
                IEnumerable<int> planIDs = ds.PlannedTransactions.Where(p => (p.HistoryReferenceID == plan.HistoryReferenceID)).Select(s => (s.ID));
                transactions = transactions.Where(t => (planIDs.Contains(t.PlannedTransactionID)));
            }

            int days =  plan.RecurrenciesRow.IncrementDays + plan.RecurrenciesRow.IncrementMonths * 30 + plan.RecurrenciesRow.IncrementYears * 365;
            DateTime startDate;
            DateTime endDate;

            if (plan.IsAggregated)
            {
                startDate = date.Date;
                endDate = date.AddDays(days).Date;
            }
            else
            {
                startDate = date.AddDays(-days / 2).Date;
                endDate = date.AddDays(days / 2).Date;
            }

            return (days > 0 ? transactions.Where(t => ((t.TransactionTime.Date >= startDate) && (t.TransactionTime.Date <= endDate))) : transactions);
        }
Exemplo n.º 3
0
        private MoneyDataSet.AccountsRow getActualAccount(MoneyDataSet.AccountsRow account)
        {
            if (account == null)
            {
                return null;
            }

            if ((account.IsHistoryReferenceIDNull()) || (account.HistoryReferenceID == 0))
            {
                return account;
            }

            return ds.Accounts.FindByID(ds.Accounts.Where(a => ((!a.IsHistoryReferenceIDNull()) && (a.HistoryReferenceID == account.HistoryReferenceID))).Select(s => (s.ID)).Max());
        }