summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp2
-rw-r--r--noncore/apps/checkbook/traninfo.cpp24
-rw-r--r--noncore/apps/checkbook/traninfo.h2
3 files changed, 14 insertions, 14 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp
index 36dde04..6e3afa7 100644
--- a/noncore/apps/checkbook/cbinfo.cpp
+++ b/noncore/apps/checkbook/cbinfo.cpp
@@ -1,228 +1,228 @@
/*
                This file is part of the OPIE Project
=.
             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.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.
*/
#include "cbinfo.h"
#include "traninfo.h"
#include <qpe/config.h>
#include <qfile.h>
// --- CBInfo -----------------------------------------------------------------
CBInfo::CBInfo()
{
n = "";
fn = "";
pw = QString::null;
t = "";
bn = "";
a = "";
p = "";
nt = "";
sb = 0.0;
_sLastTab="";
_first=-1;
_last=-1;
tl = new TranInfoList();
}
// --- CBInfo -----------------------------------------------------------------
CBInfo::CBInfo( const QString &name, const QString &filename )
{
Config config( filename, Config::File );
config.setGroup( "Account" );
n = name;
fn = filename;
pw = config.readEntryCrypt( "Password", QString::null );
t = config.readEntry( "Type" );
bn = config.readEntry( "Bank", "" );
a = config.readEntryCrypt( "Number", "" );
p = config.readEntryCrypt( "PINNumber", "" );
nt = config.readEntry( "Notes", "" );
_sLastTab = config.readEntry("LastTab", "");
_first=config.readNumEntry("First", -1);
_sSortOrder = config.readEntry( "SortOrder", QWidget::tr("Date") );
bool ok;
sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok );
loadTransactions();
}
// --- balance ----------------------------------------------------------------
float CBInfo::balance()
{
calcBalance();
return b;
}
// --- write ------------------------------------------------------------------
void CBInfo::write()
{
QFile f( fn );
if ( f.exists() )
f.remove();
Config *config = new Config(fn, Config::File);
// fix transaction numbers
_first=-1;
TranInfo *prev=NULL;
for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) {
if( _first<0 ) _first=tran->id();
if( prev ) prev->setNext( tran->id() );
tran->setNext(-1);
prev=tran;
}
// Save transactions
for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) {
tran->write(config);
}
// Save info
if( _first<0 && _last>=0 ) _first=_last;
config->setGroup( "Account" );
config->writeEntryCrypt( "Password", pw );
config->writeEntry( "Type", t );
config->writeEntry( "Bank", bn );
config->writeEntryCrypt( "Number", a );
config->writeEntryCrypt( "PINNumber", p );
config->writeEntry( "Notes", nt );
config->writeEntry( "LastTab", _sLastTab );
QString balstr;
balstr.setNum( sb, 'f', 2 );
config->writeEntry( "Balance", balstr );
config->writeEntry( "First", _first );
config->writeEntry( "SortOrder", _sSortOrder );
config->write();
delete config;
}
// --- findTransaction --------------------------------------------------------
TranInfo *CBInfo::findTransaction( const QString &sId )
{
bool bOk;
int id=sId.toInt( &bOk );
if( !bOk )
return(false);
TranInfo *traninfo;
for(traninfo=tl->first(); traninfo; traninfo=tl->next()) {
if( traninfo->id() == id )
break;
}
return(traninfo);
}
void CBInfo::addTransaction( TranInfo *tran )
{
tl->append( tran );
calcBalance();
}
void CBInfo::removeTransaction( TranInfo *tran )
{
tl->removeRef( tran );
delete tran;
calcBalance();
}
// --- loadTransactions -------------------------------------------------------
// Reads the transactions. Either the old way 1-n or as linked list.
void CBInfo::loadTransactions()
{
TranInfo *tran;
QString trandesc = "";
tl = new TranInfoList();
Config config( fn, Config::File );
int i=_first;
bool bOld=false;
if( i==-1 ) {
i=1;
bOld=true;
}
while( i>=0 ) {
_last=i;
- tran=new TranInfo(config, i);
+ tran=new TranInfo(&config, i);
trandesc = tran->desc();
if( trandesc==QString::null ) {
delete tran;
break;
}
tl->append(tran);
i= bOld ? i+1 : tran->getNext();
}
calcBalance();
}
// --- calcBalance ------------------------------------------------------------
void CBInfo::calcBalance()
{
float amount;
b = sb;
for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
{
b -= tran->fee();
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
b += amount;
}
}
int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
{
QString n1 = ((CBInfo *)item1)->name();
QString n2 = ((CBInfo *)item2)->name();
int r = -1;
if ( n1 < n2 )
r = -1;
else if ( n1 == n2 )
r = 0;
else if ( n1 > n2 )
r = 1;
return( r );
}
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp
index 4833af9..7bd2004 100644
--- a/noncore/apps/checkbook/traninfo.cpp
+++ b/noncore/apps/checkbook/traninfo.cpp
@@ -1,227 +1,227 @@
/*
                This file is part of the OPIE Project
=.
             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.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.
*/
#include "traninfo.h"
#include <qpe/config.h>
#include <qpe/timestring.h>
QString tempstr;
TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal,
const QString &type, const QString &category, float amount,
float fee, const QString &number, const QString &notes, int next )
{
i = id;
d = desc;
td = date;
w = withdrawal;
t = type;
c = category;
a = amount;
f = fee;
cn = number;
n = notes;
_next=next;
}
-TranInfo::TranInfo( Config config, int entry )
+TranInfo::TranInfo( Config *config, int entry )
{
- config.setGroup( QString::number( entry ) );
- QString desc = config.readEntry( "Description", "Not Found" );
+ config->setGroup( QString::number( entry ) );
+ QString desc = config->readEntry( "Description", "Not Found" );
if ( desc != "Not Found" )
{
// ID
i = entry;
// Description
d = desc;
// Transaction date
int yr, mn, dy;
- QString datestr = config.readEntry( "Date", "" );
+ QString datestr = config->readEntry( "Date", "" );
int begin, end;
begin = datestr.find( '/' );
mn = datestr.left( begin ).toInt();
end = datestr.find( '/', ++begin );
dy = datestr.mid( begin, end - begin ).toInt();
yr = datestr.right( datestr.length() - end - 1).toInt();
td.setYMD( yr, mn, dy );
// Deposit/withdrawal indicator ( withdrawal == TRUE )
- w = ( config.readEntry( "Payment", "false" ) == "true" );
+ w = ( config->readEntry( "Payment", "false" ) == "true" );
// Type
- QString type = config.readEntry( "Type", "0" );
+ QString type = config->readEntry( "Type", "0" );
if ( w )
{ // 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", "" );
+ c = config->readEntry( "Category", "" );
// Transaction amount
- QString stramount = config.readEntry( "Amount", "0.00" );
+ QString stramount = config->readEntry( "Amount", "0.00" );
bool ok;
a = stramount.toFloat( &ok );
// Transaction fee
- stramount = config.readEntry( "TransactionFee", "0.00" );
+ stramount = config->readEntry( "TransactionFee", "0.00" );
f = stramount.toFloat( &ok );
// Transaction number
- cn = config.readEntry( "CheckNumber", "" );
+ cn = config->readEntry( "CheckNumber", "" );
// Notes
- n = config.readEntry( "Comments", "" );
+ n = config->readEntry( "Comments", "" );
// next
- _next = config.readNumEntry("Next", -1);
+ _next = config->readNumEntry("Next", -1);
}
}
// --- datestr ----------------------------------------------------------------
const QString &TranInfo::datestr(bool bDisplayDate)
{
if( bDisplayDate ) {
tempstr=TimeString::numberDateString( td );
} else {
tempstr.sprintf( "%04d-%02d-%02d", td.year() ,td.month(), td.day() );
}
return(tempstr);
}
// --- getIdStr ---------------------------------------------------------------
const QString &TranInfo::getIdStr()
{
tempstr.sprintf("%04d", i);
return( tempstr );
}
// --- write ------------------------------------------------------------------
void TranInfo::write( Config *config )
{
config->setGroup( QString::number( id() ) );
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 );
config->writeEntry( "Next", _next );
}
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 );
}
// --- toString ---------------------------------------------------------------
QString TranInfo::toString()
{
QString ret;
ret.sprintf("(%4d) %10s %4s %-10s %5.2f %5.2f",
id(),
(const char *)datestr(),
(const char *)number(),
(const char *)desc(),
(withdrawal() ? -1 : 1) * amount(),
fee()
);
return(ret);
}
// --- findMostRecentByDesc ---------------------------------------------------
TranInfo *TranInfoList::findMostRecentByDesc( const QString &desc )
{
for(TranInfo *cur=last(); cur; cur=prev()) {
if( cur->desc()==desc )
return( cur );
}
return(NULL);
}
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h
index cbe0238..2ecb60d 100644
--- a/noncore/apps/checkbook/traninfo.h
+++ b/noncore/apps/checkbook/traninfo.h
@@ -1,103 +1,103 @@
/*
                This file is part of the OPIE Project
=.
             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.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>
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, int =-1 );
- TranInfo( Config, int );
+ TranInfo( Config *, int );
// getters
int id() const { return i; }
const QString &getIdStr();
const QString &desc() const { return d; }
const QDate &date() const { return td; }
const QString &datestr(bool = false);
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 &notes() const { return n; }
int getNext() { return(_next); }
// setters
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 &notes ) { n = notes; }
void setNext(int next) { _next=next; }
// write
void write( Config * );
// toString
QString toString();
private:
int i;
QString d;
QDate td;
bool w;
QString t;
QString c;
float a;
float f;
QString cn;
QString n;
int _next;
};
class TranInfoList : public QList<TranInfo>
{
public:
TranInfo *findMostRecentByDesc( const QString &desc );
protected:
int compareItems( QCollection::Item, QCollection::Item );
};
#endif