1
0
forked from s421507/eOSP2

Wyjazdy - zmiana radio boxow na checkboxy oraz dodanie edycji

This commit is contained in:
czup 2019-12-07 14:50:37 +01:00
parent 213b279ec6
commit d505b14b09
4 changed files with 163 additions and 65 deletions

View File

@ -10,6 +10,7 @@ use App\vehicle;
use App\operationsDrivers; use App\operationsDrivers;
use App\operationsTrucks; use App\operationsTrucks;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -20,7 +21,7 @@ class operationsController extends Controller
if(auth()->user() != null && auth()->user()->fireStationID != null ){ if(auth()->user() != null && auth()->user()->fireStationID != null ){
$operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID) $operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID)
->leftJoin('users', 'operations.commanderID', '=', 'users.id') ->leftJoin('users', 'operations.commanderID', '=', 'users.id')
->select('operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.name', 'users.surname')
->get(); ->get();
return view('operation', ["operations" => $operations]); return view('operation', ["operations" => $operations]);
@ -31,8 +32,6 @@ class operationsController extends Controller
public function addForm(){ public function addForm(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){ if(auth()->user() != null && auth()->user()->fireStationID != null ){
//$fireStationID = auth()->user()->fireStationID;
// $fireFighters = User::pluck('fireStationID', $fireStationID);
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get(); $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get();
$vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID) $vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID)
->get(); ->get();
@ -45,14 +44,25 @@ class operationsController extends Controller
public function editForm($id){ public function editForm($id){
if(auth()->user() != null && auth()->user()->fireStationID != null ){ if(auth()->user() != null && auth()->user()->fireStationID != null ){
// $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get();
$vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID)
->get();
$operation = DB::table('operations')->where('operations.id', '=', $id)->first(); $operation = DB::table('operations')->where('operations.id', '=', $id)->first();
$operationMembers = DB::table('operationsMembers')->where('operationID', '=', $id)->get();
// $operation = DB::table('operations')->where('operations.id', '=', $id) // $operation = DB::table('operations')->where('operations.id', '=', $id)
// ->leftJoin('users', 'operations.commanderID', '=', 'users.id') // ->leftJoin('users', 'operations.commanderID', '=', 'users.id')
// ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') // ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname')
// ->get(); // ->get();
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('operationsMembers', function ($join) use($id){
$join->on('users.id', '=', 'operationsMembers.memberID');
$join->where('operationsMembers.operationID', '=', $id);
})
->select('users.*', 'operationsMembers.memberID', 'operationsMembers.privateTransport')
->get();
// if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) { // if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) {
return view('operationEdit', ["operation" => $operation]); // return view('operationEdit', ["operation" => $operation], ["fireFighters" => $fireFighters], ["operationMembers" => $operationMembers] );
return View::make('/operationEdit')->with(compact('fireFighters','operation', 'operationMembers', 'vehicles'));
// } else{ // } else{
// return "Brak dostepu"; // return "Brak dostepu";
// } // }
@ -78,6 +88,7 @@ class operationsController extends Controller
'required' => ':attribute jest wymagany(e)' 'required' => ':attribute jest wymagany(e)'
]); ]);
//
$request = request(); $request = request();
$operations = operations::create([ $operations = operations::create([
'operationDate' => $request-> operationDate, 'operationDate' => $request-> operationDate,
@ -89,6 +100,7 @@ class operationsController extends Controller
'fireStationID' => auth()->user()->fireStationID, 'fireStationID' => auth()->user()->fireStationID,
]); ]);
// Add trucks
$operationDriver = $request ->operationDriver; $operationDriver = $request ->operationDriver;
$operationVehicle = $request -> operationVehicle; $operationVehicle = $request -> operationVehicle;
for($count = 0; $count < count($operationDriver); $count++){ for($count = 0; $count < count($operationDriver); $count++){
@ -99,13 +111,29 @@ class operationsController extends Controller
]); ]);
} }
// Add members
$attendance = $request-> attendance; $attendance = $request-> attendance;
for($count = 0; $count < count($attendance); $count++){ $transport = $request-> transport;
if($attendance[$count] != 'false'){
// Count of firefighters (need for length of array)
$fireFightersCount = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->count();
for($count = 0; $count < $fireFightersCount; $count++){
// Check privateTransport checklist
$privateTransport = 2;
if(isset($transport[$count])){
$privateTransport = 1;
} else{
$privateTransport = 0;
}
if(isset($attendance[$count])){
$operationsMembers = operationsMembers::create([ $operationsMembers = operationsMembers::create([
'operationID' => $operations->id, 'operationID' => $operations->id,
'memberID' => $attendance[$count], 'memberID' => $attendance[$count],
'privateTransport' => $request->transport[$count], 'privateTransport' => $privateTransport,
]); ]);
}; };
} }
@ -114,6 +142,76 @@ class operationsController extends Controller
} }
public function update(){ public function update(){
$this->validate(request(),[
'operationDate' => 'required',
'operationLocation' => 'required',
'operationTarget' => 'required',
'operationDangerType' => 'required',
'operationDescription' => 'required',
'operationLeader' => 'required',
'operationDriver.*' => 'required',
'operationVehicle.*' => 'required',
'attendance.*' => 'required',
'transport.*' => 'required',
],
[
'required' => ':attribute jest wymagany(e)'
]);
$request = request();
$operation = operations::where('id', $request->operationID)->update(array(
'operationDate' => $request-> operationDate,
'location' => $request-> operationLocation,
'target' => $request-> operationTarget,
'dangerType' => $request-> operationDangerType,
'description' => $request-> operationDescription,
'commanderID' => $request-> operationLeader,
'fireStationID' => auth()->user()->fireStationID
));
operationsTrucks::where('operationID', $request->operationID)->delete();
// Add trucks
$operationDriver = $request ->operationDriver;
$operationVehicle = $request -> operationVehicle;
for($count = 0; $count < count($operationDriver); $count++){
$operationsTrucks = operationsTrucks::create([
'operationID' => $request->operationID,
'truckID' => $operationDriver[$count],
'driverID' => $operationVehicle[$count]
]);
}
operationsMembers::where('operationID', $request->operationID)->delete();
// Add members
$attendance = $request-> attendance;
$transport = $request-> transport;
// Count of firefighters (need for length of array)
$fireFightersCount = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->count();
for($count = 0; $count < $fireFightersCount; $count++){
// Check privateTransport checklist
$privateTransport = 2;
if(isset($transport[$count])){
$privateTransport = 1;
} else{
$privateTransport = 0;
}
if(isset($attendance[$count])){
$operationsMembers = operationsMembers::create([
'operationID' => $request->operationID,
'memberID' => $attendance[$count],
'privateTransport' => $privateTransport,
]);
};
}
return operationsController::create();
} }
} }

