Compare commits

..

No commits in common. "9d220df52efd39528c8613637f4d5c4b182dbc6b" and "73b1c1459e055b562c9a2470c88055a859304eda" have entirely different histories.

2 changed files with 180 additions and 110 deletions

View File

@ -140,7 +140,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid); Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
// qCritical().noquote() << t; qCritical().noquote() << t;
// TODO: im fehlerfall // TODO: im fehlerfall
return t.getValidUntil().toString(Qt::ISODate).toStdString(); return t.getValidUntil().toString(Qt::ISODate).toStdString();
@ -207,7 +207,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
durationMinutes, durationMinutes,
prepaid); prepaid);
if (t) { if (t) {
// qCritical().noquote() << t; qCritical().noquote() << t;
} }
end_datetime = t.getValidUntil(); end_datetime = t.getValidUntil();
@ -324,6 +324,8 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
for (current = start; durationMinutes > 0; current = current.addDays(1)) { for (current = start; durationMinutes > 0; current = current.addDays(1)) {
int const weekdayId = current.date().dayOfWeek(); int const weekdayId = current.date().dayOfWeek();
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
specialDayId = -1; specialDayId = -1;
// find worktime ranges for the current day // find worktime ranges for the current day
@ -365,27 +367,28 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil(); QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
// find worktime range to start with // find worktime range to start with
int currentRange = 0; int currentRange = 0;
if (!isSpecialDay) { if (!isSpecialDay) {
if (start != current) { // on next day if (start != current) { // on next day
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} else { } else {
// check if inputDate is located inside a valid worktime-range... // check if inputDate is located inside a valid worktime-range...
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) { currentRange = findWorkTimeRange(current, worktime, ranges);
if (!prepaid && carryOverNotSet) { // parking is not allowed if (currentRange == -1) { // no...
if (!prepaid) { // parking is not allowed
return Ticket(start, QDateTime(), durationMinutesNetto, 0, return Ticket(start, QDateTime(), durationMinutesNetto, 0,
0, Ticket::s[INVALID_FROM_DATETIME]); 0, Ticket::s[INVALID_FROM_DATETIME]);
} }
// find the next worktime-range (on the same day), and start from there // find the next worktime-range (on the same day), and start from there
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) { currentRange = findNextWorkTimeRange(current, worktime, ranges);
end = current;
continue;
}
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} }
} }
} }
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) { for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
if (durationMinutes > 0) { if (durationMinutes > 0) {
QTime const &worktime_from = worktime[w].getTimeFrom(); QTime const &worktime_from = worktime[w].getTimeFrom();
@ -397,7 +400,13 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
current.setTime(worktime_from); current.setTime(worktime_from);
} }
qCritical() << "worktime_from" << worktime_from;
qCritical() << "worktime_to" << worktime_to;
qCritical() << "current" << current.toString(Qt::ISODate);
if (price == 0) { if (price == 0) {
// inputDate = inputDate.addDays(1);
// inputDate.setTime(worktime_from);
end = current; end = current;
current.setTime(QTime()); current.setTime(QTime());
continue; continue;
@ -449,6 +458,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
durationMinutes -= 1; durationMinutes -= 1;
//costFromDuration += price_per_unit; //costFromDuration += price_per_unit;
costFromDuration += price; costFromDuration += price;
qCritical() << "current" << current.toString(Qt::ISODate) << durationMinutes << costFromDuration;
} else break; } else break;
} }
} // while(durationMinutes > 0) { } // while(durationMinutes > 0) {
@ -458,9 +468,12 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
int durationMinutesBrutto = start.secsTo(end) / 60; int durationMinutesBrutto = start.secsTo(end) / 60;
qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end
<< llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit));
return return
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto, Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
ceil(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)), llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
Ticket::s[VALID]); Ticket::s[VALID]);
} }
@ -472,6 +485,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
// Get input date // Get input date
QDateTime current = start; QDateTime current = start;
qCritical() << "current" << current.toString(Qt::ISODate);
// use tariff with structure as for instance Schnau, Koenigsee: // use tariff with structure as for instance Schnau, Koenigsee:
// without given YearPeriod, SpecialDays and SpecialDaysWorktime // without given YearPeriod, SpecialDays and SpecialDaysWorktime
if (cfg->YearPeriod.size() == 0 if (cfg->YearPeriod.size() == 0
@ -511,18 +526,22 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
return Ticket(); return Ticket();
} }
qCritical() << "current" << current.toString(Qt::ISODate);
uint32_t durationMinutesNetto = 0; uint32_t durationMinutesNetto = 0;
double moneyLeft = cost; int moneyLeft = cost;
double durationUnit = 1; uint32_t durationUnit = 1;
int specialDayId = -1; int specialDayId = -1;
bool isSpecialDay = false; bool isSpecialDay = false;
QDateTime end = start; QDateTime end = start;
int totalTimeRanges = 0; int totalTimeRanges = 0;
double price = 0; uint32_t price = 0;
for (current = start; moneyLeft > 0 && moneyLeft >= price; current = current.addDays(1)) { for (current = start; moneyLeft > 0; current = current.addDays(1), moneyLeft /= durationUnit) {
int const weekdayId = current.date().dayOfWeek(); int const weekdayId = current.date().dayOfWeek();
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
specialDayId = -1; specialDayId = -1;
// find worktime ranges for the current day // find worktime ranges for the current day
@ -530,12 +549,9 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]); QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
int ranges = 0; int ranges = 0;
uint32_t p = 0; if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &price))) {
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &p))) {
// Set special day price: // Set special day price:
durationUnit = specialDaysDurationUnit; durationUnit = specialDaysDurationUnit;
price = p / durationUnit;
price = std::round(price * 1000.0) / 1000.0;
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId), worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
SpecialDaysWorkTimeUntil(cfg, specialDayId)); SpecialDaysWorkTimeUntil(cfg, specialDayId));
ranges = 1; ranges = 1;
@ -545,12 +561,10 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
// the computation the price is divided by durationUnit. // the computation the price is divided by durationUnit.
price = weekDaysPrice; price = weekDaysPrice;
durationUnit = weekDaysDurationUnit; durationUnit = weekDaysDurationUnit;
price /= durationUnit;
price = std::round(price * 1000.0) / 1000.0; // round to 3 decimals
// If no working day found, skip it (epsecially Sundays!) // If no working day found, skip it (epsecially Sundays!)
if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) { if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
// qDebug() << "No workday found, trying to find next available day"; qDebug() << "No workday found, trying to find next available day";
end = current; end = current;
current.setTime(QTime()); // start at midnight on the next day current.setTime(QTime()); // start at midnight on the next day
continue; continue;
@ -566,30 +580,33 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} }
} }
moneyLeft *= durationUnit;
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil(); QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
// find worktime range to start with // find worktime range to start with
int currentRange = 0; int currentRange = 0;
if (!isSpecialDay) { if (!isSpecialDay) {
if (start != current) { // on next day if (start != current) { // on next day
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} else { } else {
// check if inputDate is located inside a valid worktime-range... // check if inputDate is located inside a valid worktime-range...
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) { currentRange = findWorkTimeRange(current, worktime, ranges);
if (!prepaid && carryOverNotSet) { // parking is not allowed if (currentRange == -1) { // no...
if (!prepaid) { // parking is not allowed
return Ticket(start, QDateTime(), durationMinutesNetto, 0, return Ticket(start, QDateTime(), durationMinutesNetto, 0,
0, Ticket::s[INVALID_FROM_DATETIME]); 0, Ticket::s[INVALID_FROM_DATETIME]);
} }
// find the next worktime-range (on the same day), and start from there // find the next worktime-range (on the same day), and start from there
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) { currentRange = findNextWorkTimeRange(current, worktime, ranges);
end = current;
continue;
}
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} }
} }
} }
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) { for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
if (moneyLeft > 0) { if (moneyLeft > 0) {
QTime const &worktime_from = worktime[w].getTimeFrom(); QTime const &worktime_from = worktime[w].getTimeFrom();
@ -601,6 +618,10 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
current.setTime(worktime_from); current.setTime(worktime_from);
} }
qCritical() << "worktime_from" << worktime_from;
qCritical() << "worktime_to" << worktime_to;
qCritical() << "current" << current.toString(Qt::ISODate);
if (price == 0) { if (price == 0) {
// inputDate = inputDate.addDays(1); // inputDate = inputDate.addDays(1);
// inputDate.setTime(worktime_from); // inputDate.setTime(worktime_from);
@ -634,7 +655,7 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} }
} }
while(moneyLeft >= price) { while(moneyLeft > 0) {
// Check for active year period // Check for active year period
if (!IsYearPeriodActive(cfg, current)) { if (!IsYearPeriodActive(cfg, current)) {
return Ticket(); return Ticket();
@ -654,11 +675,13 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} else { } else {
if(current.time() < worktime_to) { if(current.time() < worktime_to) {
// Increment input date minutes for each monetary unit // Increment input date minutes for each monetary unit
durationMinutesNetto +=1;
moneyLeft -= price;
moneyLeft = std::round(moneyLeft * 1000.0) / 1000.0;
current = current.addSecs(60); current = current.addSecs(60);
end = current; end = current;
if(price > 0) {
durationMinutesNetto +=1;
}
moneyLeft -= price;
qCritical() << "current" << current.toString(Qt::ISODate) << "moneyLeft" << moneyLeft;
} else break; } else break;
} }
} // while(durationMinutes > 0) { } // while(durationMinutes > 0) {
@ -668,8 +691,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
int durationMinutesBrutto = start.secsTo(end) / 60; int durationMinutesBrutto = start.secsTo(end) / 60;
//qCritical() << "start" << start.toString(Qt::ISODate) << "end" qCritical() << "start" << start.toString(Qt::ISODate) << "end"
// << end.toString(Qt::ISODate) << durationMinutesBrutto; << end.toString(Qt::ISODate) << durationMinutesBrutto;
return return
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto, Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,

File diff suppressed because one or more lines are too long