Compare commits

...

37 commits

Author SHA1 Message Date
eb23243637 Merge branch 'allow_new_sellers' of ssh://brodbeck-online.de:60022/martin/kima2-cpp into allow_new_sellers 2018-10-18 13:14:09 +02:00
e92b080f7a Improve error message 2018-10-18 13:10:19 +02:00
bd23e2417c More on adding new seller during sale phase 2018-10-18 13:10:19 +02:00
fe7ddc5cf2 Allow adding sellers during sale phase 2018-10-18 13:10:19 +02:00
43faf05006 Allow adding sellers during sale phase 2018-10-18 13:10:19 +02:00
04de363af5 Allow adding sellers during sale phase 2018-10-18 13:10:19 +02:00
1aa56f24a3 bump to new version 0.12.0 2018-10-17 13:50:47 +02:00
d546b61f00 set focus on seller no edit field 2018-10-17 09:25:10 +02:00
373e143aa4 [Fix #8] Enable cancelling basket-items with shortcut 2018-10-17 09:19:21 +02:00
6c0441992f [Fix #9] Make article desc mandatory if sellerno is 0 2018-10-17 09:09:54 +02:00
4fb6d2f98b code beautifying 2018-10-12 11:49:52 +02:00
e9fde76a60 better print seller no on sale receipt 2018-10-12 11:47:03 +02:00
f6528bdf45 bump to version 0.11.5 2018-10-11 08:19:10 +02:00
127fbc1398 update basket sum after deleting all articles 2018-10-09 19:15:34 +02:00
ef88604ad4 bump to new version 0.11.4 2018-10-09 14:29:17 +02:00
ad68fb8bf7 code cleanup 2018-10-09 12:01:58 +02:00
0b4041c13a propose filename when exporting sales as json 2018-10-09 11:55:20 +02:00
9ef1ada6d9 Fix clang-format 2018-10-09 11:54:35 +02:00
723dee825b bump to new version 0.11.3 2018-10-09 08:17:33 +02:00
d15deb42c8 Merge branch 'master' of ssh://brodbeck-online.de:60022/martin/kima2-cpp 2018-10-09 08:07:00 +02:00
4f0ce62ce5 update to new lib versions 2018-10-09 08:05:38 +02:00
7571ef6a13 Fix creating new db 2018-10-09 08:04:47 +02:00
6b9ac3d284 bump to version 0.11.2 2018-10-08 16:14:12 +02:00
9f114660e1 Simplify file name 2018-10-08 15:50:41 +02:00
d5d309ac10 bump to new version 0.11.1 2018-10-08 14:31:22 +02:00
cdec552f04 Fix: Create correct sql schema 2018-10-08 14:30:42 +02:00
cdeea37f8c push to new version 0.11.0 2018-10-08 12:20:19 +02:00
639c8ec576 manual updated 2018-10-08 11:32:09 +02:00
8e5080b888 Show statistics, centered at the bottom 2018-10-08 11:21:11 +02:00
cfc632a986 [Fix #4] Archive current db when creating new 2018-10-08 10:48:28 +02:00
271aac0914 small code improvement 2018-10-08 09:52:41 +02:00
725bc8f04b [Fix #5] show no of customers in print report 2018-10-08 09:48:25 +02:00
42a1a3151f [Fix #6] Increase Font size for basket view 2018-10-08 09:39:24 +02:00
337462f010 CollapseAll after deleting a sale (item) 2018-10-08 09:23:03 +02:00
634b256da7 [Enh #7] Show seller no. in sales view 2018-10-08 09:20:59 +02:00
b76d1e129a [Fix #2] Change sort order in basket 2018-10-08 09:01:28 +02:00
a870736d72 [Fix #3] Update basket sum after deleting an article 2018-10-08 08:52:39 +02:00
18 changed files with 169 additions and 39 deletions

View file

@ -1,4 +1,3 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
@ -90,10 +89,6 @@ PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
@ -108,8 +103,7 @@ SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
Standard: Auto
TabWidth: 8
UseTab: Never
...

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.8)
project(kima2 VERSION 0.10.3)
project(kima2 VERSION 0.12.0)
set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake" ${CMAKE_MODULE_PATH})
@ -87,9 +87,9 @@ if( MINGW )
${MINGW_PATH}/libsqlite3-0.dll
${MINGW_PATH}/libusb-1.0.dll
${MINGW_PATH}/libxlnt.dll
${MINGW_PATH}/libicuuc61.dll
${MINGW_PATH}/libicuin61.dll
${MINGW_PATH}/libicudt61.dll
${MINGW_PATH}/libicuuc62.dll
${MINGW_PATH}/libicuin62.dll
${MINGW_PATH}/libicudt62.dll
${MINGW_PATH}/libjsoncpp-20.dll
${MINGW_PATH}/libpcre2-16-0.dll
${MINGW_PATH}/zlib1.dll

Binary file not shown.

Binary file not shown.

View file

@ -5,6 +5,8 @@
#include <stdexcept>
#include <vector>
#include "boost/date_time/posix_time/posix_time.hpp"
Database::Database(const std::string& dbname)
{
dbname_ = dbname;
@ -30,11 +32,29 @@ Database::Database()
throw err;
}
}
dbpath /= "kima2-cpp.db";
dbpath /= "kima2.db";
dbname_ = dbpath.string();
init();
}
void Database::newDb()
{
namespace fs = std::filesystem;
sqlite3_close(db_);
fs::path sourcePath = dbname_;
fs::path destPath = sourcePath.parent_path() / sourcePath.stem();
destPath += std::string("_") +=
boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time()) += ".db";
fs::copy_file(sourcePath, destPath, fs::copy_options::overwrite_existing);
fs::remove(sourcePath);
init();
}
Database::~Database() { sqlite3_close(db_); }
void Database::exec(const std::string& sql)
@ -55,7 +75,7 @@ void Database::createNew()
std::string sqlCreateKima2{"CREATE TABLE IF NOT EXISTS kima2 ("
"version INTEGER NOT NULL);"
"INSERT INTO kima2 (version) VALUES (1);"};
"INSERT INTO kima2 (version) VALUES (2);"};
sqlStrings.push_back(sqlCreateKima2);
std::string sqlCreateSellers{"CREATE TABLE IF NOT EXISTS sellers ("
"id TEXT PRIMARY KEY NOT NULL, "
@ -94,6 +114,12 @@ void Database::createNew()
");"};
sqlStrings.push_back(sqlCreateSalesItems);
std::string sqlInitialEntries{
"INSERT OR IGNORE INTO sellers (id, seller_no, first_name, last_name, "
"num_offered_articles) VALUES "
"('11111111-1111-1111-1111-111111111111', 0, 'Sonderkonto', 'Sonderkonto', 0)"};
sqlStrings.push_back(sqlInitialEntries);
beginTransaction();
for (const auto& sql : sqlStrings) {
exec(sql);

View file

@ -24,6 +24,7 @@ class Database
unsigned int loadSales(std::vector<std::unique_ptr<Sale>>& sales,
std::vector<std::unique_ptr<Seller>>& sellers);
void updateCashPointNo(int oldCashPointNo, int newCashPointNo);
void newDb();
private:
sqlite3* db_{nullptr};

View file

@ -7,6 +7,7 @@
#include <iomanip>
#include <numeric>
#include <sstream>
#include <filesystem>
namespace fs = std::filesystem;
@ -113,7 +114,7 @@ Seller* Marketplace::findSellerWithUuid(const std::string& uuid)
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
{
basket_.push_back(std::move(article));
basket_.insert(basket_.begin(), std::move(article)); // article to the beginning of the basket vector
}
size_t Marketplace::basketSize() { return basket_.size(); }
@ -272,7 +273,7 @@ std::string escapeCsvValue(const std::string& value, const char delimiter)
void Marketplace::clear()
{
std::for_each(sellers_.begin(), sellers_.end(), [](auto& seller) {
/* std::for_each(sellers_.begin(), sellers_.end(), [](auto& seller) {
if (seller->getUuidAsString() == "11111111-1111-1111-1111-111111111111") {
for (auto& article : seller->getArticles()) {
article->setState(Article::State::DELETE);
@ -283,5 +284,9 @@ void Marketplace::clear()
});
std::for_each(sales_.begin(), sales_.end(),
[](auto& sale) { sale->setState(Sale::State::DELETE); });
storeToDb();
storeToDb(); */
Database db;
db.newDb();
loadFromDb();
}

View file

@ -35,6 +35,16 @@ std::string Seller::getLastName() const { return lastName_; }
int Seller::getSellerNo() const { return sellerNo_; }
std::string Seller::getSellerNoAsString() const
{
std::stringstream selNoStr;
selNoStr << std::setfill('0') << std::setw(3) << sellerNo_;
return selNoStr.str();
;
}
std::vector<Article*> Seller::getArticles(bool onlySold) const
{
std::vector<Article*> articles;
@ -94,7 +104,6 @@ int Seller::sumInCents()
std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); }
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
{

View file

@ -28,6 +28,7 @@ class Seller : public Entity
std::string getFirstName() const;
std::string getLastName() const;
int getSellerNo() const;
std::string getSellerNoAsString() const;
int numArticlesOffered() const;
int numArticlesSold() const;
// int numArticlesTotal() const;

View file

@ -21,15 +21,19 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
if (role == Qt::FontRole) {
QFont myFont;
QFont myFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
switch (index.column()) {
case 0:
[[fallthrough]];
case 1:
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
return myFixedFont;
case 2:
return myFont;
myFixedFont.setPointSize(myFixedFont.pointSize() + 3);
return myFixedFont;
case 3:
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
myFixedFont.setPointSize(myFixedFont.pointSize() + 3);
return myFixedFont;
}
}

View file

@ -62,6 +62,7 @@ MainWindow::MainWindow()
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
marketplace_->clear();
setSaleModel();
updateStatLabel();
});
ui_.sellerNoEdit->installEventFilter(this);
@ -139,6 +140,8 @@ MainWindow::MainWindow()
readGeometry();
setWindowIcon(QIcon(":/misc/kima2.ico"));
updateStatLabel();
}
void MainWindow::onActionEditSellerTriggered()
@ -159,6 +162,7 @@ void MainWindow::onActionEditSellerTriggered()
}
setSaleModel();
updateStatLabel();
}
void MainWindow::setSaleModel()
@ -189,6 +193,7 @@ void MainWindow::onPaidButtonTriggered()
ui_.drawbackContainerWidget->setEnabled(false);
ui_.sellerNoEdit->setFocus();
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
updateStatLabel();
}
}
@ -255,11 +260,15 @@ void MainWindow::checkSellerNo(bool ctrlPressed)
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
if (seller) {
PriceDialog priceDialog(this);
if(sellerNo == 0) {
priceDialog.setForceDesc(true);
}
auto dialogResult = priceDialog.exec();
if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice();
std::string desc = priceDialog.getDescription();
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price, desc);
ui_.basketView->resizeColumnToContents(1);
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str());
}
}
@ -322,6 +331,9 @@ void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
ui_.basketView->model()->removeRow(iter->row());
}
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); // Update basket sum
ui_.sellerNoEdit->setFocus();
}
void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
@ -345,6 +357,9 @@ void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
ui_.salesView->model()->removeRow(iter->row(), iter->parent());
}
ui_.salesView->collapseAll();
updateStatLabel();
}
void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
@ -389,6 +404,9 @@ void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
return;
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); // Update basket sum
ui_.sellerNoEdit->setFocus();
}
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
@ -431,6 +449,7 @@ void MainWindow::onImportSellerExcelActionTriggered()
fs::path filePath(filename.toStdWString());
ExcelReader::readSellersFromFile(filePath, marketplace_.get());
updateStatLabel();
}
void MainWindow::onImportSellerJsonActionTriggered()
@ -452,6 +471,7 @@ void MainWindow::onImportSellerJsonActionTriggered()
fs::path filePath(filename.toStdWString());
JsonUtil::importSellers(filePath, marketplace_.get());
updateStatLabel();
}
void MainWindow::onExportSellerJsonActionTriggered()
@ -471,8 +491,10 @@ void MainWindow::onExportSalesJsonActionTriggered()
{
QSettings settings;
auto filename = QFileDialog::getSaveFileName(this, "Umsätze/Transaktionen exportieren",
QString(), "JSON Dateien (*.json)");
auto filename = QFileDialog::getSaveFileName(
this, "Umsätze/Transaktionen exportieren",
QString("kima2_umsaetze_kasse") + settings.value("global/cashPointNo").toString() + ".json",
"JSON Dateien (*.json)");
if (filename.isEmpty())
return;
@ -506,6 +528,7 @@ void MainWindow::onImportSalesJsonActionTriggered()
marketplace_->loadFromDb();
}
setSaleModel();
updateStatLabel();
}
void MainWindow::writeGeometry()
@ -533,3 +556,14 @@ void MainWindow::closeEvent(QCloseEvent* event)
writeGeometry();
event->accept();
}
void MainWindow::updateStatLabel()
{
std::string statistics("<b>KIMA2 - Version ");
statistics += PROJECT_VERSION;
statistics += "</b><br />Verkäufer: " + std::to_string(marketplace_->getSellers().size() - 1);
statistics += "<br />Kunden: " + std::to_string(marketplace_->getSales().size());
statistics += "<br />Umsatz: " + marketplace_->getOverallSumAsString();
ui_.statLabel->setText(statistics.c_str());
}