View File

@ -16,7 +16,7 @@
{{ csrf_field() }} {{ csrf_field() }}
<div class="form-group"> <div class="form-group">
<label for="date">Data wyjazdu: </label> <label for="date">Data wyjazdu: </label>
<input type="datetime-local" id="operationDate" name="operationDate"> <input type="datetime-local" id="operationDate" name="operationDate" value="2017-06-01 08:30">
</div> </div>
<div class="form-group"> <div class="form-group">
@ -72,14 +72,14 @@
<div class="form-group"> <div class="form-group">
<table> <table>
<tr> <tr>
<td>Imię i nazwisko: [</td><td></td><td>Obecność:</td><td>[][][]</td><td>Transport własny:</td> <td>Imię i nazwisko: </td><td></td><td>Obecność:</td><td></td><td>Transport własny:</td>
</tr> </tr>
@php @php
$i = 0; $i = 0;
@endphp @endphp
@foreach($fireFighters as $fireFighterChecklist) @foreach($fireFighters as $fireFighterChecklist)
<tr> <tr>
<td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td> </td><td>Tak <input type="radio" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}">Nie<input type="radio" name="attendance[{{$i}}]" value="false" checked></td><td> </td><td>Tak <input type="radio" name="transport[{{$i}}]" value="1">Nie <input type="radio" name="transport[{{$i}}]" value="0" checked></td> <td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td></td><td><center><input type="checkbox" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}"></center></td> <td></td> <td><center><input type="checkbox" name="transport[{{$i}}]" value="{{$i}}"></center></td>
</tr> </tr>
@php @php
$i++; $i++;
@ -88,7 +88,6 @@
</table> </table>
</div> </div>
<div class="form-group"> <div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button> <button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
</div> </div>

View File

