Diffstat (limited to 'noncore/apps/checkbook/traninfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/traninfo.cpp | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp index 65c190c..d880bb4 100644 --- a/noncore/apps/checkbook/traninfo.cpp +++ b/noncore/apps/checkbook/traninfo.cpp | |||
@@ -21,44 +21,45 @@ | |||
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "traninfo.h" | 29 | #include "traninfo.h" |
30 | 30 | ||
31 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
32 | 32 | ||
33 | QString tempstr; | 33 | QString tempstr; |
34 | 34 | ||
35 | TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal, | 35 | TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal, |
36 | const QString &type, const QString &category, float amount, | 36 | const QString &type, const QString &category, float amount, |
37 | float fee, const QString &number, const QString ¬es ) | 37 | float fee, const QString &number, const QString ¬es, int next ) |
38 | { | 38 | { |
39 | i = id; | 39 | i = id; |
40 | d = desc; | 40 | d = desc; |
41 | td = date; | 41 | td = date; |
42 | w = withdrawal; | 42 | w = withdrawal; |
43 | t = type; | 43 | t = type; |
44 | c = category; | 44 | c = category; |
45 | a = amount; | 45 | a = amount; |
46 | f = fee; | 46 | f = fee; |
47 | cn = number; | 47 | cn = number; |
48 | n = notes; | 48 | n = notes; |
49 | _next=next; | ||
49 | } | 50 | } |
50 | 51 | ||
51 | TranInfo::TranInfo( Config config, int entry ) | 52 | TranInfo::TranInfo( Config config, int entry ) |
52 | { | 53 | { |
53 | config.setGroup( QString::number( entry ) ); | 54 | config.setGroup( QString::number( entry ) ); |
54 | QString desc = config.readEntry( "Description", "Not Found" ); | 55 | QString desc = config.readEntry( "Description", "Not Found" ); |
55 | if ( desc != "Not Found" ) | 56 | if ( desc != "Not Found" ) |
56 | { | 57 | { |
57 | // ID | 58 | // ID |
58 | i = entry; | 59 | i = entry; |
59 | 60 | ||
60 | // Description | 61 | // Description |
61 | d = desc; | 62 | d = desc; |
62 | 63 | ||
63 | // Transaction date | 64 | // Transaction date |
64 | int yr, mn, dy; | 65 | int yr, mn, dy; |
@@ -98,93 +99,114 @@ TranInfo::TranInfo( Config config, int entry ) | |||
98 | else if( type == "3" ) | 99 | else if( type == "3" ) |
99 | t = "Cash"; | 100 | t = "Cash"; |
100 | } | 101 | } |
101 | 102 | ||
102 | // Category | 103 | // Category |
103 | c = config.readEntry( "Category", "" ); | 104 | c = config.readEntry( "Category", "" ); |
104 | 105 | ||
105 | // Transaction amount | 106 | // Transaction amount |
106 | QString stramount = config.readEntry( "Amount", "0.00" ); | 107 | QString stramount = config.readEntry( "Amount", "0.00" ); |
107 | bool ok; | 108 | bool ok; |
108 | a = stramount.toFloat( &ok ); | 109 | a = stramount.toFloat( &ok ); |
109 | 110 | ||
110 | // Transaction fee | 111 | // Transaction fee |
111 | stramount = config.readEntry( "TransactionFee", "0.00" ); | 112 | stramount = config.readEntry( "TransactionFee", "0.00" ); |
112 | f = stramount.toFloat( &ok ); | 113 | f = stramount.toFloat( &ok ); |
113 | 114 | ||
114 | // Transaction number | 115 | // Transaction number |
115 | cn = config.readEntry( "CheckNumber", "" ); | 116 | cn = config.readEntry( "CheckNumber", "" ); |
116 | 117 | ||
117 | // Notes | 118 | // Notes |
118 | n = config.readEntry( "Comments", "" ); | 119 | n = config.readEntry( "Comments", "" ); |
120 | |||
121 | // next | ||
122 | _next = config.readNumEntry("Next", -1); | ||
119 | } | 123 | } |
120 | } | 124 | } |
121 | 125 | ||
126 | // --- datestr ---------------------------------------------------------------- | ||
122 | const QString &TranInfo::datestr() | 127 | const QString &TranInfo::datestr() |
123 | { | 128 | { |
124 | tempstr = QString::number( td.year() ); | 129 | int y=td.year(); |
125 | tempstr.append( '/' ); | 130 | y= y>=2000 && y<=2099 ? y-2000 : y; |
126 | int tempfield = td.month(); | 131 | tempstr.sprintf( "%02d/%02d/%02d", y ,td.month(), td.day() ); |
127 | if ( tempfield < 10 ) tempstr.append( '0' ); | 132 | return( tempstr ); |
128 | tempstr.append( QString::number( tempfield ) ); | 133 | } |
129 | tempstr.append( '/' ); | ||
130 | tempfield = td.day(); | ||
131 | if ( tempfield < 10 ) tempstr.append( '0' ); | ||
132 | tempstr.append( QString::number( tempfield ) ); | ||
133 | 134 | ||
134 | return( tempstr ); | 135 | // --- getIdStr --------------------------------------------------------------- |
136 | const QString &TranInfo::getIdStr() | ||
137 | { | ||
138 | tempstr.sprintf("%04d", i); | ||
139 | return( tempstr ); | ||
135 | } | 140 | } |
136 | 141 | ||
137 | void TranInfo::write( Config *config, int entry ) | 142 | // --- write ------------------------------------------------------------------ |
143 | void TranInfo::write( Config *config ) | ||
138 | { | 144 | { |
139 | config->setGroup( QString::number( entry ) ); | 145 | config->setGroup( QString::number( id() ) ); |
140 | 146 | ||
141 | config->writeEntry( "Description", d ); | 147 | config->writeEntry( "Description", d ); |
142 | 148 | ||
143 | tempstr = QString::number( td.month() ); | 149 | tempstr = QString::number( td.month() ); |
144 | tempstr.append( '/' ); | 150 | tempstr.append( '/' ); |
145 | tempstr.append( QString::number( td.day() ) ); | 151 | tempstr.append( QString::number( td.day() ) ); |
146 | tempstr.append( '/' ); | 152 | tempstr.append( '/' ); |
147 | tempstr.append( QString::number( td.year() ) ); | 153 | tempstr.append( QString::number( td.year() ) ); |
148 | config->writeEntry( "Date", tempstr ); | 154 | config->writeEntry( "Date", tempstr ); |
149 | 155 | ||
150 | w ? tempstr = "true" | 156 | w ? tempstr = "true" |
151 | : tempstr = "false"; | 157 | : tempstr = "false"; |
152 | config->writeEntry( "Payment", tempstr ); | 158 | config->writeEntry( "Payment", tempstr ); |
153 | 159 | ||
154 | if ( t == "Debit Charge" || t == "Written Check" ) | 160 | if ( t == "Debit Charge" || t == "Written Check" ) |
155 | tempstr = "0"; | 161 | tempstr = "0"; |
156 | else if ( t == "Written Check" || t == "Automatic Payment" ) | 162 | else if ( t == "Written Check" || t == "Automatic Payment" ) |
157 | tempstr = "1"; | 163 | tempstr = "1"; |
158 | else if ( t == "Transfer" ) | 164 | else if ( t == "Transfer" ) |
159 | tempstr = "2"; | 165 | tempstr = "2"; |
160 | else if ( t == "Credit Card" || t == "Cash" ) | 166 | else if ( t == "Credit Card" || t == "Cash" ) |
161 | tempstr = "3"; | 167 | tempstr = "3"; |
162 | config->writeEntry( "Type", tempstr ); | 168 | config->writeEntry( "Type", tempstr ); |
163 | 169 | ||
164 | config->writeEntry( "Category", c ); | 170 | config->writeEntry( "Category", c ); |
165 | 171 | ||
166 | tempstr.setNum( a, 'f', 2 ); | 172 | tempstr.setNum( a, 'f', 2 ); |
167 | config->writeEntry( "Amount", tempstr ); | 173 | config->writeEntry( "Amount", tempstr ); |
168 | 174 | ||
169 | tempstr.setNum( f, 'f', 2 ); | 175 | tempstr.setNum( f, 'f', 2 ); |
170 | config->writeEntry( "TransactionFee", tempstr ); | 176 | config->writeEntry( "TransactionFee", tempstr ); |
171 | 177 | ||
172 | config->writeEntry( "CheckNumber", cn ); | 178 | config->writeEntry( "CheckNumber", cn ); |
173 | |||
174 | config->writeEntry( "Comments", n ); | 179 | config->writeEntry( "Comments", n ); |
180 | config->writeEntry( "Next", _next ); | ||
175 | } | 181 | } |
176 | 182 | ||
183 | |||
177 | int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) | 184 | int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) |
178 | { | 185 | { |
179 | QDate d1 = ((TranInfo *)item1)->date(); | 186 | QDate d1 = ((TranInfo *)item1)->date(); |
180 | QDate d2 = ((TranInfo *)item2)->date(); | 187 | QDate d2 = ((TranInfo *)item2)->date(); |
181 | int r = -1; | 188 | int r = -1; |
182 | 189 | ||
183 | if ( d1 < d2 ) | 190 | if ( d1 < d2 ) |
184 | r = -1; | 191 | r = -1; |
185 | else if ( d1 == d2 ) | 192 | else if ( d1 == d2 ) |
186 | r = 0; | 193 | r = 0; |
187 | else if ( d1 > d2 ) | 194 | else if ( d1 > d2 ) |
188 | r = 1; | 195 | r = 1; |
189 | return( r ); | 196 | return( r ); |
190 | } | 197 | } |
198 | |||
199 | // --- toString --------------------------------------------------------------- | ||
200 | QString TranInfo::toString() | ||
201 | { | ||
202 | QString ret; | ||
203 | ret.sprintf("(%4d) %10s %4s %-10s %5.2f %5.2f", | ||
204 | id(), | ||
205 | (const char *)datestr(), | ||
206 | (const char *)number(), | ||
207 | (const char *)desc(), | ||
208 | (withdrawal() ? -1 : 1) * amount(), | ||
209 | fee() | ||
210 | ); | ||
211 | return(ret); | ||
212 | } | ||