OSDN Git Service

Merge branch 'post-2.4.2'
[tjqt4port/tj2qt4.git] / taskjuggler / CSVAccountReportElement.cpp
1 /*
2  * CSVAccountReportElement.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 "CSVAccountReportElement.h"
14 #include "TableLineInfo.h"
15 #include "tjlib-internal.h"
16 #include "Project.h"
17 #include "Account.h"
18
19 CSVAccountReportElement::CSVAccountReportElement(Report* r,
20                                                    const QString& df,
21                                                    int dl) :
22     CSVReportElement(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 CSVAccountReportElement::generate()
35 {
36     generateHeader();
37
38     generateTableHeader();
39
40     AccountList filteredList;
41     if (!filterAccountList(filteredList, AllAccounts, hideAccount,
42                            rollUpAccount))
43         return false;
44     maxDepthAccountList = filteredList.maxDepth();
45
46     /* Generate table of cost accounts. */
47     if (!filterAccountList(filteredList, Cost, hideAccount, rollUpAccount))
48         return false;
49     sortAccountList(filteredList);
50     maxDepthAccountList = filteredList.maxDepth();
51
52     TableLineInfo tli;
53     int aNo = 1;
54     for (AccountListIterator ali(filteredList); *ali != 0; ++ali, ++aNo)
55     {
56         tli.ca1 = tli.account = *ali;
57         for (uint sc = 0; sc < scenarios.count(); ++sc)
58         {
59             tli.row = sc;
60             tli.idxNo = aNo;
61             tli.sc = scenarios[sc];
62             generateLine(&tli, sc == 0 ? 6 : 7);
63         }
64     }
65
66     /* Generate summary line for cost accounts. */
67     tli.boldText = true;
68     tli.specialName = i18n("Total Costs");
69     for (uint sc = 0; sc < scenarios.count(); ++sc)
70     {
71         tli.row = sc;
72         tli.idxNo = 0;
73         tli.sc = scenarios[sc];
74         generateLine(&tli, sc == 0 ? 8 : 9);
75     }
76
77     for (QPtrListIterator<TableColumnInfo> ci(columns); *ci != 0; ++ci)
78     {
79         (*ci)->addSumToMemory(true);
80         (*ci)->clearSum();
81     }
82
83     /* Generate table of revenue accounts. */
84     if (!filterAccountList(filteredList, Revenue, hideAccount, rollUpAccount))
85         return false;
86     sortAccountList(filteredList);
87     maxDepthAccountList = filteredList.maxDepth();
88
89     tli.boldText = false;
90     tli.specialName = QString::null;
91     for (AccountListIterator ali(filteredList); *ali != 0; ++ali, ++aNo)
92     {
93         tli.ca1 = tli.account = *ali;
94         for (uint sc = 0; sc < scenarios.count(); ++sc)
95         {
96             tli.row = sc;
97             tli.idxNo = aNo;
98             tli.sc = scenarios[sc];
99             generateLine(&tli, sc == 0 ? 6 : 7);
100         }
101     }
102
103     /* Generate summary line for revenue accounts. */
104     tli.boldText = true;
105     tli.specialName = i18n("Total Revenues");
106     for (uint sc = 0; sc < scenarios.count(); ++sc)
107     {
108         tli.row = sc;
109         tli.idxNo = 0;
110         tli.sc = scenarios[sc];
111         generateLine(&tli, sc == 0 ? 8 : 9);
112     }
113
114     for (QPtrListIterator<TableColumnInfo> ci(columns); *ci != 0; ++ci)
115     {
116         (*ci)->addSumToMemory(false);
117         (*ci)->recallMemory();
118     }
119
120     /* Generate total summary line. */
121     tli.specialName = i18n("Total");
122     for (uint sc = 0; sc < scenarios.count(); ++sc)
123     {
124         tli.row = sc;
125         tli.idxNo = 0;
126         tli.sc = scenarios[sc];
127         generateLine(&tli, sc == 0 ? 8 : 9);
128     }
129
130     return true;
131 }
132