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

0001 /*
0002     SPDX-FileCopyrightText: 2000-2002 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2001-2017 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-FileCopyrightText: 2001 Felix Rodriguez <frodriguez@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2003 Kevin Tambascio <ktambascio@users.sourceforge.net>
0006     SPDX-FileCopyrightText: 2004-2005 Ace Jones <acejones@users.sourceforge.net>
0007     SPDX-FileCopyrightText: 2006 Darren Gould <darren_gould@gmx.de>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef MYMONEYTRANSACTION_P_H
0012 #define MYMONEYTRANSACTION_P_H
0013 
0014 // ----------------------------------------------------------------------------
0015 // QT Includes
0016 
0017 #include <QDate>
0018 #include <QHash>
0019 #include <QList>
0020 #include <QSet>
0021 #include <QString>
0022 
0023 // ----------------------------------------------------------------------------
0024 // Project Includes
0025 
0026 #include "mymoneyobject_p.h"
0027 #include "mymoneysplit.h"
0028 
0029 using namespace eMyMoney;
0030 
0031 class MyMoneyTransactionPrivate : public MyMoneyObjectPrivate
0032 {
0033 public:
0034     /**
0035       * This method returns the next id to be used for a split
0036       */
0037     QString nextSplitID()
0038     {
0039         int lastIdUsed(0);
0040         for (const auto& split : qAsConst(m_splits)) {
0041             const int id = split.id().midRef(1).toInt();
0042             if (id > lastIdUsed) {
0043                 lastIdUsed = id;
0044             }
0045         }
0046 
0047         return QStringLiteral("S%1").arg(lastIdUsed + 1, SPLIT_ID_SIZE, 10, QLatin1Char('0'));
0048     }
0049 
0050     void collectReferencedObjects() override
0051     {
0052         m_referencedObjects.insert(m_commodity);
0053         for (const auto& split : qAsConst(m_splits)) {
0054             m_referencedObjects.unite(split.referencedObjects());
0055         }
0056     }
0057 
0058     static const int SPLIT_ID_SIZE = 4;
0059     /** constants for unique sort key */
0060     static const int YEAR_SIZE = 4;
0061     static const int MONTH_SIZE = 2;
0062     static const int DAY_SIZE = 2;
0063 
0064     /**
0065       * This member contains the date when the transaction was entered
0066       * into the engine
0067       */
0068     QDate m_entryDate;
0069 
0070     /**
0071       * This member contains the date the transaction was posted
0072       */
0073     QDate m_postDate;
0074 
0075     /**
0076       * This member keeps the memo text associated with this transaction
0077       */
0078     QString m_memo;
0079 
0080     /**
0081       * This member contains the splits for this transaction
0082       */
0083     QList<MyMoneySplit> m_splits;
0084 
0085     /**
0086       * This member keeps the base commodity (e.g. currency) for this transaction
0087       */
0088     QString  m_commodity;
0089 
0090     /**
0091       * This member keeps the bank's unique ID for the transaction, so we can
0092       * avoid duplicates.  This is only used for electronic statement downloads.
0093       *
0094       * Note this is now deprecated!  Bank ID's should be set on splits, not transactions.
0095       */
0096     QString m_bankID;
0097 
0098 };
0099 
0100 #endif