* Calculate percentage properly instead of adding to the base value #925
This commit is contained in:
@@ -147,7 +147,7 @@ class FareService extends Service
|
||||
{
|
||||
if (filled($pivot->price)) {
|
||||
if (strpos($pivot->price, '%', -1) !== false) {
|
||||
$fare->price = Math::addPercent($fare->price, $pivot->price);
|
||||
$fare->price = Math::getPercent($fare->price, $pivot->price);
|
||||
} else {
|
||||
$fare->price = $pivot->price;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ class FareService extends Service
|
||||
|
||||
if (filled($pivot->cost)) {
|
||||
if (strpos($pivot->cost, '%', -1) !== false) {
|
||||
$fare->cost = Math::addPercent($fare->cost, $pivot->cost);
|
||||
$fare->cost = Math::getPercent($fare->cost, $pivot->cost);
|
||||
} else {
|
||||
$fare->cost = $pivot->cost;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ class FareService extends Service
|
||||
|
||||
if (filled($pivot->capacity)) {
|
||||
if (strpos($pivot->capacity, '%', -1) !== false) {
|
||||
$fare->capacity = floor(Math::addPercent($fare->capacity, $pivot->capacity));
|
||||
$fare->capacity = floor(Math::getPercent($fare->capacity, $pivot->capacity));
|
||||
} else {
|
||||
$fare->capacity = floor($pivot->capacity);
|
||||
}
|
||||
|
||||
@@ -27,18 +27,19 @@ class Math
|
||||
return $override_rate;
|
||||
}
|
||||
|
||||
return static::addPercent($base_rate, $override_rate);
|
||||
// It is a percent, so apply it
|
||||
return static::getPercent($base_rate, $override_rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/subtract a percentage to a number
|
||||
* Apply a percentage to a number
|
||||
*
|
||||
* @param $number
|
||||
* @param $percent
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function addPercent($number, $percent): float
|
||||
public static function getPercent($number, $percent): float
|
||||
{
|
||||
if (!is_numeric($number)) {
|
||||
$number = (float) $number;
|
||||
@@ -48,6 +49,8 @@ class Math
|
||||
$percent = (float) $percent;
|
||||
}
|
||||
|
||||
return $number + ($number * ($percent / 100));
|
||||
$val = $number * ($percent / 100);
|
||||
|
||||
return $val;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user