View file

@ -47,6 +47,7 @@ class MainWindow : public QMainWindow
void setSaleModel();
void writeGeometry();
void readGeometry();
void updateStatLabel();
Ui::MainWindow ui_;
std::unique_ptr<Marketplace> marketplace_;

View file

@ -92,7 +92,16 @@
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -166,7 +175,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Stornieren</string>
<string>&amp;Stornieren</string>
</property>
</widget>
</item>
@ -176,7 +185,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Alles stornieren</string>
<string>&amp;Alles stornieren</string>
</property>
</widget>
</item>
@ -331,6 +340,37 @@ drucken</string>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statLabel">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
@ -379,7 +419,7 @@ drucken</string>
<x>0</x>
<y>0</y>
<width>817</width>
<height>29</height>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menu_Datei">
@ -433,8 +473,7 @@ drucken</string>
<action name="actionQuit">
<property name="icon">
<iconset theme="application-exit">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Beenden</string>

View file

@ -4,8 +4,9 @@
#include <QMessageBox>
PriceDialog::PriceDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
PriceDialog::PriceDialog(QWidget* parent, bool forceDesc, Qt::WindowFlags f) : QDialog(parent, f)
{
forceDesc_ = forceDesc;
ui_.setupUi(this);
ui_.priceSpinBox->setFocus();
}
@ -21,7 +22,18 @@ void PriceDialog::accept()
"Es sind nur 0,50 Cent-Schritte erlaubt.", QMessageBox::StandardButton::Ok,
this)
.exec();
} else if (forceDesc_ && ui_.descEdit->text().trimmed().isEmpty()) {
QMessageBox(QMessageBox::Icon::Warning, "Artikelbeschreibung fehlt",
"Da Sie auf das Sonderkonto buchen ist eine Artikelbeschreibung erforderlich.",
QMessageBox::StandardButton::Ok, this)
.exec();
ui_.descEdit->setFocus();
} else {
QDialog::accept();
}
}
void PriceDialog::setForceDesc(bool force)
{
forceDesc_ = force;
}

