2 * Account.h - TaskJuggler
4 * Copyright (c) 2001, 2002 by Chris Schlaeger <cs@suse.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
20 #include "CoreAttributes.h"
23 class TransactionList;
28 friend class TransactionList;
30 Transaction(time_t d, double a, const QString& descr)
31 : date(d), amount(a), description(descr) { }
34 time_t getDate() { return date; }
35 double getAmount() { return amount; }
36 const QString& getDescription() { return description; }
39 Transaction() { } // dont use this
40 /// The moment when the transaction happened.
42 /// The amount deposited or withdrawn.
44 /// A short description of the transaction purpose
48 class TransactionList : public QList<Transaction>
52 ~TransactionList() { }
54 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
59 class AccountList : public CoreAttributesList
64 sorting[0] = CoreAttributesList::TreeMode;
65 sorting[1] = CoreAttributesList::IdUp;
69 Account* first() { return (Account*) CoreAttributesList::first(); }
70 Account* next() { return (Account*) CoreAttributesList::next(); }
72 inline void addAccount(Account* a);
73 inline Account* getAccount(const QString& id);
75 static bool isSupportedSortingCriteria
76 (CoreAttributesList::SortCriteria sc);
78 virtual int compareItemsLevel(Account* a1, Account* a2, int level);
81 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
84 class Account : public CoreAttributes
87 enum AccountType { Cost, Revenue };
89 Account(Project* p, const QString& i, const QString& n, Account* pr,
91 : CoreAttributes(p, i, n, pr), acctType(at)
95 virtual ~Account() { };
97 virtual const char* getType() { return "Account"; }
99 Account* getParent() { return (Account*) parent; }
101 virtual AccountList getSubList() { return (AccountList&) sub; }
103 void setKotrusId(const QString& k) { kotrusId = k; }
104 const QString& getKotrusId() const { return kotrusId; }
106 void setAcctType(AccountType at) { acctType = at; }
107 AccountType getAcctType() const { return acctType; }
109 void credit(Transaction* t)
111 transactions.inSort(t);
114 bool isGroup() const { return !sub.isEmpty(); }
116 double getBalance(int sc, time_t d);
117 double getVolume(int sc, const Interval& period);
120 Account() { }; // don't use this
122 QList<Transaction> transactions;
123 AccountType acctType;
127 AccountList::addAccount(Account* a)
133 AccountList::getAccount(const QString& id)
135 for (Account* a = first(); a != 0; a = next())
136 if (a->getId() == id)