-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 @@ -218,379 +218,379 @@ QWidget *Checkbook::initTransactions() layout->addWidget( btn, 2, 0 ); btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); layout->addWidget( btn, 2, 1 ); btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); layout->addWidget( btn, 2, 2 ); return( control ); } QWidget *Checkbook::initCharts() { graphInfo = 0x0; QWidget *control = new QWidget( mainWidget ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); graphWidget = new Graph( control ); QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); graphList = new QComboBox( control ); QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); graphList->insertItem( tr( "Account balance" ) ); graphList->insertItem( tr( "Withdrawals by category" ) ); graphList->insertItem( tr( "Deposits by category" ) ); layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); layout->addWidget( btn, 1, 2 ); return control; } void Checkbook::loadCheckbook() { transactions.clear(); Config config(filename, Config::File); // Load info config.setGroup( "Account" ); nameEdit->setText( name ); QString temptext = config.readEntry( "Type" ); int i = typeList->count(); while ( i > 0 ) { i--; typeList->setCurrentItem( i ); if ( typeList->currentText() == temptext ) { break; } } bankEdit->setText( config.readEntry( "Bank", "" ) ); acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) ); pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) ); balanceEdit->setText( config.readEntry( "Balance", "0.0" ) ); notesEdit->setText( config.readEntry( "Notes", "" ) ); bool ok; currBalance = balanceEdit->text().toFloat( &ok ); startBalance = currBalance; // Load transactions TranInfo *tran; QString trandesc = ""; float amount; QString stramount; for ( int i = 1; trandesc != QString::null; i++ ) { tran = new TranInfo( config, i ); trandesc = tran->desc(); if ( trandesc != QString::null ) { currBalance -= tran->fee(); amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } currBalance += amount; stramount.sprintf( "%c%.2f", currencySymbol, amount ); // Add to transaction list - transactions.append( tran ); + transactions.inSort( tran ); // Add to transaction table ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(), trandesc, stramount ); } else { delete tran; } } balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); highTranNum = transactions.count(); } void Checkbook::adjustBalance( float amount ) { currBalance += amount; balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); } TranInfo *Checkbook::findTranByID( int id ) { TranInfo *traninfo = transactions.first(); while ( traninfo && traninfo->id() != id ) { traninfo = transactions.next(); } return( traninfo ); } void Checkbook::accept() { QFile f( filename ); if ( f.exists() ) { f.remove(); } Config *config = new Config(filename, Config::File); // Save info config->setGroup( "Account" ); config->writeEntry( "Type", typeList->currentText() ); config->writeEntry( "Bank", bankEdit->text() ); config->writeEntryCrypt( "Number", acctNumEdit->text() ); config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); config->writeEntry( "Balance", balanceEdit->text() ); config->writeEntry( "Notes", notesEdit->text() ); // Save transactions int i = 1; for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) { tran->write( config, i ); i++; } config->write(); QDialog::accept(); } void Checkbook::slotNameChanged( const QString &newname ) { name = newname; filename = filedir; filename.append( newname ); filename.append( ".qcb" ); QString tempstr = name; tempstr.append( " - " ); tempstr.append( tr( "Checkbook" ) ); setCaption( tempstr ); } void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) { currBalance -= startBalance; bool ok; startBalance = newbalance.toFloat( &ok ); adjustBalance( startBalance ); } void Checkbook::slotNewTran() { highTranNum++; TranInfo *traninfo = new TranInfo( highTranNum ); Transaction *currtran = new Transaction( this, name, traninfo, currencySymbol ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } QString stramount; stramount.sprintf( "%c%.2f", currencySymbol, amount ); // Add to transaction list - transactions.append( traninfo ); + transactions.inSort( traninfo ); // Add to transaction table ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), traninfo->datestr(), traninfo->desc(), stramount ); adjustBalance( amount ); } else { highTranNum--; delete traninfo; } } void Checkbook::slotEditTran() { bool ok; QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) { return; } int tranid = curritem->text( 0 ).toInt( &ok ); TranInfo *traninfo = findTranByID( tranid ); float origamt = traninfo->amount(); if ( traninfo->withdrawal() ) { origamt *= -1; } Transaction *currtran = new Transaction( this, name, traninfo, currencySymbol ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { curritem->setText( 1, traninfo->datestr() ); curritem->setText( 2, traninfo->desc() ); float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } adjustBalance( origamt * -1 ); adjustBalance( amount ); QString stramount; stramount.sprintf( "%c%.2f", currencySymbol, amount ); curritem->setText( 3, stramount ); balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); delete currtran; } } void Checkbook::slotDeleteTran() { QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) { return; } bool ok; int tranid = curritem->text( 0 ).toInt( &ok ); TranInfo *traninfo = findTranByID( tranid ); if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) { float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } transactions.remove( traninfo ); delete traninfo; delete curritem; adjustBalance( amount * -1 ); } } void Checkbook::slotDrawGraph() { if ( graphInfo ) { delete graphInfo; } switch ( graphList->currentItem() ) { case 0 : drawBalanceChart(); break; case 1 : drawCategoryChart( TRUE ); break; case 2 : drawCategoryChart( FALSE ); break; }; graphWidget->setGraphInfo( graphInfo ); graphWidget->drawGraph( TRUE ); } void Checkbook::drawBalanceChart() { DataPointList *list = new DataPointList(); float balance = startBalance; float amount; QString label; int i = 0; int count = transactions.count(); for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) { i++; balance -= tran->fee(); amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } balance += amount; if ( i == 1 || i == count / 2 || i == count ) { label = tran->datestr(); } else { label = ""; } list->append( new DataPointInfo( label, balance ) ); } graphInfo = new GraphInfo( GraphInfo::BarChart, list ); } void Checkbook::drawCategoryChart( bool withdrawals ) { DataPointList *list = new DataPointList(); TranInfo *tran = transactions.first(); - if ( tran->withdrawal() == withdrawals ) + if ( tran && tran->withdrawal() == withdrawals ) { list->append( new DataPointInfo( tran->category(), tran->amount() ) ); } tran = transactions.next(); DataPointInfo *cat; for ( ; tran; tran = transactions.next() ) { if ( tran->withdrawal() == withdrawals ) { // Find category in list for ( cat = list->first(); cat; cat = list->next() ) { if ( cat->label() == tran->category() ) { break; } } if ( cat && cat->label() == tran->category() ) { // Found category, add to transaction to category total cat->addToValue( tran->amount() ); } else { // Didn't find category, add category to list list->append( new DataPointInfo( tran->category(), tran->amount() ) ); } } } graphInfo = new GraphInfo( GraphInfo::PieChart, list ); } 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 @@ -80,96 +80,111 @@ TranInfo::TranInfo( Config config, int entry ) { // Withdrawal types if( type == "0" ) t = "Debit Charge"; else if( type == "1" ) t = "Written Check"; else if( type == "2" ) t = "Transfer"; else if( type == "3" ) t = "Credit Card"; } else { if( type == "0" ) t = "Written Check"; else if( type == "1" ) t = "Automatic Payment"; else if( type == "2" ) t = "Transfer"; else if( type == "3" ) t = "Cash"; } // Category c = config.readEntry( "Category", "" ); // Transaction amount QString stramount = config.readEntry( "Amount", "0.00" ); bool ok; a = stramount.toFloat( &ok ); // Transaction fee stramount = config.readEntry( "TransactionFee", "0.00" ); f = stramount.toFloat( &ok ); // Transaction number cn = config.readEntry( "CheckNumber", "" ); // Notes n = config.readEntry( "Comments", "" ); } } const QString &TranInfo::datestr() { tempstr = QString::number( td.year() ); tempstr.append( '/' ); int tempfield = td.month(); if ( tempfield < 10 ) tempstr.append( '0' ); tempstr.append( QString::number( tempfield ) ); tempstr.append( '/' ); tempfield = td.day(); if ( tempfield < 10 ) tempstr.append( '0' ); tempstr.append( QString::number( tempfield ) ); return( tempstr ); } void TranInfo::write( Config *config, int entry ) { config->setGroup( QString::number( entry ) ); config->writeEntry( "Description", d ); tempstr = QString::number( td.month() ); tempstr.append( '/' ); tempstr.append( QString::number( td.day() ) ); tempstr.append( '/' ); tempstr.append( QString::number( td.year() ) ); config->writeEntry( "Date", tempstr ); w ? tempstr = "true" : tempstr = "false"; config->writeEntry( "Payment", tempstr ); if ( t == "Debit Charge" || t == "Written Check" ) tempstr = "0"; else if ( t == "Written Check" || t == "Automatic Payment" ) tempstr = "1"; else if ( t == "Transfer" ) tempstr = "2"; else if ( t == "Credit Card" || t == "Cash" ) tempstr = "3"; config->writeEntry( "Type", tempstr ); config->writeEntry( "Category", c ); tempstr.setNum( a, 'f', 2 ); config->writeEntry( "Amount", tempstr ); tempstr.setNum( f, 'f', 2 ); config->writeEntry( "TransactionFee", tempstr ); config->writeEntry( "CheckNumber", cn ); config->writeEntry( "Comments", n ); } + +int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) +{ + QDate d1 = ((TranInfo *)item1)->date(); + QDate d2 = ((TranInfo *)item2)->date(); + int r = -1; + + if ( d1 < d2 ) + r = -1; + else if ( d1 == d2 ) + r = 0; + else if ( d1 > d2 ) + r = 1; + return( r ); +}
\ 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 @@ -1,86 +1,92 @@ /* This file is part of the OPIE Project =. .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TRANINFO_H #define TRANINFO_H #include <qdatetime.h> #include <qlist.h> #include <qstring.h> class Config; class TranInfo { public: TranInfo( int = 0, const QString & = 0x0, const QDate & = QDate::currentDate(), bool = TRUE, const QString & = 0x0, const QString & = 0x0, float = 0.0, float = 0.0, const QString & = 0x0, const QString & = 0x0 ); TranInfo( Config, int ); int id() const { return i; } const QString &desc() const { return d; } const QDate &date() const { return td; } const QString &datestr(); bool withdrawal() const { return w; } const QString &type() const { return t; } const QString &category() const { return c; } float amount() const { return a; } float fee() const { return f; } const QString &number() const { return cn; } const QString ¬es() const { return n; } void setDesc( const QString &desc ) { d = desc; } void setDate( const QDate &date ) { td = date; } void setWithdrawal( bool withdrawal ) { w = withdrawal; } void setType( const QString &type ) { t = type; } void setCategory( const QString &cat ) { c = cat; } void setAmount( float amount ) { a = amount; } void setFee( float fee ) { f = fee; } void setNumber( const QString &num ) { cn = num; } void setNotes( const QString ¬es ) { n = notes; } void write( Config *, int ); private: int i; QString d; QDate td; bool w; QString t; QString c; float a; float f; QString cn; QString n; }; -typedef QList<TranInfo> TranInfoList; +class TranInfoList : public QList<TranInfo> +{ + protected: + int compareItems( QCollection::Item, QCollection::Item ); +}; + +//typedef TranList<TranInfo> TranInfoList; #endif |