File indexing completed on 2024-05-12 16:42:13
0001 /* 0002 SPDX-FileCopyrightText: 2008-2015 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-FileCopyrightText: 2015 Christian Dávid <christian-david@web.de> 0004 SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef TRANSACTIONMATCHER_H 0009 #define TRANSACTIONMATCHER_H 0010 0011 #include <qglobal.h> 0012 0013 class MyMoneySplit; 0014 class MyMoneyTransaction; 0015 class MyMoneyAccount; 0016 0017 class TransactionMatcherPrivate; 0018 class TransactionMatcher 0019 { 0020 public: 0021 Q_DISABLE_COPY(TransactionMatcher) 0022 0023 explicit TransactionMatcher(const MyMoneyAccount& acc); 0024 ~TransactionMatcher(); 0025 0026 /** 0027 * This method matches the manual entered transaction @p tm with the imported 0028 * transaction @p ti based on the splits @p sm and @p si. If the match can be applied, 0029 * MyMoneyTransaction::addMatch() is used to include @p ti inside @p tm and the 0030 * engine data (MyMoneyFile) is updated. A possible bankid found in the imported 0031 * split is carried over into the manual transaction. 0032 * 0033 * The following things will be done in case of a match: 0034 * 0035 * - if the postdate differs between the two transactions 0036 * - the postdate of the manual entered transaction is stored in kmm-orig-postdate 0037 * - the postdate of the imported transaction is assigned to the resulting transaction 0038 * - if the payee differs between the two splits 0039 * - the payee of the manual split is stored in kmm-orig-payee 0040 * - the payee of the imported split is assigned to the resulting split 0041 * - if the reconciliation state is not-reconciled 0042 * - the reconciliation state is set to cleared 0043 * - the bankid of the imported transaction is assigned to the resulting transaction 0044 * - the resulting transaction will be updated and the imported transaction removed 0045 * from the engine 0046 * 0047 * The application of the match depends on the following items: 0048 * 0049 * - both share values of @p sm and @p si must be identical 0050 * - @p tm must be a non-imported (see below), non-matched transaction 0051 * - @p ti must be an imported transaction 0052 * 0053 * If @p allowImportedTransactions is true, @p tm may be an imported transaction. The 0054 * default of @p allowImportedTransactions is @p false. 0055 * 0056 * In case of errors, an exception is thrown. 0057 */ 0058 void match(MyMoneyTransaction tm, MyMoneySplit sm, MyMoneyTransaction ti, MyMoneySplit si, bool allowImportedTransactions = false); 0059 0060 /** 0061 * This method is used to unmatch a previously matched transaction (see match() and findMatch() ) 0062 * and restore the original and imported transaction in the engine. 0063 * 0064 * The following things will be done in case @p t is a matched transaction: 0065 * 0066 * - the enclosed imported transaction is extracted and restored 0067 * - if the kvp contains a kmm-orig-payee record 0068 * - the payee is updated to this value if it still exists, otherwise the payee is left empty 0069 * - if the kvp contains a kmm-orig-postdate record 0070 * - the postdate of the transaction is changed to the value stored in this record 0071 * - a matching bankid is removed from the transaction 0072 * - the resulting transaction will be updated and the imported transaction inserted 0073 * into the engine 0074 * 0075 * In case of errors, an exception is thrown. 0076 */ 0077 void unmatch(const MyMoneyTransaction& t, const MyMoneySplit& s); 0078 0079 /** 0080 * This method is used to accept a previously matched transaction (see match() and findMatch()) 0081 * 0082 * The following things will be done in case @p _t is a matched transaction 0083 * 0084 * - the enclosed imported transaction is removed 0085 * - the kvps kmm-orig-payee and kmm-orig-postdate are removed 0086 * - the resulting transaction will be updated 0087 * 0088 * In case of errors, an exception is thrown 0089 */ 0090 void accept(const MyMoneyTransaction& t, const MyMoneySplit& s); 0091 0092 private: 0093 TransactionMatcherPrivate * const d_ptr; 0094 Q_DECLARE_PRIVATE(TransactionMatcher) 0095 }; 0096 0097 #endif