summaryrefslogtreecommitdiff
path: root/noncore/apps/qashmoney
authorallenforsythe <allenforsythe>2003-05-13 21:14:56 (UTC)
committer allenforsythe <allenforsythe>2003-05-13 21:14:56 (UTC)
commitf08e51ae62bf814b4cbf8873afd0e44b167cb9b4 (patch) (side-by-side diff)
treebab48138189f471aa8f18dd53dd57b4d0bfd156b /noncore/apps/qashmoney
parentf31e2ecd95aba951dc77d98f02b45cb1297046ac (diff)
downloadopie-f08e51ae62bf814b4cbf8873afd0e44b167cb9b4.zip
opie-f08e51ae62bf814b4cbf8873afd0e44b167cb9b4.tar.gz
opie-f08e51ae62bf814b4cbf8873afd0e44b167cb9b4.tar.bz2
Initial revision
Diffstat (limited to 'noncore/apps/qashmoney') (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/CHANGES24
-rwxr-xr-xnoncore/apps/qashmoney/account.h100
-rwxr-xr-xnoncore/apps/qashmoney/accountdisplay.cpp432
-rwxr-xr-xnoncore/apps/qashmoney/budget.cpp221
-rwxr-xr-xnoncore/apps/qashmoney/budget.h45
-rwxr-xr-xnoncore/apps/qashmoney/memory.cpp62
-rwxr-xr-xnoncore/apps/qashmoney/memory.h45
-rwxr-xr-xnoncore/apps/qashmoney/preferences.h50
-rwxr-xr-xnoncore/apps/qashmoney/qashmoney.cpp356
-rwxr-xr-xnoncore/apps/qashmoney/transaction.cpp274
-rwxr-xr-xnoncore/apps/qashmoney/transaction.h69
-rwxr-xr-xnoncore/apps/qashmoney/transactiondisplay.h79
-rwxr-xr-xnoncore/apps/qashmoney/transfer.cpp253
-rwxr-xr-xnoncore/apps/qashmoney/transfer.h51
14 files changed, 2061 insertions, 0 deletions
diff --git a/noncore/apps/qashmoney/CHANGES b/noncore/apps/qashmoney/CHANGES
new file mode 100755
index 0000000..f17035b
--- a/dev/null
+++ b/noncore/apps/qashmoney/CHANGES
@@ -0,0 +1,24 @@
+QashMoney - Budget Software for the Sharp Zaurus
+
+CHANGES
+
+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/account.h b/noncore/apps/qashmoney/account.h
new file mode 100755
index 0000000..f77f400
--- a/dev/null
+++ b/noncore/apps/qashmoney/account.h
@@ -0,0 +1,100 @@
+#ifndef ACCOUNT_H
+#define ACCOUNT_H
+
+#include <qstring.h>
+#include <qlistview.h>
+#include <qcombobox.h>
+#include <sqlite.h>
+
+class Account
+ {
+ public:
+
+ Account ();
+ ~Account ();
+
+ // This function adds a new account to the database. It takes the account name, parent,
+ // initial balance and the account type, description, credit limit, statementbalancedate
+ // as three integers, and the statementbalance amount
+ // The parent is an integer account id. Its -1 if there is no parent
+ // The account types (so far) are 0=not defined 1=parent checking 2=child checking
+ void addAccount ( QString, int, float, int, QString, float, int, int, int, float, const char * );
+
+ // updates certain parts of an account
+ void updateAccount ( QString name, QString description, QString currencycode, int accountid );
+
+ void setAccountExpanded ( int expanded, int accountid );
+ int getAccountExpanded ( int id );
+
+ // Deletes an account
+ // Takes the accountid as its parameter
+ void deleteAccount ( int );
+
+ // Returns the number of accounts
+ int getNumberOfAccounts ();
+
+ // returns number of child accounts for a given parent
+ // this function is useless for child accounts. It will
+ // always return 0
+ int getNumberOfChildAccounts ( int );
+
+ // This function retrieves all transactions for an account and updates the
+ // account balance based on the transactions
+ void updateAccountBalance ( int accountid );
+ //void changeAccountBalance ( int accountid, float amount );
+
+ // updates a parent account
+ void changeParentAccountBalance ( int parentid );
+
+ // Returns the parent account ID for an account
+ // Takes the account name as its parameter or the account id
+ int getParentAccountID ( QString accountname );
+ int getParentAccountID ( int id );
+
+ // This takes a QListView and puts parents and children memorys
+ // into the list view
+ void displayAccounts ( QListView * );
+
+ // This function displays a sorted list of account names in a combobox
+ // Takes the combobox address for its parameter
+ int displayParentAccountNames ( QComboBox *, QString );
+
+ int getAccountType ( int ); // returns account type for given account id
+
+ // The next three collectively return a date or balance
+ // They take the accountid as their parameters
+ int getStatementDay ( int );
+ int getStatementMonth ( int );
+ int getStatementYear ( int );
+ float getStatementBalance ( int );
+
+ // Returns account description and name
+ QString getAccountDescription ( int accountid );
+ QString getCurrencyCode ( int accountid );
+ QString getAccountName ( int accountid );
+ QStringList getAccountNames ();
+ QStringList getAccountIDs ();
+ QString getAccountBalance ( int accountid );
+
+ // returns account credit limit
+ float getAccountCreditLimit ( int );
+
+ // The primary database that stores all our data
+ sqlite *adb;
+ };
+
+class GreyBackgroundItem : public QListViewItem
+ {
+ public:
+
+ GreyBackgroundItem ( QListView *parent );
+ GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 );
+ GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 );
+ GreyBackgroundItem ( 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/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp
new file mode 100755
index 0000000..46ab1db
--- a/dev/null
+++ b/noncore/apps/qashmoney/accountdisplay.cpp
@@ -0,0 +1,432 @@
+#include <qdatetime.h>
+#include <qmessagebox.h>
+#include <qheader.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 ) ) );
+
+ 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 );
+ c++;
+ }
+ }
+ }
+
+ if ( preferences->getPreference ( 4 ) == 0 )
+ newaccount->currencybox->setEnabled ( FALSE );
+
+ // 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();
+ newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
+
+ //add account information if user pushes OK button
+ if ( newaccount->exec() == QDialog::Accepted )
+ {
+ if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account
+ {
+ // go through the parentlist we created and determine the parent accountid
+ // we can't use the name of the account because there may be two accounts
+ // with the same name. This function does it all by accountid
+ int counter;
+ for ( counter = 0; counter < listview->childCount() + 1; counter++ )
+ if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() )
+ {
+ parentid = parentlist [ counter ] [ 1 ].toInt();
+ break;
+ }
+ type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types
+ }
+ else
+ {
+ parentid = -1;
+ type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts
+ }
+
+ // add the new account
+ if ( newaccount->getDateEdited () == TRUE )
+ account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type,
+ newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(),
+ newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() );
+ else
+ account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type,
+ newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear,
+ defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() );
+
+ if ( parentid != -1 )
+ account->changeParentAccountBalance ( parentid );
+
+ // redisplay accounts
+ // this function clears the account display first
+ account->displayAccounts ( listview );
+ setToggleButton();
+ }
+ maintabs->setTabEnabled ( tab2, FALSE );
+ }
+
+void AccountDisplay::deleteAccount ()
+ {
+ if ( listview->selectedItem() == 0 )
+ QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete.");
+ else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 )
+ QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children");
+ else
+ {
+ QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton );
+ if ( mb.exec() == QMessageBox::Ok )
+ {
+ int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
+ int parentid = account->getParentAccountID ( accountid );
+
+ // delete all the transactions and transfers for the account
+ transaction->deleteAllTransactions ( accountid );
+ transfer->deleteAllTransfers ( accountid );
+
+ // delete the account
+ account->deleteAccount ( accountid );
+
+ // update account balances
+ if ( parentid != -1 )
+ account->changeParentAccountBalance ( parentid );
+
+ //redisplay accounts
+ account->displayAccounts ( listview );
+
+ //remove all the columns from the accountdisplay if there are not any accounts
+ if ( account->getNumberOfAccounts() == 0 )
+ {
+ int columns = listview->columns();
+ int counter;
+ for ( counter = 0; counter <= columns; counter++ )
+ listview->removeColumn ( 0 );
+ }
+
+ setToggleButton();
+ }
+ }
+ maintabs->setTabEnabled ( tab2, FALSE );
+ }
+
+void AccountDisplay::setToggleButton ()
+ {
+ // iterate through account display and determine how many "transferable" accounts we have
+ // if there are less than two, disable the transfer button
+ QListViewItemIterator it ( listview );
+ int counter = 0;
+ for ( ; it.current(); ++it )
+ {
+ // add one to counter if we find a transferable account
+ if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 )
+ counter++;
+ }
+ if ( counter > 1 )
+ transferbutton->show();
+ else
+ transferbutton->hide();
+ }
+
+void AccountDisplay::accountTransfer ( bool state )
+ {
+ if ( state == TRUE )
+ {
+ 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;
+
+ // 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 );
+ else
+ 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;
+ }
+
+ }
+
+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 );
+ for ( int counter = 0; count - 1; counter++ )
+ {
+ if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 )
+ {
+ currencybox->currencybox->setCurrentItem ( counter );
+ break;
+ }
+ }
+ }
+ else
+ currencybox->setEnabled ( FALSE );
+
+ //execute the dialog box
+ int response = editaccountwindow->exec();
+ if ( response == 1 )
+ {
+ account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid );
+ account->displayAccounts ( listview );
+ }
+ }
+ }
+
+void AccountDisplay::setAccountExpanded ( QListViewItem *item )
+ {
+ int accountid = item->text ( getIDColumn() ).toInt();
+ account->setAccountExpanded ( 1, accountid );
+ }
+
+void AccountDisplay::setAccountCollapsed ( QListViewItem *item )
+ {
+ int accountid = item->text ( getIDColumn() ).toInt();
+ account->setAccountExpanded ( 0, accountid );
+ }
+
+
diff --git a/noncore/apps/qashmoney/budget.cpp b/noncore/apps/qashmoney/budget.cpp
new file mode 100755
index 0000000..42f7eca
--- a/dev/null
+++ b/noncore/apps/qashmoney/budget.cpp
@@ -0,0 +1,221 @@
+#include "budget.h"
+#include "transaction.h"
+#include <stdlib.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 );
+ 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 ] );
+ }
+
+void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ sqlite_exec_printf ( bdb, "update '%q' set name = '%q', lineitemamount = %f, type = %i where lineitemid = %i;", 0, 0, 0, ( const char* ) tablename, ( const char * ) lineitemname, lineitemamount, lineitemtype, lineitemid );
+ }
+
+void Budget::deleteLineItem ( int budgetid, int lineitemid )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid );
+ }
+
+void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ char **results;
+ int rows, columns, counter;
+ sqlite_get_table_printf ( bdb, "select name, lineitemamount, lineitemid from '%q';", &results, &rows, &columns, NULL, ( const char * ) tablename );
+ int total = ( ( rows + 1 ) * columns );
+ for ( counter = 3; counter < total; counter = counter + 3 )
+ {
+ float amount = 0;
+ if ( viewtype == 0 )
+ {
+ QString lineitemamount = results [ counter + 1 ];
+ amount = lineitemamount.toFloat() / 12;
+ }
+ else
+ {
+ QString lineitemamount = results [ counter + 1 ];
+ amount = lineitemamount.toFloat();
+ }
+ QListViewItem *item = new QListViewItem ( listview, results [ counter ], QString::number ( amount, 'f', 2 ), transaction->getBudgetTotal ( budgetid, atoi ( results [ counter + 2 ] ), year, month, viewtype ), results [ counter + 2 ] );
+ }
+ }
+
+QStringList Budget::getLineItems ( int budgetid )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ QStringList lineitems;
+ char **results;
+ int rows, counter;
+ sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename );
+ for ( counter = 0; counter < rows; counter++ )
+ lineitems.append ( results [ counter + 1 ] );
+ return lineitems;
+ }
+
+QStringList Budget::getLineItemIDs ( int budgetid )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ QStringList lineitemids;
+ char **results;
+ int rows, counter;
+ sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename );
+ for ( counter = 0; counter < rows; counter++ )
+ lineitemids.append ( results [ counter + 1 ] );
+ return lineitemids;
+ }
+
+int Budget::getLineItemTime ( int budgetid, int lineitemid )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ char **results;
+ sqlite_get_table_printf ( bdb, "select type from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char * ) tablename, lineitemid );
+ return atoi ( results [ 1 ] );
+ }
+
+float Budget::getLineItemAmount ( int budgetid, int lineitemid )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ char **results;
+ sqlite_get_table_printf ( bdb, "select lineitemamount from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char* ) tablename, lineitemid );
+ return strtod ( results [ 1 ], 0 );
+ }
+
+QString Budget::getBudgetTotal ( int budgetid, int viewtype )
+ {
+ QString tablename = "table";
+ tablename.append ( QString::number ( budgetid ) );
+ // determine if we are viewing a years, months, or days budget
+ // we have to pick a different sum for each
+ char **results;
+ sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename );
+ QString amount = results [ 1 ];
+ float total = amount.toFloat();
+ if ( viewtype == 0 )
+ total = total / 12;
+ amount.setNum ( total, 'f', 2 );
+ return amount;
+ }
+
+int Budget::getLastAdded ()
+ {
+ char **results;
+ sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL );
+ return atoi ( results [ 1 ] );
+ }
+
+
+
diff --git a/noncore/apps/qashmoney/budget.h b/noncore/apps/qashmoney/budget.h
new file mode 100755
index 0000000..16af26a
--- a/dev/null
+++ b/noncore/apps/qashmoney/budget.h
@@ -0,0 +1,45 @@
+#ifndef BUDGET_H
+#define BUDGET_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qlistview.h>
+#include <sqlite.h>
+
+class Budget
+ {
+ public:
+
+ Budget ();
+ ~Budget ();
+
+ int addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview );
+ void updateBudget ( QString name, QString description, QString currency, int budgetid );
+ void deleteBudget ( int budgetid );
+ int getNumberOfBudgets ();
+ int getNumberOfLineItems ( int budgetid );
+
+ QStringList* getBudgetNames ();
+ QStringList* getBudgetIDs ();
+ QStringList getLineItems ( int budgetid );
+ QStringList getLineItemIDs ( int budgetid );
+ QString getBudgetName ( int budgetid );
+ QString getBudgetDescription ( int budgetid );
+ QString getCurrency ( int budgetid );
+ QString getBudgetTotal ( int budgetid, int viewtype );
+
+ int getLastAdded ();
+
+ int addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype );
+ void updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid );
+ void displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype );
+ void deleteLineItem ( int budgetid, int lineitemid );
+ int getLineItemTime ( int budgetid, int lineitemid );
+ float getLineItemAmount ( int budgetid, int lineitemid );
+
+ private:
+ sqlite *bdb;
+ };
+
+#endif
+
diff --git a/noncore/apps/qashmoney/memory.cpp b/noncore/apps/qashmoney/memory.cpp
new file mode 100755
index 0000000..b5155b3
--- a/dev/null
+++ b/noncore/apps/qashmoney/memory.cpp
@@ -0,0 +1,62 @@
+#include "memory.h"
+
+#include <stdlib.h>
+
+Memory::Memory ()
+ {
+ db = sqlite_open ( "qmmemory.db", 0, NULL );
+ }
+
+Memory::~Memory ()
+ {
+ sqlite_close ( db );
+ }
+
+void Memory::addMemoryItem ( QString item )
+ {
+ sqlite_exec_printf ( db, "insert into memory values ( '%q', 0, 0 );", 0, 0, 0, ( const char * ) item );
+ }
+
+void Memory::deleteMemoryItem ( QString item )
+ {
+ sqlite_exec_printf ( db, "delete from memory where item = '%q';", 0, 0, 0, ( const char * ) item );
+ }
+
+int Memory::getNumberOfMemoryItems ()
+ {
+ char **results;
+ sqlite_get_table ( db, "select count() from memory;", &results, NULL, NULL, NULL );
+ return atoi ( results [ 1 ] );
+ }
+
+void Memory::changeMemoryName ( QString item )
+ {
+ sqlite_exec_printf ( db, "update memory set item = '%q' where item = '%q';", 0, 0, 0, ( const char * ) item );
+ }
+
+void Memory::displayMemoryItems ( QListBox *listbox )
+ {
+ char **results;
+ int rows;
+ sqlite_get_table ( db, "select item from memory order by item asc;", &results, &rows, NULL, NULL );
+ int counter = 1;
+ while ( counter < ( rows + 1 ) )
+ {
+ listbox->insertItem ( results [ counter ] );
+ counter ++;
+ }
+ }
+
+void Memory::displayMemoryItems ( QComboBox *box )
+ {
+ char **results;
+ int rows;
+ sqlite_get_table ( db, "select item from memory order by item asc;", &results, &rows, NULL, NULL );
+ int counter = 1;
+ while ( counter < ( rows + 1 ) )
+ {
+ box->insertItem ( results [ counter ] );
+ counter ++;
+ }
+ }
+
diff --git a/noncore/apps/qashmoney/memory.h b/noncore/apps/qashmoney/memory.h
new file mode 100755
index 0000000..6f3f100
--- a/dev/null
+++ b/noncore/apps/qashmoney/memory.h
@@ -0,0 +1,45 @@
+#ifndef MEMORY_H
+#define MEMORY_H
+
+#include <qstring.h>
+#include <qlistbox.h>
+#include <qcombobox.h>
+#include <sqlite.h>
+
+class Memory : public QObject
+ {
+
+ Q_OBJECT
+
+ public:
+
+ Memory ();
+ ~Memory ();
+
+ // This function adds a new memory to the database. It takes the memory name, parent,
+ // initial balance, a displayed variable, and the memory type
+ // The parent is an integer memory id. Its -1 if there is not parent
+ // The memory types are 0=not defined 1=parent 2=child
+ void addMemoryItem ( QString );
+
+ // Returns the number of checking memorys
+ int getNumberOfMemoryItems ();
+
+ void changeMemoryName ( QString );
+
+ // This takes a QListView and puts parents and children memorys
+ // into the list view
+ void displayMemoryItems ( QListBox * );
+ void displayMemoryItems ( QComboBox * );
+
+ // The primary database that stores all our data
+ sqlite *db;
+
+ public slots:
+
+ // Deletes a memory item. Takes the memoryid as its parameter
+ void deleteMemoryItem ( QString );
+ };
+
+#endif
+
diff --git a/noncore/apps/qashmoney/preferences.h b/noncore/apps/qashmoney/preferences.h
new file mode 100755
index 0000000..4a3e058
--- a/dev/null
+++ b/noncore/apps/qashmoney/preferences.h
@@ -0,0 +1,50 @@
+#include <sqlite.h>
+#include <qstring.h>
+
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+class Preferences
+ {
+ public:
+ Preferences ();
+ ~Preferences ();
+
+ void addPreferences ();
+ void initializeColumnPreferences ();
+
+ // Returns a preference value for the given preferences ID
+ int getPreference ( int );
+ int getColumnPreference ( int id );
+
+ // 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 );
+
+ // 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
new file mode 100755
index 0000000..1ea358c
--- a/dev/null
+++ b/noncore/apps/qashmoney/qashmoney.cpp
@@ -0,0 +1,356 @@
+#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->initializeColumnPreferences ();
+
+ // 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 );
+ tabslayout->addWidget ( budgetdisplay );
+
+ // connect a change in the maintabs with changing the tab display
+ connect ( maintabs, SIGNAL ( currentChanged ( QWidget * ) ), this, SLOT ( changeTabDisplay () ) );
+
+ // create layout that will contain the menubar and the maintabs
+ layout = new QVBoxLayout ( this, 2, 2 );
+ layout->setMenuBar ( mainmenu );
+ layout->addWidget ( maintabs );
+ }
+
+QashMoney::~QashMoney ()
+ {
+ delete budget;
+ delete preferences;
+ delete account;
+ delete transaction;
+ delete transfer;
+ delete memory;
+ }
+
+void QashMoney::changeTabDisplay ()
+ {
+ // if the user pressed the transactions tab, hide the account display
+ // object and create a new transaction display
+ if ( maintabs->currentPageIndex() == 1 )
+ {
+ // initialize variables
+ bool children = FALSE;
+
+ // hide the account display and define accountid
+ int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt();
+
+ //remove all the columns from the transactiondisplay
+ int columns = transactiondisplay->listview->columns();
+ int counter;
+ for ( counter = 0; counter <= columns; counter++ )
+ transactiondisplay->listview->removeColumn ( 0 );
+
+ // set the account name and account balance
+ QString name = account->getAccountName ( accountid );
+ 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 );
+
+ // display transactions
+ transactiondisplay->listview->clear();
+ QString displaytext = "%";
+ displaytext.prepend ( transactiondisplay->limitbox->text() );
+ if ( transaction->getNumberOfTransactions() > 0 )
+ transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext );
+
+ // display transfers
+ transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
+
+ // 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 );
+ }
+
+ // 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 ) );
+
+ // 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() );
+ if ( transaction->getNumberOfTransactions() > 0 )
+ transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext );
+
+ if ( transfer->getNumberOfTransfers() != 0 )
+ transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
+ }
+ 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() );
+ if ( transaction->getNumberOfTransactions() > 0 )
+ transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext );
+
+ if ( transfer->getNumberOfTransfers() != 0 )
+ transfer->displayTransfers ( transactiondisplay->listview, accountid, children );
+ }
+ 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();
+ }
+
+
+
diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp
new file mode 100755
index 0000000..af7d18f
--- a/dev/null
+++ b/noncore/apps/qashmoney/transaction.cpp
@@ -0,0 +1,274 @@
+// RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN
+// FUTURE VERSIONS OF QASHMONEY
+
+// RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION
+
+#include "transaction.h"
+#include "account.h"
+#include "transactiondisplay.h"
+
+#include <stdlib.h>
+
+extern Account *account;
+extern Preferences *preferences;
+
+Transaction::Transaction ()
+ {
+ tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
+ }
+
+Transaction::~Transaction ()
+ {
+ sqlite_close ( tdb );
+ }
+
+void Transaction::addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid )
+ {
+ sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0,
+ 0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description );
+ }
+
+void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid )
+ {
+ sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f,
+ cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year,
+ amount, cleared, budgetid, lineitemid, transactionid );
+ }
+
+void Transaction::deleteTransaction ( int transid )
+ {
+ sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid );
+ }
+
+void Transaction::deleteAllTransactions ( int accountid )
+ {
+ sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid );
+ }
+
+int Transaction::getAccountID ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ return atol ( results [ 1 ] );
+ }
+
+int Transaction::getNumberOfTransactions ()
+ {
+ char **results;
+ sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL );
+ return atoi ( results [ 1 ] );
+ }
+
+int Transaction::getNumberOfTransactions ( int accountid )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid );
+ return atol ( results [ 1 ] );
+ }
+
+QString Transaction::getPayee ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ return results [ 1 ];
+ }
+
+QString Transaction::getTransactionDescription ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ return results [ 1 ];
+ }
+
+QString Transaction::getNumber ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ return results [ 1 ];
+ }
+
+QString Transaction::getAmount ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ return results [ 1 ];
+ }
+
+QString Transaction::getAbsoluteAmount ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ return results [ 1 ];
+ }
+
+int Transaction::getCleared ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id );
+ QString cleared = results [ 1 ];
+ 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 )
+ {
+ int showcleared = preferences->getPreference ( 3 );
+
+ // 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 )
+ {
+ 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 );
+ }
+ else
+ {
+ if ( account->getParentAccountID ( id ) == -1 && children == TRUE )
+ sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit );
+ 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 );
+ }
+
+ // iterate through the result list and display each item
+ int counter = 7;
+ while ( counter < ( ( rows + 1 ) * columns ) )
+ {
+ // construct the date
+ //QString daystring = results [ counter ];
+ //int day = results [ counter ].toInt ();
+ //QString monthstring = results [ counter + 1 ];
+ //int month = results [ counter + 1 ].toInt ();
+ //QString yearstring = results [ counter + 2 ];
+ //int year = results [ counter + 2 ].toInt ();
+ 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
+ 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);
+ else
+ QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid );
+ }
+ 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;
+ }
+
+void Transaction::clearBudgetIDs ( int budgetid, int lineitemid )
+ {
+ sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid );
+ }
+
+void Transaction::clearBudgetIDs ( int budgetid )
+ {
+ sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid );
+ }
+
diff --git a/noncore/apps/qashmoney/transaction.h b/noncore/apps/qashmoney/transaction.h
new file mode 100755
index 0000000..5db011c
--- a/dev/null
+++ b/noncore/apps/qashmoney/transaction.h
@@ -0,0 +1,69 @@
+#ifndef TRANSACTION_H
+#define TRANSACTION_H
+
+#include <qstring.h>
+#include <qlistview.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 * );
+ 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;
+ };
+
+#endif
+
+
+
diff --git a/noncore/apps/qashmoney/transactiondisplay.h b/noncore/apps/qashmoney/transactiondisplay.h
new file mode 100755
index 0000000..79f20ba
--- a/dev/null
+++ b/noncore/apps/qashmoney/transactiondisplay.h
@@ -0,0 +1,79 @@
+#ifndef TRANSACTIONDISPLAY_H
+#define TRANSACTIONDISPLAY_H
+
+#include <qlayout.h>
+#include <qhbox.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qlineedit.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 ();
+
+ private:
+ int accountid, fromaccount, fromparent, toaccount, toparent, day, month, year, transferid;
+ 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
new file mode 100755
index 0000000..77cbb4e
--- a/dev/null
+++ b/noncore/apps/qashmoney/transfer.cpp
@@ -0,0 +1,253 @@
+#include "transfer.h"
+#include "account.h"
+#include "transactiondisplay.h"
+#include <stdlib.h>
+#include <iostream.h>
+
+extern Account *account;
+extern Preferences *preferences;
+
+Transfer::Transfer ()
+ {
+ db = sqlite_open ( "qmtransfers.db", 0, 0 );
+ }
+
+Transfer::~Transfer ()
+ {
+ sqlite_close ( db );
+ }
+
+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 )
+ {
+ 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 );
+
+ //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 ( 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
+ {
+ 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 );
+
+ //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 );
+ 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 )
+ {
+ char **results;
+ sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id );
+ return atoi ( results [ 1 ] );
+ }
+
+QString Transfer::getAmount ( int id )
+ {
+ char **results;
+ sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id );
+ return results [ 1 ];
+ }
+
+
diff --git a/noncore/apps/qashmoney/transfer.h b/noncore/apps/qashmoney/transfer.h
new file mode 100755
index 0000000..33dedf4
--- a/dev/null
+++ b/noncore/apps/qashmoney/transfer.h
@@ -0,0 +1,51 @@
+#ifndef TRANSFER_H
+#define TRANSFER_H
+
+#include <qlistview.h>
+#include <qstring.h>
+#include <sqlite.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 );
+ 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
+
+
+