File indexing completed on 2024-05-12 16:41:57

0001 /*
0002     SPDX-FileCopyrightText: 2000-2004 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2000-2004 Javier Campos Morales <javi_c@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2000-2004 Felix Rodriguez <frodriguez@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2000-2004 John C <thetacoturtle@users.sourceforge.net>
0006     SPDX-FileCopyrightText: 2000-2004 Thomas Baumgart <ipwizard@users.sourceforge.net>
0007     SPDX-FileCopyrightText: 2000-2004 Kevin Tambascio <ktambascio@users.sourceforge.net>
0008     SPDX-FileCopyrightText: 2000-2004 Ace Jones <acejones@users.sourceforge.net>
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #ifndef MYMONEYSTATEMENTREADER_H
0013 #define MYMONEYSTATEMENTREADER_H
0014 
0015 #include <QObject>
0016 #include <QString>
0017 #include <QStringList>
0018 
0019 #include "mymoneystatement.h"
0020 #include "transactionmatchfinder.h"
0021 
0022 class MyMoneyFileTransaction;
0023 class TransactionMatcher;
0024 class QStringList;
0025 class MyMoneyAccount;
0026 class MyMoneyInstitution;
0027 
0028 /**
0029   * This is a pared-down version of a MyMoneyQifReader object
0030   *
0031   * @author Ace Jones
0032   */
0033 class MyMoneyStatementReader : public QObject
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     MyMoneyStatementReader();
0039     ~MyMoneyStatementReader();
0040 
0041     /**
0042       * This method imports data from the MyMoneyStatement object @a s
0043       * into the MyMoney engine. It leaves some statistical information
0044       * in the @a messages string list
0045       *
0046       * @retval true the import was processed successfully
0047       * @retval false the import resulted in a failure.
0048       */
0049     bool import(const MyMoneyStatement& s, QStringList& messages);
0050 
0051     /**
0052       * This method is used to modify the auto payee creation flag.
0053       * If this flag is set, records for payees that are not currently
0054       * found in the engine will be automatically created with no
0055       * further user interaction required. If this flag is no set,
0056       * the user will be asked if the payee should be created or not.
0057       * If the MyMoneyQifReader object is created auto payee creation
0058       * is turned off.
0059       *
0060       * @param create flag if this feature should be turned on (@p true)
0061       *               or turned off (@p false)
0062       */
0063     void setAutoCreatePayee(bool create);
0064     void setAskPayeeCategory(bool ask);
0065 
0066     const MyMoneyAccount& account() const;
0067 
0068     void setProgressCallback(void(*callback)(int, int, const QString&));
0069 
0070     /**
0071      * Returns true in case any transaction has been added to the engine
0072      * during the import of the statement. Only returns useful result
0073      * after import() has been called.
0074      */
0075     bool anyTransactionAdded() const;
0076 
0077     /**
0078       * Imports a KMM statement into the engine, triggering the appropriate
0079       * UI to handle account matching, payee creation, and someday
0080       * payee and transaction matching.
0081       */
0082     static QStringList importStatement(const QString& url, bool silent = false, void(*callback)(int, int, const QString&) = nullptr);
0083     static QStringList importStatement(const MyMoneyStatement& s, bool silent = false, void(*callback)(int, int, const QString&) = nullptr);
0084     static void clearResultMessages();
0085     static QStringList resultMessages();
0086 
0087 private:
0088     /**
0089       * This method is used to update the progress information. It
0090       * checks if an appropriate function is known and calls it.
0091       *
0092       * For a parameter description see KMyMoneyView::progressCallback().
0093       */
0094     void signalProgress(int current, int total, const QString& = "");
0095 
0096     void processTransactionEntry(const MyMoneyStatement::Transaction& t_in);
0097     void processSecurityEntry(const MyMoneyStatement::Security& s_in);
0098 
0099     enum SelectCreateMode {
0100         Create = 0,
0101         Select,
0102     };
0103 
0104     /**
0105       * This method is used to select or create brokerage account if
0106       * it isn't specified in statement transaction.
0107       */
0108     QString SelectBrokerageAccount();
0109 
0110     /**
0111       * This method is used to find an account using the account's name
0112       * stored in @p account in the current MyMoneyFile object. If it does not
0113       * exist, the user has the chance to create it or to skip processing
0114       * of this account.
0115       *
0116       * Please see the documentation for this function in MyMoneyQifReader
0117       *
0118       * @param mode Is either Create or Select depending on the above table
0119       * @param account Reference to MyMoneyAccount object
0120       */
0121     bool selectOrCreateAccount(const SelectCreateMode mode, MyMoneyAccount& account);
0122 
0123 private:
0124     /// \internal d-pointer class.
0125     class Private;
0126     /// \internal d-pointer instance.
0127     Private* const d;
0128     QStringList             m_dontAskAgain;
0129     bool                    m_userAbort;
0130     bool                    m_autoCreatePayee;
0131     bool                    m_askPayeeCategory;
0132     MyMoneyFileTransaction* m_ft;
0133 
0134     void (*m_progressCallback)(int, int, const QString&);
0135 
0136     void handleMatchingOfExistingTransaction(TransactionMatcher & matcher,
0137             MyMoneyTransaction matchedTransaction,
0138             MyMoneySplit matchedSplit,
0139             MyMoneyTransaction & importedTransaction,
0140             const MyMoneySplit & importedSplit,
0141             const TransactionMatchFinder::MatchResult & matchResult);
0142 
0143     void handleMatchingOfScheduledTransaction(TransactionMatcher & matcher,
0144             MyMoneySchedule matchedSchedule,
0145             MyMoneySplit matchedSplit,
0146             const MyMoneyTransaction & importedTransaction,
0147             const MyMoneySplit & importedSplit);
0148     void addTransaction(MyMoneyTransaction & transaction);
0149 
0150     /** Asks the user whether to enter a schedule transaction to match it with imported one
0151      * @param matchedSchedule the schedule which matches the imported transaction
0152      * @param importedSplit the split of the imported transaction which matches the split of the schedule
0153      * @return true, if user confirmed to enter the schedule to match it with imported transaction; false otherwise
0154      */
0155     bool askUserToEnterScheduleForMatching(const MyMoneySchedule& matchedSchedule, const MyMoneySplit& importedSplit, const MyMoneyTransaction & importedTransaction) const;
0156 
0157 private Q_SLOTS:
0158     void slotNewAccount(const MyMoneyAccount& acc);
0159 };
0160 
0161 #endif