summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-23 00:11:55 (UTC)
committer alwin <alwin>2004-02-23 00:11:55 (UTC)
commitfdf3a6d59f3725bebb923a774d04fb51fb1b0d68 (patch) (unidiff)
treefffc5daec8afe5c339c3fe15988a30b7fe6aca21
parentc1cf5f3efde5a50656a196795fe297ca58ac4334 (diff)
downloadopie-fdf3a6d59f3725bebb923a774d04fb51fb1b0d68.zip
opie-fdf3a6d59f3725bebb923a774d04fb51fb1b0d68.tar.gz
opie-fdf3a6d59f3725bebb923a774d04fb51fb1b0d68.tar.bz2
remove depes to libstdc++
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/account.cpp1
-rwxr-xr-xnoncore/apps/qashmoney/budget.cpp1
-rwxr-xr-xnoncore/apps/qashmoney/qashmoney.cpp1
-rwxr-xr-xnoncore/apps/qashmoney/qashmoney.pro2
-rwxr-xr-xnoncore/apps/qashmoney/transaction.cpp1
-rwxr-xr-xnoncore/apps/qashmoney/transactiondisplay.cpp1
-rwxr-xr-xnoncore/apps/qashmoney/transfer.cpp1
7 files changed, 1 insertions, 7 deletions
diff --git a/noncore/apps/qashmoney/account.cpp b/noncore/apps/qashmoney/account.cpp
index 28f9ba2..181be23 100755
--- a/noncore/apps/qashmoney/account.cpp
+++ b/noncore/apps/qashmoney/account.cpp
@@ -1,377 +1,376 @@
1#include "account.h" 1#include "account.h"
2#include "transaction.h" 2#include "transaction.h"
3#include "transfer.h" 3#include "transfer.h"
4#include "preferences.h" 4#include "preferences.h"
5 5
6#include <qpixmap.h> 6#include <qpixmap.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <iostream.h>
9 8
10extern Preferences *preferences; 9extern Preferences *preferences;
11 10
12Account::Account () 11Account::Account ()
13 { 12 {
14 adb = sqlite_open ( "qmaccounts.db", 0, NULL ); 13 adb = sqlite_open ( "qmaccounts.db", 0, NULL );
15 } 14 }
16 15
17Account::~Account () 16Account::~Account ()
18 { 17 {
19 sqlite_close ( adb ); 18 sqlite_close ( adb );
20 } 19 }
21 20
22void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit, 21void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit,
23 int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency ) 22 int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency )
24 { 23 {
25 sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0, 24 sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0,
26 (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency ); 25 (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency );
27 } 26 }
28 27
29void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid ) 28void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid )
30 { 29 {
31 sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid ); 30 sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid );
32 } 31 }
33 32
34void Account::deleteAccount ( int accountid ) 33void Account::deleteAccount ( int accountid )
35 { 34 {
36 sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid ); 35 sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid );
37 } 36 }
38 37
39void Account::setAccountExpanded ( int expanded, int accountid ) 38void Account::setAccountExpanded ( int expanded, int accountid )
40 { 39 {
41 sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid ); 40 sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid );
42 } 41 }
43 42
44int Account::getAccountExpanded ( int id ) 43int Account::getAccountExpanded ( int id )
45 { 44 {
46 char **results; 45 char **results;
47 sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id ); 46 sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id );
48 if ( strlen ( results [1] ) == 0 ) 47 if ( strlen ( results [1] ) == 0 )
49 return 0; 48 return 0;
50 else 49 else
51 return atoi ( results [ 1 ] ); 50 return atoi ( results [ 1 ] );
52 } 51 }
53 52
54int Account::getNumberOfAccounts () 53int Account::getNumberOfAccounts ()
55 { 54 {
56 char **results; 55 char **results;
57 sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL ); 56 sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL );
58 return atoi ( results [ 1 ] ); 57 return atoi ( results [ 1 ] );
59 } 58 }
60 59
61int Account::getNumberOfChildAccounts ( int id ) 60int Account::getNumberOfChildAccounts ( int id )
62 { 61 {
63 char **results; 62 char **results;
64 sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id ); 63 sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id );
65 return atoi ( results [ 1 ] ); 64 return atoi ( results [ 1 ] );
66 } 65 }
67 66
68void Account::updateAccountBalance ( int accountid ) 67void Account::updateAccountBalance ( int accountid )
69 { 68 {
70 // Here, we'll get a balance for the transactions in an account 69 // Here, we'll get a balance for the transactions in an account
71 sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); 70 sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
72 int rows, columns; 71 int rows, columns;
73 char **results; 72 char **results;
74 sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid ); 73 sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid );
75 float transactionsbalance = strtod ( results [ 1 ], 0 ); 74 float transactionsbalance = strtod ( results [ 1 ], 0 );
76 sqlite_close ( tdb ); 75 sqlite_close ( tdb );
77 76
78 // next, we'll get a balance for all the transfers from the account 77 // next, we'll get a balance for all the transfers from the account
79 sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); 78 sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL );
80 rows = 0; 79 rows = 0;
81 columns = 0; 80 columns = 0;
82 char **results2; 81 char **results2;
83 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); 82 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid );
84 float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); 83 float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 );
85 84
86 // finally, we'll get a balance for all the transfers into the account 85 // finally, we'll get a balance for all the transfers into the account
87 rows = 0; 86 rows = 0;
88 columns= 0; 87 columns= 0;
89 char **results3; 88 char **results3;
90 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); 89 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid );
91 float totransfersbalance = strtod ( results3 [ 1 ], 0 ); 90 float totransfersbalance = strtod ( results3 [ 1 ], 0 );
92 91
93 sqlite_close ( trdb ); 92 sqlite_close ( trdb );
94 93
95 // calculate and update new balance 94 // calculate and update new balance
96 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, 95 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0,
97 ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); 96 ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid );
98 } 97 }
99 98
100void Account::changeParentAccountBalance ( int parentid ) 99void Account::changeParentAccountBalance ( int parentid )
101 { 100 {
102 // select all child balances that share the parent of the current child account 101 // select all child balances that share the parent of the current child account
103 char **results; 102 char **results;
104 int rows; 103 int rows;
105 sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); 104 sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid );
106 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); 105 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid );
107 } 106 }
108 107
109int Account::getParentAccountID ( int id ) 108int Account::getParentAccountID ( int id )
110 { 109 {
111 char **results; 110 char **results;
112 sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); 111 sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id );
113 return atoi ( results [ 1 ] ); 112 return atoi ( results [ 1 ] );
114 } 113 }
115 114
116int Account::getParentAccountID ( QString accountname ) 115int Account::getParentAccountID ( QString accountname )
117 { 116 {
118 char **results; 117 char **results;
119 sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); 118 sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname );
120 return atoi ( results [ 1 ] ); 119 return atoi ( results [ 1 ] );
121 } 120 }
122 121
123void Account::displayAccounts ( QListView *listview ) 122void Account::displayAccounts ( QListView *listview )
124 { 123 {
125 char **results; 124 char **results;
126 int rows, columns; 125 int rows, columns;
127 sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); 126 sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 );
128 127
129 // determine if we are using currency support 128 // determine if we are using currency support
130 int currency = preferences->getPreference ( 4 ); 129 int currency = preferences->getPreference ( 4 );
131 130
132 // remove all columns from the account display 131 // remove all columns from the account display
133 int counter; 132 int counter;
134 for ( counter = 0; counter <= columns; counter++ ) 133 for ( counter = 0; counter <= columns; counter++ )
135 listview->removeColumn ( 0 ); 134 listview->removeColumn ( 0 );
136 135
137 // add columns to the account display 136 // add columns to the account display
138 listview->addColumn ( "Account", 0 ); 137 listview->addColumn ( "Account", 0 );
139 int columntoalign = 1; 138 int columntoalign = 1;
140 if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it 139 if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it
141 { 140 {
142 listview->addColumn ( "C", 0 ); 141 listview->addColumn ( "C", 0 );
143 columntoalign = 2; 142 columntoalign = 2;
144 } 143 }
145 listview->addColumn ( "Balance", 0 ); 144 listview->addColumn ( "Balance", 0 );
146 listview->addColumn ( "", 0 ); 145 listview->addColumn ( "", 0 );
147 listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); 146 listview->setColumnAlignment ( columntoalign, Qt::AlignRight );
148 counter = 5; 147 counter = 5;
149 int total = ( rows + 1 ) * columns; 148 int total = ( rows + 1 ) * columns;
150 while ( counter < total ) 149 while ( counter < total )
151 { 150 {
152 int accountid = atoi ( results [ counter + 3 ] ); 151 int accountid = atoi ( results [ counter + 3 ] );
153 if ( atoi ( results [ counter + 1 ] ) == -1 ) 152 if ( atoi ( results [ counter + 1 ] ) == -1 )
154 { 153 {
155 QListViewItem *parent = new QListViewItem ( listview ); 154 QListViewItem *parent = new QListViewItem ( listview );
156 parent->setText ( 0, results [ counter ] ); 155 parent->setText ( 0, results [ counter ] );
157 if ( currency == 0 ) 156 if ( currency == 0 )
158 { 157 {
159 parent->setText ( 1, results [ counter + 2 ] ); 158 parent->setText ( 1, results [ counter + 2 ] );
160 parent->setText ( 2, results [ counter + 3 ] ); 159 parent->setText ( 2, results [ counter + 3 ] );
161 } 160 }
162 else 161 else
163 { 162 {
164 if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children 163 if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children
165 { 164 {
166 // create the string we'll use to set the currency pixmap 165 // create the string we'll use to set the currency pixmap
167 QString filename = "/opt/QtPalmtop/pics/flags/"; 166 QString filename = "/opt/QtPalmtop/pics/flags/";
168 QString flag = results [ counter + 4 ]; 167 QString flag = results [ counter + 4 ];
169 filename.append ( flag ); 168 filename.append ( flag );
170 filename.append ( ".png" ); 169 filename.append ( ".png" );
171 parent->setPixmap ( 1, QPixmap ( filename ) ); 170 parent->setPixmap ( 1, QPixmap ( filename ) );
172 parent->setText ( 1, flag ); 171 parent->setText ( 1, flag );
173 } 172 }
174 parent->setText ( 2, results [ counter + 2 ] ); 173 parent->setText ( 2, results [ counter + 2 ] );
175 parent->setText ( 3, results [ counter + 3 ] ); 174 parent->setText ( 3, results [ counter + 3 ] );
176 } 175 }
177 176
178 if ( getAccountExpanded ( accountid ) == 1 ) 177 if ( getAccountExpanded ( accountid ) == 1 )
179 parent->setOpen ( TRUE ); 178 parent->setOpen ( TRUE );
180 179
181 //Start display child accounts for this parent 180 //Start display child accounts for this parent
182 int childcounter = 5; 181 int childcounter = 5;
183 while ( childcounter < total ) 182 while ( childcounter < total )
184 { 183 {
185 if ( atoi ( results [ childcounter + 1 ] ) == accountid ) 184 if ( atoi ( results [ childcounter + 1 ] ) == accountid )
186 { 185 {
187 if ( currency == 0 ) 186 if ( currency == 0 )
188 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] ); 187 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] );
189 else 188 else
190 { 189 {
191 // create the string we'll use to set the currency pixmap 190 // create the string we'll use to set the currency pixmap
192 QString filename = "/opt/QtPalmtop/pics/flags/"; 191 QString filename = "/opt/QtPalmtop/pics/flags/";
193 QString flag = results [ childcounter + 4 ]; 192 QString flag = results [ childcounter + 4 ];
194 filename.append ( flag ); 193 filename.append ( flag );
195 filename.append ( ".png" ); 194 filename.append ( ".png" );
196 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] ); 195 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] );
197 child->setPixmap ( 1, QPixmap ( filename ) ); 196 child->setPixmap ( 1, QPixmap ( filename ) );
198 child->setText ( 1, flag ); 197 child->setText ( 1, flag );
199 } 198 }
200 } 199 }
201 childcounter = childcounter + 5; 200 childcounter = childcounter + 5;
202 } 201 }
203 //End display child accounts 202 //End display child accounts
204 } 203 }
205 counter = counter + 5; 204 counter = counter + 5;
206 } 205 }
207 206
208 // resize all columns appropriately 207 // resize all columns appropriately
209 if ( preferences->getPreference ( 4 ) == 0 ) 208 if ( preferences->getPreference ( 4 ) == 0 )
210 { 209 {
211 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); 210 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
212 listview->setColumnWidthMode ( 0, QListView::Manual ); 211 listview->setColumnWidthMode ( 0, QListView::Manual );
213 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); 212 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
214 listview->setColumnWidthMode ( 1, QListView::Manual ); 213 listview->setColumnWidthMode ( 1, QListView::Manual );
215 listview->setColumnWidthMode ( 2, QListView::Manual ); 214 listview->setColumnWidthMode ( 2, QListView::Manual );
216 } 215 }
217 else 216 else
218 { 217 {
219 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) ); 218 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) );
220 listview->setColumnWidthMode ( 0, QListView::Manual ); 219 listview->setColumnWidthMode ( 0, QListView::Manual );
221 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) ); 220 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) );
222 listview->setColumnWidthMode ( 1, QListView::Manual ); 221 listview->setColumnWidthMode ( 1, QListView::Manual );
223 listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) ); 222 listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) );
224 listview->setColumnWidthMode ( 2, QListView::Manual ); 223 listview->setColumnWidthMode ( 2, QListView::Manual );
225 listview->setColumnWidthMode ( 3, QListView::Manual ); 224 listview->setColumnWidthMode ( 3, QListView::Manual );
226 } 225 }
227 226
228 // Now reset the column sorting to user preference 227 // Now reset the column sorting to user preference
229 int column = 0; 228 int column = 0;
230 int direction = 0; 229 int direction = 0;
231 preferences->getSortingPreference ( 1, &column, &direction ); 230 preferences->getSortingPreference ( 1, &column, &direction );
232 listview->setSorting ( column, direction ); 231 listview->setSorting ( column, direction );
233 } 232 }
234 233
235int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring ) 234int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring )
236 { 235 {
237 char **results; 236 char **results;
238 int rows, columns, index; 237 int rows, columns, index;
239 index = 0; 238 index = 0;
240 sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL ); 239 sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL );
241 int counter = 1; 240 int counter = 1;
242 int indexcounter = 1; 241 int indexcounter = 1;
243 int total = ( rows + 1 ) * columns; 242 int total = ( rows + 1 ) * columns;
244 while ( counter < total ) 243 while ( counter < total )
245 { 244 {
246 if ( getParentAccountID ( results [ counter ] ) == -1 ) 245 if ( getParentAccountID ( results [ counter ] ) == -1 )
247 { 246 {
248 combobox->insertItem ( results [ counter ], -1 ); 247 combobox->insertItem ( results [ counter ], -1 );
249 if ( strcmp ( results [ counter ], indexstring ) == 0 ) 248 if ( strcmp ( results [ counter ], indexstring ) == 0 )
250 index = indexcounter; 249 index = indexcounter;
251 indexcounter++; 250 indexcounter++;
252 } 251 }
253 counter ++; 252 counter ++;
254 } 253 }
255 return index; 254 return index;
256 } 255 }
257 256
258int Account::getAccountType ( int accountid ) 257int Account::getAccountType ( int accountid )
259 { 258 {
260 char **results; 259 char **results;
261 sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 260 sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
262 return atoi ( results [ 1 ] ); 261 return atoi ( results [ 1 ] );
263 } 262 }
264 263
265int Account::getStatementDay ( int accountid ) 264int Account::getStatementDay ( int accountid )
266 { 265 {
267 char **results; 266 char **results;
268 sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 267 sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
269 return atoi ( results [ 1 ] ); 268 return atoi ( results [ 1 ] );
270 } 269 }
271 270
272int Account::getStatementMonth ( int accountid ) 271int Account::getStatementMonth ( int accountid )
273 { 272 {
274 char **results; 273 char **results;
275 sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 274 sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
276 return atoi ( results [ 1 ] ); 275 return atoi ( results [ 1 ] );
277 } 276 }
278 277
279int Account::getStatementYear ( int accountid ) 278int Account::getStatementYear ( int accountid )
280 { 279 {
281 char **results; 280 char **results;
282 sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 281 sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
283 return atoi ( results [ 1 ] ); 282 return atoi ( results [ 1 ] );
284 } 283 }
285 284
286QString Account::getAccountDescription ( int accountid ) 285QString Account::getAccountDescription ( int accountid )
287 { 286 {
288 char **results; 287 char **results;
289 sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 288 sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
290 return ( QString ) results [ 1 ]; 289 return ( QString ) results [ 1 ];
291 } 290 }
292 291
293QString Account::getCurrencyCode ( int accountid ) 292QString Account::getCurrencyCode ( int accountid )
294 { 293 {
295 char **results; 294 char **results;
296 sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 295 sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
297 return ( QString ) results [ 1 ]; 296 return ( QString ) results [ 1 ];
298 } 297 }
299 298
300QString Account::getAccountName ( int accountid ) 299QString Account::getAccountName ( int accountid )
301 { 300 {
302 char **results; 301 char **results;
303 sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 302 sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
304 return ( QString ) results [ 1 ]; 303 return ( QString ) results [ 1 ];
305 } 304 }
306 305
307QString Account::getAccountBalance ( int accountid ) 306QString Account::getAccountBalance ( int accountid )
308 { 307 {
309 char **results; 308 char **results;
310 sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 309 sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
311 return ( QString ) results [ 1 ]; 310 return ( QString ) results [ 1 ];
312 } 311 }
313 312
314float Account::getAccountCreditLimit ( int accountid ) 313float Account::getAccountCreditLimit ( int accountid )
315 { 314 {
316 char **results; 315 char **results;
317 sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 316 sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid );
318 return strtod ( results [ 1 ], NULL ); 317 return strtod ( results [ 1 ], NULL );
319 } 318 }
320 319
321float Account::getStatementBalance ( int accountid ) 320float Account::getStatementBalance ( int accountid )
322 { 321 {
323 char **results; 322 char **results;
324 sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 323 sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid );
325 return strtod ( results [ 1 ], NULL ); 324 return strtod ( results [ 1 ], NULL );
326 } 325 }
327 326
328GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) 327GreyBackgroundItem::GreyBackgroundItem ( QListView *parent )
329 : QListViewItem ( parent ) 328 : QListViewItem ( parent )
330 { 329 {
331 } 330 }
332 331
333GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) 332GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 )
334 : QListViewItem ( parent, label1, label2, label3 ) 333 : QListViewItem ( parent, label1, label2, label3 )
335 { 334 {
336 } 335 }
337 336
338GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) 337GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
339 : QListViewItem ( parent, label1, label2, label3, label4 ) 338 : QListViewItem ( parent, label1, label2, label3, label4 )
340 { 339 {
341 } 340 }
342 341
343GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) 342GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
344 : QListViewItem ( parent, label1, label2, label3, label4, label5 ) 343 : QListViewItem ( parent, label1, label2, label3, label4, label5 )
345 { 344 {
346 } 345 }
347 346
348void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) 347void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
349 { 348 {
350 QColorGroup _cg ( cg ); 349 QColorGroup _cg ( cg );
351 _cg.setColor ( QColorGroup::Base, Qt::lightGray ); 350 _cg.setColor ( QColorGroup::Base, Qt::lightGray );
352 QListViewItem::paintCell ( p, _cg, column, width, alignment ); 351 QListViewItem::paintCell ( p, _cg, column, width, alignment );
353 } 352 }
354 353
355QStringList Account::getAccountNames () 354QStringList Account::getAccountNames ()
356 { 355 {
357 QStringList accountnames; 356 QStringList accountnames;
358 char **results; 357 char **results;
359 int rows, counter; 358 int rows, counter;
360 sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); 359 sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 );
361 for ( counter = 0; counter < rows; counter++ ) 360 for ( counter = 0; counter < rows; counter++ )
362 accountnames.append ( results [ counter+1 ] ); 361 accountnames.append ( results [ counter+1 ] );
363 return accountnames; 362 return accountnames;
364 } 363 }
365 364
366QStringList Account::getAccountIDs () 365QStringList Account::getAccountIDs ()
367 { 366 {
368 QStringList accountids; 367 QStringList accountids;
369 char **results; 368 char **results;
370 int rows, counter; 369 int rows, counter;
371 sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); 370 sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 );
372 for ( counter = 0; counter < rows; counter++ ) 371 for ( counter = 0; counter < rows; counter++ )
373 accountids.append ( results [ counter+1 ] ); 372 accountids.append ( results [ counter+1 ] );
374 return accountids; 373 return accountids;
375 } 374 }
376 375
377 376
diff --git a/noncore/apps/qashmoney/budget.cpp b/noncore/apps/qashmoney/budget.cpp
index 9f74078..2cec329 100755
--- a/noncore/apps/qashmoney/budget.cpp
+++ b/noncore/apps/qashmoney/budget.cpp
@@ -1,222 +1,221 @@
1#include "budget.h" 1#include "budget.h"
2#include "transaction.h" 2#include "transaction.h"
3#include <stdlib.h> 3#include <stdlib.h>
4#include <iostream.h>
5 4
6extern Transaction *transaction; 5extern Transaction *transaction;
7 6
8Budget::Budget () 7Budget::Budget ()
9 { 8 {
10 bdb = sqlite_open ( "qmbudgets.db", 0, NULL ); 9 bdb = sqlite_open ( "qmbudgets.db", 0, NULL );
11 } 10 }
12 11
13Budget::~Budget () 12Budget::~Budget ()
14 { 13 {
15 sqlite_close ( bdb ); 14 sqlite_close ( bdb );
16 } 15 }
17 16
18int Budget::addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview ) 17int Budget::addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview )
19 { 18 {
20 sqlite_exec_printf ( bdb, "insert into budgets values ( '%q', %i, '%q', '%q', %i, %i, %i, %i, %i, %i, %i, NULL );", 0, 0, 0, ( const char * ) name, type, ( const char * ) description, ( const char * ) currency, startday, startmonth, startyear, endday, endmonth, endyear, defaultview ); 19 sqlite_exec_printf ( bdb, "insert into budgets values ( '%q', %i, '%q', '%q', %i, %i, %i, %i, %i, %i, %i, NULL );", 0, 0, 0, ( const char * ) name, type, ( const char * ) description, ( const char * ) currency, startday, startmonth, startyear, endday, endmonth, endyear, defaultview );
21 char **results; 20 char **results;
22 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); 21 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL );
23 QString tablename = "table"; 22 QString tablename = "table";
24 tablename.append ( results [ 1 ] ); 23 tablename.append ( results [ 1 ] );
25 sqlite_exec_printf ( bdb, "create table '%q' ( name, lineitemamount, type, lineitemid integer primary key );", 0, 0, 0, ( const char* ) tablename ); 24 sqlite_exec_printf ( bdb, "create table '%q' ( name, lineitemamount, type, lineitemid integer primary key );", 0, 0, 0, ( const char* ) tablename );
26 return atoi ( results [ 1 ] ); 25 return atoi ( results [ 1 ] );
27 } 26 }
28 27
29void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid ) 28void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid )
30 { 29 {
31 sqlite_exec_printf ( bdb, "update budgets set name = '%q', description = '%q', currency = '%q' where budgetid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currency, budgetid ); 30 sqlite_exec_printf ( bdb, "update budgets set name = '%q', description = '%q', currency = '%q' where budgetid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currency, budgetid );
32 } 31 }
33 32
34void Budget::deleteBudget ( int budgetid ) 33void Budget::deleteBudget ( int budgetid )
35 { 34 {
36 if ( getNumberOfBudgets() != 0 ) 35 if ( getNumberOfBudgets() != 0 )
37 { 36 {
38 QString tablename = "table"; 37 QString tablename = "table";
39 tablename.append ( QString::number ( budgetid ) ); 38 tablename.append ( QString::number ( budgetid ) );
40 sqlite_exec_printf ( bdb, "delete from budgets where budgetid = %i;", 0, 0, 0, budgetid ); 39 sqlite_exec_printf ( bdb, "delete from budgets where budgetid = %i;", 0, 0, 0, budgetid );
41 sqlite_exec_printf ( bdb, "drop table '%q';", 0, 0, 0, ( const char* ) tablename ); 40 sqlite_exec_printf ( bdb, "drop table '%q';", 0, 0, 0, ( const char* ) tablename );
42 } 41 }
43 } 42 }
44 43
45int Budget::getNumberOfBudgets () 44int Budget::getNumberOfBudgets ()
46 { 45 {
47 char **results; 46 char **results;
48 sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL ); 47 sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL );
49 return atoi ( results [ 1 ] ); 48 return atoi ( results [ 1 ] );
50 } 49 }
51 50
52int Budget::getNumberOfLineItems ( int budgetid ) 51int Budget::getNumberOfLineItems ( int budgetid )
53 { 52 {
54 QString tablename = "table"; 53 QString tablename = "table";
55 tablename.append ( QString::number ( budgetid ) ); 54 tablename.append ( QString::number ( budgetid ) );
56 char **results; 55 char **results;
57 sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); 56 sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename );
58 return atoi ( results [ 1 ] ); 57 return atoi ( results [ 1 ] );
59 } 58 }
60 59
61QStringList* Budget::getBudgetNames () 60QStringList* Budget::getBudgetNames ()
62 { 61 {
63 QStringList *names = new QStringList (); 62 QStringList *names = new QStringList ();
64 char **results; 63 char **results;
65 int rows, counter; 64 int rows, counter;
66 sqlite_get_table ( bdb, "select name from budgets;", &results, &rows, NULL, NULL ); 65 sqlite_get_table ( bdb, "select name from budgets;", &results, &rows, NULL, NULL );
67 names->append ( "None" ); 66 names->append ( "None" );
68 for ( counter = 0; counter < rows; counter++ ) 67 for ( counter = 0; counter < rows; counter++ )
69 names->append ( results [ counter+1 ] ); 68 names->append ( results [ counter+1 ] );
70 return names; 69 return names;
71 } 70 }
72 71
73QString Budget::getBudgetName ( int budgetid ) 72QString Budget::getBudgetName ( int budgetid )
74 { 73 {
75 char **results; 74 char **results;
76 sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); 75 sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
77 return ( QString ) results [ 1 ]; 76 return ( QString ) results [ 1 ];
78 } 77 }
79 78
80QString Budget::getBudgetDescription ( int budgetid ) 79QString Budget::getBudgetDescription ( int budgetid )
81 { 80 {
82 char **results; 81 char **results;
83 sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); 82 sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
84 return ( QString ) results [ 1 ]; 83 return ( QString ) results [ 1 ];
85 } 84 }
86 85
87QString Budget::getCurrency ( int budgetid ) 86QString Budget::getCurrency ( int budgetid )
88 { 87 {
89 char **results; 88 char **results;
90 sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); 89 sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
91 return ( QString ) results [ 1 ]; 90 return ( QString ) results [ 1 ];
92 } 91 }
93 92
94QStringList* Budget::getBudgetIDs () 93QStringList* Budget::getBudgetIDs ()
95 { 94 {
96 QStringList *ids = new QStringList (); 95 QStringList *ids = new QStringList ();
97 char **results; 96 char **results;
98 int rows, counter; 97 int rows, counter;
99 sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL ); 98 sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL );
100 for ( counter = 0; counter < rows; counter++ ) 99 for ( counter = 0; counter < rows; counter++ )
101 ids->append ( results [ counter+1 ] ); 100 ids->append ( results [ counter+1 ] );
102 return ids; 101 return ids;
103 } 102 }
104 103
105int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype ) 104int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype )
106 { 105 {
107 QString tablename = "table"; 106 QString tablename = "table";
108 tablename.append ( QString::number ( budgetid ) ); 107 tablename.append ( QString::number ( budgetid ) );
109 sqlite_exec_printf ( bdb, "insert into '%q' values ( '%q', %.2f, %i, NULL );", 0, 0, 0, ( const char* ) tablename, ( const char* ) lineitemname, lineitemamount, lineitemtype ); 108 sqlite_exec_printf ( bdb, "insert into '%q' values ( '%q', %.2f, %i, NULL );", 0, 0, 0, ( const char* ) tablename, ( const char* ) lineitemname, lineitemamount, lineitemtype );
110 char **results; 109 char **results;
111 sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename ); 110 sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename );
112 return atoi ( results [ 1 ] ); 111 return atoi ( results [ 1 ] );
113 } 112 }
114 113
115void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid ) 114void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid )
116 { 115 {
117 QString tablename = "table"; 116 QString tablename = "table";
118 tablename.append ( QString::number ( budgetid ) ); 117 tablename.append ( QString::number ( budgetid ) );
119 sqlite_exec_printf ( bdb, "update '%q' set name = '%q', lineitemamount = %f, type = %i where lineitemid = %i;", 0, 0, 0, ( const char* ) tablename, ( const char * ) lineitemname, lineitemamount, lineitemtype, lineitemid ); 118 sqlite_exec_printf ( bdb, "update '%q' set name = '%q', lineitemamount = %f, type = %i where lineitemid = %i;", 0, 0, 0, ( const char* ) tablename, ( const char * ) lineitemname, lineitemamount, lineitemtype, lineitemid );
120 } 119 }
121 120
122void Budget::deleteLineItem ( int budgetid, int lineitemid ) 121void Budget::deleteLineItem ( int budgetid, int lineitemid )
123 { 122 {
124 QString tablename = "table"; 123 QString tablename = "table";
125 tablename.append ( QString::number ( budgetid ) ); 124 tablename.append ( QString::number ( budgetid ) );
126 sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid ); 125 sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid );
127 } 126 }
128 127
129void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype ) 128void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype )
130 { 129 {
131 QString tablename = "table"; 130 QString tablename = "table";
132 tablename.append ( QString::number ( budgetid ) ); 131 tablename.append ( QString::number ( budgetid ) );
133 char **results; 132 char **results;
134 int rows, columns, counter; 133 int rows, columns, counter;
135 sqlite_get_table_printf ( bdb, "select name, lineitemamount, lineitemid from '%q';", &results, &rows, &columns, NULL, ( const char * ) tablename ); 134 sqlite_get_table_printf ( bdb, "select name, lineitemamount, lineitemid from '%q';", &results, &rows, &columns, NULL, ( const char * ) tablename );
136 int total = ( ( rows + 1 ) * columns ); 135 int total = ( ( rows + 1 ) * columns );
137 for ( counter = 3; counter < total; counter = counter + 3 ) 136 for ( counter = 3; counter < total; counter = counter + 3 )
138 { 137 {
139 float amount = 0; 138 float amount = 0;
140 if ( viewtype == 0 ) 139 if ( viewtype == 0 )
141 { 140 {
142 QString lineitemamount = results [ counter + 1 ]; 141 QString lineitemamount = results [ counter + 1 ];
143 amount = lineitemamount.toFloat() / 12; 142 amount = lineitemamount.toFloat() / 12;
144 } 143 }
145 else 144 else
146 { 145 {
147 QString lineitemamount = results [ counter + 1 ]; 146 QString lineitemamount = results [ counter + 1 ];
148 amount = lineitemamount.toFloat(); 147 amount = lineitemamount.toFloat();
149 } 148 }
150 QListViewItem *item = new QListViewItem ( listview, results [ counter ], QString::number ( amount, 'f', 2 ), transaction->getBudgetTotal ( budgetid, atoi ( results [ counter + 2 ] ), year, month, viewtype ), results [ counter + 2 ] ); 149 QListViewItem *item = new QListViewItem ( listview, results [ counter ], QString::number ( amount, 'f', 2 ), transaction->getBudgetTotal ( budgetid, atoi ( results [ counter + 2 ] ), year, month, viewtype ), results [ counter + 2 ] );
151 } 150 }
152 } 151 }
153 152
154QStringList Budget::getLineItems ( int budgetid ) 153QStringList Budget::getLineItems ( int budgetid )
155 { 154 {
156 QString tablename = "table"; 155 QString tablename = "table";
157 tablename.append ( QString::number ( budgetid ) ); 156 tablename.append ( QString::number ( budgetid ) );
158 QStringList lineitems; 157 QStringList lineitems;
159 char **results; 158 char **results;
160 int rows, counter; 159 int rows, counter;
161 sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); 160 sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename );
162 for ( counter = 0; counter < rows; counter++ ) 161 for ( counter = 0; counter < rows; counter++ )
163 lineitems.append ( results [ counter + 1 ] ); 162 lineitems.append ( results [ counter + 1 ] );
164 return lineitems; 163 return lineitems;
165 } 164 }
166 165
167QStringList Budget::getLineItemIDs ( int budgetid ) 166QStringList Budget::getLineItemIDs ( int budgetid )
168 { 167 {
169 QString tablename = "table"; 168 QString tablename = "table";
170 tablename.append ( QString::number ( budgetid ) ); 169 tablename.append ( QString::number ( budgetid ) );
171 QStringList lineitemids; 170 QStringList lineitemids;
172 char **results; 171 char **results;
173 int rows, counter; 172 int rows, counter;
174 sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); 173 sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename );
175 for ( counter = 0; counter < rows; counter++ ) 174 for ( counter = 0; counter < rows; counter++ )
176 lineitemids.append ( results [ counter + 1 ] ); 175 lineitemids.append ( results [ counter + 1 ] );
177 return lineitemids; 176 return lineitemids;
178 } 177 }
179 178
180int Budget::getLineItemTime ( int budgetid, int lineitemid ) 179int Budget::getLineItemTime ( int budgetid, int lineitemid )
181 { 180 {
182 QString tablename = "table"; 181 QString tablename = "table";
183 tablename.append ( QString::number ( budgetid ) ); 182 tablename.append ( QString::number ( budgetid ) );
184 char **results; 183 char **results;
185 sqlite_get_table_printf ( bdb, "select type from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char * ) tablename, lineitemid ); 184 sqlite_get_table_printf ( bdb, "select type from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char * ) tablename, lineitemid );
186 return atoi ( results [ 1 ] ); 185 return atoi ( results [ 1 ] );
187 } 186 }
188 187
189float Budget::getLineItemAmount ( int budgetid, int lineitemid ) 188float Budget::getLineItemAmount ( int budgetid, int lineitemid )
190 { 189 {
191 QString tablename = "table"; 190 QString tablename = "table";
192 tablename.append ( QString::number ( budgetid ) ); 191 tablename.append ( QString::number ( budgetid ) );
193 char **results; 192 char **results;
194 sqlite_get_table_printf ( bdb, "select lineitemamount from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char* ) tablename, lineitemid ); 193 sqlite_get_table_printf ( bdb, "select lineitemamount from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char* ) tablename, lineitemid );
195 return strtod ( results [ 1 ], 0 ); 194 return strtod ( results [ 1 ], 0 );
196 } 195 }
197 196
198QString Budget::getBudgetTotal ( int budgetid, int viewtype ) 197QString Budget::getBudgetTotal ( int budgetid, int viewtype )
199 { 198 {
200 QString tablename = "table"; 199 QString tablename = "table";
201 tablename.append ( QString::number ( budgetid ) ); 200 tablename.append ( QString::number ( budgetid ) );
202 // determine if we are viewing a years, months, or days budget 201 // determine if we are viewing a years, months, or days budget
203 // we have to pick a different sum for each 202 // we have to pick a different sum for each
204 char **results; 203 char **results;
205 sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); 204 sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename );
206 QString amount = results [ 1 ]; 205 QString amount = results [ 1 ];
207 float total = amount.toFloat(); 206 float total = amount.toFloat();
208 if ( viewtype == 0 ) 207 if ( viewtype == 0 )
209 total = total / 12; 208 total = total / 12;
210 amount.setNum ( total, 'f', 2 ); 209 amount.setNum ( total, 'f', 2 );
211 return amount; 210 return amount;
212 } 211 }
213 212
214int Budget::getLastAdded () 213int Budget::getLastAdded ()
215 { 214 {
216 char **results; 215 char **results;
217 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); 216 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL );
218 return atoi ( results [ 1 ] ); 217 return atoi ( results [ 1 ] );
219 } 218 }
220 219
221 220
222 221
diff --git a/noncore/apps/qashmoney/qashmoney.cpp b/noncore/apps/qashmoney/qashmoney.cpp
index e985f0b..d4cbc14 100755
--- a/noncore/apps/qashmoney/qashmoney.cpp
+++ b/noncore/apps/qashmoney/qashmoney.cpp
@@ -1,403 +1,402 @@
1#include "qashmoney.h" 1#include "qashmoney.h"
2#include "preferencedialogs.h" 2#include "preferencedialogs.h"
3#include "memorydialog.h" 3#include "memorydialog.h"
4 4
5#include <qheader.h> 5#include <qheader.h>
6#include <iostream.h>
7 6
8Budget *budget = new Budget (); 7Budget *budget = new Budget ();
9Preferences *preferences = new Preferences (); 8Preferences *preferences = new Preferences ();
10Account *account = new Account (); 9Account *account = new Account ();
11Transaction *transaction = new Transaction (); 10Transaction *transaction = new Transaction ();
12Transfer *transfer = new Transfer (); 11Transfer *transfer = new Transfer ();
13Memory *memory = new Memory (); 12Memory *memory = new Memory ();
14 13
15QashMoney::QashMoney () : QWidget () 14QashMoney::QashMoney () : QWidget ()
16 { 15 {
17 preferences->addPreferences (); 16 preferences->addPreferences ();
18 preferences->initializeColumnPreferences (); 17 preferences->initializeColumnPreferences ();
19 preferences->initializeSortingPreferences (); 18 preferences->initializeSortingPreferences ();
20 19
21 // set the text in the upper part of the frame 20 // set the text in the upper part of the frame
22 setCaption ( tr ( "QashMoney" ) ); 21 setCaption ( tr ( "QashMoney" ) );
23 22
24 // Create new menubar for our mainwindow 23 // Create new menubar for our mainwindow
25 // and add menu items 24 // and add menu items
26 mainmenu = new QMenuBar ( this ); 25 mainmenu = new QMenuBar ( this );
27 mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); 26 mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised );
28 preferencesmenu = new QPopupMenu ( this ); 27 preferencesmenu = new QPopupMenu ( this );
29 utilitiesmenu = new QPopupMenu ( this ); 28 utilitiesmenu = new QPopupMenu ( this );
30 mainmenu->insertItem ( "Preferences", preferencesmenu ); 29 mainmenu->insertItem ( "Preferences", preferencesmenu );
31 mainmenu->insertItem ( "Utilities", utilitiesmenu ); 30 mainmenu->insertItem ( "Utilities", utilitiesmenu );
32 preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog () ) ); 31 preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog () ) );
33 preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog () ) ); 32 preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog () ) );
34 preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog () ) ); 33 preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog () ) );
35 utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog () ) ); 34 utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog () ) );
36 35
37 // create the main tabwidget for displaying accounts and transactions 36 // create the main tabwidget for displaying accounts and transactions
38 maintabs = new QTabWidget ( this ); 37 maintabs = new QTabWidget ( this );
39 tab = new QWidget ( this ); 38 tab = new QWidget ( this );
40 tab_2 = new QWidget ( this ); 39 tab_2 = new QWidget ( this );
41 tab_3 = new QWidget ( this ); 40 tab_3 = new QWidget ( this );
42 maintabs->addTab ( tab, "Accounts" ); 41 maintabs->addTab ( tab, "Accounts" );
43 maintabs->addTab ( tab_2, "Transactions" ); 42 maintabs->addTab ( tab_2, "Transactions" );
44 maintabs->addTab ( tab_3, "Budgets" ); 43 maintabs->addTab ( tab_3, "Budgets" );
45 tabheight = tab->height(); 44 tabheight = tab->height();
46 maintabs->setTabEnabled ( tab_2, FALSE ); 45 maintabs->setTabEnabled ( tab_2, FALSE );
47 46
48 // create a new account display object 47 // create a new account display object
49 accountdisplay = new AccountDisplay ( maintabs ); 48 accountdisplay = new AccountDisplay ( maintabs );
50 accountdisplay->setTabs ( tab_2, maintabs ); 49 accountdisplay->setTabs ( tab_2, maintabs );
51 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( setTransactionTab () ) ); 50 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( setTransactionTab () ) );
52 51
53 // set the connection to disable the one touch account viewing if we are transfering money 52 // set the connection to disable the one touch account viewing if we are transfering money
54 connect ( accountdisplay->transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( toggleOneTouchViewing ( bool ) ) ); 53 connect ( accountdisplay->transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( toggleOneTouchViewing ( bool ) ) );
55 54
56 // create a new transactiondisplay object 55 // create a new transactiondisplay object
57 transactiondisplay = new TransactionDisplay ( maintabs ); 56 transactiondisplay = new TransactionDisplay ( maintabs );
58 transactiondisplay->hide(); 57 transactiondisplay->hide();
59 58
60 // create new budgetdisplay object 59 // create new budgetdisplay object
61 budgetdisplay = new BudgetDisplay ( maintabs ); 60 budgetdisplay = new BudgetDisplay ( maintabs );
62 budgetdisplay->hide(); 61 budgetdisplay->hide();
63 62
64 tabslayout = new QVBoxLayout ( maintabs, 4, 2 ); 63 tabslayout = new QVBoxLayout ( maintabs, 4, 2 );
65 tabslayout->addSpacing ( tabheight ); 64 tabslayout->addSpacing ( tabheight );
66 tabslayout->addWidget ( accountdisplay ); 65 tabslayout->addWidget ( accountdisplay );
67 tabslayout->addWidget ( transactiondisplay ); 66 tabslayout->addWidget ( transactiondisplay );
68 tabslayout->addWidget ( budgetdisplay ); 67 tabslayout->addWidget ( budgetdisplay );
69 68
70 // connect a change in the maintabs with changing the tab display 69 // connect a change in the maintabs with changing the tab display
71 connect ( maintabs, SIGNAL ( currentChanged ( QWidget * ) ), this, SLOT ( changeTabDisplay () ) ); 70 connect ( maintabs, SIGNAL ( currentChanged ( QWidget * ) ), this, SLOT ( changeTabDisplay () ) );
72 71
73 // create layout that will contain the menubar and the maintabs 72 // create layout that will contain the menubar and the maintabs
74 layout = new QVBoxLayout ( this, 2, 2 ); 73 layout = new QVBoxLayout ( this, 2, 2 );
75 layout->setMenuBar ( mainmenu ); 74 layout->setMenuBar ( mainmenu );
76 layout->addWidget ( maintabs ); 75 layout->addWidget ( maintabs );
77 } 76 }
78 77
79QashMoney::~QashMoney () 78QashMoney::~QashMoney ()
80 { 79 {
81 delete budget; 80 delete budget;
82 delete preferences; 81 delete preferences;
83 delete account; 82 delete account;
84 delete transaction; 83 delete transaction;
85 delete transfer; 84 delete transfer;
86 delete memory; 85 delete memory;
87 } 86 }
88 87
89void QashMoney::changeTabDisplay () 88void QashMoney::changeTabDisplay ()
90 { 89 {
91 // if the user pressed the transactions tab, hide the account display 90 // if the user pressed the transactions tab, hide the account display
92 // object and create a new transaction display 91 // object and create a new transaction display
93 if ( maintabs->currentPageIndex() == 1 ) 92 if ( maintabs->currentPageIndex() == 1 )
94 { 93 {
95 // initialize variables 94 // initialize variables
96 bool children = FALSE; 95 bool children = FALSE;
97 96
98 // hide the account display and define accountid 97 // hide the account display and define accountid
99 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); 98 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
100 99
101 //remove all the columns from the transactiondisplay 100 //remove all the columns from the transactiondisplay
102 int columns = transactiondisplay->listview->columns(); 101 int columns = transactiondisplay->listview->columns();
103 int counter; 102 int counter;
104 for ( counter = 0; counter <= columns; counter++ ) 103 for ( counter = 0; counter <= columns; counter++ )
105 transactiondisplay->listview->removeColumn ( 0 ); 104 transactiondisplay->listview->removeColumn ( 0 );
106 105
107 // set the account name and account balance 106 // set the account name and account balance
108 QString name = account->getAccountName ( accountid ); 107 QString name = account->getAccountName ( accountid );
109 QString balance = account->getAccountBalance ( accountid ); 108 QString balance = account->getAccountBalance ( accountid );
110 transactiondisplay->name->setText ( name ); 109 transactiondisplay->name->setText ( name );
111 transactiondisplay->balance->setText ( balance ); 110 transactiondisplay->balance->setText ( balance );
112 111
113 // clear the limitbox 112 // clear the limitbox
114 transactiondisplay->limitbox->clear(); 113 transactiondisplay->limitbox->clear();
115 114
116 // get parent account id 115 // get parent account id
117 int parentaccountid = account->getParentAccountID ( accountid ); 116 int parentaccountid = account->getParentAccountID ( accountid );
118 117
119 // add columns based on which account is selected 118 // add columns based on which account is selected
120 // this first if determines if we selected a parent with no children or a child 119 // this first if determines if we selected a parent with no children or a child
121 // in these cases, we add standard three columns for date, transaction, amount 120 // in these cases, we add standard three columns for date, transaction, amount
122 transactiondisplay->listview->addColumn ( "Date", 0 ); 121 transactiondisplay->listview->addColumn ( "Date", 0 );
123 transactiondisplay->listview->addColumn ( "Transaction", 0 ); 122 transactiondisplay->listview->addColumn ( "Transaction", 0 );
124 transactiondisplay->listview->addColumn ( "Amt", 0); 123 transactiondisplay->listview->addColumn ( "Amt", 0);
125 transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight ); 124 transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight );
126 transactiondisplay->listview->addColumn ( "", 0 ); 125 transactiondisplay->listview->addColumn ( "", 0 );
127 126
128 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children 127 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children
129 { 128 {
130 // add an extra column for the account name for eac child transaction 129 // add an extra column for the account name for eac child transaction
131 transactiondisplay->listview->addColumn ( "Acct", 0 ); 130 transactiondisplay->listview->addColumn ( "Acct", 0 );
132 children = TRUE; 131 children = TRUE;
133 132
134 // hide the new transaction button 133 // hide the new transaction button
135 transactiondisplay->newtransaction->setEnabled ( FALSE ); 134 transactiondisplay->newtransaction->setEnabled ( FALSE );
136 } 135 }
137 else //we selected a parent without children or a child 136 else //we selected a parent without children or a child
138 transactiondisplay->newtransaction->setEnabled ( TRUE ); 137 transactiondisplay->newtransaction->setEnabled ( TRUE );
139 138
140 // disable the transactionid column so it can't be red 139 // disable the transactionid column so it can't be red
141 transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 ); 140 transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 );
142 141
143 // set the accountid and children variables 142 // set the accountid and children variables
144 transactiondisplay->setChildren ( children ); 143 transactiondisplay->setChildren ( children );
145 transactiondisplay->setAccountID ( accountid ); 144 transactiondisplay->setAccountID ( accountid );
146 145
147 setTransactionDisplayDate (); 146 setTransactionDisplayDate ();
148 147
149 // display transactions 148 // display transactions
150 transactiondisplay->listview->clear(); 149 transactiondisplay->listview->clear();
151 QString displaytext = "%"; 150 QString displaytext = "%";
152 displaytext.prepend ( transactiondisplay->limitbox->text() ); 151 displaytext.prepend ( transactiondisplay->limitbox->text() );
153 if ( transaction->getNumberOfTransactions() > 0 ) 152 if ( transaction->getNumberOfTransactions() > 0 )
154 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); 153 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
155 154
156 // display transfers 155 // display transfers
157 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); 156 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
158 157
159 // open a new preferences object and resize the transaction display columns 158 // open a new preferences object and resize the transaction display columns
160 // each column will have a different size based on whether we are looking at a child 159 // each column will have a different size based on whether we are looking at a child
161 // account or children through a parent 160 // account or children through a parent
162 if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns 161 if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns
163 { 162 {
164 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width 163 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width
165 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); 164 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
166 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width 165 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width
167 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); 166 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
168 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width 167 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width
169 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); 168 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
170 } 169 }
171 else 170 else
172 { 171 {
173 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width 172 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width
174 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); 173 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
175 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width 174 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width
176 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); 175 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
177 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width 176 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width
178 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); 177 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
179 transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width 178 transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width
180 transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual ); 179 transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual );
181 } 180 }
182 181
183 // pull the column sorting preference from the preferences table, and configure the listview accordingly 182 // pull the column sorting preference from the preferences table, and configure the listview accordingly
184 int column = 0; 183 int column = 0;
185 int direction = 0; 184 int direction = 0;
186 preferences->getSortingPreference ( 2, &column, &direction ); 185 preferences->getSortingPreference ( 2, &column, &direction );
187 transactiondisplay->listview->setSorting ( column, direction ); 186 transactiondisplay->listview->setSorting ( column, direction );
188 187
189 // show the window 188 // show the window
190 transactiondisplay->show(); 189 transactiondisplay->show();
191 // hide the account display and define accountid 190 // hide the account display and define accountid
192 accountdisplay->hide(); 191 accountdisplay->hide();
193 // hide the budget display 192 // hide the budget display
194 budgetdisplay->hide(); 193 budgetdisplay->hide();
195 } 194 }
196 else if ( maintabs->currentPageIndex() == 0 ) 195 else if ( maintabs->currentPageIndex() == 0 )
197 { 196 {
198 disableOneTouchViewing(); 197 disableOneTouchViewing();
199 198
200 // clear the account display selection 199 // clear the account display selection
201 accountdisplay->listview->clearSelection(); 200 accountdisplay->listview->clearSelection();
202 201
203 // resize the account display columns 202 // resize the account display columns
204 accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); 203 accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
205 accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); 204 accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
206 205
207 // set sorting preference on account display columns 206 // set sorting preference on account display columns
208 int column = 0; 207 int column = 0;
209 int direction = 0; 208 int direction = 0;
210 preferences->getSortingPreference ( 1, &column, &direction ); 209 preferences->getSortingPreference ( 1, &column, &direction );
211 accountdisplay->listview->setSorting ( column, direction ); 210 accountdisplay->listview->setSorting ( column, direction );
212 211
213 // display the accounts 212 // display the accounts
214 if ( account->getNumberOfAccounts() != 0 ) 213 if ( account->getNumberOfAccounts() != 0 )
215 account->displayAccounts ( accountdisplay->listview ); 214 account->displayAccounts ( accountdisplay->listview );
216 maintabs->setTabEnabled ( tab_2, FALSE ); 215 maintabs->setTabEnabled ( tab_2, FALSE );
217 216
218 // set the toggle button 217 // set the toggle button
219 accountdisplay->setToggleButton (); 218 accountdisplay->setToggleButton ();
220 219
221 // show the account display 220 // show the account display
222 accountdisplay->show(); 221 accountdisplay->show();
223 222
224 // hide the transaction display 223 // hide the transaction display
225 transactiondisplay->hide(); 224 transactiondisplay->hide();
226 225
227 // hide the budget display 226 // hide the budget display
228 budgetdisplay->hide(); 227 budgetdisplay->hide();
229 228
230 229
231 enableOneTouchViewing (); 230 enableOneTouchViewing ();
232 } 231 }
233 else 232 else
234 { 233 {
235 budgetdisplay->displayLineItems(); 234 budgetdisplay->displayLineItems();
236 budgetdisplay->show(); 235 budgetdisplay->show();
237 transactiondisplay->hide(); 236 transactiondisplay->hide();
238 accountdisplay->hide(); 237 accountdisplay->hide();
239 } 238 }
240 } 239 }
241 240
242void QashMoney::setTransactionTab () 241void QashMoney::setTransactionTab ()
243 { 242 {
244 if ( accountdisplay->listview->selectedItem() == 0 ) 243 if ( accountdisplay->listview->selectedItem() == 0 )
245 maintabs->setTabEnabled ( tab_2, FALSE ); 244 maintabs->setTabEnabled ( tab_2, FALSE );
246 else 245 else
247 maintabs->setTabEnabled ( tab_2, TRUE ); 246 maintabs->setTabEnabled ( tab_2, TRUE );
248 } 247 }
249 248
250void QashMoney::displayDatePreferencesDialog () 249void QashMoney::displayDatePreferencesDialog ()
251 { 250 {
252 // this shows a dialog to set preferences for formatting the date 251 // this shows a dialog to set preferences for formatting the date
253 DatePreferences *pd = new DatePreferences ( this ); 252 DatePreferences *pd = new DatePreferences ( this );
254 pd->exec (); 253 pd->exec ();
255 if ( transactiondisplay->isVisible() ) 254 if ( transactiondisplay->isVisible() )
256 { 255 {
257 // set the account id 256 // set the account id
258 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); 257 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
259 258
260 // set children so we can let displayTransfers know if there are children for the selected account 259 // set children so we can let displayTransfers know if there are children for the selected account
261 bool children; 260 bool children;
262 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) 261 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
263 children = TRUE; 262 children = TRUE;
264 else 263 else
265 children = FALSE; 264 children = FALSE;
266 265
267 // redisplay transactions if they are visible incorporating 266 // redisplay transactions if they are visible incorporating
268 // any changes to the date format 267 // any changes to the date format
269 transactiondisplay->listview->clear(); 268 transactiondisplay->listview->clear();
270 QString displaytext = "%"; 269 QString displaytext = "%";
271 displaytext.prepend ( transactiondisplay->limitbox->text() ); 270 displaytext.prepend ( transactiondisplay->limitbox->text() );
272 271
273 setTransactionDisplayDate(); 272 setTransactionDisplayDate();
274 if ( transaction->getNumberOfTransactions() > 0 ) 273 if ( transaction->getNumberOfTransactions() > 0 )
275 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); 274 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
276 275
277 if ( transfer->getNumberOfTransfers() != 0 ) 276 if ( transfer->getNumberOfTransfers() != 0 )
278 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); 277 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
279 } 278 }
280 else if ( accountdisplay->isVisible() ) 279 else if ( accountdisplay->isVisible() )
281 { 280 {
282 accountdisplay->listview->clearSelection(); 281 accountdisplay->listview->clearSelection();
283 maintabs->setTabEnabled ( tab_2, FALSE ); 282 maintabs->setTabEnabled ( tab_2, FALSE );
284 } 283 }
285 else 284 else
286 budgetdisplay->updateBudgetInformation(); 285 budgetdisplay->updateBudgetInformation();
287 } 286 }
288 287
289void QashMoney::displayTransactionPreferencesDialog () 288void QashMoney::displayTransactionPreferencesDialog ()
290 { 289 {
291 // display a dialog for setting preferences for transactions 290 // display a dialog for setting preferences for transactions
292 TransactionPreferences *td = new TransactionPreferences ( this ); 291 TransactionPreferences *td = new TransactionPreferences ( this );
293 td->exec (); 292 td->exec ();
294 if ( transactiondisplay->isVisible() ) 293 if ( transactiondisplay->isVisible() )
295 { 294 {
296 // set the account id 295 // set the account id
297 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); 296 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
298 297
299 // set children so we can let displayTransfers know if there are children for the selected account 298 // set children so we can let displayTransfers know if there are children for the selected account
300 bool children; 299 bool children;
301 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) 300 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
302 children = TRUE; 301 children = TRUE;
303 else 302 else
304 children = FALSE; 303 children = FALSE;
305 304
306 // redisplay transactions incorporating any transaction preference changes 305 // redisplay transactions incorporating any transaction preference changes
307 transactiondisplay->listview->clear(); 306 transactiondisplay->listview->clear();
308 QString displaytext = "%"; 307 QString displaytext = "%";
309 displaytext.prepend ( transactiondisplay->limitbox->text() ); 308 displaytext.prepend ( transactiondisplay->limitbox->text() );
310 309
311 setTransactionDisplayDate(); 310 setTransactionDisplayDate();
312 if ( transaction->getNumberOfTransactions() > 0 ) 311 if ( transaction->getNumberOfTransactions() > 0 )
313 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); 312 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
314 313
315 if ( transfer->getNumberOfTransfers() != 0 ) 314 if ( transfer->getNumberOfTransfers() != 0 )
316 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); 315 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
317 } 316 }
318 else 317 else
319 { 318 {
320 accountdisplay->listview->clearSelection(); 319 accountdisplay->listview->clearSelection();
321 maintabs->setTabEnabled ( tab_2, FALSE ); 320 maintabs->setTabEnabled ( tab_2, FALSE );
322 } 321 }
323 } 322 }
324 323
325void QashMoney::displayAccountPreferencesDialog () 324void QashMoney::displayAccountPreferencesDialog ()
326 { 325 {
327 // display a dialog for setting preferences for accounts 326 // display a dialog for setting preferences for accounts
328 AccountPreferences *ap = new AccountPreferences ( this ); 327 AccountPreferences *ap = new AccountPreferences ( this );
329 ap->exec (); 328 ap->exec ();
330 329
331 if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 ) 330 if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 )
332 { 331 {
333 accountdisplay->listview->clear(); 332 accountdisplay->listview->clear();
334 account->displayAccounts ( accountdisplay->listview ); 333 account->displayAccounts ( accountdisplay->listview );
335 accountdisplay->listview->clearSelection(); 334 accountdisplay->listview->clearSelection();
336 maintabs->setTabEnabled ( tab_2, FALSE ); 335 maintabs->setTabEnabled ( tab_2, FALSE );
337 } 336 }
338 changeTabDisplay(); 337 changeTabDisplay();
339 } 338 }
340 339
341void QashMoney::displayMemoryDialog () 340void QashMoney::displayMemoryDialog ()
342 { 341 {
343 // opens a dialog to add, edit and delete memory items 342 // opens a dialog to add, edit and delete memory items
344 MemoryDialog *md = new MemoryDialog (); 343 MemoryDialog *md = new MemoryDialog ();
345 md->exec(); 344 md->exec();
346 } 345 }
347 346
348void QashMoney::showTransactions () 347void QashMoney::showTransactions ()
349 { 348 {
350 maintabs->setCurrentPage ( 1 ); 349 maintabs->setCurrentPage ( 1 );
351 } 350 }
352 351
353void QashMoney::enableOneTouchViewing () 352void QashMoney::enableOneTouchViewing ()
354 { 353 {
355 if ( preferences->getPreference ( 5 ) == 1 ) 354 if ( preferences->getPreference ( 5 ) == 1 )
356 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); 355 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
357 else 356 else
358 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); 357 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
359 } 358 }
360 359
361void QashMoney::disableOneTouchViewing () 360void QashMoney::disableOneTouchViewing ()
362 { 361 {
363 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); 362 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
364 } 363 }
365 364
366void QashMoney::toggleOneTouchViewing ( bool state ) 365void QashMoney::toggleOneTouchViewing ( bool state )
367 { 366 {
368 if ( state == TRUE ) 367 if ( state == TRUE )
369 disableOneTouchViewing(); 368 disableOneTouchViewing();
370 else 369 else
371 enableOneTouchViewing(); 370 enableOneTouchViewing();
372 } 371 }
373 372
374void QashMoney::setTransactionDisplayDate () 373void QashMoney::setTransactionDisplayDate ()
375 { 374 {
376 // determine how many days of transactions to show 375 // determine how many days of transactions to show
377 int limittype = preferences->getPreference ( 7 ); 376 int limittype = preferences->getPreference ( 7 );
378 if ( limittype != 5 ) // set today's date if we are not showing all transactions 377 if ( limittype != 5 ) // set today's date if we are not showing all transactions
379 { 378 {
380 QDate today = QDate::currentDate (); 379 QDate today = QDate::currentDate ();
381 switch ( limittype ) // if we are not showing all transactions 380 switch ( limittype ) // if we are not showing all transactions
382 { 381 {
383 case 0: // viewing two weeks 382 case 0: // viewing two weeks
384 newdate = today.addDays ( -14 ); 383 newdate = today.addDays ( -14 );
385 break; 384 break;
386 case 1: // viewing one month 385 case 1: // viewing one month
387 newdate = today.addDays ( -30 ); 386 newdate = today.addDays ( -30 );
388 break; 387 break;
389 case 2: // three months 388 case 2: // three months
390 newdate = today.addDays ( -90 ); 389 newdate = today.addDays ( -90 );
391 break; 390 break;
392 case 3: // six months 391 case 3: // six months
393 newdate = today.addDays ( -180 ); 392 newdate = today.addDays ( -180 );
394 break; 393 break;
395 case 4: // one year 394 case 4: // one year
396 newdate = today.addDays ( -365 ); 395 newdate = today.addDays ( -365 );
397 break; 396 break;
398 } 397 }
399 } 398 }
400 else 399 else
401 newdate = QDate ( 1900, 1, 1 ); 400 newdate = QDate ( 1900, 1, 1 );
402 } 401 }
403 402
diff --git a/noncore/apps/qashmoney/qashmoney.pro b/noncore/apps/qashmoney/qashmoney.pro
index 8b4646a..ec29faa 100755
--- a/noncore/apps/qashmoney/qashmoney.pro
+++ b/noncore/apps/qashmoney/qashmoney.pro
@@ -1,49 +1,49 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3 HEADERS =qashmoney.h \ 3 HEADERS =qashmoney.h \
4 accountdisplay.h \ 4 accountdisplay.h \
5 account.h \ 5 account.h \
6 transaction.h \ 6 transaction.h \
7 transactiondisplay.h \ 7 transactiondisplay.h \
8 newtransaction.h \ 8 newtransaction.h \
9 transfer.h \ 9 transfer.h \
10 transferdialog.h \ 10 transferdialog.h \
11 preferences.h \ 11 preferences.h \
12 preferencedialogs.h \ 12 preferencedialogs.h \
13 memory.h \ 13 memory.h \
14 memorydialog.h \ 14 memorydialog.h \
15 newaccount.h \ 15 newaccount.h \
16 calculator.h \ 16 calculator.h \
17 datepicker.h \ 17 datepicker.h \
18 budget.h \ 18 budget.h \
19 budgetdisplay.h \ 19 budgetdisplay.h \
20 currency.h 20 currency.h
21 SOURCES =qashmoney.cpp \ 21 SOURCES =qashmoney.cpp \
22 accountdisplay.cpp \ 22 accountdisplay.cpp \
23 account.cpp \ 23 account.cpp \
24 transaction.cpp \ 24 transaction.cpp \
25 transactiondisplay.cpp \ 25 transactiondisplay.cpp \
26 newtransaction.cpp \ 26 newtransaction.cpp \
27 transfer.cpp \ 27 transfer.cpp \
28 transferdialog.cpp \ 28 transferdialog.cpp \
29 preferences.cpp \ 29 preferences.cpp \
30 preferencedialogs.cpp \ 30 preferencedialogs.cpp \
31 memory.cpp \ 31 memory.cpp \
32 memorydialog.cpp \ 32 memorydialog.cpp \
33 newaccount.cpp \ 33 newaccount.cpp \
34 calculator.cpp \ 34 calculator.cpp \
35 datepicker.cpp \ 35 datepicker.cpp \
36 main.cpp \ 36 main.cpp \
37 budget.cpp \ 37 budget.cpp \
38 budgetdisplay.cpp \ 38 budgetdisplay.cpp \
39 currency.cpp 39 currency.cpp
40INCLUDEPATH = $(OPIEDIR)/include 40INCLUDEPATH = $(OPIEDIR)/include
41DEPENDPATH = $(OPIEDIR)/include 41DEPENDPATH = $(OPIEDIR)/include
42 42
43DESTDIR = $(OPIEDIR)/bin 43DESTDIR = $(OPIEDIR)/bin
44 44
45unix:LIBS += -lm 45unix:LIBS += -lm
46LIBS += -lqpe -lqte -lstdc++ -lsqlite 46LIBS += -lqpe -lqte -lsqlite
47 47
48include ( $(OPIEDIR)/include.pro ) 48include ( $(OPIEDIR)/include.pro )
49 49
diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp
index dcf46b1..d008a4f 100755
--- a/noncore/apps/qashmoney/transaction.cpp
+++ b/noncore/apps/qashmoney/transaction.cpp
@@ -1,346 +1,345 @@
1// RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN 1// RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN
2// FUTURE VERSIONS OF QASHMONEY 2// FUTURE VERSIONS OF QASHMONEY
3 3
4// RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION 4// RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION
5 5
6#include "transaction.h" 6#include "transaction.h"
7#include "account.h" 7#include "account.h"
8#include "transactiondisplay.h" 8#include "transactiondisplay.h"
9 9
10#include <stdlib.h> 10#include <stdlib.h>
11#include <iostream.h>
12 11
13extern Account *account; 12extern Account *account;
14extern Preferences *preferences; 13extern Preferences *preferences;
15 14
16Transaction::Transaction () 15Transaction::Transaction ()
17 { 16 {
18 tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); 17 tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
19 } 18 }
20 19
21Transaction::~Transaction () 20Transaction::~Transaction ()
22 { 21 {
23 sqlite_close ( tdb ); 22 sqlite_close ( tdb );
24 } 23 }
25 24
26void Transaction::addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid ) 25void Transaction::addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid )
27 { 26 {
28 sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0, " 27 sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0, "
29 "0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description ); 28 "0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description );
30 } 29 }
31 30
32void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid ) 31void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid )
33 { 32 {
34 sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f," 33 sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f,"
35 "cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year, 34 "cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year,
36 amount, cleared, budgetid, lineitemid, transactionid ); 35 amount, cleared, budgetid, lineitemid, transactionid );
37 } 36 }
38 37
39void Transaction::deleteTransaction ( int transid ) 38void Transaction::deleteTransaction ( int transid )
40 { 39 {
41 sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid ); 40 sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid );
42 } 41 }
43 42
44void Transaction::deleteAllTransactions ( int accountid ) 43void Transaction::deleteAllTransactions ( int accountid )
45 { 44 {
46 sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid ); 45 sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid );
47 } 46 }
48 47
49int Transaction::getAccountID ( int id ) 48int Transaction::getAccountID ( int id )
50 { 49 {
51 char **results; 50 char **results;
52 sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 51 sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
53 return atol ( results [ 1 ] ); 52 return atol ( results [ 1 ] );
54 } 53 }
55 54
56int Transaction::getNumberOfTransactions () 55int Transaction::getNumberOfTransactions ()
57 { 56 {
58 char **results; 57 char **results;
59 sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL ); 58 sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL );
60 return atoi ( results [ 1 ] ); 59 return atoi ( results [ 1 ] );
61 } 60 }
62 61
63int Transaction::getNumberOfTransactions ( int accountid ) 62int Transaction::getNumberOfTransactions ( int accountid )
64 { 63 {
65 char **results; 64 char **results;
66 sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 65 sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid );
67 return atol ( results [ 1 ] ); 66 return atol ( results [ 1 ] );
68 } 67 }
69 68
70QString Transaction::getPayee ( int id ) 69QString Transaction::getPayee ( int id )
71 { 70 {
72 char **results; 71 char **results;
73 sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 72 sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
74 return results [ 1 ]; 73 return results [ 1 ];
75 } 74 }
76 75
77QString Transaction::getTransactionDescription ( int id ) 76QString Transaction::getTransactionDescription ( int id )
78 { 77 {
79 char **results; 78 char **results;
80 sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 79 sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
81 return results [ 1 ]; 80 return results [ 1 ];
82 } 81 }
83 82
84QString Transaction::getNumber ( int id ) 83QString Transaction::getNumber ( int id )
85 { 84 {
86 char **results; 85 char **results;
87 sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 86 sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
88 return results [ 1 ]; 87 return results [ 1 ];
89 } 88 }
90 89
91QString Transaction::getAmount ( int id ) 90QString Transaction::getAmount ( int id )
92 { 91 {
93 char **results; 92 char **results;
94 sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 93 sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
95 return results [ 1 ]; 94 return results [ 1 ];
96 } 95 }
97 96
98QString Transaction::getAbsoluteAmount ( int id ) 97QString Transaction::getAbsoluteAmount ( int id )
99 { 98 {
100 char **results; 99 char **results;
101 sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 100 sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
102 return results [ 1 ]; 101 return results [ 1 ];
103 } 102 }
104 103
105int Transaction::getCleared ( int id ) 104int Transaction::getCleared ( int id )
106 { 105 {
107 char **results; 106 char **results;
108 sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 107 sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
109 QString cleared = results [ 1 ]; 108 QString cleared = results [ 1 ];
110 return cleared.toInt(); 109 return cleared.toInt();
111 } 110 }
112 111
113void Transaction::setCleared ( int id, int cleared ) 112void Transaction::setCleared ( int id, int cleared )
114 { 113 {
115 sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id ); 114 sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id );
116 } 115 }
117 116
118int Transaction::getBudgetID ( int id ) 117int Transaction::getBudgetID ( int id )
119 { 118 {
120 char **results; 119 char **results;
121 sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); 120 sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id );
122 QString budgetid = results [ 1 ]; 121 QString budgetid = results [ 1 ];
123 return budgetid.toInt(); 122 return budgetid.toInt();
124 } 123 }
125 124
126int Transaction::getLineItemID ( int id ) 125int Transaction::getLineItemID ( int id )
127 { 126 {
128 char **results; 127 char **results;
129 sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); 128 sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id );
130 QString lineitemid = results [ 1 ]; 129 QString lineitemid = results [ 1 ];
131 return lineitemid.toInt(); 130 return lineitemid.toInt();
132 } 131 }
133 132
134int Transaction::getDay ( int id ) 133int Transaction::getDay ( int id )
135 { 134 {
136 char **results; 135 char **results;
137 sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 136 sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
138 QString daystring = results [ 1 ]; 137 QString daystring = results [ 1 ];
139 return daystring.toInt(); 138 return daystring.toInt();
140 } 139 }
141 140
142int Transaction::getMonth ( int id ) 141int Transaction::getMonth ( int id )
143 { 142 {
144 char **results; 143 char **results;
145 sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 144 sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
146 QString monthstring = results [ 1 ]; 145 QString monthstring = results [ 1 ];
147 return monthstring.toInt(); 146 return monthstring.toInt();
148 } 147 }
149 148
150int Transaction::getYear ( int id ) 149int Transaction::getYear ( int id )
151 { 150 {
152 char **results; 151 char **results;
153 sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 152 sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
154 QString yearstring = results [ 1 ]; 153 QString yearstring = results [ 1 ];
155 return yearstring.toInt(); 154 return yearstring.toInt();
156 } 155 }
157 156
158char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id ) 157char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id )
159 { 158 {
160 // initialize variables 159 // initialize variables
161 char **results; 160 char **results;
162 int showcleared = preferences->getPreference ( 3 ); 161 int showcleared = preferences->getPreference ( 3 );
163 QDate today = QDate::currentDate(); 162 QDate today = QDate::currentDate();
164 int fromyear = fromdate.year(); 163 int fromyear = fromdate.year();
165 int toyear = today.year(); 164 int toyear = today.year();
166 int frommonth = fromdate.month(); 165 int frommonth = fromdate.month();
167 int tomonth = today.month(); 166 int tomonth = today.month();
168 int fromday = fromdate.day(); 167 int fromday = fromdate.day();
169 168
170 // construct the first part of the string 169 // construct the first part of the string
171 QString query = "select day, month, year, payee, amount, transid, accountid from transactions where"; 170 QString query = "select day, month, year, payee, amount, transid, accountid from transactions where";
172 171
173 if ( frommonth == tomonth && fromyear == toyear ) // our dates cross neither a month nor a year 172 if ( frommonth == tomonth && fromyear == toyear ) // our dates cross neither a month nor a year
174 { 173 {
175 query.append ( " year = " ); 174 query.append ( " year = " );
176 query.append ( QString::number ( toyear ) ); 175 query.append ( QString::number ( toyear ) );
177 query.append ( " and month = " ); 176 query.append ( " and month = " );
178 query.append ( QString::number ( tomonth ) ); 177 query.append ( QString::number ( tomonth ) );
179 query.append ( " and day >= " ); 178 query.append ( " and day >= " );
180 query.append ( QString::number ( fromday ) ); 179 query.append ( QString::number ( fromday ) );
181 query.append ( " and" ); 180 query.append ( " and" );
182 } 181 }
183 else if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year 182 else if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year
184 { 183 {
185 query.append ( " year = " ); 184 query.append ( " year = " );
186 query.append ( QString::number ( toyear ) ); 185 query.append ( QString::number ( toyear ) );
187 query.append ( " and ( ( month <= " ); 186 query.append ( " and ( ( month <= " );
188 query.append ( QString::number ( tomonth ) ); 187 query.append ( QString::number ( tomonth ) );
189 query.append ( " and month > " ); 188 query.append ( " and month > " );
190 query.append ( QString::number ( frommonth ) ); 189 query.append ( QString::number ( frommonth ) );
191 query.append ( " ) or ( month = " ); 190 query.append ( " ) or ( month = " );
192 query.append ( QString::number ( frommonth ) ); 191 query.append ( QString::number ( frommonth ) );
193 query.append ( " and day >= " ); 192 query.append ( " and day >= " );
194 query.append ( QString::number ( fromday ) ); 193 query.append ( QString::number ( fromday ) );
195 query.append ( " ) ) and " ); 194 query.append ( " ) ) and " );
196 } 195 }
197 else if ( fromyear != toyear && fromyear != 1900 ) // here we are showing transactions from an entire year 196 else if ( fromyear != toyear && fromyear != 1900 ) // here we are showing transactions from an entire year
198 { 197 {
199 // divide this taks into two parts - get the transactions from the prior and then the current year 198 // divide this taks into two parts - get the transactions from the prior and then the current year
200 // current year part 199 // current year part
201 int tmpfrommonth = 1; // set temporary from months and days to Jan. 1 200 int tmpfrommonth = 1; // set temporary from months and days to Jan. 1
202 int tmpfromday = 1; 201 int tmpfromday = 1;
203 query.append ( " ( year >= " ); 202 query.append ( " ( year >= " );
204 query.append ( QString::number ( fromyear ) ); 203 query.append ( QString::number ( fromyear ) );
205 query.append ( " and ( month <= " ); 204 query.append ( " and ( month <= " );
206 query.append ( QString::number ( tomonth ) ); 205 query.append ( QString::number ( tomonth ) );
207 query.append ( " and month > " ); 206 query.append ( " and month > " );
208 query.append ( QString::number ( tmpfrommonth ) ); 207 query.append ( QString::number ( tmpfrommonth ) );
209 query.append ( " ) or ( month = " ); 208 query.append ( " ) or ( month = " );
210 query.append ( QString::number ( tmpfrommonth ) ); 209 query.append ( QString::number ( tmpfrommonth ) );
211 query.append ( " and day >= " ); 210 query.append ( " and day >= " );
212 query.append ( QString::number ( tmpfromday ) ); 211 query.append ( QString::number ( tmpfromday ) );
213 query.append ( " ) ) or" ); 212 query.append ( " ) ) or" );
214 213
215 // prior year part 214 // prior year part
216 int tmptomonth = 12; 215 int tmptomonth = 12;
217 query.append ( " ( year = " ); 216 query.append ( " ( year = " );
218 query.append ( QString::number ( fromyear ) ); 217 query.append ( QString::number ( fromyear ) );
219 query.append ( " and ( ( month <= " ); 218 query.append ( " and ( ( month <= " );
220 query.append ( QString::number ( tmptomonth ) ); 219 query.append ( QString::number ( tmptomonth ) );
221 query.append ( " and month > " ); 220 query.append ( " and month > " );
222 query.append ( QString::number ( frommonth ) ); 221 query.append ( QString::number ( frommonth ) );
223 query.append ( " ) or ( month = " ); 222 query.append ( " ) or ( month = " );
224 query.append ( QString::number ( frommonth ) ); 223 query.append ( QString::number ( frommonth ) );
225 query.append ( " and day >= " ); 224 query.append ( " and day >= " );
226 query.append ( QString::number ( fromday ) ); 225 query.append ( QString::number ( fromday ) );
227 query.append ( " ) ) ) and " ); 226 query.append ( " ) ) ) and " );
228 } 227 }
229 228
230 if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) 229 if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
231 query.append ( " parentid = %i and payee like '%q';" ); 230 query.append ( " parentid = %i and payee like '%q';" );
232 else 231 else
233 query.append ( " accountid = %i and payee like '%q';" ); 232 query.append ( " accountid = %i and payee like '%q';" );
234 233
235 sqlite_get_table_printf ( tdb, query, &results, &rows, &columns, NULL, id, limit ); 234 sqlite_get_table_printf ( tdb, query, &results, &rows, &columns, NULL, id, limit );
236 return results; 235 return results;
237 } 236 }
238 237
239char ** Transaction::selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id ) 238char ** Transaction::selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id )
240 { 239 {
241 char **results; 240 char **results;
242 if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) 241 if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
243 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); 242 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit );
244 else 243 else
245 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); 244 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit );
246 return results; 245 return results;
247 } 246 }
248 247
249void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate ) 248void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate )
250 { 249 {
251 int showcleared = preferences->getPreference ( 3 ); 250 int showcleared = preferences->getPreference ( 3 );
252 251
253 char **results; 252 char **results;
254 if ( showcleared == 0 ) 253 if ( showcleared == 0 )
255 results = selectNonClearedTransactions ( displaydate, children, limit, id ); 254 results = selectNonClearedTransactions ( displaydate, children, limit, id );
256 else 255 else
257 results = selectAllTransactions ( displaydate, children, limit, id ); 256 results = selectAllTransactions ( displaydate, children, limit, id );
258 257
259 // iterate through the result list and display each item 258 // iterate through the result list and display each item
260 int counter = 7; 259 int counter = 7;
261 while ( counter < ( ( rows + 1 ) * columns ) ) 260 while ( counter < ( ( rows + 1 ) * columns ) )
262 { 261 {
263 //QDate testdate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); 262 //QDate testdate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
264 QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); 263 QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
265 264
266 // construct transaction name, amount, id 265 // construct transaction name, amount, id
267 QString payee = results [ counter + 3 ]; 266 QString payee = results [ counter + 3 ];
268 QString amount = results [ counter + 4 ]; 267 QString amount = results [ counter + 4 ];
269 QString transferid = results [ counter + 5 ]; 268 QString transferid = results [ counter + 5 ];
270 269
271 //determine the account name of the child accounts that we're displaying 270 //determine the account name of the child accounts that we're displaying
272 QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) ); 271 QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) );
273 272
274 // fill in values 273 // fill in values
275 if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account 274 if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account
276 { 275 {
277 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) 276 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 )
278 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid ); 277 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid );
279 else 278 else
280 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid ); 279 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid );
281 } 280 }
282 else 281 else
283 { 282 {
284 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) 283 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 )
285 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname ); 284 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname );
286 else 285 else
287 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname ); 286 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname );
288 } 287 }
289 288
290 // advance counter 289 // advance counter
291 counter = counter + 7; 290 counter = counter + 7;
292 } 291 }
293 } 292 }
294 293
295QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ) 294QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype )
296 { 295 {
297 // determine if we are viewing a years, months, or days budget 296 // determine if we are viewing a years, months, or days budget
298 // we have to pick a different sum for each 297 // we have to pick a different sum for each
299 char **results; 298 char **results;
300 switch ( viewtype ) 299 switch ( viewtype )
301 { 300 {
302 case 1: // we are viewing a year 301 case 1: // we are viewing a year
303 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, budgetid, lineitemid ); 302 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, budgetid, lineitemid );
304 break; 303 break;
305 304
306 case 0: // we are viewing a month 305 case 0: // we are viewing a month
307 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, month, budgetid, lineitemid ); 306 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, month, budgetid, lineitemid );
308 break; 307 break;
309 } 308 }
310 QString amount = results [ 1 ]; 309 QString amount = results [ 1 ];
311 float total = amount.toFloat(); 310 float total = amount.toFloat();
312 amount.setNum ( total, 'f', 2 ); 311 amount.setNum ( total, 'f', 2 );
313 return amount; 312 return amount;
314 } 313 }
315 314
316QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype ) 315QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype )
317 { 316 {
318 // determine if we are viewing a years, months, or days budget 317 // determine if we are viewing a years, months, or days budget
319 // we have to pick a different sum for each 318 // we have to pick a different sum for each
320 char **results; 319 char **results;
321 switch ( viewtype ) 320 switch ( viewtype )
322 { 321 {
323 case 1: // we are viewing a year 322 case 1: // we are viewing a year
324 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, budgetid ); 323 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, budgetid );
325 break; 324 break;
326 325
327 case 0: // we are viewing a month 326 case 0: // we are viewing a month
328 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, month, budgetid ); 327 sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, month, budgetid );
329 break; 328 break;
330 } 329 }
331 QString amount = results [ 1 ]; 330 QString amount = results [ 1 ];
332 float total = amount.toFloat(); 331 float total = amount.toFloat();
333 amount.setNum ( total, 'f', 2 ); 332 amount.setNum ( total, 'f', 2 );
334 return amount; 333 return amount;
335 } 334 }
336 335
337void Transaction::clearBudgetIDs ( int budgetid, int lineitemid ) 336void Transaction::clearBudgetIDs ( int budgetid, int lineitemid )
338 { 337 {
339 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid ); 338 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid );
340 } 339 }
341 340
342void Transaction::clearBudgetIDs ( int budgetid ) 341void Transaction::clearBudgetIDs ( int budgetid )
343 { 342 {
344 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid ); 343 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid );
345 } 344 }
346 345
diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp
index 1839cd2..78b8a00 100755
--- a/noncore/apps/qashmoney/transactiondisplay.cpp
+++ b/noncore/apps/qashmoney/transactiondisplay.cpp
@@ -1,629 +1,628 @@
1#include "transactiondisplay.h" 1#include "transactiondisplay.h"
2#include "newtransaction.h" 2#include "newtransaction.h"
3#include "account.h" 3#include "account.h"
4#include "budget.h" 4#include "budget.h"
5#include "memory.h" 5#include "memory.h"
6#include "transfer.h" 6#include "transfer.h"
7#include "preferences.h" 7#include "preferences.h"
8#include "calculator.h" 8#include "calculator.h"
9#include "datepicker.h" 9#include "datepicker.h"
10 10
11#include <qdatetime.h> 11#include <qdatetime.h>
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13#include <qheader.h> 13#include <qheader.h>
14#include <qmultilineedit.h> 14#include <qmultilineedit.h>
15#include <iostream.h>
16#include <qdatetime.h> 15#include <qdatetime.h>
17 16
18extern Transaction *transaction; 17extern Transaction *transaction;
19extern Budget *budget; 18extern Budget *budget;
20extern Account *account; 19extern Account *account;
21extern Preferences *preferences; 20extern Preferences *preferences;
22extern Memory *memory; 21extern Memory *memory;
23extern Transfer *transfer; 22extern Transfer *transfer;
24 23
25TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) 24TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent )
26 { 25 {
27 // set transactiondisplay variables; 26 // set transactiondisplay variables;
28 accountid = 0; 27 accountid = 0;
29 children = TRUE; 28 children = TRUE;
30 29
31 firstline = new QHBox ( this ); 30 firstline = new QHBox ( this );
32 firstline->setSpacing ( 2 ); 31 firstline->setSpacing ( 2 );
33 32
34 newtransaction = new QPushButton ( firstline ); 33 newtransaction = new QPushButton ( firstline );
35 newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); 34 newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
36 connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) ); 35 connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) );
37 36
38 edittransaction = new QPushButton ( firstline ); 37 edittransaction = new QPushButton ( firstline );
39 edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); 38 edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
40 connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) ); 39 connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) );
41 40
42 deletetransaction = new QPushButton ( firstline ); 41 deletetransaction = new QPushButton ( firstline );
43 deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); 42 deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
44 connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) ); 43 connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) );
45 44
46 toggletransaction = new QPushButton ( firstline ); 45 toggletransaction = new QPushButton ( firstline );
47 toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); 46 toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") );
48 connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) ); 47 connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) );
49 48
50 viewtransactionnotes = new QPushButton ( firstline ); 49 viewtransactionnotes = new QPushButton ( firstline );
51 viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); 50 viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") );
52 connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) ); 51 connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) );
53 52
54 secondline = new QHBox ( this ); 53 secondline = new QHBox ( this );
55 secondline->setSpacing ( 5 ); 54 secondline->setSpacing ( 5 );
56 55
57 name = new QLabel ( secondline ); 56 name = new QLabel ( secondline );
58 balance = new QLabel ( secondline ); 57 balance = new QLabel ( secondline );
59 58
60 QLabel *limit = new QLabel ( "Limit", secondline ); 59 QLabel *limit = new QLabel ( "Limit", secondline );
61 limitbox = new QLineEdit ( secondline ); 60 limitbox = new QLineEdit ( secondline );
62 limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); 61 limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) );
63 connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) ); 62 connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) );
64 63
65 listview = new QListView ( this ); 64 listview = new QListView ( this );
66 listview->setAllColumnsShowFocus ( TRUE ); 65 listview->setAllColumnsShowFocus ( TRUE );
67 listview->setShowSortIndicator ( TRUE ); 66 listview->setShowSortIndicator ( TRUE );
68 listview->header()->setTracking ( FALSE ); 67 listview->header()->setTracking ( FALSE );
69 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 68 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
70 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); 69 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
71 70
72 layout = new QVBoxLayout ( this, 2, 2 ); 71 layout = new QVBoxLayout ( this, 2, 2 );
73 layout->addWidget ( firstline ); 72 layout->addWidget ( firstline );
74 layout->addWidget ( secondline ); 73 layout->addWidget ( secondline );
75 layout->addWidget ( listview ); 74 layout->addWidget ( listview );
76 } 75 }
77 76
78void TransactionDisplay::addTransaction () 77void TransactionDisplay::addTransaction ()
79 { 78 {
80 // create local variables 79 // create local variables
81 int cleared = -1; 80 int cleared = -1;
82 81
83 // create new transaction window 82 // create new transaction window
84 NewTransaction *newtransaction = new NewTransaction ( this ); 83 NewTransaction *newtransaction = new NewTransaction ( this );
85 int width = this->size().width(); 84 int width = this->size().width();
86 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 85 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
87 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); 86 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
88 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 87 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
89 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 88 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
90 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 89 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
91 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); 90 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
92 91
93 // enter today's date in the date box as defaul 92 // enter today's date in the date box as defaul
94 QDate today = QDate::currentDate (); 93 QDate today = QDate::currentDate ();
95 int defaultday = today.day(); 94 int defaultday = today.day();
96 int defaultmonth = today.month(); 95 int defaultmonth = today.month();
97 int defaultyear = today.year(); 96 int defaultyear = today.year();
98 newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 97 newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
99 98
100 // add memory items to the transactionname combobox 99 // add memory items to the transactionname combobox
101 memory->displayMemoryItems ( newtransaction->transactionname ); 100 memory->displayMemoryItems ( newtransaction->transactionname );
102 newtransaction->transactionname->insertItem ( "", 0 ); 101 newtransaction->transactionname->insertItem ( "", 0 );
103 102
104 if ( newtransaction->exec () == QDialog::Accepted ) 103 if ( newtransaction->exec () == QDialog::Accepted )
105 { 104 {
106 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction 105 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction
107 cleared = 1; 106 cleared = 1;
108 else 107 else
109 cleared = 0; 108 cleared = 0;
110 109
111 float amount = newtransaction->transactionamount->text().toFloat(); 110 float amount = newtransaction->transactionamount->text().toFloat();
112 if ( newtransaction->depositbox->isChecked() == FALSE ) 111 if ( newtransaction->depositbox->isChecked() == FALSE )
113 amount = amount * -1; 112 amount = amount * -1;
114 113
115 // add the transaction name to the memory items 114 // add the transaction name to the memory items
116 memory->addMemoryItem ( newtransaction->transactionname->currentText() ); 115 memory->addMemoryItem ( newtransaction->transactionname->currentText() );
117 116
118 // add the transaction 117 // add the transaction
119 if ( newtransaction->getDateEdited () == TRUE ) 118 if ( newtransaction->getDateEdited () == TRUE )
120 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), 119 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
121 newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), 120 newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(),
122 newtransaction->getCurrentLineItem() ); 121 newtransaction->getCurrentLineItem() );
123 else 122 else
124 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), 123 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
125 newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); 124 newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() );
126 125
127 // redisplay transactions 126 // redisplay transactions
128 listview->clear(); 127 listview->clear();
129 QString displaytext = "%"; 128 QString displaytext = "%";
130 displaytext.prepend ( limitbox->text() ); 129 displaytext.prepend ( limitbox->text() );
131 setTransactionDisplayDate (); 130 setTransactionDisplayDate ();
132 if ( transaction->getNumberOfTransactions() > 0 ) 131 if ( transaction->getNumberOfTransactions() > 0 )
133 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 132 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
134 133
135 // redisplay transfers 134 // redisplay transfers
136 if ( transfer->getNumberOfTransfers() > 0 ) 135 if ( transfer->getNumberOfTransfers() > 0 )
137 transfer->displayTransfers ( listview, accountid, children, displaydate ); 136 transfer->displayTransfers ( listview, accountid, children, displaydate );
138 137
139 // add the transaction amount to the account it's associated with 138 // add the transaction amount to the account it's associated with
140 // and update its parent account balance if necessary 139 // and update its parent account balance if necessary
141 account->updateAccountBalance ( accountid ); 140 account->updateAccountBalance ( accountid );
142 if ( account->getParentAccountID ( accountid ) != -1 ) 141 if ( account->getParentAccountID ( accountid ) != -1 )
143 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); 142 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
144 143
145 // format then reset the account balance 144 // format then reset the account balance
146 redisplayAccountBalance (); 145 redisplayAccountBalance ();
147 } 146 }
148 } 147 }
149 148
150void TransactionDisplay::checkListViewEdit () 149void TransactionDisplay::checkListViewEdit ()
151 { 150 {
152 if ( listview->selectedItem() == 0 ) 151 if ( listview->selectedItem() == 0 )
153 QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); 152 QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit.");
154 else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) 153 else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
155 editTransfer (); 154 editTransfer ();
156 else 155 else
157 editTransaction(); 156 editTransaction();
158 } 157 }
159 158
160void TransactionDisplay::showCalculator () 159void TransactionDisplay::showCalculator ()
161 { 160 {
162 Calculator *calculator = new Calculator ( this ); 161 Calculator *calculator = new Calculator ( this );
163 if ( calculator->exec () == QDialog::Accepted ) 162 if ( calculator->exec () == QDialog::Accepted )
164 amount->setText ( calculator->display->text() ); 163 amount->setText ( calculator->display->text() );
165 } 164 }
166 165
167void TransactionDisplay::showCalendar () 166void TransactionDisplay::showCalendar ()
168 { 167 {
169 QDate newDate = QDate::currentDate (); 168 QDate newDate = QDate::currentDate ();
170 DatePicker *dp = new DatePicker ( newDate ); 169 DatePicker *dp = new DatePicker ( newDate );
171 if ( dp->exec () == QDialog::Accepted ) 170 if ( dp->exec () == QDialog::Accepted )
172 { 171 {
173 year = dp->getYear(); 172 year = dp->getYear();
174 month = dp->getMonth(); 173 month = dp->getMonth();
175 day = dp->getDay(); 174 day = dp->getDay();
176 date->setText ( preferences->getDate ( year, month, day ) ); 175 date->setText ( preferences->getDate ( year, month, day ) );
177 } 176 }
178 } 177 }
179 178
180void TransactionDisplay::editTransfer () 179void TransactionDisplay::editTransfer ()
181 { 180 {
182 transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); 181 transferid = listview->currentItem()->text ( getIDColumn() ).toInt();
183 fromaccount = transfer->getFromAccountID ( transferid ); 182 fromaccount = transfer->getFromAccountID ( transferid );
184 toaccount = transfer->getToAccountID ( transferid ); 183 toaccount = transfer->getToAccountID ( transferid );
185 year = transfer->getYear ( transferid ); 184 year = transfer->getYear ( transferid );
186 month = transfer->getMonth ( transferid ); 185 month = transfer->getMonth ( transferid );
187 day = transfer->getDay ( transferid ); 186 day = transfer->getDay ( transferid );
188 187
189 QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); 188 QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE );
190 editransfer->setCaption ( "Transfer" ); 189 editransfer->setCaption ( "Transfer" );
191 190
192 QStringList accountnames = account->getAccountNames(); 191 QStringList accountnames = account->getAccountNames();
193 QStringList accountids = account->getAccountIDs(); 192 QStringList accountids = account->getAccountIDs();
194 193
195 QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); 194 QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer );
196 QFont f = this->font(); 195 QFont f = this->font();
197 f.setWeight ( QFont::Bold ); 196 f.setWeight ( QFont::Bold );
198 fromaccountlabel->setFont ( f ); 197 fromaccountlabel->setFont ( f );
199 198
200 QComboBox *fromaccountbox = new QComboBox ( editransfer ); 199 QComboBox *fromaccountbox = new QComboBox ( editransfer );
201 fromaccountbox->insertStringList ( accountnames ); 200 fromaccountbox->insertStringList ( accountnames );
202 fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); 201 fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) );
203 202
204 QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); 203 QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer );
205 toaccountlabel->setFont ( f ); 204 toaccountlabel->setFont ( f );
206 205
207 QComboBox *toaccountbox = new QComboBox ( editransfer ); 206 QComboBox *toaccountbox = new QComboBox ( editransfer );
208 toaccountbox->insertStringList ( accountnames ); 207 toaccountbox->insertStringList ( accountnames );
209 toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); 208 toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) );
210 209
211 QLabel *datelabel = new QLabel ( "Date", editransfer ); 210 QLabel *datelabel = new QLabel ( "Date", editransfer );
212 QHBox *datebox = new QHBox ( editransfer ); 211 QHBox *datebox = new QHBox ( editransfer );
213 datebox->setSpacing ( 2 ); 212 datebox->setSpacing ( 2 );
214 date = new QLineEdit ( datebox ); 213 date = new QLineEdit ( datebox );
215 date->setAlignment ( Qt::AlignRight ); 214 date->setAlignment ( Qt::AlignRight );
216 date->setDisabled ( TRUE ); 215 date->setDisabled ( TRUE );
217 date->setText ( preferences->getDate ( year, month, day ) ); 216 date->setText ( preferences->getDate ( year, month, day ) );
218 QPushButton *datebutton = new QPushButton ( datebox ); 217 QPushButton *datebutton = new QPushButton ( datebox );
219 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 218 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
220 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 219 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
221 220
222 QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); 221 QLabel *amounttlabel = new QLabel ( "Amount", editransfer );
223 222
224 QHBox *amountbox = new QHBox ( editransfer ); 223 QHBox *amountbox = new QHBox ( editransfer );
225 amountbox->setSpacing ( 2 ); 224 amountbox->setSpacing ( 2 );
226 amount = new QLineEdit ( amountbox ); 225 amount = new QLineEdit ( amountbox );
227 amount->setAlignment ( Qt::AlignRight ); 226 amount->setAlignment ( Qt::AlignRight );
228 amount->setText ( transfer->getAmount ( transferid ) ); 227 amount->setText ( transfer->getAmount ( transferid ) );
229 QPushButton *calculatorbutton = new QPushButton( amountbox ); 228 QPushButton *calculatorbutton = new QPushButton( amountbox );
230 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 229 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
231 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 230 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
232 231
233 QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); 232 QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer );
234 233
235 QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); 234 QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 );
236 layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); 235 layout->addWidget ( fromaccountlabel, Qt::AlignLeft );
237 layout->addWidget ( fromaccountbox, Qt::AlignLeft ); 236 layout->addWidget ( fromaccountbox, Qt::AlignLeft );
238 layout->addWidget ( toaccountlabel, Qt::AlignLeft ); 237 layout->addWidget ( toaccountlabel, Qt::AlignLeft );
239 layout->addWidget ( toaccountbox, Qt::AlignLeft ); 238 layout->addWidget ( toaccountbox, Qt::AlignLeft );
240 layout->addSpacing ( 5 ); 239 layout->addSpacing ( 5 );
241 layout->addWidget ( datelabel, Qt::AlignLeft ); 240 layout->addWidget ( datelabel, Qt::AlignLeft );
242 layout->addWidget ( datebox, Qt::AlignLeft ); 241 layout->addWidget ( datebox, Qt::AlignLeft );
243 layout->addWidget ( amounttlabel, Qt::AlignLeft ); 242 layout->addWidget ( amounttlabel, Qt::AlignLeft );
244 layout->addWidget ( amountbox, Qt::AlignLeft ); 243 layout->addWidget ( amountbox, Qt::AlignLeft );
245 layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); 244 layout->addWidget ( clearedcheckbox, Qt::AlignLeft );
246 245
247 if ( editransfer->exec() == QDialog::Accepted ) 246 if ( editransfer->exec() == QDialog::Accepted )
248 { 247 {
249 //get fromaccount 248 //get fromaccount
250 fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); 249 fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt();
251 250
252 //get to account 251 //get to account
253 toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); 252 toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt();
254 253
255 //set cleared flag 254 //set cleared flag
256 int cleared = 0; 255 int cleared = 0;
257 if ( clearedcheckbox->isChecked() == TRUE ) 256 if ( clearedcheckbox->isChecked() == TRUE )
258 cleared = 1; 257 cleared = 1;
259 258
260 //update transfer 259 //update transfer
261 transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), 260 transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ),
262 day, month, year, amount->text().toFloat(), cleared, transferid ); 261 day, month, year, amount->text().toFloat(), cleared, transferid );
263 262
264 account->updateAccountBalance ( fromaccount ); 263 account->updateAccountBalance ( fromaccount );
265 if ( account->getParentAccountID ( fromaccount ) != -1 ) 264 if ( account->getParentAccountID ( fromaccount ) != -1 )
266 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); 265 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) );
267 266
268 updateAndDisplay ( toaccount ); 267 updateAndDisplay ( toaccount );
269 } 268 }
270 } 269 }
271 270
272void TransactionDisplay::editTransaction () 271void TransactionDisplay::editTransaction ()
273 { 272 {
274 int cleared; 273 int cleared;
275 274
276 // set the transaction id and budgetid 275 // set the transaction id and budgetid
277 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 276 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
278 int budgetid = transaction->getBudgetID ( transactionid ); 277 int budgetid = transaction->getBudgetID ( transactionid );
279 int lineitemid = transaction->getLineItemID ( transactionid ); 278 int lineitemid = transaction->getLineItemID ( transactionid );
280 279
281 // create edit transaction window 280 // create edit transaction window
282 NewTransaction *newtransaction = new NewTransaction ( this ); 281 NewTransaction *newtransaction = new NewTransaction ( this );
283 int width = this->width(); 282 int width = this->width();
284 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 283 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
285 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); 284 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
286 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 285 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
287 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 286 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
288 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 287 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
289 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); 288 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
290 289
291 // enter the date in the date box 290 // enter the date in the date box
292 newtransaction->year = transaction->getYear ( transactionid ); 291 newtransaction->year = transaction->getYear ( transactionid );
293 newtransaction->month = transaction->getMonth ( transactionid ); 292 newtransaction->month = transaction->getMonth ( transactionid );
294 newtransaction->day = transaction->getDay ( transactionid ); 293 newtransaction->day = transaction->getDay ( transactionid );
295 newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); 294 newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) );
296 295
297 // set the description 296 // set the description
298 newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); 297 newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) );
299 298
300 // add memory items to the transactionname combobox 299 // add memory items to the transactionname combobox
301 memory->displayMemoryItems ( newtransaction->transactionname ); 300 memory->displayMemoryItems ( newtransaction->transactionname );
302 301
303 // add correct transaction name 302 // add correct transaction name
304 newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); 303 newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) );
305 304
306 // add transaction number 305 // add transaction number
307 newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); 306 newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) );
308 307
309 // add transaction amount 308 // add transaction amount
310 newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); 309 newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) );
311 310
312 // check for and set the correct budget 311 // check for and set the correct budget
313 if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item 312 if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item
314 { 313 {
315 newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); 314 newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 );
316 if ( lineitemid >= 1 ) 315 if ( lineitemid >= 1 )
317 { 316 {
318 newtransaction->setLineItems (); 317 newtransaction->setLineItems ();
319 newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); 318 newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) );
320 } 319 }
321 else 320 else
322 { 321 {
323 newtransaction->lineitemlabel->setEnabled ( FALSE ); 322 newtransaction->lineitemlabel->setEnabled ( FALSE );
324 newtransaction->lineitembox->setEnabled ( FALSE ); 323 newtransaction->lineitembox->setEnabled ( FALSE );
325 } 324 }
326 } 325 }
327 else 326 else
328 { 327 {
329 newtransaction->lineitemlabel->setEnabled ( FALSE ); 328 newtransaction->lineitemlabel->setEnabled ( FALSE );
330 newtransaction->lineitembox->setEnabled ( FALSE ); 329 newtransaction->lineitembox->setEnabled ( FALSE );
331 } 330 }
332 331
333 // check cleared checkbox if necessary 332 // check cleared checkbox if necessary
334 if ( transaction->getCleared ( transactionid ) == 1 ) 333 if ( transaction->getCleared ( transactionid ) == 1 )
335 newtransaction->clearedcheckbox->setChecked ( TRUE ); 334 newtransaction->clearedcheckbox->setChecked ( TRUE );
336 335
337 // check deposit box if necessary 336 // check deposit box if necessary
338 if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) 337 if ( transaction->getAmount ( transactionid ).toFloat() > 0 )
339 newtransaction->depositbox->setChecked ( TRUE ); 338 newtransaction->depositbox->setChecked ( TRUE );
340 339
341 if ( newtransaction->exec () == QDialog::Accepted ) 340 if ( newtransaction->exec () == QDialog::Accepted )
342 { 341 {
343 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) 342 if ( newtransaction->clearedcheckbox->isChecked () == TRUE )
344 cleared = 1; 343 cleared = 1;
345 else 344 else
346 cleared = 0; 345 cleared = 0;
347 346
348 float amount = newtransaction->transactionamount->text().toFloat(); 347 float amount = newtransaction->transactionamount->text().toFloat();
349 if ( newtransaction->depositbox->isChecked() == FALSE ) 348 if ( newtransaction->depositbox->isChecked() == FALSE )
350 amount = amount * -1; 349 amount = amount * -1;
351 350
352 // add the transaction name to the memory items 351 // add the transaction name to the memory items
353 memory->addMemoryItem ( newtransaction->transactionname->currentText() ); 352 memory->addMemoryItem ( newtransaction->transactionname->currentText() );
354 353
355 // update the transaction 354 // update the transaction
356 transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), 355 transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(),
357 newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), 356 newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(),
358 amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); 357 amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid );
359 358
360 updateAndDisplay ( transaction->getAccountID ( transactionid ) ); 359 updateAndDisplay ( transaction->getAccountID ( transactionid ) );
361 } 360 }
362 } 361 }
363 362
364void TransactionDisplay::updateAndDisplay ( int id ) 363void TransactionDisplay::updateAndDisplay ( int id )
365 { 364 {
366 // redisplay transactions 365 // redisplay transactions
367 listview->clear(); 366 listview->clear();
368 QString displaytext = "%"; 367 QString displaytext = "%";
369 displaytext.prepend ( limitbox->text() ); 368 displaytext.prepend ( limitbox->text() );
370 setTransactionDisplayDate (); 369 setTransactionDisplayDate ();
371 if ( transaction->getNumberOfTransactions() > 0 ) 370 if ( transaction->getNumberOfTransactions() > 0 )
372 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 371 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
373 372
374 // redisplay transfers 373 // redisplay transfers
375 if ( transfer->getNumberOfTransfers() > 0 ) 374 if ( transfer->getNumberOfTransfers() > 0 )
376 transfer->displayTransfers ( listview, accountid, children, displaydate ); 375 transfer->displayTransfers ( listview, accountid, children, displaydate );
377 376
378 // add the transaction amount to the account it's associated with 377 // add the transaction amount to the account it's associated with
379 // and update its parent account balance if necessary 378 // and update its parent account balance if necessary
380 account->updateAccountBalance ( id ); 379 account->updateAccountBalance ( id );
381 if ( account->getParentAccountID ( id ) != -1 ) 380 if ( account->getParentAccountID ( id ) != -1 )
382 account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); 381 account->changeParentAccountBalance ( account->getParentAccountID ( id ) );
383 382
384 // format then reset the account balance 383 // format then reset the account balance
385 redisplayAccountBalance (); 384 redisplayAccountBalance ();
386 } 385 }
387 386
388void TransactionDisplay::checkListViewDelete () 387void TransactionDisplay::checkListViewDelete ()
389 { 388 {
390 if ( listview->selectedItem() == 0 ) 389 if ( listview->selectedItem() == 0 )
391 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); 390 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete.");
392 else 391 else
393 deleteTransaction (); 392 deleteTransaction ();
394 } 393 }
395 394
396void TransactionDisplay::deleteTransaction () 395void TransactionDisplay::deleteTransaction ()
397 { 396 {
398 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 397 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
399 398
400 if ( transactionid > 0 ) // takes care of deleting transactions 399 if ( transactionid > 0 ) // takes care of deleting transactions
401 { 400 {
402 // check if we are viewing child transactions through a parent 401 // check if we are viewing child transactions through a parent
403 // in that case we will have to update balances for the parent 402 // in that case we will have to update balances for the parent
404 // which is represented by accountid and the child account 403 // which is represented by accountid and the child account
405 // which will be represented by childaccountid 404 // which will be represented by childaccountid
406 int childaccountid = -1; 405 int childaccountid = -1;
407 if ( listview->columns() == 5 ) 406 if ( listview->columns() == 5 )
408 childaccountid = transaction->getAccountID ( transactionid ); 407 childaccountid = transaction->getAccountID ( transactionid );
409 408
410 transaction->deleteTransaction ( transactionid ); 409 transaction->deleteTransaction ( transactionid );
411 410
412 listview->clear(); 411 listview->clear();
413 QString displaytext = "%"; 412 QString displaytext = "%";
414 displaytext.prepend ( limitbox->text() ); 413 displaytext.prepend ( limitbox->text() );
415 setTransactionDisplayDate (); 414 setTransactionDisplayDate ();
416 if ( transaction->getNumberOfTransactions() > 0 ) 415 if ( transaction->getNumberOfTransactions() > 0 )
417 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 416 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
418 417
419 if ( transfer->getNumberOfTransfers() > 0 ) 418 if ( transfer->getNumberOfTransfers() > 0 )
420 transfer->displayTransfers ( listview, accountid, children, displaydate ); 419 transfer->displayTransfers ( listview, accountid, children, displaydate );
421 420
422 // if we are viewing different child accounts through the parent account 421 // if we are viewing different child accounts through the parent account
423 // ie if there are five columns and the parentid is -1 422 // ie if there are five columns and the parentid is -1
424 // update the accountid ( which is the parent ) and update the child account 423 // update the accountid ( which is the parent ) and update the child account
425 // balance. Get its accountid from the transactionid 424 // balance. Get its accountid from the transactionid
426 account->updateAccountBalance ( accountid ); // will update either a parent or child 425 account->updateAccountBalance ( accountid ); // will update either a parent or child
427 if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one 426 if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one
428 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); 427 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
429 if ( childaccountid != -1 ) // we've set childaccountid 428 if ( childaccountid != -1 ) // we've set childaccountid
430 account->updateAccountBalance ( childaccountid ); 429 account->updateAccountBalance ( childaccountid );
431 430
432 // format then reset the account balance 431 // format then reset the account balance
433 redisplayAccountBalance (); 432 redisplayAccountBalance ();
434 } 433 }
435 else // takes care of deleting transfers 434 else // takes care of deleting transfers
436 { 435 {
437 // get the accountids before we delete the transfer 436 // get the accountids before we delete the transfer
438 int fromaccountid = transfer->getFromAccountID ( transactionid ); 437 int fromaccountid = transfer->getFromAccountID ( transactionid );
439 int toaccountid = transfer->getToAccountID ( transactionid ); 438 int toaccountid = transfer->getToAccountID ( transactionid );
440 439
441 // delete the transfer and redisplay transactions 440 // delete the transfer and redisplay transactions
442 transfer->deleteTransfer ( transactionid ); 441 transfer->deleteTransfer ( transactionid );
443 442
444 listview->clear(); 443 listview->clear();
445 QString displaytext = "%"; 444 QString displaytext = "%";
446 displaytext.prepend ( limitbox->text() ); 445 displaytext.prepend ( limitbox->text() );
447 setTransactionDisplayDate (); 446 setTransactionDisplayDate ();
448 if ( transaction->getNumberOfTransactions() > 0 ) 447 if ( transaction->getNumberOfTransactions() > 0 )
449 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 448 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
450 449
451 if ( transfer->getNumberOfTransfers() > 0 ) 450 if ( transfer->getNumberOfTransfers() > 0 )
452 transfer->displayTransfers ( listview, accountid, children, displaydate ); 451 transfer->displayTransfers ( listview, accountid, children, displaydate );
453 452
454 // for the from account 453 // for the from account
455 account->updateAccountBalance ( fromaccountid ); 454 account->updateAccountBalance ( fromaccountid );
456 if ( account->getParentAccountID ( fromaccountid ) != -1 ) 455 if ( account->getParentAccountID ( fromaccountid ) != -1 )
457 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) ); 456 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) );
458 457
459 // for the to account 458 // for the to account
460 account->updateAccountBalance ( toaccountid ); 459 account->updateAccountBalance ( toaccountid );
461 if ( account->getParentAccountID ( toaccountid ) != -1 ) 460 if ( account->getParentAccountID ( toaccountid ) != -1 )
462 account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) ); 461 account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) );
463 462
464 // format then reset the account balance 463 // format then reset the account balance
465 redisplayAccountBalance (); 464 redisplayAccountBalance ();
466 } 465 }
467 } 466 }
468 467
469void TransactionDisplay::checkListViewToggle () 468void TransactionDisplay::checkListViewToggle ()
470 { 469 {
471 if ( listview->selectedItem() == 0 ) 470 if ( listview->selectedItem() == 0 )
472 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset."); 471 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset.");
473 else 472 else
474 toggleTransaction (); 473 toggleTransaction ();
475 } 474 }
476 475
477void TransactionDisplay::toggleTransaction () 476void TransactionDisplay::toggleTransaction ()
478 { 477 {
479 //get the transaction of the selected transaction to determine if its a transaction or transfer 478 //get the transaction of the selected transaction to determine if its a transaction or transfer
480 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 479 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
481 480
482 if ( transactionid > 0 ) // if this is a transaction 481 if ( transactionid > 0 ) // if this is a transaction
483 { 482 {
484 if ( transaction->getCleared ( transactionid ) == 0 ) 483 if ( transaction->getCleared ( transactionid ) == 0 )
485 transaction->setCleared ( transactionid, 1 ); 484 transaction->setCleared ( transactionid, 1 );
486 else 485 else
487 transaction->setCleared ( transactionid, 0 ); 486 transaction->setCleared ( transactionid, 0 );
488 } 487 }
489 else 488 else
490 { 489 {
491 if ( transfer->getCleared ( transactionid ) == 0 ) 490 if ( transfer->getCleared ( transactionid ) == 0 )
492 transfer->setCleared ( transactionid, 1 ); 491 transfer->setCleared ( transactionid, 1 );
493 else 492 else
494 transfer->setCleared ( transactionid, 0 ); 493 transfer->setCleared ( transactionid, 0 );
495 } 494 }
496 495
497 listview->clear(); 496 listview->clear();
498 QString displaytext = "%"; 497 QString displaytext = "%";
499 displaytext.prepend ( limitbox->text() ); 498 displaytext.prepend ( limitbox->text() );
500 setTransactionDisplayDate (); 499 setTransactionDisplayDate ();
501 if ( transaction->getNumberOfTransactions() > 0 ) 500 if ( transaction->getNumberOfTransactions() > 0 )
502 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 501 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
503 502
504 if ( transfer->getNumberOfTransfers() != 0 ) 503 if ( transfer->getNumberOfTransfers() != 0 )
505 transfer->displayTransfers ( listview, accountid, children, displaydate ); 504 transfer->displayTransfers ( listview, accountid, children, displaydate );
506 } 505 }
507 506
508void TransactionDisplay::redisplayAccountBalance () 507void TransactionDisplay::redisplayAccountBalance ()
509 { 508 {
510 QString accountbalance = account->getAccountBalance ( accountid ); 509 QString accountbalance = account->getAccountBalance ( accountid );
511 balance->setText ( accountbalance ); 510 balance->setText ( accountbalance );
512 } 511 }
513 512
514void TransactionDisplay::setChildren ( bool c ) 513void TransactionDisplay::setChildren ( bool c )
515 { 514 {
516 children = c; 515 children = c;
517 } 516 }
518 517
519void TransactionDisplay::setAccountID ( int id ) 518void TransactionDisplay::setAccountID ( int id )
520 { 519 {
521 accountid = id; 520 accountid = id;
522 } 521 }
523 522
524ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent ) 523ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent )
525 { 524 {
526 } 525 }
527 526
528ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) 527ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
529 : QListViewItem ( parent, label1, label2, label3, label4 ) 528 : QListViewItem ( parent, label1, label2, label3, label4 )
530 { 529 {
531 } 530 }
532 531
533ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) 532ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
534 : QListViewItem ( parent, label1, label2, label3, label4, label5 ) 533 : QListViewItem ( parent, label1, label2, label3, label4, label5 )
535 { 534 {
536 } 535 }
537 536
538void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) 537void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
539 { 538 {
540 QColorGroup _cg ( cg ); 539 QColorGroup _cg ( cg );
541 _cg.setColor ( QColorGroup::Text, Qt::red ); 540 _cg.setColor ( QColorGroup::Text, Qt::red );
542 QListViewItem::paintCell ( p, _cg, column, width, alignment ); 541 QListViewItem::paintCell ( p, _cg, column, width, alignment );
543 } 542 }
544 543
545void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 544void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize )
546 { 545 {
547 if ( listview->columns() == 4 ) 546 if ( listview->columns() == 4 )
548 preferences->changeColumnPreference ( column + 3, newsize ); 547 preferences->changeColumnPreference ( column + 3, newsize );
549 else if ( listview->columns() == 5 && column != 4 ) 548 else if ( listview->columns() == 5 && column != 4 )
550 preferences->changeColumnPreference ( column + 6, newsize ); 549 preferences->changeColumnPreference ( column + 6, newsize );
551 else 550 else
552 preferences->changeColumnPreference ( 9, newsize ); 551 preferences->changeColumnPreference ( 9, newsize );
553 } 552 }
554 553
555void TransactionDisplay::saveSortingPreference ( int column ) 554void TransactionDisplay::saveSortingPreference ( int column )
556 { 555 {
557 preferences->changeSortingPreference ( 2, column ); 556 preferences->changeSortingPreference ( 2, column );
558 } 557 }
559 558
560void TransactionDisplay::limitDisplay ( const QString &text ) 559void TransactionDisplay::limitDisplay ( const QString &text )
561 { 560 {
562 listview->clear (); 561 listview->clear ();
563 QString displaytext = "%"; 562 QString displaytext = "%";
564 displaytext.prepend ( text ); 563 displaytext.prepend ( text );
565 setTransactionDisplayDate (); 564 setTransactionDisplayDate ();
566 if ( transaction->getNumberOfTransactions() > 0 ) 565 if ( transaction->getNumberOfTransactions() > 0 )
567 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 566 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
568 567
569 if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) 568 if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 )
570 transfer->displayTransfers ( listview, accountid, children, displaydate ); 569 transfer->displayTransfers ( listview, accountid, children, displaydate );
571 } 570 }
572 571
573int TransactionDisplay::getIDColumn () 572int TransactionDisplay::getIDColumn ()
574 { 573 {
575 int counter; 574 int counter;
576 int columns = listview->columns(); 575 int columns = listview->columns();
577 for ( counter = 0; counter <= columns; counter++ ) 576 for ( counter = 0; counter <= columns; counter++ )
578 if ( listview->header()->label ( counter ).length() == 0 ) 577 if ( listview->header()->label ( counter ).length() == 0 )
579 return counter; 578 return counter;
580 } 579 }
581 580
582void TransactionDisplay::showTransactionNotes () 581void TransactionDisplay::showTransactionNotes ()
583 { 582 {
584 if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) 583 if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
585 QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes."); 584 QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes.");
586 else 585 else
587 { 586 {
588 int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt (); 587 int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
589 QDialog *description = new QDialog ( this, "description", TRUE ); 588 QDialog *description = new QDialog ( this, "description", TRUE );
590 description->setCaption ( "Notes" ); 589 description->setCaption ( "Notes" );
591 QMultiLineEdit *notes = new QMultiLineEdit ( description ); 590 QMultiLineEdit *notes = new QMultiLineEdit ( description );
592 notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); 591 notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
593 notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); 592 notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
594 notes->setWordWrap ( QMultiLineEdit::WidgetWidth ); 593 notes->setWordWrap ( QMultiLineEdit::WidgetWidth );
595 notes->setEnabled ( FALSE ); 594 notes->setEnabled ( FALSE );
596 notes->setText ( transaction->getTransactionDescription ( transactionid ) ); 595 notes->setText ( transaction->getTransactionDescription ( transactionid ) );
597 description->show(); 596 description->show();
598 } 597 }
599 } 598 }
600 599
601void TransactionDisplay::setTransactionDisplayDate () 600void TransactionDisplay::setTransactionDisplayDate ()
602 { 601 {
603 // determine how many days of transactions to show 602 // determine how many days of transactions to show
604 int limittype = preferences->getPreference ( 7 ); 603 int limittype = preferences->getPreference ( 7 );
605 if ( limittype != 5 ) // set today's date if we are not showing all transactions 604 if ( limittype != 5 ) // set today's date if we are not showing all transactions
606 { 605 {
607 QDate today = QDate::currentDate (); 606 QDate today = QDate::currentDate ();
608 switch ( limittype ) // if we are not showing all transactions 607 switch ( limittype ) // if we are not showing all transactions
609 { 608 {
610 case 0: // viewing two weeks 609 case 0: // viewing two weeks
611 displaydate = today.addDays ( -14 ); 610 displaydate = today.addDays ( -14 );
612 break; 611 break;
613 case 1: // viewing one month 612 case 1: // viewing one month
614 displaydate = today.addDays ( -30 ); 613 displaydate = today.addDays ( -30 );
615 break; 614 break;
616 case 2: // three months 615 case 2: // three months
617 displaydate = today.addDays ( -90 ); 616 displaydate = today.addDays ( -90 );
618 break; 617 break;
619 case 3: // six months 618 case 3: // six months
620 displaydate = today.addDays ( -180 ); 619 displaydate = today.addDays ( -180 );
621 break; 620 break;
622 case 4: // one year 621 case 4: // one year
623 displaydate = today.addDays ( -365 ); 622 displaydate = today.addDays ( -365 );
624 break; 623 break;
625 } 624 }
626 } 625 }
627 else 626 else
628 displaydate = QDate ( 1900, 1, 1 ); 627 displaydate = QDate ( 1900, 1, 1 );
629 } 628 }
diff --git a/noncore/apps/qashmoney/transfer.cpp b/noncore/apps/qashmoney/transfer.cpp
index c4bbaf9..ae1b748 100755
--- a/noncore/apps/qashmoney/transfer.cpp
+++ b/noncore/apps/qashmoney/transfer.cpp
@@ -1,260 +1,259 @@
1#include "transfer.h" 1#include "transfer.h"
2#include "account.h" 2#include "account.h"
3#include "transactiondisplay.h" 3#include "transactiondisplay.h"
4#include <stdlib.h> 4#include <stdlib.h>
5#include <iostream.h>
6 5
7extern Account *account; 6extern Account *account;
8extern Preferences *preferences; 7extern Preferences *preferences;
9 8
10Transfer::Transfer () 9Transfer::Transfer ()
11 { 10 {
12 db = sqlite_open ( "qmtransfers.db", 0, 0 ); 11 db = sqlite_open ( "qmtransfers.db", 0, 0 );
13 } 12 }
14 13
15Transfer::~Transfer () 14Transfer::~Transfer ()
16 { 15 {
17 sqlite_close ( db ); 16 sqlite_close ( db );
18 } 17 }
19 18
20void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared ) 19void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared )
21 { 20 {
22 int nextrowid = -1; 21 int nextrowid = -1;
23 char **results; 22 char **results;
24 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); 23 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 );
25 if ( atoi ( results [ 1 ] ) != 0 ) 24 if ( atoi ( results [ 1 ] ) != 0 )
26 { 25 {
27 char **results; 26 char **results;
28 sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 ); 27 sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 );
29 nextrowid = ( atoi ( results [ 1 ] ) ) - 1; 28 nextrowid = ( atoi ( results [ 1 ] ) ) - 1;
30 } 29 }
31 sqlite_exec_printf ( db, "insert into transfers values ( %i, %i, %i, %i, %i, %i, %i, 0, 0, %.2f, %i, 0, 0, 0, 0, 0, %i );", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, nextrowid ); 30 sqlite_exec_printf ( db, "insert into transfers values ( %i, %i, %i, %i, %i, %i, %i, 0, 0, %.2f, %i, 0, 0, 0, 0, 0, %i );", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, nextrowid );
32 } 31 }
33 32
34void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid ) 33void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid )
35 { 34 {
36 sqlite_exec_printf ( db, "update transfers set fromaccount = %i, fromparent = %i, toaccount = %i, toparent = %i, day = %i, month = %i, year = %i," 35 sqlite_exec_printf ( db, "update transfers set fromaccount = %i, fromparent = %i, toaccount = %i, toparent = %i, day = %i, month = %i, year = %i,"
37 "amount = %.2f, cleared = %i where transferid = %i;", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, transferid ); 36 "amount = %.2f, cleared = %i where transferid = %i;", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, transferid );
38 } 37 }
39 38
40void Transfer::deleteTransfer ( int transferid ) 39void Transfer::deleteTransfer ( int transferid )
41 { 40 {
42 sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid ); 41 sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid );
43 } 42 }
44 43
45void Transfer::deleteAllTransfers ( int accountid ) 44void Transfer::deleteAllTransfers ( int accountid )
46 { 45 {
47 sqlite_exec_printf ( db, "delete from transfers where fromaccount = %i;", 0, 0, 0, accountid ); 46 sqlite_exec_printf ( db, "delete from transfers where fromaccount = %i;", 0, 0, 0, accountid );
48 sqlite_exec_printf ( db, "delete from transfers where toaccount = %i;", 0, 0, 0, accountid ); 47 sqlite_exec_printf ( db, "delete from transfers where toaccount = %i;", 0, 0, 0, accountid );
49 } 48 }
50 49
51int Transfer::getNumberOfTransfers () 50int Transfer::getNumberOfTransfers ()
52 { 51 {
53 char **results; 52 char **results;
54 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); 53 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 );
55 return atoi ( results [ 1 ] ); 54 return atoi ( results [ 1 ] );
56 } 55 }
57 56
58int Transfer::getNumberOfTransfers ( int accountid ) 57int Transfer::getNumberOfTransfers ( int accountid )
59 { 58 {
60 char **results; 59 char **results;
61 sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid ); 60 sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid );
62 int transfers = atoi ( results [ 1 ] ); 61 int transfers = atoi ( results [ 1 ] );
63 sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid ); 62 sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid );
64 transfers = transfers + atoi ( results [ 1 ] ); 63 transfers = transfers + atoi ( results [ 1 ] );
65 return transfers; 64 return transfers;
66 } 65 }
67 66
68void Transfer::displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate ) 67void Transfer::displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate )
69 { 68 {
70 int showcleared = preferences->getPreference ( 3 ); 69 int showcleared = preferences->getPreference ( 3 );
71 70
72 // select the from transfers to display 71 // select the from transfers to display
73 char **results; 72 char **results;
74 int rows, columns; 73 int rows, columns;
75 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) 74 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE )
76 { 75 {
77 if ( showcleared == 0 ) 76 if ( showcleared == 0 )
78 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toparent = %i;", &results, &rows, &columns, 0, accountid ); 77 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toparent = %i;", &results, &rows, &columns, 0, accountid );
79 else 78 else
80 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toparent = %i;", &results, &rows, &columns, 0, accountid ); 79 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toparent = %i;", &results, &rows, &columns, 0, accountid );
81 } 80 }
82 else 81 else
83 { 82 {
84 if ( showcleared == 0 ) 83 if ( showcleared == 0 )
85 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toaccount = %i;", &results, &rows, &columns, 0, accountid ); 84 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toaccount = %i;", &results, &rows, &columns, 0, accountid );
86 else 85 else
87 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toaccount = %i;", &results, &rows, &columns, 0, accountid ); 86 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toaccount = %i;", &results, &rows, &columns, 0, accountid );
88 } 87 }
89 88
90 // iterate through the list and display the from items 89 // iterate through the list and display the from items
91 int counter = 7; 90 int counter = 7;
92 int position = 0; 91 int position = 0;
93 while ( counter < ( ( rows + 1 ) * columns ) ) 92 while ( counter < ( ( rows + 1 ) * columns ) )
94 { 93 {
95 // construct the date 94 // construct the date
96 QString daystring = results [ counter ]; 95 QString daystring = results [ counter ];
97 int day = daystring.toInt (); 96 int day = daystring.toInt ();
98 QString monthstring = results [ counter + 1 ]; 97 QString monthstring = results [ counter + 1 ];
99 int month = monthstring.toInt (); 98 int month = monthstring.toInt ();
100 QString yearstring = results [ counter + 2 ]; 99 QString yearstring = results [ counter + 2 ];
101 int year = yearstring.toInt (); 100 int year = yearstring.toInt ();
102 QString date = preferences->getDate ( year, month, day ); 101 QString date = preferences->getDate ( year, month, day );
103 QDate testdate ( year, month, day ); 102 QDate testdate ( year, month, day );
104 103
105 //construct the amount and id strings 104 //construct the amount and id strings
106 QString amount = results [ counter + 3 ]; 105 QString amount = results [ counter + 3 ];
107 QString id = results [ counter + 4 ]; 106 QString id = results [ counter + 4 ];
108 107
109 // construct the transaction name 108 // construct the transaction name
110 QString transactionname = "FROM: "; 109 QString transactionname = "FROM: ";
111 QString temp1 = results [ counter + 5 ]; 110 QString temp1 = results [ counter + 5 ];
112 transactionname.append ( account->getAccountName ( temp1.toInt() ) ); 111 transactionname.append ( account->getAccountName ( temp1.toInt() ) );
113 112
114 QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) ); 113 QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) );
115 114
116 if ( testdate >= displaydate || showcleared == 0 ) 115 if ( testdate >= displaydate || showcleared == 0 )
117 { 116 {
118 // display this transfer 117 // display this transfer
119 if ( account->getParentAccountID ( accountid ) == -1 ) 118 if ( account->getParentAccountID ( accountid ) == -1 )
120 { 119 {
121 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) 120 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
122 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount ); 121 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount );
123 else 122 else
124 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount ); 123 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount );
125 } 124 }
126 else 125 else
127 { 126 {
128 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) 127 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
129 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id ); 128 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
130 else 129 else
131 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); 130 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
132 } 131 }
133 } 132 }
134 counter = counter + 7; 133 counter = counter + 7;
135 } 134 }
136 135
137 // select the to transfers to display 136 // select the to transfers to display
138 char **toresults; 137 char **toresults;
139 rows = 0; 138 rows = 0;
140 columns = 0; 139 columns = 0;
141 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) 140 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE )
142 { 141 {
143 if ( showcleared == 0 ) 142 if ( showcleared == 0 )
144 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromparent = %i;", &toresults, &rows, &columns, 0, accountid ); 143 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromparent = %i;", &toresults, &rows, &columns, 0, accountid );
145 else 144 else
146 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromparent = %i;", &toresults, &rows, &columns, 0, accountid ); 145 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromparent = %i;", &toresults, &rows, &columns, 0, accountid );
147 } 146 }
148 else 147 else
149 { 148 {
150 if ( showcleared == 0 ) 149 if ( showcleared == 0 )
151 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromaccount = %i;", &toresults, &rows, &columns, 0, accountid ); 150 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromaccount = %i;", &toresults, &rows, &columns, 0, accountid );
152 else 151 else
153 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromaccount = %i;", &toresults, &rows, &columns, 0, accountid ); 152 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromaccount = %i;", &toresults, &rows, &columns, 0, accountid );
154 } 153 }
155 154
156 // iterate through the list and display the from items 155 // iterate through the list and display the from items
157 counter = 7; 156 counter = 7;
158 position = 0; 157 position = 0;
159 while ( counter < ( ( rows + 1 ) * columns ) ) 158 while ( counter < ( ( rows + 1 ) * columns ) )
160 { 159 {
161 // construct the date 160 // construct the date
162 QString daystring = toresults [ counter ]; 161 QString daystring = toresults [ counter ];
163 int day = daystring.toInt (); 162 int day = daystring.toInt ();
164 QString monthstring = toresults [ counter + 1 ]; 163 QString monthstring = toresults [ counter + 1 ];
165 int month = monthstring.toInt (); 164 int month = monthstring.toInt ();
166 QString yearstring = toresults [ counter + 2 ]; 165 QString yearstring = toresults [ counter + 2 ];
167 int year = yearstring.toInt (); 166 int year = yearstring.toInt ();
168 QString date = preferences->getDate ( year, month, day ); 167 QString date = preferences->getDate ( year, month, day );
169 QDate testdate ( year, month, day ); 168 QDate testdate ( year, month, day );
170 169
171 //construct the amount and id strings 170 //construct the amount and id strings
172 QString amount = toresults [ counter + 3 ]; 171 QString amount = toresults [ counter + 3 ];
173 amount.prepend ( "-" ); 172 amount.prepend ( "-" );
174 QString id = toresults [ counter + 4 ]; 173 QString id = toresults [ counter + 4 ];
175 174
176 // construct the transaction name 175 // construct the transaction name
177 QString transactionname = "TO: "; 176 QString transactionname = "TO: ";
178 QString temp1 = toresults [ counter + 6 ]; 177 QString temp1 = toresults [ counter + 6 ];
179 transactionname.append ( account->getAccountName ( temp1.toInt() ) ); 178 transactionname.append ( account->getAccountName ( temp1.toInt() ) );
180 179
181 QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) ); 180 QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) );
182 181
183 if ( testdate >= displaydate || showcleared == 0 ) 182 if ( testdate >= displaydate || showcleared == 0 )
184 { 183 {
185 // display this transfer 184 // display this transfer
186 if ( account->getParentAccountID ( accountid ) == -1 ) 185 if ( account->getParentAccountID ( accountid ) == -1 )
187 { 186 {
188 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) 187 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
189 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount ); 188 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount );
190 else 189 else
191 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount ); 190 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount );
192 } 191 }
193 else 192 else
194 { 193 {
195 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) 194 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
196 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id ); 195 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
197 else 196 else
198 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); 197 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
199 } 198 }
200 } 199 }
201 200
202 counter = counter + 7; 201 counter = counter + 7;
203 } 202 }
204 } 203 }
205 204
206int Transfer::getCleared ( int id ) 205int Transfer::getCleared ( int id )
207 { 206 {
208 char **results; 207 char **results;
209 sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id ); 208 sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id );
210 return atoi ( results [ 1 ] ); 209 return atoi ( results [ 1 ] );
211 } 210 }
212 211
213void Transfer::setCleared ( int id, int cleared ) 212void Transfer::setCleared ( int id, int cleared )
214 { 213 {
215 sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id ); 214 sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id );
216 } 215 }
217 216
218int Transfer::getFromAccountID ( int id ) 217int Transfer::getFromAccountID ( int id )
219 { 218 {
220 char **results; 219 char **results;
221 sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); 220 sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id );
222 return atoi ( results [ 1 ] ); 221 return atoi ( results [ 1 ] );
223 } 222 }
224 223
225int Transfer::getToAccountID ( int id ) 224int Transfer::getToAccountID ( int id )
226 { 225 {
227 char **results; 226 char **results;
228 sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); 227 sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id );
229 return atoi ( results [ 1 ] ); 228 return atoi ( results [ 1 ] );
230 } 229 }
231 230
232int Transfer::getDay ( int id ) 231int Transfer::getDay ( int id )
233 { 232 {
234 char **results; 233 char **results;
235 sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id ); 234 sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id );
236 return atoi ( results [ 1 ] ); 235 return atoi ( results [ 1 ] );
237 } 236 }
238 237
239int Transfer::getMonth ( int id ) 238int Transfer::getMonth ( int id )
240 { 239 {
241 char **results; 240 char **results;
242 sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id ); 241 sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id );
243 return atoi ( results [ 1 ] ); 242 return atoi ( results [ 1 ] );
244 } 243 }
245 244
246int Transfer::getYear ( int id ) 245int Transfer::getYear ( int id )
247 { 246 {
248 char **results; 247 char **results;
249 sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id ); 248 sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id );
250 return atoi ( results [ 1 ] ); 249 return atoi ( results [ 1 ] );
251 } 250 }
252 251
253QString Transfer::getAmount ( int id ) 252QString Transfer::getAmount ( int id )
254 { 253 {
255 char **results; 254 char **results;
256 sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id ); 255 sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id );
257 return results [ 1 ]; 256 return results [ 1 ];
258 } 257 }
259 258
260 259