diff --git a/app/Http/Controllers/operationsController.php b/app/Http/Controllers/operationsController.php
index d32a094..40e7d50 100644
--- a/app/Http/Controllers/operationsController.php
+++ b/app/Http/Controllers/operationsController.php
@@ -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)
diff --git a/resources/views/operationAdd.blade.php b/resources/views/operationAdd.blade.php
index 6d9d622..b5e01e7 100644
--- a/resources/views/operationAdd.blade.php
+++ b/resources/views/operationAdd.blade.php
@@ -43,11 +43,11 @@
@@ -119,8 +119,8 @@
html += '';
html += '';
html += '';
diff --git a/resources/views/operationEdit.blade.php b/resources/views/operationEdit.blade.php
index 1e089fe..e682b3e 100644
--- a/resources/views/operationEdit.blade.php
+++ b/resources/views/operationEdit.blade.php
@@ -47,8 +47,8 @@
@@ -63,8 +63,8 @@
@@ -73,7 +73,13 @@