@ -12,7 +12,7 @@
@section('center-area') @section('center-area')
@parent @parent
<form method="POST" action="/wyjazdy" id="dynamic_form"> <form method="POST" action="/wyjazdy/edit" id="dynamic_form">
{{ csrf_field() }} {{ csrf_field() }}
<input type="hidden" class="form-control" name="operationID" value="{{ $operation->id }}"> <input type="hidden" class="form-control" name="operationID" value="{{ $operation->id }}">
@ -41,15 +41,15 @@
<textarea class="form-control" id="'operationDescription" name="operationDescription">{{ $operation->description }}</textarea> <textarea class="form-control" id="'operationDescription" name="operationDescription">{{ $operation->description }}</textarea>
</div> </div>
{{-- <div class=form-group">--}} <div class=form-group">
{{-- <label for="location">Dowodzący:</label>--}} <label for="location">Dowodzący:</label>
{{-- <select name="operationLeader" class="form-control">--}} <select name="operationLeader" class="form-control">
{{-- <option value="">--- Wybierz dowódcę ---</option>--}} <option value="">--- Wybierz dowódcę ---</option>
{{-- @foreach ($fireFighters as $fireFighter)--}} @foreach ($fireFighters as $fireFighter)
{{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}} <option value="{{$fireFighter->id}}" {{$fireFighter->id == $operation->commanderID ? 'selected' : ''}}>{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
{{-- @endforeach--}} @endforeach
{{-- </select>--}} </select>
{{-- </div>--}} </div>
<div class=form-group"> <div class=form-group">
@ -71,24 +71,25 @@
</div> </div>
</div> </div>
{{-- <div class="form-group">--}} <div class="form-group">
{{-- <table>--}} <table>
{{-- <tr>--}} <tr>
{{-- <td>Imię i nazwisko: [</td><td></td><td>Obecność:</td><td>[][][]</td><td>Transport własny:</td>--}} <td>Imię i nazwisko: </td><td></td><td>Obecność:</td><td></td><td>Transport własny:</td>
{{-- </tr>--}} </tr>
{{-- @php--}} @php
{{-- $i = 0;--}} $i = 0;
{{-- @endphp--}} @endphp
{{-- @foreach($fireFighters as $fireFighterChecklist)--}} @foreach($fireFighters as $fireFighterChecklist)
{{-- <tr>--}} <tr>
{{-- <td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td> </td><td>Tak <input type="radio" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}">Nie<input type="radio" name="attendance[{{$i}}]" value="false" checked></td><td> </td><td>Tak <input type="radio" name="transport[{{$i}}]" value="1">Nie <input type="radio" name="transport[{{$i}}]" value="0" checked></td>--}} <td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td></td><td><center><input type="checkbox" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}" {{$fireFighterChecklist->memberID != null ? 'checked' : ''}} ></center></td> <td></td> <td><center><input type="checkbox" name="transport[{{$i}}]" value="{{$i}}" {{$fireFighterChecklist->privateTransport == 1 ? 'checked' : ''}}></center></td>
{{-- </tr>--}} </tr>
{{-- @php--}} @php
{{-- $i++;--}} $i++;
{{-- @endphp--}} @endphp
{{-- @endforeach--}} @endforeach
{{-- </table>--}} </table>
{{-- </div>--}} </div>
<div class="form-group"> <div class="form-group">
@ -109,31 +110,31 @@
function dynamic_field(number) function dynamic_field(number)
{ {
{{--html = '<div id="singleDriver"><label for="location">Kierowca:</label>';--}} html = '<div id="singleDriver"><label for="location">Kierowca:</label>';
{{--html += '<select name="operationDriver[]" class="form-control">';--}} html += '<select name="operationDriver[]" class="form-control">';
{{--html += '<option value="">--- Wybierz kierowcę ---</option>';--}} html += '<option value="">--- Wybierz kierowcę ---</option>';
{{--html += '@foreach ($fireFighters as $fireFighter)';--}} html += '@foreach ($fireFighters as $fireFighter)';
{{--html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';--}} html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
{{--html += '@endforeach';--}} html += '@endforeach';
{{--html += '</select>';--}} html += '</select>';
{{--html += '<label for="location">Pojazd:</label>';--}} html += '<label for="location">Pojazd:</label>';
{{--html += '<select name="operationVehicle[]" class="form-control">';--}} html += '<select name="operationVehicle[]" class="form-control">';
{{--html += '<option value="">--- Wybierz pojazd ---</option>';--}} html += '<option value="">--- Wybierz pojazd ---</option>';
{{--html += '@foreach ($vehicles as $vehicle)';--}} html += '@foreach ($vehicles as $vehicle)';
{{--html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>';--}} html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>';
{{--html += '@endforeach';--}} html += '@endforeach';
{{--html += '</select>';--}} html += '</select>';
{{--if(number > 1)--}} if(number > 1)
{{--{--}} {
{{-- html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';--}} html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';
{{-- $('#drivers').append(html);--}} $('#drivers').append(html);
{{--}--}} }
{{--else--}} else
{{--{--}} {
{{-- html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';--}} html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';
{{-- $('#drivers').html(html);--}} $('#drivers').html(html);
{{--}--}} }
} }
$(document).on('click', '#add', function(){ $(document).on('click', '#add', function(){

View File

@ -33,8 +33,8 @@ Route::get('/pojazdy', function(){
Route::get('/wyjazdy', 'operationsController@create'); Route::get('/wyjazdy', 'operationsController@create');
Route::get('/wyjazdy/add/', 'operationsController@addForm'); Route::get('/wyjazdy/add/', 'operationsController@addForm');
Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store'); Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store');
Route::post('/wyjazdy/edit/', 'operationsController@update')->name('operationController.update');
Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm'); Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm');
Route::post('/wyjazdy/edit', 'operationsController@update');
Route::get('/register', 'RegistrationController@create'); Route::get('/register', 'RegistrationController@create');
Route::post('/register', 'RegistrationController@store'); Route::post('/register', 'RegistrationController@store');