Return the flight fares if there are no subfleet fares #488 (#489)

* Return the flight fares if there are no subfleet fares #488

* Formatting

* Formatting
This commit is contained in:
Nabeel S 2020-01-06 13:44:43 -05:00 committed by GitHub
parent 282cb4be95
commit 74052e4542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 28 deletions

View File

@ -34,7 +34,14 @@ class FareService extends Service
$flight_fares = $this->getForFlight($flight);
}
if (empty($subfleet)) {
return $flight_fares;
}
$subfleet_fares = $this->getForSubfleet($subfleet);
if (empty($subfleet_fares) || $subfleet_fares->count() === 0) {
return $flight_fares;
}
// Go through all of the fares assigned by the subfleet
// See if any of the same fares are assigned to the flight
@ -60,7 +67,7 @@ class FareService extends Service
protected function getFares($fare)
{
if (filled($fare->pivot->price)) {
if (substr_count($fare->pivot->price, '%', -1)) {
if (strpos($fare->pivot->price, '%', -1) !== false) {
$fare->price = Math::addPercent($fare->price, $fare->pivot->price);
} else {
$fare->price = $fare->pivot->price;
@ -68,7 +75,7 @@ class FareService extends Service
}
if (filled($fare->pivot->cost)) {
if (substr_count($fare->pivot->cost, '%', -1)) {
if (strpos($fare->pivot->cost, '%', -1) !== false) {
$fare->cost = Math::addPercent($fare->cost, $fare->pivot->cost);
} else {
$fare->cost = $fare->pivot->cost;
@ -76,7 +83,7 @@ class FareService extends Service
}
if (filled($fare->pivot->capacity)) {
if (substr_count($fare->pivot->capacity, '%', -1)) {
if (strpos($fare->pivot->capacity, '%', -1) !== false) {
$fare->capacity = Math::addPercent($fare->capacity, $fare->pivot->capacity);
} else {
$fare->capacity = $fare->pivot->capacity;

View File

@ -177,7 +177,7 @@ class FinanceTest extends TestCase
'capacity' => $percent_200,
]);
$ac_fares = $this->fareSvc->getForFlight($flight);
$ac_fares = $this->fareSvc->getAllFares($flight, null);
$this->assertCount(1, $ac_fares);
$this->assertEquals($new_price, $ac_fares[0]->price);