File indexing completed on 2024-04-28 16:30:10
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 #ifndef SKGDOCUMENTBANK_H 0007 #define SKGDOCUMENTBANK_H 0008 /** @file 0009 * This file defines classes SKGDocumentBank. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 0014 #include "skgbankmodeler_export.h" 0015 #include "skgdefinebank.h" 0016 #include "skgdocument.h" 0017 0018 class SKGUnitValueObject; 0019 0020 /** 0021 * This class manages skg bank documents 0022 */ 0023 class SKGBANKMODELER_EXPORT SKGDocumentBank : public SKGDocument 0024 { 0025 Q_OBJECT 0026 Q_CLASSINFO("D-Bus Interface", "org.kde.skrooge.SKGDocumentBank") 0027 0028 public: 0029 /** 0030 * Constructor 0031 */ 0032 explicit SKGDocumentBank(); 0033 0034 /** 0035 * Destructor 0036 */ 0037 ~SKGDocumentBank() override; 0038 0039 /** 0040 * dump the document in the std output. 0041 * It is useful for debug. 0042 * @param iMode to select what you want to dump. 0043 * @code 0044 * document->dump (DUMPUNIT|DUMPPARAMETERS); 0045 * @endcode 0046 * @return an object managing the error. 0047 * @see SKGError 0048 */ 0049 SKGError dump(int iMode = DUMPBANKOBJECT) const override; 0050 0051 /** 0052 * Create or modify an account 0053 * @param iName account name 0054 * @param iNumber account number 0055 * @param iBankName name of the bank 0056 * @return an object managing the error. 0057 * @see SKGError 0058 */ 0059 virtual SKGError addOrModifyAccount(const QString& iName, const QString& iNumber, const QString& iBankName) const; 0060 0061 /** 0062 * Create or modify the value of an unit 0063 * @param iUnitName unit name 0064 * @param iDate date 0065 * @param iValue unit value for the date @p iDate 0066 * @param oValue this output unit value 0067 * @return an object managing the error. 0068 * @see SKGError 0069 */ 0070 // cppcheck-suppress passedByValue 0071 virtual SKGError addOrModifyUnitValue(const QString& iUnitName, QDate iDate, double iValue, SKGUnitValueObject* oValue = nullptr) const; 0072 0073 /** 0074 * Get Primary unit. WARNING: This value can be not uptodated in a transaction. 0075 * @return Primary unit. 0076 */ 0077 virtual SKGServices::SKGUnitInfo getPrimaryUnit() const; 0078 0079 /** 0080 * Get Secondary unit. WARNING: This value can be not uptodated in a transaction. 0081 * @return Secondary unit. 0082 */ 0083 virtual SKGServices::SKGUnitInfo getSecondaryUnit() const; 0084 0085 /** 0086 * Get the preferred category for a payee. WARNING: This value can be not uptodated in a transaction. 0087 * @param iPayee the payee 0088 * @param iComputeAllPayees compute all categories for all payees and put them in cache. This is better when you know that you will need all. 0089 * @return The preferred category. 0090 */ 0091 virtual QString getCategoryForPayee(const QString& iPayee, bool iComputeAllPayees = true) const; 0092 0093 /** 0094 * Return the number version of views, indexes and triggers 0095 * @return 0096 */ 0097 virtual QString getViewsIndexesAndTriggersVersion() const; 0098 0099 /** 0100 * Get display schemas 0101 * @param iRealTable the real table name 0102 * @return list of schemas 0103 */ 0104 SKGDocument::SKGModelTemplateList getDisplaySchemas(const QString& iRealTable) const override; 0105 0106 /** 0107 * Get the display string for any modeler object (table, attribute) 0108 * @param iString the name of the object (example: v_operation, v_unit.t_name) 0109 * @return the display string 0110 */ 0111 QString getDisplay(const QString& iString) const override; 0112 0113 /** 0114 * Get the real attribute 0115 * @param iString the name of the attribute (something like t_BANK) 0116 * @return the real attribute (something like bank.rd_bank_id.t_name) 0117 */ 0118 QString getRealAttribute(const QString& iString) const override; 0119 /** 0120 * Get the icon for attribute 0121 * @param iString the name of the attribute 0122 * @return the icon name 0123 */ 0124 QString getIconName(const QString& iString) const override; 0125 0126 /** 0127 * Get the attribute type 0128 * @param iAttributeName the name of an attribute 0129 * @return the type 0130 */ 0131 SKGServices::AttributeType getAttributeType(const QString& iAttributeName) const override; 0132 0133 /** 0134 * Get the file extension for this kind of document (must be overwritten) 0135 * @return file extension (like skg) 0136 */ 0137 QString getFileExtension() const override; 0138 0139 /** 0140 * Get the header of the file (useful for magic mime type). 0141 * @return document header 0142 */ 0143 QString getDocumentHeader() const override; 0144 0145 /** 0146 * Get budget report 0147 * @param iMonth the month 0148 * @return the report 0149 */ 0150 virtual QVariantList getBudget(const QString& iMonth) const; 0151 0152 /** 0153 * Get main categories report 0154 * @param iPeriod the period 0155 * @param iNb number of categories 0156 * @return the report 0157 */ 0158 virtual QVariantList getMainCategories(const QString& iPeriod, int iNb = 5); 0159 0160 /** 0161 * Get 5 main variation of categories report 0162 * @param iPeriod the period 0163 * @param iPreviousPeriod the previous period 0164 * @param iOnlyIssues only "Expenses increased" and "Incomes decreased" 0165 * @param oCategoryList to get the category for each variation 0166 * @return the list of variation string 0167 */ 0168 virtual QStringList get5MainCategoriesVariationList(const QString& iPeriod, const QString& iPreviousPeriod, bool iOnlyIssues, QStringList* oCategoryList = nullptr); 0169 0170 /** 0171 * Get the report 0172 * Do not forget to delete the pointer 0173 * @return the report 0174 */ 0175 SKGReport* getReport() const override; 0176 0177 /** 0178 * Refresh all views and indexes in the database 0179 * @param iForce force the refresh 0180 * @return an object managing the error. 0181 * @see SKGError 0182 */ 0183 SKGError refreshViewsIndexesAndTriggers(bool iForce = false) const override; 0184 0185 /** 0186 * Get formated money in primary unit 0187 * @param iValue value 0188 * @param iForcedNbOfDigit the number of digit (-1 means nb of digit of the unit) 0189 * @return formated value in red or black 0190 */ 0191 Q_INVOKABLE QString formatPrimaryMoney(double iValue, int iForcedNbOfDigit = -1) const override; 0192 0193 /** 0194 * Get formated money in primary unit 0195 * @param iValue value 0196 * @param iForcedNbOfDigit the number of digit (-1 means nb of digit of the unit) 0197 * @return formated value in red or black 0198 */ 0199 Q_INVOKABLE QString formatSecondaryMoney(double iValue, int iForcedNbOfDigit = -1) const override; 0200 0201 public Q_SLOTS: 0202 /** 0203 * Close the current transaction. 0204 * A transaction is needed to modify the SKGDocument. 0205 * This transaction is also used to manage the undo/redo. 0206 * @see beginTransaction 0207 * @param succeedded : true to indicate that current transaction has been successfully executed 0208 * : false to indicate that current transaction has failed 0209 * @return an object managing the error 0210 * @see SKGError 0211 */ 0212 SKGError endTransaction(bool succeedded) override; 0213 0214 /** 0215 * Enable/disable balances computation 0216 */ 0217 virtual void setComputeBalances(bool iEnabled); 0218 0219 /** 0220 * Refresh the case. 0221 * @param iTable the modified table triggering the cache refresh. 0222 */ 0223 void refreshCache(const QString& iTable) const override; 0224 0225 protected: 0226 /** 0227 * Migrate the current SKGDocument to the latest version of the data model. 0228 * WARNING: This method must be used in a transaction. 0229 * @see beginTransaction 0230 * @param oMigrationDone to know if a migration has been done or not. 0231 * @return an object managing the error. 0232 * @see SKGError 0233 */ 0234 SKGError migrate(bool& oMigrationDone) override; 0235 0236 /** 0237 * Compute balance of each transaction. 0238 * @return an object managing the error. 0239 * @see SKGError 0240 */ 0241 virtual SKGError computeBalances() const; 0242 0243 /** 0244 * Compute the budget suboperation links. 0245 * @return an object managing the error. 0246 * @see SKGError 0247 */ 0248 virtual SKGError computeBudgetSuboperationLinks() const; 0249 0250 private: 0251 Q_DISABLE_COPY(SKGDocumentBank) 0252 0253 QString m_5mainVariations_inputs; 0254 QStringList m_5mainVariations_cache; 0255 QStringList m_5mainVariationsCat_cache; 0256 bool m_computeBalances{true}; 0257 QStringList getMigationSteps(); 0258 }; 0259 /** 0260 * Declare the class 0261 */ 0262 Q_DECLARE_TYPEINFO(SKGDocumentBank, Q_MOVABLE_TYPE); 0263 #endif