570 lines
21 KiB
C++
570 lines
21 KiB
C++
#include "mainwindow.h"
|
|
|
|
#include "basketmodel.h"
|
|
#include "pricedialog.h"
|
|
#include "reportdialog.h"
|
|
#include "salemodel.h"
|
|
#include "sellerdialog.h"
|
|
#include "settingsdialog.h"
|
|
#include <config.h>
|
|
|
|
#include <core/csvreader.h>
|
|
#include <core/jsonutil.h>
|
|
#include <core/utils.h>
|
|
#include <printer/posprinter.h>
|
|
#include <printer/utils.h>
|
|
|
|
#include <exception>
|
|
#include <filesystem>
|
|
#include <regex>
|
|
#include <string>
|
|
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
#include <QSettings>
|
|
#include <QStandardPaths>
|
|
#include <QtGui/QDesktopServices>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
constexpr int STATUSBAR_TIMEOUT = 5000;
|
|
|
|
MainWindow::MainWindow()
|
|
{
|
|
m_ui.setupUi(this);
|
|
|
|
m_marketplace = std::make_unique<Marketplace>();
|
|
Database::InitResult res = m_marketplace->loadFromDb();
|
|
if (res == Database::InitResult::OUTDATED_REPLACED) {
|
|
QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation",
|
|
"Es wurde eine <b>veraltete</b> Datenbankdatei erkannt.<br />Diese wurde "
|
|
"umbenannt und eine <b>neue</b> Datei wurde erstellt.")
|
|
.exec();
|
|
}
|
|
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
|
|
|
BasketModel *model = new BasketModel(getMarketplace(), m_ui.basketView);
|
|
m_ui.basketView->setModel(model);
|
|
m_ui.basketView->setColumnHidden(0, true); // hide the uuid
|
|
|
|
setWindowTitle("KIMA2 - Kasse Nr. " + QSettings().value("global/cashPointNo").toString());
|
|
|
|
m_ui.salesView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
setSaleModel();
|
|
|
|
connect(m_ui.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows,
|
|
Qt::QueuedConnection);
|
|
connect(m_ui.newAction, &QAction::triggered, this, [this]() {
|
|
if (m_marketplace->getSellers().size() == 0 && m_marketplace->getSales().size() == 0) {
|
|
return;
|
|
}
|
|
auto dlgResult =
|
|
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
"Möchten Sie wirklich alle gespeicherten Daten verwerfen?",
|
|
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
|
.exec();
|
|
|
|
if (dlgResult == QMessageBox::No)
|
|
return;
|
|
|
|
delete m_ui.salesView->model();
|
|
dynamic_cast<BasketModel *>(m_ui.basketView->model())->cancelSale();
|
|
m_marketplace->clear();
|
|
setSaleModel();
|
|
updateStatLabel();
|
|
});
|
|
|
|
m_ui.sellerNoEdit->installEventFilter(this);
|
|
m_ui.givenSpinBox->installEventFilter(this);
|
|
|
|
connect(m_ui.actionEditSeller, &QAction::triggered, this,
|
|
&MainWindow::onActionEditSellerTriggered);
|
|
connect(m_ui.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered);
|
|
connect(m_ui.givenSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
|
&MainWindow::onGivenSpinBoxValueChanged);
|
|
connect(m_ui.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
&MainWindow::onBasketViewSelectionChanged);
|
|
connect(m_ui.cancelArticleButton, &QPushButton::clicked, this,
|
|
&MainWindow::onCancelArticleButtonClicked);
|
|
connect(m_ui.cancelSaleButton, &QPushButton::clicked, this,
|
|
&MainWindow::onCancelSaleButtonClicked);
|
|
connect(m_ui.printSaleReceiptButton, &QPushButton::clicked, this,
|
|
&MainWindow::onPrintSaleReceiptButtonClicked);
|
|
connect(m_ui.cancelAllArticlesButton, &QPushButton::clicked, this,
|
|
&MainWindow::onCancelAllArticlesButtonClicked);
|
|
connect(m_ui.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt);
|
|
connect(m_ui.aboutAction, &QAction::triggered, this, &MainWindow::onAbout);
|
|
connect(m_ui.openManualAction, &QAction::triggered, this, []() {
|
|
auto locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
|
|
for (auto location : locations) {
|
|
if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) {
|
|
QDesktopServices::openUrl(
|
|
QUrl::fromLocalFile(location + QString("/Benutzerhandbuch.pdf")));
|
|
}
|
|
}
|
|
});
|
|
connect(m_ui.licenseAction, &QAction::triggered, this, [this]() {
|
|
QString licenseText(
|
|
"Copyright © 2018-2024 Martin Brodbeck\n\n"
|
|
"Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der "
|
|
"zugehörigen Dokumentationen (die \"Software\") erhält, die Erlaubnis erteilt, "
|
|
"sie uneingeschränkt zu nutzen, inklusive und ohne Ausnahme mit dem Recht, "
|
|
"sie zu verwenden, zu kopieren, zu verändern, zusammenzufügen, zu "
|
|
"veröffentlichen, zu verbreiten, und Personen, denen diese Software überlassen "
|
|
"wird, diese Rechte zu verschaffen, unter den folgenden Bedingungen:\n\n"
|
|
"Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in allen "
|
|
"Kopien oder Teilkopien der Software beizulegen.\n\n"
|
|
"DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE "
|
|
"GARANTIE BEREITGESTELLT, EINSCHLIESSLICH DER GARANTIE ZUR BENUTZUNG "
|
|
"FÜR DEN VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER "
|
|
"RECHTSVERLETZUNG, JEDOCH NICHT DARAUF BESCHRÄNKT. IN KEINEM FALL "
|
|
"SIND DIE AUTOREN ODER COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER "
|
|
"SONSTIGE ANSPRÜCHE HAFTBAR ZU MACHEN, OB INFOLGE DER ERFÜLLUNG "
|
|
"EINES VERTRAGES, EINES DELIKTES ODER ANDERS IM ZUSAMMENHANG MIT DER "
|
|
"SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN.");
|
|
QMessageBox::information(this, "Lizenzinformation", licenseText);
|
|
});
|
|
connect(m_ui.reportAction, &QAction::triggered, this, [this]() { ReportDialog(this).exec(); });
|
|
connect(m_ui.configAction, &QAction::triggered, this, [this]() {
|
|
int result = SettingsDialog(this).exec();
|
|
if (result == QDialog::Accepted) {
|
|
delete m_ui.salesView->model();
|
|
m_marketplace->loadFromDb();
|
|
setSaleModel();
|
|
}
|
|
this->setWindowTitle("KIMA2 - Kasse Nr. " +
|
|
QSettings().value("global/cashPointNo").toString());
|
|
});
|
|
connect(m_ui.importSellerAction, &QAction::triggered, this,
|
|
&MainWindow::onImportSellerActionTriggered);
|
|
connect(m_ui.exportSalesJsonAction, &QAction::triggered, this,
|
|
&MainWindow::onExportSalesJsonActionTriggered);
|
|
connect(m_ui.importSalesJsonAction, &QAction::triggered, this,
|
|
&MainWindow::onImportSalesJsonActionTriggered);
|
|
|
|
readGeometry();
|
|
setWindowIcon(QIcon(":/misc/kima2.ico"));
|
|
|
|
updateStatLabel();
|
|
m_ui.lastPriceLabel1->setText(formatCentAsEuroString(0).c_str());
|
|
m_ui.lastPriceLabel2->setText(formatCentAsEuroString(0).c_str());
|
|
}
|
|
|
|
void MainWindow::onActionEditSellerTriggered()
|
|
{
|
|
auto dialog = std::make_unique<SellerDialog>(this);
|
|
int retCode = dialog->exec();
|
|
|
|
delete m_ui.salesView->model();
|
|
|
|
if (retCode == QDialog::Accepted) {
|
|
m_marketplace->sortSellers();
|
|
m_marketplace->storeToDb();
|
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
|
|
STATUSBAR_TIMEOUT);
|
|
} else {
|
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
|
|
STATUSBAR_TIMEOUT);
|
|
}
|
|
|
|
setSaleModel();
|
|
updateStatLabel();
|
|
}
|
|
|
|
void MainWindow::setSaleModel()
|
|
{
|
|
m_ui.salesView->setModel(new SaleModel(getMarketplace(), m_ui.salesView));
|
|
m_ui.salesView->setColumnHidden(2, true);
|
|
m_ui.salesView->resizeColumnToContents(0);
|
|
m_ui.salesView->resizeColumnToContents(1);
|
|
|
|
m_ui.printSaleReceiptButton->setEnabled(false);
|
|
m_ui.cancelSaleButton->setEnabled(false);
|
|
|
|
connect(static_cast<BasketModel *>(m_ui.basketView->model()), &BasketModel::basketDataChanged,
|
|
static_cast<SaleModel *>(m_ui.salesView->model()), &SaleModel::onBasketDataChanged);
|
|
connect(m_ui.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
&MainWindow::onSalesViewSelectionChanged);
|
|
}
|
|
|
|
void MainWindow::onPaidButtonTriggered()
|
|
{
|
|
if (m_marketplace->basketSize() > 0) {
|
|
QString lastPrice{m_marketplace->getBasketSumAsString().c_str()};
|
|
dynamic_cast<BasketModel *>(m_ui.basketView->model())->finishSale();
|
|
m_ui.salesView->resizeColumnToContents(0);
|
|
m_ui.lastPriceLabel1->setText(lastPrice);
|
|
m_ui.lastPriceLabel2->setText(lastPrice);
|
|
m_ui.basketSumLabel->setText(formatCentAsEuroString(0).c_str());
|
|
m_ui.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
|
|
m_ui.drawbackContainerWidget->setEnabled(false);
|
|
m_ui.sellerNoEdit->setFocus();
|
|
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
|
|
updateStatLabel();
|
|
}
|
|
}
|
|
|
|
bool MainWindow::eventFilter(QObject *target, QEvent *event)
|
|
{
|
|
if (target == m_ui.sellerNoEdit) {
|
|
if (event->type() == QEvent::KeyPress) {
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
|
|
if (keyEvent->modifiers() & Qt::ControlModifier) {
|
|
checkSellerNo(true);
|
|
} else {
|
|
checkSellerNo(false);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} else if (target == m_ui.givenSpinBox) {
|
|
if (event->type() == QEvent::KeyPress) {
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
|
|
if (keyEvent->modifiers() & Qt::ControlModifier) {
|
|
onPaidButtonTriggered();
|
|
return true;
|
|
}
|
|
} else if (keyEvent->key() == Qt::Key::Key_Escape) {
|
|
m_ui.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
|
|
m_ui.drawbackContainerWidget->setEnabled(false);
|
|
m_ui.sellerNoEdit->setFocus();
|
|
}
|
|
}
|
|
}
|
|
return QMainWindow::eventFilter(target, event);
|
|
}
|
|
|
|
void MainWindow::checkSellerNo(bool ctrlPressed)
|
|
{
|
|
using std::regex, std::regex_match, std::smatch;
|
|
|
|
auto inputText = m_ui.sellerNoEdit->text().toStdString();
|
|
|
|
if (inputText.empty()) {
|
|
if (ctrlPressed == false) {
|
|
onPaidButtonTriggered();
|
|
} else if (m_marketplace->getBasket().size() > 0) {
|
|
m_ui.drawbackContainerWidget->setEnabled(true);
|
|
m_ui.givenSpinBox->setFocus();
|
|
m_ui.givenSpinBox->selectAll();
|
|
}
|
|
return;
|
|
}
|
|
|
|
regex pattern{R"(\d{1,5})"};
|
|
smatch result;
|
|
|
|
if (!regex_match(inputText, result, pattern)) {
|
|
m_ui.sellerNoEdit->clear();
|
|
return;
|
|
}
|
|
|
|
int sellerNo = std::stoi(result[0]);
|
|
|
|
auto seller = m_marketplace->findSellerWithSellerNo(sellerNo);
|
|
if (seller) {
|
|
PriceDialog priceDialog(this);
|
|
if (sellerNo == 0) {
|
|
priceDialog.setForceDesc(true);
|
|
}
|
|
auto dialogResult = priceDialog.exec();
|
|
if (dialogResult == QDialog::Accepted) {
|
|
int price = priceDialog.getPrice();
|
|
std::string desc = priceDialog.getDescription();
|
|
dynamic_cast<BasketModel *>(m_ui.basketView->model())->addArticle(seller, price, desc);
|
|
m_ui.basketView->resizeColumnToContents(1);
|
|
m_ui.basketSumLabel->setText(m_marketplace->getBasketSumAsString().c_str());
|
|
}
|
|
}
|
|
|
|
m_ui.sellerNoEdit->clear();
|
|
}
|
|
|
|
void MainWindow::onGivenSpinBoxValueChanged(double value)
|
|
{
|
|
int givenInCent = std::round(value * 100);
|
|
int basketSumInCent = m_marketplace->getBasketSumInCent();
|
|
int drawback = givenInCent - basketSumInCent;
|
|
m_ui.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str());
|
|
}
|
|
|
|
void MainWindow::onBasketViewSelectionChanged(const QItemSelection &selected,
|
|
[[maybe_unused]] const QItemSelection &deselected)
|
|
{
|
|
if (selected.size() > 0) {
|
|
m_ui.cancelArticleButton->setEnabled(true);
|
|
} else {
|
|
m_ui.cancelArticleButton->setEnabled(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::onSalesViewSelectionChanged(const QItemSelection &selected,
|
|
[[maybe_unused]] const QItemSelection &deselected)
|
|
{
|
|
if (selected.size() > 0) {
|
|
m_ui.cancelSaleButton->setEnabled(true);
|
|
if (!selected.indexes()[0].parent().isValid())
|
|
m_ui.printSaleReceiptButton->setEnabled(true);
|
|
else
|
|
m_ui.printSaleReceiptButton->setEnabled(false);
|
|
|
|
} else {
|
|
m_ui.cancelSaleButton->setEnabled(false);
|
|
m_ui.printSaleReceiptButton->setEnabled(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
|
|
{
|
|
auto selModel = m_ui.basketView->selectionModel();
|
|
if (selModel->hasSelection() == false)
|
|
return;
|
|
|
|
auto dlgResult =
|
|
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
"Möchten Sie wirklich den Artikel stornieren?",
|
|
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
|
.exec();
|
|
if (dlgResult == QMessageBox::No)
|
|
return;
|
|
|
|
auto indexes = selModel->selectedRows();
|
|
std::sort(indexes.begin(), indexes.end());
|
|
|
|
// Deleting the rows, beginning with the last one!
|
|
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
|
|
m_ui.basketView->model()->removeRow(iter->row());
|
|
}
|
|
|
|
m_ui.basketSumLabel->setText(
|
|
m_marketplace->getBasketSumAsString().c_str()); // Update basket sum
|
|
m_ui.sellerNoEdit->setFocus();
|
|
}
|
|
|
|
void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
|
|
{
|
|
auto selModel = m_ui.salesView->selectionModel();
|
|
if (selModel->hasSelection() == false)
|
|
return;
|
|
|
|
auto dlgResult =
|
|
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
"Möchten Sie wirklich aus abgeschlossenen Verkäufen stornieren?",
|
|
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
|
.exec();
|
|
if (dlgResult == QMessageBox::No)
|
|
return;
|
|
|
|
auto indexes = selModel->selectedRows();
|
|
std::sort(indexes.begin(), indexes.end());
|
|
|
|
// Deleting the rows, beginning with the last one!
|
|
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
|
|
m_ui.salesView->model()->removeRow(iter->row(), iter->parent());
|
|
}
|
|
|
|
m_ui.salesView->collapseAll();
|
|
|
|
QString lastPriceValue(formatCentAsEuroString(0).c_str());
|
|
if (m_ui.salesView->model()->rowCount() > 0) {
|
|
lastPriceValue =
|
|
m_ui.salesView->model()->data(m_ui.salesView->model()->index(0, 1)).toString();
|
|
}
|
|
m_ui.lastPriceLabel1->setText(lastPriceValue);
|
|
m_ui.lastPriceLabel2->setText(lastPriceValue);
|
|
|
|
updateStatLabel();
|
|
}
|
|
|
|
void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
|
|
{
|
|
auto selModel = m_ui.salesView->selectionModel();
|
|
if (selModel->hasSelection() == false)
|
|
return;
|
|
|
|
QSettings settings{};
|
|
QString posPrinterDevice = settings.value("global/posPrinterDevice", "").toString();
|
|
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString();
|
|
|
|
auto indexes = selModel->selectedRows();
|
|
auto &sale = m_marketplace->getSales().at(indexes[0].row());
|
|
|
|
auto printerDevice =
|
|
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
|
|
|
|
std::unique_ptr<PosPrinter> printer;
|
|
|
|
if (printerDevice) {
|
|
printer = std::make_unique<PosPrinter>(*printerDevice);
|
|
} else {
|
|
printer = std::make_unique<PosPrinter>();
|
|
}
|
|
|
|
if (printer->isValid())
|
|
printer->printSaleReceipt(
|
|
sale.get(), settings.value("global/commune", "Dettingen").toString().toStdString());
|
|
}
|
|
|
|
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
|
|
{
|
|
if (m_ui.basketView->model()->rowCount() == 0)
|
|
return;
|
|
|
|
auto dlgResult =
|
|
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
"Möchten Sie wirklich *alle* Artikel des aktuellen Einkaufs stornieren?",
|
|
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
|
.exec();
|
|
if (dlgResult == QMessageBox::No)
|
|
return;
|
|
|
|
dynamic_cast<BasketModel *>(m_ui.basketView->model())->cancelSale();
|
|
|
|
m_ui.basketSumLabel->setText(
|
|
m_marketplace->getBasketSumAsString().c_str()); // Update basket sum
|
|
m_ui.sellerNoEdit->setFocus();
|
|
}
|
|
|
|
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
|
|
|
|
void MainWindow::onAbout()
|
|
{
|
|
QMessageBox::about(
|
|
this, "Über",
|
|
QString("<p style='text-align:center;'><b>KIMA2</b> - Version ") + PROJECT_VERSION +
|
|
"</p>"
|
|
"<p>KIMA2 ist ein kleines Kassenprogramm für Kindersachenmärkte.<p />"
|
|
"<p>Copyright © Martin Brodbeck <<a href=mailto:martin@brodbeck-online.de"
|
|
">info@rustysoft.de</a>></p>");
|
|
}
|
|
|
|
void MainWindow::onImportSellerActionTriggered()
|
|
{
|
|
if (!m_marketplace->getSales().empty()) {
|
|
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
|
|
"Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.",
|
|
QMessageBox::StandardButton::Ok, this)
|
|
.exec();
|
|
return;
|
|
}
|
|
|
|
auto filename =
|
|
QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
|
|
"Alle unterstützte Dateien (*.csv);;CSV Dateien (*.csv)");
|
|
|
|
if (filename.isEmpty())
|
|
return;
|
|
|
|
#if defined(_WIN64) || defined(_WIN32)
|
|
fs::path filePath(filename.toStdWString());
|
|
#else
|
|
fs::path filePath(filename.toStdString());
|
|
#endif
|
|
|
|
std::size_t numImported{};
|
|
numImported = CsvReader::readSellersFromFile(filePath, m_marketplace.get());
|
|
|
|
updateStatLabel();
|
|
|
|
using namespace std::string_literals;
|
|
std::ostringstream msg;
|
|
msg << "Aus der CSV-Datei wurden <b>"s << std::to_string(numImported)
|
|
<< "</b> Verkäufer importiert.";
|
|
QMessageBox(QMessageBox::Icon::Information, "Verkäufer erfolgreich importiert",
|
|
msg.str().c_str(), QMessageBox::StandardButton::Ok, this)
|
|
.exec();
|
|
}
|
|
|
|
void MainWindow::onExportSalesJsonActionTriggered()
|
|
{
|
|
QSettings settings;
|
|
|
|
auto filename = QFileDialog::getSaveFileName(
|
|
this, "Umsätze/Transaktionen exportieren",
|
|
QString("kima2_umsaetze_kasse") + settings.value("global/cashPointNo").toString() + ".json",
|
|
"JSON Dateien (*.json)");
|
|
|
|
if (filename.isEmpty())
|
|
return;
|
|
|
|
#if defined(_WIN64) || defined(_WIN32)
|
|
fs::path filePath(filename.toStdWString());
|
|
#else
|
|
fs::path filePath(filename.toStdString());
|
|
#endif
|
|
|
|
JsonUtil::exportSales(filePath, m_marketplace.get(),
|
|
settings.value("global/cashPointNo").toInt());
|
|
}
|
|
|
|
void MainWindow::onImportSalesJsonActionTriggered()
|
|
{
|
|
QSettings settings;
|
|
|
|
auto filenames = QFileDialog::getOpenFileNames(this, "Umsätze/Transaktionen importieren",
|
|
QString(), "JSON Dateien (*.json)");
|
|
|
|
if (filenames.isEmpty())
|
|
return;
|
|
|
|
for(auto filename: filenames) {
|
|
#if defined(_WIN64) || defined(_WIN32)
|
|
fs::path filePath(filename.toStdWString());
|
|
#else
|
|
fs::path filePath(filename.toStdString());
|
|
#endif
|
|
|
|
delete m_ui.salesView->model();
|
|
try {
|
|
JsonUtil::importSales(filePath, m_marketplace.get(),
|
|
settings.value("global/cashPointNo").toInt());
|
|
} catch (std::runtime_error &err) {
|
|
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
|
|
this)
|
|
.exec();
|
|
}
|
|
}
|
|
|
|
setSaleModel();
|
|
updateStatLabel();
|
|
}
|
|
|
|
void MainWindow::writeGeometry()
|
|
{
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("mainwindow");
|
|
settings.setValue("size", size());
|
|
settings.setValue("pos", pos());
|
|
settings.endGroup();
|
|
}
|
|
|
|
void MainWindow::readGeometry()
|
|
{
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("mainwindow");
|
|
resize(settings.value("size", QSize(800, 600)).toSize());
|
|
move(settings.value("pos", QPoint(200, 200)).toPoint());
|
|
settings.endGroup();
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
{
|
|
writeGeometry();
|
|
event->accept();
|
|
}
|
|
|
|
void MainWindow::updateStatLabel()
|
|
{
|
|
std::string statistics("<b>KIMA2 - Version ");
|
|
statistics += PROJECT_VERSION;
|
|
statistics += "</b><br />Verkäufer: " + std::to_string(m_marketplace->getSellers().size() - 1);
|
|
statistics += "<br />Kunden: " + std::to_string(m_marketplace->getSales().size());
|
|
statistics += "<br />Umsatz: " + m_marketplace->getOverallSumAsString();
|
|
|
|
m_ui.statLabel->setText(statistics.c_str());
|
|
}
|