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.
prodejna/core/numberseriesservice.cpp

56 lines
1.5 KiB
C++

#include "numberseriesservice.h"
#include "seasonservice.h"
QSharedPointer<NumberSeries> NumberSeriesService::forPluginAndSeason(const QString& pluginId, const QSharedPointer<Season>& season)
{
QList<QSharedPointer<NumberSeries> > series = all(QString("pluginId = '%1' AND season = %2").arg(pluginId, QString::number(season->id())));
if (!series.isEmpty())
{
load(series[0]);
return series[0];
}
return {};
}
QSharedPointer<NumberSeries> NumberSeriesService::forPlugin(const QString& pluginId)
{
SeasonService sesSrv;
QSharedPointer<Season> currentSeason = sesSrv.active();
if (!currentSeason.isNull())
{
return forPluginAndSeason(pluginId, currentSeason);
}
return {};
}
QSharedPointer<NumberSeries> NumberSeriesService::nextForPlugin(const QString& pluginId, qx::QxSession* pSession/* = nullptr*/)
{
QSharedPointer<NumberSeries> numSer = forPlugin(pluginId);
if (numSer.isNull())
{
return {};
}
numSer->setLastNumber(numSer->lastNumber() + 1);
update(numSer, pSession);
return numSer;
}
QList<QSharedPointer<NumberSeries> > NumberSeriesService::allForSeason(const QSharedPointer<Season>& season)
{
return all(QString("season = %1").arg(QString::number(season->id())));
}
QString NumberSeriesService::nextStrForPlugin(const QString& pluginId, qx::QxSession* pSession)
{
NumberSeriesPtr numSer = nextForPlugin(pluginId, pSession);
return QString("%1%2").arg(numSer->prefix()).arg(numSer->lastNumber(), 5, 10, QLatin1Char('0'));
}