aboutsummaryrefslogtreecommitdiff
path: root/cashflow.h
blob: c5b92c65d7111c5d31814b639c6be64f0cd4b4cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef CASHFLOW_H
#define CASHFLOW_H

#include <QMainWindow>
#include <QTableWidget>
#include <QDate>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QChart>
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QValueAxis>
#include "database.h"
#include "transaction.h"

QT_BEGIN_NAMESPACE
namespace Ui { class CashFlow; }
QT_END_NAMESPACE

class CashFlow : public QMainWindow
{
    Q_OBJECT

public:
    CashFlow(QWidget *parent = nullptr);
    ~CashFlow();

protected:
    void keyPressEvent(QKeyEvent *event) override;
    bool eventFilter(QObject *watched, QEvent *event) override;

private slots:
    void onDateRangeChanged();
    void onTransactionSelected();
    void onSaveTransaction();
    void onNewTransaction();
    void onDeleteTransaction();
    void onRecurringSelected();
    void onSaveRecurring();
    void onNewRecurring();
    void onDeleteRecurring();
    void onPeriodChanged();
    void onNewFile();
    void onOpenFile();
    void onSaveAs();
    void onExportCSV();
    void onQuit();
    void onPreferences();
    void onRecurringRuleChanged();
    void onTransactionDateChanged();
    void onCreateAdjustment();
    void onSearchTextChanged();
    void onCollapseAll();
    void onExpandAll();
    void onJumpToToday();
    void onTransactionTableDoubleClicked(int row, int column);
    
private:
    enum PeriodType {
        Daily,
        Weekly,
        Monthly,
        Quarterly
    };
    
    Ui::CashFlow *ui;
    Database *database;
    int currentTransactionId;
    int currentRecurringId;
    double startingBalance;
    QFont currentAmountFont;
    int weekStartDay;
    QString currentFilePath;
    QMap<PeriodType, QSet<int>> collapsedPeriods; // Track which period end rows are collapsed per period type
    QChartView *chartView;
    QChart *chart;
    
    void setupConnections();
    void refreshView();
    void refreshTransactionTable();
    void refreshRecurringTable();
    void refreshCharts();
    void calculateAndDisplayBalance();
    QList<Transaction> getAllTransactionsInRange();
    void clearTransactionEntry();
    void loadTransactionToEntry(const Transaction &t);
    void clearRecurringEntry();
    void loadRecurringToEntry(const RecurringRule &r);
    QDate getPeriodEnd(const QDate &date, PeriodType periodType);
    QDate getPeriodStart(const QDate &date, PeriodType periodType);
    QString getPeriodLabel(const QDate &date, PeriodType periodType, int count);
    void insertPeriodEndRow(const QString &label, double balance, const QMap<QString, double> &accountBalances, int periodId);
    void updateAmountColors();
    void loadSettings();
    QString formatCurrency(double amount) const;
    double calculateBalanceUpTo(const QDate &date, const QString &account);
    void recalculateAllReconciliations();
    bool openDatabase(const QString &filePath);
    void populateRecurringRulesCombo();
    void updateOccurrenceKey();
    QString generateOccurrenceKey(const QDate &date, RecurrenceFrequency frequency) const;
    void jumpToDateInTable(const QDate &date);
};
#endif // CASHFLOW_H