Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mymoneyfile.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           mymoneyfile.h
00003                              -------------------
00004     copyright            : (C) 2002, 2007 by Thomas Baumgart
00005     email                : ipwizard@users.sourceforge.net
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #ifndef MYMONEYFILE_H
00018 #define MYMONEYFILE_H
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 // ----------------------------------------------------------------------------
00025 // QT Includes
00026 
00027 #include <qobject.h>
00028 #include <qstring.h>
00029 #include <qmap.h>
00030 #include <qvaluelist.h>
00031 
00032 // ----------------------------------------------------------------------------
00033 // Project Includes
00034 
00035 #include <kmymoney/imymoneystorage.h>
00036 #include <kmymoney/mymoneyexception.h>
00037 #include <kmymoney/mymoneyutils.h>
00038 #include <kmymoney/mymoneyinstitution.h>
00039 #include <kmymoney/mymoneyaccount.h>
00040 #include <kmymoney/mymoneytransaction.h>
00041 #include <kmymoney/mymoneypayee.h>
00042 #include <kmymoney/mymoneykeyvaluecontainer.h>
00043 #include <kmymoney/mymoneysecurity.h>
00044 #include <kmymoney/mymoneyprice.h>
00045 #include <kmymoney/mymoneyreport.h>
00046 #include <kmymoney/mymoneybudget.h>
00047 #include <kmymoney/mymoneyscheduled.h>
00048 #include <kmymoney/export.h>
00049 
00054 class IMyMoneyStorage;
00055 class MyMoneyTransactionFilter;
00056 class MyMoneyFilePrivate;
00057 
00138 class KMYMONEY_EXPORT MyMoneyFile : public QObject
00139 {
00140   Q_OBJECT
00141 public:
00142 
00143   class MyMoneyNotifier
00144   {
00145   public:
00146     MyMoneyNotifier(MyMoneyFile* file) { m_file = file; m_file->clearNotification(); };
00147     ~MyMoneyNotifier() { m_file->notify(); };
00148   private:
00149     MyMoneyFile* m_file;
00150   };
00151 
00152   friend class MyMoneyNotifier;
00153 
00158   static inline MyMoneyFile* instance() { return &file; }
00159 
00163   ~MyMoneyFile();
00164 
00172   MyMoneyFile(IMyMoneyStorage *storage);
00173 
00174   // general get functions
00175   const MyMoneyPayee user(void) const;
00176 
00177   // general set functions
00178   void setUser(const MyMoneyPayee& user);
00179 
00199   void attachStorage(IMyMoneyStorage* const storage);
00200 
00211   void detachStorage(IMyMoneyStorage* const storage = 0);
00212 
00219   bool storageAttached(void) const { return m_storage != 0; };
00220 
00227   IMyMoneyStorage* storage(void) const { return m_storage; };
00228 
00237   void startTransaction(void);
00238 
00243   bool hasTransaction(void) const;
00244 
00248   void commitTransaction(void);
00249 
00253   void rollbackTransaction(void);
00254 
00259   const MyMoneyAccount& liability(void) const;
00260 
00265   const MyMoneyAccount& asset(void) const;
00266 
00271   const MyMoneyAccount& expense(void) const;
00272 
00277   const MyMoneyAccount& income(void) const;
00278 
00283   const MyMoneyAccount& equity(void) const;
00284 
00299   const MyMoneyAccount openingBalanceAccount(const MyMoneySecurity& security);
00300 
00312   const MyMoneyAccount openingBalanceAccount(const MyMoneySecurity& security) const;
00313 
00326   void createOpeningBalanceTransaction(const MyMoneyAccount& acc, const MyMoneyMoney& balance);
00327 
00336   const QCString openingBalanceTransaction(const MyMoneyAccount& acc) const;
00337 
00344   bool dirty(void) const;
00345 
00352   void setDirty(void) const;
00353 
00364   void addInstitution(MyMoneyInstitution& institution);
00365 
00374   void modifyInstitution(const MyMoneyInstitution& institution);
00375 
00385   void removeInstitution(const MyMoneyInstitution& institution);
00386 
00410   void addAccount(MyMoneyAccount& account, MyMoneyAccount& parent);
00411 
00419   void modifyAccount(const MyMoneyAccount& account);
00420 
00429   void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent);
00430 
00439   unsigned int moveSplits(const QCString& oldAccount, const QCString& newAccount);
00440 
00448   bool hasActiveSplits(const QCString& id) const;
00449 
00459   bool isStandardAccount(const QCString& id) const;
00460 
00466   bool isTransfer(const MyMoneyTransaction& t) const;
00467 
00477   void setAccountName(const QCString& id, const QString& name) const;
00478 
00488   void removeAccount(const MyMoneyAccount& account);
00489 
00504   void removeAccountList(const QCStringList& account_list, unsigned int level = 0);
00505 
00521   bool hasOnlyUnusedAccounts(const QCStringList& account_list, unsigned int level = 0);
00522 
00534   void addTransaction(MyMoneyTransaction& transaction);
00535 
00546   void modifyTransaction(const MyMoneyTransaction& transaction);
00547 
00556   const MyMoneyTransaction transaction(const QCString& id) const;
00557 
00566   const MyMoneyTransaction transaction(const QCString& account, const int idx) const;
00567 
00581   const QValueList<MyMoneyTransaction> transactionList(MyMoneyTransactionFilter& filter) const;
00582 
00583   void transactionList(QValueList<MyMoneyTransaction>& list, MyMoneyTransactionFilter& filter) const;
00584 
00585   void transactionList(QValueList<QPair<MyMoneyTransaction, MyMoneySplit> >& list, MyMoneyTransactionFilter& filter) const;
00586 
00593   void removeTransaction(const MyMoneyTransaction& transaction);
00594 
00606   const MyMoneyMoney balance(const QCString& id, const QDate& date = QDate()) const;
00607 
00619   const MyMoneyMoney totalBalance(const QCString& id, const QDate& date = QDate()) const;
00620 
00632   unsigned int transactionCount(const QCString& account = QCString()) const;
00633 
00643   const QMap<QCString, unsigned long> transactionCountMap(void) const;
00644 
00651   unsigned int institutionCount(void) const;
00652 
00659   unsigned int accountCount(void) const;
00660 
00668   const MyMoneyInstitution& institution(const QCString& id) const;
00669 
00676   void institutionList(QValueList<MyMoneyInstitution>& list) const;
00677 
00685   const QValueList<MyMoneyInstitution> institutionList(void) const;
00686 
00694   const MyMoneyAccount& account(const QCString& id) const;
00695 
00703   const MyMoneyAccount& accountByName(const QString& name) const;
00704 
00713   const MyMoneyAccount& subAccountByName(const MyMoneyAccount& acc, const QString& name) const;
00714 
00728   void accountList(QValueList<MyMoneyAccount>& list, const QCStringList& idlist = QCStringList(), const bool recursive = false) const;
00729 
00742   const QString accountToCategory(const QCString& accountId, bool includeStandardAccounts = false) const;
00743 
00755   const QCString categoryToAccount(const QString& category, MyMoneyAccount::accountTypeE type = MyMoneyAccount::UnknownAccountType) const;
00756 
00768   const QCString nameToAccount(const QString& name) const;
00769 
00777   const QString parentName(const QString& name) const;
00778 
00786   void addPayee(MyMoneyPayee& payee);
00787 
00796   const MyMoneyPayee& payee(const QCString& id) const;
00797 
00807   const MyMoneyPayee& payeeByName(const QString& payee) const;
00808 
00816   void modifyPayee(const MyMoneyPayee& payee);
00817 
00827   void removePayee(const MyMoneyPayee& payee);
00828 
00835   const QValueList<MyMoneyPayee> payeeList(void) const;
00836 
00844   const QString value(const QCString& key) const;
00845 
00856   void setValue(const QCString& key, const QString& val);
00857 
00865   void deletePair(const QCString& key);
00866 
00877   void addSchedule(MyMoneySchedule& sched);
00878 
00887   void modifySchedule(const MyMoneySchedule& sched);
00888 
00897   void removeSchedule(const MyMoneySchedule& sched);
00898 
00908   const MyMoneySchedule schedule(const QCString& id) const;
00909 
00936   const QValueList<MyMoneySchedule> scheduleList(const QCString& accountId = QCString(),
00937                                      const MyMoneySchedule::typeE type = MyMoneySchedule::TYPE_ANY,
00938                                      const MyMoneySchedule::occurenceE occurence = MyMoneySchedule::OCCUR_ANY,
00939                                      const MyMoneySchedule::paymentTypeE paymentType = MyMoneySchedule::STYPE_ANY,
00940                                      const QDate& startDate = QDate(),
00941                                      const QDate& endDate = QDate(),
00942                                      const bool overdue = false) const;
00943 
00944   const QStringList consistencyCheck(void);
00945 
00951   static const QString OpeningBalancesPrefix;
00952 
00957   static const QString AccountSeperator;
00958 
00977   const QCString createCategory(const MyMoneyAccount& base, const QString& name);
00978 
00979   const QValueList<MyMoneySchedule> scheduleListEx( int scheduleTypes,
00980                                               int scheduleOcurrences,
00981                                               int schedulePaymentTypes,
00982                                               QDate startDate,
00983                                               const QCStringList& accounts=QCStringList()) const;
00984 
00994   void addSecurity(MyMoneySecurity& security);
00995 
01004   void modifySecurity(const MyMoneySecurity& security);
01005 
01014   void removeSecurity(const MyMoneySecurity& security);
01015 
01027   const MyMoneySecurity& security(const QCString& id) const;
01028 
01032   const QValueList<MyMoneySecurity> securityList(void) const;
01033 
01043   void addCurrency(const MyMoneySecurity& currency);
01044 
01053   void modifyCurrency(const MyMoneySecurity& currency);
01054 
01063   void removeCurrency(const MyMoneySecurity& currency);
01064 
01075   const MyMoneySecurity& currency(const QCString& id) const;
01076 
01085   const QValueList<MyMoneySecurity> currencyList(void) const;
01086 
01098   const MyMoneySecurity& baseCurrency(void) const;
01099 
01105   const QCString& foreignCurrency(const QCString& first, const QCString& second) const;
01106 
01117   void setBaseCurrency(const MyMoneySecurity& currency);
01118 
01122   void addPrice(const MyMoneyPrice& price);
01123 
01127   void removePrice(const MyMoneyPrice& price);
01128 
01144   const MyMoneyPrice price(const QCString& fromId, const QCString& toId = QCString(), const QDate& date = QDate::currentDate(), const bool exactDate = false) const;
01145 
01151   const MyMoneyPriceList priceList(void) const;
01152 
01162   bool hasAccount(const QCString& id, const QString& name) const;
01163 
01172   const QValueList<MyMoneyReport> reportList( void ) const;
01173 
01184   void addReport( MyMoneyReport& report );
01185 
01194   void modifyReport( const MyMoneyReport& report );
01195 
01202   unsigned countReports( void ) const;
01203 
01213   const MyMoneyReport report( const QCString& id ) const;
01214 
01223   void removeReport(const MyMoneyReport& report);
01224 
01233   const QValueList<MyMoneyBudget> budgetList( void ) const;
01234 
01245   void addBudget( MyMoneyBudget& budget );
01246 
01247 
01257   const MyMoneyBudget budgetByName(const QString& budget) const;
01258 
01259 
01268   void modifyBudget( const MyMoneyBudget& budget );
01269 
01276   unsigned countBudgets( void ) const;
01277 
01287   const MyMoneyBudget budget( const QCString& id ) const;
01288 
01297   void removeBudget(const MyMoneyBudget& budget);
01298 
01299 
01311   bool isReferenced(const MyMoneyObject& obj, const MyMoneyFileBitArray& skipCheck = MyMoneyFileBitArray()) const;
01312 
01323   bool checkNoUsed(const QCString& accId, const QString& no) const;
01324 
01332   const QString highestCheckNo(const QCString& accId) const;
01333 
01337   void clearCache(void);
01338 
01339   void forceDataChanged(void) { emit dataChanged(); }
01340 
01341   void preloadCache(void);
01342 
01343 protected:
01347   MyMoneyFile();
01348 
01349 signals:
01354   void dataChanged(void);
01355 
01356 private:
01357   static MyMoneyFile file;
01358 
01359   MyMoneyFile& operator=(MyMoneyFile&); // not allowed for singleton
01360   MyMoneyFile(const MyMoneyFile&);      // not allowed for singleton
01361 
01362   const QCString locateSubAccount(const MyMoneyAccount& base, const QString& category) const;
01363 
01364   void ensureDefaultCurrency(MyMoneyAccount& acc) const;
01365 
01366   void warningMissingRate(const QCString& fromId, const QCString& toId) const;
01367 
01376   const MyMoneyAccount createOpeningBalanceAccount(const MyMoneySecurity& security);
01377 
01378   const MyMoneyAccount openingBalanceAccount_internal(const MyMoneySecurity& security) const;
01379 
01380 private:
01389   void addNotification(const QCString& id, bool reload = true);
01390 
01394   void clearNotification(void);
01395 
01400   void notify(void);
01401 
01406   inline void checkStorage(void) const {
01407     if(m_storage == 0)
01408       throw new MYMONEYEXCEPTION("No storage object attached to MyMoneyFile");
01409   }
01410 
01416   void checkTransaction(const char* txt) const;
01417 
01418 private:
01422   IMyMoneyStorage *m_storage;
01423 
01427   MyMoneyFilePrivate* const d;
01428 
01429   static MyMoneyFile* _instance;
01430 };
01431 
01432 class KMYMONEY_EXPORT MyMoneyFileTransaction
01433 {
01434 public:
01435   MyMoneyFileTransaction();
01436   ~MyMoneyFileTransaction();
01437 
01446   void commit(void);
01447   void rollback(void);
01448   void restart(void);
01449 
01450 private:
01451   bool m_isNested;
01452   bool m_needRollback;
01453 };
01454 
01455 #endif
01456 

Generated on Mon Nov 17 11:59:19 2008 for KMyMoney by  doxygen 1.4.1