author | allenforsythe <allenforsythe> | 2003-05-16 20:08:38 (UTC) |
---|---|---|
committer | allenforsythe <allenforsythe> | 2003-05-16 20:08:38 (UTC) |
commit | e6ff2dbd2d128c3cf873e23f4df8006759b47079 (patch) (unidiff) | |
tree | bb3c996b76c8937d871f642f0e32032848d32396 /noncore/apps/qashmoney/transaction.cpp | |
parent | 87051a7ba4834aed152bc09aad7f4935c9729ccb (diff) | |
download | opie-e6ff2dbd2d128c3cf873e23f4df8006759b47079.zip opie-e6ff2dbd2d128c3cf873e23f4df8006759b47079.tar.gz opie-e6ff2dbd2d128c3cf873e23f4df8006759b47079.tar.bz2 |
Working on time frame for displaying cleared transactions. Not yet working.
Diffstat (limited to 'noncore/apps/qashmoney/transaction.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/apps/qashmoney/transaction.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp index af7d18f..5ecc7ed 100755 --- a/noncore/apps/qashmoney/transaction.cpp +++ b/noncore/apps/qashmoney/transaction.cpp | |||
@@ -1,34 +1,35 @@ | |||
1 | // RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN | 1 | // RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN |
2 | // FUTURE VERSIONS OF QASHMONEY | 2 | // FUTURE VERSIONS OF QASHMONEY |
3 | 3 | ||
4 | // RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION | 4 | // RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION |
5 | 5 | ||
6 | #include "transaction.h" | 6 | #include "transaction.h" |
7 | #include "account.h" | 7 | #include "account.h" |
8 | #include "transactiondisplay.h" | 8 | #include "transactiondisplay.h" |
9 | 9 | ||
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <iostream.h> | ||
11 | 12 | ||
12 | extern Account *account; | 13 | extern Account *account; |
13 | extern Preferences *preferences; | 14 | extern Preferences *preferences; |
14 | 15 | ||
15 | Transaction::Transaction () | 16 | Transaction::Transaction () |
16 | { | 17 | { |
17 | tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); | 18 | tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); |
18 | } | 19 | } |
19 | 20 | ||
20 | Transaction::~Transaction () | 21 | Transaction::~Transaction () |
21 | { | 22 | { |
22 | sqlite_close ( tdb ); | 23 | sqlite_close ( tdb ); |
23 | } | 24 | } |
24 | 25 | ||
25 | void Transaction::addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid ) | 26 | void Transaction::addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid ) |
26 | { | 27 | { |
27 | sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0, | 28 | sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0, |
28 | 0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description ); | 29 | 0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description ); |
29 | } | 30 | } |
30 | 31 | ||
31 | void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid ) | 32 | void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid ) |
32 | { | 33 | { |
33 | sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f, | 34 | sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f, |
34 | cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year, | 35 | cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year, |
@@ -133,84 +134,79 @@ int Transaction::getLineItemID ( int id ) | |||
133 | int Transaction::getDay ( int id ) | 134 | int Transaction::getDay ( int id ) |
134 | { | 135 | { |
135 | char **results; | 136 | char **results; |
136 | sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | 137 | sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); |
137 | QString daystring = results [ 1 ]; | 138 | QString daystring = results [ 1 ]; |
138 | return daystring.toInt(); | 139 | return daystring.toInt(); |
139 | } | 140 | } |
140 | 141 | ||
141 | int Transaction::getMonth ( int id ) | 142 | int Transaction::getMonth ( int id ) |
142 | { | 143 | { |
143 | char **results; | 144 | char **results; |
144 | sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | 145 | sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); |
145 | QString monthstring = results [ 1 ]; | 146 | QString monthstring = results [ 1 ]; |
146 | return monthstring.toInt(); | 147 | return monthstring.toInt(); |
147 | } | 148 | } |
148 | 149 | ||
149 | int Transaction::getYear ( int id ) | 150 | int Transaction::getYear ( int id ) |
150 | { | 151 | { |
151 | char **results; | 152 | char **results; |
152 | sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | 153 | sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); |
153 | QString yearstring = results [ 1 ]; | 154 | QString yearstring = results [ 1 ]; |
154 | return yearstring.toInt(); | 155 | return yearstring.toInt(); |
155 | } | 156 | } |
156 | 157 | ||
157 | void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit ) | 158 | void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate ) |
158 | { | 159 | { |
159 | int showcleared = preferences->getPreference ( 3 ); | 160 | int showcleared = preferences->getPreference ( 3 ); |
161 | int year = ( displaydate.year() ) - 1; | ||
160 | 162 | ||
161 | // select the transactions to display | 163 | // select the transactions to display |
162 | // two different statements are used based on | 164 | // two different statements are used based on |
163 | // whether we are showing cleared transactions | 165 | // whether we are showing cleared transactions |
164 | char **results; | 166 | char **results; |
165 | int rows, columns; | 167 | int rows, columns; |
166 | if ( showcleared == 0 ) | 168 | if ( showcleared == 0 ) |
167 | { | 169 | { |
168 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) | 170 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) |
169 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); | 171 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and year >= %i parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, year, id, limit ); |
170 | else | 172 | else |
171 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); | 173 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 year >= %i accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, year, id, limit ); |
172 | } | 174 | } |
173 | else | 175 | else |
174 | { | 176 | { |
175 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) | 177 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) |
176 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); | 178 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where year >= %i and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, year, id, limit ); |
177 | else | 179 | else |
178 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); | 180 | sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); |
179 | } | 181 | } |
180 | 182 | ||
181 | // iterate through the result list and display each item | 183 | // iterate through the result list and display each item |
182 | int counter = 7; | 184 | int counter = 7; |
183 | while ( counter < ( ( rows + 1 ) * columns ) ) | 185 | while ( counter < ( ( rows + 1 ) * columns ) ) |
184 | { | 186 | { |
185 | // construct the date | 187 | QDate displaydate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); |
186 | //QString daystring = results [ counter ]; | 188 | QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); |
187 | //int day = results [ counter ].toInt (); | ||
188 | //QString monthstring = results [ counter + 1 ]; | ||
189 | //int month = results [ counter + 1 ].toInt (); | ||
190 | //QString yearstring = results [ counter + 2 ]; | ||
191 | //int year = results [ counter + 2 ].toInt (); | ||
192 | QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); | ||
193 | 189 | ||
194 | // construct transaction name, amount, id | 190 | // construct transaction name, amount, id |
195 | QString payee = results [ counter + 3 ]; | 191 | QString payee = results [ counter + 3 ]; |
196 | QString amount = results [ counter + 4 ]; | 192 | QString amount = results [ counter + 4 ]; |
197 | QString transferid = results [ counter + 5 ]; | 193 | QString transferid = results [ counter + 5 ]; |
198 | 194 | ||
199 | //determine the account name of the child accounts that we're displaying | 195 | //determine the account name of the child accounts that we're displaying |
200 | QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) ); | 196 | QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) ); |
201 | 197 | ||
202 | // fill in values | 198 | // fill in values |
203 | if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account | 199 | if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account |
204 | { | 200 | { |
205 | if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) | 201 | if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) |
206 | ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid); | 202 | ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid); |
207 | else | 203 | else |
208 | QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid ); | 204 | QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid ); |
209 | } | 205 | } |
210 | else | 206 | else |
211 | { | 207 | { |
212 | if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) | 208 | if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) |
213 | ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname ); | 209 | ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname ); |
214 | else | 210 | else |
215 | QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname ); | 211 | QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname ); |
216 | } | 212 | } |