2018-07-14 14:03:35 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2018-07-22 20:10:22 +02:00
|
|
|
#include "basketmodel.h"
|
2018-07-30 16:39:33 +02:00
|
|
|
#include "config.h"
|
2018-08-02 11:15:15 +02:00
|
|
|
#include "jsonutil.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"
|
2018-07-16 12:00:17 +02:00
|
|
|
|
2018-08-08 13:36:49 +02:00
|
|
|
#include <utils.h>
|
|
|
|
|
2018-08-01 15:36:41 +02:00
|
|
|
#include <excelreader.h>
|
2018-08-06 16:14:45 +02:00
|
|
|
#include <posprinter.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>
|
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-07-17 10:37:21 +02:00
|
|
|
constexpr int STATUSBAR_TIMEOUT = 5000;
|
|
|
|
|
2018-07-14 14:03:35 +02:00
|
|
|
MainWindow::MainWindow()
|
|
|
|
{
|
2018-07-14 15:54:29 +02:00
|
|
|
ui_.setupUi(this);
|
|
|
|
|
|
|
|
marketplace_ = std::make_unique<Marketplace>();
|
2018-07-17 10:37:21 +02:00
|
|
|
marketplace_->loadFromDb();
|
|
|
|
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
2018-07-22 20:10:22 +02:00
|
|
|
|
|
|
|
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);
|
|
|
|
ui_.basketView->setModel(model);
|
|
|
|
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());
|
|
|
|
|
2018-07-30 19:26:10 +02:00
|
|
|
setSaleModel();
|
|
|
|
|
2018-07-23 12:49:19 +02:00
|
|
|
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
|
2018-08-08 10:22:38 +02:00
|
|
|
connect(ui_.newAction, &QAction::triggered, this, [=]() {
|
|
|
|
if (marketplace_->getSellers().size() == 0 && 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 ui_.salesView->model();
|
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
|
|
|
|
marketplace_->clear();
|
|
|
|
setSaleModel();
|
|
|
|
});
|
2018-08-08 13:36:49 +02:00
|
|
|
|
|
|
|
ui_.sellerNoEdit->installEventFilter(this);
|
|
|
|
ui_.givenSpinBox->installEventFilter(this);
|
|
|
|
|
2018-07-23 12:49:19 +02:00
|
|
|
connect(ui_.actionEditSeller, &QAction::triggered, this,
|
2018-07-27 10:16:07 +02:00
|
|
|
&MainWindow::onActionEditSellerTriggered);
|
|
|
|
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered);
|
2018-08-08 13:36:49 +02:00
|
|
|
connect(ui_.givenSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
|
|
|
&MainWindow::onGivenSpinBoxValueChanged);
|
2018-07-23 12:49:19 +02:00
|
|
|
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
|
|
&MainWindow::onBasketViewSelectionChanged);
|
2018-07-23 13:39:49 +02:00
|
|
|
connect(ui_.cancelArticleButton, &QPushButton::clicked, this,
|
|
|
|
&MainWindow::onCancelArticleButtonClicked);
|
2018-07-27 16:04:01 +02:00
|
|
|
connect(ui_.cancelSaleButton, &QPushButton::clicked, this,
|
|
|
|
&MainWindow::onCancelSaleButtonClicked);
|
2018-08-06 16:14:45 +02:00
|
|
|
connect(ui_.printSaleReceiptButton, &QPushButton::clicked, this,
|
|
|
|
&MainWindow::onPrintSaleReceiptButtonClicked);
|
2018-07-23 13:39:49 +02:00
|
|
|
connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this,
|
|
|
|
&MainWindow::onCancelAllArticlesButtonClicked);
|
2018-07-29 09:56:37 +02:00
|
|
|
connect(ui_.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt);
|
2018-07-30 16:39:33 +02:00
|
|
|
connect(ui_.aboutAction, &QAction::triggered, this, &MainWindow::onAbout);
|
2018-08-07 20:39:15 +02:00
|
|
|
connect(ui_.openManualAction, &QAction::triggered, this, []() {
|
|
|
|
auto locations = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
|
|
|
|
for (auto location : locations) {
|
|
|
|
if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) {
|
2018-08-08 10:22:38 +02:00
|
|
|
QDesktopServices::openUrl(
|
|
|
|
QUrl(QString("file:///") + location + QString("/Benutzerhandbuch.pdf"),
|
|
|
|
QUrl::TolerantMode));
|
2018-08-07 20:39:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-07-30 09:50:54 +02:00
|
|
|
connect(ui_.reportAction, &QAction::triggered, this, [=]() { ReportDialog(this).exec(); });
|
2018-07-30 13:40:58 +02:00
|
|
|
connect(ui_.configAction, &QAction::triggered, this, [=]() {
|
2018-07-30 19:26:10 +02:00
|
|
|
int result = SettingsDialog(this).exec();
|
|
|
|
if (result == QDialog::Accepted) {
|
|
|
|
delete ui_.salesView->model();
|
|
|
|
marketplace_->loadFromDb();
|
|
|
|
setSaleModel();
|
|
|
|
}
|
2018-07-30 13:40:58 +02:00
|
|
|
this->setWindowTitle("KIMA2 - Kasse Nr. " +
|
|
|
|
QSettings().value("global/cashPointNo").toString());
|
|
|
|
});
|
2018-08-02 12:34:56 +02:00
|
|
|
connect(ui_.importSellerExcelAction, &QAction::triggered, this,
|
2018-08-02 11:15:15 +02:00
|
|
|
&MainWindow::onImportSellerExcelActionTriggered);
|
2018-08-02 12:34:56 +02:00
|
|
|
connect(ui_.importSellerJsonAction, &QAction::triggered, this,
|
|
|
|
&MainWindow::onImportSellerJsonActionTriggered);
|
2018-08-02 11:15:15 +02:00
|
|
|
connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
|
|
|
|
&MainWindow::onExportSellerJsonActionTriggered);
|
2018-08-02 15:06:35 +02:00
|
|
|
connect(ui_.exportSalesJsonAction, &QAction::triggered, this,
|
|
|
|
&MainWindow::onExportSalesJsonActionTriggered);
|
2018-08-02 15:28:35 +02:00
|
|
|
connect(ui_.importSalesJsonAction, &QAction::triggered, this,
|
|
|
|
&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-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
|
|
|
|
2018-07-30 19:26:10 +02:00
|
|
|
delete ui_.salesView->model();
|
2018-07-26 08:55:03 +02:00
|
|
|
|
2018-07-16 18:04:25 +02:00
|
|
|
if (retCode == QDialog::Accepted) {
|
2018-07-18 09:00:46 +02:00
|
|
|
marketplace_->sortSellers();
|
2018-07-16 18:04:25 +02:00
|
|
|
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 {
|
|
|
|
marketplace_->loadFromDb();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setSaleModel()
|
|
|
|
{
|
2018-07-26 08:55:03 +02:00
|
|
|
ui_.salesView->setModel(new SaleModel(getMarketplace(), ui_.salesView));
|
|
|
|
ui_.salesView->setColumnHidden(2, true);
|
|
|
|
ui_.salesView->resizeColumnToContents(0);
|
|
|
|
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged,
|
|
|
|
static_cast<SaleModel*>(ui_.salesView->model()), &SaleModel::onBasketDataChanged);
|
2018-07-28 17:38:45 +02:00
|
|
|
connect(ui_.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
|
|
&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
|
|
|
{
|
|
|
|
if (marketplace_->basketSize() > 0) {
|
2018-07-23 14:18:24 +02:00
|
|
|
QString lastPrice{marketplace_->getBasketSumAsString().c_str()};
|
2018-07-23 08:21:28 +02:00
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
2018-07-23 14:18:24 +02:00
|
|
|
ui_.lastPriceLabel1->setText(lastPrice);
|
|
|
|
ui_.lastPriceLabel2->setText(lastPrice);
|
2018-08-08 13:36:49 +02:00
|
|
|
ui_.basketSumLabel->setText(formatCentAsEuroString(0).c_str());
|
|
|
|
ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
|
|
|
|
ui_.drawbackContainerWidget->setEnabled(false);
|
|
|
|
ui_.sellerNoEdit->setFocus();
|
2018-07-26 08:59:54 +02:00
|
|
|
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
|
2018-07-23 08:21:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 13:36:49 +02:00
|
|
|
bool MainWindow::eventFilter(QObject* target, QEvent* event)
|
|
|
|
{
|
|
|
|
if (target == 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 == 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) {
|
|
|
|
ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
|
|
|
|
ui_.drawbackContainerWidget->setEnabled(false);
|
|
|
|
ui_.sellerNoEdit->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
auto inputText = ui_.sellerNoEdit->text().toStdString();
|
|
|
|
|
|
|
|
if (inputText.empty()) {
|
2018-08-08 13:36:49 +02:00
|
|
|
if (ctrlPressed == false) {
|
|
|
|
onPaidButtonTriggered();
|
|
|
|
} else if (marketplace_->getBasket().size() > 0) {
|
|
|
|
ui_.drawbackContainerWidget->setEnabled(true);
|
|
|
|
ui_.givenSpinBox->setFocus();
|
|
|
|
ui_.givenSpinBox->selectAll();
|
|
|
|
}
|
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)) {
|
2018-07-23 14:18:24 +02:00
|
|
|
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]);
|
|
|
|
|
|
|
|
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
|
|
|
|
if (seller) {
|
2018-07-21 19:24:56 +02:00
|
|
|
PriceDialog priceDialog(this);
|
|
|
|
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();
|
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price, desc);
|
2018-07-30 14:43:02 +02:00
|
|
|
ui_.basketSumLabel->setText(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
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
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);
|
|
|
|
int basketSumInCent = marketplace_->getBasketSumInCent();
|
|
|
|
int drawback = givenInCent - basketSumInCent;
|
|
|
|
ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str());
|
|
|
|
}
|
|
|
|
|
2018-07-23 12:49:19 +02:00
|
|
|
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
|
2018-07-23 13:39:49 +02:00
|
|
|
[[maybe_unused]] const QItemSelection& deselected)
|
2018-07-23 12:49:19 +02:00
|
|
|
{
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
ui_.cancelArticleButton->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ui_.cancelArticleButton->setEnabled(false);
|
|
|
|
}
|
2018-07-23 13:39:49 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 16:04:01 +02:00
|
|
|
void MainWindow::onSalesViewSelectionChanged(const QItemSelection& selected,
|
|
|
|
[[maybe_unused]] const QItemSelection& deselected)
|
|
|
|
{
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
ui_.cancelSaleButton->setEnabled(true);
|
2018-08-06 16:14:45 +02:00
|
|
|
if (!selected.indexes()[0].parent().isValid())
|
|
|
|
ui_.printSaleReceiptButton->setEnabled(true);
|
|
|
|
else
|
|
|
|
ui_.printSaleReceiptButton->setEnabled(false);
|
|
|
|
|
2018-07-27 16:04:01 +02:00
|
|
|
} else {
|
|
|
|
ui_.cancelSaleButton->setEnabled(false);
|
2018-08-06 16:14:45 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
auto selModel = 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) {
|
|
|
|
ui_.basketView->model()->removeRow(iter->row());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 16:04:01 +02:00
|
|
|
void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
|
|
|
auto selModel = ui_.salesView->selectionModel();
|
|
|
|
if (selModel->hasSelection() == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto dlgResult =
|
|
|
|
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
|
|
"Möchten Sie wirklich 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) {
|
2018-07-27 16:41:34 +02:00
|
|
|
ui_.salesView->model()->removeRow(iter->row(), iter->parent());
|
2018-07-27 16:04:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 16:14:45 +02:00
|
|
|
void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
|
|
|
auto selModel = ui_.salesView->selectionModel();
|
|
|
|
if (selModel->hasSelection() == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto indexes = selModel->selectedRows();
|
|
|
|
auto& sale = marketplace_->getSales().at(indexes[0].row());
|
|
|
|
PosPrinter printer;
|
2018-08-06 20:57:12 +02:00
|
|
|
if (printer.isValid())
|
|
|
|
printer.printSaleReceipt(sale.get());
|
2018-08-06 16:14:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-23 13:39:49 +02:00
|
|
|
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
|
|
|
|
{
|
|
|
|
if (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;
|
2018-07-23 14:18:24 +02:00
|
|
|
|
2018-07-23 13:39:49 +02:00
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
|
2018-07-29 09:56:37 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 16:39:33 +02:00
|
|
|
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
|
|
|
|
|
|
|
|
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 +
|
2018-07-30 16:39:33 +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
|
|
|
}
|
|
|
|
|
2018-08-02 11:15:15 +02:00
|
|
|
void MainWindow::onImportSellerExcelActionTriggered()
|
2018-08-01 15:36:41 +02:00
|
|
|
{
|
|
|
|
if (!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(),
|
|
|
|
"Excel Dateien (*.xlsx *.xls)");
|
|
|
|
|
2018-08-08 10:22:38 +02:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
2018-08-09 12:58:11 +02:00
|
|
|
|
2018-08-09 12:52:15 +02:00
|
|
|
std::filesystem::path filePath(filename.toStdWString());
|
2018-08-09 12:58:11 +02:00
|
|
|
|
2018-08-09 08:36:45 +02:00
|
|
|
ExcelReader::readSellersFromFile(filePath, marketplace_.get());
|
2018-08-02 11:15:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 12:34:56 +02:00
|
|
|
void MainWindow::onImportSellerJsonActionTriggered()
|
|
|
|
{
|
|
|
|
if (!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(),
|
|
|
|
"JSON Dateien (*.json)");
|
|
|
|
|
2018-08-05 14:52:34 +02:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-08-09 12:58:11 +02:00
|
|
|
std::filesystem::path filePath(filename.toStdWString());
|
|
|
|
|
|
|
|
JsonUtil::importSellers(filePath, marketplace_.get());
|
2018-08-02 12:34:56 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 11:15:15 +02:00
|
|
|
void MainWindow::onExportSellerJsonActionTriggered()
|
|
|
|
{
|
|
|
|
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
|
|
|
"JSON Dateien (*.json)");
|
|
|
|
|
2018-08-05 14:52:34 +02:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-08-02 11:15:15 +02:00
|
|
|
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get());
|
2018-08-02 15:06:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onExportSalesJsonActionTriggered()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
auto filename = QFileDialog::getSaveFileName(this, "Umsätze/Transaktionen exportieren",
|
|
|
|
QString(), "JSON Dateien (*.json)");
|
2018-08-05 14:52:34 +02:00
|
|
|
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-08-02 15:28:35 +02:00
|
|
|
JsonUtil::exportSales(filename.toStdString(), marketplace_.get(),
|
|
|
|
settings.value("global/cashPointNo").toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onImportSalesJsonActionTriggered()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
auto filename = QFileDialog::getOpenFileName(this, "Umsätze/Transaktionen importieren",
|
|
|
|
QString(), "JSON Dateien (*.json)");
|
|
|
|
|
2018-08-05 14:52:34 +02:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-08-09 13:02:33 +02:00
|
|
|
std::filesystem::path filePath(filename.toStdWString());
|
|
|
|
|
2018-08-05 14:52:34 +02:00
|
|
|
delete ui_.salesView->model();
|
2018-08-02 15:28:35 +02:00
|
|
|
try {
|
2018-08-09 13:02:33 +02:00
|
|
|
JsonUtil::importSales(filePath, marketplace_.get(),
|
2018-08-05 14:52:34 +02:00
|
|
|
settings.value("global/cashPointNo").toInt());
|
2018-08-02 15:28:35 +02:00
|
|
|
} catch (std::runtime_error& err) {
|
|
|
|
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
|
|
|
|
this)
|
|
|
|
.exec();
|
|
|
|
}
|
2018-08-05 14:52:34 +02:00
|
|
|
setSaleModel();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
|
|
|
writeGeometry();
|
|
|
|
event->accept();
|
2018-08-08 08:19:19 +02:00
|
|
|
}
|