Merge remote-tracking branch 'origin/schoenau_23112023'
This commit is contained in:
		@@ -118,6 +118,15 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                            bool nextDay,
 | 
			
		||||
                                            bool prepaid)
 | 
			
		||||
{
 | 
			
		||||
    // use tariff with structure as for instance Schnau, Koenigsee:
 | 
			
		||||
    // without given YearPeriod, SpecialDays and SpecialDaysWorktime
 | 
			
		||||
    if (cfg->YearPeriod.size() == 0
 | 
			
		||||
        && cfg->SpecialDays.size() == 0
 | 
			
		||||
        && cfg->SpecialDaysWorktime.size() == 0)
 | 
			
		||||
    {
 | 
			
		||||
        return QString().setNum(GetDurationForPrice(cfg, price)).toStdString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Get input date
 | 
			
		||||
    QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
@@ -341,30 +350,28 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
/// <inheritdoc/>
 | 
			
		||||
///
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
 | 
			
		||||
                                         QDateTime const &start,
 | 
			
		||||
                                         quint64 timeStepInMinutes,
 | 
			
		||||
                                         uint8_t paymentMethod) {
 | 
			
		||||
                                         quint64 timeStepInMinutes) const {
 | 
			
		||||
    // for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
 | 
			
		||||
    // special days, nonstop.
 | 
			
		||||
    if (paymentMethod == PaymentMethod::Steps
 | 
			
		||||
    if (cfg->YearPeriod.size() == 0
 | 
			
		||||
     && cfg->SpecialDays.size() == 0
 | 
			
		||||
     && cfg->SpecialDaysWorktime.size() == 0) {
 | 
			
		||||
        QDateTime const end = start.addSecs(timeStepInMinutes*60);
 | 
			
		||||
        return GetCostFromDuration(cfg, start, end, paymentMethod);
 | 
			
		||||
        return GetCostFromDuration(cfg, start, end);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
 | 
			
		||||
                                         QDateTime const &start,
 | 
			
		||||
                                         QDateTime const &end,
 | 
			
		||||
                                         uint8_t paymentMethod) {
 | 
			
		||||
    if (paymentMethod == PaymentMethod::Steps
 | 
			
		||||
                                         QDateTime const &end) const {
 | 
			
		||||
    if (cfg->YearPeriod.size() == 0
 | 
			
		||||
     && cfg->SpecialDays.size() == 0
 | 
			
		||||
     && cfg->SpecialDaysWorktime.size() == 0) {
 | 
			
		||||
        int const timeStepInMinutes = start.secsTo(end) / 60;
 | 
			
		||||
        return GetPriceForTimeStep(cfg, paymentMethod, timeStepInMinutes);
 | 
			
		||||
        return GetPriceForTimeStep(cfg, timeStepInMinutes);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -377,12 +384,12 @@ uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
/// <inheritdoc/>
 | 
			
		||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime,  double durationMin, bool nextDay, bool prepaid)
 | 
			
		||||
{
 | 
			
		||||
    // condition for 'PaymentMethod::Steps' (e.g. 332/Schoenau):
 | 
			
		||||
    if (cfg->SpecialDays.size() == 0
 | 
			
		||||
    if (cfg->YearPeriod.size() == 0
 | 
			
		||||
        && cfg->SpecialDays.size() == 0
 | 
			
		||||
        && cfg->SpecialDaysWorktime.size() == 0)
 | 
			
		||||
    {
 | 
			
		||||
        end_datetime = start_datetime.addSecs(durationMin*60);
 | 
			
		||||
        return GetCostFromDuration(cfg, start_datetime, end_datetime, PaymentMethod::Steps);
 | 
			
		||||
        return GetCostFromDuration(cfg, start_datetime, end_datetime);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Get input date
 | 
			
		||||
@@ -588,10 +595,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption) {
 | 
			
		||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
 | 
			
		||||
    QList<int> timeSteps;
 | 
			
		||||
 | 
			
		||||
    int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions().pop_id;
 | 
			
		||||
 | 
			
		||||
    for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
 | 
			
		||||
    {
 | 
			
		||||
@@ -603,9 +610,9 @@ QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption)
 | 
			
		||||
    return timeSteps;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentOption, int timeStep) {
 | 
			
		||||
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
 | 
			
		||||
 | 
			
		||||
    int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions().pop_id;
 | 
			
		||||
 | 
			
		||||
    for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
 | 
			
		||||
    {
 | 
			
		||||
@@ -616,7 +623,25 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t payme
 | 
			
		||||
 | 
			
		||||
        int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
 | 
			
		||||
        if (timeStep == pun_duration) {
 | 
			
		||||
                return (uint32_t)(itr->second.pra_price);
 | 
			
		||||
            return (uint32_t)(itr->second.pra_price);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions().pop_id;
 | 
			
		||||
 | 
			
		||||
    for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
 | 
			
		||||
    {
 | 
			
		||||
        int const payment_unit_id = itr->second.pra_payment_unit_id;
 | 
			
		||||
        int const pra_price = cfg->PaymentRate.find(payment_unit_id)->second.pra_price;
 | 
			
		||||
 | 
			
		||||
        if (price == pra_price) {
 | 
			
		||||
            int const durationId = itr->second.pra_payment_unit_id;
 | 
			
		||||
            int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
			
		||||
            return durationUnit;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user