Account for fuel in the finance calculations #313
This commit is contained in:
@@ -11,7 +11,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laracasts\Flash\Flash;
|
||||
use SebastianBergmann\Version;
|
||||
use PragmaRX\Version\Package\Facade as Version;
|
||||
use vierbergenlars\SemVer\version as semver;
|
||||
|
||||
class DashboardController extends Controller
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Fuel;
|
||||
|
||||
class Acars extends Response
|
||||
{
|
||||
/**
|
||||
@@ -9,16 +12,25 @@ class Acars extends Response
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
||||
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$res = parent::toArray($request);
|
||||
|
||||
$this->checkUnitFields($res, [
|
||||
'distance',
|
||||
'fuel',
|
||||
]);
|
||||
// Set these to the response units
|
||||
if (!empty($res['distance'])) {
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
}
|
||||
|
||||
if (!empty($res['fuel'])) {
|
||||
$fuel = new Fuel($res['fuel'], config('phpvms.internal_units.fuel'));
|
||||
$res['fuel'] = $fuel->getResponseUnits();
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Support\Units\Distance;
|
||||
|
||||
class Flight extends Response
|
||||
{
|
||||
/**
|
||||
@@ -19,16 +21,24 @@ class Flight extends Response
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
||||
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$res = parent::toArray($request);
|
||||
|
||||
$res['ident'] = $this->ident;
|
||||
|
||||
// Return multiple measures so the client can pick what they want
|
||||
$this->checkUnitFields($res, [
|
||||
'distance',
|
||||
]);
|
||||
if (!empty($res['distance'])) {
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
}
|
||||
|
||||
$res['airline'] = new Airline($this->airline);
|
||||
$res['subfleets'] = Subfleet::collection($this->subfleets);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Enums\PirepStatus;
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Fuel;
|
||||
|
||||
class Pirep extends Response
|
||||
{
|
||||
@@ -11,6 +13,9 @@ class Pirep extends Response
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
||||
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
@@ -18,11 +23,21 @@ class Pirep extends Response
|
||||
$res = parent::toArray($request);
|
||||
$res['ident'] = $this->ident;
|
||||
|
||||
$this->checkUnitFields($res, [
|
||||
'distance',
|
||||
'fuel_used',
|
||||
'planned_distance',
|
||||
]);
|
||||
// Set these to the response units
|
||||
if (!empty($res['distance'])) {
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
}
|
||||
|
||||
if (!empty($res['fuel_used'])) {
|
||||
$fuel_used = new Fuel($res['fuel_used'], config('phpvms.internal_units.fuel'));
|
||||
$res['fuel_used'] = $fuel_used->getResponseUnits();
|
||||
}
|
||||
|
||||
if (!empty($res['planned_distance'])) {
|
||||
$planned_dist = new Distance($res['planned_distance'], config('phpvms.internal_units.distance'));
|
||||
$res['planned_distance'] = $planned_dist->getResponseUnits();
|
||||
}
|
||||
|
||||
/*
|
||||
* Relationship fields
|
||||
|
||||
Reference in New Issue
Block a user