From 53e4bf533fcacf97c6c54c2ce370017a863d0868 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 5 Mar 2018 14:18:54 -0600 Subject: [PATCH] Add finance controller; morphable expense type so they can be applied to any model #130 --- ...018_02_26_185121_create_expenses_table.php | 6 ++- .../Controllers/Admin/FinanceController.php | 46 +++++++++++++++++++ app/Models/Airport.php | 2 + app/Models/Traits/ExpensableTrait.php | 28 +++++++++++ app/Routes/admin.php | 3 ++ resources/views/admin/menu.blade.php | 1 + 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Admin/FinanceController.php create mode 100644 app/Models/Traits/ExpensableTrait.php diff --git a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php index bba538ed..bf59172f 100644 --- a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php +++ b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php @@ -20,7 +20,11 @@ class CreateExpensesTable extends Migration $table->unsignedInteger('amount'); $table->unsignedTinyInteger('type'); $table->boolean('multiplier')->nullable()->default(0); - $table->boolean('active')->nullable()->default(1); + $table->boolean('active')->nullable()->default(true); + + # Internal fields are expenses tied to some system object + # EG, the airports has an internal expense for gate costs + $table->nullableMorphs('expensable'); $table->timestamps(); }); } diff --git a/app/Http/Controllers/Admin/FinanceController.php b/app/Http/Controllers/Admin/FinanceController.php new file mode 100644 index 00000000..494de410 --- /dev/null +++ b/app/Http/Controllers/Admin/FinanceController.php @@ -0,0 +1,46 @@ +financeSvc = $financeSvc; + $this->journalRepo = $journalRepo; + } + + /** + * Display a listing of the Aircraft. + */ + public function index(Request $request) + { + + } + + /** + * Show a month + */ + public function show($id) + { + + } +} diff --git a/app/Models/Airport.php b/app/Models/Airport.php index c306e155..a257f995 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Traits\ExpensableTrait; use Illuminate\Notifications\Notifiable; /** @@ -11,6 +12,7 @@ use Illuminate\Notifications\Notifiable; */ class Airport extends BaseModel { + use ExpensableTrait; use Notifiable; public $table = 'airports'; diff --git a/app/Models/Traits/ExpensableTrait.php b/app/Models/Traits/ExpensableTrait.php new file mode 100644 index 00000000..7aa479f9 --- /dev/null +++ b/app/Models/Traits/ExpensableTrait.php @@ -0,0 +1,28 @@ +initJournal(config('phpvms.currency')); + });*/ + } + + /** + * Morph to Expenses. + * @return mixed + */ + public function expenses() + { + return $this->morphToMany(Expense::class, 'expensable'); + } +} diff --git a/app/Routes/admin.php b/app/Routes/admin.php index c8cb49a6..f847b0fc 100644 --- a/app/Routes/admin.php +++ b/app/Routes/admin.php @@ -21,6 +21,9 @@ Route::group([ # fares Route::resource('fares', 'FareController'); + # finances + Route::resource('finances', 'FinanceController'); + # flights and aircraft associations Route::resource('flights', 'FlightController'); Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/fares', 'FlightController@fares'); diff --git a/resources/views/admin/menu.blade.php b/resources/views/admin/menu.blade.php index bac6a7a3..d6bfbaa0 100644 --- a/resources/views/admin/menu.blade.php +++ b/resources/views/admin/menu.blade.php @@ -18,6 +18,7 @@
  • flights
  • fleet
  • fares
  • +
  • finances