Commit df2dd777 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Add view of past money transfers

This commit introduces a new view in the database
parent 5c3d6a24
......@@ -323,6 +323,20 @@ MainWindow::MainWindow(QWidget *parent) :
setMoneyAccountValues();
setAccTransferCombo();
QSqlTableModel* transHistoryModel = new QSqlTableModel();
ui->moneyTransferHistory->setModel(transHistoryModel);
transHistoryModel->setTable("money_transfers_simple");
transHistoryModel->select();
transHistoryModel->setHeaderData(0, Qt::Horizontal, "Tid");
transHistoryModel->setHeaderData(1, Qt::Horizontal, "Från");
transHistoryModel->setHeaderData(2, Qt::Horizontal, "Till");
transHistoryModel->setHeaderData(3, Qt::Horizontal, "Summa");
transHistoryModel->setHeaderData(4, Qt::Horizontal, "Notering");
// Don't actualy try to submit on this table
transHistoryModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
ui->moneyTransferHistory->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
MainWindow::~MainWindow()
......@@ -334,6 +348,7 @@ void MainWindow::updateMoneyString()
{
setMoneyDiffLabels();
setMoneyAccountValues();
((QSqlTableModel*) ui->moneyTransferHistory->model())->select();
}
void MainWindow::setAccTransferCombo() {
......
......@@ -689,7 +689,27 @@
<string>Övrigt</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="1" rowspan="4">
<item row="3" column="3">
<widget class="QPushButton" name="openTillButton">
<property name="text">
<string>Öppna Kassan</string>
</property>
</widget>
</item>
<item row="2" column="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" rowspan="6">
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<layout class="QGridLayout" name="gridLayout_6">
......@@ -790,27 +810,7 @@
</item>
</layout>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="openTillButton">
<property name="text">
<string>Öppna Kassan</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<item row="3" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -823,6 +823,26 @@
</property>
</spacer>
</item>
<item row="1" column="2" colspan="2">
<widget class="QTreeView" name="moneyTransferHistory">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Forna Överföringar</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
......
......@@ -221,6 +221,18 @@ SELECT name,
printf("%.2f", amount / 100.0) AS amount
FROM money WHERE id != 0;
CREATE VIEW money_transfers_simple AS
SELECT
t.time AS time,
m.name AS from_acc,
n.name AS to_acc,
printf("%.2f", t.change / 100.0) AS amount,
t.note AS note
FROM money_transfers t
LEFT JOIN money m ON t.from_acc = m.id
LEFT JOIN money n ON t.to_acc = n.id
ORDER by time DESC;
-- ============================== Triggers ===============================
-- some of these would benefit from being FOR EACH STATEMENT instead of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment