Make commune configurable (Default is still Dettingen)

This commit is contained in:
Martin Brodbeck 2018-10-19 08:48:25 +02:00
parent bc9e395ee9
commit cac9ee9e30
6 changed files with 47 additions and 24 deletions

View File

@ -387,7 +387,7 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
}
if (printer->isValid())
printer->printSaleReceipt(sale.get());
printer->printSaleReceipt(sale.get(), settings.value("global/commune", "Dettingen").toString().toStdString());
}
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)

View File

@ -207,7 +207,9 @@ void ReportDialog::onPrintSellerReceiptButtonClicked()
}
if (printer->isValid())
printer->printSellerReceipt(seller.get(), feeInPercent, maxFeeInEuro * 100);
printer->printSellerReceipt(
seller.get(), feeInPercent, maxFeeInEuro * 100,
settings.value("global/commune", "Dettingen").toString().toStdString());
}
void ReportDialog::onReportViewSelectionChanged(const QItemSelection& selected,

View File

@ -18,6 +18,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
QSettings settings{};
int cashPointNo = settings.value("global/cashPointNo").toInt();
QString commune = settings.value("global/commune", "Dettingen").toString();
QString posPrinterDevice = settings.value("global/posPrinterDevice").toString();
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint").toString();
int feeInPercent = settings.value("global/feeInPercent").toInt();
@ -27,6 +28,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace();
ui_.cashPointNoSpinBox->setValue(cashPointNo);
ui_.communeEdit->setText(commune);
ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
ui_.posPrinterEndpointEdit->setText(posPrinterEndpoint);
ui_.feePercentSpinBox->setValue(feeInPercent);
@ -79,6 +81,7 @@ void SettingsDialog::accept()
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
int newCashPointNo = ui_.cashPointNoSpinBox->value();
settings.setValue("global/commune", ui_.communeEdit->text().trimmed());
settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text().trimmed());
settings.setValue("global/posPrinterEndpoint", ui_.posPrinterEndpointEdit->text().trimmed());
settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value());

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>392</width>
<height>242</height>
<height>246</height>
</rect>
</property>
<property name="windowTitle">
@ -24,14 +24,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Bondrucker:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="posPrinterDeviceEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -47,42 +47,49 @@
</property>
</widget>
</item>
<item row="1" column="3">
<item row="2" column="3">
<widget class="QPushButton" name="testPosPrinterButton">
<property name="text">
<string>Testen</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Gebühr in %:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="feePercentSpinBox">
<property name="value">
<number>20</number>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>max. Gebühr in €:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QSpinBox" name="maxFeeSpinBox">
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<item row="3" column="1">
<widget class="QLineEdit" name="posPrinterEndpointEdit">
<property name="placeholderText">
<string>Endpoint Address</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -92,10 +99,20 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="posPrinterEndpointEdit">
<property name="placeholderText">
<string>Endpoint Address</string>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Gemeinde:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="communeEdit">
<property name="text">
<string>Dettingen</string>
</property>
<property name="maxLength">
<number>30</number>
</property>
</widget>
</item>

View File

@ -131,13 +131,13 @@ void PosPrinter::write(const std::string& text)
std::cerr << "Write Error" << std::endl;
}
void PosPrinter::printHeader()
void PosPrinter::printHeader(const std::string& commune)
{
std::stringstream commandStream;
commandStream << Command::RESET << Command::ENCODING << Command::CENTERING
<< Command::FONT_SIZE_BIG;
commandStream << "Kindersachenmarkt\nDettingen\n\n";
commandStream << "Kindersachenmarkt\n" << commune << "\n\n";
commandStream << Command::LEFT_ALIGN << Command::Command::FONT_SIZE_NORMAL;
write(commandStream.str());
@ -154,10 +154,10 @@ void PosPrinter::printTest()
write(commandStream.str());
}
void PosPrinter::printSaleReceipt(Sale* sale)
void PosPrinter::printSaleReceipt(Sale* sale, const std::string& commune)
{
std::stringstream commandStream;
printHeader();
printHeader(commune);
commandStream << Command::RESET << Command::ENCODING << Command::RIGHT_ALIGN;
commandStream << sale->getTimestampFormatted() << "\n\n";
commandStream << Command::LEFT_ALIGN;
@ -172,10 +172,11 @@ void PosPrinter::printSaleReceipt(Sale* sale)
write(commandStream.str());
}
void PosPrinter::printSellerReceipt(Seller* seller, int percent, int maxFeeInCent)
void PosPrinter::printSellerReceipt(Seller* seller, const int percent, const int maxFeeInCent,
const std::string& commune)
{
std::stringstream commandStream;
printHeader();
printHeader(commune);
commandStream << Command::RESET << Command::ENCODING << Command::RIGHT_ALIGN;
std::string timeStr =
boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time());

View File

@ -33,10 +33,10 @@ class PosPrinter
PosPrinter(const PrinterDevice& printerDevice);
~PosPrinter();
void write(const std::string& text);
void printHeader();
void printHeader(const std::string& commune = "Musterhausen");
void printTest();
void printSaleReceipt(Sale* sale);
void printSellerReceipt(Seller* seller, int percent, int maxFeeInCent);
void printSaleReceipt(Sale* sale, const std::string& commune = "Dettingen");
void printSellerReceipt(Seller* seller, const int percent, const int maxFeeInCent, const std::string& commune = "Dettingen");
bool isValid();
struct Command {