diff --git a/CHANGELOG.md b/CHANGELOG.md index 269da447..04d53acd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,20 @@ - Finances! The finance portions have been implemented, you can [read about them here](http://docs.phpvms.net/concepts/finances) - Awards! Added the award plugin system. [see docs](http://docs.phpvms.net/customizing/awards) +- Import/Export in admin panel for aircraft, airports, expenses, fares, flights and subfleets - Changed theme system to using [laravel-theme](https://github.com/igaster/laravel-theme), there are changes to making theming much simpler with much more flexibility. +- Added cron task for background tasks +- Expanded on flight types to match IATA SIMM format +- Added subfleet `cost_block_hour` - Fixed several security vulnerabilities (thanks magicflyer!) - Fuel units changed to lbs/kgs [#193](https://github.com/nabeelio/phpvms/issues/193) - Airports can be restricted to only hubs on registration/user profile - Cleaned up a lot unused icons and files [#195](https://github.com/nabeelio/phpvms/issues/195) - Rank restrictions for PIREPs are respected [#170](https://github.com/nabeelio/phpvms/issues/170) - API: Added the ability to get/update/delete user bids [#172](https://github.com/nabeelio/phpvms/issues/172) -- Artisan: Added a `phpvms:export [tables]` to export tables to YAML files which can be re-imported using `phpvms:import` +- API: Added `block_time` parameter for PIREP prefile/update/file calls +- Artisan: Added a `phpvms:csv-import [table] [file]` to import from CSV +- Artisan: Added a `phpvms:yaml-export [tables]` to export tables to YAML files which can be re-imported using `phpvms:yaml-import` - Numerous bug fixes ## Alpha 2 (2018-02-23, v7.0.0-alpha2) diff --git a/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php b/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php index a786020a..8959af7f 100644 --- a/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php +++ b/app/Database/migrations/2017_06_23_011011_create_subfleet_tables.php @@ -15,6 +15,8 @@ class CreateSubfleetTables extends Migration $table->unsignedInteger('airline_id')->nullable(); $table->string('type', 50)->unique(); $table->string('name', 50); + $table->unsignedDecimal('cost_block_hour'); + $table->unsignedDecimal('cost_delay_minute'); $table->unsignedTinyInteger('fuel_type')->nullable(); $table->unsignedDecimal('ground_handling_multiplier')->nullable()->default(100); $table->unsignedDecimal('cargo_capacity')->nullable(); diff --git a/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php b/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php index 734faa7b..fb6f0a3c 100644 --- a/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php +++ b/app/Database/migrations/2017_06_28_195426_create_pirep_tables.php @@ -28,6 +28,7 @@ class CreatePirepTables extends Migration $table->unsignedInteger('level')->nullable(); $table->unsignedDecimal('distance')->nullable(); $table->unsignedDecimal('planned_distance')->nullable(); + $table->unsignedInteger('block_time')->nullable(); $table->unsignedInteger('flight_time')->nullable(); $table->unsignedInteger('planned_flight_time')->nullable(); $table->unsignedDecimal('zfw')->nullable(); diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index 47ffa56a..a0fbdea7 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -265,16 +265,19 @@ subfleets: airline_id: 1 name: 747-43X RB211-524G type: 744-3X-RB211 + cost_block_hour: 1000 ground_handling_multiplier: 200 - id: 2 airline_id: 1 name: 777-222ER GE90-76B type: 772-22ER-GE90-76B + cost_block_hour: 500 ground_handling_multiplier: 150 - id: 3 airline_id: 1 name: 777-367 ER GE90-115B type: 772-36ER-GE90-115B + cost_block_hour: 100 ground_handling_multiplier: 150 # add a few mods to aircraft and fares @@ -384,6 +387,7 @@ pireps: 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 created_at: NOW @@ -397,6 +401,7 @@ pireps: arr_airport_id: LGRP flight_time: 180 # 6 hours state: 1 + flight_type: J route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 notes: just a pilot report source: 1 # pending @@ -413,6 +418,7 @@ pireps: flight_time: 180 # 6 hours state: 1 # pending source: 0 # manual + flight_type: J route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 notes: just a pilot report created_at: NOW @@ -610,9 +616,9 @@ journal_transactions: tags: '"pilot_pay"' ref_class: App\Models\Pirep ref_class_id: pirepid_1 - created_at: '2018-03-06 12:34:15' - updated_at: '2018-03-06 12:34:15' - post_date: '2018-03-06 12:34:15' + created_at: now + updated_at: now + post_date: now - id: ed516367-eeb9-4a09-bfb7-531ec4be2f93 transaction_group: Fares @@ -624,9 +630,9 @@ journal_transactions: tags: '"fare"' ref_class: App\Models\Pirep ref_class_id: pirepid_1 - created_at: '2018-03-06 12:34:15' - updated_at: '2018-03-06 12:34:15' - post_date: '2018-03-06 12:34:15' + created_at: now + updated_at: now + post_date: now - id: f3f8585e-894c-4491-b19b-d07b6ad20208 transaction_group: 'Ground Handling' @@ -638,6 +644,21 @@ journal_transactions: tags: '"ground_handling"' ref_class: App\Models\Pirep ref_class_id: pirepid_1 - created_at: '2018-03-06 12:34:15' - updated_at: '2018-03-06 12:34:15' - post_date: '2018-03-06 12:34:15' + created_at: now + updated_at: now + post_date: now + + - + id: 1bd1616c-eaa4-4ab9-b5c1-441004ceef14 + transaction_group: 'Subfleet 744-3X-RB211' + journal_id: 1 + credit: null + debit: 300000 + currency: USD + memo: 'Subfleet 744-3X-RB211: Block Time Cost' + tags: '"subfleet"' + ref_class: App\Models\Pirep + ref_class_id: pirepid_1 + created_at: now + updated_at: now + post_date: now diff --git a/app/Http/Requests/Acars/FileRequest.php b/app/Http/Requests/Acars/FileRequest.php index 8417adb2..7ace80bc 100644 --- a/app/Http/Requests/Acars/FileRequest.php +++ b/app/Http/Requests/Acars/FileRequest.php @@ -26,6 +26,7 @@ class FileRequest extends FormRequest 'flight_time' => 'required|integer', 'fuel_used' => 'required|numeric', + 'block_time' => 'nullable|integer', 'airline_id' => 'nullable|exists:airlines,id', 'aircraft_id' => 'nullable|exists:aircraft,id', 'flight_number' => 'nullable', diff --git a/app/Http/Requests/Acars/PrefileRequest.php b/app/Http/Requests/Acars/PrefileRequest.php index ddcf8fb1..8e31c71f 100644 --- a/app/Http/Requests/Acars/PrefileRequest.php +++ b/app/Http/Requests/Acars/PrefileRequest.php @@ -29,6 +29,7 @@ class PrefileRequest extends FormRequest 'route_code' => 'nullable', 'route_leg' => 'nullable', 'distance' => 'nullable|numeric', + 'block_time' => 'nullable|integer', 'flight_time' => 'nullable|integer', 'planned_distance' => 'nullable|numeric', 'planned_flight_time' => 'nullable|integer', diff --git a/app/Http/Requests/Acars/UpdateRequest.php b/app/Http/Requests/Acars/UpdateRequest.php index b0a6e99e..ca06da23 100644 --- a/app/Http/Requests/Acars/UpdateRequest.php +++ b/app/Http/Requests/Acars/UpdateRequest.php @@ -31,8 +31,9 @@ class UpdateRequest extends FormRequest 'route_leg' => 'nullable', 'distance' => 'nullable|numeric', 'planned_distance' => 'nullable|numeric', - 'planned_flight_time' => 'nullable|integer', + 'block_time' => 'nullable|integer', 'flight_time' => 'nullable|integer', + 'planned_flight_time' => 'nullable|integer', 'level' => 'nullable|numeric', 'zfw' => 'nullable|numeric', 'fuel_used' => 'nullable|numeric', diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index 410dc351..301a9007 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -24,6 +24,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName; * @property Airline airline * @property Airport arr_airport * @property Airport dep_airport + * @property integer block_time * @property integer flight_time In minutes * @property User user * @property Flight|null flight @@ -53,6 +54,7 @@ class Pirep extends Model 'level', 'distance', 'planned_distance', + 'block_time', 'flight_time', 'planned_flight_time', 'zfw', @@ -77,6 +79,7 @@ class Pirep extends Model 'level' => 'integer', 'distance' => 'float', 'planned_distance' => 'float', + 'block_time' => 'integer', 'flight_time' => 'integer', 'planned_flight_time' => 'integer', 'zfw' => 'float', diff --git a/app/Models/Subfleet.php b/app/Models/Subfleet.php index 2e630c00..ff254df0 100644 --- a/app/Models/Subfleet.php +++ b/app/Models/Subfleet.php @@ -10,8 +10,11 @@ use App\Models\Traits\ExpensableTrait; * Class Subfleet * @property int id * @property string type + * @property string name * @property string ground_handling_multiplier * @property Fare[] fares + * @property float cost_block_hour + * @property float cost_delay_minute * @package App\Models */ class Subfleet extends Model @@ -24,6 +27,7 @@ class Subfleet extends Model 'airline_id', 'type', 'name', + 'turn_time', 'fuel_type', 'ground_handling_multiplier', 'cargo_capacity', @@ -33,6 +37,9 @@ class Subfleet extends Model public $casts = [ 'airline_id' => 'integer', + 'turn_time' => 'integer', + 'cost_block_hour' => 'float', + 'cost_delay_minute' => 'float', 'fuel_type' => 'integer', 'ground_handling_multiplier' => 'float', 'cargo_capacity' => 'float', diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index 2606a809..4ea0ab65 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -14,6 +14,7 @@ use App\Services\FareService; use App\Services\PirepService; use App\Support\Math; use App\Support\Money; +use App\Support\Units\Time; use Log; /** @@ -73,6 +74,7 @@ class PirepFinanceService extends Service # Now start and pay from scratch $this->payFaresForPirep($pirep); + $this->payExpensesForSubfleet($pirep); $this->payExpensesForPirep($pirep); $this->payExpensesEventsForPirep($pirep); $this->payGroundHandlingForPirep($pirep); @@ -128,6 +130,48 @@ class PirepFinanceService extends Service } } + /** + * Calculate what the cost is for the operating an aircraft + * in this subfleet, as-per the block time + * @param Pirep $pirep + * @throws \UnexpectedValueException + * @throws \InvalidArgumentException + * @throws \Prettus\Validator\Exceptions\ValidatorException + */ + public function payExpensesForSubfleet(Pirep $pirep): void + { + $sf = $pirep->aircraft->subfleet; + + Log::info('subfleet: ', $sf->toArray()); + # Haven't entered a cost + if (!filled($sf->cost_block_hour)) { + return; + } + + # Convert to cost per-minute + $cost_per_min = round($sf->cost_block_hour / 60, 2); + + # Time to use - use the block time if it's there, actual + # flight time if that hasn't been used + $block_time = $pirep->block_time; + if(!filled($block_time)) { + $block_time = $pirep->flight_time; + } + + $debit = Money::createFromAmount($cost_per_min * $block_time); + + $this->journalRepo->post( + $pirep->airline->journal, + null, + $debit, + $pirep, + 'Subfleet '.$sf->type.': Block Time Cost', + null, + 'Subfleet '.$sf->type, + 'subfleet' + ); + } + /** * Collect all of the expenses and apply those to the journal * @param Pirep $pirep diff --git a/resources/views/admin/subfleets/fields.blade.php b/resources/views/admin/subfleets/fields.blade.php index 2d5fdae0..24b46773 100644 --- a/resources/views/admin/subfleets/fields.blade.php +++ b/resources/views/admin/subfleets/fields.blade.php @@ -12,13 +12,19 @@ @endcomponent -
{{ $errors->first('airline_id') }}
+{{ $errors->first('type') }}
{{ $errors->first('name') }}
@@ -27,19 +33,25 @@{{ $errors->first('airline_id') }}
+{{ $errors->first('cost_block_hour') }}
{{ $errors->first('cost_delay_minute') }}
+{{ $errors->first('fuel_type') }}
{{ $errors->first('ground_handling_multiplier') }}