author | allenforsythe <allenforsythe> | 2003-05-13 21:14:56 (UTC) |
---|---|---|
committer | allenforsythe <allenforsythe> | 2003-05-13 21:14:56 (UTC) |
commit | f08e51ae62bf814b4cbf8873afd0e44b167cb9b4 (patch) (unidiff) | |
tree | bab48138189f471aa8f18dd53dd57b4d0bfd156b | |
parent | f31e2ecd95aba951dc77d98f02b45cb1297046ac (diff) | |
download | opie-f08e51ae62bf814b4cbf8873afd0e44b167cb9b4.zip opie-f08e51ae62bf814b4cbf8873afd0e44b167cb9b4.tar.gz opie-f08e51ae62bf814b4cbf8873afd0e44b167cb9b4.tar.bz2 |
Initial revision
-rwxr-xr-x | noncore/apps/qashmoney/CHANGES | 24 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/account.h | 100 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/accountdisplay.cpp | 432 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/budget.cpp | 221 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/budget.h | 45 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/memory.cpp | 62 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/memory.h | 45 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/preferences.h | 50 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/qashmoney.cpp | 356 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transaction.cpp | 274 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transaction.h | 69 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transactiondisplay.h | 79 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transfer.cpp | 253 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transfer.h | 51 |
14 files changed, 2061 insertions, 0 deletions
diff --git a/noncore/apps/qashmoney/CHANGES b/noncore/apps/qashmoney/CHANGES new file mode 100755 index 0000000..f17035b --- a/dev/null +++ b/noncore/apps/qashmoney/CHANGES | |||
@@ -0,0 +1,24 @@ | |||
1 | QashMoney - Budget Software for the Sharp Zaurus | ||
2 | |||
3 | CHANGES | ||
4 | |||
5 | 11/1/02 - Initial release of 0.2 version. Considered stable beta version. | ||
6 | 11/16/02 - Release of version 0.3. This is a stable version adding function to | ||
7 | transfer money between accounts. Several bugs fixes and speed enhancements | ||
8 | have been done. | ||
9 | 11/21/02 - 0.31 news tabs working but not yet displaying accounts | ||
10 | 12/15/02 - QashMoney gets a complete face lift and now has a date picker. | ||
11 | 12/29/02 - Version 0.41 released. This release fixes more bugs and adds a | ||
12 | function to manage transaction memory items. | ||
13 | 12/31/02 - Version 0.42 released. Maintenance release fixing soem rather nasty | ||
14 | bugs that screw up account, transaction, and transfer displays. | ||
15 | 03/03/03 - Version 0.60 released. QashMoney has undergone quite a transformation. | ||
16 | A new GUI that incorporates all of Qts excellent layout capabilities should | ||
17 | display nicely in all formats. A new embedded SQL database should make QashMoney | ||
18 | very extensible. | ||
19 | 4/25/03 - Version 0.70 released. This version includes many new features over 0.60 including | ||
20 | currency support for accounts, a function to limit transaction views, and an all new budgeting | ||
21 | tab that allows multiple budgets and currency support. | ||
22 | 5/7/03 - Version 0.73 released. Few minor bugfixes and feature enhancements. QashMoney now | ||
23 | right justifies all numbers and remembers the sate in which you leave the account window. So, if you | ||
24 | collapse a parent account, it will stay collapsed (even between QashMoney restarts). | ||
diff --git a/noncore/apps/qashmoney/account.h b/noncore/apps/qashmoney/account.h new file mode 100755 index 0000000..f77f400 --- a/dev/null +++ b/noncore/apps/qashmoney/account.h | |||
@@ -0,0 +1,100 @@ | |||
1 | #ifndef ACCOUNT_H | ||
2 | #define ACCOUNT_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qlistview.h> | ||
6 | #include <qcombobox.h> | ||
7 | #include <sqlite.h> | ||
8 | |||
9 | class Account | ||
10 | { | ||
11 | public: | ||
12 | |||
13 | Account (); | ||
14 | ~Account (); | ||
15 | |||
16 | // This function adds a new account to the database. It takes the account name, parent, | ||
17 | // initial balance and the account type, description, credit limit, statementbalancedate | ||
18 | // as three integers, and the statementbalance amount | ||
19 | // The parent is an integer account id. Its -1 if there is no parent | ||
20 | // The account types (so far) are 0=not defined 1=parent checking 2=child checking | ||
21 | void addAccount ( QString, int, float, int, QString, float, int, int, int, float, const char * ); | ||
22 | |||
23 | // updates certain parts of an account | ||
24 | void updateAccount ( QString name, QString description, QString currencycode, int accountid ); | ||
25 | |||
26 | void setAccountExpanded ( int expanded, int accountid ); | ||
27 | int getAccountExpanded ( int id ); | ||
28 | |||
29 | // Deletes an account | ||
30 | // Takes the accountid as its parameter | ||
31 | void deleteAccount ( int ); | ||
32 | |||
33 | // Returns the number of accounts | ||
34 | int getNumberOfAccounts (); | ||
35 | |||
36 | // returns number of child accounts for a given parent | ||
37 | // this function is useless for child accounts. It will | ||
38 | // always return 0 | ||
39 | int getNumberOfChildAccounts ( int ); | ||
40 | |||
41 | // This function retrieves all transactions for an account and updates the | ||
42 | // account balance based on the transactions | ||
43 | void updateAccountBalance ( int accountid ); | ||
44 | //void changeAccountBalance ( int accountid, float amount ); | ||
45 | |||
46 | // updates a parent account | ||
47 | void changeParentAccountBalance ( int parentid ); | ||
48 | |||
49 | // Returns the parent account ID for an account | ||
50 | // Takes the account name as its parameter or the account id | ||
51 | int getParentAccountID ( QString accountname ); | ||
52 | int getParentAccountID ( int id ); | ||
53 | |||
54 | // This takes a QListView and puts parents and children memorys | ||
55 | // into the list view | ||
56 | void displayAccounts ( QListView * ); | ||
57 | |||
58 | // This function displays a sorted list of account names in a combobox | ||
59 | // Takes the combobox address for its parameter | ||
60 | int displayParentAccountNames ( QComboBox *, QString ); | ||
61 | |||
62 | int getAccountType ( int ); // returns account type for given account id | ||
63 | |||
64 | // The next three collectively return a date or balance | ||
65 | // They take the accountid as their parameters | ||
66 | int getStatementDay ( int ); | ||
67 | int getStatementMonth ( int ); | ||
68 | int getStatementYear ( int ); | ||
69 | float getStatementBalance ( int ); | ||
70 | |||
71 | // Returns account description and name | ||
72 | QString getAccountDescription ( int accountid ); | ||
73 | QString getCurrencyCode ( int accountid ); | ||
74 | QString getAccountName ( int accountid ); | ||
75 | QStringList getAccountNames (); | ||
76 | QStringList getAccountIDs (); | ||
77 | QString getAccountBalance ( int accountid ); | ||
78 | |||
79 | // returns account credit limit | ||
80 | float getAccountCreditLimit ( int ); | ||
81 | |||
82 | // The primary database that stores all our data | ||
83 | sqlite *adb; | ||
84 | }; | ||
85 | |||
86 | class GreyBackgroundItem : public QListViewItem | ||
87 | { | ||
88 | public: | ||
89 | |||
90 | GreyBackgroundItem ( QListView *parent ); | ||
91 | GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ); | ||
92 | GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ); | ||
93 | GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ); | ||
94 | |||
95 | virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); | ||
96 | |||
97 | }; | ||
98 | |||
99 | #endif | ||
100 | |||
diff --git a/noncore/apps/qashmoney/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp new file mode 100755 index 0000000..46ab1db --- a/dev/null +++ b/noncore/apps/qashmoney/accountdisplay.cpp | |||
@@ -0,0 +1,432 @@ | |||
1 | #include <qdatetime.h> | ||
2 | #include <qmessagebox.h> | ||
3 | #include <qheader.h> | ||
4 | |||
5 | #include "accountdisplay.h" | ||
6 | #include "newaccount.h" | ||
7 | #include "transaction.h" | ||
8 | #include "transferdialog.h" | ||
9 | #include "preferences.h" | ||
10 | #include "transfer.h" | ||
11 | |||
12 | extern Account *account; | ||
13 | extern Transaction *transaction; | ||
14 | extern Transfer *transfer; | ||
15 | extern Preferences *preferences; | ||
16 | |||
17 | AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) | ||
18 | { | ||
19 | cleared = 0; | ||
20 | |||
21 | firstline = new QHBox ( this ); | ||
22 | firstline->setSpacing ( 2 ); | ||
23 | |||
24 | newaccount = new QPushButton ( firstline ); | ||
25 | newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); | ||
26 | connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); | ||
27 | |||
28 | editaccount = new QPushButton ( firstline ); | ||
29 | editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); | ||
30 | connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); | ||
31 | |||
32 | deleteaccount = new QPushButton ( firstline ); | ||
33 | deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); | ||
34 | connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); | ||
35 | |||
36 | transferbutton = new QPushButton ( firstline ); | ||
37 | transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); | ||
38 | transferbutton->setToggleButton ( TRUE ); | ||
39 | connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); | ||
40 | |||
41 | listview = new QListView ( this ); | ||
42 | listview->setAllColumnsShowFocus ( TRUE ); | ||
43 | listview->setShowSortIndicator ( TRUE ); | ||
44 | listview->setRootIsDecorated ( TRUE ); | ||
45 | listview->setMultiSelection ( FALSE ); | ||
46 | connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); | ||
47 | connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); | ||
48 | |||
49 | listview->header()->setTracking ( FALSE ); | ||
50 | connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); | ||
51 | |||
52 | layout = new QVBoxLayout ( this, 2, 5 ); | ||
53 | layout->addWidget ( firstline ); | ||
54 | layout->addWidget ( listview ); | ||
55 | } | ||
56 | |||
57 | void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) | ||
58 | { | ||
59 | tab2 = newtab2; | ||
60 | maintabs = newtabs; | ||
61 | } | ||
62 | |||
63 | void AccountDisplay::addAccount () | ||
64 | { | ||
65 | // initialize local variables | ||
66 | int parentid = 0; | ||
67 | type = 0; | ||
68 | QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; | ||
69 | |||
70 | // create new account window for entering data | ||
71 | NewAccount *newaccount = new NewAccount ( this ); | ||
72 | int width = this->width(); | ||
73 | newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); | ||
74 | newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
75 | newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); | ||
76 | newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
77 | newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | ||
78 | |||
79 | // if there are no accounts, disable the child check box | ||
80 | if ( account->getNumberOfAccounts () == 0 ) | ||
81 | newaccount->childcheckbox->setEnabled ( FALSE ); | ||
82 | |||
83 | // if there are accounts, fill up the pulldown menu for | ||
84 | // selecting a parent account. We should only add those parents without transactions | ||
85 | else | ||
86 | { | ||
87 | int c = 0; | ||
88 | QListViewItemIterator it ( listview ); | ||
89 | for ( ; it.current(); ++it ) | ||
90 | { | ||
91 | int id = it.current()->text ( getIDColumn() ).toInt(); | ||
92 | // iterate through accountdisplay listview and add parents with no transactions | ||
93 | // add this item to the list box only if it is a parent and has no transactions | ||
94 | if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 ) | ||
95 | { | ||
96 | newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); | ||
97 | parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); | ||
98 | parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); | ||
99 | parentlist [ c ] [ 2 ] = QString::number ( c ); | ||
100 | c++; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | if ( preferences->getPreference ( 4 ) == 0 ) | ||
106 | newaccount->currencybox->setEnabled ( FALSE ); | ||
107 | |||
108 | // enter today's date in the date box as default | ||
109 | QDate today = QDate::currentDate (); | ||
110 | int defaultday = today.day(); | ||
111 | int defaultmonth = today.month(); | ||
112 | int defaultyear = today.year(); | ||
113 | newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); | ||
114 | |||
115 | //add account information if user pushes OK button | ||
116 | if ( newaccount->exec() == QDialog::Accepted ) | ||
117 | { | ||
118 | if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account | ||
119 | { | ||
120 | // go through the parentlist we created and determine the parent accountid | ||
121 | // we can't use the name of the account because there may be two accounts | ||
122 | // with the same name. This function does it all by accountid | ||
123 | int counter; | ||
124 | for ( counter = 0; counter < listview->childCount() + 1; counter++ ) | ||
125 | if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) | ||
126 | { | ||
127 | parentid = parentlist [ counter ] [ 1 ].toInt(); | ||
128 | break; | ||
129 | } | ||
130 | type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | parentid = -1; | ||
135 | type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts | ||
136 | } | ||
137 | |||
138 | // add the new account | ||
139 | if ( newaccount->getDateEdited () == TRUE ) | ||
140 | account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type, | ||
141 | newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(), | ||
142 | newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); | ||
143 | else | ||
144 | account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, | ||
145 | newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, | ||
146 | defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); | ||
147 | |||
148 | if ( parentid != -1 ) | ||
149 | account->changeParentAccountBalance ( parentid ); | ||
150 | |||
151 | // redisplay accounts | ||
152 | // this function clears the account display first | ||
153 | account->displayAccounts ( listview ); | ||
154 | setToggleButton(); | ||
155 | } | ||
156 | maintabs->setTabEnabled ( tab2, FALSE ); | ||
157 | } | ||
158 | |||
159 | void AccountDisplay::deleteAccount () | ||
160 | { | ||
161 | if ( listview->selectedItem() == 0 ) | ||
162 | QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); | ||
163 | else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) | ||
164 | QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); | ||
165 | else | ||
166 | { | ||
167 | QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); | ||
168 | if ( mb.exec() == QMessageBox::Ok ) | ||
169 | { | ||
170 | int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); | ||
171 | int parentid = account->getParentAccountID ( accountid ); | ||
172 | |||
173 | // delete all the transactions and transfers for the account | ||
174 | transaction->deleteAllTransactions ( accountid ); | ||
175 | transfer->deleteAllTransfers ( accountid ); | ||
176 | |||
177 | // delete the account | ||
178 | account->deleteAccount ( accountid ); | ||
179 | |||
180 | // update account balances | ||
181 | if ( parentid != -1 ) | ||
182 | account->changeParentAccountBalance ( parentid ); | ||
183 | |||
184 | //redisplay accounts | ||
185 | account->displayAccounts ( listview ); | ||
186 | |||
187 | //remove all the columns from the accountdisplay if there are not any accounts | ||
188 | if ( account->getNumberOfAccounts() == 0 ) | ||
189 | { | ||
190 | int columns = listview->columns(); | ||
191 | int counter; | ||
192 | for ( counter = 0; counter <= columns; counter++ ) | ||
193 | listview->removeColumn ( 0 ); | ||
194 | } | ||
195 | |||
196 | setToggleButton(); | ||
197 | } | ||
198 | } | ||
199 | maintabs->setTabEnabled ( tab2, FALSE ); | ||
200 | } | ||
201 | |||
202 | void AccountDisplay::setToggleButton () | ||
203 | { | ||
204 | // iterate through account display and determine how many "transferable" accounts we have | ||
205 | // if there are less than two, disable the transfer button | ||
206 | QListViewItemIterator it ( listview ); | ||
207 | int counter = 0; | ||
208 | for ( ; it.current(); ++it ) | ||
209 | { | ||
210 | // add one to counter if we find a transferable account | ||
211 | if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) | ||
212 | counter++; | ||
213 | } | ||
214 | if ( counter > 1 ) | ||
215 | transferbutton->show(); | ||
216 | else | ||
217 | transferbutton->hide(); | ||
218 | } | ||
219 | |||
220 | void AccountDisplay::accountTransfer ( bool state ) | ||
221 | { | ||
222 | if ( state == TRUE ) | ||
223 | { | ||
224 | firstaccountid = -1; | ||
225 | secondaccountid = -1; | ||
226 | listview->clearSelection (); | ||
227 | listview->setMultiSelection ( TRUE ); | ||
228 | disableParentsWithChildren (); | ||
229 | connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | firstaccountid = -1; | ||
234 | secondaccountid = -1; | ||
235 | listview->clearSelection (); | ||
236 | listview->setMultiSelection ( FALSE ); | ||
237 | enableAccounts (); | ||
238 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | void AccountDisplay::getTransferAccounts ( QListViewItem * item ) | ||
243 | { | ||
244 | if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children | ||
245 | { | ||
246 | if ( firstaccountid == -1 ) | ||
247 | firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account | ||
248 | else | ||
249 | if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first | ||
250 | secondaccountid = item->text ( getIDColumn() ).toInt(); | ||
251 | } | ||
252 | |||
253 | // open transfer window if both accounts are set | ||
254 | if ( firstaccountid != -1 && secondaccountid != -1 ) | ||
255 | { | ||
256 | // construct the transferdialog window | ||
257 | TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); | ||
258 | |||
259 | // enter today's date in the date box as default | ||
260 | QDate today = QDate::currentDate (); | ||
261 | int defaultday = today.day(); | ||
262 | int defaultmonth = today.month(); | ||
263 | int defaultyear = today.year(); | ||
264 | td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); | ||
265 | |||
266 | if ( td->exec() == QDialog::Accepted ) | ||
267 | { | ||
268 | // set the cleared integer if the checkbox is checked | ||
269 | if ( td->clearedcheckbox->isChecked() == TRUE ) | ||
270 | cleared = 1; | ||
271 | |||
272 | // add the transfer with a new date if its been edited or use the default date | ||
273 | if ( td->getDateEdited () == TRUE ) | ||
274 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, | ||
275 | account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); | ||
276 | else | ||
277 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, | ||
278 | account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); | ||
279 | |||
280 | // update account balances of both accounts and parents if necessary | ||
281 | account->updateAccountBalance ( firstaccountid ); | ||
282 | if ( account->getParentAccountID ( firstaccountid ) != -1 ) | ||
283 | account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); | ||
284 | account->updateAccountBalance ( secondaccountid ); | ||
285 | if ( account->getParentAccountID ( secondaccountid ) != -1 ) | ||
286 | account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); | ||
287 | |||
288 | // redisplay accounts | ||
289 | account->displayAccounts ( listview ); | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | firstaccountid = -1; | ||
294 | secondaccountid = -1; | ||
295 | listview->clearSelection (); | ||
296 | listview->setMultiSelection ( FALSE ); | ||
297 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | ||
298 | } | ||
299 | |||
300 | // reset the accounts display window | ||
301 | transferbutton->toggle(); // toggling this button with clear the window as well | ||
302 | |||
303 | // reenable all the accounts so the transaction tab will be properly set | ||
304 | enableAccounts (); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | void AccountDisplay::disableParentsWithChildren () | ||
309 | { | ||
310 | // iterate through accountdisplay listview and disable all the parents that have children | ||
311 | QListViewItemIterator it ( listview ); | ||
312 | for ( ; it.current(); ++it ) | ||
313 | { | ||
314 | if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) | ||
315 | it.current()->setSelectable ( FALSE ); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | void AccountDisplay::enableAccounts () | ||
320 | { | ||
321 | // iterate through accountdisplay listview and enable all accounts | ||
322 | QListViewItemIterator it ( listview ); | ||
323 | for ( ; it.current(); ++it ) | ||
324 | it.current()->setSelectable ( TRUE ); | ||
325 | } | ||
326 | |||
327 | void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) | ||
328 | { | ||
329 | switch ( column ) | ||
330 | { | ||
331 | case 0: | ||
332 | if ( listview->columns() == 3 ) | ||
333 | preferences->changeColumnPreference ( 1, newsize ); | ||
334 | else | ||
335 | preferences->changeColumnPreference ( 10, newsize ); | ||
336 | break; | ||
337 | case 1: | ||
338 | if ( listview->columns() == 3 ) | ||
339 | preferences->changeColumnPreference ( 2, newsize ); | ||
340 | else | ||
341 | preferences->changeColumnPreference ( 11, newsize ); | ||
342 | break; | ||
343 | case 2: | ||
344 | preferences->changeColumnPreference ( 12, newsize ); | ||
345 | break; | ||
346 | } | ||
347 | |||
348 | } | ||
349 | |||
350 | int AccountDisplay::getIDColumn () | ||
351 | { | ||
352 | int counter; | ||
353 | int columns = listview->columns(); | ||
354 | for ( counter = 0; counter <= columns; counter++ ) | ||
355 | if ( listview->header()->label ( counter ).length() == 0 ) | ||
356 | return counter; | ||
357 | } | ||
358 | |||
359 | void AccountDisplay::editAccount () | ||
360 | { | ||
361 | if ( listview->selectedItem() == 0 ) | ||
362 | QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); | ||
363 | else | ||
364 | { | ||
365 | // set the accountid | ||
366 | int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); | ||
367 | |||
368 | //construct new dialog box | ||
369 | QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); | ||
370 | editaccountwindow->setCaption ( "Edit Account" ); | ||
371 | |||
372 | // construct the items which will go in the dialog bix | ||
373 | QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); | ||
374 | QLineEdit *accountname = new QLineEdit ( editaccountwindow ); | ||
375 | QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); | ||
376 | QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); | ||
377 | Currency *currencybox = new Currency ( editaccountwindow ); | ||
378 | |||
379 | QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); | ||
380 | layout->addWidget ( namelabel ); | ||
381 | layout->addWidget ( accountname ); | ||
382 | layout->addWidget ( descriptionlabel ); | ||
383 | layout->addWidget ( accountdescription ); | ||
384 | layout->addWidget ( currencybox ); | ||
385 | |||
386 | //set the account name | ||
387 | accountname->setText ( listview->selectedItem()->text ( 0 ) ); | ||
388 | |||
389 | //set the account description | ||
390 | accountdescription->setText ( account->getAccountDescription ( accountid ) ); | ||
391 | |||
392 | if ( preferences->getPreference ( 4 ) == 1 ) | ||
393 | { | ||
394 | // get currency code for this account then iterate through the currency box | ||
395 | // to find the one we want | ||
396 | int count = currencybox->currencybox->count(); | ||
397 | QString code = account->getCurrencyCode ( accountid ); | ||
398 | for ( int counter = 0; count - 1; counter++ ) | ||
399 | { | ||
400 | if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 ) | ||
401 | { | ||
402 | currencybox->currencybox->setCurrentItem ( counter ); | ||
403 | break; | ||
404 | } | ||
405 | } | ||
406 | } | ||
407 | else | ||
408 | currencybox->setEnabled ( FALSE ); | ||
409 | |||
410 | //execute the dialog box | ||
411 | int response = editaccountwindow->exec(); | ||
412 | if ( response == 1 ) | ||
413 | { | ||
414 | account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid ); | ||
415 | account->displayAccounts ( listview ); | ||
416 | } | ||
417 | } | ||
418 | } | ||
419 | |||
420 | void AccountDisplay::setAccountExpanded ( QListViewItem *item ) | ||
421 | { | ||
422 | int accountid = item->text ( getIDColumn() ).toInt(); | ||
423 | account->setAccountExpanded ( 1, accountid ); | ||
424 | } | ||
425 | |||
426 | void AccountDisplay::setAccountCollapsed ( QListViewItem *item ) | ||
427 | { | ||
428 | int accountid = item->text ( getIDColumn() ).toInt(); | ||
429 | account->setAccountExpanded ( 0, accountid ); | ||
430 | } | ||
431 | |||
432 | |||
diff --git a/noncore/apps/qashmoney/budget.cpp b/noncore/apps/qashmoney/budget.cpp new file mode 100755 index 0000000..42f7eca --- a/dev/null +++ b/noncore/apps/qashmoney/budget.cpp | |||
@@ -0,0 +1,221 @@ | |||
1 | #include "budget.h" | ||
2 | #include "transaction.h" | ||
3 | #include <stdlib.h> | ||
4 | |||
5 | extern Transaction *transaction; | ||
6 | |||
7 | Budget::Budget () | ||
8 | { | ||
9 | bdb = sqlite_open ( "qmbudgets.db", 0, NULL ); | ||
10 | } | ||
11 | |||
12 | Budget::~Budget () | ||
13 | { | ||
14 | sqlite_close ( bdb ); | ||
15 | } | ||
16 | |||
17 | int Budget::addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview ) | ||
18 | { | ||
19 | sqlite_exec_printf ( bdb, "insert into budgets values ( '%q', %i, '%q', '%q', %i, %i, %i, %i, %i, %i, %i, NULL );", 0, 0, 0, ( const char * ) name, type, ( const char * ) description, ( const char * ) currency, startday, startmonth, startyear, endday, endmonth, endyear, defaultview ); | ||
20 | char **results; | ||
21 | sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); | ||
22 | QString tablename = "table"; | ||
23 | tablename.append ( results [ 1 ] ); | ||
24 | sqlite_exec_printf ( bdb, "create table '%q' ( name, lineitemamount, type, lineitemid integer primary key );", 0, 0, 0, ( const char* ) tablename ); | ||
25 | return atoi ( results [ 1 ] ); | ||
26 | } | ||
27 | |||
28 | void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid ) | ||
29 | { | ||
30 | sqlite_exec_printf ( bdb, "update budgets set name = '%q', description = '%q', currency = '%q' where budgetid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currency, budgetid ); | ||
31 | } | ||
32 | |||
33 | void Budget::deleteBudget ( int budgetid ) | ||
34 | { | ||
35 | if ( getNumberOfBudgets() != 0 ) | ||
36 | { | ||
37 | QString tablename = "table"; | ||
38 | tablename.append ( QString::number ( budgetid ) ); | ||
39 | sqlite_exec_printf ( bdb, "delete from budgets where budgetid = %i;", 0, 0, 0, budgetid ); | ||
40 | sqlite_exec_printf ( bdb, "drop table '%q';", 0, 0, 0, ( const char* ) tablename ); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | int Budget::getNumberOfBudgets () | ||
45 | { | ||
46 | char **results; | ||
47 | sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL ); | ||
48 | return atoi ( results [ 1 ] ); | ||
49 | } | ||
50 | |||
51 | int Budget::getNumberOfLineItems ( int budgetid ) | ||
52 | { | ||
53 | QString tablename = "table"; | ||
54 | tablename.append ( QString::number ( budgetid ) ); | ||
55 | char **results; | ||
56 | sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); | ||
57 | return atoi ( results [ 1 ] ); | ||
58 | } | ||
59 | |||
60 | QStringList* Budget::getBudgetNames () | ||
61 | { | ||
62 | QStringList *names = new QStringList (); | ||
63 | char **results; | ||
64 | int rows, counter; | ||
65 | sqlite_get_table ( bdb, "select name from budgets order by name asc;", &results, &rows, NULL, NULL ); | ||
66 | names->append ( "None" ); | ||
67 | for ( counter = 0; counter < rows; counter++ ) | ||
68 | names->append ( results [ counter+1 ] ); | ||
69 | return names; | ||
70 | } | ||
71 | |||
72 | QString Budget::getBudgetName ( int budgetid ) | ||
73 | { | ||
74 | char **results; | ||
75 | sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); | ||
76 | return ( QString ) results [ 1 ]; | ||
77 | } | ||
78 | |||
79 | QString Budget::getBudgetDescription ( int budgetid ) | ||
80 | { | ||
81 | char **results; | ||
82 | sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); | ||
83 | return ( QString ) results [ 1 ]; | ||
84 | } | ||
85 | |||
86 | QString Budget::getCurrency ( int budgetid ) | ||
87 | { | ||
88 | char **results; | ||
89 | sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); | ||
90 | return ( QString ) results [ 1 ]; | ||
91 | } | ||
92 | |||
93 | QStringList* Budget::getBudgetIDs () | ||
94 | { | ||
95 | QStringList *ids = new QStringList (); | ||
96 | char **results; | ||
97 | int rows, counter; | ||
98 | sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL ); | ||
99 | for ( counter = 0; counter < rows; counter++ ) | ||
100 | ids->append ( results [ counter+1 ] ); | ||
101 | return ids; | ||
102 | } | ||
103 | |||
104 | int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype ) | ||
105 | { | ||
106 | QString tablename = "table"; | ||
107 | tablename.append ( QString::number ( budgetid ) ); | ||
108 | sqlite_exec_printf ( bdb, "insert into '%q' values ( '%q', %.2f, %i, NULL );", 0, 0, 0, ( const char* ) tablename, ( const char* ) lineitemname, lineitemamount, lineitemtype ); | ||
109 | char **results; | ||
110 | sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename ); | ||
111 | return atoi ( results [ 1 ] ); | ||
112 | } | ||
113 | |||
114 | void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid ) | ||
115 | { | ||
116 | QString tablename = "table"; | ||
117 | tablename.append ( QString::number ( budgetid ) ); | ||
118 | sqlite_exec_printf ( bdb, "update '%q' set name = '%q', lineitemamount = %f, type = %i where lineitemid = %i;", 0, 0, 0, ( const char* ) tablename, ( const char * ) lineitemname, lineitemamount, lineitemtype, lineitemid ); | ||
119 | } | ||
120 | |||
121 | void Budget::deleteLineItem ( int budgetid, int lineitemid ) | ||
122 | { | ||
123 | QString tablename = "table"; | ||
124 | tablename.append ( QString::number ( budgetid ) ); | ||
125 | sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid ); | ||
126 | } | ||
127 | |||
128 | void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype ) | ||
129 | { | ||
130 | QString tablename = "table"; | ||
131 | tablename.append ( QString::number ( budgetid ) ); | ||
132 | char **results; | ||
133 | int rows, columns, counter; | ||
134 | sqlite_get_table_printf ( bdb, "select name, lineitemamount, lineitemid from '%q';", &results, &rows, &columns, NULL, ( const char * ) tablename ); | ||
135 | int total = ( ( rows + 1 ) * columns ); | ||
136 | for ( counter = 3; counter < total; counter = counter + 3 ) | ||
137 | { | ||
138 | float amount = 0; | ||
139 | if ( viewtype == 0 ) | ||
140 | { | ||
141 | QString lineitemamount = results [ counter + 1 ]; | ||
142 | amount = lineitemamount.toFloat() / 12; | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | QString lineitemamount = results [ counter + 1 ]; | ||
147 | amount = lineitemamount.toFloat(); | ||
148 | } | ||
149 | QListViewItem *item = new QListViewItem ( listview, results [ counter ], QString::number ( amount, 'f', 2 ), transaction->getBudgetTotal ( budgetid, atoi ( results [ counter + 2 ] ), year, month, viewtype ), results [ counter + 2 ] ); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | QStringList Budget::getLineItems ( int budgetid ) | ||
154 | { | ||
155 | QString tablename = "table"; | ||
156 | tablename.append ( QString::number ( budgetid ) ); | ||
157 | QStringList lineitems; | ||
158 | char **results; | ||
159 | int rows, counter; | ||
160 | sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); | ||
161 | for ( counter = 0; counter < rows; counter++ ) | ||
162 | lineitems.append ( results [ counter + 1 ] ); | ||
163 | return lineitems; | ||
164 | } | ||
165 | |||
166 | QStringList Budget::getLineItemIDs ( int budgetid ) | ||
167 | { | ||
168 | QString tablename = "table"; | ||
169 | tablename.append ( QString::number ( budgetid ) ); | ||
170 | QStringList lineitemids; | ||
171 | char **results; | ||
172 | int rows, counter; | ||
173 | sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); | ||
174 | for ( counter = 0; counter < rows; counter++ ) | ||
175 | lineitemids.append ( results [ counter + 1 ] ); | ||
176 | return lineitemids; | ||
177 | } | ||
178 | |||
179 | int Budget::getLineItemTime ( int budgetid, int lineitemid ) | ||
180 | { | ||
181 | QString tablename = "table"; | ||
182 | tablename.append ( QString::number ( budgetid ) ); | ||
183 | char **results; | ||
184 | sqlite_get_table_printf ( bdb, "select type from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char * ) tablename, lineitemid ); | ||
185 | return atoi ( results [ 1 ] ); | ||
186 | } | ||
187 | |||
188 | float Budget::getLineItemAmount ( int budgetid, int lineitemid ) | ||
189 | { | ||
190 | QString tablename = "table"; | ||
191 | tablename.append ( QString::number ( budgetid ) ); | ||
192 | char **results; | ||
193 | sqlite_get_table_printf ( bdb, "select lineitemamount from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char* ) tablename, lineitemid ); | ||
194 | return strtod ( results [ 1 ], 0 ); | ||
195 | } | ||
196 | |||
197 | QString Budget::getBudgetTotal ( int budgetid, int viewtype ) | ||
198 | { | ||
199 | QString tablename = "table"; | ||
200 | tablename.append ( QString::number ( budgetid ) ); | ||
201 | // determine if we are viewing a years, months, or days budget | ||
202 | // we have to pick a different sum for each | ||
203 | char **results; | ||
204 | sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); | ||
205 | QString amount = results [ 1 ]; | ||
206 | float total = amount.toFloat(); | ||
207 | if ( viewtype == 0 ) | ||
208 | total = total / 12; | ||
209 | amount.setNum ( total, 'f', 2 ); | ||
210 | return amount; | ||
211 | } | ||
212 | |||
213 | int Budget::getLastAdded () | ||
214 | { | ||
215 | char **results; | ||
216 | sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); | ||
217 | return atoi ( results [ 1 ] ); | ||
218 | } | ||
219 | |||
220 | |||
221 | |||
diff --git a/noncore/apps/qashmoney/budget.h b/noncore/apps/qashmoney/budget.h new file mode 100755 index 0000000..16af26a --- a/dev/null +++ b/noncore/apps/qashmoney/budget.h | |||
@@ -0,0 +1,45 @@ | |||
1 | #ifndef BUDGET_H | ||
2 | #define BUDGET_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qlistview.h> | ||
7 | #include <sqlite.h> | ||
8 | |||
9 | class Budget | ||
10 | { | ||
11 | public: | ||
12 | |||
13 | Budget (); | ||
14 | ~Budget (); | ||
15 | |||
16 | int addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview ); | ||
17 | void updateBudget ( QString name, QString description, QString currency, int budgetid ); | ||
18 | void deleteBudget ( int budgetid ); | ||
19 | int getNumberOfBudgets (); | ||
20 | int getNumberOfLineItems ( int budgetid ); | ||
21 | |||
22 | QStringList* getBudgetNames (); | ||
23 | QStringList* getBudgetIDs (); | ||
24 | QStringList getLineItems ( int budgetid ); | ||
25 | QStringList getLineItemIDs ( int budgetid ); | ||
26 | QString getBudgetName ( int budgetid ); | ||
27 | QString getBudgetDescription ( int budgetid ); | ||
28 | QString getCurrency ( int budgetid ); | ||
29 | QString getBudgetTotal ( int budgetid, int viewtype ); | ||
30 | |||
31 | int getLastAdded (); | ||
32 | |||
33 | int addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype ); | ||
34 | void updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid ); | ||
35 | void displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype ); | ||
36 | void deleteLineItem ( int budgetid, int lineitemid ); | ||
37 | int getLineItemTime ( int budgetid, int lineitemid ); | ||
38 | float getLineItemAmount ( int budgetid, int lineitemid ); | ||
39 | |||
40 | private: | ||
41 | sqlite *bdb; | ||
42 | }; | ||
43 | |||
44 | #endif | ||
45 | |||
diff --git a/noncore/apps/qashmoney/memory.cpp b/noncore/apps/qashmoney/memory.cpp new file mode 100755 index 0000000..b5155b3 --- a/dev/null +++ b/noncore/apps/qashmoney/memory.cpp | |||
@@ -0,0 +1,62 @@ | |||
1 | #include "memory.h" | ||
2 | |||
3 | #include <stdlib.h> | ||
4 | |||
5 | Memory::Memory () | ||
6 | { | ||
7 | db = sqlite_open ( "qmmemory.db", 0, NULL ); | ||
8 | } | ||
9 | |||
10 | Memory::~Memory () | ||
11 | { | ||
12 | sqlite_close ( db ); | ||
13 | } | ||
14 | |||
15 | void Memory::addMemoryItem ( QString item ) | ||
16 | { | ||
17 | sqlite_exec_printf ( db, "insert into memory values ( '%q', 0, 0 );", 0, 0, 0, ( const char * ) item ); | ||
18 | } | ||
19 | |||
20 | void Memory::deleteMemoryItem ( QString item ) | ||
21 | { | ||
22 | sqlite_exec_printf ( db, "delete from memory where item = '%q';", 0, 0, 0, ( const char * ) item ); | ||
23 | } | ||
24 | |||
25 | int Memory::getNumberOfMemoryItems () | ||
26 | { | ||
27 | char **results; | ||
28 | sqlite_get_table ( db, "select count() from memory;", &results, NULL, NULL, NULL ); | ||
29 | return atoi ( results [ 1 ] ); | ||
30 | } | ||
31 | |||
32 | void Memory::changeMemoryName ( QString item ) | ||
33 | { | ||
34 | sqlite_exec_printf ( db, "update memory set item = '%q' where item = '%q';", 0, 0, 0, ( const char * ) item ); | ||
35 | } | ||
36 | |||
37 | void Memory::displayMemoryItems ( QListBox *listbox ) | ||
38 | { | ||
39 | char **results; | ||
40 | int rows; | ||
41 | sqlite_get_table ( db, "select item from memory order by item asc;", &results, &rows, NULL, NULL ); | ||
42 | int counter = 1; | ||
43 | while ( counter < ( rows + 1 ) ) | ||
44 | { | ||
45 | listbox->insertItem ( results [ counter ] ); | ||
46 | counter ++; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | void Memory::displayMemoryItems ( QComboBox *box ) | ||
51 | { | ||
52 | char **results; | ||
53 | int rows; | ||
54 | sqlite_get_table ( db, "select item from memory order by item asc;", &results, &rows, NULL, NULL ); | ||
55 | int counter = 1; | ||
56 | while ( counter < ( rows + 1 ) ) | ||
57 | { | ||
58 | box->insertItem ( results [ counter ] ); | ||
59 | counter ++; | ||
60 | } | ||
61 | } | ||
62 | |||
diff --git a/noncore/apps/qashmoney/memory.h b/noncore/apps/qashmoney/memory.h new file mode 100755 index 0000000..6f3f100 --- a/dev/null +++ b/noncore/apps/qashmoney/memory.h | |||
@@ -0,0 +1,45 @@ | |||
1 | #ifndef MEMORY_H | ||
2 | #define MEMORY_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qlistbox.h> | ||
6 | #include <qcombobox.h> | ||
7 | #include <sqlite.h> | ||
8 | |||
9 | class Memory : public QObject | ||
10 | { | ||
11 | |||
12 | Q_OBJECT | ||
13 | |||
14 | public: | ||
15 | |||
16 | Memory (); | ||
17 | ~Memory (); | ||
18 | |||
19 | // This function adds a new memory to the database. It takes the memory name, parent, | ||
20 | // initial balance, a displayed variable, and the memory type | ||
21 | // The parent is an integer memory id. Its -1 if there is not parent | ||
22 | // The memory types are 0=not defined 1=parent 2=child | ||
23 | void addMemoryItem ( QString ); | ||
24 | |||
25 | // Returns the number of checking memorys | ||
26 | int getNumberOfMemoryItems (); | ||
27 | |||
28 | void changeMemoryName ( QString ); | ||
29 | |||
30 | // This takes a QListView and puts parents and children memorys | ||
31 | // into the list view | ||
32 | void displayMemoryItems ( QListBox * ); | ||
33 | void displayMemoryItems ( QComboBox * ); | ||
34 | |||
35 | // The primary database that stores all our data | ||
36 | sqlite *db; | ||
37 | |||
38 | public slots: | ||
39 | |||
40 | // Deletes a memory item. Takes the memoryid as its parameter | ||
41 | void deleteMemoryItem ( QString ); | ||
42 | }; | ||
43 | |||
44 | #endif | ||
45 | |||
diff --git a/noncore/apps/qashmoney/preferences.h b/noncore/apps/qashmoney/preferences.h new file mode 100755 index 0000000..4a3e058 --- a/dev/null +++ b/noncore/apps/qashmoney/preferences.h | |||
@@ -0,0 +1,50 @@ | |||
1 | #include <sqlite.h> | ||
2 | #include <qstring.h> | ||
3 | |||
4 | #ifndef PREFERENCES_H | ||
5 | #define PREFERENCES_H | ||
6 | |||
7 | class Preferences | ||
8 | { | ||
9 | public: | ||
10 | Preferences (); | ||
11 | ~Preferences (); | ||
12 | |||
13 | void addPreferences (); | ||
14 | void initializeColumnPreferences (); | ||
15 | |||
16 | // Returns a preference value for the given preferences ID | ||
17 | int getPreference ( int ); | ||
18 | int getColumnPreference ( int id ); | ||
19 | |||
20 | // Convenience for getting date separator with one function | ||
21 | // call. Takes the preference id as its argument | ||
22 | QString getSeparator ( ); | ||
23 | |||
24 | // Changes a preference for the given ID | ||
25 | void changePreference ( int , int ); | ||
26 | void changeColumnPreference ( int id, int width ); | ||
27 | |||
28 | // The primary database that stores all our data | ||
29 | sqlite *db; | ||
30 | |||
31 | // This function returns a Qstring for the year first date formats | ||
32 | // for displaying. It takes the date numbers | ||
33 | QString getDate ( int, int, int ); | ||
34 | QString getDate ( int y, int m ); | ||
35 | |||
36 | void setDefaultDatePreferences (); | ||
37 | }; | ||
38 | |||
39 | #endif | ||
40 | |||
41 | |||
42 | |||
43 | |||
44 | |||
45 | |||
46 | |||
47 | |||
48 | |||
49 | |||
50 | |||
diff --git a/noncore/apps/qashmoney/qashmoney.cpp b/noncore/apps/qashmoney/qashmoney.cpp new file mode 100755 index 0000000..1ea358c --- a/dev/null +++ b/noncore/apps/qashmoney/qashmoney.cpp | |||
@@ -0,0 +1,356 @@ | |||
1 | #include "qashmoney.h" | ||
2 | #include "preferencedialogs.h" | ||
3 | #include "memorydialog.h" | ||
4 | |||
5 | #include <qheader.h> | ||
6 | #include <iostream.h> | ||
7 | |||
8 | Budget *budget = new Budget (); | ||
9 | Preferences *preferences = new Preferences (); | ||
10 | Account *account = new Account (); | ||
11 | Transaction *transaction = new Transaction (); | ||
12 | Transfer *transfer = new Transfer (); | ||
13 | Memory *memory = new Memory (); | ||
14 | |||
15 | QashMoney::QashMoney () : QWidget () | ||
16 | { | ||
17 | preferences->addPreferences(); | ||
18 | preferences->initializeColumnPreferences (); | ||
19 | |||
20 | // set the text in the upper part of the frame | ||
21 | setCaption ( tr ( "QashMoney" ) ); | ||
22 | |||
23 | // Create new menubar for our mainwindow | ||
24 | // and add menu items | ||
25 | mainmenu = new QPEMenuBar ( this ); | ||
26 | mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); | ||
27 | preferencesmenu = new QPopupMenu ( this ); | ||
28 | utilitiesmenu = new QPopupMenu ( this ); | ||
29 | mainmenu->insertItem ( "Preferences", preferencesmenu ); | ||
30 | mainmenu->insertItem ( "Utilities", utilitiesmenu ); | ||
31 | preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog () ) ); | ||
32 | preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog () ) ); | ||
33 | preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog () ) ); | ||
34 | utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog () ) ); | ||
35 | |||
36 | // create the main tabwidget for displaying accounts and transactions | ||
37 | maintabs = new QTabWidget ( this ); | ||
38 | tab = new QWidget ( this ); | ||
39 | tab_2 = new QWidget ( this ); | ||
40 | tab_3 = new QWidget ( this ); | ||
41 | maintabs->addTab ( tab, "Accounts" ); | ||
42 | maintabs->addTab ( tab_2, "Transactions" ); | ||
43 | maintabs->addTab ( tab_3, "Budgets" ); | ||
44 | tabheight = tab->height(); | ||
45 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
46 | |||
47 | // create a new account display object | ||
48 | accountdisplay = new AccountDisplay ( maintabs ); | ||
49 | accountdisplay->setTabs ( tab_2, maintabs ); | ||
50 | connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( setTransactionTab () ) ); | ||
51 | |||
52 | // set the connection to disable the one touch account viewing if we are transfering money | ||
53 | connect ( accountdisplay->transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( toggleOneTouchViewing ( bool ) ) ); | ||
54 | |||
55 | // create a new transactiondisplay object | ||
56 | transactiondisplay = new TransactionDisplay ( maintabs ); | ||
57 | transactiondisplay->hide(); | ||
58 | |||
59 | // create new budgetdisplay object | ||
60 | budgetdisplay = new BudgetDisplay ( maintabs ); | ||
61 | budgetdisplay->hide(); | ||
62 | |||
63 | tabslayout = new QVBoxLayout ( maintabs, 4, 2 ); | ||
64 | tabslayout->addSpacing ( tabheight ); | ||
65 | tabslayout->addWidget ( accountdisplay ); | ||
66 | tabslayout->addWidget ( transactiondisplay ); | ||
67 | tabslayout->addWidget ( budgetdisplay ); | ||
68 | |||
69 | // connect a change in the maintabs with changing the tab display | ||
70 | connect ( maintabs, SIGNAL ( currentChanged ( QWidget * ) ), this, SLOT ( changeTabDisplay () ) ); | ||
71 | |||
72 | // create layout that will contain the menubar and the maintabs | ||
73 | layout = new QVBoxLayout ( this, 2, 2 ); | ||
74 | layout->setMenuBar ( mainmenu ); | ||
75 | layout->addWidget ( maintabs ); | ||
76 | } | ||
77 | |||
78 | QashMoney::~QashMoney () | ||
79 | { | ||
80 | delete budget; | ||
81 | delete preferences; | ||
82 | delete account; | ||
83 | delete transaction; | ||
84 | delete transfer; | ||
85 | delete memory; | ||
86 | } | ||
87 | |||
88 | void QashMoney::changeTabDisplay () | ||
89 | { | ||
90 | // if the user pressed the transactions tab, hide the account display | ||
91 | // object and create a new transaction display | ||
92 | if ( maintabs->currentPageIndex() == 1 ) | ||
93 | { | ||
94 | // initialize variables | ||
95 | bool children = FALSE; | ||
96 | |||
97 | // hide the account display and define accountid | ||
98 | int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); | ||
99 | |||
100 | //remove all the columns from the transactiondisplay | ||
101 | int columns = transactiondisplay->listview->columns(); | ||
102 | int counter; | ||
103 | for ( counter = 0; counter <= columns; counter++ ) | ||
104 | transactiondisplay->listview->removeColumn ( 0 ); | ||
105 | |||
106 | // set the account name and account balance | ||
107 | QString name = account->getAccountName ( accountid ); | ||
108 | QString balance = account->getAccountBalance ( accountid ); | ||
109 | transactiondisplay->name->setText ( name ); | ||
110 | transactiondisplay->balance->setText ( balance ); | ||
111 | |||
112 | // clear the limitbox | ||
113 | transactiondisplay->limitbox->clear(); | ||
114 | |||
115 | // get parent account id | ||
116 | int parentaccountid = account->getParentAccountID ( accountid ); | ||
117 | |||
118 | // add columns based on which account is selected | ||
119 | // this first if determines if we selected a parent with no children or a child | ||
120 | // in these cases, we add standard three columns for date, transaction, amount | ||
121 | transactiondisplay->listview->addColumn ( "Date", 0 ); | ||
122 | transactiondisplay->listview->addColumn ( "Transaction", 0 ); | ||
123 | transactiondisplay->listview->addColumn ( "Amt", 0); | ||
124 | transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight ); | ||
125 | transactiondisplay->listview->addColumn ( "", 0 ); | ||
126 | |||
127 | if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children | ||
128 | { | ||
129 | // add an extra column for the account name for eac child transaction | ||
130 | transactiondisplay->listview->addColumn ( "Acct", 0 ); | ||
131 | children = TRUE; | ||
132 | |||
133 | // hide the new transaction button | ||
134 | transactiondisplay->newtransaction->setEnabled ( FALSE ); | ||
135 | } | ||
136 | else //we selected a parent without children or a child | ||
137 | transactiondisplay->newtransaction->setEnabled ( TRUE ); | ||
138 | |||
139 | // disable the transactionid column so it can't be red | ||
140 | transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 ); | ||
141 | |||
142 | // set the accountid and children variables | ||
143 | transactiondisplay->setChildren ( children ); | ||
144 | transactiondisplay->setAccountID ( accountid ); | ||
145 | |||
146 | // display transactions | ||
147 | transactiondisplay->listview->clear(); | ||
148 | QString displaytext = "%"; | ||
149 | displaytext.prepend ( transactiondisplay->limitbox->text() ); | ||
150 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
151 | transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext ); | ||
152 | |||
153 | // display transfers | ||
154 | transfer->displayTransfers ( transactiondisplay->listview, accountid, children ); | ||
155 | |||
156 | // open a new preferences object and resize the transaction display columns | ||
157 | // each column will have a different size based on whether we are looking at a child | ||
158 | // account or children through a parent | ||
159 | if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns | ||
160 | { | ||
161 | transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width | ||
162 | transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); | ||
163 | transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width | ||
164 | transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); | ||
165 | transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width | ||
166 | transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); | ||
167 | } | ||
168 | else | ||
169 | { | ||
170 | transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width | ||
171 | transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); | ||
172 | transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width | ||
173 | transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); | ||
174 | transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width | ||
175 | transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); | ||
176 | transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width | ||
177 | transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual ); | ||
178 | } | ||
179 | |||
180 | // show the window | ||
181 | transactiondisplay->show(); | ||
182 | // hide the account display and define accountid | ||
183 | accountdisplay->hide(); | ||
184 | // hide the budget display | ||
185 | budgetdisplay->hide(); | ||
186 | } | ||
187 | else if ( maintabs->currentPageIndex() == 0 ) | ||
188 | { | ||
189 | disableOneTouchViewing(); | ||
190 | |||
191 | // clear the account display selection | ||
192 | accountdisplay->listview->clearSelection(); | ||
193 | |||
194 | // resize the account display columns | ||
195 | accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); | ||
196 | accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); | ||
197 | |||
198 | // display the accounts | ||
199 | if ( account->getNumberOfAccounts() != 0 ) | ||
200 | account->displayAccounts ( accountdisplay->listview ); | ||
201 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
202 | |||
203 | // set the toggle button | ||
204 | accountdisplay->setToggleButton (); | ||
205 | |||
206 | // show the account display | ||
207 | accountdisplay->show(); | ||
208 | |||
209 | // hide the transaction display | ||
210 | transactiondisplay->hide(); | ||
211 | |||
212 | // hide the budget display | ||
213 | budgetdisplay->hide(); | ||
214 | |||
215 | |||
216 | enableOneTouchViewing (); | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | budgetdisplay->displayLineItems(); | ||
221 | budgetdisplay->show(); | ||
222 | transactiondisplay->hide(); | ||
223 | accountdisplay->hide(); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | void QashMoney::setTransactionTab () | ||
228 | { | ||
229 | if ( accountdisplay->listview->selectedItem() == 0 ) | ||
230 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
231 | else | ||
232 | maintabs->setTabEnabled ( tab_2, TRUE ); | ||
233 | } | ||
234 | |||
235 | void QashMoney::displayDatePreferencesDialog () | ||
236 | { | ||
237 | // this shows a dialog to set preferences for formatting the date | ||
238 | DatePreferences *pd = new DatePreferences ( this ); | ||
239 | pd->exec (); | ||
240 | if ( transactiondisplay->isVisible() ) | ||
241 | { | ||
242 | // set the account id | ||
243 | int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); | ||
244 | |||
245 | // set children so we can let displayTransfers know if there are children for the selected account | ||
246 | bool children; | ||
247 | if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) | ||
248 | children = TRUE; | ||
249 | else | ||
250 | children = FALSE; | ||
251 | |||
252 | // redisplay transactions if they are visible incorporating | ||
253 | // any changes to the date format | ||
254 | transactiondisplay->listview->clear(); | ||
255 | QString displaytext = "%"; | ||
256 | displaytext.prepend ( transactiondisplay->limitbox->text() ); | ||
257 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
258 | transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext ); | ||
259 | |||
260 | if ( transfer->getNumberOfTransfers() != 0 ) | ||
261 | transfer->displayTransfers ( transactiondisplay->listview, accountid, children ); | ||
262 | } | ||
263 | else if ( accountdisplay->isVisible() ) | ||
264 | { | ||
265 | accountdisplay->listview->clearSelection(); | ||
266 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
267 | } | ||
268 | else | ||
269 | budgetdisplay->updateBudgetInformation(); | ||
270 | } | ||
271 | |||
272 | void QashMoney::displayTransactionPreferencesDialog () | ||
273 | { | ||
274 | // display a dialog for setting preferences for transactions | ||
275 | TransactionPreferences *td = new TransactionPreferences ( this ); | ||
276 | td->exec (); | ||
277 | if ( transactiondisplay->isVisible() ) | ||
278 | { | ||
279 | // set the account id | ||
280 | int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); | ||
281 | |||
282 | // set children so we can let displayTransfers know if there are children for the selected account | ||
283 | bool children; | ||
284 | if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) | ||
285 | children = TRUE; | ||
286 | else | ||
287 | children = FALSE; | ||
288 | |||
289 | // redisplay transactions incorporating any transaction preference changes | ||
290 | transactiondisplay->listview->clear(); | ||
291 | QString displaytext = "%"; | ||
292 | displaytext.prepend ( transactiondisplay->limitbox->text() ); | ||
293 | if ( transaction->getNumberOfTransactions() > 0 ) | ||
294 | transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext ); | ||
295 | |||
296 | if ( transfer->getNumberOfTransfers() != 0 ) | ||
297 | transfer->displayTransfers ( transactiondisplay->listview, accountid, children ); | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | accountdisplay->listview->clearSelection(); | ||
302 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | void QashMoney::displayAccountPreferencesDialog () | ||
307 | { | ||
308 | // display a dialog for setting preferences for accounts | ||
309 | AccountPreferences *ap = new AccountPreferences ( this ); | ||
310 | ap->exec (); | ||
311 | |||
312 | if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 ) | ||
313 | { | ||
314 | accountdisplay->listview->clear(); | ||
315 | account->displayAccounts ( accountdisplay->listview ); | ||
316 | accountdisplay->listview->clearSelection(); | ||
317 | maintabs->setTabEnabled ( tab_2, FALSE ); | ||
318 | } | ||
319 | changeTabDisplay(); | ||
320 | } | ||
321 | |||
322 | void QashMoney::displayMemoryDialog () | ||
323 | { | ||
324 | // opens a dialog to add, edit and delete memory items | ||
325 | MemoryDialog *md = new MemoryDialog (); | ||
326 | md->exec(); | ||
327 | } | ||
328 | |||
329 | void QashMoney::showTransactions () | ||
330 | { | ||
331 | maintabs->setCurrentPage ( 1 ); | ||
332 | } | ||
333 | |||
334 | void QashMoney::enableOneTouchViewing () | ||
335 | { | ||
336 | if ( preferences->getPreference ( 5 ) == 1 ) | ||
337 | connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); | ||
338 | else | ||
339 | disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); | ||
340 | } | ||
341 | |||
342 | void QashMoney::disableOneTouchViewing () | ||
343 | { | ||
344 | disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); | ||
345 | } | ||
346 | |||
347 | void QashMoney::toggleOneTouchViewing ( bool state ) | ||
348 | { | ||
349 | if ( state == TRUE ) | ||
350 | disableOneTouchViewing(); | ||
351 | else | ||
352 | enableOneTouchViewing(); | ||
353 | } | ||
354 | |||
355 | |||
356 | |||
diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp new file mode 100755 index 0000000..af7d18f --- a/dev/null +++ b/noncore/apps/qashmoney/transaction.cpp | |||
@@ -0,0 +1,274 @@ | |||
1 | // RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN | ||
2 | // FUTURE VERSIONS OF QASHMONEY | ||
3 | |||
4 | // RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION | ||
5 | |||
6 | #include "transaction.h" | ||
7 | #include "account.h" | ||
8 | #include "transactiondisplay.h" | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | |||
12 | extern Account *account; | ||
13 | extern Preferences *preferences; | ||
14 | |||
15 | Transaction::Transaction () | ||
16 | { | ||
17 | tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); | ||
18 | } | ||
19 | |||
20 | Transaction::~Transaction () | ||
21 | { | ||
22 | sqlite_close ( tdb ); | ||
23 | } | ||
24 | |||
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 | { | ||
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 | 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 | |||
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 | { | ||
33 | 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 | amount, cleared, budgetid, lineitemid, transactionid ); | ||
36 | } | ||
37 | |||
38 | void Transaction::deleteTransaction ( int transid ) | ||
39 | { | ||
40 | sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid ); | ||
41 | } | ||
42 | |||
43 | void Transaction::deleteAllTransactions ( int accountid ) | ||
44 | { | ||
45 | sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid ); | ||
46 | } | ||
47 | |||
48 | int Transaction::getAccountID ( int id ) | ||
49 | { | ||
50 | char **results; | ||
51 | sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
52 | return atol ( results [ 1 ] ); | ||
53 | } | ||
54 | |||
55 | int Transaction::getNumberOfTransactions () | ||
56 | { | ||
57 | char **results; | ||
58 | sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL ); | ||
59 | return atoi ( results [ 1 ] ); | ||
60 | } | ||
61 | |||
62 | int Transaction::getNumberOfTransactions ( int accountid ) | ||
63 | { | ||
64 | char **results; | ||
65 | sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid ); | ||
66 | return atol ( results [ 1 ] ); | ||
67 | } | ||
68 | |||
69 | QString Transaction::getPayee ( int id ) | ||
70 | { | ||
71 | char **results; | ||
72 | sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
73 | return results [ 1 ]; | ||
74 | } | ||
75 | |||
76 | QString Transaction::getTransactionDescription ( int id ) | ||
77 | { | ||
78 | char **results; | ||
79 | sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
80 | return results [ 1 ]; | ||
81 | } | ||
82 | |||
83 | QString Transaction::getNumber ( int id ) | ||
84 | { | ||
85 | char **results; | ||
86 | sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
87 | return results [ 1 ]; | ||
88 | } | ||
89 | |||
90 | QString Transaction::getAmount ( int id ) | ||
91 | { | ||
92 | char **results; | ||
93 | sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
94 | return results [ 1 ]; | ||
95 | } | ||
96 | |||
97 | QString Transaction::getAbsoluteAmount ( int id ) | ||
98 | { | ||
99 | char **results; | ||
100 | sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
101 | return results [ 1 ]; | ||
102 | } | ||
103 | |||
104 | int Transaction::getCleared ( int id ) | ||
105 | { | ||
106 | char **results; | ||
107 | sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
108 | QString cleared = results [ 1 ]; | ||
109 | return cleared.toInt(); | ||
110 | } | ||
111 | |||
112 | void Transaction::setCleared ( int id, int cleared ) | ||
113 | { | ||
114 | sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id ); | ||
115 | } | ||
116 | |||
117 | int Transaction::getBudgetID ( int id ) | ||
118 | { | ||
119 | char **results; | ||
120 | sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); | ||
121 | QString budgetid = results [ 1 ]; | ||
122 | return budgetid.toInt(); | ||
123 | } | ||
124 | |||
125 | int Transaction::getLineItemID ( int id ) | ||
126 | { | ||
127 | char **results; | ||
128 | sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); | ||
129 | QString lineitemid = results [ 1 ]; | ||
130 | return lineitemid.toInt(); | ||
131 | } | ||
132 | |||
133 | int Transaction::getDay ( int id ) | ||
134 | { | ||
135 | char **results; | ||
136 | sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
137 | QString daystring = results [ 1 ]; | ||
138 | return daystring.toInt(); | ||
139 | } | ||
140 | |||
141 | int Transaction::getMonth ( int id ) | ||
142 | { | ||
143 | char **results; | ||
144 | sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
145 | QString monthstring = results [ 1 ]; | ||
146 | return monthstring.toInt(); | ||
147 | } | ||
148 | |||
149 | int Transaction::getYear ( int id ) | ||
150 | { | ||
151 | char **results; | ||
152 | sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); | ||
153 | QString yearstring = results [ 1 ]; | ||
154 | return yearstring.toInt(); | ||
155 | } | ||
156 | |||
157 | void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit ) | ||
158 | { | ||
159 | int showcleared = preferences->getPreference ( 3 ); | ||
160 | |||
161 | // select the transactions to display | ||
162 | // two different statements are used based on | ||
163 | // whether we are showing cleared transactions | ||
164 | char **results; | ||
165 | int rows, columns; | ||
166 | if ( showcleared == 0 ) | ||
167 | { | ||
168 | 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 ); | ||
170 | 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 ); | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | 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 ); | ||
177 | 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 ); | ||
179 | } | ||
180 | |||
181 | // iterate through the result list and display each item | ||
182 | int counter = 7; | ||
183 | while ( counter < ( ( rows + 1 ) * columns ) ) | ||
184 | { | ||
185 | // construct the date | ||
186 | //QString daystring = 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 | |||
194 | // construct transaction name, amount, id | ||
195 | QString payee = results [ counter + 3 ]; | ||
196 | QString amount = results [ counter + 4 ]; | ||
197 | QString transferid = results [ counter + 5 ]; | ||
198 | |||
199 | //determine the account name of the child accounts that we're displaying | ||
200 | QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) ); | ||
201 | |||
202 | // fill in values | ||
203 | if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account | ||
204 | { | ||
205 | if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) | ||
206 | ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid); | ||
207 | else | ||
208 | QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid ); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) | ||
213 | ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname ); | ||
214 | else | ||
215 | QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname ); | ||
216 | } | ||
217 | |||
218 | // advance counter | ||
219 | counter = counter + 7; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ) | ||
224 | { | ||
225 | // determine if we are viewing a years, months, or days budget | ||
226 | // we have to pick a different sum for each | ||
227 | char **results; | ||
228 | switch ( viewtype ) | ||
229 | { | ||
230 | case 1: // we are viewing a year | ||
231 | sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, budgetid, lineitemid ); | ||
232 | break; | ||
233 | |||
234 | case 0: // we are viewing a month | ||
235 | sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, month, budgetid, lineitemid ); | ||
236 | break; | ||
237 | } | ||
238 | QString amount = results [ 1 ]; | ||
239 | float total = amount.toFloat(); | ||
240 | amount.setNum ( total, 'f', 2 ); | ||
241 | return amount; | ||
242 | } | ||
243 | |||
244 | QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype ) | ||
245 | { | ||
246 | // determine if we are viewing a years, months, or days budget | ||
247 | // we have to pick a different sum for each | ||
248 | char **results; | ||
249 | switch ( viewtype ) | ||
250 | { | ||
251 | case 1: // we are viewing a year | ||
252 | sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, budgetid ); | ||
253 | break; | ||
254 | |||
255 | case 0: // we are viewing a month | ||
256 | sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, month, budgetid ); | ||
257 | break; | ||
258 | } | ||
259 | QString amount = results [ 1 ]; | ||
260 | float total = amount.toFloat(); | ||
261 | amount.setNum ( total, 'f', 2 ); | ||
262 | return amount; | ||
263 | } | ||
264 | |||
265 | void Transaction::clearBudgetIDs ( int budgetid, int lineitemid ) | ||
266 | { | ||
267 | sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid ); | ||
268 | } | ||
269 | |||
270 | void Transaction::clearBudgetIDs ( int budgetid ) | ||
271 | { | ||
272 | sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid ); | ||
273 | } | ||
274 | |||
diff --git a/noncore/apps/qashmoney/transaction.h b/noncore/apps/qashmoney/transaction.h new file mode 100755 index 0000000..5db011c --- a/dev/null +++ b/noncore/apps/qashmoney/transaction.h | |||
@@ -0,0 +1,69 @@ | |||
1 | #ifndef TRANSACTION_H | ||
2 | #define TRANSACTION_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qlistview.h> | ||
6 | #include <sqlite.h> | ||
7 | |||
8 | #include "preferences.h" | ||
9 | |||
10 | class Transaction | ||
11 | { | ||
12 | public: | ||
13 | |||
14 | Transaction (); | ||
15 | ~Transaction (); | ||
16 | |||
17 | // This function adds a new transaction to the database. It takes the payee, accountid, | ||
18 | // budgetid, number, day, month, year, amount, cleared | ||
19 | void 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 ); | ||
20 | |||
21 | // This updates an already existing transaction | ||
22 | void updateTransaction ( QString, QString, int, int, int, int, float, int, int, int, int ); | ||
23 | |||
24 | // Deletes a transaction. Takes the transid as its parameter | ||
25 | void deleteTransaction ( int ); | ||
26 | |||
27 | // Returns the number of transactions | ||
28 | int getNumberOfTransactions (); | ||
29 | |||
30 | // this is an overloaded function that returns the number of | ||
31 | // transactions for an account | ||
32 | int getNumberOfTransactions ( int ); | ||
33 | |||
34 | // deletes all transactions for the provided accountid | ||
35 | void deleteAllTransactions ( int accountid ); | ||
36 | |||
37 | QString getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ); | ||
38 | QString getActualTotal ( int budgetid, int year, int month, int viewtype ); | ||
39 | |||
40 | // These two functions clear budget ids is either a line item or an entire budget is deleted | ||
41 | void clearBudgetIDs ( int, int ); | ||
42 | void clearBudgetIDs ( int ); | ||
43 | |||
44 | public slots: | ||
45 | |||
46 | void displayTransactions ( QListView *, int, bool, const char * ); | ||
47 | QString getPayee ( int ); | ||
48 | QString getTransactionDescription ( int ); | ||
49 | QString getNumber ( int ); | ||
50 | QString getAmount ( int ); | ||
51 | QString getAbsoluteAmount ( int ); | ||
52 | int getCleared ( int ); | ||
53 | void setCleared ( int id, int cleared ); | ||
54 | int getBudgetID ( int id ); | ||
55 | int getLineItemID ( int id ); | ||
56 | int getDay ( int ); | ||
57 | int getMonth ( int ); | ||
58 | int getYear ( int ); | ||
59 | int getAccountID ( int id ); | ||
60 | |||
61 | private: | ||
62 | |||
63 | sqlite *tdb; | ||
64 | }; | ||
65 | |||
66 | #endif | ||
67 | |||
68 | |||
69 | |||
diff --git a/noncore/apps/qashmoney/transactiondisplay.h b/noncore/apps/qashmoney/transactiondisplay.h new file mode 100755 index 0000000..79f20ba --- a/dev/null +++ b/noncore/apps/qashmoney/transactiondisplay.h | |||
@@ -0,0 +1,79 @@ | |||
1 | #ifndef TRANSACTIONDISPLAY_H | ||
2 | #define TRANSACTIONDISPLAY_H | ||
3 | |||
4 | #include <qlayout.h> | ||
5 | #include <qhbox.h> | ||
6 | #include <qlistview.h> | ||
7 | #include <qpushbutton.h> | ||
8 | #include <qlabel.h> | ||
9 | #include <qlineedit.h> | ||
10 | |||
11 | class TransactionDisplay : public QWidget | ||
12 | { | ||
13 | Q_OBJECT | ||
14 | |||
15 | public: | ||
16 | TransactionDisplay ( QWidget* parent ); | ||
17 | |||
18 | QListView* listview; | ||
19 | QPushButton* newtransaction; | ||
20 | QPushButton* edittransaction; | ||
21 | QPushButton* deletetransaction; | ||
22 | QPushButton* toggletransaction; | ||
23 | QPushButton* viewtransactionnotes; | ||
24 | |||
25 | QLabel *name; | ||
26 | QLabel *balance; | ||
27 | QLineEdit *limitbox; | ||
28 | QLineEdit *amount; | ||
29 | QLineEdit *date; | ||
30 | |||
31 | int getIDColumn (); | ||
32 | |||
33 | public slots: | ||
34 | void setChildren ( bool ); | ||
35 | void setAccountID ( int ); | ||
36 | void showTransactionNotes (); | ||
37 | |||
38 | private slots: | ||
39 | void addTransaction (); | ||
40 | void editTransaction (); | ||
41 | void editTransfer (); | ||
42 | void deleteTransaction (); | ||
43 | void toggleTransaction (); | ||
44 | void checkListViewDelete (); | ||
45 | void checkListViewEdit (); | ||
46 | void checkListViewToggle (); | ||
47 | void saveColumnSize ( int column, int oldsize, int newsize ); | ||
48 | void limitDisplay ( const QString & ); | ||
49 | void showCalculator (); | ||
50 | void showCalendar (); | ||
51 | |||
52 | private: | ||
53 | int accountid, fromaccount, fromparent, toaccount, toparent, day, month, year, transferid; | ||
54 | bool children; | ||
55 | QBoxLayout *layout; | ||
56 | QHBox *firstline; | ||
57 | QHBox *secondline; | ||
58 | void redisplayAccountBalance (); | ||
59 | void updateAndDisplay ( int accountid ); | ||
60 | }; | ||
61 | |||
62 | #endif | ||
63 | |||
64 | #ifndef COLORLISTITEM_H | ||
65 | #define COLORLISTITEM_H | ||
66 | |||
67 | class ColorListItem : public QListViewItem | ||
68 | { | ||
69 | public: | ||
70 | |||
71 | ColorListItem ( QListView *parent ); | ||
72 | ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ); | ||
73 | ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ); | ||
74 | |||
75 | virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); | ||
76 | }; | ||
77 | |||
78 | #endif | ||
79 | |||
diff --git a/noncore/apps/qashmoney/transfer.cpp b/noncore/apps/qashmoney/transfer.cpp new file mode 100755 index 0000000..77cbb4e --- a/dev/null +++ b/noncore/apps/qashmoney/transfer.cpp | |||
@@ -0,0 +1,253 @@ | |||
1 | #include "transfer.h" | ||
2 | #include "account.h" | ||
3 | #include "transactiondisplay.h" | ||
4 | #include <stdlib.h> | ||
5 | #include <iostream.h> | ||
6 | |||
7 | extern Account *account; | ||
8 | extern Preferences *preferences; | ||
9 | |||
10 | Transfer::Transfer () | ||
11 | { | ||
12 | db = sqlite_open ( "qmtransfers.db", 0, 0 ); | ||
13 | } | ||
14 | |||
15 | Transfer::~Transfer () | ||
16 | { | ||
17 | sqlite_close ( db ); | ||
18 | } | ||
19 | |||
20 | void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared ) | ||
21 | { | ||
22 | int nextrowid = -1; | ||
23 | char **results; | ||
24 | sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); | ||
25 | if ( atoi ( results [ 1 ] ) != 0 ) | ||
26 | { | ||
27 | char **results; | ||
28 | sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 ); | ||
29 | nextrowid = ( atoi ( results [ 1 ] ) ) - 1; | ||
30 | } | ||
31 | sqlite_exec_printf ( db, "insert into transfers values ( %i, %i, %i, %i, %i, %i, %i, 0, 0, %.2f, %i, 0, 0, 0, 0, 0, %i );", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, nextrowid ); | ||
32 | } | ||
33 | |||
34 | void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid ) | ||
35 | { | ||
36 | sqlite_exec_printf ( db, "update transfers set fromaccount = %i, fromparent = %i, toaccount = %i, toparent = %i, day = %i, month = %i, year = %i, | ||
37 | amount = %.2f, cleared = %i where transferid = %i;", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, transferid ); | ||
38 | } | ||
39 | |||
40 | void Transfer::deleteTransfer ( int transferid ) | ||
41 | { | ||
42 | sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid ); | ||
43 | } | ||
44 | |||
45 | void Transfer::deleteAllTransfers ( int accountid ) | ||
46 | { | ||
47 | sqlite_exec_printf ( db, "delete from transfers where fromaccount = %i;", 0, 0, 0, accountid ); | ||
48 | sqlite_exec_printf ( db, "delete from transfers where toaccount = %i;", 0, 0, 0, accountid ); | ||
49 | } | ||
50 | |||
51 | int Transfer::getNumberOfTransfers () | ||
52 | { | ||
53 | char **results; | ||
54 | sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); | ||
55 | return atoi ( results [ 1 ] ); | ||
56 | } | ||
57 | |||
58 | int Transfer::getNumberOfTransfers ( int accountid ) | ||
59 | { | ||
60 | char **results; | ||
61 | sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid ); | ||
62 | int transfers = atoi ( results [ 1 ] ); | ||
63 | sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid ); | ||
64 | transfers = transfers + atoi ( results [ 1 ] ); | ||
65 | return transfers; | ||
66 | } | ||
67 | |||
68 | void Transfer::displayTransfers ( QListView *listview, int accountid, bool children ) | ||
69 | { | ||
70 | int showcleared = preferences->getPreference ( 3 ); | ||
71 | |||
72 | // select the from transfers to display | ||
73 | char **results; | ||
74 | int rows, columns; | ||
75 | if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) | ||
76 | { | ||
77 | if ( showcleared == 0 ) | ||
78 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toparent = %i;", &results, &rows, &columns, 0, accountid ); | ||
79 | else | ||
80 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toparent = %i;", &results, &rows, &columns, 0, accountid ); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | if ( showcleared == 0 ) | ||
85 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toaccount = %i;", &results, &rows, &columns, 0, accountid ); | ||
86 | else | ||
87 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toaccount = %i;", &results, &rows, &columns, 0, accountid ); | ||
88 | } | ||
89 | |||
90 | // iterate through the list and display the from items | ||
91 | int counter = 7; | ||
92 | int position = 0; | ||
93 | while ( counter < ( ( rows + 1 ) * columns ) ) | ||
94 | { | ||
95 | // construct the date | ||
96 | QString daystring = results [ counter ]; | ||
97 | int day = daystring.toInt (); | ||
98 | QString monthstring = results [ counter + 1 ]; | ||
99 | int month = monthstring.toInt (); | ||
100 | QString yearstring = results [ counter + 2 ]; | ||
101 | int year = yearstring.toInt (); | ||
102 | QString date = preferences->getDate ( year, month, day ); | ||
103 | |||
104 | //construct the amount and id strings | ||
105 | QString amount = results [ counter + 3 ]; | ||
106 | QString id = results [ counter + 4 ]; | ||
107 | |||
108 | // construct the transaction name | ||
109 | QString transactionname = "FROM: "; | ||
110 | QString temp1 = results [ counter + 5 ]; | ||
111 | transactionname.append ( account->getAccountName ( temp1.toInt() ) ); | ||
112 | |||
113 | QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) ); | ||
114 | |||
115 | // display this transfer | ||
116 | if ( account->getParentAccountID ( accountid ) == -1 ) | ||
117 | { | ||
118 | if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) | ||
119 | ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount ); | ||
120 | else | ||
121 | QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount ); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) | ||
126 | ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id ); | ||
127 | else | ||
128 | QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); | ||
129 | } | ||
130 | |||
131 | counter = counter + 7; | ||
132 | } | ||
133 | |||
134 | // select the to transfers to display | ||
135 | char **toresults; | ||
136 | rows = 0; | ||
137 | columns = 0; | ||
138 | if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) | ||
139 | { | ||
140 | if ( showcleared == 0 ) | ||
141 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromparent = %i;", &toresults, &rows, &columns, 0, accountid ); | ||
142 | else | ||
143 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromparent = %i;", &toresults, &rows, &columns, 0, accountid ); | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | if ( showcleared == 0 ) | ||
148 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromaccount = %i;", &toresults, &rows, &columns, 0, accountid ); | ||
149 | else | ||
150 | sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromaccount = %i;", &toresults, &rows, &columns, 0, accountid ); | ||
151 | } | ||
152 | |||
153 | // iterate through the list and display the from items | ||
154 | counter = 7; | ||
155 | position = 0; | ||
156 | while ( counter < ( ( rows + 1 ) * columns ) ) | ||
157 | { | ||
158 | // construct the date | ||
159 | QString daystring = toresults [ counter ]; | ||
160 | int day = daystring.toInt (); | ||
161 | QString monthstring = toresults [ counter + 1 ]; | ||
162 | int month = monthstring.toInt (); | ||
163 | QString yearstring = toresults [ counter + 2 ]; | ||
164 | int year = yearstring.toInt (); | ||
165 | QString date = preferences->getDate ( year, month, day ); | ||
166 | |||
167 | //construct the amount and id strings | ||
168 | QString amount = toresults [ counter + 3 ]; | ||
169 | amount.prepend ( "-" ); | ||
170 | QString id = toresults [ counter + 4 ]; | ||
171 | |||
172 | // construct the transaction name | ||
173 | QString transactionname = "TO: "; | ||
174 | QString temp1 = toresults [ counter + 6 ]; | ||
175 | transactionname.append ( account->getAccountName ( temp1.toInt() ) ); | ||
176 | |||
177 | QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) ); | ||
178 | |||
179 | // display this transfer | ||
180 | if ( account->getParentAccountID ( accountid ) == -1 ) | ||
181 | { | ||
182 | if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) | ||
183 | ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount ); | ||
184 | else | ||
185 | QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount ); | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) | ||
190 | ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id ); | ||
191 | else | ||
192 | QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); | ||
193 | } | ||
194 | |||
195 | counter = counter + 7; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | int Transfer::getCleared ( int id ) | ||
200 | { | ||
201 | char **results; | ||
202 | sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
203 | return atoi ( results [ 1 ] ); | ||
204 | } | ||
205 | |||
206 | void Transfer::setCleared ( int id, int cleared ) | ||
207 | { | ||
208 | sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id ); | ||
209 | } | ||
210 | |||
211 | int Transfer::getFromAccountID ( int id ) | ||
212 | { | ||
213 | char **results; | ||
214 | sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
215 | return atoi ( results [ 1 ] ); | ||
216 | } | ||
217 | |||
218 | int Transfer::getToAccountID ( int id ) | ||
219 | { | ||
220 | char **results; | ||
221 | sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
222 | return atoi ( results [ 1 ] ); | ||
223 | } | ||
224 | |||
225 | int Transfer::getDay ( int id ) | ||
226 | { | ||
227 | char **results; | ||
228 | sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
229 | return atoi ( results [ 1 ] ); | ||
230 | } | ||
231 | |||
232 | int Transfer::getMonth ( int id ) | ||
233 | { | ||
234 | char **results; | ||
235 | sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
236 | return atoi ( results [ 1 ] ); | ||
237 | } | ||
238 | |||
239 | int Transfer::getYear ( int id ) | ||
240 | { | ||
241 | char **results; | ||
242 | sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
243 | return atoi ( results [ 1 ] ); | ||
244 | } | ||
245 | |||
246 | QString Transfer::getAmount ( int id ) | ||
247 | { | ||
248 | char **results; | ||
249 | sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id ); | ||
250 | return results [ 1 ]; | ||
251 | } | ||
252 | |||
253 | |||
diff --git a/noncore/apps/qashmoney/transfer.h b/noncore/apps/qashmoney/transfer.h new file mode 100755 index 0000000..33dedf4 --- a/dev/null +++ b/noncore/apps/qashmoney/transfer.h | |||
@@ -0,0 +1,51 @@ | |||
1 | #ifndef TRANSFER_H | ||
2 | #define TRANSFER_H | ||
3 | |||
4 | #include <qlistview.h> | ||
5 | #include <qstring.h> | ||
6 | #include <sqlite.h> | ||
7 | |||
8 | #include "preferences.h" | ||
9 | |||
10 | class Transfer | ||
11 | { | ||
12 | public: | ||
13 | |||
14 | Transfer (); | ||
15 | ~Transfer (); | ||
16 | |||
17 | // This function adds a new transfer to the database. It takes the fromaccount, toaccount, | ||
18 | // number, frombudget, tobudget, day, month, year, amount, cleared | ||
19 | void addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared ); | ||
20 | void updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid ); | ||
21 | |||
22 | // Deletes a transfer. Takes the transferid as its parameter | ||
23 | void deleteTransfer ( int ); | ||
24 | |||
25 | // Deletes all transfers for a given accountid | ||
26 | void deleteAllTransfers ( int accountid ); | ||
27 | |||
28 | // Returns the number of checking transfers | ||
29 | int getNumberOfTransfers (); | ||
30 | int getNumberOfTransfers ( int accountid ); | ||
31 | |||
32 | void displayTransfers ( QListView *listview, int accountid, bool children ); | ||
33 | int getCleared ( int id ); | ||
34 | void setCleared ( int id, int cleared ); | ||
35 | int getFromAccountID ( int id ); | ||
36 | int getToAccountID ( int id ); | ||
37 | |||
38 | int getDay ( int id ); | ||
39 | int getMonth ( int id ); | ||
40 | int getYear ( int id ); | ||
41 | QString getAmount ( int id ); | ||
42 | |||
43 | private: | ||
44 | |||
45 | sqlite *db; | ||
46 | }; | ||
47 | |||
48 | #endif | ||
49 | |||
50 | |||
51 | |||