summaryrefslogtreecommitdiff
authorallenforsythe <allenforsythe>2003-05-28 11:49:47 (UTC)
committer allenforsythe <allenforsythe>2003-05-28 11:49:47 (UTC)
commit52047fd3d3f30509d65834747c3a0c5c6760dc01 (patch) (side-by-side diff)
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 @@
QashMoney - Budget Software for the Sharp Zaurus
CHANGES
+0.76 - 5/21/03
+
+ Updated postinst file so app will install on new Sharp ROM 3.1
+ Improved algorithm for selecting cleared transaction
+ Fixed budget display bug
+
+----------------------------------------------------------------------------------
+
11/1/02 - Initial release of 0.2 version. Considered stable beta version.
11/16/02 - Release of version 0.3. This is a stable version adding function to
transfer money between accounts. Several bugs fixes and speed enhancements
have been done.
11/21/02 - 0.31 news tabs working but not yet displaying accounts
12/15/02 - QashMoney gets a complete face lift and now has a date picker.
12/29/02 - Version 0.41 released. This release fixes more bugs and adds a
function to manage transaction memory items.
12/31/02 - Version 0.42 released. Maintenance release fixing soem rather nasty
bugs that screw up account, transaction, and transfer displays.
03/03/03 - Version 0.60 released. QashMoney has undergone quite a transformation.
A new GUI that incorporates all of Qts excellent layout capabilities should
display nicely in all formats. A new embedded SQL database should make QashMoney
very extensible.
4/25/03 - Version 0.70 released. This version includes many new features over 0.60 including
currency support for accounts, a function to limit transaction views, and an all new budgeting
tab that allows multiple budgets and currency support.
5/7/03 - Version 0.73 released. Few minor bugfixes and feature enhancements. QashMoney now
right justifies all numbers and remembers the sate in which you leave the account window. So, if you
collapse 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 @@
QashMoney - Budget Software for the Sharp Zaurus
README
-Welcome to the latest version of QashMoney! This app is designed to make your
-budgeting fast, inuitive and easy.
-
This file lists all the important files in the qashmoney CVS directory and how
to make the IPK file that goes on the Zaurus. When you checkout the
-qashmoney module from CVS, it will create a directory on your hard drive called
-qashmoney. These instructions assume you are in the directory.
+qashmoney-source module from CVS, it will create a directory on your hard drive called
+qashmoney-source. These instructions assume you are in this directory.
The first thing you need to do is have all the necessary cross-compile software
and Qtopia installed on your system. I assume you have already done this since
you are downloading CVS, but if not, go to:
http://docs.zaurus.com
and download the RPMS that you need for development.
You also must have sqlite installed on your system to successfully compile
QashMoney. Go to:
http://www.sqlite.org
-to download this progam. The SQLite library has already been compiled for the
-IPK and is in the 'install' directory. So there is no need to compile SQLite
-for ARM but you can if you want. There are instructions for that on the
-website.
+to download this progam.
After that, set the correct environment variables for the package you
-are developing.Two scripts in the qashmoney are used for that purpose: x86.sh
-andarm.shIf you are buidling for x86 type:
+are developing. Two scripts in the qashmoney-source directory are used for that purpose: x86.sh
+and arm.sh. If you are building for x86 type:
source x86.sh
and press enter. To make binaries that run on the Zaurus, type:
source arm.sh
Next, construct the makefile by typing:
tmake -o Makefile qashmoney.pro
tmake is Trolltech's program for constructing a typical GNU Makefile from the
project file (qashmoney.pro for this application). If you get an "error: tmake
command not found", you either don't have all the correct RPMS installed or your
environment variables are not correctly set. If all is well type:
make
and the program should be constructed and you will be left with a qashmoney
binary in this directory. If you compiled for x86, you can see the application
by using the Qt Virtual Frame Buffer which emulates the Qtopia environment on
your computer. First, copy all the files from the databasefiles directory within the
qashmoney directory. Otherwise, the program will not function.
To run QashMoney in the Qtopia Virtual Frame Buffer, type:
qvfb &
./qashmoney -qws
and QashMoney should appear in the frambuffer. You can use and test qashmoney
here as you would on the Zaurus.
-If you compile the binary file for the Zaurus, another script in this directory
-will come in handy. To automagically make the IPK file, type:
-
-su
-./make_ipk
-
-You need to be the root user to set the ownership of the binary and other
-files correctly. The IPK file will appear in the qashmoney directory. Now put
-this file onto the Zaurus and install!
-
-Two other scripts in the directory may be of use. The make_x86 script cleans
-the directory and makes the x86 qashmoney binary automatically. The make_arm
-scripts makes the ARM binary. So you should really only have to type three
-commands the make the IPK file:
-
-./make_arm
-su
-./make_ipk
+If 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.
I hope the program can be useful. If you have any questions or comments, please
contact me at qashmoneyman@attbi.com
Thanks!
Allen
Disclaimer: Altough I've tried to make this application tight and well
functioning, it comes with absolutely no warranty and I will not be liable for
any 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,75 +1,74 @@
#include "account.h"
#include "transaction.h"
#include "transfer.h"
#include "preferences.h"
#include <qpixmap.h>
#include <stdlib.h>
#include <iostream.h>
extern Preferences *preferences;
Account::Account ()
{
adb = sqlite_open ( "qmaccounts.db", 0, NULL );
}
Account::~Account ()
{
sqlite_close ( adb );
}
void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit,
int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency )
{
- 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,
+ 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,
(const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency );
- cout << "Results = " << r << endl;
}
void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid )
{
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 );
}
void Account::deleteAccount ( int accountid )
{
sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid );
}
void Account::setAccountExpanded ( int expanded, int accountid )
{
sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid );
}
int Account::getAccountExpanded ( int id )
{
char **results;
sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id );
if ( strlen ( results [1] ) == 0 )
return 0;
else
return atoi ( results [ 1 ] );
}
int Account::getNumberOfAccounts ()
{
char **results;
sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL );
return atoi ( results [ 1 ] );
}
int Account::getNumberOfChildAccounts ( int id )
{
char **results;
sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id );
return atoi ( results [ 1 ] );
}
void Account::updateAccountBalance ( int accountid )
{
// Here, we'll get a balance for the transactions in an account
sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
int rows, columns;
char **results;
sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid );
@@ -180,96 +179,102 @@ void Account::displayAccounts ( QListView *listview )
parent->setOpen ( TRUE );
//Start display child accounts for this parent
int childcounter = 5;
while ( childcounter < total )
{
if ( atoi ( results [ childcounter + 1 ] ) == accountid )
{
if ( currency == 0 )
QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] );
else
{
// create the string we'll use to set the currency pixmap
QString filename = "/opt/QtPalmtop/pics/flags/";
QString flag = results [ childcounter + 4 ];
filename.append ( flag );
filename.append ( ".png" );
QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] );
child->setPixmap ( 1, QPixmap ( filename ) );
child->setText ( 1, flag );
}
}
childcounter = childcounter + 5;
}
//End display child accounts
}
counter = counter + 5;
}
// resize all columns appropriately
if ( preferences->getPreference ( 4 ) == 0 )
{
listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
listview->setColumnWidthMode ( 0, QListView::Manual );
listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
listview->setColumnWidthMode ( 1, QListView::Manual );
listview->setColumnWidthMode ( 2, QListView::Manual );
}
else
{
listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) );
listview->setColumnWidthMode ( 0, QListView::Manual );
listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) );
listview->setColumnWidthMode ( 1, QListView::Manual );
listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) );
listview->setColumnWidthMode ( 2, QListView::Manual );
listview->setColumnWidthMode ( 3, QListView::Manual );
}
+
+ // Now reset the column sorting to user preference
+ int column = 0;
+ int direction = 0;
+ preferences->getSortingPreference ( 1, &column, &direction );
+ listview->setSorting ( column, direction );
}
int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring )
{
char **results;
int rows, columns, index;
index = 0;
sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL );
int counter = 1;
int indexcounter = 1;
int total = ( rows + 1 ) * columns;
while ( counter < total )
{
if ( getParentAccountID ( results [ counter ] ) == -1 )
{
combobox->insertItem ( results [ counter ], -1 );
if ( strcmp ( results [ counter ], indexstring ) == 0 )
index = indexcounter;
indexcounter++;
}
counter ++;
}
return index;
}
int Account::getAccountType ( int accountid )
{
char **results;
sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
return atoi ( results [ 1 ] );
}
int Account::getStatementDay ( int accountid )
{
char **results;
sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
return atoi ( results [ 1 ] );
}
int Account::getStatementMonth ( int accountid )
{
char **results;
sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
return atoi ( results [ 1 ] );
}
int Account::getStatementYear ( int accountid )
{
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,99 +1,101 @@
#include <qdatetime.h>
#include <qmessagebox.h>
#include <qheader.h>
+#include <iostream.h>
#include "accountdisplay.h"
#include "newaccount.h"
#include "transaction.h"
#include "transferdialog.h"
#include "preferences.h"
#include "transfer.h"
extern Account *account;
extern Transaction *transaction;
extern Transfer *transfer;
extern Preferences *preferences;
AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent )
{
cleared = 0;
firstline = new QHBox ( this );
firstline->setSpacing ( 2 );
newaccount = new QPushButton ( firstline );
newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) );
editaccount = new QPushButton ( firstline );
editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) );
deleteaccount = new QPushButton ( firstline );
deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) );
transferbutton = new QPushButton ( firstline );
transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") );
transferbutton->setToggleButton ( TRUE );
connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) );
listview = new QListView ( this );
listview->setAllColumnsShowFocus ( TRUE );
listview->setShowSortIndicator ( TRUE );
listview->setRootIsDecorated ( TRUE );
listview->setMultiSelection ( FALSE );
connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) );
connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) );
-
+
listview->header()->setTracking ( FALSE );
connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
-
+ connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
+
layout = new QVBoxLayout ( this, 2, 5 );
layout->addWidget ( firstline );
layout->addWidget ( listview );
}
void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs )
{
tab2 = newtab2;
maintabs = newtabs;
}
void AccountDisplay::addAccount ()
{
// initialize local variables
int parentid = 0;
type = 0;
QString parentlist [ listview->childCount() + 1 ] [ 3 ] ;
// create new account window for entering data
NewAccount *newaccount = new NewAccount ( this );
int width = this->width();
newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) );
newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) );
newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
// if there are no accounts, disable the child check box
if ( account->getNumberOfAccounts () == 0 )
newaccount->childcheckbox->setEnabled ( FALSE );
// if there are accounts, fill up the pulldown menu for
// selecting a parent account. We should only add those parents without transactions
else
{
int c = 0;
QListViewItemIterator it ( listview );
for ( ; it.current(); ++it )
{
int id = it.current()->text ( getIDColumn() ).toInt();
// iterate through accountdisplay listview and add parents with no transactions
// add this item to the list box only if it is a parent and has no transactions
if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 )
{
newaccount->childbox->insertItem ( it.current()->text ( 0 ) );
parentlist [ c ] [ 0 ] = it.current()->text ( 0 );
parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() );
parentlist [ c ] [ 2 ] = QString::number ( c );
@@ -223,175 +225,178 @@ void AccountDisplay::accountTransfer ( bool state )
{
firstaccountid = -1;
secondaccountid = -1;
listview->clearSelection ();
listview->setMultiSelection ( TRUE );
disableParentsWithChildren ();
connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
}
else
{
firstaccountid = -1;
secondaccountid = -1;
listview->clearSelection ();
listview->setMultiSelection ( FALSE );
enableAccounts ();
disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
}
}
void AccountDisplay::getTransferAccounts ( QListViewItem * item )
{
if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children
{
if ( firstaccountid == -1 )
firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account
else
if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first
secondaccountid = item->text ( getIDColumn() ).toInt();
}
// open transfer window if both accounts are set
if ( firstaccountid != -1 && secondaccountid != -1 )
{
// construct the transferdialog window
TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid );
// enter today's date in the date box as default
QDate today = QDate::currentDate ();
int defaultday = today.day();
int defaultmonth = today.month();
int defaultyear = today.year();
td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
if ( td->exec() == QDialog::Accepted )
{
// set the cleared integer if the checkbox is checked
if ( td->clearedcheckbox->isChecked() == TRUE )
cleared = 1;
-
+ cout << "Year from transferdialog = " << td->getYear() << endl;
// add the transfer with a new date if its been edited or use the default date
if ( td->getDateEdited () == TRUE )
- transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid,
- account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared );
+ transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared );
else
- transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid,
- account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared );
+ transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared );
// update account balances of both accounts and parents if necessary
account->updateAccountBalance ( firstaccountid );
if ( account->getParentAccountID ( firstaccountid ) != -1 )
account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) );
account->updateAccountBalance ( secondaccountid );
if ( account->getParentAccountID ( secondaccountid ) != -1 )
account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) );
// redisplay accounts
account->displayAccounts ( listview );
}
else
{
firstaccountid = -1;
secondaccountid = -1;
listview->clearSelection ();
listview->setMultiSelection ( FALSE );
disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
}
// reset the accounts display window
transferbutton->toggle(); // toggling this button with clear the window as well
// reenable all the accounts so the transaction tab will be properly set
enableAccounts ();
}
}
void AccountDisplay::disableParentsWithChildren ()
{
// iterate through accountdisplay listview and disable all the parents that have children
QListViewItemIterator it ( listview );
for ( ; it.current(); ++it )
{
if ( it.current()->parent() == 0 && it.current()->childCount() != 0 )
it.current()->setSelectable ( FALSE );
}
}
void AccountDisplay::enableAccounts ()
{
// iterate through accountdisplay listview and enable all accounts
QListViewItemIterator it ( listview );
for ( ; it.current(); ++it )
it.current()->setSelectable ( TRUE );
}
void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize )
{
switch ( column )
{
case 0:
if ( listview->columns() == 3 )
preferences->changeColumnPreference ( 1, newsize );
else
preferences->changeColumnPreference ( 10, newsize );
break;
case 1:
if ( listview->columns() == 3 )
preferences->changeColumnPreference ( 2, newsize );
else
preferences->changeColumnPreference ( 11, newsize );
break;
case 2:
preferences->changeColumnPreference ( 12, newsize );
break;
}
}
+void AccountDisplay::saveSortingPreference ( int column )
+ {
+ preferences->changeSortingPreference ( 1, column );
+ }
+
int AccountDisplay::getIDColumn ()
{
int counter;
int columns = listview->columns();
for ( counter = 0; counter <= columns; counter++ )
if ( listview->header()->label ( counter ).length() == 0 )
return counter;
}
void AccountDisplay::editAccount ()
{
if ( listview->selectedItem() == 0 )
QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit.");
else
{
// set the accountid
int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt();
//construct new dialog box
QDialog *editaccountwindow = new QDialog ( this, 0, TRUE );
editaccountwindow->setCaption ( "Edit Account" );
// construct the items which will go in the dialog bix
QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow );
QLineEdit *accountname = new QLineEdit ( editaccountwindow );
QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow );
QLineEdit *accountdescription = new QLineEdit ( editaccountwindow );
Currency *currencybox = new Currency ( editaccountwindow );
QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 );
layout->addWidget ( namelabel );
layout->addWidget ( accountname );
layout->addWidget ( descriptionlabel );
layout->addWidget ( accountdescription );
layout->addWidget ( currencybox );
//set the account name
accountname->setText ( listview->selectedItem()->text ( 0 ) );
//set the account description
accountdescription->setText ( account->getAccountDescription ( accountid ) );
if ( preferences->getPreference ( 4 ) == 1 )
{
// get currency code for this account then iterate through the currency box
// to find the one we want
int count = currencybox->currencybox->count();
QString code = account->getCurrencyCode ( accountid );
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 @@
#ifndef ACCOUNTDISPLAY_H
#define ACCOUNTDISPLAY_H
#include <qlistview.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtabwidget.h>
#include <qhbox.h>
class AccountDisplay : public QWidget
{
Q_OBJECT
public:
AccountDisplay ( QWidget *parent );
QHBox *firstline;
QPushButton* newaccount;
QPushButton* editaccount;
QPushButton* deleteaccount;
QPushButton* transferbutton;
QListView* listview;
QBoxLayout *layout;
void setTabs ( QWidget *newtab2, QTabWidget *newtabs );
int getIDColumn ();
void setToggleButton ();
public slots:
void addAccount ();
void editAccount ();
void deleteAccount ();
void accountTransfer ( bool state );
void getTransferAccounts ( QListViewItem * item );
void disableParentsWithChildren ();
void enableAccounts ();
private slots:
void saveColumnSize ( int column, int oldsize, int newsize );
void setAccountExpanded ( QListViewItem *item );
void setAccountCollapsed ( QListViewItem *item );
+ void saveSortingPreference ( int column );
private:
int type, firstaccountid, secondaccountid, cleared;
QWidget *tab2;
QTabWidget *maintabs;
};
#endif // ACCOUNTDISPLAY_H
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,113 +1,114 @@
#include "budget.h"
#include "transaction.h"
#include <stdlib.h>
+#include <iostream.h>
extern Transaction *transaction;
Budget::Budget ()
{
bdb = sqlite_open ( "qmbudgets.db", 0, NULL );
}
Budget::~Budget ()
{
sqlite_close ( bdb );
}
int Budget::addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview )
{
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 );
char **results;
sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL );
QString tablename = "table";
tablename.append ( results [ 1 ] );
sqlite_exec_printf ( bdb, "create table '%q' ( name, lineitemamount, type, lineitemid integer primary key );", 0, 0, 0, ( const char* ) tablename );
return atoi ( results [ 1 ] );
}
void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid )
{
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 );
}
void Budget::deleteBudget ( int budgetid )
{
if ( getNumberOfBudgets() != 0 )
{
QString tablename = "table";
tablename.append ( QString::number ( budgetid ) );
sqlite_exec_printf ( bdb, "delete from budgets where budgetid = %i;", 0, 0, 0, budgetid );
sqlite_exec_printf ( bdb, "drop table '%q';", 0, 0, 0, ( const char* ) tablename );
}
}
int Budget::getNumberOfBudgets ()
{
char **results;
sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL );
return atoi ( results [ 1 ] );
}
int Budget::getNumberOfLineItems ( int budgetid )
{
QString tablename = "table";
tablename.append ( QString::number ( budgetid ) );
char **results;
sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename );
return atoi ( results [ 1 ] );
}
QStringList* Budget::getBudgetNames ()
{
QStringList *names = new QStringList ();
char **results;
int rows, counter;
- sqlite_get_table ( bdb, "select name from budgets order by name asc;", &results, &rows, NULL, NULL );
+ sqlite_get_table ( bdb, "select name from budgets;", &results, &rows, NULL, NULL );
names->append ( "None" );
for ( counter = 0; counter < rows; counter++ )
names->append ( results [ counter+1 ] );
return names;
}
QString Budget::getBudgetName ( int budgetid )
{
char **results;
sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
return ( QString ) results [ 1 ];
}
QString Budget::getBudgetDescription ( int budgetid )
{
char **results;
sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
return ( QString ) results [ 1 ];
}
QString Budget::getCurrency ( int budgetid )
{
char **results;
sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid );
return ( QString ) results [ 1 ];
}
QStringList* Budget::getBudgetIDs ()
{
QStringList *ids = new QStringList ();
char **results;
int rows, counter;
sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL );
for ( counter = 0; counter < rows; counter++ )
ids->append ( results [ counter+1 ] );
return ids;
}
int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype )
{
QString tablename = "table";
tablename.append ( QString::number ( budgetid ) );
sqlite_exec_printf ( bdb, "insert into '%q' values ( '%q', %.2f, %i, NULL );", 0, 0, 0, ( const char* ) tablename, ( const char* ) lineitemname, lineitemamount, lineitemtype );
char **results;
sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename );
return atoi ( results [ 1 ] );
}
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
@@ -37,132 +37,144 @@ BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent )
menu->setFrameStyle ( QFrame::Box | QFrame::Sunken );
budgetmenu = new QPopupMenu ( this );
lineitemsmenu = new QPopupMenu ( this );
datemenu = new QPopupMenu ( this );
menu->insertItem ( "Budget", budgetmenu );
menu->insertItem ( "Line Item", lineitemsmenu );
menu->insertItem ( "Date", datemenu );
budgetmenu->insertItem ( "New", this, SLOT ( newBudget () ), 0, 1 );
budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget () ), 0, 2 );
budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget () ), 0, 3 );
lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem () ), 0, 1 );
lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem () ), 0, 2 );
lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem () ), 0, 3 );
datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) );
budgetbox = new QComboBox ( firstline );
connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) );
budgetview = new QComboBox ( firstline );
budgetview->insertItem ( "Month" );
budgetview->insertItem ( "Year" );
connect ( budgetview, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentView ( int ) ) );
budgeted = new QLabel ( secondline );
budgeted->setFont ( font );
actual = new QLabel ( secondline );
actual->setFont ( font );
date = new QLabel ( secondline );
date->setFont ( font );
listview = new QListView ( this );
listview->setAllColumnsShowFocus ( TRUE );
listview->setShowSortIndicator ( TRUE );
listview->setRootIsDecorated ( TRUE );
listview->setMultiSelection ( FALSE );
listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13
listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14
listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15
listview->addColumn ( "", 0 ); // line item ids
listview->setColumnWidthMode ( 0, QListView::Manual );
listview->setColumnWidthMode ( 1, QListView::Manual );
listview->setColumnWidthMode ( 2, QListView::Manual );
listview->setColumnAlignment ( 1, Qt::AlignRight );
listview->setColumnAlignment ( 2, Qt::AlignRight );
listview->setColumnWidthMode ( 3, QListView::Manual );
listview->header()->setTracking ( FALSE );
connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
+ connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
+
+ // pull the column sorting preference from the preferences table, and configure the listview accordingly
+ int column = 0;
+ int direction = 0;
+ preferences->getSortingPreference ( 3, &column, &direction );
+ listview->setSorting ( column, direction );
displayBudgetNames();
layout = new QVBoxLayout ( this, 2, 2 );
layout->setMenuBar ( menu );
layout->addWidget ( firstline );
layout->addWidget ( secondline );
layout->addWidget ( listview );
}
void BudgetDisplay::deleteBudget ()
{
listview->clear();
transaction->clearBudgetIDs ( currentbudget );
budget->deleteBudget ( currentbudget );
if ( budgetbox->count() != 0 )
displayBudgetNames();
checkBudgets();
}
void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize )
{
switch ( column )
{
case 0:
preferences->changeColumnPreference ( 13, newsize );
break;
case 1:
preferences->changeColumnPreference ( 14, newsize );
break;
case 2:
preferences->changeColumnPreference ( 15, newsize );
break;
}
}
+void BudgetDisplay::saveSortingPreference ( int column )
+ {
+ preferences->changeSortingPreference ( 3, column );
+ }
+
int BudgetDisplay::getIDColumn ()
{
int counter;
int columns = listview->columns();
for ( counter = 0; counter <= columns; counter++ )
if ( listview->header()->label ( counter ).length() == 0 )
return counter;
}
void BudgetDisplay::newBudget ()
{
constructBudgetWindow();
int response = nb->exec();
if ( response == 1 )
{
// open a new budget object
int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 );
transaction->clearBudgetIDs ( addedbudget );
displayBudgetNames();
}
checkBudgets();
}
void BudgetDisplay::constructBudgetWindow ()
{
//construct and format the new budget window
nb = new QDialog ( this, 0, TRUE );
nb->setCaption ( "Budget" );
QLabel *namelabel = new QLabel ( "Budget Name", nb );
budgetname = new QLineEdit ( nb );
QLabel *descriptionlabel = new QLabel ( "Description", nb );
description = new QLineEdit ( nb );
currencybox = new Currency ( nb );
QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 );
layout->addWidget ( namelabel );
layout->addWidget ( budgetname );
layout->addWidget ( descriptionlabel );
layout->addWidget ( description );
layout->addWidget ( currencybox );
}
void BudgetDisplay::displayBudgetNames ()
{
budgetbox->clear();
if ( budget->getNumberOfBudgets() != 0 )
{
ids = budget->getBudgetIDs();
for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it )
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
@@ -24,62 +24,63 @@ class BudgetDisplay : public QWidget
QPEMenuBar *menu;
QPopupMenu *budgetmenu;
QPopupMenu *lineitemsmenu;
QPopupMenu *datemenu;
QHBox *firstline;
QHBox *secondline;
QLabel *budgeted;
QLabel *actual;
QLabel *date;
QLineEdit *budgetname;
QLineEdit *description;
Currency *currencybox;
QLineEdit *lineitemname;
QLineEdit *lineitemamount;
QComboBox *lineitemtime;
QListView *listview;
QComboBox *budgetbox;
QComboBox *budgetview;
QBoxLayout *layout;
int getIDColumn ();
public slots:
void displayBudgetNames ();
void displayLineItems ();
void updateBudgetInformation ();
private slots:
void saveColumnSize ( int column, int oldsize, int newsize );
void newBudget ();
void deleteBudget ();
void setCurrentBudget ( int );
void setCurrentView ( int );
void showCalendar ();
void newLineItem ();
void deleteLineItem ();
void checkBudgets ();
void editBudget ();
void editLineItem ();
void constructBudgetWindow ();
void constructLineItemWindow ();
+ void saveSortingPreference ( int column );
private:
QStringList *names;
QStringList *ids;
int currentbudget, year, month, day;
QDate newDate;
QString totalbudget, totalactual;
QString datelabel;
QDialog *nb;
QDialog *newlineitem;
};
#endif // BUDGETDISPLAY_H
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 @@
Package: qashmoney
+Files: bin/qashmoney pics/qashmony/* pics/qashmony/flags/* apps/Applications/qashmoney.desktop
Priority: optional
-Version: 0.75
+Version: 0.76
Architecture: arm
-Maintainer: Allen Forsythe qashmoneyman@attbi.com
+Maintainer: Allen Forsythe allen@qashmoney.org
Section: Applications
Description: 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
@@ -105,108 +105,158 @@ void Preferences::initializeColumnPreferences ()
sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize transactionname column width
sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize transactionamount column width
sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize transactionaccount column width
sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize account name with currency column width
sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize account currency column width
sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize account balance with currency column width
sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize budget line item column
sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize budget budget column
sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 );
// initialize budget actual column
sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 );
if ( rows == 0 )
sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 );
}
+void Preferences::initializeSortingPreferences ()
+ {
+ int rows = 0;
+ int columns = 0;
+ char **results;
+
+ if ( sqlite_get_table ( db, "select count() from sorting;", 0, 0, 0, 0 ) != 0 )
+ sqlite_exec ( db, "create table sorting ( listbox, column, direction, id integer primary key );", 0, 0, 0 );
+
+ // initialize account listbox sorting. Set direction = 1 here so ascending sort is default.
+ sqlite_get_table ( db, "select column, direction from sorting where id = 1;", &results, &rows, &columns, 0 );
+ if ( rows == 0 )
+ sqlite_exec ( db, "insert into sorting values ( 'accounts', 0, 1, NULL );", 0, 0, 0 );
+
+ // initialize transaction listbox sorting
+ sqlite_get_table ( db, "select column, direction from sorting where id = 2;", &results, &rows, &columns, 0);
+ if ( rows == 0 )
+ sqlite_exec ( db, "insert into sorting values ( 'transactions', 0, 1, NULL );", 0, 0, 0 );
+
+ // initialize budgets listbox sorting
+ sqlite_get_table ( db, "select column, direction from sorting where id = 3;", & results, &rows, &columns, 0 );
+ if ( rows == 0 )
+ sqlite_exec ( db, "insert into sorting values ( 'budgets', 0, 1, NULL );", 0, 0, 0 );
+ }
+
void Preferences::changeColumnPreference ( int id, int width )
{
sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id );
}
int Preferences::getColumnPreference ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id );
return atoi ( results [ 1 ] );
}
+void Preferences::changeSortingPreference ( int id, int column )
+ {
+ int pColumn = 0; // column setting coming from the prefs object
+ int pDirection = 0; // direction setting coming from the prefs object
+
+ // because there appears to be no way to query the QT header object directly for it's current sort settings, we have
+ // to maintain track of them ourselves. So start by pulling the current saved setting for this view.
+ getSortingPreference ( id, &pColumn, &pDirection );
+
+ // if the current saved column == the new column, then the user wants to toggle the sort order.
+ // otherwise we behave like QT does by default, which is to select the new column and default to an ascending sort.
+ if ( column == pColumn )
+ sqlite_exec_printf ( db, "update sorting set direction = %i where id = %i;", 0, 0, 0, !pDirection, id );
+ else
+ sqlite_exec_printf ( db, "update sorting set column = %i, direction = 1 where id = %i;", 0, 0, 0, column, id );
+ }
+
+void Preferences::getSortingPreference ( int id, int *column, int *direction )
+ {
+ char **results;
+ sqlite_get_table_printf ( db, "select column, direction from sorting where id = %i;", &results, NULL, NULL, NULL, id );
+ *column = atoi ( results [ 2 ] );
+ *direction = atoi ( results [ 3 ] );
+ }
+
int Preferences::getPreference ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id );
return atoi ( results [ 1 ] );
}
QString Preferences::getSeparator ( )
{
int s = getPreference ( 2 );
if ( s == 1 )
return "/";
if ( s ==2 )
return "-";
else
return ".";
}
void Preferences::changePreference ( int id, int newpreference )
{
sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id );
}
void Preferences::setDefaultDatePreferences ()
{
sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 );
sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 );
}
QString Preferences::getDate ( int y, int m, int d )
{
QString date;
int format = getPreference ( 1 );
QString separator = getSeparator();
// Convert all date integers to QStrings
QString year = QString::number ( y );
QString month = QString::number ( m );
if ( m < 10 )
month.prepend ( "0" );
QString day = QString::number ( d );
if ( d < 10 )
day.prepend ( "0" );
// Truncate four digit year if necessary
if ( format == 2 || format == 4 || format == 6 || format == 8 )
year.remove ( 0, 2 );
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 @@
#include <sqlite.h>
#include <qstring.h>
#ifndef PREFERENCES_H
#define PREFERENCES_H
class Preferences
{
public:
Preferences ();
~Preferences ();
void addPreferences ();
void initializeColumnPreferences ();
+ void initializeSortingPreferences ();
// Returns a preference value for the given preferences ID
int getPreference ( int );
int getColumnPreference ( int id );
+ void getSortingPreference ( int id, int *column, int *direction );
// Convenience for getting date separator with one function
// call. Takes the preference id as its argument
QString getSeparator ( );
// Changes a preference for the given ID
void changePreference ( int , int );
void changeColumnPreference ( int id, int width );
+ void changeSortingPreference ( int id, int column );
// The primary database that stores all our data
sqlite *db;
// This function returns a Qstring for the year first date formats
// for displaying. It takes the date numbers
QString getDate ( int, int, int );
QString getDate ( int y, int m );
void setDefaultDatePreferences ();
};
#endif
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,66 +1,67 @@
#include "qashmoney.h"
#include "preferencedialogs.h"
#include "memorydialog.h"
#include <qheader.h>
#include <iostream.h>
Budget *budget = new Budget ();
Preferences *preferences = new Preferences ();
Account *account = new Account ();
Transaction *transaction = new Transaction ();
Transfer *transfer = new Transfer ();
Memory *memory = new Memory ();
QashMoney::QashMoney () : QWidget ()
{
- preferences->addPreferences();
+ preferences->addPreferences ();
preferences->initializeColumnPreferences ();
+ preferences->initializeSortingPreferences ();
// set the text in the upper part of the frame
setCaption ( tr ( "QashMoney" ) );
// Create new menubar for our mainwindow
// and add menu items
mainmenu = new QPEMenuBar ( this );
mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised );
preferencesmenu = new QPopupMenu ( this );
utilitiesmenu = new QPopupMenu ( this );
mainmenu->insertItem ( "Preferences", preferencesmenu );
mainmenu->insertItem ( "Utilities", utilitiesmenu );
preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog () ) );
preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog () ) );
preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog () ) );
utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog () ) );
// create the main tabwidget for displaying accounts and transactions
maintabs = new QTabWidget ( this );
tab = new QWidget ( this );
tab_2 = new QWidget ( this );
tab_3 = new QWidget ( this );
maintabs->addTab ( tab, "Accounts" );
maintabs->addTab ( tab_2, "Transactions" );
maintabs->addTab ( tab_3, "Budgets" );
tabheight = tab->height();
maintabs->setTabEnabled ( tab_2, FALSE );
// create a new account display object
accountdisplay = new AccountDisplay ( maintabs );
accountdisplay->setTabs ( tab_2, maintabs );
connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( setTransactionTab () ) );
// set the connection to disable the one touch account viewing if we are transfering money
connect ( accountdisplay->transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( toggleOneTouchViewing ( bool ) ) );
// create a new transactiondisplay object
transactiondisplay = new TransactionDisplay ( maintabs );
transactiondisplay->hide();
// create new budgetdisplay object
budgetdisplay = new BudgetDisplay ( maintabs );
budgetdisplay->hide();
tabslayout = new QVBoxLayout ( maintabs, 4, 2 );
tabslayout->addSpacing ( tabheight );
tabslayout->addWidget ( accountdisplay );
tabslayout->addWidget ( transactiondisplay );
@@ -108,283 +109,295 @@ void QashMoney::changeTabDisplay ()
QString balance = account->getAccountBalance ( accountid );
transactiondisplay->name->setText ( name );
transactiondisplay->balance->setText ( balance );
// clear the limitbox
transactiondisplay->limitbox->clear();
// get parent account id
int parentaccountid = account->getParentAccountID ( accountid );
// add columns based on which account is selected
// this first if determines if we selected a parent with no children or a child
// in these cases, we add standard three columns for date, transaction, amount
transactiondisplay->listview->addColumn ( "Date", 0 );
transactiondisplay->listview->addColumn ( "Transaction", 0 );
transactiondisplay->listview->addColumn ( "Amt", 0);
transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight );
transactiondisplay->listview->addColumn ( "", 0 );
if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children
{
// add an extra column for the account name for eac child transaction
transactiondisplay->listview->addColumn ( "Acct", 0 );
children = TRUE;
// hide the new transaction button
transactiondisplay->newtransaction->setEnabled ( FALSE );
}
else //we selected a parent without children or a child
transactiondisplay->newtransaction->setEnabled ( TRUE );
// disable the transactionid column so it can't be red
transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 );
// set the accountid and children variables
transactiondisplay->setChildren ( children );
transactiondisplay->setAccountID ( accountid );
setTransactionDisplayDate ();
// display transactions
transactiondisplay->listview->clear();
QString displaytext = "%";
displaytext.prepend ( transactiondisplay->limitbox->text() );
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
// display transfers
- transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
+ transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
// open a new preferences object and resize the transaction display columns
// each column will have a different size based on whether we are looking at a child
// account or children through a parent
if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns
{
transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width
transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width
transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width
transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
}
else
{
transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width
transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual );
transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width
transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual );
transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width
transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual );
transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width
transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual );
}
+
+ // pull the column sorting preference from the preferences table, and configure the listview accordingly
+ int column = 0;
+ int direction = 0;
+ preferences->getSortingPreference ( 2, &column, &direction );
+ transactiondisplay->listview->setSorting ( column, direction );
// show the window
transactiondisplay->show();
// hide the account display and define accountid
accountdisplay->hide();
// hide the budget display
budgetdisplay->hide();
}
else if ( maintabs->currentPageIndex() == 0 )
{
disableOneTouchViewing();
// clear the account display selection
accountdisplay->listview->clearSelection();
// resize the account display columns
accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
+ // set sorting preference on account display columns
+ int column = 0;
+ int direction = 0;
+ preferences->getSortingPreference ( 1, &column, &direction );
+ accountdisplay->listview->setSorting ( column, direction );
+
// display the accounts
if ( account->getNumberOfAccounts() != 0 )
account->displayAccounts ( accountdisplay->listview );
maintabs->setTabEnabled ( tab_2, FALSE );
// set the toggle button
accountdisplay->setToggleButton ();
// show the account display
accountdisplay->show();
// hide the transaction display
transactiondisplay->hide();
// hide the budget display
budgetdisplay->hide();
enableOneTouchViewing ();
}
else
{
budgetdisplay->displayLineItems();
budgetdisplay->show();
transactiondisplay->hide();
accountdisplay->hide();
}
}
void QashMoney::setTransactionTab ()
{
if ( accountdisplay->listview->selectedItem() == 0 )
maintabs->setTabEnabled ( tab_2, FALSE );
else
maintabs->setTabEnabled ( tab_2, TRUE );
}
void QashMoney::displayDatePreferencesDialog ()
{
// this shows a dialog to set preferences for formatting the date
DatePreferences *pd = new DatePreferences ( this );
pd->exec ();
if ( transactiondisplay->isVisible() )
{
// set the account id
int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
// set children so we can let displayTransfers know if there are children for the selected account
bool children;
if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
children = TRUE;
else
children = FALSE;
// redisplay transactions if they are visible incorporating
// any changes to the date format
transactiondisplay->listview->clear();
QString displaytext = "%";
displaytext.prepend ( transactiondisplay->limitbox->text() );
setTransactionDisplayDate();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
if ( transfer->getNumberOfTransfers() != 0 )
- transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
+ transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
}
else if ( accountdisplay->isVisible() )
{
accountdisplay->listview->clearSelection();
maintabs->setTabEnabled ( tab_2, FALSE );
}
else
budgetdisplay->updateBudgetInformation();
}
void QashMoney::displayTransactionPreferencesDialog ()
{
// display a dialog for setting preferences for transactions
TransactionPreferences *td = new TransactionPreferences ( this );
td->exec ();
if ( transactiondisplay->isVisible() )
{
// set the account id
int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
// set children so we can let displayTransfers know if there are children for the selected account
bool children;
if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 )
children = TRUE;
else
children = FALSE;
// redisplay transactions incorporating any transaction preference changes
transactiondisplay->listview->clear();
QString displaytext = "%";
displaytext.prepend ( transactiondisplay->limitbox->text() );
setTransactionDisplayDate();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate );
if ( transfer->getNumberOfTransfers() != 0 )
- transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
+ transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate );
}
else
{
accountdisplay->listview->clearSelection();
maintabs->setTabEnabled ( tab_2, FALSE );
}
}
void QashMoney::displayAccountPreferencesDialog ()
{
// display a dialog for setting preferences for accounts
AccountPreferences *ap = new AccountPreferences ( this );
ap->exec ();
if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 )
{
accountdisplay->listview->clear();
account->displayAccounts ( accountdisplay->listview );
accountdisplay->listview->clearSelection();
maintabs->setTabEnabled ( tab_2, FALSE );
}
changeTabDisplay();
}
void QashMoney::displayMemoryDialog ()
{
// opens a dialog to add, edit and delete memory items
MemoryDialog *md = new MemoryDialog ();
md->exec();
}
void QashMoney::showTransactions ()
{
maintabs->setCurrentPage ( 1 );
}
void QashMoney::enableOneTouchViewing ()
{
if ( preferences->getPreference ( 5 ) == 1 )
connect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
else
disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
}
void QashMoney::disableOneTouchViewing ()
{
disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged () ), this, SLOT ( showTransactions () ) );
}
void QashMoney::toggleOneTouchViewing ( bool state )
{
if ( state == TRUE )
disableOneTouchViewing();
else
enableOneTouchViewing();
}
void QashMoney::setTransactionDisplayDate ()
{
// determine how many days of transactions to show
int limittype = preferences->getPreference ( 7 );
if ( limittype != 5 ) // set today's date if we are not showing all transactions
{
QDate today = QDate::currentDate ();
switch ( limittype ) // if we are not showing all transactions
{
case 0: // viewing two weeks
newdate = today.addDays ( -14 );
break;
case 1: // viewing one month
newdate = today.addDays ( -30 );
break;
case 2: // three months
newdate = today.addDays ( -90 );
break;
case 3: // six months
newdate = today.addDays ( -180 );
break;
case 4: // one year
newdate = today.addDays ( -365 );
break;
}
}
else
- newdate = QDate ( 1, 1, 1000 );
+ newdate = QDate ( 1900, 1, 1 );
}
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
@@ -110,151 +110,227 @@ int Transaction::getCleared ( int id )
return cleared.toInt();
}
void Transaction::setCleared ( int id, int cleared )
{
sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id );
}
int Transaction::getBudgetID ( int id )
{
char **results;
sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id );
QString budgetid = results [ 1 ];
return budgetid.toInt();
}
int Transaction::getLineItemID ( int id )
{
char **results;
sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id );
QString lineitemid = results [ 1 ];
return lineitemid.toInt();
}
int Transaction::getDay ( int id )
{
char **results;
sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
QString daystring = results [ 1 ];
return daystring.toInt();
}
int Transaction::getMonth ( int id )
{
char **results;
sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
QString monthstring = results [ 1 ];
return monthstring.toInt();
}
int Transaction::getYear ( int id )
{
char **results;
sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
QString yearstring = results [ 1 ];
return yearstring.toInt();
}
-void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate )
+char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id )
{
+ // initialize variables
+ char **results;
int showcleared = preferences->getPreference ( 3 );
- int year = ( displaydate.year() ) - 1;
+ QDate today = QDate::currentDate();
+ int fromyear = fromdate.year();
+ int toyear = today.year();
+ int frommonth = fromdate.month();
+ int tomonth = today.month();
+ int fromday = fromdate.day();
- // select the transactions to display
- // two different statements are used based on
- // whether we are showing cleared transactions
- char **results;
- int rows, columns;
- if ( showcleared == 0 )
+ // construct the first part of the string
+ QString query = "select day, month, year, payee, amount, transid, accountid from transactions where";
+
+ if ( frommonth == tomonth && fromyear == toyear ) // our dates cross neither a month nor a year
{
- if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
- 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 );
- else
- 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 );
+ query.append ( " year = " );
+ query.append ( QString::number ( toyear ) );
+ query.append ( " and month = " );
+ query.append ( QString::number ( tomonth ) );
+ query.append ( " and day >= " );
+ query.append ( QString::number ( fromday ) );
+ query.append ( " and" );
}
- else
+ else if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year
{
- if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
- 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 );
- else
- 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 );
+ query.append ( " year = " );
+ query.append ( QString::number ( toyear ) );
+ query.append ( " and ( ( month <= " );
+ query.append ( QString::number ( tomonth ) );
+ query.append ( " and month > " );
+ query.append ( QString::number ( frommonth ) );
+ query.append ( " ) or ( month = " );
+ query.append ( QString::number ( frommonth ) );
+ query.append ( " and day >= " );
+ query.append ( QString::number ( fromday ) );
+ query.append ( " ) ) and " );
}
+ else if ( fromyear != toyear && fromyear != 1900 ) // here we are showing transactions from an entire year
+ {
+ // divide this taks into two parts - get the transactions from the prior and then the current year
+ // current year part
+ int tmpfrommonth = 1; // set temporary from months and days to Jan. 1
+ int tmpfromday = 1;
+ query.append ( " ( year >= " );
+ query.append ( QString::number ( fromyear ) );
+ query.append ( " and ( month <= " );
+ query.append ( QString::number ( tomonth ) );
+ query.append ( " and month > " );
+ query.append ( QString::number ( tmpfrommonth ) );
+ query.append ( " ) or ( month = " );
+ query.append ( QString::number ( tmpfrommonth ) );
+ query.append ( " and day >= " );
+ query.append ( QString::number ( tmpfromday ) );
+ query.append ( " ) ) or" );
+
+ // prior year part
+ int tmptomonth = 12;
+ query.append ( " ( year = " );
+ query.append ( QString::number ( fromyear ) );
+ query.append ( " and ( ( month <= " );
+ query.append ( QString::number ( tmptomonth ) );
+ query.append ( " and month > " );
+ query.append ( QString::number ( frommonth ) );
+ query.append ( " ) or ( month = " );
+ query.append ( QString::number ( frommonth ) );
+ query.append ( " and day >= " );
+ query.append ( QString::number ( fromday ) );
+ query.append ( " ) ) ) and " );
+ }
+
+ if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
+ query.append ( " parentid = %i and payee like '%q';" );
+ else
+ query.append ( " accountid = %i and payee like '%q';" );
+
+ sqlite_get_table_printf ( tdb, query, &results, &rows, &columns, NULL, id, limit );
+ return results;
+ }
+
+char ** Transaction::selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id )
+ {
+ char **results;
+ if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
+ 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 );
+ else
+ 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 );
+ return results;
+ }
+
+void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate )
+ {
+ int showcleared = preferences->getPreference ( 3 );
+
+ char **results;
+ if ( showcleared == 0 )
+ results = selectNonClearedTransactions ( displaydate, children, limit, id );
+ else
+ results = selectAllTransactions ( displaydate, children, limit, id );
// iterate through the result list and display each item
int counter = 7;
while ( counter < ( ( rows + 1 ) * columns ) )
{
- QDate displaydate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
+ //QDate testdate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) );
// construct transaction name, amount, id
QString payee = results [ counter + 3 ];
QString amount = results [ counter + 4 ];
QString transferid = results [ counter + 5 ];
//determine the account name of the child accounts that we're displaying
QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) );
- // fill in values
+ // fill in values
if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account
{
if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 )
- ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid);
+ ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid );
else
QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid );
}
- else
- {
+ else
+ {
if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 )
ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname );
else
QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname );
- }
+ }
// advance counter
counter = counter + 7;
}
}
QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype )
{
// determine if we are viewing a years, months, or days budget
// we have to pick a different sum for each
char **results;
switch ( viewtype )
{
case 1: // we are viewing a year
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 );
break;
case 0: // we are viewing a month
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 );
break;
}
QString amount = results [ 1 ];
float total = amount.toFloat();
amount.setNum ( total, 'f', 2 );
return amount;
}
QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype )
{
// determine if we are viewing a years, months, or days budget
// we have to pick a different sum for each
char **results;
switch ( viewtype )
{
case 1: // we are viewing a year
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 );
break;
case 0: // we are viewing a month
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 );
break;
}
QString amount = results [ 1 ];
float total = amount.toFloat();
amount.setNum ( total, 'f', 2 );
return amount;
}
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 @@
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <qstring.h>
#include <qlistview.h>
#include <qdatetime.h>
#include <sqlite.h>
#include "preferences.h"
class Transaction
{
public:
Transaction ();
~Transaction ();
// This function adds a new transaction to the database. It takes the payee, accountid,
// budgetid, number, day, month, year, amount, cleared
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 );
// This updates an already existing transaction
void updateTransaction ( QString, QString, int, int, int, int, float, int, int, int, int );
// Deletes a transaction. Takes the transid as its parameter
void deleteTransaction ( int );
// Returns the number of transactions
int getNumberOfTransactions ();
// this is an overloaded function that returns the number of
// transactions for an account
int getNumberOfTransactions ( int );
// deletes all transactions for the provided accountid
void deleteAllTransactions ( int accountid );
QString getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype );
QString getActualTotal ( int budgetid, int year, int month, int viewtype );
// These two functions clear budget ids is either a line item or an entire budget is deleted
void clearBudgetIDs ( int, int );
void clearBudgetIDs ( int );
public slots:
void displayTransactions ( QListView *, int, bool, const char *, QDate );
+ char ** selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id );
+ char ** selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id );
QString getPayee ( int );
QString getTransactionDescription ( int );
QString getNumber ( int );
QString getAmount ( int );
QString getAbsoluteAmount ( int );
int getCleared ( int );
void setCleared ( int id, int cleared );
int getBudgetID ( int id );
int getLineItemID ( int id );
int getDay ( int );
int getMonth ( int );
int getYear ( int );
int getAccountID ( int id );
private:
sqlite *tdb;
+ int rows, columns;
};
#endif
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
@@ -22,163 +22,164 @@ extern Preferences *preferences;
extern Memory *memory;
extern Transfer *transfer;
TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent )
{
// set transactiondisplay variables;
accountid = 0;
children = TRUE;
firstline = new QHBox ( this );
firstline->setSpacing ( 2 );
newtransaction = new QPushButton ( firstline );
newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) );
edittransaction = new QPushButton ( firstline );
edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) );
deletetransaction = new QPushButton ( firstline );
deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) );
toggletransaction = new QPushButton ( firstline );
toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") );
connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) );
viewtransactionnotes = new QPushButton ( firstline );
viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") );
connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) );
secondline = new QHBox ( this );
secondline->setSpacing ( 5 );
name = new QLabel ( secondline );
balance = new QLabel ( secondline );
QLabel *limit = new QLabel ( "Limit", secondline );
limitbox = new QLineEdit ( secondline );
limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) );
connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) );
listview = new QListView ( this );
listview->setAllColumnsShowFocus ( TRUE );
listview->setShowSortIndicator ( TRUE );
listview->header()->setTracking ( FALSE );
connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
+ connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
layout = new QVBoxLayout ( this, 2, 2 );
layout->addWidget ( firstline );
layout->addWidget ( secondline );
layout->addWidget ( listview );
}
void TransactionDisplay::addTransaction ()
{
// create local variables
int cleared = -1;
// create new transaction window
NewTransaction *newtransaction = new NewTransaction ( this );
int width = this->size().width();
newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
// enter today's date in the date box as defaul
QDate today = QDate::currentDate ();
int defaultday = today.day();
int defaultmonth = today.month();
int defaultyear = today.year();
newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
// add memory items to the transactionname combobox
memory->displayMemoryItems ( newtransaction->transactionname );
newtransaction->transactionname->insertItem ( "", 0 );
if ( newtransaction->exec () == QDialog::Accepted )
{
if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction
cleared = 1;
else
cleared = 0;
float amount = newtransaction->transactionamount->text().toFloat();
if ( newtransaction->depositbox->isChecked() == FALSE )
amount = amount * -1;
// add the transaction name to the memory items
memory->addMemoryItem ( newtransaction->transactionname->currentText() );
// add the transaction
if ( newtransaction->getDateEdited () == TRUE )
transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(),
newtransaction->getCurrentLineItem() );
else
transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() );
// redisplay transactions
listview->clear();
QString displaytext = "%";
displaytext.prepend ( limitbox->text() );
setTransactionDisplayDate ();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
// redisplay transfers
if ( transfer->getNumberOfTransfers() > 0 )
- transfer->displayTransfers ( listview, accountid, children );
+ transfer->displayTransfers ( listview, accountid, children, displaydate );
// add the transaction amount to the account it's associated with
// and update its parent account balance if necessary
account->updateAccountBalance ( accountid );
if ( account->getParentAccountID ( accountid ) != -1 )
account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
// format then reset the account balance
redisplayAccountBalance ();
}
}
void TransactionDisplay::checkListViewEdit ()
{
if ( listview->selectedItem() == 0 )
QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit.");
else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
editTransfer ();
else
editTransaction();
}
void TransactionDisplay::showCalculator ()
{
Calculator *calculator = new Calculator ( this );
if ( calculator->exec () == QDialog::Accepted )
amount->setText ( calculator->display->text() );
}
void TransactionDisplay::showCalendar ()
{
QDate newDate = QDate::currentDate ();
DatePicker *dp = new DatePicker ( newDate );
if ( dp->exec () == QDialog::Accepted )
{
year = dp->getYear();
month = dp->getMonth();
day = dp->getDay();
date->setText ( preferences->getDate ( year, month, day ) );
}
}
void TransactionDisplay::editTransfer ()
{
transferid = listview->currentItem()->text ( getIDColumn() ).toInt();
fromaccount = transfer->getFromAccountID ( transferid );
toaccount = transfer->getToAccountID ( transferid );
year = transfer->getYear ( transferid );
@@ -327,297 +328,302 @@ void TransactionDisplay::editTransaction ()
{
newtransaction->lineitemlabel->setEnabled ( FALSE );
newtransaction->lineitembox->setEnabled ( FALSE );
}
// check cleared checkbox if necessary
if ( transaction->getCleared ( transactionid ) == 1 )
newtransaction->clearedcheckbox->setChecked ( TRUE );
// check deposit box if necessary
if ( transaction->getAmount ( transactionid ).toFloat() > 0 )
newtransaction->depositbox->setChecked ( TRUE );
if ( newtransaction->exec () == QDialog::Accepted )
{
if ( newtransaction->clearedcheckbox->isChecked () == TRUE )
cleared = 1;
else
cleared = 0;
float amount = newtransaction->transactionamount->text().toFloat();
if ( newtransaction->depositbox->isChecked() == FALSE )
amount = amount * -1;
// add the transaction name to the memory items
memory->addMemoryItem ( newtransaction->transactionname->currentText() );
// update the transaction
transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(),
newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(),
amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid );
updateAndDisplay ( transaction->getAccountID ( transactionid ) );
}
}
void TransactionDisplay::updateAndDisplay ( int id )
{
// redisplay transactions
listview->clear();
QString displaytext = "%";
displaytext.prepend ( limitbox->text() );
setTransactionDisplayDate ();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
// redisplay transfers
if ( transfer->getNumberOfTransfers() > 0 )
- transfer->displayTransfers ( listview, accountid, children );
+ transfer->displayTransfers ( listview, accountid, children, displaydate );
// add the transaction amount to the account it's associated with
// and update its parent account balance if necessary
account->updateAccountBalance ( id );
if ( account->getParentAccountID ( id ) != -1 )
account->changeParentAccountBalance ( account->getParentAccountID ( id ) );
// format then reset the account balance
redisplayAccountBalance ();
}
void TransactionDisplay::checkListViewDelete ()
{
if ( listview->selectedItem() == 0 )
QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete.");
else
deleteTransaction ();
}
void TransactionDisplay::deleteTransaction ()
{
int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
if ( transactionid > 0 ) // takes care of deleting transactions
{
// check if we are viewing child transactions through a parent
// in that case we will have to update balances for the parent
// which is represented by accountid and the child account
// which will be represented by childaccountid
int childaccountid = -1;
if ( listview->columns() == 5 )
childaccountid = transaction->getAccountID ( transactionid );
transaction->deleteTransaction ( transactionid );
listview->clear();
QString displaytext = "%";
displaytext.prepend ( limitbox->text() );
setTransactionDisplayDate ();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
if ( transfer->getNumberOfTransfers() > 0 )
- transfer->displayTransfers ( listview, accountid, children );
+ transfer->displayTransfers ( listview, accountid, children, displaydate );
// if we are viewing different child accounts through the parent account
// ie if there are five columns and the parentid is -1
// update the accountid ( which is the parent ) and update the child account
// balance. Get its accountid from the transactionid
account->updateAccountBalance ( accountid ); // will update either a parent or child
if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one
account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
if ( childaccountid != -1 ) // we've set childaccountid
account->updateAccountBalance ( childaccountid );
// format then reset the account balance
redisplayAccountBalance ();
}
else // takes care of deleting transfers
{
// get the accountids before we delete the transfer
int fromaccountid = transfer->getFromAccountID ( transactionid );
int toaccountid = transfer->getToAccountID ( transactionid );
// delete the transfer and redisplay transactions
transfer->deleteTransfer ( transactionid );
listview->clear();
QString displaytext = "%";
displaytext.prepend ( limitbox->text() );
setTransactionDisplayDate ();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
if ( transfer->getNumberOfTransfers() > 0 )
- transfer->displayTransfers ( listview, accountid, children );
+ transfer->displayTransfers ( listview, accountid, children, displaydate );
// for the from account
account->updateAccountBalance ( fromaccountid );
if ( account->getParentAccountID ( fromaccountid ) != -1 )
account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) );
// for the to account
account->updateAccountBalance ( toaccountid );
if ( account->getParentAccountID ( toaccountid ) != -1 )
account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) );
// format then reset the account balance
redisplayAccountBalance ();
}
}
void TransactionDisplay::checkListViewToggle ()
{
if ( listview->selectedItem() == 0 )
QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset.");
else
toggleTransaction ();
}
void TransactionDisplay::toggleTransaction ()
{
//get the transaction of the selected transaction to determine if its a transaction or transfer
int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
if ( transactionid > 0 ) // if this is a transaction
{
if ( transaction->getCleared ( transactionid ) == 0 )
transaction->setCleared ( transactionid, 1 );
else
transaction->setCleared ( transactionid, 0 );
}
else
{
if ( transfer->getCleared ( transactionid ) == 0 )
transfer->setCleared ( transactionid, 1 );
else
transfer->setCleared ( transactionid, 0 );
}
listview->clear();
QString displaytext = "%";
displaytext.prepend ( limitbox->text() );
setTransactionDisplayDate ();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
if ( transfer->getNumberOfTransfers() != 0 )
- transfer->displayTransfers ( listview, accountid, children );
+ transfer->displayTransfers ( listview, accountid, children, displaydate );
}
void TransactionDisplay::redisplayAccountBalance ()
{
QString accountbalance = account->getAccountBalance ( accountid );
balance->setText ( accountbalance );
}
void TransactionDisplay::setChildren ( bool c )
{
children = c;
}
void TransactionDisplay::setAccountID ( int id )
{
accountid = id;
}
ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent )
{
}
ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
: QListViewItem ( parent, label1, label2, label3, label4 )
{
}
ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
: QListViewItem ( parent, label1, label2, label3, label4, label5 )
{
}
void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
{
QColorGroup _cg ( cg );
_cg.setColor ( QColorGroup::Text, Qt::red );
QListViewItem::paintCell ( p, _cg, column, width, alignment );
}
void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize )
{
if ( listview->columns() == 4 )
preferences->changeColumnPreference ( column + 3, newsize );
else if ( listview->columns() == 5 && column != 4 )
preferences->changeColumnPreference ( column + 6, newsize );
else
preferences->changeColumnPreference ( 9, newsize );
}
+void TransactionDisplay::saveSortingPreference ( int column )
+ {
+ preferences->changeSortingPreference ( 2, column );
+ }
+
void TransactionDisplay::limitDisplay ( const QString &text )
{
listview->clear ();
QString displaytext = "%";
displaytext.prepend ( text );
setTransactionDisplayDate ();
if ( transaction->getNumberOfTransactions() > 0 )
transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 )
- transfer->displayTransfers ( listview, accountid, children );
+ transfer->displayTransfers ( listview, accountid, children, displaydate );
}
int TransactionDisplay::getIDColumn ()
{
int counter;
int columns = listview->columns();
for ( counter = 0; counter <= columns; counter++ )
if ( listview->header()->label ( counter ).length() == 0 )
return counter;
}
void TransactionDisplay::showTransactionNotes ()
{
if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes.");
else
{
int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
QDialog *description = new QDialog ( this, "description", TRUE );
description->setCaption ( "Notes" );
QMultiLineEdit *notes = new QMultiLineEdit ( description );
notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
notes->setWordWrap ( QMultiLineEdit::WidgetWidth );
notes->setEnabled ( FALSE );
notes->setText ( transaction->getTransactionDescription ( transactionid ) );
description->show();
}
}
void TransactionDisplay::setTransactionDisplayDate ()
{
// determine how many days of transactions to show
int limittype = preferences->getPreference ( 7 );
if ( limittype != 5 ) // set today's date if we are not showing all transactions
{
QDate today = QDate::currentDate ();
switch ( limittype ) // if we are not showing all transactions
{
case 0: // viewing two weeks
displaydate = today.addDays ( -14 );
break;
case 1: // viewing one month
displaydate = today.addDays ( -30 );
break;
case 2: // three months
displaydate = today.addDays ( -90 );
break;
case 3: // six months
displaydate = today.addDays ( -180 );
break;
case 4: // one year
displaydate = today.addDays ( -365 );
break;
}
}
else
- displaydate = QDate ( 1, 1, 1000 );
+ displaydate = QDate ( 1900, 1, 1 );
}
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
@@ -5,78 +5,79 @@
#include <qhbox.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qdatetime.h>
class TransactionDisplay : public QWidget
{
Q_OBJECT
public:
TransactionDisplay ( QWidget* parent );
QListView* listview;
QPushButton* newtransaction;
QPushButton* edittransaction;
QPushButton* deletetransaction;
QPushButton* toggletransaction;
QPushButton* viewtransactionnotes;
QLabel *name;
QLabel *balance;
QLineEdit *limitbox;
QLineEdit *amount;
QLineEdit *date;
int getIDColumn ();
public slots:
void setChildren ( bool );
void setAccountID ( int );
void showTransactionNotes ();
private slots:
void addTransaction ();
void editTransaction ();
void editTransfer ();
void deleteTransaction ();
void toggleTransaction ();
void checkListViewDelete ();
void checkListViewEdit ();
void checkListViewToggle ();
void saveColumnSize ( int column, int oldsize, int newsize );
void limitDisplay ( const QString & );
void showCalculator ();
void showCalendar ();
void setTransactionDisplayDate ();
+ void saveSortingPreference ( int column );
private:
int accountid, fromaccount, fromparent, toaccount, toparent, day, month, year, transferid;
QDate displaydate;
bool children;
QBoxLayout *layout;
QHBox *firstline;
QHBox *secondline;
void redisplayAccountBalance ();
void updateAndDisplay ( int accountid );
};
#endif
#ifndef COLORLISTITEM_H
#define COLORLISTITEM_H
class ColorListItem : public QListViewItem
{
public:
ColorListItem ( QListView *parent );
ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 );
ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 );
virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
};
#endif
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
@@ -20,221 +20,228 @@ Transfer::~Transfer ()
void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared )
{
int nextrowid = -1;
char **results;
sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 );
if ( atoi ( results [ 1 ] ) != 0 )
{
char **results;
sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 );
nextrowid = ( atoi ( results [ 1 ] ) ) - 1;
}
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 );
}
void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid )
{
sqlite_exec_printf ( db, "update transfers set fromaccount = %i, fromparent = %i, toaccount = %i, toparent = %i, day = %i, month = %i, year = %i,
amount = %.2f, cleared = %i where transferid = %i;", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, transferid );
}
void Transfer::deleteTransfer ( int transferid )
{
sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid );
}
void Transfer::deleteAllTransfers ( int accountid )
{
sqlite_exec_printf ( db, "delete from transfers where fromaccount = %i;", 0, 0, 0, accountid );
sqlite_exec_printf ( db, "delete from transfers where toaccount = %i;", 0, 0, 0, accountid );
}
int Transfer::getNumberOfTransfers ()
{
char **results;
sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 );
return atoi ( results [ 1 ] );
}
int Transfer::getNumberOfTransfers ( int accountid )
{
char **results;
sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid );
int transfers = atoi ( results [ 1 ] );
sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid );
transfers = transfers + atoi ( results [ 1 ] );
return transfers;
}
-void Transfer::displayTransfers ( QListView *listview, int accountid, bool children )
+void Transfer::displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate )
{
int showcleared = preferences->getPreference ( 3 );
// select the from transfers to display
char **results;
int rows, columns;
if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE )
{
if ( showcleared == 0 )
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 );
else
sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toparent = %i;", &results, &rows, &columns, 0, accountid );
}
else
{
if ( showcleared == 0 )
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 );
else
sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toaccount = %i;", &results, &rows, &columns, 0, accountid );
}
// iterate through the list and display the from items
int counter = 7;
int position = 0;
while ( counter < ( ( rows + 1 ) * columns ) )
{
// construct the date
QString daystring = results [ counter ];
int day = daystring.toInt ();
QString monthstring = results [ counter + 1 ];
int month = monthstring.toInt ();
QString yearstring = results [ counter + 2 ];
int year = yearstring.toInt ();
QString date = preferences->getDate ( year, month, day );
+ QDate testdate ( year, month, day );
//construct the amount and id strings
QString amount = results [ counter + 3 ];
QString id = results [ counter + 4 ];
// construct the transaction name
QString transactionname = "FROM: ";
QString temp1 = results [ counter + 5 ];
transactionname.append ( account->getAccountName ( temp1.toInt() ) );
QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) );
- // display this transfer
- if ( account->getParentAccountID ( accountid ) == -1 )
+ if ( testdate >= displaydate || showcleared == 0 )
{
- if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
- ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount );
+ // display this transfer
+ if ( account->getParentAccountID ( accountid ) == -1 )
+ {
+ if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
+ ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount );
+ else
+ QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount );
+ }
else
- QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount );
+ {
+ if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
+ ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
+ else
+ QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
+ }
}
- else
- {
- if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
- ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
- else
- QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
- }
-
counter = counter + 7;
}
// select the to transfers to display
char **toresults;
rows = 0;
columns = 0;
if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE )
{
if ( showcleared == 0 )
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 );
else
sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromparent = %i;", &toresults, &rows, &columns, 0, accountid );
}
else
{
if ( showcleared == 0 )
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 );
else
sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromaccount = %i;", &toresults, &rows, &columns, 0, accountid );
}
// iterate through the list and display the from items
counter = 7;
position = 0;
while ( counter < ( ( rows + 1 ) * columns ) )
{
// construct the date
QString daystring = toresults [ counter ];
int day = daystring.toInt ();
QString monthstring = toresults [ counter + 1 ];
int month = monthstring.toInt ();
QString yearstring = toresults [ counter + 2 ];
int year = yearstring.toInt ();
QString date = preferences->getDate ( year, month, day );
+ QDate testdate ( year, month, day );
//construct the amount and id strings
QString amount = toresults [ counter + 3 ];
amount.prepend ( "-" );
QString id = toresults [ counter + 4 ];
// construct the transaction name
QString transactionname = "TO: ";
QString temp1 = toresults [ counter + 6 ];
transactionname.append ( account->getAccountName ( temp1.toInt() ) );
QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) );
- // display this transfer
- if ( account->getParentAccountID ( accountid ) == -1 )
- {
- if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
- ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount );
- else
- QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount );
- }
- else
- {
- if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
- ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
+ if ( testdate >= displaydate || showcleared == 0 )
+ {
+ // display this transfer
+ if ( account->getParentAccountID ( accountid ) == -1 )
+ {
+ if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
+ ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount );
+ else
+ QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount );
+ }
else
- QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
+ {
+ if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 )
+ ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id );
+ else
+ QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id );
+ }
}
counter = counter + 7;
}
}
int Transfer::getCleared ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id );
return atoi ( results [ 1 ] );
}
void Transfer::setCleared ( int id, int cleared )
{
sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id );
}
int Transfer::getFromAccountID ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id );
return atoi ( results [ 1 ] );
}
int Transfer::getToAccountID ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id );
return atoi ( results [ 1 ] );
}
int Transfer::getDay ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id );
return atoi ( results [ 1 ] );
}
int Transfer::getMonth ( int id )
{
char **results;
sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id );
return atoi ( results [ 1 ] );
}
int Transfer::getYear ( int id )
{
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 @@
#ifndef TRANSFER_H
#define TRANSFER_H
#include <qlistview.h>
#include <qstring.h>
#include <sqlite.h>
+#include <qdatetime.h>
#include "preferences.h"
class Transfer
{
public:
Transfer ();
~Transfer ();
// This function adds a new transfer to the database. It takes the fromaccount, toaccount,
// number, frombudget, tobudget, day, month, year, amount, cleared
void addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared );
void updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid );
// Deletes a transfer. Takes the transferid as its parameter
void deleteTransfer ( int );
// Deletes all transfers for a given accountid
void deleteAllTransfers ( int accountid );
// Returns the number of checking transfers
int getNumberOfTransfers ();
int getNumberOfTransfers ( int accountid );
- void displayTransfers ( QListView *listview, int accountid, bool children );
+ void displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate );
int getCleared ( int id );
void setCleared ( int id, int cleared );
int getFromAccountID ( int id );
int getToAccountID ( int id );
int getDay ( int id );
int getMonth ( int id );
int getYear ( int id );
QString getAmount ( int id );
private:
sqlite *db;
};
#endif
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
@@ -52,63 +52,63 @@ TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccou
layout->addWidget ( toaccountlabel, Qt::AlignLeft );
layout->addWidget ( toaccount, Qt::AlignLeft );
layout->addSpacing ( 5 );
layout->addWidget ( datelabel, Qt::AlignLeft );
layout->addWidget ( datebox, Qt::AlignLeft );
layout->addWidget ( amounttlabel, Qt::AlignLeft );
layout->addWidget ( amountbox, Qt::AlignLeft );
layout->addWidget ( clearedcheckbox, Qt::AlignLeft );
}
bool TransferDialog::getDateEdited ()
{
return dateedited;
}
void TransferDialog::showCalendar ()
{
QDate newDate = QDate::currentDate ();
DatePicker *dp = new DatePicker ( newDate );
if ( dp->exec () == QDialog::Accepted )
{
// Set date integers
year = dp->getYear();
month = dp->getMonth();
day = dp->getDay();
// Set dateedited to TRUE
// This tells the accountdisplay object that the user edited an account
// and did change the date
dateedited = TRUE;
// Display date with our selected format
date->setText ( preferences->getDate ( year, month, day ) );
}
}
int TransferDialog::getDay ()
{
return day;
}
int TransferDialog::getMonth ()
{
return month;
}
int TransferDialog::getYear ()
{
- return day;
+ return year;
}
void TransferDialog::showCalculator ()
{
Calculator *calculator = new Calculator ( this );
if ( calculator->exec () == QDialog::Accepted )
amount->setText ( calculator->display->text() );
}