File indexing completed on 2024-05-12 16:42:36

0001 /*
0002     SPDX-FileCopyrightText: 2000-2003 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2001-2002 Felix Rodriguez <frodriguez@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2002-2004 Kevin Tambascio <ktambascio@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2004-2005 Ace Jones <acejones@users.sourceforge.net>
0006     SPDX-FileCopyrightText: 2006-2018 Thomas Baumgart <tbaumgart@kde.org>
0007     SPDX-FileCopyrightText: 2006 Darren Gould <darren_gould@gmx.de>
0008     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #ifndef MYMONEYFILE_H
0013 #define MYMONEYFILE_H
0014 
0015 // ----------------------------------------------------------------------------
0016 // QT Includes
0017 
0018 #include <QObject>
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 #include "kmm_mymoney_export.h"
0023 #include "mymoneyunittestable.h"
0024 
0025 /**
0026   * @author Thomas Baumgart, Michael Edwardes, Kevin Tambascio, Christian Dávid
0027   */
0028 
0029 /**
0030   * This class represents the interface to the MyMoney engine.
0031   * For historical reasons it is still called MyMoneyFile.
0032   * It is implemented using the singleton pattern and thus only
0033   * exists once for each running instance of an application.
0034   *
0035   * The instance of the MyMoneyFile object is accessed as follows:
0036   *
0037   * @code
0038   * MyMoneyFile *file = MyMoneyFile::instance();
0039   * file->anyMemberFunction();
0040   * @endcode
0041   *
0042   * The first line of the above code creates a unique MyMoneyFile
0043   * object if it is called for the first time ever. All subsequent
0044   * calls to this functions return a pointer to the object created
0045   * during the first call.
0046   *
0047   * As the MyMoneyFile object represents the business logic, a storage
0048   * manager must be attached to it. This mechanism allows to use different
0049   * access methods to store the objects. The interface to access such an
0050   * storage manager is defined in the class MyMoneyStorageMgr. The methods
0051   * attachStorage() and detachStorage() are used to attach/detach a
0052   * storage manager object. The following code can be used to create a
0053   * functional MyMoneyFile instance:
0054   *
0055   * @code
0056   * MyMoneyStorageMgr *storage = ....
0057   * MyMoneyFile *file = MyMoneyFile::instance();
0058   * file->attachStorage(storage);
0059   * @endcode
0060   *
0061   * The methods addAccount(), modifyAccount() and removeAccount() implement the
0062   * general account maintenance functions. The method reparentAccount() is
0063   * available to move an account from one superordinate account to another.
0064   * account() and accountList() are used to retrieve a single instance or a
0065   * QList of MyMoneyAccount objects.
0066   *
0067   * The methods addInstitution(), modifyInstitution() and removeInstitution()
0068   * implement the general institution maintenance functions. institution() and
0069   * institutionList() are used to retrieve a single instance or a
0070   * QList of MyMoneyInstitution objects.
0071   *
0072   * The methods addPayee(), modifyPayee() and removePayee()
0073   * implement the general payee maintenance functions.
0074   * payee() and payeeList() are used to retrieve a single instance or a
0075   * QList of MyMoneyPayee objects.
0076   *
0077   * The methods addTag(), modifyTag() and removeTag()
0078   * implement the general tag maintenance functions.
0079   * tag() and tagList() are used to retrieve a single instance or a
0080   * QList of MyMoneyTag objects.
0081   *
0082   * The methods addTransaction(), modifyTransaction() and removeTransaction()
0083   * implement the general transaction maintenance functions.
0084   * transaction() and transactionList() are used to retrieve
0085   * a single instance or a QList of MyMoneyTransaction objects.
0086   *
0087   * The methods addSecurity(), modifySecurity() and removeSecurity()
0088   * implement the general access to equities held in the engine.
0089   *
0090   * The methods addCurrency(), modifyCurrency() and removeCurrency()
0091   * implement the general access to multiple currencies held in the engine.
0092   * The methods baseCurrency() and setBaseCurrency() allow to retrieve/set
0093   * the currency selected by the user as base currency. If a currency
0094   * reference is empty, it will usually be interpreted as baseCurrency().
0095   *
0096   * The methods liability(), asset(), expense(), income() and equity() are
0097   * used to retrieve the five standard accounts. isStandardAccount()
0098   * checks if a given accountId references one of the or not.
0099   * setAccountName() is used to specify a name for the standard accounts
0100   * from the GUI.
0101   *
0102   * The MyMoneyFile object emits the dataChanged() signal when data
0103   * has been changed.
0104   *
0105   * For arbitrary values that have to be stored with the storage object
0106   * but are of importance to the application only, the object is derived
0107   * for MyMoneyKeyValueContainer which provides a container to store
0108   * these values indexed by an alphanumeric key.
0109   *
0110   * @exception MyMoneyException is thrown whenever an error occurs
0111   * while the engine code is running. The MyMoneyException:: object
0112   * describes the problem.
0113   */
0114 template <class Key, class T> class QMap;
0115 class QString;
0116 class QStringList;
0117 class QBitArray;
0118 class MyMoneyStorageMgr;
0119 class MyMoneyCostCenter;
0120 class MyMoneyAccount;
0121 class MyMoneyInstitution;
0122 class MyMoneySecurity;
0123 class MyMoneyPrice;
0124 typedef QPair<QString, QString> MyMoneySecurityPair;
0125 typedef QMap<QDate, MyMoneyPrice> MyMoneyPriceEntries;
0126 typedef QMap<MyMoneySecurityPair, MyMoneyPriceEntries> MyMoneyPriceList;
0127 class MyMoneySchedule;
0128 class MyMoneyTag;
0129 class MyMoneyPayee;
0130 class MyMoneyBudget;
0131 class MyMoneyReport;
0132 class MyMoneyMoney;
0133 class MyMoneySplit;
0134 class MyMoneyObject;
0135 class MyMoneyTransaction;
0136 class MyMoneyTransactionFilter;
0137 class onlineJob;
0138 
0139 namespace eMyMoney {
0140 enum class StockSplitDirection;
0141 namespace Account {
0142 enum class Type;
0143 }
0144 namespace File {
0145 enum class Object;
0146 }
0147 namespace Schedule {
0148 enum class Type;
0149 enum class Occurrence;
0150 enum class PaymentType;
0151 }
0152 namespace TransactionFilter {
0153 enum class State;
0154 }
0155 }
0156 
0157 class KMM_MYMONEY_EXPORT MyMoneyFile : public QObject
0158 {
0159     Q_OBJECT
0160     KMM_MYMONEY_UNIT_TESTABLE
0161 
0162 public:
0163     friend class MyMoneyNotifier;
0164 
0165     /**
0166       * This is the function to access the MyMoneyFile object.
0167       * It returns a pointer to the single instance of the object.
0168       */
0169     static MyMoneyFile* instance();
0170 
0171     /**
0172       * This is the destructor for any MyMoneyFile object
0173       */
0174     ~MyMoneyFile();
0175 
0176     /**
0177       * @deprecated This is a convenience constructor. Do not use it anymore.
0178       * It will be deprecated in a future version of the engine.
0179       *
0180       * @param storage pointer to object that implements the MyMoneyStorageMgr
0181       *                interface.
0182       */
0183     explicit MyMoneyFile(MyMoneyStorageMgr *storage);
0184 
0185     // general get functions
0186     MyMoneyPayee user() const;
0187 
0188     // general set functions
0189     void setUser(const MyMoneyPayee& user);
0190 
0191     /**
0192       * This method is used to attach a storage object to the MyMoneyFile object
0193       * Without an attached storage object, the MyMoneyFile object is
0194       * of no use.
0195       *
0196       * After successful completion, the dataChanged() signal is emitted.
0197       *
0198       * In case of an error condition, an exception is thrown.
0199       * The following error conditions are checked:
0200       *
0201       * - @a storage is not equal to 0
0202       * - there is no other @a storage object attached (use detachStorage()
0203       *   to revert the attachStorage() operation.
0204       *
0205       * @param storage pointer to object that implements the MyMoneyStorageMgr
0206       *                interface.
0207       *
0208       * @sa detachStorage()
0209       */
0210     void attachStorage(MyMoneyStorageMgr* const storage);
0211 
0212     /**
0213       * This method is used to detach a previously attached storage
0214       * object from the MyMoneyFile object. If no storage object
0215       * is attached to the engine, this is a NOP.
0216       *
0217       * @param storage pointer to object that implements the MyMoneyStorageMgr
0218       *                interface.
0219       *
0220       * @sa attachStorage()
0221       */
0222     void detachStorage(MyMoneyStorageMgr* const storage = 0);
0223 
0224     /**
0225       * This method returns whether a storage is currently attached to
0226       * the engine or not.
0227       *
0228       * @return true if storage object is attached, false otherwise
0229       */
0230     bool storageAttached() const;
0231 
0232     /**
0233       * This method returns a pointer to the storage object
0234       *
0235       * @return const pointer to the current attached storage object.
0236       *         If no object is attached, returns 0.
0237       */
0238     MyMoneyStorageMgr* storage() const;
0239 
0240     /**
0241       * This method must be called before any single change or a series of changes
0242       * in the underlying storage area is performed.
0243       * Once all changes are complete (i.e. the transaction is completed),
0244       * commitTransaction() must be called to finalize all changes. If an error occurs
0245       * during the processing of the changes call rollbackTransaction() to undo the
0246       * changes done so far.
0247       */
0248     void startTransaction();
0249 
0250     /**
0251       * This method returns whether a transaction has been started (@a true)
0252       * or not (@a false).
0253       */
0254     bool hasTransaction() const;
0255 
0256     /**
0257       * @sa startTransaction()
0258       */
0259     void commitTransaction();
0260 
0261     /**
0262       * @sa startTransaction()
0263       */
0264     void rollbackTransaction();
0265 
0266     /**
0267      * Calculate the balance after (with @a direction set to StockSplitForward) or before
0268      * (with @a direction set to StockSplitBackward) from a given @a balance and @a factor
0269      * in account @a accountId.
0270      */
0271     MyMoneyMoney stockSplit(const QString& accountId, MyMoneyMoney balance, MyMoneyMoney factor, eMyMoney::StockSplitDirection direction) const;
0272 
0273     /**
0274       * This method is used to return the standard liability account
0275       * @return MyMoneyAccount liability account(group)
0276       */
0277     MyMoneyAccount liability() const;
0278 
0279     /**
0280       * This method is used to return the standard asset account
0281       * @return MyMoneyAccount asset account(group)
0282       */
0283     MyMoneyAccount asset() const;
0284 
0285     /**
0286       * This method is used to return the standard expense account
0287       * @return MyMoneyAccount expense account(group)
0288       */
0289     MyMoneyAccount expense() const;
0290 
0291     /**
0292       * This method is used to return the standard income account
0293       * @return MyMoneyAccount income account(group)
0294       */
0295     MyMoneyAccount income() const;
0296 
0297     /**
0298       * This method is used to return the standard equity account
0299       * @return MyMoneyAccount equity account(group)
0300       */
0301     MyMoneyAccount equity() const;
0302 
0303     /**
0304       * This method returns the account information for the opening
0305       * balances account for the given @p security. If the respective
0306       * account does not exist, it will be created. The name is constructed
0307       * using MyMoneyFile::openingBalancesPrefix() and appending " (xxx)" in
0308       * case the @p security is not the baseCurrency(). The account created
0309       * will be a sub-account of the standard equity account provided by equity().
0310       *
0311       * @param security Security for which the account is searched
0312       *
0313       * @return The opening balance account
0314       *
0315       * @note No notifications will be sent!
0316       */
0317     MyMoneyAccount openingBalanceAccount(const MyMoneySecurity& security);
0318 
0319     /**
0320       * This method is essentially the same as the above, except it works on
0321       * const objects.  If there is no opening balance account, this method
0322       * WILL NOT create one.  Instead it will thrown an exception.
0323       *
0324       * @param security Security for which the account is searched
0325       *
0326       * @return The opening balance account
0327       *
0328       * @note No notifications will be sent!
0329       */
0330     MyMoneyAccount openingBalanceAccount(const MyMoneySecurity& security) const;
0331 
0332     /**
0333       * Create an opening balance transaction for the account @p acc
0334       * with a value of @p balance. If the corresponding opening balance account
0335       * for the account's currency does not exist it will be created. If it exists
0336       * and it's opening date is later than the opening date of @p acc,
0337       * the opening date of the opening balances account will be adjusted to the
0338       * one of @p acc.
0339       *
0340       * @param acc reference to account for which the opening balance transaction
0341       *            should be created
0342       * @param balance reference to the value of the opening balance transaction
0343       *
0344       * @returns The created MyMoneyTransaction object. In case no transaction has been
0345       *          created, the id of the object is empty.
0346       */
0347     MyMoneyTransaction createOpeningBalanceTransaction(const MyMoneyAccount& acc, const MyMoneyMoney& balance);
0348 
0349     /**
0350       * Retrieve the opening balance transaction for the account @p acc.
0351       * If there is no opening balance transaction, QString() will be returned.
0352       *
0353       * @param acc reference to account for which the opening balance transaction
0354       *            should be retrieved
0355       * @return QString id for the transaction, or QString() if no transaction exists
0356       */
0357     QString openingBalanceTransaction(const MyMoneyAccount& acc) const;
0358 
0359     /**
0360       * This method returns an indicator if the MyMoneyFile object has been
0361       * changed after it has last been saved to permanent storage.
0362       *
0363       * @return true if changed, false if not
0364       */
0365     bool dirty() const;
0366 
0367     /**
0368       * This method is used to force the attached storage object to
0369       * be dirty. This is used by the application to re-set the dirty
0370       * flag after a failed upload to a server when the save operation
0371       * to a local temp file was OK.
0372       */
0373     void setDirty() const;
0374 
0375     /**
0376       * Adds an institution to the file-global institution pool. A
0377       * respective institution-ID will be generated for this object.
0378       * The ID is stored as QString in the object passed as argument.
0379       *
0380       * An exception will be thrown upon error conditions.
0381 
0382       * @param institution The complete institution information in a
0383       *        MyMoneyInstitution object
0384       */
0385     void addInstitution(MyMoneyInstitution& institution);
0386 
0387     /**
0388       * Modifies an already existing institution in the file global
0389       * institution pool.
0390       *
0391       * An exception will be thrown upon error conditions.
0392       *
0393       * @param institution The complete new institution information
0394       */
0395     void modifyInstitution(const MyMoneyInstitution& institution);
0396 
0397     /**
0398       * Deletes an existing institution from the file global institution pool
0399       * Also modifies the accounts that reference this institution as
0400       * their institution.
0401       *
0402       * An exception will be thrown upon error conditions.
0403       *
0404       * @param institution institution to be deleted.
0405       */
0406     void removeInstitution(const MyMoneyInstitution& institution);
0407 
0408     void createAccount(MyMoneyAccount& newAccount, MyMoneyAccount& parentAccount, MyMoneyAccount& brokerageAccount, MyMoneyMoney openingBal);
0409     /**
0410       * Adds an account to the file-global account pool. A respective
0411       * account-ID will be generated within this record. The modified
0412       * members of @a account will be updated.
0413       *
0414       * A few parameters of the account to be added are checked against
0415       * the following conditions. If they do not match, an exception is
0416       * thrown.
0417       *
0418       * An account must match the following conditions:
0419       *
0420       *   a) the account must have a name with length > 0
0421       *   b) the account must not have an id assigned
0422       *   c) the transaction list must be empty
0423       *   d) the account must not have any sub-ordinate accounts
0424       *   e) the account must have no parent account
0425       *   f) the account must not have any reference to a MyMoneyFile object
0426       *
0427       * An exception will be thrown upon error conditions.
0428       *
0429       * @param account The complete account information in a MyMoneyAccount object
0430       * @param parent  The complete account information of the parent account
0431       */
0432     void addAccount(MyMoneyAccount& account, MyMoneyAccount& parent);
0433 
0434     /**
0435       * Modifies an already existing account in the file global account pool.
0436       *
0437       * An exception will be thrown upon error conditions.
0438       *
0439       * @param account reference to the new account information
0440       */
0441     void modifyAccount(const MyMoneyAccount& account);
0442 
0443     /**
0444       * This method re-parents an existing account
0445       *
0446       * An exception will be thrown upon error conditions.
0447       *
0448       * @param account MyMoneyAccount reference to account to be re-parented
0449       * @param parent  MyMoneyAccount reference to new parent account
0450       */
0451     void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent);
0452 
0453     /**
0454       * moves splits from one account to another
0455       *
0456       * @param oldAccount id of the current account
0457       * @param newAccount if of the new account
0458       *
0459       * @return the number of modified splits
0460       */
0461     unsigned int moveSplits(const QString& oldAccount, const QString& newAccount);
0462 
0463     /**
0464       * This method is used to determine, if the account with the
0465       * given ID is referenced by any split in m_transactionList.
0466       *
0467       * @param id id of the account to be checked for
0468       * @return true if account is referenced, false otherwise
0469       */
0470     bool hasActiveSplits(const QString& id) const;
0471 
0472     /**
0473       * This method is used to check whether a given
0474       * account id references one of the standard accounts or not.
0475       *
0476       * An exception will be thrown upon error conditions.
0477       *
0478       * @param id account id
0479       * @return true if account-id is one of the standards, false otherwise
0480       */
0481     bool isStandardAccount(const QString& id) const;
0482 
0483     /**
0484       * Returns @a true, if transaction @p t is a transfer transaction.
0485       * A transfer transaction has two splits, both referencing either
0486       * an asset, a liability or an equity account.
0487       */
0488     bool isTransfer(const MyMoneyTransaction& t) const;
0489 
0490     /**
0491       * This method is used to set the name for the specified standard account
0492       * within the storage area. An exception will be thrown, if an error
0493       * occurs
0494       *
0495       * @param id QString reference to one of the standard accounts.
0496       * @param name QString reference to the name to be set
0497       *
0498       */
0499     void setAccountName(const QString& id, const QString& name) const;
0500 
0501     /**
0502       * Deletes an existing account from the file global account pool
0503       * This method only allows to remove accounts that are not
0504       * referenced by any split. Use moveSplits() to move splits
0505       * to another account. An exception is thrown in case of a
0506       * problem.
0507       *
0508       * @param account reference to the account to be deleted.
0509       */
0510     void removeAccount(const MyMoneyAccount& account);
0511 
0512     /**
0513       * Deletes existing accounts and their subaccounts recursively
0514       * from the global account pool.
0515       * This method expects that all accounts and their subaccounts
0516       * are no longer assigned to any transactions or splits.
0517       * An exception is thrown in case of a problem deleting an account.
0518       *
0519       * The optional parameter level is used to keep track of the recursion level.
0520       * If the recursion level exceeds 100 (some arbitrary number which seems a good
0521       * maximum), an exception is thrown.
0522       *
0523       * @param account_list Reference to a list of account IDs to be deleted.
0524       * @param level Parameter to keep track of recursion level (do not pass a value here).
0525       */
0526     void removeAccountList(const QStringList& account_list, unsigned int level = 0);
0527 
0528     /**
0529       * This member function checks all accounts identified by account_list
0530       * and their subaccounts whether they are assigned to transactions/splits or not.
0531       * The function calls itself recursively with the list of sub-accounts of
0532       * the currently processed account.
0533       *
0534       * The optional parameter level is used to keep track of the recursion level.
0535       * If the recursion level exceeds 100 (some arbitrary number which seems a good
0536       * maximum), an exception is thrown.
0537       *
0538       * @param account_list  A QStringList with account IDs that need to be checked.
0539       * @param level         (optional) Optional parameter to indicate recursion level.
0540       * @return              Returns 'false' if at least one account has been found that
0541       *                      is still referenced by a transaction.
0542       */
0543     bool hasOnlyUnusedAccounts(const QStringList& account_list, unsigned int level = 0);
0544 
0545     /**
0546       * Adds a transaction to the file-global transaction pool. A respective
0547       * transaction-ID will be generated for this object. The ID is stored
0548       * as QString in the object passed as argument.
0549       * Splits must reference valid accounts and valid payees. The payee
0550       * id can be empty.
0551       *
0552       * An exception will be thrown upon error conditions.
0553       *
0554       * @param transaction reference to the transaction
0555       */
0556     void addTransaction(MyMoneyTransaction& transaction);
0557 
0558     /**
0559       * This method is used to update a specific transaction in the
0560       * transaction pool of the MyMoneyFile object.
0561       * Splits must reference valid accounts and valid payees. The payee
0562       * id can be empty.
0563       *
0564       * An exception will be thrown upon error conditions.
0565       *
0566       * @param transaction reference to transaction to be changed
0567       */
0568     void modifyTransaction(const MyMoneyTransaction& transaction);
0569 
0570     /**
0571       * This method is used to extract a transaction from the file global
0572       * transaction pool through an id. In case of an invalid id, an
0573       * exception will be thrown.
0574       *
0575       * @param id id of transaction as QString.
0576       * @return reference to the requested transaction
0577       */
0578     MyMoneyTransaction transaction(const QString& id) const;
0579 
0580     /**
0581       * This method is used to extract a transaction from the file global
0582       * transaction pool through an index into an account.
0583       *
0584       * @param account id of the account as QString
0585       * @param idx number of transaction in this account
0586       * @return reference to MyMoneyTransaction object
0587       */
0588     MyMoneyTransaction transaction(const QString& account, const int idx) const;
0589 
0590     /**
0591       * This method is used to pull a list of transactions from the file
0592       * global transaction pool. It returns all those transactions
0593       * that match the filter passed as argument. If the filter is empty,
0594       * the whole journal will be returned.
0595       * The list returned is sorted according to the transactions posting date.
0596       * If more than one transaction exists for the same date, the order among
0597       * them is undefined.
0598       *
0599       * @param filter MyMoneyTransactionFilter object with the match criteria
0600       *
0601       * @return set of transactions in form of a QList<MyMoneyTransaction>
0602       */
0603     QList<MyMoneyTransaction> transactionList(MyMoneyTransactionFilter& filter) const;
0604 
0605     void transactionList(QList<MyMoneyTransaction>& list, MyMoneyTransactionFilter& filter) const;
0606 
0607     void transactionList(QList<QPair<MyMoneyTransaction, MyMoneySplit> >& list, MyMoneyTransactionFilter& filter) const;
0608 
0609     /**
0610       * This method is used to remove a transaction from the transaction
0611       * pool (journal).
0612       *
0613       * @param transaction const reference to transaction to be deleted
0614       */
0615     void removeTransaction(const MyMoneyTransaction& transaction);
0616 
0617     /**
0618       * This method is used to return the actual balance of an account
0619       * without it's sub-ordinate accounts. If a @p date is presented,
0620       * the balance at the beginning of this date (not including any
0621       * transaction on this date) is returned. Otherwise all recorded
0622       * transactions are included in the balance.
0623       *
0624       * @param id id of the account in question
0625       * @param date return balance for specific date (default = QDate())
0626       * @return balance of the account as MyMoneyMoney object
0627       */
0628     MyMoneyMoney balance(const QString& id, const QDate& date) const;
0629     MyMoneyMoney balance(const QString& id) const;
0630 
0631     /**
0632       * This method is used to return the cleared balance of an account
0633       * without it's sub-ordinate accounts for a specific date. All
0634       * recorded  transactions are included in the balance.
0635       * This method is used by the reconciliation functionality
0636       *
0637       * @param id id of the account in question
0638       * @param date return cleared balance for specific date
0639       * @return balance of the account as MyMoneyMoney object
0640       */
0641     MyMoneyMoney clearedBalance(const QString& id, const QDate& date) const;
0642 
0643 
0644     /**
0645       * This method is used to return the actual balance of an account
0646       * including it's sub-ordinate accounts. If a @p date is presented,
0647       * the balance at the beginning of this date (not including any
0648       * transaction on this date) is returned. Otherwise all recorded
0649       * transactions are included in the balance.
0650       *
0651       * @param id id of the account in question
0652       * @param date return balance for specific date (default = QDate())
0653       * @return balance of the account as MyMoneyMoney object
0654       */
0655     MyMoneyMoney totalBalance(const QString& id, const QDate& date) const;
0656     MyMoneyMoney totalBalance(const QString& id) const;
0657 
0658     /**
0659       * This method returns the number of transactions currently known to file
0660       * in the range 0..MAXUINT
0661       *
0662       * @param account QString reference to account id. If account is empty
0663       +                all transactions (the journal) will be counted. If account
0664       *                is not empty it returns the number of transactions
0665       *                that have splits in this account.
0666       *
0667       * @return number of transactions in journal/account
0668       */
0669     unsigned int transactionCount(const QString& account) const;
0670     unsigned int transactionCount() const;
0671 
0672     /**
0673       * This method returns a QMap filled with the number of transactions
0674       * per account. The account id serves as index into the map. If one
0675       * needs to have all transactionCounts() for many accounts, this method
0676       * is faster than calling transactionCount(const QString& account) many
0677       * times.
0678       *
0679       * @return QMap with numbers of transactions per account
0680       */
0681     QMap<QString, unsigned long> transactionCountMap() const;
0682 
0683     /**
0684       * This method returns the number of institutions currently known to file
0685       * in the range 0..MAXUINT
0686       *
0687       * @return number of institutions known to file
0688       */
0689     unsigned int institutionCount() const;
0690 
0691     /**
0692       * This method returns the number of accounts currently known to file
0693       * in the range 0..MAXUINT
0694       *
0695       * @return number of accounts currently known inside a MyMoneyFile object
0696       */
0697     unsigned int accountCount() const;
0698 
0699     /**
0700       * Returns the institution of a given ID
0701       *
0702       * @param id id of the institution to locate
0703       * @return MyMoneyInstitution object filled with data. If the institution
0704       *         could not be found, an exception will be thrown
0705       */
0706     MyMoneyInstitution institution(const QString& id) const;
0707 
0708     /**
0709       * This method returns a list of the institutions
0710       * inside a MyMoneyFile object. This is a convenience method
0711       * to the one above
0712       *
0713       * @return QList containing the institution objects
0714       */
0715     QList<MyMoneyInstitution> institutionList() const;
0716 
0717     /**
0718       * Returns the account addressed by its id.
0719       *
0720       * @param id id of the account to locate.
0721       * @return MyMoneyAccount object carrying the @p id. An exception is thrown
0722       *         if the id is unknown
0723       */
0724     MyMoneyAccount account(const QString& id) const;
0725 
0726     /**
0727      * Returns the account addressed by its name.
0728      *
0729      * @param name  name of the account to locate.
0730      * @return First MyMoneyAccount object found carrying the @p name.
0731      * An empty MyMoneyAccount object will be returned if the name is not found.
0732      */
0733     MyMoneyAccount accountByName(const QString& name) const;
0734 
0735     /**
0736      * Returns the sub-account addressed by its name.
0737      *
0738      * @param acc account to search in
0739      * @param name  name of the account to locate.
0740      * @return First MyMoneyAccount object found carrying the @p name.
0741      * An empty MyMoneyAccount object will be returned if the name is not found.
0742      */
0743     MyMoneyAccount subAccountByName(const MyMoneyAccount& account, const QString& name) const;
0744 
0745     /**
0746       * This method returns a list of accounts inside a MyMoneyFile object.
0747       * An optional parameter is a list of id's. If this list is empty (the default)
0748       * the returned list contains all accounts, otherwise only those referenced
0749       * in the id-list.
0750       *
0751       * @param list reference to QList receiving the account objects
0752       * @param idlist QStringList of account ids of those accounts that
0753       *        should be returned. If this list is empty, all accounts
0754       *        currently known will be returned.
0755       *
0756       * @param recursive if @p true, then recurse in all found accounts. The default is @p false
0757       */
0758     void accountList(QList<MyMoneyAccount>& list, const QStringList& idlist = QStringList(), const bool recursive = false) const;
0759 
0760     /**
0761       * This method is used to convert an account id to a string representation
0762       * of the names which can be used as a category description. If the account
0763       * is part of a hierarchy, the category name will be the concatenation of
0764       * the single account names separated by MyMoneyFile::AccountSeparator.
0765       *
0766       * @param accountId QString reference of the account's id
0767       * @param includeStandardAccounts if true, the standard top account will be part
0768       *                   of the name, otherwise it will not be included (default is @c false)
0769       *
0770       * @return QString of the constructed name.
0771       */
0772     QString accountToCategory(const QString& accountId, bool includeStandardAccounts = false) const;
0773 
0774     /**
0775       * This method is used to convert a string representing a category to
0776       * an account id. A category can be the concatenation of multiple accounts
0777       * representing a hierarchy of accounts. They have to be separated by
0778       * MyMoneyFile::AccountSeparator.
0779       *
0780       * @param category const reference to QString containing the category
0781       * @param type account type if a specific type is required (defaults to Unknown)
0782       *
0783       * @return QString of the corresponding account. If account was not found
0784       *         the return value will be an empty string.
0785       */
0786     QString categoryToAccount(const QString& category, eMyMoney::Account::Type type) const;
0787     QString categoryToAccount(const QString& category) const;
0788 
0789     /**
0790       * This method is used to convert a string representing an asset or
0791       * liability account to an account id. An account name can be the
0792       * concatenation of multiple accounts representing a hierarchy of
0793       * accounts. They have to be separated by MyMoneyFile::AccountSeparator.
0794       *
0795       * @param name const reference to QString containing the account name
0796       *
0797       * @return QString of the corresponding account. If account was not found
0798       *         the return value will be an empty string.
0799       */
0800     QString nameToAccount(const QString& name) const;
0801 
0802     /**
0803       * This method is used to extract the parent part of an account hierarchy
0804       * name who's parts are separated by MyMoneyFile::AccountSeparator.
0805       *
0806       * @param name full account name
0807       * @return parent name (full account name excluding the last part)
0808       */
0809     QString parentName(const QString& name) const;
0810 
0811     /**
0812       * This method is used to create a new payee
0813       *
0814       * An exception will be thrown upon error conditions
0815       *
0816       * @param payee MyMoneyPayee reference to payee information
0817       */
0818     void addPayee(MyMoneyPayee& payee);
0819 
0820     /**
0821       * This method is used to retrieve information about a payee
0822       * An exception will be thrown upon error conditions.
0823       *
0824       * @param id QString reference to id of payee
0825       *
0826       * @return MyMoneyPayee object of payee
0827       */
0828     MyMoneyPayee payee(const QString& id) const;
0829 
0830     /**
0831       * This method is used to retrieve the id to a corresponding
0832       * name of a payee/receiver.
0833       * An exception will be thrown upon error conditions.
0834       *
0835       * @param payee QString reference to name of payee
0836       *
0837       * @return MyMoneyPayee object of payee
0838       */
0839     MyMoneyPayee payeeByName(const QString& payee) const;
0840 
0841     /**
0842       * This method is used to modify an existing payee
0843       *
0844       * An exception will be thrown upon error conditions
0845       *
0846       * @param payee MyMoneyPayee reference to payee information
0847       */
0848     void modifyPayee(const MyMoneyPayee& payee);
0849 
0850     /**
0851       * This method is used to remove an existing payee.
0852       * An error condition occurs, if the payee is still referenced
0853       * by a split.
0854       *
0855       * An exception will be thrown upon error conditions
0856       *
0857       * @param payee MyMoneyPayee reference to payee information
0858       */
0859     void removePayee(const MyMoneyPayee& payee);
0860 
0861     /**
0862       * This method returns a list of the payees
0863       * inside a MyMoneyStorage object
0864       *
0865       * @return QList<MyMoneyPayee> containing the payee information
0866       */
0867     QList<MyMoneyPayee> payeeList() const;
0868 
0869     /**
0870       * This method is used to create a new tag
0871       *
0872       * An exception will be thrown upon error conditions
0873       *
0874       * @param tag MyMoneyTag reference to tag information
0875       */
0876     void addTag(MyMoneyTag& tag);
0877 
0878     /**
0879       * This method is used to retrieve information about a tag
0880       * An exception will be thrown upon error conditions.
0881       *
0882       * @param id QString reference to id of tag
0883       *
0884       * @return MyMoneyTag object of tag
0885       */
0886     MyMoneyTag tag(const QString& id) const;
0887 
0888     /**
0889       * This method is used to retrieve the id to a corresponding
0890       * name of a tag.
0891       * An exception will be thrown upon error conditions.
0892       *
0893       * @param tag QString reference to name of tag
0894       *
0895       * @return MyMoneyTag object of tag
0896       */
0897     MyMoneyTag tagByName(const QString& tag) const;
0898 
0899     /**
0900       * This method is used to modify an existing tag
0901       *
0902       * An exception will be thrown upon error conditions
0903       *
0904       * @param tag MyMoneyTag reference to tag information
0905       */
0906     void modifyTag(const MyMoneyTag& tag);
0907 
0908     /**
0909       * This method is used to remove an existing tag.
0910       * An error condition occurs, if the tag is still referenced
0911       * by a split.
0912       *
0913       * An exception will be thrown upon error conditions
0914       *
0915       * @param tag MyMoneyTag reference to tag information
0916       */
0917     void removeTag(const MyMoneyTag& tag);
0918 
0919     /**
0920       * This method returns a list of the tags
0921       * inside a MyMoneyStorage object
0922       *
0923       * @return QList<MyMoneyTag> containing the tag information
0924       */
0925     QList<MyMoneyTag> tagList() const;
0926 
0927     /**
0928       * This method returns a list of the cost centers
0929       * inside a MyMoneyStorage object
0930       *
0931       * @return QList<MyMoneyCostCenter> containing the cost center information
0932       */
0933     void costCenterList(QList< MyMoneyCostCenter >& list) const;
0934 
0935     /**
0936       * This method is used to extract a value from the storage's
0937       * KeyValueContainer. For details see MyMoneyKeyValueContainer::value().
0938       * @note Do not use this method to return the value of the key @p kmm-id. Use
0939       * storageId() instead.
0940       *
0941       * @param key const reference to QString containing the key
0942       * @return QString containing the value
0943       */
0944     QString value(const QString& key) const;
0945 
0946     /**
0947       * This method is used to set a value in the storage's
0948       * KeyValueContainer. For details see MyMoneyKeyValueContainer::setValue().
0949       *
0950       * @param key const reference to QString containing the key
0951       * @param val const reference to QString containing the value
0952       *
0953       * @note Keys starting with the leading @p kmm- are reserved for internal use
0954       *       by the MyMoneyFile object.
0955       */
0956     void setValue(const QString& key, const QString& val);
0957 
0958     /**
0959      * This method returns the unique id of the attached storage object.
0960      * In case the storage object does not have an id yet, a new one will be
0961      * assigned.
0962      *
0963      * @return QString containing the value
0964      *
0965      * An exception is thrown if no storage object is attached.
0966      */
0967     QString storageId();
0968 
0969     /**
0970       * This method is used to delete a key-value-pair from the
0971       * storage's KeyValueContainer identified by the parameter
0972       * @p key. For details see MyMoneyKeyValueContainer::deletePair().
0973       *
0974       * @param key const reference to QString containing the key
0975       */
0976     void deletePair(const QString& key);
0977 
0978     /**
0979       * This method is used to add a scheduled transaction to the engine.
0980       * It must be sure, that the id of the object is not filled. When the
0981       * method returns to the caller, the id will be filled with the
0982       * newly created object id value.
0983       *
0984       * An exception will be thrown upon erroneous situations.
0985       *
0986       * @param sched reference to the MyMoneySchedule object
0987       */
0988     void addSchedule(MyMoneySchedule& sched);
0989 
0990     /**
0991       * This method is used to modify an existing MyMoneySchedule
0992       * object. Therefor, the id attribute of the object must be set.
0993       *
0994       * An exception will be thrown upon erroneous situations.
0995       *
0996       * @param sched const reference to the MyMoneySchedule object to be updated
0997       */
0998     void modifySchedule(const MyMoneySchedule& sched);
0999 
1000     /**
1001       * This method is used to remove an existing MyMoneySchedule object
1002       * from the engine. The id attribute of the object must be set.
1003       *
1004       * An exception will be thrown upon erroneous situations.
1005       *
1006       * @param sched const reference to the MyMoneySchedule object to be updated
1007       */
1008     void removeSchedule(const MyMoneySchedule& sched);
1009 
1010     /**
1011       * This method is used to retrieve a single MyMoneySchedule object.
1012       * The id of the object must be supplied in the parameter @p id.
1013       *
1014       * An exception will be thrown upon erroneous situations.
1015       *
1016       * @param id QString containing the id of the MyMoneySchedule object
1017       * @return MyMoneySchedule object
1018       */
1019     MyMoneySchedule schedule(const QString& id) const;
1020 
1021     /**
1022       * This method is used to extract a list of scheduled transactions
1023       * according to the filter criteria passed as arguments.
1024       *
1025       * @param accountId only search for scheduled transactions that reference
1026       *                  account @p accountId. If accountId is the empty string,
1027       *                  this filter is off. Default is @p QString().
1028       * @param type      only schedules of type @p type are searched for.
1029       *                  See eMyMoney::Schedule::Type for details.
1030       *                  Default is eMyMoney::Schedule::Type::Any
1031       * @param occurrence only schedules of occurrence type @p occurrence are searched for.
1032       *                  See eMyMoney::Schedule::Occurrence for details.
1033       *                  Default is eMyMoney::Schedule::Occurrence::Any
1034       * @param paymentType only schedules of payment method @p paymentType
1035       *                  are searched for.
1036       *                  See eMyMoney::Schedule::PaymentType for details.
1037       *                  Default is eMyMoney::Schedule::PaymentType::Any
1038       * @param startDate only schedules with payment dates after @p startDate
1039       *                  are searched for. Default is all dates (QDate()).
1040       * @param endDate   only schedules with payment dates ending prior to @p endDate
1041       *                  are searched for. Default is all dates (QDate()).
1042       * @param overdue   if true, only those schedules that are overdue are
1043       *                  searched for. Default is false (all schedules will be returned).
1044       *
1045       * @return const QList<MyMoneySchedule> list of schedule objects.
1046       */
1047     QList<MyMoneySchedule> scheduleList(const QString& accountId,
1048                                         const eMyMoney::Schedule::Type type,
1049                                         const eMyMoney::Schedule::Occurrence occurrence,
1050                                         const eMyMoney::Schedule::PaymentType paymentType,
1051                                         const QDate& startDate,
1052                                         const QDate& endDate,
1053                                         const bool overdue) const;
1054     QList<MyMoneySchedule> scheduleList(const QString& accountId) const;
1055     QList<MyMoneySchedule> scheduleList() const;
1056 
1057     QStringList consistencyCheck();
1058 
1059     /**
1060       * MyMoneyFile::openingBalancesPrefix() is a special string used
1061       * to generate the name for opening balances accounts. See openingBalanceAccount()
1062       * for details.
1063       */
1064     static QString openingBalancesPrefix();
1065 
1066     /**
1067       * MyMoneyFile::AccountSeparator is used as the separator
1068       * between account names to form a hierarchy.
1069       */
1070     static const QString AccountSeparator;
1071 
1072     /**
1073       * createCategory creates a category from a text name.
1074       *
1075       * The whole account hierarchy is created if it does not
1076       * already exist.  e.g if name = Bills:Credit Card and
1077       * base = expense(), Bills will first be checked to see if
1078       * it exists and created if not.  Credit Card will then
1079       * be created with Bills as it's parent.  The Credit Card account
1080       * will have it's id returned.
1081       *
1082       * @param base The base account (expense or income)
1083       * @param name The category to create
1084       *
1085       * @return The category account id or empty on error.
1086       *
1087       * @exception An exception will be thrown, if @p base is not equal
1088       *            expense() or income().
1089       **/
1090     QString createCategory(const MyMoneyAccount& base, const QString& name);
1091 
1092     /**
1093       * This method is used to get the account id of the split for
1094       * a transaction from the text found in the QIF $ or L record.
1095       * If an account with the name is not found, the user is asked
1096       * if it should be created.
1097       *
1098       * @param name name of account as found in the QIF file
1099       * @param value value found in the T record
1100       * @param value2 value found in the $ record for split transactions
1101       *
1102       * @return id of the account for the split. If no name is specified
1103       *            or the account was not found and not created the
1104       *            return value will be "".
1105       */
1106     QString checkCategory(const QString& name, const MyMoneyMoney& value, const MyMoneyMoney& value2);
1107 
1108     /**
1109       * This method is used to add a new security object to the engine.
1110       * The ID of the object is the trading symbol, so there is no need for an additional
1111       * ID since the symbol is guaranteed to be unique.
1112       *
1113       * An exception will be thrown upon erroneous situations.
1114       *
1115       * @param security reference to the MyMoneySecurity object
1116       */
1117     void addSecurity(MyMoneySecurity& security);
1118 
1119     /**
1120       * This method is used to modify an existing MyMoneySchedule
1121       * object.
1122       *
1123       * An exception will be thrown upon erroneous situations.
1124       *
1125       * @param security reference to the MyMoneySecurity object to be updated
1126       */
1127     void modifySecurity(const MyMoneySecurity& security);
1128 
1129     /**
1130       * This method is used to remove an existing MyMoneySecurity object
1131       * from the engine.
1132       *
1133       * An exception will be thrown upon erroneous situations.
1134       *
1135       * @param security reference to the MyMoneySecurity object to be removed
1136       */
1137     void removeSecurity(const MyMoneySecurity& security);
1138 
1139     /**
1140       * This method is used to retrieve a single MyMoneySecurity object.
1141       * The id of the object must be supplied in the parameter @p id.
1142       * If no security with the given id is found, then a corresponding
1143       * currency is searched. If @p id is empty, the baseCurrency() is returned.
1144       *
1145       * An exception will be thrown upon erroneous situations.
1146       *
1147       * @param id QString containing the id of the MyMoneySecurity object
1148       * @return MyMoneySecurity object
1149       */
1150     MyMoneySecurity security(const QString& id) const;
1151 
1152     /**
1153       * This method is used to retrieve a list of all MyMoneySecurity objects.
1154       */
1155     QList<MyMoneySecurity> securityList() const;
1156 
1157     /**
1158       * This method is used to add a new currency object to the engine.
1159       * The ID of the object is the trading symbol, so there is no need for an additional
1160       * ID since the symbol is guaranteed to be unique.
1161       *
1162       * An exception will be thrown upon erroneous situations.
1163       *
1164       * @param currency reference to the MyMoneySecurity object
1165       */
1166     void addCurrency(const MyMoneySecurity& currency);
1167 
1168     /**
1169       * This method is used to modify an existing MyMoneySecurity
1170       * object.
1171       *
1172       * An exception will be thrown upon erroneous situations.
1173       *
1174       * @param currency reference to the MyMoneySecurity object
1175       */
1176     void modifyCurrency(const MyMoneySecurity& currency);
1177 
1178     /**
1179       * This method is used to remove an existing MyMoneySecurity object
1180       * from the engine.
1181       *
1182       * An exception will be thrown upon erroneous situations.
1183       *
1184       * @param currency reference to the MyMoneySecurity object
1185       */
1186     void removeCurrency(const MyMoneySecurity& currency);
1187 
1188     /**
1189       * This method is used to retrieve a single MyMoneySecurity object.
1190       * The id of the object must be supplied in the parameter @p id.
1191       * If @p id is empty, this method returns baseCurrency(). In case
1192       * no currency is found, @p id is searched in the loaded set of securities.
1193       *
1194       * An exception will be thrown upon erroneous situations.
1195       *
1196       * @param id QString containing the id of the MyMoneySchedule object
1197       * @return MyMoneySchedule object
1198       */
1199     MyMoneySecurity currency(const QString& id) const;
1200 
1201     /**
1202       * This method is used to retrieve the map of ancient currencies (together with their last prices)
1203       * known to the engine.
1204       *
1205       * An exception will be thrown upon erroneous situations.
1206       *
1207       * @return QMap of all MyMoneySecurity and MyMoneyPrice objects.
1208       */
1209     QMap<MyMoneySecurity, MyMoneyPrice> ancientCurrencies() const;
1210 
1211     /**
1212       * This method is used to retrieve the list of available currencies
1213       * known to the engine.
1214       *
1215       * An exception will be thrown upon erroneous situations.
1216       *
1217       * @return QList of all MyMoneySecurity objects.
1218       */
1219     QList<MyMoneySecurity> availableCurrencyList() const;
1220 
1221     /**
1222       * This method is used to retrieve the list of stored currencies
1223       * known to the engine.
1224       *
1225       * An exception will be thrown upon erroneous situations.
1226       *
1227       * @return QList of all MyMoneySecurity objects.
1228       */
1229     QList<MyMoneySecurity> currencyList() const;
1230 
1231     /**
1232       * This method retrieves a MyMoneySecurity object representing
1233       * the selected base currency. If the base currency is not
1234       * selected (e.g. due to a previous call to setBaseCurrency())
1235       * a standard MyMoneySecurity object will be returned. See
1236       * MyMoneySecurity() for details.
1237       *
1238       * An exception will be thrown upon erroneous situations.
1239       *
1240       * @return MyMoneySecurity describing base currency
1241       */
1242     MyMoneySecurity baseCurrency() const;
1243 
1244     /**
1245       * This method returns the foreign currency of the given two
1246       * currency ids. If second is the base currency id then @a first
1247       * is returned otherwise @a second is returned.
1248       */
1249     QString foreignCurrency(const QString& first, const QString& second) const;
1250 
1251     /**
1252       * This method allows to select the base currency. It does
1253       * not perform any changes to the data in the engine. It merely
1254       * stores a reference to the base currency. The currency
1255       * passed as argument must exist in the engine.
1256       *
1257       * An exception will be thrown upon erroneous situations.
1258       *
1259       * @param currency
1260       */
1261     void setBaseCurrency(const MyMoneySecurity& currency);
1262 
1263     /**
1264       * This method adds/replaces a price to/from the price list
1265       */
1266     void addPrice(const MyMoneyPrice& price);
1267 
1268     /**
1269       * This method removes a price from the price list
1270       */
1271     void removePrice(const MyMoneyPrice& price);
1272 
1273     /**
1274       * This method is used to retrieve a price for a specific security
1275       * on a specific date. If there is no price for this date, the last
1276       * known price for this currency is used. If no price information
1277       * is available, 1.0 will be returned as price.
1278       *
1279       * @param fromId the id of the currency in question
1280       * @param toId the id of the currency to convert to (if empty, baseCurrency)
1281       * @param date the date for which the price should be returned (default = today)
1282       * @param exactDate if true, entry for date must exist, if false any price information
1283       *                  with a date less or equal to @p date will be returned
1284       *
1285       * @return price found as MyMoneyPrice object
1286       * @note This throws an exception when the base currency is not set and toId is empty
1287       */
1288     MyMoneyPrice price(const QString& fromId, const QString& toId, const QDate& date, const bool exactDate = false) const;
1289     MyMoneyPrice price(const QString& fromId, const QString& toId) const;
1290     MyMoneyPrice price(const QString& fromId) const;
1291 
1292     /**
1293       * This method returns a list of all prices.
1294       *
1295       * @return MyMoneyPriceList of all MyMoneyPrice objects.
1296       */
1297     MyMoneyPriceList priceList() const;
1298 
1299     /**
1300       * This method allows to interrogate the engine, if a known account
1301       * with id @p id has a subaccount with the name @p name.
1302       *
1303       * @param id id of the account to look at
1304       * @param name account name that needs to be searched force
1305       * @retval true account with name @p name found as subaccounts
1306       * @retval false no subaccount present with that name
1307       */
1308     bool hasAccount(const QString& id, const QString& name) const;
1309 
1310     /**
1311       * This method is used to retrieve the list of all reports
1312       * known to the engine.
1313       *
1314       * An exception will be thrown upon erroneous situations.
1315       *
1316       * @return QList of all MyMoneyReport objects.
1317       */
1318     QList<MyMoneyReport> reportList() const;
1319 
1320     /**
1321       * Adds a report to the file-global institution pool. A
1322       * respective report-ID will be generated for this object.
1323       * The ID is stored as QString in the object passed as argument.
1324       *
1325       * An exception will be thrown upon error conditions.
1326       *
1327       * @param report The complete report information in a
1328       *        MyMoneyReport object
1329       */
1330     void addReport(MyMoneyReport& report);
1331 
1332     /**
1333       * Modifies an already existing report in the file global
1334       * report pool.
1335       *
1336       * An exception will be thrown upon error conditions.
1337       *
1338       * @param report The complete new report information
1339       */
1340     void modifyReport(const MyMoneyReport& report);
1341 
1342     /**
1343       * This method returns the number of reports currently known to file
1344       * in the range 0..MAXUINT
1345       *
1346       * @return number of reports known to file
1347       */
1348     unsigned countReports() const;
1349 
1350     /**
1351       * This method is used to retrieve a single MyMoneyReport object.
1352       * The id of the object must be supplied in the parameter @p id.
1353       *
1354       * An exception will be thrown upon erroneous situations.
1355       *
1356       * @param id QString containing the id of the MyMoneyReport object
1357       * @return MyMoneyReport object
1358       */
1359     MyMoneyReport report(const QString& id) const;
1360 
1361     /**
1362       * This method is used to remove an existing MyMoneyReport object
1363       * from the engine. The id attribute of the object must be set.
1364       *
1365       * An exception will be thrown upon erroneous situations.
1366       *
1367       * @param report const reference to the MyMoneyReport object to be updated
1368       */
1369     void removeReport(const MyMoneyReport& report);
1370 
1371     /**
1372       * This method is used to retrieve the list of all budgets
1373       * known to the engine.
1374       *
1375       * An exception will be thrown upon erroneous situations.
1376       *
1377       * @return QList of all MyMoneyBudget objects.
1378       */
1379     QList<MyMoneyBudget> budgetList() const;
1380 
1381     /**
1382       * Adds a budget to the file-global institution pool. A
1383       * respective budget-ID will be generated for this object.
1384       * The ID is stored as QString in the object passed as argument.
1385       *
1386       * An exception will be thrown upon error conditions.
1387       *
1388       * @param budget The complete budget information in a
1389       *        MyMoneyBudget object
1390       */
1391     void addBudget(MyMoneyBudget &budget);
1392 
1393 
1394     /**
1395       * This method is used to retrieve the id to a corresponding
1396       * name of a budget.
1397       * An exception will be thrown upon error conditions.
1398       *
1399       * @param budget QString reference to name of budget
1400       *
1401       * @return MyMoneyBudget reference to object of budget
1402       */
1403     MyMoneyBudget budgetByName(const QString& budget) const;
1404 
1405 
1406     /**
1407       * Modifies an already existing budget in the file global
1408       * budget pool.
1409       *
1410       * An exception will be thrown upon error conditions.
1411       *
1412       * @param budget The complete new budget information
1413       */
1414     void modifyBudget(const MyMoneyBudget& budget);
1415 
1416     /**
1417       * This method returns the number of budgets currently known to file
1418       * in the range 0..MAXUINT
1419       *
1420       * @return number of budgets known to file
1421       */
1422     unsigned countBudgets() const;
1423 
1424     /**
1425       * This method is used to retrieve a single MyMoneyBudget object.
1426       * The id of the object must be supplied in the parameter @p id.
1427       *
1428       * An exception will be thrown upon erroneous situations.
1429       *
1430       * @param id QString containing the id of the MyMoneyBudget object
1431       * @return MyMoneyBudget object
1432       */
1433     MyMoneyBudget budget(const QString& id) const;
1434 
1435     /**
1436       * This method is used to remove an existing MyMoneyBudget object
1437       * from the engine. The id attribute of the object must be set.
1438       *
1439       * An exception will be thrown upon erroneous situations.
1440       *
1441       * @param budget const reference to the MyMoneyBudget object to be updated
1442       */
1443     void removeBudget(const MyMoneyBudget& budget);
1444 
1445     /**
1446       * This method is used to add a VAT split to a transaction.
1447       *
1448       * @param transaction reference to the transaction
1449       * @param account reference to the account
1450       * @param category reference to the category
1451       * @param amount reference to the amount of the VAT split
1452       *
1453       * @return true if a VAT split has been added
1454       */
1455     bool addVATSplit(MyMoneyTransaction& transaction, const MyMoneyAccount& account, const MyMoneyAccount& category, const MyMoneyMoney& amount) const;
1456 
1457     /**
1458       * This method checks if the @a transaction has two or three splits and
1459       * one references an asset or liability, one references an income or expense and one
1460       * references a tax account. All three accounts must be denominated in the same
1461       * transaction.commodity(). Also, if there is a tax split it must reference the
1462       * same account as the one that is assigned to the income/expense category.
1463       *
1464       * If that all matches, the @a transaction is updated such that the amount
1465       * of the asset/liability is split according to the tax settings.
1466       *
1467       * @param transaction reference to the transaction
1468       */
1469     void updateVAT(MyMoneyTransaction& transaction) const;
1470 
1471     /**
1472       * This method checks, if the given @p object is referenced
1473       * by another engine object.
1474       *
1475       * @param obj const reference to object to be checked
1476       * @param skipCheck QBitArray with eStorage::Reference bits set for which
1477       *                  the check should be skipped
1478       *
1479       * @retval false @p object is not referenced
1480       * @retval true @p institution is referenced
1481       */
1482     bool isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const;
1483     bool isReferenced(const MyMoneyObject& obj) const;
1484 
1485     /**
1486       * Returns true if any of the accounts referenced by the splits
1487       * of transaction @a t is closed.
1488       */
1489     bool referencesClosedAccount(const MyMoneyTransaction& t) const;
1490 
1491     /**
1492       * Returns true if the accounts referenced by the split @a s is closed.
1493       */
1494     bool referencesClosedAccount(const MyMoneySplit& s) const;
1495 
1496     /**
1497       * This method checks if the given check no &p no is used in
1498       * a transaction referencing account &p accId. If  @p accId is empty,
1499       * @p false is returned.
1500       *
1501       * @param accId id of account to checked
1502       * @param no check number to be verified if used or not
1503       * @retval false @p no is not in use
1504       * @retval true @p no is already assigned
1505       */
1506     bool checkNoUsed(const QString& accId, const QString& no) const;
1507 
1508     /**
1509       * This method returns the highest assigned check no for
1510       * account @p accId.
1511       *
1512       * @param accId id of account to be scanned
1513       * @return highest check no. used
1514       */
1515     QString highestCheckNo(const QString& accId) const;
1516 
1517 
1518     /**
1519       * This method checks if there is a transaction
1520       * after the date @p date for account @p accId.
1521       *
1522       * @param accId id of account to be scanned
1523       * @param date date to compare with
1524       * @retval false if there is no transaction after @p date
1525       * @retval true if there is a transaction after @p date
1526       */
1527     bool hasNewerTransaction(const QString& accId, const QDate& date) const;
1528 
1529 
1530     /**
1531       * Clear all internal caches (used internally for performance measurements)
1532       */
1533     void clearCache();
1534 
1535     void forceDataChanged();
1536 
1537     /**
1538       * This returns @p true if file and online balance of a specific
1539       * @p account are matching. Returns false if there is no online balance.
1540       *
1541       * @param account @p account to be checked
1542       * @retval false if @p account has balance mismatch or if there is no online balance.
1543       * @retval true if @p account has matching balances
1544       */
1545     bool hasMatchingOnlineBalance(const MyMoneyAccount& account) const;
1546 
1547     /**
1548       * This returns the number of transactions of a specific reconciliation state @p state of account with id @p accId.
1549       *
1550       * @param accId @p accId is the account id of account to be checked
1551       * @param state @p state reconciliation state
1552       * @return number of transactions with state @p state
1553       */
1554     int countTransactionsWithSpecificReconciliationState(const QString& accId, eMyMoney::TransactionFilter::State state) const;
1555     QMap< QString, QVector<int> > countTransactionsWithSpecificReconciliationState() const;
1556 
1557     /**
1558      * @brief Saves a new onlineJob
1559      * @param job you stay owner of the object (a copy will be created)
1560      */
1561     void addOnlineJob(onlineJob& job);
1562 
1563     /**
1564      * @brief Saves a onlineJob
1565      * @param job you stay owner of the object (a copy will be created)
1566      */
1567     void modifyOnlineJob(const onlineJob job);
1568 
1569     /**
1570      * @brief Returns onlineJob identified by jobId
1571      * @param jobId
1572      * @return
1573      */
1574     onlineJob getOnlineJob(const QString &jobId) const;
1575 
1576     /**
1577      * @brief Returns all onlineJobs
1578      * @return all online jobs, caller gains ownership
1579      */
1580     QList<onlineJob> onlineJobList() const;
1581 
1582     /**
1583      * @brief Returns the number of onlineJobs
1584      */
1585     int countOnlineJobs() const;
1586 
1587     /**
1588      * @brief Remove onlineJob
1589      *
1590      * @note Removing an onlineJob fails if it is locked
1591      */
1592     void removeOnlineJob(const onlineJob& job);
1593 
1594     /**
1595      * @brief Removes multiple onlineJobs by id
1596      *
1597      * @note Removing an onlineJob fails if it is locked
1598      */
1599     void removeOnlineJob(const QStringList onlineJobIds);
1600 
1601 protected:
1602     /**
1603       * This is the constructor for a new empty file description
1604       */
1605     MyMoneyFile();
1606 
1607 Q_SIGNALS:
1608     /**
1609      * This signal is emitted when a transaction has been committed and
1610      * the notifications are about to be sent out.
1611      */
1612     void beginChangeNotification();
1613 
1614     /**
1615      * This signal is emitted when a transaction has been committed and
1616      * all notifications have been sent out.
1617      */
1618     void endChangeNotification();
1619 
1620     /**
1621       * This signal is emitted whenever any data has been changed in the engine
1622       * via any of the methods of this object
1623       */
1624     void dataChanged();
1625 
1626     /**
1627       * This signal is emitted by the engine whenever a new object
1628       * had been added. The data for the new object is contained in
1629       * @a obj.
1630       */
1631     void objectAdded(eMyMoney::File::Object objType, const QString& id);
1632 
1633     /**
1634       * This signal is emitted by the engine whenever an object
1635       * had been removed.
1636       *
1637       * @note: The data contained in @a obj is only for reference
1638       * purposes and should not be used to call any MyMoneyFile
1639       * method anymore as the object is already deleted in the storage
1640       * when the signal is emitted.
1641       */
1642     void objectRemoved(eMyMoney::File::Object objType, const QString& id);
1643 
1644     /**
1645       * This signal is emitted by the engine whenever an object
1646       * had been changed. The new state of the object is contained
1647       * in @a obj.
1648       */
1649     void objectModified(eMyMoney::File::Object objType, const QString& id);
1650 
1651     /**
1652       * This signal is emitted by the engine whenever the balance
1653       * of an account had been changed by adding, modifying or
1654       * removing transactions from the MyMoneyFile object.
1655       */
1656     void balanceChanged(const MyMoneyAccount& acc);
1657 
1658     /**
1659       * This signal is emitted by the engine whenever the value
1660       * of an account had been changed by adding or removing
1661       * prices from the MyMoneyFile object.
1662       */
1663     void valueChanged(const MyMoneyAccount& acc);
1664 
1665 private:
1666     static MyMoneyFile file;
1667 
1668     MyMoneyFile& operator=(MyMoneyFile&); // not allowed for singleton
1669     MyMoneyFile(const MyMoneyFile&);      // not allowed for singleton
1670 
1671     QString locateSubAccount(const MyMoneyAccount& base, const QString& category) const;
1672 
1673     void ensureDefaultCurrency(MyMoneyAccount& acc) const;
1674 
1675     void warningMissingRate(const QString& fromId, const QString& toId) const;
1676 
1677     /**
1678       * This method creates an opening balances account. The name is constructed
1679       * using MyMoneyFile::openingBalancesPrefix() and appending " (xxx)" in
1680       * case the @p security is not the baseCurrency(). The account created
1681       * will be a sub-account of the standard equity account provided by equity().
1682       *
1683       * @param security Security for which the account is searched
1684       */
1685     MyMoneyAccount createOpeningBalanceAccount(const MyMoneySecurity& security);
1686 
1687     MyMoneyAccount openingBalanceAccount_internal(const MyMoneySecurity& security) const;
1688 
1689     /**
1690      * Make sure that the splits value has the precision of the corresponding account
1691      */
1692     void fixSplitPrecision(MyMoneyTransaction& t) const;
1693 
1694 private:
1695     /// \internal d-pointer class.
1696     class Private;
1697     /// \internal d-pointer instance.
1698     Private* const d;
1699 };
1700 
1701 class MyMoneyFileTransactionPrivate;
1702 class KMM_MYMONEY_EXPORT MyMoneyFileTransaction
1703 {
1704     Q_DISABLE_COPY(MyMoneyFileTransaction)
1705 
1706 public:
1707     MyMoneyFileTransaction();
1708     ~MyMoneyFileTransaction();
1709 
1710     /**
1711      * Commit the current transaction.
1712      *
1713      * @warning Make sure not to use any variable that might have been altered by
1714      *          the transaction. Please keep in mind, that changing transactions
1715      *          can also affect account objects. If you still need those variables
1716      *          just reload them from the engine.
1717      */
1718     void commit();
1719     void rollback();
1720     void restart();
1721 
1722 private:
1723     MyMoneyFileTransactionPrivate * const d_ptr;
1724     Q_DECLARE_PRIVATE(MyMoneyFileTransaction)
1725 };
1726 
1727 #endif
1728