1
0
forked from s421507/eOSP2

Wyjazdy - zawężenie list strażaków do tych, którzy mają stosowne szkolenia

This commit is contained in:
Krzysztof Strzelecki 2020-02-27 14:33:21 +01:00
parent 32486d50b0
commit 1b0c7bc916
3 changed files with 74 additions and 20 deletions

View File

@ -16,9 +16,15 @@ use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;
const basicTrainingID = 1; //szkolenie podstawowe
const leaderTrainingID = 2; //szkolenie dowódcy
const driverTrainingID = 3; //szkolenie kierowcy-mechanika
class operationsController extends Controller
{
//
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID)
@ -61,14 +67,34 @@ class operationsController extends Controller
public function addForm(){
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get();
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', basicTrainingID)
->select('users.*')
->get();
$leaders = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', leaderTrainingID)
->select('users.*')
->get();
$drivers = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', driverTrainingID)
->select('users.*')
->get();
$vehicles = DB::table('vehicles')->where([
["fireStationID", '=', auth()->user()->fireStationID],
["vehicles.status", "=", 1],
["vehicles.deleted_at", "=", null],
])
->get();
return view("operationAdd", ["fireFighters" => $fireFighters], ["vehicles" => $vehicles]);
//return view("operationAdd", ["fireFighters" => $fireFighters], ["vehicles" => $vehicles]);
return view("operationAdd")
->with(compact('fireFighters'))
->with(compact('leaders'))
->with(compact('drivers'))
->with(compact('vehicles'));
} else return redirect()->to('/wyjazdy');
}
@ -80,7 +106,7 @@ class operationsController extends Controller
// $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get();
$vehicles = DB::table('vehicles')->where([
["fireStationID", '=', auth()->user()->fireStationID],
["vehicles.deleted_at", "=", null]
//["vehicles.status", "=", 1],
])
->get();
$operation = DB::table('operations')->where('operations.id', '=', $id)->first();
@ -90,6 +116,26 @@ class operationsController extends Controller
// ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname')
// ->get();
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', basicTrainingID)
->leftJoin('operationsMembers', function ($join) use($id){
$join->on('users.id', '=', 'operationsMembers.memberID');
$join->where('operationsMembers.operationID', '=', $id);
})
->select('users.*', 'operationsMembers.memberID', 'operationsMembers.privateTransport')
->get();
$drivers = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', driverTrainingID)
->leftJoin('operationsMembers', function ($join) use($id){
$join->on('users.id', '=', 'operationsMembers.memberID');
$join->where('operationsMembers.operationID', '=', $id);
})
->select('users.*', 'operationsMembers.memberID', 'operationsMembers.privateTransport')
->get();
$leaders = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', leaderTrainingID)
->leftJoin('operationsMembers', function ($join) use($id){
$join->on('users.id', '=', 'operationsMembers.memberID');
$join->where('operationsMembers.operationID', '=', $id);
@ -115,7 +161,7 @@ class operationsController extends Controller
// if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) {
// return view('operationEdit', ["operation" => $operation], ["fireFighters" => $fireFighters], ["operationMembers" => $operationMembers] );
return View::make('/operationEdit')->with(compact('fireFighters','operation', 'operationMembers', 'vehicles', 'operationsTrucks'));
return View::make('/operationEdit')->with(compact('fireFighters', 'drivers', 'leaders', 'operation', 'operationMembers', 'vehicles', 'operationsTrucks'));
// } else{
// return "Brak dostepu";
// }
@ -160,19 +206,21 @@ class operationsController extends Controller
for($count = 0; $count < count($operationDriver); $count++){
$operationsTrucks = operationsTrucks::create([
'operationID' => $operations->id,
'truckID' => $operationVehicle[$count],
'truckID' => $operationVehicle[$count],
'driverID' => $operationDriver[$count]
]);
]);
}
// 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();
$fireFightersCount = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
->where('trainingsFirefighters.trainingID', '=', basicTrainingID)
->count();
for($count = 0; $count < $fireFightersCount; $count++){
// Check privateTransport checklist
@ -267,7 +315,7 @@ class operationsController extends Controller
};
}
return operationsController::create();
return redirect()->to('/wyjazdy');
}
public function destroy($id)

View File

@ -43,11 +43,11 @@
<label for="location">Dowodzący:</label>
<select name="operationLeader" class="form-control">
<option value="">--- Wybierz dowódcę ---</option>
@foreach ($fireFighters as $fireFighter)
@if(Illuminate\Support\Facades\Input::old('operationLeader') == $fireFighter->id)
<option value="{{$fireFighter->id}}" selected>{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@foreach ($leaders as $leader)
@if(Illuminate\Support\Facades\Input::old('operationLeader') == $leader->id)
<option value="{{$leader->id}}" selected>{{ $leader->name }} {{$leader->surname }}</option>
@else
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
<option value="{{$leader->id}}">{{ $leader->name }} {{$leader->surname }}</option>
@endif
@endforeach
</select>
@ -119,8 +119,8 @@
html += '<label for="location">Kierowca:</label>';
html += '<select name="operationDriver[]" class="form-control">';
html += '<option value="">--- Wybierz kierowcę ---</option>';
html += '@foreach ($fireFighters as $fireFighter)';
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
html += '@foreach ($drivers as $driver)';
html += '<option value="{{$driver->id}}">{{ $driver->name }} {{$driver->surname }}</option>';
html += '@endforeach';
html += '</select>';
html += '</div>';

View File

@ -47,8 +47,8 @@
<label for="location">Dowodzący:</label>
<select name="operationLeader" class="form-control">
<option value="">--- Wybierz dowódcę ---</option>
@foreach ($fireFighters as $fireFighter)
<option value="{{$fireFighter->id}}" {{$fireFighter->id == $operation->commanderID ? 'selected' : ''}}>{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@foreach ($leaders as $leader)
<option value="{{$leader->id}}" {{$leader->id == $operation->commanderID ? 'selected' : ''}}>{{ $leader->name }} {{$leader->surname }}</option>
@endforeach
</select>
</div>
@ -63,8 +63,8 @@
<label for="location">Kierowca:</label>
<select name="operationDriver[]" class="form-control">
<option value="">--- Wybierz kierowcę ---</option>
@foreach ($fireFighters as $fireFighter)
<option {{$fireFighter->id == $operationTruck->driverID ? 'selected' : ''}} value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@foreach ($drivers as $driver)
<option {{$driver->id == $operationTruck->driverID ? 'selected' : ''}} value="{{$driver->id}}">{{ $driver->name }} {{$driver->surname }}</option>
@endforeach
</select>
</div>
@ -73,7 +73,13 @@
<select name="operationVehicle[]" class="form-control">
<option value="">--- Wybierz pojazd ---</option>
@foreach ($vehicles as $vehicle)
<option {{$vehicle->id == $operationTruck->truckID ? 'selected' : ''}} value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>
<option {{$vehicle->id == $operationTruck->truckID ? 'selected' : ''}} value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}
@if ($vehicle->deleted_at)
(USUNIĘTY {{$vehicle->deleted_at }})
@elseif ($vehicle->status == 0)
(zawieszony)
@endif
</option>
@endforeach
</select>
</div>