-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add table/models and admin for expenses #136
- Loading branch information
Showing
27 changed files
with
556 additions
and
41 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
app/Database/migrations/2018_02_26_185121_create_expenses_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateExpensesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('expenses', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->unsignedInteger('airline_id')->nullable(); | ||
$table->string('name'); | ||
$table->unsignedDecimal('amount'); | ||
$table->unsignedTinyInteger('type'); | ||
$table->boolean('multiplier')->nullable()->default(0); | ||
$table->boolean('active')->nullable()->default(1); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('expenses'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Pirep; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
/** | ||
* This event is dispatched when the expenses for a flight report | ||
* are collected. Your listeners should return a list of Expense | ||
* models. Don't call save on the model! | ||
* | ||
* Example return: | ||
* | ||
* [ | ||
* new Expense([ | ||
* 'airline_id': '', # < optional field | ||
* 'name': '', | ||
* 'amount': [DECIMAL], | ||
* 'type': int from ExpenseType enum class | ||
* ]), | ||
* ] | ||
* | ||
* The event caller will check the 'type' to make sure that it | ||
* will filter out expenses that only apply to the current process | ||
* | ||
* The event will have a copy of the PIREP model, if it's applicable | ||
* | ||
* @package App\Events | ||
*/ | ||
class Expenses | ||
{ | ||
use Dispatchable, SerializesModels; | ||
|
||
public $pirep; | ||
|
||
/** | ||
* @param Pirep|null $pirep | ||
*/ | ||
public function __construct(Pirep $pirep=null) | ||
{ | ||
$this->pirep = $pirep; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Requests\CreateAirlineRequest; | ||
use App\Http\Requests\UpdateAirlineRequest; | ||
use App\Models\Enums\ExpenseType; | ||
use App\Repositories\AirlineRepository; | ||
use App\Repositories\ExpenseRepository; | ||
use Flash; | ||
use Illuminate\Http\Request; | ||
use Prettus\Repository\Criteria\RequestCriteria; | ||
use Response; | ||
|
||
class ExpenseController extends BaseController | ||
{ | ||
private $airlineRepo, | ||
$expenseRepo; | ||
|
||
/** | ||
* expensesController constructor. | ||
* @param AirlineRepository $airlineRepo | ||
* @param ExpenseRepository $expenseRepo | ||
*/ | ||
public function __construct( | ||
AirlineRepository $airlineRepo, | ||
ExpenseRepository $expenseRepo | ||
) { | ||
$this->airlineRepo = $airlineRepo; | ||
$this->expenseRepo = $expenseRepo; | ||
} | ||
|
||
/** | ||
* Display a listing of the expenses. | ||
* @param Request $request | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
* @throws \Prettus\Repository\Exceptions\RepositoryException | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$this->expenseRepo->pushCriteria(new RequestCriteria($request)); | ||
$expenses = $this->expenseRepo->all(); | ||
|
||
return view('admin.expenses.index', [ | ||
'expenses' => $expenses | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new expenses. | ||
*/ | ||
public function create() | ||
{ | ||
return view('admin.expenses.create', [ | ||
'airlines_list' => $this->airlineRepo->selectBoxList(true), | ||
'expense_types' => ExpenseType::select(), | ||
]); | ||
} | ||
|
||
/** | ||
* Store a newly created expenses in storage. | ||
* @param Request $request | ||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||
* @throws \Prettus\Validator\Exceptions\ValidatorException | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$input = $request->all(); | ||
$this->expenseRepo->create($input); | ||
|
||
Flash::success('Expense saved successfully.'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
|
||
/** | ||
* Display the specified expenses. | ||
* @param int $id | ||
* @return mixed | ||
*/ | ||
public function show($id) | ||
{ | ||
$expenses = $this->expenseRepo->findWithoutFail($id); | ||
|
||
if (empty($expenses)) { | ||
Flash::error('expenses not found'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
|
||
return view('admin.expenses.show', [ | ||
'expenses' => $expenses, | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified expenses. | ||
* @param int $id | ||
* @return Response | ||
*/ | ||
public function edit($id) | ||
{ | ||
$expense = $this->expenseRepo->findWithoutFail($id); | ||
|
||
if (empty($expense)) { | ||
Flash::error('Expense not found'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
|
||
return view('admin.expenses.edit', [ | ||
'expense' => $expense, | ||
'airlines_list' => $this->airlineRepo->selectBoxList(true), | ||
'expense_types' => ExpenseType::select(), | ||
]); | ||
} | ||
|
||
/** | ||
* Update the specified expenses in storage. | ||
* @param int $id | ||
* @param Request $request | ||
* @return Response | ||
* @throws \Prettus\Validator\Exceptions\ValidatorException | ||
*/ | ||
public function update($id, Request $request) | ||
{ | ||
$expenses = $this->expenseRepo->findWithoutFail($id); | ||
|
||
if (empty($expenses)) { | ||
Flash::error('Expense not found'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
|
||
$this->expenseRepo->update($request->all(), $id); | ||
|
||
Flash::success('Expense updated successfully.'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
|
||
/** | ||
* Remove the specified expenses from storage. | ||
* @param int $id | ||
* @return Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
$expenses = $this->expenseRepo->findWithoutFail($id); | ||
|
||
if (empty($expenses)) { | ||
Flash::error('Expense not found'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
|
||
$this->expenseRepo->delete($id); | ||
|
||
Flash::success('Expense deleted successfully.'); | ||
return redirect(route('admin.expenses.index')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Models\Enums; | ||
|
||
/** | ||
* Class ExpenseType | ||
* @package App\Models\Enums | ||
*/ | ||
class ExpenseType extends EnumBase { | ||
|
||
public const FLIGHT = 0; | ||
public const DAILY = 1; | ||
public const MONTHLY = 2; | ||
|
||
protected static $labels = [ | ||
ExpenseType::FLIGHT => 'Flight', | ||
ExpenseType::DAILY => 'Daily', | ||
ExpenseType::MONTHLY => 'Monthly', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
/** | ||
* Class Expense | ||
* @package App\Models | ||
*/ | ||
class Expense extends BaseModel | ||
{ | ||
public $table = 'expenses'; | ||
|
||
public $fillable = [ | ||
'airline_id', | ||
'name', | ||
'amount', | ||
'type', | ||
'multiplier', | ||
'active', | ||
]; | ||
|
||
public static $rules = [ | ||
'active' => 'boolean', | ||
'airline_id' => 'integer', | ||
'amount' => 'float', | ||
'multiplier' => 'integer', | ||
'type' => 'integer', | ||
]; | ||
|
||
/** | ||
* Foreign Keys | ||
*/ | ||
|
||
public function airline() | ||
{ | ||
return $this->belongsTo(Airline::class, 'airline_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Repositories; | ||
|
||
use App\Models\Expense; | ||
use Prettus\Repository\Contracts\CacheableInterface; | ||
use Prettus\Repository\Traits\CacheableRepository; | ||
|
||
/** | ||
* Class ExpenseRepository | ||
* @package App\Repositories | ||
*/ | ||
class ExpenseRepository extends BaseRepository implements CacheableInterface | ||
{ | ||
use CacheableRepository; | ||
|
||
public function model() | ||
{ | ||
return Expense::class; | ||
} | ||
} |
Oops, something went wrong.