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

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 SKGCATEGORYOBJECT_H
0007 #define SKGCATEGORYOBJECT_H
0008 /** @file
0009  * This file defines classes SKGCategoryObject.
0010  *
0011  * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 
0014 #include "skgbankmodeler_export.h"
0015 #include "skgnamedobject.h"
0016 class SKGDocumentBank;
0017 /**
0018  * This class manages category object
0019  */
0020 class SKGBANKMODELER_EXPORT SKGCategoryObject final : public SKGNamedObject
0021 {
0022 public:
0023     /**
0024      * Default constructor
0025      */
0026     explicit SKGCategoryObject();
0027 
0028     /**
0029      * Constructor
0030      * @param iDocument the document containing the object
0031      * @param iID the identifier in @p iTable of the object
0032      */
0033     explicit SKGCategoryObject(SKGDocument* iDocument, int iID = 0);
0034 
0035     /**
0036      * Copy constructor
0037      * @param iObject the object to copy
0038      */
0039     SKGCategoryObject(const SKGCategoryObject& iObject);
0040 
0041     /**
0042      * Copy constructor
0043      * @param iObject the object to copy
0044      */
0045     explicit SKGCategoryObject(const SKGObjectBase& iObject);
0046 
0047     /**
0048      * Operator affectation
0049      * @param iObject the object to copy
0050      */
0051     SKGCategoryObject& operator= (const SKGObjectBase& iObject);
0052 
0053     /**
0054      * Operator affectation
0055      * @param iObject the object to copy
0056      */
0057     SKGCategoryObject& operator= (const SKGCategoryObject& iObject);
0058 
0059     /**
0060      * Destructor
0061      */
0062     virtual ~SKGCategoryObject();
0063 
0064     /**
0065      * Create a category branch if needed and return the leaf of the branch
0066      * @param iDocument the document where to create
0067      * @param iFullPath the full path. Example: cat1 > cat2 > cat3
0068      * @param oCategory the leaf of the branch
0069      * @param iSendPopupMessageOnCreation to send a creation message if the category is created
0070      * @param iRenameIfAlreadyExist if a leaf with the expected name already exist than the leaf will be renamed and created
0071      * @return an object managing the error.
0072      *   @see SKGError
0073      */
0074     static SKGError createPathCategory(SKGDocumentBank* iDocument,
0075                                        const QString& iFullPath,
0076                                        SKGCategoryObject& oCategory,
0077                                        bool iSendPopupMessageOnCreation = false,
0078                                        bool iRenameIfAlreadyExist = false);
0079 
0080     /**
0081      * Set the name of this object
0082      * @param iName the name
0083      * @return an object managing the error
0084      *   @see SKGError
0085      */
0086     SKGError setName(const QString& iName) override;
0087 
0088     /**
0089      * To bookmark or not a category
0090      * @param iBookmark the bookmark: true or false
0091      * @return an object managing the error
0092      *   @see SKGError
0093      */
0094     SKGError bookmark(bool iBookmark);
0095 
0096     /**
0097      * To know if the category is bookmarked
0098      * @return an object managing the error
0099      *   @see SKGError
0100      */
0101     bool isBookmarked() const;
0102 
0103     /**
0104      * To set the closed attribute of a payee
0105      * @param iClosed the closed attribute: true or false
0106      * @return an object managing the error
0107      *   @see SKGError
0108      */
0109     virtual SKGError setClosed(bool iClosed);
0110 
0111     /**
0112      * To know if the payee has been closed or not
0113      * @return an object managing the error
0114      *   @see SKGError
0115      */
0116     virtual bool isClosed() const;
0117 
0118     /**
0119      * Get the full name of this category.
0120      * The full name is the unique name of the category.
0121      * It is computed by the concatenation of names for all
0122      * the fathers of this category.
0123      * @return the full name
0124      */
0125     QString getFullName() const;
0126 
0127     /**
0128      * Add a category
0129      * @param oCategory the created category
0130      * @return an object managing the error.
0131      *   @see SKGError
0132      */
0133     SKGError addCategory(SKGCategoryObject& oCategory);
0134 
0135     /**
0136      * Move the category by changing the parent
0137      * @param iCategory the parent category
0138      * @return an object managing the error.
0139      *   @see SKGError
0140      */
0141     SKGError setParentCategory(const SKGCategoryObject& iCategory);
0142 
0143     /**
0144      * Remove the parent category. The category will be a root.
0145      * @return an object managing the error.
0146      *   @see SKGError
0147      */
0148     SKGError removeParentCategory();
0149 
0150     /**
0151      * Get the parent category
0152      * @param oCategory the parent category
0153      * @return an object managing the error.
0154      *   @see SKGError
0155      */
0156     SKGError getParentCategory(SKGCategoryObject& oCategory) const;
0157 
0158     /**
0159      * Get the root category
0160      * @param oCategory the root category
0161      * @return an object managing the error.
0162      *   @see SKGError
0163      */
0164     SKGError getRootCategory(SKGCategoryObject& oCategory) const;
0165 
0166     /**
0167      * Get categories
0168      * @param oCategoryList the list of categories under the current one
0169      * @return an object managing the error
0170      *   @see SKGError
0171      */
0172     SKGError getCategories(SKGListSKGObjectBase& oCategoryList) const;
0173 
0174     /**
0175      * Get the current amount
0176      * @return the current amount
0177      */
0178     double getCurrentAmount() const;
0179 
0180     /**
0181      * Get all sub transactions of this category
0182      * @param oSubOperations all sub transactions of this category
0183      * @return an object managing the error
0184      *   @see SKGError
0185      */
0186     SKGError getSubOperations(SKGListSKGObjectBase& oSubOperations) const;
0187 
0188     /**
0189      * Merge iCategory in current category
0190      * @param iCategory the category. All sub transactions will be transferred into this category. The category will be removed
0191      * @return an object managing the error
0192      *   @see SKGError
0193      */
0194     SKGError merge(const SKGCategoryObject& iCategory);
0195 
0196 protected:
0197     /**
0198      * Get where clause needed to identify objects.
0199      * For this class, the whereclause is based on name + rd_category_id
0200      * @return the where clause
0201      */
0202     QString getWhereclauseId() const override;
0203 };
0204 /**
0205  * Declare the class
0206  */
0207 Q_DECLARE_TYPEINFO(SKGCategoryObject, Q_MOVABLE_TYPE);
0208 #endif