Skip to content

Commit

Permalink
Return the flight fares if there are no subfleet fares #488 (#489)
Browse files Browse the repository at this point in the history
* Return the flight fares if there are no subfleet fares #488

* Formatting

* Formatting
  • Loading branch information
nabeelio authored Jan 6, 2020
1 parent 282cb4b commit 74052e4
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/Http/Middleware/MeasureExecutionTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function handle(Request $request, Closure $next)
// I assume you're using valid json in your responses
// Then I manipulate them below
$content = json_decode($response->getContent(), true) + [
'execution_time' => $executionTime,
];
'execution_time' => $executionTime,
];

// Change the content of your response
$response->setData($content);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getExtensionAttribute(): string
*
* @return string
*/
public function getFilenameAttribute() :string
public function getFilenameAttribute(): string
{
if (!$this->pathinfo) {
$this->pathinfo = pathinfo($this->path);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function getAvatarAttribute()
}

return new File([
'path' => $this->attributes['avatar'],
'path' => $this->attributes['avatar'],
]);
}

Expand Down
13 changes: 10 additions & 3 deletions app/Services/FareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ public function getAllFares($flight, $subfleet)
$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
Expand All @@ -60,23 +67,23 @@ public function getAllFares($flight, $subfleet)
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;
}
}

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;
}
}

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;
Expand Down
6 changes: 3 additions & 3 deletions app/Services/PirepService.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ public function updateCustomFields($pirep_id, array $field_values)
foreach ($field_values as $fv) {
PirepFieldValue::updateOrCreate(
['pirep_id' => $pirep_id,
'name' => $fv['name'],
'name' => $fv['name'],
],
['value' => $fv['value'],
'source' => $fv['source'],
['value' => $fv['value'],
'source' => $fv['source'],
]
);
}
Expand Down
6 changes: 3 additions & 3 deletions modules/Importer/Services/Importers/RankImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function run($start = 0)
$count = 0;
foreach ($this->db->readRows($this->table, $start) as $row) {
$rank = Rank::firstOrCreate(['name' => $row->rank], [
'image_url' => $row->rankimage,
'hours' => $row->minhours,
]);
'image_url' => $row->rankimage,
'hours' => $row->minhours,
]);

$this->idMapper->addMapping('ranks', $row->rankid, $rank->id);
$this->idMapper->addMapping('ranks', $row->rank, $rank->id);
Expand Down
2 changes: 1 addition & 1 deletion modules/Importer/Utils/ImporterDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($creds)
'host='.$this->creds['host'],
'port='.$this->creds['port'],
'dbname='.$this->creds['name'],
]);
]);

Log::info('Using DSN: '.$this->dsn);

Expand Down
22 changes: 11 additions & 11 deletions modules/Updater/Providers/UpdateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public function boot()
protected function registerRoutes()
{
Route::group([
'as' => 'update.',
'prefix' => 'update',
'middleware' => ['auth', 'ability:admin,admin-access', 'web'],
'namespace' => 'Modules\Updater\Http\Controllers',
], function () {
Route::get('/', 'UpdateController@index')->name('index');
'as' => 'update.',
'prefix' => 'update',
'middleware' => ['auth', 'ability:admin,admin-access', 'web'],
'namespace' => 'Modules\Updater\Http\Controllers',
], function () {
Route::get('/', 'UpdateController@index')->name('index');

Route::get('/step1', 'UpdateController@step1')->name('step1');
Route::post('/step1', 'UpdateController@step1')->name('step1');
Route::get('/step1', 'UpdateController@step1')->name('step1');
Route::post('/step1', 'UpdateController@step1')->name('step1');

Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations');
Route::get('/complete', 'UpdateController@complete')->name('complete');
});
Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations');
Route::get('/complete', 'UpdateController@complete')->name('complete');
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/FinanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testFlightFareOverrideAsPercent()
'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);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
/**
* @throws Exception
*/
public function setUp() : void
public function setUp(): void
{
parent::setUp();

Expand All @@ -52,7 +52,7 @@ public function setUp() : void
Artisan::call('migrate:refresh', ['--env' => 'testing']);
}

public function tearDown() : void
public function tearDown(): void
{
parent::tearDown();
}
Expand Down

0 comments on commit 74052e4

Please sign in to comment.