OSDN Git Service

f2224721ce7ebcb2e8428fc4485c31988d596e7c
[tjqt4port/tj2qt4.git] / taskjuggler / Account.h
1 /*
2  * Account.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002 by Chris Schlaeger <cs@suse.de>
5  *
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.
9  *
10  * $Id$
11  */
12
13 #ifndef _Account_h_
14 #define _Account_h_
15
16 #include <qstring.h>
17 #include <qlist.h>
18 #include <time.h>
19
20 #include "CoreAttributes.h"
21
22 class Task;
23 class TransactionList;
24 class Interval;
25
26 class Transaction
27 {
28         friend class TransactionList;
29 public:
30         Transaction(time_t d, double a, const QString& descr)
31                 : date(d), amount(a), description(descr) { }
32         ~Transaction() { }
33
34         time_t getDate() { return date; }
35         double getAmount() { return amount; }
36         const QString& getDescription() { return description; }
37
38 private:
39         Transaction() { }       // dont use this
40         /// The moment when the transaction happened.
41         time_t date;
42         /// The amount deposited or withdrawn.
43         double amount;
44         /// A short description of the transaction purpose
45         QString description;
46 } ;
47
48 class TransactionList : public QList<Transaction>
49 {
50 public:
51         TransactionList() { }
52         ~TransactionList() { }
53 protected:
54         virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
55 } ;
56
57 class Account;
58
59 class AccountList : public CoreAttributesList
60 {
61 public:
62         AccountList() 
63         { 
64                 sorting[0] = CoreAttributesList::TreeMode;
65                 sorting[1] = CoreAttributesList::IdUp;
66         }
67         ~AccountList() { }
68
69         Account* first() { return (Account*) CoreAttributesList::first(); }
70         Account* next() { return (Account*) CoreAttributesList::next(); }
71
72         inline void addAccount(Account* a);
73         inline Account* getAccount(const QString& id);
74
75         static bool isSupportedSortingCriteria
76                 (CoreAttributesList::SortCriteria sc);
77         
78         virtual int compareItemsLevel(Account* a1, Account* a2, int level);
79
80 protected:
81         virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
82 } ;
83
84 class Account : public CoreAttributes
85 {
86 public:
87         enum AccountType { Cost, Revenue };
88
89         Account(Project* p, const QString& i, const QString& n, Account* pr,
90                         AccountType at)
91                 : CoreAttributes(p, i, n, pr), acctType(at)
92         {
93                 kotrusId = "";
94         }
95         virtual ~Account() { };
96
97         virtual const char* getType() { return "Account"; }
98
99         Account* getParent() { return (Account*) parent; }
100
101         virtual AccountList getSubList() { return (AccountList&) sub; }
102
103         void setKotrusId(const QString& k) { kotrusId = k; }
104         const QString& getKotrusId() const { return kotrusId; }
105
106         void setAcctType(AccountType at) { acctType = at; }
107         AccountType getAcctType() const { return acctType; }
108
109         void credit(Transaction* t)
110         {
111                 transactions.inSort(t);
112         }
113
114         bool isGroup() const { return !sub.isEmpty(); }
115
116         double getBalance(int sc, time_t d);
117         double getVolume(int sc, const Interval& period);
118
119 private:
120         Account() { };  // don't use this
121         QString kotrusId;
122         QList<Transaction> transactions;
123         AccountType acctType;
124 } ;
125
126 void
127 AccountList::addAccount(Account* a)
128 {
129         append(a);
130 }
131
132 Account*
133 AccountList::getAccount(const QString& id)
134 {
135         for (Account* a = first(); a != 0; a = next())
136                 if (a->getId() == id)
137                         return a;
138         return 0;
139 }
140
141 #endif