summaryrefslogtreecommitdiff
path: root/noncore/apps/qashmoney/account.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/qashmoney/account.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/account.cpp2
1 files changed, 0 insertions, 2 deletions
diff --git a/noncore/apps/qashmoney/account.cpp b/noncore/apps/qashmoney/account.cpp
index 181be23..f21598e 100755
--- a/noncore/apps/qashmoney/account.cpp
+++ b/noncore/apps/qashmoney/account.cpp
@@ -1,195 +1,193 @@
#include "account.h"
-#include "transaction.h"
-#include "transfer.h"
#include "preferences.h"
#include <qpixmap.h>
#include <stdlib.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 ] );