Merge branch 'moransBranch' of git.mimbach49.de:GerhardHoffmann/MOBILISIS-Calculator into moransBranch
This commit is contained in:
		@@ -177,8 +177,12 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // Set new price for the normal day
 | 
			
		||||
        day_price = cfg->PaymentRate.find(payment_option)->second.pra_price;
 | 
			
		||||
        price_per_unit = Utilities::CalculatePricePerUnit(day_price);
 | 
			
		||||
        int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
 | 
			
		||||
        day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
 | 
			
		||||
 | 
			
		||||
        int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
 | 
			
		||||
        double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
			
		||||
        price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
 | 
			
		||||
 | 
			
		||||
        // If no working day found, skip it (recursively call method again)
 | 
			
		||||
        size_t found = 0;
 | 
			
		||||
@@ -410,8 +414,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // Set new price for the normal day
 | 
			
		||||
        day_price = cfg->PaymentRate.find(payment_option)->second.pra_price;
 | 
			
		||||
        price_per_unit = Utilities::CalculatePricePerUnit(day_price);
 | 
			
		||||
 | 
			
		||||
        int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
 | 
			
		||||
        day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
 | 
			
		||||
 | 
			
		||||
        int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
 | 
			
		||||
        double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
			
		||||
        price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
 | 
			
		||||
 | 
			
		||||
        // If no working day found, skip it (recursively call method again)
 | 
			
		||||
        size_t found = 0;
 | 
			
		||||
@@ -506,11 +515,12 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
 | 
			
		||||
            return 0.0f;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int carry_over_status = 0;
 | 
			
		||||
        carry_over_status = cfg->PaymentOption.find(payment_option)->second.pop_carry_over;
 | 
			
		||||
 | 
			
		||||
        // Go to next day if minutes not spent
 | 
			
		||||
        if(inputDate.time() >= worktime_to)
 | 
			
		||||
        {
 | 
			
		||||
            int carry_over_status = 0;
 | 
			
		||||
            carry_over_status = cfg->PaymentOption.find(payment_option)->second.pop_carry_over;
 | 
			
		||||
            if (carry_over_status < 1) break;
 | 
			
		||||
 | 
			
		||||
            LOG_DEBUG("Reached end of worktime, searching for the next working day");
 | 
			
		||||
 
 | 
			
		||||
@@ -210,7 +210,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
					cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
 | 
			
		||||
					break;
 | 
			
		||||
				case MemberType::PaymentRateType:
 | 
			
		||||
					cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_unit_id, PaymentRate));
 | 
			
		||||
                    cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_option_id, PaymentRate));
 | 
			
		||||
					break;
 | 
			
		||||
				case MemberType::PaymentOptionType:
 | 
			
		||||
					cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
 | 
			
		||||
 
 | 
			
		||||
@@ -8,12 +8,15 @@ static int protection_counter = 0;
 | 
			
		||||
/// </summary>
 | 
			
		||||
/// <param name="pra_price"></param>
 | 
			
		||||
/// <returns></returns>
 | 
			
		||||
double Utilities::CalculatePricePerUnit(double pra_price)
 | 
			
		||||
double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit)
 | 
			
		||||
{
 | 
			
		||||
	try
 | 
			
		||||
	{
 | 
			
		||||
		double price_per_unit = pra_price;
 | 
			
		||||
		price_per_unit /= 60.0f; // Divided by 60 because price per unit is set per hour and we are using minutes
 | 
			
		||||
        double unit = durationUnit;
 | 
			
		||||
 | 
			
		||||
        if(unit < 0 || unit > 65535 ) unit = 60.0f;
 | 
			
		||||
        price_per_unit /= unit; // Divided by 60 because price per unit is set per hour and we are using minutes
 | 
			
		||||
		//printf("Price per unit (min) is: %lf\n", price_per_unit);
 | 
			
		||||
		return price_per_unit;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user