File indexing completed on 2024-05-12 05:06:44
0001 /* 0002 SPDX-FileCopyrightText: 2002-2019 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-FileCopyrightText: 2004 Kevin Tambascio <ktambascio@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2005-2006 Ace Jones <acejones@users.sourceforge.net> 0005 SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef MYMONEYSPLIT_H 0010 #define MYMONEYSPLIT_H 0011 0012 #include "kmm_mymoney_export.h" 0013 0014 // ---------------------------------------------------------------------------- 0015 // QT Includes 0016 0017 #include <QMetaType> 0018 0019 // ---------------------------------------------------------------------------- 0020 // KDE Includes 0021 0022 // ---------------------------------------------------------------------------- 0023 // Project Includes 0024 0025 #include "mymoneyobject.h" 0026 #include "mymoneykeyvaluecontainer.h" 0027 0028 class QString; 0029 class QDate; 0030 0031 class MyMoneyMoney; 0032 class MyMoneyTransaction; 0033 0034 namespace eMyMoney { 0035 namespace Split { 0036 enum class InvestmentTransactionType; 0037 enum class State; 0038 enum class Action; 0039 } 0040 } 0041 0042 /** 0043 * @author Thomas Baumgart 0044 * @author Łukasz Wojniłowicz 0045 */ 0046 0047 /** 0048 * This class represents a split of a transaction. 0049 */ 0050 class MyMoneySplitPrivate; 0051 class KMM_MYMONEY_EXPORT MyMoneySplit : public MyMoneyObject, public MyMoneyKeyValueContainer 0052 { 0053 Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneySplit) 0054 0055 KMM_MYMONEY_UNIT_TESTABLE 0056 0057 public: 0058 0059 MyMoneySplit(); 0060 explicit MyMoneySplit(const QString &id); 0061 0062 MyMoneySplit(const QString& id, 0063 const MyMoneySplit& other); 0064 0065 MyMoneySplit(const MyMoneySplit & other); 0066 MyMoneySplit(MyMoneySplit && other); 0067 MyMoneySplit & operator=(MyMoneySplit other); 0068 friend void swap(MyMoneySplit& first, MyMoneySplit& second); 0069 0070 ~MyMoneySplit(); 0071 0072 bool operator == (const MyMoneySplit&) const; 0073 0074 /** 0075 * Returns a copy of the MyMoneySplit where the sign of 0076 * shares and value is inverted. 0077 */ 0078 MyMoneySplit operator-() const; 0079 0080 MyMoneyMoney shares() const; 0081 void setShares(const MyMoneyMoney& shares); 0082 0083 void negateShares(); 0084 0085 /** 0086 * This method returns the price. If the member m_price is not zero 0087 * its value is returned. Otherwise, if m_shares is not zero the quotient 0088 * of m_value / m_shares is returned. If m_values equals to zero, 1 0089 * will be returned. 0090 */ 0091 MyMoneyMoney price() const; 0092 void setPrice(const MyMoneyMoney& price); 0093 0094 MyMoneyMoney value() const; 0095 MyMoneyMoney value(const QString& transactionCurrencyId, const QString& splitCurrencyId) const; 0096 0097 /** 0098 * Required to have (direct) access to the MyMoneyKeyValueContainer::value() method. 0099 */ 0100 QString value(const QString& key) const; 0101 0102 /** 0103 * Required to have (direct) access to the MyMoneyKeyValueContainer::setValue() method. 0104 */ 0105 void setValue(const QString& key, const QString& value, const QString& defaultValue = QString()); 0106 void setValue(const MyMoneyMoney& value); 0107 /** 0108 * This method is used to set either the shares or the value depending on 0109 * the currencies assigned to the split/account and the transaction. 0110 * 0111 * If @p transactionCurrencyId equals @p splitCurrencyId this method 0112 * calls setValue(MyMoneyMoney) otherwise setShares(MyMoneyMoney). 0113 * 0114 * @param value the value to be assigned 0115 * @param transactionCurrencyId the id of the currency assigned to the transaction 0116 * @param splitCurrencyId the id of the currency assigned to the split (i.e. the 0117 * the id of the currency assigned to the account that is 0118 * referenced by the split) 0119 */ 0120 void setValue(const MyMoneyMoney& value, const QString& transactionCurrencyId, const QString& splitCurrencyId); 0121 0122 void negateValue(); 0123 0124 QString accountId() const; 0125 void setAccountId(const QString& account); 0126 0127 QString costCenterId() const; 0128 void setCostCenterId(const QString& costCenter); 0129 0130 QString memo() const; 0131 void setMemo(const QString& memo); 0132 0133 eMyMoney::Split::State reconcileFlag() const; 0134 void setReconcileFlag(const eMyMoney::Split::State flag); 0135 0136 QDate reconcileDate() const; 0137 void setReconcileDate(const QDate& date); 0138 0139 QString payeeId() const; 0140 void setPayeeId(const QString& payee); 0141 0142 QList<QString> tagIdList() const; 0143 void setTagIdList(const QList<QString>& tagList); 0144 0145 QString action() const; 0146 void setAction(const QString& action); 0147 void setAction(eMyMoney::Split::InvestmentTransactionType type); 0148 eMyMoney::Split::InvestmentTransactionType investmentTransactionType() const; 0149 eMyMoney::Split::Action actionStringToAction(const QString &text) const; 0150 0151 bool isAmortizationSplit() const; 0152 bool isInterestSplit() const; 0153 0154 QString number() const; 0155 void setNumber(const QString& number); 0156 0157 bool isAutoCalc() const; 0158 0159 QString bankID() const; 0160 void setBankID(const QString& bankID); 0161 0162 QString transactionId() const; 0163 void setTransactionId(const QString& id); 0164 0165 /** 0166 * returns @a true if this its a transaction matched against an imported 0167 * transaction. The imported and matched transaction can be extracted 0168 * using matchedTransaction() and can be removed using removeMatch(). 0169 */ 0170 bool isMatched() const; 0171 0172 /** 0173 * add an imported transaction @p t as matching transaction. Any previously 0174 * added transaction will be overridden. @p t.isImported() must return true, 0175 * otherwise the transaction is not stored. 0176 */ 0177 void addMatch(const MyMoneyTransaction& t); 0178 0179 /** 0180 * remove the data of the imported transaction added with addMatch(). 0181 */ 0182 void removeMatch(); 0183 0184 /** 0185 * Return the matching imported transaction. If no such transaction 0186 * is available (isMatched() returns false) an empty transaction is returned. 0187 */ 0188 MyMoneyTransaction matchedTransaction() const; 0189 0190 /** 0191 * This method replaces all occurrences of id @a oldId with 0192 * @a newId. All other ids are not changed. 0193 * 0194 * @return true if any change has been performed 0195 * @return false if nothing has been modified 0196 */ 0197 bool replaceId(const QString& newId, const QString& oldId); 0198 0199 static QString actionName(eMyMoney::Split::Action action); 0200 }; 0201 0202 0203 inline void swap(MyMoneySplit& first, MyMoneySplit& second) // krazy:exclude=inline 0204 { 0205 using std::swap; 0206 swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); 0207 swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); 0208 } 0209 0210 inline MyMoneySplit::MyMoneySplit(MyMoneySplit && other) : MyMoneySplit() // krazy:exclude=inline 0211 { 0212 swap(*this, other); 0213 } 0214 0215 inline MyMoneySplit & MyMoneySplit::operator=(MyMoneySplit other) // krazy:exclude=inline 0216 { 0217 swap(*this, other); 0218 return *this; 0219 } 0220 0221 /** 0222 * Make it possible to hold @ref MyMoneySplit objects inside @ref QVariant objects. 0223 */ 0224 Q_DECLARE_METATYPE(MyMoneySplit) 0225 0226 #endif