Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

traninfo.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the OPIE Project
00003                =.
00004              .=l.            Copyright (c)  2002 Dan Williams <drw@handhelds.org>
00005            .>+-=
00006  _;:,     .>    :=|.         This file is free software; you can
00007 .> <`_,   >  .   <=          redistribute it and/or modify it under
00008 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00009 .="- .-=="i,     .._         License as published by the Free Software
00010  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00011      ._= =}       :          or (at your option) any later version.
00012     .%`+i>       _;_.
00013     .i_,=:_.      -<s.       This file is distributed in the hope that
00014      +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
00015     : ..    .:,     . . .    without even the implied warranty of
00016     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
00018 ..}^=.=       =       ;      Public License for more details.
00019 ++=   -.     .`     .:
00020  :     =  ...= . :.=-        You should have received a copy of the GNU
00021  -.   .:....=;==+<;          General Public License along with this file;
00022   -_. . .   )=.  =           see the file COPYING. If not, write to the
00023     --        :-=`           Free Software Foundation, Inc.,
00024                              59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
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 &notes, 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                 // ID
00060                 i = entry;
00061 
00062                 // Description
00063                 d = desc;
00064 
00065                 // Transaction date
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                 // Deposit/withdrawal indicator ( withdrawal == TRUE )
00077                 w = ( config->readEntry( "Payment", "false" ) == "true" );
00078 
00079                 // Type
00080                 QString type = config->readEntry( "Type", "0" );
00081                 if ( w )
00082                 {   // Withdrawal types
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                 // Category
00105                 c = config->readEntry( "Category", "" );
00106 
00107                 // Transaction amount
00108                 QString stramount = config->readEntry( "Amount", "0.00" );
00109                 bool ok;
00110                 a = stramount.toFloat( &ok );
00111 
00112                 // Transaction fee
00113                 stramount = config->readEntry( "TransactionFee", "0.00" );
00114                 f = stramount.toFloat( &ok );
00115 
00116         // Transaction number
00117                 cn = config->readEntry( "CheckNumber", "" );
00118 
00119                 // Notes
00120                 n = config->readEntry( "Comments", "" );
00121 
00122         // next
00123         _next = config->readNumEntry("Next", -1);
00124         }
00125 }
00126 
00127 // --- datestr ----------------------------------------------------------------
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 // --- getIdStr ---------------------------------------------------------------
00140 const QString &TranInfo::getIdStr()
00141 {
00142     tempstr.sprintf("%04d", i);
00143     return( tempstr );
00144 }
00145 
00146 // --- write ------------------------------------------------------------------
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 // --- toString ---------------------------------------------------------------
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 // --- findMostRecentByDesc ---------------------------------------------------
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 }

Generated on Sat Nov 5 16:16:47 2005 for OPIE by  doxygen 1.4.2