Added:
Calculator::computeBruttoDurationInSecs() and Calculator::computeBruttoDateTime() (based on it).
This commit is contained in:
parent
21534ba153
commit
75c98c18ad
@ -117,6 +117,117 @@ QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime
|
||||
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
int Calculator::computeBruttoDurationInSecs(Configuration const *cfg,
|
||||
QDateTime const &start,
|
||||
int nettoDurationInSecs,
|
||||
bool maxBrutto) {
|
||||
QDateTime from(start);
|
||||
int bruttoDurationInSecs = 0;
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER << "netto duration in secs" << nettoDurationInSecs;
|
||||
}
|
||||
|
||||
while (nettoDurationInSecs > 0) {
|
||||
int day_in_week_id = from.date().dayOfWeek();
|
||||
int count = cfg->WeekDaysWorktime.count(day_in_week_id);
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER << "count for " << day_in_week_id << ": " << count;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
|
||||
QTime const &pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
||||
QTime const &pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
|
||||
QTime fromTime = from.time();
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER;
|
||||
qCritical() << DBG_HEADER << " wd-from" << pwd_time_from.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " wd-to" << pwd_time_to.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << "fromTime" << fromTime.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER;
|
||||
}
|
||||
|
||||
if (fromTime <= pwd_time_from) {
|
||||
int secs = fromTime.secsTo(pwd_time_from);
|
||||
bruttoDurationInSecs += secs;
|
||||
fromTime = pwd_time_from;
|
||||
from.setTime(pwd_time_from);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER << "fromTime" << fromTime.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " netto" << nettoDurationInSecs;
|
||||
qCritical() << DBG_HEADER << " brutto" << bruttoDurationInSecs;
|
||||
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
|
||||
}
|
||||
|
||||
while (fromTime < pwd_time_to && nettoDurationInSecs > 0) {
|
||||
bruttoDurationInSecs += 60;
|
||||
nettoDurationInSecs -= 60;
|
||||
fromTime = fromTime.addSecs(60);
|
||||
from = from.addSecs(60);
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER;
|
||||
qCritical() << DBG_HEADER << " netto" << nettoDurationInSecs;
|
||||
qCritical() << DBG_HEADER << " brutto" << bruttoDurationInSecs;
|
||||
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
|
||||
qCritical() << DBG_HEADER << "fromTime" << fromTime.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER;
|
||||
}
|
||||
|
||||
if (--count == 0 && fromTime == pwd_time_to) {
|
||||
// handle rest
|
||||
QDateTime midnight(from);
|
||||
midnight = midnight.addDays(1);
|
||||
midnight.setTime(QTime(0, 0, 0));
|
||||
int secs = from.secsTo(midnight);
|
||||
bruttoDurationInSecs += secs;
|
||||
from = midnight;
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER;
|
||||
qCritical() << DBG_HEADER << " netto" << nettoDurationInSecs;
|
||||
qCritical() << DBG_HEADER << " brutto" << bruttoDurationInSecs;
|
||||
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
|
||||
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
bruttoDurationInSecs += (24 * 3600);
|
||||
from = from.addDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxBrutto) {
|
||||
qCritical() << DBG_HEADER << "TODO";
|
||||
}
|
||||
|
||||
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
|
||||
}
|
||||
|
||||
return bruttoDurationInSecs;
|
||||
}
|
||||
|
||||
QDateTime Calculator::computeBruttoDateTime(Configuration const *cfg,
|
||||
QDateTime const &from,
|
||||
int durationInSecs,
|
||||
bool maxBrutto) {
|
||||
return from.addSecs(computeBruttoDurationInSecs(cfg, from, durationInSecs, maxBrutto));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
uint8_t payment_option,
|
||||
|
Loading…
Reference in New Issue
Block a user