Compare commits
No commits in common. "b1570b3a9944ea014c519b20b7983d0a7a78fb1d" and "e13339a4322adb36fd6d3e591ed32de2a09d905f" have entirely different histories.
b1570b3a99
...
e13339a432
5 changed files with 2 additions and 75 deletions
|
@ -2,7 +2,6 @@
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -134,27 +133,6 @@ void Marketplace::removeSale(boost::uuids::uuid uuid)
|
||||||
sales_.end());
|
sales_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro)
|
|
||||||
{
|
|
||||||
const char delimiter = ',';
|
|
||||||
std::ofstream file(filename);
|
|
||||||
|
|
||||||
file << "Verk.Nr." << delimiter << "Nachname" << delimiter << "Vorname" << delimiter
|
|
||||||
<< "Anz. gemeldet" << delimiter << "Anz. verkauft" << delimiter << "Umsatz" << delimiter
|
|
||||||
<< "Auszahlung\n";
|
|
||||||
|
|
||||||
for (const auto& seller : sellers_) {
|
|
||||||
file << seller->getSellerNo() << delimiter
|
|
||||||
<< escapeCsvValue(seller->getLastName(), delimiter) << delimiter
|
|
||||||
<< escapeCsvValue(seller->getFirstName(), delimiter) << delimiter
|
|
||||||
<< seller->numArticlesOffered() << delimiter << seller->numArticlesSold() << delimiter
|
|
||||||
<< escapeCsvValue(seller->sumAsString(), delimiter) << delimiter
|
|
||||||
<< escapeCsvValue(paymentAsString(seller->sumInCents(), feeInPercent, maxFeeInEuro),
|
|
||||||
delimiter)
|
|
||||||
<< "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double marketFee(int sum, int percent, int maxFee)
|
double marketFee(int sum, int percent, int maxFee)
|
||||||
{
|
{
|
||||||
int fee = (sum * percent) / 100.0L;
|
int fee = (sum * percent) / 100.0L;
|
||||||
|
@ -179,28 +157,3 @@ std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent)
|
||||||
<< std::put_money(sumInCent - marketFee(sumInCent, percent, maxFeeInCent), false);
|
<< std::put_money(sumInCent - marketFee(sumInCent, percent, maxFeeInCent), false);
|
||||||
return feeStream.str();
|
return feeStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string escapeCsvValue(const std::string& value, const char delimiter)
|
|
||||||
{
|
|
||||||
std::stringstream output;
|
|
||||||
bool containsDelim{false};
|
|
||||||
|
|
||||||
if (value.find(delimiter) != std::string::npos || value.find('"') != std::string::npos) {
|
|
||||||
containsDelim = true;
|
|
||||||
output << '"';
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& symbol : value) {
|
|
||||||
if (symbol == '"') {
|
|
||||||
output << '"' << symbol;
|
|
||||||
} else {
|
|
||||||
output << symbol;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (containsDelim) {
|
|
||||||
output << '"';
|
|
||||||
}
|
|
||||||
|
|
||||||
return output.str();
|
|
||||||
}
|
|
|
@ -41,8 +41,6 @@ class Marketplace
|
||||||
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
||||||
void removeSale(boost::uuids::uuid uuid);
|
void removeSale(boost::uuids::uuid uuid);
|
||||||
|
|
||||||
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SellersVec sellers_;
|
SellersVec sellers_;
|
||||||
SalesVec sales_;
|
SalesVec sales_;
|
||||||
|
@ -52,6 +50,5 @@ class Marketplace
|
||||||
double marketFee(int sumInCent, int percent, int maxFeeInCent);
|
double marketFee(int sumInCent, int percent, int maxFeeInCent);
|
||||||
std::string marketFeeAsString(int sumInCent, int percent, int maxFeeInCent);
|
std::string marketFeeAsString(int sumInCent, int percent, int maxFeeInCent);
|
||||||
std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent);
|
std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent);
|
||||||
std::string escapeCsvValue(const std::string& value, const char delimiter);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||||
{
|
{
|
||||||
ui_.setupUi(this);
|
ui_.setupUi(this);
|
||||||
|
@ -12,21 +9,4 @@ ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
|
||||||
model_ = std::make_unique<ReportModel>(market_, ui_.reportView);
|
model_ = std::make_unique<ReportModel>(market_, ui_.reportView);
|
||||||
ui_.reportView->setModel(model_.get());
|
ui_.reportView->setModel(model_.get());
|
||||||
ui_.reportView->hideColumn(0);
|
ui_.reportView->hideColumn(0);
|
||||||
|
|
||||||
connect(ui_.exportCsvButton, &QPushButton::clicked, this, &ReportDialog::onExportCsvButtonClicked);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReportDialog::onExportCsvButtonClicked()
|
|
||||||
{
|
|
||||||
QSettings settings;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -17,9 +17,6 @@ class ReportDialog : public QDialog
|
||||||
ReportDialog(QWidget* parent = nullptr,
|
ReportDialog(QWidget* parent = nullptr,
|
||||||
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
|
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onExportCsvButtonClicked();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ReportDialog ui_;
|
Ui::ReportDialog ui_;
|
||||||
Marketplace* market_;
|
Marketplace* market_;
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="exportCsvButton">
|
<widget class="QPushButton" name="pushButton_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Exportieren (.csv)</string>
|
<string>Exportieren (.csv)</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue