File indexing completed on 2024-05-12 16:44:09

0001 /*
0002     SPDX-FileCopyrightText: 2006-2018 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef TRANSACTION_P_H
0008 #define TRANSACTION_P_H
0009 
0010 #include "registeritem_p.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // QT Includes
0014 
0015 #include <QColor>
0016 #include <QList>
0017 
0018 // ----------------------------------------------------------------------------
0019 // KDE Includes
0020 
0021 #include <KLocalizedString>
0022 
0023 // ----------------------------------------------------------------------------
0024 // Project Includes
0025 
0026 #include "register.h"
0027 #include "mymoneyaccount.h"
0028 #include "mymoneyfile.h"
0029 #include "mymoneymoney.h"
0030 #include "mymoneypayee.h"
0031 #include "mymoneysplit.h"
0032 #include "mymoneytag.h"
0033 #include "mymoneytransaction.h"
0034 
0035 namespace KMyMoneyRegister
0036 {
0037 class  TransactionPrivate : public RegisterItemPrivate
0038 {
0039 public:
0040     TransactionPrivate() :
0041         m_form(nullptr),
0042         m_formRowHeight(-1),
0043         m_selected(false),
0044         m_focus(false),
0045         m_erroneous(false),
0046         m_inEdit(false),
0047         m_inRegisterEdit(false),
0048         m_showBalance(true),
0049         m_reducedIntensity(false)
0050     {
0051     }
0052 
0053     virtual ~ TransactionPrivate()
0054     {
0055     }
0056 
0057     void init(int uniqueId)
0058     {
0059         auto file = MyMoneyFile::instance();
0060 
0061         // load the account
0062         if (!m_split.accountId().isEmpty())
0063             m_account = file->account(m_split.accountId());
0064 
0065         // load the payee
0066         if (!m_split.payeeId().isEmpty()) {
0067             m_payee = file->payee(m_split.payeeId()).name();
0068         }
0069         if (m_parent->account().isIncomeExpense()) {
0070             m_payeeHeader = m_split.shares().isNegative() ? i18nc("Payer", "From") : i18nc("Payee", "Pay to");
0071         } else {
0072             m_payeeHeader = m_split.shares().isNegative() ? i18nc("Payee", "Pay to") : i18nc("Payer", "From");
0073         }
0074 
0075         // load the tag
0076         if (!m_split.tagIdList().isEmpty()) {
0077             const QList<QString> t = m_split.tagIdList();
0078             for (auto i = 0; i < t.count(); i++) {
0079                 m_tagList << file->tag(t[i]).name();
0080                 m_tagColorList << file->tag(t[i]).tagColor();
0081             }
0082         }
0083 
0084         // load the currency
0085         if (!m_transaction.id().isEmpty())
0086             m_splitCurrencyId = m_account.currencyId();
0087 
0088         // check if transaction is erroneous or not
0089         m_erroneous = !m_transaction.splitSum().isZero();
0090 
0091         if (!m_uniqueId.isEmpty()) {
0092             m_uniqueId += '-';
0093             QString id;
0094             id.setNum(uniqueId);
0095             m_uniqueId += id.rightJustified(3, '0');
0096         }
0097     }
0098 
0099     MyMoneyTransaction      m_transaction;
0100     MyMoneySplit            m_split;
0101     MyMoneyAccount          m_account;
0102     MyMoneyMoney            m_balance;
0103     QTableWidget*           m_form;
0104     QString                 m_category;
0105     QString                 m_payee;
0106     QString                 m_payeeHeader;
0107     QList<QString>          m_tagList;
0108     QList<QColor>           m_tagColorList;
0109     QString                 m_categoryHeader;
0110     QString                 m_splitCurrencyId;
0111     QString                 m_uniqueId;
0112     int                     m_formRowHeight;
0113     bool                    m_selected;
0114     bool                    m_focus;
0115     bool                    m_erroneous;
0116     bool                    m_inEdit;
0117     bool                    m_inRegisterEdit;
0118     bool                    m_showBalance;
0119     bool                    m_reducedIntensity;
0120 };
0121 }
0122 
0123 #endif