From b92483d866f263235bc9b52aa271241e1e55112e Mon Sep 17 00:00:00 2001 From: allenforsythe Date: Wed, 14 May 2003 10:55:23 +0000 Subject: Initial revision --- (limited to 'noncore/apps/qashmoney') diff --git a/noncore/apps/qashmoney/TODO b/noncore/apps/qashmoney/TODO new file mode 100755 index 0000000..c85b0d2 --- a/dev/null +++ b/noncore/apps/qashmoney/TODO @@ -0,0 +1,15 @@ +QashMoney Budget Software for the Sharp Zaurus + +TODO + +Planned features for QashtMoney include: + +- Go to another account from within the transactionwindow +- Move a transaction from one account to another +- Purge transactions (remove them without effecting the account balances). +- Add difference account types such as stocks, etc. Basically I want it to + becoming a full featured money app, hence the name!! +- Open Financial Exchange protocol support +- Allow limiting the number of transactions that are displayed when showing cleared transactions. + This will become important when a database becomes very large as the program will + slow greatly if it retrieves serveral hundred transactions to view. diff --git a/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control b/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control new file mode 100755 index 0000000..ffd11db --- a/dev/null +++ b/noncore/apps/qashmoney/install/CONTROL/opie-qashmoney.control @@ -0,0 +1,7 @@ +Package: qashmoney +Priority: optional +Version: 0.74 +Architecture: arm +Maintainer: Allen Forsythe qashmoneyman@attbi.com +Section: Applications +Description: QashMoney provides an intuitive and fast way to keep track of your accounts and budgets. diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/accountpreferenceswindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/accountpreferenceswindow.png new file mode 100755 index 0000000..e37580f --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/accountpreferenceswindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/budgetwindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/budgetwindow.png new file mode 100755 index 0000000..e42d52a --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/budgetwindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/datepreferenceswindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/datepreferenceswindow.png new file mode 100755 index 0000000..7ae6821 --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/datepreferenceswindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/mainwindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/mainwindow.png new file mode 100755 index 0000000..c8a88c2 --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/mainwindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/newaccountwindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/newaccountwindow.png new file mode 100755 index 0000000..d0e4664 --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/newaccountwindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/newtransactionwindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/newtransactionwindow.png new file mode 100755 index 0000000..c011235 --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/newtransactionwindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/qashmoney.html b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/qashmoney.html new file mode 100755 index 0000000..40bfe27 --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/qashmoney.html @@ -0,0 +1,153 @@ + + + + +QashMoney Help + + + + + +
QashMoney
+ +
Welcome to QashMoney help. This file should help you get started +using QashMoney quickly!
+ +
Main Window
+ +
When you start the application, the Main Window will appear. This window +consists of account buttons and the account display which shows you the account +names and balances for each account. Parent accounts are to the left +and child accounts are indented. By default, child accounts contribute +to the balance of their respective parents. Parent accounts are used only for viewing +transactions for the child accounts beneath them as well as deleting and clearing/reseting +transactions in those child accounts. As such, parent accounts with child accounts will +not accept transactions. + +

NOTE: The columns in the account and transaction display windows default to a reasonable but +static width. You can press in between the columns and drag to resize them to your liking and QashMoney will remember +these widths. + +


+ +
Press this button to add a new account to the list. + +
Press this button to edit the name, description, +and currency that has been assigned to the account.  The other parameters of the account are not editable. + +
Press this button to delete an account that you've added. When you +delete a child account, all of its transactions will also be deleted so be careful with this. You can only delete a parent +account if it has no child accounts. + +
Press this button to transfer money between accounts. This is a toggle button +and will stay down when you press it. Next, select two accounts from the account list. These will become the accounts +between which funds are transferred. The money is transferred from the account you tap first and transferred to the account you tap second. +A popup dialog will appear after you tap two accounts and looks like this: + +

+ +
To complete the transfer, enter the date and amount. Check the cleared check box to set this transfer cleared. + +

Add Account
+ +
+ +
Use the Add Account dialog to add accounts. The initial +balance may be typed in manually or you can push the calculator to enter +the amount with the stylus. Next, select the currency pulldown menu to choose +the currency for this account. If currency support is disabled, this box will be disabled. + You'll notice that the date line is disabled. Dates may only +be entered by pressing the calendar button and selecting the date. Today's date is put into the +calendar entry line by default. If you select this to a child account, +a pulldown menu will appear so you can select its parent account. Using the Type +pulldown menu, you may select any type of equity or liability account. If you choose a +liability account, you may also type in a credit limit for the account. Press the button next to +the account name box to enter a description of the account. To cancel the account addition, +click the X button. Otherwise, press OK to complete the account addition. + +

Transaction Window
+ +
+ +
To see the transactions for each account, highlight the +account and press the Transactions tab, this will display the transaction +window, the account name you've selected, the account balance and several +transaction buttons. If you've selected a child account or a parent account with no +children, the transaction window will contain three columns for date, transaction name, +and amount. A fourth column identifying the account for each transaction will be added +if you choose to view a parent account with children. Entering text in the "Limit" box will +display items that begin with the text in the box. Text in this box does not effect transfers. + +

New Transaction + +
Edit Transaction. Use this button to edit transactions. +Just select the transaction you want to edit and the appropriate window will appear. You cannot edit transfers +from this window (yet). You must delete transfers and then reenter them in the account display. + +
Delete Transaction. This also deletes a transfer if one is selected. + +
Clear or Reset Transaction. Use this button to clear transactions. + If an uncleared transaction is selected, it will be cleared. If a cleared transaction is selected, it will be reset. This functions +identically for transfers. If you prefer not to see cleared transactions, the transaction you clear will disappear from the +transaction window. If however, you are showing cleared transactions, cleared transactions will appear red rather than black differentiating +them from the non-cleared transactions. + +
Transaction Information. If you've entered notes about a transaction, select the transaction and +press this button to see the notes. + +

Add Transaction
+ +
+ +
Use this dialog to enter new transactions. Enter the transaction name, transaction number, amount, and date. +Each transaction defaults to a non-cleared debit transaction. If you want to clear the transaction right away, check +the Cleared checkbox. If you want to make this a deposit (credit) to the account, check the Credit checkbox. Press the +button next to Transaction Name to enter a description of this transaction. The budget and line item buttons at the bottom allow you to +add this transaction to budgets you have set up. The budget button defaults to None. If you don't want the add this transaction to +any budget, leave this as is. Otherwise, select the budget and then a line item from that budget to add the transaction. These buttons will +be disabled unless you've set up budgets. + +

Budgets
+ +
+ +
QashMoney's newest addition, this tab allows you to set up multiple budgets with different currencies then add any transaction from any account to any budget. +At the top of the budget display, a menu system allows you to add, edit, and delete budgets and line items within each budget. Using the Change item +under Date menu, you can change the date range for which you want to view budgets. Currently, you can view budgets by year and by month. The +budgeted and actual amounts will change appropriately for the view you select. Like the column sizes in the accounts and transaction windows. Drag these to +the size you want and QashMoney will remember them. + +

Preferences Menu
+ +
The preferences menus (currently) allow you to change the date format, determine whether cleared transactions are shown in the +transaction window, and to enable currenct support. Just tap the respective menu items to see the dialog for each preference. These dialogs are self explanatory +and look like this: + +

+ +

+ +

+ +
Defaults are provided for each preference. + +
Utilities Menu
+ +
Using the utlities menu and the memory window, you can add, delete, or edit memory items. These will be presented +in an easy to use pulldown menu when entering transactions. + +

+ +
New Memory Item. Press this button to add a new memory to the list. +This button is also used to add an edited item ( see below ). + +

