Diffstat (limited to 'noncore/apps/checkbook/traninfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/traninfo.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp new file mode 100644 index 0000000..5a770b0 --- a/dev/null +++ b/noncore/apps/checkbook/traninfo.cpp | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "traninfo.h" | ||
30 | |||
31 | #include <qpe/config.h> | ||
32 | |||
33 | TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal, | ||
34 | const QString &type, const QString &category, float amount, | ||
35 | float fee, const QString &number, const QString ¬es ) | ||
36 | { | ||
37 | i = id; | ||
38 | d = desc; | ||
39 | td = date; | ||
40 | w = withdrawal; | ||
41 | t = type; | ||
42 | c = category; | ||
43 | a = amount; | ||
44 | f = fee; | ||
45 | cn = number; | ||
46 | n = notes; | ||
47 | } | ||
48 | |||
49 | TranInfo::TranInfo( Config config, int entry ) | ||
50 | { | ||
51 | config.setGroup( QString::number( entry ) ); | ||
52 | QString desc = config.readEntry( "Description", "Not Found" ); | ||
53 | if ( desc != "Not Found" ) | ||
54 | { | ||
55 | // ID | ||
56 | i = entry; | ||
57 | |||
58 | // Description | ||
59 | d = desc; | ||
60 | |||
61 | // Transaction date | ||
62 | int yr, mn, dy; | ||
63 | QString datestr = config.readEntry( "Date", "" ); | ||
64 | int begin, end; | ||
65 | begin = datestr.find( '/' ); | ||
66 | mn = datestr.left( begin ).toInt(); | ||
67 | end = datestr.find( '/', ++begin ); | ||
68 | dy = datestr.mid( begin, end - begin ).toInt(); | ||
69 | yr = datestr.right( datestr.length() - end - 1).toInt(); | ||
70 | td.setYMD( yr, mn, dy ); | ||
71 | |||
72 | // Deposit/withdrawal indicator ( withdrawal == TRUE ) | ||
73 | w = ( config.readEntry( "Payment", "false" ) == "true" ); | ||
74 | |||
75 | // Type | ||
76 | QString type = config.readEntry( "Type", "0" ); | ||
77 | if ( w ) | ||
78 | { // Withdrawal types | ||
79 | if( type == "0" ) | ||
80 | t = "Debit Charge"; | ||
81 | else if( type == "1" ) | ||
82 | t = "Written Check"; | ||
83 | else if( type == "2" ) | ||
84 | t = "Transfer"; | ||
85 | else if( type == "3" ) | ||
86 | t = "Credit Card"; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | if( type == "0" ) | ||
91 | t = "Written Check"; | ||
92 | else if( type == "1" ) | ||
93 | t = "Automatic Payment"; | ||
94 | else if( type == "2" ) | ||
95 | t = "Transfer"; | ||
96 | else if( type == "3" ) | ||
97 | t = "Cash"; | ||
98 | } | ||
99 | |||
100 | // Category | ||
101 | c = config.readEntry( "Category", "" ); | ||
102 | |||
103 | // Transaction amount | ||
104 | QString stramount = config.readEntry( "Amount", "0.00" ); | ||
105 | bool ok; | ||
106 | a = stramount.toFloat( &ok ); | ||
107 | |||
108 | // Transaction fee | ||
109 | stramount = config.readEntry( "TransactionFee", "0.00" ); | ||
110 | f = stramount.toFloat( &ok ); | ||
111 | |||
112 | // Transaction number | ||
113 | cn = config.readEntry( "CheckNumber", "" ); | ||
114 | |||
115 | // Notes | ||
116 | n = config.readEntry( "Comments", "" ); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | void TranInfo::write( Config *config, int entry ) | ||
121 | { | ||
122 | config->setGroup( QString::number( entry ) ); | ||
123 | |||
124 | config->writeEntry( "Description", d ); | ||
125 | |||
126 | QString tempstr = QString::number( td.month() ) + "/" + | ||
127 | QString::number( td.day() ) + "/" + | ||
128 | QString::number( td.year() ); | ||
129 | config->writeEntry( "Date", tempstr ); | ||
130 | |||
131 | w ? tempstr = "true" | ||
132 | : tempstr = "false"; | ||
133 | config->writeEntry( "Payment", tempstr ); | ||
134 | |||
135 | if ( t == "Debit Charge" || t == "Written Check" ) | ||
136 | tempstr = "0"; | ||
137 | else if ( t == "Written Check" || t == "Automatic Payment" ) | ||
138 | tempstr = "1"; | ||
139 | else if ( t == "Transfer" ) | ||
140 | tempstr = "2"; | ||
141 | else if ( t == "Credit Card" || t == "Cash" ) | ||
142 | tempstr = "3"; | ||
143 | config->writeEntry( "Type", tempstr ); | ||
144 | |||
145 | config->writeEntry( "Category", c ); | ||
146 | |||
147 | tempstr.setNum( a, 'f', 2 ); | ||
148 | config->writeEntry( "Amount", tempstr ); | ||
149 | |||
150 | tempstr.setNum( f, 'f', 2 ); | ||
151 | config->writeEntry( "TransactionFee", tempstr ); | ||
152 | |||
153 | config->writeEntry( "CheckNumber", cn ); | ||
154 | |||
155 | config->writeEntry( "Comments", n ); | ||
156 | } | ||