payout code forms

This commit is contained in:
2019-07-02 23:55:35 -05:00
parent 51c926c20b
commit 556b62065a
6 changed files with 165 additions and 2 deletions

View File

@@ -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.');
}
}

View File

@@ -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);
}
}

View File

@@ -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');
}
}

View File

@@ -0,0 +1,27 @@
@extends('srp.layouts.b4')
@section('content')
<div class="card">
<div class="card-header">
<h2>Add a New Cost Code</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'SRP\SRPAdminController@addCostCode', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('code', 'Code') }}
{{ Form::text('code', null, ['class' => 'form-control', 'placeholder' => 'T1']) }}
</div>
<div class="form-group">
{{ Form::label('description', 'Description') }}
{{ Form::text('description', null, ['class' => 'form-control', 'placeholder' => 'description']) }}
</div>
<div class="form-group">
{{ Form::label('payout', 'Payout') }}
{{ Form::text('payout', null, ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::submit('Add Payout Code', ['class' => 'btn btn-primary']) }}
</div>
{!! Form::close() !!}
</div>
</div>
@endsection

View File

@@ -0,0 +1,36 @@
@extends('srp.layouts.b4')
@section('content')
<div class="container">
<table class="table table-striped">
<thead>
<th>Code</th>
<th>Description</th>
<th>Payout Percentage</th>
<th>Modify</th>
</thead>
<tbody>
@foreach($costcodes as $code)
<tr>
{!! Form::open(['action' => 'SRP\SRPAdminController@modifyCostCodes', 'method' => 'POST']) !!}
<td>
{{ $code->code }}
{{ Form::text('code', null, ['class' => 'form-control', 'placeholder' => $code->code]) }}
</td>
<td>
{{ $code->description }}
{{ Form::text('description', null, ['class' => 'form-control', 'placeholder' => $code->description]) }}
</td>
<td>
{{ $code->payout }}
{{ Form::text('payout', null, ['class' => 'form-control', 'placeholder' => $code->payout]) }}
</td>
<td>
{{ Form::submit('Modify', ['class' => 'btn btn-primary']) }}
</td>
</tr>
{!! Form::close() !!}
@endforeach
</tbody>
</table>
</div>
@endsection

View File

@@ -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');
});