diff --git a/camp/addservicedialog.cpp b/camp/addservicedialog.cpp new file mode 100644 index 0000000..7b813dd --- /dev/null +++ b/camp/addservicedialog.cpp @@ -0,0 +1,27 @@ +#include "addservicedialog.h" +#include "ui_addservicedialog.h" + +AddServiceDialog::AddServiceDialog(AccServicePtr service, QWidget *parent) : + QDialog(parent), + ui(new Ui::AddServiceDialog) +{ + ui->setupUi(this); + + ui->editName->setText(service->accServiceName()); + ui->editPrice->setValue(service->price().toDouble()); +} + +AddServiceDialog::~AddServiceDialog() +{ + delete ui; +} + +QString AddServiceDialog::description() +{ + return ui->editDescription->text(); +} + +QDecDouble AddServiceDialog::price() +{ + return QDecDouble(ui->editPrice->value()); +} diff --git a/camp/addservicedialog.h b/camp/addservicedialog.h new file mode 100644 index 0000000..31ba935 --- /dev/null +++ b/camp/addservicedialog.h @@ -0,0 +1,27 @@ +#ifndef ADDSERVICEDIALOG_H +#define ADDSERVICEDIALOG_H + +#include +#include +#include + +namespace Ui { +class AddServiceDialog; +} + +class AddServiceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AddServiceDialog(AccServicePtr service, QWidget *parent = 0); + ~AddServiceDialog(); + + QString description(); + QDecDouble price(); + +private: + Ui::AddServiceDialog *ui; +}; + +#endif // ADDSERVICEDIALOG_H diff --git a/camp/addservicedialog.ui b/camp/addservicedialog.ui new file mode 100644 index 0000000..d02a1c7 --- /dev/null +++ b/camp/addservicedialog.ui @@ -0,0 +1,105 @@ + + + AddServiceDialog + + + + 0 + 0 + 400 + 143 + + + + Dialog + + + + + + Service name + + + + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + Description + + + + + + + QAbstractSpinBox::NoButtons + + + 999999.989999999990687 + + + + + + + Price + + + + + + + + + buttonBox + accepted() + AddServiceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddServiceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/camp/camp.cpp b/camp/camp.cpp index 156c912..94e3e2e 100644 --- a/camp/camp.cpp +++ b/camp/camp.cpp @@ -25,3 +25,8 @@ QTranslator *Camp::translator() { return translatorFrom(":/translations/camp_"); } + +bool Camp::hasNumberSeries() +{ + return true; +} diff --git a/camp/camp.h b/camp/camp.h index 2073a4b..a27fd14 100644 --- a/camp/camp.h +++ b/camp/camp.h @@ -23,6 +23,7 @@ protected: public: virtual QIcon pluginIcon(); QTranslator *translator(); + bool hasNumberSeries(); }; #endif // CAMP_H diff --git a/camp/camp.json b/camp/camp.json index fc5d329..cbbecf4 100644 --- a/camp/camp.json +++ b/camp/camp.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 3, + "schemaVersion" : 5, "sql" : [ "CREATE TABLE \"CampData\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -80,8 +80,17 @@ CREATE TABLE \"PersonPrice\" ( ", "ALTER TABLE AddressItem ADD \"owner\" INTEGER NULL; -" +", +"ALTER TABLE ServiceItem ADD \"sale\" INTEGER NULL; +ALTER TABLE ServiceItem ADD \"description\" TEXT NULL; +", + +"ALTER TABLE ServiceItem ADD \"totalPrice\" INTEGER NULL; +ALTER TABLE ServiceItem ADD \"fullPrice\" INTEGER NULL; +ALTER TABLE CampData ADD \"fullPrice\" INTEGER NULL; +ALTER TABLE CampData ADD \"totalSale\" INTEGER NULL; +" ], "dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ], "translations" : { diff --git a/camp/camp.pro b/camp/camp.pro index cb46bf7..3cae173 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -33,7 +33,8 @@ SOURCES += camp.cpp \ data/personprice.cpp \ settings/campsettings.cpp \ campwizard.cpp \ - campservice.cpp + campservice.cpp \ + addservicedialog.cpp HEADERS += camp.h\ camp_global.h \ @@ -48,7 +49,8 @@ HEADERS += camp.h\ data/personprice.h \ settings/campsettings.h \ campwizard.h \ - campservice.h + campservice.h \ + addservicedialog.h include(../config_plugin.pri) @@ -94,4 +96,5 @@ RESOURCES += \ FORMS += \ campform.ui \ settings/campsettingsform.ui \ - campwizard.ui + campwizard.ui \ + addservicedialog.ui diff --git a/camp/campgrid.cpp b/camp/campgrid.cpp index a4532c2..73a07a7 100644 --- a/camp/campgrid.cpp +++ b/camp/campgrid.cpp @@ -10,9 +10,14 @@ CampGrid::CampGrid(QWidget *parent) : GridForm(parent) void CampGrid::handleNewRecord() { CampService srv; + CampDataPtr data = srv.create(); CampWizard *wizard = new CampWizard(); wizard->setAttribute(Qt::WA_DeleteOnClose); - wizard->setData(srv.create()); + wizard->setData(data); + + connect(wizard, &QDialog::accepted, [this, data](){ + addRow(data); + }); wizard->show(); } diff --git a/camp/campservice.cpp b/camp/campservice.cpp index d3d6580..323cd7d 100644 --- a/camp/campservice.cpp +++ b/camp/campservice.cpp @@ -1,7 +1,14 @@ #include "campservice.h" +#include +#include +#include +#include CampService::CampService() { + SettingsService srv("CAMP"); + m_settings = srv.loadSettings(); + m_pluginId = "CAMP"; } void CampService::addPerson(CampDataPtr data, AddressbookDataPtr address) @@ -22,6 +29,26 @@ void CampService::addPerson(CampDataPtr data, AddressbookDataPtr address) data->addPerson(addrItem); } +void CampService::addService(CampDataPtr data, AccServicePtr service) +{ + ServiceItemPtr serviceItem(new ServiceItem); + + serviceItem->setName(service->accServiceName()); + serviceItem->setCode(service->accServiceCode()); + serviceItem->setPrice(service->price()); + serviceItem->setSalePossible(service->salePossible()); + serviceItem->setType(service->serviceType()); + + data->addServiceItem(serviceItem); +} + +void CampService::addService(CampDataPtr data, AccServicePtr service, QDecDouble price, QString description) +{ + ServiceItemPtr item = addServiceInt(data, service); + item->setPrice(price); + item->setDescription(description); +} + void CampService::setOwner(CampDataPtr data, AddressItemPtr person) { foreach (AddressItemPtr p, data->people()) { @@ -43,3 +70,217 @@ CampDataPtr CampService::create() return data; } + +void CampService::calculate(CampDataPtr data) +{ + calcServices(data); + calcPeople(data); + calcPrice(data); +} + +void CampService::saveCamp(CampDataPtr data) +{ + if (!checkPermission(PERM_ADD)) + { + return; + } + + SeasonService seasonSrv; + SeasonPtr season = seasonSrv.active(); + data->setSeason(season); + + Transaction tr; + try + { + odb::database *db = Context::instance().db(); + + NumberSeriesService numSrv; + data->setNumSer(numSrv.nextStrForPlugin("CAMP")); + + db->persist(data); + + foreach (ServiceItemPtr item, data->services()) { + item->setCampData(data.toWeakRef()); + db->persist(item); + } + + foreach (AddressItemPtr item, data->people()) { + item->setCampData(data.toWeakRef()); + db->persist(item); + } + + tr.commit(); + } + catch (const odb::exception &ex) + { + emit dbError(ex.what()); + emit dbErrorUpdate(ex.what()); + return; + } +} + +void CampService::calcPeople(CampDataPtr data) +{ + foreach (ServiceItemPtr service, data->services()) { + if (service->type() == AccService::ACCFEE) + { + data->removeServiceItem(service); + } + } + + Service srvPrices; + QList prices = srvPrices.all("active = 1"); + int days = data->start().daysTo(data->end()); + + foreach (AddressItemPtr item, data->people()) { + QDate first(1,1,1); + qint64 daysStart = item->adbItem()->birthDate().daysTo(data->start()); + first = first.addDays(daysStart); + int startAge = first.year() - 1; + + first = QDate(1,1,1); + qint64 daysEnd = item->adbItem()->birthDate().daysTo(data->end()); + first = first.addDays(daysEnd); + int endAge = first.year() - 1; + + if (!item->personPrice().isNull()) + { + item->setPrice(item->personPrice()->price() * days); + addAccFee(data, item, startAge, endAge, days); + continue; + } + else + { + item->setPrice(0); + } + + foreach (PersonPricePtr price, prices) { + if (price->fromAge() <= endAge && price->toAge() >= endAge) + { + item->setPersonPrice(price); + item->setPrice(price->price() * days); + break; + } + } + + if (item->adbItem()->ztp()) + { + continue; + } + + addAccFee(data, item, startAge, endAge, days); + } +} + +void CampService::calcServices(CampDataPtr data) +{ + QDecDouble sale = data->sale(); + bool fixedSale = data->fixedSale(); + int days = data->start().daysTo(data->end()); + + foreach (ServiceItemPtr item, data->services()) { + item->setFullPrice(item->price() * days); + + if (sale != QDecDouble(0) && !fixedSale && item->salePossible()) + { + QDecDouble itemSale = (item->fullPrice() * sale) / 100; + item->setSale(itemSale); + item->setTotalPrice(item->fullPrice() - itemSale); + } + else + { + item->setSale(0); + item->setTotalPrice(item->fullPrice()); + } + } +} + +void CampService::calcPrice(CampDataPtr data) +{ + QDecDouble totalPrice(0); + QDecDouble sale(0); + + foreach (ServiceItemPtr service, data->services()) { + totalPrice += service->totalPrice(); + sale += service->sale(); + } + + foreach (AddressItemPtr addr, data->people()) { + totalPrice += addr->price(); + } + + if (data->fixedSale()) + { + totalPrice -= data->sale(); + sale = data->sale(); + } + + switch (m_settings->rounding()) { + case Enums::R_UP: + totalPrice = QDecDouble(ceil(totalPrice.toDouble() * pow(10, m_settings->decimalPlaces())) / pow(10, m_settings->decimalPlaces())); + break; + case Enums::R_DOWN: + totalPrice = QDecDouble(floor(totalPrice.toDouble() * pow(10, m_settings->decimalPlaces())) / pow(10, m_settings->decimalPlaces())); + break; + case Enums::R_MATH: + totalPrice = QDecDouble(round(totalPrice.toDouble() * pow(10, m_settings->decimalPlaces())) / pow(10, m_settings->decimalPlaces())); + break; + case Enums::R_NONE: + break; + } + + data->setTotalPrice(totalPrice); + data->setTotalSale(sale); +} + +void CampService::addAccFee(CampDataPtr data, AddressItemPtr item, int startAge, int endAge, int days) +{ + auto addAccService = [this, item, data](int count){ + ServiceItemPtr srvItem(new ServiceItem); + + srvItem->setName(item->firstName() + " " + item->lastName()); + srvItem->setDescription(m_settings->accFeeText()); + srvItem->setPrice(m_settings->accFee()); + srvItem->setTotalPrice(m_settings->accFee() * count); + srvItem->setFullPrice(srvItem->totalPrice()); + srvItem->setType(AccService::ACCFEE); + srvItem->setSalePossible(false); + srvItem->setCampData(data); + data->addServiceItem(srvItem); + }; + + if (startAge == endAge || (startAge >= m_settings->accFeeStartAge() && startAge <= m_settings->accFeeEndAge())) + { + if (endAge >= m_settings->accFeeStartAge() && endAge <= m_settings->accFeeEndAge()) + { + addAccService(days); + } + } + else + { + if (endAge >= m_settings->accFeeStartAge() && endAge <= m_settings->accFeeEndAge()) + { + QDate tmp(data->end().year(), item->adbItem()->birthDate().month(), item->adbItem()->birthDate().day()); + int count = tmp.daysTo(data->end()); + + addAccService(count); + } + } +} + +ServiceItemPtr CampService::addServiceInt(CampDataPtr data, AccServicePtr service) +{ + ServiceItemPtr serviceItem(new ServiceItem); + + serviceItem->setName(service->accServiceName()); + serviceItem->setCode(service->accServiceCode()); + serviceItem->setPrice(service->price()); + serviceItem->setSalePossible(service->salePossible()); + serviceItem->setType(service->serviceType()); + serviceItem->setCampData(data); + + data->addServiceItem(serviceItem); + + return serviceItem; +} + diff --git a/camp/campservice.h b/camp/campservice.h index 1760707..f58b07a 100644 --- a/camp/campservice.h +++ b/camp/campservice.h @@ -3,7 +3,9 @@ #include #include +#include #include "data/camp-data.h" +#include "settings/campsettings.h" #include "camp-odb.hxx" class CampService : public Service @@ -11,8 +13,20 @@ class CampService : public Service public: CampService(); void addPerson(CampDataPtr data, AddressbookDataPtr address); + void addService(CampDataPtr data, AccServicePtr service); + void addService(CampDataPtr data, AccServicePtr service, QDecDouble price, QString description); void setOwner(CampDataPtr data, AddressItemPtr person); CampDataPtr create(); + void calculate(CampDataPtr data); + void saveCamp(CampDataPtr data); + +private: + ServiceItemPtr addServiceInt(CampDataPtr data, AccServicePtr service); + void calcPeople(CampDataPtr data); + void calcServices(CampDataPtr data); + void calcPrice(CampDataPtr data); + void addAccFee(CampDataPtr data, AddressItemPtr item, int startAge, int endAge, int days); + CampSettingsPtr m_settings; }; #endif // CAMPSERVICE_H diff --git a/camp/campwizard.cpp b/camp/campwizard.cpp index 22e0f42..5a3d382 100644 --- a/camp/campwizard.cpp +++ b/camp/campwizard.cpp @@ -1,9 +1,16 @@ #include "campwizard.h" #include "ui_campwizard.h" #include "campservice.h" +#include "addservicedialog.h" + #include #include +#include +//////////////////////////////////// +/// \brief AddressHelper::AddressHelper +/// \param parent +/// AddressHelper::AddressHelper(QObject *parent) :QObject(parent) { @@ -51,6 +58,39 @@ AddressbookDataPtr AddressHelper::copyAddress() return m_copyAddress; } +////////////////////////////////////////////////////////////// +/// \brief SaleHelper::SaleHelper +/// \param parent +/// +SaleHelper::SaleHelper(QObject *parent) :QObject(parent) +{ + m_sale = SalePtr(new Sale); +} + +SalePtr SaleHelper::salePtr() const +{ + return m_sale; +} + +void SaleHelper::setSalePtr(const SalePtr &sale) +{ + m_sale = sale; +} + +QSharedPointer SaleHelper::sale() const +{ + return m_sale; +} + +void SaleHelper::setSale(const QSharedPointer &sale) +{ + if (qobject_cast(sale.data()) != NULL) + { + m_sale = qSharedPointerDynamicCast(sale); + emit saleChanged(); + } +} + /////////////////////////////////////////////////////////// /// \brief CampWizard::CampWizard /// \param parent @@ -76,6 +116,8 @@ CampWizard::CampWizard(QWidget *parent) : m_dataBinder = new ObjectBinder(this); m_dataBinder->registerBinding(ui->start); m_dataBinder->registerBinding(ui->end); + m_dataBinder->registerBinding(ui->totalPrice); + m_dataBinder->registerBinding(ui->totalSale); m_addrHelper = new AddressHelper(this); @@ -103,6 +145,47 @@ CampWizard::CampWizard(QWidget *parent) : m_addressBinder->bindToUi(); m_bindAddrCombo = true; + + Service serviceSrv; + m_servicesModel = new AutoTableModel(this); + m_servicesModel->setData(serviceSrv.all()); + ui->tableServices->setModel(m_servicesModel); + + ui->tableServices->hideColumn(1); + ui->tableServices->hideColumn(3); + ui->tableServices->hideColumn(4); + ui->tableServices->hideColumn(5); + ui->tableServices->hideColumn(6); + + ui->tableServices->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + m_itemsModel = new AutoTableModel(); + ui->tableItems->setModel(m_itemsModel); + + ui->tableItems->hideColumn(1); + ui->tableItems->hideColumn(4); + ui->tableItems->hideColumn(5); + ui->tableItems->hideColumn(6); + + ui->tableItems->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); + + connect(ui->tableServices->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex current, QModelIndex){ + ui->btnAddService->setEnabled(current.isValid()); + }); + + connect(ui->tableItems->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex, QModelIndex){ + ui->btnRemoveService->setEnabled(!m_data->services().isEmpty()); + }); + + m_saleHelper = new SaleHelper(this); + m_saleBinder = new ObjectBinder(this); + Service saleSrv; + m_saleBinder->registerBinding(ui->sale, ComboData::createComboData(saleSrv.all())); + m_saleBinder->setData(m_saleHelper); + m_saleBinder->bindToUi(); + + ui->tabPeople->setModel(m_peopleModel); + ui->tabServices->setModel(m_itemsModel); } CampWizard::~CampWizard() @@ -117,6 +200,9 @@ void CampWizard::setData(const CampDataPtr &data) m_dataBinder->setData(data.data()); m_dataBinder->bindToUi(); m_addrHelperBinder->bindToUi(); + + m_peopleModel->setData(data->people()); + m_itemsModel->setData(data->services()); } void CampWizard::on_btnAdd_clicked() @@ -192,5 +278,119 @@ void CampWizard::on_groupNew_clicked(bool checked) void CampWizard::on_CampWizard_currentIdChanged(int id) { + if (id == 2) + { + CampService srv; + srv.calculate(m_data); + + m_dataBinder->bindToUi(); + m_itemsModel->setData(m_data->services()); + + ui->lFrom->setText(m_data->start().toString()); + ui->lTo->setText(m_data->end().toString()); + ui->lDays->setText(QString::number(m_data->start().daysTo(m_data->end()))); + ui->lOwner->setText(m_data->ownerAddress()); + } +} + +void CampWizard::on_btnAddService_clicked() +{ + AccServicePtr service = m_servicesModel->itemFromIndex(ui->tableServices->currentIndex()); + AddServiceDialog *dialog = new AddServiceDialog(service, this); + + dialog->setAttribute(Qt::WA_DeleteOnClose); + + connect(dialog, &QDialog::accepted, [=](){ + CampService srv; + srv.addService(m_data, service, dialog->price(), dialog->description()); + m_itemsModel->setData(m_data->services()); + }); + + dialog->show(); +} + +void CampWizard::on_btnRemoveService_clicked() +{ + ServiceItemPtr item = m_itemsModel->itemFromIndex(ui->tableItems->currentIndex()); + m_data->removeServiceItem(item); + m_itemsModel->setData(m_data->services()); + + ui->btnRemoveService->setEnabled(false); +} + +void CampWizard::on_checkSale_clicked() +{ + ui->sale->setEnabled(ui->checkSale->isChecked()); + applySale(); +} + +void CampWizard::applySale() +{ + if (m_data.isNull()) + { + return; + } + + if (ui->checkSale->isChecked()) + { + m_saleBinder->bindToData(); + m_data->setSale(m_saleHelper->salePtr()->sale()); + m_data->setFixedSale(m_saleHelper->salePtr()->fixed()); + } + else + { + m_data->setSale(QDecDouble(0)); + } +} + +void CampWizard::on_sale_currentIndexChanged(int) +{ + applySale(); +} +bool CampWizard::validateCurrentPage() +{ + m_dataBinder->bindToData(); + + if (currentPage() == ui->peoplePage && m_data->people().isEmpty()) + { + QMessageBox::critical(this, tr("Error"), tr("Add people.")); + return false; + } + + if (currentPage() == ui->peoplePage && m_data->start() >= m_data->end()) + { + QMessageBox::critical(this, tr("Error"), tr("Start date is after or equals end date.")); + return false; + } + + if (currentPage() == ui->servicePage && m_data->services().isEmpty()) + { + QMessageBox::critical(this, tr("Error"), tr("Add service.")); + return false; + } + + return true; +} + +void CampWizard::accept() +{ + CampService srv; + srv.saveCamp(m_data); + bool success = true; + + connect(&srv, &IService::dbError, [this, &success](QString msg){ + QMessageBox::critical(this, tr("Database error"), tr(msg.toStdString().c_str())); + success = false; + }); + + connect(&srv, &IService::permissionDenied, [this, &success](QString msg){ + QMessageBox::critical(this, "Permission denied", msg.toStdString().c_str()); + success = false; + }); + + if (success) + { + QDialog::accept(); + } } diff --git a/camp/campwizard.h b/camp/campwizard.h index 925de2c..4c5bcaf 100644 --- a/camp/campwizard.h +++ b/camp/campwizard.h @@ -5,6 +5,7 @@ #include "data/camp-data.h" #include #include +#include #include class AddressHelper : public QObject @@ -29,6 +30,27 @@ private: AddressbookDataPtr m_copyAddress; }; +class SaleHelper : public QObject +{ + Q_OBJECT + Q_PROPERTY(QSharedPointer sale READ sale WRITE setSale NOTIFY saleChanged) + +public: + SaleHelper(QObject *parent = NULL); + + SalePtr salePtr() const; + void setSalePtr(const SalePtr &sale); + + QSharedPointer sale() const; + void setSale(const QSharedPointer &sale); + +signals: + void saleChanged(); + +private: + SalePtr m_sale; +}; + namespace Ui { class CampWizard; } @@ -56,6 +78,16 @@ private slots: void on_CampWizard_currentIdChanged(int id); + void on_btnAddService_clicked(); + + void on_btnRemoveService_clicked(); + + void on_checkSale_clicked(); + + void applySale(); + + void on_sale_currentIndexChanged(int index); + private: Ui::CampWizard *ui; CampDataPtr m_data; @@ -63,9 +95,21 @@ private: ObjectBinder *m_addrHelperBinder; ObjectBinder *m_addressBinder; AddressHelper *m_addrHelper; + ObjectBinder *m_saleBinder; + SaleHelper *m_saleHelper; AutoTableModel *m_peopleModel; + AutoTableModel *m_servicesModel; + AutoTableModel *m_itemsModel; bool m_bindAddrCombo; + + // QWizard interface +public: + bool validateCurrentPage(); + + // QDialog interface +public slots: + void accept(); }; #endif // CAMPWIZARD_H diff --git a/camp/campwizard.ui b/camp/campwizard.ui index af97135..ae420fa 100644 --- a/camp/campwizard.ui +++ b/camp/campwizard.ui @@ -268,7 +268,7 @@ - + 0 0 @@ -422,7 +422,7 @@ - + @@ -441,14 +441,20 @@ - + + + false + ... - + + + false + ... @@ -471,7 +477,7 @@ - + @@ -483,14 +489,18 @@ - + Apply sale - + + + false + + @@ -525,7 +535,7 @@ - + TextLabel @@ -539,7 +549,7 @@ - + TextLabel @@ -581,7 +591,7 @@ - + TextLabel @@ -603,6 +613,48 @@ + + + + + 0 + + + 0 + + + 0 + + + + + Owner: + + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + @@ -611,7 +663,7 @@ - + @@ -621,7 +673,7 @@ - + @@ -633,13 +685,6 @@ - - - - TextLabel - - - @@ -654,15 +699,26 @@ - + 75 true + true - - TextLabel + + false + + + true + + + + + + + false @@ -725,19 +781,19 @@ btnRemove btnOwner tablePeople - toolButton - toolButton_2 - tableView_3 - tableView_4 - tableView_5 + btnAddService + btnRemoveService + tableItems + tabPeople + tabServices pushButton_2 - checkBox_2 + checkSale sale - tableView_2 + tableServices - + diff --git a/camp/data/campdata.cpp b/camp/data/campdata.cpp index 022bd7a..fdaa25c 100644 --- a/camp/data/campdata.cpp +++ b/camp/data/campdata.cpp @@ -6,6 +6,7 @@ CampData::CampData(QObject *parent) : QObject(parent) m_id = 0; m_totalPrice = 0; m_sale = 0; + m_totalSale = 0; m_ownerFirstame = false; } @@ -158,3 +159,23 @@ void CampData::setNumSer(const QString &numSer) { m_numSer = numSer; } + +QDecDouble CampData::totalSale() const +{ + return TO_DEC(m_totalSale); +} + +void CampData::setTotalSale(QDecDouble totalSale) +{ + m_totalSale = FROM_DEC(totalSale); +} + +QDecDouble CampData::fullPrice() const +{ + return TO_DEC(m_fullPrice); +} + +void CampData::setFullPrice(QDecDouble fullPrice) +{ + m_fullPrice = FROM_DEC(fullPrice); +} diff --git a/camp/data/campdata.h b/camp/data/campdata.h index 65622ee..17b6536 100644 --- a/camp/data/campdata.h +++ b/camp/data/campdata.h @@ -23,6 +23,7 @@ class CampData : public QObject Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) Q_PROPERTY(QDecDouble sale READ sale WRITE setSale) Q_PROPERTY(bool fixedSale READ fixedSale WRITE setFixedSale) + Q_PROPERTY(QDecDouble totalSale READ totalSale WRITE setTotalSale) public: explicit CampData(QObject *parent = 0); @@ -70,6 +71,12 @@ public: QString numSer() const; void setNumSer(const QString &numSer); + QDecDouble totalSale() const; + void setTotalSale(QDecDouble totalSale); + + QDecDouble fullPrice() const; + void setFullPrice(QDecDouble fullPrice); + private: friend class odb::access; #pragma db id auto @@ -84,8 +91,10 @@ private: QOdbList m_services; #pragma db value_not_null inverse(m_campData) QOdbList m_people; + int m_fullPrice; int m_totalPrice; int m_sale; + int m_totalSale; bool m_fixedSale; SeasonPtr m_season; }; diff --git a/camp/data/sale.cpp b/camp/data/sale.cpp index 22dc0c9..c85dddf 100644 --- a/camp/data/sale.cpp +++ b/camp/data/sale.cpp @@ -1,7 +1,7 @@ #include "sale.h" #include -Sale::Sale(QObject *parent) : QObject(parent) +Sale::Sale(QObject *parent) : ComboItem(parent) { m_id = 0; m_sale = 0; @@ -47,3 +47,20 @@ void Sale::setDescription(const QString &description) { m_description = description; } + +bool Sale::eq(ComboItem *other) +{ + Sale *sale = qobject_cast(other); + + if (sale == NULL) + { + return false; + } + + return this->m_id == sale->m_id && this->m_sale == sale->m_sale && this->m_fixed == sale->m_fixed; +} + +QString Sale::toString() +{ + return m_description; +} diff --git a/camp/data/sale.h b/camp/data/sale.h index 2047f1a..e0ae25b 100644 --- a/camp/data/sale.h +++ b/camp/data/sale.h @@ -4,9 +4,10 @@ #include #include #include +#include #pragma db object -class Sale : public QObject +class Sale : public ComboItem { Q_OBJECT Q_PROPERTY(QString description READ description WRITE setDescription) @@ -35,6 +36,11 @@ private: QString m_description; int m_sale; bool m_fixed; + + // ComboItem interface +public: + bool eq(ComboItem *other); + QString toString(); }; #endif // SALE_H diff --git a/camp/data/serviceitem.cpp b/camp/data/serviceitem.cpp index 34b1286..4ed2171 100644 --- a/camp/data/serviceitem.cpp +++ b/camp/data/serviceitem.cpp @@ -5,7 +5,9 @@ ServiceItem::ServiceItem(QObject *parent) : QObject(parent) { m_id = 0; m_salePossible = false; + m_sale = 0; m_price = 0; + m_totalPrice = 0; m_type = AccService::OTHER; } @@ -78,3 +80,43 @@ void ServiceItem::setCampData(const QWeakPointer &campData) { m_campData = campData; } + +QString ServiceItem::description() const +{ + return m_description; +} + +void ServiceItem::setDescription(const QString &description) +{ + m_description = description; +} + +QDecDouble ServiceItem::sale() const +{ + return TO_DEC(m_sale); +} + +void ServiceItem::setSale(QDecDouble sale) +{ + m_sale = FROM_DEC(sale); +} + +QDecDouble ServiceItem::totalPrice() const +{ + return TO_DEC(m_totalPrice); +} + +void ServiceItem::setTotalPrice(QDecDouble totalPrice) +{ + m_totalPrice = FROM_DEC(totalPrice); +} + +QDecDouble ServiceItem::fullPrice() const +{ + return TO_DEC(m_fullPrice); +} + +void ServiceItem::setFullPrice(QDecDouble fullPrice) +{ + m_fullPrice = FROM_DEC(fullPrice); +} diff --git a/camp/data/serviceitem.h b/camp/data/serviceitem.h index b31aaf1..44b2f4a 100644 --- a/camp/data/serviceitem.h +++ b/camp/data/serviceitem.h @@ -18,8 +18,10 @@ class ServiceItem : public QObject Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString code READ code WRITE setCode) + Q_PROPERTY(QString description READ description WRITE setDescription) Q_PROPERTY(QDecDouble price READ price WRITE setPrice) - Q_PROPERTY(bool salePossible READ salePossible WRITE setSalePossible) + Q_PROPERTY(QDecDouble sale READ sale WRITE setSale) + Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) Q_PROPERTY(AccService::ServiceType type READ type WRITE setType) Q_ENUMS(AccService::ServiceType) @@ -47,13 +49,29 @@ public: QWeakPointer campData() const; void setCampData(const QWeakPointer &campData); + QString description() const; + void setDescription(const QString &description); + + QDecDouble sale() const; + void setSale(QDecDouble sale); + + QDecDouble totalPrice() const; + void setTotalPrice(QDecDouble totalPrice); + + QDecDouble fullPrice() const; + void setFullPrice(QDecDouble fullPrice); + private: friend class odb::access; #pragma db id auto int m_id; QString m_name; QString m_code; + QString m_description; int m_price; + int m_fullPrice; + int m_totalPrice; + int m_sale; bool m_salePossible; AccService::ServiceType m_type; #pragma db not_null diff --git a/camp/settings/campsettings.cpp b/camp/settings/campsettings.cpp index 322c7ff..0178dc1 100644 --- a/camp/settings/campsettings.cpp +++ b/camp/settings/campsettings.cpp @@ -38,3 +38,33 @@ void CampSettings::setDecimalPlaces(int decimalPlaces) { m_decimalPlaces = decimalPlaces; } + +int CampSettings::accFeeStartAge() const +{ + return m_accFeeStartAge; +} + +void CampSettings::setAccFeeStartAge(int accFeeStartAge) +{ + m_accFeeStartAge = accFeeStartAge; +} + +int CampSettings::accFeeEndAge() const +{ + return m_accFeeEndAge; +} + +void CampSettings::setAccFeeEndAge(int accFeeEndAge) +{ + m_accFeeEndAge = accFeeEndAge; +} + +QString CampSettings::accFeeText() const +{ + return m_accFeeText; +} + +void CampSettings::setAccFeeText(const QString &accFeeText) +{ + m_accFeeText = accFeeText; +} diff --git a/camp/settings/campsettings.h b/camp/settings/campsettings.h index 57a64a2..cf12832 100644 --- a/camp/settings/campsettings.h +++ b/camp/settings/campsettings.h @@ -10,8 +10,11 @@ class CampSettings : public QObject { Q_OBJECT Q_PROPERTY(QDecDouble accFee READ accFee WRITE setAccFee) + Q_PROPERTY(int accFeeStartAge READ accFeeStartAge WRITE setAccFeeStartAge) + Q_PROPERTY(int accFeeEndAge READ accFeeEndAge WRITE setAccFeeEndAge) Q_PROPERTY(Enums::Rounding rounding READ rounding WRITE setRounding) Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces) + Q_PROPERTY(QString accFeeText READ accFeeText WRITE setAccFeeText) public: explicit CampSettings(QObject *parent = 0); @@ -25,8 +28,20 @@ public: int decimalPlaces() const; void setDecimalPlaces(int decimalPlaces); + int accFeeStartAge() const; + void setAccFeeStartAge(int accFeeStartAge); + + int accFeeEndAge() const; + void setAccFeeEndAge(int accFeeEndAge); + + QString accFeeText() const; + void setAccFeeText(const QString &accFeeText); + private: int m_accFee; + int m_accFeeStartAge; + int m_accFeeEndAge; + QString m_accFeeText; Enums::Rounding m_rounding; int m_decimalPlaces; }; diff --git a/camp/settings/campsettingsform.cpp b/camp/settings/campsettingsform.cpp index 7cdd305..ed481cb 100644 --- a/camp/settings/campsettingsform.cpp +++ b/camp/settings/campsettingsform.cpp @@ -37,7 +37,10 @@ CampSettingsForm::CampSettingsForm(QWidget *parent) : }); registerBinding(ui->accFee); + registerBinding(ui->accFeeStartAge); + registerBinding(ui->accFeeEndAge); registerBinding(ui->decimalPlaces); + registerBinding(ui->accFeeText); QList roundings ; roundings << ComboData(Enums::R_NONE, tr("None")) << ComboData(Enums::R_UP, tr("Up")) diff --git a/camp/settings/campsettingsform.ui b/camp/settings/campsettingsform.ui index c2c558a..1bc29ff 100644 --- a/camp/settings/campsettingsform.ui +++ b/camp/settings/campsettingsform.ui @@ -6,214 +6,227 @@ 0 0 - 696 - 489 + 995 + 641 Form - + - - - Person prices - - + + - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Add - - - ... - - - - :/icons/new.svg:/icons/new.svg - - - true - - - - - - - false - - - Remove - - - ... - - - - :/icons/remove.svg:/icons/remove.svg - - - true - - - - - - - false - - - Deactivate - - - ... - - - - :/icons/ok.svg:/icons/ok.svg - - - true - - - true - - - + + + Person prices + + - - - Filter active - - - ... - - - - :/icons/filter.svg:/icons/filter.svg - - - true - - - true - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Add + + + ... + + + + :/icons/new.svg:/icons/new.svg + + + true + + + + + + + false + + + Remove + + + ... + + + + :/icons/remove.svg:/icons/remove.svg + + + true + + + + + + + false + + + Deactivate + + + ... + + + + :/icons/ok.svg:/icons/ok.svg + + + true + + + true + + + + + + + Filter active + + + ... + + + + :/icons/filter.svg:/icons/filter.svg + + + true + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - Qt::Horizontal - - + + - 40 - 20 + 550 + 0 - + - - - - - - - - - Sales - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Add - - - ... - - - - :/icons/new.svg:/icons/new.svg - - - true - - - + + + Sales + + - - - false - - - Remove - - - ... - - - - :/icons/remove.svg:/icons/remove.svg - - - true - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Add + + + ... + + + + :/icons/new.svg:/icons/new.svg + + + true + + + + + + + false + + + Remove + + + ... + + + + :/icons/remove.svg:/icons/remove.svg + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - Qt::Horizontal - - - - 40 - 20 - - - + - - - @@ -223,31 +236,31 @@ Other settings - + Accommodation fee - + Rounding - + - + Decimal places - + QAbstractSpinBox::NoButtons @@ -260,7 +273,21 @@ - + + + + Fee start age + + + + + + + QAbstractSpinBox::NoButtons + + + + QAbstractSpinBox::NoButtons @@ -270,6 +297,30 @@ + + + + Fee end age + + + + + + + QAbstractSpinBox::NoButtons + + + + + + + Fee description + + + + + + diff --git a/services/data/accservice.h b/services/data/accservice.h index cda12f9..9b10971 100644 --- a/services/data/accservice.h +++ b/services/data/accservice.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -28,7 +29,7 @@ public: - enum ServiceType { CAR,TENT,OTHER }; + enum ServiceType { CAR,TENT,OTHER,ACCFEE }; int id() const; void setId(int id); @@ -68,4 +69,7 @@ private: Enums::VatType m_vatType; }; + +typedef QSharedPointer AccServicePtr; + #endif // ACCSERVICE_H