From 653f8eac30d725729fe1ac4a23bab0288ba41d0e Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 23 May 2018 14:11:56 +0200 Subject: [PATCH] Added dashboard to Shop plugin. --- shop/data/voucher.cpp | 16 +++++ shop/data/voucher.h | 14 ++++ shop/icons/shop_64x64.png | Bin 0 -> 2377 bytes shop/shop.cpp | 2 + shop/shop.pro | 9 ++- shop/shopoverview.cpp | 28 ++++++++ shop/shopoverview.h | 27 ++++++++ shop/shopoverview.ui | 139 ++++++++++++++++++++++++++++++++++++++ shop/shoprc.qrc | 1 + shop/shopservice.cpp | 28 ++++++++ shop/shopservice.h | 2 + 11 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 shop/icons/shop_64x64.png create mode 100644 shop/shopoverview.cpp create mode 100644 shop/shopoverview.h create mode 100644 shop/shopoverview.ui 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 0000000000000000000000000000000000000000..67917e647ee2e6c384972f882c5f11d538968270 GIT binary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{^q}x$#*LhdGx(Nsf{~Qo-^`)LUAO@eR zcJ{bNhZ9rT)&MYKm}WFnm!ik3TTi9+1N|dOKy8^yi$j!cL~83Pd`hOY-%aEJ!q#O= z|44fMuWWx4;KfYd3jZQ!=tk1-?2&!LuHL&eePF~@gaVq+{jRd#jWZTtwM$3eu*(Xm z2#yQ@ypRzB>b7h_2+?FE7Ud{~7kULEv1<|@E>-C+JL=;B9*^4t7){62CUgKoSZhcv zfp+o(I5(Lu$`caMeEKv>Svfa1-0N_+ms*pFFs@)zg|~YTN5zywU^pr~F`FuqO_(O& z#a1USXZY5bPnnbW7&F-rhy(GeE3Y|}z25FRKU8@fc!29et`P7cAT~p~@RqYLFEopCxaqAX(m$;sYD+GMXV5$dnN4zoX7A6x&?@)RR zUe(?J@R!Mcikr%(u@~|p-Byex6l(TDQxjo%x(D>6kQCI$As}TnJsuvgy4-cw9kDI2 z-wP=zywd^jo5>nADFQybb0?9Jky8o{5sM|0642sGgd57!6IUup0?3`0j>(X;}4-pF0<(!R8}^fhZihBsg#} z{a|wVvY>C+>Z9KJ0J;X#3FsQM-brOOH-|5aG$IdN6dbx_>DqimIN~1#t1kT%;N_|O zFT#|ry*F&!$o%|#*|PC~xVd2MhwF>SwbQJ5_j_@}G=ozaH)#)e;)y3{Ie#ADn;XvW zV`10Xv`dINc@!+}Y-G*5-v#)>REfLW{}1>gs9(kd1#~RmLx1@OlopuP9TzfA*^L%z z{{066@gYEb&M?iRvqFGPLNV}tP+uL3)mdd=?1uxucMQ`Uyqjr)(^$fQVVe7ZeIZ@X vLCpGRG-a6PXv!6SRsetupUi(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);