Added sales to people. Print button on Camp wizard is now functional. Added item grids below Camp main grid.

master
Josef Rokos 8 years ago
parent e5b33fa973
commit cc6111d09f

@ -8,7 +8,7 @@
"default" : "", "default" : "",
"CZ" : "" "CZ" : ""
}, },
"schemaVersion" : 6, "schemaVersion" : 7,
"sql" : [ "sql" : [
"CREATE TABLE \"CampData\" ( "CREATE TABLE \"CampData\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"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 CampData ADD \"onVoucher\" INTEGER NULL;
",
"ALTER TABLE AddressItem ADD \"sale\" INTEGER NULL;
ALTER TABLE AddressItem ADD \"totalPrice\" INTEGER NULL;
" "
], ],
"dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ], "dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ],

@ -36,7 +36,8 @@ SOURCES += camp.cpp \
campservice.cpp \ campservice.cpp \
addservicedialog.cpp \ addservicedialog.cpp \
campshopitem.cpp \ campshopitem.cpp \
campseller.cpp campseller.cpp \
detailwidget.cpp
HEADERS += camp.h\ HEADERS += camp.h\
camp_global.h \ camp_global.h \
@ -54,7 +55,8 @@ HEADERS += camp.h\
campservice.h \ campservice.h \
addservicedialog.h \ addservicedialog.h \
campshopitem.h \ campshopitem.h \
campseller.h campseller.h \
detailwidget.h
include(../config_plugin.pri) include(../config_plugin.pri)
@ -104,4 +106,5 @@ FORMS += \
campform.ui \ campform.ui \
settings/campsettingsform.ui \ settings/campsettingsform.ui \
campwizard.ui \ campwizard.ui \
addservicedialog.ui addservicedialog.ui \
detailwidget.ui

@ -31,6 +31,9 @@ CampGrid::CampGrid(QWidget *parent) : GridForm<CampData>(parent)
} }
}); });
} }
m_detail = new DetailWidget(this);
mainLayout()->addWidget(m_detail);
} }
void CampGrid::handleNewRecord() void CampGrid::handleNewRecord()
@ -101,6 +104,12 @@ void CampGrid::doDelete(CampDataPtr entity)
void CampGrid::addToVoucher(CampDataPtr data) 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); CampShopItemPtr campItem(new CampShopItem);
campItem->setId(data->id()); campItem->setId(data->id());
@ -134,3 +143,11 @@ void CampGrid::addToVoucher(CampDataPtr data)
shopSrv.eraseVoucher(voucher); shopSrv.eraseVoucher(voucher);
}); });
} }
void CampGrid::currentIndexChanged(const QModelIndex &current)
{
if (current.isValid())
{
m_detail->setData(currentEntity());
}
}

@ -5,6 +5,8 @@
#include "data/camp-data.h" #include "data/camp-data.h"
#include "camp-odb.hxx" #include "camp-odb.hxx"
#include "detailwidget.h"
class CampGrid : public GridForm<CampData> class CampGrid : public GridForm<CampData>
{ {
public: public:
@ -21,7 +23,12 @@ protected:
private: private:
void addToVoucher(CampDataPtr data); void addToVoucher(CampDataPtr data);
DetailWidget *m_detail;
// IGridForm interface
protected:
void currentIndexChanged(const QModelIndex &current);
}; };
#endif // CAMPGRID_H #endif // CAMPGRID_H

@ -212,6 +212,8 @@ void CampService::calcPeople(CampDataPtr data)
Service<PersonPrice> srvPrices; Service<PersonPrice> srvPrices;
QList<PersonPricePtr> prices = srvPrices.all("active = 1"); QList<PersonPricePtr> prices = srvPrices.all("active = 1");
int days = data->start().daysTo(data->end()); int days = data->start().daysTo(data->end());
QDecDouble sale = data->sale();
bool fixedSale = data->fixedSale();
foreach (AddressItemPtr item, data->people()) { foreach (AddressItemPtr item, data->people()) {
QDate first(1,1,1); QDate first(1,1,1);
@ -249,6 +251,18 @@ void CampService::calcPeople(CampDataPtr data)
continue; 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); addAccFee(data, item, startAge, endAge, days);
} }
} }
@ -287,7 +301,8 @@ void CampService::calcPrice(CampDataPtr data)
} }
foreach (AddressItemPtr addr, data->people()) { foreach (AddressItemPtr addr, data->people()) {
totalPrice += addr->price(); totalPrice += addr->totalPrice();
sale += addr->sale();
} }
if (data->fixedSale()) if (data->fixedSale())

