File indexing completed on 2024-05-12 16:42:41
0001 /* 0002 SPDX-FileCopyrightText: 2002-2017 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 /** 0081 * This method checks if a reference to the given object exists. It returns, 0082 * a @p true if the object is referencing the one requested by the 0083 * parameter @p id. If it does not, this method returns @p false. 0084 * 0085 * @param id id of the object to be checked for references 0086 * @retval true This object references object with id @p id. 0087 * @retval false This object does not reference the object with id @p id. 0088 */ 0089 bool hasReferenceTo(const QString& id) const override; 0090 0091 MyMoneyMoney shares() const; 0092 void setShares(const MyMoneyMoney& shares); 0093 0094 void negateShares(); 0095 0096 /** 0097 * This method returns the price. If the member m_price is not zero 0098 * its value is returned. Otherwise, if m_shares is not zero the quotient 0099 * of m_value / m_shares is returned. If m_values equals to zero, 1 0100 * will be returned. 0101 */ 0102 MyMoneyMoney price() const; 0103 /** This method just returns what is in m_price, so when we write to the 0104 * database, we don't just generate prices 0105 */ 0106 MyMoneyMoney actualPrice() const; 0107 void setPrice(const MyMoneyMoney& price); 0108 0109 MyMoneyMoney value() const; 0110 MyMoneyMoney value(const QString& transactionCurrencyId, const QString& splitCurrencyId) const; 0111 0112 /** 0113 * Required to have (direct) access to the MyMoneyKeyValueContainer::value() method. 0114 */ 0115 QString value(const QString& key) const; 0116 0117 /** 0118 * Required to have (direct) access to the MyMoneyKeyValueContainer::setValue() method. 0119 */ 0120 void setValue(const QString& key, const QString& value); 0121 void setValue(const MyMoneyMoney& value); 0122 /** 0123 * This method is used to set either the shares or the value depending on 0124 * the currencies assigned to the split/account and the transaction. 0125 * 0126 * If @p transactionCurrencyId equals @p splitCurrencyId this method 0127 * calls setValue(MyMoneyMoney) otherwise setShares(MyMoneyMoney). 0128 * 0129 * @param value the value to be assiged 0130 * @param transactionCurrencyId the id of the currency assigned to the transaction 0131 * @param splitCurrencyId the id of the currency assigned to the split (i.e. the 0132 * the id of the currency assigned to the account that is 0133 * referenced by the split) 0134 */ 0135 void setValue(const MyMoneyMoney& value, const QString& transactionCurrencyId, const QString& splitCurrencyId); 0136 0137 void negateValue(); 0138 0139 QString accountId() const; 0140 void setAccountId(const QString& account); 0141 0142 QString costCenterId() const; 0143 void setCostCenterId(const QString& costCenter); 0144 0145 QString memo() const; 0146 void setMemo(const QString& memo); 0147 0148 eMyMoney::Split::State reconcileFlag() const; 0149 void setReconcileFlag(const eMyMoney::Split::State flag); 0150 0151 QDate reconcileDate() const; 0152 void setReconcileDate(const QDate& date); 0153 0154 QString payeeId() const; 0155 void setPayeeId(const QString& payee); 0156 0157 QList<QString> tagIdList() const; 0158 void setTagIdList(const QList<QString>& tagList); 0159 0160 QString action() const; 0161 void setAction(const QString& action); 0162 void setAction(eMyMoney::Split::InvestmentTransactionType type); 0163 bool isAmortizationSplit() const; 0164 bool isInterestSplit() const; 0165 0166 QString number() const; 0167 void setNumber(const QString& number); 0168 0169 bool isAutoCalc() const; 0170 0171 QString bankID() const; 0172 void setBankID(const QString& bankID); 0173 0174 QString transactionId() const; 0175 void setTransactionId(const QString& id); 0176 0177 /** 0178 * returns @a true if this its a transaction matched against an imported 0179 * transaction. The imported and matched transaction can be extracted 0180 * using matchedTransaction() and can be removed using removeMatch(). 0181 */ 0182 bool isMatched() const; 0183 0184 /** 0185 * add an imported transaction @p t as matching transaction. Any previously 0186 * added transaction will be overridden. @p t.isImported() must return true, 0187 * otherwise the transaction is not stored. 0188 */ 0189 void addMatch(const MyMoneyTransaction& t); 0190 0191 /** 0192 * remove the data of the imported transaction added with addMatch(). 0193 */ 0194 void removeMatch(); 0195 0196 /** 0197 * Return the matching imported transaction. If no such transaction 0198 * is available (isMatched() returns false) an empty transaction is returned. 0199 */ 0200 MyMoneyTransaction matchedTransaction() const; 0201 0202 /** 0203 * This method replaces all occurrences of id @a oldId with 0204 * @a newId. All other ids are not changed. 0205 * 0206 * @return true if any change has been performed 0207 * @return false if nothing has been modified 0208 */ 0209 bool replaceId(const QString& newId, const QString& oldId); 0210 0211 static QString actionName(eMyMoney::Split::Action action); 0212 }; 0213 0214 0215 inline void swap(MyMoneySplit& first, MyMoneySplit& second) // krazy:exclude=inline 0216 { 0217 using std::swap; 0218 swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); 0219 swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); 0220 } 0221 0222 inline MyMoneySplit::MyMoneySplit(MyMoneySplit && other) : MyMoneySplit() // krazy:exclude=inline 0223 { 0224 swap(*this, other); 0225 } 0226 0227 inline MyMoneySplit & MyMoneySplit::operator=(MyMoneySplit other) // krazy:exclude=inline 0228 { 0229 swap(*this, other); 0230 return *this; 0231 } 0232 0233 /** 0234 * Make it possible to hold @ref MyMoneySplit objects inside @ref QVariant objects. 0235 */ 0236 Q_DECLARE_METATYPE(MyMoneySplit) 0237 0238 #endif