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

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 SKGREPORTBANK_H
0007 #define SKGREPORTBANK_H
0008 /** @file
0009  * A report class for bank document
0010 *
0011 * @author Stephane MANKOWSKI
0012 */
0013 #include <qvariant.h>
0014 
0015 #include "skgbankmodeler_export.h"
0016 #include "skgerror.h"
0017 #include "skgreport.h"
0018 #include "skgunitobject.h"
0019 
0020 class SKGDocument;
0021 /**
0022  * A report class for bank document
0023  */
0024 class SKGBANKMODELER_EXPORT SKGReportBank : public SKGReport
0025 {
0026     Q_OBJECT
0027     /**
0028      * The budget table
0029      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0030      */
0031     Q_PROPERTY(QVariantList budget_table READ getBudgetTable NOTIFY changed2)
0032 
0033     /**
0034      * The unit table
0035      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0036      */
0037     Q_PROPERTY(QVariantList unit_table READ getUnitTable NOTIFY changed2)
0038 
0039     /**
0040      * The portfolio
0041      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0042      */
0043     Q_PROPERTY(QVariantList portfolio READ getPortfolio NOTIFY changed2)
0044 
0045     /**
0046      * The account table
0047      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0048      */
0049     Q_PROPERTY(QVariantList account_table READ getAccountTable NOTIFY changed2)
0050 
0051     /**
0052      * The bank table
0053      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0054      */
0055     Q_PROPERTY(QVariantList bank_table READ getBankTable NOTIFY changed2)
0056 
0057     /**
0058      * The alarms
0059      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0060      */
0061     Q_PROPERTY(QVariantList alarms READ getAlarms NOTIFY changed2)
0062 
0063     /**
0064      * The interests
0065      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0066      */
0067     Q_PROPERTY(QVariantList interests READ getInterests NOTIFY changed2)
0068 
0069     /**
0070      * The scheduled transactions
0071      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0072      */
0073     Q_PROPERTY(QVariantList scheduled_operations READ getScheduledOperations NOTIFY changed2)
0074 
0075     /**
0076      * The main categories of the period
0077      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0078      */
0079     Q_PROPERTY(QVariantList categories_period READ getMainCategoriesForPeriod NOTIFY changed2)
0080 
0081     /**
0082      * The main categories of the previous period
0083      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0084      */
0085     Q_PROPERTY(QVariantList categories_previous_period READ getMainCategoriesForPreviousPeriod NOTIFY changed2)
0086 
0087     /**
0088      * The main categories of the period (for compatibility)
0089      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0090      */
0091     Q_PROPERTY(QVariantList categories_month READ getMainCategoriesForPeriod NOTIFY changed2)
0092 
0093     /**
0094      * The main categories of the previous period (for compatibility)
0095      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0096      */
0097     Q_PROPERTY(QVariantList categories_previous_month READ getMainCategoriesForPreviousPeriod NOTIFY changed2)
0098 
0099     /**
0100      * The income versus expenditure
0101      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0102      */
0103     Q_PROPERTY(QVariantList income_vs_expenditure READ getIncomeVsExpenditure NOTIFY changed2)
0104 
0105     /**
0106      * The net worth
0107      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0108      */
0109     Q_PROPERTY(double networth READ getNetWorth NOTIFY changed2)
0110 
0111     /**
0112      * The annual spending
0113      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0114      */
0115     Q_PROPERTY(double annual_spending READ getAnnualSpending NOTIFY changed2)
0116 
0117     /**
0118      * The personal finance score
0119      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0120      */
0121     Q_PROPERTY(double personal_finance_score READ getPersonalFinanceScore NOTIFY changed2)
0122 
0123     /**
0124      * The personal finance score details
0125      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0126      */
0127     Q_PROPERTY(QVariantMap personal_finance_score_details READ getPersonalFinanceScoreDetails NOTIFY changed2)
0128 
0129     /**
0130      * The main categories variations
0131      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0132      */
0133     Q_PROPERTY(QStringList categories_variations READ get5MainCategoriesVariation NOTIFY changed2)
0134 
0135     /**
0136      * The main categories variations which are issues (expenditure increasing or incomes decreasing
0137      * WARNING: Notification is launched only when cleanCache or setPeriod are called. So do not forget to connect cleanCache with SKGDocument::transactionSuccessfullyEnded
0138      */
0139     Q_PROPERTY(QStringList categories_variations_issues READ get5MainCategoriesVariationIssue NOTIFY changed2)
0140 
0141 public:
0142     /**
0143      * Default Constructor
0144      */
0145     explicit SKGReportBank(SKGDocument* iDocument);
0146 
0147     /**
0148      * Default Destructor
0149      */
0150     virtual ~SKGReportBank() override;
0151 
0152     /**
0153      * Get the budget table
0154      * @return the budget table
0155      */
0156     Q_INVOKABLE virtual QVariantList getBudgetTable();
0157 
0158     /**
0159      * Get the unit table
0160      * @return the unit table
0161      */
0162     Q_INVOKABLE virtual QVariantList getUnitTable();
0163 
0164     /**
0165      * Get the portfolio
0166      * @return the portfolio
0167      */
0168     Q_INVOKABLE virtual QVariantList getPortfolio();
0169 
0170     /**
0171      * Get the account table
0172      * @return the account table
0173      */
0174     Q_INVOKABLE virtual QVariantList getAccountTable();
0175 
0176     /**
0177      * Get the bank table
0178      * @return the bank table
0179      */
0180     Q_INVOKABLE virtual QVariantList getBankTable();
0181 
0182     /**
0183      * Get the scheduled transactions
0184      * Parameters supported:
0185      *    scheduled_operation_days_max: number max of days displayed (default: 30)
0186      * @return the scheduled transactions
0187      */
0188     Q_INVOKABLE virtual QVariantList getScheduledOperations();
0189 
0190     /**
0191      * Get the main categories of the period
0192      * @return the main categories of the period
0193      */
0194     Q_INVOKABLE virtual QVariantList getMainCategoriesForPeriod();
0195 
0196     /**
0197      * Get the main categories of the previous period
0198      * @return the main categories of the previous period
0199      */
0200     Q_INVOKABLE virtual QVariantList getMainCategoriesForPreviousPeriod();
0201 
0202     /**
0203      * Get the main categories variations
0204      * @return the main categories variations
0205      */
0206     Q_INVOKABLE virtual QStringList get5MainCategoriesVariation();
0207 
0208     /**
0209      * Get the main categories variations which are issues (expenditure increasing or incomes decreasing)
0210      * @return the main categories variations
0211      */
0212     Q_INVOKABLE virtual QStringList get5MainCategoriesVariationIssue();
0213 
0214     /**
0215      * Get the income versus expenditure
0216      * @param iOnSubOperation the computation is done on sub operation
0217      * @param iGrouped the computation includes grouped (sub) operation
0218      * @param iTransfer the computation includes Transfers
0219      * @param iTracker the computation includes tracked transactions
0220      * @param iWhereClause1 the period where clause (if empty then use the period of the report)
0221      * @param iWhereClause2 the period where clause (if empty then use the previous period of the report)
0222      * @return the income versus expenditure
0223      */
0224     Q_INVOKABLE virtual QVariantList getIncomeVsExpenditure(bool iOnSubOperation = true,
0225             bool iGrouped = true,
0226             bool iTransfer = false,
0227             bool iTracker = true,
0228             const QString& iWhereClause1 = QString(),
0229             const QString& iWhereClause2 = QString());
0230 
0231     /**
0232      * Get the net worth
0233      * @param iTransfer the computation includes Transfers
0234      * @param iTracker the computation includes tracked transactions
0235      * @return the net worth
0236      */
0237     Q_INVOKABLE virtual double getNetWorth(bool iTransfer = false, bool iTracker = true);
0238 
0239     /**
0240      * Get the annual spending
0241      * @param iTransfer the computation includes Transfers
0242      * @param iTracker the computation includes tracked transactions
0243      * @return the annual spending
0244      */
0245     Q_INVOKABLE virtual double getAnnualSpending(bool iTransfer = false, bool iTracker = true);
0246 
0247     /**
0248      * Get the personal finance score (https://jlyblog.wordpress.com/2013/10/13/the-new-score-that-outweighs-your-credit-score/)
0249      * @param iTransfer the computation includes Transfers
0250      * @param iTracker the computation includes tracked transactions
0251      * @return the personal finance score
0252      */
0253     Q_INVOKABLE virtual double getPersonalFinanceScore(bool iTransfer = false, bool iTracker = true);
0254 
0255     /**
0256      * Get the personal finance score (https://jlyblog.wordpress.com/2013/10/13/the-new-score-that-outweighs-your-credit-score/)
0257      * @param iTransfer the computation includes Transfers
0258      * @param iTracker the computation includes tracked transactions
0259      * @return the personal finance score + (success, warning or danger) + advice string + color
0260      */
0261     Q_INVOKABLE virtual QVariantMap getPersonalFinanceScoreDetails(bool iTransfer = false, bool iTracker = true);
0262 
0263     /**
0264      * Get the alarms
0265      * @return the alarms
0266      */
0267     Q_INVOKABLE virtual QVariantList getAlarms();
0268 
0269     /**
0270      * Get the interests
0271      * @return the interests
0272      */
0273     Q_INVOKABLE virtual QVariantList getInterests();
0274 
0275 Q_SIGNALS:
0276     /**
0277      * Emitted when the report changed
0278      */
0279     void changed2();
0280 
0281 protected:
0282     /**
0283      * Enrich the grantlee mapping
0284      * @param iMapping the mapping
0285      */
0286     void addItemsInMapping(QVariantHash& iMapping) override;
0287 
0288 private:
0289     Q_DISABLE_COPY(SKGReportBank)
0290 
0291     struct unitValues {
0292         SKGUnitObject unit;
0293         double initalAmount{};
0294         double purchaseAmount{};
0295         double currentAmount{};
0296         double quantity{};
0297     };
0298 };
0299 
0300 /**
0301  * Declare the class
0302  */
0303 Q_DECLARE_TYPEINFO(SKGReportBank, Q_MOVABLE_TYPE);
0304 #endif  // SKGREPORTBANK_H