diff --git a/admin/mainwindow.cpp b/admin/mainwindow.cpp index 036405253446d809fb3aa88c44283694bc046d12..84d6dee0d9e0714e0f084e8a7848bff1790a6269 100644 --- a/admin/mainwindow.cpp +++ b/admin/mainwindow.cpp @@ -59,6 +59,11 @@ // TODO stock diff should show null when actual field is null +// TODO possibly allow each money account in the database two have +// two nemes. One "true" name, which can alse be used as a key. +// And one "fancy" name, that should never be checked agains, and +// can be allowed to be translated. + /* * All internal prices should be in öre * Never trust a front end number unless you KNOW it's good @@ -372,15 +377,28 @@ void MainWindow::setMoneyAccountValues() { QSqlRecord rec = accModel->record(); + QVariant projected_price = get_projected_stock_value(); rec.setValue("name", QVariant("Lager (projicerat)")); - rec.setValue("amount", QVariant(QString("%1").arg(get_projected_stock_value().toDouble() / 100.0, - 0, 'f', 2))); + rec.setValue("amount", QVariant(formatMoney(projected_price.toDouble() / 100.0))); accModel->insertRecord(-1, rec); + QVariant buy_price = get_acquistion_stock_value(); rec.setValue("name", QVariant("Lager (inköp)")); - rec.setValue("amount", QVariant(QString("%1").arg(get_acquistion_stock_value().toDouble() / 100.0, - 0, 'f', 2))); + rec.setValue("amount", QVariant(formatMoney(buy_price.toDouble() / 100.0))); accModel->insertRecord(-1, rec); + + QSqlQuery query("SELECT sum(amount) FROM money"); + if (query.next()) { + qlonglong sum = query.value(0).toLongLong() + + projected_price.toLongLong(); + rec.setValue("name", QVariant("Totalt (projicerat)")); + rec.setValue("amount", QVariant(formatMoney((double) sum / 100.0))); + accModel->insertRecord(-1, rec); + } +} + +QString MainWindow::formatMoney(double in){ + return QString("%1").arg(in, 0, 'f', 2); } /* diff --git a/admin/mainwindow.h b/admin/mainwindow.h index 40c65f492a1f5bfa090bcc5e09dfc5173040611b..8201175aa8abb3fd80ce42d99620ddc4d18e871a 100644 --- a/admin/mainwindow.h +++ b/admin/mainwindow.h @@ -110,6 +110,7 @@ private: QVariant get_acquistion_stock_value(); void setStockValues(); void setAccTransferCombo(); + QString formatMoney(double in); void open_till(); };