@ -6,6 +6,7 @@
#include <core.h> #include <core.h>
#include <addressbookservice.h> #include <addressbookservice.h>
#include <accservice.h> #include <accservice.h>
#include <reporting/reportviewer.h>
//////////////////////////////////// ////////////////////////////////////
/// \brief AddressHelper::AddressHelper /// \brief AddressHelper::AddressHelper
@ -105,6 +106,8 @@ CampWizard::CampWizard(QWidget *parent) :
ui->tablePeople->setModel(m_peopleModel); ui->tablePeople->setModel(m_peopleModel);
ui->tablePeople->hideColumn(2); ui->tablePeople->hideColumn(2);
ui->tablePeople->hideColumn(3); ui->tablePeople->hideColumn(3);
ui->tablePeople->hideColumn(4);
ui->tablePeople->hideColumn(5);
ui->tablePeople->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->tablePeople->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->tablePeople->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); ui->tablePeople->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
@ -166,6 +169,7 @@ CampWizard::CampWizard(QWidget *parent) :
ui->tableItems->hideColumn(4); ui->tableItems->hideColumn(4);
ui->tableItems->hideColumn(5); ui->tableItems->hideColumn(5);
ui->tableItems->hideColumn(6); ui->tableItems->hideColumn(6);
ui->tableItems->hideColumn(7);
ui->tableItems->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); ui->tableItems->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
@ -187,12 +191,13 @@ CampWizard::CampWizard(QWidget *parent) :
ui->tabPeople->setModel(m_peopleModel); ui->tabPeople->setModel(m_peopleModel);
ui->tabPeople->hideColumn(0); ui->tabPeople->hideColumn(0);
ui->tabPeople->hideColumn(1); ui->tabPeople->hideColumn(1);
ui->tabPeople->hideColumn(4); ui->tabPeople->hideColumn(6);
ui->tabPeople->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); ui->tabPeople->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
ui->tabServices->setModel(m_itemsModel); ui->tabServices->setModel(m_itemsModel);
ui->tabServices->hideColumn(1); 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(0, QHeaderView::Stretch);
ui->tabServices->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); ui->tabServices->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
@ -432,3 +437,48 @@ void CampWizard::accept()
QDialog::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();
}

@ -89,6 +89,8 @@ private slots:
void on_sale_currentIndexChanged(int index); void on_sale_currentIndexChanged(int index);
void on_btnPrint_clicked();
private: private:
Ui::CampWizard *ui; Ui::CampWizard *ui;
CampDataPtr m_data; CampDataPtr m_data;

@ -843,7 +843,7 @@
<widget class="QWidget" name="widget_7" native="true"> <widget class="QWidget" name="widget_7" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QPushButton" name="pushButton_2"> <widget class="QPushButton" name="btnPrint">
<property name="text"> <property name="text">
<string>Print</string> <string>Print</string>
</property> </property>
@ -900,14 +900,14 @@
<tabstop>tableItems</tabstop> <tabstop>tableItems</tabstop>
<tabstop>tabPeople</tabstop> <tabstop>tabPeople</tabstop>
<tabstop>tabServices</tabstop> <tabstop>tabServices</tabstop>
<tabstop>pushButton_2</tabstop> <tabstop>btnPrint</tabstop>
<tabstop>checkSale</tabstop> <tabstop>checkSale</tabstop>
<tabstop>sale</tabstop> <tabstop>sale</tabstop>
<tabstop>tableServices</tabstop> <tabstop>tableServices</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="camprc.qrc"/>
<include location="../core/rc.qrc"/> <include location="../core/rc.qrc"/>
<include location="camprc.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

@ -6,6 +6,8 @@ AddressItem::AddressItem(QObject *parent) : QObject(parent)
m_id = 0; m_id = 0;
m_price = 0; m_price = 0;
m_owner = false; m_owner = false;
m_sale = 0;
m_totalPrice = 0;
} }
int AddressItem::id() const int AddressItem::id() const
@ -97,3 +99,23 @@ void AddressItem::setOwner(bool owner)
{ {
m_owner = 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);
}

@ -20,6 +20,8 @@ class AddressItem : public QObject
Q_PROPERTY(QString lastName READ lastName WRITE setLastName) Q_PROPERTY(QString lastName READ lastName WRITE setLastName)
Q_PROPERTY(QString address READ address WRITE setAddress) Q_PROPERTY(QString address READ address WRITE setAddress)
Q_PROPERTY(QDecDouble price READ price WRITE setPrice) 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) Q_PROPERTY(bool owner READ owner WRITE setOwner)
public: public:
@ -52,6 +54,12 @@ public:
bool owner() const; bool owner() const;
void setOwner(bool owner); void setOwner(bool owner);
QDecDouble totalPrice() const;
void setTotalPrice(QDecDouble totalPrice);
QDecDouble sale() const;
void setSale(QDecDouble sale);
private: private:
friend class odb::access; friend class odb::access;
#pragma db id auto #pragma db id auto
@ -61,6 +69,8 @@ private:
QString m_address; QString m_address;
AddressbookDataPtr m_adbItem; AddressbookDataPtr m_adbItem;
int m_price; int m_price;
int m_totalPrice;
int m_sale;
#pragma db not_null #pragma db not_null
QWeakPointer<CampData> m_campData; QWeakPointer<CampData> m_campData;
PersonPricePtr m_personPrice; PersonPricePtr m_personPrice;

@ -20,6 +20,7 @@ class ServiceItem : public QObject
Q_PROPERTY(QString code READ code WRITE setCode) Q_PROPERTY(QString code READ code WRITE setCode)
Q_PROPERTY(QString description READ description WRITE setDescription) Q_PROPERTY(QString description READ description WRITE setDescription)
Q_PROPERTY(QDecDouble price READ price WRITE setPrice) 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 sale READ sale WRITE setSale)
Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice)
Q_PROPERTY(AccService::ServiceType type READ type WRITE setType) Q_PROPERTY(AccService::ServiceType type READ type WRITE setType)

@ -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<AddressItem>(this);
m_servicesModel = new AutoTableModel<ServiceItem>(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());
}

@ -0,0 +1,28 @@
#ifndef DETAILWIDGET_H
#define DETAILWIDGET_H
#include <QWidget>
#include <autotablemodel.h>
#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<AddressItem> *m_peopleModel;
AutoTableModel<ServiceItem> *m_servicesModel;
};
#endif // DETAILWIDGET_H

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DetailWidget</class>
<widget class="QWidget" name="DetailWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>806</width>
<height>445</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>People</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTableView" name="tabPeople">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Services</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QTableView" name="tabServices">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save