Compare commits
No commits in common. "9d220df52efd39528c8613637f4d5c4b182dbc6b" and "73b1c1459e055b562c9a2470c88055a859304eda" have entirely different histories.
9d220df52e
...
73b1c1459e
@ -140,7 +140,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
|
||||
|
||||
// qCritical().noquote() << t;
|
||||
qCritical().noquote() << t;
|
||||
|
||||
// TODO: im fehlerfall
|
||||
return t.getValidUntil().toString(Qt::ISODate).toStdString();
|
||||
@ -207,7 +207,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
||||
durationMinutes,
|
||||
prepaid);
|
||||
if (t) {
|
||||
// qCritical().noquote() << t;
|
||||
qCritical().noquote() << t;
|
||||
}
|
||||
|
||||
end_datetime = t.getValidUntil();
|
||||
@ -324,6 +324,8 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
for (current = start; durationMinutes > 0; current = current.addDays(1)) {
|
||||
int const weekdayId = current.date().dayOfWeek();
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
|
||||
|
||||
specialDayId = -1;
|
||||
|
||||
// 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();
|
||||
|
||||
// find worktime range to start with
|
||||
|
||||
int currentRange = 0;
|
||||
if (!isSpecialDay) {
|
||||
if (start != current) { // on next day
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
} else {
|
||||
// check if inputDate is located inside a valid worktime-range...
|
||||
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
if (!prepaid && carryOverNotSet) { // parking is not allowed
|
||||
currentRange = findWorkTimeRange(current, worktime, ranges);
|
||||
if (currentRange == -1) { // no...
|
||||
if (!prepaid) { // parking is not allowed
|
||||
return Ticket(start, QDateTime(), durationMinutesNetto, 0,
|
||||
0, Ticket::s[INVALID_FROM_DATETIME]);
|
||||
}
|
||||
// find the next worktime-range (on the same day), and start from there
|
||||
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
end = current;
|
||||
continue;
|
||||
}
|
||||
currentRange = findNextWorkTimeRange(current, worktime, ranges);
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
|
||||
|
||||
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
||||
if (durationMinutes > 0) {
|
||||
QTime const &worktime_from = worktime[w].getTimeFrom();
|
||||
@ -397,7 +400,13 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
current.setTime(worktime_from);
|
||||
}
|
||||
|
||||
qCritical() << "worktime_from" << worktime_from;
|
||||
qCritical() << "worktime_to" << worktime_to;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
if (price == 0) {
|
||||
// inputDate = inputDate.addDays(1);
|
||||
// inputDate.setTime(worktime_from);
|
||||
end = current;
|
||||
current.setTime(QTime());
|
||||
continue;
|
||||
@ -449,6 +458,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
durationMinutes -= 1;
|
||||
//costFromDuration += price_per_unit;
|
||||
costFromDuration += price;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << durationMinutes << costFromDuration;
|
||||
} else break;
|
||||
}
|
||||
} // while(durationMinutes > 0) {
|
||||
@ -458,9 +468,12 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
|
||||
int durationMinutesBrutto = start.secsTo(end) / 60;
|
||||
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end
|
||||
<< llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit));
|
||||
|
||||
return
|
||||
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
|
||||
ceil(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
|
||||
llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
|
||||
Ticket::s[VALID]);
|
||||
}
|
||||
|
||||
@ -472,6 +485,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
// Get input date
|
||||
QDateTime current = start;
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
// use tariff with structure as for instance Schnau, Koenigsee:
|
||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||
if (cfg->YearPeriod.size() == 0
|
||||
@ -511,18 +526,22 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
return Ticket();
|
||||
}
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
uint32_t durationMinutesNetto = 0;
|
||||
double moneyLeft = cost;
|
||||
double durationUnit = 1;
|
||||
int moneyLeft = cost;
|
||||
uint32_t durationUnit = 1;
|
||||
int specialDayId = -1;
|
||||
bool isSpecialDay = false;
|
||||
QDateTime end = start;
|
||||
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();
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
|
||||
|
||||
specialDayId = -1;
|
||||
|
||||
// find worktime ranges for the current day
|
||||
@ -530,12 +549,9 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
|
||||
int ranges = 0;
|
||||
|
||||
uint32_t p = 0;
|
||||
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &p))) {
|
||||
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &price))) {
|
||||
// Set special day price:
|
||||
durationUnit = specialDaysDurationUnit;
|
||||
price = p / durationUnit;
|
||||
price = std::round(price * 1000.0) / 1000.0;
|
||||
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
|
||||
SpecialDaysWorkTimeUntil(cfg, specialDayId));
|
||||
ranges = 1;
|
||||
@ -545,12 +561,10 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
// the computation the price is divided by durationUnit.
|
||||
price = weekDaysPrice;
|
||||
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 (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;
|
||||
current.setTime(QTime()); // start at midnight on the next day
|
||||
continue;
|
||||
@ -566,30 +580,33 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
}
|
||||
}
|
||||
|
||||
moneyLeft *= durationUnit;
|
||||
|
||||
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
||||
|
||||
// find worktime range to start with
|
||||
|
||||
int currentRange = 0;
|
||||
if (!isSpecialDay) {
|
||||
if (start != current) { // on next day
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
} else {
|
||||
// check if inputDate is located inside a valid worktime-range...
|
||||
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
if (!prepaid && carryOverNotSet) { // parking is not allowed
|
||||
currentRange = findWorkTimeRange(current, worktime, ranges);
|
||||
if (currentRange == -1) { // no...
|
||||
if (!prepaid) { // parking is not allowed
|
||||
return Ticket(start, QDateTime(), durationMinutesNetto, 0,
|
||||
0, Ticket::s[INVALID_FROM_DATETIME]);
|
||||
}
|
||||
// find the next worktime-range (on the same day), and start from there
|
||||
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
end = current;
|
||||
continue;
|
||||
}
|
||||
currentRange = findNextWorkTimeRange(current, worktime, ranges);
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
|
||||
|
||||
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
||||
if (moneyLeft > 0) {
|
||||
QTime const &worktime_from = worktime[w].getTimeFrom();
|
||||
@ -601,6 +618,10 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
current.setTime(worktime_from);
|
||||
}
|
||||
|
||||
qCritical() << "worktime_from" << worktime_from;
|
||||
qCritical() << "worktime_to" << worktime_to;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
if (price == 0) {
|
||||
// inputDate = inputDate.addDays(1);
|
||||
// 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
|
||||
if (!IsYearPeriodActive(cfg, current)) {
|
||||
return Ticket();
|
||||
@ -654,11 +675,13 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
} else {
|
||||
if(current.time() < worktime_to) {
|
||||
// Increment input date minutes for each monetary unit
|
||||
durationMinutesNetto +=1;
|
||||
moneyLeft -= price;
|
||||
moneyLeft = std::round(moneyLeft * 1000.0) / 1000.0;
|
||||
current = current.addSecs(60);
|
||||
end = current;
|
||||
if(price > 0) {
|
||||
durationMinutesNetto +=1;
|
||||
}
|
||||
moneyLeft -= price;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << "moneyLeft" << moneyLeft;
|
||||
} else break;
|
||||
}
|
||||
} // while(durationMinutes > 0) {
|
||||
@ -668,8 +691,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
|
||||
int durationMinutesBrutto = start.secsTo(end) / 60;
|
||||
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate) << "end"
|
||||
// << end.toString(Qt::ISODate) << durationMinutesBrutto;
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << "end"
|
||||
<< end.toString(Qt::ISODate) << durationMinutesBrutto;
|
||||
|
||||
return
|
||||
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
|
||||
|
203
main/main.cpp
203
main/main.cpp
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user