diff --git a/app/Http/Controllers/SRP/SRPAdminController.php b/app/Http/Controllers/SRP/SRPAdminController.php index 5408a7ff5..ecb9f819c 100644 --- a/app/Http/Controllers/SRP/SRPAdminController.php +++ b/app/Http/Controllers/SRP/SRPAdminController.php @@ -75,8 +75,6 @@ class SRPAdminController extends Controller } public function processSRPRequest(Request $request) { - $this->middleware('permission:srp.admin'); - $this->validate($request, [ 'id' => 'required', 'approved' => 'required', @@ -165,4 +163,83 @@ class SRPAdminController extends Controller return view('srp.admin.statistics')->with('lava', $lava); } + + public function displayCostCodes() { + $costcodes = array(); + $count = 0; + $shipType = SrpShipType::all(); + $srpPayout = SrpPayout::all(); + + foreach($shipType as $ship) { + //Don't process if the code is None + if($ship->code != 'None') { + $tempCode = $ship->code; + $tempDescription = $ship->description; + $temp = SrpPayout::where(['code' => $ship->code])->get(); + $tempPayout = $temp->payout; + + $block = [ + 'code' => $tempCode, + 'description' => $tempDescription, + 'payout' => $tempPayout, + ]; + + array_push($costcodes, $block); + } + } + + return view('srp.admin.costcodes.display')->with($costcodes); + } + + public function addCostCode(Request $request) { + $this->validate($request, [ + 'code' => 'required', + 'description' => 'required', + 'payout' => 'required', + ]); + + $code = $request->code; + $description = $request->description; + $payout = $request->payout; + + $payoutCount = SrpPayout::where(['code' => $code])->count(); + $shipTypeCount = SrpShipType::where(['code' => $code])->count(); + + //If we don't find the cost code, let's add it. otherwise send an error. + if($payoutCount == 0 && $shipTypeCount == 0) { + $payoutTable = new SrpPayout; + $payoutTable->code = $code; + $payoutTable->payout = $payout; + $payoutTable->save(); + + $shipType = new SrpShipType; + $shipType->code = $code; + $shipType->description = $description; + $shipType->save(); + + redirect('/srp/admin/display')->with('success', 'Cost code added.'); + } else { + redirect('/srp/admin/display')->with('error', 'Cost code already exists in the database.'); + } + } + + public function modifyCostCodes(Request $request) { + $this->validate($request, [ + 'code' => 'required', + 'description' => 'required', + 'payout' => 'required', + ]); + + //Update the SrpShipType + SrpShipType::where(['code' => $request->code])->update([ + 'description' => $request->description, + ]); + + //Update the payout + SrpPayout::where(['code' => $request->code])->update([ + 'payout' => $request->payout, + ]); + + return redirect('/srp/admin/display')->with('success', 'Payout and Description updated.'); + } } diff --git a/app/Models/SRP/SrpPayout.php b/app/Models/SRP/SrpPayout.php index 256377fd1..73b2a0a95 100644 --- a/app/Models/SRP/SrpPayout.php +++ b/app/Models/SRP/SrpPayout.php @@ -14,4 +14,14 @@ class SrpPayout extends Model //Timestamps public $timestamps = false; + + //Fillable + protected $fillable = [ + 'code', + 'payout', + ]; + + public function shipType() { + return $this->belongsTo(SrpShipType::class); + } } diff --git a/app/Models/SRP/SrpShipType.php b/app/Models/SRP/SrpShipType.php index b81937523..273a4cc51 100644 --- a/app/Models/SRP/SrpShipType.php +++ b/app/Models/SRP/SrpShipType.php @@ -14,4 +14,14 @@ class SrpShipType extends Model //Timestamps public $timestamps = false; + + //Fillable + protected $fillable = [ + 'code', + 'description', + ]; + + public function costCode() { + return $this->hasOne('App\Models\SRP\SrpPayout', 'code', 'code'); + } } diff --git a/resources/views/srp/admin/costcodes/add.blade.php b/resources/views/srp/admin/costcodes/add.blade.php new file mode 100644 index 000000000..a5722e255 --- /dev/null +++ b/resources/views/srp/admin/costcodes/add.blade.php @@ -0,0 +1,27 @@ +@extends('srp.layouts.b4') +@section('content') +
+
+

Add a New Cost Code

+
+
+ {!! Form::open(['action' => 'SRP\SRPAdminController@addCostCode', 'method' => 'POST']) !!} +
+ {{ Form::label('code', 'Code') }} + {{ Form::text('code', null, ['class' => 'form-control', 'placeholder' => 'T1']) }} +
+
+ {{ Form::label('description', 'Description') }} + {{ Form::text('description', null, ['class' => 'form-control', 'placeholder' => 'description']) }} +
+
+ {{ Form::label('payout', 'Payout') }} + {{ Form::text('payout', null, ['class' => 'form-control']) }} +
+
+ {{ Form::submit('Add Payout Code', ['class' => 'btn btn-primary']) }} +
+ {!! Form::close() !!} +
+
+@endsection \ No newline at end of file diff --git a/resources/views/srp/admin/costcodes/display.blade.php b/resources/views/srp/admin/costcodes/display.blade.php new file mode 100644 index 000000000..749eeb804 --- /dev/null +++ b/resources/views/srp/admin/costcodes/display.blade.php @@ -0,0 +1,36 @@ +@extends('srp.layouts.b4') +@section('content') +
+ + + + + + + + + @foreach($costcodes as $code) + + {!! Form::open(['action' => 'SRP\SRPAdminController@modifyCostCodes', 'method' => 'POST']) !!} + + + + + + {!! Form::close() !!} + @endforeach + +
CodeDescriptionPayout PercentageModify
+ {{ $code->code }} + {{ Form::text('code', null, ['class' => 'form-control', 'placeholder' => $code->code]) }} + + {{ $code->description }} + {{ Form::text('description', null, ['class' => 'form-control', 'placeholder' => $code->description]) }} + + {{ $code->payout }} + {{ Form::text('payout', null, ['class' => 'form-control', 'placeholder' => $code->payout]) }} + + {{ Form::submit('Modify', ['class' => 'btn btn-primary']) }} +
+
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 9aa86e80c..d5296bbea 100644 --- a/routes/web.php +++ b/routes/web.php @@ -106,6 +106,9 @@ Route::group(['middleware' => ['auth']], function(){ Route::get('/srp/admin/display', 'SRP\SRPAdminController@displaySRPRequests'); Route::post('/srp/admin/process', 'SRP\SRPAdminController@processSRPRequest'); Route::get('/srp/admin/statistics', 'SRP\SRPAdminController@displayStatistics'); + Route::get('/srp/admin/costcodes/display', 'SRP\SRPAdminController@displayCostCodes'); + Route::post('/srp/admin/costcodes/add', 'SRP\SRPAdminController@addCostCode'); + Route::post('/srp/admin/costcodes/modify', 'SRP\SRPAdminController@modifyCostCodes'); });