-rwxr-xr-x | noncore/apps/qashmoney/account.cpp | 1 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/budget.cpp | 1 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/qashmoney.cpp | 1 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/qashmoney.pro | 2 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transaction.cpp | 1 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transactiondisplay.cpp | 1 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transfer.cpp | 1 |
7 files changed, 1 insertions, 7 deletions
diff --git a/noncore/apps/qashmoney/account.cpp b/noncore/apps/qashmoney/account.cpp index 28f9ba2..181be23 100755 --- a/noncore/apps/qashmoney/account.cpp +++ b/noncore/apps/qashmoney/account.cpp @@ -1,377 +1,376 @@ #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 ) { 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 ); } 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 ); float transactionsbalance = strtod ( results [ 1 ], 0 ); sqlite_close ( tdb ); // next, we'll get a balance for all the transfers from the account sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); rows = 0; columns = 0; char **results2; sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); // finally, we'll get a balance for all the transfers into the account rows = 0; columns= 0; char **results3; sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); float totransfersbalance = strtod ( results3 [ 1 ], 0 ); sqlite_close ( trdb ); // calculate and update new balance sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); } void Account::changeParentAccountBalance ( int parentid ) { // select all child balances that share the parent of the current child account char **results; int rows; sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); } int Account::getParentAccountID ( int id ) { char **results; sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); return atoi ( results [ 1 ] ); } int Account::getParentAccountID ( QString accountname ) { char **results; sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); return atoi ( results [ 1 ] ); } void Account::displayAccounts ( QListView *listview ) { char **results; int rows, columns; sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); // determine if we are using currency support int currency = preferences->getPreference ( 4 ); // remove all columns from the account display int counter; for ( counter = 0; counter <= columns; counter++ ) listview->removeColumn ( 0 ); // add columns to the account display listview->addColumn ( "Account", 0 ); int columntoalign = 1; if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it { listview->addColumn ( "C", 0 ); columntoalign = 2; } listview->addColumn ( "Balance", 0 ); listview->addColumn ( "", 0 ); listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); counter = 5; int total = ( rows + 1 ) * columns; while ( counter < total ) { int accountid = atoi ( results [ counter + 3 ] ); if ( atoi ( results [ counter + 1 ] ) == -1 ) { QListViewItem *parent = new QListViewItem ( listview ); parent->setText ( 0, results [ counter ] ); if ( currency == 0 ) { parent->setText ( 1, results [ counter + 2 ] ); parent->setText ( 2, results [ counter + 3 ] ); } else { if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children { // create the string we'll use to set the currency pixmap QString filename = "/opt/QtPalmtop/pics/flags/"; QString flag = results [ counter + 4 ]; filename.append ( flag ); filename.append ( ".png" ); parent->setPixmap ( 1, QPixmap ( filename ) ); parent->setText ( 1, flag ); } parent->setText ( 2, results [ counter + 2 ] ); parent->setText ( 3, results [ counter + 3 ] ); } if ( getAccountExpanded ( accountid ) == 1 ) 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 ) { char **results; sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return atoi ( results [ 1 ] ); } QString Account::getAccountDescription ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } QString Account::getCurrencyCode ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } QString Account::getAccountName ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } QString Account::getAccountBalance ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } float Account::getAccountCreditLimit ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); return strtod ( results [ 1 ], NULL ); } float Account::getStatementBalance ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); return strtod ( results [ 1 ], NULL ); } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) : QListViewItem ( parent ) { } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) : QListViewItem ( parent, label1, label2, label3 ) { } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) : QListViewItem ( parent, label1, label2, label3, label4 ) { } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) : QListViewItem ( parent, label1, label2, label3, label4, label5 ) { } void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { QColorGroup _cg ( cg ); _cg.setColor ( QColorGroup::Base, Qt::lightGray ); QListViewItem::paintCell ( p, _cg, column, width, alignment ); } QStringList Account::getAccountNames () { QStringList accountnames; char **results; int rows, counter; sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); for ( counter = 0; counter < rows; counter++ ) accountnames.append ( results [ counter+1 ] ); return accountnames; } QStringList Account::getAccountIDs () { QStringList accountids; char **results; int rows, counter; sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); for ( counter = 0; counter < rows; counter++ ) accountids.append ( results [ counter+1 ] ); return accountids; } diff --git a/noncore/apps/qashmoney/budget.cpp b/noncore/apps/qashmoney/budget.cpp index 9f74078..2cec329 100755 --- a/noncore/apps/qashmoney/budget.cpp +++ b/noncore/apps/qashmoney/budget.cpp @@ -1,222 +1,221 @@ #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;", &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/qashmoney.cpp b/noncore/apps/qashmoney/qashmoney.cpp index e985f0b..d4cbc14 100755 --- a/noncore/apps/qashmoney/qashmoney.cpp +++ b/noncore/apps/qashmoney/qashmoney.cpp @@ -1,403 +1,402 @@ #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 (); 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 QMenuBar ( 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 ); 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, 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, 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, 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 ( 1900, 1, 1 ); } diff --git a/noncore/apps/qashmoney/qashmoney.pro b/noncore/apps/qashmoney/qashmoney.pro index 8b4646a..ec29faa 100755 --- a/noncore/apps/qashmoney/qashmoney.pro +++ b/noncore/apps/qashmoney/qashmoney.pro @@ -1,49 +1,49 @@ TEMPLATE = app CONFIG = qt warn_on release HEADERS = qashmoney.h \ accountdisplay.h \ account.h \ transaction.h \ transactiondisplay.h \ newtransaction.h \ transfer.h \ transferdialog.h \ preferences.h \ preferencedialogs.h \ memory.h \ memorydialog.h \ newaccount.h \ calculator.h \ datepicker.h \ budget.h \ budgetdisplay.h \ currency.h SOURCES = qashmoney.cpp \ accountdisplay.cpp \ account.cpp \ transaction.cpp \ transactiondisplay.cpp \ newtransaction.cpp \ transfer.cpp \ transferdialog.cpp \ preferences.cpp \ preferencedialogs.cpp \ memory.cpp \ memorydialog.cpp \ newaccount.cpp \ calculator.cpp \ datepicker.cpp \ main.cpp \ budget.cpp \ budgetdisplay.cpp \ currency.cpp INCLUDEPATH = $(OPIEDIR)/include DEPENDPATH = $(OPIEDIR)/include DESTDIR = $(OPIEDIR)/bin unix:LIBS += -lm -LIBS += -lqpe -lqte -lstdc++ -lsqlite +LIBS += -lqpe -lqte -lsqlite include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/apps/qashmoney/transaction.cpp b/noncore/apps/qashmoney/transaction.cpp index dcf46b1..d008a4f 100755 --- a/noncore/apps/qashmoney/transaction.cpp +++ b/noncore/apps/qashmoney/transaction.cpp @@ -1,346 +1,345 @@ // 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> -#include <iostream.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(); } char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id ) { // initialize variables char **results; int showcleared = preferences->getPreference ( 3 ); QDate today = QDate::currentDate(); int fromyear = fromdate.year(); int toyear = today.year(); int frommonth = fromdate.month(); int tomonth = today.month(); int fromday = fromdate.day(); // 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 { 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 if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year { 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 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 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/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp index 1839cd2..78b8a00 100755 --- a/noncore/apps/qashmoney/transactiondisplay.cpp +++ b/noncore/apps/qashmoney/transactiondisplay.cpp @@ -1,629 +1,628 @@ #include "transactiondisplay.h" #include "newtransaction.h" #include "account.h" #include "budget.h" #include "memory.h" #include "transfer.h" #include "preferences.h" #include "calculator.h" #include "datepicker.h" #include <qdatetime.h> #include <qmessagebox.h> #include <qheader.h> #include <qmultilineedit.h> -#include <iostream.h> #include <qdatetime.h> extern Transaction *transaction; extern Budget *budget; extern Account *account; 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, 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 ); month = transfer->getMonth ( transferid ); day = transfer->getDay ( transferid ); QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); editransfer->setCaption ( "Transfer" ); QStringList accountnames = account->getAccountNames(); QStringList accountids = account->getAccountIDs(); QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); QFont f = this->font(); f.setWeight ( QFont::Bold ); fromaccountlabel->setFont ( f ); QComboBox *fromaccountbox = new QComboBox ( editransfer ); fromaccountbox->insertStringList ( accountnames ); fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); toaccountlabel->setFont ( f ); QComboBox *toaccountbox = new QComboBox ( editransfer ); toaccountbox->insertStringList ( accountnames ); toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); QLabel *datelabel = new QLabel ( "Date", editransfer ); QHBox *datebox = new QHBox ( editransfer ); datebox->setSpacing ( 2 ); date = new QLineEdit ( datebox ); date->setAlignment ( Qt::AlignRight ); date->setDisabled ( TRUE ); date->setText ( preferences->getDate ( year, month, day ) ); QPushButton *datebutton = new QPushButton ( datebox ); datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); QHBox *amountbox = new QHBox ( editransfer ); amountbox->setSpacing ( 2 ); amount = new QLineEdit ( amountbox ); amount->setAlignment ( Qt::AlignRight ); amount->setText ( transfer->getAmount ( transferid ) ); QPushButton *calculatorbutton = new QPushButton( amountbox ); calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); layout->addWidget ( fromaccountbox, Qt::AlignLeft ); layout->addWidget ( toaccountlabel, Qt::AlignLeft ); layout->addWidget ( toaccountbox, 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 ); if ( editransfer->exec() == QDialog::Accepted ) { //get fromaccount fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); //get to account toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); //set cleared flag int cleared = 0; if ( clearedcheckbox->isChecked() == TRUE ) cleared = 1; //update transfer transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), day, month, year, amount->text().toFloat(), cleared, transferid ); account->updateAccountBalance ( fromaccount ); if ( account->getParentAccountID ( fromaccount ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); updateAndDisplay ( toaccount ); } } void TransactionDisplay::editTransaction () { int cleared; // set the transaction id and budgetid int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); int budgetid = transaction->getBudgetID ( transactionid ); int lineitemid = transaction->getLineItemID ( transactionid ); // create edit transaction window NewTransaction *newtransaction = new NewTransaction ( this ); int width = this->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 the date in the date box newtransaction->year = transaction->getYear ( transactionid ); newtransaction->month = transaction->getMonth ( transactionid ); newtransaction->day = transaction->getDay ( transactionid ); newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); // set the description newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); // add memory items to the transactionname combobox memory->displayMemoryItems ( newtransaction->transactionname ); // add correct transaction name newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); // add transaction number newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); // add transaction amount newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); // check for and set the correct budget if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item { newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); if ( lineitemid >= 1 ) { newtransaction->setLineItems (); newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); } else { newtransaction->lineitemlabel->setEnabled ( FALSE ); newtransaction->lineitembox->setEnabled ( FALSE ); } } else { 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, 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, 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, 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, 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, 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 ( 1900, 1, 1 ); } diff --git a/noncore/apps/qashmoney/transfer.cpp b/noncore/apps/qashmoney/transfer.cpp index c4bbaf9..ae1b748 100755 --- a/noncore/apps/qashmoney/transfer.cpp +++ b/noncore/apps/qashmoney/transfer.cpp @@ -1,260 +1,259 @@ #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, 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 ] ) ); 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, 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 ); 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 ] ) ); 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 { 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 ]; } |