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
4a4eb036
Commit
4a4eb036
authored
Nov 09, 2017
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added two stock value indicators to admin, only one of them works
parent
1eefc871
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
17 deletions
+107
-17
admin/mainwindow.cpp
admin/mainwindow.cpp
+65
-0
admin/mainwindow.h
admin/mainwindow.h
+4
-0
admin/mainwindow.ui
admin/mainwindow.ui
+38
-17
No files found.
admin/mainwindow.cpp
View file @
4a4eb036
...
...
@@ -342,6 +342,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui
->
addMoneyEdit
->
setValidator
(
pIntVal
);
updateMoneyString
();
setStockValues
();
}
MainWindow
::~
MainWindow
()
...
...
@@ -881,3 +882,67 @@ void MainWindow::clear_stockDiffTemp()
QSqlQuery
(
"DELETE FROM stock_diff_temp"
);
QSqlQuery
(
"UPDATE my_db_settings SET value = 1 WHERE name = 'stock_diff_temp_transfer'"
);
}
/*
* This is incredibly broken at the moment.
*/
QVariant
MainWindow
::
get_acquistion_stock_value
()
{
qlonglong
total_price
;
QSqlQuery
tQuery
(
"SELECT s.product_id as id, s.active as active, p.name "
"FROM stock s INNER JOIN products p "
"ON s.product_id = p.id"
);
while
(
tQuery
.
next
())
{
qDebug
()
<<
__LINE__
;
long
target
=
tQuery
.
value
(
"active"
).
toLongLong
();
if
(
target
<
0
)
continue
;
QSqlQuery
query
;
query
.
prepare
(
"SELECT id, time, product_id, item_price, amount "
"FROM acquisitions WHERE product_id = :id "
"ORDER BY time DESC"
);
query
.
bindValue
(
":id"
,
tQuery
.
value
(
"id"
));
query
.
exec
();
long
amount
=
0
;
long
total_product_price
=
0
;
while
(
query
.
next
())
{
long
sub_amount
=
query
.
value
(
"amount"
).
toLongLong
();
long
item_price
=
query
.
value
(
"item_price"
).
toLongLong
();
qDebug
()
<<
__LINE__
<<
amount
<<
sub_amount
;
if
(
amount
+
sub_amount
>
target
)
{
total_product_price
+=
(
target
-
amount
)
*
item_price
;
amount
=
target
;
break
;
}
else
{
amount
+=
sub_amount
;
total_product_price
+=
sub_amount
*
item_price
;
}
}
total_price
+=
total_product_price
;
}
return
QVariant
(
total_price
);
}
QVariant
MainWindow
::
get_projected_stock_value
()
{
QSqlQuery
query
(
"SELECT SUM(p.price * s.active) "
"FROM products p "
"INNER JOIN stock s ON "
"p.id = s.product_id"
);
if
(
query
.
next
())
return
query
.
value
(
0
);
return
QVariant
::
Int
;
}
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
));
}
admin/mainwindow.h
View file @
4a4eb036
...
...
@@ -103,6 +103,10 @@ private:
void
addRemoveCommon
(
QString
from
,
QString
to
);
void
clear_stockDiffTemp
();
QVariant
get_projected_stock_value
();
QVariant
get_acquistion_stock_value
();
void
setStockValues
();
void
open_till
();
};
...
...
admin/mainwindow.ui
View file @
4a4eb036
...
...
@@ -21,7 +21,7 @@
<enum>
QTabWidget::Rounded
</enum>
</property>
<property
name=
"currentIndex"
>
<number>
5
</number>
<number>
6
</number>
</property>
<property
name=
"tabsClosable"
>
<bool>
false
</bool>
...
...
@@ -929,7 +929,7 @@
</item>
<item
row=
"0"
column=
"2"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_2"
>
<item
row=
"
5
"
column=
"1"
>
<item
row=
"
7
"
column=
"1"
>
<spacer
name=
"verticalSpacer_4"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
...
...
@@ -942,24 +942,10 @@
</property>
</spacer>
</item>
<item
row=
"4"
column=
"0"
>
<widget
class=
"QLabel"
name=
"stockValueLabel"
>
<property
name=
"text"
>
<string>
X
</string>
</property>
</widget>
</item>
<item
row=
"4"
column=
"1"
>
<widget
class=
"QPushButton"
name=
"stockValueRefresh"
>
<property
name=
"text"
>
<string>
Refresh
</string>
</property>
</widget>
</item>
<item
row=
"3"
column=
"0"
colspan=
"2"
>
<widget
class=
"QLabel"
name=
"label_9"
>
<property
name=
"text"
>
<string>
Värde Lager
</string>
<string>
Lagervärde:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignCenter
</set>
...
...
@@ -979,6 +965,41 @@
</property>
</spacer>
</item>
<item
row=
"4"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_14"
>
<property
name=
"text"
>
<string>
• inköp
</string>
</property>
</widget>
</item>
<item
row=
"5"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_15"
>
<property
name=
"text"
>
<string>
• projicerat
</string>
</property>
</widget>
</item>
<item
row=
"4"
column=
"1"
>
<widget
class=
"QLabel"
name=
"valueAccquisitionLabel"
>
<property
name=
"text"
>
<string>
456.30
</string>
</property>
</widget>
</item>
<item
row=
"5"
column=
"1"
>
<widget
class=
"QLabel"
name=
"valueProjectedLabel"
>
<property
name=
"text"
>
<string>
852.20
</string>
</property>
</widget>
</item>
<item
row=
"6"
column=
"0"
colspan=
"2"
>
<widget
class=
"QPushButton"
name=
"stockValueRefresh"
>
<property
name=
"text"
>
<string>
Refresh
</string>
</property>
</widget>
</item>
</layout>
</item>
<item
row=
"0"
column=
"3"
>
...
...
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