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