00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "traninfo.h"
00030
00031 #include <qpe/config.h>
00032 #include <qpe/timestring.h>
00033
00034 QString tempstr;
00035
00036 TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal,
00037 const QString &type, const QString &category, float amount,
00038 float fee, const QString &number, const QString ¬es, int next )
00039 {
00040 i = id;
00041 d = desc;
00042 td = date;
00043 w = withdrawal;
00044 t = type;
00045 c = category;
00046 a = amount;
00047 f = fee;
00048 cn = number;
00049 n = notes;
00050 _next=next;
00051 }
00052
00053 TranInfo::TranInfo( Config *config, int entry )
00054 {
00055 config->setGroup( QString::number( entry ) );
00056 QString desc = config->readEntry( "Description", "Not Found" );
00057 if ( desc != "Not Found" )
00058 {
00059
00060 i = entry;
00061
00062
00063 d = desc;
00064
00065
00066 int yr, mn, dy;
00067 QString datestr = config->readEntry( "Date", "" );
00068 int begin, end;
00069 begin = datestr.find( '/' );
00070 mn = datestr.left( begin ).toInt();
00071 end = datestr.find( '/', ++begin );
00072 dy = datestr.mid( begin, end - begin ).toInt();
00073 yr = datestr.right( datestr.length() - end - 1).toInt();
00074 td.setYMD( yr, mn, dy );
00075
00076
00077 w = ( config->readEntry( "Payment", "false" ) == "true" );
00078
00079
00080 QString type = config->readEntry( "Type", "0" );
00081 if ( w )
00082 {
00083 if( type == "0" )
00084 t = "Debit Charge";
00085 else if( type == "1" )
00086 t = "Written Check";
00087 else if( type == "2" )
00088 t = "Transfer";
00089 else if( type == "3" )
00090 t = "Credit Card";
00091 }
00092 else
00093 {
00094 if( type == "0" )
00095 t = "Written Check";
00096 else if( type == "1" )
00097 t = "Automatic Payment";
00098 else if( type == "2" )
00099 t = "Transfer";
00100 else if( type == "3" )
00101 t = "Cash";
00102 }
00103
00104
00105 c = config->readEntry( "Category", "" );
00106
00107
00108 QString stramount = config->readEntry( "Amount", "0.00" );
00109 bool ok;
00110 a = stramount.toFloat( &ok );
00111
00112
00113 stramount = config->readEntry( "TransactionFee", "0.00" );
00114 f = stramount.toFloat( &ok );
00115
00116
00117 cn = config->readEntry( "CheckNumber", "" );
00118
00119
00120 n = config->readEntry( "Comments", "" );
00121
00122
00123 _next = config->readNumEntry("Next", -1);
00124 }
00125 }
00126
00127
00128 const QString &TranInfo::datestr(bool bDisplayDate)
00129 {
00130 if( bDisplayDate ) {
00131 tempstr=TimeString::numberDateString( td );
00132 } else {
00133 tempstr.sprintf( "%04d-%02d-%02d", td.year() ,td.month(), td.day() );
00134 }
00135 return(tempstr);
00136 }
00137
00138
00139
00140 const QString &TranInfo::getIdStr()
00141 {
00142 tempstr.sprintf("%04d", i);
00143 return( tempstr );
00144 }
00145
00146
00147 void TranInfo::write( Config *config )
00148 {
00149 config->setGroup( QString::number( id() ) );
00150
00151 config->writeEntry( "Description", d );
00152
00153 tempstr = QString::number( td.month() );
00154 tempstr.append( '/' );
00155 tempstr.append( QString::number( td.day() ) );
00156 tempstr.append( '/' );
00157 tempstr.append( QString::number( td.year() ) );
00158 config->writeEntry( "Date", tempstr );
00159
00160 w ? tempstr = "true"
00161 : tempstr = "false";
00162 config->writeEntry( "Payment", tempstr );
00163
00164 if ( t == "Debit Charge" || t == "Written Check" )
00165 tempstr = "0";
00166 else if ( t == "Written Check" || t == "Automatic Payment" )
00167 tempstr = "1";
00168 else if ( t == "Transfer" )
00169 tempstr = "2";
00170 else if ( t == "Credit Card" || t == "Cash" )
00171 tempstr = "3";
00172 config->writeEntry( "Type", tempstr );
00173
00174 config->writeEntry( "Category", c );
00175
00176 tempstr.setNum( a, 'f', 2 );
00177 config->writeEntry( "Amount", tempstr );
00178
00179 tempstr.setNum( f, 'f', 2 );
00180 config->writeEntry( "TransactionFee", tempstr );
00181
00182 config->writeEntry( "CheckNumber", cn );
00183 config->writeEntry( "Comments", n );
00184 config->writeEntry( "Next", _next );
00185 }
00186
00187
00188 int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
00189 {
00190 QDate d1 = ((TranInfo *)item1)->date();
00191 QDate d2 = ((TranInfo *)item2)->date();
00192 int r = -1;
00193
00194 if ( d1 < d2 )
00195 r = -1;
00196 else if ( d1 == d2 )
00197 r = 0;
00198 else if ( d1 > d2 )
00199 r = 1;
00200 return( r );
00201 }
00202
00203
00204 QString TranInfo::toString()
00205 {
00206 QString ret;
00207 ret.sprintf("(%4d) %10s %4s %-10s %5.2f %5.2f",
00208 id(),
00209 (const char *)datestr(),
00210 (const char *)number(),
00211 (const char *)desc(),
00212 (withdrawal() ? -1 : 1) * amount(),
00213 fee()
00214 );
00215 return(ret);
00216 }
00217
00218
00219
00220 TranInfo *TranInfoList::findMostRecentByDesc( const QString &desc )
00221 {
00222 for(TranInfo *cur=last(); cur; cur=prev()) {
00223 if( cur->desc()==desc )
00224 return( cur );
00225 }
00226 return(NULL);
00227 }