From cc6111d09f70d1c0b45f345c9f87b957295b5697 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 8 Jun 2017 14:24:33 +0200 Subject: [PATCH] Added sales to people. Print button on Camp wizard is now functional. Added item grids below Camp main grid. --- camp/camp.json | 6 +- camp/camp.pro | 9 +- camp/campgrid.cpp | 17 + camp/campgrid.h | 7 + camp/campservice.cpp | 17 +- camp/campwizard.cpp | 54 ++- camp/campwizard.h | 2 + camp/campwizard.ui | 6 +- camp/data/addressitem.cpp | 22 ++ camp/data/addressitem.h | 10 + camp/data/serviceitem.h | 1 + camp/detailwidget.cpp | 41 ++ camp/detailwidget.h | 28 ++ camp/detailwidget.ui | 59 +++ reports/camp_accommodation_document.lrxml | 456 +++++++++++----------- 15 files changed, 497 insertions(+), 238 deletions(-) create mode 100644 camp/detailwidget.cpp create mode 100644 camp/detailwidget.h create mode 100644 camp/detailwidget.ui diff --git a/camp/camp.json b/camp/camp.json index 3d979e8..37d9645 100644 --- a/camp/camp.json +++ b/camp/camp.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 6, + "schemaVersion" : 7, "sql" : [ "CREATE TABLE \"CampData\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -93,6 +93,10 @@ ALTER TABLE CampData ADD \"totalSale\" INTEGER NULL; ", "ALTER TABLE CampData ADD \"onVoucher\" INTEGER NULL; +", + +"ALTER TABLE AddressItem ADD \"sale\" INTEGER NULL; +ALTER TABLE AddressItem ADD \"totalPrice\" INTEGER NULL; " ], "dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ], diff --git a/camp/camp.pro b/camp/camp.pro index af5b7ca..39cc5a5 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -36,7 +36,8 @@ SOURCES += camp.cpp \ campservice.cpp \ addservicedialog.cpp \ campshopitem.cpp \ - campseller.cpp + campseller.cpp \ + detailwidget.cpp HEADERS += camp.h\ camp_global.h \ @@ -54,7 +55,8 @@ HEADERS += camp.h\ campservice.h \ addservicedialog.h \ campshopitem.h \ - campseller.h + campseller.h \ + detailwidget.h include(../config_plugin.pri) @@ -104,4 +106,5 @@ FORMS += \ campform.ui \ settings/campsettingsform.ui \ campwizard.ui \ - addservicedialog.ui + addservicedialog.ui \ + detailwidget.ui diff --git a/camp/campgrid.cpp b/camp/campgrid.cpp index ced56f5..aef85db 100644 --- a/camp/campgrid.cpp +++ b/camp/campgrid.cpp @@ -31,6 +31,9 @@ CampGrid::CampGrid(QWidget *parent) : GridForm(parent) } }); } + + m_detail = new DetailWidget(this); + mainLayout()->addWidget(m_detail); } void CampGrid::handleNewRecord() @@ -101,6 +104,12 @@ void CampGrid::doDelete(CampDataPtr entity) void CampGrid::addToVoucher(CampDataPtr data) { + if (data->onVoucher()) + { + QMessageBox::information(this, tr("Can not pay"), tr("This record is already paid")); + return; + } + CampShopItemPtr campItem(new CampShopItem); campItem->setId(data->id()); @@ -134,3 +143,11 @@ void CampGrid::addToVoucher(CampDataPtr data) shopSrv.eraseVoucher(voucher); }); } + +void CampGrid::currentIndexChanged(const QModelIndex ¤t) +{ + if (current.isValid()) + { + m_detail->setData(currentEntity()); + } +} diff --git a/camp/campgrid.h b/camp/campgrid.h index ec33b29..59fb0b4 100644 --- a/camp/campgrid.h +++ b/camp/campgrid.h @@ -5,6 +5,8 @@ #include "data/camp-data.h" #include "camp-odb.hxx" +#include "detailwidget.h" + class CampGrid : public GridForm { public: @@ -21,7 +23,12 @@ protected: private: void addToVoucher(CampDataPtr data); + DetailWidget *m_detail; + + // IGridForm interface +protected: + void currentIndexChanged(const QModelIndex ¤t); }; #endif // CAMPGRID_H diff --git a/camp/campservice.cpp b/camp/campservice.cpp index b7e4b3b..ae96cef 100644 --- a/camp/campservice.cpp +++ b/camp/campservice.cpp @@ -212,6 +212,8 @@ void CampService::calcPeople(CampDataPtr data) Service srvPrices; QList prices = srvPrices.all("active = 1"); int days = data->start().daysTo(data->end()); + QDecDouble sale = data->sale(); + bool fixedSale = data->fixedSale(); foreach (AddressItemPtr item, data->people()) { QDate first(1,1,1); @@ -249,6 +251,18 @@ void CampService::calcPeople(CampDataPtr data) continue; } + if (sale != QDecDouble(0) && !fixedSale) + { + QDecDouble itemSale = (item->price() * sale) / 100; + item->setSale(itemSale); + item->setTotalPrice(item->price() - itemSale); + } + else + { + item->setSale(0); + item->setTotalPrice(item->price()); + } + addAccFee(data, item, startAge, endAge, days); } } @@ -287,7 +301,8 @@ void CampService::calcPrice(CampDataPtr data) } foreach (AddressItemPtr addr, data->people()) { - totalPrice += addr->price(); + totalPrice += addr->totalPrice(); + sale += addr->sale(); } if (data->fixedSale()) diff --git a/camp/campwizard.cpp b/camp/campwizard.cpp index 51ef15a..0d08961 100644 --- a/camp/campwizard.cpp +++ b/camp/campwizard.cpp @@ -6,6 +6,7 @@ #include #include #include +#include //////////////////////////////////// /// \brief AddressHelper::AddressHelper @@ -105,6 +106,8 @@ CampWizard::CampWizard(QWidget *parent) : ui->tablePeople->setModel(m_peopleModel); ui->tablePeople->hideColumn(2); ui->tablePeople->hideColumn(3); + ui->tablePeople->hideColumn(4); + ui->tablePeople->hideColumn(5); ui->tablePeople->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->tablePeople->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); @@ -166,6 +169,7 @@ CampWizard::CampWizard(QWidget *parent) : ui->tableItems->hideColumn(4); ui->tableItems->hideColumn(5); ui->tableItems->hideColumn(6); + ui->tableItems->hideColumn(7); ui->tableItems->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); @@ -187,12 +191,13 @@ CampWizard::CampWizard(QWidget *parent) : ui->tabPeople->setModel(m_peopleModel); ui->tabPeople->hideColumn(0); ui->tabPeople->hideColumn(1); - ui->tabPeople->hideColumn(4); + ui->tabPeople->hideColumn(6); ui->tabPeople->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); ui->tabServices->setModel(m_itemsModel); ui->tabServices->hideColumn(1); - ui->tabServices->hideColumn(6); + ui->tabServices->hideColumn(3); + ui->tabServices->hideColumn(7); ui->tabServices->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->tabServices->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); @@ -432,3 +437,48 @@ void CampWizard::accept() QDialog::accept(); } } + +void CampWizard::on_btnPrint_clicked() +{ + if (QMessageBox::question(this, tr("Save record?"), tr("Record must be saved before print. Do you want to save record?")) != QMessageBox::Yes) + { + return; + } + + CampService srv; + 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, tr("Permission denied"), msg.toStdString().c_str()); + success = false; + }); + + if (m_newRecord && m_data->id() == 0) + { + srv.saveCamp(m_data); + } + else + { + srv.updateCamp(m_data); + } + + if(!success) + { + return; + } + + ReportPtr report(new Report); + report->setFile("camp_accommodation_document.lrxml"); + + VariableFiller filler; + filler.fill(report, m_data->id()); + + ReportViewer *viewer = new ReportViewer(this); + viewer->setReport(report); + viewer->openPreview(); +} diff --git a/camp/campwizard.h b/camp/campwizard.h index 41ff339..c17d537 100644 --- a/camp/campwizard.h +++ b/camp/campwizard.h @@ -89,6 +89,8 @@ private slots: void on_sale_currentIndexChanged(int index); + void on_btnPrint_clicked(); + private: Ui::CampWizard *ui; CampDataPtr m_data; diff --git a/camp/campwizard.ui b/camp/campwizard.ui index e3f1c80..ea2d08b 100644 --- a/camp/campwizard.ui +++ b/camp/campwizard.ui @@ -843,7 +843,7 @@ - + Print @@ -900,14 +900,14 @@ tableItems tabPeople tabServices - pushButton_2 + btnPrint checkSale sale tableServices - + diff --git a/camp/data/addressitem.cpp b/camp/data/addressitem.cpp index a9d17ea..645be20 100644 --- a/camp/data/addressitem.cpp +++ b/camp/data/addressitem.cpp @@ -6,6 +6,8 @@ AddressItem::AddressItem(QObject *parent) : QObject(parent) m_id = 0; m_price = 0; m_owner = false; + m_sale = 0; + m_totalPrice = 0; } int AddressItem::id() const @@ -97,3 +99,23 @@ void AddressItem::setOwner(bool owner) { m_owner = owner; } + +QDecDouble AddressItem::totalPrice() const +{ + return TO_DEC(m_totalPrice); +} + +void AddressItem::setTotalPrice(QDecDouble totalPrice) +{ + m_totalPrice = FROM_DEC(totalPrice); +} + +QDecDouble AddressItem::sale() const +{ + return TO_DEC(m_sale); +} + +void AddressItem::setSale(QDecDouble sale) +{ + m_sale = FROM_DEC(sale); +} diff --git a/camp/data/addressitem.h b/camp/data/addressitem.h index c82117f..f6f348f 100644 --- a/camp/data/addressitem.h +++ b/camp/data/addressitem.h @@ -20,6 +20,8 @@ class AddressItem : public QObject Q_PROPERTY(QString lastName READ lastName WRITE setLastName) Q_PROPERTY(QString address READ address WRITE setAddress) Q_PROPERTY(QDecDouble price READ price WRITE setPrice) + Q_PROPERTY(QDecDouble sale READ sale WRITE setSale) + Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) Q_PROPERTY(bool owner READ owner WRITE setOwner) public: @@ -52,6 +54,12 @@ public: bool owner() const; void setOwner(bool owner); + QDecDouble totalPrice() const; + void setTotalPrice(QDecDouble totalPrice); + + QDecDouble sale() const; + void setSale(QDecDouble sale); + private: friend class odb::access; #pragma db id auto @@ -61,6 +69,8 @@ private: QString m_address; AddressbookDataPtr m_adbItem; int m_price; + int m_totalPrice; + int m_sale; #pragma db not_null QWeakPointer m_campData; PersonPricePtr m_personPrice; diff --git a/camp/data/serviceitem.h b/camp/data/serviceitem.h index 44b2f4a..65547a3 100644 --- a/camp/data/serviceitem.h +++ b/camp/data/serviceitem.h @@ -20,6 +20,7 @@ class ServiceItem : public QObject 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(QDecDouble fullPrice READ fullPrice WRITE setFullPrice) 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) diff --git a/camp/detailwidget.cpp b/camp/detailwidget.cpp new file mode 100644 index 0000000..130d0c0 --- /dev/null +++ b/camp/detailwidget.cpp @@ -0,0 +1,41 @@ +#include "detailwidget.h" +#include "ui_detailwidget.h" + +#include "campservice.h" + +DetailWidget::DetailWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::DetailWidget) +{ + ui->setupUi(this); + + m_peopleModel = new AutoTableModel(this); + m_servicesModel = new AutoTableModel(this); + ui->tabPeople->setModel(m_peopleModel); + ui->tabServices->setModel(m_servicesModel); + + ui->tabPeople->hideColumn(0); + ui->tabPeople->hideColumn(1); + ui->tabPeople->hideColumn(6); + ui->tabPeople->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); + + ui->tabServices->hideColumn(1); + ui->tabServices->hideColumn(3); + ui->tabServices->hideColumn(7); + ui->tabServices->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + ui->tabServices->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); +} + +DetailWidget::~DetailWidget() +{ + delete ui; +} + +void DetailWidget::setData(const CampDataPtr &data) +{ + CampService srv; + srv.loadItems(data); + + m_peopleModel->setData(data->people()); + m_servicesModel->setData(data->services()); +} diff --git a/camp/detailwidget.h b/camp/detailwidget.h new file mode 100644 index 0000000..bc022b0 --- /dev/null +++ b/camp/detailwidget.h @@ -0,0 +1,28 @@ +#ifndef DETAILWIDGET_H +#define DETAILWIDGET_H + +#include +#include +#include "data/camp-data.h" + +namespace Ui { +class DetailWidget; +} + +class DetailWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DetailWidget(QWidget *parent = 0); + ~DetailWidget(); + + void setData(const CampDataPtr &data); + +private: + Ui::DetailWidget *ui; + AutoTableModel *m_peopleModel; + AutoTableModel *m_servicesModel; +}; + +#endif // DETAILWIDGET_H diff --git a/camp/detailwidget.ui b/camp/detailwidget.ui new file mode 100644 index 0000000..5d02498 --- /dev/null +++ b/camp/detailwidget.ui @@ -0,0 +1,59 @@ + + + DetailWidget + + + + 0 + 0 + 806 + 445 + + + + Form + + + + + + People + + + + + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + + + + + + + + + + Services + + + + + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + + + + + + + + + + + diff --git a/reports/camp_accommodation_document.lrxml b/reports/camp_accommodation_document.lrxml index 57d4e40..496a6e9 100644 --- a/reports/camp_accommodation_document.lrxml +++ b/reports/camp_accommodation_document.lrxml @@ -1,27 +1,27 @@ - + - + page1 - + - + - + ReportPage1 - + - + ReportHeader1 - + - + TextItem2 - + @@ -37,7 +37,7 @@ - + @@ -58,9 +58,9 @@ - + TextItem1 - + @@ -76,7 +76,7 @@ - + @@ -97,9 +97,9 @@ - + TextItem13 - + @@ -115,7 +115,7 @@ - + @@ -136,9 +136,9 @@ - + TextItem14 - + @@ -154,7 +154,7 @@ - + @@ -175,9 +175,9 @@ - + TextItem62 - + @@ -193,7 +193,7 @@ - + @@ -214,9 +214,9 @@ - + TextItem63 - + @@ -232,7 +232,7 @@ - + @@ -253,9 +253,9 @@ - + TextItem64 - + @@ -271,7 +271,7 @@ - + @@ -292,9 +292,9 @@ - + TextItem65 - + @@ -310,7 +310,7 @@ - + @@ -347,13 +347,13 @@ - + DataBand3 - + - + TextItem4 - + @@ -369,7 +369,7 @@ - + @@ -390,9 +390,9 @@ - + TextItem19 - + @@ -408,7 +408,7 @@ - + @@ -429,9 +429,9 @@ - + TextItem20 - + @@ -447,7 +447,7 @@ - + @@ -468,9 +468,9 @@ - + TextItem23 - + @@ -486,7 +486,7 @@ - + @@ -507,9 +507,9 @@ - + TextItem54 - + @@ -525,7 +525,7 @@ - + @@ -546,9 +546,9 @@ - + TextItem55 - + @@ -564,7 +564,7 @@ - + @@ -585,9 +585,9 @@ - + TextItem56 - + @@ -603,7 +603,7 @@ - + @@ -624,9 +624,9 @@ - + TextItem57 - + @@ -642,7 +642,7 @@ - + @@ -688,13 +688,13 @@ - + SubDetailBand6 - + - + TextItem7 - + @@ -710,7 +710,7 @@ - + @@ -731,9 +731,9 @@ - + TextItem26 - + @@ -749,7 +749,7 @@ - + @@ -770,9 +770,9 @@ - + TextItem31 - + @@ -788,7 +788,7 @@ - + @@ -809,9 +809,9 @@ - + TextItem32 - + @@ -827,7 +827,7 @@ - + @@ -848,9 +848,9 @@ - + TextItem33 - + @@ -866,7 +866,7 @@ - + @@ -887,9 +887,9 @@ - + TextItem21 - + @@ -905,7 +905,7 @@ - + @@ -926,9 +926,9 @@ - + TextItem22 - + @@ -944,7 +944,7 @@ - + @@ -965,9 +965,9 @@ - + TextItem27 - + @@ -983,7 +983,7 @@ - + @@ -1004,9 +1004,9 @@ - + TextItem36 - + @@ -1022,7 +1022,7 @@ - + @@ -1043,9 +1043,9 @@ - + TextItem38 - + @@ -1061,7 +1061,7 @@ - + @@ -1082,9 +1082,9 @@ - + TextItem39 - + @@ -1100,7 +1100,7 @@ - + @@ -1121,9 +1121,9 @@ - + TextItem40 - + @@ -1139,7 +1139,7 @@ - + @@ -1160,9 +1160,9 @@ - + TextItem41 - + @@ -1178,7 +1178,7 @@ - + @@ -1199,9 +1199,9 @@ - + TextItem42 - + @@ -1217,7 +1217,7 @@ - + @@ -1238,9 +1238,9 @@ - + TextItem43 - + @@ -1256,7 +1256,7 @@ - + @@ -1277,9 +1277,9 @@ - + TextItem49 - + @@ -1295,7 +1295,7 @@ - + @@ -1316,9 +1316,9 @@ - + TextItem50 - + @@ -1334,7 +1334,7 @@ - + @@ -1355,9 +1355,9 @@ - + TextItem51 - + @@ -1373,7 +1373,7 @@ - + @@ -1394,9 +1394,9 @@ - + TextItem52 - + @@ -1412,7 +1412,7 @@ - + @@ -1433,9 +1433,9 @@ - + TextItem53 - + @@ -1451,7 +1451,7 @@ - + @@ -1493,13 +1493,13 @@ - + SubDetailHeaderBand6 - + - + TextItem24 - + @@ -1515,7 +1515,7 @@ - + @@ -1536,9 +1536,9 @@ - + TextItem25 - + @@ -1554,7 +1554,7 @@ - + @@ -1575,9 +1575,9 @@ - + TextItem28 - + @@ -1593,7 +1593,7 @@ - + @@ -1614,9 +1614,9 @@ - + TextItem29 - + @@ -1632,7 +1632,7 @@ - + @@ -1653,9 +1653,9 @@ - + TextItem30 - + @@ -1671,7 +1671,7 @@ - + @@ -1692,9 +1692,9 @@ - + TextItem44 - + @@ -1710,7 +1710,7 @@ - + @@ -1731,9 +1731,9 @@ - + TextItem45 - + @@ -1749,7 +1749,7 @@ - + @@ -1770,9 +1770,9 @@ - + TextItem46 - + @@ -1788,7 +1788,7 @@ - + @@ -1809,9 +1809,9 @@ - + TextItem47 - + @@ -1827,7 +1827,7 @@ - + @@ -1848,9 +1848,9 @@ - + TextItem48 - + @@ -1866,7 +1866,7 @@ - + @@ -1905,13 +1905,13 @@ - + DataFooterBand10 - + - + TextItem34 - + @@ -1927,7 +1927,7 @@ - + @@ -1948,9 +1948,9 @@ - + TextItem35 - + @@ -1966,7 +1966,7 @@ - + @@ -1987,9 +1987,9 @@ - + TextItem37 - + @@ -2005,7 +2005,7 @@ - + @@ -2026,9 +2026,9 @@ - + TextItem3 - + @@ -2044,7 +2044,7 @@ - + @@ -2065,9 +2065,9 @@ - + TextItem9 - + @@ -2083,7 +2083,7 @@ - + @@ -2104,9 +2104,9 @@ - + TextItem10 - + @@ -2122,7 +2122,7 @@ - + @@ -2143,9 +2143,9 @@ - + TextItem11 - + @@ -2161,7 +2161,7 @@ - + @@ -2182,9 +2182,9 @@ - + TextItem12 - + @@ -2200,7 +2200,7 @@ - + @@ -2239,13 +2239,13 @@ - + DataHeaderBand14 - + - + TextItem15 - + @@ -2261,7 +2261,7 @@ - + @@ -2282,9 +2282,9 @@ - + TextItem16 - + @@ -2300,7 +2300,7 @@ - + @@ -2321,9 +2321,9 @@ - + TextItem17 - + @@ -2339,7 +2339,7 @@ - + @@ -2360,9 +2360,9 @@ - + TextItem18 - + @@ -2378,7 +2378,7 @@ - + @@ -2399,9 +2399,9 @@ - + TextItem58 - + @@ -2417,7 +2417,7 @@ - + @@ -2438,9 +2438,9 @@ - + TextItem59 - + @@ -2456,7 +2456,7 @@ - + @@ -2477,9 +2477,9 @@ - + TextItem60 - + @@ -2495,7 +2495,7 @@ - + @@ -2516,9 +2516,9 @@ - + TextItem61 - + @@ -2534,7 +2534,7 @@ - + @@ -2575,9 +2575,9 @@ - + TextItem5 - + @@ -2593,7 +2593,7 @@ - + @@ -2614,9 +2614,9 @@ - + TextItem6 - + @@ -2632,7 +2632,7 @@ - + @@ -2673,10 +2673,10 @@ - + datasources - + prodejna QSQLITE @@ -2689,7 +2689,7 @@ - + data_ubytovani @@ -2718,7 +2718,7 @@ WHERE cd.id = $V{RECORD_ID} - + polozky_ubytovani select si.name as name, @@ -2738,8 +2738,8 @@ UNION ALL select ai.firstName || ' ' || ai.lastName as name, NULL as description, NULL as itemPrice, - 0 as sale, - ai.price as totalPrice, + ai.sale as sale, + ai.totalPrice as totalPrice, ai.price as fullPrice, -1 as type, ad.birthDate as birthDate, @@ -2757,59 +2757,59 @@ ORDER BY type - + dbPath /home/pepa/Dokumenty/dev/qt/pokus.db - + RECORD_ID - 6 + 15 - + COMPANY Veřejné tábořiště Vyskytná - + STREET Vyskytná - + HOUSE_NUMBER 22 - + CITY Vyskytná - + ZIP_CODE - + IC 1212121218 - + DIC CZ1212121218 - + LOGO_PATH /home/pepa/Dokumenty/face3.jpg - +