File indexing completed on 2024-05-26 05:10:14

0001 /*
0002     SPDX-FileCopyrightText: 2007 Thomas Baumgart <ipwizard@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kloanschedulepage.h"
0008 #include "kloanschedulepage_p.h"
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QLineEdit>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "ui_kgeneralloaninfopage.h"
0022 #include "ui_kloanschedulepage.h"
0023 
0024 #include <kguiutils.h>
0025 #include "kmymoneyaccountselector.h"
0026 #include "kmymoneycategory.h"
0027 #include "knewaccountwizard.h"
0028 #include "knewaccountwizard_p.h"
0029 #include "kaccountsummarypage.h"
0030 #include "kgeneralloaninfopage.h"
0031 #include "kgeneralloaninfopage_p.h"
0032 #include "kloanpayoutpage.h"
0033 #include "mymoneyaccount.h"
0034 #include "mymoneyfile.h"
0035 #include "knewaccountdlg.h"
0036 #include "mymoneymoney.h"
0037 #include "wizardpage.h"
0038 #include "mymoneyenums.h"
0039 
0040 using namespace NewAccountWizard;
0041 using namespace Icons;
0042 using namespace eMyMoney;
0043 
0044 namespace NewAccountWizard
0045 {
0046 LoanSchedulePage::LoanSchedulePage(Wizard* wizard) :
0047     QWidget(wizard),
0048     WizardPage<Wizard>(*new LoanSchedulePagePrivate(wizard), StepSchedule, this, wizard)
0049 {
0050     Q_D(const LoanSchedulePage);
0051     d->ui->setupUi(this);
0052     d->m_mandatoryGroup->add(d->ui->m_interestCategory->lineEdit());
0053     d->m_mandatoryGroup->add(d->ui->m_paymentAccount->lineEdit());
0054     connect(d->ui->m_interestCategory, &KMyMoneyCombo::createItem, this, &LoanSchedulePage::slotCreateCategory);
0055     connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &LoanSchedulePage::slotLoadWidgets);
0056 }
0057 
0058 LoanSchedulePage::~LoanSchedulePage()
0059 {
0060 }
0061 
0062 void LoanSchedulePage::slotCreateCategory(const QString& name, QString& id)
0063 {
0064     Q_D(LoanSchedulePage);
0065     MyMoneyAccount acc, parent;
0066     acc.setName(name);
0067 
0068     if (d->m_wizard->moneyBorrowed())
0069         parent = MyMoneyFile::instance()->expense();
0070     else
0071         parent = MyMoneyFile::instance()->income();
0072 
0073     KNewAccountDlg::newCategory(acc, parent);
0074 
0075     // return id
0076     id = acc.id();
0077 }
0078 
0079 QDate LoanSchedulePage::firstPaymentDueDate() const
0080 {
0081     Q_D(const LoanSchedulePage);
0082     if (d->ui->m_firstPaymentDueDate->isEnabled())
0083         return d->ui->m_firstPaymentDueDate->date();
0084     return d->m_wizard->d_func()->m_generalLoanInfoPage->d_func()->ui->m_firstPaymentDate->date();
0085 }
0086 
0087 QWidget* LoanSchedulePage::initialFocusWidget() const
0088 {
0089     Q_D(const LoanSchedulePage);
0090     return d->ui->m_interestCategory;
0091 }
0092 
0093 void LoanSchedulePage::enterPage()
0094 {
0095     Q_D(LoanSchedulePage);
0096     d->ui->m_interestCategory->setFocus();
0097     d->ui->m_firstPaymentDueDate->setDisabled(d->m_wizard->d_func()->m_generalLoanInfoPage->recordAllPayments());
0098     slotLoadWidgets();
0099 }
0100 
0101 void LoanSchedulePage::slotLoadWidgets()
0102 {
0103     Q_D(LoanSchedulePage);
0104     AccountSet set;
0105     if (d->m_wizard->moneyBorrowed())
0106         set.addAccountGroup(Account::Type::Expense);
0107     else
0108         set.addAccountGroup(Account::Type::Income);
0109     set.load(d->ui->m_interestCategory->selector());
0110 
0111     set.clear();
0112     set.addAccountGroup(Account::Type::Asset);
0113     set.load(d->ui->m_paymentAccount->selector());
0114 }
0115 
0116 KMyMoneyWizardPage* LoanSchedulePage::nextPage() const
0117 {
0118     Q_D(const LoanSchedulePage);
0119     // if the balance widget of the general loan info page is enabled and
0120     // the value is not zero, then the payout already happened and we don't
0121     // ask for it.
0122     if (d->m_wizard->openingBalance().isZero())
0123         return d->m_wizard->d_func()->m_loanPayoutPage;
0124     return d->m_wizard->d_func()->m_accountSummaryPage;
0125 }
0126 }