summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp6
-rw-r--r--noncore/apps/checkbook/traninfo.cpp15
-rw-r--r--noncore/apps/checkbook/traninfo.h8
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
@@ -266,97 +266,97 @@ void Checkbook::loadCheckbook()
266 266
267 Config config(filename, Config::File); 267 Config config(filename, Config::File);
268 268
269 // Load info 269 // Load info
270 config.setGroup( "Account" ); 270 config.setGroup( "Account" );
271 nameEdit->setText( name ); 271 nameEdit->setText( name );
272 QString temptext = config.readEntry( "Type" ); 272 QString temptext = config.readEntry( "Type" );
273 int i = typeList->count(); 273 int i = typeList->count();
274 while ( i > 0 ) 274 while ( i > 0 )
275 { 275 {
276 i--; 276 i--;
277 typeList->setCurrentItem( i ); 277 typeList->setCurrentItem( i );
278 if ( typeList->currentText() == temptext ) 278 if ( typeList->currentText() == temptext )
279 { 279 {
280 break; 280 break;
281 } 281 }
282 } 282 }
283 bankEdit->setText( config.readEntry( "Bank", "" ) ); 283 bankEdit->setText( config.readEntry( "Bank", "" ) );
284 acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) ); 284 acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) );
285 pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) ); 285 pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) );
286 balanceEdit->setText( config.readEntry( "Balance", "0.0" ) ); 286 balanceEdit->setText( config.readEntry( "Balance", "0.0" ) );
287 notesEdit->setText( config.readEntry( "Notes", "" ) ); 287 notesEdit->setText( config.readEntry( "Notes", "" ) );
288 288
289 bool ok; 289 bool ok;
290 currBalance = balanceEdit->text().toFloat( &ok ); 290 currBalance = balanceEdit->text().toFloat( &ok );
291 startBalance = currBalance; 291 startBalance = currBalance;
292 292
293 // Load transactions 293 // Load transactions
294 TranInfo *tran; 294 TranInfo *tran;
295 QString trandesc = ""; 295 QString trandesc = "";
296 float amount; 296 float amount;
297 QString stramount; 297 QString stramount;
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
330void Checkbook::adjustBalance( float amount ) 330void Checkbook::adjustBalance( float amount )
331{ 331{
332 currBalance += amount; 332 currBalance += amount;
333 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); 333 balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
334 334
335} 335}
336 336
337TranInfo *Checkbook::findTranByID( int id ) 337TranInfo *Checkbook::findTranByID( int id )
338{ 338{
339 TranInfo *traninfo = transactions.first(); 339 TranInfo *traninfo = transactions.first();
340 while ( traninfo && traninfo->id() != id ) 340 while ( traninfo && traninfo->id() != id )
341 { 341 {
342 traninfo = transactions.next(); 342 traninfo = transactions.next();
343 } 343 }
344 return( traninfo ); 344 return( traninfo );
345} 345}
346 346
347void Checkbook::accept() 347void Checkbook::accept()
348{ 348{
349 QFile f( filename ); 349 QFile f( filename );
350 if ( f.exists() ) 350 if ( f.exists() )
351 { 351 {
352 f.remove(); 352 f.remove();
353 } 353 }
354 354
355 Config *config = new Config(filename, Config::File); 355 Config *config = new Config(filename, Config::File);
356 356
357 // Save info 357 // Save info
358 config->setGroup( "Account" ); 358 config->setGroup( "Account" );
359 config->writeEntry( "Type", typeList->currentText() ); 359 config->writeEntry( "Type", typeList->currentText() );
360 config->writeEntry( "Bank", bankEdit->text() ); 360 config->writeEntry( "Bank", bankEdit->text() );
361 config->writeEntryCrypt( "Number", acctNumEdit->text() ); 361 config->writeEntryCrypt( "Number", acctNumEdit->text() );
362 config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); 362 config->writeEntryCrypt( "PINNumber", pinNumEdit->text() );
@@ -370,97 +370,97 @@ void Checkbook::accept()
370 tran->write( config, i ); 370 tran->write( config, i );
371 i++; 371 i++;
372 } 372 }
373 config->write(); 373 config->write();
374 374
375 QDialog::accept(); 375 QDialog::accept();
376} 376}
377 377
378void Checkbook::slotNameChanged( const QString &newname ) 378void Checkbook::slotNameChanged( const QString &newname )
379{ 379{
380 name = newname; 380 name = newname;
381 filename = filedir; 381 filename = filedir;
382 filename.append( newname ); 382 filename.append( newname );
383 filename.append( ".qcb" ); 383 filename.append( ".qcb" );
384 QString tempstr = name; 384 QString tempstr = name;
385 tempstr.append( " - " ); 385 tempstr.append( " - " );
386 tempstr.append( tr( "Checkbook" ) ); 386 tempstr.append( tr( "Checkbook" ) );
387 setCaption( tempstr ); 387 setCaption( tempstr );
388} 388}
389 389
390void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) 390void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
391{ 391{
392 currBalance -= startBalance; 392 currBalance -= startBalance;
393 bool ok; 393 bool ok;
394 startBalance = newbalance.toFloat( &ok ); 394 startBalance = newbalance.toFloat( &ok );
395 adjustBalance( startBalance ); 395 adjustBalance( startBalance );
396} 396}
397 397
398void Checkbook::slotNewTran() 398void Checkbook::slotNewTran()
399{ 399{
400 highTranNum++; 400 highTranNum++;
401 TranInfo *traninfo = new TranInfo( highTranNum ); 401 TranInfo *traninfo = new TranInfo( highTranNum );
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
433void Checkbook::slotEditTran() 433void Checkbook::slotEditTran()
434{ 434{
435 bool ok; 435 bool ok;
436 QListViewItem *curritem = tranTable->currentItem(); 436 QListViewItem *curritem = tranTable->currentItem();
437 if ( !curritem ) 437 if ( !curritem )
438 { 438 {
439 return; 439 return;
440 } 440 }
441 441
442 int tranid = curritem->text( 0 ).toInt( &ok ); 442 int tranid = curritem->text( 0 ).toInt( &ok );
443 TranInfo *traninfo = findTranByID( tranid ); 443 TranInfo *traninfo = findTranByID( tranid );
444 float origamt = traninfo->amount(); 444 float origamt = traninfo->amount();
445 if ( traninfo->withdrawal() ) 445 if ( traninfo->withdrawal() )
446 { 446 {
447 origamt *= -1; 447 origamt *= -1;
448 } 448 }
449 449
450 Transaction *currtran = new Transaction( this, name, 450 Transaction *currtran = new Transaction( this, name,
451 traninfo, 451 traninfo,
452 currencySymbol ); 452 currencySymbol );
453 currtran->showMaximized(); 453 currtran->showMaximized();
454 if ( currtran->exec() == QDialog::Accepted ) 454 if ( currtran->exec() == QDialog::Accepted )
455 { 455 {
456 curritem->setText( 1, traninfo->datestr() ); 456 curritem->setText( 1, traninfo->datestr() );
457 457
458 curritem->setText( 2, traninfo->desc() ); 458 curritem->setText( 2, traninfo->desc() );
459 459
460 float amount = traninfo->amount(); 460 float amount = traninfo->amount();
461 if ( traninfo->withdrawal() ) 461 if ( traninfo->withdrawal() )
462 { 462 {
463 amount *= -1; 463 amount *= -1;
464 } 464 }
465 adjustBalance( origamt * -1 ); 465 adjustBalance( origamt * -1 );
466 adjustBalance( amount ); 466 adjustBalance( amount );
@@ -517,80 +517,80 @@ void Checkbook::slotDrawGraph()
517 break; 517 break;
518 case 2 : drawCategoryChart( FALSE ); 518 case 2 : drawCategoryChart( FALSE );
519 break; 519 break;
520 }; 520 };
521 521
522 graphWidget->setGraphInfo( graphInfo ); 522 graphWidget->setGraphInfo( graphInfo );
523 graphWidget->drawGraph( TRUE ); 523 graphWidget->drawGraph( TRUE );
524} 524}
525 525
526void Checkbook::drawBalanceChart() 526void Checkbook::drawBalanceChart()
527{ 527{
528 DataPointList *list = new DataPointList(); 528 DataPointList *list = new DataPointList();
529 529
530 float balance = startBalance; 530 float balance = startBalance;
531 float amount; 531 float amount;
532 QString label; 532 QString label;
533 int i = 0; 533 int i = 0;
534 int count = transactions.count(); 534 int count = transactions.count();
535 535
536 for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) 536 for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() )
537 { 537 {
538 i++; 538 i++;
539 balance -= tran->fee(); 539 balance -= tran->fee();
540 amount = tran->amount(); 540 amount = tran->amount();
541 if ( tran->withdrawal() ) 541 if ( tran->withdrawal() )
542 { 542 {
543 amount *= -1; 543 amount *= -1;
544 } 544 }
545 balance += amount; 545 balance += amount;
546 if ( i == 1 || i == count / 2 || i == count ) 546 if ( i == 1 || i == count / 2 || i == count )
547 { 547 {
548 label = tran->datestr(); 548 label = tran->datestr();
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
560void Checkbook::drawCategoryChart( bool withdrawals ) 560void 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;
582 } 582 }
583 } 583 }
584 if ( cat && cat->label() == tran->category() ) 584 if ( cat && cat->label() == tran->category() )
585 { // Found category, add to transaction to category total 585 { // Found category, add to transaction to category total
586 cat->addToValue( tran->amount() ); 586 cat->addToValue( tran->amount() );
587 } 587 }
588 else 588 else
589 { // Didn't find category, add category to list 589 { // Didn't find category, add category to list
590 list->append( new DataPointInfo( tran->category(), tran->amount() ) ); 590 list->append( new DataPointInfo( tran->category(), tran->amount() ) );
591 } 591 }
592 } 592 }
593 } 593 }
594 594
595 graphInfo = new GraphInfo( GraphInfo::PieChart, list ); 595 graphInfo = new GraphInfo( GraphInfo::PieChart, list );
596} 596}
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
@@ -128,48 +128,63 @@ const QString &TranInfo::datestr()
128 tempstr.append( QString::number( tempfield ) ); 128 tempstr.append( QString::number( tempfield ) );
129 tempstr.append( '/' ); 129 tempstr.append( '/' );
130 tempfield = td.day(); 130 tempfield = td.day();
131 if ( tempfield < 10 ) tempstr.append( '0' ); 131 if ( tempfield < 10 ) tempstr.append( '0' );
132 tempstr.append( QString::number( tempfield ) ); 132 tempstr.append( QString::number( tempfield ) );
133 133
134 return( tempstr ); 134 return( tempstr );
135} 135}
136 136
137void TranInfo::write( Config *config, int entry ) 137void TranInfo::write( Config *config, int entry )
138{ 138{
139 config->setGroup( QString::number( entry ) ); 139 config->setGroup( QString::number( entry ) );
140 140
141 config->writeEntry( "Description", d ); 141 config->writeEntry( "Description", d );
142 142
143 tempstr = QString::number( td.month() ); 143 tempstr = QString::number( td.month() );
144 tempstr.append( '/' ); 144 tempstr.append( '/' );
145 tempstr.append( QString::number( td.day() ) ); 145 tempstr.append( QString::number( td.day() ) );
146 tempstr.append( '/' ); 146 tempstr.append( '/' );
147 tempstr.append( QString::number( td.year() ) ); 147 tempstr.append( QString::number( td.year() ) );
148 config->writeEntry( "Date", tempstr ); 148 config->writeEntry( "Date", tempstr );
149 149
150 w ? tempstr = "true" 150 w ? tempstr = "true"
151 : tempstr = "false"; 151 : tempstr = "false";
152 config->writeEntry( "Payment", tempstr ); 152 config->writeEntry( "Payment", tempstr );
153 153
154 if ( t == "Debit Charge" || t == "Written Check" ) 154 if ( t == "Debit Charge" || t == "Written Check" )
155 tempstr = "0"; 155 tempstr = "0";
156 else if ( t == "Written Check" || t == "Automatic Payment" ) 156 else if ( t == "Written Check" || t == "Automatic Payment" )
157 tempstr = "1"; 157 tempstr = "1";
158 else if ( t == "Transfer" ) 158 else if ( t == "Transfer" )
159 tempstr = "2"; 159 tempstr = "2";
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
177int 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
@@ -36,51 +36,57 @@
36class Config; 36class Config;
37 37
38class TranInfo 38class TranInfo
39{ 39{
40 public: 40 public:
41 TranInfo( int = 0, const QString & = 0x0, const QDate & = QDate::currentDate(), 41 TranInfo( int = 0, const QString & = 0x0, const QDate & = QDate::currentDate(),
42 bool = TRUE, const QString & = 0x0, const QString & = 0x0, 42 bool = TRUE, const QString & = 0x0, const QString & = 0x0,
43 float = 0.0, float = 0.0, 43 float = 0.0, float = 0.0,
44 const QString & = 0x0, const QString & = 0x0 ); 44 const QString & = 0x0, const QString & = 0x0 );
45 TranInfo( Config, int ); 45 TranInfo( Config, int );
46 46
47 int id() const { return i; } 47 int id() const { return i; }
48 const QString &desc() const { return d; } 48 const QString &desc() const { return d; }
49 const QDate &date() const { return td; } 49 const QDate &date() const { return td; }
50 const QString &datestr(); 50 const QString &datestr();
51 bool withdrawal()const { return w; } 51 bool withdrawal()const { return w; }
52 const QString &type() const { return t; } 52 const QString &type() const { return t; }
53 const QString &category()const { return c; } 53 const QString &category()const { return c; }
54 float amount() const { return a; } 54 float amount() const { return a; }
55 float fee() const { return f; } 55 float fee() const { return f; }
56 const QString &number() const { return cn; } 56 const QString &number() const { return cn; }
57 const QString &notes() const { return n; } 57 const QString &notes() const { return n; }
58 58
59 void setDesc( const QString &desc ) { d = desc; } 59 void setDesc( const QString &desc ) { d = desc; }
60 void setDate( const QDate &date ) { td = date; } 60 void setDate( const QDate &date ) { td = date; }
61 void setWithdrawal( bool withdrawal ){ w = withdrawal; } 61 void setWithdrawal( bool withdrawal ){ w = withdrawal; }
62 void setType( const QString &type ) { t = type; } 62 void setType( const QString &type ) { t = type; }
63 void setCategory( const QString &cat ){ c = cat; } 63 void setCategory( const QString &cat ){ c = cat; }
64 void setAmount( float amount ) { a = amount; } 64 void setAmount( float amount ) { a = amount; }
65 void setFee( float fee ) { f = fee; } 65 void setFee( float fee ) { f = fee; }
66 void setNumber( const QString &num ){ cn = num; } 66 void setNumber( const QString &num ){ cn = num; }
67 void setNotes( const QString &notes ){ n = notes; } 67 void setNotes( const QString &notes ){ n = notes; }
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
84typedef QList<TranInfo> TranInfoList; 84class 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