Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BossOfGames committed Aug 19, 2024
0 parents commit 97193a6
Show file tree
Hide file tree
Showing 28 changed files with 1,195 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
/**
* Provide any configuration items here
*/

return [
'name' => 'CHJumpSeat'
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use App\Contracts\Migration;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

/**
* Class CreateJumpseatRequestsTable
*/
class CreateJumpseatRequestsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ch_jumpseat_requests', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->string('airport_id');
$table->integer('type')->default(0); // Automatic or Manual
$table->string('request_reason')->nullable();
$table->string('deny_reason')->nullable();
$table->integer('status')->default(0);
$table->unsignedBigInteger('approver_id')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ch_jumpseat_requests');
}
}
42 changes: 42 additions & 0 deletions Database/migrations/2024_08_13_051351_seed_jumpseat_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use App\Contracts\Migration;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

/**
* Class SeedJumpseatSettings
*/
class SeedJumpseatSettings extends Migration
{
/**
* Run thce migrations.
*
* @return void
*/
public function up()
{
$setting = \App\Models\Setting::firstOrNew(['id' => 'ch_jumpseat_price']);
$setting->id = 'ch_jumpseat_price';
$setting->offset = 9000;
$setting->order = 9100;
$setting->key = 'ch_jupmpseat.price';
$setting->name = 'User Price';
$setting->value = 1000;
$setting->default = 1000;
$setting->group = 'chjumpseat';
$setting->type = 'int';
$setting->description = 'The price to set for a user created jumpseat with the decimal suppressed if the currency applies (e.g. $1000.00 would be entered as "100000")';
$setting->save();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Binary file added Http/Controllers/.DS_Store
Binary file not shown.
49 changes: 49 additions & 0 deletions Http/Controllers/Admin/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Modules\CHJumpSeat\Http\Controllers\Admin;

use App\Contracts\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Notification;
use Modules\CHJumpSeat\Models\CHJumpseatRequest;
use Modules\CHJumpSeat\Notifications\JumpSeatApproval;
use Modules\CHJumpSeat\Notifications\JumpSeatRequested;

/**
* Admin controller
*/
class AdminController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @return mixed
*/
public function index(Request $request)
{

return view('chjumpseat::admin.index', ['requests' => CHJumpseatRequest::orderByDesc('created_at')->paginate(30)]);
}

public function status(CHJumpseatRequest $id, Request $request) {
$status = $request->input('status');

$id->status = $status;
$id->approver_id = Auth::user()->id;
$id->save();

if ($request->input('status') == 1) {
// do the Jumpseat
$user = User::find($id->user_id);

$user->curr_airport_id = $id->airport_id;
$user->save();
Notification::send($id, new JumpSeatApproval($id));
}
return response()->redirectToRoute('admin.chjumpseat.index');
}
}
42 changes: 42 additions & 0 deletions Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Modules\CHJumpSeat\Http\Controllers\Api;

use App\Contracts\Controller;
use Illuminate\Http\Request;

/**
* class ApiController
* @package Modules\CHJumpSeat\Http\Controllers\Api
*/
class ApiController extends Controller
{
/**
* Just send out a message
*
* @param Request $request
*
* @return mixed
*/
public function index(Request $request)
{
return $this->message('Hello, world!');
}

/**
* Handles /hello
*
* @param Request $request
*
* @return mixed
*/
public function hello(Request $request)
{
// Another way to return JSON, this for a custom response
// It's recommended to use Resources for responses from the database
return response()->json([
'name' => Auth::user()->name,
]);
}

}
104 changes: 104 additions & 0 deletions Http/Controllers/Frontend/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Modules\CHJumpSeat\Http\Controllers\Frontend;

use App\Contracts\Controller;
use App\Models\User;
use App\Services\FinanceService;
use App\Support\Money;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Session;
use Laracasts\Flash\Flash;
use Modules\CHJumpSeat\Models\CHJumpseatRequest;
use Modules\CHJumpSeat\Notifications\JumpSeatRequested;

/**
* Class $CLASS$
* @package
*/
class IndexController extends Controller
{
public function __construct(public FinanceService $financeService)
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @return mixed
*/
public function index(Request $request)
{
$jsrs = CHJumpseatRequest::where(['user_id' => Auth::user()->id])->orderByDesc('created_at')->paginate(20);
return view('chjumpseat::index', ['requests' => $jsrs]);
}

/**
* Show the form for creating a new resource.
*
* @param Request $request
*
* @return mixed
*/
public function create(Request $request)
{
$price = new Money(setting('ch_jumpseat.price', 100000));
return view('chjumpseat::create', ['price' => $price]);
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return mixed
*/
public function store(Request $request)
{
$data = $request->all();
if (!isset($data['airport_id'])) {
Flash::error("No Airport Selected! Please select an airport before submitting a request.");
return response()->redirectToRoute('chjumpseat.create');
}

// If pay for immediate Jumpseat, check the balance and apply to journal, then move the pilot.
$user = User::find(Auth::user()->id);
$data['user_id'] = Auth::user()->id;
$curr_apt = $user->curr_airport_id;

if ($curr_apt === $data['airport_id']) {
Flash::info("Jumpseat Request Cancelled. You're already at this airport!");
return response()->redirectToRoute('frontend.dashboard.index');
}
$jumpseat_price = new Money(setting('ch_jumpseat.price', 100000));
$journal = optional($user->journal)->balance ?? new Money(0);
// Create a new jumpseat Request
$jsr = CHJumpseatRequest::create($data);
if ($jsr->type == 1 && $journal->getValue() >= $jumpseat_price->getValue()) {

$user->curr_airport_id = $data['airport_id'];
$user->save();
$jsr->status = 1;
$jsr->save();
$this->financeService->debitFromJournal($user->journal, $jumpseat_price, $jsr, "Jumpseat: {$curr_apt}->{$data['airport_id']}", null, null);
Flash::success("Jumpseat Request Fulfilled");
return response()->redirectToRoute('frontend.dashboard.index');
} else {
$jsr->type = 0;
$jsr->save();
Notification::send($jsr, new JumpSeatRequested($jsr));
$add = "";
if (!($journal->getValue() >= $jumpseat_price->getValue())) {
Flash::warning("Jumpseat request created. However, you did not have sufficient funds to make a instant transfer. Your Request has been submitted for approval.");
} else {
Flash::info("Jumpseat request created.");
}
}

return response()->redirectToRoute('chjumpseat.index');
}
}
5 changes: 5 additions & 0 deletions Http/Routes/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

# This is the admin path. Comment this out if you don't have an admin panel component.
Route::get('/', 'AdminController@index')->name('index');
Route::post('/{id}', 'AdminController@status')->name('status');
17 changes: 17 additions & 0 deletions Http/Routes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* This is publicly accessible
*/
Route::group(['middleware' => []], function() {
Route::get('/', 'ApiController@index');
});

/**
* This is required to have a valid API key
*/
Route::group(['middleware' => [
'api.auth'
]], function() {
Route::get('/hello', 'ApiController@hello');
});
12 changes: 12 additions & 0 deletions Http/Routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

Route::get('/', 'IndexController@index')->name('index');
Route::get('/create', [\Modules\CHJumpSeat\Http\Controllers\Frontend\IndexController::class, 'create'])->name('create');
Route::post('/', [\Modules\CHJumpSeat\Http\Controllers\Frontend\IndexController::class, 'store'])->name('store');
/*
* To register a route that needs to be authentication, wrap it in a
* Route::group() with the auth middleware
*/
// Route::group(['middleware' => 'auth'], function() {
// Route::get('/', 'IndexController@index');
// })
Loading

0 comments on commit 97193a6

Please sign in to comment.