File indexing completed on 2024-05-19 05:07:25

0001 /*
0002     SPDX-FileCopyrightText: 2002-2003 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002-2016 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-FileCopyrightText: 2002 Kevin Tambascio <ktambascio@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef MYMONEYUTILS_H
0010 #define MYMONEYUTILS_H
0011 
0012 #include "kmm_mymoney_export.h"
0013 
0014 // ----------------------------------------------------------------------------
0015 // QT Includes
0016 
0017 #include <QLocale>
0018 #include <QString>
0019 class QDate;
0020 class QProcess;
0021 
0022 // ----------------------------------------------------------------------------
0023 // KDE Includes
0024 
0025 // ----------------------------------------------------------------------------
0026 // Project Includes
0027 
0028 #include "mymoneyenums.h"
0029 
0030 class MyMoneyAccount;
0031 class MyMoneyMoney;
0032 class MyMoneySecurity;
0033 class MyMoneySplit;
0034 class MyMoneyTransaction;
0035 
0036 typedef enum {
0037     NoWarning = 0,
0038     OneSplitReconciled,
0039     OneSplitFrozen,
0040     OneAccountClosed,
0041 } modifyTransactionWarnLevel_t;
0042 
0043 namespace MyMoneyUtils
0044 {
0045 KMM_MYMONEY_EXPORT QString getFileExtension(QString strFileName);
0046 
0047 /**
0048  * This is a convenience method. It behaves exactly as
0049  * MyMoneyMoney::formatMoney, but takes the information
0050  * about currency symbol and precision out of the MyMoneySecurity
0051  * and MyMoneyAccount objects @a acc and @a sec. The value to be
0052  * formatted is passed as @a val.
0053  */
0054 KMM_MYMONEY_EXPORT QString formatMoney(const MyMoneyMoney& val,
0055                                        const MyMoneyAccount& acc,
0056                                        const MyMoneySecurity& sec,
0057                                        bool showThousandSeparator = true);
0058 
0059 /**
0060  * This is a convenience method. It behaves exactly as the above one,
0061  * but takes the information about currency symbol and precision out
0062  * of the MyMoneySecurity object @a sec.  The value to be
0063  * formatted is passed as @a val.
0064  */
0065 KMM_MYMONEY_EXPORT QString formatMoney(const MyMoneyMoney& val,
0066                                        const MyMoneySecurity& sec,
0067                                        bool showThousandSeparator = true);
0068 
0069 /**
0070  * This function returns a date in the form specified by Qt::ISODate.
0071  * If the @p date is invalid an empty string will be returned.
0072  *
0073  * @param date const reference to date to be converted
0074  * @return QString containing the converted date
0075  */
0076 KMM_MYMONEY_EXPORT QString dateToString(const QDate& date);
0077 
0078 /**
0079  * This function returns a date as QDate object as specified by
0080  * the parameter @p str. @p str must be in Qt::ISODate format.
0081  * If @p str is empty or contains an invalid date, QDate() is
0082  * returned.
0083  *
0084  * @param str date in Qt::ISODate format
0085  * @return QDate object
0086  */
0087 KMM_MYMONEY_EXPORT QDate stringToDate(const QString& str);
0088 
0089 /**
0090  * This function returns a timestamp in the form specified by IS08601.
0091  * If the @p date is invalid an empty string will be returned.
0092  *
0093  * @param date const reference to date to be converted
0094  * @return QString containing the converted date
0095  */
0096 KMM_MYMONEY_EXPORT QString dateTimeToString(const QDateTime& dateTime);
0097 
0098 /**
0099  * This function returns date and time as QDateTime object as specified by
0100  * the parameter @a str. @a str must be in Qt::ISODate format. If @a str
0101  * only contains a date, the time will be set to 00:00:00 and the timezone
0102  * is localtime.
0103  *
0104  * If @a str is empty or contains an invalid date, QDateTime() is
0105  * returned.
0106  *
0107  * @param str date in Qt::ISODate format
0108  * @return QDateTime object
0109  */
0110 KMM_MYMONEY_EXPORT QDateTime stringToDateTime(const QString& str);
0111 
0112 KMM_MYMONEY_EXPORT QString QStringEmpty(const QString&);
0113 
0114 KMM_MYMONEY_EXPORT unsigned long extractId(const QString& txt);
0115 
0116 KMM_MYMONEY_EXPORT void dissectTransaction(const MyMoneyTransaction& transaction, const MyMoneySplit& split, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency, eMyMoney::Split::InvestmentTransactionType& transactionType);
0117 
0118 KMM_MYMONEY_EXPORT void clearFormatCaches();
0119 KMM_MYMONEY_EXPORT QString formatDate(const QDate& date, QLocale::FormatType formatType = QLocale::ShortFormat);
0120 KMM_MYMONEY_EXPORT QString formatTime(const QTime& date);
0121 KMM_MYMONEY_EXPORT QString formatDateTime(const QDateTime& date);
0122 
0123 /**
0124  * This method is used to convert the payment type from its
0125  * internal representation into a human readable format.
0126  *
0127  * @param paymentType numerical representation of the MyMoneySchedule
0128  *                  payment type
0129  *
0130  * @return QString representing the human readable format translated according to the language catalog
0131  *
0132  * @sa MyMoneySchedule::paymentMethodToString()
0133  */
0134 KMM_MYMONEY_EXPORT QString paymentMethodToString(eMyMoney::Schedule::PaymentType paymentType);
0135 
0136 KMM_MYMONEY_EXPORT QString convertWildcardToRegularExpression(const QString& pattern);
0137 KMM_MYMONEY_EXPORT QString convertRegularExpressionToWildcard(const QString& pattern);
0138 
0139 KMM_MYMONEY_EXPORT modifyTransactionWarnLevel_t transactionWarnLevel(const QString& transactionId);
0140 KMM_MYMONEY_EXPORT modifyTransactionWarnLevel_t transactionWarnLevel(const QStringList& transactionIds);
0141 }
0142 
0143 #endif