diff --git a/commodity/commodityform.cpp b/commodity/commodityform.cpp index 7daacdd..f8c2cba 100644 --- a/commodity/commodityform.cpp +++ b/commodity/commodityform.cpp @@ -30,11 +30,6 @@ CommodityForm::~CommodityForm() void CommodityForm::registerCombos() { - QList ct; - Service cts; - foreach (QSharedPointer ctd , cts.all()) { - ComboData cd(ctd); - ct << cd; - } - registerBinding(ui->type,ct); + Service srvComTypes; + registerBinding(ui->type, ComboData::createComboData(srvComTypes.all())); } diff --git a/core/combodata.h b/core/combodata.h index 2e8bfff..945984a 100644 --- a/core/combodata.h +++ b/core/combodata.h @@ -20,6 +20,20 @@ public: QString label() const; void setLabel(const QString &label); + template + static QList createComboData(QList > list) { + QList data; + foreach (QSharedPointer item, list) { + QSharedPointer qObj = qSharedPointerDynamicCast(item); + if (!qObj.isNull()) + { + data << ComboData(qObj); + } + } + + return data; + } + private: QVariant m_index; QString m_label; diff --git a/core/context.cpp b/core/context.cpp index 08cf434..c658df6 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -125,6 +125,16 @@ Context::Context() m_dbOpened = false; } +SeasonPtr Context::currentSeason() const +{ + return m_currentSeason; +} + +void Context::setCurrentSeason(const SeasonPtr ¤tSeason) +{ + m_currentSeason = currentSeason; +} + QSharedPointer Context::currentUser() const { return m_currentUser; @@ -271,6 +281,8 @@ void Context::checkSeason() season->setActive(true); srv.save(season); } + + m_currentSeason = season; } void Context::checkNumberSeries() diff --git a/core/context.h b/core/context.h index 7eb06a7..2ff1eac 100644 --- a/core/context.h +++ b/core/context.h @@ -39,6 +39,11 @@ public: odb::session &session(); + SeasonPtr currentSeason() const; + void setCurrentSeason(const SeasonPtr ¤tSeason); + + void checkNumberSeries(); + private: Context(); QList m_plugins; @@ -47,6 +52,7 @@ private: bool m_dbOpened; odb::session m_session; QSharedPointer m_currentUser; + SeasonPtr m_currentSeason; QStringList m_solved; @@ -56,7 +62,6 @@ private: void createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap &schemaMap); void checkPermissions(); void checkSeason(); - void checkNumberSeries(); }; #endif // CONTEXT_H diff --git a/core/core.pro b/core/core.pro index 0a86309..8b9a091 100644 --- a/core/core.pro +++ b/core/core.pro @@ -56,7 +56,8 @@ SOURCES += \ data/numberseries.cpp \ data/season.cpp \ seasonservice.cpp \ - numberseriesservice.cpp + numberseriesservice.cpp \ + settings/seasonnamedialog.cpp HEADERS += core.h\ core_global.h \ @@ -112,7 +113,8 @@ HEADERS += core.h\ data/numberseries.h \ data/season.h \ seasonservice.h \ - numberseriesservice.h + numberseriesservice.h \ + settings/seasonnamedialog.h unix { target.path = /usr/lib @@ -146,7 +148,8 @@ FORMS += \ savefilterdialog.ui \ filterdialog.ui \ settingsform.ui \ - settings/globalsettingsform.ui + settings/globalsettingsform.ui \ + settings/seasonnamedialog.ui OTHER_FILES += \ users/metaData.json \ @@ -154,6 +157,9 @@ OTHER_FILES += \ CONFIG(debug, release|debug):DEFINES += _DEBUG +win32:CONFIG(release, debug|release):DEFINES += PLUGIN_ROOT=\\\"/plugins\\\" +else:unix:CONFIG(release, debug|release):DEFINES += PLUGIN_ROOT=\\\"/usr/lib/prodejna/plugins\\\" + win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber else:unix: LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber diff --git a/core/data/numberseries.h b/core/data/numberseries.h index 7c189e0..0ef04ad 100644 --- a/core/data/numberseries.h +++ b/core/data/numberseries.h @@ -49,4 +49,6 @@ private: QSharedPointer m_season; }; +typedef QSharedPointer NumberSeriesPtr; + #endif // NUMBERSERIES_H diff --git a/core/data/season.h b/core/data/season.h index cf7158d..e96e852 100644 --- a/core/data/season.h +++ b/core/data/season.h @@ -46,4 +46,6 @@ private: bool m_active; }; +typedef QSharedPointer SeasonPtr; + #endif // SEASON_H diff --git a/core/settings/globalsettingsform.cpp b/core/settings/globalsettingsform.cpp index 3aab7c6..06cf031 100644 --- a/core/settings/globalsettingsform.cpp +++ b/core/settings/globalsettingsform.cpp @@ -1,8 +1,14 @@ #include "globalsettingsform.h" #include "ui_globalsettingsform.h" +#include + +#include "seasonnamedialog.h" #include "globalsettings.h" #include "../settingsservice.h" +#include "../seasonservice.h" +#include "../numberseriesservice.h" +#include "core-odb.hxx" GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) : FormBinder(parent), @@ -21,6 +27,10 @@ GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) : registerBinding(ui->vatHigh); registerBinding(ui->vatFirstLower); registerBinding(ui->vatSecondLower); + + m_seriesModel = new AutoTableModel(this); + m_seriesModel->setEditableCols(QList() << 0); + ui->tableNumSer->setModel(m_seriesModel); } GlobalSettingsForm::~GlobalSettingsForm() @@ -28,8 +38,61 @@ GlobalSettingsForm::~GlobalSettingsForm() delete ui; } +void GlobalSettingsForm::loadSeasons() +{ + ui->season->clear(); + SeasonService srv; + m_seasons = srv.all(); + + foreach (SeasonPtr season, m_seasons) { + ui->season->addItem(season->name()); + + if (season->active()) + { + ui->season->setCurrentIndex(ui->season->count() - 1); + } + } +} + +void GlobalSettingsForm::loadNumSeries() +{ + NumberSeriesService srvNumSer; + SeasonService srvSeason; + + if (ui->season->currentIndex() >= 0) + { + SeasonPtr currentSeason = m_seasons[ui->season->currentIndex()]; + m_seriesModel->setData(srvNumSer.allForSeason(currentSeason)); + } +} + bool GlobalSettingsForm::saveRecord() { + SeasonService srvSeason; + NumberSeriesService srvNumSer; + + SeasonPtr selSeason = m_seasons[ui->season->currentIndex()]; + if (selSeason->id() != Context::instance().currentSeason()->id()) + { + if (QMessageBox::question(this, tr("Switch season"), tr("Realy switch active season?")) == QMessageBox::Yes) + { + srvSeason.activate(selSeason); + Context::instance().setCurrentSeason(selSeason); + } + else + { + return false; + } + } + + foreach (SeasonPtr season, m_seasons) { + srvSeason.update(season); + } + + foreach (NumberSeriesPtr numSer, m_seriesModel->list()) { + srvNumSer.update(numSer); + } + bindToData(); SettingsService srv("CORE"); srv.saveSettings(entity()); @@ -43,9 +106,52 @@ void GlobalSettingsForm::loadEntity() QSharedPointer settings = srv.loadSettings(); setEntity(settings); ui->grpVat->setEnabled(settings->vatPayer()); + + loadSeasons(); + loadNumSeries(); } void GlobalSettingsForm::on_vatPayer_toggled(bool checked) { ui->grpVat->setEnabled(checked); } + +void GlobalSettingsForm::on_season_currentIndexChanged(int) +{ + loadNumSeries(); +} + +void GlobalSettingsForm::on_btnEditName_clicked() +{ + SeasonPtr selSeason = m_seasons[ui->season->currentIndex()]; + SeasonNameDialog *dialog = new SeasonNameDialog(selSeason, this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + + connect(dialog, &QDialog::accepted, [this](){ + this->loadSeasons(); + }); +} + +void GlobalSettingsForm::on_btnNew_clicked() +{ + if (QMessageBox::question(this, tr("New season"), tr("Realy create new season and switch to it?")) == QMessageBox::Yes) + { + SeasonPtr newSeason = SeasonPtr(new Season); + SeasonNameDialog *dialog = new SeasonNameDialog(newSeason, this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + + connect(dialog, &QDialog::accepted, [this, newSeason](){ + SeasonService srv; + newSeason->setValidFrom(QDate::currentDate()); + srv.save(newSeason); + srv.activate(newSeason); + Context::instance().setCurrentSeason(newSeason); + Context::instance().checkNumberSeries(); + + this->loadSeasons(); + this->loadNumSeries(); + }); + } +} diff --git a/core/settings/globalsettingsform.h b/core/settings/globalsettingsform.h index e355b3f..8db5838 100644 --- a/core/settings/globalsettingsform.h +++ b/core/settings/globalsettingsform.h @@ -4,6 +4,8 @@ #include #include "../formbinder.h" #include "globalsettings.h" +#include "../autotablemodel.h" +#include "../data/numberseries.h" namespace Ui { class GlobalSettingsForm; @@ -19,6 +21,11 @@ public: private: Ui::GlobalSettingsForm *ui; + AutoTableModel *m_seriesModel; + QList m_seasons; + + void loadSeasons(); + void loadNumSeries(); // IForm interface public slots: @@ -29,6 +36,9 @@ public: void loadEntity() override; private slots: void on_vatPayer_toggled(bool checked); + void on_season_currentIndexChanged(int index); + void on_btnEditName_clicked(); + void on_btnNew_clicked(); }; #endif // GLOBALSETTINGSFORM_H diff --git a/core/settings/globalsettingsform.ui b/core/settings/globalsettingsform.ui index 5a87665..0907e4c 100644 --- a/core/settings/globalsettingsform.ui +++ b/core/settings/globalsettingsform.ui @@ -6,194 +6,293 @@ 0 0 - 586 - 419 + 759 + 552 Form - - - - Company info - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - IC - - - - - - - - - - VAT number - - - - - - - - - - VAT payer - - - - - - - - 0 - 0 - - - - VAT rates - - - - - - High - - - - - - - QAbstractSpinBox::NoButtons - - - - - - - First lower - - - - - - - QAbstractSpinBox::NoButtons - - - - - - - Second lower - - - - - - - QAbstractSpinBox::NoButtons - - - - - - - - - - - - Contact + + + QTabWidget::North - - - - - Firm Name - - - - - - - - - - Street - - - - - - - - - - House Number - - - - - - - - - - City - - - - - - - - - - ZIP code - - - - - - - - - - - - - Logo + + QTabWidget::Rounded + + + 0 + + + Qt::ElideNone - - - - - Logo - - - - - - - Select file - - - - + + + Base settings + + + + + + Contact + + + + + + Firm Name + + + + + + + + + + Street + + + + + + + + + + House Number + + + + + + + + + + City + + + + + + + + + + ZIP code + + + + + + + + + + + + + Logo + + + + + + Logo + + + + + + + Select file + + + + + + + + + + Company info + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + IC + + + + + + + + + + VAT number + + + + + + + + + + VAT payer + + + + + + + + 0 + 0 + + + + VAT rates + + + + + + High + + + + + + + QAbstractSpinBox::NoButtons + + + + + + + First lower + + + + + + + QAbstractSpinBox::NoButtons + + + + + + + Second lower + + + + + + + QAbstractSpinBox::NoButtons + + + + + + + + + + + + + + Number series + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 120 + 0 + + + + + + + + Edit name + + + + :/icons/edit.svg:/icons/edit.svg + + + + + + + Season + + + + + + + Create new + + + + :/icons/new.svg:/icons/new.svg + + + false + + + + + + + Number series + + + + + + + + + + - + + + diff --git a/core/settings/seasonnamedialog.cpp b/core/settings/seasonnamedialog.cpp new file mode 100644 index 0000000..ef3dcd2 --- /dev/null +++ b/core/settings/seasonnamedialog.cpp @@ -0,0 +1,24 @@ +#include "seasonnamedialog.h" +#include "ui_seasonnamedialog.h" + +SeasonNameDialog::SeasonNameDialog(SeasonPtr season, QWidget *parent) : + QDialog(parent), + ui(new Ui::SeasonNameDialog) +{ + ui->setupUi(this); + + m_binder.registerBinding(ui->name); + m_binder.setData(season.data()); + m_binder.bindToUi(); +} + +SeasonNameDialog::~SeasonNameDialog() +{ + delete ui; +} + +void SeasonNameDialog::accept() +{ + m_binder.bindToData(); + QDialog::accept(); +} diff --git a/core/settings/seasonnamedialog.h b/core/settings/seasonnamedialog.h new file mode 100644 index 0000000..ffa7b31 --- /dev/null +++ b/core/settings/seasonnamedialog.h @@ -0,0 +1,30 @@ +#ifndef SEASONNAMEDIALOG_H +#define SEASONNAMEDIALOG_H + +#include + +#include "../data/season.h" +#include "../objectbinder.h" + +namespace Ui { +class SeasonNameDialog; +} + +class SeasonNameDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SeasonNameDialog(SeasonPtr season, QWidget *parent = 0); + ~SeasonNameDialog(); + +private: + Ui::SeasonNameDialog *ui; + ObjectBinder m_binder; + + // QDialog interface +public slots: + void accept(); +}; + +#endif // SEASONNAMEDIALOG_H diff --git a/core/settings/seasonnamedialog.ui b/core/settings/seasonnamedialog.ui new file mode 100644 index 0000000..35e4ce9 --- /dev/null +++ b/core/settings/seasonnamedialog.ui @@ -0,0 +1,77 @@ + + + SeasonNameDialog + + + + 0 + 0 + 406 + 82 + + + + Season + + + true + + + + + + Season name + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SeasonNameDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SeasonNameDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/core/settingsform.ui b/core/settingsform.ui index f6b41b7..3041060 100644 --- a/core/settingsform.ui +++ b/core/settingsform.ui @@ -16,6 +16,10 @@ Settings + + + :/icons/settings.svg:/icons/settings.svg + @@ -39,6 +43,8 @@ - + + + diff --git a/shop/receiptsaveform.cpp b/shop/receiptsaveform.cpp index f3dd4e8..e1c0751 100644 --- a/shop/receiptsaveform.cpp +++ b/shop/receiptsaveform.cpp @@ -44,14 +44,9 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) : ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); }); - AddressBookService srvAdb; - QList comboData; - foreach (QSharedPointer adb, srvAdb.all()) { - comboData << ComboData(adb); - } - m_binder.setData(new Voucher); - m_binder.registerBinding(ui->contact, comboData); + AddressBookService srvAdb; + m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all())); m_binder.bindToUi(); ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion);