author | mickeyl <mickeyl> | 2004-11-04 10:33:04 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-04 10:33:04 (UTC) |
commit | 7855b19ce0241a7b7b4fc72e3a8ddd9bf73b0a77 (patch) (unidiff) | |
tree | e76604c6af3da9c19b69dcdcf8105d58bac63f71 /noncore/unsupported/qashmoney/account.cpp | |
parent | cd2d50799e087fad5b56df9d7fe9aa572a313e64 (diff) | |
download | opie-7855b19ce0241a7b7b4fc72e3a8ddd9bf73b0a77.zip opie-7855b19ce0241a7b7b4fc72e3a8ddd9bf73b0a77.tar.gz opie-7855b19ce0241a7b7b4fc72e3a8ddd9bf73b0a77.tar.bz2 |
opie-qashmoney is now unsupported
Diffstat (limited to 'noncore/unsupported/qashmoney/account.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/unsupported/qashmoney/account.cpp | 374 |
1 files changed, 374 insertions, 0 deletions
diff --git a/noncore/unsupported/qashmoney/account.cpp b/noncore/unsupported/qashmoney/account.cpp new file mode 100755 index 0000000..f21598e --- a/dev/null +++ b/noncore/unsupported/qashmoney/account.cpp | |||
@@ -0,0 +1,374 @@ | |||
1 | #include "account.h" | ||
2 | #include "preferences.h" | ||
3 | |||
4 | #include <qpixmap.h> | ||
5 | #include <stdlib.h> | ||
6 | |||
7 | extern Preferences *preferences; | ||
8 | |||
9 | Account::Account () | ||
10 | { | ||
11 | adb = sqlite_open ( "qmaccounts.db", 0, NULL ); | ||
12 | } | ||
13 | |||
14 | Account::~Account () | ||
15 | { | ||
16 | sqlite_close ( adb ); | ||
17 | } | ||
18 | |||
19 | void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit, | ||
20 | int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency ) | ||
21 | { | ||
22 | 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, | ||
23 | (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency ); | ||
24 | } | ||
25 | |||
26 | void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid ) | ||
27 | { | ||
28 | 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 ); | ||
29 | } | ||
30 | |||
31 | void Account::deleteAccount ( int accountid ) | ||
32 | { | ||
33 | sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid ); | ||
34 | } | ||
35 | |||
36 | void Account::setAccountExpanded ( int expanded, int accountid ) | ||
37 | { | ||
38 | sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid ); | ||
39 | } | ||
40 | |||
41 | int Account::getAccountExpanded ( int id ) | ||
42 | { | ||
43 | char **results; | ||
44 | sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id ); | ||
45 | if ( strlen ( results [1] ) == 0 ) | ||
46 | return 0; | ||
47 | else | ||
48 | return atoi ( results [ 1 ] ); | ||
49 | } | ||
50 | |||
51 | int Account::getNumberOfAccounts () | ||
52 | { | ||
53 | char **results; | ||
54 | sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL ); | ||
55 | return atoi ( results [ 1 ] ); | ||
56 | } | ||
57 | |||
58 | int Account::getNumberOfChildAccounts ( int id ) | ||
59 | { | ||
60 | char **results; | ||
61 | sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id ); | ||
62 | return atoi ( results [ 1 ] ); | ||
63 | } | ||
64 | |||
65 | void Account::updateAccountBalance ( int accountid ) | ||
66 | { | ||
67 | // Here, we'll get a balance for the transactions in an account | ||
68 | sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); | ||
69 | int rows, columns; | ||
70 | char **results; | ||
71 | sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid ); | ||
72 | float transactionsbalance = strtod ( results [ 1 ], 0 ); | ||
73 | sqlite_close ( tdb ); | ||
74 | |||
75 | // next, we'll get a balance for all the transfers from the account | ||
76 | sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); | ||
77 | rows = 0; | ||
78 | columns = 0; | ||
79 | char **results2; | ||
80 | sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); | ||
81 | float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); | ||
82 | |||
83 | // finally, we'll get a balance for all the transfers into the account | ||
84 | rows = 0; | ||
85 | columns= 0; | ||
86 | char **results3; | ||
87 | sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); | ||
88 | float totransfersbalance = strtod ( results3 [ 1 ], 0 ); | ||
89 | |||
90 | sqlite_close ( trdb ); | ||
91 | |||
92 | // calculate and update new balance | ||
93 | sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, | ||
94 | ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); | ||
95 | } | ||
96 | |||
97 | void Account::changeParentAccountBalance ( int parentid ) | ||
98 | { | ||
99 | // select all child balances that share the parent of the current child account | ||
100 | char **results; | ||
101 | int rows; | ||
102 | sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); | ||
103 | sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); | ||
104 | } | ||
105 | |||
106 | int Account::getParentAccountID ( int id ) | ||
107 | { | ||
108 | char **results; | ||
109 | sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); | ||
110 | return atoi ( results [ 1 ] ); | ||
111 | } | ||
112 | |||
113 | int Account::getParentAccountID ( QString accountname ) | ||
114 | { | ||
115 | char **results; | ||
116 | sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); | ||
117 | return atoi ( results [ 1 ] ); | ||
118 | } | ||
119 | |||
120 | void Account::displayAccounts ( QListView *listview ) | ||
121 | { | ||
122 | char **results; | ||
123 | int rows, columns; | ||
124 | sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); | ||
125 | |||
126 | // determine if we are using currency support | ||
127 | int currency = preferences->getPreference ( 4 ); | ||
128 | |||
129 | // remove all columns from the account display | ||
130 | int counter; | ||
131 | for ( counter = 0; counter <= columns; counter++ ) | ||
132 | listview->removeColumn ( 0 ); | ||
133 | |||
134 | // add columns to the account display | ||
135 | listview->addColumn ( "Account", 0 ); | ||
136 | int columntoalign = 1; | ||
137 | if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it | ||
138 | { | ||
139 | listview->addColumn ( "C", 0 ); | ||
140 | columntoalign = 2; | ||
141 | } | ||
142 | listview->addColumn ( "Balance", 0 ); | ||
143 | listview->addColumn ( "", 0 ); | ||
144 | listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); | ||
145 | counter = 5; | ||
146 | int total = ( rows + 1 ) * columns; | ||
147 | while ( counter < total ) | ||
148 | { | ||
149 | int accountid = atoi ( results [ counter + 3 ] ); | ||
150 | if ( atoi ( results [ counter + 1 ] ) == -1 ) | ||
151 | { | ||
152 | QListViewItem *parent = new QListViewItem ( listview ); | ||
153 | parent->setText ( 0, results [ counter ] ); | ||
154 | if ( currency == 0 ) | ||
155 | { | ||
156 | parent->setText ( 1, results [ counter + 2 ] ); | ||
157 | parent->setText ( 2, results [ counter + 3 ] ); | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children | ||
162 | { | ||
163 | // create the string we'll use to set the currency pixmap | ||
164 | QString filename = "/opt/QtPalmtop/pics/flags/"; | ||
165 | QString flag = results [ counter + 4 ]; | ||
166 | filename.append ( flag ); | ||
167 | filename.append ( ".png" ); | ||
168 | parent->setPixmap ( 1, QPixmap ( filename ) ); | ||
169 | parent->setText ( 1, flag ); | ||
170 | } | ||
171 | parent->setText ( 2, results [ counter + 2 ] ); | ||
172 | parent->setText ( 3, results [ counter + 3 ] ); | ||
173 | } | ||
174 | |||
175 | if ( getAccountExpanded ( accountid ) == 1 ) | ||
176 | parent->setOpen ( TRUE ); | ||
177 | |||
178 | //Start display child accounts for this parent | ||
179 | int childcounter = 5; | ||
180 | while ( childcounter < total ) | ||
181 | { | ||
182 | if ( atoi ( results [ childcounter + 1 ] ) == accountid ) | ||
183 | { | ||
184 | if ( currency == 0 ) | ||
185 | QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] ); | ||
186 | else | ||
187 | { | ||
188 | // create the string we'll use to set the currency pixmap | ||
189 | QString filename = "/opt/QtPalmtop/pics/flags/"; | ||
190 | QString flag = results [ childcounter + 4 ]; | ||
191 | filename.append ( flag ); | ||
192 | filename.append ( ".png" ); | ||
193 | QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] ); | ||
194 | child->setPixmap ( 1, QPixmap ( filename ) ); | ||
195 | child->setText ( 1, flag ); | ||
196 | } | ||
197 | } | ||
198 | childcounter = childcounter + 5; | ||
199 | } | ||
200 | //End display child accounts | ||
201 | } | ||
202 | counter = counter + 5; | ||
203 | } | ||
204 | |||
205 | // resize all columns appropriately | ||
206 | if ( preferences->getPreference ( 4 ) == 0 ) | ||
207 | { | ||
208 | listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); | ||
209 | listview->setColumnWidthMode ( 0, QListView::Manual ); | ||
210 | listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); | ||
211 | listview->setColumnWidthMode ( 1, QListView::Manual ); | ||
212 | listview->setColumnWidthMode ( 2, QListView::Manual ); | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) ); | ||
217 | listview->setColumnWidthMode ( 0, QListView::Manual ); | ||
218 | listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) ); | ||
219 | listview->setColumnWidthMode ( 1, QListView::Manual ); | ||
220 | listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) ); | ||
221 | listview->setColumnWidthMode ( 2, QListView::Manual ); | ||
222 | listview->setColumnWidthMode ( 3, QListView::Manual ); | ||
223 | } | ||
224 | |||
225 | // Now reset the column sorting to user preference | ||
226 | int column = 0; | ||
227 | int direction = 0; | ||
228 | preferences->getSortingPreference ( 1, &column, &direction ); | ||
229 | listview->setSorting ( column, direction ); | ||
230 | } | ||
231 | |||
232 | int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring ) | ||
233 | { | ||
234 | char **results; | ||
235 | int rows, columns, index; | ||
236 | index = 0; | ||
237 | sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL ); | ||
238 | int counter = 1; | ||
239 | int indexcounter = 1; | ||
240 | int total = ( rows + 1 ) * columns; | ||
241 | while ( counter < total ) | ||
242 | { | ||
243 | if ( getParentAccountID ( results [ counter ] ) == -1 ) | ||
244 | { | ||
245 | combobox->insertItem ( results [ counter ], -1 ); | ||
246 | if ( strcmp ( results [ counter ], indexstring ) == 0 ) | ||
247 | index = indexcounter; | ||
248 | indexcounter++; | ||
249 | } | ||
250 | counter ++; | ||
251 | } | ||
252 | return index; | ||
253 | } | ||
254 | |||
255 | int Account::getAccountType ( int accountid ) | ||
256 | { | ||
257 | char **results; | ||
258 | sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
259 | return atoi ( results [ 1 ] ); | ||
260 | } | ||
261 | |||
262 | int Account::getStatementDay ( int accountid ) | ||
263 | { | ||
264 | char **results; | ||
265 | sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
266 | return atoi ( results [ 1 ] ); | ||
267 | } | ||
268 | |||
269 | int Account::getStatementMonth ( int accountid ) | ||
270 | { | ||
271 | char **results; | ||
272 | sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
273 | return atoi ( results [ 1 ] ); | ||
274 | } | ||
275 | |||
276 | int Account::getStatementYear ( int accountid ) | ||
277 | { | ||
278 | char **results; | ||
279 | sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
280 | return atoi ( results [ 1 ] ); | ||
281 | } | ||
282 | |||
283 | QString Account::getAccountDescription ( int accountid ) | ||
284 | { | ||
285 | char **results; | ||
286 | sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
287 | return ( QString ) results [ 1 ]; | ||
288 | } | ||
289 | |||
290 | QString Account::getCurrencyCode ( int accountid ) | ||
291 | { | ||
292 | char **results; | ||
293 | sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
294 | return ( QString ) results [ 1 ]; | ||
295 | } | ||
296 | |||
297 | QString Account::getAccountName ( int accountid ) | ||
298 | { | ||
299 | char **results; | ||
300 | sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
301 | return ( QString ) results [ 1 ]; | ||
302 | } | ||
303 | |||
304 | QString Account::getAccountBalance ( int accountid ) | ||
305 | { | ||
306 | char **results; | ||
307 | sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); | ||
308 | return ( QString ) results [ 1 ]; | ||
309 | } | ||
310 | |||
311 | float Account::getAccountCreditLimit ( int accountid ) | ||
312 | { | ||
313 | char **results; | ||
314 | sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); | ||
315 | return strtod ( results [ 1 ], NULL ); | ||
316 | } | ||
317 | |||
318 | float Account::getStatementBalance ( int accountid ) | ||
319 | { | ||
320 | char **results; | ||
321 | sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); | ||
322 | return strtod ( results [ 1 ], NULL ); | ||
323 | } | ||
324 | |||
325 | GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) | ||
326 | : QListViewItem ( parent ) | ||
327 | { | ||
328 | } | ||
329 | |||
330 | GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) | ||
331 | : QListViewItem ( parent, label1, label2, label3 ) | ||
332 | { | ||
333 | } | ||
334 | |||
335 | GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) | ||
336 | : QListViewItem ( parent, label1, label2, label3, label4 ) | ||
337 | { | ||
338 | } | ||
339 | |||
340 | GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) | ||
341 | : QListViewItem ( parent, label1, label2, label3, label4, label5 ) | ||
342 | { | ||
343 | } | ||
344 | |||
345 | void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) | ||
346 | { | ||
347 | QColorGroup _cg ( cg ); | ||
348 | _cg.setColor ( QColorGroup::Base, Qt::lightGray ); | ||
349 | QListViewItem::paintCell ( p, _cg, column, width, alignment ); | ||
350 | } | ||
351 | |||
352 | QStringList Account::getAccountNames () | ||
353 | { | ||
354 | QStringList accountnames; | ||
355 | char **results; | ||
356 | int rows, counter; | ||
357 | sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); | ||
358 | for ( counter = 0; counter < rows; counter++ ) | ||
359 | accountnames.append ( results [ counter+1 ] ); | ||
360 | return accountnames; | ||
361 | } | ||
362 | |||
363 | QStringList Account::getAccountIDs () | ||
364 | { | ||
365 | QStringList accountids; | ||
366 | char **results; | ||
367 | int rows, counter; | ||
368 | sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); | ||
369 | for ( counter = 0; counter < rows; counter++ ) | ||
370 | accountids.append ( results [ counter+1 ] ); | ||
371 | return accountids; | ||
372 | } | ||
373 | |||
374 | |||