summaryrefslogtreecommitdiff
path: root/autoxact.cc
blob: bed69e2e030bdae6a3f637c0dbe70cd0e575286b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "autoxact.h"

namespace ledger {

void automated_transaction_t::extend_entry(entry_t& entry)
{
  transactions_deque initial_xacts(entry.transactions.begin(),
				   entry.transactions.end());

  for (transactions_deque::iterator i = initial_xacts.begin();
       i != initial_xacts.end();
       i++)
    if (predicate(**i))
      for (transactions_deque::iterator t = transactions.begin();
	   t != transactions.end();
	   t++) {
	amount_t amt;
	if ((*t)->amount.commodity().symbol.empty())
	  amt = (*i)->amount * (*t)->amount;
	else
	  amt = (*t)->amount;

	transaction_t * xact
	  = new transaction_t((*t)->account, amt,
			      (*t)->flags | TRANSACTION_AUTO);
	entry.add_transaction(xact);
      }
}

} // namespace ledger