diff --git a/app/Http/Controllers/FareController.php b/app/Http/Controllers/FareController.php
new file mode 100644
index 00000000..2bed7932
--- /dev/null
+++ b/app/Http/Controllers/FareController.php
@@ -0,0 +1,146 @@
+fareRepository = $fareRepo;
+ }
+
+ /**
+ * Display a listing of the Fare.
+ *
+ * @param Request $request
+ *
+ * @return Response
+ */
+ public function index(Request $request)
+ {
+ $this->fareRepository->pushCriteria(new RequestCriteria($request));
+ $fares = $this->fareRepository->all();
+
+ return view('admin.fares.index')
+ ->with('fares', $fares);
+ }
+
+ /**
+ * Show the form for creating a new Fare.
+ *
+ * @return Response
+ */
+ public function create()
+ {
+ return view('admin.fares.create');
+ }
+
+ /**
+ * Store a newly created Fare in storage.
+ *
+ * @param CreateFareRequest $request
+ *
+ * @return Response
+ */
+ public function store(CreateFareRequest $request)
+ {
+ $input = $request->all();
+ $fare = $this->fareRepository->create($input);
+ Flash::success('Fare saved successfully.');
+
+ return redirect(route('admin.fares.index'));
+ }
+
+ /**
+ * Display the specified Fare.
+ *
+ * @param int $id
+ *
+ * @return Response
+ */
+ public function show($id)
+ {
+ $fare = $this->fareRepository->findWithoutFail($id);
+ if (empty($fare)) {
+ Flash::error('Fare not found');
+
+ return redirect(route('admin.fares.index'));
+ }
+
+ return view('admin.fares.show')->with('fare', $fare);
+ }
+
+ /**
+ * Show the form for editing the specified Fare.
+ *
+ * @param int $id
+ *
+ * @return Response
+ */
+ public function edit($id)
+ {
+ $fare = $this->fareRepository->findWithoutFail($id);
+ if (empty($fare)) {
+ Flash::error('Fare not found');
+
+ return redirect(route('admin.fares.index'));
+ }
+
+ return view('admin.fares.edit')->with('fare', $fare);
+ }
+
+ /**
+ * Update the specified Fare in storage.
+ *
+ * @param int $id
+ * @param UpdateFareRequest $request
+ *
+ * @return Response
+ */
+ public function update($id, UpdateFareRequest $request)
+ {
+ $fare = $this->fareRepository->findWithoutFail($id);
+ if (empty($fare)) {
+ Flash::error('Fare not found');
+
+ return redirect(route('admin.fares.index'));
+ }
+ $fare = $this->fareRepository->update($request->all(), $id);
+ Flash::success('Fare updated successfully.');
+
+ return redirect(route('admin.fares.index'));
+ }
+
+ /**
+ * Remove the specified Fare from storage.
+ *
+ * @param int $id
+ *
+ * @return Response
+ */
+ public function destroy($id)
+ {
+ $fare = $this->fareRepository->findWithoutFail($id);
+ if (empty($fare)) {
+ Flash::error('Fare not found');
+
+ return redirect(route('admin.fares.index'));
+ }
+ $this->fareRepository->delete($id);
+ Flash::success('Fare deleted successfully.');
+
+ return redirect(route('admin.fares.index'));
+ }
+}
diff --git a/app/Http/Requests/CreateFareRequest.php b/app/Http/Requests/CreateFareRequest.php
new file mode 100644
index 00000000..107c8cfb
--- /dev/null
+++ b/app/Http/Requests/CreateFareRequest.php
@@ -0,0 +1,30 @@
+ 'string',
- 'name' => 'string',
- 'full_name' => 'string',
- 'registration' => 'string',
- 'active' => 'boolean',
- ];
+ protected $casts
+ = [
+ 'icao' => 'string',
+ 'name' => 'string',
+ 'full_name' => 'string',
+ 'registration' => 'string',
+ 'active' => 'boolean',
+ ];
/**
* Validation rules
*
* @var array
*/
- public static $rules = [
- 'icao' => 'required|max:4',
- 'name' => 'required',
- 'full_name' => 'required',
- 'registration' => 'required',
- 'active' => 'default:1'
- ];
+ public static $rules
+ = [
+ 'icao' => 'required|max:4',
+ 'name' => 'required',
+ 'full_name' => 'required',
+ 'registration' => 'required',
+ 'active' => 'default:1',
+ ];
/**
* foreign key
@@ -63,8 +68,12 @@ class Aircraft extends Model
);
}
- public function fares() {
- # aircraft_fare == table name
- return $this->belongsToMany('App\Models\Fare', 'aircraft_fare');
+ public function fares()
+ {
+ $r = $this->belongsToMany(
+ 'App\Models\Fare',
+ 'aircraft_fare'
+ )->withPivot('price', 'cost', 'capacity');
+ return $r;
}
}
diff --git a/app/Models/Fare.php b/app/Models/Fare.php
new file mode 100644
index 00000000..2526887f
--- /dev/null
+++ b/app/Models/Fare.php
@@ -0,0 +1,66 @@
+ 'string',
+ 'name' => 'string',
+ 'price' => 'float',
+ 'cost' => 'float',
+ 'notes' => 'string',
+ 'active' => 'boolean',
+ ];
+
+ /**
+ * Validation rules
+ *
+ * @var array
+ */
+ public static $rules
+ = [
+ 'code' => 'required',
+ 'name' => 'required',
+ 'cost' => 'default:0.0',
+ ];
+
+ public function aircraft() {
+ return $this->belongsToMany(
+ 'App\Models\Aircraft',
+ 'aircraft_fare'
+ )->withPivot('price', 'cost', 'capacity');
+ }
+
+}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 35471f6f..c4379642 100755
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -4,6 +4,8 @@ namespace App\Providers;
use Illuminate\Support\ServiceProvider;
+use App\Services\AircraftService;
+
class AppServiceProvider extends ServiceProvider
{
/**
@@ -23,6 +25,13 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
- //
+ // bind all the app services...
+ $this->app->bind('App\Services\AircraftService', function($app) {
+ return new \App\Services\AircraftService();
+ });
+
+ $this->app->bind('App\Services\AircraftFareService', function($app) {
+ return new \App\Services\AircraftFareService();
+ });
}
}
diff --git a/app/Repositories/AircraftClassRepository.php b/app/Repositories/AircraftClassRepository.php
index dbd104bc..631596a6 100644
--- a/app/Repositories/AircraftClassRepository.php
+++ b/app/Repositories/AircraftClassRepository.php
@@ -3,7 +3,6 @@
namespace App\Repositories;
use App\Models\AircraftClass;
-use InfyOm\Generator\Common\BaseRepository;
class AircraftClassRepository extends BaseRepository
{
diff --git a/app/Repositories/AircraftRepository.php b/app/Repositories/AircraftRepository.php
index 468e23c8..e5218fbc 100644
--- a/app/Repositories/AircraftRepository.php
+++ b/app/Repositories/AircraftRepository.php
@@ -3,20 +3,20 @@
namespace App\Repositories;
use App\Models\Aircraft;
-use InfyOm\Generator\Common\BaseRepository;
class AircraftRepository extends BaseRepository
{
/**
* @var array
*/
- protected $fieldSearchable = [
- 'icao',
- 'name',
- 'full_name',
- 'registration',
- 'active',
- ];
+ protected $fieldSearchable
+ = [
+ 'icao',
+ 'name',
+ 'full_name',
+ 'registration',
+ 'active',
+ ];
/**
* Configure the Model
@@ -25,4 +25,9 @@ class AircraftRepository extends BaseRepository
{
return Aircraft::class;
}
+
+ public function findByICAO($icao)
+ {
+ return $this->findByField('icao', $icao)->first();
+ }
}
diff --git a/app/Repositories/AirlinesRepository.php b/app/Repositories/AirlinesRepository.php
index 5f7488e0..103d6f11 100644
--- a/app/Repositories/AirlinesRepository.php
+++ b/app/Repositories/AirlinesRepository.php
@@ -3,7 +3,6 @@
namespace App\Repositories;
use App\Models\Airlines;
-use InfyOm\Generator\Common\BaseRepository;
class AirlinesRepository extends BaseRepository
{
diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php
new file mode 100644
index 00000000..258fb593
--- /dev/null
+++ b/app/Repositories/BaseRepository.php
@@ -0,0 +1,21 @@
+model()->rules
+ );
+
+ if($validator->fails()) {
+ return $validator->messages();
+ }
+
+ return true;
+ }
+}
diff --git a/app/Repositories/FareRepository.php b/app/Repositories/FareRepository.php
new file mode 100644
index 00000000..88a96a43
--- /dev/null
+++ b/app/Repositories/FareRepository.php
@@ -0,0 +1,32 @@
+findByField('code', $code)->first();
+ }
+}
diff --git a/app/Services/AircraftFareService.php b/app/Services/AircraftFareService.php
deleted file mode 100644
index aa1582fb..00000000
--- a/app/Services/AircraftFareService.php
+++ /dev/null
@@ -1,30 +0,0 @@
-fare = $fare;
- $this->aircraft = $aircraft;
- }
-
- public function link(int $aircraft_id, int $fare_id) {
-
- }
-
- public function unlink(int $aircraft_id, int $fare_id) {
-
- }
-}
diff --git a/app/Services/AircraftService.php b/app/Services/AircraftService.php
new file mode 100644
index 00000000..74bc25ff
--- /dev/null
+++ b/app/Services/AircraftService.php
@@ -0,0 +1,31 @@
+create($attributes);
+ } catch (Exception $e) {
+ return false;
+ }
+
+ if ($class != null) {
+ $model->class()->associate($class);
+ $model->save();
+ }
+
+ return $model;
+ }
+}
diff --git a/app/Services/BaseService.php b/app/Services/BaseService.php
new file mode 100644
index 00000000..3c80d020
--- /dev/null
+++ b/app/Services/BaseService.php
@@ -0,0 +1,7 @@
+fares()->syncWithoutDetaching([$fare->id]);
+
+ # modify any pivot values?
+ if(count($override) > 0) {
+ $aircraft->fares()->updateExistingPivot($fare->id, $override);
+ }
+
+ $aircraft->save();
+ $aircraft = $aircraft->fresh();
+ return $aircraft;
+ }
+
+ /**
+ * return all the fares for an aircraft. check the pivot
+ * table to see if the price/cost/capacity has been overridden
+ * and return the correct amounts.
+ * @param Aircraft $aircraft
+ * @return Fare[]
+ */
+ public function get_for_aircraft(Aircraft &$aircraft)
+ {
+ $fares = [];
+ foreach($aircraft->fares as $fare) {
+ if(!is_null($fare->pivot->price)) {
+ $fare->price = $fare->pivot->price;
+ }
+
+ if(!is_null($fare->pivot->cost)) {
+ $fare->cost = $fare->pivot->cost;
+ }
+
+ if(!is_null($fare->pivot->capacity)) {
+ $fare->capacity = $fare->pivot->capacity;
+ }
+ array_push($fares, $fare);
+ }
+
+ return $fares;
+ }
+
+ public function delete_from_aircraft(Aircraft &$aircraft, Fare &$fare)
+ {
+ $aircraft->fares()->detach($fare->id);
+ $aircraft = $aircraft->fresh();
+ return $aircraft;
+ }
+}
diff --git a/app/Services/PIREPService.php b/app/Services/PIREPService.php
index 79fdef3a..540e2a11 100644
--- a/app/Services/PIREPService.php
+++ b/app/Services/PIREPService.php
@@ -5,7 +5,7 @@ namespace App\Services;
use App\Repositories\AircraftRepository;
-class PIREPService {
+class PIREPService extends BaseService {
protected $aircraft;
diff --git a/database/factories/FaresFactory.php b/database/factories/FaresFactory.php
index 4ced6e91..c35fb54f 100644
--- a/database/factories/FaresFactory.php
+++ b/database/factories/FaresFactory.php
@@ -2,6 +2,9 @@
$factory->define(App\Models\Fare::class, function (Faker\Generator $faker) {
return [
-
+ 'code' => 'Y',
+ 'name' => 'Economy',
+ 'price' => '100',
+ 'capacity' => '200',
];
});
diff --git a/database/migrations/2017_06_09_010621_create_aircrafts_table.php b/database/migrations/2017_06_09_010621_create_aircrafts_table.php
index bd0496e8..3825d777 100644
--- a/database/migrations/2017_06_09_010621_create_aircrafts_table.php
+++ b/database/migrations/2017_06_09_010621_create_aircrafts_table.php
@@ -9,7 +9,7 @@ class CreateAircraftsTable extends Migration
{
Schema::create('aircraft', function (Blueprint $table) {
$table->increments('id');
- $table->integer('aircraft_class_id')->unsigned();
+ $table->integer('aircraft_class_id')->unsigned()->nullable();
$table->string('icao');
$table->string('name');
$table->string('full_name')->nullable();
diff --git a/database/migrations/2017_06_10_040335_create_fares_table.php b/database/migrations/2017_06_10_040335_create_fares_table.php
new file mode 100644
index 00000000..ba5a4500
--- /dev/null
+++ b/database/migrations/2017_06_10_040335_create_fares_table.php
@@ -0,0 +1,51 @@
+increments('id');
+ $table->string('code');
+ $table->string('name');
+ $table->float('price');
+ $table->float('cost')->default(0.0);
+ $table->integer('capacity')->default(0);
+ $table->string('notes')->nullable();
+ $table->boolean('active')->default(true);
+ $table->timestamps();
+ $table->softDeletes();
+ });
+
+ Schema::create('aircraft_fare', function (Blueprint $table) {
+ $table->increments('id');
+ $table->integer('aircraft_id');
+ $table->integer('fare_id');
+ $table->float('price')->nullable();
+ $table->float('cost')->nullable();
+ $table->float('capacity')->nullable();
+ $table->timestamps();
+ $table->softDeletes();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::drop('fares');
+ Schema::drop('aircraft_fare');
+ }
+}
diff --git a/resources/views/admin/fares/create.blade.php b/resources/views/admin/fares/create.blade.php
new file mode 100644
index 00000000..43145702
--- /dev/null
+++ b/resources/views/admin/fares/create.blade.php
@@ -0,0 +1,24 @@
+@extends('admin.app')
+
+@section('content')
+
+ Fare
+
+
{!! $fare->id !!}
+{!! $fare->code !!}
+{!! $fare->name !!}
+{!! $fare->price !!}
+{!! $fare->cost !!}
+{!! $fare->notes !!}
+{!! $fare->active !!}
+{!! $fare->created_at !!}
+{!! $fare->updated_at !!}
+| Code | +Name | +Price | +Cost | +Notes | +Active | +Action | + + + @foreach($fares as $fare) +
|---|---|---|---|---|---|---|
| {!! $fare->code !!} | +{!! $fare->name !!} | +{!! $fare->price !!} | +{!! $fare->cost !!} | +{!! $fare->notes !!} | +{!! $fare->active !!} | ++ {!! Form::open(['route' => ['admin.fares.destroy', $fare->id], 'method' => 'delete']) !!} + + {!! Form::close() !!} + | +