Browse Source

save csv with correct umlauts even on windows

allow_new_sellers
Martin Brodbeck 4 years ago
parent
commit
00f870b0c3
  1. 6
      src/core/marketplace.cpp
  2. 4
      src/core/marketplace.h
  3. 3
      src/gui/mainwindow.cpp
  4. 24
      src/gui/reportdialog.cpp

6
src/core/marketplace.cpp

@ -8,6 +8,8 @@
#include <numeric>
#include <sstream>
namespace fs = std::filesystem;
Marketplace::Marketplace()
{
auto seller = std::make_unique<Seller>("Max", "Mustermann");
@ -168,10 +170,10 @@ void Marketplace::setSalesToDelete(int cashPointNo)
});
}
void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro)
void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent, int maxFeeInEuro)
{
const char delimiter = ',';
std::ofstream file(filename);
std::ofstream file(filePath);
file << "Verk.Nr." << delimiter << "Nachname" << delimiter << "Vorname" << delimiter
<< "Anz. gemeldet" << delimiter << "Anz. verkauft" << delimiter << "Umsatz" << delimiter

4
src/core/marketplace.h

@ -5,6 +5,7 @@
#include "sale.h"
#include "seller.h"
#include <filesystem>
#include <vector>
class ExcelReader;
@ -52,7 +53,8 @@ class Marketplace
void clear();
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro);
void exportReportToCSV(const std::filesystem::path& filePath, int feeInPercent,
int maxFeeInEuro);
friend class ExcelReader;

3
src/gui/mainwindow.cpp

@ -360,7 +360,8 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
auto indexes = selModel->selectedRows();
auto& sale = marketplace_->getSales().at(indexes[0].row());
auto printerDevice = convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
auto printerDevice =
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
std::unique_ptr<PosPrinter> printer;

24
src/gui/reportdialog.cpp

@ -5,6 +5,8 @@
#include <posprinter.h>
#include <utils.h>
#include <filesystem>
#include <QFileDialog>
#include <QFontDatabase>
#include <QPainter>
@ -12,6 +14,8 @@
#include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter>
namespace fs = std::filesystem;
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{
ui_.setupUi(this);
@ -37,14 +41,15 @@ void ReportDialog::onExportCsvButtonClicked()
int feeInPercent = settings.value("global/feeInPercent").toInt();
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
QFileDialog fileDialog(this);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setNameFilter("CSV Files (*.csv)");
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
if (fileDialog.exec()) {
market_->exportReportToCSV(fileDialog.selectedFiles().at(0).toStdString(), feeInPercent,
maxFeeInEuro);
}
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
"CSV Dateien (*.csv)");
if (filename.isEmpty())
return;
fs::path filePath(filename.toStdWString());
market_->exportReportToCSV(filePath, feeInPercent, maxFeeInEuro);
}
void ReportDialog::onPrintReportButtonClicked()
@ -159,8 +164,7 @@ void ReportDialog::onPrintReportButtonClicked()
content += QString("Verkaufte Artikel: %1 (%L2 %)\n\n")
.arg(numArticlesSold, 6)
.arg(percentArticlesSold, 0, 'f', 2);
content +=
QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10);
content += QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10);
content +=
QString("Ausgezahlt: %1\n")
.arg(market_->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);

Loading…
Cancel
Save