File indexing completed on 2024-04-28 16:30:08
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 SKGACCOUNTOBJECT_H 0007 #define SKGACCOUNTOBJECT_H 0008 /** @file 0009 * This file defines classes SKGAccountObject. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 0014 #include "skgbankmodeler_export.h" 0015 #include "skgnamedobject.h" 0016 class SKGBankObject; 0017 class SKGOperationObject; 0018 class SKGUnitObject; 0019 class SKGInterestObject; 0020 0021 /** 0022 * This class manages account object 0023 */ 0024 class SKGBANKMODELER_EXPORT SKGAccountObject : public SKGNamedObject 0025 { 0026 public: 0027 /** 0028 * Describe a interest item 0029 */ 0030 struct SKGInterestItem { 0031 SKGObjectBase object; /**< The object (an operation, an interest or nothing for initial balance) */ 0032 QDate date; /**< The date */ 0033 QDate valueDate; /**< The valueDate */ 0034 int base{}; /**< Base */ 0035 double amount{}; /**< Amount */ 0036 double coef{}; /**< Coef */ 0037 double rate{}; /**< Rate */ 0038 double annualInterest{}; /**< Annual Interest */ 0039 double accruedInterest{}; /**< Accrued Interest */ 0040 }; 0041 0042 using SKGInterestItemList = QVector<SKGAccountObject::SKGInterestItem>; 0043 0044 /** 0045 * This enumerate defines type of account 0046 */ 0047 enum AccountType {CURRENT, /**< to define a bank account*/ 0048 CREDITCARD, /**< to define a credit card account*/ 0049 INVESTMENT, /**< to define an account for investment */ 0050 ASSETS, /**< to define a assets account */ 0051 OTHER, /**< other kind of account */ 0052 WALLET, /**< to define a wallet account */ 0053 LOAN, /**< to define a loan account */ 0054 SAVING, /**< to define a saving account */ 0055 PENSION /**< to define a pension account */ 0056 }; 0057 /** 0058 * This enumerate defines type of account 0059 */ 0060 Q_ENUM(AccountType) 0061 0062 /** 0063 * Default constructor 0064 */ 0065 explicit SKGAccountObject(); 0066 0067 /** 0068 * Constructor 0069 * @param iDocument the document containing the object 0070 * @param iID the identifier in @p iTable of the object 0071 */ 0072 explicit SKGAccountObject(SKGDocument* iDocument, int iID = 0); 0073 0074 /** 0075 * Copy constructor 0076 * @param iObject the object to copy 0077 */ 0078 SKGAccountObject(const SKGAccountObject& iObject); 0079 0080 /** 0081 * Copy constructor 0082 * @param iObject the object to copy 0083 */ 0084 explicit SKGAccountObject(const SKGNamedObject& iObject); 0085 0086 /** 0087 * Copy constructor 0088 * @param iObject the object to copy 0089 */ 0090 explicit SKGAccountObject(const SKGObjectBase& iObject); 0091 0092 /** 0093 * Operator affectation 0094 * @param iObject the object to copy 0095 */ 0096 SKGAccountObject& operator= (const SKGObjectBase& iObject); 0097 0098 /** 0099 * Operator affectation 0100 * @param iObject the object to copy 0101 */ 0102 SKGAccountObject& operator= (const SKGAccountObject& iObject); 0103 0104 /** 0105 * Destructor 0106 */ 0107 virtual ~SKGAccountObject(); 0108 0109 /** 0110 * Get the parent bank 0111 * @param oBank the parent bank 0112 * @return an object managing the error 0113 * @see SKGError 0114 */ 0115 virtual SKGError getBank(SKGBankObject& oBank) const; 0116 0117 /** 0118 * Set the parent bank 0119 * @param iBank the parent bank 0120 * @return an object managing the error 0121 * @see SKGError 0122 */ 0123 virtual SKGError setBank(const SKGBankObject& iBank); 0124 0125 /** 0126 * Get the linked account 0127 * @param oAccount the linked account 0128 * @return an object managing the error 0129 * @see SKGError 0130 */ 0131 virtual SKGError getLinkedAccount(SKGAccountObject& oAccount) const; 0132 0133 /** 0134 * Get the list of accounts linked to this one 0135 * @param oAccounts the list of accounts linked 0136 * @return an object managing the error 0137 * @see SKGError 0138 */ 0139 virtual SKGError getLinkedByAccounts(SKGListSKGObjectBase& oAccounts) const; 0140 0141 /** 0142 * Set the linked account 0143 * @param iAccount the linked account 0144 * @return an object managing the error 0145 * @see SKGError 0146 */ 0147 virtual SKGError setLinkedAccount(const SKGAccountObject& iAccount); 0148 0149 /** 0150 * Set the initial balance of this account 0151 * @param iBalance the balance 0152 * @param iUnit the unit 0153 * @return an object managing the error 0154 * @see SKGError 0155 */ 0156 virtual SKGError setInitialBalance(double iBalance, const SKGUnitObject& iUnit); 0157 0158 /** 0159 * Get the initial balance of this account 0160 * @param oBalance the balance 0161 * @param oUnit the unit 0162 * @return an object managing the error 0163 * @see SKGError 0164 */ 0165 virtual SKGError getInitialBalance(double& oBalance, SKGUnitObject& oUnit); 0166 0167 /** 0168 * Set the number of the account 0169 * @param iNumber the number 0170 * @return an object managing the error 0171 * @see SKGError 0172 */ 0173 virtual SKGError setNumber(const QString& iNumber); 0174 0175 /** 0176 * Get the number of the account 0177 * @return the number 0178 */ 0179 virtual QString getNumber() const; 0180 0181 /** 0182 * Set the agency number of the account 0183 * @param iNumber the agency number 0184 * @return an object managing the error 0185 * @see SKGError 0186 */ 0187 virtual SKGError setAgencyNumber(const QString& iNumber); 0188 0189 /** 0190 * Get the agency number of the account 0191 * @return the number 0192 */ 0193 virtual QString getAgencyNumber() const; 0194 0195 /** 0196 * Set the agency address of the account 0197 * @param iAddress the agency address 0198 * @return an object managing the error 0199 * @see SKGError 0200 */ 0201 virtual SKGError setAgencyAddress(const QString& iAddress); 0202 0203 /** 0204 * Get the agency address of the account 0205 * @return the number 0206 */ 0207 virtual QString getAgencyAddress() const; 0208 0209 /** 0210 * Set the comment of account 0211 * @param iComment the comment 0212 * @return an object managing the error 0213 * @see SKGError 0214 */ 0215 virtual SKGError setComment(const QString& iComment); 0216 0217 /** 0218 * Get the comment of this account 0219 * @return the comment 0220 */ 0221 virtual QString getComment() const; 0222 0223 /** 0224 * Add a new transaction to this account 0225 * @param oOperation the created operation 0226 * @param iForce force the creation even if the account is closed 0227 * @return an object managing the error 0228 * @see SKGError 0229 */ 0230 virtual SKGError addOperation(SKGOperationObject& oOperation, bool iForce = false); 0231 0232 /** 0233 * Get number of transactions 0234 * @return the number of transactions 0235 */ 0236 virtual int getNbOperation() const; 0237 0238 /** 0239 * Get all transactions of this account 0240 * @param oOperations all transactions of this account 0241 * @return an object managing the error 0242 * @see SKGError 0243 */ 0244 virtual SKGError getOperations(SKGListSKGObjectBase& oOperations) const; 0245 0246 /** 0247 * Get the current amount 0248 * @return the current amount 0249 */ 0250 virtual double getCurrentAmount() const; 0251 0252 /** 0253 * Get amount of the account at a date 0254 * @param iDate date 0255 * @param iOnlyCurrencies only the transactions based on currencies are taken into account, not shares 0256 * @return amount of the account 0257 */ 0258 // cppcheck-suppress passedByValue 0259 virtual double getAmount(QDate iDate, bool iOnlyCurrencies = false) const; 0260 0261 /** 0262 * Set the type of this account 0263 * @param iType the type 0264 * @return an object managing the error 0265 * @see SKGError 0266 */ 0267 virtual SKGError setType(SKGAccountObject::AccountType iType); 0268 0269 /** 0270 * Get the type of this account 0271 * @return the type 0272 */ 0273 virtual SKGAccountObject::AccountType getType() const; 0274 0275 /** 0276 * To set the closed attribute of an account 0277 * @param iClosed the closed attribute: true or false 0278 * @return an object managing the error 0279 * @see SKGError 0280 */ 0281 virtual SKGError setClosed(bool iClosed); 0282 0283 /** 0284 * To know if the account has been closed or not 0285 * @return an object managing the error 0286 * @see SKGError 0287 */ 0288 virtual bool isClosed() const; 0289 0290 /** 0291 * To bookmark or not on an account 0292 * @param iBookmark the bookmark: true or false 0293 * @return an object managing the error 0294 * @see SKGError 0295 */ 0296 virtual SKGError bookmark(bool iBookmark); 0297 0298 /** 0299 * To know if the account is bookmarked 0300 * @return an object managing the error 0301 * @see SKGError 0302 */ 0303 virtual bool isBookmarked() const; 0304 0305 /** 0306 * To enable the max amount limit or not on an account 0307 * @param iEnabled the state: true or false 0308 * @return an object managing the error 0309 * @see SKGError 0310 */ 0311 virtual SKGError maxLimitAmountEnabled(bool iEnabled); 0312 0313 /** 0314 * To know if the account has a max amount limit 0315 * @return an object managing the error 0316 * @see SKGError 0317 */ 0318 virtual bool isMaxLimitAmountEnabled() const; 0319 0320 /** 0321 * To set the max amount limit 0322 * @param iAmount the amount (in account's unit) 0323 * @return an object managing the error 0324 * @see SKGError 0325 */ 0326 virtual SKGError setMaxLimitAmount(double iAmount); 0327 0328 /** 0329 * To get the max amount limit (in account's unit) 0330 * @return an object managing the error 0331 * @see SKGError 0332 */ 0333 virtual double getMaxLimitAmount() const; 0334 0335 /** 0336 * To enable the min amount limit or not on an account 0337 * @param iEnabled the state: true or false 0338 * @return an object managing the error 0339 * @see SKGError 0340 */ 0341 virtual SKGError minLimitAmountEnabled(bool iEnabled); 0342 0343 /** 0344 * To know if the account has a min amount limit 0345 * @return an object managing the error 0346 * @see SKGError 0347 */ 0348 virtual bool isMinLimitAmountEnabled() const; 0349 0350 /** 0351 * To set the min amount limit 0352 * @param iAmount the amount (in account's unit) 0353 * @return an object managing the error 0354 * @see SKGError 0355 */ 0356 virtual SKGError setMinLimitAmount(double iAmount); 0357 0358 /** 0359 * To get the min amount limit (in account's unit) 0360 * @return an object managing the error 0361 * @see SKGError 0362 */ 0363 virtual double getMinLimitAmount() const; 0364 0365 /** 0366 * Set reconciliation date of this account 0367 * @param iDate the date 0368 * @return an object managing the error 0369 * @see SKGError 0370 */ 0371 // cppcheck-suppress passedByValue 0372 virtual SKGError setReconciliationDate(QDate iDate); 0373 0374 /** 0375 * Get reconciliation date of this account 0376 * @return the date 0377 */ 0378 virtual QDate getReconciliationDate() const; 0379 0380 /** 0381 * Set reconciliation balance of this account 0382 * @param iAmount the balance 0383 * @return an object managing the error 0384 * @see SKGError 0385 */ 0386 virtual SKGError setReconciliationBalance(double iAmount); 0387 0388 /** 0389 * Get reconciliation balance of this account 0390 * @return the balance 0391 */ 0392 virtual double getReconciliationBalance() const; 0393 0394 /** 0395 * Get the unit 0396 * @param oUnit the unit 0397 * @return an object managing the error 0398 * @see SKGError 0399 */ 0400 virtual SKGError getUnit(SKGUnitObject& oUnit) const; 0401 0402 /** 0403 * Add an interest 0404 * @param oInterest the created interest 0405 * @return an object managing the error. 0406 * @see SKGError 0407 */ 0408 virtual SKGError addInterest(SKGInterestObject& oInterest); 0409 0410 /** 0411 * Get interests 0412 * @param oInterestList the list of interest in this account 0413 * @return an object managing the error 0414 * @see SKGError 0415 */ 0416 virtual SKGError getInterests(SKGListSKGObjectBase& oInterestList) const; 0417 0418 /** 0419 * Get interest object at a given date 0420 * @param iDate the date 0421 * @param oInterest the interest object 0422 * @return an object managing the error 0423 * @see SKGError 0424 */ 0425 // cppcheck-suppress passedByValue 0426 virtual SKGError getInterest(QDate iDate, SKGInterestObject& oInterest) const; 0427 0428 /** 0429 * Get and compute interest items 0430 * @param oInterestList interest items 0431 * @param oInterests sum of annual interests 0432 * @param iYear the year of computation (default=current year) 0433 * @return an object managing the error 0434 * @see SKGError 0435 */ 0436 virtual SKGError getInterestItems(SKGAccountObject::SKGInterestItemList& oInterestList, double& oInterests, int iYear = 0) const; 0437 0438 /** 0439 * Compute all items 0440 * @param ioInterestList interest items 0441 * @param oInterests sum of annual interests 0442 * @param iYear the year of computation (default=current year) 0443 * @return an object managing the error 0444 * @see SKGError 0445 */ 0446 virtual SKGError computeInterestItems(SKGAccountObject::SKGInterestItemList& ioInterestList, double& oInterests, int iYear = 0) const; 0447 0448 /** 0449 * Try to mark all imported transactions to obtain the expected balance 0450 * @param iBalance the expected balance in the account unit 0451 * @return an object managing the error 0452 * @see SKGError 0453 */ 0454 virtual SKGError autoReconcile(double iBalance); 0455 0456 /** 0457 * Merge iAccount in current account 0458 * @param iAccount the account. All transactions will be transferred into this account. The account will be removed 0459 * @param iMergeInitalBalance to merge the initial balances too 0460 * @return an object managing the error 0461 * @see SKGError 0462 */ 0463 virtual SKGError merge(const SKGAccountObject& iAccount, bool iMergeInitalBalance); 0464 0465 /** 0466 * Create a Transfer transaction to balance a credit card account (based on marked transactions) 0467 * @param iTargetAccount the target account (should be the bank account) 0468 * @param iDate the date of the balance operation 0469 * @return an object managing the error 0470 * @see SKGError 0471 */ 0472 // cppcheck-suppress passedByValue 0473 virtual SKGError transferDeferredOperations(const SKGAccountObject& iTargetAccount, QDate iDate = QDate::currentDate()); 0474 0475 /** 0476 * Get all list of transactions that can be checked to reconcile with target balance 0477 * @param iTargetBalance the target balance (in the unit of the account) 0478 * @param iSearchAllPossibleReconciliation to search all possible reconciliation 0479 * @return the list of possible solutions 0480 */ 0481 virtual QVector< QVector<SKGOperationObject> > getPossibleReconciliations(double iTargetBalance, bool iSearchAllPossibleReconciliation = true) const; 0482 0483 private: 0484 /** 0485 * Get all list of transactions that can be checked to reconcile with target balance 0486 * @param iOperations the transactions to take into account 0487 * @param iBalance the current balance (in the unit of the account) 0488 * @param iTargetBalance the target balance (in the unit of the account) 0489 * @param iUnit the unit of the account (for better performances) 0490 * @param iSearchAllPossibleReconciliation to search all possible reconciliation 0491 * @return the list of possible solutions 0492 */ 0493 QVector< QVector<SKGOperationObject> > getPossibleReconciliations(const SKGObjectBase::SKGListSKGObjectBase& iOperations, double iBalance, double iTargetBalance, const SKGServices::SKGUnitInfo& iUnit, bool iSearchAllPossibleReconciliation) const; 0494 }; 0495 /** 0496 * Declare the class 0497 */ 0498 Q_DECLARE_TYPEINFO(SKGAccountObject, Q_MOVABLE_TYPE); 0499 #endif