24-hour ticket

This commit is contained in:
Moran Rod 2023-08-22 12:16:25 +02:00
parent 7bd7f66666
commit 8a7828c1e6
8 changed files with 885 additions and 18 deletions

View File

@ -137,6 +137,11 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
parking_tariff_t *tariff,
QString const &start_parking_time,
uint8_t paymentMethod);
CalcState CALCULATE_LIBRARY_API compute_duration_for_24hour_daily_ticket(
parking_tariff_t *tariff,
QString const &start_parking_time,
uint8_t paymentMethod);
//#ifdef __cplusplus
//} // extern "C"
//#endif

View File

@ -29,4 +29,7 @@ public:
// Daily ticket
QString GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over);
// 24-hour daily ticket
QString Get24HourTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over);
};

View File

@ -15,4 +15,5 @@ public:
double pop_min_price;
int pop_carry_over;
int pop_daily_card_price;
int pop_multi_hour_price;
};

View File

@ -284,3 +284,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
return calcState.set(CalcState::State::SUCCESS);
}
CalcState CALCULATE_LIBRARY_API compute_duration_for_24hour_daily_ticket(parking_tariff_t *tariff, QString const &start_parking_time,uint8_t paymentMethod)
{
CalcState calcState;
QString result = calculator.Get24HourTicketDuration(tariff, start_parking_time, PaymentOption::Option1,false);
qDebug() << "24HourDailyTicket() => " + result;
return calcState.set(CalcState::State::SUCCESS);
}

View File

@ -10,6 +10,7 @@
double total_duration_min = 0.0f;
double total_cost = 0.0f;
bool overtime = false;
int protection_counter = 0;
#ifdef _WIN32
inline struct tm* localtime_r(const time_t *clock, struct tm* result){
@ -19,6 +20,41 @@ inline struct tm* localtime_r(const time_t *clock, struct tm* result){
}
#endif
QString Calculator::Get24HourTicketDuration(Configuration *cfg, QString start_datetime, uint8_t payment_option, bool carry_over)
{
if(start_datetime.isNull() || start_datetime.isEmpty()) return "Invalid date-time";
protection_counter = 0;
double day_price = 0.0f;
int current_special_day_id = -1;
QDateTime inputDateTime = QDateTime::fromString(start_datetime, Qt::ISODate);
QTime worktime_from;
QTime worktime_to;
int daily_24hour_card_price = cfg->PaymentOption.find(payment_option)->second.pop_multi_hour_price;
if(daily_24hour_card_price <= 0) return "24-hour daily ticket: price zero or less";
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toStdString().c_str(), &current_special_day_id, &day_price);
if(is_special_day)
{
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str(), Qt::ISODate);
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str(),Qt::ISODate);
return "24-hour ticket cannot be bought on special day";
}
// Check next special day
inputDateTime = inputDateTime.addSecs(86400);
while(Utilities::CheckSpecialDay(cfg, inputDateTime.toString(Qt::ISODate).toLocal8Bit(), &current_special_day_id, &day_price))
{
protection_counter++;
if(protection_counter >=7) return NULL;
inputDateTime = inputDateTime.addSecs(86400);
}
return inputDateTime.toString(Qt::ISODate) + ", price = " + to_string(daily_24hour_card_price).c_str();
}
QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over)
{
if(start_datetime.isNull() || start_datetime.isEmpty()) return NULL;
@ -113,6 +149,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
bool nextDay,
bool prepaid)
{
// Get input date
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
@ -201,7 +238,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
if (price_per_unit < 0) price_per_unit = 1.0f;
if((price/price_per_unit) < minMin) return "PARKING NOT ALLOWED";
// Commented on 07.06.2023
//if((price/price_per_unit) < minMin)
// return "PARKING NOT ALLOWED";
LOG_DEBUG("Calculated price per minute: ", price_per_unit);
if (price_per_unit < 0)

View File

@ -155,6 +155,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
else if (strcmp(inner_obj_name, "pop_multi_hour_price") == 0) PaymentOption.pop_multi_hour_price = k->value.GetInt();
break;
case MemberType::DurationType:
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();

View File

@ -29,30 +29,32 @@ extern "C" char* strptime(const char* s,
int main() {
parking_tariff_t *tariff = 0;
if (init_tariff(&tariff, "C:\\Users\\MROD\\Documents\\QtCreator\\build-MOBILISIS-Calculator-Desktop_Qt_5_12_12_MSVC2017_32bit-Debug\\main\\etc\\psa_tariff\\zone1.json"))
if (init_tariff(&tariff, "C:\\Users\\MROD\\Documents\\QtCreator\\Old\\build-MOBILISIS-Calculator-Desktop_Qt_5_12_12_MSVC2017_32bit-Debug\\main\\etc\\psa_tariff\\tariff01.json"))
{
struct price_t price;
memset(&price, 0x00, sizeof(price));
QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime();
QDateTime start = QDateTime::fromString("2023-06-02T13:03:00.000Z",Qt::ISODate); //QDateTime::currentDateTime();
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
time_t end_parking_time = start_parking_time + 615;
time_t end_parking_time = start_parking_time + 1230;
if (compute_price_for_parking_ticket(tariff,
start_parking_time,
end_parking_time,
&price))
{
qDebug() << "GetCostFromDuration() => price=" << price.netto;
}
// if (compute_price_for_parking_ticket(tariff,
// start_parking_time,
// end_parking_time,
// &price))
// {
// qDebug() << "GetCostFromDuration() => price=" << price.netto;
// }
QString duration;
if(compute_duration_for_parking_ticket(tariff,start_parking_time,3090,duration))
{
qDebug() << "GetDurationFromCost() => duration=" << duration;
}
// QString duration;
// if(compute_duration_for_parking_ticket(tariff,start_parking_time,1650,duration))
// {
// qDebug() << "GetDurationFromCost() => duration=" << duration;
// }
// Daily ticket
compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
// compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
compute_duration_for_24hour_daily_ticket(tariff,start.toString(Qt::ISODate),3);
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
// // tests

File diff suppressed because one or more lines are too long