Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Stupan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Hugo Hörnquist
Stupan
Commits
0775f548
Commit
0775f548
authored
Sep 16, 2018
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add account select to money diff.
parent
a6b8efbe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
22 deletions
+61
-22
admin/mainwindow.cpp
admin/mainwindow.cpp
+50
-19
admin/mainwindow.h
admin/mainwindow.h
+7
-2
admin/mainwindow.ui
admin/mainwindow.ui
+4
-1
No files found.
admin/mainwindow.cpp
View file @
0775f548
...
...
@@ -242,14 +242,7 @@ MainWindow::MainWindow(QWidget *parent) :
acView
->
horizontalHeader
()
->
setSectionResizeMode
(
QHeaderView
::
ResizeToContents
);
acView
->
horizontalHeader
()
->
setSectionResizeMode
(
1
,
QHeaderView
::
Stretch
);
// TODO this combo box isn't updated when new accounts are added.
ui
->
submitBuyAccountCombo
->
clear
();
QSqlQuery
accQuery
(
"SELECT id, name FROM money WHERE amount IS NOT NULL"
);
while
(
accQuery
.
next
())
{
QString
name
=
accQuery
.
value
(
1
).
toString
();
QVariant
value
=
accQuery
.
value
(
0
);
ui
->
submitBuyAccountCombo
->
addItem
(
name
,
value
);
}
populateMoneyComboBox
(
ui
->
submitBuyAccountCombo
);
// We usually want the "Vault" account. So we select it by default.
ui
->
submitBuyAccountCombo
->
setCurrentIndex
(
1
);
...
...
@@ -290,10 +283,12 @@ MainWindow::MainWindow(QWidget *parent) :
// -------------- Money Check -----------------------
setMoneyDiffLabels
();
ui
->
diffDrawer
->
setValidator
(
anyIntVal
);
populateMoneyComboBox
(
ui
->
moneyDiffCombo
);
ui
->
moneyDiffCombo
->
setCurrentIndex
(
0
);
setMoneyDiffLabels
();
// ============== Drainage ==========================
// TODO some of these things possibly should requery under usage
...
...
@@ -402,6 +397,18 @@ void MainWindow::setAccTransferCombo() {
}
}
void
MainWindow
::
populateMoneyComboBox
(
QComboBox
*
box
)
{
// TODO this combo box isn't updated when new accounts are added.
box
->
clear
();
QSqlQuery
accQuery
(
"SELECT id, name FROM money WHERE amount IS NOT NULL"
);
while
(
accQuery
.
next
())
{
QString
name
=
accQuery
.
value
(
1
).
toString
();
QVariant
value
=
accQuery
.
value
(
0
);
box
->
addItem
(
name
,
value
);
}
}
void
MainWindow
::
setMoneyAccountValues
()
{
QSqlTableModel
*
accModel
=
(
QSqlTableModel
*
)
ui
->
accTreeView
->
model
();
...
...
@@ -747,14 +754,17 @@ void MainWindow::on_stockRefreshButton_clicked()
void
MainWindow
::
on_diffSubmit_clicked
()
{
// TODO this doesn't update the money menu
QString
str
=
ui
->
diffDrawer
->
text
();
if
(
str
==
""
)
return
;
int
total
=
str
.
toInt
()
*
100
;
QSqlQuery
query
;
query
.
prepare
(
"INSERT INTO money_diffs (actual, expected, account) "
"SELECT :total, amount, id "
"
FROM money WHERE name = 'Cash Drawer'
"
);
"
FROM money WHERE id = :id
"
);
query
.
bindValue
(
":total"
,
total
);
query
.
bindValue
(
":id"
,
ui
->
moneyDiffCombo
->
currentData
());
if
(
!
query
.
exec
())
qDebug
()
<<
query
.
lastError
();
...
...
@@ -766,7 +776,7 @@ void MainWindow::on_diffSubmit_clicked()
void
MainWindow
::
on_diffDrawer_textChanged
(
const
QString
&
arg1
)
{
int
new_total
=
arg1
.
toInt
()
*
100
;
setMoneyDiffLabels
(
new_total
);
setMoneyDiffLabels
(
ui
->
moneyDiffCombo
->
currentData
(),
new_total
);
}
void
MainWindow
::
on_submitStockDiff_clicked
()
...
...
@@ -775,12 +785,27 @@ void MainWindow::on_submitStockDiff_clicked()
((
QSqlRelationalTableModel
*
)
ui
->
inventoryCheckView
->
model
())
->
select
();
}
int
MainWindow
::
setMoneyDiffLabels
()
void
MainWindow
::
setMoneyDiffLabels
()
{
QSqlQuery
query
(
"SELECT amount FROM money WHERE name = 'Cash Drawer'"
);
query
.
next
();
int
expected
=
query
.
value
(
0
).
toInt
();
QString
diff_text
=
QString
(
"%1 kr"
).
arg
(
expected
/
100.0
,
0
,
'f'
,
2
);
setMoneyDiffLabels
(
ui
->
moneyDiffCombo
->
currentData
());
}
int
MainWindow
::
setMoneyDiffLabels
(
QVariant
accountId
)
{
QSqlQuery
query
;
query
.
prepare
(
"SELECT amount FROM money WHERE id = :id"
);
query
.
bindValue
(
":id"
,
accountId
);
query
.
exec
();
QString
diff_text
;
int
expected
;
if
(
query
.
next
())
{
expected
=
query
.
value
(
0
).
toInt
();
diff_text
=
QString
(
"%1 kr"
).
arg
(
expected
/
100.0
,
0
,
'f'
,
2
);
}
else
{
qDebug
()
<<
query
.
lastError
();
return
-
1
;
}
// This might seem like a mistake at first sight, though it isn't.
// This just sets a default value for diffTotal. The new value is
...
...
@@ -792,9 +817,9 @@ int MainWindow::setMoneyDiffLabels()
return
expected
;
}
void
MainWindow
::
setMoneyDiffLabels
(
int
new_total
)
void
MainWindow
::
setMoneyDiffLabels
(
QVariant
accountId
,
int
new_total
)
{
double
diff
=
new_total
-
setMoneyDiffLabels
();
double
diff
=
new_total
-
setMoneyDiffLabels
(
accountId
);
ui
->
diffTotal
->
setText
(
QString
(
"%1 kr"
).
arg
(
diff
/
100.0
,
0
,
'f'
,
2
));
}
...
...
@@ -1110,3 +1135,9 @@ void MainWindow::on_sqlBufferDeleteButton_clicked()
model
->
select
();
}
void
MainWindow
::
on_moneyDiffCombo_currentIndexChanged
(
int
index
)
{
setMoneyDiffLabels
();
ui
->
diffDrawer
->
setText
(
""
);
}
admin/mainwindow.h
View file @
0775f548
...
...
@@ -6,6 +6,7 @@
#include <QSqlRelationalTableModel>
#include <QTableView>
#include <QPrinter>
#include <QComboBox>
#include "disablingmodel.h"
...
...
@@ -100,6 +101,8 @@ private slots:
void
on_sqlBufferDeleteButton_clicked
();
void
on_moneyDiffCombo_currentIndexChanged
(
int
index
);
private:
Ui
::
MainWindow
*
ui
;
QSqlTableModel
*
model
;
...
...
@@ -108,8 +111,9 @@ private:
char
*
port_name
;
void
updateMoneyString
();
void
setMoneyDiffLabels
(
int
);
int
setMoneyDiffLabels
();
void
setMoneyDiffLabels
(
QVariant
,
int
);
int
setMoneyDiffLabels
(
QVariant
);
void
setMoneyDiffLabels
();
void
transferMoney
(
QString
from
,
QString
to
,
int
amount
,
QString
message
);
void
transferMoney
(
QString
from
,
QString
to
,
int
amount
);
void
updateDrainageView
();
...
...
@@ -120,6 +124,7 @@ private:
void
clear_stockDiffTemp
();
void
setProductFilter
();
void
setMoneyAccountValues
();
void
populateMoneyComboBox
(
QComboBox
*
box
);
void
setSqlQuery
(
qlonglong
id
);
void
setSqlQuery
(
QString
name
);
...
...
admin/mainwindow.ui
View file @
0775f548
...
...
@@ -357,10 +357,13 @@
<item>
<widget
class=
"QLabel"
name=
"label_11"
>
<property
name=
"text"
>
<string>
Kass
adiff:
</string>
<string>
Peng
adiff:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QComboBox"
name=
"moneyDiffCombo"
/>
</item>
<item>
<spacer
name=
"horizontalSpacer_5"
>
<property
name=
"orientation"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment