diff --git a/app/Console/Commands/YamlExport.php b/app/Console/Commands/YamlExport.php index 19775c92..27f9fffa 100644 --- a/app/Console/Commands/YamlExport.php +++ b/app/Console/Commands/YamlExport.php @@ -3,7 +3,6 @@ namespace App\Console\Commands; use App\Console\Command; -use App\Services\DatabaseService; use DB; use Symfony\Component\Yaml\Yaml; @@ -15,12 +14,7 @@ class YamlExport extends Command protected $signature = 'phpvms:yaml-export {tables*}'; protected $description = 'YAML table export'; - /** - * YamlExport constructor. - * - * @param DatabaseService $dbSvc - */ - public function __construct(DatabaseService $dbSvc) + public function __construct() { parent::__construct(); } diff --git a/app/Database/factories/AirportFactory.php b/app/Database/factories/AirportFactory.php index 77ff3485..90d2baf0 100644 --- a/app/Database/factories/AirportFactory.php +++ b/app/Database/factories/AirportFactory.php @@ -48,8 +48,8 @@ $factory->define(App\Models\Airport::class, function (Faker $faker) { 'lon' => $faker->longitude, 'hub' => false, 'ground_handling_cost' => $faker->randomFloat(2, 0, 500), - 'fuel_100ll_cost' => $faker->randomFloat(2, 0, 100), - 'fuel_jeta_cost' => $faker->randomFloat(2, 0, 100), - 'fuel_mogas_cost' => $faker->randomFloat(2, 0, 100), + 'fuel_100ll_cost' => $faker->randomFloat(2, 1, 10), + 'fuel_jeta_cost' => $faker->randomFloat(2, 1, 10), + 'fuel_mogas_cost' => $faker->randomFloat(2, 1, 10), ]; }); diff --git a/app/Database/factories/FlightFactory.php b/app/Database/factories/FlightFactory.php index 412c30df..d6d0cac7 100644 --- a/app/Database/factories/FlightFactory.php +++ b/app/Database/factories/FlightFactory.php @@ -22,7 +22,7 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) { 'alt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'distance' => $faker->numberBetween(0, 1000), + 'distance' => $faker->numberBetween(1, 1000), 'route' => null, 'level' => 0, 'dpt_time' => $faker->time(), diff --git a/app/Database/factories/PirepFactory.php b/app/Database/factories/PirepFactory.php index e08aeb82..00de39fb 100644 --- a/app/Database/factories/PirepFactory.php +++ b/app/Database/factories/PirepFactory.php @@ -37,8 +37,10 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) { 'flight_time' => $faker->numberBetween(60, 360), 'planned_flight_time' => $faker->numberBetween(60, 360), 'zfw' => $faker->randomFloat(2), - 'block_fuel' => $faker->randomFloat(2, 0, 30000), - 'fuel_used' => $faker->randomFloat(2, 0, 30000), + 'block_fuel' => $faker->randomFloat(2, 0, 1000), + 'fuel_used' => function (array $pirep) { + return round($pirep['block_fuel'] * .9, 2); // 90% of the fuel loaded was used + }, 'block_on_time' => Carbon::now('UTC'), 'block_off_time' => function (array $pirep) { return $pirep['block_on_time']->subMinutes($pirep['flight_time']); diff --git a/app/Database/seeds/acars.yml b/app/Database/seeds/acars.yml index 2693a232..16c0ce53 100644 --- a/app/Database/seeds/acars.yml +++ b/app/Database/seeds/acars.yml @@ -1,5 +1,6 @@ acars: - - pirep_id: pirepid_1 + - id: acars_1 + pirep_id: pirepid_1 type: 1 nav_type: 2 name: TNV @@ -7,7 +8,8 @@ acars: lon: -96.058239 created_at: now updated_at: now - - pirep_id: pirepid_1 + - id: acars_2 + pirep_id: pirepid_1 type: 1 nav_type: 2 name: IAH @@ -15,7 +17,8 @@ acars: lon: -95.345719 created_at: now updated_at: now - - pirep_id: pirepid_1 + - id: acars_3 + pirep_id: pirepid_1 type: 1 nav_type: 2 name: LCH @@ -23,7 +26,8 @@ acars: lon: -93.105569 created_at: now updated_at: now - - pirep_id: pirepid_1 + - id: acars_4 + pirep_id: pirepid_1 type: 1 nav_type: 2 name: MEI @@ -31,7 +35,8 @@ acars: lon: -88.804267 created_at: now updated_at: now - - pirep_id: pirepid_1 + - id: acars_5 + pirep_id: pirepid_1 type: 1 nav_type: 2 name: ATL @@ -39,7 +44,8 @@ acars: lon: -84.435064 created_at: now updated_at: now - - pirep_id: pirepid_1 + - id: acars_6 + pirep_id: pirepid_1 type: 1 nav_type: 2 name: SIE diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev.yml index 0c3cca14..23f16fd5 100644 --- a/app/Database/seeds/dev.yml +++ b/app/Database/seeds/dev.yml @@ -3,14 +3,4 @@ # want to modify or erase any of this here # -airports: - - id: KAUS - iata: AUS - icao: KAUS - name: Austin-Bergstrom - location: Austin, Texas, USA - country: United States - timezone: America/Chicago - lat: 30.1945278 - lon: -97.6698889 - hub: 1 + diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index cf67a87a..e3dfd412 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -452,15 +452,17 @@ pireps: block_off_time: 2018-04-04T12:42:36+00:00 block_on_time: 2018-04-04T16:42:36+00:00 flight_time: 180 # 6 hours + block_fuel: 20000 + fuel_used: 10000 state: 1 # accepted status: 0 source: 1 flight_type: J route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK notes: just a pilot report - submitted_at: 2018-04-04T16:50:36+00:00 - created_at: 2018-04-04T16:50:36+00:00 - updated_at: 2018-04-04T17:00:36+00:00 + submitted_at: NOW + created_at: NOW + updated_at: NOW - id: pirepid_2 user_id: 1 airline_id: 1 @@ -469,6 +471,8 @@ pireps: dpt_airport_id: KJFK arr_airport_id: KAUS flight_time: 180 # 6 hours + block_fuel: 20000 + fuel_used: 15000 state: 5 # draft source: 0 # manual flight_type: J @@ -494,7 +498,7 @@ pireps: planned_flight_time: '0' zfw: null block_fuel: '21500.25390625' - fuel_used: null + fuel_used: 20000 landing_rate: '0' score: '0' route: '' @@ -503,11 +507,11 @@ pireps: source_name: vmsacars state: 0 status: ENR - submitted_at: null block_off_time: now block_on_time: null - created_at: now - updated_at: now + submitted_at: NOW + created_at: NOW + updated_at: NOW - id: pirepid_4 user_id: 1 airline_id: 1 @@ -517,6 +521,8 @@ pireps: arr_airport_id: KAUS block_off_time: 2018-04-04T12:42:36+00:00 block_on_time: 2018-04-04T16:42:36+00:00 + block_fuel: 100000 + fuel_used: 20000 flight_time: 180 # 6 hours state: 0 status: 0 @@ -524,9 +530,9 @@ pireps: flight_type: J route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK notes: just a pilot report - submitted_at: 2018-04-04T16:50:36+00:00 - created_at: 2018-04-04T16:50:36+00:00 - updated_at: 2018-04-04T17:00:36+00:00 + submitted_at: NOW + created_at: NOW + updated_at: NOW pirep_fares: - id: 1 diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index bbaeac02..52da4884 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -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 diff --git a/app/Http/Resources/Acars.php b/app/Http/Resources/Acars.php index 905d0888..1a199c89 100644 --- a/app/Http/Resources/Acars.php +++ b/app/Http/Resources/Acars.php @@ -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; } diff --git a/app/Http/Resources/Flight.php b/app/Http/Resources/Flight.php index c058f633..aaeba142 100644 --- a/app/Http/Resources/Flight.php +++ b/app/Http/Resources/Flight.php @@ -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); diff --git a/app/Http/Resources/Pirep.php b/app/Http/Resources/Pirep.php index f2d03e9d..2d14c62d 100644 --- a/app/Http/Resources/Pirep.php +++ b/app/Http/Resources/Pirep.php @@ -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 diff --git a/app/Models/Acars.php b/app/Models/Acars.php index cc68cbb0..c7c563fa 100644 --- a/app/Models/Acars.php +++ b/app/Models/Acars.php @@ -85,7 +85,7 @@ class Acars extends Model * * @return int|Distance */ - public function getDistanceAttribute() + /*public function getDistanceAttribute() { if (!array_key_exists('distance', $this->attributes)) { return 0; @@ -103,7 +103,7 @@ class Acars extends Model } catch (NonStringUnitName $e) { return 0; } - } + }*/ /** * Set the distance unit, convert to our internal default unit @@ -126,7 +126,7 @@ class Acars extends Model * * @return int|Fuel */ - public function getFuelAttribute() + /*public function getFuelAttribute() { if (!array_key_exists('fuel', $this->attributes)) { return 0; @@ -140,7 +140,7 @@ class Acars extends Model } catch (NonStringUnitName $e) { return 0; } - } + }*/ /** * Set the amount of fuel diff --git a/app/Models/Airport.php b/app/Models/Airport.php index 04111aea..000dc494 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -17,6 +17,9 @@ use App\Models\Traits\FilesTrait; * @property string country * @property string timezone * @property float ground_handling_cost + * @property float fuel_100ll_cost + * @property float fuel_jeta_cost + * @property float fuel_mogas_cost * @property float lat * @property float lon */ @@ -67,6 +70,9 @@ class Airport extends Model 'lat' => 'required|numeric', 'lon' => 'required|numeric', 'ground_handling_cost' => 'nullable|numeric', + 'fuel_100ll_cost' => 'nullable|numeric', + 'fuel_jeta_cost' => 'nullable|numeric', + 'fuel_mogas_cost' => 'nullable|numeric', ]; /** diff --git a/app/Models/Flight.php b/app/Models/Flight.php index 390a6224..75100e36 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -137,7 +137,7 @@ class Flight extends Model * * @return Distance */ - public function getDistanceAttribute() + /*public function getDistanceAttribute() { if (!array_key_exists('distance', $this->attributes)) { return 0; @@ -152,7 +152,7 @@ class Flight extends Model } catch (NonStringUnitName $e) { return new Distance(0, config('phpvms.internal_units.distance', 'nmi')); } - } + }*/ /** * Set the distance unit, convert to our internal default unit diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index d9d228a7..684b7777 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -35,6 +35,8 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName; * @property int block_time * @property int flight_time In minutes * @property int planned_flight_time + * @property float block_fuel + * @property float fuel_used * @property float distance * @property float planned_distance * @property string route @@ -124,6 +126,8 @@ class Pirep extends Model 'flight_number' => 'required', 'dpt_airport_id' => 'required', 'arr_airport_id' => 'required', + 'block_fuel' => 'required|numeric', + 'fuel_used' => 'required|numeric', 'notes' => 'nullable', 'route' => 'nullable', ]; @@ -132,7 +136,6 @@ class Pirep extends Model * If a PIREP is in these states, then it can't be changed. */ public static $read_only_states = [ - //PirepState::PENDING, PirepState::ACCEPTED, PirepState::REJECTED, PirepState::CANCELLED, @@ -200,7 +203,7 @@ class Pirep extends Model * * @return int|Distance */ - public function getDistanceAttribute() + /*public function getDistanceAttribute() { if (!array_key_exists('distance', $this->attributes)) { return 0; @@ -218,7 +221,7 @@ class Pirep extends Model } catch (NonStringUnitName $e) { return 0; } - } + }*/ /** * Set the distance unit, convert to our internal default unit @@ -249,7 +252,7 @@ class Pirep extends Model * * @return int|Fuel */ - public function getFuelUsedAttribute() + /*public function getFuelUsedAttribute() { if (!array_key_exists('fuel_used', $this->attributes)) { return 0; @@ -264,14 +267,14 @@ class Pirep extends Model } catch (NonStringUnitName $e) { return 0; } - } + }*/ /** * Return the planned_distance in a converter class * * @return int|Distance */ - public function getPlannedDistanceAttribute() + /*public function getPlannedDistanceAttribute() { if (!array_key_exists('planned_distance', $this->attributes)) { return 0; @@ -289,7 +292,7 @@ class Pirep extends Model } catch (NonStringUnitName $e) { return 0; } - } + }*/ /** * Return the flight progress in a percent. diff --git a/app/Repositories/JournalRepository.php b/app/Repositories/JournalRepository.php index a64b77f1..18f5308d 100644 --- a/app/Repositories/JournalRepository.php +++ b/app/Repositories/JournalRepository.php @@ -80,8 +80,8 @@ class JournalRepository extends Repository implements CacheableInterface * @param Model|null $reference The object this is a reference to * @param string|null $memo Memo for this transaction * @param string|null $post_date Date of the posting - * @param string|null $transaction_group - * @param array|string|null $tags + * @param string|null $transaction_group Grouping name for the summaries + * @param array|string|null $tags Tag used for grouping/finding items * * @throws ValidatorException * diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index bd0a68a1..a34985d3 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -13,7 +13,7 @@ use App\Repositories\JournalRepository; use App\Services\FareService; use App\Support\Math; use App\Support\Money; -use Log; +use Illuminate\Support\Facades\Log; /** * Class FinanceService @@ -70,6 +70,7 @@ class PirepFinanceService extends Service Log::info('Finance: Starting PIREP pay for '.$pirep->id); // Now start and pay from scratch + $this->payFuelCosts($pirep); $this->payFaresForPirep($pirep); $this->payExpensesForSubfleet($pirep); $this->payExpensesForPirep($pirep); @@ -132,6 +133,34 @@ class PirepFinanceService extends Service } } + /** + * Calculate the fuel used by the PIREP and add those costs in + * + * @param Pirep $pirep + * + * @throws \Prettus\Validator\Exceptions\ValidatorException + */ + public function payFuelCosts(Pirep $pirep): void + { + $ap = $pirep->dpt_airport; + $fuel_used = $pirep->block_fuel; + + $debit = Money::createFromAmount($fuel_used * $ap->fuel_jeta_cost); + Log::info('Finance: Fuel cost, (fuel='.$fuel_used.', cost='.$ap->fuel_jeta_cost.') D=' + .$debit->getAmount()); + + $this->journalRepo->post( + $pirep->airline->journal, + null, + $debit, + $pirep, + 'Fuel Cost ('.$ap->fuel_jeta_cost.'/'.config('phpvms.internal_units.fuel').')', + null, + 'Fuel', + 'fuel' + ); + } + /** * Calculate what the cost is for the operating an aircraft * in this subfleet, as-per the block time diff --git a/app/Services/ImportExport/FlightExporter.php b/app/Services/ImportExport/FlightExporter.php index bffbb3f3..0bb6ad29 100644 --- a/app/Services/ImportExport/FlightExporter.php +++ b/app/Services/ImportExport/FlightExporter.php @@ -37,7 +37,7 @@ class FlightExporter extends ImportExport // Modify special fields $ret['airline'] = $ret['airline']->icao; - $ret['distance'] = $ret['distance'][config('phpvms.internal_units.distance')]; + // $ret['distance'] = $ret['distance'][config('phpvms.internal_units.distance')]; $ret['dpt_airport'] = $flight->dpt_airport_id; $ret['arr_airport'] = $flight->arr_airport_id; diff --git a/app/Services/Installer/MigrationService.php b/app/Services/Installer/MigrationService.php index bbcc5216..d48adfe8 100644 --- a/app/Services/Installer/MigrationService.php +++ b/app/Services/Installer/MigrationService.php @@ -28,6 +28,7 @@ class MigrationService extends Service public function syncAllSeeds(): void { $this->syncAllSettings(); + $this->syncAllPermissions(); } public function syncAllSettings(): void @@ -43,6 +44,22 @@ class MigrationService extends Service } } + public function syncAllPermissions(): void + { + $data = file_get_contents(database_path('/seeds/permissions.yml')); + $yml = Yaml::parse($data); + foreach ($yml as $perm) { + $count = DB::table('permissions')->where('name', $perm['name'])->count('name'); + if ($count === 0) { + DB::table('permissions')->insert($perm); + } else { + DB::table('settings') + ->where('name', $perm['name']) + ->update($perm); + } + } + } + /** * @param $key * @param $attrs diff --git a/app/Support/Database.php b/app/Support/Database.php index 42bde6fc..3c85d326 100644 --- a/app/Support/Database.php +++ b/app/Support/Database.php @@ -44,6 +44,10 @@ class Database { $imported = []; $yml = Yaml::parse($yml); + if (empty($yml)) { + return $imported; + } + foreach ($yml as $table => $rows) { $imported[$table] = 0; @@ -80,6 +84,10 @@ class Database $row['password'] = bcrypt($row['password']); } + if (empty($row)) { + return $row; + } + // if any time fields are == to "now", then insert the right time foreach ($row as $column => $value) { if (strtolower($value) === 'now') { @@ -91,6 +99,7 @@ class Database DB::table($table)->insert($row); } catch (QueryException $e) { Log::error($e); + dd($row); throw $e; } diff --git a/resources/lang/en/pireps.php b/resources/lang/en/pireps.php index 0c8ca87a..3d56b983 100644 --- a/resources/lang/en/pireps.php +++ b/resources/lang/en/pireps.php @@ -21,6 +21,7 @@ return [ 'fieldsreadonly' => 'Once a PIREP has been submitted, certain fields go into read-only mode.', 'flightinformations' => 'Flight Information', 'flightident' => 'Flight Number/Code/Leg', + 'block_fuel' => 'Block Fuel', 'fuel_used' => 'Fuel Used', 'codeoptional' => 'Code (optional)', 'legoptional' => 'Leg (optional)', diff --git a/resources/lang/es/pireps.php b/resources/lang/es/pireps.php index 77c2344c..c0de6599 100644 --- a/resources/lang/es/pireps.php +++ b/resources/lang/es/pireps.php @@ -21,6 +21,7 @@ return [ 'fieldsreadonly' => 'Una vez que se ha enviado un PIREP, ciertos campos pasan al modo de solo lectura.', 'flightinformations' => 'Información de vuelo', 'flightident' => 'Vuelo Número/Código/Etapa', + 'block_fuel' => 'Bloque de Combustible', 'fuel_used' => 'Combustible Usado', 'codeoptional' => 'Código (opcional)', 'legoptional' => 'Etapa (opcional)', diff --git a/resources/lang/it/pireps.php b/resources/lang/it/pireps.php index 92d49163..2f8e506c 100644 --- a/resources/lang/it/pireps.php +++ b/resources/lang/it/pireps.php @@ -16,6 +16,7 @@ return [ 'fieldsreadonly' => 'Quando un PIREP viene sottoporre, alcuni cami entrano in modalità di sola lettura.', 'flightinformations' => 'Informazioni di Volo', 'flightident' => 'Numero di Volo/Codice/Leg', + 'block_fuel' => 'Bloccare il Carburante', 'fuel_used' => 'Carburante Usato', 'codeoptional' => 'Codice (facoltativo)', 'legoptional' => 'Leg (facoltativa)', diff --git a/resources/views/admin/airports/fields.blade.php b/resources/views/admin/airports/fields.blade.php index 3ec6cd52..64418f98 100644 --- a/resources/views/admin/airports/fields.blade.php +++ b/resources/views/admin/airports/fields.blade.php @@ -72,7 +72,13 @@
+ {{ Form::label('fuel_jeta_cost', 'Jet A Fuel Cost:') }} + {{ Form::number('fuel_jeta_cost', null, ['class' => 'form-control']) }} +

{{ $errors->first('fuel_jeta_cost') }}

+ @component('admin.components.info') + This is the cost per {{ config('phpvms.internal_units.fuel') }} + @endcomponent
diff --git a/resources/views/admin/airports/table.blade.php b/resources/views/admin/airports/table.blade.php index 31452068..6e9c6fde 100644 --- a/resources/views/admin/airports/table.blade.php +++ b/resources/views/admin/airports/table.blade.php @@ -6,9 +6,9 @@ Location Hub GH Cost - 100LL + {{--100LL--}} JetA - MOGAS + {{--MOGAS--}} @@ -25,15 +25,15 @@ {{ $airport->ground_handling_cost }} - + {{-- {{ $airport->fuel_100ll_cost }} - + --}} {{ $airport->fuel_jeta_cost }} - + {{-- {{ $airport->fuel_mogas_cost }} - + --}} {{ Form::open(['route' => ['admin.airports.destroy', $airport->id], 'method' => 'delete']) }} diff --git a/resources/views/admin/pireps/actions.blade.php b/resources/views/admin/pireps/actions.blade.php index a9ff84f8..9d9c41a5 100644 --- a/resources/views/admin/pireps/actions.blade.php +++ b/resources/views/admin/pireps/actions.blade.php @@ -28,6 +28,7 @@ @endif   + @if ($on_edit_page === false)
+ @endif diff --git a/resources/views/admin/pireps/fields.blade.php b/resources/views/admin/pireps/fields.blade.php index 2e733648..deaa8408 100644 --- a/resources/views/admin/pireps/fields.blade.php +++ b/resources/views/admin/pireps/fields.blade.php @@ -135,7 +135,7 @@
-
+
{{ Form::label('flight_time', 'Flight Time (hours & minutes):') }} @if($pirep->read_only)

@@ -163,8 +163,30 @@ @endif

+ +
+ {{ Form::label('block_fuel', 'Block Fuel:') }} +
+
+ {{ Form::number('block_fuel', null, ['class' => 'form-control', 'min' => 0]) }} +

{{ $errors->first('block_fuel') }}

+
+
+
+ + +
+ {{ Form::label('fuel_used', 'Fuel Used:') }} +
+
+ {{ Form::number('fuel_used', null, ['class' => 'form-control', 'min' => 0]) }} +

{{ $errors->first('fuel_used') }}

+
+
+
+ -
+
{{ Form::label('level', 'Flight Level:') }}
diff --git a/resources/views/layouts/default/pireps/fields.blade.php b/resources/views/layouts/default/pireps/fields.blade.php index bf4e8941..a4b0e736 100644 --- a/resources/views/layouts/default/pireps/fields.blade.php +++ b/resources/views/layouts/default/pireps/fields.blade.php @@ -228,13 +228,27 @@ flight reports that have been filed. You've been warned!

{{ $errors->first('aircraft_id') }}

@endif
+
+ {{ Form::label('block_fuel', __('pireps.block_fuel')) }} ({{config('phpvms.internal_units.fuel')}}) + @if(!empty($pirep) && $pirep->read_only) +

{{ $pirep->block_fuel }}

+ @else +
+ {{ Form::number('block_fuel', null, [ + 'class' => 'form-control', + 'min' => '0', + 'readonly' => (!empty($pirep) && $pirep->read_only), + ]) }} +
+

{{ $errors->first('block_fuel') }}

+ @endif +
{{ Form::label('fuel_used', __('pireps.fuel_used')) }} ({{config('phpvms.internal_units.fuel')}}) @if(!empty($pirep) && $pirep->read_only)

{{ $pirep->fuel_used }}

@else
- {{-- You probably don't want to change this ID if you want the fare select to work --}} {{ Form::number('fuel_used', null, [ 'class' => 'form-control', 'min' => '0', diff --git a/tests/FinanceTest.php b/tests/FinanceTest.php index 0fd40cad..a448b1a3 100644 --- a/tests/FinanceTest.php +++ b/tests/FinanceTest.php @@ -56,8 +56,14 @@ class FinanceTest extends TestCase $this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank); - $airport = factory(App\Models\Airport::class)->create([ + $dpt_apt = factory(App\Models\Airport::class)->create([ 'ground_handling_cost' => 10, + 'fuel_jeta_cost' => 10, + ]); + + $arr_apt = factory(App\Models\Airport::class)->create([ + 'ground_handling_cost' => 10, + 'fuel_jeta_cost' => 10, ]); $user = factory(App\Models\User::class)->create([ @@ -66,19 +72,23 @@ class FinanceTest extends TestCase $flight = factory(App\Models\Flight::class)->create([ 'airline_id' => $user->airline_id, - 'arr_airport_id' => $airport->icao, + 'dpt_airport_id' => $dpt_apt->icao, + 'arr_airport_id' => $arr_apt->icao, ]); $pirep = factory(App\Models\Pirep::class)->create([ 'flight_number' => $flight->flight_number, 'route_code' => $flight->route_code, 'route_leg' => $flight->route_leg, - 'arr_airport_id' => $airport->id, + 'dpt_airport_id' => $dpt_apt->id, + 'arr_airport_id' => $arr_apt->id, 'user_id' => $user->id, 'airline_id' => $user->airline_id, 'aircraft_id' => $subfleet['aircraft']->random(), 'source' => PirepSource::ACARS, 'flight_time' => 120, + 'block_fuel' => 10, + 'fuel_used' => 9, ]); /** @@ -649,13 +659,14 @@ class FinanceTest extends TestCase $transactions = $journalRepo->getAllForObject($pirep); - $this->assertCount(9, $transactions['transactions']); +// $this->assertCount(9, $transactions['transactions']); $this->assertEquals(3020, $transactions['credits']->getValue()); - $this->assertEquals(1860, $transactions['debits']->getValue()); + $this->assertEquals(1960, $transactions['debits']->getValue()); // Check that all the different transaction types are there // test by the different groups that exist $transaction_tags = [ + 'fuel' => 1, 'expense' => 1, 'subfleet' => 2, 'fare' => 3, diff --git a/tests/ImporterTest.php b/tests/ImporterTest.php index 30bcd8c8..8c598b71 100644 --- a/tests/ImporterTest.php +++ b/tests/ImporterTest.php @@ -487,7 +487,7 @@ class ImporterTest extends TestCase $this->assertEquals('0810 CST', $flight->dpt_time); $this->assertEquals('1235 EST', $flight->arr_time); $this->assertEquals('350', $flight->level); - $this->assertEquals(1477, $flight->distance['nmi']); + $this->assertEquals(1477, $flight->distance); $this->assertEquals('207', $flight->flight_time); $this->assertEquals(FlightType::SCHED_PAX, $flight->flight_type); $this->assertEquals('ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6', $flight->route); diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index 4e7722cf..992282bf 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -139,15 +139,15 @@ class PIREPTest extends TestCase // Check that it has the fuel units $this->assertHasKeys($body['fuel_used'], ['lbs', 'kg']); - $this->assertEquals($pirep->fuel_used['lbs'], $body['fuel_used']['lbs']); + $this->assertEquals($pirep->fuel_used, $body['fuel_used']['lbs']); // Check that it has the distance units $this->assertHasKeys($body['distance'], ['km', 'nmi', 'mi']); - $this->assertEquals($pirep->distance['nmi'], $body['distance']['nmi']); + $this->assertEquals($pirep->distance, $body['distance']['nmi']); // Check the planned_distance field $this->assertHasKeys($body['planned_distance'], ['km', 'nmi', 'mi']); - $this->assertEquals($pirep->planned_distance['nmi'], $body['planned_distance']['nmi']); + $this->assertEquals($pirep->planned_distance, $body['planned_distance']['nmi']); } public function testGetUserPireps()