Diffstat (limited to 'noncore/apps/qashmoney/transaction.cpp') (more/less context) (show whitespace changes)
-rwxr-xr-x | noncore/apps/qashmoney/transaction.cpp | 106 |
1 files changed, 91 insertions, 15 deletions
diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp index 5ecc7ed..a3bd9e7 100755 --- a/noncore/apps/qashmoney/transaction.cpp +++ b/noncore/apps/qashmoney/transaction.cpp | |||
@@ -155,36 +155,112 @@ int Transaction::getYear ( int id ) | |||
155 | return yearstring.toInt(); | 155 | return yearstring.toInt(); |
156 | } | 156 | } |
157 | 157 | ||
158 | void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate ) | 158 | char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id ) |
159 | { | 159 | { |
160 | // initialize variables | ||
161 | char **results; | ||
160 | int showcleared = preferences->getPreference ( 3 ); | 162 | int showcleared = preferences->getPreference ( 3 ); |
161 | int year = ( displaydate.year() ) - 1; | 163 | QDate today = QDate::currentDate(); |
164 | int fromyear = fromdate.year(); | ||
165 | int toyear = today.year(); | ||
166 | int frommonth = fromdate.month(); | ||
167 | int tomonth = today.month(); | ||
168 | int fromday = fromdate.day(); | ||
169 | |||
170 | // construct the first part of the string | ||
171 | QString query = "select day, month, year, payee, amount, transid, accountid from transactions where"; | ||
172 | |||
173 | if ( frommonth == tomonth && fromyear == toyear ) // our dates cross neither a month nor a year | ||
174 | { | ||
175 | query.append ( " year = " ); | ||
176 | query.append ( QString::number ( toyear ) ); | ||
177 | query.append ( " and month = " ); | ||
178 | query.append ( QString::number ( tomonth ) ); | ||
179 | query.append ( " and day >= " ); | ||
180 | query.append ( QString::number ( fromday ) ); | ||
181 | query.append ( " and" ); | ||
182 | } | ||
183 | else if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year | ||
184 | { | ||
185 | query.append ( " year = " ); | ||
186 | query.append ( QString::number ( toyear ) ); | ||
187 | query.append ( " and ( ( month <= " ); | ||
188 | query.append ( QString::number ( tomonth ) ); | ||
189 | query.append ( " and month > " ); | ||
190 | query.append ( QString::number ( frommonth ) ); | ||
191 | query.append ( " ) or ( month = " ); | ||
192 | query.append ( QString::number ( frommonth ) ); | ||
193 | query.append ( " and day >= " ); | ||
194 | query.append ( QString::number ( fromday ) ); | ||
195 | query.append ( " ) ) and " ); | ||
196 | } | ||
197 | else if ( fromyear != toyear && fromyear != 1900 ) // here we are showing transactions from an entire year | ||
198 | { | ||
199 | // divide this taks into two parts - get the transactions from the prior and then the current year | ||
200 | // current year part | ||
201 | int tmpfrommonth = 1; // set temporary from months and days to Jan. 1 | ||
202 | int tmpfromday = 1; | ||
203 | query.append ( " ( year >= " ); | ||
204 | query.append ( QString::number ( fromyear ) ); | ||
205 | query.append ( " and ( month <= " ); | ||
206 | query.append ( QString::number ( tomonth ) ); | ||
207 | query.append ( " and month > " ); | ||
208 | query.append ( QString::number ( tmpfrommonth ) ); | ||
209 | query.append ( " ) or ( month = " ); | ||
210 | query.append ( QString::number ( tmpfrommonth ) ); | ||
211 | query.append ( " and day >= " ); | ||
212 | query.append ( QString::number ( tmpfromday ) ); | ||
213 | query.append ( " ) ) or" ); | ||
214 | |||
215 | // prior year part | ||
216 | int tmptomonth = 12; | ||
217 | query.append ( " ( year = " ); | ||
218 | query.append ( QString::number ( fromyear ) ); | ||
219 | query.append ( " and ( ( month <= " ); | ||
220 | query.append ( QString::number ( tmptomonth ) ); | ||
221 | query.append ( " and month > " ); | ||
222 | query.append ( QString::number ( frommonth ) ); | ||
223 | query.append ( " ) or ( month = " ); | ||
224 | query.append ( QString::number ( frommonth ) ); | ||
225 | query.append ( " and day >= " ); | ||
226 | query.append ( QString::number ( fromday ) ); | ||
227 | query.append ( " ) ) ) and " ); | ||
228 | } | ||
162 | 229 | ||
163 | // select the transactions to display | ||
164 | // two different statements are used based on | ||
165 | // whether we are showing cleared transactions | ||
166 | char **results; | ||
167 | int rows, columns; | ||
168 | if ( showcleared == 0 ) | ||
169 | { | ||
170 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) | 230 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) |
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 ); | 231 | query.append ( " parentid = %i and payee like '%q';" ); |
172 | else | 232 | else |
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 ); | 233 | query.append ( " accountid = %i and payee like '%q';" ); |
234 | |||
235 | sqlite_get_table_printf ( tdb, query, &results, &rows, &columns, NULL, id, limit ); | ||
236 | return results; | ||
174 | } | 237 | } |
175 | else | 238 | |
239 | char ** Transaction::selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id ) | ||
176 | { | 240 | { |
241 | char **results; | ||
177 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) | 242 | if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) |
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 ); | 243 | 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 ); |
179 | else | 244 | else |
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 ); | 245 | 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 ); |
246 | return results; | ||
181 | } | 247 | } |
182 | 248 | ||
249 | void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate ) | ||
250 | { | ||
251 | int showcleared = preferences->getPreference ( 3 ); | ||
252 | |||
253 | char **results; | ||
254 | if ( showcleared == 0 ) | ||
255 | results = selectNonClearedTransactions ( displaydate, children, limit, id ); | ||
256 | else | ||
257 | results = selectAllTransactions ( displaydate, children, limit, id ); | ||
258 | |||
183 | // iterate through the result list and display each item | 259 | // iterate through the result list and display each item |
184 | int counter = 7; | 260 | int counter = 7; |
185 | while ( counter < ( ( rows + 1 ) * columns ) ) | 261 | while ( counter < ( ( rows + 1 ) * columns ) ) |
186 | { | 262 | { |
187 | QDate displaydate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); | 263 | //QDate testdate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); |
188 | QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); | 264 | QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); |
189 | 265 | ||
190 | // construct transaction name, amount, id | 266 | // construct transaction name, amount, id |