Commit 4a4eb036 authored by Hugo Hörnquist's avatar Hugo Hörnquist

added two stock value indicators to admin, only one of them works

parent 1eefc871
...@@ -342,6 +342,7 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -342,6 +342,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->addMoneyEdit->setValidator(pIntVal); ui->addMoneyEdit->setValidator(pIntVal);
updateMoneyString(); updateMoneyString();
setStockValues();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
...@@ -881,3 +882,67 @@ void MainWindow::clear_stockDiffTemp() ...@@ -881,3 +882,67 @@ void MainWindow::clear_stockDiffTemp()
QSqlQuery("DELETE FROM stock_diff_temp"); QSqlQuery("DELETE FROM stock_diff_temp");
QSqlQuery("UPDATE my_db_settings SET value = 1 WHERE name = 'stock_diff_temp_transfer'"); 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));
}
...@@ -103,6 +103,10 @@ private: ...@@ -103,6 +103,10 @@ private:
void addRemoveCommon(QString from, QString to); void addRemoveCommon(QString from, QString to);
void clear_stockDiffTemp(); void clear_stockDiffTemp();
QVariant get_projected_stock_value();
QVariant get_acquistion_stock_value();
void setStockValues();
void open_till(); void open_till();
}; };
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>5</number> <number>6</number>
</property> </property>
<property name="tabsClosable"> <property name="tabsClosable">
<bool>false</bool> <bool>false</bool>
...@@ -929,7 +929,7 @@ ...@@ -929,7 +929,7 @@
</item> </item>
<item row="0" column="2"> <item row="0" column="2">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="5" column="1"> <item row="7" column="1">
<spacer name="verticalSpacer_4"> <spacer name="verticalSpacer_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -942,24 +942,10 @@ ...@@ -942,24 +942,10 @@
</property> </property>
</spacer> </spacer>
</item> </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"> <item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="text"> <property name="text">
<string>Värde Lager</string> <string>Lagervärde:</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
...@@ -979,6 +965,41 @@ ...@@ -979,6 +965,41 @@
</property> </property>
</spacer> </spacer>
</item> </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> </layout>
</item> </item>
<item row="0" column="3"> <item row="0" column="3">
......
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