File indexing completed on 2024-04-28 16:30:12

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 SKGOPERATIONOBJECT_H
0007 #define SKGOPERATIONOBJECT_H
0008 /** @file
0009  * This file defines classes SKGOperationObject.
0010  *
0011  * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 
0014 #include "skgbankmodeler_export.h"
0015 #include "skgobjectbase.h"
0016 class SKGAccountObject;
0017 class SKGUnitObject;
0018 class SKGSubOperationObject;
0019 class SKGRecurrentOperationObject;
0020 class SKGPayeeObject;
0021 
0022 /**
0023  * This class manages transaction object
0024  */
0025 class SKGBANKMODELER_EXPORT SKGOperationObject final : public SKGObjectBase
0026 {
0027 public:
0028     /**
0029      * This enumerate defines status for transactions
0030      */
0031     enum OperationStatus {NONE, /**< no status */
0032                           MARKED, /**< marked */
0033                           CHECKED /**< checked */
0034                          };
0035     /**
0036      * This enumerate defines status for transactions
0037      */
0038     Q_ENUM(OperationStatus)
0039 
0040     /**
0041     * This enumerate defines the alignment amount mode
0042     */
0043     enum AmountAlignmentMode {
0044         DEFAULT,         /**< Default */
0045         PROPORTIONAL,    /**< Proportional */
0046         ADDSUBOPERATION  /**< Add sub transaction */
0047     };
0048     /**
0049      * This enumerate defines the alignment amount mode
0050      */
0051     Q_ENUM(AmountAlignmentMode)
0052 
0053     /**
0054      * Default constructor
0055      */
0056     explicit SKGOperationObject();
0057 
0058     /**
0059      * Constructor
0060      * @param iDocument the document containing the object
0061      * @param iID the identifier in @p iTable of the object
0062      */
0063     explicit SKGOperationObject(SKGDocument* iDocument, int iID = 0);
0064 
0065     /**
0066      * Copy constructor
0067      * @param iObject the object to copy
0068      */
0069     explicit SKGOperationObject(const SKGObjectBase& iObject);
0070 
0071     /**
0072      * Copy constructor
0073      * @param iObject the object to copy
0074      */
0075 
0076     SKGOperationObject(const SKGOperationObject& iObject);
0077 
0078     /**
0079      * Operator affectation
0080      * @param iObject the object to copy
0081      */
0082     SKGOperationObject& operator= (const SKGObjectBase& iObject);
0083 
0084     /**
0085      * Operator affectation
0086      * @param iObject the object to copy
0087      */
0088     SKGOperationObject& operator= (const SKGOperationObject& iObject);
0089 
0090     /**
0091      * Destructor
0092      */
0093     virtual ~SKGOperationObject();
0094 
0095     /**
0096      * Duplicate current transaction including subtransactions and grouped transactions
0097      * @param oOperation the created operation
0098      * @param iDate date(s) for new transaction(s)
0099      * @param iTemplateMode the template mode for new transaction(s)
0100      * @return an object managing the error.
0101      *   @see SKGError
0102      */
0103     // cppcheck-suppress passedByValue
0104     SKGError duplicate(SKGOperationObject& oOperation, QDate iDate = QDate::currentDate(), bool iTemplateMode = false) const;
0105 
0106     /**
0107      * Get the parent account
0108      * @param oAccount the parent account
0109      * @return an object managing the error.
0110      *   @see SKGError
0111      */
0112     SKGError getParentAccount(SKGAccountObject& oAccount) const;
0113 
0114     /**
0115      * Set the parent account
0116      * @param iAccount the parent account
0117      * @param iForce force the creation even if the account is closed
0118      * @return an object managing the error.
0119      *   @see SKGError
0120      */
0121     SKGError setParentAccount(const SKGAccountObject& iAccount, bool iForce = false);
0122 
0123     /**
0124      * Set the mode of operation
0125      * @param iNumber the number
0126      * @return an object managing the error
0127      *   @see SKGError
0128      */
0129     SKGError setNumber(const QString& iNumber);
0130 
0131     /**
0132      * Get the number of this transaction
0133      * @return the number
0134      */
0135     QString getNumber() const;
0136 
0137     /**
0138      * Set the mode of operation
0139      * @param iMode the mode
0140      * @return an object managing the error
0141      *   @see SKGError
0142      */
0143     SKGError setMode(const QString& iMode);
0144 
0145     /**
0146      * Get the mode of this transaction
0147      * @return the mode
0148      */
0149     QString getMode() const;
0150 
0151     /**
0152      * Set the payee of operation
0153      * @param iPayee the payee
0154      * @return an object managing the error
0155      *   @see SKGError
0156      */
0157     SKGError setPayee(const SKGPayeeObject& iPayee);
0158 
0159     /**
0160      * Get the payee of this transaction
0161      * @param oPayee the payee
0162      * @return an object managing the error
0163      *   @see SKGError
0164      */
0165     SKGError getPayee(SKGPayeeObject& oPayee) const;
0166 
0167     /**
0168      * Set the comment of operation
0169      * @param iComment the comment
0170      * @return an object managing the error
0171      *   @see SKGError
0172      */
0173     SKGError setComment(const QString& iComment);
0174 
0175     /**
0176      * Get the comment of this transaction
0177      * @return the comment
0178      */
0179     QString getComment() const;
0180 
0181     /**
0182      * Get the status of this transaction
0183      * @return the status
0184      */
0185     SKGOperationObject::OperationStatus getStatus() const;
0186 
0187     /**
0188      * Set the status of operation
0189      * @param iStatus the status
0190      * @return an object managing the error
0191      *   @see SKGError
0192      */
0193     SKGError setStatus(SKGOperationObject::OperationStatus iStatus);
0194 
0195     /**
0196      * Set date of this transaction
0197      * @param iDate the date
0198      * @param iRefreshSubOperations to refresh the sub transactions
0199      * @return an object managing the error
0200      *   @see SKGError
0201      */
0202     // cppcheck-suppress passedByValue
0203     SKGError setDate(QDate iDate, bool iRefreshSubOperations = true);
0204 
0205     /**
0206      * Get date of this transaction
0207      * @return the date
0208      */
0209     QDate getDate() const;
0210 
0211     /**
0212      * Set the unit
0213      * @param iUnit the unit
0214      * @return an object managing the error
0215      *   @see SKGError
0216      */
0217     SKGError setUnit(const SKGUnitObject& iUnit);
0218 
0219     /**
0220      * Get the unit
0221      * @param oUnit the unit
0222      * @return an object managing the error
0223      *   @see SKGError
0224      */
0225     SKGError getUnit(SKGUnitObject& oUnit) const;
0226 
0227     /**
0228      * To know if a transaction is grouped
0229      * @return true or false
0230      */
0231     bool isInGroup() const;
0232 
0233     /**
0234      * To know if the current transaction is a transfer of the other one
0235      * @param oOperation the other operation
0236      * @return true or false
0237      */
0238     bool isTransfer(SKGOperationObject& oOperation) const;
0239 
0240     /**
0241      * Set the group operation
0242      * @param iOperation the transaction (itself to remove from group)
0243      * @return an object managing the error
0244      *   @see SKGError
0245      */
0246     SKGError setGroupOperation(const SKGOperationObject& iOperation);
0247 
0248     /**
0249      * Get the group operation
0250      * @param oOperation the operation
0251      * @return an object managing the error
0252      *   @see SKGError
0253      */
0254     SKGError getGroupOperation(SKGOperationObject& oOperation) const;
0255 
0256     /**
0257      * Get all transactions in the same group
0258      * @param oGroupedOperations all transaction in the same group
0259      * @return an object managing the error
0260      *   @see SKGError
0261      */
0262     SKGError getGroupedOperations(SKGListSKGObjectBase& oGroupedOperations) const;
0263 
0264     /**
0265      * To bookmark or not an operation
0266      * @param iBookmark the bookmark: true or false
0267      * @return an object managing the error
0268      *   @see SKGError
0269      */
0270     SKGError bookmark(bool iBookmark);
0271 
0272     /**
0273      * To know if the transaction is bookmarked
0274      * @return an object managing the error
0275      *   @see SKGError
0276      */
0277     bool isBookmarked() const;
0278 
0279     /**
0280      * To set the imported attribute of an operation
0281      * @param iImported the imported status: true or false
0282      * @return an object managing the error
0283      *   @see SKGError
0284      */
0285     SKGError setImported(bool iImported);
0286 
0287     /**
0288      * To know if the transaction has been imported or not
0289      * @return an object managing the error
0290      *   @see SKGError
0291      */
0292     bool isImported() const;
0293 
0294     /**
0295      * Set the import identifier of operation, t_imported is set to 'T'
0296      * @param iImportID the import identifier (it is used to check if the transaction is already imported)
0297      * @return an object managing the error
0298      *   @see SKGError
0299      */
0300     SKGError setImportID(const QString& iImportID);
0301 
0302     /**
0303      * Get the import identifier of operation
0304      * @return the comment
0305      */
0306     QString getImportID() const;
0307 
0308     /**
0309      * To set the template attribute of an operation
0310      * @param iTemplate the template status: true or false
0311      * @return an object managing the error
0312      *   @see SKGError
0313      */
0314     SKGError setTemplate(bool iTemplate);
0315 
0316     /**
0317      * To know if the transaction is a template or not
0318      * @return an object managing the error
0319      *   @see SKGError
0320      */
0321     bool isTemplate() const;
0322 
0323     /**
0324      * Add a new suboperation to this transaction
0325      * @param oSubOperation the created suboperation
0326      * @return an object managing the error
0327      *   @see SKGError
0328      */
0329     SKGError addSubOperation(SKGSubOperationObject& oSubOperation);
0330 
0331     /**
0332      * Get the number of sub transactions
0333      * @return number of sub transactions
0334      */
0335     int getNbSubOperations() const;
0336 
0337     /**
0338      * Get all subtransactions of this transaction
0339      * @param oSubOperations all subtransactions of this transaction
0340      * @return an object managing the error
0341      *   @see SKGError
0342      */
0343     SKGError getSubOperations(SKGListSKGObjectBase& oSubOperations) const;
0344 
0345     /**
0346      * Get the current amount
0347      * @return the current amount
0348      */
0349     double getCurrentAmount() const;
0350 
0351     /**
0352      * Get the account balance for this transaction
0353      * @return the account balance
0354      */
0355     double getBalance() const;
0356 
0357     /**
0358      * Get amount of the transaction at a date
0359      * @param iDate date
0360      * @return amount of the transaction
0361      */
0362     // cppcheck-suppress passedByValue
0363     double getAmount(QDate iDate) const;
0364 
0365     /**
0366      * Create a recurrent transaction based on this one
0367      * @param oRecurrentOperation the created recurrent operation
0368      * @return an object managing the error
0369      *   @see SKGError
0370      */
0371     SKGError addRecurrentOperation(SKGRecurrentOperationObject& oRecurrentOperation) const;
0372 
0373     /**
0374      * Get the recurrent transactions based on this one
0375      * @param oRecurrentOperation the recurrent transactions
0376      * @return an object managing the error
0377      *   @see SKGError
0378      */
0379     SKGError getRecurrentOperations(SKGListSKGObjectBase& oRecurrentOperation) const;
0380 
0381     /**
0382      * Get the recurrent transaction ID this transaction is linked to
0383      * @return an object managing the error
0384      *   @see SKGError
0385      */
0386     int getRecurrentOperation() const;
0387 
0388     /**
0389      * Link this transaction to a particular recurrent one
0390      * @param recurrentId ID of the recurrent operation
0391      * @return an object managing the error.
0392      *   @see SKGError
0393      */
0394     SKGError setRecurrentOperation(int recurrentId);
0395 
0396     /**
0397      * Merge current transaction with another one
0398      * @param iDeletedOne after merge this transaction will be deleted
0399      * @param iMode the alignment mode
0400      * @param iSendMessage send warning message
0401      * @return an object managing the error
0402      *   @see SKGError
0403      */
0404     SKGError mergeAttribute(const SKGOperationObject& iDeletedOne, SKGOperationObject::AmountAlignmentMode iMode = SKGOperationObject::DEFAULT, bool iSendMessage = true);
0405 
0406     /**
0407      * Merge current transaction with another one
0408      * @param iDeletedOne after merge this transaction will be deleted
0409      * @return an object managing the error
0410      *   @see SKGError
0411      */
0412     SKGError mergeSuboperations(const SKGOperationObject& iDeletedOne);
0413 };
0414 /**
0415  * Declare the class
0416  */
0417 Q_DECLARE_TYPEINFO(SKGOperationObject, Q_MOVABLE_TYPE);
0418 #endif