closes #4: Favorite buttons has been extended with category buttons.

This commit is contained in:
2023-05-17 21:31:32 +02:00
parent 5b5f31f64d
commit 5b77337b3f
33 changed files with 596 additions and 106 deletions
+50 -5
View File
@@ -371,7 +371,7 @@ void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, Vouc
if (target->status() == Voucher::NEW && target->id() == 0)
{
this->saveVoucher(target, &session);
this->save(target, &session);
}
for (const auto& it : items) {
@@ -415,7 +415,7 @@ QList<VoucherPtr> ShopService::vouchersForEet()
.arg(QString::number(Voucher::PAID), QString::number(Voucher::EET_SENT), QString::number(Voucher::EET_NOT_ENTERING)));
}
QList<IShopItemPtr> ShopService::allSellableItems()
QList<IShopItemPtr> ShopService::allSellableItems(const QString& category/* = ""*/)
{
QList<QSharedPointer<IShopItem> > items;
foreach (IPlugin *plugin, Context::instance().plugins()) {
@@ -424,7 +424,7 @@ QList<IShopItemPtr> ShopService::allSellableItems()
if (selSrv != nullptr)
{
items.append(selSrv->shopItems());
items.append(selSrv->shopItems(category));
}
}
@@ -491,13 +491,58 @@ QDecDouble ShopService::vatRate(Enums::VatType vatType)
return vatRate;
}
void ShopService::saveVoucher(VoucherPtr entity, qx::QxSession* pSession/* = nullptr*/)
void ShopService::save(VoucherPtr entity, qx::QxSession* pSession/* = nullptr*/)
{
SeasonService seasonSrv;
SeasonPtr season = seasonSrv.active();
entity->setSeason(season);
addDateAndUser(entity, true);
save(entity, pSession);
Service::save(entity, pSession);
}
QMap<QString, QString> ShopService::allCategories() {
QMap<QString, QString> ret;
for (const auto& item : allSellableItems()) {
if (!item->category().isEmpty() && !ret.contains(item->category())) {
ret[item->category()] = item->color();
}
}
return ret;
}
void ShopService::update(VoucherPtr entity, qx::QxSession* pSession) {
bool reloadItems = pSession == nullptr;
{
QScopedPointer<qx::QxSession> ptrSession;
if (pSession == nullptr) {
ptrSession.reset(new qx::QxSession());
pSession = ptrSession.data();
}
Service::update(entity, pSession);
auto oldItems = entity->items();
entity->clearItems();
load(entity);
for (auto item : entity->items()) {
auto newItem = std::find_if(oldItems.begin(), oldItems.end(), [item](auto it){
return item->id() == it->id();
});
if (newItem == oldItems.end()) {
qx::dao::delete_by_id(item, pSession->database());
}
}
}
if (reloadItems) {
entity->clearItems();
load(entity);
}
}