summaryrefslogtreecommitdiff
authorallenforsythe <allenforsythe>2003-05-28 11:49:47 (UTC)
committer allenforsythe <allenforsythe>2003-05-28 11:49:47 (UTC)
commit52047fd3d3f30509d65834747c3a0c5c6760dc01 (patch) (unidiff)
tree136945c2ffff2434ba1e3c8959b5335f5016e8f8
parent7c85b3e98921afa74c7c6a90da4dfd54631c89c5 (diff)
downloadopie-52047fd3d3f30509d65834747c3a0c5c6760dc01.zip
opie-52047fd3d3f30509d65834747c3a0c5c6760dc01.tar.gz
opie-52047fd3d3f30509d65834747c3a0c5c6760dc01.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/CHANGES8
-rwxr-xr-xnoncore/apps/qashmoney/README35
-rwxr-xr-xnoncore/apps/qashmoney/account.cpp9
-rwxr-xr-xnoncore/apps/qashmoney/accountdisplay.cpp19
-rwxr-xr-xnoncore/apps/qashmoney/accountdisplay.h1
-rwxr-xr-xnoncore/apps/qashmoney/budget.cpp3
-rwxr-xr-xnoncore/apps/qashmoney/budgetdisplay.cpp12
-rwxr-xr-xnoncore/apps/qashmoney/budgetdisplay.h1
-rwxr-xr-xnoncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control5
-rwxr-xr-xnoncore/apps/qashmoney/preferences.cpp50
-rwxr-xr-xnoncore/apps/qashmoney/preferences.h3
-rwxr-xr-xnoncore/apps/qashmoney/qashmoney.cpp23
-rwxr-xr-xnoncore/apps/qashmoney/transaction.cpp122
-rwxr-xr-xnoncore/apps/qashmoney/transaction.h3
-rwxr-xr-xnoncore/apps/qashmoney/transactiondisplay.cpp20
-rwxr-xr-xnoncore/apps/qashmoney/transactiondisplay.h1
-rwxr-xr-xnoncore/apps/qashmoney/transfer.cpp61
-rwxr-xr-xnoncore/apps/qashmoney/transfer.h3
-rwxr-xr-xnoncore/apps/qashmoney/transferdialog.cpp2
19 files changed, 276 insertions, 105 deletions
diff --git a/noncore/apps/qashmoney/CHANGES b/noncore/apps/qashmoney/CHANGES
index f17035b..a3ac224 100755
--- a/noncore/apps/qashmoney/CHANGES
+++ b/noncore/apps/qashmoney/CHANGES
@@ -1,24 +1,32 @@
1QashMoney - Budget Software for the Sharp Zaurus 1QashMoney - Budget Software for the Sharp Zaurus
2 2
3CHANGES 3CHANGES
4 4
50.76 - 5/21/03
6
7 Updated postinst file so app will install on new Sharp ROM 3.1
8 Improved algorithm for selecting cleared transaction
9 Fixed budget display bug
10
11----------------------------------------------------------------------------------
12
511/1/02 - Initial release of 0.2 version. Considered stable beta version. 1311/1/02 - Initial release of 0.2 version. Considered stable beta version.
611/16/02 - Release of version 0.3. This is a stable version adding function to 1411/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 15 transfer money between accounts. Several bugs fixes and speed enhancements
8 have been done. 16 have been done.
911/21/02 - 0.31 news tabs working but not yet displaying accounts 1711/21/02 - 0.31 news tabs working but not yet displaying accounts
1012/15/02 - QashMoney gets a complete face lift and now has a date picker. 1812/15/02 - QashMoney gets a complete face lift and now has a date picker.
1112/29/02 - Version 0.41 released. This release fixes more bugs and adds a 1912/29/02 - Version 0.41 released. This release fixes more bugs and adds a
12 function to manage transaction memory items. 20 function to manage transaction memory items.
1312/31/02 - Version 0.42 released. Maintenance release fixing soem rather nasty 2112/31/02 - Version 0.42 released. Maintenance release fixing soem rather nasty
14 bugs that screw up account, transaction, and transfer displays. 22 bugs that screw up account, transaction, and transfer displays.
1503/03/03 - Version 0.60 released. QashMoney has undergone quite a transformation. 2303/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 24 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 25 display nicely in all formats. A new embedded SQL database should make QashMoney
18very extensible. 26very extensible.
194/25/03 - Version 0.70 released. This version includes many new features over 0.60 including 274/25/03 - Version 0.70 released. This version includes many new features over 0.60 including
20currency support for accounts, a function to limit transaction views, and an all new budgeting 28currency support for accounts, a function to limit transaction views, and an all new budgeting
21tab that allows multiple budgets and currency support. 29tab that allows multiple budgets and currency support.
225/7/03 - Version 0.73 released. Few minor bugfixes and feature enhancements. QashMoney now 305/7/03 - Version 0.73 released. Few minor bugfixes and feature enhancements. QashMoney now
23right justifies all numbers and remembers the sate in which you leave the account window. So, if you 31right justifies all numbers and remembers the sate in which you leave the account window. So, if you
24collapse a parent account, it will stay collapsed (even between QashMoney restarts). 32collapse a parent account, it will stay collapsed (even between QashMoney restarts).
diff --git a/noncore/apps/qashmoney/README b/noncore/apps/qashmoney/README
index 1888ce6..ef004f7 100755
--- a/noncore/apps/qashmoney/README
+++ b/noncore/apps/qashmoney/README
@@ -1,94 +1,71 @@
1QashMoney - Budget Software for the Sharp Zaurus 1QashMoney - Budget Software for the Sharp Zaurus
2 2
3README 3README
4 4
5Welcome to the latest version of QashMoney! This app is designed to make your
6budgeting fast, inuitive and easy.
7
8This file lists all the important files in the qashmoney CVS directory and how 5This file lists all the important files in the qashmoney CVS directory and how
9to make the IPK file that goes on the Zaurus. When you checkout the 6to make the IPK file that goes on the Zaurus. When you checkout the
10qashmoney module from CVS, it will create a directory on your hard drive called 7qashmoney-source module from CVS, it will create a directory on your hard drive called
11qashmoney. These instructions assume you are in the directory. 8qashmoney-source. These instructions assume you are in this directory.
12 9
13The first thing you need to do is have all the necessary cross-compile software 10The first thing you need to do is have all the necessary cross-compile software
14and Qtopia installed on your system. I assume you have already done this since 11and Qtopia installed on your system. I assume you have already done this since
15you are downloading CVS, but if not, go to: 12you are downloading CVS, but if not, go to:
16 13
17http://docs.zaurus.com 14http://docs.zaurus.com
18 15
19and download the RPMS that you need for development. 16and download the RPMS that you need for development.
20 17
21You also must have sqlite installed on your system to successfully compile 18You also must have sqlite installed on your system to successfully compile
22QashMoney. Go to: 19QashMoney. Go to:
23 20
24http://www.sqlite.org 21http://www.sqlite.org
25 22
26to download this progam. The SQLite library has already been compiled for the 23to download this progam.
27IPK and is in the 'install' directory. So there is no need to compile SQLite
28for ARM but you can if you want. There are instructions for that on the
29website.
30 24
31After that, set the correct environment variables for the package you 25After that, set the correct environment variables for the package you
32are developing.Two scripts in the qashmoney are used for that purpose: x86.sh 26are developing. Two scripts in the qashmoney-source directory are used for that purpose: x86.sh
33andarm.shIf you are buidling for x86 type: 27and arm.sh. If you are building for x86 type:
34 28
35source x86.sh 29source x86.sh
36 30
37and press enter. To make binaries that run on the Zaurus, type: 31and press enter. To make binaries that run on the Zaurus, type:
38 32
39source arm.sh 33source arm.sh
40 34
41Next, construct the makefile by typing: 35Next, construct the makefile by typing:
42 36
43tmake -o Makefile qashmoney.pro 37tmake -o Makefile qashmoney.pro
44 38
45tmake is Trolltech's program for constructing a typical GNU Makefile from the 39tmake is Trolltech's program for constructing a typical GNU Makefile from the
46project file (qashmoney.pro for this application). If you get an "error: tmake 40project file (qashmoney.pro for this application). If you get an "error: tmake
47command not found", you either don't have all the correct RPMS installed or your 41command not found", you either don't have all the correct RPMS installed or your
48environment variables are not correctly set. If all is well type: 42environment variables are not correctly set. If all is well type:
49 43
50make 44make
51 45
52and the program should be constructed and you will be left with a qashmoney 46and the program should be constructed and you will be left with a qashmoney
53binary in this directory. If you compiled for x86, you can see the application 47binary in this directory. If you compiled for x86, you can see the application
54by using the Qt Virtual Frame Buffer which emulates the Qtopia environment on 48by using the Qt Virtual Frame Buffer which emulates the Qtopia environment on
55your computer. First, copy all the files from the databasefiles directory within the 49your computer. First, copy all the files from the databasefiles directory within the
56qashmoney directory. Otherwise, the program will not function. 50qashmoney directory. Otherwise, the program will not function.
57 51
58To run QashMoney in the Qtopia Virtual Frame Buffer, type: 52To run QashMoney in the Qtopia Virtual Frame Buffer, type:
59 53
60qvfb & 54qvfb &
61./qashmoney -qws 55./qashmoney -qws
62 56
63and QashMoney should appear in the frambuffer. You can use and test qashmoney 57and QashMoney should appear in the frambuffer. You can use and test qashmoney
64here as you would on the Zaurus. 58here as you would on the Zaurus.
65 59
66If you compile the binary file for the Zaurus, another script in this directory 60If you want to compile the app and make the IPK file, check out the qashmoney-build module and see the README file in that module.
67will come in handy. To automagically make the IPK file, type:
68
69su
70./make_ipk
71
72You need to be the root user to set the ownership of the binary and other
73files correctly. The IPK file will appear in the qashmoney directory. Now put
74this file onto the Zaurus and install!
75
76Two other scripts in the directory may be of use. The make_x86 script cleans
77the directory and makes the x86 qashmoney binary automatically. The make_arm
78scripts makes the ARM binary. So you should really only have to type three
79commands the make the IPK file:
80
81./make_arm
82su
83./make_ipk
84 61
85I hope the program can be useful. If you have any questions or comments, please 62I hope the program can be useful. If you have any questions or comments, please
86contact me at qashmoneyman@attbi.com 63contact me at qashmoneyman@attbi.com
87 64
88Thanks! 65Thanks!
89 66
90Allen 67Allen
91 68
92Disclaimer: Altough I've tried to make this application tight and well 69Disclaimer: Altough I've tried to make this application tight and well
93functioning, it comes with absolutely no warranty and I will not be liable for 70functioning, it comes with absolutely no warranty and I will not be liable for
94any damage it may cause. 71any damage it may cause.
diff --git a/noncore/apps/qashmoney/account.cpp b/noncore/apps/qashmoney/account.cpp
index fc2f8c1..28f9ba2 100755
--- a/noncore/apps/qashmoney/account.cpp
+++ b/noncore/apps/qashmoney/account.cpp
@@ -1,372 +1,377 @@
1#include "account.h" 1#include "account.h"
2#include "transaction.h" 2#include "transaction.h"
3#include "transfer.h" 3#include "transfer.h"
4#include "preferences.h" 4#include "preferences.h"
5 5
6#include <qpixmap.h> 6#include <qpixmap.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <iostream.h> 8#include <iostream.h>
9 9
10extern Preferences *preferences; 10extern Preferences *preferences;
11 11
12Account::Account () 12Account::Account ()
13 { 13 {
14 adb = sqlite_open ( "qmaccounts.db", 0, NULL ); 14 adb = sqlite_open ( "qmaccounts.db", 0, NULL );
15 } 15 }
16 16
17Account::~Account () 17Account::~Account ()
18 { 18 {
19 sqlite_close ( adb ); 19 sqlite_close ( adb );
20 } 20 }
21 21
22void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit, 22void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit,
23 int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency ) 23 int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency )
24 { 24 {
25 int r = sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0, 25 sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0,
26 (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency ); 26 (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency );
27 cout << "Results = " << r << endl;
28 } 27 }
29 28
30void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid ) 29void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid )
31 { 30 {
32 sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid ); 31 sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid );
33 } 32 }
34 33
35void Account::deleteAccount ( int accountid ) 34void Account::deleteAccount ( int accountid )
36 { 35 {
37 sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid ); 36 sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid );
38 } 37 }
39 38
40void Account::setAccountExpanded ( int expanded, int accountid ) 39void Account::setAccountExpanded ( int expanded, int accountid )
41 { 40 {
42 sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid ); 41 sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid );
43 } 42 }
44 43
45int Account::getAccountExpanded ( int id ) 44int Account::getAccountExpanded ( int id )
46 { 45 {
47 char **results; 46 char **results;
48 sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id ); 47 sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id );
49 if ( strlen ( results [1] ) == 0 ) 48 if ( strlen ( results [1] ) == 0 )
50 return 0; 49 return 0;
51 else 50 else
52 return atoi ( results [ 1 ] ); 51 return atoi ( results [ 1 ] );
53 } 52 }
54 53
55int Account::getNumberOfAccounts () 54int Account::getNumberOfAccounts ()
56 { 55 {
57 char **results; 56 char **results;
58 sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL ); 57 sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL );
59 return atoi ( results [ 1 ] ); 58 return atoi ( results [ 1 ] );
60 } 59 }
61 60
62int Account::getNumberOfChildAccounts ( int id ) 61int Account::getNumberOfChildAccounts ( int id )
63 { 62 {
64 char **results; 63 char **results;
65 sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id ); 64 sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id );
66 return atoi ( results [ 1 ] ); 65 return atoi ( results [ 1 ] );
67 } 66 }
68 67
69void Account::updateAccountBalance ( int accountid ) 68void Account::updateAccountBalance ( int accountid )
70 { 69 {
71 // Here, we'll get a balance for the transactions in an account 70 // Here, we'll get a balance for the transactions in an account
72 sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); 71 sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
73 int rows, columns; 72 int rows, columns;
74 char **results; 73 char **results;
75 sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid ); 74 sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid );
76 float transactionsbalance = strtod ( results [ 1 ], 0 ); 75 float transactionsbalance = strtod ( results [ 1 ], 0 );
77 sqlite_close ( tdb ); 76 sqlite_close ( tdb );
78 77
79 // next, we'll get a balance for all the transfers from the account 78 // next, we'll get a balance for all the transfers from the account
80 sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); 79 sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL );
81 rows = 0; 80 rows = 0;
82 columns = 0; 81 columns = 0;
83 char **results2; 82 char **results2;
84 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); 83 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid );
85 float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); 84 float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 );
86 85
87 // finally, we'll get a balance for all the transfers into the account 86 // finally, we'll get a balance for all the transfers into the account
88 rows = 0; 87 rows = 0;
89 columns= 0; 88 columns= 0;
90 char **results3; 89 char **results3;
91 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); 90 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid );
92 float totransfersbalance = strtod ( results3 [ 1 ], 0 ); 91 float totransfersbalance = strtod ( results3 [ 1 ], 0 );
93 92
94 sqlite_close ( trdb ); 93 sqlite_close ( trdb );
95 94
96 // calculate and update new balance 95 // calculate and update new balance
97 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, 96 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0,
98 ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); 97 ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid );
99 } 98 }
100 99
101void Account::changeParentAccountBalance ( int parentid ) 100void Account::changeParentAccountBalance ( int parentid )
102 { 101 {
103 // select all child balances that share the parent of the current child account 102 // select all child balances that share the parent of the current child account
104 char **results; 103 char **results;
105 int rows; 104 int rows;
106 sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); 105 sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid );
107 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); 106 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid );
108 } 107 }
109 108
110int Account::getParentAccountID ( int id ) 109int Account::getParentAccountID ( int id )
111 { 110 {
112 char **results; 111 char **results;
113 sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); 112 sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id );
114 return atoi ( results [ 1 ] ); 113 return atoi ( results [ 1 ] );
115 } 114 }
116 115
117int Account::getParentAccountID ( QString accountname ) 116int Account::getParentAccountID ( QString accountname )
118 { 117 {
119 char **results; 118 char **results;
120 sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); 119 sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname );
121 return atoi ( results [ 1 ] ); 120 return atoi ( results [ 1 ] );
122 } 121 }
123 122
124void Account::displayAccounts ( QListView *listview ) 123void Account::displayAccounts ( QListView *listview )
125 { 124 {
126 char **results; 125 char **results;
127 int rows, columns; 126 int rows, columns;
128 sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); 127 sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 );
129 128
130 // determine if we are using currency support 129 // determine if we are using currency support
131 int currency = preferences->getPreference ( 4 ); 130 int currency = preferences->getPreference ( 4 );
132 131
133 // remove all columns from the account display 132 // remove all columns from the account display
134 int counter; 133 int counter;
135 for ( counter = 0; counter <= columns; counter++ ) 134 for ( counter = 0; counter <= columns; counter++ )
136 listview->removeColumn ( 0 ); 135 listview->removeColumn ( 0 );
137 136
138 // add columns to the account display 137 // add columns to the account display
139 listview->addColumn ( "Account", 0 ); 138 listview->addColumn ( "Account", 0 );
140 int columntoalign = 1; 139 int columntoalign = 1;
141 if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it 140 if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it
142 { 141 {
143 listview->addColumn ( "C", 0 ); 142 listview->addColumn ( "C", 0 );
144 columntoalign = 2; 143 columntoalign = 2;
145 } 144 }
146 listview->addColumn ( "Balance", 0 ); 145 listview->addColumn ( "Balance", 0 );
147 listview->addColumn ( "", 0 ); 146 listview->addColumn ( "", 0 );
148 listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); 147 listview->setColumnAlignment ( columntoalign, Qt::AlignRight );
149 counter = 5; 148 counter = 5;
150 int total = ( rows + 1 ) * columns; 149 int total = ( rows + 1 ) * columns;
151 while ( counter < total ) 150 while ( counter < total )
152 { 151 {
153 int accountid = atoi ( results [ counter + 3 ] ); 152 int accountid = atoi ( results [ counter + 3 ] );
154 if ( atoi ( results [ counter + 1 ] ) == -1 ) 153 if ( atoi ( results [ counter + 1 ] ) == -1 )
155 { 154 {
156 QListViewItem *parent = new QListViewItem ( listview ); 155 QListViewItem *parent = new QListViewItem ( listview );
157 parent->setText ( 0, results [ counter ] ); 156 parent->setText ( 0, results [ counter ] );
158 if ( currency == 0 ) 157 if ( currency == 0 )
159 { 158 {
160 parent->setText ( 1, results [ counter + 2 ] ); 159 parent->setText ( 1, results [ counter + 2 ] );
161 parent->setText ( 2, results [ counter + 3 ] ); 160 parent->setText ( 2, results [ counter + 3 ] );
162 } 161 }
163 else 162 else
164 { 163 {
165 if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children 164 if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children
166 { 165 {
167 // create the string we'll use to set the currency pixmap 166 // create the string we'll use to set the currency pixmap
168 QString filename = "/opt/QtPalmtop/pics/flags/"; 167 QString filename = "/opt/QtPalmtop/pics/flags/";
169 QString flag = results [ counter + 4 ]; 168 QString flag = results [ counter + 4 ];
170 filename.append ( flag ); 169 filename.append ( flag );
171 filename.append ( ".png" ); 170 filename.append ( ".png" );
172 parent->setPixmap ( 1, QPixmap ( filename ) ); 171 parent->setPixmap ( 1, QPixmap ( filename ) );
173 parent->setText ( 1, flag ); 172 parent->setText ( 1, flag );
174 } 173 }
175 parent->setText ( 2, results [ counter + 2 ] ); 174 parent->setText ( 2, results [ counter + 2 ] );
176 parent->setText ( 3, results [ counter + 3 ] ); 175 parent->setText ( 3, results [ counter + 3 ] );
177 } 176 }
178 177
179 if ( getAccountExpanded ( accountid ) == 1 ) 178 if ( getAccountExpanded ( accountid ) == 1 )
180 parent->setOpen ( TRUE ); 179 parent->setOpen ( TRUE );
181 180
182 //Start display child accounts for this parent 181 //Start display child accounts for this parent
183 int childcounter = 5; 182 int childcounter = 5;
184 while ( childcounter < total ) 183 while ( childcounter < total )
185 { 184 {
186 if ( atoi ( results [ childcounter + 1 ] ) == accountid ) 185 if ( atoi ( results [ childcounter + 1 ] ) == accountid )
187 { 186 {
188 if ( currency == 0 ) 187 if ( currency == 0 )
189 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] ); 188 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] );
190 else 189 else
191 { 190 {
192 // create the string we'll use to set the currency pixmap 191 // create the string we'll use to set the currency pixmap
193 QString filename = "/opt/QtPalmtop/pics/flags/"; 192 QString filename = "/opt/QtPalmtop/pics/flags/";
194 QString flag = results [ childcounter + 4 ]; 193 QString flag = results [ childcounter + 4 ];
195 filename.append ( flag ); 194 filename.append ( flag );
196 filename.append ( ".png" ); 195 filename.append ( ".png" );
197 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] ); 196 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] );
198 child->setPixmap ( 1, QPixmap ( filename ) ); 197 child->setPixmap ( 1, QPixmap ( filename ) );
199 child->setText ( 1, flag ); 198 child->setText ( 1, flag );
200 } 199 }
201 } 200 }
202 childcounter = childcounter + 5; 201 childcounter = childcounter + 5;
203 } 202 }
204 //End display child accounts 203 //End display child accounts
205 } 204 }
206 counter = counter + 5; 205 counter = counter + 5;
207 } 206 }
208 207
209 // resize all columns appropriately 208 // resize all columns appropriately
210 if ( preferences->getPreference ( 4 ) == 0 ) 209 if ( preferences->getPreference ( 4 ) == 0 )
211 { 210 {
212 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); 211 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
213 listview->setColumnWidthMode ( 0, QListView::Manual ); 212 listview->setColumnWidthMode ( 0, QListView::Manual );
214 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); 213 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
215 listview->setColumnWidthMode ( 1, QListView::Manual ); 214 listview->setColumnWidthMode ( 1, QListView::Manual );
216 listview->setColumnWidthMode ( 2, QListView::Manual ); 215 listview->setColumnWidthMode ( 2, QListView::Manual );
217 } 216 }
218 else 217 else
219 { 218 {
220 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) ); 219 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) );
221 listview->setColumnWidthMode ( 0, QListView::Manual ); 220 listview->setColumnWidthMode ( 0, QListView::Manual );
222 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) ); 221 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) );
223 listview->setColumnWidthMode ( 1, QListView::Manual ); 222 listview->setColumnWidthMode ( 1, QListView::Manual );
224 listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) ); 223 listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) );
225 listview->setColumnWidthMode ( 2, QListView::Manual ); 224 listview->setColumnWidthMode ( 2, QListView::Manual );
226 listview->setColumnWidthMode ( 3, QListView::Manual ); 225 listview->setColumnWidthMode ( 3, QListView::Manual );
227 } 226 }
227
228 // Now reset the column sorting to user preference
229 int column = 0;
230 int direction = 0;
231 preferences->getSortingPreference ( 1, &column, &direction );
232 listview->setSorting ( column, direction );
228 } 233 }
229 234
230int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring ) 235int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring )
231 { 236 {
232 char **results; 237 char **results;
233 int rows, columns, index; 238 int rows, columns, index;
234 index = 0; 239 index = 0;
235 sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL ); 240 sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL );
236 int counter = 1; 241 int counter = 1;
237 int indexcounter = 1; 242 int indexcounter = 1;
238 int total = ( rows + 1 ) * columns; 243 int total = ( rows + 1 ) * columns;
239 while ( counter < total ) 244 while ( counter < total )
240 { 245 {
241 if ( getParentAccountID ( results [ counter ] ) == -1 ) 246 if ( getParentAccountID ( results [ counter ] ) == -1 )
242 { 247 {
243 combobox->insertItem ( results [ counter ], -1 ); 248 combobox->insertItem ( results [ counter ], -1 );
244 if ( strcmp ( results [ counter ], indexstring ) == 0 ) 249 if ( strcmp ( results [ counter ], indexstring ) == 0 )
245 index = indexcounter; 250 index = indexcounter;
246 indexcounter++; 251 indexcounter++;
247 } 252 }
248 counter ++; 253 counter ++;
249 } 254 }
250 return index; 255 return index;
251 } 256 }
252 257
253int Account::getAccountType ( int accountid ) 258int Account::getAccountType ( int accountid )
254 { 259 {
255 char **results; 260 char **results;
256 sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 261 sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
257 return atoi ( results [ 1 ] ); 262 return atoi ( results [ 1 ] );
258 } 263 }
259 264
260int Account::getStatementDay ( int accountid ) 265int Account::getStatementDay ( int accountid )
261 { 266 {
262 char **results; 267 char **results;
263 sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 268 sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
264 return atoi ( results [ 1 ] ); 269 return atoi ( results [ 1 ] );
265 } 270 }
266 271
267int Account::getStatementMonth ( int accountid ) 272int Account::getStatementMonth ( int accountid )
268 { 273 {
269 char **results; 274 char **results;
270 sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 275 sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
271 return atoi ( results [ 1 ] ); 276 return atoi ( results [ 1 ] );
272 } 277 }
273 278
274int Account::getStatementYear ( int accountid ) 279int Account::getStatementYear ( int accountid )
275 { 280 {
276 char **results; 281 char **results;
277 sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 282 sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
278 return atoi ( results [ 1 ] ); 283 return atoi ( results [ 1 ] );
279 } 284 }
280 285
281QString Account::getAccountDescription ( int accountid ) 286QString Account::getAccountDescription ( int accountid )
282 { 287 {
283 char **results; 288 char **results;
284 sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 289 sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
285 return ( QString ) results [ 1 ]; 290 return ( QString ) results [ 1 ];
286 } 291 }
287 292
288QString Account::getCurrencyCode ( int accountid ) 293QString Account::getCurrencyCode ( int accountid )
289 { 294 {
290 char **results; 295 char **results;
291 sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 296 sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
292 return ( QString ) results [ 1 ]; 297 return ( QString ) results [ 1 ];
293 } 298 }
294 299
295QString Account::getAccountName ( int accountid ) 300QString Account::getAccountName ( int accountid )
296 { 301 {
297 char **results; 302 char **results;
298 sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 303 sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
299 return ( QString ) results [ 1 ]; 304 return ( QString ) results [ 1 ];
300 } 305 }
301 306
302QString Account::getAccountBalance ( int accountid ) 307QString Account::getAccountBalance ( int accountid )
303 { 308 {
304 char **results; 309 char **results;
305 sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 310 sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
306 return ( QString ) results [ 1 ]; 311 return ( QString ) results [ 1 ];
307 } 312 }
308 313
309float Account::getAccountCreditLimit ( int accountid ) 314float Account::getAccountCreditLimit ( int accountid )
310 { 315 {
311 char **results; 316 char **results;
312 sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 317 sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid );
313 return strtod ( results [ 1 ], NULL ); 318 return strtod ( results [ 1 ], NULL );
314 } 319 }
315 320
316float Account::getStatementBalance ( int accountid ) 321float Account::getStatementBalance ( int accountid )
317 { 322 {
318 char **results; 323 char **results;
319 sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 324 sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid );
320 return strtod ( results [ 1 ], NULL ); 325 return strtod ( results [ 1 ], NULL );
321 } 326 }
322 327
323GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) 328GreyBackgroundItem::GreyBackgroundItem ( QListView *parent )
324 : QListViewItem ( parent ) 329 : QListViewItem ( parent )
325 { 330 {
326 } 331 }
327 332
328GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) 333GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 )
329 : QListViewItem ( parent, label1, label2, label3 ) 334 : QListViewItem ( parent, label1, label2, label3 )
330 { 335 {
331 } 336 }
332 337
333GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) 338GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
334 : QListViewItem ( parent, label1, label2, label3, label4 ) 339 : QListViewItem ( parent, label1, label2, label3, label4 )
335 { 340 {
336 } 341 }
337 342
338GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) 343GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
339 : QListViewItem ( parent, label1, label2, label3, label4, label5 ) 344 : QListViewItem ( parent, label1, label2, label3, label4, label5 )
340 { 345 {
341 } 346 }
342 347
343void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) 348void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
344 { 349 {
345 QColorGroup _cg ( cg ); 350 QColorGroup _cg ( cg );
346 _cg.setColor ( QColorGroup::Base, Qt::lightGray ); 351 _cg.setColor ( QColorGroup::Base, Qt::lightGray );
347 QListViewItem::paintCell ( p, _cg, column, width, alignment ); 352 QListViewItem::paintCell ( p, _cg, column, width, alignment );
348 } 353 }
349 354
350QStringList Account::getAccountNames () 355QStringList Account::getAccountNames ()
351 { 356 {
352 QStringList accountnames; 357 QStringList accountnames;
353 char **results; 358 char **results;
354 int rows, counter; 359 int rows, counter;
355 sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); 360 sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 );
356 for ( counter = 0; counter < rows; counter++ ) 361 for ( counter = 0; counter < rows; counter++ )
357 accountnames.append ( results [ counter+1 ] ); 362 accountnames.append ( results [ counter+1 ] );
358 return accountnames; 363 return accountnames;
359 } 364 }
360 365
361QStringList Account::getAccountIDs () 366QStringList Account::getAccountIDs ()
362 { 367 {
363 QStringList accountids; 368 QStringList accountids;
364 char **results; 369 char **results;
365 int rows, counter; 370 int rows, counter;
366 sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); 371 sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 );
367 for ( counter = 0; counter < rows; counter++ ) 372 for ( counter = 0; counter < rows; counter++ )
368 accountids.append ( results [ counter+1 ] ); 373 accountids.append ( results [ counter+1 ] );
369 return accountids; 374 return accountids;
370 } 375 }
371 376
372 377
diff --git a/noncore/apps/qashmoney/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp
index b2c0838..64f4ea8 100755
--- a/noncore/apps/qashmoney/accountdisplay.cpp
+++ b/noncore/apps/qashmoney/accountdisplay.cpp
@@ -1,444 +1,449 @@
1#include <qdatetime.h> 1#include <qdatetime.h>
2#include <qmessagebox.h> 2#include <qmessagebox.h>
3#include <qheader.h> 3#include <qheader.h>
4#include <iostream.h>
4 5
5#include "accountdisplay.h" 6#include "accountdisplay.h"
6#include "newaccount.h" 7#include "newaccount.h"
7#include "transaction.h" 8#include "transaction.h"
8#include "transferdialog.h" 9#include "transferdialog.h"
9#include "preferences.h" 10#include "preferences.h"
10#include "transfer.h" 11#include "transfer.h"
11 12
12extern Account *account; 13extern Account *account;
13extern Transaction *transaction; 14extern Transaction *transaction;
14extern Transfer *transfer; 15extern Transfer *transfer;
15extern Preferences *preferences; 16extern Preferences *preferences;
16 17
17AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) 18AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent )
18 { 19 {
19 cleared = 0; 20 cleared = 0;
20 21
21 firstline = new QHBox ( this ); 22 firstline = new QHBox ( this );
22 firstline->setSpacing ( 2 ); 23 firstline->setSpacing ( 2 );
23 24
24 newaccount = new QPushButton ( firstline ); 25 newaccount = new QPushButton ( firstline );
25 newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); 26 newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
26 connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); 27 connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) );
27 28
28 editaccount = new QPushButton ( firstline ); 29 editaccount = new QPushButton ( firstline );
29 editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); 30 editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
30 connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); 31 connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) );
31 32
32 deleteaccount = new QPushButton ( firstline ); 33 deleteaccount = new QPushButton ( firstline );
33 deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); 34 deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
34 connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); 35 connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) );
35 36
36 transferbutton = new QPushButton ( firstline ); 37 transferbutton = new QPushButton ( firstline );
37 transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); 38 transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") );
38 transferbutton->setToggleButton ( TRUE ); 39 transferbutton->setToggleButton ( TRUE );
39 connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); 40 connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) );
40 41
41 listview = new QListView ( this ); 42 listview = new QListView ( this );
42 listview->setAllColumnsShowFocus ( TRUE ); 43 listview->setAllColumnsShowFocus ( TRUE );
43 listview->setShowSortIndicator ( TRUE ); 44 listview->setShowSortIndicator ( TRUE );
44 listview->setRootIsDecorated ( TRUE ); 45 listview->setRootIsDecorated ( TRUE );
45 listview->setMultiSelection ( FALSE ); 46 listview->setMultiSelection ( FALSE );
46 connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); 47 connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) );
47 connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); 48 connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) );
48 49
49 listview->header()->setTracking ( FALSE ); 50 listview->header()->setTracking ( FALSE );
50 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 51 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
51 52 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
53
52 layout = new QVBoxLayout ( this, 2, 5 ); 54 layout = new QVBoxLayout ( this, 2, 5 );
53 layout->addWidget ( firstline ); 55 layout->addWidget ( firstline );
54 layout->addWidget ( listview ); 56 layout->addWidget ( listview );
55 } 57 }
56 58
57void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) 59void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs )
58 { 60 {
59 tab2 = newtab2; 61 tab2 = newtab2;
60 maintabs = newtabs; 62 maintabs = newtabs;
61 } 63 }
62 64
63void AccountDisplay::addAccount () 65void AccountDisplay::addAccount ()
64 { 66 {
65 // initialize local variables 67 // initialize local variables
66 int parentid = 0; 68 int parentid = 0;
67 type = 0; 69 type = 0;
68 QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; 70 QString parentlist [ listview->childCount() + 1 ] [ 3 ] ;
69 71
70 // create new account window for entering data 72 // create new account window for entering data
71 NewAccount *newaccount = new NewAccount ( this ); 73 NewAccount *newaccount = new NewAccount ( this );
72 int width = this->width(); 74 int width = this->width();
73 newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); 75 newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) );
74 newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 76 newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
75 newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); 77 newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) );
76 newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 78 newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
77 newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 79 newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
78 80
79 // if there are no accounts, disable the child check box 81 // if there are no accounts, disable the child check box
80 if ( account->getNumberOfAccounts () == 0 ) 82 if ( account->getNumberOfAccounts () == 0 )
81 newaccount->childcheckbox->setEnabled ( FALSE ); 83 newaccount->childcheckbox->setEnabled ( FALSE );
82 84
83 // if there are accounts, fill up the pulldown menu for 85 // if there are accounts, fill up the pulldown menu for
84 // selecting a parent account. We should only add those parents without transactions 86 // selecting a parent account. We should only add those parents without transactions
85 else 87 else
86 { 88 {
87 int c = 0; 89 int c = 0;
88 QListViewItemIterator it ( listview ); 90 QListViewItemIterator it ( listview );
89 for ( ; it.current(); ++it ) 91 for ( ; it.current(); ++it )
90 { 92 {
91 int id = it.current()->text ( getIDColumn() ).toInt(); 93 int id = it.current()->text ( getIDColumn() ).toInt();
92 // iterate through accountdisplay listview and add parents with no transactions 94 // 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 95 // 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 ) 96 if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 )
95 { 97 {
96 newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); 98 newaccount->childbox->insertItem ( it.current()->text ( 0 ) );
97 parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); 99 parentlist [ c ] [ 0 ] = it.current()->text ( 0 );
98 parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); 100 parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() );
99 parentlist [ c ] [ 2 ] = QString::number ( c ); 101 parentlist [ c ] [ 2 ] = QString::number ( c );
100 c++; 102 c++;
101 } 103 }
102 } 104 }
103 } 105 }
104 106
105 if ( preferences->getPreference ( 4 ) == 0 ) 107 if ( preferences->getPreference ( 4 ) == 0 )
106 newaccount->currencybox->setEnabled ( FALSE ); 108 newaccount->currencybox->setEnabled ( FALSE );
107 109
108 // enter today's date in the date box as default 110 // enter today's date in the date box as default
109 QDate today = QDate::currentDate (); 111 QDate today = QDate::currentDate ();
110 int defaultday = today.day(); 112 int defaultday = today.day();
111 int defaultmonth = today.month(); 113 int defaultmonth = today.month();
112 int defaultyear = today.year(); 114 int defaultyear = today.year();
113 newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 115 newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
114 116
115 //add account information if user pushes OK button 117 //add account information if user pushes OK button
116 if ( newaccount->exec() == QDialog::Accepted ) 118 if ( newaccount->exec() == QDialog::Accepted )
117 { 119 {
118 if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account 120 if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account
119 { 121 {
120 // go through the parentlist we created and determine the parent accountid 122 // 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 123 // 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 124 // with the same name. This function does it all by accountid
123 int counter; 125 int counter;
124 for ( counter = 0; counter < listview->childCount() + 1; counter++ ) 126 for ( counter = 0; counter < listview->childCount() + 1; counter++ )
125 if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) 127 if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() )
126 { 128 {
127 parentid = parentlist [ counter ] [ 1 ].toInt(); 129 parentid = parentlist [ counter ] [ 1 ].toInt();
128 break; 130 break;
129 } 131 }
130 type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types 132 type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types
131 } 133 }
132 else 134 else
133 { 135 {
134 parentid = -1; 136 parentid = -1;
135 type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts 137 type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts
136 } 138 }
137 139
138 // add the new account 140 // add the new account
139 if ( newaccount->getDateEdited () == TRUE ) 141 if ( newaccount->getDateEdited () == TRUE )
140 account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type, 142 account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type,
141 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(), 143 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(),
142 newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); 144 newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() );
143 else 145 else
144 account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, 146 account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type,
145 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, 147 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear,
146 defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); 148 defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() );
147 149
148 if ( parentid != -1 ) 150 if ( parentid != -1 )
149 account->changeParentAccountBalance ( parentid ); 151 account->changeParentAccountBalance ( parentid );
150 152
151 // redisplay accounts 153 // redisplay accounts
152 // this function clears the account display first 154 // this function clears the account display first
153 account->displayAccounts ( listview ); 155 account->displayAccounts ( listview );
154 setToggleButton(); 156 setToggleButton();
155 } 157 }
156 maintabs->setTabEnabled ( tab2, FALSE ); 158 maintabs->setTabEnabled ( tab2, FALSE );
157 } 159 }
158 160
159void AccountDisplay::deleteAccount () 161void AccountDisplay::deleteAccount ()
160 { 162 {
161 if ( listview->selectedItem() == 0 ) 163 if ( listview->selectedItem() == 0 )
162 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); 164 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete.");
163 else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) 165 else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 )
164 QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); 166 QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children");
165 else 167 else
166 { 168 {
167 QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); 169 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 ) 170 if ( mb.exec() == QMessageBox::Ok )
169 { 171 {
170 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); 172 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
171 int parentid = account->getParentAccountID ( accountid ); 173 int parentid = account->getParentAccountID ( accountid );
172 174
173 // delete all the transactions and transfers for the account 175 // delete all the transactions and transfers for the account
174 transaction->deleteAllTransactions ( accountid ); 176 transaction->deleteAllTransactions ( accountid );
175 transfer->deleteAllTransfers ( accountid ); 177 transfer->deleteAllTransfers ( accountid );
176 178
177 // delete the account 179 // delete the account
178 account->deleteAccount ( accountid ); 180 account->deleteAccount ( accountid );
179 181
180 // update account balances 182 // update account balances
181 if ( parentid != -1 ) 183 if ( parentid != -1 )
182 account->changeParentAccountBalance ( parentid ); 184 account->changeParentAccountBalance ( parentid );
183 185
184 //redisplay accounts 186 //redisplay accounts
185 account->displayAccounts ( listview ); 187 account->displayAccounts ( listview );
186 188
187 //remove all the columns from the accountdisplay if there are not any accounts 189 //remove all the columns from the accountdisplay if there are not any accounts
188 if ( account->getNumberOfAccounts() == 0 ) 190 if ( account->getNumberOfAccounts() == 0 )
189 { 191 {
190 int columns = listview->columns(); 192 int columns = listview->columns();
191 int counter; 193 int counter;
192 for ( counter = 0; counter <= columns; counter++ ) 194 for ( counter = 0; counter <= columns; counter++ )
193 listview->removeColumn ( 0 ); 195 listview->removeColumn ( 0 );
194 } 196 }
195 197
196 setToggleButton(); 198 setToggleButton();
197 } 199 }
198 } 200 }
199 maintabs->setTabEnabled ( tab2, FALSE ); 201 maintabs->setTabEnabled ( tab2, FALSE );
200 } 202 }
201 203
202void AccountDisplay::setToggleButton () 204void AccountDisplay::setToggleButton ()
203 { 205 {
204 // iterate through account display and determine how many "transferable" accounts we have 206 // iterate through account display and determine how many "transferable" accounts we have
205 // if there are less than two, disable the transfer button 207 // if there are less than two, disable the transfer button
206 QListViewItemIterator it ( listview ); 208 QListViewItemIterator it ( listview );
207 int counter = 0; 209 int counter = 0;
208 for ( ; it.current(); ++it ) 210 for ( ; it.current(); ++it )
209 { 211 {
210 // add one to counter if we find a transferable account 212 // add one to counter if we find a transferable account
211 if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) 213 if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 )
212 counter++; 214 counter++;
213 } 215 }
214 if ( counter > 1 ) 216 if ( counter > 1 )
215 transferbutton->show(); 217 transferbutton->show();
216 else 218 else
217 transferbutton->hide(); 219 transferbutton->hide();
218 } 220 }
219 221
220void AccountDisplay::accountTransfer ( bool state ) 222void AccountDisplay::accountTransfer ( bool state )
221 { 223 {
222 if ( state == TRUE ) 224 if ( state == TRUE )
223 { 225 {
224 firstaccountid = -1; 226 firstaccountid = -1;
225 secondaccountid = -1; 227 secondaccountid = -1;
226 listview->clearSelection (); 228 listview->clearSelection ();
227 listview->setMultiSelection ( TRUE ); 229 listview->setMultiSelection ( TRUE );
228 disableParentsWithChildren (); 230 disableParentsWithChildren ();
229 connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); 231 connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
230 } 232 }
231 else 233 else
232 { 234 {
233 firstaccountid = -1; 235 firstaccountid = -1;
234 secondaccountid = -1; 236 secondaccountid = -1;
235 listview->clearSelection (); 237 listview->clearSelection ();
236 listview->setMultiSelection ( FALSE ); 238 listview->setMultiSelection ( FALSE );
237 enableAccounts (); 239 enableAccounts ();
238 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); 240 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
239 } 241 }
240 } 242 }
241 243
242void AccountDisplay::getTransferAccounts ( QListViewItem * item ) 244void AccountDisplay::getTransferAccounts ( QListViewItem * item )
243 { 245 {
244 if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children 246 if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children
245 { 247 {
246 if ( firstaccountid == -1 ) 248 if ( firstaccountid == -1 )
247 firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account 249 firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account
248 else 250 else
249 if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first 251 if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first
250 secondaccountid = item->text ( getIDColumn() ).toInt(); 252 secondaccountid = item->text ( getIDColumn() ).toInt();
251 } 253 }
252 254
253 // open transfer window if both accounts are set 255 // open transfer window if both accounts are set
254 if ( firstaccountid != -1 && secondaccountid != -1 ) 256 if ( firstaccountid != -1 && secondaccountid != -1 )
255 { 257 {
256 // construct the transferdialog window 258 // construct the transferdialog window
257 TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); 259 TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid );
258 260
259 // enter today's date in the date box as default 261 // enter today's date in the date box as default
260 QDate today = QDate::currentDate (); 262 QDate today = QDate::currentDate ();
261 int defaultday = today.day(); 263 int defaultday = today.day();
262 int defaultmonth = today.month(); 264 int defaultmonth = today.month();
263 int defaultyear = today.year(); 265 int defaultyear = today.year();
264 td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 266 td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
265 267
266 if ( td->exec() == QDialog::Accepted ) 268 if ( td->exec() == QDialog::Accepted )
267 { 269 {
268 // set the cleared integer if the checkbox is checked 270 // set the cleared integer if the checkbox is checked
269 if ( td->clearedcheckbox->isChecked() == TRUE ) 271 if ( td->clearedcheckbox->isChecked() == TRUE )
270 cleared = 1; 272 cleared = 1;
271 273 cout << "Year from transferdialog = " << td->getYear() << endl;
272 // add the transfer with a new date if its been edited or use the default date 274 // add the transfer with a new date if its been edited or use the default date
273 if ( td->getDateEdited () == TRUE ) 275 if ( td->getDateEdited () == TRUE )
274 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, 276 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared );
275 account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared );
276 else 277 else
277 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, 278 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared );
278 account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared );
279 279
280 // update account balances of both accounts and parents if necessary 280 // update account balances of both accounts and parents if necessary
281 account->updateAccountBalance ( firstaccountid ); 281 account->updateAccountBalance ( firstaccountid );
282 if ( account->getParentAccountID ( firstaccountid ) != -1 ) 282 if ( account->getParentAccountID ( firstaccountid ) != -1 )
283 account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); 283 account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) );
284 account->updateAccountBalance ( secondaccountid ); 284 account->updateAccountBalance ( secondaccountid );
285 if ( account->getParentAccountID ( secondaccountid ) != -1 ) 285 if ( account->getParentAccountID ( secondaccountid ) != -1 )
286 account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); 286 account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) );
287 287
288 // redisplay accounts 288 // redisplay accounts
289 account->displayAccounts ( listview ); 289 account->displayAccounts ( listview );
290 } 290 }
291 else 291 else
292 { 292 {
293 firstaccountid = -1; 293 firstaccountid = -1;
294 secondaccountid = -1; 294 secondaccountid = -1;
295 listview->clearSelection (); 295 listview->clearSelection ();
296 listview->setMultiSelection ( FALSE ); 296 listview->setMultiSelection ( FALSE );
297 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); 297 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
298 } 298 }
299 299
300 // reset the accounts display window 300 // reset the accounts display window
301 transferbutton->toggle(); // toggling this button with clear the window as well 301 transferbutton->toggle(); // toggling this button with clear the window as well
302 302
303 // reenable all the accounts so the transaction tab will be properly set 303 // reenable all the accounts so the transaction tab will be properly set
304 enableAccounts (); 304 enableAccounts ();
305 } 305 }
306 } 306 }
307 307
308void AccountDisplay::disableParentsWithChildren () 308void AccountDisplay::disableParentsWithChildren ()
309 { 309 {
310 // iterate through accountdisplay listview and disable all the parents that have children 310 // iterate through accountdisplay listview and disable all the parents that have children
311 QListViewItemIterator it ( listview ); 311 QListViewItemIterator it ( listview );
312 for ( ; it.current(); ++it ) 312 for ( ; it.current(); ++it )
313 { 313 {
314 if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) 314 if ( it.current()->parent() == 0 && it.current()->childCount() != 0 )
315 it.current()->setSelectable ( FALSE ); 315 it.current()->setSelectable ( FALSE );
316 } 316 }
317 } 317 }
318 318
319void AccountDisplay::enableAccounts () 319void AccountDisplay::enableAccounts ()
320 { 320 {
321 // iterate through accountdisplay listview and enable all accounts 321 // iterate through accountdisplay listview and enable all accounts
322 QListViewItemIterator it ( listview ); 322 QListViewItemIterator it ( listview );
323 for ( ; it.current(); ++it ) 323 for ( ; it.current(); ++it )
324 it.current()->setSelectable ( TRUE ); 324 it.current()->setSelectable ( TRUE );
325 } 325 }
326 326
327void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 327void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize )
328 { 328 {
329 switch ( column ) 329 switch ( column )
330 { 330 {
331 case 0: 331 case 0:
332 if ( listview->columns() == 3 ) 332 if ( listview->columns() == 3 )
333 preferences->changeColumnPreference ( 1, newsize ); 333 preferences->changeColumnPreference ( 1, newsize );
334 else 334 else
335 preferences->changeColumnPreference ( 10, newsize ); 335 preferences->changeColumnPreference ( 10, newsize );
336 break; 336 break;
337 case 1: 337 case 1:
338 if ( listview->columns() == 3 ) 338 if ( listview->columns() == 3 )
339 preferences->changeColumnPreference ( 2, newsize ); 339 preferences->changeColumnPreference ( 2, newsize );
340 else 340 else
341 preferences->changeColumnPreference ( 11, newsize ); 341 preferences->changeColumnPreference ( 11, newsize );
342 break; 342 break;
343 case 2: 343 case 2:
344 preferences->changeColumnPreference ( 12, newsize ); 344 preferences->changeColumnPreference ( 12, newsize );
345 break; 345 break;
346 } 346 }
347 347
348 } 348 }
349 349
350void AccountDisplay::saveSortingPreference ( int column )
351 {
352 preferences->changeSortingPreference ( 1, column );
353 }
354
350int AccountDisplay::getIDColumn () 355int AccountDisplay::getIDColumn ()
351 { 356 {
352 int counter; 357 int counter;
353 int columns = listview->columns(); 358 int columns = listview->columns();
354 for ( counter = 0; counter <= columns; counter++ ) 359 for ( counter = 0; counter <= columns; counter++ )
355 if ( listview->header()->label ( counter ).length() == 0 ) 360 if ( listview->header()->label ( counter ).length() == 0 )
356 return counter; 361 return counter;
357 } 362 }
358 363
359void AccountDisplay::editAccount () 364void AccountDisplay::editAccount ()
360 { 365 {
361 if ( listview->selectedItem() == 0 ) 366 if ( listview->selectedItem() == 0 )
362 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); 367 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit.");
363 else 368 else
364 { 369 {
365 // set the accountid 370 // set the accountid
366 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); 371 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt();
367 372
368 //construct new dialog box 373 //construct new dialog box
369 QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); 374 QDialog *editaccountwindow = new QDialog ( this, 0, TRUE );
370 editaccountwindow->setCaption ( "Edit Account" ); 375 editaccountwindow->setCaption ( "Edit Account" );
371 376
372 // construct the items which will go in the dialog bix 377 // construct the items which will go in the dialog bix
373 QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); 378 QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow );
374 QLineEdit *accountname = new QLineEdit ( editaccountwindow ); 379 QLineEdit *accountname = new QLineEdit ( editaccountwindow );
375 QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); 380 QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow );
376 QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); 381 QLineEdit *accountdescription = new QLineEdit ( editaccountwindow );
377 Currency *currencybox = new Currency ( editaccountwindow ); 382 Currency *currencybox = new Currency ( editaccountwindow );
378 383
379 QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); 384 QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 );
380 layout->addWidget ( namelabel ); 385 layout->addWidget ( namelabel );
381 layout->addWidget ( accountname ); 386 layout->addWidget ( accountname );
382 layout->addWidget ( descriptionlabel ); 387 layout->addWidget ( descriptionlabel );
383 layout->addWidget ( accountdescription ); 388 layout->addWidget ( accountdescription );
384 layout->addWidget ( currencybox ); 389 layout->addWidget ( currencybox );
385 390
386 //set the account name 391 //set the account name
387 accountname->setText ( listview->selectedItem()->text ( 0 ) ); 392 accountname->setText ( listview->selectedItem()->text ( 0 ) );
388 393
389 //set the account description 394 //set the account description
390 accountdescription->setText ( account->getAccountDescription ( accountid ) ); 395 accountdescription->setText ( account->getAccountDescription ( accountid ) );
391 396
392 if ( preferences->getPreference ( 4 ) == 1 ) 397 if ( preferences->getPreference ( 4 ) == 1 )
393 { 398 {
394 // get currency code for this account then iterate through the currency box 399 // get currency code for this account then iterate through the currency box
395 // to find the one we want 400 // to find the one we want
396 int count = currencybox->currencybox->count(); 401 int count = currencybox->currencybox->count();
397 QString code = account->getCurrencyCode ( accountid ); 402 QString code = account->getCurrencyCode ( accountid );
398 for ( int counter = 0; count - 1; counter++ ) 403 for ( int counter = 0; count - 1; counter++ )
399 { 404 {
400 if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 ) 405 if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 )
401 { 406 {
402 currencybox->currencybox->setCurrentItem ( counter ); 407 currencybox->currencybox->setCurrentItem ( counter );
403 break; 408 break;
404 } 409 }
405 } 410 }
406 } 411 }
407 else 412 else
408 currencybox->setEnabled ( FALSE ); 413 currencybox->setEnabled ( FALSE );
409 414
410 //execute the dialog box 415 //execute the dialog box
411 int response = editaccountwindow->exec(); 416 int response = editaccountwindow->exec();
412 if ( response == 1 ) 417 if ( response == 1 )
413 { 418 {
414 account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid ); 419 account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid );
415 account->displayAccounts ( listview ); 420 account->displayAccounts ( listview );
416 421
417 // Try and select the same account that was just edited 422 // Try and select the same account that was just edited
418 QListViewItemIterator it ( listview ); 423 QListViewItemIterator it ( listview );
419 for ( ; it.current(); ++it ) 424 for ( ; it.current(); ++it )
420 { 425 {
421 if ( it.current()->text ( 0 ) == accountname->text() ) 426 if ( it.current()->text ( 0 ) == accountname->text() )
422 { 427 {
423 listview->setSelected ( it.current(), TRUE ); 428 listview->setSelected ( it.current(), TRUE );
424 return; 429 return;
425 } 430 }
426 } 431 }
427 maintabs->setTabEnabled ( tab2, FALSE ); 432 maintabs->setTabEnabled ( tab2, FALSE );
428 } 433 }
429 } 434 }
430 } 435 }
431 436
432void AccountDisplay::setAccountExpanded ( QListViewItem *item ) 437void AccountDisplay::setAccountExpanded ( QListViewItem *item )
433 { 438 {
434 int accountid = item->text ( getIDColumn() ).toInt(); 439 int accountid = item->text ( getIDColumn() ).toInt();
435 account->setAccountExpanded ( 1, accountid ); 440 account->setAccountExpanded ( 1, accountid );
436 } 441 }
437 442
438void AccountDisplay::setAccountCollapsed ( QListViewItem *item ) 443void AccountDisplay::setAccountCollapsed ( QListViewItem *item )
439 { 444 {
440 int accountid = item->text ( getIDColumn() ).toInt(); 445 int accountid = item->text ( getIDColumn() ).toInt();
441 account->setAccountExpanded ( 0, accountid ); 446 account->setAccountExpanded ( 0, accountid );
442 } 447 }
443 448
444 449
diff --git a/noncore/apps/qashmoney/accountdisplay.h b/noncore/apps/qashmoney/accountdisplay.h
index 37bcb34..6d67b9b 100755
--- a/noncore/apps/qashmoney/accountdisplay.h
+++ b/noncore/apps/qashmoney/accountdisplay.h
@@ -1,53 +1,54 @@
1#ifndef ACCOUNTDISPLAY_H 1#ifndef ACCOUNTDISPLAY_H
2#define ACCOUNTDISPLAY_H 2#define ACCOUNTDISPLAY_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qpushbutton.h> 5#include <qpushbutton.h>
6#include <qlayout.h> 6#include <qlayout.h>
7#include <qtabwidget.h> 7#include <qtabwidget.h>
8#include <qhbox.h> 8#include <qhbox.h>
9 9
10class AccountDisplay : public QWidget 10class AccountDisplay : public QWidget
11 { 11 {
12 Q_OBJECT 12 Q_OBJECT
13 13
14 public: 14 public:
15 AccountDisplay ( QWidget *parent ); 15 AccountDisplay ( QWidget *parent );
16 16
17 QHBox *firstline; 17 QHBox *firstline;
18 18
19 QPushButton* newaccount; 19 QPushButton* newaccount;
20 QPushButton* editaccount; 20 QPushButton* editaccount;
21 QPushButton* deleteaccount; 21 QPushButton* deleteaccount;
22 QPushButton* transferbutton; 22 QPushButton* transferbutton;
23 23
24 QListView* listview; 24 QListView* listview;
25 25
26 QBoxLayout *layout; 26 QBoxLayout *layout;
27 27
28 void setTabs ( QWidget *newtab2, QTabWidget *newtabs ); 28 void setTabs ( QWidget *newtab2, QTabWidget *newtabs );
29 int getIDColumn (); 29 int getIDColumn ();
30 void setToggleButton (); 30 void setToggleButton ();
31 31
32 public slots: 32 public slots:
33 void addAccount (); 33 void addAccount ();
34 void editAccount (); 34 void editAccount ();
35 void deleteAccount (); 35 void deleteAccount ();
36 void accountTransfer ( bool state ); 36 void accountTransfer ( bool state );
37 void getTransferAccounts ( QListViewItem * item ); 37 void getTransferAccounts ( QListViewItem * item );
38 void disableParentsWithChildren (); 38 void disableParentsWithChildren ();
39 void enableAccounts (); 39 void enableAccounts ();
40 40
41 private slots: 41 private slots:
42 void saveColumnSize ( int column, int oldsize, int newsize ); 42 void saveColumnSize ( int column, int oldsize, int newsize );
43 void setAccountExpanded ( QListViewItem *item ); 43 void setAccountExpanded ( QListViewItem *item );
44 void setAccountCollapsed ( QListViewItem *item ); 44 void setAccountCollapsed ( QListViewItem *item );
45 void saveSortingPreference ( int column );
45 46
46 private: 47 private:
47 int type, firstaccountid, secondaccountid, cleared; 48 int type, firstaccountid, secondaccountid, cleared;
48 QWidget *tab2; 49 QWidget *tab2;
49 QTabWidget *maintabs; 50 QTabWidget *maintabs;
50}; 51};
51 52
52#endif // ACCOUNTDISPLAY_H 53#endif // ACCOUNTDISPLAY_H
53 54
diff --git a/noncore/apps/qashmoney/budget.cpp b/noncore/apps/qashmoney/budget.cpp
index 42f7eca..9f74078 100755
--- a/noncore/apps/qashmoney/budget.cpp
+++ b/noncore/apps/qashmoney/budget.cpp
@@ -1,221 +1,222 @@
1#include "budget.h" 1#include "budget.h"
2#include "transaction.h" 2#include "transaction.h"
3#include <stdlib.h> 3#include <stdlib.h>
4#include <iostream.h>
4 5
5extern Transaction *transaction; 6extern Transaction *transaction;
6 7
7Budget::Budget () 8Budget::Budget ()
8 { 9 {
9 bdb = sqlite_open ( "qmbudgets.db", 0, NULL ); 10 bdb = sqlite_open ( "qmbudgets.db", 0, NULL );
10 } 11 }
11 12
12Budget::~Budget () 13Budget::~Budget ()
13 { 14 {
14 sqlite_close ( bdb ); 15 sqlite_close ( bdb );
15 } 16 }
16 17
17int Budget::addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview ) 18int 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 {
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 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 char **results;
21 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); 22 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL );
22 QString tablename = "table"; 23 QString tablename = "table";
23 tablename.append ( results [ 1 ] ); 24 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 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 return atoi ( results [ 1 ] );
26 } 27 }
27 28
28void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid ) 29void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid )
29 { 30 {
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 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 }
32 33
33void Budget::deleteBudget ( int budgetid ) 34void Budget::deleteBudget ( int budgetid )
34 { 35 {
35 if ( getNumberOfBudgets() != 0 ) 36 if ( getNumberOfBudgets() != 0 )
36 { 37 {
37 QString tablename = "table"; 38 QString tablename = "table";
38 tablename.append ( QString::number ( budgetid ) ); 39 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, "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 sqlite_exec_printf ( bdb, "drop table '%q';", 0, 0, 0, ( const char* ) tablename );
41 } 42 }
42 } 43 }
43 44
44int Budget::getNumberOfBudgets () 45int Budget::getNumberOfBudgets ()
45 { 46 {
46 char **results; 47 char **results;
47 sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL ); 48 sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL );
48 return atoi ( results [ 1 ] ); 49 return atoi ( results [ 1 ] );
49 } 50 }
50 51
51int Budget::getNumberOfLineItems ( int budgetid ) 52int Budget::getNumberOfLineItems ( int budgetid )
52 { 53 {
53 QString tablename = "table"; 54 QString tablename = "table";
54 tablename.append ( QString::number ( budgetid ) ); 55 tablename.append ( QString::number ( budgetid ) );
55 char **results; 56 char **results;
56 sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); 57 sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename );
57 return atoi ( results [ 1 ] ); 58 return atoi ( results [ 1 ] );
58 } 59 }
59 60
60QStringList* Budget::getBudgetNames () 61QStringList* Budget::getBudgetNames ()
61 { 62 {
62 QStringList *names = new QStringList (); 63 QStringList *names = new QStringList ();
63 char **results; 64 char **results;
64 int rows, counter; 65 int rows, counter;
65 sqlite_get_table ( bdb, "select name from budgets order by name asc;", &results, &rows, NULL, NULL ); 66 sqlite_get_table ( bdb, "select name from budgets;", &results, &rows, NULL, NULL );
66 names->append ( "None" ); 67 names->append ( "None" );
67 for ( counter = 0; counter < rows; counter++ ) 68 for ( counter = 0; counter < rows; counter++ )
68 names->append ( results [ counter+1 ] ); 69 names->append ( results [ counter+1 ] );
69 return names; 70 return names;
70 } 71 }
71 72
72QString Budget::getBudgetName ( int budgetid ) 73QString Budget::getBudgetName ( int budgetid )
73 { 74 {
74 char **results; 75 char **results;
75 sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); 76 sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
76 return ( QString ) results [ 1 ]; 77 return ( QString ) results [ 1 ];
77 } 78 }
78 79
79QString Budget::getBudgetDescription ( int budgetid ) 80QString Budget::getBudgetDescription ( int budgetid )
80 { 81 {
81 char **results; 82 char **results;
82 sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); 83 sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
83 return ( QString ) results [ 1 ]; 84 return ( QString ) results [ 1 ];
84 } 85 }
85 86
86QString Budget::getCurrency ( int budgetid ) 87QString Budget::getCurrency ( int budgetid )
87 { 88 {
88 char **results; 89 char **results;
89 sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); 90 sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
90 return ( QString ) results [ 1 ]; 91 return ( QString ) results [ 1 ];
91 } 92 }
92 93
93QStringList* Budget::getBudgetIDs () 94QStringList* Budget::getBudgetIDs ()
94 { 95 {
95 QStringList *ids = new QStringList (); 96 QStringList *ids = new QStringList ();
96 char **results; 97 char **results;
97 int rows, counter; 98 int rows, counter;
98 sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL ); 99 sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL );
99 for ( counter = 0; counter < rows; counter++ ) 100 for ( counter = 0; counter < rows; counter++ )
100 ids->append ( results [ counter+1 ] ); 101 ids->append ( results [ counter+1 ] );
101 return ids; 102 return ids;
102 } 103 }
103 104
104int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype ) 105int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype )
105 { 106 {
106 QString tablename = "table"; 107 QString tablename = "table";
107 tablename.append ( QString::number ( budgetid ) ); 108 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 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 char **results;
110 sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename ); 111 sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename );
111 return atoi ( results [ 1 ] ); 112 return atoi ( results [ 1 ] );
112 } 113 }
113 114
114void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid ) 115void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid )
115 { 116 {
116 QString tablename = "table"; 117 QString tablename = "table";
117 tablename.append ( QString::number ( budgetid ) ); 118 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 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 }
120 121
121void Budget::deleteLineItem ( int budgetid, int lineitemid ) 122void Budget::deleteLineItem ( int budgetid, int lineitemid )
122 { 123 {
123 QString tablename = "table"; 124 QString tablename = "table";
124 tablename.append ( QString::number ( budgetid ) ); 125 tablename.append ( QString::number ( budgetid ) );
125 sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid ); 126 sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid );
126 } 127 }
127 128
128void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype ) 129void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype )
129 { 130 {
130 QString tablename = "table"; 131 QString tablename = "table";
131 tablename.append ( QString::number ( budgetid ) ); 132 tablename.append ( QString::number ( budgetid ) );
132 char **results; 133 char **results;
133 int rows, columns, counter; 134 int rows, columns, counter;
134 sqlite_get_table_printf ( bdb, "select name, lineitemamount, lineitemid from '%q';", &results, &rows, &columns, NULL, ( const char * ) tablename ); 135 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 int total = ( ( rows + 1 ) * columns );
136 for ( counter = 3; counter < total; counter = counter + 3 ) 137 for ( counter = 3; counter < total; counter = counter + 3 )
137 { 138 {
138 float amount = 0; 139 float amount = 0;
139 if ( viewtype == 0 ) 140 if ( viewtype == 0 )
140 { 141 {
141 QString lineitemamount = results [ counter + 1 ]; 142 QString lineitemamount = results [ counter + 1 ];
142 amount = lineitemamount.toFloat() / 12; 143 amount = lineitemamount.toFloat() / 12;
143 } 144 }
144 else 145 else
145 { 146 {
146 QString lineitemamount = results [ counter + 1 ]; 147 QString lineitemamount = results [ counter + 1 ];
147 amount = lineitemamount.toFloat(); 148 amount = lineitemamount.toFloat();
148 } 149 }
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 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 }
151 } 152 }
152 153
153QStringList Budget::getLineItems ( int budgetid ) 154QStringList Budget::getLineItems ( int budgetid )
154 { 155 {
155 QString tablename = "table"; 156 QString tablename = "table";
156 tablename.append ( QString::number ( budgetid ) ); 157 tablename.append ( QString::number ( budgetid ) );
157 QStringList lineitems; 158 QStringList lineitems;
158 char **results; 159 char **results;
159 int rows, counter; 160 int rows, counter;
160 sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); 161 sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename );
161 for ( counter = 0; counter < rows; counter++ ) 162 for ( counter = 0; counter < rows; counter++ )
162 lineitems.append ( results [ counter + 1 ] ); 163 lineitems.append ( results [ counter + 1 ] );
163 return lineitems; 164 return lineitems;
164 } 165 }
165 166
166QStringList Budget::getLineItemIDs ( int budgetid ) 167QStringList Budget::getLineItemIDs ( int budgetid )
167 { 168 {
168 QString tablename = "table"; 169 QString tablename = "table";
169 tablename.append ( QString::number ( budgetid ) ); 170 tablename.append ( QString::number ( budgetid ) );
170 QStringList lineitemids; 171 QStringList lineitemids;
171 char **results; 172 char **results;
172 int rows, counter; 173 int rows, counter;
173 sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); 174 sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename );
174 for ( counter = 0; counter < rows; counter++ ) 175 for ( counter = 0; counter < rows; counter++ )
175 lineitemids.append ( results [ counter + 1 ] ); 176 lineitemids.append ( results [ counter + 1 ] );
176 return lineitemids; 177 return lineitemids;
177 } 178 }
178 179
179int Budget::getLineItemTime ( int budgetid, int lineitemid ) 180int Budget::getLineItemTime ( int budgetid, int lineitemid )
180 { 181 {
181 QString tablename = "table"; 182 QString tablename = "table";
182 tablename.append ( QString::number ( budgetid ) ); 183 tablename.append ( QString::number ( budgetid ) );
183 char **results; 184 char **results;
184 sqlite_get_table_printf ( bdb, "select type from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char * ) tablename, lineitemid ); 185 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 return atoi ( results [ 1 ] );
186 } 187 }
187 188
188float Budget::getLineItemAmount ( int budgetid, int lineitemid ) 189float Budget::getLineItemAmount ( int budgetid, int lineitemid )
189 { 190 {
190 QString tablename = "table"; 191 QString tablename = "table";
191 tablename.append ( QString::number ( budgetid ) ); 192 tablename.append ( QString::number ( budgetid ) );
192 char **results; 193 char **results;
193 sqlite_get_table_printf ( bdb, "select lineitemamount from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char* ) tablename, lineitemid ); 194 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 return strtod ( results [ 1 ], 0 );
195 } 196 }
196 197
197QString Budget::getBudgetTotal ( int budgetid, int viewtype ) 198QString Budget::getBudgetTotal ( int budgetid, int viewtype )
198 { 199 {
199 QString tablename = "table"; 200 QString tablename = "table";
200 tablename.append ( QString::number ( budgetid ) ); 201 tablename.append ( QString::number ( budgetid ) );
201 // determine if we are viewing a years, months, or days budget 202 // determine if we are viewing a years, months, or days budget
202 // we have to pick a different sum for each 203 // we have to pick a different sum for each
203 char **results; 204 char **results;
204 sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); 205 sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename );
205 QString amount = results [ 1 ]; 206 QString amount = results [ 1 ];
206 float total = amount.toFloat(); 207 float total = amount.toFloat();
207 if ( viewtype == 0 ) 208 if ( viewtype == 0 )
208 total = total / 12; 209 total = total / 12;
209 amount.setNum ( total, 'f', 2 ); 210 amount.setNum ( total, 'f', 2 );
210 return amount; 211 return amount;
211 } 212 }
212 213
213int Budget::getLastAdded () 214int Budget::getLastAdded ()
214 { 215 {
215 char **results; 216 char **results;
216 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); 217 sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL );
217 return atoi ( results [ 1 ] ); 218 return atoi ( results [ 1 ] );
218 } 219 }
219 220
220 221
221 222
diff --git a/noncore/apps/qashmoney/budgetdisplay.cpp b/noncore/apps/qashmoney/budgetdisplay.cpp
index 09f62b2..afc6a2d 100755
--- a/noncore/apps/qashmoney/budgetdisplay.cpp
+++ b/noncore/apps/qashmoney/budgetdisplay.cpp
@@ -1,376 +1,388 @@
1#include <qmessagebox.h> 1#include <qmessagebox.h>
2#include <qheader.h> 2#include <qheader.h>
3#include <qfont.h> 3#include <qfont.h>
4#include <sqlite.h> 4#include <sqlite.h>
5 5
6#include "budgetdisplay.h" 6#include "budgetdisplay.h"
7#include "budget.h" 7#include "budget.h"
8#include "newaccount.h" 8#include "newaccount.h"
9#include "datepicker.h" 9#include "datepicker.h"
10#include "preferences.h" 10#include "preferences.h"
11#include "transaction.h" 11#include "transaction.h"
12 12
13extern Preferences *preferences; 13extern Preferences *preferences;
14extern Budget *budget; 14extern Budget *budget;
15extern Transaction *transaction; 15extern Transaction *transaction;
16 16
17BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent ) 17BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent )
18 { 18 {
19 QFont font = this->font(); 19 QFont font = this->font();
20 font.setWeight ( QFont::Bold ); 20 font.setWeight ( QFont::Bold );
21 21
22 //set the default date to today 22 //set the default date to today
23 newDate = QDate::currentDate (); 23 newDate = QDate::currentDate ();
24 year = newDate.year(); 24 year = newDate.year();
25 month = newDate.month(); 25 month = newDate.month();
26 day = newDate.day(); 26 day = newDate.day();
27 datelabel = preferences->getDate ( year, month ); 27 datelabel = preferences->getDate ( year, month );
28 28
29 setCaption ( "Budget" ); 29 setCaption ( "Budget" );
30 30
31 firstline = new QHBox ( this ); 31 firstline = new QHBox ( this );
32 firstline->setSpacing ( 2 ); 32 firstline->setSpacing ( 2 );
33 secondline = new QHBox ( this ); 33 secondline = new QHBox ( this );
34 secondline->setSpacing ( 10 ); 34 secondline->setSpacing ( 10 );
35 35
36 menu = new QPEMenuBar ( this ); 36 menu = new QPEMenuBar ( this );
37 menu->setFrameStyle ( QFrame::Box | QFrame::Sunken ); 37 menu->setFrameStyle ( QFrame::Box | QFrame::Sunken );
38 budgetmenu = new QPopupMenu ( this ); 38 budgetmenu = new QPopupMenu ( this );
39 lineitemsmenu = new QPopupMenu ( this ); 39 lineitemsmenu = new QPopupMenu ( this );
40 datemenu = new QPopupMenu ( this ); 40 datemenu = new QPopupMenu ( this );
41 menu->insertItem ( "Budget", budgetmenu ); 41 menu->insertItem ( "Budget", budgetmenu );
42 menu->insertItem ( "Line Item", lineitemsmenu ); 42 menu->insertItem ( "Line Item", lineitemsmenu );
43 menu->insertItem ( "Date", datemenu ); 43 menu->insertItem ( "Date", datemenu );
44 budgetmenu->insertItem ( "New", this, SLOT ( newBudget () ), 0, 1 ); 44 budgetmenu->insertItem ( "New", this, SLOT ( newBudget () ), 0, 1 );
45 budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget () ), 0, 2 ); 45 budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget () ), 0, 2 );
46 budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget () ), 0, 3 ); 46 budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget () ), 0, 3 );
47 lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem () ), 0, 1 ); 47 lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem () ), 0, 1 );
48 lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem () ), 0, 2 ); 48 lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem () ), 0, 2 );
49 lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem () ), 0, 3 ); 49 lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem () ), 0, 3 );
50 datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) ); 50 datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) );
51 51
52 budgetbox = new QComboBox ( firstline ); 52 budgetbox = new QComboBox ( firstline );
53 connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) ); 53 connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) );
54 54
55 budgetview = new QComboBox ( firstline ); 55 budgetview = new QComboBox ( firstline );
56 budgetview->insertItem ( "Month" ); 56 budgetview->insertItem ( "Month" );
57 budgetview->insertItem ( "Year" ); 57 budgetview->insertItem ( "Year" );
58 connect ( budgetview, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentView ( int ) ) ); 58 connect ( budgetview, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentView ( int ) ) );
59 59
60 budgeted = new QLabel ( secondline ); 60 budgeted = new QLabel ( secondline );
61 budgeted->setFont ( font ); 61 budgeted->setFont ( font );
62 actual = new QLabel ( secondline ); 62 actual = new QLabel ( secondline );
63 actual->setFont ( font ); 63 actual->setFont ( font );
64 date = new QLabel ( secondline ); 64 date = new QLabel ( secondline );
65 date->setFont ( font ); 65 date->setFont ( font );
66 66
67 listview = new QListView ( this ); 67 listview = new QListView ( this );
68 listview->setAllColumnsShowFocus ( TRUE ); 68 listview->setAllColumnsShowFocus ( TRUE );
69 listview->setShowSortIndicator ( TRUE ); 69 listview->setShowSortIndicator ( TRUE );
70 listview->setRootIsDecorated ( TRUE ); 70 listview->setRootIsDecorated ( TRUE );
71 listview->setMultiSelection ( FALSE ); 71 listview->setMultiSelection ( FALSE );
72 listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13 72 listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13
73 listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14 73 listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14
74 listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15 74 listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15
75 listview->addColumn ( "", 0 ); // line item ids 75 listview->addColumn ( "", 0 ); // line item ids
76 listview->setColumnWidthMode ( 0, QListView::Manual ); 76 listview->setColumnWidthMode ( 0, QListView::Manual );
77 listview->setColumnWidthMode ( 1, QListView::Manual ); 77 listview->setColumnWidthMode ( 1, QListView::Manual );
78 listview->setColumnWidthMode ( 2, QListView::Manual ); 78 listview->setColumnWidthMode ( 2, QListView::Manual );
79 listview->setColumnAlignment ( 1, Qt::AlignRight ); 79 listview->setColumnAlignment ( 1, Qt::AlignRight );
80 listview->setColumnAlignment ( 2, Qt::AlignRight ); 80 listview->setColumnAlignment ( 2, Qt::AlignRight );
81 listview->setColumnWidthMode ( 3, QListView::Manual ); 81 listview->setColumnWidthMode ( 3, QListView::Manual );
82 82
83 listview->header()->setTracking ( FALSE ); 83 listview->header()->setTracking ( FALSE );
84 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 84 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
85 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
86
87 // pull the column sorting preference from the preferences table, and configure the listview accordingly
88 int column = 0;
89 int direction = 0;
90 preferences->getSortingPreference ( 3, &column, &direction );
91 listview->setSorting ( column, direction );
85 92
86 displayBudgetNames(); 93 displayBudgetNames();
87 94
88 layout = new QVBoxLayout ( this, 2, 2 ); 95 layout = new QVBoxLayout ( this, 2, 2 );
89 layout->setMenuBar ( menu ); 96 layout->setMenuBar ( menu );
90 layout->addWidget ( firstline ); 97 layout->addWidget ( firstline );
91 layout->addWidget ( secondline ); 98 layout->addWidget ( secondline );
92 layout->addWidget ( listview ); 99 layout->addWidget ( listview );
93 } 100 }
94 101
95void BudgetDisplay::deleteBudget () 102void BudgetDisplay::deleteBudget ()
96 { 103 {
97 listview->clear(); 104 listview->clear();
98 transaction->clearBudgetIDs ( currentbudget ); 105 transaction->clearBudgetIDs ( currentbudget );
99 budget->deleteBudget ( currentbudget ); 106 budget->deleteBudget ( currentbudget );
100 if ( budgetbox->count() != 0 ) 107 if ( budgetbox->count() != 0 )
101 displayBudgetNames(); 108 displayBudgetNames();
102 checkBudgets(); 109 checkBudgets();
103 } 110 }
104 111
105void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 112void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize )
106 { 113 {
107 switch ( column ) 114 switch ( column )
108 { 115 {
109 case 0: 116 case 0:
110 preferences->changeColumnPreference ( 13, newsize ); 117 preferences->changeColumnPreference ( 13, newsize );
111 break; 118 break;
112 case 1: 119 case 1:
113 preferences->changeColumnPreference ( 14, newsize ); 120 preferences->changeColumnPreference ( 14, newsize );
114 break; 121 break;
115 case 2: 122 case 2:
116 preferences->changeColumnPreference ( 15, newsize ); 123 preferences->changeColumnPreference ( 15, newsize );
117 break; 124 break;
118 } 125 }
119 } 126 }
120 127
128void BudgetDisplay::saveSortingPreference ( int column )
129 {
130 preferences->changeSortingPreference ( 3, column );
131 }
132
121int BudgetDisplay::getIDColumn () 133int BudgetDisplay::getIDColumn ()
122 { 134 {
123 int counter; 135 int counter;
124 int columns = listview->columns(); 136 int columns = listview->columns();
125 for ( counter = 0; counter <= columns; counter++ ) 137 for ( counter = 0; counter <= columns; counter++ )
126 if ( listview->header()->label ( counter ).length() == 0 ) 138 if ( listview->header()->label ( counter ).length() == 0 )
127 return counter; 139 return counter;
128 } 140 }
129 141
130void BudgetDisplay::newBudget () 142void BudgetDisplay::newBudget ()
131 { 143 {
132 constructBudgetWindow(); 144 constructBudgetWindow();
133 int response = nb->exec(); 145 int response = nb->exec();
134 if ( response == 1 ) 146 if ( response == 1 )
135 { 147 {
136 // open a new budget object 148 // open a new budget object
137 int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 ); 149 int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 );
138 transaction->clearBudgetIDs ( addedbudget ); 150 transaction->clearBudgetIDs ( addedbudget );
139 displayBudgetNames(); 151 displayBudgetNames();
140 } 152 }
141 checkBudgets(); 153 checkBudgets();
142 } 154 }
143 155
144void BudgetDisplay::constructBudgetWindow () 156void BudgetDisplay::constructBudgetWindow ()
145 { 157 {
146 //construct and format the new budget window 158 //construct and format the new budget window
147 nb = new QDialog ( this, 0, TRUE ); 159 nb = new QDialog ( this, 0, TRUE );
148 nb->setCaption ( "Budget" ); 160 nb->setCaption ( "Budget" );
149 QLabel *namelabel = new QLabel ( "Budget Name", nb ); 161 QLabel *namelabel = new QLabel ( "Budget Name", nb );
150 budgetname = new QLineEdit ( nb ); 162 budgetname = new QLineEdit ( nb );
151 QLabel *descriptionlabel = new QLabel ( "Description", nb ); 163 QLabel *descriptionlabel = new QLabel ( "Description", nb );
152 description = new QLineEdit ( nb ); 164 description = new QLineEdit ( nb );
153 currencybox = new Currency ( nb ); 165 currencybox = new Currency ( nb );
154 QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 ); 166 QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 );
155 layout->addWidget ( namelabel ); 167 layout->addWidget ( namelabel );
156 layout->addWidget ( budgetname ); 168 layout->addWidget ( budgetname );
157 layout->addWidget ( descriptionlabel ); 169 layout->addWidget ( descriptionlabel );
158 layout->addWidget ( description ); 170 layout->addWidget ( description );
159 layout->addWidget ( currencybox ); 171 layout->addWidget ( currencybox );
160 } 172 }
161 173
162void BudgetDisplay::displayBudgetNames () 174void BudgetDisplay::displayBudgetNames ()
163 { 175 {
164 budgetbox->clear(); 176 budgetbox->clear();
165 if ( budget->getNumberOfBudgets() != 0 ) 177 if ( budget->getNumberOfBudgets() != 0 )
166 { 178 {
167 ids = budget->getBudgetIDs(); 179 ids = budget->getBudgetIDs();
168 for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it ) 180 for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it )
169 { 181 {
170 QString flag = "/opt/QtPalmtop/pics/flags/"; 182 QString flag = "/opt/QtPalmtop/pics/flags/";
171 flag.append ( budget->getCurrency ( (*it).toInt() ) ); 183 flag.append ( budget->getCurrency ( (*it).toInt() ) );
172 flag.append ( ".png" ); 184 flag.append ( ".png" );
173 budgetbox->insertItem ( QPixmap ( flag ), budget->getBudgetName ( (*it).toInt() ) ); 185 budgetbox->insertItem ( QPixmap ( flag ), budget->getBudgetName ( (*it).toInt() ) );
174 } 186 }
175 setCurrentBudget ( 0 ); 187 setCurrentBudget ( 0 );
176 } 188 }
177 else 189 else
178 checkBudgets(); 190 checkBudgets();
179 } 191 }
180 192
181void BudgetDisplay::setCurrentBudget ( int index ) 193void BudgetDisplay::setCurrentBudget ( int index )
182 { 194 {
183 currentbudget = ( ids->operator[] ( index ).toInt() ); 195 currentbudget = ( ids->operator[] ( index ).toInt() );
184 displayLineItems(); 196 displayLineItems();
185 } 197 }
186 198
187void BudgetDisplay::setCurrentView ( int index ) 199void BudgetDisplay::setCurrentView ( int index )
188 { 200 {
189 displayLineItems(); 201 displayLineItems();
190 } 202 }
191 203
192void BudgetDisplay::showCalendar () 204void BudgetDisplay::showCalendar ()
193 { 205 {
194 // create new calendar object and show it 206 // create new calendar object and show it
195 DatePicker *dp = new DatePicker ( QDate ( year, month, day ) ); 207 DatePicker *dp = new DatePicker ( QDate ( year, month, day ) );
196 dp->daylabel->hide(); 208 dp->daylabel->hide();
197 dp->daybox->hide(); 209 dp->daybox->hide();
198 if ( budgetview->currentItem() == 1 ) 210 if ( budgetview->currentItem() == 1 )
199 { 211 {
200 dp->monthlabel->hide(); 212 dp->monthlabel->hide();
201 dp->monthbox->hide(); 213 dp->monthbox->hide();
202 } 214 }
203 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 215 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
204 216
205 int response = dp->exec(); 217 int response = dp->exec();
206 if ( response == 1 ) 218 if ( response == 1 )
207 { 219 {
208 // Set date integers 220 // Set date integers
209 year = dp->getYear(); 221 year = dp->getYear();
210 if ( budgetview->currentItem() == 0 ) 222 if ( budgetview->currentItem() == 0 )
211 month = dp->getMonth(); 223 month = dp->getMonth();
212 else 224 else
213 month = newDate.month(); 225 month = newDate.month();
214 datelabel = preferences->getDate ( year, month ); 226 datelabel = preferences->getDate ( year, month );
215 displayLineItems(); 227 displayLineItems();
216 } 228 }
217 } 229 }
218 230
219void BudgetDisplay::newLineItem () 231void BudgetDisplay::newLineItem ()
220 { 232 {
221 //construct and format the new line item window 233 //construct and format the new line item window
222 constructLineItemWindow (); 234 constructLineItemWindow ();
223 235
224 int response = newlineitem->exec(); 236 int response = newlineitem->exec();
225 if ( response == 1 ) 237 if ( response == 1 )
226 { 238 {
227 float amount; 239 float amount;
228 if ( lineitemtime->currentItem() == 0 ) 240 if ( lineitemtime->currentItem() == 0 )
229 amount = lineitemamount->text().toFloat(); 241 amount = lineitemamount->text().toFloat();
230 else if ( lineitemtime->currentItem() == 1 ) 242 else if ( lineitemtime->currentItem() == 1 )
231 amount = lineitemamount->text().toFloat() * 12; 243 amount = lineitemamount->text().toFloat() * 12;
232 else 244 else
233 amount = lineitemamount->text().toFloat() * 52; 245 amount = lineitemamount->text().toFloat() * 52;
234 int lineitemadded = budget->addLineItem ( currentbudget, lineitemname->text(), amount, lineitemtime->currentItem() ); 246 int lineitemadded = budget->addLineItem ( currentbudget, lineitemname->text(), amount, lineitemtime->currentItem() );
235 transaction->clearBudgetIDs ( currentbudget, lineitemadded ); 247 transaction->clearBudgetIDs ( currentbudget, lineitemadded );
236 displayLineItems(); 248 displayLineItems();
237 } 249 }
238 checkBudgets(); 250 checkBudgets();
239 } 251 }
240 252
241void BudgetDisplay::constructLineItemWindow () 253void BudgetDisplay::constructLineItemWindow ()
242 { 254 {
243 //construct and format the new budget window 255 //construct and format the new budget window
244 newlineitem = new QDialog ( this, 0, TRUE ); 256 newlineitem = new QDialog ( this, 0, TRUE );
245 newlineitem->setCaption ( "Line Item" ); 257 newlineitem->setCaption ( "Line Item" );
246 QLabel *namelabel = new QLabel ( "Line Item Name", newlineitem ); 258 QLabel *namelabel = new QLabel ( "Line Item Name", newlineitem );
247 lineitemname = new QLineEdit ( newlineitem ); 259 lineitemname = new QLineEdit ( newlineitem );
248 QLabel *budgetamountlabel = new QLabel ( "Budget Amount", newlineitem ); 260 QLabel *budgetamountlabel = new QLabel ( "Budget Amount", newlineitem );
249 lineitemamount = new QLineEdit ( newlineitem ); 261 lineitemamount = new QLineEdit ( newlineitem );
250 QLabel *lineitemtimelabel = new QLabel ( "Per:", newlineitem ); 262 QLabel *lineitemtimelabel = new QLabel ( "Per:", newlineitem );
251 lineitemtime = new QComboBox ( newlineitem ); 263 lineitemtime = new QComboBox ( newlineitem );
252 lineitemtime->insertItem ( "Year" ); // type 0 264 lineitemtime->insertItem ( "Year" ); // type 0
253 lineitemtime->insertItem ( "Month" ); // type 1 265 lineitemtime->insertItem ( "Month" ); // type 1
254 lineitemtime->insertItem ( "Week" ); // type 2 266 lineitemtime->insertItem ( "Week" ); // type 2
255 QBoxLayout *layout = new QVBoxLayout ( newlineitem, 2, 2 ); 267 QBoxLayout *layout = new QVBoxLayout ( newlineitem, 2, 2 );
256 layout->addWidget ( namelabel ); 268 layout->addWidget ( namelabel );
257 layout->addWidget ( lineitemname ); 269 layout->addWidget ( lineitemname );
258 layout->addWidget ( budgetamountlabel ); 270 layout->addWidget ( budgetamountlabel );
259 layout->addWidget ( lineitemamount ); 271 layout->addWidget ( lineitemamount );
260 layout->addWidget ( lineitemtimelabel ); 272 layout->addWidget ( lineitemtimelabel );
261 layout->addWidget ( lineitemtime ); 273 layout->addWidget ( lineitemtime );
262 } 274 }
263 275
264void BudgetDisplay::deleteLineItem () 276void BudgetDisplay::deleteLineItem ()
265 { 277 {
266 if ( listview->selectedItem() != 0 ) 278 if ( listview->selectedItem() != 0 )
267 { 279 {
268 int lineitemid = listview->selectedItem()->text ( getIDColumn() ).toInt(); 280 int lineitemid = listview->selectedItem()->text ( getIDColumn() ).toInt();
269 transaction->clearBudgetIDs ( currentbudget, lineitemid ); 281 transaction->clearBudgetIDs ( currentbudget, lineitemid );
270 budget->deleteLineItem ( currentbudget, lineitemid ); 282 budget->deleteLineItem ( currentbudget, lineitemid );
271 displayBudgetNames(); 283 displayBudgetNames();
272 } 284 }
273 else 285 else
274 QMessageBox::warning ( this, "QashMoney", "Please select a line item to delete." ); 286 QMessageBox::warning ( this, "QashMoney", "Please select a line item to delete." );
275 checkBudgets(); 287 checkBudgets();
276 } 288 }
277 289
278void BudgetDisplay::displayLineItems () 290void BudgetDisplay::displayLineItems ()
279 { 291 {
280 listview->clear(); 292 listview->clear();
281 if ( budget->getNumberOfBudgets() != 0 ) 293 if ( budget->getNumberOfBudgets() != 0 )
282 { 294 {
283 QString budgettable = budgetbox->currentText(); 295 QString budgettable = budgetbox->currentText();
284 budgettable.append ( QString::number ( currentbudget ) ); 296 budgettable.append ( QString::number ( currentbudget ) );
285 budget->displayLineItems ( currentbudget, listview, month, year, budgetview->currentItem() ); 297 budget->displayLineItems ( currentbudget, listview, month, year, budgetview->currentItem() );
286 totalactual = transaction->getActualTotal ( currentbudget, year, month, budgetview->currentItem() ); 298 totalactual = transaction->getActualTotal ( currentbudget, year, month, budgetview->currentItem() );
287 totalbudget = budget->getBudgetTotal ( currentbudget, budgetview->currentItem() ); 299 totalbudget = budget->getBudgetTotal ( currentbudget, budgetview->currentItem() );
288 updateBudgetInformation(); 300 updateBudgetInformation();
289 } 301 }
290 } 302 }
291 303
292void BudgetDisplay::checkBudgets () 304void BudgetDisplay::checkBudgets ()
293 { 305 {
294 if ( budget->getNumberOfBudgets() == 0 ) 306 if ( budget->getNumberOfBudgets() == 0 )
295 { 307 {
296 budgetview->setEnabled ( FALSE ); 308 budgetview->setEnabled ( FALSE );
297 budgetmenu->setItemEnabled ( 2, FALSE ); 309 budgetmenu->setItemEnabled ( 2, FALSE );
298 budgetmenu->setItemEnabled ( 3, FALSE ); 310 budgetmenu->setItemEnabled ( 3, FALSE );
299 lineitemsmenu->setItemEnabled ( 1, FALSE ); 311 lineitemsmenu->setItemEnabled ( 1, FALSE );
300 lineitemsmenu->setItemEnabled ( 2, FALSE ); 312 lineitemsmenu->setItemEnabled ( 2, FALSE );
301 lineitemsmenu->setItemEnabled ( 3, FALSE ); 313 lineitemsmenu->setItemEnabled ( 3, FALSE );
302 } 314 }
303 else 315 else
304 { 316 {
305 budgetview->setEnabled ( TRUE ); 317 budgetview->setEnabled ( TRUE );
306 budgetmenu->setItemEnabled ( 2, TRUE ); 318 budgetmenu->setItemEnabled ( 2, TRUE );
307 budgetmenu->setItemEnabled ( 3, TRUE ); 319 budgetmenu->setItemEnabled ( 3, TRUE );
308 lineitemsmenu->setItemEnabled ( 1, TRUE ); 320 lineitemsmenu->setItemEnabled ( 1, TRUE );
309 lineitemsmenu->setItemEnabled ( 2, FALSE ); 321 lineitemsmenu->setItemEnabled ( 2, FALSE );
310 lineitemsmenu->setItemEnabled ( 3, FALSE ); 322 lineitemsmenu->setItemEnabled ( 3, FALSE );
311 323
312 if ( budget->getNumberOfLineItems ( currentbudget ) != 0 ) 324 if ( budget->getNumberOfLineItems ( currentbudget ) != 0 )
313 { 325 {
314 lineitemsmenu->setItemEnabled ( 2, TRUE ); 326 lineitemsmenu->setItemEnabled ( 2, TRUE );
315 lineitemsmenu->setItemEnabled ( 3, TRUE ); 327 lineitemsmenu->setItemEnabled ( 3, TRUE );
316 } 328 }
317 } 329 }
318 } 330 }
319 331
320void BudgetDisplay::updateBudgetInformation () 332void BudgetDisplay::updateBudgetInformation ()
321 { 333 {
322 if ( budgetview->currentItem() == 0 ) 334 if ( budgetview->currentItem() == 0 )
323 { 335 {
324 datelabel = preferences->getDate ( year, month ); 336 datelabel = preferences->getDate ( year, month );
325 datelabel.prepend ( "Date: " ); 337 datelabel.prepend ( "Date: " );
326 date->setText ( datelabel ); 338 date->setText ( datelabel );
327 } 339 }
328 else 340 else
329 date->setText ( QString::number ( year ) ); 341 date->setText ( QString::number ( year ) );
330 342
331 QString budget = "Budget: "; 343 QString budget = "Budget: ";
332 budget.append ( totalbudget ); 344 budget.append ( totalbudget );
333 budgeted->setText ( budget ); 345 budgeted->setText ( budget );
334 346
335 QString actualamount = "Actual: "; 347 QString actualamount = "Actual: ";
336 actualamount.append ( totalactual ); 348 actualamount.append ( totalactual );
337 actual->setText ( actualamount ); 349 actual->setText ( actualamount );
338 } 350 }
339 351
340void BudgetDisplay::editBudget () 352void BudgetDisplay::editBudget ()
341 { 353 {
342 constructBudgetWindow(); 354 constructBudgetWindow();
343 355
344 //set the title 356 //set the title
345 budgetname->setText ( budget->getBudgetName ( currentbudget ) ); 357 budgetname->setText ( budget->getBudgetName ( currentbudget ) );
346 //set the description 358 //set the description
347 description->setText ( budget->getBudgetDescription ( currentbudget ) ); 359 description->setText ( budget->getBudgetDescription ( currentbudget ) );
348 // retrieve the two character currency code then 360 // retrieve the two character currency code then
349 // go through the currencty box and find the code 361 // go through the currencty box and find the code
350 //set the currency box to that index number 362 //set the currency box to that index number
351 int count = currencybox->currencybox->count(); 363 int count = currencybox->currencybox->count();
352 QString code = budget->getCurrency ( currentbudget ); 364 QString code = budget->getCurrency ( currentbudget );
353 for ( int counter = 0; count - 1; counter++ ) 365 for ( int counter = 0; count - 1; counter++ )
354 { 366 {
355 if ( QString::compare (currencybox->currencybox->text ( counter ), code ) == 0 ) 367 if ( QString::compare (currencybox->currencybox->text ( counter ), code ) == 0 )
356 { 368 {
357 currencybox->currencybox->setCurrentItem ( counter ); 369 currencybox->currencybox->setCurrentItem ( counter );
358 break; 370 break;
359 } 371 }
360 } 372 }
361 int response = nb->exec(); 373 int response = nb->exec();
362 if ( response == 1 ) 374 if ( response == 1 )
363 { 375 {
364 budget->updateBudget ( budgetname->text(), description->text(), currencybox->currencybox->currentText(), currentbudget ); 376 budget->updateBudget ( budgetname->text(), description->text(), currencybox->currencybox->currentText(), currentbudget );
365 displayBudgetNames(); 377 displayBudgetNames();
366 } 378 }
367 } 379 }
368 380
369void BudgetDisplay::editLineItem () 381void BudgetDisplay::editLineItem ()
370 { 382 {
371 if ( listview->selectedItem() != 0 ) 383 if ( listview->selectedItem() != 0 )
372 { 384 {
373 constructLineItemWindow(); 385 constructLineItemWindow();
374 386
375 // set the line item name 387 // set the line item name
376 lineitemname->setText ( listview->selectedItem()->text( 0 ) ); 388 lineitemname->setText ( listview->selectedItem()->text( 0 ) );
diff --git a/noncore/apps/qashmoney/budgetdisplay.h b/noncore/apps/qashmoney/budgetdisplay.h
index 25e952a..3976ce1 100755
--- a/noncore/apps/qashmoney/budgetdisplay.h
+++ b/noncore/apps/qashmoney/budgetdisplay.h
@@ -1,85 +1,86 @@
1#ifndef BUDGETDISPLAY_H 1#ifndef BUDGETDISPLAY_H
2#define BUDGETDISPLAY_H 2#define BUDGETDISPLAY_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlineedit.h> 5#include <qlineedit.h>
6#include <qpushbutton.h> 6#include <qpushbutton.h>
7#include <qcombobox.h> 7#include <qcombobox.h>
8#include <qlayout.h> 8#include <qlayout.h>
9#include <qlabel.h> 9#include <qlabel.h>
10#include <qstringlist.h> 10#include <qstringlist.h>
11#include <qdatetime.h> 11#include <qdatetime.h>
12#include <qpe/qpemenubar.h> 12#include <qpe/qpemenubar.h>
13#include <qpopupmenu.h> 13#include <qpopupmenu.h>
14#include <qhbox.h> 14#include <qhbox.h>
15 15
16#include "currency.h" 16#include "currency.h"
17 17
18class BudgetDisplay : public QWidget 18class BudgetDisplay : public QWidget
19 { 19 {
20 Q_OBJECT 20 Q_OBJECT
21 21
22 public: 22 public:
23 BudgetDisplay ( QWidget *parent ); 23 BudgetDisplay ( QWidget *parent );
24 24
25 QPEMenuBar *menu; 25 QPEMenuBar *menu;
26 QPopupMenu *budgetmenu; 26 QPopupMenu *budgetmenu;
27 QPopupMenu *lineitemsmenu; 27 QPopupMenu *lineitemsmenu;
28 QPopupMenu *datemenu; 28 QPopupMenu *datemenu;
29 29
30 QHBox *firstline; 30 QHBox *firstline;
31 QHBox *secondline; 31 QHBox *secondline;
32 32
33 QLabel *budgeted; 33 QLabel *budgeted;
34 QLabel *actual; 34 QLabel *actual;
35 QLabel *date; 35 QLabel *date;
36 36
37 QLineEdit *budgetname; 37 QLineEdit *budgetname;
38 QLineEdit *description; 38 QLineEdit *description;
39 Currency *currencybox; 39 Currency *currencybox;
40 40
41 QLineEdit *lineitemname; 41 QLineEdit *lineitemname;
42 QLineEdit *lineitemamount; 42 QLineEdit *lineitemamount;
43 QComboBox *lineitemtime; 43 QComboBox *lineitemtime;
44 44
45 QListView *listview; 45 QListView *listview;
46 QComboBox *budgetbox; 46 QComboBox *budgetbox;
47 QComboBox *budgetview; 47 QComboBox *budgetview;
48 48
49 QBoxLayout *layout; 49 QBoxLayout *layout;
50 50
51 int getIDColumn (); 51 int getIDColumn ();
52 52
53 public slots: 53 public slots:
54 void displayBudgetNames (); 54 void displayBudgetNames ();
55 void displayLineItems (); 55 void displayLineItems ();
56 void updateBudgetInformation (); 56 void updateBudgetInformation ();
57 57
58 private slots: 58 private slots:
59 void saveColumnSize ( int column, int oldsize, int newsize ); 59 void saveColumnSize ( int column, int oldsize, int newsize );
60 void newBudget (); 60 void newBudget ();
61 void deleteBudget (); 61 void deleteBudget ();
62 void setCurrentBudget ( int ); 62 void setCurrentBudget ( int );
63 void setCurrentView ( int ); 63 void setCurrentView ( int );
64 void showCalendar (); 64 void showCalendar ();
65 void newLineItem (); 65 void newLineItem ();
66 void deleteLineItem (); 66 void deleteLineItem ();
67 void checkBudgets (); 67 void checkBudgets ();
68 void editBudget (); 68 void editBudget ();
69 void editLineItem (); 69 void editLineItem ();
70 void constructBudgetWindow (); 70 void constructBudgetWindow ();
71 void constructLineItemWindow (); 71 void constructLineItemWindow ();
72 void saveSortingPreference ( int column );
72 73
73 private: 74 private:
74 QStringList *names; 75 QStringList *names;
75 QStringList *ids; 76 QStringList *ids;
76 int currentbudget, year, month, day; 77 int currentbudget, year, month, day;
77 QDate newDate; 78 QDate newDate;
78 QString totalbudget, totalactual; 79 QString totalbudget, totalactual;
79 QString datelabel; 80 QString datelabel;
80 QDialog *nb; 81 QDialog *nb;
81 QDialog *newlineitem; 82 QDialog *newlineitem;
82}; 83};
83 84
84#endif // BUDGETDISPLAY_H 85#endif // BUDGETDISPLAY_H
85 86
diff --git a/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control b/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control
index b00e3b1..ec65c0e 100755
--- a/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control
+++ b/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control
@@ -1,7 +1,8 @@
1Package: qashmoney 1Package: qashmoney
2Files: bin/qashmoney pics/qashmony/* pics/qashmony/flags/* apps/Applications/qashmoney.desktop
2Priority: optional 3Priority: optional
3Version: 0.75 4Version: 0.76
4Architecture: arm 5Architecture: arm
5Maintainer: Allen Forsythe qashmoneyman@attbi.com 6Maintainer: Allen Forsythe allen@qashmoney.org
6Section: Applications 7Section: Applications
7Description: QashMoney provides an intuitive and fast way to keep track of your accounts and budgets. 8Description: QashMoney provides an intuitive and fast way to keep track of your accounts and budgets.
diff --git a/noncore/apps/qashmoney/preferences.cpp b/noncore/apps/qashmoney/preferences.cpp
index 9bf64dd..880807a 100755
--- a/noncore/apps/qashmoney/preferences.cpp
+++ b/noncore/apps/qashmoney/preferences.cpp
@@ -1,302 +1,352 @@
1#include "preferences.h" 1#include "preferences.h"
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4Preferences::Preferences () 4Preferences::Preferences ()
5 { 5 {
6 db = sqlite_open ( "qmpreferences.db", 0, NULL ); 6 db = sqlite_open ( "qmpreferences.db", 0, NULL );
7 } 7 }
8 8
9Preferences::~Preferences () 9Preferences::~Preferences ()
10 { 10 {
11 sqlite_close ( db ); 11 sqlite_close ( db );
12 } 12 }
13 13
14void Preferences::addPreferences () 14void Preferences::addPreferences ()
15 { 15 {
16 // This function checks the preferences database for existing preferences and adds 16 // This function checks the preferences database for existing preferences and adds
17 // them if they are not there. First we set up variables. Preferences are always set 17 // them if they are not there. First we set up variables. Preferences are always set
18 // to non-zero numbers because when we check to see if a preference has been 18 // to non-zero numbers because when we check to see if a preference has been
19 // added to the database, the result is zero if it hasn't 19 // added to the database, the result is zero if it hasn't
20 int rows = 0; 20 int rows = 0;
21 int columns = 0; 21 int columns = 0;
22 char **results; 22 char **results;
23 23
24 sqlite_get_table ( db, "select count() from preferences;", &results, 0, 0, 0 ); 24 sqlite_get_table ( db, "select count() from preferences;", &results, 0, 0, 0 );
25 if ( atoi ( results [ 1 ] ) != 7 ) 25 if ( atoi ( results [ 1 ] ) != 7 )
26 { 26 {
27 // dateformat preference 1 = yyyymmdd 2 = yymmdd 3 = mmddyyyy 4 = mmddyy 27 // dateformat preference 1 = yyyymmdd 2 = yymmdd 3 = mmddyyyy 4 = mmddyy
28 // 5 = yyyyddmm 6 = yyddmm 7 = ddmmyyyy 8 = ddmmyy 28 // 5 = yyyyddmm 6 = yyddmm 7 = ddmmyyyy 8 = ddmmyy
29 sqlite_get_table ( db, "select preference from preferences where id = 1;", &results, &rows, &columns, 0 ); 29 sqlite_get_table ( db, "select preference from preferences where id = 1;", &results, &rows, &columns, 0 );
30 if ( rows == 0 ) 30 if ( rows == 0 )
31 sqlite_exec ( db, "insert into preferences values ( 4, 'dateformat', 0, 0, 0, NULL );", 0, 0, 0 ); 31 sqlite_exec ( db, "insert into preferences values ( 4, 'dateformat', 0, 0, 0, NULL );", 0, 0, 0 );
32 32
33 // dateseparator preference 1 = / ( forward slash ) 2 = - ( dash ) 3 = . ( period ) 33 // dateseparator preference 1 = / ( forward slash ) 2 = - ( dash ) 3 = . ( period )
34 rows = 0; 34 rows = 0;
35 sqlite_get_table ( db, "select preference from preferences where id = 2;", &results, &rows, &columns, 0 ); 35 sqlite_get_table ( db, "select preference from preferences where id = 2;", &results, &rows, &columns, 0 );
36 if ( rows == 0 ) 36 if ( rows == 0 )
37 sqlite_exec ( db, "insert into preferences values ( 1, 'dateseparator', 0, 0, 0, NULL );", 0, 0, 0 ); 37 sqlite_exec ( db, "insert into preferences values ( 1, 'dateseparator', 0, 0, 0, NULL );", 0, 0, 0 );
38 38
39 // showclearedtransactions preference 0 = no 1 = yes 39 // showclearedtransactions preference 0 = no 1 = yes
40 rows = 0; 40 rows = 0;
41 sqlite_get_table ( db, "select preference from preferences where id = 3;", &results, &rows, &columns, 0 ); 41 sqlite_get_table ( db, "select preference from preferences where id = 3;", &results, &rows, &columns, 0 );
42 if ( rows == 0 ) 42 if ( rows == 0 )
43 sqlite_exec ( db, "insert into preferences values ( 0, 'showclearedtransactions', 0, 0, 0, NULL );", 0, 0, 0 ); 43 sqlite_exec ( db, "insert into preferences values ( 0, 'showclearedtransactions', 0, 0, 0, NULL );", 0, 0, 0 );
44 44
45 // enable currency support preference 0 = no 1 = yes 45 // enable currency support preference 0 = no 1 = yes
46 rows = 0; 46 rows = 0;
47 sqlite_get_table ( db, "select preference from preferences where id = 4;", &results, &rows, &columns, 0 ); 47 sqlite_get_table ( db, "select preference from preferences where id = 4;", &results, &rows, &columns, 0 );
48 if ( rows == 0 ) 48 if ( rows == 0 )
49 sqlite_exec ( db, "insert into preferences values ( 0, 'enablecurrencysupport', 0, 0, 0, NULL );", 0, 0, 0 ); 49 sqlite_exec ( db, "insert into preferences values ( 0, 'enablecurrencysupport', 0, 0, 0, NULL );", 0, 0, 0 );
50 50
51 // one touch account viewing preference 0 = no 1 = yes 51 // one touch account viewing preference 0 = no 1 = yes
52 rows = 0; 52 rows = 0;
53 sqlite_get_table ( db, "select preference from preferences where id = 5;", &results, &rows, &columns, 0 ); 53 sqlite_get_table ( db, "select preference from preferences where id = 5;", &results, &rows, &columns, 0 );
54 if ( rows == 0 ) 54 if ( rows == 0 )
55 sqlite_exec ( db, "insert into preferences values ( 0, 'onetouchviewing', 0, 0, 0, NULL );", 0, 0, 0 ); 55 sqlite_exec ( db, "insert into preferences values ( 0, 'onetouchviewing', 0, 0, 0, NULL );", 0, 0, 0 );
56 56
57 // exclude transfers from limit view 0 = no 1 = yes 57 // exclude transfers from limit view 0 = no 1 = yes
58 rows = 0; 58 rows = 0;
59 sqlite_get_table ( db, "select preference from preferences where id = 6;", &results, &rows, &columns, 0 ); 59 sqlite_get_table ( db, "select preference from preferences where id = 6;", &results, &rows, &columns, 0 );
60 if ( rows == 0 ) 60 if ( rows == 0 )
61 sqlite_exec ( db, "insert into preferences values ( 0, 'excludetransfersfromlimit', 0, 0, 0, NULL );", 0, 0, 0 ); 61 sqlite_exec ( db, "insert into preferences values ( 0, 'excludetransfersfromlimit', 0, 0, 0, NULL );", 0, 0, 0 );
62 62
63 // limit number of transactions to 0 = 14 days 1 = 30 days, 2 = 90 days, 3 = 180 days, 4 = 365 days 5 = all 63 // limit number of transactions to 0 = 14 days 1 = 30 days, 2 = 90 days, 3 = 180 days, 4 = 365 days 5 = all
64 rows = 0; 64 rows = 0;
65 sqlite_get_table ( db, "select preference from preferences where id = 7;", &results, &rows, &columns, 0 ); 65 sqlite_get_table ( db, "select preference from preferences where id = 7;", &results, &rows, &columns, 0 );
66 if ( rows == 0 ) 66 if ( rows == 0 )
67 sqlite_exec ( db, "insert into preferences values ( 0, 'limittransactions', 0, 0, 0, NULL );", 0, 0, 0 ); 67 sqlite_exec ( db, "insert into preferences values ( 0, 'limittransactions', 0, 0, 0, NULL );", 0, 0, 0 );
68 } 68 }
69 } 69 }
70 70
71void Preferences::initializeColumnPreferences () 71void Preferences::initializeColumnPreferences ()
72 { 72 {
73 int rows = 0; 73 int rows = 0;
74 int columns = 0; 74 int columns = 0;
75 char **results; 75 char **results;
76 76
77 // initialize accountname column width 77 // initialize accountname column width
78 sqlite_get_table ( db, "select width from columns where id = 1;", &results, &rows, &columns, 0 ); 78 sqlite_get_table ( db, "select width from columns where id = 1;", &results, &rows, &columns, 0 );
79 if ( rows == 0 ) 79 if ( rows == 0 )
80 sqlite_exec ( db, "insert into columns values ( 'accountname', 90, 0, 0, 0, NULL );", 0, 0, 0 ); 80 sqlite_exec ( db, "insert into columns values ( 'accountname', 90, 0, 0, 0, NULL );", 0, 0, 0 );
81 81
82 // initialize accountbalance column width 82 // initialize accountbalance column width
83 sqlite_get_table ( db, "select width from columns where id = 2;", &results, &rows, &columns, 0 ); 83 sqlite_get_table ( db, "select width from columns where id = 2;", &results, &rows, &columns, 0 );
84 if ( rows == 0 ) 84 if ( rows == 0 )
85 sqlite_exec ( db, "insert into columns values ( 'accountbalance', 90, 0, 0, 0, NULL );", 0, 0, 0 ); 85 sqlite_exec ( db, "insert into columns values ( 'accountbalance', 90, 0, 0, 0, NULL );", 0, 0, 0 );
86 86
87 // initialize transactiondate column width 87 // initialize transactiondate column width
88 sqlite_get_table ( db, "select width from columns where id = 3;", &results, &rows, &columns, 0 ); 88 sqlite_get_table ( db, "select width from columns where id = 3;", &results, &rows, &columns, 0 );
89 if ( rows == 0 ) 89 if ( rows == 0 )
90 sqlite_exec ( db, "insert into columns values ( 'normaltransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 90 sqlite_exec ( db, "insert into columns values ( 'normaltransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 );
91 91
92 // initialize transactionname column width 92 // initialize transactionname column width
93 sqlite_get_table ( db, "select width from columns where id = 4;", &results, &rows, &columns, 0 ); 93 sqlite_get_table ( db, "select width from columns where id = 4;", &results, &rows, &columns, 0 );
94 if ( rows == 0 ) 94 if ( rows == 0 )
95 sqlite_exec ( db, "insert into columns values ( 'normaltransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); 95 sqlite_exec ( db, "insert into columns values ( 'normaltransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 );
96 96
97 // initialize transactionamount column width 97 // initialize transactionamount column width
98 sqlite_get_table ( db, "select width from columns where id = 5;", &results, &rows, &columns, 0 ); 98 sqlite_get_table ( db, "select width from columns where id = 5;", &results, &rows, &columns, 0 );
99 if ( rows == 0 ) 99 if ( rows == 0 )
100 sqlite_exec ( db, "insert into columns values ( 'normaltransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 100 sqlite_exec ( db, "insert into columns values ( 'normaltransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
101 101
102 // initialize transactiondate column width 102 // initialize transactiondate column width
103 sqlite_get_table ( db, "select width from columns where id = 6;", &results, &rows, &columns, 0 ); 103 sqlite_get_table ( db, "select width from columns where id = 6;", &results, &rows, &columns, 0 );
104 if ( rows == 0 ) 104 if ( rows == 0 )
105 sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 105 sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 );
106 106
107 // initialize transactionname column width 107 // initialize transactionname column width
108 sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 ); 108 sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 );
109 if ( rows == 0 ) 109 if ( rows == 0 )
110 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); 110 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 );
111 111
112 // initialize transactionamount column width 112 // initialize transactionamount column width
113 sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 ); 113 sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 );
114 if ( rows == 0 ) 114 if ( rows == 0 )
115 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 115 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
116 116
117 // initialize transactionaccount column width 117 // initialize transactionaccount column width
118 sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 ); 118 sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 );
119 if ( rows == 0 ) 119 if ( rows == 0 )
120 sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 120 sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
121 121
122 // initialize account name with currency column width 122 // initialize account name with currency column width
123 sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 ); 123 sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 );
124 if ( rows == 0 ) 124 if ( rows == 0 )
125 sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 ); 125 sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 );
126 126
127 // initialize account currency column width 127 // initialize account currency column width
128 sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 ); 128 sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 );
129 if ( rows == 0 ) 129 if ( rows == 0 )
130 sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 ); 130 sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 );
131 131
132 // initialize account balance with currency column width 132 // initialize account balance with currency column width
133 sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 ); 133 sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 );
134 if ( rows == 0 ) 134 if ( rows == 0 )
135 sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 135 sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 );
136 136
137 // initialize budget line item column 137 // initialize budget line item column
138 sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 ); 138 sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 );
139 if ( rows == 0 ) 139 if ( rows == 0 )
140 sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 140 sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 );
141 141
142 // initialize budget budget column 142 // initialize budget budget column
143 sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 ); 143 sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 );
144 if ( rows == 0 ) 144 if ( rows == 0 )
145 sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 145 sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 );
146 146
147 // initialize budget actual column 147 // initialize budget actual column
148 sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 ); 148 sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 );
149 if ( rows == 0 ) 149 if ( rows == 0 )
150 sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 150 sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 );
151 } 151 }
152 152
153void Preferences::initializeSortingPreferences ()
154 {
155 int rows = 0;
156 int columns = 0;
157 char **results;
158
159 if ( sqlite_get_table ( db, "select count() from sorting;", 0, 0, 0, 0 ) != 0 )
160 sqlite_exec ( db, "create table sorting ( listbox, column, direction, id integer primary key );", 0, 0, 0 );
161
162 // initialize account listbox sorting. Set direction = 1 here so ascending sort is default.
163 sqlite_get_table ( db, "select column, direction from sorting where id = 1;", &results, &rows, &columns, 0 );
164 if ( rows == 0 )
165 sqlite_exec ( db, "insert into sorting values ( 'accounts', 0, 1, NULL );", 0, 0, 0 );
166
167 // initialize transaction listbox sorting
168 sqlite_get_table ( db, "select column, direction from sorting where id = 2;", &results, &rows, &columns, 0);
169 if ( rows == 0 )
170 sqlite_exec ( db, "insert into sorting values ( 'transactions', 0, 1, NULL );", 0, 0, 0 );
171
172 // initialize budgets listbox sorting
173 sqlite_get_table ( db, "select column, direction from sorting where id = 3;", & results, &rows, &columns, 0 );
174 if ( rows == 0 )
175 sqlite_exec ( db, "insert into sorting values ( 'budgets', 0, 1, NULL );", 0, 0, 0 );
176 }
177
153void Preferences::changeColumnPreference ( int id, int width ) 178void Preferences::changeColumnPreference ( int id, int width )
154 { 179 {
155 sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id ); 180 sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id );
156 } 181 }
157 182
158int Preferences::getColumnPreference ( int id ) 183int Preferences::getColumnPreference ( int id )
159 { 184 {
160 char **results; 185 char **results;
161 sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id ); 186 sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id );
162 return atoi ( results [ 1 ] ); 187 return atoi ( results [ 1 ] );
163 } 188 }
164 189
190void Preferences::changeSortingPreference ( int id, int column )
191 {
192 int pColumn = 0; // column setting coming from the prefs object
193 int pDirection = 0; // direction setting coming from the prefs object
194
195 // because there appears to be no way to query the QT header object directly for it's current sort settings, we have
196 // to maintain track of them ourselves. So start by pulling the current saved setting for this view.
197 getSortingPreference ( id, &pColumn, &pDirection );
198
199 // if the current saved column == the new column, then the user wants to toggle the sort order.
200 // otherwise we behave like QT does by default, which is to select the new column and default to an ascending sort.
201 if ( column == pColumn )
202 sqlite_exec_printf ( db, "update sorting set direction = %i where id = %i;", 0, 0, 0, !pDirection, id );
203 else
204 sqlite_exec_printf ( db, "update sorting set column = %i, direction = 1 where id = %i;", 0, 0, 0, column, id );
205 }
206
207void Preferences::getSortingPreference ( int id, int *column, int *direction )
208 {
209 char **results;
210 sqlite_get_table_printf ( db, "select column, direction from sorting where id = %i;", &results, NULL, NULL, NULL, id );
211 *column = atoi ( results [ 2 ] );
212 *direction = atoi ( results [ 3 ] );
213 }
214
165int Preferences::getPreference ( int id ) 215int Preferences::getPreference ( int id )
166 { 216 {
167 char **results; 217 char **results;
168 sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id ); 218 sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id );
169 return atoi ( results [ 1 ] ); 219 return atoi ( results [ 1 ] );
170 } 220 }
171 221
172QString Preferences::getSeparator ( ) 222QString Preferences::getSeparator ( )
173 { 223 {
174 int s = getPreference ( 2 ); 224 int s = getPreference ( 2 );
175 if ( s == 1 ) 225 if ( s == 1 )
176 return "/"; 226 return "/";
177 if ( s ==2 ) 227 if ( s ==2 )
178 return "-"; 228 return "-";
179 else 229 else
180 return "."; 230 return ".";
181 } 231 }
182 232
183void Preferences::changePreference ( int id, int newpreference ) 233void Preferences::changePreference ( int id, int newpreference )
184 { 234 {
185 sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id ); 235 sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id );
186 } 236 }
187 237
188void Preferences::setDefaultDatePreferences () 238void Preferences::setDefaultDatePreferences ()
189 { 239 {
190 sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 ); 240 sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 );
191 sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 ); 241 sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 );
192 } 242 }
193 243
194QString Preferences::getDate ( int y, int m, int d ) 244QString Preferences::getDate ( int y, int m, int d )
195 { 245 {
196 QString date; 246 QString date;
197 int format = getPreference ( 1 ); 247 int format = getPreference ( 1 );
198 QString separator = getSeparator(); 248 QString separator = getSeparator();
199 249
200 // Convert all date integers to QStrings 250 // Convert all date integers to QStrings
201 QString year = QString::number ( y ); 251 QString year = QString::number ( y );
202 QString month = QString::number ( m ); 252 QString month = QString::number ( m );
203 if ( m < 10 ) 253 if ( m < 10 )
204 month.prepend ( "0" ); 254 month.prepend ( "0" );
205 QString day = QString::number ( d ); 255 QString day = QString::number ( d );
206 if ( d < 10 ) 256 if ( d < 10 )
207 day.prepend ( "0" ); 257 day.prepend ( "0" );
208 258
209 // Truncate four digit year if necessary 259 // Truncate four digit year if necessary
210 if ( format == 2 || format == 4 || format == 6 || format == 8 ) 260 if ( format == 2 || format == 4 || format == 6 || format == 8 )
211 year.remove ( 0, 2 ); 261 year.remove ( 0, 2 );
212 262
213 // Concatenate dates as necessary 263 // Concatenate dates as necessary
214 if ( format == 1 || format == 2 ) 264 if ( format == 1 || format == 2 )
215 { 265 {
216 date = year; 266 date = year;
217 date.append ( separator ); 267 date.append ( separator );
218 date.append ( month ); 268 date.append ( month );
219 date.append ( separator ); 269 date.append ( separator );
220 date.append ( day ); 270 date.append ( day );
221 return date; 271 return date;
222 } 272 }
223 if ( format == 3 || format == 4 ) 273 if ( format == 3 || format == 4 )
224 { 274 {
225 date = month; 275 date = month;
226 date.append ( separator ); 276 date.append ( separator );
227 date.append ( day ); 277 date.append ( day );
228 date.append ( separator ); 278 date.append ( separator );
229 date.append ( year ); 279 date.append ( year );
230 return date; 280 return date;
231 } 281 }
232 if ( format == 5 || format == 6 ) 282 if ( format == 5 || format == 6 )
233 { 283 {
234 date = year; 284 date = year;
235 date.append ( separator ); 285 date.append ( separator );
236 date.append ( day ); 286 date.append ( day );
237 date.append ( separator ); 287 date.append ( separator );
238 date.append ( month ); 288 date.append ( month );
239 return date; 289 return date;
240 } 290 }
241 if ( format == 7 || format == 8 ) 291 if ( format == 7 || format == 8 )
242 { 292 {
243 date = day; 293 date = day;
244 date.append ( separator ); 294 date.append ( separator );
245 date.append ( month ); 295 date.append ( month );
246 date.append ( separator ); 296 date.append ( separator );
247 date.append ( year ); 297 date.append ( year );
248 return date; 298 return date;
249 } 299 }
250 } 300 }
251 301
252QString Preferences::getDate ( int y, int m ) 302QString Preferences::getDate ( int y, int m )
253 { 303 {
254 QString date; 304 QString date;
255 int format = getPreference ( 1 ); 305 int format = getPreference ( 1 );
256 QString separator = getSeparator(); 306 QString separator = getSeparator();
257 307
258 // Convert all date integers to QStrings 308 // Convert all date integers to QStrings
259 QString year = QString::number ( y ); 309 QString year = QString::number ( y );
260 QString month = QString::number ( m ); 310 QString month = QString::number ( m );
261 if ( m < 10 ) 311 if ( m < 10 )
262 month.prepend ( "0" ); 312 month.prepend ( "0" );
263 313
264 // Truncate four digit year if necessary 314 // Truncate four digit year if necessary
265 if ( format == 2 || format == 4 || format == 6 || format == 8 ) 315 if ( format == 2 || format == 4 || format == 6 || format == 8 )
266 year.remove ( 0, 2 ); 316 year.remove ( 0, 2 );
267 317
268 // Concatenate dates as necessary 318 // Concatenate dates as necessary
269 if ( format == 1 || format == 2 ) 319 if ( format == 1 || format == 2 )
270 { 320 {
271 date = year; 321 date = year;
272 date.append ( separator ); 322 date.append ( separator );
273 date.append ( month ); 323 date.append ( month );
274 return date; 324 return date;
275 } 325 }
276 if ( format == 3 || format == 4 ) 326 if ( format == 3 || format == 4 )
277 { 327 {
278 date = month; 328 date = month;
279 date.append ( separator ); 329 date.append ( separator );
280 date.append ( year ); 330 date.append ( year );
281 return date; 331 return date;
282 } 332 }
283 if ( format == 5 || format == 6 ) 333 if ( format == 5 || format == 6 )
284 { 334 {
285 date = year; 335 date = year;
286 date.append ( separator ); 336 date.append ( separator );
287 date.append ( month ); 337 date.append ( month );
288 return date; 338 return date;
289 } 339 }
290 if ( format == 7 || format == 8 ) 340 if ( format == 7 || format == 8 )
291 { 341 {
292 date.append ( month ); 342 date.append ( month );
293 date.append ( separator ); 343 date.append ( separator );
294 date.append ( year ); 344 date.append ( year );
295 return date; 345 return date;
296 } 346 }
297 } 347 }
298 348
299 349
300 350
301 351
302 352
diff --git a/noncore/apps/qashmoney/preferences.h b/noncore/apps/qashmoney/preferences.h
index 4a3e058..10ec6e9 100755
--- a/noncore/apps/qashmoney/preferences.h
+++ b/noncore/apps/qashmoney/preferences.h
@@ -1,50 +1,53 @@
1#include <sqlite.h> 1#include <sqlite.h>
2#include <qstring.h> 2#include <qstring.h>
3 3
4#ifndef PREFERENCES_H 4#ifndef PREFERENCES_H
5#define PREFERENCES_H 5#define PREFERENCES_H
6 6
7class Preferences 7class Preferences
8 { 8 {
9 public: 9 public:
10 Preferences (); 10 Preferences ();
11 ~Preferences (); 11 ~Preferences ();
12 12
13 void addPreferences (); 13 void addPreferences ();
14 void initializeColumnPreferences (); 14 void initializeColumnPreferences ();
15 void initializeSortingPreferences ();
15 16
16 // Returns a preference value for the given preferences ID 17 // Returns a preference value for the given preferences ID
17 int getPreference ( int ); 18 int getPreference ( int );
18 int getColumnPreference ( int id ); 19 int getColumnPreference ( int id );
20 void getSortingPreference ( int id, int *column, int *direction );
19 21
20 // Convenience for getting date separator with one function 22 // Convenience for getting date separator with one function
21 // call. Takes the preference id as its argument 23 // call. Takes the preference id as its argument
22 QString getSeparator ( ); 24 QString getSeparator ( );
23 25
24 // Changes a preference for the given ID 26 // Changes a preference for the given ID
25 void changePreference ( int , int ); 27 void changePreference ( int , int );
26 void changeColumnPreference ( int id, int width ); 28 void changeColumnPreference ( int id, int width );
29 void changeSortingPreference ( int id, int column );
27 30
28 // The primary database that stores all our data 31 // The primary database that stores all our data
29 sqlite *db; 32 sqlite *db;
30 33
31 // This function returns a Qstring for the year first date formats 34 // This function returns a Qstring for the year first date formats
32 // for displaying. It takes the date numbers 35 // for displaying. It takes the date numbers
33 QString getDate ( int, int, int ); 36 QString getDate ( int, int, int );
34 QString getDate ( int y, int m ); 37 QString getDate ( int y, int m );
35 38
36 void setDefaultDatePreferences (); 39 void setDefaultDatePreferences ();
37 }; 40 };
38 41
39#endif 42#endif
40 43
41 44
42 45
43 46
44 47
45 48
46 49
47 50
48 51
49 52
50 53
diff --git a/noncore/apps/qashmoney/qashmoney.cpp b/noncore/apps/qashmoney/qashmoney.cpp
index 83eea01..20e8d32 100755
--- a/noncore/apps/qashmoney/qashmoney.cpp
+++ b/noncore/apps/qashmoney/qashmoney.cpp
@@ -1,390 +1,403 @@
1#include "qashmoney.h" 1#include "qashmoney.h"
2#include "preferencedialogs.h" 2#include "preferencedialogs.h"
3#include "memorydialog.h" 3#include "memorydialog.h"
4 4
5#include <qheader.h> 5#include <qheader.h>
6#include <iostream.h> 6#include <iostream.h>
7 7
8Budget *budget = new Budget (); 8Budget *budget = new Budget ();
9Preferences *preferences = new Preferences (); 9Preferences *preferences = new Preferences ();
10Account *account = new Account (); 10Account *account = new Account ();
11Transaction *transaction = new Transaction (); 11Transaction *transaction = new Transaction ();
12Transfer *transfer = new Transfer (); 12Transfer *transfer = new Transfer ();
13Memory *memory = new Memory (); 13Memory *memory = new Memory ();
14 14
15QashMoney::QashMoney () : QWidget () 15QashMoney::QashMoney () : QWidget ()
16 { 16 {
17 preferences->addPreferences(); 17 preferences->addPreferences ();
18 preferences->initializeColumnPreferences (); 18 preferences->initializeColumnPreferences ();
19 preferences->initializeSortingPreferences ();
19 20
20 // set the text in the upper part of the frame 21 // set the text in the upper part of the frame
21 setCaption ( tr ( "QashMoney" ) ); 22 setCaption ( tr ( "QashMoney" ) );
22 23
23 // Create new menubar for our mainwindow 24 // Create new menubar for our mainwindow
24 // and add menu items 25 // and add menu items
25 mainmenu = new QPEMenuBar ( this ); 26 mainmenu = new QPEMenuBar ( this );
26 mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); 27 mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised );
27 preferencesmenu = new QPopupMenu ( this ); 28 preferencesmenu = new QPopupMenu ( this );
28 utilitiesmenu = new QPopupMenu ( this ); 29 utilitiesmenu = new QPopupMenu ( this );
29 mainmenu->insertItem ( "Preferences", preferencesmenu ); 30 mainmenu->insertItem ( "Preferences", preferencesmenu );
30 mainmenu->insertItem ( "Utilities", utilitiesmenu ); 31 mainmenu->insertItem ( "Utilities", utilitiesmenu );
31 preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog () ) ); 32 preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog () ) );
32 preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog () ) ); 33 preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog () ) );
33 preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog () ) ); 34 preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog () ) );
34 utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog () ) ); 35 utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog () ) );
35 36
36 // create the main tabwidget for displaying accounts and transactions 37 // create the main tabwidget for displaying accounts and transactions
37 maintabs = new QTabWidget ( this ); 38 maintabs = new QTabWidget ( this );
38 tab = new QWidget ( this ); 39 tab = new QWidget ( this );
39 tab_2 = new QWidget ( this ); 40 tab_2 = new QWidget ( this );
40 tab_3 = new QWidget ( this ); 41 tab_3 = new QWidget ( this );
41 maintabs->addTab ( tab, "Accounts" ); 42 maintabs->addTab ( tab, "Accounts" );
42 maintabs->addTab ( tab_2, "Transactions" ); 43 maintabs->addTab ( tab_2, "Transactions" );
43 maintabs->addTab ( tab_3, "Budgets" ); 44 maintabs->addTab ( tab_3, "Budgets" );
44 tabheight = tab->height(); 45 tabheight = tab->height();
45 maintabs->setTabEnabled ( tab_2, FALSE ); 46 maintabs->setTabEnabled ( tab_2, FALSE );
46 47
47 // create a new account display object 48 // create a new account display object
48 accountdisplay = new AccountDisplay ( maintabs ); 49 accountdisplay = new AccountDisplay ( maintabs );
49 accountdisplay->setTabs ( tab_2, maintabs ); 50 accountdisplay->setTabs ( tab_2, maintabs );
50 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( setTransactionTab () ) ); 51 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( setTransactionTab () ) );
51 52
52 // set the connection to disable the one touch account viewing if we are transfering money 53 // 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 connect ( accountdisplay->transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( toggleOneTouchViewing ( bool ) ) );
54 55
55 // create a new transactiondisplay object 56 // create a new transactiondisplay object
56 transactiondisplay = new TransactionDisplay ( maintabs ); 57 transactiondisplay = new TransactionDisplay ( maintabs );
57 transactiondisplay->hide(); 58 transactiondisplay->hide();
58 59
59 // create new budgetdisplay object 60 // create new budgetdisplay object
60 budgetdisplay = new BudgetDisplay ( maintabs ); 61 budgetdisplay = new BudgetDisplay ( maintabs );
61 budgetdisplay->hide(); 62 budgetdisplay->hide();
62 63
63 tabslayout = new QVBoxLayout ( maintabs, 4, 2 ); 64 tabslayout = new QVBoxLayout ( maintabs, 4, 2 );
64 tabslayout->addSpacing ( tabheight ); 65 tabslayout->addSpacing ( tabheight );
65 tabslayout->addWidget ( accountdisplay ); 66 tabslayout->addWidget ( accountdisplay );
66 tabslayout->addWidget ( transactiondisplay ); 67 tabslayout->addWidget ( transactiondisplay );
67 tabslayout->addWidget ( budgetdisplay ); 68 tabslayout->addWidget ( budgetdisplay );
68 69
69 // connect a change in the maintabs with changing the tab display 70 // connect a change in the maintabs with changing the tab display
70 connect ( maintabs, SIGNAL ( currentChanged ( QWidget * ) ), this, SLOT ( changeTabDisplay () ) ); 71 connect ( maintabs, SIGNAL ( currentChanged ( QWidget * ) ), this, SLOT ( changeTabDisplay () ) );
71 72
72 // create layout that will contain the menubar and the maintabs 73 // create layout that will contain the menubar and the maintabs
73 layout = new QVBoxLayout ( this, 2, 2 ); 74 layout = new QVBoxLayout ( this, 2, 2 );
74 layout->setMenuBar ( mainmenu ); 75 layout->setMenuBar ( mainmenu );
75 layout->addWidget ( maintabs ); 76 layout->addWidget ( maintabs );
76 } 77 }
77 78
78QashMoney::~QashMoney () 79QashMoney::~QashMoney ()
79 { 80 {
80 delete budget; 81 delete budget;
81 delete preferences; 82 delete preferences;
82 delete account; 83 delete account;
83 delete transaction; 84 delete transaction;
84 delete transfer; 85 delete transfer;
85 delete memory; 86 delete memory;
86 } 87 }
87 88
88void QashMoney::changeTabDisplay () 89void QashMoney::changeTabDisplay ()
89 { 90 {
90 // if the user pressed the transactions tab, hide the account display 91 // if the user pressed the transactions tab, hide the account display
91 // object and create a new transaction display 92 // object and create a new transaction display
92 if ( maintabs->currentPageIndex() == 1 ) 93 if ( maintabs->currentPageIndex() == 1 )
93 { 94 {
94 // initialize variables 95 // initialize variables
95 bool children = FALSE; 96 bool children = FALSE;
96 97
97 // hide the account display and define accountid 98 // hide the account display and define accountid
98 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); 99 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
99 100
100 //remove all the columns from the transactiondisplay 101 //remove all the columns from the transactiondisplay
101 int columns = transactiondisplay->listview->columns(); 102 int columns = transactiondisplay->listview->columns();
102 int counter; 103 int counter;
103 for ( counter = 0; counter <= columns; counter++ ) 104 for ( counter = 0; counter <= columns; counter++ )
104 transactiondisplay->listview->removeColumn ( 0 ); 105 transactiondisplay->listview->removeColumn ( 0 );
105 106
106 // set the account name and account balance 107 // set the account name and account balance
107 QString name = account->getAccountName ( accountid ); 108 QString name = account->getAccountName ( accountid );
108 QString balance = account->getAccountBalance ( accountid ); 109 QString balance = account->getAccountBalance ( accountid );
109 transactiondisplay->name->setText ( name ); 110 transactiondisplay->name->setText ( name );
110 transactiondisplay->balance->setText ( balance ); 111 transactiondisplay->balance->setText ( balance );
111 112
112 // clear the limitbox 113 // clear the limitbox
113 transactiondisplay->limitbox->clear(); 114 transactiondisplay->limitbox->clear();
114 115
115 // get parent account id 116 // get parent account id
116 int parentaccountid = account->getParentAccountID ( accountid ); 117 int parentaccountid = account->getParentAccountID ( accountid );
117 118
118 // add columns based on which account is selected 119 // 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 // 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 // in these cases, we add standard three columns for date, transaction, amount
121 transactiondisplay->listview->addColumn ( "Date", 0 ); 122 transactiondisplay->listview->addColumn ( "Date", 0 );
122 transactiondisplay->listview->addColumn ( "Transaction", 0 ); 123 transactiondisplay->listview->addColumn ( "Transaction", 0 );
123 transactiondisplay->listview->addColumn ( "Amt", 0); 124 transactiondisplay->listview->addColumn ( "Amt", 0);
124 transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight ); 125 transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight );
125 transactiondisplay->listview->addColumn ( "", 0 ); 126 transactiondisplay->listview->addColumn ( "", 0 );
126 127
127 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children 128 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children
128 { 129 {
129 // add an extra column for the account name for eac child transaction 130 // add an extra column for the account name for eac child transaction
130 transactiondisplay->listview->addColumn ( "Acct", 0 ); 131 transactiondisplay->listview->addColumn ( "Acct", 0 );
131 children = TRUE; 132 children = TRUE;
132 133
133 // hide the new transaction button 134 // hide the new transaction button
134 transactiondisplay->newtransaction->setEnabled ( FALSE ); 135 transactiondisplay->newtransaction->setEnabled ( FALSE );
135 } 136 }
136 else //we selected a parent without children or a child 137 else //we selected a parent without children or a child
137 transactiondisplay->newtransaction->setEnabled ( TRUE ); 138 transactiondisplay->newtransaction->setEnabled ( TRUE );
138 139
139 // disable the transactionid column so it can't be red 140 // disable the transactionid column so it can't be red
140 transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 ); 141 transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 );
141 142
142 // set the accountid and children variables 143 // set the accountid and children variables
143 transactiondisplay->setChildren ( children ); 144 transactiondisplay->setChildren ( children );
144 transactiondisplay->setAccountID ( accountid ); 145 transactiondisplay->setAccountID ( accountid );
145 146
146 setTransactionDisplayDate (); 147 setTransactionDisplayDate ();
147 148
148 // display transactions 149 // display transactions
149 transactiondisplay->listview->clear(); 150 transactiondisplay->listview->clear();
150 QString displaytext = "%"; 151 QString displaytext = "%";
151 displaytext.prepend ( transactiondisplay->limitbox->text() ); 152 displaytext.prepend ( transactiondisplay->limitbox->text() );
152 if ( transaction->getNumberOfTransactions() > 0 ) 153 if ( transaction->getNumberOfTransactions() > 0 )
153 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); 154 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
154 155
155 // display transfers 156 // display transfers
156 transfer->displayTransfers ( transactiondisplay->listview, accountid, children ); 157 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
157 158
158 // open a new preferences object and resize the transaction display columns 159 // open a new preferences object and resize the transaction display columns
159 // each column will have a different size based on whether we are looking at a child 160 // each column will have a different size based on whether we are looking at a child
160 // account or children through a parent 161 // account or children through a parent
161 if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns 162 if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns
162 { 163 {
163 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width 164 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width
164 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); 165 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
165 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width 166 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width
166 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); 167 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
167 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width 168 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width
168 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); 169 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
169 } 170 }
170 else 171 else
171 { 172 {
172 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width 173 transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width
173 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); 174 transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
174 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width 175 transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width
175 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); 176 transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
176 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width 177 transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width
177 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); 178 transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
178 transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width 179 transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width
179 transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual ); 180 transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual );
180 } 181 }
182
183 // pull the column sorting preference from the preferences table, and configure the listview accordingly
184 int column = 0;
185 int direction = 0;
186 preferences->getSortingPreference ( 2, &column, &direction );
187 transactiondisplay->listview->setSorting ( column, direction );
181 188
182 // show the window 189 // show the window
183 transactiondisplay->show(); 190 transactiondisplay->show();
184 // hide the account display and define accountid 191 // hide the account display and define accountid
185 accountdisplay->hide(); 192 accountdisplay->hide();
186 // hide the budget display 193 // hide the budget display
187 budgetdisplay->hide(); 194 budgetdisplay->hide();
188 } 195 }
189 else if ( maintabs->currentPageIndex() == 0 ) 196 else if ( maintabs->currentPageIndex() == 0 )
190 { 197 {
191 disableOneTouchViewing(); 198 disableOneTouchViewing();
192 199
193 // clear the account display selection 200 // clear the account display selection
194 accountdisplay->listview->clearSelection(); 201 accountdisplay->listview->clearSelection();
195 202
196 // resize the account display columns 203 // resize the account display columns
197 accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); 204 accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
198 accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); 205 accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
199 206
207 // set sorting preference on account display columns
208 int column = 0;
209 int direction = 0;
210 preferences->getSortingPreference ( 1, &column, &direction );
211 accountdisplay->listview->setSorting ( column, direction );
212
200 // display the accounts 213 // display the accounts
201 if ( account->getNumberOfAccounts() != 0 ) 214 if ( account->getNumberOfAccounts() != 0 )
202 account->displayAccounts ( accountdisplay->listview ); 215 account->displayAccounts ( accountdisplay->listview );
203 maintabs->setTabEnabled ( tab_2, FALSE ); 216 maintabs->setTabEnabled ( tab_2, FALSE );
204 217
205 // set the toggle button 218 // set the toggle button
206 accountdisplay->setToggleButton (); 219 accountdisplay->setToggleButton ();
207 220
208 // show the account display 221 // show the account display
209 accountdisplay->show(); 222 accountdisplay->show();
210 223
211 // hide the transaction display 224 // hide the transaction display
212 transactiondisplay->hide(); 225 transactiondisplay->hide();
213 226
214 // hide the budget display 227 // hide the budget display
215 budgetdisplay->hide(); 228 budgetdisplay->hide();
216 229
217 230
218 enableOneTouchViewing (); 231 enableOneTouchViewing ();
219 } 232 }
220 else 233 else
221 { 234 {
222 budgetdisplay->displayLineItems(); 235 budgetdisplay->displayLineItems();
223 budgetdisplay->show(); 236 budgetdisplay->show();
224 transactiondisplay->hide(); 237 transactiondisplay->hide();
225 accountdisplay->hide(); 238 accountdisplay->hide();
226 } 239 }
227 } 240 }
228 241
229void QashMoney::setTransactionTab () 242void QashMoney::setTransactionTab ()
230 { 243 {
231 if ( accountdisplay->listview->selectedItem() == 0 ) 244 if ( accountdisplay->listview->selectedItem() == 0 )
232 maintabs->setTabEnabled ( tab_2, FALSE ); 245 maintabs->setTabEnabled ( tab_2, FALSE );
233 else 246 else
234 maintabs->setTabEnabled ( tab_2, TRUE ); 247 maintabs->setTabEnabled ( tab_2, TRUE );
235 } 248 }
236 249
237void QashMoney::displayDatePreferencesDialog () 250void QashMoney::displayDatePreferencesDialog ()
238 { 251 {
239 // this shows a dialog to set preferences for formatting the date 252 // this shows a dialog to set preferences for formatting the date
240 DatePreferences *pd = new DatePreferences ( this ); 253 DatePreferences *pd = new DatePreferences ( this );
241 pd->exec (); 254 pd->exec ();
242 if ( transactiondisplay->isVisible() ) 255 if ( transactiondisplay->isVisible() )
243 { 256 {
244 // set the account id 257 // set the account id
245 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); 258 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
246 259
247 // set children so we can let displayTransfers know if there are children for the selected account 260 // set children so we can let displayTransfers know if there are children for the selected account
248 bool children; 261 bool children;
249 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) 262 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
250 children = TRUE; 263 children = TRUE;
251 else 264 else
252 children = FALSE; 265 children = FALSE;
253 266
254 // redisplay transactions if they are visible incorporating 267 // redisplay transactions if they are visible incorporating
255 // any changes to the date format 268 // any changes to the date format
256 transactiondisplay->listview->clear(); 269 transactiondisplay->listview->clear();
257 QString displaytext = "%"; 270 QString displaytext = "%";
258 displaytext.prepend ( transactiondisplay->limitbox->text() ); 271 displaytext.prepend ( transactiondisplay->limitbox->text() );
259 272
260 setTransactionDisplayDate(); 273 setTransactionDisplayDate();
261 if ( transaction->getNumberOfTransactions() > 0 ) 274 if ( transaction->getNumberOfTransactions() > 0 )
262 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); 275 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
263 276
264 if ( transfer->getNumberOfTransfers() != 0 ) 277 if ( transfer->getNumberOfTransfers() != 0 )
265 transfer->displayTransfers ( transactiondisplay->listview, accountid, children ); 278 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
266 } 279 }
267 else if ( accountdisplay->isVisible() ) 280 else if ( accountdisplay->isVisible() )
268 { 281 {
269 accountdisplay->listview->clearSelection(); 282 accountdisplay->listview->clearSelection();
270 maintabs->setTabEnabled ( tab_2, FALSE ); 283 maintabs->setTabEnabled ( tab_2, FALSE );
271 } 284 }
272 else 285 else
273 budgetdisplay->updateBudgetInformation(); 286 budgetdisplay->updateBudgetInformation();
274 } 287 }
275 288
276void QashMoney::displayTransactionPreferencesDialog () 289void QashMoney::displayTransactionPreferencesDialog ()
277 { 290 {
278 // display a dialog for setting preferences for transactions 291 // display a dialog for setting preferences for transactions
279 TransactionPreferences *td = new TransactionPreferences ( this ); 292 TransactionPreferences *td = new TransactionPreferences ( this );
280 td->exec (); 293 td->exec ();
281 if ( transactiondisplay->isVisible() ) 294 if ( transactiondisplay->isVisible() )
282 { 295 {
283 // set the account id 296 // set the account id
284 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); 297 int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
285 298
286 // set children so we can let displayTransfers know if there are children for the selected account 299 // set children so we can let displayTransfers know if there are children for the selected account
287 bool children; 300 bool children;
288 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) 301 if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
289 children = TRUE; 302 children = TRUE;
290 else 303 else
291 children = FALSE; 304 children = FALSE;
292 305
293 // redisplay transactions incorporating any transaction preference changes 306 // redisplay transactions incorporating any transaction preference changes
294 transactiondisplay->listview->clear(); 307 transactiondisplay->listview->clear();
295 QString displaytext = "%"; 308 QString displaytext = "%";
296 displaytext.prepend ( transactiondisplay->limitbox->text() ); 309 displaytext.prepend ( transactiondisplay->limitbox->text() );
297 310
298 setTransactionDisplayDate(); 311 setTransactionDisplayDate();
299 if ( transaction->getNumberOfTransactions() > 0 ) 312 if ( transaction->getNumberOfTransactions() > 0 )
300 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); 313 transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
301 314
302 if ( transfer->getNumberOfTransfers() != 0 ) 315 if ( transfer->getNumberOfTransfers() != 0 )
303 transfer->displayTransfers ( transactiondisplay->listview, accountid, children ); 316 transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
304 } 317 }
305 else 318 else
306 { 319 {
307 accountdisplay->listview->clearSelection(); 320 accountdisplay->listview->clearSelection();
308 maintabs->setTabEnabled ( tab_2, FALSE ); 321 maintabs->setTabEnabled ( tab_2, FALSE );
309 } 322 }
310 } 323 }
311 324
312void QashMoney::displayAccountPreferencesDialog () 325void QashMoney::displayAccountPreferencesDialog ()
313 { 326 {
314 // display a dialog for setting preferences for accounts 327 // display a dialog for setting preferences for accounts
315 AccountPreferences *ap = new AccountPreferences ( this ); 328 AccountPreferences *ap = new AccountPreferences ( this );
316 ap->exec (); 329 ap->exec ();
317 330
318 if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 ) 331 if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 )
319 { 332 {
320 accountdisplay->listview->clear(); 333 accountdisplay->listview->clear();
321 account->displayAccounts ( accountdisplay->listview ); 334 account->displayAccounts ( accountdisplay->listview );
322 accountdisplay->listview->clearSelection(); 335 accountdisplay->listview->clearSelection();
323 maintabs->setTabEnabled ( tab_2, FALSE ); 336 maintabs->setTabEnabled ( tab_2, FALSE );
324 } 337 }
325 changeTabDisplay(); 338 changeTabDisplay();
326 } 339 }
327 340
328void QashMoney::displayMemoryDialog () 341void QashMoney::displayMemoryDialog ()
329 { 342 {
330 // opens a dialog to add, edit and delete memory items 343 // opens a dialog to add, edit and delete memory items
331 MemoryDialog *md = new MemoryDialog (); 344 MemoryDialog *md = new MemoryDialog ();
332 md->exec(); 345 md->exec();
333 } 346 }
334 347
335void QashMoney::showTransactions () 348void QashMoney::showTransactions ()
336 { 349 {
337 maintabs->setCurrentPage ( 1 ); 350 maintabs->setCurrentPage ( 1 );
338 } 351 }
339 352
340void QashMoney::enableOneTouchViewing () 353void QashMoney::enableOneTouchViewing ()
341 { 354 {
342 if ( preferences->getPreference ( 5 ) == 1 ) 355 if ( preferences->getPreference ( 5 ) == 1 )
343 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); 356 connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
344 else 357 else
345 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); 358 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
346 } 359 }
347 360
348void QashMoney::disableOneTouchViewing () 361void QashMoney::disableOneTouchViewing ()
349 { 362 {
350 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) ); 363 disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
351 } 364 }
352 365
353void QashMoney::toggleOneTouchViewing ( bool state ) 366void QashMoney::toggleOneTouchViewing ( bool state )
354 { 367 {
355 if ( state == TRUE ) 368 if ( state == TRUE )
356 disableOneTouchViewing(); 369 disableOneTouchViewing();
357 else 370 else
358 enableOneTouchViewing(); 371 enableOneTouchViewing();
359 } 372 }
360 373
361void QashMoney::setTransactionDisplayDate () 374void QashMoney::setTransactionDisplayDate ()
362 { 375 {
363 // determine how many days of transactions to show 376 // determine how many days of transactions to show
364 int limittype = preferences->getPreference ( 7 ); 377 int limittype = preferences->getPreference ( 7 );
365 if ( limittype != 5 ) // set today's date if we are not showing all transactions 378 if ( limittype != 5 ) // set today's date if we are not showing all transactions
366 { 379 {
367 QDate today = QDate::currentDate (); 380 QDate today = QDate::currentDate ();
368 switch ( limittype ) // if we are not showing all transactions 381 switch ( limittype ) // if we are not showing all transactions
369 { 382 {
370 case 0: // viewing two weeks 383 case 0: // viewing two weeks
371 newdate = today.addDays ( -14 ); 384 newdate = today.addDays ( -14 );
372 break; 385 break;
373 case 1: // viewing one month 386 case 1: // viewing one month
374 newdate = today.addDays ( -30 ); 387 newdate = today.addDays ( -30 );
375 break; 388 break;
376 case 2: // three months 389 case 2: // three months
377 newdate = today.addDays ( -90 ); 390 newdate = today.addDays ( -90 );
378 break; 391 break;
379 case 3: // six months 392 case 3: // six months
380 newdate = today.addDays ( -180 ); 393 newdate = today.addDays ( -180 );
381 break; 394 break;
382 case 4: // one year 395 case 4: // one year
383 newdate = today.addDays ( -365 ); 396 newdate = today.addDays ( -365 );
384 break; 397 break;
385 } 398 }
386 } 399 }
387 else 400 else
388 newdate = QDate ( 1, 1, 1000 ); 401 newdate = QDate ( 1900, 1, 1 );
389 } 402 }
390 403
diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp
index 5ecc7ed..a3bd9e7 100755
--- a/noncore/apps/qashmoney/transaction.cpp
+++ b/noncore/apps/qashmoney/transaction.cpp
@@ -1,270 +1,346 @@
1// RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN 1// RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN
2// FUTURE VERSIONS OF QASHMONEY 2// FUTURE VERSIONS OF QASHMONEY
3 3
4// RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION 4// RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION
5 5
6#include "transaction.h" 6#include "transaction.h"
7#include "account.h" 7#include "account.h"
8#include "transactiondisplay.h" 8#include "transactiondisplay.h"
9 9
10#include <stdlib.h> 10#include <stdlib.h>
11#include <iostream.h> 11#include <iostream.h>
12 12
13extern Account *account; 13extern Account *account;
14extern Preferences *preferences; 14extern Preferences *preferences;
15 15
16Transaction::Transaction () 16Transaction::Transaction ()
17 { 17 {
18 tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); 18 tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
19 } 19 }
20 20
21Transaction::~Transaction () 21Transaction::~Transaction ()
22 { 22 {
23 sqlite_close ( tdb ); 23 sqlite_close ( tdb );
24 } 24 }
25 25
26void 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 ) 26void 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 )
27 { 27 {
28 sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0, 28 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,
29 0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description ); 29 0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description );
30 } 30 }
31 31
32void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid ) 32void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid )
33 { 33 {
34 sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f, 34 sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f,
35 cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year, 35 cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year,
36 amount, cleared, budgetid, lineitemid, transactionid ); 36 amount, cleared, budgetid, lineitemid, transactionid );
37 } 37 }
38 38
39void Transaction::deleteTransaction ( int transid ) 39void Transaction::deleteTransaction ( int transid )
40 { 40 {
41 sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid ); 41 sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid );
42 } 42 }
43 43
44void Transaction::deleteAllTransactions ( int accountid ) 44void Transaction::deleteAllTransactions ( int accountid )
45 { 45 {
46 sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid ); 46 sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid );
47 } 47 }
48 48
49int Transaction::getAccountID ( int id ) 49int Transaction::getAccountID ( int id )
50 { 50 {
51 char **results; 51 char **results;
52 sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 52 sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
53 return atol ( results [ 1 ] ); 53 return atol ( results [ 1 ] );
54 } 54 }
55 55
56int Transaction::getNumberOfTransactions () 56int Transaction::getNumberOfTransactions ()
57 { 57 {
58 char **results; 58 char **results;
59 sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL ); 59 sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL );
60 return atoi ( results [ 1 ] ); 60 return atoi ( results [ 1 ] );
61 } 61 }
62 62
63int Transaction::getNumberOfTransactions ( int accountid ) 63int Transaction::getNumberOfTransactions ( int accountid )
64 { 64 {
65 char **results; 65 char **results;
66 sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 66 sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid );
67 return atol ( results [ 1 ] ); 67 return atol ( results [ 1 ] );
68 } 68 }
69 69
70QString Transaction::getPayee ( int id ) 70QString Transaction::getPayee ( int id )
71 { 71 {
72 char **results; 72 char **results;
73 sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 73 sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
74 return results [ 1 ]; 74 return results [ 1 ];
75 } 75 }
76 76
77QString Transaction::getTransactionDescription ( int id ) 77QString Transaction::getTransactionDescription ( int id )
78 { 78 {
79 char **results; 79 char **results;
80 sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 80 sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
81 return results [ 1 ]; 81 return results [ 1 ];
82 } 82 }
83 83
84QString Transaction::getNumber ( int id ) 84QString Transaction::getNumber ( int id )
85 { 85 {
86 char **results; 86 char **results;
87 sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 87 sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
88 return results [ 1 ]; 88 return results [ 1 ];
89 } 89 }
90 90
91QString Transaction::getAmount ( int id ) 91QString Transaction::getAmount ( int id )
92 { 92 {
93 char **results; 93 char **results;
94 sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 94 sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
95 return results [ 1 ]; 95 return results [ 1 ];
96 } 96 }
97 97
98QString Transaction::getAbsoluteAmount ( int id ) 98QString Transaction::getAbsoluteAmount ( int id )
99 { 99 {
100 char **results; 100 char **results;
101 sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 101 sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
102 return results [ 1 ]; 102 return results [ 1 ];
103 } 103 }
104 104
105int Transaction::getCleared ( int id ) 105int Transaction::getCleared ( int id )
106 { 106 {
107 char **results; 107 char **results;
108 sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 108 sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
109 QString cleared = results [ 1 ]; 109 QString cleared = results [ 1 ];
110 return cleared.toInt(); 110 return cleared.toInt();
111 } 111 }
112 112
113void Transaction::setCleared ( int id, int cleared ) 113void Transaction::setCleared ( int id, int cleared )
114 { 114 {
115 sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id ); 115 sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id );
116 } 116 }
117 117
118int Transaction::getBudgetID ( int id ) 118int Transaction::getBudgetID ( int id )
119 { 119 {
120 char **results; 120 char **results;
121 sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); 121 sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id );
122 QString budgetid = results [ 1 ]; 122 QString budgetid = results [ 1 ];
123 return budgetid.toInt(); 123 return budgetid.toInt();
124 } 124 }
125 125
126int Transaction::getLineItemID ( int id ) 126int Transaction::getLineItemID ( int id )
127 { 127 {
128 char **results; 128 char **results;
129 sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); 129 sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id );
130 QString lineitemid = results [ 1 ]; 130 QString lineitemid = results [ 1 ];
131 return lineitemid.toInt(); 131 return lineitemid.toInt();
132 } 132 }
133 133
134int Transaction::getDay ( int id ) 134int Transaction::getDay ( int id )
135 { 135 {
136 char **results; 136 char **results;
137 sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 137 sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
138 QString daystring = results [ 1 ]; 138 QString daystring = results [ 1 ];
139 return daystring.toInt(); 139 return daystring.toInt();
140 } 140 }
141 141
142int Transaction::getMonth ( int id ) 142int Transaction::getMonth ( int id )
143 { 143 {
144 char **results; 144 char **results;
145 sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 145 sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
146 QString monthstring = results [ 1 ]; 146 QString monthstring = results [ 1 ];
147 return monthstring.toInt(); 147 return monthstring.toInt();
148 } 148 }
149 149
150int Transaction::getYear ( int id ) 150int Transaction::getYear ( int id )
151 { 151 {
152 char **results; 152 char **results;
153 sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); 153 sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
154 QString yearstring = results [ 1 ]; 154 QString yearstring = results [ 1 ];
155 return yearstring.toInt(); 155 return yearstring.toInt();
156 } 156 }
157 157
158void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate ) 158char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id )
159 { 159 {
160 // initialize variables
161 char **results;
160 int showcleared = preferences->getPreference ( 3 ); 162 int showcleared = preferences->getPreference ( 3 );
161 int year = ( displaydate.year() ) - 1; 163 QDate today = QDate::currentDate();
164 int fromyear = fromdate.year();
165 int toyear = today.year();
166 int frommonth = fromdate.month();
167 int tomonth = today.month();
168 int fromday = fromdate.day();
162 169
163 // select the transactions to display 170 // construct the first part of the string
164 // two different statements are used based on 171 QString query = "select day, month, year, payee, amount, transid, accountid from transactions where";
165 // whether we are showing cleared transactions 172
166 char **results; 173 if ( frommonth == tomonth && fromyear == toyear ) // our dates cross neither a month nor a year
167 int rows, columns;
168 if ( showcleared == 0 )
169 { 174 {
170 if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) 175 query.append ( " year = " );
171 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and year >= %i parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, year, id, limit ); 176 query.append ( QString::number ( toyear ) );
172 else 177 query.append ( " and month = " );
173 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 year >= %i accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, year, id, limit ); 178 query.append ( QString::number ( tomonth ) );
179 query.append ( " and day >= " );
180 query.append ( QString::number ( fromday ) );
181 query.append ( " and" );
174 } 182 }
175 else 183 else if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year
176 { 184 {
177 if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) 185 query.append ( " year = " );
178 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where year >= %i and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, year, id, limit ); 186 query.append ( QString::number ( toyear ) );
179 else 187 query.append ( " and ( ( month <= " );
180 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); 188 query.append ( QString::number ( tomonth ) );
189 query.append ( " and month > " );
190 query.append ( QString::number ( frommonth ) );
191 query.append ( " ) or ( month = " );
192 query.append ( QString::number ( frommonth ) );
193 query.append ( " and day >= " );
194 query.append ( QString::number ( fromday ) );
195 query.append ( " ) ) and " );
181 } 196 }
197 else if ( fromyear != toyear && fromyear != 1900 ) // here we are showing transactions from an entire year
198 {
199 // divide this taks into two parts - get the transactions from the prior and then the current year
200 // current year part
201 int tmpfrommonth = 1; // set temporary from months and days to Jan. 1
202 int tmpfromday = 1;
203 query.append ( " ( year >= " );
204 query.append ( QString::number ( fromyear ) );
205 query.append ( " and ( month <= " );
206 query.append ( QString::number ( tomonth ) );
207 query.append ( " and month > " );
208 query.append ( QString::number ( tmpfrommonth ) );
209 query.append ( " ) or ( month = " );
210 query.append ( QString::number ( tmpfrommonth ) );
211 query.append ( " and day >= " );
212 query.append ( QString::number ( tmpfromday ) );
213 query.append ( " ) ) or" );
214
215 // prior year part
216 int tmptomonth = 12;
217 query.append ( " ( year = " );
218 query.append ( QString::number ( fromyear ) );
219 query.append ( " and ( ( month <= " );
220 query.append ( QString::number ( tmptomonth ) );
221 query.append ( " and month > " );
222 query.append ( QString::number ( frommonth ) );
223 query.append ( " ) or ( month = " );
224 query.append ( QString::number ( frommonth ) );
225 query.append ( " and day >= " );
226 query.append ( QString::number ( fromday ) );
227 query.append ( " ) ) ) and " );
228 }
229
230 if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
231 query.append ( " parentid = %i and payee like '%q';" );
232 else
233 query.append ( " accountid = %i and payee like '%q';" );
234
235 sqlite_get_table_printf ( tdb, query, &results, &rows, &columns, NULL, id, limit );
236 return results;
237 }
238
239char ** Transaction::selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id )
240 {
241 char **results;
242 if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
243 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit );
244 else
245 sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit );
246 return results;
247 }
248
249void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate )
250 {
251 int showcleared = preferences->getPreference ( 3 );
252
253 char **results;
254 if ( showcleared == 0 )
255 results = selectNonClearedTransactions ( displaydate, children, limit, id );
256 else
257 results = selectAllTransactions ( displaydate, children, limit, id );
182 258
183 // iterate through the result list and display each item 259 // iterate through the result list and display each item
184 int counter = 7; 260 int counter = 7;
185 while ( counter < ( ( rows + 1 ) * columns ) ) 261 while ( counter < ( ( rows + 1 ) * columns ) )
186 { 262 {
187 QDate displaydate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); 263 //QDate testdate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
188 QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); 264 QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
189 265
190 // construct transaction name, amount, id 266 // construct transaction name, amount, id
191 QString payee = results [ counter + 3 ]; 267 QString payee = results [ counter + 3 ];
192 QString amount = results [ counter + 4 ]; 268 QString amount = results [ counter + 4 ];
193 QString transferid = results [ counter + 5 ]; 269 QString transferid = results [ counter + 5 ];
194 270
195 //determine the account name of the child accounts that we're displaying 271 //determine the account name of the child accounts that we're displaying
196 QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) ); 272 QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) );
197 273
198 // fill in values 274 // fill in values
199 if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account 275 if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account
200 { 276 {
201 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) 277 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 )
202 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid); 278 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid );
203 else 279 else
204 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid ); 280 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid );
205 } 281 }
206 else 282 else
207 { 283 {
208 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) 284 if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 )
209 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname ); 285 ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname );
210 else 286 else
211 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname ); 287 QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname );
212 } 288 }
213 289
214 // advance counter 290 // advance counter
215 counter = counter + 7; 291 counter = counter + 7;
216 } 292 }
217 } 293 }
218 294
219QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ) 295QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype )
220 { 296 {
221 // determine if we are viewing a years, months, or days budget 297 // determine if we are viewing a years, months, or days budget
222 // we have to pick a different sum for each 298 // we have to pick a different sum for each
223 char **results; 299 char **results;
224 switch ( viewtype ) 300 switch ( viewtype )
225 { 301 {
226 case 1: // we are viewing a year 302 case 1: // we are viewing a year
227 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 ); 303 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 );
228 break; 304 break;
229 305
230 case 0: // we are viewing a month 306 case 0: // we are viewing a month
231 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 ); 307 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 );
232 break; 308 break;
233 } 309 }
234 QString amount = results [ 1 ]; 310 QString amount = results [ 1 ];
235 float total = amount.toFloat(); 311 float total = amount.toFloat();
236 amount.setNum ( total, 'f', 2 ); 312 amount.setNum ( total, 'f', 2 );
237 return amount; 313 return amount;
238 } 314 }
239 315
240QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype ) 316QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype )
241 { 317 {
242 // determine if we are viewing a years, months, or days budget 318 // determine if we are viewing a years, months, or days budget
243 // we have to pick a different sum for each 319 // we have to pick a different sum for each
244 char **results; 320 char **results;
245 switch ( viewtype ) 321 switch ( viewtype )
246 { 322 {
247 case 1: // we are viewing a year 323 case 1: // we are viewing a year
248 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 ); 324 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 );
249 break; 325 break;
250 326
251 case 0: // we are viewing a month 327 case 0: // we are viewing a month
252 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 ); 328 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 );
253 break; 329 break;
254 } 330 }
255 QString amount = results [ 1 ]; 331 QString amount = results [ 1 ];
256 float total = amount.toFloat(); 332 float total = amount.toFloat();
257 amount.setNum ( total, 'f', 2 ); 333 amount.setNum ( total, 'f', 2 );
258 return amount; 334 return amount;
259 } 335 }
260 336
261void Transaction::clearBudgetIDs ( int budgetid, int lineitemid ) 337void Transaction::clearBudgetIDs ( int budgetid, int lineitemid )
262 { 338 {
263 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid ); 339 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid );
264 } 340 }
265 341
266void Transaction::clearBudgetIDs ( int budgetid ) 342void Transaction::clearBudgetIDs ( int budgetid )
267 { 343 {
268 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid ); 344 sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid );
269 } 345 }
270 346
diff --git a/noncore/apps/qashmoney/transaction.h b/noncore/apps/qashmoney/transaction.h
index 7297bb1..5871555 100755
--- a/noncore/apps/qashmoney/transaction.h
+++ b/noncore/apps/qashmoney/transaction.h
@@ -1,70 +1,73 @@
1#ifndef TRANSACTION_H 1#ifndef TRANSACTION_H
2#define TRANSACTION_H 2#define TRANSACTION_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qlistview.h> 5#include <qlistview.h>
6#include <qdatetime.h> 6#include <qdatetime.h>
7#include <sqlite.h> 7#include <sqlite.h>
8 8
9#include "preferences.h" 9#include "preferences.h"
10 10
11class Transaction 11class Transaction
12 { 12 {
13 public: 13 public:
14 14
15 Transaction (); 15 Transaction ();
16 ~Transaction (); 16 ~Transaction ();
17 17
18 // This function adds a new transaction to the database. It takes the payee, accountid, 18 // This function adds a new transaction to the database. It takes the payee, accountid,
19 // budgetid, number, day, month, year, amount, cleared 19 // budgetid, number, day, month, year, amount, cleared
20 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 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 );
21 21
22 // This updates an already existing transaction 22 // This updates an already existing transaction
23 void updateTransaction ( QString, QString, int, int, int, int, float, int, int, int, int ); 23 void updateTransaction ( QString, QString, int, int, int, int, float, int, int, int, int );
24 24
25 // Deletes a transaction. Takes the transid as its parameter 25 // Deletes a transaction. Takes the transid as its parameter
26 void deleteTransaction ( int ); 26 void deleteTransaction ( int );
27 27
28 // Returns the number of transactions 28 // Returns the number of transactions
29 int getNumberOfTransactions (); 29 int getNumberOfTransactions ();
30 30
31 // this is an overloaded function that returns the number of 31 // this is an overloaded function that returns the number of
32 // transactions for an account 32 // transactions for an account
33 int getNumberOfTransactions ( int ); 33 int getNumberOfTransactions ( int );
34 34
35 // deletes all transactions for the provided accountid 35 // deletes all transactions for the provided accountid
36 void deleteAllTransactions ( int accountid ); 36 void deleteAllTransactions ( int accountid );
37 37
38 QString getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ); 38 QString getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype );
39 QString getActualTotal ( int budgetid, int year, int month, int viewtype ); 39 QString getActualTotal ( int budgetid, int year, int month, int viewtype );
40 40
41 // These two functions clear budget ids is either a line item or an entire budget is deleted 41 // These two functions clear budget ids is either a line item or an entire budget is deleted
42 void clearBudgetIDs ( int, int ); 42 void clearBudgetIDs ( int, int );
43 void clearBudgetIDs ( int ); 43 void clearBudgetIDs ( int );
44 44
45 public slots: 45 public slots:
46 46
47 void displayTransactions ( QListView *, int, bool, const char *, QDate ); 47 void displayTransactions ( QListView *, int, bool, const char *, QDate );
48 char ** selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id );
49 char ** selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id );
48 QString getPayee ( int ); 50 QString getPayee ( int );
49 QString getTransactionDescription ( int ); 51 QString getTransactionDescription ( int );
50 QString getNumber ( int ); 52 QString getNumber ( int );
51 QString getAmount ( int ); 53 QString getAmount ( int );
52 QString getAbsoluteAmount ( int ); 54 QString getAbsoluteAmount ( int );
53 int getCleared ( int ); 55 int getCleared ( int );
54 void setCleared ( int id, int cleared ); 56 void setCleared ( int id, int cleared );
55 int getBudgetID ( int id ); 57 int getBudgetID ( int id );
56 int getLineItemID ( int id ); 58 int getLineItemID ( int id );
57 int getDay ( int ); 59 int getDay ( int );
58 int getMonth ( int ); 60 int getMonth ( int );
59 int getYear ( int ); 61 int getYear ( int );
60 int getAccountID ( int id ); 62 int getAccountID ( int id );
61 63
62 private: 64 private:
63 65
64 sqlite *tdb; 66 sqlite *tdb;
67 int rows, columns;
65 }; 68 };
66 69
67#endif 70#endif
68 71
69 72
70 73
diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp
index ae6223d..1839cd2 100755
--- a/noncore/apps/qashmoney/transactiondisplay.cpp
+++ b/noncore/apps/qashmoney/transactiondisplay.cpp
@@ -1,623 +1,629 @@
1#include "transactiondisplay.h" 1#include "transactiondisplay.h"
2#include "newtransaction.h" 2#include "newtransaction.h"
3#include "account.h" 3#include "account.h"
4#include "budget.h" 4#include "budget.h"
5#include "memory.h" 5#include "memory.h"
6#include "transfer.h" 6#include "transfer.h"
7#include "preferences.h" 7#include "preferences.h"
8#include "calculator.h" 8#include "calculator.h"
9#include "datepicker.h" 9#include "datepicker.h"
10 10
11#include <qdatetime.h> 11#include <qdatetime.h>
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13#include <qheader.h> 13#include <qheader.h>
14#include <qmultilineedit.h> 14#include <qmultilineedit.h>
15#include <iostream.h> 15#include <iostream.h>
16#include <qdatetime.h> 16#include <qdatetime.h>
17 17
18extern Transaction *transaction; 18extern Transaction *transaction;
19extern Budget *budget; 19extern Budget *budget;
20extern Account *account; 20extern Account *account;
21extern Preferences *preferences; 21extern Preferences *preferences;
22extern Memory *memory; 22extern Memory *memory;
23extern Transfer *transfer; 23extern Transfer *transfer;
24 24
25TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) 25TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent )
26 { 26 {
27 // set transactiondisplay variables; 27 // set transactiondisplay variables;
28 accountid = 0; 28 accountid = 0;
29 children = TRUE; 29 children = TRUE;
30 30
31 firstline = new QHBox ( this ); 31 firstline = new QHBox ( this );
32 firstline->setSpacing ( 2 ); 32 firstline->setSpacing ( 2 );
33 33
34 newtransaction = new QPushButton ( firstline ); 34 newtransaction = new QPushButton ( firstline );
35 newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); 35 newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
36 connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) ); 36 connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) );
37 37
38 edittransaction = new QPushButton ( firstline ); 38 edittransaction = new QPushButton ( firstline );
39 edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); 39 edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
40 connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) ); 40 connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) );
41 41
42 deletetransaction = new QPushButton ( firstline ); 42 deletetransaction = new QPushButton ( firstline );
43 deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); 43 deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
44 connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) ); 44 connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) );
45 45
46 toggletransaction = new QPushButton ( firstline ); 46 toggletransaction = new QPushButton ( firstline );
47 toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); 47 toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") );
48 connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) ); 48 connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) );
49 49
50 viewtransactionnotes = new QPushButton ( firstline ); 50 viewtransactionnotes = new QPushButton ( firstline );
51 viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); 51 viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") );
52 connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) ); 52 connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) );
53 53
54 secondline = new QHBox ( this ); 54 secondline = new QHBox ( this );
55 secondline->setSpacing ( 5 ); 55 secondline->setSpacing ( 5 );
56 56
57 name = new QLabel ( secondline ); 57 name = new QLabel ( secondline );
58 balance = new QLabel ( secondline ); 58 balance = new QLabel ( secondline );
59 59
60 QLabel *limit = new QLabel ( "Limit", secondline ); 60 QLabel *limit = new QLabel ( "Limit", secondline );
61 limitbox = new QLineEdit ( secondline ); 61 limitbox = new QLineEdit ( secondline );
62 limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); 62 limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) );
63 connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) ); 63 connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) );
64 64
65 listview = new QListView ( this ); 65 listview = new QListView ( this );
66 listview->setAllColumnsShowFocus ( TRUE ); 66 listview->setAllColumnsShowFocus ( TRUE );
67 listview->setShowSortIndicator ( TRUE ); 67 listview->setShowSortIndicator ( TRUE );
68 listview->header()->setTracking ( FALSE ); 68 listview->header()->setTracking ( FALSE );
69 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 69 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
70 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
70 71
71 layout = new QVBoxLayout ( this, 2, 2 ); 72 layout = new QVBoxLayout ( this, 2, 2 );
72 layout->addWidget ( firstline ); 73 layout->addWidget ( firstline );
73 layout->addWidget ( secondline ); 74 layout->addWidget ( secondline );
74 layout->addWidget ( listview ); 75 layout->addWidget ( listview );
75 } 76 }
76 77
77void TransactionDisplay::addTransaction () 78void TransactionDisplay::addTransaction ()
78 { 79 {
79 // create local variables 80 // create local variables
80 int cleared = -1; 81 int cleared = -1;
81 82
82 // create new transaction window 83 // create new transaction window
83 NewTransaction *newtransaction = new NewTransaction ( this ); 84 NewTransaction *newtransaction = new NewTransaction ( this );
84 int width = this->size().width(); 85 int width = this->size().width();
85 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 86 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
86 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); 87 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
87 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 88 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
88 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 89 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
89 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 90 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
90 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); 91 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
91 92
92 // enter today's date in the date box as defaul 93 // enter today's date in the date box as defaul
93 QDate today = QDate::currentDate (); 94 QDate today = QDate::currentDate ();
94 int defaultday = today.day(); 95 int defaultday = today.day();
95 int defaultmonth = today.month(); 96 int defaultmonth = today.month();
96 int defaultyear = today.year(); 97 int defaultyear = today.year();
97 newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 98 newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
98 99
99 // add memory items to the transactionname combobox 100 // add memory items to the transactionname combobox
100 memory->displayMemoryItems ( newtransaction->transactionname ); 101 memory->displayMemoryItems ( newtransaction->transactionname );
101 newtransaction->transactionname->insertItem ( "", 0 ); 102 newtransaction->transactionname->insertItem ( "", 0 );
102 103
103 if ( newtransaction->exec () == QDialog::Accepted ) 104 if ( newtransaction->exec () == QDialog::Accepted )
104 { 105 {
105 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction 106 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction
106 cleared = 1; 107 cleared = 1;
107 else 108 else
108 cleared = 0; 109 cleared = 0;
109 110
110 float amount = newtransaction->transactionamount->text().toFloat(); 111 float amount = newtransaction->transactionamount->text().toFloat();
111 if ( newtransaction->depositbox->isChecked() == FALSE ) 112 if ( newtransaction->depositbox->isChecked() == FALSE )
112 amount = amount * -1; 113 amount = amount * -1;
113 114
114 // add the transaction name to the memory items 115 // add the transaction name to the memory items
115 memory->addMemoryItem ( newtransaction->transactionname->currentText() ); 116 memory->addMemoryItem ( newtransaction->transactionname->currentText() );
116 117
117 // add the transaction 118 // add the transaction
118 if ( newtransaction->getDateEdited () == TRUE ) 119 if ( newtransaction->getDateEdited () == TRUE )
119 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), 120 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
120 newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), 121 newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(),
121 newtransaction->getCurrentLineItem() ); 122 newtransaction->getCurrentLineItem() );
122 else 123 else
123 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), 124 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
124 newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); 125 newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() );
125 126
126 // redisplay transactions 127 // redisplay transactions
127 listview->clear(); 128 listview->clear();
128 QString displaytext = "%"; 129 QString displaytext = "%";
129 displaytext.prepend ( limitbox->text() ); 130 displaytext.prepend ( limitbox->text() );
130 setTransactionDisplayDate (); 131 setTransactionDisplayDate ();
131 if ( transaction->getNumberOfTransactions() > 0 ) 132 if ( transaction->getNumberOfTransactions() > 0 )
132 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 133 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
133 134
134 // redisplay transfers 135 // redisplay transfers
135 if ( transfer->getNumberOfTransfers() > 0 ) 136 if ( transfer->getNumberOfTransfers() > 0 )
136 transfer->displayTransfers ( listview, accountid, children ); 137 transfer->displayTransfers ( listview, accountid, children, displaydate );
137 138
138 // add the transaction amount to the account it's associated with 139 // add the transaction amount to the account it's associated with
139 // and update its parent account balance if necessary 140 // and update its parent account balance if necessary
140 account->updateAccountBalance ( accountid ); 141 account->updateAccountBalance ( accountid );
141 if ( account->getParentAccountID ( accountid ) != -1 ) 142 if ( account->getParentAccountID ( accountid ) != -1 )
142 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); 143 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
143 144
144 // format then reset the account balance 145 // format then reset the account balance
145 redisplayAccountBalance (); 146 redisplayAccountBalance ();
146 } 147 }
147 } 148 }
148 149
149void TransactionDisplay::checkListViewEdit () 150void TransactionDisplay::checkListViewEdit ()
150 { 151 {
151 if ( listview->selectedItem() == 0 ) 152 if ( listview->selectedItem() == 0 )
152 QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); 153 QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit.");
153 else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) 154 else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
154 editTransfer (); 155 editTransfer ();
155 else 156 else
156 editTransaction(); 157 editTransaction();
157 } 158 }
158 159
159void TransactionDisplay::showCalculator () 160void TransactionDisplay::showCalculator ()
160 { 161 {
161 Calculator *calculator = new Calculator ( this ); 162 Calculator *calculator = new Calculator ( this );
162 if ( calculator->exec () == QDialog::Accepted ) 163 if ( calculator->exec () == QDialog::Accepted )
163 amount->setText ( calculator->display->text() ); 164 amount->setText ( calculator->display->text() );
164 } 165 }
165 166
166void TransactionDisplay::showCalendar () 167void TransactionDisplay::showCalendar ()
167 { 168 {
168 QDate newDate = QDate::currentDate (); 169 QDate newDate = QDate::currentDate ();
169 DatePicker *dp = new DatePicker ( newDate ); 170 DatePicker *dp = new DatePicker ( newDate );
170 if ( dp->exec () == QDialog::Accepted ) 171 if ( dp->exec () == QDialog::Accepted )
171 { 172 {
172 year = dp->getYear(); 173 year = dp->getYear();
173 month = dp->getMonth(); 174 month = dp->getMonth();
174 day = dp->getDay(); 175 day = dp->getDay();
175 date->setText ( preferences->getDate ( year, month, day ) ); 176 date->setText ( preferences->getDate ( year, month, day ) );
176 } 177 }
177 } 178 }
178 179
179void TransactionDisplay::editTransfer () 180void TransactionDisplay::editTransfer ()
180 { 181 {
181 transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); 182 transferid = listview->currentItem()->text ( getIDColumn() ).toInt();
182 fromaccount = transfer->getFromAccountID ( transferid ); 183 fromaccount = transfer->getFromAccountID ( transferid );
183 toaccount = transfer->getToAccountID ( transferid ); 184 toaccount = transfer->getToAccountID ( transferid );
184 year = transfer->getYear ( transferid ); 185 year = transfer->getYear ( transferid );
185 month = transfer->getMonth ( transferid ); 186 month = transfer->getMonth ( transferid );
186 day = transfer->getDay ( transferid ); 187 day = transfer->getDay ( transferid );
187 188
188 QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); 189 QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE );
189 editransfer->setCaption ( "Transfer" ); 190 editransfer->setCaption ( "Transfer" );
190 191
191 QStringList accountnames = account->getAccountNames(); 192 QStringList accountnames = account->getAccountNames();
192 QStringList accountids = account->getAccountIDs(); 193 QStringList accountids = account->getAccountIDs();
193 194
194 QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); 195 QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer );
195 QFont f = this->font(); 196 QFont f = this->font();
196 f.setWeight ( QFont::Bold ); 197 f.setWeight ( QFont::Bold );
197 fromaccountlabel->setFont ( f ); 198 fromaccountlabel->setFont ( f );
198 199
199 QComboBox *fromaccountbox = new QComboBox ( editransfer ); 200 QComboBox *fromaccountbox = new QComboBox ( editransfer );
200 fromaccountbox->insertStringList ( accountnames ); 201 fromaccountbox->insertStringList ( accountnames );
201 fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); 202 fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) );
202 203
203 QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); 204 QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer );
204 toaccountlabel->setFont ( f ); 205 toaccountlabel->setFont ( f );
205 206
206 QComboBox *toaccountbox = new QComboBox ( editransfer ); 207 QComboBox *toaccountbox = new QComboBox ( editransfer );
207 toaccountbox->insertStringList ( accountnames ); 208 toaccountbox->insertStringList ( accountnames );
208 toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); 209 toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) );
209 210
210 QLabel *datelabel = new QLabel ( "Date", editransfer ); 211 QLabel *datelabel = new QLabel ( "Date", editransfer );
211 QHBox *datebox = new QHBox ( editransfer ); 212 QHBox *datebox = new QHBox ( editransfer );
212 datebox->setSpacing ( 2 ); 213 datebox->setSpacing ( 2 );
213 date = new QLineEdit ( datebox ); 214 date = new QLineEdit ( datebox );
214 date->setAlignment ( Qt::AlignRight ); 215 date->setAlignment ( Qt::AlignRight );
215 date->setDisabled ( TRUE ); 216 date->setDisabled ( TRUE );
216 date->setText ( preferences->getDate ( year, month, day ) ); 217 date->setText ( preferences->getDate ( year, month, day ) );
217 QPushButton *datebutton = new QPushButton ( datebox ); 218 QPushButton *datebutton = new QPushButton ( datebox );
218 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 219 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
219 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 220 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
220 221
221 QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); 222 QLabel *amounttlabel = new QLabel ( "Amount", editransfer );
222 223
223 QHBox *amountbox = new QHBox ( editransfer ); 224 QHBox *amountbox = new QHBox ( editransfer );
224 amountbox->setSpacing ( 2 ); 225 amountbox->setSpacing ( 2 );
225 amount = new QLineEdit ( amountbox ); 226 amount = new QLineEdit ( amountbox );
226 amount->setAlignment ( Qt::AlignRight ); 227 amount->setAlignment ( Qt::AlignRight );
227 amount->setText ( transfer->getAmount ( transferid ) ); 228 amount->setText ( transfer->getAmount ( transferid ) );
228 QPushButton *calculatorbutton = new QPushButton( amountbox ); 229 QPushButton *calculatorbutton = new QPushButton( amountbox );
229 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 230 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
230 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 231 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
231 232
232 QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); 233 QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer );
233 234
234 QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); 235 QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 );
235 layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); 236 layout->addWidget ( fromaccountlabel, Qt::AlignLeft );
236 layout->addWidget ( fromaccountbox, Qt::AlignLeft ); 237 layout->addWidget ( fromaccountbox, Qt::AlignLeft );
237 layout->addWidget ( toaccountlabel, Qt::AlignLeft ); 238 layout->addWidget ( toaccountlabel, Qt::AlignLeft );
238 layout->addWidget ( toaccountbox, Qt::AlignLeft ); 239 layout->addWidget ( toaccountbox, Qt::AlignLeft );
239 layout->addSpacing ( 5 ); 240 layout->addSpacing ( 5 );
240 layout->addWidget ( datelabel, Qt::AlignLeft ); 241 layout->addWidget ( datelabel, Qt::AlignLeft );
241 layout->addWidget ( datebox, Qt::AlignLeft ); 242 layout->addWidget ( datebox, Qt::AlignLeft );
242 layout->addWidget ( amounttlabel, Qt::AlignLeft ); 243 layout->addWidget ( amounttlabel, Qt::AlignLeft );
243 layout->addWidget ( amountbox, Qt::AlignLeft ); 244 layout->addWidget ( amountbox, Qt::AlignLeft );
244 layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); 245 layout->addWidget ( clearedcheckbox, Qt::AlignLeft );
245 246
246 if ( editransfer->exec() == QDialog::Accepted ) 247 if ( editransfer->exec() == QDialog::Accepted )
247 { 248 {
248 //get fromaccount 249 //get fromaccount
249 fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); 250 fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt();
250 251
251 //get to account 252 //get to account
252 toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); 253 toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt();
253 254
254 //set cleared flag 255 //set cleared flag
255 int cleared = 0; 256 int cleared = 0;
256 if ( clearedcheckbox->isChecked() == TRUE ) 257 if ( clearedcheckbox->isChecked() == TRUE )
257 cleared = 1; 258 cleared = 1;
258 259
259 //update transfer 260 //update transfer
260 transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), 261 transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ),
261 day, month, year, amount->text().toFloat(), cleared, transferid ); 262 day, month, year, amount->text().toFloat(), cleared, transferid );
262 263
263 account->updateAccountBalance ( fromaccount ); 264 account->updateAccountBalance ( fromaccount );
264 if ( account->getParentAccountID ( fromaccount ) != -1 ) 265 if ( account->getParentAccountID ( fromaccount ) != -1 )
265 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); 266 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) );
266 267
267 updateAndDisplay ( toaccount ); 268 updateAndDisplay ( toaccount );
268 } 269 }
269 } 270 }
270 271
271void TransactionDisplay::editTransaction () 272void TransactionDisplay::editTransaction ()
272 { 273 {
273 int cleared; 274 int cleared;
274 275
275 // set the transaction id and budgetid 276 // set the transaction id and budgetid
276 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 277 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
277 int budgetid = transaction->getBudgetID ( transactionid ); 278 int budgetid = transaction->getBudgetID ( transactionid );
278 int lineitemid = transaction->getLineItemID ( transactionid ); 279 int lineitemid = transaction->getLineItemID ( transactionid );
279 280
280 // create edit transaction window 281 // create edit transaction window
281 NewTransaction *newtransaction = new NewTransaction ( this ); 282 NewTransaction *newtransaction = new NewTransaction ( this );
282 int width = this->width(); 283 int width = this->width();
283 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 284 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
284 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); 285 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
285 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 286 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
286 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 287 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
287 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 288 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
288 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); 289 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
289 290
290 // enter the date in the date box 291 // enter the date in the date box
291 newtransaction->year = transaction->getYear ( transactionid ); 292 newtransaction->year = transaction->getYear ( transactionid );
292 newtransaction->month = transaction->getMonth ( transactionid ); 293 newtransaction->month = transaction->getMonth ( transactionid );
293 newtransaction->day = transaction->getDay ( transactionid ); 294 newtransaction->day = transaction->getDay ( transactionid );
294 newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); 295 newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) );
295 296
296 // set the description 297 // set the description
297 newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); 298 newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) );
298 299
299 // add memory items to the transactionname combobox 300 // add memory items to the transactionname combobox
300 memory->displayMemoryItems ( newtransaction->transactionname ); 301 memory->displayMemoryItems ( newtransaction->transactionname );
301 302
302 // add correct transaction name 303 // add correct transaction name
303 newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); 304 newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) );
304 305
305 // add transaction number 306 // add transaction number
306 newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); 307 newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) );
307 308
308 // add transaction amount 309 // add transaction amount
309 newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); 310 newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) );
310 311
311 // check for and set the correct budget 312 // check for and set the correct budget
312 if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item 313 if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item
313 { 314 {
314 newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); 315 newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 );
315 if ( lineitemid >= 1 ) 316 if ( lineitemid >= 1 )
316 { 317 {
317 newtransaction->setLineItems (); 318 newtransaction->setLineItems ();
318 newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); 319 newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) );
319 } 320 }
320 else 321 else
321 { 322 {
322 newtransaction->lineitemlabel->setEnabled ( FALSE ); 323 newtransaction->lineitemlabel->setEnabled ( FALSE );
323 newtransaction->lineitembox->setEnabled ( FALSE ); 324 newtransaction->lineitembox->setEnabled ( FALSE );
324 } 325 }
325 } 326 }
326 else 327 else
327 { 328 {
328 newtransaction->lineitemlabel->setEnabled ( FALSE ); 329 newtransaction->lineitemlabel->setEnabled ( FALSE );
329 newtransaction->lineitembox->setEnabled ( FALSE ); 330 newtransaction->lineitembox->setEnabled ( FALSE );
330 } 331 }
331 332
332 // check cleared checkbox if necessary 333 // check cleared checkbox if necessary
333 if ( transaction->getCleared ( transactionid ) == 1 ) 334 if ( transaction->getCleared ( transactionid ) == 1 )
334 newtransaction->clearedcheckbox->setChecked ( TRUE ); 335 newtransaction->clearedcheckbox->setChecked ( TRUE );
335 336
336 // check deposit box if necessary 337 // check deposit box if necessary
337 if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) 338 if ( transaction->getAmount ( transactionid ).toFloat() > 0 )
338 newtransaction->depositbox->setChecked ( TRUE ); 339 newtransaction->depositbox->setChecked ( TRUE );
339 340
340 if ( newtransaction->exec () == QDialog::Accepted ) 341 if ( newtransaction->exec () == QDialog::Accepted )
341 { 342 {
342 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) 343 if ( newtransaction->clearedcheckbox->isChecked () == TRUE )
343 cleared = 1; 344 cleared = 1;
344 else 345 else
345 cleared = 0; 346 cleared = 0;
346 347
347 float amount = newtransaction->transactionamount->text().toFloat(); 348 float amount = newtransaction->transactionamount->text().toFloat();
348 if ( newtransaction->depositbox->isChecked() == FALSE ) 349 if ( newtransaction->depositbox->isChecked() == FALSE )
349 amount = amount * -1; 350 amount = amount * -1;
350 351
351 // add the transaction name to the memory items 352 // add the transaction name to the memory items
352 memory->addMemoryItem ( newtransaction->transactionname->currentText() ); 353 memory->addMemoryItem ( newtransaction->transactionname->currentText() );
353 354
354 // update the transaction 355 // update the transaction
355 transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), 356 transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(),
356 newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), 357 newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(),
357 amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); 358 amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid );
358 359
359 updateAndDisplay ( transaction->getAccountID ( transactionid ) ); 360 updateAndDisplay ( transaction->getAccountID ( transactionid ) );
360 } 361 }
361 } 362 }
362 363
363void TransactionDisplay::updateAndDisplay ( int id ) 364void TransactionDisplay::updateAndDisplay ( int id )
364 { 365 {
365 // redisplay transactions 366 // redisplay transactions
366 listview->clear(); 367 listview->clear();
367 QString displaytext = "%"; 368 QString displaytext = "%";
368 displaytext.prepend ( limitbox->text() ); 369 displaytext.prepend ( limitbox->text() );
369 setTransactionDisplayDate (); 370 setTransactionDisplayDate ();
370 if ( transaction->getNumberOfTransactions() > 0 ) 371 if ( transaction->getNumberOfTransactions() > 0 )
371 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 372 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
372 373
373 // redisplay transfers 374 // redisplay transfers
374 if ( transfer->getNumberOfTransfers() > 0 ) 375 if ( transfer->getNumberOfTransfers() > 0 )
375 transfer->displayTransfers ( listview, accountid, children ); 376 transfer->displayTransfers ( listview, accountid, children, displaydate );
376 377
377 // add the transaction amount to the account it's associated with 378 // add the transaction amount to the account it's associated with
378 // and update its parent account balance if necessary 379 // and update its parent account balance if necessary
379 account->updateAccountBalance ( id ); 380 account->updateAccountBalance ( id );
380 if ( account->getParentAccountID ( id ) != -1 ) 381 if ( account->getParentAccountID ( id ) != -1 )
381 account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); 382 account->changeParentAccountBalance ( account->getParentAccountID ( id ) );
382 383
383 // format then reset the account balance 384 // format then reset the account balance
384 redisplayAccountBalance (); 385 redisplayAccountBalance ();
385 } 386 }
386 387
387void TransactionDisplay::checkListViewDelete () 388void TransactionDisplay::checkListViewDelete ()
388 { 389 {
389 if ( listview->selectedItem() == 0 ) 390 if ( listview->selectedItem() == 0 )
390 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); 391 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete.");
391 else 392 else
392 deleteTransaction (); 393 deleteTransaction ();
393 } 394 }
394 395
395void TransactionDisplay::deleteTransaction () 396void TransactionDisplay::deleteTransaction ()
396 { 397 {
397 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 398 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
398 399
399 if ( transactionid > 0 ) // takes care of deleting transactions 400 if ( transactionid > 0 ) // takes care of deleting transactions
400 { 401 {
401 // check if we are viewing child transactions through a parent 402 // check if we are viewing child transactions through a parent
402 // in that case we will have to update balances for the parent 403 // in that case we will have to update balances for the parent
403 // which is represented by accountid and the child account 404 // which is represented by accountid and the child account
404 // which will be represented by childaccountid 405 // which will be represented by childaccountid
405 int childaccountid = -1; 406 int childaccountid = -1;
406 if ( listview->columns() == 5 ) 407 if ( listview->columns() == 5 )
407 childaccountid = transaction->getAccountID ( transactionid ); 408 childaccountid = transaction->getAccountID ( transactionid );
408 409
409 transaction->deleteTransaction ( transactionid ); 410 transaction->deleteTransaction ( transactionid );
410 411
411 listview->clear(); 412 listview->clear();
412 QString displaytext = "%"; 413 QString displaytext = "%";
413 displaytext.prepend ( limitbox->text() ); 414 displaytext.prepend ( limitbox->text() );
414 setTransactionDisplayDate (); 415 setTransactionDisplayDate ();
415 if ( transaction->getNumberOfTransactions() > 0 ) 416 if ( transaction->getNumberOfTransactions() > 0 )
416 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 417 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
417 418
418 if ( transfer->getNumberOfTransfers() > 0 ) 419 if ( transfer->getNumberOfTransfers() > 0 )
419 transfer->displayTransfers ( listview, accountid, children ); 420 transfer->displayTransfers ( listview, accountid, children, displaydate );
420 421
421 // if we are viewing different child accounts through the parent account 422 // if we are viewing different child accounts through the parent account
422 // ie if there are five columns and the parentid is -1 423 // ie if there are five columns and the parentid is -1
423 // update the accountid ( which is the parent ) and update the child account 424 // update the accountid ( which is the parent ) and update the child account
424 // balance. Get its accountid from the transactionid 425 // balance. Get its accountid from the transactionid
425 account->updateAccountBalance ( accountid ); // will update either a parent or child 426 account->updateAccountBalance ( accountid ); // will update either a parent or child
426 if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one 427 if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one
427 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); 428 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
428 if ( childaccountid != -1 ) // we've set childaccountid 429 if ( childaccountid != -1 ) // we've set childaccountid
429 account->updateAccountBalance ( childaccountid ); 430 account->updateAccountBalance ( childaccountid );
430 431
431 // format then reset the account balance 432 // format then reset the account balance
432 redisplayAccountBalance (); 433 redisplayAccountBalance ();
433 } 434 }
434 else // takes care of deleting transfers 435 else // takes care of deleting transfers
435 { 436 {
436 // get the accountids before we delete the transfer 437 // get the accountids before we delete the transfer
437 int fromaccountid = transfer->getFromAccountID ( transactionid ); 438 int fromaccountid = transfer->getFromAccountID ( transactionid );
438 int toaccountid = transfer->getToAccountID ( transactionid ); 439 int toaccountid = transfer->getToAccountID ( transactionid );
439 440
440 // delete the transfer and redisplay transactions 441 // delete the transfer and redisplay transactions
441 transfer->deleteTransfer ( transactionid ); 442 transfer->deleteTransfer ( transactionid );
442 443
443 listview->clear(); 444 listview->clear();
444 QString displaytext = "%"; 445 QString displaytext = "%";
445 displaytext.prepend ( limitbox->text() ); 446 displaytext.prepend ( limitbox->text() );
446 setTransactionDisplayDate (); 447 setTransactionDisplayDate ();
447 if ( transaction->getNumberOfTransactions() > 0 ) 448 if ( transaction->getNumberOfTransactions() > 0 )
448 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 449 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
449 450
450 if ( transfer->getNumberOfTransfers() > 0 ) 451 if ( transfer->getNumberOfTransfers() > 0 )
451 transfer->displayTransfers ( listview, accountid, children ); 452 transfer->displayTransfers ( listview, accountid, children, displaydate );
452 453
453 // for the from account 454 // for the from account
454 account->updateAccountBalance ( fromaccountid ); 455 account->updateAccountBalance ( fromaccountid );
455 if ( account->getParentAccountID ( fromaccountid ) != -1 ) 456 if ( account->getParentAccountID ( fromaccountid ) != -1 )
456 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) ); 457 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) );
457 458
458 // for the to account 459 // for the to account
459 account->updateAccountBalance ( toaccountid ); 460 account->updateAccountBalance ( toaccountid );
460 if ( account->getParentAccountID ( toaccountid ) != -1 ) 461 if ( account->getParentAccountID ( toaccountid ) != -1 )
461 account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) ); 462 account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) );
462 463
463 // format then reset the account balance 464 // format then reset the account balance
464 redisplayAccountBalance (); 465 redisplayAccountBalance ();
465 } 466 }
466 } 467 }
467 468
468void TransactionDisplay::checkListViewToggle () 469void TransactionDisplay::checkListViewToggle ()
469 { 470 {
470 if ( listview->selectedItem() == 0 ) 471 if ( listview->selectedItem() == 0 )
471 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset."); 472 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset.");
472 else 473 else
473 toggleTransaction (); 474 toggleTransaction ();
474 } 475 }
475 476
476void TransactionDisplay::toggleTransaction () 477void TransactionDisplay::toggleTransaction ()
477 { 478 {
478 //get the transaction of the selected transaction to determine if its a transaction or transfer 479 //get the transaction of the selected transaction to determine if its a transaction or transfer
479 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 480 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
480 481
481 if ( transactionid > 0 ) // if this is a transaction 482 if ( transactionid > 0 ) // if this is a transaction
482 { 483 {
483 if ( transaction->getCleared ( transactionid ) == 0 ) 484 if ( transaction->getCleared ( transactionid ) == 0 )
484 transaction->setCleared ( transactionid, 1 ); 485 transaction->setCleared ( transactionid, 1 );
485 else 486 else
486 transaction->setCleared ( transactionid, 0 ); 487 transaction->setCleared ( transactionid, 0 );
487 } 488 }
488 else 489 else
489 { 490 {
490 if ( transfer->getCleared ( transactionid ) == 0 ) 491 if ( transfer->getCleared ( transactionid ) == 0 )
491 transfer->setCleared ( transactionid, 1 ); 492 transfer->setCleared ( transactionid, 1 );
492 else 493 else
493 transfer->setCleared ( transactionid, 0 ); 494 transfer->setCleared ( transactionid, 0 );
494 } 495 }
495 496
496 listview->clear(); 497 listview->clear();
497 QString displaytext = "%"; 498 QString displaytext = "%";
498 displaytext.prepend ( limitbox->text() ); 499 displaytext.prepend ( limitbox->text() );
499 setTransactionDisplayDate (); 500 setTransactionDisplayDate ();
500 if ( transaction->getNumberOfTransactions() > 0 ) 501 if ( transaction->getNumberOfTransactions() > 0 )
501 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 502 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
502 503
503 if ( transfer->getNumberOfTransfers() != 0 ) 504 if ( transfer->getNumberOfTransfers() != 0 )
504 transfer->displayTransfers ( listview, accountid, children ); 505 transfer->displayTransfers ( listview, accountid, children, displaydate );
505 } 506 }
506 507
507void TransactionDisplay::redisplayAccountBalance () 508void TransactionDisplay::redisplayAccountBalance ()
508 { 509 {
509 QString accountbalance = account->getAccountBalance ( accountid ); 510 QString accountbalance = account->getAccountBalance ( accountid );
510 balance->setText ( accountbalance ); 511 balance->setText ( accountbalance );
511 } 512 }
512 513
513void TransactionDisplay::setChildren ( bool c ) 514void TransactionDisplay::setChildren ( bool c )
514 { 515 {
515 children = c; 516 children = c;
516 } 517 }
517 518
518void TransactionDisplay::setAccountID ( int id ) 519void TransactionDisplay::setAccountID ( int id )
519 { 520 {
520 accountid = id; 521 accountid = id;
521 } 522 }
522 523
523ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent ) 524ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent )
524 { 525 {
525 } 526 }
526 527
527ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) 528ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
528 : QListViewItem ( parent, label1, label2, label3, label4 ) 529 : QListViewItem ( parent, label1, label2, label3, label4 )
529 { 530 {
530 } 531 }
531 532
532ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) 533ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
533 : QListViewItem ( parent, label1, label2, label3, label4, label5 ) 534 : QListViewItem ( parent, label1, label2, label3, label4, label5 )
534 { 535 {
535 } 536 }
536 537
537void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) 538void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
538 { 539 {
539 QColorGroup _cg ( cg ); 540 QColorGroup _cg ( cg );
540 _cg.setColor ( QColorGroup::Text, Qt::red ); 541 _cg.setColor ( QColorGroup::Text, Qt::red );
541 QListViewItem::paintCell ( p, _cg, column, width, alignment ); 542 QListViewItem::paintCell ( p, _cg, column, width, alignment );
542 } 543 }
543 544
544void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 545void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize )
545 { 546 {
546 if ( listview->columns() == 4 ) 547 if ( listview->columns() == 4 )
547 preferences->changeColumnPreference ( column + 3, newsize ); 548 preferences->changeColumnPreference ( column + 3, newsize );
548 else if ( listview->columns() == 5 && column != 4 ) 549 else if ( listview->columns() == 5 && column != 4 )
549 preferences->changeColumnPreference ( column + 6, newsize ); 550 preferences->changeColumnPreference ( column + 6, newsize );
550 else 551 else
551 preferences->changeColumnPreference ( 9, newsize ); 552 preferences->changeColumnPreference ( 9, newsize );
552 } 553 }
553 554
555void TransactionDisplay::saveSortingPreference ( int column )
556 {
557 preferences->changeSortingPreference ( 2, column );
558 }
559
554void TransactionDisplay::limitDisplay ( const QString &text ) 560void TransactionDisplay::limitDisplay ( const QString &text )
555 { 561 {
556 listview->clear (); 562 listview->clear ();
557 QString displaytext = "%"; 563 QString displaytext = "%";
558 displaytext.prepend ( text ); 564 displaytext.prepend ( text );
559 setTransactionDisplayDate (); 565 setTransactionDisplayDate ();
560 if ( transaction->getNumberOfTransactions() > 0 ) 566 if ( transaction->getNumberOfTransactions() > 0 )
561 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 567 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
562 568
563 if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) 569 if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 )
564 transfer->displayTransfers ( listview, accountid, children ); 570 transfer->displayTransfers ( listview, accountid, children, displaydate );
565 } 571 }
566 572
567int TransactionDisplay::getIDColumn () 573int TransactionDisplay::getIDColumn ()
568 { 574 {
569 int counter; 575 int counter;
570 int columns = listview->columns(); 576 int columns = listview->columns();
571 for ( counter = 0; counter <= columns; counter++ ) 577 for ( counter = 0; counter <= columns; counter++ )
572 if ( listview->header()->label ( counter ).length() == 0 ) 578 if ( listview->header()->label ( counter ).length() == 0 )
573 return counter; 579 return counter;
574 } 580 }
575 581
576void TransactionDisplay::showTransactionNotes () 582void TransactionDisplay::showTransactionNotes ()
577 { 583 {
578 if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) 584 if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
579 QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes."); 585 QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes.");
580 else 586 else
581 { 587 {
582 int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt (); 588 int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
583 QDialog *description = new QDialog ( this, "description", TRUE ); 589 QDialog *description = new QDialog ( this, "description", TRUE );
584 description->setCaption ( "Notes" ); 590 description->setCaption ( "Notes" );
585 QMultiLineEdit *notes = new QMultiLineEdit ( description ); 591 QMultiLineEdit *notes = new QMultiLineEdit ( description );
586 notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); 592 notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
587 notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); 593 notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
588 notes->setWordWrap ( QMultiLineEdit::WidgetWidth ); 594 notes->setWordWrap ( QMultiLineEdit::WidgetWidth );
589 notes->setEnabled ( FALSE ); 595 notes->setEnabled ( FALSE );
590 notes->setText ( transaction->getTransactionDescription ( transactionid ) ); 596 notes->setText ( transaction->getTransactionDescription ( transactionid ) );
591 description->show(); 597 description->show();
592 } 598 }
593 } 599 }
594 600
595void TransactionDisplay::setTransactionDisplayDate () 601void TransactionDisplay::setTransactionDisplayDate ()
596 { 602 {
597 // determine how many days of transactions to show 603 // determine how many days of transactions to show
598 int limittype = preferences->getPreference ( 7 ); 604 int limittype = preferences->getPreference ( 7 );
599 if ( limittype != 5 ) // set today's date if we are not showing all transactions 605 if ( limittype != 5 ) // set today's date if we are not showing all transactions
600 { 606 {
601 QDate today = QDate::currentDate (); 607 QDate today = QDate::currentDate ();
602 switch ( limittype ) // if we are not showing all transactions 608 switch ( limittype ) // if we are not showing all transactions
603 { 609 {
604 case 0: // viewing two weeks 610 case 0: // viewing two weeks
605 displaydate = today.addDays ( -14 ); 611 displaydate = today.addDays ( -14 );
606 break; 612 break;
607 case 1: // viewing one month 613 case 1: // viewing one month
608 displaydate = today.addDays ( -30 ); 614 displaydate = today.addDays ( -30 );
609 break; 615 break;
610 case 2: // three months 616 case 2: // three months
611 displaydate = today.addDays ( -90 ); 617 displaydate = today.addDays ( -90 );
612 break; 618 break;
613 case 3: // six months 619 case 3: // six months
614 displaydate = today.addDays ( -180 ); 620 displaydate = today.addDays ( -180 );
615 break; 621 break;
616 case 4: // one year 622 case 4: // one year
617 displaydate = today.addDays ( -365 ); 623 displaydate = today.addDays ( -365 );
618 break; 624 break;
619 } 625 }
620 } 626 }
621 else 627 else
622 displaydate = QDate ( 1, 1, 1000 ); 628 displaydate = QDate ( 1900, 1, 1 );
623 } 629 }
diff --git a/noncore/apps/qashmoney/transactiondisplay.h b/noncore/apps/qashmoney/transactiondisplay.h
index 1746f6c..594776a 100755
--- a/noncore/apps/qashmoney/transactiondisplay.h
+++ b/noncore/apps/qashmoney/transactiondisplay.h
@@ -1,82 +1,83 @@
1#ifndef TRANSACTIONDISPLAY_H 1#ifndef TRANSACTIONDISPLAY_H
2#define TRANSACTIONDISPLAY_H 2#define TRANSACTIONDISPLAY_H
3 3
4#include <qlayout.h> 4#include <qlayout.h>
5#include <qhbox.h> 5#include <qhbox.h>
6#include <qlistview.h> 6#include <qlistview.h>
7#include <qpushbutton.h> 7#include <qpushbutton.h>
8#include <qlabel.h> 8#include <qlabel.h>
9#include <qlineedit.h> 9#include <qlineedit.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11 11
12class TransactionDisplay : public QWidget 12class TransactionDisplay : public QWidget
13 { 13 {
14 Q_OBJECT 14 Q_OBJECT
15 15
16 public: 16 public:
17 TransactionDisplay ( QWidget* parent ); 17 TransactionDisplay ( QWidget* parent );
18 18
19 QListView* listview; 19 QListView* listview;
20 QPushButton* newtransaction; 20 QPushButton* newtransaction;
21 QPushButton* edittransaction; 21 QPushButton* edittransaction;
22 QPushButton* deletetransaction; 22 QPushButton* deletetransaction;
23 QPushButton* toggletransaction; 23 QPushButton* toggletransaction;
24 QPushButton* viewtransactionnotes; 24 QPushButton* viewtransactionnotes;
25 25
26 QLabel *name; 26 QLabel *name;
27 QLabel *balance; 27 QLabel *balance;
28 QLineEdit *limitbox; 28 QLineEdit *limitbox;
29 QLineEdit *amount; 29 QLineEdit *amount;
30 QLineEdit *date; 30 QLineEdit *date;
31 31
32 int getIDColumn (); 32 int getIDColumn ();
33 33
34 public slots: 34 public slots:
35 void setChildren ( bool ); 35 void setChildren ( bool );
36 void setAccountID ( int ); 36 void setAccountID ( int );
37 void showTransactionNotes (); 37 void showTransactionNotes ();
38 38
39 private slots: 39 private slots:
40 void addTransaction (); 40 void addTransaction ();
41 void editTransaction (); 41 void editTransaction ();
42 void editTransfer (); 42 void editTransfer ();
43 void deleteTransaction (); 43 void deleteTransaction ();
44 void toggleTransaction (); 44 void toggleTransaction ();
45 void checkListViewDelete (); 45 void checkListViewDelete ();
46 void checkListViewEdit (); 46 void checkListViewEdit ();
47 void checkListViewToggle (); 47 void checkListViewToggle ();
48 void saveColumnSize ( int column, int oldsize, int newsize ); 48 void saveColumnSize ( int column, int oldsize, int newsize );
49 void limitDisplay ( const QString & ); 49 void limitDisplay ( const QString & );
50 void showCalculator (); 50 void showCalculator ();
51 void showCalendar (); 51 void showCalendar ();
52 void setTransactionDisplayDate (); 52 void setTransactionDisplayDate ();
53 void saveSortingPreference ( int column );
53 54
54 private: 55 private:
55 int accountid, fromaccount, fromparent, toaccount, toparent, day, month, year, transferid; 56 int accountid, fromaccount, fromparent, toaccount, toparent, day, month, year, transferid;
56 QDate displaydate; 57 QDate displaydate;
57 bool children; 58 bool children;
58 QBoxLayout *layout; 59 QBoxLayout *layout;
59 QHBox *firstline; 60 QHBox *firstline;
60 QHBox *secondline; 61 QHBox *secondline;
61 void redisplayAccountBalance (); 62 void redisplayAccountBalance ();
62 void updateAndDisplay ( int accountid ); 63 void updateAndDisplay ( int accountid );
63 }; 64 };
64 65
65#endif 66#endif
66 67
67#ifndef COLORLISTITEM_H 68#ifndef COLORLISTITEM_H
68#define COLORLISTITEM_H 69#define COLORLISTITEM_H
69 70
70class ColorListItem : public QListViewItem 71class ColorListItem : public QListViewItem
71 { 72 {
72 public: 73 public:
73 74
74 ColorListItem ( QListView *parent ); 75 ColorListItem ( QListView *parent );
75 ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ); 76 ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 );
76 ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ); 77 ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 );
77 78
78 virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); 79 virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
79 }; 80 };
80 81
81#endif 82#endif
82 83
diff --git a/noncore/apps/qashmoney/transfer.cpp b/noncore/apps/qashmoney/transfer.cpp
index 77cbb4e..568d584 100755
--- a/noncore/apps/qashmoney/transfer.cpp
+++ b/noncore/apps/qashmoney/transfer.cpp
@@ -1,253 +1,260 @@
1#include "transfer.h" 1#include "transfer.h"
2#include "account.h" 2#include "account.h"
3#include "transactiondisplay.h" 3#include "transactiondisplay.h"
4#include <stdlib.h> 4#include <stdlib.h>
5#include <iostream.h> 5#include <iostream.h>
6 6
7extern Account *account; 7extern Account *account;
8extern Preferences *preferences; 8extern Preferences *preferences;
9 9
10Transfer::Transfer () 10Transfer::Transfer ()
11 { 11 {
12 db = sqlite_open ( "qmtransfers.db", 0, 0 ); 12 db = sqlite_open ( "qmtransfers.db", 0, 0 );
13 } 13 }
14 14
15Transfer::~Transfer () 15Transfer::~Transfer ()
16 { 16 {
17 sqlite_close ( db ); 17 sqlite_close ( db );
18 } 18 }
19 19
20void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared ) 20void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared )
21 { 21 {
22 int nextrowid = -1; 22 int nextrowid = -1;
23 char **results; 23 char **results;
24 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); 24 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 );
25 if ( atoi ( results [ 1 ] ) != 0 ) 25 if ( atoi ( results [ 1 ] ) != 0 )
26 { 26 {
27 char **results; 27 char **results;
28 sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 ); 28 sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 );
29 nextrowid = ( atoi ( results [ 1 ] ) ) - 1; 29 nextrowid = ( atoi ( results [ 1 ] ) ) - 1;
30 } 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 ); 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 } 32 }
33 33
34void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid ) 34void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid )
35 { 35 {
36 sqlite_exec_printf ( db, "update transfers set fromaccount = %i, fromparent = %i, toaccount = %i, toparent = %i, day = %i, month = %i, year = %i, 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 ); 37 amount = %.2f, cleared = %i where transferid = %i;", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, transferid );
38 } 38 }
39 39
40void Transfer::deleteTransfer ( int transferid ) 40void Transfer::deleteTransfer ( int transferid )
41 { 41 {
42 sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid ); 42 sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid );
43 } 43 }
44 44
45void Transfer::deleteAllTransfers ( int accountid ) 45void Transfer::deleteAllTransfers ( int accountid )
46 { 46 {
47 sqlite_exec_printf ( db, "delete from transfers where fromaccount = %i;", 0, 0, 0, accountid ); 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 ); 48 sqlite_exec_printf ( db, "delete from transfers where toaccount = %i;", 0, 0, 0, accountid );
49 } 49 }
50 50
51int Transfer::getNumberOfTransfers () 51int Transfer::getNumberOfTransfers ()
52 { 52 {
53 char **results; 53 char **results;
54 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); 54 sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 );
55 return atoi ( results [ 1 ] ); 55 return atoi ( results [ 1 ] );
56 } 56 }
57 57
58int Transfer::getNumberOfTransfers ( int accountid ) 58int Transfer::getNumberOfTransfers ( int accountid )
59 { 59 {
60 char **results; 60 char **results;
61 sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid ); 61 sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid );
62 int transfers = atoi ( results [ 1 ] ); 62 int transfers = atoi ( results [ 1 ] );
63 sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid ); 63 sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid );
64 transfers = transfers + atoi ( results [ 1 ] ); 64 transfers = transfers + atoi ( results [ 1 ] );
65 return transfers; 65 return transfers;
66 } 66 }
67 67
68void Transfer::displayTransfers ( QListView *listview, int accountid, bool children ) 68void Transfer::displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate )
69 { 69 {
70 int showcleared = preferences->getPreference ( 3 ); 70 int showcleared = preferences->getPreference ( 3 );
71 71
72 // select the from transfers to display 72 // select the from transfers to display
73 char **results; 73 char **results;
74 int rows, columns; 74 int rows, columns;
75 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) 75 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE )
76 { 76 {
77 if ( showcleared == 0 ) 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 ); 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 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 ); 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 } 81 }
82 else 82 else
83 { 83 {
84 if ( showcleared == 0 ) 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 ); 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 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 ); 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 } 88 }
89 89
90 // iterate through the list and display the from items 90 // iterate through the list and display the from items
91 int counter = 7; 91 int counter = 7;
92 int position = 0; 92 int position = 0;
93 while ( counter < ( ( rows + 1 ) * columns ) ) 93 while ( counter < ( ( rows + 1 ) * columns ) )
94 { 94 {
95 // construct the date 95 // construct the date
96 QString daystring = results [ counter ]; 96 QString daystring = results [ counter ];
97 int day = daystring.toInt (); 97 int day = daystring.toInt ();
98 QString monthstring = results [ counter + 1 ]; 98 QString monthstring = results [ counter + 1 ];
99 int month = monthstring.toInt (); 99 int month = monthstring.toInt ();
100 QString yearstring = results [ counter + 2 ]; 100 QString yearstring = results [ counter + 2 ];
101 int year = yearstring.toInt (); 101 int year = yearstring.toInt ();
102 QString date = preferences->getDate ( year, month, day ); 102 QString date = preferences->getDate ( year, month, day );
103 QDate testdate ( year, month, day );
103 104
104 //construct the amount and id strings 105 //construct the amount and id strings
105 QString amount = results [ counter + 3 ]; 106 QString amount = results [ counter + 3 ];
106 QString id = results [ counter + 4 ]; 107 QString id = results [ counter + 4 ];
107 108
108 // construct the transaction name 109 // construct the transaction name
109 QString transactionname = "FROM: "; 110 QString transactionname = "FROM: ";
110 QString temp1 = results [ counter + 5 ]; 111 QString temp1 = results [ counter + 5 ];
111 transactionname.append ( account->getAccountName ( temp1.toInt() ) ); 112 transactionname.append ( account->getAccountName ( temp1.toInt() ) );
112 113
113 QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) ); 114 QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) );
114 115
115 // display this transfer 116 if ( testdate >= displaydate || showcleared == 0 )
116 if ( account->getParentAccountID ( accountid ) == -1 )
117 { 117 {
118 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) 118 // display this transfer
119 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount ); 119 if ( account->getParentAccountID ( accountid ) == -1 )
120 {
121 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
122 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount );
123 else
124 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount );
125 }
120 else 126 else
121 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount ); 127 {
128 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
129 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
130 else
131 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
132 }
122 } 133 }
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; 134 counter = counter + 7;
132 } 135 }
133 136
134 // select the to transfers to display 137 // select the to transfers to display
135 char **toresults; 138 char **toresults;
136 rows = 0; 139 rows = 0;
137 columns = 0; 140 columns = 0;
138 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) 141 if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE )
139 { 142 {
140 if ( showcleared == 0 ) 143 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 ); 144 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 145 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 ); 146 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromparent = %i;", &toresults, &rows, &columns, 0, accountid );
144 } 147 }
145 else 148 else
146 { 149 {
147 if ( showcleared == 0 ) 150 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 ); 151 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 152 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 ); 153 sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromaccount = %i;", &toresults, &rows, &columns, 0, accountid );
151 } 154 }
152 155
153 // iterate through the list and display the from items 156 // iterate through the list and display the from items
154 counter = 7; 157 counter = 7;
155 position = 0; 158 position = 0;
156 while ( counter < ( ( rows + 1 ) * columns ) ) 159 while ( counter < ( ( rows + 1 ) * columns ) )
157 { 160 {
158 // construct the date 161 // construct the date
159 QString daystring = toresults [ counter ]; 162 QString daystring = toresults [ counter ];
160 int day = daystring.toInt (); 163 int day = daystring.toInt ();
161 QString monthstring = toresults [ counter + 1 ]; 164 QString monthstring = toresults [ counter + 1 ];
162 int month = monthstring.toInt (); 165 int month = monthstring.toInt ();
163 QString yearstring = toresults [ counter + 2 ]; 166 QString yearstring = toresults [ counter + 2 ];
164 int year = yearstring.toInt (); 167 int year = yearstring.toInt ();
165 QString date = preferences->getDate ( year, month, day ); 168 QString date = preferences->getDate ( year, month, day );
169 QDate testdate ( year, month, day );
166 170
167 //construct the amount and id strings 171 //construct the amount and id strings
168 QString amount = toresults [ counter + 3 ]; 172 QString amount = toresults [ counter + 3 ];
169 amount.prepend ( "-" ); 173 amount.prepend ( "-" );
170 QString id = toresults [ counter + 4 ]; 174 QString id = toresults [ counter + 4 ];
171 175
172 // construct the transaction name 176 // construct the transaction name
173 QString transactionname = "TO: "; 177 QString transactionname = "TO: ";
174 QString temp1 = toresults [ counter + 6 ]; 178 QString temp1 = toresults [ counter + 6 ];
175 transactionname.append ( account->getAccountName ( temp1.toInt() ) ); 179 transactionname.append ( account->getAccountName ( temp1.toInt() ) );
176 180
177 QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) ); 181 QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) );
178 182
179 // display this transfer 183 if ( testdate >= displaydate || showcleared == 0 )
180 if ( account->getParentAccountID ( accountid ) == -1 ) 184 {
181 { 185 // display this transfer
182 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) 186 if ( account->getParentAccountID ( accountid ) == -1 )
183 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount ); 187 {
184 else 188 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
185 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount ); 189 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount );
186 } 190 else
187 else 191 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount );
188 { 192 }
189 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
190 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
191 else 193 else
192 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); 194 {
195 if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
196 ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
197 else
198 QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
199 }
193 } 200 }
194 201
195 counter = counter + 7; 202 counter = counter + 7;
196 } 203 }
197 } 204 }
198 205
199int Transfer::getCleared ( int id ) 206int Transfer::getCleared ( int id )
200 { 207 {
201 char **results; 208 char **results;
202 sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id ); 209 sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id );
203 return atoi ( results [ 1 ] ); 210 return atoi ( results [ 1 ] );
204 } 211 }
205 212
206void Transfer::setCleared ( int id, int cleared ) 213void Transfer::setCleared ( int id, int cleared )
207 { 214 {
208 sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id ); 215 sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id );
209 } 216 }
210 217
211int Transfer::getFromAccountID ( int id ) 218int Transfer::getFromAccountID ( int id )
212 { 219 {
213 char **results; 220 char **results;
214 sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); 221 sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id );
215 return atoi ( results [ 1 ] ); 222 return atoi ( results [ 1 ] );
216 } 223 }
217 224
218int Transfer::getToAccountID ( int id ) 225int Transfer::getToAccountID ( int id )
219 { 226 {
220 char **results; 227 char **results;
221 sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); 228 sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id );
222 return atoi ( results [ 1 ] ); 229 return atoi ( results [ 1 ] );
223 } 230 }
224 231
225int Transfer::getDay ( int id ) 232int Transfer::getDay ( int id )
226 { 233 {
227 char **results; 234 char **results;
228 sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id ); 235 sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id );
229 return atoi ( results [ 1 ] ); 236 return atoi ( results [ 1 ] );
230 } 237 }
231 238
232int Transfer::getMonth ( int id ) 239int Transfer::getMonth ( int id )
233 { 240 {
234 char **results; 241 char **results;
235 sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id ); 242 sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id );
236 return atoi ( results [ 1 ] ); 243 return atoi ( results [ 1 ] );
237 } 244 }
238 245
239int Transfer::getYear ( int id ) 246int Transfer::getYear ( int id )
240 { 247 {
241 char **results; 248 char **results;
242 sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id ); 249 sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id );
243 return atoi ( results [ 1 ] ); 250 return atoi ( results [ 1 ] );
244 } 251 }
245 252
246QString Transfer::getAmount ( int id ) 253QString Transfer::getAmount ( int id )
247 { 254 {
248 char **results; 255 char **results;
249 sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id ); 256 sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id );
250 return results [ 1 ]; 257 return results [ 1 ];
251 } 258 }
252 259
253 260
diff --git a/noncore/apps/qashmoney/transfer.h b/noncore/apps/qashmoney/transfer.h
index 33dedf4..e910e7c 100755
--- a/noncore/apps/qashmoney/transfer.h
+++ b/noncore/apps/qashmoney/transfer.h
@@ -1,51 +1,52 @@
1#ifndef TRANSFER_H 1#ifndef TRANSFER_H
2#define TRANSFER_H 2#define TRANSFER_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qstring.h> 5#include <qstring.h>
6#include <sqlite.h> 6#include <sqlite.h>
7#include <qdatetime.h>
7 8
8#include "preferences.h" 9#include "preferences.h"
9 10
10class Transfer 11class Transfer
11 { 12 {
12 public: 13 public:
13 14
14 Transfer (); 15 Transfer ();
15 ~Transfer (); 16 ~Transfer ();
16 17
17 // This function adds a new transfer to the database. It takes the fromaccount, toaccount, 18 // This function adds a new transfer to the database. It takes the fromaccount, toaccount,
18 // number, frombudget, tobudget, day, month, year, amount, cleared 19 // 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 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 void updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid );
21 22
22 // Deletes a transfer. Takes the transferid as its parameter 23 // Deletes a transfer. Takes the transferid as its parameter
23 void deleteTransfer ( int ); 24 void deleteTransfer ( int );
24 25
25 // Deletes all transfers for a given accountid 26 // Deletes all transfers for a given accountid
26 void deleteAllTransfers ( int accountid ); 27 void deleteAllTransfers ( int accountid );
27 28
28 // Returns the number of checking transfers 29 // Returns the number of checking transfers
29 int getNumberOfTransfers (); 30 int getNumberOfTransfers ();
30 int getNumberOfTransfers ( int accountid ); 31 int getNumberOfTransfers ( int accountid );
31 32
32 void displayTransfers ( QListView *listview, int accountid, bool children ); 33 void displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate );
33 int getCleared ( int id ); 34 int getCleared ( int id );
34 void setCleared ( int id, int cleared ); 35 void setCleared ( int id, int cleared );
35 int getFromAccountID ( int id ); 36 int getFromAccountID ( int id );
36 int getToAccountID ( int id ); 37 int getToAccountID ( int id );
37 38
38 int getDay ( int id ); 39 int getDay ( int id );
39 int getMonth ( int id ); 40 int getMonth ( int id );
40 int getYear ( int id ); 41 int getYear ( int id );
41 QString getAmount ( int id ); 42 QString getAmount ( int id );
42 43
43 private: 44 private:
44 45
45 sqlite *db; 46 sqlite *db;
46 }; 47 };
47 48
48#endif 49#endif
49 50
50 51
51 52
diff --git a/noncore/apps/qashmoney/transferdialog.cpp b/noncore/apps/qashmoney/transferdialog.cpp
index 7bc3eb0..f85c740 100755
--- a/noncore/apps/qashmoney/transferdialog.cpp
+++ b/noncore/apps/qashmoney/transferdialog.cpp
@@ -1,114 +1,114 @@
1#include "transferdialog.h" 1#include "transferdialog.h"
2#include "datepicker.h" 2#include "datepicker.h"
3#include "calculator.h" 3#include "calculator.h"
4 4
5#include <qdatetime.h> 5#include <qdatetime.h>
6#include <qfont.h> 6#include <qfont.h>
7 7
8extern Preferences *preferences; 8extern Preferences *preferences;
9extern Account *account; 9extern Account *account;
10 10
11TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ) : QDialog ( parent, 0, TRUE ) 11TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ) : QDialog ( parent, 0, TRUE )
12 { 12 {
13 dateedited = FALSE; 13 dateedited = FALSE;
14 setCaption ( "Transfer" ); 14 setCaption ( "Transfer" );
15 15
16 fromaccountlabel = new QLabel ( "From account:", this ); 16 fromaccountlabel = new QLabel ( "From account:", this );
17 QFont f = this->font(); 17 QFont f = this->font();
18 f.setWeight ( QFont::Bold ); 18 f.setWeight ( QFont::Bold );
19 fromaccountlabel->setFont ( f ); 19 fromaccountlabel->setFont ( f );
20 fromaccount = new QLabel ( account->getAccountName ( fromaccountid ), this ); 20 fromaccount = new QLabel ( account->getAccountName ( fromaccountid ), this );
21 21
22 toaccountlabel = new QLabel ( "To Account:", this ); 22 toaccountlabel = new QLabel ( "To Account:", this );
23 toaccountlabel->setFont ( f ); 23 toaccountlabel->setFont ( f );
24 toaccount = new QLabel ( account->getAccountName ( toaccountid ), this ); 24 toaccount = new QLabel ( account->getAccountName ( toaccountid ), this );
25 25
26 datelabel = new QLabel ( "Date", this ); 26 datelabel = new QLabel ( "Date", this );
27 27
28 datebox = new QHBox ( this ); 28 datebox = new QHBox ( this );
29 datebox->setSpacing ( 2 ); 29 datebox->setSpacing ( 2 );
30 date = new QLineEdit ( datebox ); 30 date = new QLineEdit ( datebox );
31 date->setAlignment ( Qt::AlignRight ); 31 date->setAlignment ( Qt::AlignRight );
32 date->setDisabled ( TRUE ); 32 date->setDisabled ( TRUE );
33 datebutton = new QPushButton ( datebox ); 33 datebutton = new QPushButton ( datebox );
34 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 34 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
35 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 35 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
36 36
37 amounttlabel = new QLabel ( "Amount", this ); 37 amounttlabel = new QLabel ( "Amount", this );
38 38
39 amountbox = new QHBox ( this ); 39 amountbox = new QHBox ( this );
40 amountbox->setSpacing ( 2 ); 40 amountbox->setSpacing ( 2 );
41 amount = new QLineEdit ( amountbox ); 41 amount = new QLineEdit ( amountbox );
42 amount->setAlignment ( Qt::AlignRight ); 42 amount->setAlignment ( Qt::AlignRight );
43 calculatorbutton = new QPushButton( amountbox ); 43 calculatorbutton = new QPushButton( amountbox );
44 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 44 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
45 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 45 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
46 46
47 clearedcheckbox = new QCheckBox ( "Cleared", this ); 47 clearedcheckbox = new QCheckBox ( "Cleared", this );
48 48
49 layout = new QVBoxLayout ( this, 4, 2 ); 49 layout = new QVBoxLayout ( this, 4, 2 );
50 layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); 50 layout->addWidget ( fromaccountlabel, Qt::AlignLeft );
51 layout->addWidget ( fromaccount, Qt::AlignLeft ); 51 layout->addWidget ( fromaccount, Qt::AlignLeft );
52 layout->addWidget ( toaccountlabel, Qt::AlignLeft ); 52 layout->addWidget ( toaccountlabel, Qt::AlignLeft );
53 layout->addWidget ( toaccount, Qt::AlignLeft ); 53 layout->addWidget ( toaccount, Qt::AlignLeft );
54 layout->addSpacing ( 5 ); 54 layout->addSpacing ( 5 );
55 layout->addWidget ( datelabel, Qt::AlignLeft ); 55 layout->addWidget ( datelabel, Qt::AlignLeft );
56 layout->addWidget ( datebox, Qt::AlignLeft ); 56 layout->addWidget ( datebox, Qt::AlignLeft );
57 layout->addWidget ( amounttlabel, Qt::AlignLeft ); 57 layout->addWidget ( amounttlabel, Qt::AlignLeft );
58 layout->addWidget ( amountbox, Qt::AlignLeft ); 58 layout->addWidget ( amountbox, Qt::AlignLeft );
59 layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); 59 layout->addWidget ( clearedcheckbox, Qt::AlignLeft );
60 } 60 }
61 61
62bool TransferDialog::getDateEdited () 62bool TransferDialog::getDateEdited ()
63 { 63 {
64 return dateedited; 64 return dateedited;
65 } 65 }
66 66
67void TransferDialog::showCalendar () 67void TransferDialog::showCalendar ()
68 { 68 {
69 QDate newDate = QDate::currentDate (); 69 QDate newDate = QDate::currentDate ();
70 DatePicker *dp = new DatePicker ( newDate ); 70 DatePicker *dp = new DatePicker ( newDate );
71 if ( dp->exec () == QDialog::Accepted ) 71 if ( dp->exec () == QDialog::Accepted )
72 { 72 {
73 // Set date integers 73 // Set date integers
74 year = dp->getYear(); 74 year = dp->getYear();
75 month = dp->getMonth(); 75 month = dp->getMonth();
76 day = dp->getDay(); 76 day = dp->getDay();
77 77
78 // Set dateedited to TRUE 78 // Set dateedited to TRUE
79 // This tells the accountdisplay object that the user edited an account 79 // This tells the accountdisplay object that the user edited an account
80 // and did change the date 80 // and did change the date
81 dateedited = TRUE; 81 dateedited = TRUE;
82 82
83 // Display date with our selected format 83 // Display date with our selected format
84 date->setText ( preferences->getDate ( year, month, day ) ); 84 date->setText ( preferences->getDate ( year, month, day ) );
85 } 85 }
86 } 86 }
87 87
88int TransferDialog::getDay () 88int TransferDialog::getDay ()
89 { 89 {
90 return day; 90 return day;
91 } 91 }
92 92
93int TransferDialog::getMonth () 93int TransferDialog::getMonth ()
94 { 94 {
95 return month; 95 return month;
96 } 96 }
97 97
98int TransferDialog::getYear () 98int TransferDialog::getYear ()
99 { 99 {
100 return day; 100 return year;
101 } 101 }
102 102
103void TransferDialog::showCalculator () 103void TransferDialog::showCalculator ()
104 { 104 {
105 Calculator *calculator = new Calculator ( this ); 105 Calculator *calculator = new Calculator ( this );
106 if ( calculator->exec () == QDialog::Accepted ) 106 if ( calculator->exec () == QDialog::Accepted )
107 amount->setText ( calculator->display->text() ); 107 amount->setText ( calculator->display->text() );
108 } 108 }
109 109
110 110
111 111
112 112
113 113
114 114