You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
3.8 KiB
C++
166 lines
3.8 KiB
C++
#include "campgrid.h"
|
|
#include "campwizard.h"
|
|
#include "campservice.h"
|
|
#include "campshopitem.h"
|
|
|
|
#include <data/shop-data.h>
|
|
#include <shopservice.h>
|
|
#include <paydialog.h>
|
|
|
|
CampGrid::CampGrid(QWidget *parent) : GridForm<CampData>(parent)
|
|
{
|
|
setTableModel(new AutoTableModel<CampData>);
|
|
|
|
QHBoxLayout *tbLayout = qobject_cast<QHBoxLayout*>(this->toolbar()->layout());
|
|
|
|
if (tbLayout != nullptr)
|
|
{
|
|
QToolButton *btnImport = new QToolButton(this->toolbar());
|
|
btnImport->setIcon(QIcon(":/icons/pay.svg"));
|
|
btnImport->setAutoRaise(true);
|
|
btnImport->setIconSize(QSize(24, 24));
|
|
btnImport->setToolTip(tr("Pay"));
|
|
tbLayout->insertWidget(tbLayout->count() - 1, btnImport);
|
|
|
|
connect(btnImport, &QToolButton::clicked, [this](){
|
|
CampDataPtr data = currentEntity();
|
|
|
|
if (!data.isNull())
|
|
{
|
|
addToVoucher(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
m_detail = new DetailWidget(this);
|
|
mainLayout()->addWidget(m_detail);
|
|
}
|
|
|
|
void CampGrid::handleNewRecord()
|
|
{
|
|
if (!checkPermAdd())
|
|
{
|
|
return;
|
|
}
|
|
|
|
CampService srv;
|
|
CampDataPtr data = srv.create();
|
|
CampWizard *wizard = new CampWizard();
|
|
wizard->setAttribute(Qt::WA_DeleteOnClose);
|
|
wizard->setData(data);
|
|
wizard->setNewRecord(true);
|
|
|
|
connect(wizard, &QDialog::accepted, [this, data](){
|
|
addRow(data);
|
|
});
|
|
|
|
wizard->show();
|
|
}
|
|
|
|
void CampGrid::handleEditRecord()
|
|
{
|
|
if (!checkPermEdit())
|
|
{
|
|
return;
|
|
}
|
|
|
|
CampDataPtr data = currentEntity();
|
|
if (data.isNull())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (data->onVoucher())
|
|
{
|
|
QMessageBox::critical(this, tr("Can not edit"), tr("This record is asociated with voucher. Can not edit paid items"));
|
|
return;
|
|
}
|
|
|
|
if (data->people().isEmpty() || data->services().isEmpty()) {
|
|
CampService srv;
|
|
srv.load(data);
|
|
}
|
|
|
|
CampWizard *wizard = new CampWizard();
|
|
wizard->setAttribute(Qt::WA_DeleteOnClose);
|
|
wizard->setData(data);
|
|
wizard->show();
|
|
}
|
|
|
|
void CampGrid::doDelete(CampDataPtr entity)
|
|
{
|
|
if (!checkPermDelete())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (entity->onVoucher())
|
|
{
|
|
QMessageBox::critical(this, tr("Can not delete"), tr("This record is asociated with voucher. Can not delete paid items"));
|
|
return;
|
|
}
|
|
|
|
CampService srv;
|
|
srv.erase(entity);
|
|
}
|
|
|
|
void CampGrid::addToVoucher(const CampDataPtr& data)
|
|
{
|
|
if (data->onVoucher())
|
|
{
|
|
QMessageBox::information(this, tr("Can not pay"), tr("This record is already paid"));
|
|
return;
|
|
}
|
|
|
|
SettingsService settSrv("CAMP");
|
|
CampSettingsPtr settings = settSrv.loadSettings<CampSettings>();
|
|
CampShopItemPtr campItem(new CampShopItem);
|
|
|
|
campItem->setId(data->id());
|
|
campItem->setUnitPrice(data->totalPrice());
|
|
campItem->setVatType(settings->vatType());
|
|
|
|
ShopService shopSrv;
|
|
VoucherPtr voucher = shopSrv.createVoucher();
|
|
|
|
shopSrv.addShopItem(voucher, campItem, 1);
|
|
shopSrv.calculate(voucher);
|
|
shopSrv.save(voucher);
|
|
|
|
data->setOnVoucher(true);
|
|
|
|
CampService srvCamp;
|
|
srvCamp.update(data);
|
|
|
|
PayDialog *payDlg = new PayDialog(voucher->totalPrice(), this);
|
|
payDlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
payDlg->show();
|
|
|
|
connect(payDlg, &QDialog::accepted, [payDlg, voucher](){
|
|
payVoucherFromUI(voucher, payDlg);
|
|
});
|
|
|
|
connect(payDlg, &QDialog::rejected, [voucher, &shopSrv, data](){
|
|
CampService srvCamp;
|
|
data->setOnVoucher(false);
|
|
srvCamp.update(data);
|
|
voucher->clearItems();
|
|
shopSrv.erase(voucher);
|
|
});
|
|
}
|
|
|
|
void CampGrid::currentIndexChanged(const QModelIndex ¤t)
|
|
{
|
|
if (current.isValid())
|
|
{
|
|
auto current = currentEntity();
|
|
m_detail->setData(current);
|
|
}
|
|
}
|
|
|
|
QList<CampDataPtr> CampGrid::listForGrid()
|
|
{
|
|
CampService srv;
|
|
return srv.allForSeason();
|
|
}
|