2018-07-14 14:03:35 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2018-07-22 20:10:22 +02:00
|
|
|
#include "basketmodel.h"
|
2018-07-21 19:24:56 +02:00
|
|
|
#include "pricedialog.h"
|
2018-07-30 09:50:54 +02:00
|
|
|
#include "reportdialog.h"
|
2018-07-25 16:04:45 +02:00
|
|
|
#include "salemodel.h"
|
2018-07-26 08:34:01 +02:00
|
|
|
#include "sellerdialog.h"
|
2018-07-30 13:40:58 +02:00
|
|
|
#include "settingsdialog.h"
|
2022-07-07 15:31:32 +02:00
|
|
|
#include <config.h>
|
2018-07-16 12:00:17 +02:00
|
|
|
|
2019-10-10 08:09:16 +02:00
|
|
|
#include <core/csvreader.h>
|
|
|
|
#include <core/jsonutil.h>
|
|
|
|
#include <core/utils.h>
|
|
|
|
#include <printer/posprinter.h>
|
|
|
|
#include <printer/utils.h>
|
2018-08-01 15:36:41 +02:00
|
|
|
|
2018-08-02 15:28:35 +02:00
|
|
|
#include <exception>
|
2018-08-09 08:36:45 +02:00
|
|
|
#include <filesystem>
|
2018-08-09 12:58:11 +02:00
|
|
|
#include <regex>
|
2019-02-25 09:26:21 +01:00
|
|
|
#include <string>
|
2018-07-20 22:07:42 +02:00
|
|
|
|
2018-08-01 15:36:41 +02:00
|
|
|
#include <QFileDialog>
|
2018-07-23 13:39:49 +02:00
|
|
|
#include <QMessageBox>
|
2018-07-30 13:40:58 +02:00
|
|
|
#include <QSettings>
|
2018-08-07 20:39:15 +02:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QtGui/QDesktopServices>
|
2018-07-23 12:49:19 +02:00
|
|
|
|
2018-08-09 16:37:56 +02:00
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
2018-07-17 10:37:21 +02:00
|
|
|
constexpr int STATUSBAR_TIMEOUT = 5000;
|
|
|
|
|
2018-07-14 14:03:35 +02:00
|
|
|
MainWindow::MainWindow()
|
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.setupUi(this);
|
2018-07-14 15:54:29 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_marketplace = std::make_unique<Marketplace>();
|
|
|
|
Database::InitResult res = m_marketplace->loadFromDb();
|
2019-10-04 15:50:13 +02:00
|
|
|
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.")
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2019-10-04 15:50:13 +02:00
|
|
|
}
|
2018-07-17 10:37:21 +02:00
|
|
|
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
2018-07-22 20:10:22 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
BasketModel *model = new BasketModel(getMarketplace(), m_ui.basketView);
|
|
|
|
m_ui.basketView->setModel(model);
|
|
|
|
m_ui.basketView->setColumnHidden(0, true); // hide the uuid
|
2018-07-23 12:49:19 +02:00
|
|
|
|
2018-07-30 13:40:58 +02:00
|
|
|
setWindowTitle("KIMA2 - Kasse Nr. " + QSettings().value("global/cashPointNo").toString());
|
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.salesView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
2018-07-30 19:26:10 +02:00
|
|
|
setSaleModel();
|
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows,
|
2019-09-30 10:39:00 +02:00
|
|
|
Qt::QueuedConnection);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.newAction, &QAction::triggered, this, [this]() {
|
|
|
|
if (m_marketplace->getSellers().size() == 0 && m_marketplace->getSales().size() == 0) {
|
2018-08-08 10:22:38 +02:00
|
|
|
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)
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2018-08-08 10:22:38 +02:00
|
|
|
|
|
|
|
if (dlgResult == QMessageBox::No)
|
|
|
|
return;
|
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
delete m_ui.salesView->model();
|
|
|
|
dynamic_cast<BasketModel *>(m_ui.basketView->model())->cancelSale();
|
|
|
|
m_marketplace->clear();
|
2018-08-08 10:22:38 +02:00
|
|
|
setSaleModel();
|
2018-10-09 08:04:47 +02:00
|
|
|
updateStatLabel();
|
2018-08-08 10:22:38 +02:00
|
|
|
});
|
2018-08-08 13:36:49 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.sellerNoEdit->installEventFilter(this);
|
|
|
|
m_ui.givenSpinBox->installEventFilter(this);
|
2018-08-08 13:36:49 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.actionEditSeller, &QAction::triggered, this,
|
2018-07-27 10:16:07 +02:00
|
|
|
&MainWindow::onActionEditSellerTriggered);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered);
|
|
|
|
connect(m_ui.givenSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
2018-08-08 13:36:49 +02:00
|
|
|
&MainWindow::onGivenSpinBoxValueChanged);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
2018-07-23 12:49:19 +02:00
|
|
|
&MainWindow::onBasketViewSelectionChanged);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.cancelArticleButton, &QPushButton::clicked, this,
|
2018-07-23 13:39:49 +02:00
|
|
|
&MainWindow::onCancelArticleButtonClicked);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.cancelSaleButton, &QPushButton::clicked, this,
|
2018-07-27 16:04:01 +02:00
|
|
|
&MainWindow::onCancelSaleButtonClicked);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.printSaleReceiptButton, &QPushButton::clicked, this,
|
2018-08-06 16:14:45 +02:00
|
|
|
&MainWindow::onPrintSaleReceiptButtonClicked);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.cancelAllArticlesButton, &QPushButton::clicked, this,
|
2018-07-23 13:39:49 +02:00
|
|
|
&MainWindow::onCancelAllArticlesButtonClicked);
|
2022-07-07 15:37:33 +02:00
|
|
|
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, []() {
|
2022-07-07 17:16:51 +02:00
|
|
|
auto locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
|
2018-08-07 20:39:15 +02:00
|
|
|
for (auto location : locations) {
|
|
|
|
if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) {
|
2018-08-08 10:22:38 +02:00
|
|
|
QDesktopServices::openUrl(
|
2023-04-26 12:46:35 +02:00
|
|
|
QUrl::fromLocalFile(location + QString("/Benutzerhandbuch.pdf")));
|
2018-08-07 20:39:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.licenseAction, &QAction::triggered, this, [this]() {
|
2018-08-13 14:26:34 +02:00
|
|
|
QString licenseText(
|
2023-04-26 12:47:41 +02:00
|
|
|
"Copyright © 2018-2023 Martin Brodbeck\n\n"
|
2018-08-13 14:26:34 +02:00
|
|
|
"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);
|
|
|
|
});
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.reportAction, &QAction::triggered, this, [this]() { ReportDialog(this).exec(); });
|
|
|
|
connect(m_ui.configAction, &QAction::triggered, this, [this]() {
|
2018-07-30 19:26:10 +02:00
|
|
|
int result = SettingsDialog(this).exec();
|
|
|
|
if (result == QDialog::Accepted) {
|
2022-07-07 15:37:33 +02:00
|
|
|
delete m_ui.salesView->model();
|
|
|
|
m_marketplace->loadFromDb();
|
2018-07-30 19:26:10 +02:00
|
|
|
setSaleModel();
|
|
|
|
}
|
2018-07-30 13:40:58 +02:00
|
|
|
this->setWindowTitle("KIMA2 - Kasse Nr. " +
|
|
|
|
QSettings().value("global/cashPointNo").toString());
|
|
|
|
});
|
2023-01-18 16:35:28 +01:00
|
|
|
connect(m_ui.importSellerAction, &QAction::triggered, this,
|
|
|
|
&MainWindow::onImportSellerActionTriggered);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.exportSalesJsonAction, &QAction::triggered, this,
|
2018-08-02 15:06:35 +02:00
|
|
|
&MainWindow::onExportSalesJsonActionTriggered);
|
2022-07-07 15:37:33 +02:00
|
|
|
connect(m_ui.importSalesJsonAction, &QAction::triggered, this,
|
2018-08-02 15:28:35 +02:00
|
|
|
&MainWindow::onImportSalesJsonActionTriggered);
|
2018-08-07 10:52:51 +02:00
|
|
|
|
|
|
|
readGeometry();
|
2018-08-07 16:06:01 +02:00
|
|
|
setWindowIcon(QIcon(":/misc/kima2.ico"));
|
2018-10-08 11:21:11 +02:00
|
|
|
|
|
|
|
updateStatLabel();
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.lastPriceLabel1->setText(formatCentAsEuroString(0).c_str());
|
|
|
|
m_ui.lastPriceLabel2->setText(formatCentAsEuroString(0).c_str());
|
2018-07-14 15:54:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 10:16:07 +02:00
|
|
|
void MainWindow::onActionEditSellerTriggered()
|
2018-07-16 12:00:17 +02:00
|
|
|
{
|
|
|
|
auto dialog = std::make_unique<SellerDialog>(this);
|
2018-07-16 18:04:25 +02:00
|
|
|
int retCode = dialog->exec();
|
2018-07-26 08:55:03 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
delete m_ui.salesView->model();
|
2018-07-26 08:55:03 +02:00
|
|
|
|
2018-07-16 18:04:25 +02:00
|
|
|
if (retCode == QDialog::Accepted) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_marketplace->sortSellers();
|
|
|
|
m_marketplace->storeToDb();
|
2018-07-17 10:37:21 +02:00
|
|
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
|
|
|
|
STATUSBAR_TIMEOUT);
|
2018-07-16 18:04:25 +02:00
|
|
|
} else {
|
2018-07-17 11:09:35 +02:00
|
|
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
|
2018-07-17 10:37:21 +02:00
|
|
|
STATUSBAR_TIMEOUT);
|
2018-07-16 18:04:25 +02:00
|
|
|
}
|
2018-07-26 08:55:03 +02:00
|
|
|
|
2018-07-30 19:26:10 +02:00
|
|
|
setSaleModel();
|
2018-10-08 11:21:11 +02:00
|
|
|
updateStatLabel();
|
2018-07-30 19:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setSaleModel()
|
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
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);
|
2018-08-15 10:51:57 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.printSaleReceiptButton->setEnabled(false);
|
|
|
|
m_ui.cancelSaleButton->setEnabled(false);
|
2018-08-15 10:51:57 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
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,
|
2018-07-28 17:38:45 +02:00
|
|
|
&MainWindow::onSalesViewSelectionChanged);
|
2018-07-20 22:07:42 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 10:16:07 +02:00
|
|
|
void MainWindow::onPaidButtonTriggered()
|
2018-07-23 08:21:28 +02:00
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
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();
|
2018-07-26 08:59:54 +02:00
|
|
|
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
|
2018-10-08 11:21:11 +02:00
|
|
|
updateStatLabel();
|
2018-07-23 08:21:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-07 15:31:32 +02:00
|
|
|
bool MainWindow::eventFilter(QObject *target, QEvent *event)
|
2018-08-08 13:36:49 +02:00
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
if (target == m_ui.sellerNoEdit) {
|
2018-08-08 13:36:49 +02:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
2022-07-07 15:31:32 +02:00
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
2018-08-08 13:36:49 +02:00
|
|
|
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
|
2019-09-28 15:02:55 +02:00
|
|
|
if (keyEvent->modifiers() & Qt::ControlModifier) {
|
2018-08-08 13:36:49 +02:00
|
|
|
checkSellerNo(true);
|
|
|
|
} else {
|
|
|
|
checkSellerNo(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-07-07 15:37:33 +02:00
|
|
|
} else if (target == m_ui.givenSpinBox) {
|
2018-08-08 13:36:49 +02:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
2022-07-07 15:31:32 +02:00
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
2018-08-08 13:36:49 +02:00
|
|
|
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
|
2019-09-28 15:02:55 +02:00
|
|
|
if (keyEvent->modifiers() & Qt::ControlModifier) {
|
2018-08-08 13:36:49 +02:00
|
|
|
onPaidButtonTriggered();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (keyEvent->key() == Qt::Key::Key_Escape) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
|
|
|
|
m_ui.drawbackContainerWidget->setEnabled(false);
|
|
|
|
m_ui.sellerNoEdit->setFocus();
|
2018-08-08 13:36:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QMainWindow::eventFilter(target, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::checkSellerNo(bool ctrlPressed)
|
2018-07-20 22:07:42 +02:00
|
|
|
{
|
|
|
|
using std::regex, std::regex_match, std::smatch;
|
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
auto inputText = m_ui.sellerNoEdit->text().toStdString();
|
2018-07-20 22:07:42 +02:00
|
|
|
|
|
|
|
if (inputText.empty()) {
|
2018-08-08 13:36:49 +02:00
|
|
|
if (ctrlPressed == false) {
|
|
|
|
onPaidButtonTriggered();
|
2022-07-07 15:37:33 +02:00
|
|
|
} else if (m_marketplace->getBasket().size() > 0) {
|
|
|
|
m_ui.drawbackContainerWidget->setEnabled(true);
|
|
|
|
m_ui.givenSpinBox->setFocus();
|
|
|
|
m_ui.givenSpinBox->selectAll();
|
2018-08-08 13:36:49 +02:00
|
|
|
}
|
2018-07-20 22:07:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
regex pattern{R"(\d{1,5})"};
|
|
|
|
smatch result;
|
2018-07-22 20:10:22 +02:00
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
if (!regex_match(inputText, result, pattern)) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.sellerNoEdit->clear();
|
2018-07-20 22:07:42 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-21 21:18:22 +02:00
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
int sellerNo = std::stoi(result[0]);
|
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
auto seller = m_marketplace->findSellerWithSellerNo(sellerNo);
|
2018-07-20 22:07:42 +02:00
|
|
|
if (seller) {
|
2018-07-21 19:24:56 +02:00
|
|
|
PriceDialog priceDialog(this);
|
2018-10-18 14:50:15 +02:00
|
|
|
if (sellerNo == 0) {
|
2018-10-17 09:09:54 +02:00
|
|
|
priceDialog.setForceDesc(true);
|
|
|
|
}
|
2018-07-21 19:24:56 +02:00
|
|
|
auto dialogResult = priceDialog.exec();
|
2018-07-21 21:18:22 +02:00
|
|
|
if (dialogResult == QDialog::Accepted) {
|
2018-07-21 19:24:56 +02:00
|
|
|
int price = priceDialog.getPrice();
|
2018-08-07 09:27:15 +02:00
|
|
|
std::string desc = priceDialog.getDescription();
|
2022-07-07 15:37:33 +02:00
|
|
|
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());
|
2018-07-21 19:24:56 +02:00
|
|
|
}
|
2018-07-20 22:07:42 +02:00
|
|
|
}
|
2018-07-20 22:10:05 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.sellerNoEdit->clear();
|
2018-07-23 12:49:19 +02:00
|
|
|
}
|
|
|
|
|
2018-08-08 13:36:49 +02:00
|
|
|
void MainWindow::onGivenSpinBoxValueChanged(double value)
|
|
|
|
{
|
|
|
|
int givenInCent = std::round(value * 100);
|
2022-07-07 15:37:33 +02:00
|
|
|
int basketSumInCent = m_marketplace->getBasketSumInCent();
|
2018-08-08 13:36:49 +02:00
|
|
|
int drawback = givenInCent - basketSumInCent;
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str());
|
2018-08-08 13:36:49 +02:00
|
|
|
}
|
|
|
|
|
2022-07-07 15:31:32 +02:00
|
|
|
void MainWindow::onBasketViewSelectionChanged(const QItemSelection &selected,
|
|
|
|
[[maybe_unused]] const QItemSelection &deselected)
|
2018-07-23 12:49:19 +02:00
|
|
|
{
|
|
|
|
if (selected.size() > 0) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.cancelArticleButton->setEnabled(true);
|
2018-07-23 12:49:19 +02:00
|
|
|
} else {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.cancelArticleButton->setEnabled(false);
|
2018-07-23 12:49:19 +02:00
|
|
|
}
|
2018-07-23 13:39:49 +02:00
|
|
|
}
|
|
|
|
|
2022-07-07 15:31:32 +02:00
|
|
|
void MainWindow::onSalesViewSelectionChanged(const QItemSelection &selected,
|
|
|
|
[[maybe_unused]] const QItemSelection &deselected)
|
2018-07-27 16:04:01 +02:00
|
|
|
{
|
|
|
|
if (selected.size() > 0) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.cancelSaleButton->setEnabled(true);
|
2018-08-06 16:14:45 +02:00
|
|
|
if (!selected.indexes()[0].parent().isValid())
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.printSaleReceiptButton->setEnabled(true);
|
2018-08-06 16:14:45 +02:00
|
|
|
else
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.printSaleReceiptButton->setEnabled(false);
|
2018-08-06 16:14:45 +02:00
|
|
|
|
2018-07-27 16:04:01 +02:00
|
|
|
} else {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.cancelSaleButton->setEnabled(false);
|
|
|
|
m_ui.printSaleReceiptButton->setEnabled(false);
|
2018-07-27 16:04:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:39:49 +02:00
|
|
|
void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
auto selModel = m_ui.basketView->selectionModel();
|
2018-07-23 13:39:49 +02:00
|
|
|
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)
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2018-07-23 13:39:49 +02:00
|
|
|
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) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.basketView->model()->removeRow(iter->row());
|
2018-07-23 13:39:49 +02:00
|
|
|
}
|
2018-10-08 08:52:39 +02:00
|
|
|
|
2023-01-18 16:35:28 +01:00
|
|
|
m_ui.basketSumLabel->setText(
|
|
|
|
m_marketplace->getBasketSumAsString().c_str()); // Update basket sum
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.sellerNoEdit->setFocus();
|
2018-07-23 13:39:49 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 16:04:01 +02:00
|
|
|
void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
auto selModel = m_ui.salesView->selectionModel();
|
2018-07-27 16:04:01 +02:00
|
|
|
if (selModel->hasSelection() == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto dlgResult =
|
|
|
|
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
2019-10-01 08:33:36 +02:00
|
|
|
"Möchten Sie wirklich aus abgeschlossenen Verkäufen stornieren?",
|
2018-07-27 16:04:01 +02:00
|
|
|
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2018-07-27 16:04:01 +02:00
|
|
|
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) {
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.salesView->model()->removeRow(iter->row(), iter->parent());
|
2018-07-27 16:04:01 +02:00
|
|
|
}
|
2018-10-08 09:23:03 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.salesView->collapseAll();
|
2019-09-30 10:39:00 +02:00
|
|
|
|
2019-09-30 10:28:03 +02:00
|
|
|
QString lastPriceValue(formatCentAsEuroString(0).c_str());
|
2022-07-07 15:37:33 +02:00
|
|
|
if (m_ui.salesView->model()->rowCount() > 0) {
|
2019-09-30 10:39:00 +02:00
|
|
|
lastPriceValue =
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.salesView->model()->data(m_ui.salesView->model()->index(0, 1)).toString();
|
2019-09-30 10:28:03 +02:00
|
|
|
}
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.lastPriceLabel1->setText(lastPriceValue);
|
|
|
|
m_ui.lastPriceLabel2->setText(lastPriceValue);
|
2019-09-30 10:39:00 +02:00
|
|
|
|
2018-10-08 11:21:11 +02:00
|
|
|
updateStatLabel();
|
2018-07-27 16:04:01 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 16:14:45 +02:00
|
|
|
void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
auto selModel = m_ui.salesView->selectionModel();
|
2018-08-06 16:14:45 +02:00
|
|
|
if (selModel->hasSelection() == false)
|
|
|
|
return;
|
|
|
|
|
2018-08-15 10:51:57 +02:00
|
|
|
QSettings settings{};
|
|
|
|
QString posPrinterDevice = settings.value("global/posPrinterDevice", "").toString();
|
|
|
|
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString();
|
|
|
|
|
2018-08-06 16:14:45 +02:00
|
|
|
auto indexes = selModel->selectedRows();
|
2022-07-07 15:37:33 +02:00
|
|
|
auto &sale = m_marketplace->getSales().at(indexes[0].row());
|
2018-08-15 10:51:57 +02:00
|
|
|
|
2018-08-16 12:40:19 +02:00
|
|
|
auto printerDevice =
|
|
|
|
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
|
2018-08-15 10:51:57 +02:00
|
|
|
|
|
|
|
std::unique_ptr<PosPrinter> printer;
|
|
|
|
|
|
|
|
if (printerDevice) {
|
|
|
|
printer = std::make_unique<PosPrinter>(*printerDevice);
|
|
|
|
} else {
|
|
|
|
printer = std::make_unique<PosPrinter>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (printer->isValid())
|
2019-02-25 09:26:21 +01:00
|
|
|
printer->printSaleReceipt(
|
|
|
|
sale.get(), settings.value("global/commune", "Dettingen").toString().toStdString());
|
2018-08-06 16:14:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-23 13:39:49 +02:00
|
|
|
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
if (m_ui.basketView->model()->rowCount() == 0)
|
2018-07-23 13:39:49 +02:00
|
|
|
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)
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2018-07-23 13:39:49 +02:00
|
|
|
if (dlgResult == QMessageBox::No)
|
|
|
|
return;
|
2018-07-23 14:18:24 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
dynamic_cast<BasketModel *>(m_ui.basketView->model())->cancelSale();
|
2018-10-09 19:15:34 +02:00
|
|
|
|
2023-01-18 16:35:28 +01:00
|
|
|
m_ui.basketSumLabel->setText(
|
|
|
|
m_marketplace->getBasketSumAsString().c_str()); // Update basket sum
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.sellerNoEdit->setFocus();
|
2018-07-29 09:56:37 +02:00
|
|
|
}
|
|
|
|
|
2022-07-07 15:31:32 +02:00
|
|
|
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
|
2018-07-30 16:39:33 +02:00
|
|
|
|
|
|
|
void MainWindow::onAbout()
|
|
|
|
{
|
|
|
|
QMessageBox::about(
|
|
|
|
this, "Über",
|
2018-07-30 19:29:16 +02:00
|
|
|
QString("<p style='text-align:center;'><b>KIMA2</b> - Version ") + PROJECT_VERSION +
|
2022-07-07 15:31:32 +02:00
|
|
|
"</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>");
|
2018-08-01 15:36:41 +02:00
|
|
|
}
|
|
|
|
|
2023-01-18 16:35:28 +01:00
|
|
|
void MainWindow::onImportSellerActionTriggered()
|
2018-08-01 15:36:41 +02:00
|
|
|
{
|
2022-07-07 15:37:33 +02:00
|
|
|
if (!m_marketplace->getSales().empty()) {
|
2018-08-01 15:36:41 +02:00
|
|
|
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)
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2018-08-01 15:36:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-18 16:35:28 +01:00
|
|
|
auto filename =
|
|
|
|
QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
|
|
|
|
"Alle unterstützte Dateien (*.csv);;CSV Dateien (*.csv)");
|
2018-08-01 15:36:41 +02:00
|
|
|
|
2018-08-08 10:22:38 +02:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
2018-08-09 12:58:11 +02:00
|
|
|
|
2019-10-07 08:32:51 +02:00
|
|
|
#if defined(_WIN64) || defined(_WIN32)
|
2018-08-09 16:37:56 +02:00
|
|
|
fs::path filePath(filename.toStdWString());
|
2019-10-07 08:32:51 +02:00
|
|
|
#else
|
|
|
|
fs::path filePath(filename.toStdString());
|
|
|
|
#endif
|
2018-08-09 12:58:11 +02:00
|
|
|
|
2019-09-26 16:41:39 +02:00
|
|
|
std::size_t numImported{};
|
2023-01-18 16:35:28 +01:00
|
|
|
numImported = CsvReader::readSellersFromFile(filePath, m_marketplace.get());
|
2019-09-30 10:39:00 +02:00
|
|
|
|
2018-10-08 11:21:11 +02:00
|
|
|
updateStatLabel();
|
2019-02-25 09:26:21 +01:00
|
|
|
|
|
|
|
using namespace std::string_literals;
|
|
|
|
std::ostringstream msg;
|
2023-01-18 16:35:28 +01:00
|
|
|
msg << "Aus der CSV-Datei wurden <b>"s << std::to_string(numImported)
|
2019-02-25 09:26:21 +01:00
|
|
|
<< "</b> Verkäufer importiert.";
|
|
|
|
QMessageBox(QMessageBox::Icon::Information, "Verkäufer erfolgreich importiert",
|
|
|
|
msg.str().c_str(), QMessageBox::StandardButton::Ok, this)
|
2022-07-07 15:31:32 +02:00
|
|
|
.exec();
|
2018-08-02 11:15:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 15:06:35 +02:00
|
|
|
void MainWindow::onExportSalesJsonActionTriggered()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
2018-10-09 11:55:20 +02:00
|
|
|
auto filename = QFileDialog::getSaveFileName(
|
2022-07-07 15:31:32 +02:00
|
|
|
this, "Umsätze/Transaktionen exportieren",
|
|
|
|
QString("kima2_umsaetze_kasse") + settings.value("global/cashPointNo").toString() + ".json",
|
|
|
|
"JSON Dateien (*.json)");
|
2018-08-05 14:52:34 +02:00
|
|
|
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2019-10-07 08:32:51 +02:00
|
|
|
#if defined(_WIN64) || defined(_WIN32)
|
2018-08-09 16:37:56 +02:00
|
|
|
fs::path filePath(filename.toStdWString());
|
2019-10-07 08:32:51 +02:00
|
|
|
#else
|
|
|
|
fs::path filePath(filename.toStdString());
|
|
|
|
#endif
|
2018-08-09 13:11:23 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
JsonUtil::exportSales(filePath, m_marketplace.get(),
|
2018-08-02 15:28:35 +02:00
|
|
|
settings.value("global/cashPointNo").toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onImportSalesJsonActionTriggered()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
2024-01-23 10:39:43 +01:00
|
|
|
auto filenames = QFileDialog::getOpenFileNames(this, "Umsätze/Transaktionen importieren",
|
2022-07-07 15:31:32 +02:00
|
|
|
QString(), "JSON Dateien (*.json)");
|
2018-08-02 15:28:35 +02:00
|
|
|
|
2024-01-23 10:39:43 +01:00
|
|
|
if (filenames.isEmpty())
|
2018-08-05 14:52:34 +02:00
|
|
|
return;
|
|
|
|
|
2024-01-23 10:39:43 +01:00
|
|
|
for(auto filename: filenames) {
|
2019-10-07 08:32:51 +02:00
|
|
|
#if defined(_WIN64) || defined(_WIN32)
|
2024-01-23 10:39:43 +01:00
|
|
|
fs::path filePath(filename.toStdWString());
|
2019-10-07 08:32:51 +02:00
|
|
|
#else
|
2024-01-23 10:39:43 +01:00
|
|
|
fs::path filePath(filename.toStdString());
|
2019-10-07 08:32:51 +02:00
|
|
|
#endif
|
2018-08-09 13:02:33 +02:00
|
|
|
|
2024-01-23 10:39:43 +01:00
|
|
|
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();
|
|
|
|
}
|
2018-08-02 15:28:35 +02:00
|
|
|
}
|
2024-01-23 10:39:43 +01:00
|
|
|
|
2018-08-05 14:52:34 +02:00
|
|
|
setSaleModel();
|
2018-10-08 11:21:11 +02:00
|
|
|
updateStatLabel();
|
2018-08-02 15:28:35 +02:00
|
|
|
}
|
2018-08-07 10:52:51 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2022-07-07 15:31:32 +02:00
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
2018-08-07 10:52:51 +02:00
|
|
|
{
|
|
|
|
writeGeometry();
|
|
|
|
event->accept();
|
2018-08-08 08:19:19 +02:00
|
|
|
}
|
2018-10-08 11:21:11 +02:00
|
|
|
|
|
|
|
void MainWindow::updateStatLabel()
|
|
|
|
{
|
|
|
|
std::string statistics("<b>KIMA2 - Version ");
|
|
|
|
statistics += PROJECT_VERSION;
|
2022-07-07 15:37:33 +02:00
|
|
|
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();
|
2018-10-08 11:21:11 +02:00
|
|
|
|
2022-07-07 15:37:33 +02:00
|
|
|
m_ui.statLabel->setText(statistics.c_str());
|
2019-02-25 13:32:34 +01:00
|
|
|
}
|