-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.cpp | 15 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.h | 8 |
3 files changed, 25 insertions, 4 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 77c1f57..ab25516 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -298,33 +298,33 @@ void Checkbook::loadCheckbook() | |||
298 | for ( int i = 1; trandesc != QString::null; i++ ) | 298 | for ( int i = 1; trandesc != QString::null; i++ ) |
299 | { | 299 | { |
300 | tran = new TranInfo( config, i ); | 300 | tran = new TranInfo( config, i ); |
301 | trandesc = tran->desc(); | 301 | trandesc = tran->desc(); |
302 | if ( trandesc != QString::null ) | 302 | if ( trandesc != QString::null ) |
303 | { | 303 | { |
304 | currBalance -= tran->fee(); | 304 | currBalance -= tran->fee(); |
305 | amount = tran->amount(); | 305 | amount = tran->amount(); |
306 | if ( tran->withdrawal() ) | 306 | if ( tran->withdrawal() ) |
307 | { | 307 | { |
308 | amount *= -1; | 308 | amount *= -1; |
309 | } | 309 | } |
310 | currBalance += amount; | 310 | currBalance += amount; |
311 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 311 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); |
312 | 312 | ||
313 | // Add to transaction list | 313 | // Add to transaction list |
314 | transactions.append( tran ); | 314 | transactions.inSort( tran ); |
315 | 315 | ||
316 | // Add to transaction table | 316 | // Add to transaction table |
317 | ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(), | 317 | ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(), |
318 | trandesc, stramount ); | 318 | trandesc, stramount ); |
319 | } | 319 | } |
320 | else | 320 | else |
321 | { | 321 | { |
322 | delete tran; | 322 | delete tran; |
323 | } | 323 | } |
324 | } | 324 | } |
325 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); | 325 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); |
326 | 326 | ||
327 | highTranNum = transactions.count(); | 327 | highTranNum = transactions.count(); |
328 | } | 328 | } |
329 | 329 | ||
330 | void Checkbook::adjustBalance( float amount ) | 330 | void Checkbook::adjustBalance( float amount ) |
@@ -402,33 +402,33 @@ void Checkbook::slotNewTran() | |||
402 | 402 | ||
403 | Transaction *currtran = new Transaction( this, name, | 403 | Transaction *currtran = new Transaction( this, name, |
404 | traninfo, | 404 | traninfo, |
405 | currencySymbol ); | 405 | currencySymbol ); |
406 | currtran->showMaximized(); | 406 | currtran->showMaximized(); |
407 | if ( currtran->exec() == QDialog::Accepted ) | 407 | if ( currtran->exec() == QDialog::Accepted ) |
408 | { | 408 | { |
409 | float amount = traninfo->amount(); | 409 | float amount = traninfo->amount(); |
410 | if ( traninfo->withdrawal() ) | 410 | if ( traninfo->withdrawal() ) |
411 | { | 411 | { |
412 | amount *= -1; | 412 | amount *= -1; |
413 | } | 413 | } |
414 | QString stramount; | 414 | QString stramount; |
415 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 415 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); |
416 | 416 | ||
417 | // Add to transaction list | 417 | // Add to transaction list |
418 | transactions.append( traninfo ); | 418 | transactions.inSort( traninfo ); |
419 | 419 | ||
420 | // Add to transaction table | 420 | // Add to transaction table |
421 | ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), | 421 | ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), |
422 | traninfo->datestr(), traninfo->desc(), stramount ); | 422 | traninfo->datestr(), traninfo->desc(), stramount ); |
423 | 423 | ||
424 | adjustBalance( amount ); | 424 | adjustBalance( amount ); |
425 | } | 425 | } |
426 | else | 426 | else |
427 | { | 427 | { |
428 | highTranNum--; | 428 | highTranNum--; |
429 | delete traninfo; | 429 | delete traninfo; |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | void Checkbook::slotEditTran() | 433 | void Checkbook::slotEditTran() |
434 | { | 434 | { |
@@ -549,33 +549,33 @@ void Checkbook::drawBalanceChart() | |||
549 | } | 549 | } |
550 | else | 550 | else |
551 | { | 551 | { |
552 | label = ""; | 552 | label = ""; |
553 | } | 553 | } |
554 | list->append( new DataPointInfo( label, balance ) ); | 554 | list->append( new DataPointInfo( label, balance ) ); |
555 | } | 555 | } |
556 | 556 | ||
557 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); | 557 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); |
558 | } | 558 | } |
559 | 559 | ||
560 | void Checkbook::drawCategoryChart( bool withdrawals ) | 560 | void Checkbook::drawCategoryChart( bool withdrawals ) |
561 | { | 561 | { |
562 | DataPointList *list = new DataPointList(); | 562 | DataPointList *list = new DataPointList(); |
563 | 563 | ||
564 | TranInfo *tran = transactions.first(); | 564 | TranInfo *tran = transactions.first(); |
565 | if ( tran->withdrawal() == withdrawals ) | 565 | if ( tran && tran->withdrawal() == withdrawals ) |
566 | { | 566 | { |
567 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); | 567 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); |
568 | } | 568 | } |
569 | tran = transactions.next(); | 569 | tran = transactions.next(); |
570 | 570 | ||
571 | DataPointInfo *cat; | 571 | DataPointInfo *cat; |
572 | for ( ; tran; tran = transactions.next() ) | 572 | for ( ; tran; tran = transactions.next() ) |
573 | { | 573 | { |
574 | if ( tran->withdrawal() == withdrawals ) | 574 | if ( tran->withdrawal() == withdrawals ) |
575 | { | 575 | { |
576 | // Find category in list | 576 | // Find category in list |
577 | for ( cat = list->first(); cat; cat = list->next() ) | 577 | for ( cat = list->first(); cat; cat = list->next() ) |
578 | { | 578 | { |
579 | if ( cat->label() == tran->category() ) | 579 | if ( cat->label() == tran->category() ) |
580 | { | 580 | { |
581 | break; | 581 | break; |
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp index 460466c..dcba869 100644 --- a/noncore/apps/checkbook/traninfo.cpp +++ b/noncore/apps/checkbook/traninfo.cpp | |||
@@ -160,16 +160,31 @@ void TranInfo::write( Config *config, int entry ) | |||
160 | else if ( t == "Credit Card" || t == "Cash" ) | 160 | else if ( t == "Credit Card" || t == "Cash" ) |
161 | tempstr = "3"; | 161 | tempstr = "3"; |
162 | config->writeEntry( "Type", tempstr ); | 162 | config->writeEntry( "Type", tempstr ); |
163 | 163 | ||
164 | config->writeEntry( "Category", c ); | 164 | config->writeEntry( "Category", c ); |
165 | 165 | ||
166 | tempstr.setNum( a, 'f', 2 ); | 166 | tempstr.setNum( a, 'f', 2 ); |
167 | config->writeEntry( "Amount", tempstr ); | 167 | config->writeEntry( "Amount", tempstr ); |
168 | 168 | ||
169 | tempstr.setNum( f, 'f', 2 ); | 169 | tempstr.setNum( f, 'f', 2 ); |
170 | config->writeEntry( "TransactionFee", tempstr ); | 170 | config->writeEntry( "TransactionFee", tempstr ); |
171 | 171 | ||
172 | config->writeEntry( "CheckNumber", cn ); | 172 | config->writeEntry( "CheckNumber", cn ); |
173 | 173 | ||
174 | config->writeEntry( "Comments", n ); | 174 | config->writeEntry( "Comments", n ); |
175 | } | 175 | } |
176 | |||
177 | int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) | ||
178 | { | ||
179 | QDate d1 = ((TranInfo *)item1)->date(); | ||
180 | QDate d2 = ((TranInfo *)item2)->date(); | ||
181 | int r = -1; | ||
182 | |||
183 | if ( d1 < d2 ) | ||
184 | r = -1; | ||
185 | else if ( d1 == d2 ) | ||
186 | r = 0; | ||
187 | else if ( d1 > d2 ) | ||
188 | r = 1; | ||
189 | return( r ); | ||
190 | } \ No newline at end of file | ||
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h index e944c29..e488816 100644 --- a/noncore/apps/checkbook/traninfo.h +++ b/noncore/apps/checkbook/traninfo.h | |||
@@ -68,19 +68,25 @@ class TranInfo | |||
68 | 68 | ||
69 | void write( Config *, int ); | 69 | void write( Config *, int ); |
70 | 70 | ||
71 | private: | 71 | private: |
72 | int i; | 72 | int i; |
73 | QString d; | 73 | QString d; |
74 | QDate td; | 74 | QDate td; |
75 | bool w; | 75 | bool w; |
76 | QString t; | 76 | QString t; |
77 | QString c; | 77 | QString c; |
78 | float a; | 78 | float a; |
79 | float f; | 79 | float f; |
80 | QString cn; | 80 | QString cn; |
81 | QString n; | 81 | QString n; |
82 | }; | 82 | }; |
83 | 83 | ||
84 | typedef QList<TranInfo> TranInfoList; | 84 | class TranInfoList : public QList<TranInfo> |
85 | { | ||
86 | protected: | ||
87 | int compareItems( QCollection::Item, QCollection::Item ); | ||
88 | }; | ||
89 | |||
90 | //typedef TranList<TranInfo> TranInfoList; | ||
85 | 91 | ||
86 | #endif | 92 | #endif |