diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index d380649..482972a 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -350,3 +350,19 @@ void Voucher::setId(int id) { m_id = id; } + +VoucherSum::VoucherSum() +{ + m_totalPrice = 0; + m_count = 0; +} + +QDecDouble VoucherSum::totalPrice() const +{ + return TO_DEC(m_totalPrice); +} + +void VoucherSum::setTotalPrice(QDecDouble totalPrice) +{ + m_totalPrice = FROM_DEC(totalPrice); +} diff --git a/shop/data/voucher.h b/shop/data/voucher.h index f0de1b9..50efa76 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -210,4 +210,18 @@ private: typedef QSharedPointer VoucherPtr; +#pragma db view object(Voucher) +struct VoucherSum +{ + VoucherSum(); + + QDecDouble totalPrice() const; + void setTotalPrice(QDecDouble totalPrice); + + #pragma db column("count(id)") + int m_count; + #pragma db column("sum(totalPrice)") + int m_totalPrice; +}; + #endif // VOUCHER_H diff --git a/shop/icons/shop_64x64.png b/shop/icons/shop_64x64.png new file mode 100644 index 0000000..67917e6 Binary files /dev/null and b/shop/icons/shop_64x64.png differ diff --git a/shop/shop.cpp b/shop/shop.cpp index 7d6cf73..46d3d53 100644 --- a/shop/shop.cpp +++ b/shop/shop.cpp @@ -4,6 +4,7 @@ #include "shopservice.h" #include "settings/shopsettingsform.h" #include "shop-odb.hxx" +#include "shopoverview.h" Shop::Shop() { @@ -14,6 +15,7 @@ void Shop::initServiceUi() m_ui = new ShopForm(); m_service = new ShopService(); m_settingsUi = new ShopSettingsForm(); + m_dashboardWidgets << new ShopOverview(); } QIcon Shop::pluginIcon() diff --git a/shop/shop.pro b/shop/shop.pro index c736271..81fd717 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -32,7 +32,8 @@ SOURCES += shop.cpp \ isellableservice.cpp \ data/favorititem.cpp \ eetbatchdialog.cpp \ - iseller.cpp + iseller.cpp \ + shopoverview.cpp HEADERS += shop.h\ shop_global.h \ @@ -57,7 +58,8 @@ HEADERS += shop.h\ data/favorititem.h \ eetbatchdialog.h \ favbutton.h \ - iseller.h + iseller.h \ + shopoverview.h include(../config_plugin.pri) @@ -80,7 +82,8 @@ FORMS += \ settings/shopsettingsform.ui \ paydialog.ui \ paydvouchersdialog.ui \ - eetbatchdialog.ui + eetbatchdialog.ui \ + shopoverview.ui win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook diff --git a/shop/shopoverview.cpp b/shop/shopoverview.cpp new file mode 100644 index 0000000..fadf141 --- /dev/null +++ b/shop/shopoverview.cpp @@ -0,0 +1,28 @@ +#include "shopoverview.h" +#include "ui_shopoverview.h" +#include "shop-odb.hxx" +#include "shopservice.h" + +ShopOverview::ShopOverview(QWidget *parent) : + QFrame(parent), + ui(new Ui::ShopOverview) +{ + ui->setupUi(this); +} + +ShopOverview::~ShopOverview() +{ + delete ui; +} + +void ShopOverview::refresh() +{ + ShopService srv; + + VoucherSum unpaid = srv.unpaidSummary(); + VoucherSum unsend = srv.unsendEET(); + + ui->labelUnapiedCount->setText(QString::number(unpaid.m_count)); + ui->labelUnpaiedAmount->setText(QString::number(unpaid.totalPrice().toDouble())); + ui->labelUnsendEET->setText(QString::number(unsend.m_count)); +} diff --git a/shop/shopoverview.h b/shop/shopoverview.h new file mode 100644 index 0000000..d999ec8 --- /dev/null +++ b/shop/shopoverview.h @@ -0,0 +1,27 @@ +#ifndef SHOPOVERVIEW_H +#define SHOPOVERVIEW_H + +#include +#include + +namespace Ui { +class ShopOverview; +} + +class ShopOverview : public QFrame, public IDashboardWidget +{ + Q_OBJECT + +public: + explicit ShopOverview(QWidget *parent = 0); + ~ShopOverview(); + +private: + Ui::ShopOverview *ui; + + // IDashboardWidget interface +public: + virtual void refresh() override; +}; + +#endif // SHOPOVERVIEW_H diff --git a/shop/shopoverview.ui b/shop/shopoverview.ui new file mode 100644 index 0000000..f228cc6 --- /dev/null +++ b/shop/shopoverview.ui @@ -0,0 +1,139 @@ + + + ShopOverview + + + + 0 + 0 + 908 + 95 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + :/icons/shop_64x64.png + + + + + + + + + + Unpaid vouchers: + + + + + + + + 90 + 0 + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Unpaid amount: + + + + + + + + 90 + 0 + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + true + + + + Unsend to EET: + + + + + + + + 90 + 0 + + + + + 75 + true + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/shop/shoprc.qrc b/shop/shoprc.qrc index 97a2d74..e28635d 100644 --- a/shop/shoprc.qrc +++ b/shop/shoprc.qrc @@ -7,5 +7,6 @@ icons/pay.svg icons/sendEet.svg icons/pay_24x24.png + icons/shop_64x64.png diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 3ff5b4b..17852e5 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -427,6 +427,34 @@ QList ShopService::allSellableItems() return items; } +VoucherSum ShopService::unpaidSummary() +{ + Transaction tr; + + odb::database *db = Context::instance().db(); + typedef odb::query query; + + VoucherSum sum = db->query_value("status = " + query::_ref((int)Voucher::NOT_PAID)); + + tr.commit(); + return sum; +} + +VoucherSum ShopService::unsendEET() +{ + Transaction tr; + + odb::database *db = Context::instance().db(); + typedef odb::query query; + + VoucherSum sum = db->query_value("(eetStatus = " + query::_ref((int)Voucher::EET_FOR_SEND) + + " OR eetStatus = " + query::_ref((int)Voucher::EET_ERROR) + + ") AND status = " + query::_ref((int)Voucher::PAID)); + + tr.commit(); + return sum; +} + QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType) { return price * ((vatRate(vatType) / 100) + QDecDouble(1)); diff --git a/shop/shopservice.h b/shop/shopservice.h index d4dc3a1..4092a26 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -41,6 +41,8 @@ public: QList paiedVouchers(); QList vouchersForEet(); QList allSellableItems(); + VoucherSum unpaidSummary(); + VoucherSum unsendEET(); private: QDecDouble includeVat(QDecDouble price, Enums::VatType vatType);