2019-11-23 15:01:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
use App\User;
|
|
|
|
use App\operations;
|
|
|
|
use App\operationsMembers;
|
2019-11-25 01:10:46 +01:00
|
|
|
use App\vehicle;
|
2019-11-23 15:01:59 +01:00
|
|
|
use App\operationsDrivers;
|
2019-12-07 14:44:28 +01:00
|
|
|
use App\operationsTrucks;
|
2020-02-01 01:03:57 +01:00
|
|
|
use App\Http\Controllers\documentCreators;
|
|
|
|
|
2019-11-23 15:01:59 +01:00
|
|
|
use Illuminate\Http\Request;
|
2019-12-07 14:50:37 +01:00
|
|
|
use Illuminate\Support\Facades\View;
|
2019-11-23 15:01:59 +01:00
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2020-02-27 14:33:21 +01:00
|
|
|
const basicTrainingID = 1; //szkolenie podstawowe
|
|
|
|
const leaderTrainingID = 2; //szkolenie dowódcy
|
|
|
|
const driverTrainingID = 3; //szkolenie kierowcy-mechanika
|
|
|
|
|
2019-11-23 15:01:59 +01:00
|
|
|
class operationsController extends Controller
|
|
|
|
{
|
|
|
|
//
|
2020-02-27 14:33:21 +01:00
|
|
|
|
|
|
|
|
2019-11-23 15:01:59 +01:00
|
|
|
public function create(){
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
2019-12-07 14:44:28 +01:00
|
|
|
$operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID)
|
2020-01-24 23:05:55 +01:00
|
|
|
->whereNull('deleted_at')
|
2019-12-07 14:44:28 +01:00
|
|
|
->leftJoin('users', 'operations.commanderID', '=', 'users.id')
|
2019-12-07 14:50:37 +01:00
|
|
|
->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.name', 'users.surname')
|
2020-01-24 23:05:55 +01:00
|
|
|
->paginate(10);
|
2020-01-03 05:13:22 +01:00
|
|
|
$fireFighters = array();
|
|
|
|
$trucks = array();
|
2019-12-11 20:28:53 +01:00
|
|
|
foreach($operations as $operation){
|
|
|
|
$id =$operation->id;
|
|
|
|
$fireFighters[$id] = 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();
|
|
|
|
|
2020-01-30 17:34:16 +01:00
|
|
|
$trucks[$id] = DB::table('vehicles')->where([
|
|
|
|
["vehicles.fireStationID", "=", auth()->user()->fireStationID ],
|
|
|
|
])
|
2019-12-11 20:28:53 +01:00
|
|
|
->leftJoin('operationsTrucks', function ($join) use($id){
|
|
|
|
$join->on('vehicles.id', '=', 'operationsTrucks.truckID');
|
|
|
|
$join->where('operationsTrucks.operationID', '=', $id);
|
|
|
|
})
|
|
|
|
->leftJoin('users', 'operationsTrucks.driverID', '=', 'users.id')
|
|
|
|
->select('vehicles.*', 'operationsTrucks.truckID', 'operationsTrucks.driverID', 'users.name as driverName', 'users.surname as driverSurname')
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return view('operation', ["operations" => $operations], ["fireFighters" => $fireFighters], ["trucks" => $trucks]);
|
|
|
|
return View::make('/operation')->with(compact('operations', 'fireFighters', 'trucks'));
|
2019-11-23 15:01:59 +01:00
|
|
|
} else{
|
|
|
|
return view('operation');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
2020-02-01 01:01:26 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
|
2020-02-27 14:33:21 +01:00
|
|
|
$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();
|
2020-01-30 17:34:16 +01:00
|
|
|
$vehicles = DB::table('vehicles')->where([
|
|
|
|
["fireStationID", '=', auth()->user()->fireStationID],
|
|
|
|
["vehicles.status", "=", 1],
|
|
|
|
["vehicles.deleted_at", "=", null],
|
|
|
|
])
|
2019-11-25 01:10:46 +01:00
|
|
|
->get();
|
2020-02-27 14:33:21 +01:00
|
|
|
//return view("operationAdd", ["fireFighters" => $fireFighters], ["vehicles" => $vehicles]);
|
|
|
|
return view("operationAdd")
|
|
|
|
->with(compact('fireFighters'))
|
|
|
|
->with(compact('leaders'))
|
|
|
|
->with(compact('drivers'))
|
|
|
|
->with(compact('vehicles'));
|
|
|
|
|
2020-02-01 01:01:26 +01:00
|
|
|
} else return redirect()->to('/wyjazdy');
|
2019-11-23 15:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-07 14:44:28 +01:00
|
|
|
public function editForm($id){
|
2020-02-01 01:01:26 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
|
2019-11-23 15:01:59 +01:00
|
|
|
|
2019-12-07 14:50:37 +01:00
|
|
|
// $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get();
|
2020-01-30 17:34:16 +01:00
|
|
|
$vehicles = DB::table('vehicles')->where([
|
|
|
|
["fireStationID", '=', auth()->user()->fireStationID],
|
2020-02-27 14:33:21 +01:00
|
|
|
//["vehicles.status", "=", 1],
|
2020-01-30 17:34:16 +01:00
|
|
|
])
|
2019-12-07 14:50:37 +01:00
|
|
|
->get();
|
2019-12-07 14:44:28 +01:00
|
|
|
$operation = DB::table('operations')->where('operations.id', '=', $id)->first();
|
2019-12-07 14:50:37 +01:00
|
|
|
$operationMembers = DB::table('operationsMembers')->where('operationID', '=', $id)->get();
|
2019-12-07 14:44:28 +01:00
|
|
|
// $operation = DB::table('operations')->where('operations.id', '=', $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')
|
|
|
|
// ->get();
|
2019-12-07 14:50:37 +01:00
|
|
|
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
|
2020-02-27 14:33:21 +01:00
|
|
|
->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)
|
2019-12-07 14:50:37 +01:00
|
|
|
->leftJoin('operationsMembers', function ($join) use($id){
|
|
|
|
$join->on('users.id', '=', 'operationsMembers.memberID');
|
|
|
|
$join->where('operationsMembers.operationID', '=', $id);
|
|
|
|
})
|
|
|
|
->select('users.*', 'operationsMembers.memberID', 'operationsMembers.privateTransport')
|
|
|
|
->get();
|
2020-01-15 11:47:40 +01:00
|
|
|
|
|
|
|
|
2020-01-22 00:54:08 +01:00
|
|
|
// $operationsTrucks = DB::table('vehicles')->where("vehicles.fireStationID", "=", auth()->user()->fireStationID )
|
|
|
|
// ->leftJoin('operationsTrucks', function ($join) use($id){
|
|
|
|
// $join->on('vehicles.id', '=', 'operationsTrucks.truckID');
|
|
|
|
// $join->where('operationsTrucks.operationID', '=', $id);
|
|
|
|
// })
|
|
|
|
// ->leftJoin('users', 'operationsTrucks.driverID', '=', 'users.id')
|
|
|
|
// ->select('vehicles.*', 'operationsTrucks.truckID', 'operationsTrucks.driverID', 'users.name as driverName', 'users.surname as driverSurname')
|
|
|
|
// ->get();
|
|
|
|
|
|
|
|
$operationsTrucks = DB::table('operationsTrucks')->where("operationsTrucks.operationID", "=", $id)
|
|
|
|
->join('users', 'operationsTrucks.driverID', '=', 'users.ID')
|
|
|
|
->join('vehicles', 'operationsTrucks.truckID', '=', 'vehicles.ID')
|
2020-01-15 11:47:40 +01:00
|
|
|
->select('vehicles.*', 'operationsTrucks.truckID', 'operationsTrucks.driverID', 'users.name as driverName', 'users.surname as driverSurname')
|
|
|
|
->get();
|
|
|
|
|
2019-12-07 14:44:28 +01:00
|
|
|
// if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) {
|
2019-12-07 14:50:37 +01:00
|
|
|
// return view('operationEdit', ["operation" => $operation], ["fireFighters" => $fireFighters], ["operationMembers" => $operationMembers] );
|
2020-02-27 14:33:21 +01:00
|
|
|
return View::make('/operationEdit')->with(compact('fireFighters', 'drivers', 'leaders', 'operation', 'operationMembers', 'vehicles', 'operationsTrucks'));
|
2019-12-07 14:44:28 +01:00
|
|
|
// } else{
|
|
|
|
// return "Brak dostepu";
|
|
|
|
// }
|
|
|
|
} else{
|
2020-02-01 01:01:26 +01:00
|
|
|
return redirect()->to('/wyjazdy');
|
2019-12-07 14:44:28 +01:00
|
|
|
}
|
2019-11-23 15:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(){
|
|
|
|
$this->validate(request(),[
|
|
|
|
'operationDate' => 'required',
|
2020-01-31 03:13:13 +01:00
|
|
|
'operationLocation' => 'required|max:100',
|
|
|
|
'operationTarget' => 'required|max:100',
|
|
|
|
'operationDangerType' => 'required|max:100',
|
|
|
|
'operationDescription' => 'required|max:250',
|
2019-11-23 15:01:59 +01:00
|
|
|
'operationLeader' => 'required',
|
2019-12-07 14:44:28 +01:00
|
|
|
'operationDriver.*' => 'required',
|
|
|
|
'operationVehicle.*' => 'required',
|
|
|
|
'attendance.*' => 'required',
|
|
|
|
'transport.*' => 'required',
|
2019-11-23 15:01:59 +01:00
|
|
|
],
|
|
|
|
[
|
2020-01-31 03:13:13 +01:00
|
|
|
'required' => ':attribute jest wymagany(e)',
|
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.'
|
2019-11-23 15:01:59 +01:00
|
|
|
]);
|
|
|
|
|
2019-12-07 14:50:37 +01:00
|
|
|
//
|
2019-11-23 15:01:59 +01:00
|
|
|
$request = request();
|
|
|
|
$operations = operations::create([
|
|
|
|
'operationDate' => $request-> operationDate,
|
|
|
|
'location' => $request-> operationLocation,
|
|
|
|
'target' => $request-> operationTarget,
|
|
|
|
'dangerType' => $request-> operationDangerType,
|
|
|
|
'description' => $request-> operationDescription,
|
|
|
|
'commanderID' => $request-> operationLeader,
|
2019-12-07 14:44:28 +01:00
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
2019-11-23 15:01:59 +01:00
|
|
|
]);
|
|
|
|
|
2019-12-07 14:50:37 +01:00
|
|
|
// Add trucks
|
2019-12-07 14:44:28 +01:00
|
|
|
$operationDriver = $request ->operationDriver;
|
|
|
|
$operationVehicle = $request -> operationVehicle;
|
|
|
|
for($count = 0; $count < count($operationDriver); $count++){
|
|
|
|
$operationsTrucks = operationsTrucks::create([
|
|
|
|
'operationID' => $operations->id,
|
2020-02-27 14:33:21 +01:00
|
|
|
'truckID' => $operationVehicle[$count],
|
2020-02-27 02:04:39 +01:00
|
|
|
'driverID' => $operationDriver[$count]
|
2020-02-27 14:33:21 +01:00
|
|
|
]);
|
2019-12-07 14:44:28 +01:00
|
|
|
}
|
|
|
|
|
2019-12-07 14:50:37 +01:00
|
|
|
|
|
|
|
// Add members
|
2019-12-07 14:44:28 +01:00
|
|
|
$attendance = $request-> attendance;
|
2019-12-07 14:50:37 +01:00
|
|
|
$transport = $request-> transport;
|
|
|
|
|
|
|
|
// Count of firefighters (need for length of array)
|
2020-02-27 14:33:21 +01:00
|
|
|
$fireFightersCount = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
|
|
|
|
->leftJoin('trainingsFirefighters', 'trainingsFirefighters.firefighterID', '=', 'users.id')
|
|
|
|
->where('trainingsFirefighters.trainingID', '=', basicTrainingID)
|
|
|
|
->count();
|
2019-12-07 14:50:37 +01:00
|
|
|
for($count = 0; $count < $fireFightersCount; $count++){
|
|
|
|
|
|
|
|
// Check privateTransport checklist
|
|
|
|
$privateTransport = 2;
|
|
|
|
if(isset($transport[$count])){
|
|
|
|
$privateTransport = 1;
|
|
|
|
} else{
|
|
|
|
$privateTransport = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($attendance[$count])){
|
2019-12-07 14:44:28 +01:00
|
|
|
$operationsMembers = operationsMembers::create([
|
|
|
|
'operationID' => $operations->id,
|
|
|
|
'memberID' => $attendance[$count],
|
2019-12-07 14:50:37 +01:00
|
|
|
'privateTransport' => $privateTransport,
|
2019-12-07 14:44:28 +01:00
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-23 15:01:59 +01:00
|
|
|
return operationsController::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(){
|
2019-12-07 14:50:37 +01:00
|
|
|
$this->validate(request(),[
|
|
|
|
'operationDate' => 'required',
|
2020-01-31 03:13:13 +01:00
|
|
|
'operationLocation' => 'required|max:100',
|
|
|
|
'operationTarget' => 'required|max:100',
|
|
|
|
'operationDangerType' => 'required|max:100',
|
|
|
|
'operationDescription' => 'required|max:250',
|
2019-12-07 14:50:37 +01:00
|
|
|
'operationLeader' => 'required',
|
|
|
|
'operationDriver.*' => 'required',
|
|
|
|
'operationVehicle.*' => 'required',
|
|
|
|
'attendance.*' => 'required',
|
|
|
|
'transport.*' => 'required',
|
|
|
|
],
|
|
|
|
[
|
2020-01-22 00:54:08 +01:00
|
|
|
'required' => ':attribute jest wymagany(e)',
|
2020-01-31 03:13:13 +01:00
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.'
|
2019-12-07 14:50:37 +01:00
|
|
|
]);
|
|
|
|
|
2019-11-23 15:01:59 +01:00
|
|
|
|
2019-12-07 14:50:37 +01:00
|
|
|
$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,
|
2019-12-11 20:28:53 +01:00
|
|
|
'truckID' => $operationVehicle[$count],
|
|
|
|
'driverID' => $operationDriver[$count]
|
2019-12-07 14:50:37 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:33:21 +01:00
|
|
|
return redirect()->to('/wyjazdy');
|
2019-11-23 15:01:59 +01:00
|
|
|
}
|
2020-01-24 23:05:55 +01:00
|
|
|
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
operations::find($id)->delete($id);
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'success' => 'Record deleted successfully!'
|
|
|
|
]);
|
|
|
|
}
|
2020-02-01 01:03:57 +01:00
|
|
|
|
|
|
|
public function createSingleOperationPDF(){
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ) {
|
|
|
|
$request = request();
|
|
|
|
$test = new documentCreators();
|
|
|
|
$test->createSingleOperationPDF2($request->operationID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createAllOperationsPDF(){
|
|
|
|
if (auth()->user() != null && auth()->user()->fireStationID != null) {
|
|
|
|
$request = request();
|
|
|
|
$test = new documentCreators();
|
|
|
|
$test->createAllOperationsPDF($request->fireStationID);
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 15:01:59 +01:00
|
|
|
}
|