Edit Memory Item. Select an item in the memory +item window then press this button to edit it. The item will be added to the line editor below the +button and deleted from the list. You must press the new button to add it back to +the list whether you edit it or not. Otherwise it will be lost. + +
Delete Memory Item. Press this button to delete a memory +item after selecting it in the memory item window. + + + diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transactionpreferenceswindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transactionpreferenceswindow.png new file mode 100755 index 0000000..7b183b3 --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transactionpreferenceswindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transactionwindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transactionwindow.png new file mode 100755 index 0000000..3f25a0a --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transactionwindow.png Binary files differ diff --git a/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transferwindow.png b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transferwindow.png new file mode 100755 index 0000000..13bbe0a --- a/dev/null +++ b/noncore/apps/qashmoney/install/opt/QtPalmtop/help/html/transferwindow.png Binary files differ diff --git a/noncore/apps/qashmoney/make_arm b/noncore/apps/qashmoney/make_arm new file mode 100755 index 0000000..4d0dc1c --- a/dev/null +++ b/noncore/apps/qashmoney/make_arm @@ -0,0 +1,23 @@ +# Use this script to automatically make the arm version +# of QashMoney. The arm.sh file must be in this folder +# for it to work + +# clean the directory then remove the Makefile +echo "Cleaning the directory and removing the current Makefile..." +if [ -e Makefile ] +then + make clean + rm Makefile +fi + +# set the environment variables for the arm environment +echo "Setting environment variables..." +source arm.sh + +# Make the new Makefile +echo "Making the new Makefile..." +tmake -o Makefile qashmoney.pro + +# Make the program +echo "Making the program..." +make diff --git a/noncore/apps/qashmoney/make_x86 b/noncore/apps/qashmoney/make_x86 new file mode 100755 index 0000000..fe1874d --- a/dev/null +++ b/noncore/apps/qashmoney/make_x86 @@ -0,0 +1,22 @@ +# Use this script to automatically make the x86 version +# of QashMoney. The x86.sh file must be in this folder +# for it to work. + +# Clean the directory +if [ -e Makefile ] +then + make clean + rm Makefile +fi + +# set the environment variables for the x86 environment +echo "Setting environment variables..." +source x86.sh + +# Make the new Makefile +echo "Making the new Makefile..." +tmake -o Makefile qashmoney.pro + +# Make the program +echo "Making the program..." +make diff --git a/noncore/apps/qashmoney/preferencedialogs.cpp b/noncore/apps/qashmoney/preferencedialogs.cpp new file mode 100755 index 0000000..3c2fb97 --- a/dev/null +++ b/noncore/apps/qashmoney/preferencedialogs.cpp @@ -0,0 +1,195 @@ +#include "preferencedialogs.h" +#include "preferences.h" +#include + +extern Preferences *preferences; + +DatePreferences::DatePreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) + { + setCaption( tr( "Date" ) ); + + QLabel *datelabel = new QLabel ( "Format", this ); + dateformat = new QComboBox ( this ); + dateformat->setEditable ( FALSE ); + dateformat->insertItem ( "yyyymmdd" ); + dateformat->insertItem ( "yymmdd" ); + dateformat->insertItem ( "mmddyyyy" ); + dateformat->insertItem ( "mmddyy" ); + dateformat->insertItem ( "yyyyddmm" ); + dateformat->insertItem ( "yyddmm" ); + dateformat->insertItem ( "ddmmyyyy" ); + dateformat->insertItem ( "ddmmyy" ); + connect ( dateformat, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateFormat ( int ) ) ); + + QLabel *dateseparatorlabel = new QLabel ( "Separator", this ); + dateseparator = new QComboBox ( this ); + dateseparator->insertItem ( "/" ); + dateseparator->insertItem ( "-" ); + dateseparator->insertItem ( "." ); + connect ( dateseparator, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateSeparator ( int ) ) ); + + defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); + connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultDatePreferences () ) ); + + dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); + dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( datelabel ); + layout->addWidget ( dateformat ); + layout->addWidget ( dateseparatorlabel ); + layout->addWidget ( dateseparator ); + layout->insertSpacing ( 4, 5 ); + layout->addWidget ( defaults ); + + } + +DatePreferences::~DatePreferences () + { + } + +void DatePreferences::changeDateFormat ( int index ) + { + index ++; + preferences->changePreference ( 1, index ); + } + +void DatePreferences::changeDateSeparator ( int index ) + { + index ++; + preferences->changePreference ( 2, index ); + } + +void DatePreferences::setDefaultDatePreferences () + { + preferences->setDefaultDatePreferences (); + dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); + dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); + } + +// START TRANSACTION PREFERENCES + +TransactionPreferences::TransactionPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) +{ + setCaption( tr ( "Transaction" ) ); + + showclearedtransactions = new QCheckBox ( this ); + showclearedtransactions->setText ( "Show Cleared Transactions" ); + + excludetransfers = new QCheckBox ( this ); + excludetransfers->setText ( "Include Transfers In Limit View" ); + + if ( preferences->getPreference ( 3 ) == 1 ) + showclearedtransactions->setChecked ( TRUE ); + else + showclearedtransactions->setChecked ( FALSE ); + + if ( preferences->getPreference ( 6 ) == 1 ) + excludetransfers->setChecked ( TRUE ); + else + excludetransfers->setChecked ( FALSE ); + + defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); + connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultTransactionPreferences () ) ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( showclearedtransactions ); + layout->addWidget ( excludetransfers ); + layout->insertSpacing ( 2, 5 ); + layout->addWidget ( defaults ); + + connect ( showclearedtransactions, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeShowClearedPreference ( bool ) ) ); + connect ( excludetransfers, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeExcludeTranfersPreference ( bool ) ) ); +} + +TransactionPreferences::~TransactionPreferences () + { + } + +void TransactionPreferences::changeShowClearedPreference ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 3, 1 ); + else + preferences->changePreference ( 3, 0 ); + } + +void TransactionPreferences::changeExcludeTranfersPreference ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 6, 1 ); + else + preferences->changePreference ( 6, 0 ); + } + +void TransactionPreferences::setDefaultTransactionPreferences () + { + preferences->changePreference ( 3, 0 ); + preferences->changePreference ( 6, 0 ); + showclearedtransactions->setChecked ( FALSE ); + } + +// START ACCOUNT PREFERNCES + +AccountPreferences::AccountPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) +{ + + setCaption( tr ( "Account" ) ); + + currencysupport = new QCheckBox ( this ); + currencysupport->setText ( "Enable Currency Support" ); + + onetouch = new QCheckBox ( this ); + onetouch->setText ( "One Touch Account Viewing" ); + + if ( preferences->getPreference ( 4 ) == 1 ) + currencysupport->setChecked ( TRUE ); + else + currencysupport->setChecked ( FALSE ); + + if ( preferences->getPreference ( 5 ) == 1 ) + onetouch->setChecked ( TRUE ); + else + onetouch->setChecked ( FALSE ); + + defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); + connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultAccountPreferences () ) ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( currencysupport ); + layout->addWidget ( onetouch ); + layout->insertSpacing ( 2, 5 ); + layout->addWidget ( defaults ); + + connect ( currencysupport, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeCurrencySupport ( bool ) ) ); + connect ( onetouch, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeOneTouchViewing ( bool ) ) ); +} + +AccountPreferences::~AccountPreferences () + { + } + +void AccountPreferences::changeCurrencySupport ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 4, 1 ); + else + preferences->changePreference ( 4, 0 ); + } + +void AccountPreferences::changeOneTouchViewing ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 5, 1 ); + else + preferences->changePreference ( 5, 0 ); + } + +void AccountPreferences::setDefaultAccountPreferences () + { + preferences->changePreference ( 4, 0 ); + preferences->changePreference ( 5, 0 ); + currencysupport->setChecked ( FALSE ); + onetouch->setChecked ( FALSE ); + } + diff --git a/noncore/apps/qashmoney/preferencedialogs.h b/noncore/apps/qashmoney/preferencedialogs.h new file mode 100755 index 0000000..e96c4bd --- a/dev/null +++ b/noncore/apps/qashmoney/preferencedialogs.h @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef DATEPREFERENCES_H +#define DATEPREFERENCES_H + +class DatePreferences : public QDialog + { + Q_OBJECT + + public: + DatePreferences ( QWidget * parent ); + ~DatePreferences(); + + QPushButton *defaults; + QComboBox *dateformat; + QComboBox *dateseparator; + QBoxLayout *layout; + + public slots: + void changeDateFormat ( int ); + void changeDateSeparator ( int ); + void setDefaultDatePreferences (); +}; + +#endif + +#ifndef TRANSACTIONPREFERENCES_H +#define TRANSACTIONPREFERENCES_H + +class TransactionPreferences : public QDialog + { + Q_OBJECT + + public: + TransactionPreferences ( QWidget * parent ); + ~TransactionPreferences(); + + QCheckBox *showclearedtransactions; + QCheckBox *excludetransfers; + QPushButton *defaults; + QBoxLayout *layout; + + public slots: + void changeShowClearedPreference ( bool ); + void changeExcludeTranfersPreference ( bool ); + void setDefaultTransactionPreferences (); +}; + +#endif + +#ifndef ACCOUNTPREFERENCES_H +#define ACCOUNTPREFERENCES_H + +class AccountPreferences : public QDialog + { + Q_OBJECT + + public: + AccountPreferences ( QWidget * parent ); + ~AccountPreferences(); + + QCheckBox *currencysupport; + QCheckBox *onetouch; + QPushButton *defaults; + QBoxLayout *layout; + + public slots: + void changeCurrencySupport ( bool ); + void changeOneTouchViewing ( bool ); + void setDefaultAccountPreferences (); +}; + +#endif + + + + diff --git a/noncore/apps/qashmoney/preferences.cpp b/noncore/apps/qashmoney/preferences.cpp new file mode 100755 index 0000000..8783a47 --- a/dev/null +++ b/noncore/apps/qashmoney/preferences.cpp @@ -0,0 +1,296 @@ +#include "preferences.h" +#include + +Preferences::Preferences () + { + db = sqlite_open ( "qmpreferences.db", 0, NULL ); + } + +Preferences::~Preferences () + { + sqlite_close ( db ); + } + +void Preferences::addPreferences () + { + // This function checks the preferences database for existing preferences and adds + // them if they are not there. First we set up variables. Preferences are always set + // to non-zero numbers because when we check to see if a preference has been + // added to the database, the result is zero if it hasn't + int rows = 0; + int columns = 0; + char **results; + + sqlite_get_table ( db, "select count() from preferences;", &results, 0, 0, 0 ); + if ( atoi ( results [ 1 ] ) != 6 ) + { + // dateformat preference 1 = yyyymmdd 2 = yymmdd 3 = mmddyyyy 4 = mmddyy + // 5 = yyyyddmm 6 = yyddmm 7 = ddmmyyyy 8 = ddmmyy + sqlite_get_table ( db, "select preference from preferences where id = 1;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 4, 'dateformat', 0, 0, 0, NULL );", 0, 0, 0 ); + + // dateseparator preference 1 = / ( forward slash ) 2 = - ( dash ) 3 = . ( period ) + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 2;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 1, 'dateseparator', 0, 0, 0, NULL );", 0, 0, 0 ); + + // showclearedtransactions preference 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 3;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'showclearedtransactions', 0, 0, 0, NULL );", 0, 0, 0 ); + + // enable currency support preference 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 4;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'enablecurrencysupport', 0, 0, 0, NULL );", 0, 0, 0 ); + + // one touch account viewing preference 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 5;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'onetouchviewing', 0, 0, 0, NULL );", 0, 0, 0 ); + + // exclude transfers from limit view 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 6;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'excludetransfersfromlimit', 0, 0, 0, NULL );", 0, 0, 0 ); + } + } + +void Preferences::initializeColumnPreferences () + { + int rows = 0; + int columns = 0; + char **results; + + // initialize accountname column width + sqlite_get_table ( db, "select width from columns where id = 1;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountname', 90, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize accountbalance column width + sqlite_get_table ( db, "select width from columns where id = 2;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountbalance', 90, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactiondate column width + sqlite_get_table ( db, "select width from columns where id = 3;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'normaltransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionname column width + sqlite_get_table ( db, "select width from columns where id = 4;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'normaltransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionamount column width + sqlite_get_table ( db, "select width from columns where id = 5;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'normaltransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactiondate column width + sqlite_get_table ( db, "select width from columns where id = 6;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionname column width + sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionamount column width + sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionaccount column width + sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize account name with currency column width + sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize account currency column width + sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize account balance with currency column width + sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize budget line item column + sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize budget budget column + sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize budget actual column + sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + } + +void Preferences::changeColumnPreference ( int id, int width ) + { + sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id ); + } + +int Preferences::getColumnPreference ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id ); + return atoi ( results [ 1 ] ); + } + +int Preferences::getPreference ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id ); + return atoi ( results [ 1 ] ); + } + +QString Preferences::getSeparator ( ) + { + int s = getPreference ( 2 ); + if ( s == 1 ) + return "/"; + if ( s ==2 ) + return "-"; + else + return "."; + } + +void Preferences::changePreference ( int id, int newpreference ) + { + sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id ); + } + +void Preferences::setDefaultDatePreferences () + { + sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 ); + sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 ); + } + +QString Preferences::getDate ( int y, int m, int d ) + { + QString date; + int format = getPreference ( 1 ); + QString separator = getSeparator(); + + // Convert all date integers to QStrings + QString year = QString::number ( y ); + QString month = QString::number ( m ); + if ( m < 10 ) + month.prepend ( "0" ); + QString day = QString::number ( d ); + if ( d < 10 ) + day.prepend ( "0" ); + + // Truncate four digit year if necessary + if ( format == 2 || format == 4 || format == 6 || format == 8 ) + year.remove ( 0, 2 ); + + // Concatenate dates as necessary + if ( format == 1 || format == 2 ) + { + date = year; + date.append ( separator ); + date.append ( month ); + date.append ( separator ); + date.append ( day ); + return date; + } + if ( format == 3 || format == 4 ) + { + date = month; + date.append ( separator ); + date.append ( day ); + date.append ( separator ); + date.append ( year ); + return date; + } + if ( format == 5 || format == 6 ) + { + date = year; + date.append ( separator ); + date.append ( day ); + date.append ( separator ); + date.append ( month ); + return date; + } + if ( format == 7 || format == 8 ) + { + date = day; + date.append ( separator ); + date.append ( month ); + date.append ( separator ); + date.append ( year ); + return date; + } + } + +QString Preferences::getDate ( int y, int m ) + { + QString date; + int format = getPreference ( 1 ); + QString separator = getSeparator(); + + // Convert all date integers to QStrings + QString year = QString::number ( y ); + QString month = QString::number ( m ); + if ( m < 10 ) + month.prepend ( "0" ); + + // Truncate four digit year if necessary + if ( format == 2 || format == 4 || format == 6 || format == 8 ) + year.remove ( 0, 2 ); + + // Concatenate dates as necessary + if ( format == 1 || format == 2 ) + { + date = year; + date.append ( separator ); + date.append ( month ); + return date; + } + if ( format == 3 || format == 4 ) + { + date = month; + date.append ( separator ); + date.append ( year ); + return date; + } + if ( format == 5 || format == 6 ) + { + date = year; + date.append ( separator ); + date.append ( month ); + return date; + } + if ( format == 7 || format == 8 ) + { + date.append ( month ); + date.append ( separator ); + date.append ( year ); + return date; + } + } + + + + + diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp new file mode 100755 index 0000000..6e5c4f6 --- a/dev/null +++ b/noncore/apps/qashmoney/transactiondisplay.cpp @@ -0,0 +1,586 @@ +#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 +#include +#include +#include +#include +#include + +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 ) ) ); + + 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() ); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext ); + + // redisplay transfers + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children ); + + // 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 ( 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() ); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext ); + + // redisplay transfers + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children ); + + // 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() ); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext ); + + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children ); + + // 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() ); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext ); + + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children ); + + // 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() ); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext ); + + if ( transfer->getNumberOfTransfers() != 0 ) + transfer->displayTransfers ( listview, accountid, children ); + } + +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::limitDisplay ( const QString &text ) + { + listview->clear (); + QString displaytext = "%"; + displaytext.prepend ( text ); + transaction->displayTransactions ( listview, accountid, children, displaytext ); + if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) + transfer->displayTransfers ( listview, accountid, children ); + } + +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(); + } + } + -- cgit v0.9.0.2