OSDN Git Service

Merge branch 'post-2.4.2'
[tjqt4port/tj2qt4.git] / taskjuggler / HTMLAccountReportElement.cpp
1 /*
2  * HTMLAccountReportElement.cpp - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
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 #include "HTMLAccountReportElement.h"
14 #include "TableLineInfo.h"
15 #include "tjlib-internal.h"
16 #include "Project.h"
17 #include "Account.h"
18
19 HTMLAccountReportElement::HTMLAccountReportElement(Report* r,
20                                                    const QString& df,
21                                                    int dl) :
22     HTMLReportElement(r, df, dl)
23 {
24     uint sc = r->getProject()->getMaxScenarios();
25     columns.append(new TableColumnInfo(sc, "no"));
26     columns.append(new TableColumnInfo(sc, "name"));
27     columns.append(new TableColumnInfo(sc, "total"));
28
29     accountSortCriteria[0] = CoreAttributesList::TreeMode;
30     accountSortCriteria[1] = CoreAttributesList::NameUp;
31 }
32
33 bool
34 HTMLAccountReportElement::generate()
35 {
36     generateHeader();
37
38     generateTableHeader();
39
40     s() << "<tbody>" << endl;
41
42     AccountList filteredList;
43     if (!filterAccountList(filteredList, AllAccounts, hideAccount,
44                            rollUpAccount))
45         return false;
46     maxDepthAccountList = filteredList.maxDepth();
47
48     /* Generate table of cost accounts. */
49     if (!filterAccountList(filteredList, Cost, hideAccount, rollUpAccount))
50         return false;
51     sortAccountList(filteredList);
52     maxDepthAccountList = filteredList.maxDepth();
53
54     TableLineInfo tli;
55     int aNo = 1;
56     for (AccountListIterator ali(filteredList); *ali != 0; ++ali, ++aNo)
57     {
58         tli.ca1 = tli.account = *ali;
59         for (uint sc = 0; sc < scenarios.count(); ++sc)
60         {
61             tli.row = sc;
62             tli.idxNo = aNo;
63             tli.sc = scenarios[sc];
64             tli.bgCol = colors.getColor("default").dark(100 + sc * 10);
65             generateLine(&tli, sc == 0 ? 6 : 7);
66         }
67     }
68
69     /* Generate summary line for cost accounts. */
70     tli.boldText = true;
71     tli.specialName = i18n("Total Costs");
72     for (uint sc = 0; sc < scenarios.count(); ++sc)
73     {
74         tli.row = sc;
75         tli.idxNo = 0;
76         tli.sc = scenarios[sc];
77         tli.bgCol = colors.getColor("header").dark(100 + sc * 10);
78         generateLine(&tli, sc == 0 ? 8 : 9);
79     }
80
81     for (QPtrListIterator<TableColumnInfo> ci(columns); *ci != 0; ++ci)
82     {
83         (*ci)->addSumToMemory(true);
84         (*ci)->clearSum();
85     }
86
87     /* Generate table of revenue accounts. */
88     if (!filterAccountList(filteredList, Revenue, hideAccount, rollUpAccount))
89         return false;
90     sortAccountList(filteredList);
91     maxDepthAccountList = filteredList.maxDepth();
92
93     tli.boldText = false;
94     tli.specialName = QString::null;
95     for (AccountListIterator ali(filteredList); *ali != 0; ++ali, ++aNo)
96     {
97         tli.ca1 = tli.account = *ali;
98         for (uint sc = 0; sc < scenarios.count(); ++sc)
99         {
100             tli.row = sc;
101             tli.idxNo = aNo;
102             tli.sc = scenarios[sc];
103             tli.bgCol = colors.getColor("default").dark(100 + sc * 10);
104             generateLine(&tli, sc == 0 ? 6 : 7);
105         }
106     }
107
108     /* Generate summary line for revenue accounts. */
109     tli.boldText = true;
110     tli.specialName = i18n("Total Revenues");
111     for (uint sc = 0; sc < scenarios.count(); ++sc)
112     {
113         tli.row = sc;
114         tli.idxNo = 0;
115         tli.sc = scenarios[sc];
116         tli.bgCol = colors.getColor("header").dark(100 + sc * 10);
117         generateLine(&tli, sc == 0 ? 8 : 9);
118     }
119
120     for (QPtrListIterator<TableColumnInfo> ci(columns); *ci != 0; ++ci)
121     {
122         (*ci)->addSumToMemory(false);
123         (*ci)->recallMemory();
124     }
125
126     /* Generate total summary line. */
127     tli.specialName = i18n("Total");
128     for (uint sc = 0; sc < scenarios.count(); ++sc)
129     {
130         tli.row = sc;
131         tli.idxNo = 0;
132         tli.sc = scenarios[sc];
133         tli.bgCol = colors.getColor("default").dark(100 + sc * 10);
134         generateLine(&tli, sc == 0 ? 8 : 9);
135     }
136
137     s() << "</tbody>" << endl;
138     s() << "</table>" << endl;
139
140     return true;
141 }
142