Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hugo Hörnquist
Stupan
Commits
a14ca471
Commit
a14ca471
authored
Apr 13, 2018
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'money'
parents
58e3f544
b86fbb25
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
271 additions
and
344 deletions
+271
-344
admin/mainwindow.cpp
admin/mainwindow.cpp
+127
-104
admin/mainwindow.h
admin/mainwindow.h
+12
-4
admin/mainwindow.ui
admin/mainwindow.ui
+115
-236
create-db.sql
create-db.sql
+17
-0
No files found.
admin/mainwindow.cpp
View file @
a14ca471
...
...
@@ -312,12 +312,33 @@ MainWindow::MainWindow(QWidget *parent) :
// ==================================================
QIntValidator
*
pIntVal
=
new
QIntValidator
(
0
,
INT_MAX
);
ui
->
moneyMoveAmount
->
setValidator
(
pIntVal
);
ui
->
addMoneyEdit
->
setValidator
(
pIntVal
);
updateMoneyString
();
setStockValues
();
QSqlTableModel
*
accModel
=
new
QSqlTableModel
();
ui
->
accTreeView
->
setModel
(
accModel
);
accModel
->
setTable
(
"money_simple"
);
accModel
->
select
();
accModel
->
setHeaderData
(
0
,
Qt
::
Horizontal
,
"Namn"
);
accModel
->
setHeaderData
(
1
,
Qt
::
Horizontal
,
"Kronor"
);
// Don't actualy try to submit on this table
accModel
->
setEditStrategy
(
QSqlTableModel
::
OnManualSubmit
);
ui
->
accTreeView
->
header
()
->
setSectionResizeMode
(
QHeaderView
::
ResizeToContents
);
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
()
...
...
@@ -325,6 +346,43 @@ MainWindow::~MainWindow()
delete
ui
;
}
void
MainWindow
::
updateMoneyString
()
{
setMoneyDiffLabels
();
setMoneyAccountValues
();
((
QSqlTableModel
*
)
ui
->
moneyTransferHistory
->
model
())
->
select
();
}
void
MainWindow
::
setAccTransferCombo
()
{
ui
->
accTransferFrom
->
clear
();
ui
->
accTransferTo
->
clear
();
QSqlQuery
accQuery
(
"SELECT id, name FROM money"
);
while
(
accQuery
.
next
())
{
ui
->
accTransferFrom
->
addItem
(
accQuery
.
value
(
1
).
toString
(),
accQuery
.
value
(
0
));
ui
->
accTransferTo
->
addItem
(
accQuery
.
value
(
1
).
toString
(),
accQuery
.
value
(
0
));
}
}
void
MainWindow
::
setMoneyAccountValues
()
{
QSqlTableModel
*
accModel
=
(
QSqlTableModel
*
)
ui
->
accTreeView
->
model
();
accModel
->
select
();
QSqlRecord
rec
=
accModel
->
record
();
rec
.
setValue
(
"name"
,
QVariant
(
"Lager (projicerat)"
));
rec
.
setValue
(
"amount"
,
QVariant
(
QString
(
"%1"
).
arg
(
get_projected_stock_value
().
toDouble
()
/
100.0
,
0
,
'f'
,
2
)));
accModel
->
insertRecord
(
-
1
,
rec
);
rec
.
setValue
(
"name"
,
QVariant
(
"Lager (inköp)"
));
rec
.
setValue
(
"amount"
,
QVariant
(
QString
(
"%1"
).
arg
(
get_acquistion_stock_value
().
toDouble
()
/
100.0
,
0
,
'f'
,
2
)));
accModel
->
insertRecord
(
-
1
,
rec
);
}
/*
* This updates the QSqlTableModel to contain the same data as the database.
* This is needed since it looks at a view, and can therefore not find the
...
...
@@ -480,93 +538,6 @@ void MainWindow::on_buyRemoveButton_clicked()
tempAcquisitionsModel
->
select
();
}
void
MainWindow
::
updateMoneyString
()
{
QSqlQuery
query
(
"SELECT name, amount / 100.0 "
"FROM money "
"WHERE name in ('Cash Drawer', 'Vault') "
"ORDER BY name ASC"
);
// TODO also push the names from db to gui
query
.
next
();
ui
->
drawerLabel
->
setText
(
QString
(
"%1"
).
arg
(
query
.
value
(
1
).
toDouble
(),
0
,
'f'
,
2
));
query
.
next
();
ui
->
vaultLabel
->
setText
(
QString
(
"%1"
).
arg
(
query
.
value
(
1
).
toDouble
(),
0
,
'f'
,
2
));
}
void
MainWindow
::
on_toVaultButton_clicked
()
{
toVaultDrawer_shared
(
CASH_ACCOUNT
,
VAULT_ACCOUNT
);
}
void
MainWindow
::
on_toDrawerButton_clicked
()
{
toVaultDrawer_shared
(
VAULT_ACCOUNT
,
CASH_ACCOUNT
);
}
void
MainWindow
::
toVaultDrawer_shared
(
QString
from
,
QString
to
)
{
int
amount
=
ui
->
moneyMoveAmount
->
text
().
toInt
();
transferMoney
(
from
,
to
,
amount
);
ui
->
moneyMoveAmount
->
setText
(
""
);
updateMoneyString
();
}
void
MainWindow
::
transferMoney
(
QString
from
,
QString
to
,
int
amount
,
QString
message
)
{
if
((
from
==
""
&&
to
==
""
)
||
amount
==
0
)
return
;
QSqlQuery
query
;
query
.
prepare
(
"INSERT INTO money_transfers (change, note, from_acc, to_acc) "
"VALUES (:amount, :message, "
"(SELECT CASE "
" WHEN count(1) != 0 THEN id "
" ELSE 0 END "
" FROM money WHERE name = :from), "
"(SELECT CASE "
" WHEN count(1) != 0 THEN id "
" ELSE 0 END "
" FROM money WHERE name = :to))"
);
query
.
bindValue
(
":amount"
,
amount
);
query
.
bindValue
(
":message"
,
message
);
query
.
bindValue
(
":from"
,
from
);
query
.
bindValue
(
":to"
,
to
);
if
(
!
query
.
exec
())
qDebug
()
<<
query
.
lastError
();
open_till
();
}
// invalid account names results in the outside world
void
MainWindow
::
transferMoney
(
QString
from
,
QString
to
,
int
amount
)
{
transferMoney
(
from
,
to
,
amount
,
NULL
);
}
void
MainWindow
::
on_addMoneySubmitButton_clicked
()
{
addRemoveCommon
(
CASH_NULL
,
CASH_ACCOUNT
);
}
void
MainWindow
::
on_removeMoneySubmitButton_clicked
()
{
addRemoveCommon
(
CASH_ACCOUNT
,
CASH_NULL
);
}
void
MainWindow
::
addRemoveCommon
(
QString
from
,
QString
to
)
{
QString
msg
=
ui
->
addMoneyReason
->
toPlainText
();
QString
message
=
msg
==
""
?
NULL
:
msg
;
int
amount
=
ui
->
addMoneyEdit
->
text
().
toInt
();
transferMoney
(
from
,
to
,
amount
,
message
);
ui
->
addMoneyEdit
->
setText
(
""
);
ui
->
addMoneyReason
->
setPlainText
(
""
);
updateMoneyString
();
}
void
MainWindow
::
on_addDrainageButton_clicked
()
{
// Products to go from crown to öre
...
...
@@ -752,6 +723,7 @@ int MainWindow::setMoneyDiffLabels()
ui
->
diffExpected
->
setText
(
diff_text
);
ui
->
diffTotal
->
setText
(
diff_text
);
ui
->
diffDrawer
->
setText
(
""
);
return
expected
;
}
...
...
@@ -798,7 +770,7 @@ QVariant MainWindow::get_acquistion_stock_value()
"FROM stock s INNER JOIN products p "
"ON s.product_id = p.id"
);
while
(
tQuery
.
next
())
{
qDebug
()
<<
__LINE__
;
//
qDebug() << __LINE__;
long
target
=
tQuery
.
value
(
"active"
).
toLongLong
();
if
(
target
<
0
)
continue
;
...
...
@@ -815,7 +787,7 @@ QVariant MainWindow::get_acquistion_stock_value()
while
(
query
.
next
())
{
long
sub_amount
=
query
.
value
(
"amount"
).
toLongLong
();
long
item_price
=
query
.
value
(
"item_price"
).
toLongLong
();
qDebug
()
<<
__LINE__
<<
amount
<<
sub_amount
;
//
qDebug() << __LINE__ << amount << sub_amount;
if
(
amount
+
sub_amount
>
target
)
{
total_product_price
+=
(
target
-
amount
)
*
item_price
;
amount
=
target
;
...
...
@@ -843,15 +815,6 @@ QVariant MainWindow::get_projected_stock_value() {
}
void
MainWindow
::
setStockValues
()
{
double
accVal
=
get_acquistion_stock_value
().
toDouble
()
/
100.0
;
ui
->
valueAccquisitionLabel
->
setText
(
QString
(
"%1"
).
arg
(
accVal
,
0
,
'f'
,
2
));
double
projVal
=
get_projected_stock_value
().
toDouble
()
/
100.0
;
ui
->
valueProjectedLabel
->
setText
(
QString
(
"%1"
).
arg
(
projVal
,
0
,
'f'
,
2
));
}
void
MainWindow
::
setProductFilter
()
{
QString
searchStr
=
ui
->
productListSearch
->
text
();
...
...
@@ -899,3 +862,63 @@ void MainWindow::on_moneyDiffReload_clicked()
ui
->
diffDrawer
->
setText
(
""
);
setMoneyDiffLabels
();
}
void
MainWindow
::
on_accTransferSubmit_clicked
()
{
qlonglong
amount
=
ui
->
accTransferAmonut
->
value
()
*
100
;
qlonglong
from
=
ui
->
accTransferFrom
->
currentData
().
toLongLong
();
qlonglong
to
=
ui
->
accTransferTo
->
currentData
().
toLongLong
();
QString
text
=
ui
->
accTransferText
->
text
();
if
(
amount
==
0
||
from
==
to
)
return
;
qDebug
()
<<
amount
<<
from
<<
to
<<
text
;
QSqlQuery
query
;
query
.
prepare
(
"INSERT INTO money_transfers (change, from_acc, to_acc, note) "
"VALUES (:amount, :from, :to, :note)"
);
query
.
bindValue
(
":amount"
,
amount
);
query
.
bindValue
(
":from"
,
from
);
query
.
bindValue
(
":to"
,
to
);
query
.
bindValue
(
":note"
,
text
.
isEmpty
()
?
QVariant
::
String
:
QVariant
(
text
));
if
(
!
query
.
exec
())
qDebug
()
<<
query
.
lastError
();
ui
->
accTransferAmonut
->
setValue
(
0
);
ui
->
accTransferFrom
->
setCurrentIndex
(
0
);
ui
->
accTransferTo
->
setCurrentIndex
(
0
);
ui
->
accTransferText
->
setText
(
""
);
// TODO update money values
updateMoneyString
();
}
void
MainWindow
::
on_accUpdateBtn_clicked
()
{
setMoneyAccountValues
();
}
void
MainWindow
::
on_accNewAccBtn_clicked
()
{
QString
name
=
ui
->
accNewAccText
->
text
();
if
(
name
.
isEmpty
())
return
;
QSqlQuery
query
;
query
.
prepare
(
"INSERT INTO money (name) VALUES (:name)"
);
query
.
bindValue
(
":name"
,
name
);
if
(
!
query
.
exec
())
{
qDebug
()
<<
query
.
lastError
();
if
(
query
.
lastError
().
text
().
contains
(
"UNIQUE"
))
{
QMessageBox
::
warning
(
this
,
"Add failed"
,
"Account with that name probably already exitst. "
"It's either that, or that SQLite have bad error messages"
);
return
;
}
}
ui
->
accNewAccText
->
setText
(
""
);
setMoneyAccountValues
();
setAccTransferCombo
();
}
admin/mainwindow.h
View file @
a14ca471
...
...
@@ -37,13 +37,13 @@ private slots:
void
on_buyRemoveButton_clicked
();
void
on_toVaultButton_clicked
();
//
void on_toVaultButton_clicked();
void
on_toDrawerButton_clicked
();
//
void on_toDrawerButton_clicked();
void
on_addMoneySubmitButton_clicked
();
//
void on_addMoneySubmitButton_clicked();
void
on_removeMoneySubmitButton_clicked
();
//
void on_removeMoneySubmitButton_clicked();
void
on_addDrainageButton_clicked
();
...
...
@@ -79,6 +79,12 @@ private slots:
void
on_moneyDiffReload_clicked
();
void
on_accTransferSubmit_clicked
();
void
on_accUpdateBtn_clicked
();
void
on_accNewAccBtn_clicked
();
private:
Ui
::
MainWindow
*
ui
;
QSqlTableModel
*
model
;
...
...
@@ -98,10 +104,12 @@ private:
void
addRemoveCommon
(
QString
from
,
QString
to
);
void
clear_stockDiffTemp
();
void
setProductFilter
();
void
setMoneyAccountValues
();
QVariant
get_projected_stock_value
();
QVariant
get_acquistion_stock_value
();
void
setStockValues
();
void
setAccTransferCombo
();
void
open_till
();
};
...
...
admin/mainwindow.ui
View file @
a14ca471
...
...
@@ -689,40 +689,18 @@
<string>
Övrigt
</string>
</attribute>
<layout
class=
"QGridLayout"
name=
"gridLayout_5"
>
<item
row=
"4"
column=
"1"
>
<spacer
name=
"verticalSpacer_2"
>
<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"
>
<spacer
name=
"horizontalSpacer_6"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
<item
row=
"3"
column=
"3"
>
<widget
class=
"QPushButton"
name=
"openTillButton"
>
<property
name=
"text"
>
<string>
Öppna Kassan
</string>
</property>
</
spacer
>
</
widget
>
</item>
<item
row=
"
1
"
column=
"
0
"
>
<item
row=
"
2
"
column=
"
3
"
>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeType"
>
<enum>
QSizePolicy::Preferred
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
...
...
@@ -731,234 +709,115 @@
</property>
</spacer>
</item>
<item
row=
"3"
column=
"0"
>
<layout
class=
"QGridLayout"
name=
"gridLayout"
>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_31"
>
<property
name=
"text"
>
<string>
Kassalåda
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"3"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_4"
>
<property
name=
"text"
>
<string>
Kassaskåp
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"3"
column=
"1"
colspan=
"3"
>
<widget
class=
"QLabel"
name=
"vaultLabel"
>
<property
name=
"text"
>
<string>
Y
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"text"
>
<string>
Överför (öre)
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QLineEdit"
name=
"moneyMoveAmount"
>
<property
name=
"placeholderText"
>
<string>
0
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"1"
colspan=
"3"
>
<widget
class=
"QLabel"
name=
"drawerLabel"
>
<property
name=
"text"
>
<string>
X
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"toVaultButton"
>
<property
name=
"maximumSize"
>
<size>
<width>
30
</width>
<height>
30
</height>
</size>
</property>
<property
name=
"toolTip"
>
<string>
Cash Drawer to Vault
</string>
</property>
<property
name=
"text"
>
<string>
↧
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"3"
>
<widget
class=
"QPushButton"
name=
"toDrawerButton"
>
<property
name=
"maximumSize"
>
<size>
<width>
30
</width>
<height>
30
</height>
</size>
</property>
<property
name=
"toolTip"
>
<string>
Vault to Cash Drawer
</string>
</property>
<property
name=
"text"
>
<string>
↥
</string>
</property>
</widget>
</item>
</layout>
</item>
<item
row=
"3"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"openTillButton"
>
<property
name=
"text"
>
<string>
Öppna Kassan
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"0"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_3"
>
<property
name=
"verticalSpacing"
>
<number>
0
</number>
</property>
<item
row=
"1"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"removeMoneySubmitButton"
>
<property
name=
"text"
>
<string>
Ta bort
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"addMoneySubmitButton"
>
<property
name=
"text"
>
<string>
Lägg till
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
colspan=
"2"
>
<widget
class=
"QLineEdit"
name=
"addMoneyEdit"
>
<property
name=
"placeholderText"
>
<string>
0
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"0"
colspan=
"2"
>
<widget
class=
"QLabel"
name=
"label_7"
>
<property
name=
"text"
>
<string>
Lägg till/ta bort pengar (öre)
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"2"
column=
"0"
colspan=
"3"
>
<widget
class=
"QPlainTextEdit"
name=
"addMoneyReason"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Minimum"
vsizetype=
"Minimum"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"placeholderText"
>
<string>
Anledning / Person / ...
</string>
</property>
</widget>
</item>
</layout>
</item>
<item
row=
"0"
column=
"2"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_2"
>
<item
row=
"7"
column=
"1"
>
<spacer
name=
"verticalSpacer_4"
>
<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=
"3"
column=
"0"
colspan=
"2"
>
<widget
class=
"QLabel"
name=
"label_9"
>
<property
name=
"text"
>
<string>
Lagervärde:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignCenter
</set>
</property>
</widget>
<item
row=
"0"
column=
"1"
rowspan=
"6"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_10"
>
<item>
<layout
class=
"QGridLayout"
name=
"gridLayout_6"
>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QDoubleSpinBox"
name=
"accTransferAmonut"
>
<property
name=
"suffix"
>
<string>
kr
</string>
</property>
<property
name=
"maximum"
>
<double>
99999999999999991433150857216.000000000000000
</double>
</property>
</widget>
</item>
<item
row=
"2"
column=
"0"
colspan=
"2"
>
<widget
class=
"QLineEdit"
name=
"accTransferText"
>
<property
name=
"placeholderText"
>
<string>
Notering (anledning, person, ...)
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"2"
>
<widget
class=
"QComboBox"
name=
"accTransferTo"
/>
</item>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_16"
>
<property
name=
"text"
>
<string>
Från
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QLabel"
name=
"label_18"
>
<property
name=
"text"
>
<string>
Kronor
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QComboBox"
name=
"accTransferFrom"
/>
</item>
<item
row=
"0"
column=
"2"
>
<widget
class=
"QLabel"
name=
"label_17"
>
<property
name=
"text"
>
<string>
Till
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"accTransferSubmit"
>
<property
name=
"text"
>
<string>
Submit
</string>
</property>
</widget>
</item>
</layout>
</item>
<item
row=
"2"
column=
"0"
>
<
spacer
name=
"verticalSpacer_3
"
>
<item>
<
widget
class=
"Line"
name=
"line_7
"
>
<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=
"4"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_14"
>
<property
name=
"text"
>
<string>
• inköp
</string>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item
row=
"5"
column=
"0"
>
<widget
class=
"Q
Label"
name=
"label_15
"
>
<property
name=
"
text
"
>
<s
tring>
• projicerat
</string
>
<item>