View file

@ -10,15 +10,17 @@ class PriceDialog : public QDialog
Q_OBJECT
public:
PriceDialog(QWidget* parent = nullptr,
PriceDialog(QWidget* parent = nullptr, bool forceDesc = false,
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
int getPrice() const;
std::string getDescription() const;
void setForceDesc(bool force);
private:
void on_model_duplicateSellerNo(const QString& message);
virtual void accept() override;
Ui::PriceDialog ui_;
bool forceDesc_;
};
#endif

View file

@ -161,9 +161,10 @@ void ReportDialog::onPrintReportButtonClicked()
(static_cast<double>(numArticlesSold) / static_cast<double>(numArticlesOffered)) * 100;
content += QString("Registrierte Verkäufer: %1\n").arg(sellers.size() - 1, 6);
content += QString("Angelieferte Artikel: %1\n").arg(numArticlesOffered, 6);
content += QString("Verkaufte Artikel: %1 (%L2 %)\n\n")
content += QString("Verkaufte Artikel: %1 (%L2 %)\n")
.arg(numArticlesSold, 6)
.arg(percentArticlesSold, 0, 'f', 2);
content += QString("Anzahl Kunden: %1\n\n").arg(market_->getSales().size(), 6);
content += QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10);
content +=
QString("Ausgezahlt: %1\n")

View file

@ -108,7 +108,7 @@ QVariant SaleModel::data(const QModelIndex& index, int role) const
Article* article = static_cast<Article*>(index.internalPointer());
switch (index.column()) {
case 0:
return article->getCompleteArticleNo().c_str();
return (std::string("Verk. ") + std::to_string(article->getSeller()->getSellerNo()) + " (" + article->getCompleteArticleNo() + ")").c_str();
case 1:
return article->getPriceAsString().c_str();
case 2:
@ -146,7 +146,7 @@ QVariant SaleModel::headerData(int section, Qt::Orientation orientation, int rol
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return "Zeit / Art.Nr.";
return "Zeit / Verk.Nr. (Art.Nr)";
case 1:
return "Preis";
default:

View file

@ -46,7 +46,8 @@ PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_(prin
if (printerDevice_.idVendor == 0) {
for (const auto& supported : supportedPrinters_.models) {
if (desc.idVendor == std::get<0>(supported) && desc.idProduct == std::get<1>(supported)) {
if (desc.idVendor == std::get<0>(supported) &&
desc.idProduct == std::get<1>(supported)) {
numDevice = i;
printerEndpoint_ = std::get<2>(supported);
break;
@ -161,8 +162,8 @@ void PosPrinter::printSaleReceipt(Sale* sale)
commandStream << sale->getTimestampFormatted() << "\n\n";
commandStream << Command::LEFT_ALIGN;
for (const auto& article : sale->getArticles()) {
commandStream << "Art. " << article->getCompleteArticleNo() << "........... "
<< article->getPriceAsString() << "\n";
commandStream << "Verk.Nr. " << article->getSeller()->getSellerNoAsString()
<< "........... " << article->getPriceAsString() << "\n";
}
commandStream << "\nGesamt................. " << sale->sumAsString() << "\n";
commandStream << Command::CENTERING;