File indexing completed on 2024-05-19 05:06:53
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 "kmm_base_dialogs_export.h" 0012 0013 #include <qglobal.h> 0014 0015 class MyMoneySplit; 0016 class MyMoneyTransaction; 0017 class MyMoneyAccount; 0018 0019 class TransactionMatcherPrivate; 0020 class KMM_BASE_DIALOGS_EXPORT TransactionMatcher 0021 { 0022 public: 0023 Q_DISABLE_COPY(TransactionMatcher) 0024 0025 explicit TransactionMatcher(); 0026 ~TransactionMatcher(); 0027 0028 /** 0029 * This method matches the manual entered transaction @p tm with the imported 0030 * transaction @p ti based on the splits @p sm and @p si. If the match can be applied, 0031 * MyMoneyTransaction::addMatch() is used to include @p ti inside @p tm and the 0032 * engine data (MyMoneyFile) is updated. A possible bankid found in the imported 0033 * split is carried over into the manual transaction. 0034 * 0035 * The following things will be done in case of a match: 0036 * 0037 * - if the postdate differs between the two transactions 0038 * - the postdate of the manual entered transaction is stored in kmm-orig-postdate 0039 * - the postdate of the imported transaction is assigned to the resulting transaction 0040 * - if the payee differs between the two splits 0041 * - the payee of the manual split is stored in kmm-orig-payee 0042 * - the payee of the imported split is assigned to the resulting split 0043 * - if the reconciliation state is not-reconciled 0044 * - the reconciliation state is set to cleared 0045 * - the bankid of the imported transaction is assigned to the resulting transaction 0046 * - the resulting transaction will be updated and the imported transaction removed 0047 * from the engine 0048 * 0049 * The application of the match depends on the following items: 0050 * 0051 * - both share values of @p sm and @p si must be identical 0052 * - @p tm must be a non-imported (see below), non-matched transaction 0053 * - @p ti must be an imported transaction 0054 * 0055 * If @p allowImportedTransactions is true, @p tm may be an imported transaction. The 0056 * default of @p allowImportedTransactions is @p false. 0057 * 0058 * In case of errors, an exception is thrown. 0059 */ 0060 void match(MyMoneyTransaction tm, MyMoneySplit sm, MyMoneyTransaction ti, MyMoneySplit si, bool allowImportedTransactions = false); 0061 0062 /** 0063 * This method is used to unmatch a previously matched transaction (see match() and findMatch() ) 0064 * and restore the original and imported transaction in the engine. 0065 * 0066 * The following things will be done in case @p t is a matched transaction: 0067 * 0068 * - the enclosed imported transaction is extracted and restored 0069 * - if the kvp contains a kmm-orig-payee record 0070 * - the payee is updated to this value if it still exists, otherwise the payee is left empty 0071 * - if the kvp contains a kmm-orig-postdate record 0072 * - the postdate of the transaction is changed to the value stored in this record 0073 * - a matching bankid is removed from the transaction 0074 * - the resulting transaction will be updated and the imported transaction inserted 0075 * into the engine 0076 * 0077 * In case of errors, an exception is thrown. 0078 */ 0079 void unmatch(const MyMoneyTransaction& t, const MyMoneySplit& s); 0080 0081 /** 0082 * This method is used to accept a previously matched transaction (see match() and findMatch()) 0083 * 0084 * The following things will be done in case @p _t is a matched transaction 0085 * 0086 * - the enclosed imported transaction is removed 0087 * - the kvps kmm-orig-payee and kmm-orig-postdate are removed 0088 * - the resulting transaction will be updated 0089 * 0090 * In case of errors, an exception is thrown 0091 */ 0092 void accept(const MyMoneyTransaction& t, const MyMoneySplit& s); 0093 0094 private: 0095 TransactionMatcherPrivate * const d_ptr; 0096 Q_DECLARE_PRIVATE(TransactionMatcher) 0097 }; 0098 0099 #endif