Calculator::GetDurationFromCost():
Compute duration from cost for PaymentMethod::Degressive: introduced for Valser Alm (location: Fane).
This commit is contained in:
		@@ -130,15 +130,94 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
    Q_UNUSED(nextDay);
 | 
			
		||||
 | 
			
		||||
    // Get input date
 | 
			
		||||
    QDateTime inputDate = QDateTime::fromString(startDatetimePassed,Qt::ISODate);
 | 
			
		||||
    QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate);
 | 
			
		||||
    inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << "          start" << inputDate.toString(Qt::ISODate);
 | 
			
		||||
    qCritical() << DBG_HEADER << "paymentMethodId" << static_cast<int>(paymentMethodId);
 | 
			
		||||
    qCritical() << DBG_HEADER << "          start:" << inputDate.toString(Qt::ISODate);
 | 
			
		||||
    qCritical() << DBG_HEADER << "   option index:" << paymentOptionIndex;
 | 
			
		||||
    qCritical() << DBG_HEADER << "paymentMethodId:" << static_cast<int>(paymentMethodId);
 | 
			
		||||
    qCritical() << DBG_HEADER << "        prepaid:" << prepaid;
 | 
			
		||||
    qCritical() << DBG_HEADER << "   cost (price):" << cost;
 | 
			
		||||
 | 
			
		||||
    Calculator::GetInstance().GetTimeSteps(cfg, 0, inputDate);
 | 
			
		||||
    QList<int> tsteps = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, inputDate);
 | 
			
		||||
    qCritical() << DBG_HEADER << "     time steps:" << tsteps;
 | 
			
		||||
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Degressive) {
 | 
			
		||||
        if (prepaid == false) {
 | 
			
		||||
            int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
 | 
			
		||||
            int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
 | 
			
		||||
            int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
 | 
			
		||||
 | 
			
		||||
            // qCritical() << DBG_HEADER << "   pop id:" << pop_id;
 | 
			
		||||
 | 
			
		||||
            int price = 0;
 | 
			
		||||
            int new_price = 0;
 | 
			
		||||
            int durationInMinutes = 0;
 | 
			
		||||
            uint32_t duration_previous = 0;
 | 
			
		||||
            // bool found = false;
 | 
			
		||||
 | 
			
		||||
            for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
 | 
			
		||||
                int const pra_price = itr->second.pra_price;
 | 
			
		||||
                int const durationId = itr->second.pra_payment_unit_id;
 | 
			
		||||
                if (pop_accumulate_prices) {
 | 
			
		||||
                    price += pra_price;
 | 
			
		||||
                } else {
 | 
			
		||||
                    price = pra_price;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                //qCritical() << DBG_HEADER << "  PRICE" << price << "COST" << cost;
 | 
			
		||||
                //qCritical() << DBG_HEADER << "  duration id" << durationId;
 | 
			
		||||
 | 
			
		||||
                auto search = cfg->Duration.find(durationId);
 | 
			
		||||
                if (search != cfg->Duration.end()) {
 | 
			
		||||
                    // found now the duration in minutes
 | 
			
		||||
                    // check if we are still inside the working-time-range
 | 
			
		||||
                    ATBDuration duration = search->second;
 | 
			
		||||
 | 
			
		||||
                    if (pop_accumulate_prices) {
 | 
			
		||||
                        uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
			
		||||
 | 
			
		||||
                        new_price += pra_price;
 | 
			
		||||
                        // qCritical() << "(" << __func__ << ":" << __LINE__ << ")  old price" << price << ", new_price:" << new_price;
 | 
			
		||||
                        if (new_price <= cost) {
 | 
			
		||||
                            duration_previous = durationUnit;
 | 
			
		||||
                            if (pop_accumulate_durations) {
 | 
			
		||||
                                durationInMinutes += durationUnit;
 | 
			
		||||
                            }
 | 
			
		||||
                            //qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
 | 
			
		||||
                            //qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
 | 
			
		||||
                            //qCritical() << "(" << __func__ << ":" << __LINE__ << ")  old price" << price << ", new_price:" << new_price;
 | 
			
		||||
                        } else {
 | 
			
		||||
                            //found = true;
 | 
			
		||||
                            //qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
 | 
			
		||||
                            //qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
 | 
			
		||||
                            QString s = inputDate.toString(Qt::ISODate);
 | 
			
		||||
                            QDateTime d(QDateTime::fromString(s, Qt::ISODate));
 | 
			
		||||
                            d = d.addSecs(duration_previous * 60);
 | 
			
		||||
                            //qCritical() << DBG_HEADER << "XXXX" << d;
 | 
			
		||||
                            return d.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if ((double)price == cost) {
 | 
			
		||||
                        //qCritical() << DBG_HEADER << "price" << price << "cost" << cost;
 | 
			
		||||
                        //qCritical() << DBG_HEADER << "duration in minutes" << durationInMinutes;
 | 
			
		||||
 | 
			
		||||
                        QString s = inputDate.toString(Qt::ISODate);
 | 
			
		||||
                        QDateTime d(QDateTime::fromString(s, Qt::ISODate));
 | 
			
		||||
                        d = d.addSecs(durationInMinutes * 60);
 | 
			
		||||
                        //qCritical() << DBG_HEADER << "YYYY" << d;
 | 
			
		||||
                        return d.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } else {
 | 
			
		||||
            qCritical() << DBG_HEADER << "   TODO";
 | 
			
		||||
        }
 | 
			
		||||
    } else
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        if (tariffIs24_7(cfg)) {
 | 
			
		||||
            // use tariff with structure as for instance Schoenau, Koenigsee:
 | 
			
		||||
@@ -155,8 +234,6 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                int paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
 | 
			
		||||
                int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
 | 
			
		||||
                int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
 | 
			
		||||
                int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user