Diffstat (limited to 'noncore/apps/qashmoney/transactiondisplay.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/apps/qashmoney/transactiondisplay.cpp | 625 |
1 files changed, 0 insertions, 625 deletions
diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp deleted file mode 100755 index 0b94d62..0000000 --- a/noncore/apps/qashmoney/transactiondisplay.cpp +++ b/dev/null | |||
@@ -1,625 +0,0 @@ | |||
1 | #include "transactiondisplay.h" | ||
2 | #include "newtransaction.h" | ||
3 | #include "account.h" | ||
4 | #include "budget.h" | ||
5 | #include "memory.h" | ||
6 | #include "transfer.h" | ||
7 | #include "calculator.h" | ||
8 | #include "datepicker.h" | ||
9 | |||
10 | #include <qmessagebox.h> | ||
11 | #include <qheader.h> | ||
12 | #include <qmultilineedit.h> | ||
13 | |||
14 | extern Transaction *transaction; | ||
15 | extern Budget *budget; | ||
16 | extern Account *account; | ||
17 | extern Preferences *preferences; | ||
18 | extern Memory *memory; | ||
19 | extern Transfer *transfer; | ||
20 | |||
21 | TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) | ||
22 | { | ||
23 | // set transactiondisplay variables; | ||
24 | accountid = 0; | ||
25 | children = TRUE; | ||
26 | |||
27 | firstline = new QHBox ( this ); | ||
28 | firstline->setSpacing ( 2 ); | ||
29 | |||
30 | newtransaction = new QPushButton ( firstline ); | ||
31 | newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); | ||
32 | connect ( newtransaction, SIGNAL ( released() ), this, SLOT ( addTransaction() ) ); | ||
33 | |||
34 | edittransaction = new QPushButton ( firstline ); | ||
35 | edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); | ||
36 | connect ( edittransaction, SIGNAL ( released() ), this, SLOT ( checkListViewEdit() ) ); | ||
37 | |||
38 | deletetransaction = new QPushButton ( firstline ); | ||
39 | deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); | ||
40 | connect ( deletetransaction, SIGNAL ( released() ), this, SLOT ( checkListViewDelete() ) ); | ||
41 | |||
42 | toggletransaction = new QPushButton ( firstline ); | ||
43 | toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); | ||
44 | connect ( toggletransaction, SIGNAL ( released() ), this, SLOT ( checkListViewToggle() ) ); | ||
45 | |||
46 | viewtransactionnotes = new QPushButton ( firstline ); | ||
47 | viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); | ||
48 | connect ( viewtransactionnotes, SIGNAL ( released() ), this, SLOT ( showTransactionNotes() ) ); | ||
49 | |||
50 | secondline = new QHBox ( this ); | ||
51 | secondline->setSpacing ( 5 ); | ||
52 | |||
53 | name = new QLabel ( secondline ); | ||
54 | balance = new QLabel ( secondline ); | ||
55 | |||
56 | QLabel *limit = new QLabel ( "Limit", secondline ); | ||
57 | limitbox = new QLineEdit ( secondline ); | ||
58 | limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); | ||
59 | connect ( limitbox, SIGNAL ( textChanged(const QString&) ), this, SLOT ( limitDisplay(const QString&) ) ); | ||
60 | |||
61 | listview = new QListView ( this ); | ||
62 | listview->setAllColumnsShowFocus ( TRUE ); | ||
63 | listview->setShowSortIndicator ( TRUE ); | ||
64 | listview->header()->setTracking ( FALSE ); | ||
65 | connect ( listview->header(), SIGNAL ( sizeChange(int,int,int) ), this, SLOT ( saveColumnSize(int,int,int) ) ); | ||
66 | connect ( listview->header(), SIGNAL ( clicked(int) ), this, SLOT ( saveSortingPreference(int) ) ); | ||
67 | |||
68 | layout = new QVBoxLayout ( this, 2, 2 ); | ||
69 | layout->addWidget ( firstline ); | ||
70 | layout->addWidget ( secondline ); | ||
71 | layout->addWidget ( listview ); | ||
72 | } | ||
73 | |||
74 | void TransactionDisplay::addTransaction () | ||
75 | { | ||
76 | // create local variables | ||
77 | int cleared = -1; | ||
78 | |||
79 | // create new transaction window | ||
80 | NewTransaction *newtransaction = new NewTransaction ( this ); | ||
81 | int width = this->size().width(); | ||
82 | newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); | ||
83 | newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); | ||
84 | newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); | ||
85 | newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
86 | newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
87 | newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); | ||
88 | |||
89 | // enter today's date in the date box as defaul | ||
90 | QDate today = QDate::currentDate (); | ||
91 | int defaultday = today.day(); | ||
92 | int defaultmonth = today.month(); | ||
93 | int defaultyear = today.year(); | ||
94 | newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); | ||
95 | |||
96 | // add memory items to the transactionname combobox | ||
97 | memory->displayMemoryItems ( newtransaction->transactionname ); | ||
98 | newtransaction->transactionname->insertItem ( "", 0 ); | ||
99 | |||
100 | if ( newtransaction->exec () == QDialog::Accepted ) | ||
101 | { | ||
102 | if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction | ||
103 | cleared = 1; | ||
104 | else | ||
105 | cleared = 0; | ||
106 | |||
107 | float amount = newtransaction->transactionamount->text().toFloat(); | ||
108 | if ( newtransaction->depositbox->isChecked() == FALSE ) | ||
109 | amount = amount * -1; | ||
110 | |||
111 | // add the transaction name to the memory items | ||
112 | memory->addMemoryItem ( newtransaction->transactionname->currentText() ); | ||
113 | |||
114 | // add the transaction | ||
115 | if ( newtransaction->getDateEdited () == TRUE ) | ||
116 | transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), | ||
117 | newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), | ||
118 | newtransaction->getCurrentLineItem() ); | ||
119 | else | ||
120 | transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), | ||
121 | newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); | ||
122 | |||
123 | // redisplay transactions | ||
124 | listview->clear(); | ||
125 | QString displaytext = "%"; | ||
126 | displaytext.prepend ( limitbox->text() ); | ||
127 | setTransactionDisplayDate (); | ||
128 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
129 | transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); | ||
130 | |||
131 | // redisplay transfers | ||
132 | if ( transfer->getNumberOfTransfers() > 0 ) | ||
133 | transfer->displayTransfers ( listview, accountid, children, displaydate ); | ||
134 | |||
135 | // add the transaction amount to the account it's associated with | ||
136 | // and update its parent account balance if necessary | ||
137 | account->updateAccountBalance ( accountid ); | ||
138 | if ( account->getParentAccountID ( accountid ) != -1 ) | ||
139 | account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); | ||
140 | |||
141 | // format then reset the account balance | ||
142 | redisplayAccountBalance (); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | void TransactionDisplay::checkListViewEdit () | ||
147 | { | ||
148 | if ( listview->selectedItem() == 0 ) | ||
149 | QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); | ||
150 | else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) | ||
151 | editTransfer (); | ||
152 | else | ||
153 | editTransaction(); | ||
154 | } | ||
155 | |||
156 | void TransactionDisplay::showCalculator () | ||
157 | { | ||
158 | Calculator *calculator = new Calculator ( this ); | ||
159 | if ( calculator->exec () == QDialog::Accepted ) | ||
160 | amount->setText ( calculator->display->text() ); | ||
161 | } | ||
162 | |||
163 | void TransactionDisplay::showCalendar () | ||
164 | { | ||
165 | QDate newDate = QDate::currentDate (); | ||
166 | DatePicker *dp = new DatePicker ( newDate ); | ||
167 | if ( dp->exec () == QDialog::Accepted ) | ||
168 | { | ||
169 | year = dp->getYear(); | ||
170 | month = dp->getMonth(); | ||
171 | day = dp->getDay(); | ||
172 | date->setText ( preferences->getDate ( year, month, day ) ); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | void TransactionDisplay::editTransfer () | ||
177 | { | ||
178 | transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); | ||
179 | fromaccount = transfer->getFromAccountID ( transferid ); | ||
180 | toaccount = transfer->getToAccountID ( transferid ); | ||
181 | year = transfer->getYear ( transferid ); | ||
182 | month = transfer->getMonth ( transferid ); | ||
183 | day = transfer->getDay ( transferid ); | ||
184 | |||
185 | QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); | ||
186 | editransfer->setCaption ( "Transfer" ); | ||
187 | |||
188 | QStringList accountnames = account->getAccountNames(); | ||
189 | QStringList accountids = account->getAccountIDs(); | ||
190 | |||
191 | QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); | ||
192 | QFont f = this->font(); | ||
193 | f.setWeight ( QFont::Bold ); | ||
194 | fromaccountlabel->setFont ( f ); | ||
195 | |||
196 | QComboBox *fromaccountbox = new QComboBox ( editransfer ); | ||
197 | fromaccountbox->insertStringList ( accountnames ); | ||
198 | fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); | ||
199 | |||
200 | QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); | ||
201 | toaccountlabel->setFont ( f ); | ||
202 | |||
203 | QComboBox *toaccountbox = new QComboBox ( editransfer ); | ||
204 | toaccountbox->insertStringList ( accountnames ); | ||
205 | toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); | ||
206 | |||
207 | QLabel *datelabel = new QLabel ( "Date", editransfer ); | ||
208 | QHBox *datebox = new QHBox ( editransfer ); | ||
209 | datebox->setSpacing ( 2 ); | ||
210 | date = new QLineEdit ( datebox ); | ||
211 | date->setAlignment ( Qt::AlignRight ); | ||
212 | date->setDisabled ( TRUE ); | ||
213 | date->setText ( preferences->getDate ( year, month, day ) ); | ||
214 | QPushButton *datebutton = new QPushButton ( datebox ); | ||
215 | datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); | ||
216 | connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) ); | ||
217 | |||
218 | QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); | ||
219 | |||
220 | QHBox *amountbox = new QHBox ( editransfer ); | ||
221 | amountbox->setSpacing ( 2 ); | ||
222 | amount = new QLineEdit ( amountbox ); | ||
223 | amount->setAlignment ( Qt::AlignRight ); | ||
224 | amount->setText ( transfer->getAmount ( transferid ) ); | ||
225 | QPushButton *calculatorbutton = new QPushButton( amountbox ); | ||
226 | calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); | ||
227 | connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); | ||
228 | |||
229 | QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); | ||
230 | |||
231 | QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); | ||
232 | layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); | ||
233 | layout->addWidget ( fromaccountbox, Qt::AlignLeft ); | ||
234 | layout->addWidget ( toaccountlabel, Qt::AlignLeft ); | ||
235 | layout->addWidget ( toaccountbox, Qt::AlignLeft ); | ||
236 | layout->addSpacing ( 5 ); | ||
237 | layout->addWidget ( datelabel, Qt::AlignLeft ); | ||
238 | layout->addWidget ( datebox, Qt::AlignLeft ); | ||
239 | layout->addWidget ( amounttlabel, Qt::AlignLeft ); | ||
240 | layout->addWidget ( amountbox, Qt::AlignLeft ); | ||
241 | layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); | ||
242 | |||
243 | if ( editransfer->exec() == QDialog::Accepted ) | ||
244 | { | ||
245 | //get fromaccount | ||
246 | fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); | ||
247 | |||
248 | //get to account | ||
249 | toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); | ||
250 | |||
251 | //set cleared flag | ||
252 | int cleared = 0; | ||
253 | if ( clearedcheckbox->isChecked() == TRUE ) | ||
254 | cleared = 1; | ||
255 | |||
256 | //update transfer | ||
257 | transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), | ||
258 | day, month, year, amount->text().toFloat(), cleared, transferid ); | ||
259 | |||
260 | account->updateAccountBalance ( fromaccount ); | ||
261 | if ( account->getParentAccountID ( fromaccount ) != -1 ) | ||
262 | account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); | ||
263 | |||
264 | updateAndDisplay ( toaccount ); | ||
265 | } | ||
266 | } | ||
267 | |||
268 | void TransactionDisplay::editTransaction () | ||
269 | { | ||
270 | int cleared; | ||
271 | |||
272 | // set the transaction id and budgetid | ||
273 | int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); | ||
274 | int budgetid = transaction->getBudgetID ( transactionid ); | ||
275 | int lineitemid = transaction->getLineItemID ( transactionid ); | ||
276 | |||
277 | // create edit transaction window | ||
278 | NewTransaction *newtransaction = new NewTransaction ( this ); | ||
279 | int width = this->width(); | ||
280 | newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); | ||
281 | newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); | ||
282 | newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); | ||
283 | newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
284 | newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
285 | newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); | ||
286 | |||
287 | // enter the date in the date box | ||
288 | newtransaction->year = transaction->getYear ( transactionid ); | ||
289 | newtransaction->month = transaction->getMonth ( transactionid ); | ||
290 | newtransaction->day = transaction->getDay ( transactionid ); | ||
291 | newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); | ||
292 | |||
293 | // set the description | ||
294 | newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); | ||
295 | |||
296 | // add memory items to the transactionname combobox | ||
297 | memory->displayMemoryItems ( newtransaction->transactionname ); | ||
298 | |||
299 | // add correct transaction name | ||
300 | newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); | ||
301 | |||
302 | // add transaction number | ||
303 | newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); | ||
304 | |||
305 | // add transaction amount | ||
306 | newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); | ||
307 | |||
308 | // check for and set the correct budget | ||
309 | if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item | ||
310 | { | ||
311 | newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); | ||
312 | if ( lineitemid >= 1 ) | ||
313 | { | ||
314 | newtransaction->setLineItems (); | ||
315 | newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | newtransaction->lineitemlabel->setEnabled ( FALSE ); | ||
320 | newtransaction->lineitembox->setEnabled ( FALSE ); | ||
321 | } | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | newtransaction->lineitemlabel->setEnabled ( FALSE ); | ||
326 | newtransaction->lineitembox->setEnabled ( FALSE ); | ||
327 | } | ||
328 | |||
329 | // check cleared checkbox if necessary | ||
330 | if ( transaction->getCleared ( transactionid ) == 1 ) | ||
331 | newtransaction->clearedcheckbox->setChecked ( TRUE ); | ||
332 | |||
333 | // check deposit box if necessary | ||
334 | if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) | ||
335 | newtransaction->depositbox->setChecked ( TRUE ); | ||
336 | |||
337 | if ( newtransaction->exec () == QDialog::Accepted ) | ||
338 | { | ||
339 | if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) | ||
340 | cleared = 1; | ||
341 | else | ||
342 | cleared = 0; | ||
343 | |||
344 | float amount = newtransaction->transactionamount->text().toFloat(); | ||
345 | if ( newtransaction->depositbox->isChecked() == FALSE ) | ||
346 | amount = amount * -1; | ||
347 | |||
348 | // add the transaction name to the memory items | ||
349 | memory->addMemoryItem ( newtransaction->transactionname->currentText() ); | ||
350 | |||
351 | // update the transaction | ||
352 | transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), | ||
353 | newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), | ||
354 | amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); | ||
355 | |||
356 | updateAndDisplay ( transaction->getAccountID ( transactionid ) ); | ||
357 | } | ||
358 | } | ||
359 | |||
360 | void TransactionDisplay::updateAndDisplay ( int id ) | ||
361 | { | ||
362 | // redisplay transactions | ||
363 | listview->clear(); | ||
364 | QString displaytext = "%"; | ||
365 | displaytext.prepend ( limitbox->text() ); | ||
366 | setTransactionDisplayDate (); | ||
367 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
368 | transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); | ||
369 | |||
370 | // redisplay transfers | ||
371 | if ( transfer->getNumberOfTransfers() > 0 ) | ||
372 | transfer->displayTransfers ( listview, accountid, children, displaydate ); | ||
373 | |||
374 | // add the transaction amount to the account it's associated with | ||
375 | // and update its parent account balance if necessary | ||
376 | account->updateAccountBalance ( id ); | ||
377 | if ( account->getParentAccountID ( id ) != -1 ) | ||
378 | account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); | ||
379 | |||
380 | // format then reset the account balance | ||
381 | redisplayAccountBalance (); | ||
382 | } | ||
383 | |||
384 | void TransactionDisplay::checkListViewDelete () | ||
385 | { | ||
386 | if ( listview->selectedItem() == 0 ) | ||
387 | QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); | ||
388 | else | ||
389 | deleteTransaction (); | ||
390 | } | ||
391 | |||
392 | void TransactionDisplay::deleteTransaction () | ||
393 | { | ||
394 | int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); | ||
395 | |||
396 | if ( transactionid > 0 ) // takes care of deleting transactions | ||
397 | { | ||
398 | // check if we are viewing child transactions through a parent | ||
399 | // in that case we will have to update balances for the parent | ||
400 | // which is represented by accountid and the child account | ||
401 | // which will be represented by childaccountid | ||
402 | int childaccountid = -1; | ||
403 | if ( listview->columns() == 5 ) | ||
404 | childaccountid = transaction->getAccountID ( transactionid ); | ||
405 | |||
406 | transaction->deleteTransaction ( transactionid ); | ||
407 | |||
408 | listview->clear(); | ||
409 | QString displaytext = "%"; | ||
410 | displaytext.prepend ( limitbox->text() ); | ||
411 | setTransactionDisplayDate (); | ||
412 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
413 | transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); | ||
414 | |||
415 | if ( transfer->getNumberOfTransfers() > 0 ) | ||
416 | transfer->displayTransfers ( listview, accountid, children, displaydate ); | ||
417 | |||
418 | // if we are viewing different child accounts through the parent account | ||
419 | // ie if there are five columns and the parentid is -1 | ||
420 | // update the accountid ( which is the parent ) and update the child account | ||
421 | // balance. Get its accountid from the transactionid | ||
422 | account->updateAccountBalance ( accountid ); // will update either a parent or child | ||
423 | if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one | ||
424 | account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); | ||
425 | if ( childaccountid != -1 ) // we've set childaccountid | ||
426 | account->updateAccountBalance ( childaccountid ); | ||
427 | |||
428 | // format then reset the account balance | ||
429 | redisplayAccountBalance (); | ||
430 | } | ||
431 | else // takes care of deleting transfers | ||
432 | { | ||
433 | // get the accountids before we delete the transfer | ||
434 | int fromaccountid = transfer->getFromAccountID ( transactionid ); | ||
435 | int toaccountid = transfer->getToAccountID ( transactionid ); | ||
436 | |||
437 | // delete the transfer and redisplay transactions | ||
438 | transfer->deleteTransfer ( transactionid ); | ||
439 | |||
440 | listview->clear(); | ||
441 | QString displaytext = "%"; | ||
442 | displaytext.prepend ( limitbox->text() ); | ||
443 | setTransactionDisplayDate (); | ||
444 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
445 | transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); | ||
446 | |||
447 | if ( transfer->getNumberOfTransfers() > 0 ) | ||
448 | transfer->displayTransfers ( listview, accountid, children, displaydate ); | ||
449 | |||
450 | // for the from account | ||
451 | account->updateAccountBalance ( fromaccountid ); | ||
452 | if ( account->getParentAccountID ( fromaccountid ) != -1 ) | ||
453 | account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) ); | ||
454 | |||
455 | // for the to account | ||
456 | account->updateAccountBalance ( toaccountid ); | ||
457 | if ( account->getParentAccountID ( toaccountid ) != -1 ) | ||
458 | account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) ); | ||
459 | |||
460 | // format then reset the account balance | ||
461 | redisplayAccountBalance (); | ||
462 | } | ||
463 | } | ||
464 | |||
465 | void TransactionDisplay::checkListViewToggle () | ||
466 | { | ||
467 | if ( listview->selectedItem() == 0 ) | ||
468 | QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset."); | ||
469 | else | ||
470 | toggleTransaction (); | ||
471 | } | ||
472 | |||
473 | void TransactionDisplay::toggleTransaction () | ||
474 | { | ||
475 | //get the transaction of the selected transaction to determine if its a transaction or transfer | ||
476 | int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); | ||
477 | |||
478 | if ( transactionid > 0 ) // if this is a transaction | ||
479 | { | ||
480 | if ( transaction->getCleared ( transactionid ) == 0 ) | ||
481 | transaction->setCleared ( transactionid, 1 ); | ||
482 | else | ||
483 | transaction->setCleared ( transactionid, 0 ); | ||
484 | } | ||
485 | else | ||
486 | { | ||
487 | if ( transfer->getCleared ( transactionid ) == 0 ) | ||
488 | transfer->setCleared ( transactionid, 1 ); | ||
489 | else | ||
490 | transfer->setCleared ( transactionid, 0 ); | ||
491 | } | ||
492 | |||
493 | listview->clear(); | ||
494 | QString displaytext = "%"; | ||
495 | displaytext.prepend ( limitbox->text() ); | ||
496 | setTransactionDisplayDate (); | ||
497 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
498 | transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); | ||
499 | |||
500 | if ( transfer->getNumberOfTransfers() != 0 ) | ||
501 | transfer->displayTransfers ( listview, accountid, children, displaydate ); | ||
502 | } | ||
503 | |||
504 | void TransactionDisplay::redisplayAccountBalance () | ||
505 | { | ||
506 | QString accountbalance = account->getAccountBalance ( accountid ); | ||
507 | balance->setText ( accountbalance ); | ||
508 | } | ||
509 | |||
510 | void TransactionDisplay::setChildren ( bool c ) | ||
511 | { | ||
512 | children = c; | ||
513 | } | ||
514 | |||
515 | void TransactionDisplay::setAccountID ( int id ) | ||
516 | { | ||
517 | accountid = id; | ||
518 | } | ||
519 | |||
520 | ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent ) | ||
521 | { | ||
522 | } | ||
523 | |||
524 | ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) | ||
525 | : QListViewItem ( parent, label1, label2, label3, label4 ) | ||
526 | { | ||
527 | } | ||
528 | |||
529 | ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) | ||
530 | : QListViewItem ( parent, label1, label2, label3, label4, label5 ) | ||
531 | { | ||
532 | } | ||
533 | |||
534 | void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) | ||
535 | { | ||
536 | QColorGroup _cg ( cg ); | ||
537 | _cg.setColor ( QColorGroup::Text, Qt::red ); | ||
538 | QListViewItem::paintCell ( p, _cg, column, width, alignment ); | ||
539 | } | ||
540 | |||
541 | void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize ) | ||
542 | { | ||
543 | if ( listview->columns() == 4 ) | ||
544 | preferences->changeColumnPreference ( column + 3, newsize ); | ||
545 | else if ( listview->columns() == 5 && column != 4 ) | ||
546 | preferences->changeColumnPreference ( column + 6, newsize ); | ||
547 | else | ||
548 | preferences->changeColumnPreference ( 9, newsize ); | ||
549 | } | ||
550 | |||
551 | void TransactionDisplay::saveSortingPreference ( int column ) | ||
552 | { | ||
553 | preferences->changeSortingPreference ( 2, column ); | ||
554 | } | ||
555 | |||
556 | void TransactionDisplay::limitDisplay ( const QString &text ) | ||
557 | { | ||
558 | listview->clear (); | ||
559 | QString displaytext = "%"; | ||
560 | displaytext.prepend ( text ); | ||
561 | setTransactionDisplayDate (); | ||
562 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
563 | transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); | ||
564 | |||
565 | if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) | ||
566 | transfer->displayTransfers ( listview, accountid, children, displaydate ); | ||
567 | } | ||
568 | |||
569 | int TransactionDisplay::getIDColumn () | ||
570 | { | ||
571 | int counter; | ||
572 | int columns = listview->columns(); | ||
573 | for ( counter = 0; counter <= columns; counter++ ) | ||
574 | if ( listview->header()->label ( counter ).length() == 0 ) | ||
575 | return counter; | ||
576 | } | ||
577 | |||
578 | void TransactionDisplay::showTransactionNotes () | ||
579 | { | ||
580 | if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) | ||
581 | QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes."); | ||
582 | else | ||
583 | { | ||
584 | int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt (); | ||
585 | QDialog *description = new QDialog ( this, "description", TRUE ); | ||
586 | description->setCaption ( "Notes" ); | ||
587 | QMultiLineEdit *notes = new QMultiLineEdit ( description ); | ||
588 | notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); | ||
589 | notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); | ||
590 | notes->setWordWrap ( QMultiLineEdit::WidgetWidth ); | ||
591 | notes->setEnabled ( FALSE ); | ||
592 | notes->setText ( transaction->getTransactionDescription ( transactionid ) ); | ||
593 | description->show(); | ||
594 | } | ||
595 | } | ||
596 | |||
597 | void TransactionDisplay::setTransactionDisplayDate () | ||
598 | { | ||
599 | // determine how many days of transactions to show | ||
600 | int limittype = preferences->getPreference ( 7 ); | ||
601 | if ( limittype != 5 ) // set today's date if we are not showing all transactions | ||
602 | { | ||
603 | QDate today = QDate::currentDate (); | ||
604 | switch ( limittype ) // if we are not showing all transactions | ||
605 | { | ||
606 | case 0: // viewing two weeks | ||
607 | displaydate = today.addDays ( -14 ); | ||
608 | break; | ||
609 | case 1: // viewing one month | ||
610 | displaydate = today.addDays ( -30 ); | ||
611 | break; | ||
612 | case 2: // three months | ||
613 | displaydate = today.addDays ( -90 ); | ||
614 | break; | ||
615 | case 3: // six months | ||
616 | displaydate = today.addDays ( -180 ); | ||
617 | break; | ||
618 | case 4: // one year | ||
619 | displaydate = today.addDays ( -365 ); | ||
620 | break; | ||
621 | } | ||
622 | } | ||
623 | else | ||
624 | displaydate = QDate ( 1900, 1, 1 ); | ||
625 | } | ||