diff --git a/app/Http/Controllers/SRP/SRPAdminController.php b/app/Http/Controllers/SRP/SRPAdminController.php new file mode 100644 index 000000000..512959cf8 --- /dev/null +++ b/app/Http/Controllers/SRP/SRPAdminController.php @@ -0,0 +1,54 @@ +middleware('auth'); + $this->middleware('role:User'); + $this->middleware('permission:srp.admin'); + } + + public function displaySRPRequests() { + $this->middleware('permission:srp.admin'); + + $requests = Ship::where(['approved' => 'Not Paid'])->get(); + + return view('srp.admin.process')->with('requests', $request); + } + + public function processSRPRequest() { + $this->middleware('permission:srp.admin'); + + $this->validate($request, [ + 'id' => 'required', + 'approved' => 'required', + 'paid_value' => 'required', + ]); + + $srp = SRPShip::where(['id' => $id])->update([ + 'approved' => $request->approved, + 'paid_value' => $request->paid_value, + 'paid_by_id' => auth()->user()->character_id, + 'paid_by_name' => auth()->user()->name, + ]); + + if($request->approved == 'Yes') { + return redirect('/srp/admin/display')->with('success', 'SRP Marked as Paid'); + } else { + return redirect('/srp/admin/display')->with('error', 'SRP Request Denied.'); + } + } +} diff --git a/app/Http/Controllers/SRP/SRPController.php b/app/Http/Controllers/SRP/SRPController.php index a7bb91647..a00f32ac6 100644 --- a/app/Http/Controllers/SRP/SRPController.php +++ b/app/Http/Controllers/SRP/SRPController.php @@ -11,22 +11,20 @@ use Auth; //User Libraries //Models -use App\Models\SRP\Fleet; -use App\Models\SRP\FleetCommander; -use App\Models\SRP\Ship; +use App\Models\SRP\SRPShip; class SRPController extends Controller { public function __construct() { $this->middleware('auth'); - $this->middelware('role:User'); + $this->middleware('role:User'); } public function displaySrpForm() { return view('srp.srpform'); } - public function storeSRPFile() { + public function storeSRPFile(Request $request) { $this->validate($request, [ 'FC' => 'required', 'FleetType' => 'required', @@ -35,16 +33,22 @@ class SRPController extends Controller 'ShipType' => 'required', ]); - $fc = $request->FC; - $fleetType = $request->FleetType; - $zKill = $request->zKillboard; - $loss = $request->LossValue; - $ship = $request->ShipType; + //See if the FC Name ties to a user on the services site + $fcId = User::where(['name' => $request->fc])->get(['character_id']); + + $ship = new SRPShip; + $ship->character_id = auth()->user()->character_id; + $ship->character_name = auth()->user()->name; + $ship->fleet_commander_name = $request->fc; + if($fcId[0] != null) { + $ship->fleet_commander_id = $fcId; + } + $ship->zkillboard = $request->zKillboard; + $ship->ship_type = $request->ShipType; + $ship->loss_value = $request->LossValue; + $ship->save(); + + return redirect('/srpform')->with('success', 'SRP Form Submitted.'); } - public function displaySRPRequests() { - $this->middleware('permission:SRP'); - - - } } diff --git a/app/Models/SRP/Fleet.php b/app/Models/SRP/Fleet.php deleted file mode 100644 index b0f340445..000000000 --- a/app/Models/SRP/Fleet.php +++ /dev/null @@ -1,27 +0,0 @@ -increments('id'); - $table->string('ship_type'); - $table->string('character_id'); - $table->string('zkillboard'); - $table->string('loss_values'); - $table->text('notes'); - }); - } - - if(!Schema::hasTable('srp_fleets')) { - Schema::create('srp_fleets', function(Blueprint $table) { - $table->increments('fleet_id'); - $table->string('fleet_name'); - $table->string('fleet_commander'); + $table->string('character_id')->default('N/A'); + $table->string('character_name'); $table->string('fleet_commander_id'); - $table->string('fleet_type'); - $table->string('fleet_description'); + $table->string('fleet_commander_name'); + $table->string('zkillboard'); + $table->string('ship_type'); + $table->decimal('loss_value', 20, 2); + $table->string('approved')->default('Not Paid'); + $table->decimal('paid_value', 20, 2)->default(0.00); + $table->string('notes')->nullable(); + $table->string('paid_by_id')->nullable(); + $table->string('paid_by_name')->nullable(); + $table->timestamps(); }); } } @@ -44,6 +41,5 @@ class CreateSrpTables extends Migration public function down() { Schema::dropIfExists('srp_ships'); - Schema::dropIfExists('srp_fleets'); } }